Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public static List <HwndObject> GetWindows()
        {
            List <HwndObject> list = new List <HwndObject>();

            foreach (IntPtr ptr in HwndInterface.EnumHwnds())
            {
                list.Add(new HwndObject(ptr));
            }
            return(list);
        }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
0
        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();
            }
        }
Esempio n. 8
0
 public int GetMessageInt(WM msg)
 {
     return(HwndInterface.GetMessageInt(this.Hwnd, msg));
 }
Esempio n. 9
0
        /// <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));
        }
Esempio n. 10
0
 /// <summary>
 /// Seeks a parent for this Hwnd Object (if any).
 /// </summary>
 /// <returns></returns>
 public HwndObject GetParent()
 {
     return(new HwndObject(HwndInterface.GetHwndParent(NativePtr)));
 }
Esempio n. 11
0
 /// <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));
 }
Esempio n. 12
0
 /// <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);
 }
Esempio n. 13
0
 public void SendMessage(WM msg, uint param1, uint param2)
 {
     HwndInterface.SendMessage(this.Hwnd, msg, param1, param2);
 }
Esempio n. 14
0
 public static HwndObject GetWindowByClassName(string className)
 {
     return(new HwndObject(HwndInterface.GetHwndFromClass(className)));
 }
Esempio n. 15
0
        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);
                }
            }
        }
Esempio n. 16
0
        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;
                }
            }
        }
Esempio n. 17
0
 /// <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);
 }
Esempio n. 18
0
 public string GetMessageString(WM msg, uint param)
 {
     return(HwndInterface.GetMessageString(this.Hwnd, msg, param));
 }
Esempio n. 19
0
 public HwndObject GetParent()
 {
     return(new HwndObject(HwndInterface.GetHwndParent(this.Hwnd)));
 }
Esempio n. 20
0
 public void RestoreWindow()
 {
     HwndInterface.RestoreWindow(this.Hwnd);
 }
Esempio n. 21
0
 /// <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)));
 }
Esempio n. 22
0
 public void Click()
 {
     HwndInterface.ClickHwnd(this.Hwnd);
 }
Esempio n. 23
0
 /// <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));
 }
Esempio n. 24
0
 // <summary>
 // Bring this window to the foreground
 // </summary>
 public bool Activate()
 {
     return(HwndInterface.ActivateWindow(Hwnd));
 }
Esempio n. 25
0
 /// <summary>
 /// Simulates a user-click on this object.
 /// </summary>
 public void Click()
 {
     HwndInterface.ClickHwnd(NativePtr);
 }
Esempio n. 26
0
        /// <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));
        }
Esempio n. 27
0
 // <summary>
 // Minimize this window
 // </summary>
 public bool Minimize()
 {
     return(HwndInterface.MinimizeWindow(Hwnd));
 }
Esempio n. 28
0
 /// <summary>
 /// Seeks all children of this Hwnd Object.
 /// </summary>
 /// <returns></returns>
 public List <HwndObject> GetSiblings()
 {
     return(GetWindows(HwndInterface.EnumSiblings(Hwnd)));
 }
Esempio n. 29
0
 public bool MoveWindow(Point location, Size size)
 {
     return(HwndInterface.MoveWindow(NativePtr, location.X, location.Y, size.Width, size.Height));
 }
Esempio n. 30
0
 public HwndObject GetChild(string cls, string title)
 {
     return(new HwndObject(HwndInterface.GetHwndChild(this.Hwnd, cls, title)));
 }