private static IEnumerable <CodeInstruction> OnEventPatcher(ILGenerator ilg, IEnumerable <CodeInstruction> instructions) { if (instructions.Count() != 923) { VRCModLogger.Log("[RamExploitPatcher] NetworkingPeer.OnEvent seems to have been modified. Patch disabled to avoid weird bugs."); return(instructions); } CodeInstruction[] newInst = new CodeInstruction[instructions.Count() + 4]; int offset = 0; bool done = false; for (int i = 0; i < newInst.Length - 4; i++) { CodeInstruction instruction = instructions.ElementAt(i); //VRCModLogger.Log("[RamExploitPatcher] Instruction " + i + ": " + instruction); if (instruction.opcode == OpCodes.Ldc_I4_M1 && !done) { done = true; VRCModLogger.Log("[RamExploitPatcher] Injecting instructions to list"); CodeInstruction ci1 = new CodeInstruction(OpCodes.Ldarg_1); ci1.labels.Add(instruction.labels[0]); newInst[i + (offset++)] = ci1; newInst[i + (offset++)] = new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(RamExploitPatcher), "PhotonOnEvent")); Label label = ilg.DefineLabel(); newInst[i + (offset++)] = new CodeInstruction(OpCodes.Brtrue_S, label); instruction.labels.Remove(instruction.labels[0]); instruction.labels.Add(label); newInst[i + (offset++)] = new CodeInstruction(OpCodes.Ret); VRCModLogger.Log("[RamExploitPatcher] Injection done !"); } newInst[i + offset] = instruction; } /* * VRCModLogger.Log("[RamExploitPatcher] Done. Patched IL:"); * foreach(CodeInstruction instruction in newInst) * VRCModLogger.Log("[RamExploitPatcher] | " + instruction); */ return(newInst.AsEnumerable()); }