Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Threading;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- namespace Slots_Bot_v0._1
- {
- public partial class Form1 : Form
- {
- public static Boolean isGoing = false;
- public static Boolean PokeMMODetected = false; // CHANGE THIS TO FALSE
- private const int WM_SETTEXT = 0x000c;
- private const int WM_KEYDOWN = 0x0100;
- Thread inputThreadThing = new Thread(new ThreadStart(inputThread));
- Thread detectionThreadThing = new Thread(new ThreadStart(detectionThread));
- public Form1()
- {
- InitializeComponent();
- }
- private void createTheThread(string StartStop)
- {
- if (StartStop.ToLower().Equals("start"))
- {
- //Thread inputThreadThing = new Thread(new ThreadStart(inputThread));
- inputThreadThing.Start();
- }
- else if (StartStop.ToLower().Equals("stop"))
- {
- inputThreadThing.Abort();
- }
- }
- private void createDetectionThread(string StartStop)
- {
- if (StartStop.ToLower().Equals("start"))
- {
- detectionThreadThing.Start();
- }
- else if (StartStop.ToLower().Equals("stop"))
- {
- detectionThreadThing.Abort();
- }
- }
- public static void detectionThread()
- {
- while(true)
- {
- var runningProcessByName = Process.GetProcessesByName("javaw");
- if (runningProcessByName.Length == 0)
- {
- PokeMMODetected = false;
- Thread.Sleep(1000);
- }
- else
- {
- PokeMMODetected = true;
- }
- //Debug.WriteLine(PokeMMODetected);
- Thread.Sleep(500);
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- createTheThread("start");
- createDetectionThread("start");
- LinkLabel.Link link = new LinkLabel.Link();
- link.LinkData = "http://www.steamcommunity.com/id/skizerzz";
- skizerzLink.Links.Add(link);
- }
- private void startButton_Click(object sender, EventArgs e)
- {
- if(!isGoing)
- {
- isGoing = true;
- startButton.Text = "Stop";
- //Debug.WriteLine(isGoing);
- }
- else
- {
- isGoing = false;
- startButton.Text = "Start";
- //Debug.WriteLine(isGoing);
- }
- }
- public static void inputThread()
- {
- while (true)
- {
- String windName = "";
- IntPtr handle = NativeMethods.GetForegroundWindow();
- const int count = 512;
- var text = new StringBuilder(count);
- if(NativeMethods.GetWindowText(handle, text, count) > 0)
- {
- windName = text.ToString();
- }
- if(windName.Length > 3)
- {
- windName = windName.Substring(0, 3);
- }
- else
- {
- Thread.Sleep(50);
- continue;
- }
- 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")))
- {
- //IntPtr hWndPokegame = NativeMethods.FindWindow("PokeMMO", null);
- //IntPtr hWndEdit = NativeMethods.FindWindowEx(hWndPokegame, IntPtr.Zero, "Edit", null);
- ////NativeMethods.SendMessage(hWndEdit, WM_SETTEXT, 0, " z");
- //NativeMethods.PostMessage(hWndEdit, WM_KEYDOWN, Keys.Z, IntPtr.Zero);
- //Thread.Sleep(50);
- Debug.WriteLine("On");
- SendKeys.SendWait("{DOWN}");
- Thread.Sleep(50);
- SendKeys.SendWait("{DOWN}");
- Thread.Sleep(50);
- SendKeys.SendWait("{DOWN}");
- Thread.Sleep(50);
- SendKeys.SendWait("{Z}");
- Thread.Sleep(50);
- SendKeys.SendWait("{Z}");
- Thread.Sleep(50);
- SendKeys.SendWait("{Z}");
- Thread.Sleep(50);
- SendKeys.SendWait("{Z}");
- Thread.Sleep(50);
- }
- else
- {
- //Debug.WriteLine("Off");
- Thread.Sleep(500);
- }
- }
- }
- internal static class NativeMethods
- {
- [DllImport("user32.dll", SetLastError = true)]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll", SetLastError = true)]
- public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
- [return: MarshalAs(UnmanagedType.Bool)]
- [DllImport("user32.dll", SetLastError = true)]
- public static extern bool PostMessage(IntPtr hWnd, int Msg, Keys wParam, IntPtr lParam);
- [DllImport("User32.dll")]
- public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
- [DllImport("user32.dll")]
- public static extern IntPtr GetForegroundWindow();
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
- }
- private void refreshTimer_Tick(object sender, EventArgs e)
- {
- if(PokeMMODetected)
- {
- detectionLabel.ForeColor = System.Drawing.Color.Green;
- detectionLabel.Text = "PokeMMO: DETECTED";
- }
- else
- {
- detectionLabel.ForeColor = System.Drawing.Color.Red;
- detectionLabel.Text = "PokeMMO: Not Detected";
- }
- if(isGoing)
- {
- runningLabel.Text = "RUNNING";
- }
- else
- {
- runningLabel.Text = "Stopped";
- }
- }
- private void notWorkingToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Troubleshooting Tips\n-Make sure you have the game window selected, otherwise the input pauses.\n"
- + "-If the process name is not javaw, than the bot will not detect it. Email me at skizerzz@gmail.com to notify me "
- + "of other process names the game can go by, and I will add them.\n"
- + "-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"
- + "-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");
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- createDetectionThread("stop");
- createTheThread("stop");
- }
- private void instructionsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Instructions:\n"
- + "1. Launch PokeMMO and SlotBot, make sure to have equal launch rights (admin or non-admin need to be the same)\n"
- + "2. Go to the Slot Machines in Celadon City and begin playing one.\n"
- + "3. Click Start on SlotBot and set PokeMMO as your foreground application (Bot will pause until PokeMMO is foreground)\n"
- + "4. When ready to stop, press Stop and close SlotBot\n"
- + "Any suggestions or questions please email me at skizerzz@gmail.com\n"
- + "Enjoy! c:");
- }
- private void skizerzLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- Process.Start(e.Link.LinkData as string);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement