RimWorld

RimWorld

Walls are solid
ogre 19 Dec, 2022 @ 6:58am
transpiler code for canMine bools
using HarmonyLib; using System; using System.Collections.Generic; using System.Linq; using System.Reflection.Emit; using Verse; using Verse.AI; namespace YourNamespace // UPDATE NAMESPACE BEFORE RELEASE { // run this patch when the constructor is called [StaticConstructorOnStartup] // the method we want harmony to find // Verse.AI.JobGiver_ExitMap.TryGiveJob(Pawn) [HarmonyPatch(typeof(JobGiver_ExitMap), "TryGiveJob", new Type[] { typeof(Pawn) })] public class JobGiver_ExitMap_TryGiveJob_Patch { static JobGiver_ExitMap_TryGiveJob_Patch() { // harmony debug file Harmony.DEBUG = true; // DELETE OR SET DEBUG TO FALSE BEFORE RELEASE // create and apply the harmony patch new Harmony("your.patch.id.here").PatchAll(); // UPDATE ID BEFORE RELEASE } static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { // we need to change the value of two booleans, so when found, save the index int index1 = 0; int index2 = 0; // only change the opcodes if we found the correct call bool found = false; // get all the instructions for the method harmony found var codes = new List<CodeInstruction>(instructions); // loop through the codes for (var i = 0; i < codes.Count; i++) { // check if the code is a call if (codes.opcode == OpCodes.Call)
{
// check if this call's operand matches our desired method
var strOp = codes.operand.ToString();
if (strOp == "Verse.AI.Job PassBlockerJob(Verse.Pawn, Verse.Thing, Verse.IntVec3, Boolean, Boolean)")
{
// we found the correct call, update our boolean
FileLog.LogBuffered($"FOUND METHOD CALL @ {i}");
found = true;
// update our index numbers for our stack push opcodes
index1 = i - 2;
index2 = i - 1;
FileLog.LogBuffered($"INDEX1 = {index1}");
FileLog.LogBuffered($"INDEX2 = {index2}");
// stop the loop
break;
}
}
}
// if we found the correct method call
if (found)
{
// change our opcodes to push a zero instead of a one (true to false)
codes[index1].opcode = OpCodes.Ldc_I4_0;
codes[index2].opcode = OpCodes.Ldc_I4_0;
FileLog.LogBuffered("Updated Target OpCodes.");
}
// write our logs to disk
FileLog.FlushBuffer();
// return the updated codes
return codes.AsEnumerable();
}
}
}
Last edited by ogre; 19 Dec, 2022 @ 7:03am
< >
Showing 1-1 of 1 comments
Victor  [developer] 19 Dec, 2022 @ 1:04pm 
Thanks, I'll have a look at it next weekend.
< >
Showing 1-1 of 1 comments
Per page: 1530 50