Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualBasic.CompilerServices;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Windows.Forms;
- namespace ConsoleApp10
- {
- class Program
- {
- // mouse_event
- public delegate bool mouse_event(uint dwFlags, int dx, int dy, uint dwData, UIntPtr dwExtraInfo);
- public static mouse_event Mouse_Event_Delegate;
- // GetAsyncKeyState
- public delegate ushort get_async_keystate(int vKey);
- public static get_async_keystate GetAsyncKeyState_Delegate;
- // setcursorpos
- public delegate long setcursorpos(int x, int y);
- public static setcursorpos Set_Cursor_pos;
- static void Main(string[] args)
- {
- Mouse_Event_Delegate = CreateAPI<mouse_event>("user32.dll", "mouse_event"); //Cast the Delegate
- GetAsyncKeyState_Delegate =
- CreateAPI<get_async_keystate>("user32.dll", "GetAsyncKeyState"); //Cast the Delegate
- Set_Cursor_pos =
- CreateAPI<setcursorpos>("user32.dll", "SetCursorPos"); //Cast the Delegate
- bool cycleDone = false;
- Point p1 = new Point();
- if (Mouse_Event_Delegate != null
- && GetAsyncKeyState_Delegate != null
- && Set_Cursor_pos != null)
- {
- // supposedly populate this array with the relative offsets to mousemovement to counter the recoil of
- // the AK or any other weapon, gotta find these offsets
- int[] recoil_offsets = { 10, 10 };
- int stepCount = recoil_offsets.Length;
- while (true)
- {
- if (IsDown() && !cycleDone)
- {
- // Get initial position
- p1.X = Cursor.Position.X * 65535 / Screen.PrimaryScreen.Bounds.Width;
- p1.Y = Cursor.Position.Y * 65535 / Screen.PrimaryScreen.Bounds.Height;
- for (int i = 0; i <= stepCount - 1; i++)
- {
- // Get new position after mouse mouve
- p1.X = Cursor.Position.X * 65535 / Screen.PrimaryScreen.Bounds.Width;
- p1.Y = Cursor.Position.Y * 65535 / Screen.PrimaryScreen.Bounds.Height;
- // SetCursorPos
- Set_Cursor_pos(p1.X - recoil_offsets[i], p1.Y - recoil_offsets[i]);
- }
- cycleDone = true;
- }
- else
- {
- if (p1.X != -1 || p1.Y != -1)
- {
- p1.X = -1;
- p1.Y = -1;
- }
- if (!cycleDone) cycleDone = false;
- Thread.Sleep(10);
- }
- }
- }
- else
- {
- Debug.WriteLine("[ERR] Could not create delegate(s)");
- }
- }
- public static bool IsDown()
- {
- return 0 != (GetAsyncKeyState_Delegate((int) Keys.LButton) & 0x8000);
- }
- public static T CreateAPI<T>(string wLib, string mName)
- {
- AssemblyBuilder ASMB =
- AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(Assembly.GetExecutingAssembly().FullName),
- AssemblyBuilderAccess.RunAndSave);
- ModuleBuilder MODB = ASMB.DefineDynamicModule(MethodBase.GetCurrentMethod().Name);
- TypeBuilder TB = MODB.DefineType(MethodBase.GetCurrentMethod().DeclaringType.Name, TypeAttributes.Public);
- MethodInfo MI = typeof(T).GetMethods()[0];
- List<Type> LP = new List<Type>();
- foreach (ParameterInfo pI in MI.GetParameters())
- LP.Add(pI.ParameterType);
- MethodBuilder MB = TB.DefinePInvokeMethod(mName,
- wLib,
- MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.PinvokeImpl,
- CallingConventions.Standard,
- MI.ReturnType, LP.ToArray(),
- CallingConvention.Winapi,
- CharSet.Ansi);
- MB.SetImplementationFlags(MB.GetMethodImplementationFlags() | MethodImplAttributes.PreserveSig);
- return Conversions.ToGenericParameter<T>(Delegate.CreateDelegate(typeof(T), TB.CreateType().GetMethod(mName)));
- }
- }
- }
Add Comment
Please, Sign In to add comment