Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vanilla Event Expanded Compat #3616

Open
wants to merge 3 commits into
base: Development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Source/CombatExtended.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VehiclesCompat", "VehiclesC
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SRTSCompat", "SRTSCompat\SRTSCompat.csproj", "{2ECDEC68-5878-41C7-B494-E189B8C5C33E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SOS2Compat", "SOS2Compat\SOS2Compat.csproj", "{D7AF4074-CE88-4272-91F4-A0D63951C1F0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SOS2Compat", "SOS2Compat\SOS2Compat.csproj", "{D7AF4074-CE88-4272-91F4-A0D63951C1F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PsyblastersCompat", "PsyblastersCompat\PsyblastersCompat.csproj", "{6B518120-4315-4017-B4E6-7DA8ABCCFF84}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PsyblastersCompat", "PsyblastersCompat\PsyblastersCompat.csproj", "{6B518120-4315-4017-B4E6-7DA8ABCCFF84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VEEventCompat", "VEEventCompat\VEEventCompat.csproj", "{4D883AAF-5689-4B17-AD63-DCB9E74684C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -74,6 +76,12 @@ Global
{6B518120-4315-4017-B4E6-7DA8ABCCFF84}.Debugger|Any CPU.Build.0 = Debug|Any CPU
{6B518120-4315-4017-B4E6-7DA8ABCCFF84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B518120-4315-4017-B4E6-7DA8ABCCFF84}.Release|Any CPU.Build.0 = Release|Any CPU
{4D883AAF-5689-4B17-AD63-DCB9E74684C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D883AAF-5689-4B17-AD63-DCB9E74684C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D883AAF-5689-4B17-AD63-DCB9E74684C8}.Debugger|Any CPU.ActiveCfg = Debug|Any CPU
{4D883AAF-5689-4B17-AD63-DCB9E74684C8}.Debugger|Any CPU.Build.0 = Debug|Any CPU
{4D883AAF-5689-4B17-AD63-DCB9E74684C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D883AAF-5689-4B17-AD63-DCB9E74684C8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
74 changes: 74 additions & 0 deletions Source/VEEventCompat/Harmony.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using CombatExtended;
using HarmonyLib;
using JetBrains.Annotations;
using Mono.Unix.Native;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using VEE.RegularEvents;
using Verse;
using Verse.AI;
using Verse.Noise;

namespace VEEventCompat
{
[UsedImplicitly]
[StaticConstructorOnStartup]
public class PatchMain
{
private static Harmony harmonyInstance;

internal static Harmony HarmonyInstance
{
get
{
if (harmonyInstance == null)
{
harmonyInstance = new Harmony("CE_VEEventCompat");
}
return harmonyInstance;
}
}

static PatchMain()
{
HarmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
}
}

[StaticConstructorOnStartup]
[HarmonyPatch(typeof(WeaponPod), "TryExecuteWorker")]
public class InsertAmmo
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> transp(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = instructions.ToList();
for (int i = list.Count - 1; i >= 0; --i)
{
if (list[i].opcode == OpCodes.Brtrue_S)
{
MethodInfo overrideMethod = typeof(InsertAmmo).GetMethod("InsertMethod", BindingFlags.Static | BindingFlags.Public);

list.InsertRange(i + 1, new CodeInstruction[]
{
new CodeInstruction(OpCodes.Ldloc_S,6),
new CodeInstruction(OpCodes.Call, overrideMethod),
});
break;
}
}
return list;
}

public static void InsertMethod(List<Thing> outThings)
{
CE_ThingSetMakerUtility.GenerateAmmoForWeapon(outThings, true, true, new IntRange(1, 3));
}
}
}
33 changes: 33 additions & 0 deletions Source/VEEventCompat/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VEEventCompat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VEEventCompat")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4d883aaf-5689-4b17-ad63-dcb9e74684c8")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
76 changes: 76 additions & 0 deletions Source/VEEventCompat/VEEventCompat.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4D883AAF-5689-4B17-AD63-DCB9E74684C8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VEEventCompat</RootNamespace>
<AssemblyName>VEEventCompat</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VEE">
<HintPath>..\..\..\..\..\..\workshop\content\294100\1938420742\1.5\Assemblies\VEE.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Harmony.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CombatExtended\CombatExtended.csproj">
<Project>{5bf06bfb-6506-48a4-bda5-8a2e5f9153f9}</Project>
<Name>CombatExtended</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref">
<Version>1.5.4104</Version>
</PackageReference>
<PackageReference Include="Lib.Harmony">
<Version>2.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading