diff --git a/1.1/Assemblies/TurretExtensions.dll b/1.1/Assemblies/TurretExtensions.dll index 428a36d..b7b588f 100644 Binary files a/1.1/Assemblies/TurretExtensions.dll and b/1.1/Assemblies/TurretExtensions.dll differ diff --git a/About/About.xml b/About/About.xml index 02fe953..2c01863 100644 --- a/About/About.xml +++ b/About/About.xml @@ -8,7 +8,7 @@
  • 1.0
  • 1.1
  • - Current Version: v1.3.1.0 (2nd March 2020)\n\nA resource which allows modders to create turret mods with more flair, as well as various bugfixes and quality-of-life improvements. + Current Version: v1.3.2.0 (3rd March 2020)\n\nA resource which allows modders to create turret mods with more flair, as well as various bugfixes and quality-of-life improvements.
  • brrainz.harmony diff --git a/Source/TurretExtensions/.vs/TurretExtensions/v16/.suo b/Source/TurretExtensions/.vs/TurretExtensions/v16/.suo index ba509f3..0a5b632 100644 Binary files a/Source/TurretExtensions/.vs/TurretExtensions/v16/.suo and b/Source/TurretExtensions/.vs/TurretExtensions/v16/.suo differ diff --git a/Source/TurretExtensions/.vs/TurretExtensions/v16/Server/sqlite3/storage.ide b/Source/TurretExtensions/.vs/TurretExtensions/v16/Server/sqlite3/storage.ide index 48559cb..119dd25 100644 Binary files a/Source/TurretExtensions/.vs/TurretExtensions/v16/Server/sqlite3/storage.ide and b/Source/TurretExtensions/.vs/TurretExtensions/v16/Server/sqlite3/storage.ide differ diff --git a/Source/TurretExtensions/TurretExtensions/HarmonyPatches/Patch_Verb_Shoot.cs b/Source/TurretExtensions/TurretExtensions/HarmonyPatches/Patch_Verb_Shoot.cs new file mode 100644 index 0000000..8d8ff32 --- /dev/null +++ b/Source/TurretExtensions/TurretExtensions/HarmonyPatches/Patch_Verb_Shoot.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Reflection; +using System.Reflection.Emit; +using System.Runtime.CompilerServices; +using RimWorld; +using Verse; +using HarmonyLib; +using UnityEngine; + +namespace TurretExtensions +{ + + public static class Patch_Verb_Shoot + { + + [HarmonyPatch(typeof(Verb_Shoot), nameof(Verb_Shoot.WarmupComplete))] + public static class WarmupComplete + { + + public static IEnumerable Transpiler(IEnumerable instructions) + { + // Reason why this transpiler exists instead of just a postfix on the CasterPawn and CasterIsPawn properties is because CasterPawn gets referenced in several other places too, which causes other issues + + #if DEBUG + Log.Message("Transpiler start: Verb_Shoot.WarmupComplete (3 matches)"); + #endif + + var instructionList = instructions.ToList(); + + var getCasterIsPawnInfo = AccessTools.Property(typeof(Verb), nameof(Verb.CasterIsPawn)).GetGetMethod(); + var casterIsActuallyPawn = AccessTools.Method(typeof(WarmupComplete), nameof(WarmupComplete.CasterIsActuallyPawn)); + + var getCasterPawnInfo = AccessTools.Property(typeof(Verb), nameof(Verb.CasterPawn)).GetGetMethod(); + var actualCasterPawnInfo = AccessTools.Method(typeof(WarmupComplete), nameof(WarmupComplete.ActualCasterPawn)); + + for (int i = 0; i < instructionList.Count; i++) + { + var instruction = instructionList[i]; + + // Update all 'CasterIsPawn' and 'CasterPawn' calls to factor in CompMannable + if (instruction.opcode == OpCodes.Callvirt) + { + #if DEBUG + Log.Message("Verb_Shoot.WarmupComplete match 1 of 3"); + #endif + + // CasterIsPawn + if (instruction.OperandIs(getCasterIsPawnInfo)) + { + #if DEBUG + Log.Message("Verb_Shoot.WarmupComplete match 2 of 3"); + #endif + + yield return instruction; // this.CasterIsPawn + yield return new CodeInstruction(OpCodes.Ldarg_0); // this + instruction = new CodeInstruction(OpCodes.Call, casterIsActuallyPawn); // CasterIsActuallyPawn(this.CasterIsPawn, this) + } + + // CasterPawn + else if (instruction.OperandIs(getCasterPawnInfo)) + { + #if DEBUG + Log.Message("Verb_Shoot.WarmupComplete match 3 of 3"); + #endif + + yield return instruction; // this.CasterPawn + yield return new CodeInstruction(OpCodes.Ldarg_0); // this + instruction = new CodeInstruction(OpCodes.Call, actualCasterPawnInfo); // ActualCasterPawn(this.CasterPawn, this) + } + } + + yield return instruction; + } + } + + private static bool CasterIsActuallyPawn(bool original, Verb instance) + { + // Factor in CompMannable for exp purposes + return original || (instance.Caster.TryGetComp() is CompMannable mannableComp && mannableComp.MannedNow); + } + + private static Pawn ActualCasterPawn(Pawn original, Verb instance) + { + // Factor in CompMannable for exp purposes + if (original == null && instance.Caster.TryGetComp() is CompMannable mannableComp) + return mannableComp.ManningPawn; + return original; + } + + } + + [HarmonyPatch(typeof(Verb_Shoot), "TryCastShot")] + public static class TryCastShot + { + + public static IEnumerable Transpiler(IEnumerable instructions) + { + // WarmupComplete transpiler can be reused + return WarmupComplete.Transpiler(instructions); + } + + } + + + + } + +} diff --git a/Source/TurretExtensions/TurretExtensions/Properties/AssemblyInfo.cs b/Source/TurretExtensions/TurretExtensions/Properties/AssemblyInfo.cs index a693f48..af027f7 100644 --- a/Source/TurretExtensions/TurretExtensions/Properties/AssemblyInfo.cs +++ b/Source/TurretExtensions/TurretExtensions/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.1.0")] -[assembly: AssemblyFileVersion("1.3.1.0")] +[assembly: AssemblyVersion("1.3.2.0")] +[assembly: AssemblyFileVersion("1.3.2.0")] diff --git a/Source/TurretExtensions/TurretExtensions/TurretExtensions.csproj b/Source/TurretExtensions/TurretExtensions/TurretExtensions.csproj index 467dcab..942c836 100644 --- a/Source/TurretExtensions/TurretExtensions/TurretExtensions.csproj +++ b/Source/TurretExtensions/TurretExtensions/TurretExtensions.csproj @@ -64,6 +64,7 @@ + diff --git a/Source/TurretExtensions/TurretExtensions/obj/Debug/TurretExtensions.csprojAssemblyReference.cache b/Source/TurretExtensions/TurretExtensions/obj/Debug/TurretExtensions.csprojAssemblyReference.cache index ceb7d84..1997ff2 100644 Binary files a/Source/TurretExtensions/TurretExtensions/obj/Debug/TurretExtensions.csprojAssemblyReference.cache and b/Source/TurretExtensions/TurretExtensions/obj/Debug/TurretExtensions.csprojAssemblyReference.cache differ diff --git a/Source/TurretExtensions/TurretExtensions/obj/Debug/TurretExtensions.dll b/Source/TurretExtensions/TurretExtensions/obj/Debug/TurretExtensions.dll index 428a36d..b7b588f 100644 Binary files a/Source/TurretExtensions/TurretExtensions/obj/Debug/TurretExtensions.dll and b/Source/TurretExtensions/TurretExtensions/obj/Debug/TurretExtensions.dll differ