Skip to content

Instantly share code, notes, and snippets.

@slippycheeze
Created July 14, 2022 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slippycheeze/8ee7bdc7e035a3ea4c7ecb2fcb1c4406 to your computer and use it in GitHub Desktop.
Save slippycheeze/8ee7bdc7e035a3ea4c7ecb2fcb1c4406 to your computer and use it in GitHub Desktop.
// WTF, why there no kitchen?
[HarmonyPatch(typeof(RoomRoleWorker_Kitchen), "GetScore")]
internal static class RoomRoleWorker_Kitchen__HandleDesignationCategoryChanges {
public static IEnumerable<CodeInstruction> Transpiler(
IEnumerable<CodeInstruction> code,
ILGenerator generator,
MethodBase original
) {
string name = original.ShortDescription();
try {
Log.Message($"[SlippyCheeze] {name}: patching out the DesignationCategory check…");
CodeMatch[] to_be_removed = new CodeMatch[]{
// IL_0018: ldloc.3 // thing
new CodeMatch(i => i.IsLdloc()),
// IL_0019: ldfld class Verse.ThingDef Verse.Thing::def
new CodeMatch(i => i.LoadsField(AccessTools.Field(typeof(Thing), "def"))),
// IL_001e: ldfld class Verse.DesignationCategoryDef Verse.BuildableDef::designationCategory
new CodeMatch(i => i.LoadsField(AccessTools.Field(typeof(BuildableDef), "designationCategory"))),
// IL_0023: ldsfld class Verse.DesignationCategoryDef RimWorld.DesignationCategoryDefOf::Production
new CodeMatch(i => i.LoadsField(AccessTools.Field(typeof(DesignationCategoryDefOf), "Production"))),
// IL_0028: bne.un IL_00ad
new CodeMatch(i => i.Branches(out Label? _))
};
return new CodeMatcher(code, generator)
.Start()
.MatchStartForward(to_be_removed)
.ThrowIfInvalid("finding the designation category check")
.RemoveInstructions(to_be_removed.Count())
.InstructionEnumeration();
} catch (Exception ex) {
Log.Error($"[SlippyCheeze] {name}: {ex}");
code.ForEach((i, n) => Log.Message($" {n:###} {i}"));
return code;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment