public static void Patch(ModuleDefinition module, List <string> log) { var fn = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "GameLocation"), "checkAction"); int spot = IL.ScanForOpcodePattern(fn, (i, instruction) => { var reference = fn.Body.Instructions[i + 3].Operand as FieldReference; return(reference != null && reference.Name == "haltAfterCheck"); }, OpCodes.Ldarg_3, OpCodes.Callvirt, OpCodes.Ldc_I4_0, OpCodes.Stsfld ); if (spot == -1) { log.Add("Can't find patch location!"); return; } spot += 4; var callType = module.ImportReference(typeof(dotNetMT.EasyPlant)).Resolve(); var callMethod = module.ImportReference(IL.GetMethodDefinition(callType, "ProcessPlant")); IL.MethodAppend(fn, spot, 0, new[] { Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "tileLocation")), Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "who")), Instruction.Create(OpCodes.Call, callMethod), }); }
public static void PathOnUpdateControlInput(ModuleDefinition module, List <string> log) { var fn = IL.GetMethodDefinition(module, "Game1", "UpdateControlInput"); if (fn == null) { log.Add("Can't find target method!"); return; } int spot = IL.ScanForOpcodePattern(fn, (i, instruction) => { var reference = fn.Body.Instructions[i + 2].Operand as MethodReference; return(reference != null && reference.Name == "checkForRunButton"); }, OpCodes.Ldloc_0, OpCodes.Ldc_I4_0, OpCodes.Call ); if (spot == -1) { log.Add("Can't find patch location!"); return; } spot += 3; var callType = module.ImportReference(typeof(dotNetMT.EventRouter)).Resolve(); var callMethod = module.ImportReference(IL.GetMethodDefinition(callType, "OnUpdateControlInput")); IL.MethodAppend(fn, spot, 0, new[] { Instruction.Create(OpCodes.Call, callMethod), }); }
public static void PatchBuffUpdate(ModuleDefinition module, List <string> log) { var target = IL.GetMethodDefinition(module, "Buff", "update"); if (target == null) { log.Add("Can't find target method!"); return; } int spot = IL.ScanForOpcodePattern(target, (i, instruction) => { var reference = target.Body.Instructions[i + 0].Operand as FieldReference; return(reference != null && reference.Name == "millisecondsDuration"); }, OpCodes.Ldfld, OpCodes.Ldc_I4_0, OpCodes.Bgt_S, OpCodes.Ldc_I4_1, OpCodes.Ret ); if (spot == -1) { log.Add("Can't find patch location!"); return; } var type = module.ImportReference(MethodBase.GetCurrentMethod().DeclaringType).Resolve(); // typeof(dotNetMT.EasyPlant) var method = module.ImportReference(IL.GetMethodDefinition(type, "PlayNotifySound")); IL.MethodAppend(target, spot + 3, 0, new[] { Instruction.Create(OpCodes.Call, method) }); }
public static void PatchFishingRodDoneFishing(ModuleDefinition module, List <string> log) { var target = IL.GetMethodDefinition(module, "FishingRod", "doneFishing"); if (target == null) { log.Add("Can't find target method!"); return; } var type = module.ImportReference(MethodBase.GetCurrentMethod().DeclaringType).Resolve(); // typeof(dotNetMT.EasyPlant) var method = module.ImportReference(IL.GetMethodDefinition(type, "PlayNotifySound")); int spot; spot = IL.ScanForOpcodePattern(target, (i, instruction) => { var reference = target.Body.Instructions[i + 1].Operand as FieldReference; return(reference != null && reference.Name == "attachments"); }, OpCodes.Ldarg_0, OpCodes.Ldfld, OpCodes.Ldc_I4_0, OpCodes.Ldnull ); if (spot == -1) { log.Add("Can't find patch location!"); return; } IL.MethodAppend(target, spot + 0, 0, new[] { Instruction.Create(OpCodes.Call, method) }); spot = IL.ScanForOpcodePattern(target, (i, instruction) => { var reference = target.Body.Instructions[i + 1].Operand as FieldReference; return(reference != null && reference.Name == "attachments"); }, OpCodes.Ldarg_0, OpCodes.Ldfld, OpCodes.Ldc_I4_1, OpCodes.Ldnull ); if (spot == -1) { log.Add("Can't find patch location!"); return; } IL.MethodAppend(target, spot + 0, 0, new[] { Instruction.Create(OpCodes.Call, method) }); }
public static void Patch(ModuleDefinition module, List <string> log) { var player = IL.GetTypeDefinition(module, "Player"); var updatePlayerEquips = IL.GetMethodDefinition(player, "UpdateEquips"); var wings = IL.GetFieldDefinition(player, "wings"); var wingsLogic = IL.GetFieldDefinition(player, "wingsLogic"); var wingTimeMax = IL.GetFieldDefinition(player, "wingTimeMax"); IL.MethodAppend(updatePlayerEquips, updatePlayerEquips.Body.Instructions.Count - 1, 1, new[] { Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Ldc_I4, 32), Instruction.Create(OpCodes.Stfld, wings), Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Ldc_I4, 32), Instruction.Create(OpCodes.Stfld, wingsLogic), Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Ldc_I4, int.MaxValue), Instruction.Create(OpCodes.Stfld, wingTimeMax), Instruction.Create(OpCodes.Ret) }); }
public static void Patch(ModuleDefinition module, List <string> log) { var target = IL.GetMethodDefinition(module, "GeodeMenu", "receiveLeftClick"); if (target == null) { log.Add("Can't find target method!"); return; } // --- int spot = IL.ScanForOpcodePattern(target, (i, instruction) => { var reference = target.Body.Instructions[i + 3].Operand as FieldReference; return(reference != null && reference.Name == "clint"); }, OpCodes.Callvirt, OpCodes.Callvirt, OpCodes.Ldarg_0, OpCodes.Ldfld ); if (spot == -1) { log.Add("Can't find patch location!"); return; } // --- var type = module.ImportReference(MethodBase.GetCurrentMethod().DeclaringType).Resolve(); // typeof(dotNetMT.EasyPlant) var method = module.ImportReference(IL.GetMethodDefinition(type, "Adjust")); IL.MethodAppend(target, spot + 1, 0, new[] { Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Call, method), }); }
public static void Patch(ModuleDefinition module, List <string> log) { var fn = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "Crop"), ".ctor", 3); int spot = IL.ScanForOpcodePattern(fn, (i, instruction) => { var fieldReference = fn.Body.Instructions[i + 2].Operand as FieldReference; return(fieldReference != null && fieldReference.Name == "harvestMethod"); }, OpCodes.Ldelem_Ref, OpCodes.Call, OpCodes.Stfld ); if (spot == -1) { log.Add("Can't find patch location!"); return; } //spot -= 2; //fn.Body.Instructions[spot + 0].OpCode = OpCodes.Nop; //fn.Body.Instructions[spot + 1].OpCode = OpCodes.Ldc_I4_1; //fn.Body.Instructions[spot + 2].OpCode = OpCodes.Nop; //fn.Body.Instructions[spot + 3].OpCode = OpCodes.Nop; spot += 2; var callType = module.ImportReference(typeof(dotNetMT.ScytheHarvest)).Resolve(); var callMethod = module.ImportReference(IL.GetMethodDefinition(callType, "AdjustHarvestMethod")); IL.MethodAppend(fn, spot, 0, new[] { Instruction.Create(OpCodes.Ldarg_1), Instruction.Create(OpCodes.Call, callMethod), }); // --- fn = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "Crop"), "harvest"); spot = IL.ScanForOpcodePattern(fn, (i, instruction) => { var fieldReference = fn.Body.Instructions[i + 1].Operand as FieldReference; return(fieldReference != null && fieldReference.Name == "harvestMethod"); }, OpCodes.Ldarg_0, OpCodes.Ldfld, OpCodes.Ldc_I4_1, OpCodes.Bne_Un ); if (spot == -1) { log.Add("Can't find patch location!"); return; } spot += 4; callMethod = module.ImportReference(IL.GetMethodDefinition(callType, "ProcessScytheHarvest")); IL.MethodAppend(fn, spot, 0, new[] { Instruction.Create(OpCodes.Ldarg_0), Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "xTile")), Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "yTile")), //Instruction.Create(OpCodes.Ldloc_S, fn.Body.Variables[4]), Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "soil")), Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "junimoHarvester")), Instruction.Create(OpCodes.Call, callMethod), //Instruction.Create(OpCodes.Stloc_S, fn.Body.Variables[4]), }); // --- }