Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
1,639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 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 %ConsoleApp%
  13. {
  14.     class %Program%
  15.     {
  16.         public delegate bool %MOUSE_DELG%(uint %dwFlags%, int %dx%, int %dy%, uint %dwData%, UIntPtr %dwExtraInfo%);
  17.         public static %MOUSE_DELG% %MOUSE%;
  18.  
  19.         public delegate ushort %ASYNC_KEY_DELG%(int %vKey%);
  20.         public static %ASYNC_KEY_DELG% %ASYNC_KEY%;
  21.  
  22.         static void Main(string[] args)
  23.         {
  24.             %MOUSE% = %CreateAPI%<%MOUSE_DELG%>("user32.dll", "mouse_event"); //Cast the Delegate
  25.             %ASYNC_KEY% =
  26.                 %CreateAPI%<%ASYNC_KEY_DELG%>("user32.dll", "GetAsyncKeyState"); //Cast the Delegate
  27.  
  28.             bool %cycleDone% = false;
  29.             Point %p1% = new Point();
  30.  
  31.             if (%MOUSE% != null
  32.                 && %ASYNC_KEY% != null )
  33.             {
  34.  
  35.                 int %fireRate% = 1000 / (450 / 60);
  36.  
  37.                 int[] %xRecoil% = { 40, 48, 48, 48, 33, 33, 28, 24, 16, 13, 18, 22, 24, 29, 33, 33, 33, 29, 22, 20, 17, 17, 17, 17, 20, 27, 27, 27, 26 };
  38.                 int[] %yRecoil% = { -36, 5, -59, -49, 3, 20, 25, 45, 43, 32, 82, 8, 43, -32, -25, -40, -35, -32, -43, -42, -42, -55, -25, 15, 20, 35, 50, 62, 40 };
  39.  
  40.                 int %mouseXNext% = 0;
  41.                 int %mouseYNext% = 0;
  42.  
  43.                 while (true)
  44.                 {
  45.                     if (%IsDown%() && %cycleDone% != true)
  46.                     {
  47.  
  48.                         for (int %i% = 0; %i% < %xRecoil%.Length -1; %i%++)
  49.                         {
  50.                             %mouseXNext% = Cursor.Position.X - %xRecoil%[%i%];
  51.                             %mouseYNext% = Cursor.Position.Y - %yRecoil%[%i%];
  52.  
  53.                             %MOUSE%(0x0001, %mouseXNext%, %mouseYNext%, 0, UIntPtr.Zero);
  54.                             Thread.Sleep(%fireRate%);
  55.                         }
  56.  
  57.                         %cycleDone% = true;
  58.                     }
  59.                     else
  60.                     {
  61.                         if (%p1%.X != -1 || %p1%.Y != -1)
  62.                         {
  63.                             %p1%.X = -1;
  64.                             %p1%.Y = -1;
  65.                         }
  66.  
  67.                         if (!%cycleDone%) %cycleDone% = false;
  68.                         Thread.Sleep(1);
  69.                     }
  70.                 }
  71.             }
  72.             else
  73.             {
  74.                 Debug.WriteLine("[ERR] Could not create delegate(s)");
  75.             }
  76.         }
  77.  
  78.         public static bool %IsDown%()
  79.         {
  80.             return 0 != (%ASYNC_KEY%((int) Keys.LButton) & 0x8000);
  81.         }
  82.  
  83.         public static T %CreateAPI%<T>(string %wLib%, string %mName%)
  84.         {
  85.             AssemblyBuilder ASMB =
  86.                 AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(Assembly.GetExecutingAssembly().FullName),
  87.                     AssemblyBuilderAccess.RunAndSave);
  88.             ModuleBuilder MODB = ASMB.DefineDynamicModule(MethodBase.GetCurrentMethod().Name);
  89.             TypeBuilder TB = MODB.DefineType(MethodBase.GetCurrentMethod().DeclaringType.Name, TypeAttributes.Public);
  90.             MethodInfo MI = typeof(T).GetMethods()[0];
  91.             List<Type> LP = new List<Type>();
  92.  
  93.             foreach (ParameterInfo pI in MI.GetParameters())
  94.                 LP.Add(pI.ParameterType);
  95.  
  96.             MethodBuilder MB = TB.DefinePInvokeMethod(%mName%,
  97.                 %wLib%,
  98.                 MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.PinvokeImpl,
  99.                 CallingConventions.Standard,
  100.                 MI.ReturnType, LP.ToArray(),
  101.                 CallingConvention.Winapi,
  102.                 CharSet.Ansi);
  103.  
  104.             MB.SetImplementationFlags(MB.GetMethodImplementationFlags() | MethodImplAttributes.PreserveSig);
  105.  
  106.             return Conversions.ToGenericParameter<T>(Delegate.CreateDelegate(typeof(T), TB.CreateType().GetMethod(%mName%)));
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement