Advertisement
Guest User

Untitled

a guest
Mar 20th, 2016
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. using Mono.Cecil;
  2. using System;
  3. using Mono.Cecil.Cil;
  4.  
  5. namespace AssemblyPather
  6. {
  7. class Program
  8. {
  9. #pragma warning disable 0618
  10. static void Main(string[] args)
  11. {
  12.  
  13. ModuleDefinition module = null;
  14. Console.WriteLine("Loading...");
  15. try
  16. {
  17. module = ModuleDefinition.ReadModule("../../AssemblyPather.exe");
  18. }
  19. catch
  20. {
  21. Console.WriteLine("Cant find assembly.");
  22. return;
  23. }
  24. try
  25. {
  26. TypeDefinition type = type = new TypeDefinition("AssemblyPather","Injected",TypeAttributes.Public,module.Import(typeof(UnityEngine.MonoBehaviour)));
  27. module.Types.Add(type);
  28. var method = new MethodDefinition("OnGUI",MethodAttributes.Public ,module.Import(typeof(void)));
  29.  
  30. //Instruction 1
  31. Instruction IL1 = method.Body.GetILProcessor().Create(OpCodes.Ldc_I4_S, 105);
  32. method.Body.GetILProcessor().InsertAfter(method.Body.Instructions[0], IL1);
  33.  
  34. //Instruction 2
  35. Instruction IL2 = method.Body.GetILProcessor().Create(OpCodes.Call,UnityEngine.Input.GetKeyDown);
  36. method.Body.GetILProcessor().InsertAfter(method.Body.Instructions[1], IL2);
  37.  
  38. //Add the method
  39. type.Methods.Add(method);
  40. //method.Parameters.Add(new ParameterDefinition(module.Import(typeof(string))));
  41. Console.WriteLine("Assembly has been patched!");
  42. module.Write("../../Assembly.exe");
  43. }
  44. catch(Exception e)
  45. {
  46. Console.WriteLine("ERROR: "+e.ToString());
  47. }
  48.  
  49. Console.ReadLine();
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement