Guest User

Untitled

a guest
Sep 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.Reflection;
  7. using System.Reflection.Emit;
  8. using System.Runtime.InteropServices;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11.  
  12. namespace ConsoleApp10
  13. {
  14. class Program
  15. {
  16. // mouse_event
  17. public delegate bool mouse_event(uint dwFlags, int dx, int dy, uint dwData, UIntPtr dwExtraInfo);
  18. public static mouse_event Mouse_Event_Delegate;
  19.  
  20. // GetAsyncKeyState
  21. public delegate ushort get_async_keystate(int vKey);
  22. public static get_async_keystate GetAsyncKeyState_Delegate;
  23.  
  24. // setcursorpos
  25. public delegate long setcursorpos(int x, int y);
  26. public static setcursorpos Set_Cursor_pos;
  27.  
  28.  
  29. static void Main(string[] args)
  30. {
  31. Mouse_Event_Delegate = CreateAPI<mouse_event>("user32.dll", "mouse_event"); //Cast the Delegate
  32.  
  33. GetAsyncKeyState_Delegate =
  34. CreateAPI<get_async_keystate>("user32.dll", "GetAsyncKeyState"); //Cast the Delegate
  35.  
  36. Set_Cursor_pos =
  37. CreateAPI<setcursorpos>("user32.dll", "SetCursorPos"); //Cast the Delegate
  38.  
  39. bool cycleDone = false;
  40. Point p1 = new Point();
  41.  
  42. if (Mouse_Event_Delegate != null
  43. && GetAsyncKeyState_Delegate != null
  44. && Set_Cursor_pos != null)
  45. {
  46. // supposedly populate this array with the relative offsets to mousemovement to counter the recoil of
  47. // the AK or any other weapon, gotta find these offsets
  48.  
  49. int[] recoil_offsets = { 10, 10 };
  50. int stepCount = recoil_offsets.Length;
  51.  
  52. while (true)
  53. {
  54. if (IsDown() && !cycleDone)
  55. {
  56. // Get initial position
  57. p1.X = Cursor.Position.X * 65535 / Screen.PrimaryScreen.Bounds.Width;
  58. p1.Y = Cursor.Position.Y * 65535 / Screen.PrimaryScreen.Bounds.Height;
  59.  
  60. for (int i = 0; i <= stepCount - 1; i++)
  61. {
  62. // Get new position after mouse mouve
  63. p1.X = Cursor.Position.X * 65535 / Screen.PrimaryScreen.Bounds.Width;
  64. p1.Y = Cursor.Position.Y * 65535 / Screen.PrimaryScreen.Bounds.Height;
  65.  
  66. // SetCursorPos
  67. Set_Cursor_pos(p1.X - recoil_offsets[i], p1.Y - recoil_offsets[i]);
  68. }
  69.  
  70. cycleDone = true;
  71. }
  72. else
  73. {
  74. if (p1.X != -1 || p1.Y != -1)
  75. {
  76. p1.X = -1;
  77. p1.Y = -1;
  78. }
  79.  
  80. if (!cycleDone) cycleDone = false;
  81. Thread.Sleep(10);
  82. }
  83. }
  84. }
  85. else
  86. {
  87. Debug.WriteLine("[ERR] Could not create delegate(s)");
  88. }
  89. }
  90.  
  91. public static bool IsDown()
  92. {
  93. return 0 != (GetAsyncKeyState_Delegate((int) Keys.LButton) & 0x8000);
  94. }
  95.  
  96. public static T CreateAPI<T>(string wLib, string mName)
  97. {
  98. AssemblyBuilder ASMB =
  99. AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(Assembly.GetExecutingAssembly().FullName),
  100. AssemblyBuilderAccess.RunAndSave);
  101. ModuleBuilder MODB = ASMB.DefineDynamicModule(MethodBase.GetCurrentMethod().Name);
  102. TypeBuilder TB = MODB.DefineType(MethodBase.GetCurrentMethod().DeclaringType.Name, TypeAttributes.Public);
  103. MethodInfo MI = typeof(T).GetMethods()[0];
  104. List<Type> LP = new List<Type>();
  105.  
  106. foreach (ParameterInfo pI in MI.GetParameters())
  107. LP.Add(pI.ParameterType);
  108.  
  109. MethodBuilder MB = TB.DefinePInvokeMethod(mName,
  110. wLib,
  111. MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.PinvokeImpl,
  112. CallingConventions.Standard,
  113. MI.ReturnType, LP.ToArray(),
  114. CallingConvention.Winapi,
  115. CharSet.Ansi);
  116.  
  117. MB.SetImplementationFlags(MB.GetMethodImplementationFlags() | MethodImplAttributes.PreserveSig);
  118.  
  119. return Conversions.ToGenericParameter<T>(Delegate.CreateDelegate(typeof(T), TB.CreateType().GetMethod(mName)));
  120. }
  121. }
  122. }
Add Comment
Please, Sign In to add comment