Skip to content

Commit

Permalink
v1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
XeoNovaDan committed Mar 3, 2020
1 parent 2c7d010 commit 494b57e
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 3 deletions.
Binary file modified 1.1/Assemblies/TurretExtensions.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<li>1.0</li>
<li>1.1</li>
</supportedVersions>
<description>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.</description>
<description>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.</description>
<modDependencies>
<li>
<packageId>brrainz.harmony</packageId>
Expand Down
Binary file modified Source/TurretExtensions/.vs/TurretExtensions/v16/.suo
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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<CompMannable>() 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<CompMannable>() is CompMannable mannableComp)
return mannableComp.ManningPawn;
return original;
}

}

[HarmonyPatch(typeof(Verb_Shoot), "TryCastShot")]
public static class TryCastShot
{

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
// WarmupComplete transpiler can be reused
return WarmupComplete.Transpiler(instructions);
}

}



}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<Compile Include="HarmonyPatches\HarmonyPatchesUtility.cs" />
<Compile Include="HarmonyPatches\Patch_Building_Turret.cs" />
<Compile Include="HarmonyPatches\Patch_JobDriver_ManTurret.cs" />
<Compile Include="HarmonyPatches\Patch_Verb_Shoot.cs" />
<Compile Include="HarmonyPatches\Patch_Verb.cs" />
<Compile Include="HarmonyPatches\Patch_Pawn_RotationTracker.cs" />
<Compile Include="HarmonyPatches\Patch_Designator_Cancel.cs" />
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 494b57e

Please sign in to comment.