12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using Mono.Cecil;
- using Mono.Cecil.Cil;
- namespace SuppressTransformDestroy.Patcher
- {
- public static class FixDestroyImmediatePatcher
- {
- public static string[] TargetAssemblyNames = {"UnityEngine.dll"};
- public static void Patch(AssemblyDefinition def)
- {
-
- AssemblyDefinition hooksAd;
- try
- {
- hooksAd = AssemblyDefinition.ReadAssembly(Path.Combine(
- Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SuppressTransformDestroy.Managed.dll"));
- }
- catch (Exception)
- {
- return;
- }
- var hooksTd = hooksAd.MainModule.GetType("SuppressTransformDestroy.Managed.DestroyFixer");
- var destroyImmediateHook = hooksTd.Methods.FirstOrDefault(m => m.Name == "DestroyCustomImmediate");
- var md = def.MainModule;
- var objTd = md.GetType("UnityEngine.Object");
- var destroyImmediate =
- objTd.Methods.FirstOrDefault(m => m.Name == "DestroyImmediate" && m.Parameters.Count == 1);
- if (destroyImmediate == null)
- return;
- var il = destroyImmediate.Body.GetILProcessor();
- var ins = destroyImmediate.Body.Instructions[0];
- il.InsertBefore(ins, il.Create(OpCodes.Ldarga, destroyImmediate.Parameters[0]));
- il.InsertBefore(ins, il.Create(OpCodes.Call, md.ImportReference(destroyImmediateHook)));
- }
- }
- }
|