Skip to content

Commit

Permalink
also applied needs fix in 1.1 version
Browse files Browse the repository at this point in the history
  • Loading branch information
rheirman committed Aug 16, 2020
1 parent 2152c2f commit 9161db8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Binary file modified 1.1/Assemblies/WhatTheHack.dll
Binary file not shown.
29 changes: 23 additions & 6 deletions 1.1/Source/WhatTheHack/Harmony/Caravan_NeedsTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Verse;

namespace WhatTheHack.Harmony
{
//Can wear belts d
// Patch that prevents a null reference error when a pawn doesn't have psychic entropy (which is always the case for mechs).
[HarmonyPatch(typeof(Caravan_NeedsTracker), "TrySatisfyPawnNeeds")]
class Caravan_NeedsTracker_TrySatisfyPawnNeeds
static class Caravan_NeedsTracker_TrySatisfyPawnNeeds
{
static void Postfix(Pawn p, ThingDef apparel, ref bool __result)
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator ilg)
{
if(!__result && Utilities.IsBelt(apparel.apparel) && p.health != null && p.health.hediffSet.HasHediff(WTH_DefOf.WTH_BeltModule)) //TODO: make more general
Label label = ilg.DefineLabel();

var instructionsList = new List<CodeInstruction>(instructions);
for (var i = 0; i < instructionsList.Count; i++)
{
__result = true;
CodeInstruction instruction = instructionsList[i];
yield return instruction;

if (instruction.operand as FieldInfo == AccessTools.Field(typeof(Pawn), "psychicEntropy"))
{
yield return new CodeInstruction(OpCodes.Dup);
yield return new CodeInstruction(OpCodes.Isinst, typeof(Pawn_PsychicEntropyTracker));
instructionsList[i + 1].labels.Add(label);
yield return new CodeInstruction(OpCodes.Brtrue, label);
yield return new CodeInstruction(OpCodes.Pop);
yield return new CodeInstruction(OpCodes.Ret);
}

}
}
}


}
1 change: 1 addition & 0 deletions 1.1/Source/WhatTheHack/WhatTheHack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<Compile Include="Comps\CompProperties_DataLevel.cs" />
<Compile Include="Comps\CompDataLevel.cs" />
<Compile Include="Comps\CompProperties_Overlays.cs" />
<Compile Include="Harmony\Caravan_NeedsTracker.cs" />
<Compile Include="Harmony\HealthCardUtility.cs" />
<Compile Include="Harmony\HediffStatsUtility.cs" />
<Compile Include="Harmony\JobDriver_Wear.cs" />
Expand Down

0 comments on commit 9161db8

Please sign in to comment.