示例#1
0
        /// <summary>
        /// Creates new CustomGame object using an Overwatch process.
        /// </summary>
        /// <param name="overwatchHandle">Overwatch process handle to use. Leave at default to use the first Overwatch process found.</param>
        /// <param name="screenshotMethod">Method to take screenshots with.</param>
        /// <param name="openChatIsDefault">Determines if the chat should be opened at all times. Command scanning is more reliable if true.</param>
        public CustomGame(IntPtr overwatchHandle = new IntPtr(), ScreenshotMethods screenshotMethod = ScreenshotMethods.BitBlt, bool openChatIsDefault = true)
        {
            if (overwatchHandle == IntPtr.Zero)
            {
                // Get the overwatch process
                Process[] overwatchProcesses = Process.GetProcessesByName("Overwatch");
                if (overwatchProcesses.Length > 0)
                {
                    OverwatchHandle = overwatchProcesses[0].MainWindowHandle;
                }
            }
            else
            {
                OverwatchHandle = overwatchHandle;
            }

            if (OverwatchHandle == IntPtr.Zero)
            {
                throw new MissingOverwatchProcessException("Could not find any Overwatch processes running.");
            }

            SetupWindow(OverwatchHandle, ScreenshotMethod);
            Thread.Sleep(500);

            // Set up debug window if debugmode is set to true.
            if (debugmode)
            {
                new Task(() =>
                {
                    debug        = new Form();
                    debug.Width  = 1500;
                    debug.Height = 1000;
                    debug.Show();
                    g = debug.CreateGraphics();
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                    Application.Run(debug);
                }).Start();
            }

            Command      = new Commands(this);
            AI           = new CG_AI(this);
            Maps         = new CG_Maps(this);
            Chat         = new CG_Chat(this);
            Pause        = new CG_Pause(this);
            PlayerInfo   = new CG_PlayerInfo(this);
            Interact     = new CG_Interact(this);
            GameSettings = new CG_Settings(this);

            // Create bitmap of overwatch client screen capture.
            ScreenshotMethod = screenshotMethod; // Set the screenshot method
            updateScreen();

            OpenChatIsDefault = openChatIsDefault;
            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }

            SetupGameOverCheck();
        }
示例#2
0
 static void SetupWindow(IntPtr hWnd, ScreenshotMethods method)
 {
     if (method == ScreenshotMethods.ScreenCopy)
     {
         User32.SetForegroundWindow(hWnd);
     }
     else
     {
         User32.ShowWindow(hWnd, User32.nCmdShow.SW_SHOWNOACTIVATE);
     }
     User32.MoveWindow(hWnd, -7, 0, shotarea.Width, shotarea.Height, false);
 }
示例#3
0
        static void Screenshot(ScreenshotMethods method, IntPtr hWnd, ref Bitmap bmp)
        {
            // Show the window behind all other opened windows. Screenshot does not work if Overwatch is minimized.
            SetupWindow(hWnd, method);

            if (method == ScreenshotMethods.BitBlt)
            {
                ScreenshotBitBlt(hWnd, ref bmp);
            }
            else if (method == ScreenshotMethods.ScreenCopy)
            {
                ScreenshotScreenCopy(hWnd, ref bmp);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            string header = "Zombiebot v1.2";

            Console.Title = header;
            Console.WriteLine(header);

            string            name             = "Zombies - Infection"; // Default name for the Abyxa server.
            string            region           = "us";                  // Default region for the Abyxa server.
            bool              local            = false;                 // Determines if the Abyxa website is on the local server.
            Event?            owevent          = null;                  // The current overwatch event
            ScreenshotMethods screenshotMethod = ScreenshotMethods.BitBlt;

            // Parse config file
            string[] config    = null;
            string   filecheck = Extra.GetExecutingDirectory() + "config.txt"; // File location of config file.

            try
            {
                config = System.IO.File.ReadAllLines(filecheck);
            }
            catch (Exception ex)
            {
                if (ex is System.IO.DirectoryNotFoundException || ex is System.IO.FileNotFoundException)
                {
                    Console.WriteLine("Could not find configuration file at '{0}', using default settings.", filecheck);
                }
                else
                {
                    Console.WriteLine("Error getting configuration file at '{0}', using default settings.", filecheck);
                }
            }
            if (config != null)
            {
                for (int i = 0; i < config.Length; i++) // For each line in the config file
                {
                    string line = config[i].Trim(' ');
                    if (line.Length >= 2)
                    {
                        if (line[0] == '/' && line[1] == '/')
                        {
                            continue;
                        }
                    }

                    // Remove any text after "//"
                    int index = line.IndexOf("//");
                    if (index > 0)
                    {
                        line = line.Substring(0, index);
                    }
                    // Split line at "="
                    string[] lineSplit = line.Split(new string[] { "=" }, 2, StringSplitOptions.RemoveEmptyEntries);
                    // Trim whitespace
                    for (int lsi = 0; lsi < lineSplit.Length; lsi++)
                    {
                        lineSplit[lsi] = lineSplit[lsi].Trim(' ');
                    }

                    if (lineSplit.Length > 1)
                    {
                        switch (lineSplit[0])
                        {
                        case "local":
                        {
                            if (bool.TryParse(lineSplit[1], out bool set))
                            {
                                local = set;
                            }
                        }
                        break;

                        case "minimumPlayers":
                        {
                            if (int.TryParse(lineSplit[1], out int set) && set >= 0 && set <= 7)
                            {
                                minimumPlayers = set;
                            }
                        }
                        break;

                        case "name":
                        {
                            name = lineSplit[1];
                        }
                        break;

                        case "region":
                        {
                            if (lineSplit[0] == "region" && ValidRegions.Contains(lineSplit[1]))
                            {
                                region = lineSplit[1];
                            }
                        }
                        break;

                        case "DefaultMode":
                        {
                            if (Enum.TryParse(lineSplit[1], out JoinType jointype))
                            {
                                Join = jointype;
                            }
                        }
                        break;

                        case "Event":
                        {
                            if (Enum.TryParse(lineSplit[1], out Event setowevent))
                            {
                                owevent = setowevent;
                            }
                        }
                        break;

                        case "ScreenshotMethod":
                        {
                            if (Enum.TryParse(lineSplit[1], out ScreenshotMethods set))
                            {
                                screenshotMethod = set;
                            }
                        }
                        break;

                        case "version":
                        {
                            if (Int32.TryParse(lineSplit[1], out int set))
                            {
                                if (set == 0 || set == 1)
                                {
                                    version = set;
                                }
                            }
                        }
                        break;
                        }
                    }
                }
            }

            if (Join == null)
            {
                string joinmode = Extra.ConsoleInput("Abyxa or server browser (\"abyxa\"/\"sb\"/\"private\"): ", "abyxa", "sb", "private");
                if (joinmode == "abyxa")
                {
                    Join = JoinType.Abyxa;
                }
                else if (joinmode == "sb")
                {
                    Join = JoinType.ServerBrowser;
                }
                else if (joinmode == "private")
                {
                    Join = JoinType.Private;
                }
            }

            IntPtr useHwnd = new IntPtr();

            while (true)
            {
                Process[] overwatchProcesses = Process.GetProcessesByName("Overwatch");

                if (overwatchProcesses.Length == 0)
                {
                    Console.WriteLine("No Overwatch processes found, press enter to recheck.");
                    Console.ReadLine();
                    continue;
                }

                else if (overwatchProcesses.Length == 1)
                {
                    useHwnd = overwatchProcesses[0].MainWindowHandle;
                    break;
                }

                else if (overwatchProcesses.Length > 1)
                {
                    Console.Write("Click on the Overwatch window to use... ");
                    bool lookingForWindow = true;
                    while (lookingForWindow)
                    {
                        IntPtr hwnd = Extra.GetForegroundWindow();
                        overwatchProcesses = Process.GetProcessesByName("Overwatch");
                        for (int i = 0; i < overwatchProcesses.Length; i++)
                        {
                            if (overwatchProcesses[i].MainWindowHandle == hwnd)
                            {
                                Console.WriteLine("Overwatch window found.");
                                useHwnd          = hwnd;
                                lookingForWindow = false;
                                break;
                            }
                        }
                        System.Threading.Thread.Sleep(500);
                    }
                    break;
                }
            }

            Console.WriteLine("Press return to start.");
            Console.ReadLine();
            Console.WriteLine("Starting...");

            cg = new CustomGame(useHwnd, screenshotMethod);

            // Set the mode enabled
            if (version == 0)
            {
                cg.ModesEnabled = new ModesEnabled()
                {
                    Elimination = true
                };
                maps     = ElimMaps;
                mapsSend = ElimMapsSend;
            }
            else if (version == 1)
            {
                cg.ModesEnabled = new ModesEnabled()
                {
                    TeamDeathmatch = true
                };
                maps     = DmMaps;
                mapsSend = DmMapsSend;
            }

            // Set event
            if (owevent == null)
            {
                cg.CurrentOverwatchEvent = cg.GetCurrentOverwatchEvent();
            }
            else
            {
                cg.CurrentOverwatchEvent = (Event)owevent;
            }

            cg.Command.ListenTo.Add("$VOTE", true);
            cg.Command.SameExecutorCommandUpdate = true;
            cg.Chat.BlockGeneralChat             = true;

            a = null;
            if (Join == JoinType.Abyxa)
            {
                a = new Abyxa(name, region, local);
                a.SetMinimumPlayerCount(minimumPlayers);
                cg.GameSettings.SetJoinSetting(Deltin.CustomGameAutomation.Join.InviteOnly);
            }

            Setup();

            while (true)
            {
                bool pregame = Pregame();
                if (pregame)
                {
                    Ingame();
                }
                else
                {
                    Setup();
                }
            }
        }