Program.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Runtime.CompilerServices;
  7. using System.Text;
  8. using XUnity.RuntimeHooker.Core;
  9. using XUnity.RuntimeHooker.Core.Utilities;
  10. namespace XUnity.RuntimeHooker.ConsoleTests
  11. {
  12. class Program
  13. {
  14. static void Main( string[] args )
  15. {
  16. //var sayHello = typeof( Program ).GetMethod( "SayHello" );
  17. //var sayGoodbye = typeof( Program ).GetMethod( "SayGoodbye" );
  18. //RuntimeMethodPatcher.Patch( sayHello, new HookMethod( sayGoodbye ), null );
  19. //SayHello();
  20. //var textComponent = new TextComponent();
  21. //textComponent.Text = "こんにちは";
  22. //var textGetter = typeof( TextComponent ).GetProperty( "Text" ).GetGetMethod();
  23. //var textGetterHook = typeof( Program ).GetMethod( "TextGetterHook" );
  24. //RuntimeMethodPatcher.Patch( textGetter, null, new HookMethod( textGetterHook ) );
  25. //Console.WriteLine( textComponent.Text );
  26. //var printValue = typeof( Program ).GetMethod( "PrintValue" );
  27. //var printValueHook = typeof( Program ).GetMethod( "PrintValueHook" );
  28. //RuntimeMethodPatcher.Patch( printValue, new HookMethod( printValueHook ), null );
  29. //PrintValue( 7331 );
  30. }
  31. [MethodImpl( MethodImplOptions.NoInlining )]
  32. public static void SayHello()
  33. {
  34. Console.WriteLine( "Hello" );
  35. }
  36. public static bool SayGoodbye()
  37. {
  38. Console.WriteLine( "Goodbye" );
  39. return false;
  40. }
  41. public static void TextGetterHook( ref string __result, TextComponent __instance )
  42. {
  43. Console.WriteLine( "Instance: " + __instance );
  44. __result = "Hello there!";
  45. }
  46. [MethodImpl( MethodImplOptions.NoInlining )]
  47. public static void PrintValue( int i )
  48. {
  49. Console.WriteLine( i );
  50. }
  51. public static void PrintValueHook( ref int i )
  52. {
  53. i = 1337;
  54. }
  55. }
  56. public class TextComponent
  57. {
  58. public string Text { [MethodImpl( MethodImplOptions.NoInlining )]get; set; }
  59. }
  60. }