コード例 #1
0
ファイル: Program.cs プロジェクト: thquinn/HackMatcher
        static void Main(string[] args)
        {
            // Run EXAPUNKS at 1366*768 resolution and disable HACK*MATCH CRT effect in the settings.
            // Launch HACK*MATCH, wait for the menu to show, then launch the solver.

            Process[] processes = Process.GetProcessesByName("EXAPUNKS");
            if (processes.Length == 0)
            {
                Console.WriteLine("Couldn't find an open instance of EXAPUNKS. Press any key to quit.");
                Console.ReadKey();
                return;
            }
            Process process = processes.OrderBy(e => e.StartTime).First();

            selfHandle = Process.GetCurrentProcess().MainWindowHandle;
            IntPtr hWnd = process.MainWindowHandle;

            if (hWnd != IntPtr.Zero)
            {
                Util32.handle = hWnd;
            }
            Util32.ForegroundWindow();

            while (true)
            {
                State state     = null;
                Color heldColor = Color.White;
                while (state == null)
                {
                    //Image image = Image.FromFile("last.png");
                    Image  image  = ScreenCapture.CaptureWindow(hWnd);
                    Bitmap bitmap = new Bitmap(360, 540, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    using (Graphics g = Graphics.FromImage(bitmap)) {
                        Rectangle srcRect  = new Rectangle(312, 110, 360, 540);
                        Rectangle destRect = new Rectangle(0, 0, 360, 540);
                        g.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel);
                    }
                    bitmap.Save("last.png");
                    state     = CV.ReadBitmap(bitmap);
                    heldColor = new Bitmap(image).GetPixel(320, 610);
                }
                Console.WriteLine("Holding: " + state.held);
                List <Move> moves = FindMoves(state, out bool hasMatch);
                if (moves == null)
                {
                    continue;
                }

                foreach (Move move in moves)
                {
                    Console.WriteLine(move);
                }
                Util32.ExecuteMoves(new Queue <Move>(moves));
                if (hasMatch)
                {
                    Console.WriteLine("Found match, sleeping 500ms...");
                    Thread.Sleep(500);
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Nickardson/HackMatcher
        private static void SetUpWindowHandles()
        {
            Process[] processes = Process.GetProcessesByName("EXAPUNKS");
            if (processes.Length == 0)
            {
                Console.WriteLine("Couldn't find an open instance of EXAPUNKS. Press any key to quit.");
                Console.ReadKey();
                Environment.Exit(1);
            }
            Process process = processes.OrderBy(e => e.StartTime).First();

            selfHandle = Process.GetCurrentProcess().MainWindowHandle;
            IntPtr hWnd = process.MainWindowHandle;

            if (hWnd != IntPtr.Zero)
            {
                Util32.handle = hWnd;
            }
            Util32.ForegroundWindow();
        }