public OsrsScanData SearchScreenForColors(List <Color> colors, OsrsImage image, ScanBoundaries boundaries = null) { LoggingUtility.WriteToAuditLog("Starting Color Search"); OsrsScanData response = null; var osrsWindow = HwndInterface.GetHwndFromTitle("Old School RuneScape"); var windowSize = HwndInterface.GetHwndSize(osrsWindow); var windowLocation = HwndInterface.GetHwndPos(osrsWindow); HwndInterface.ActivateWindow(osrsWindow); var screenshot = TakeScreenshot(); #region Scan Boundaries Calculation if (boundaries == null) { boundaries = new ScanBoundaries(); boundaries.MinX = windowLocation.X < 0 ? 0 : windowLocation.X; boundaries.MinY = windowLocation.Y < 0 ? 0 : windowLocation.Y; boundaries.MaxX = (windowLocation.X + windowSize.Width) > screenshot.Width ? screenshot.Width : (windowLocation.X + windowSize.Width); boundaries.MaxY = (windowLocation.Y + windowSize.Height) > screenshot.Height ? screenshot.Height : (windowLocation.Y + windowSize.Height); } #endregion response = FindColorsInImage(colors, screenshot, boundaries); //response = FindColorsInImage(colors, image.ImageBitmap, new ScanBoundaries { MinX = 0, MinY = 0, MaxX = image.ImageBitmap.Width, MaxY = image.ImageBitmap.Height }); LoggingUtility.WriteToAuditLog("Color Search Complete"); return(response); }
public List <OsrsScanData> SearchScreenForImages(List <OsrsImage> osrsImages, ScanBoundaries boundaries = null, bool getSingleOccurrence = false) { var response = new List <OsrsScanData>(); var osrsWindow = HwndInterface.GetHwndFromTitle("Old School RuneScape"); var windowSize = HwndInterface.GetHwndSize(osrsWindow); var windowLocation = HwndInterface.GetHwndPos(osrsWindow); HwndInterface.ActivateWindow(osrsWindow); var screenshot = TakeScreenshot(); #region Scan Boundaries Calculation if (boundaries == null) { boundaries = new ScanBoundaries(); var imgMaxX = osrsImages.Max(x => x.ImageBitmap.Width); var imgMaxY = osrsImages.Max(x => x.ImageBitmap.Height); boundaries.MinX = windowLocation.X < 0 ? 0 : windowLocation.X; boundaries.MinY = windowLocation.Y < 0 ? 0 : windowLocation.Y; boundaries.MaxX = (windowLocation.X + windowSize.Width) > screenshot.Width ? screenshot.Width - imgMaxX : (windowLocation.X + windowSize.Width) - imgMaxX; boundaries.MaxY = (windowLocation.Y + windowSize.Height) > screenshot.Height ? screenshot.Height - imgMaxY : (windowLocation.Y + windowSize.Height) - imgMaxY; } #endregion response = FindAllBitmapsInImage(osrsImages, screenshot, boundaries, getSingleOccurrence); return(response); }
/// <summary> /// Seeks all children of this Hwnd Object. /// </summary> /// <returns></returns> public List <HwndObject> GetChildren() { var result = new List <HwndObject>(); foreach (var hwnd in HwndInterface.EnumChildren(NativePtr)) { result.Add(new HwndObject(hwnd)); } return(result); }
public List <HwndObject> GetChildren() { List <HwndObject> list = new List <HwndObject>(); foreach (IntPtr ptr in HwndInterface.EnumChildren(this.Hwnd)) { list.Add(new HwndObject(ptr)); } return(list); }
public static List <HwndObject> GetWindows() { List <HwndObject> list = new List <HwndObject>(); foreach (IntPtr ptr in HwndInterface.EnumHwnds()) { list.Add(new HwndObject(ptr)); } return(list); }
/// <summary> /// Retrieves all top-level Hwnd Objects. /// </summary> /// <returns></returns> public static List <HwndObject> GetWindows() { var result = new List <HwndObject>(); foreach (var hwnd in HwndInterface.EnumHwnds()) { result.Add(new HwndObject(hwnd)); } return(result); }
public static void ClickLocation(Point location, bool leftClick = true) { var osrsWindow = HwndInterface.GetHwndFromTitle("Old School RuneScape"); HwndInterface.ActivateWindow(osrsWindow); Cursor.Position = location; if (leftClick) { MouseEvent.MouseLeftClick(); } else { MouseEvent.MouseRightClick(); } }
public int GetMessageInt(WM msg) { return(HwndInterface.GetMessageInt(this.Hwnd, msg)); }
/// <summary> /// Retrieves a child Hwnd Object by its class and title. /// </summary> /// <param name="cls"></param> /// <param name="title"></param> /// <returns></returns> public HwndObject GetChild(string cls, string title) { var hwnd = HwndInterface.GetHwndChild(Hwnd, cls, title); return(GetInstance(hwnd)); }
/// <summary> /// Seeks a parent for this Hwnd Object (if any). /// </summary> /// <returns></returns> public HwndObject GetParent() { return(new HwndObject(HwndInterface.GetHwndParent(NativePtr))); }
/// <summary> /// Returns an integer result from a message. /// </summary> /// <param name="msg"></param> /// <returns></returns> public int GetMessageInt(WM msg) { return(HwndInterface.GetMessageInt(NativePtr, msg)); }
/// <summary> /// Sends a message to this Hwnd Object /// </summary> /// <param name="msg"></param> /// <param name="param1"></param> /// <param name="param2"></param> public void SendMessage(WM msg, uint param1, uint param2) { HwndInterface.SendMessage(NativePtr, msg, param1, param2); }
public void SendMessage(WM msg, uint param1, uint param2) { HwndInterface.SendMessage(this.Hwnd, msg, param1, param2); }
public static HwndObject GetWindowByClassName(string className) { return(new HwndObject(HwndInterface.GetHwndFromClass(className))); }
public void RunGame(string cmdArguments, int systemId) { int procId; bool rememberWinPos = GlobalSettings.GetGlobals().rememberSysWinPositions.Value; using (System.Diagnostics.Process gProcess = new System.Diagnostics.Process()) { gProcess.StartInfo.UseShellExecute = true; gProcess.StartInfo.RedirectStandardOutput = false; gProcess.StartInfo.WorkingDirectory = "\"" + MednafenFolder + "\""; gProcess.StartInfo.FileName = "\"" + BuildMednafenPath(MednafenFolder) + "\""; gProcess.StartInfo.CreateNoWindow = false; // Build command line config arguments gProcess.StartInfo.Arguments = cmdArguments; gProcess.Start(); gProcess.WaitForInputIdle(); procId = gProcess.Id; // get process window handle IntPtr hwnd = gProcess.MainWindowHandle; // set windows position System.Drawing.Point pnt = new System.Drawing.Point(); if (rememberWinPos == true) { // get windows position from database pnt = GlobalSettings.GetWindowPosBySystem(systemId); // set windows position HwndInterface.SetHwndPos(hwnd, pnt.X, pnt.Y); } bool isClosed = false; while (isClosed == false) { try { // get process id Process p = Process.GetProcessById(procId); if (rememberWinPos == true) { // get window top left x y coords pnt = HwndInterface.GetHwndPos(hwnd); } } catch { isClosed = true; } Thread.Sleep(1000); } if (rememberWinPos == true) { // save coords to database GlobalSettings.SaveWindowPosBySystem(systemId, pnt); } } }
public void RunGame(string cmdArguments, int systemId) { /* * // check mednafen.exe instruction set * InstructionSet medInst = InstructionSetDetector.GetExeInstructionSet(BuildMednafenPath(MednafenFolder)); * // get operating system type * InstructionSet osInst = InstructionSetDetector.GetOperatingSystemInstructionSet(); * * if (osInst == InstructionSet.x86) * { * if (medInst == InstructionSet.x64) * { * MessageBox.Show("You are targetting a 64-bit version of Mednafen on a 32-bit operating system. This will not work.\n\nPlease target a 32-bit (x86) version of Mednafen", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); * return; * } * * if (systemId == 13 && medInst == InstructionSet.x86) * { * MessageBox.Show("You are trying to emulate a Sega Saturn game using a 32-bit Mednafen build on a 32-bit operating system. This will not work.\n\nYou are unable to emulate Saturn games on this machine", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); * return; * } * * if (systemId == 13) * { * MessageBox.Show("You are trying to emulate a Sega Saturn game using a 32-bit operating system. This will not work.\n\nYou are unable to emulate Saturn games on this machine", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); * return; * } * } * * if (osInst == InstructionSet.x64) * { * if (systemId == 13 && medInst == InstructionSet.x86) * { * MessageBox.Show("You are trying to emulate a Sega Saturn game using a 32-bit Mednafen build. This will not work.\n\nPlease target a 64-bit (x64) version of Mednafen", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); * return; * } * } * */ int procId; bool rememberWinPos = GlobalSettings.GetGlobals().rememberSysWinPositions.Value; using (System.Diagnostics.Process gProcess = new System.Diagnostics.Process()) { gProcess.StartInfo.UseShellExecute = true; gProcess.StartInfo.RedirectStandardOutput = false; gProcess.StartInfo.WorkingDirectory = "\"" + MednafenFolder + "\""; gProcess.StartInfo.FileName = "\"" + BuildMednafenPath(MednafenFolder) + "\""; gProcess.StartInfo.CreateNoWindow = false; // Build command line config arguments gProcess.StartInfo.Arguments = cmdArguments; //gProcess.StartInfo.UseShellExecute = false; //gProcess.StartInfo.EnvironmentVariables["MEDNAFEN_NOPOPUPS"] = "1"; gProcess.Start(); gProcess.WaitForExit(); procId = gProcess.Id; IntPtr hwnd = new IntPtr(); // set windows position System.Drawing.Point pnt = new System.Drawing.Point(); // get process window handle try { hwnd = gProcess.MainWindowHandle; if (rememberWinPos == true) { // get windows position from database pnt = GlobalSettings.GetWindowPosBySystem(systemId); // set windows position HwndInterface.SetHwndPos(hwnd, pnt.X, pnt.Y); } bool isClosed = false; while (isClosed == false) { try { // get process id Process p = Process.GetProcessById(procId); if (rememberWinPos == true) { // get window top left x y coords pnt = HwndInterface.GetHwndPos(hwnd); } } catch { isClosed = true; } Thread.Sleep(1000); } if (rememberWinPos == true) { // save coords to database GlobalSettings.SaveWindowPosBySystem(systemId, pnt); } } catch { // catch exception if mednafen doesnt launch correctly if (VersionChecker.Instance.CurrentMedVerDesc.MajorINT > 0) { // new mednafen already pops up error messages - so do nothing } else { // old mednafen does not pop messages - interogate stdout.txt and display the last error string res = LogParser.Instance.GetErrors(); if (res != string.Empty) { string end = "\n--------------------------------------------\n"; string beg = "It looks like mednafen did NOT launch correctly.\nThe following error log may help in troubleshooting:" + end; MessagePopper.ShowMessageDialog((beg + res + end).Replace("\n\n", "\n").TrimEnd('\n'), "MEDNAFEN ERROR PARSER"); } } return; } } }
/// <summary> /// Sends a message to this Hwnd Object /// </summary> /// <param name="msg"></param> /// <param name="param1"></param> /// <param name="param2"></param> public void SendMessage(WM msg, uint param1, string param2) { HwndInterface.SendMessage(Hwnd, msg, param1, param2); }
public string GetMessageString(WM msg, uint param) { return(HwndInterface.GetMessageString(this.Hwnd, msg, param)); }
public HwndObject GetParent() { return(new HwndObject(HwndInterface.GetHwndParent(this.Hwnd))); }
public void RestoreWindow() { HwndInterface.RestoreWindow(this.Hwnd); }
/// <summary> /// Gets the first top-level HwndObject with the given title. /// </summary> /// <param name="title"></param> /// <returns></returns> public static HwndObject GetWindowByTitle(string title) { return(new HwndObject(HwndInterface.GetHwndFromTitle(title))); }
public void Click() { HwndInterface.ClickHwnd(this.Hwnd); }
/// <summary> /// Returns a string result from a message. /// </summary> /// <param name="msg"></param> /// <param name="param"></param> /// <returns></returns> public string GetMessageString(WM msg, uint param) { return(HwndInterface.GetMessageString(NativePtr, msg, param)); }
// <summary> // Bring this window to the foreground // </summary> public bool Activate() { return(HwndInterface.ActivateWindow(Hwnd)); }
/// <summary> /// Simulates a user-click on this object. /// </summary> public void Click() { HwndInterface.ClickHwnd(NativePtr); }
/// <summary> /// Retrieves a child Hwnd Object by its class and title. /// </summary> /// <param name="cls"></param> /// <param name="title"></param> /// <returns></returns> public HwndObject GetChild(string cls, string title) { var hwnd = HwndInterface.GetHwndChild(NativePtr, cls, title); return(new HwndObject(hwnd)); }
// <summary> // Minimize this window // </summary> public bool Minimize() { return(HwndInterface.MinimizeWindow(Hwnd)); }
/// <summary> /// Seeks all children of this Hwnd Object. /// </summary> /// <returns></returns> public List <HwndObject> GetSiblings() { return(GetWindows(HwndInterface.EnumSiblings(Hwnd))); }
public bool MoveWindow(Point location, Size size) { return(HwndInterface.MoveWindow(NativePtr, location.X, location.Y, size.Width, size.Height)); }
public HwndObject GetChild(string cls, string title) { return(new HwndObject(HwndInterface.GetHwndChild(this.Hwnd, cls, title))); }