static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { List <CodeInstruction> codes = new List <CodeInstruction>(instructions); try { int start = InstructionHandlers.getInstruction(codes, 0, 0, OpCodes.Isinst, "Room_Enviro") - 1; int startAll = InstructionHandlers.getLastInstructionBefore(codes, start, codes[start].opcode, codes[start].operand); object operand = codes[start].operand; int end = InstructionHandlers.getInstruction(codes, start, 0, OpCodes.Stfld, "RoomController", "NumHeaters"); FileLog.Log("Running patch, which found anchors " + InstructionHandlers.toString(codes, start) + " and " + InstructionHandlers.toString(codes, end)); if (end > start && end >= 0) { InstructionHandlers.nullInstructions(codes, startAll, start); codes.RemoveRange(start, end - start + 1); FileLog.Log("Deletion of range successful, injecting new instructions"); List <CodeInstruction> inject = new List <CodeInstruction>(); inject.Add(new CodeInstruction(OpCodes.Ldarg_0)); inject.Add(new CodeInstruction(OpCodes.Ldloc, operand)); inject.Add(InstructionHandlers.createMethodCall("ReikaKalseki.RoomEnvironmentals.RoomEnvironmentalsMod", "onRoomFindMachine", false, typeof(RoomController), typeof(SegmentEntity))); FileLog.Log("Injecting " + inject.Count + " instructions: " + InstructionHandlers.toString(inject)); codes.InsertRange(start, inject); } FileLog.Log("Done patch " + MethodBase.GetCurrentMethod().DeclaringType); //FileLog.Log("Codes are "+InstructionHandlers.toString(codes)); } catch (Exception e) { FileLog.Log("Caught exception when running patch " + MethodBase.GetCurrentMethod().DeclaringType + "!"); FileLog.Log(e.Message); FileLog.Log(e.StackTrace); FileLog.Log(e.ToString()); } return(codes.AsEnumerable()); }
static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { List <CodeInstruction> codes = new List <CodeInstruction>(instructions); try { int loc = InstructionHandlers.getLastInstructionBefore(codes, codes.Count, OpCodes.Stfld, "RoomController", "mnVolume"); FileLog.Log("Running patch, which found anchor " + InstructionHandlers.toString(codes, loc)); List <CodeInstruction> inject = new List <CodeInstruction>(); inject.Add(new CodeInstruction(OpCodes.Ldarg_0)); inject.Add(InstructionHandlers.createMethodCall("ReikaKalseki.RoomEnvironmentals.RoomEnvironmentalsMod", "onRoomCalculateEnvironment", false, typeof(int), typeof(RoomController))); FileLog.Log("Injecting " + inject.Count + " instructions: " + InstructionHandlers.toString(inject)); codes.InsertRange(loc, inject); FileLog.Log("Done patch " + MethodBase.GetCurrentMethod().DeclaringType); //FileLog.Log("Codes are "+InstructionHandlers.toString(codes)); } catch (Exception e) { FileLog.Log("Caught exception when running patch " + MethodBase.GetCurrentMethod().DeclaringType + "!"); FileLog.Log(e.Message); FileLog.Log(e.StackTrace); FileLog.Log(e.ToString()); } return(codes.AsEnumerable()); }