该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
贴吧发代码真够作死的。。。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections;
using UnityEngine;
public class Injection
{
public static void Main(string[] args)
{
AssemblyDefinition assembiy = AssemblyDefinition.ReadAssembly(@"D:\games\Unity Projects\xxxxxx\Library\ScriptAssemblies\Assembly-CSharp.dll");
foreach (Mono.Cecil.TypeDefinition item in assembiy.MainModule.Types)
{
foreach (MethodDefinition method in item.Methods)
{
if (method.Name.Equals("Main"))
{
Debug.Log("main");
var ins = method.Body.Instructions[0];
var worker = method.Body.GetILProcessor ();
//worker.InsertBefore(ins, worker.Create(OpCodes.Ldstr, "Method start…"));
worker.InsertBefore(ins, worker.Create(OpCodes.Call,
assembiy.MainModule.ImportReference(typeof(Global).GetMethod("DoSomeThing"))));
break;
}
}
}
AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition("",new Version()),@"D:\games\Unity Projects\xxxxx\Library\ScriptAssemblies\Assembly-CSharp.dll",ModuleKind.Console);
}
}
Global 是我的类,里面有个void DoSomeThing();这个作死的main被GLOBAL的一个函数引用,这函数被Load什么什么attribute就是在场景加载前运行那个标识,能够正常接入。