Peuri said: Is it possible to replace a segment of a method or an entire method with Harmony? Click to expand...

C#: private static IEnumerable<CodeInstruction> GetAttackCollisionResultsTranspiler(IEnumerable<CodeInstruction> instructions) { // This is the list of instructions I want to insert. List<CodeInstruction> MyLittlePoney = new List<CodeInstruction> { new CodeInstruction(OpCodes.Ldarga_S, 5), new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(Blow), nameof(Blow.InflictedDamage))), new CodeInstruction(OpCodes.Conv_R8), new CodeInstruction(OpCodes.Ldsfld, AccessTools.DeclaredField(typeof(SettingsManager), nameof(_settings))), new CodeInstruction(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(Settings), nameof(_settings.Charge))), new CodeInstruction(OpCodes.Callvirt, AccessTools.DeclaredPropertyGetter(typeof(Settings.ChargeConfig), nameof(_settings.Charge.Charge_Damage_Multiplier))), new CodeInstruction(OpCodes.Mul), new CodeInstruction(OpCodes.Conv_I4), new CodeInstruction(OpCodes.Stfld, AccessTools.DeclaredField(typeof(Blow), nameof(Blow.InflictedDamage))) }; List<CodeInstruction> currentInstructions = instructions.ToList(); List<CodeInstruction> newInstructions = new List<CodeInstruction>(instructions.Count() + MyLittlePoney.Count()); CodeInstruction currentInstruction; // I'm looking for a very specific pattern where to insert my instructions. for (int i = 0; i < currentInstructions.Count; i++) { currentInstruction = currentInstructions[i]; if (currentInstruction.opcode == OpCodes.Ldind_Ref) { CodeInstruction previousInstruction = currentInstructions[i - 1]; if (previousInstruction.opcode == OpCodes.Ldarg_S && previousInstruction.operand == typeof(WeaponComponentData)) { newInstructions.AddRange(MyLittlePoney); } } // I'm adding back all read instructions since I'm not removing anything. newInstructions.Add(currentInstruction); } return newInstructions; }

With what they call a transpiler, yes, but you'll have to learn about CIL . However dealing with stack-based languages is messy and I wouldn't recommend it. You should be able to do pretty much everything you want with prefixes and postfixes, even if it means letting the original code run.But here's a short example of what it could look like. I'm simply multiplying two values.If you did something wrong, at best it breaks when patching. Otherwise, well you can't really put any break point so...