Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Mono.Cecil;
- using System;
- using Mono.Cecil.Cil;
- namespace AssemblyPather
- {
- class Program
- {
- #pragma warning disable 0618
- static void Main(string[] args)
- {
- ModuleDefinition module = null;
- Console.WriteLine("Loading...");
- try
- {
- module = ModuleDefinition.ReadModule("../../AssemblyPather.exe");
- }
- catch
- {
- Console.WriteLine("Cant find assembly.");
- return;
- }
- try
- {
- TypeDefinition type = type = new TypeDefinition("AssemblyPather","Injected",TypeAttributes.Public,module.Import(typeof(UnityEngine.MonoBehaviour)));
- module.Types.Add(type);
- var method = new MethodDefinition("OnGUI",MethodAttributes.Public ,module.Import(typeof(void)));
- //Instruction 1
- Instruction IL1 = method.Body.GetILProcessor().Create(OpCodes.Ldc_I4_S, 105);
- method.Body.GetILProcessor().InsertAfter(method.Body.Instructions[0], IL1);
- //Instruction 2
- Instruction IL2 = method.Body.GetILProcessor().Create(OpCodes.Call,UnityEngine.Input.GetKeyDown);
- method.Body.GetILProcessor().InsertAfter(method.Body.Instructions[1], IL2);
- //Add the method
- type.Methods.Add(method);
- //method.Parameters.Add(new ParameterDefinition(module.Import(typeof(string))));
- Console.WriteLine("Assembly has been patched!");
- module.Write("../../Assembly.exe");
- }
- catch(Exception e)
- {
- Console.WriteLine("ERROR: "+e.ToString());
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement