Advertisement
Guest User

osu!Tapspeed by DaRealSlimOni v.1.2

a guest
Oct 4th, 2014
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.22 KB | None | 0 0
  1. // Version 1.2
  2.  
  3. using System;
  4. using System.Diagnostics;
  5. using System.Threading;
  6. using System.Windows.Forms;
  7. using System.Runtime.InteropServices;
  8.  
  9. namespace osu_Tapspeed
  10. {
  11.     class Program
  12.     {
  13.         private const int WH_KEYBOARD_LL = 13;
  14.         private const int WM_KEYDOWN = 0x0100;
  15.         private const int WH_MOUSE_LL = 14;
  16.         private const int WM_LBUTTONDOWN = 0x0201;
  17.         private const int WM_RBUTTONDOWN = 0x0204;
  18.         private static LowLevelProc _procK = HookCallbackK;
  19.         private static LowLevelProc _procM = HookCallbackM;
  20.         private static IntPtr _hookIDK = IntPtr.Zero;
  21.         private static IntPtr _hookIDM = IntPtr.Zero;
  22.         private static Stopwatch stopwatch = new Stopwatch();
  23.         private static ConsoleKeyInfo hk1;
  24.         private static ConsoleKeyInfo hk2;
  25.         private static int taps;
  26.         private static int taps_count;
  27.         private static bool start;
  28.         private static bool first = true;
  29.         private static bool setkeys;
  30.  
  31.         #region Imports
  32.         public delegate IntPtr LowLevelProc(int nCode, IntPtr wParam, IntPtr lParam);
  33.  
  34.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  35.         public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc lpfn, IntPtr hMod, uint dwThreadId);
  36.  
  37.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  38.         public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
  39.  
  40.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  41.         [return: MarshalAs(UnmanagedType.Bool)]
  42.         public static extern bool UnhookWindowsHookEx(IntPtr hhk);
  43.  
  44.         [DllImport("kernel32.dll", SetLastError = true)]
  45.         public static extern IntPtr GetModuleHandle(string lpModuleName);
  46.         #endregion
  47.  
  48.         private static IntPtr HookCallbackK(int nCode, IntPtr wParam, IntPtr lParam)
  49.         {
  50.             try
  51.             {
  52.                 if (nCode >= 0)
  53.                 {
  54.                     if ((int) wParam == WM_KEYDOWN)
  55.                     {
  56.                         if (start)
  57.                         {
  58.                             int vkCode = Marshal.ReadInt32(lParam);
  59.                             //Debug.WriteLine("vkCode: " + vkCode);
  60.                             if (vkCode == (int) hk1.Key || vkCode == (int) hk2.Key)
  61.                             {
  62.                                 if (first)
  63.                                 {
  64.                                     stopwatch.Start();
  65.                                     first = false;
  66.                                 }
  67.                                 if (taps_count == 0)
  68.                                 {
  69.                                     stopwatch.Stop();
  70.                                     start = false;
  71.                                     SendKeys.Send("{F15}");
  72.                                     return CallNextHookEx(_hookIDM, nCode, wParam, lParam);
  73.                                 }
  74.                                 //Debug.WriteLine("KeyChar: " + vkCode);
  75.                                 taps_count--;
  76.                             }
  77.                         }
  78.                     }
  79.                 }
  80.             }
  81.             catch (Exception ex)
  82.             {
  83.                 //Debug.WriteLine("Error in HookCallbackK(): " + ex.Message);
  84.             }
  85.             return CallNextHookEx(_hookIDK, nCode, wParam, lParam);
  86.         }
  87.  
  88.         private static IntPtr HookCallbackM(int nCode, IntPtr wParam, IntPtr lParam)
  89.         {
  90.             try
  91.             {
  92.                 if (nCode >= 0)
  93.                 {
  94.                     if ((int)wParam == WM_LBUTTONDOWN || (int)wParam == WM_RBUTTONDOWN)
  95.                     {
  96.                         if (start)
  97.                         {
  98.                             if (hk1.Key == ConsoleKey.F13 && (int)wParam == WM_LBUTTONDOWN || hk1.Key == ConsoleKey.F14 && (int)wParam == WM_RBUTTONDOWN || hk2.Key == ConsoleKey.F13 && (int)wParam == WM_LBUTTONDOWN || hk2.Key == ConsoleKey.F14 && (int)wParam == WM_RBUTTONDOWN)
  99.                             {
  100.                                 if (first)
  101.                                 {
  102.                                     stopwatch.Start();
  103.                                     first = false;
  104.                                 }
  105.                                 if (taps_count == 0)
  106.                                 {
  107.                                     stopwatch.Stop();
  108.                                     start = false;
  109.                                     SendKeys.Send("{F15}");
  110.                                     return CallNextHookEx(_hookIDM, nCode, wParam, lParam);
  111.                                 }
  112.                                 taps_count--;
  113.                             }
  114.                         }
  115.                         else
  116.                         {
  117.                             if (setkeys)
  118.                             {
  119.                                 if ((int) wParam == WM_LBUTTONDOWN)
  120.                                     SendKeys.Send("{F13}");
  121.                                 else
  122.                                     SendKeys.Send("{F14}");
  123.                             }
  124.                         }
  125.                     }
  126.                 }
  127.             }
  128.             catch (Exception ex)
  129.             {
  130.                 //Debug.WriteLine("Error in HookCallbackM(): " + ex.Message);
  131.             }
  132.             return CallNextHookEx(_hookIDM, nCode, wParam, lParam);
  133.         }
  134.  
  135.         static void Main(string[] args)
  136.         {
  137.             _hookIDK = SetWindowsHookEx(WH_KEYBOARD_LL, _procK, GetModuleHandle("user32"), 0);
  138.             _hookIDM = SetWindowsHookEx(WH_MOUSE_LL, _procM, GetModuleHandle("user32"), 0);
  139.             new Thread(Prog).Start();
  140.             Application.Run();
  141.         }
  142.  
  143.         private static void Prog()
  144.         {
  145.             Console.ForegroundColor = ConsoleColor.Red;
  146.             Console.WriteLine(@"       ,--,   _,.---._      ,-,--.                    ,--,  ");
  147.             Console.WriteLine(@"      /-\==\,-.' , -  `.  ,-.'-  _\ .--.-. .-.-.     /-\==\ ");
  148.             Console.WriteLine(@"     / '/==/==/_,  ,  - \/==/_ ,_.'/==/ -|/=/  |    / '/==/ ");
  149.             Console.WriteLine(@"    /  /==/==|   .=.     \==\  \   |==| ,||=| -|   /  /==/  ");
  150.             Console.WriteLine(@"   / -/==/|==|_ : ;=:  - |\==\ -\  |==|- | =/  |  / -/==/   ");
  151.             Console.WriteLine(@"  / `/==/ |==| , '='     |_\==\ ,\ |==|,  \/ - | / `/==/    ");
  152.             Console.WriteLine(@" / -/==/   \==\ -    ,_ //==/\/ _ ||==|-   ,   // -/==/     ");
  153.             Console.WriteLine(@"/ `/==/     '.='. -   .' \==\ - , //==/ , _  .'/ `/==/      ");
  154.             Console.WriteLine(@"`--`-`        `--`--''    `--`---' `--`..---'  `--`-`       ");
  155.             Console.WriteLine("             [ osu!Tapspeed-meter for /osu/ ]");
  156.             Console.WriteLine("                   - by DaRealSlimOni -");
  157.             Console.WriteLine("");
  158.            
  159.             Console.ForegroundColor = ConsoleColor.Cyan;
  160.             Console.Write("[~]");
  161.             Console.ForegroundColor = ConsoleColor.White;
  162.             Console.Write(" Tapkey1: ");
  163.             setkeys = true;
  164.             hk1 = Console.ReadKey(true);
  165.             if (hk1.Key == ConsoleKey.F13)
  166.                 Console.WriteLine("LeftMouseButton");
  167.             else if (hk1.Key == ConsoleKey.F14)
  168.                 Console.WriteLine("RightMouseButton");
  169.             else
  170.                 Console.WriteLine(hk1.Key.ToString());
  171.             Console.ForegroundColor = ConsoleColor.Cyan;
  172.             Console.Write("[~]");
  173.             Console.ForegroundColor = ConsoleColor.White;
  174.             Console.Write(" Tapkey2: ");
  175.             hk2 = Console.ReadKey(true);
  176.             if (hk2.Key == ConsoleKey.F13)
  177.                 Console.WriteLine("LeftMouseButton");
  178.             else if (hk2.Key == ConsoleKey.F14)
  179.                 Console.WriteLine("RightMouseButton");
  180.             else
  181.                 Console.WriteLine(hk2.Key.ToString());
  182.             setkeys = false;
  183.  
  184.             Console.ForegroundColor = ConsoleColor.Cyan;
  185.             Console.Write("[~]");
  186.             Console.ForegroundColor = ConsoleColor.White;
  187.             Console.Write(" Taps: ");
  188.             string line = Console.ReadLine();
  189.             while (!Int32.TryParse(line, out taps))
  190.             {
  191.                 Console.ForegroundColor = ConsoleColor.Cyan;
  192.                 Console.WriteLine("ERROR! VALUE NOT VALID!");
  193.                 Console.Write("[~]");
  194.                 Console.ForegroundColor = ConsoleColor.White;
  195.                 Console.Write(" Taps: ");
  196.                 line = Console.ReadLine();
  197.             }
  198.             if (taps < 10)
  199.             {
  200.                 taps = 10;
  201.                 Console.SetCursorPosition(0, Console.CursorTop - 1);
  202.                 Console.ForegroundColor = ConsoleColor.Cyan;
  203.                 Console.Write("[~]");
  204.                 Console.ForegroundColor = ConsoleColor.White;
  205.                 Console.Write(" Taps: 10         ");
  206.             }
  207.            
  208.             TapMeter();
  209.         }
  210.  
  211.         private static void TapMeter()
  212.         {
  213.             taps_count = taps - 1;
  214.  
  215.             Console.WriteLine("");
  216.             Console.ForegroundColor = ConsoleColor.Cyan;
  217.             Console.Write("[~]");
  218.             Console.ForegroundColor = ConsoleColor.White;
  219.             Console.WriteLine(" Now start hitting keys! ");
  220.             stopwatch.Reset();
  221.             first = true;
  222.             start = true;
  223.             ConsoleKeyInfo key = Console.ReadKey(true);
  224.             while (key.Key != ConsoleKey.F15)
  225.             {
  226.                 key = Console.ReadKey(true);
  227.             }
  228.             Cont();
  229.         }
  230.  
  231.         private static void Cont()
  232.         {
  233.             double t_ms = stopwatch.ElapsedMilliseconds;
  234.             double t_sec = t_ms / 1000;
  235.            
  236.             Console.ForegroundColor = ConsoleColor.Green;
  237.             Console.Write("         [+]");
  238.             Console.ForegroundColor = ConsoleColor.White;
  239.             Console.WriteLine(" Time: " + t_sec + "sec");
  240.             Console.ForegroundColor = ConsoleColor.Green;
  241.             Console.Write("         [+]");
  242.             Console.ForegroundColor = ConsoleColor.White;
  243.             Console.WriteLine(" TapsPerMinute: " + (int)((taps / t_sec) * 60));
  244.             Console.ForegroundColor = ConsoleColor.Green;
  245.             Console.Write("         [+]");
  246.             Console.ForegroundColor = ConsoleColor.White;
  247.             Console.WriteLine(" maximal osu stream speed (1/4): " + (int)(((taps / t_sec) * 60) / 4) + "bpm");
  248.  
  249.             Console.WriteLine("");
  250.             Console.ForegroundColor = ConsoleColor.Cyan;
  251.             Console.Write("[~]");
  252.             Console.ForegroundColor = ConsoleColor.White;
  253.             Console.Write("Retry? (y/n) ");
  254.             ConsoleKeyInfo key = Console.ReadKey(true);
  255.             while (key.KeyChar != 'y' && key.KeyChar != 'n')
  256.             {
  257.                 key = Console.ReadKey(true);
  258.             }
  259.             if (key.KeyChar == 'y')
  260.                 TapMeter();
  261.             else
  262.             {
  263.                 UnhookWindowsHookEx(_hookIDK);
  264.                 UnhookWindowsHookEx(_hookIDM);
  265.                 Application.Exit();
  266.             }
  267.         }
  268.     }
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement