-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathHarmonyPatches.cs
160 lines (146 loc) · 5.78 KB
/
HarmonyPatches.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using RimWorld;
using Harmony;
using System.Reflection;
using Verse.AI;
namespace QEthics
{
[StaticConstructorOnStartup]
public static class HarmonyPatches
{
static HarmonyPatches()
{
//Harmony
HarmonyInstance harmony = HarmonyInstance.Create("chjees.QEthics");
//Template
/*{
Type type = typeof(HarmonyPatches);
MethodInfo originalMethod = type.GetMethod("MethodName");
HarmonyMethod patchMethod = new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(Patch_Example_Example)));
harmony.Patch(
originalMethod,
null,
null);
}*/
{
if(!CompatibilityTracker.DeathRattleActive)
{
Type type = typeof(Pawn_HealthTracker);
MethodInfo originalMethod = AccessTools.Method(type, "ShouldBeDeadFromRequiredCapacity");
HarmonyMethod patchMethod = new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(Patch_ShouldBeDeadFromRequiredCapacity)));
harmony.Patch(
originalMethod,
patchMethod,
null);
}
else
{
Log.Message("Questionable Ethics, Compatibility with Death Rattle: Not patching Pawn_HealthTracker.ShouldBeDeadFromRequiredCapacity");
}
}
{
Type type = typeof(Toils_LayDown);
MethodInfo originalMethod = AccessTools.Method(type, "LayDown");
HarmonyMethod patchMethod = new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(Patch_LayDown)));
harmony.Patch(
originalMethod,
null,
patchMethod);
}
{
Type type = typeof(Pawn_EquipmentTracker);
MethodInfo originalMethod = AccessTools.Method(type, "DropAllEquipment");
HarmonyMethod patchMethod = new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(Patch_DropAllEquipment)));
harmony.Patch(
originalMethod,
patchMethod,
null);
}
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
public static bool Patch_DropAllEquipment(Pawn ___pawn, ThingOwner<ThingWithComps> ___equipment)
{
Pawn pawn = ___pawn;
if(pawn.health.Downed && pawn.health.hediffSet.hediffs.Any(hediff => hediff is Hediff_AddedPart addedPart && addedPart.comps.Any(comp => comp.props is HediffCompProperties_WeaponsPlatform)) &&
___equipment.InnerListForReading.Any(thing => thing.def.IsRangedWeapon))
{
return false;
}
return true;
}
public static bool Patch_ShouldBeDeadFromRequiredCapacity(PawnCapacityDef __result, Pawn ___pawn)
{
Pawn pawn = ___pawn;
if(pawn.health.hediffSet.HasHediff(QEHediffDefOf.QE_LifeSupport) && pawn.ValidLifeSupportNearby())
{
//Check if consciousness is there. If it is then its okay.
PawnCapacityDef pawnCapacityDef = PawnCapacityDefOf.Consciousness;
bool flag = (!pawn.RaceProps.IsFlesh) ? pawnCapacityDef.lethalMechanoids : pawnCapacityDef.lethalFlesh;
if (flag && pawn.health.capacities.CapableOf(pawnCapacityDef))
{
__result = pawnCapacityDef;
return false;
}
__result = null;
return false;
}
return true;
}
public static void Patch_LayDown(ref Toil __result)
{
Toil toil = __result;
if (toil == null)
return;
/*toil.AddPreInitAction(delegate()
{
Pawn actor = toil.actor;
if(actor.ValidLifeSupportNearby())
{
actor.health.AddHediff(QEHediffDefOf.QE_LifeSupport);
}
});*/
toil.AddPreTickAction(delegate()
{
Pawn actor = toil.actor;
if(actor != null && !actor.Dead)
{
if (actor.ValidLifeSupportNearby())
{
if (!actor.health.hediffSet.HasHediff(QEHediffDefOf.QE_LifeSupport))
{
actor.health.AddHediff(QEHediffDefOf.QE_LifeSupport);
}
}
else
{
if (actor.health.hediffSet.GetFirstHediffOfDef(QEHediffDefOf.QE_LifeSupport, false) is Hediff hediff)
{
actor.health.RemoveHediff(hediff);
}
}
}
});
/*toil.AddFinishAction(delegate()
{
if(toil == null)
{
Log.Message("wtf, the toil is null somehow.");
return;
}
Pawn actor = toil.actor;
if(actor != null && !actor.Dead)
{
if (actor.health.hediffSet.GetFirstHediffOfDef(QEHediffDefOf.QE_LifeSupport, false) is Hediff hediff)
{
actor.health.RemoveHediff(hediff);
}
//actor.health.CheckForStateChange(null, null);
}
});*/
}
}
}