using System;
using Mono.Cecil;
public class Application
{
static MethodDefinition Extract (AssemblyDefinition asm, string type, string func)
{
var mod = asm.MainModule;
if (mod == null) return null;
var existingType = mod.GetType(type);
if (existingType == null) return null;
var methods = existingType.Methods;
foreach (var method in methods)
{
if (method.Name == func)
{
return method;
}
}
return null;
}
static bool Replace (AssemblyDefinition original, AssemblyDefinition replacement, string type, string func)
{
var method0 = Extract(original, type, func);
var method1 = Extract(replacement, type, func);
if (method0 != null && method1 != null)
{
method0.Body = method1.Body;
Console.WriteLine("Replaced " + type + "." + func);
return true;
}
Console.WriteLine("Unable to replace " + type + "." + func);
return false;
}
static int Main (string[] args)
{
var dll0 = "C:/Projects/FixUnityEngine/UnityEngine.dll";
var dll1 = "C:/Projects/FixUnityEngine/FixUnityEngine.dll";
var asm0 = AssemblyDefinition.ReadAssembly(dll0);
var asm1 = AssemblyDefinition.ReadAssembly(dll1);
Replace(asm0, asm1, "UnityEngine.AttributeHelperEngine", "GetParentTypeDisallowingMultipleInclusion");
Replace(asm0, asm1, "UnityEngine.AttributeHelperEngine", "GetRequiredComponents");
asm0.Write("C:/Projects/FixUnityEngine/UnityEngine_edited.dll");
Console.ReadKey();
return 0;
}
}