// Loops around the instructions and removes the return condition. static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { SphereII_PlayerMoveController_Logger.Log("Patching OnClose()"); int counter = 0; // Grab all the instructions var codes = new List <CodeInstruction>(instructions); for (int i = 0; i < codes.Count; i++) { if (codes[i].opcode == OpCodes.Ldc_I4_8) { counter++; SphereII_PlayerMoveController_Logger.Log("Adjusting 8 to 10"); codes[i].opcode = OpCodes.Ldc_I4; // convert to the right thing codes[i].operand = 10; SphereII_PlayerMoveController_Logger.Log("Done with 8 to 10"); } } SphereII_PlayerMoveController_Logger.Log("Done With Patching OnClose()"); return(codes.AsEnumerable()); }
public void Start() { SphereII_PlayerMoveController_Logger.Log(" Loading Patch: " + GetType().ToString()); var harmony = HarmonyInstance.Create(GetType().ToString()); harmony.PatchAll(Assembly.GetExecutingAssembly()); }
// Loops around the instructions and removes the return condition. static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { SphereII_PlayerMoveController_Logger.Log("Patching SetupSlots()"); int counter = 0; // Grab all the instructions var codes = new List <CodeInstruction>(instructions); for (int i = 0; i < codes.Count; i++) { if (codes[i].opcode == OpCodes.Ldc_I4_S) { codes[i].opcode = OpCodes.Ldc_I4; codes[i].operand = 11; } } SphereII_PlayerMoveController_Logger.Log("Done With Patching SetupSlots()"); return(codes.AsEnumerable()); }
// In addition to the transpiler above, we also want to see whether out inventory actions has the expected amount here. Hopefully this will only ever execute once. public static bool Prefix(PlayerMoveController __instance) { if (__instance.playerInput.InventoryActions.Count == 9) { SphereII_PlayerMoveController_Logger.Log("Player Action is 9. Adding Additional Slots"); PlayerActionsLocal temp = __instance.playerInput; temp.InventorySlot10 = temp.CreatePlayerAction("Inventory10"); temp.InventorySlot10.UserData = new PlayerActionsBase.ActionUserData("inpActInventorySlot9Name", null, PlayerActionsBase.GroupToolbelt, PlayerActionsBase.EAppliesToInputType.KbdMouseOnly, true); temp.InventorySlot11 = temp.CreatePlayerAction("Inventory11"); temp.InventorySlot11.UserData = new PlayerActionsBase.ActionUserData("inpActInventorySlot10Name", null, PlayerActionsBase.GroupToolbelt, PlayerActionsBase.EAppliesToInputType.KbdMouseOnly, true); temp.InventoryActions.Add(temp.InventorySlot10); temp.InventoryActions.Add(temp.InventorySlot11); temp.InventorySlot10.AddDefaultBinding(new InControl.Key[] { InControl.Key.Key0 }); } return(true); }