Advertisement
Skizerzz

SlotBot v0.2015.5.13

Aug 16th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using System.Diagnostics;
  12. using System.Runtime.InteropServices;
  13.  
  14. namespace Slots_Bot_v0._1
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public static Boolean isGoing = false;
  19.         public static Boolean PokeMMODetected = false; // CHANGE THIS TO FALSE
  20.         private const int WM_SETTEXT = 0x000c;
  21.         private const int WM_KEYDOWN = 0x0100;
  22.  
  23.         Thread inputThreadThing = new Thread(new ThreadStart(inputThread));
  24.         Thread detectionThreadThing = new Thread(new ThreadStart(detectionThread));
  25.  
  26.         public Form1()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.  
  31.         private void createTheThread(string StartStop)
  32.         {
  33.             if (StartStop.ToLower().Equals("start"))
  34.             {
  35.                 //Thread inputThreadThing = new Thread(new ThreadStart(inputThread));
  36.                 inputThreadThing.Start();
  37.             }
  38.             else if (StartStop.ToLower().Equals("stop"))
  39.             {
  40.                 inputThreadThing.Abort();
  41.             }
  42.         }
  43.  
  44.         private void createDetectionThread(string StartStop)
  45.         {
  46.             if (StartStop.ToLower().Equals("start"))
  47.             {
  48.                 detectionThreadThing.Start();
  49.             }
  50.             else if (StartStop.ToLower().Equals("stop"))
  51.             {
  52.                 detectionThreadThing.Abort();
  53.             }
  54.         }
  55.  
  56.         public static void detectionThread()
  57.         {
  58.             while(true)
  59.             {
  60.                 var runningProcessByName = Process.GetProcessesByName("javaw");
  61.                 if (runningProcessByName.Length == 0)
  62.                 {
  63.                     PokeMMODetected = false;
  64.                     Thread.Sleep(1000);
  65.                 }
  66.                 else
  67.                 {
  68.                     PokeMMODetected = true;
  69.                 }
  70.                 //Debug.WriteLine(PokeMMODetected);
  71.                 Thread.Sleep(500);
  72.             }
  73.         }
  74.  
  75.         private void Form1_Load(object sender, EventArgs e)
  76.         {
  77.             createTheThread("start");
  78.             createDetectionThread("start");
  79.  
  80.             LinkLabel.Link link = new LinkLabel.Link();
  81.             link.LinkData = "http://www.steamcommunity.com/id/skizerzz";
  82.             skizerzLink.Links.Add(link);
  83.         }
  84.  
  85.         private void startButton_Click(object sender, EventArgs e)
  86.         {
  87.  
  88.             if(!isGoing)
  89.             {
  90.                 isGoing = true;
  91.                 startButton.Text = "Stop";
  92.                 //Debug.WriteLine(isGoing);
  93.             }
  94.             else
  95.             {
  96.                 isGoing = false;
  97.                 startButton.Text = "Start";
  98.                 //Debug.WriteLine(isGoing);
  99.             }
  100.         }
  101.  
  102.         public static void inputThread()
  103.         {
  104.             while (true)
  105.             {
  106.                 String windName = "";
  107.                 IntPtr handle = NativeMethods.GetForegroundWindow();
  108.                 const int count = 512;
  109.                 var text = new StringBuilder(count);
  110.                 if(NativeMethods.GetWindowText(handle, text, count) > 0)
  111.                 {
  112.                     windName = text.ToString();
  113.                 }  
  114.  
  115.                 if(windName.Length > 3)
  116.                 {
  117.                     windName = windName.Substring(0, 3);
  118.                 }
  119.                 else
  120.                 {
  121.                     Thread.Sleep(50);
  122.                     continue;
  123.                 }
  124.  
  125.                 if (isGoing && PokeMMODetected && (windName.ToLower().Equals("pok") || windName.Substring(0, 3).ToLower().Equals("p0k")))//(windName.ToLower().Equals("pokeмmo") || windName.ToLower().Equals("рokеmмo") || windName.ToLower().Equals("pokеммo") || windName.ToLower().Equals("pokеmmo")))
  126.                 {
  127.                     //IntPtr hWndPokegame = NativeMethods.FindWindow("PokeMMO", null);
  128.  
  129.                     //IntPtr hWndEdit = NativeMethods.FindWindowEx(hWndPokegame, IntPtr.Zero, "Edit", null);
  130.  
  131.                     ////NativeMethods.SendMessage(hWndEdit, WM_SETTEXT, 0, " z");
  132.  
  133.                     //NativeMethods.PostMessage(hWndEdit, WM_KEYDOWN, Keys.Z, IntPtr.Zero);
  134.                     //Thread.Sleep(50);
  135.                    
  136.                     Debug.WriteLine("On");
  137.                     SendKeys.SendWait("{DOWN}");
  138.                     Thread.Sleep(50);
  139.                     SendKeys.SendWait("{DOWN}");
  140.                     Thread.Sleep(50);
  141.                     SendKeys.SendWait("{DOWN}");
  142.                     Thread.Sleep(50);
  143.                     SendKeys.SendWait("{Z}");
  144.                     Thread.Sleep(50);
  145.                     SendKeys.SendWait("{Z}");
  146.                     Thread.Sleep(50);
  147.                     SendKeys.SendWait("{Z}");
  148.                     Thread.Sleep(50);
  149.                     SendKeys.SendWait("{Z}");
  150.                     Thread.Sleep(50);
  151.                 }
  152.                 else
  153.                 {
  154.                     //Debug.WriteLine("Off");
  155.                     Thread.Sleep(500);
  156.                 }
  157.             }
  158.         }
  159.         internal static class NativeMethods
  160.         {
  161.             [DllImport("user32.dll", SetLastError = true)]
  162.             public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  163.  
  164.             [DllImport("user32.dll", SetLastError = true)]
  165.             public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
  166.  
  167.             [return: MarshalAs(UnmanagedType.Bool)]
  168.             [DllImport("user32.dll", SetLastError = true)]
  169.             public static extern bool PostMessage(IntPtr hWnd, int Msg, Keys wParam, IntPtr lParam);
  170.  
  171.             [DllImport("User32.dll")]
  172.             public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
  173.  
  174.             [DllImport("user32.dll")]
  175.             public static extern IntPtr GetForegroundWindow();
  176.  
  177.             [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  178.             public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  179.         }
  180.  
  181.         private void refreshTimer_Tick(object sender, EventArgs e)
  182.         {
  183.             if(PokeMMODetected)
  184.             {
  185.                 detectionLabel.ForeColor = System.Drawing.Color.Green;
  186.                 detectionLabel.Text = "PokeMMO: DETECTED";
  187.             }
  188.             else
  189.             {
  190.                 detectionLabel.ForeColor = System.Drawing.Color.Red;
  191.                 detectionLabel.Text = "PokeMMO: Not Detected";
  192.             }
  193.  
  194.             if(isGoing)
  195.             {
  196.                 runningLabel.Text = "RUNNING";
  197.             }
  198.             else
  199.             {
  200.                 runningLabel.Text = "Stopped";
  201.             }
  202.         }
  203.  
  204.         private void notWorkingToolStripMenuItem_Click(object sender, EventArgs e)
  205.         {
  206.             MessageBox.Show("Troubleshooting Tips\n-Make sure you have the game window selected, otherwise the input pauses.\n"
  207.                 + "-If the process name is not javaw, than the bot will not detect it.  Email me at skizerzz@gmail.com to notify me "
  208.                 + "of other process names the game can go by, and I will add them.\n"
  209.                 + "-The bot directly sends input, and the binds being used are Down Arrow and Z (the game's defaults), so make sure these are bound in game.\n"
  210.                 + "-If you run PokeMMO as admin, make sure to run this as Admin also.  If you run PokeMMO as non-admin, run this as non-Admin.\n");
  211.         }
  212.  
  213.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  214.         {
  215.             createDetectionThread("stop");
  216.             createTheThread("stop");
  217.         }
  218.  
  219.         private void instructionsToolStripMenuItem_Click(object sender, EventArgs e)
  220.         {
  221.             MessageBox.Show("Instructions:\n"
  222.             + "1. Launch PokeMMO and SlotBot, make sure to have equal launch rights (admin or non-admin need to be the same)\n"
  223.             + "2. Go to the Slot Machines in Celadon City and begin playing one.\n"
  224.             + "3. Click Start on SlotBot and set PokeMMO as your foreground application (Bot will pause until PokeMMO is foreground)\n"
  225.             + "4.  When ready to stop, press Stop and close SlotBot\n"
  226.             + "Any suggestions or questions please email me at skizerzz@gmail.com\n"
  227.             + "Enjoy! c:");
  228.         }
  229.  
  230.         private void skizerzLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  231.         {
  232.             Process.Start(e.Link.LinkData as string);
  233.         }
  234.     }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement