public static Bitmap Take_Snapshot_Process(Process_Object proc) { int is_success = 0; WindowsStructs.RECT window_dimensions; WindowsStructs.GetWindowRect(proc.GetMWHandle(), out window_dimensions); Bitmap scrnsht_wind = new Bitmap(window_dimensions.Right - window_dimensions.Left + 1, window_dimensions.Bottom - window_dimensions.Top + 1); Graphics to_shot = Graphics.FromImage(scrnsht_wind); IntPtr bitmap_pointer = to_shot.GetHdc(); is_success = WindowsStructs.PrintWindow(proc.GetMWHandle(), bitmap_pointer, 0); if (is_success == 0) { System.Console.Write("\nError Taking Screenshot\n"); } else { System.Console.Write("\nSnapshot Taken\n"); } to_shot.ReleaseHdc(bitmap_pointer); to_shot.Dispose(); /*try * { * scrnsht_wind.Save("League.bmp"); //Only included for debugging reasons * } * catch(Exception e) * { * System.Console.Write("\nError Saving Bitmap\n"); * }*/ return(scrnsht_wind); }
//For Diagnostics public static void Print_Process_Window_Dimensions(Process_Object proc) { WindowsStructs.RECT window_size; if (WindowsStructs.GetWindowRect(proc.GetMWHandle(), out window_size) == 0) { System.Console.Write("\nERROR getting size"); return; } System.Console.Write(string.Concat("\nHeight: ", window_size.Bottom - window_size.Top + 1, " Width: ", window_size.Right - window_size.Left + 1)); }
public static void Click(Process_Object procObj, Program_Profile progProf) { //Adapted only for 64 bit systems? //TODO: Make alternate code for 32bit systems WindowsStructs.SetForegroundWindow(procObj.GetMWHandle()); UInt64 clickPoint = 0x0; clickPoint = clickPoint | (UInt32)(progProf.Get_OffsetY() + 5); clickPoint = clickPoint << 0x10; clickPoint = clickPoint | (UInt32)(progProf.Get_OffsetX() + 5); WindowsStructs.SendMessage(procObj.GetMWHandle(), WindowsStructs.WM_LBUTTONDOWN, (IntPtr)WindowsStructs.MK_LBUTTON, (IntPtr)clickPoint); WindowsStructs.SendMessage(procObj.GetMWHandle(), WindowsStructs.WM_LBUTTONUP, (IntPtr)WindowsStructs.MK_LBUTTON, (IntPtr)clickPoint); //WindowsStructs.SendMessage(procObj.GetMWHandle(), WindowsStructs.WM_LBUTTONDOWN, WindowsStructs.MK_LBUTTON, (UInt32)((progProf.Get_LengthY() << 0x10) | progProf.Get_LengthX())); //WindowsStructs.SendMessage(procObj.GetMWHandle(), WindowsStructs.WM_LBUTTONUP, WindowsStructs.MK_LBUTTON, (UInt32)((progProf.Get_LengthY() << 0x10) | progProf.Get_LengthX())); }
//string p_name = "LolClient"; // Set name of program launcher //string m_name = ""; //Set name of main program. Aka the actual game launching passed the launcher. // Load Process into a Process_Object. Will load the first process in the data.txt, should be lol public static void Find_Process() { Console.Write(string.Concat("Searching for Process: ", Program_Importer.programs.ElementAt(choice).Get_Name())); Process_Object cn_process = Process_Object.GetProcessObject(Program_Importer.programs.ElementAt(choice).Get_Name()); while (cn_process == null) { Console.Write("."); System.Threading.Thread.Sleep(2500); cn_process = Process_Object.GetProcessObject(Program_Importer.programs.ElementAt(choice).Get_Name()); } // Print Resulting Process Name and PID (Process ID) System.Console.Write(string.Concat("\n", cn_process.GetName(), " ", "PID: ", cn_process.GetPID())); // End Load and Print Segment Analyze_Process(cn_process); }
//Allows part of the picture to be cropped out according to offsets public static Bitmap Take_Snapshot_Process(Process_Object proc, int offset_x, int offset_y, int offset_x2, int offset_y2) { int is_success = 0; Rectangle new_img_bounds = new Rectangle(0, 0, offset_x2, offset_y2); Rectangle crop_bounds = new Rectangle(offset_x, offset_y, offset_x2, offset_y2); WindowsStructs.RECT window_dimensions; WindowsStructs.GetWindowRect(proc.GetMWHandle(), out window_dimensions); Bitmap scrnsht_wind = new Bitmap(window_dimensions.Right - window_dimensions.Left + 1, window_dimensions.Bottom - window_dimensions.Top + 1); Graphics to_shot = Graphics.FromImage(scrnsht_wind); IntPtr bitmap_pointer = to_shot.GetHdc(); is_success = WindowsStructs.PrintWindow(proc.GetMWHandle(), bitmap_pointer, 0); if (is_success == 0) { System.Console.Write("\nError Taking Screenshot\n");// can return null which can call for a new mainwindowhandler } else { System.Console.Write("\nSnapshot Taken\n"); } Bitmap cropped_pic = new Bitmap(offset_x2, offset_y2); to_shot.ReleaseHdc(bitmap_pointer); to_shot.Dispose(); cropped_pic = (Bitmap)scrnsht_wind.Clone(crop_bounds, scrnsht_wind.PixelFormat); scrnsht_wind.Dispose(); /* try * { * cropped_pic.Save("League.bmp"); //Only included for debugging reasons * } * catch (Exception e) * { * System.Console.Write("\nError Saving Bitmap\n"); * }*/ return(cropped_pic); }
/**Retrieves a Process_Object to be stored. Stores name, PID, handle to process, and the actual Process object */ public static Process_Object GetProcessObject(string name) { Process_Object pb1 = new Process_Object(); Process[] tmp = Process.GetProcessesByName(name); // System.Console.Write(tmp.Length); if (tmp.Length == 0) { System.Console.Write("\nCouldn't find process\n"); return(null); } else if (tmp.Length == 1) { System.Console.Write("Found Exact Process"); pb1.SetProcess(tmp[0]); pb1.SetName(tmp[0].ProcessName); pb1.SetPID(tmp[0].Id); pb1.SetMWHandle(tmp[0].MainWindowHandle); //Get Handle after opening process, currently only containing Terminate_Process tag IntPtr tmp_hndle = WindowsStructs.OpenProcess((IntPtr)0x1F0FFF, false, (IntPtr)tmp[0].Id); if (tmp_hndle == null) { System.Console.Write("Could not open process"); pb1.SetHandle(tmp[0].Handle); } else { pb1.SetHandle(tmp_hndle); } //End getting of handle } else { System.Console.Write("Multiple Processes Found -- returning null"); return(null); } return(pb1); }
//Test Process Close() //cn_process.Close();// //End Test //Diagnostic Window Test //SnapshotHelper.Print_Process_Window_Dimensions(cn_process); //End Test //Test Launcher Copy and Compare //Bitmap screen = SnapshotHelper.Take_Snapshot_Process(cn_process, 491, 436, 183, 41); //Bitmap refScreen = new Bitmap("reference.PNG"); //Bitmap queue_img = new Bitmap("join.bmp"); //Image_Manipulator.Compare_Image_Section(refScreen, queue_img, new Rectangle(491, 436, 183, 41), new Rectangle(0, 0, queue_img.Width, queue_img.Height)); //End Test //Loop for test comparison of live results //TODO: Add listener for Lol.exe to know when it closes and resume scanning. Assuming user will want to queue for another game //TODO: Add listener to LolClient.exe to when the user closes it, shutdown the app. Currently working prototype //TODO: Add implementation for normal blind pick //TODO: Bug starting program before league starts endless Error Loop - workaround repress button //Connect to phone //TODO: On activation of queue pop, move process window to active, so that click corresponds to the proper progam // Server_Socket.StartListening(); //end connect // COMMENTED OUT PROGRAM CODE FOR OTHER TESTS public static void Analyze_Process(Process_Object cn_process) { //Console.Write(Program_Importer.programs.ElementAt(choice).ToString()); bool queue_popped = false; //CHANGE TO FALSE OR BROKEN bool is_active = true; bool main_game_launched = false; //Need to actually start a game to get name of the process int counter = 0; Program_Profile chosen = Program_Importer.programs.ElementAt(choice); Bitmap screen = null; // Bitmap queue_img = new Bitmap("join.bmp"); // Can Cache image in order to increase perfomance, image is also hardcoded byte[,,] pixelValues = Image_Manipulator.Store_Image_Value(chosen.Get_Image(), Image_Manipulator.DEFAULT_RESIZE); while (!queue_popped && is_active) { is_active = cn_process.IsOpen(); if (is_active == false) { Console.Clear(); Console.Write("Process has closed. Closing Program..."); return; } try { screen = SnapshotHelper.Take_Snapshot_Process(cn_process, chosen); // if (Image_Manipulator.Compare_Image(Program_Importer.programs.ElementAt(choice).Get_Image(), screen) && Program_Importer.programs.ElementAt(choice).Get_MatchMode()) queue_popped = true; if (Image_Manipulator.Compare_Image(pixelValues, screen, Image_Manipulator.DEFAULT_RESIZE) && chosen.Get_MatchMode()) { queue_popped = true; } else { queue_popped = false; } } catch (Exception e) { Console.Write("\nError: " + e.ToString()); } //Console.Write(queue_popped); System.Threading.Thread.Sleep(250); if (counter == 100) { GC.Collect(); counter = 0; } counter++; } if (chosen.Get_AutoStatus()) { Process_Object.Click(cn_process, chosen); } //if (queue_popped == true) Server_Socket.SendSignal("Popped"); //else Server_Socket.SendSignal("Closed"); //End Test //Socket Tests //Server_Socket.StartListening(); //End Socket Tests //Close connection //Server_Socket.GoDeaf(); //End Close Console.Write("\nClick to Restart"); //Console.Clear(); }
public static Bitmap Take_Snapshot_Process(Process_Object proc, Program_Profile prof) { return(Take_Snapshot_Process(proc, prof.Get_OffsetX(), prof.Get_OffsetY(), prof.Get_LengthX(), prof.Get_LengthY())); }