示例#1
0
        public static Config ParseConfig()
        {
            string configLocation = Extra.GetExecutingDirectory() + "config.xml";

            if (!File.Exists(configLocation))
            {
                Log("Could not find config file, using defaults.");
                return(new Config());
            }

            XDocument document = XDocument.Load(configLocation);

            return(new Config()
            {
                Version = ParseString(document, "version", "elim", "tdm") == "elim" ? 0 : 1,
                MinimumPlayers = ParseInt(document, "minimumPlayers", min: 0, max: 7, @default: 5),
                DefaultMode = ParseString(document, "defaultMode", "abyxa", "serverbrowser", "private"),
                OverwatchEvent = ParseString(document, "overwatchEvent", OWEvent.None),
                ScreenshotMethod = ParseString(document, "screenshotMethod", ScreenshotMethod.BitBlt),
                Preset = ParseString(document, "preset", @default: "")
                         .Trim(),

                Name = ParseString(document, "name", "Zombies - Infection"),
                Region = ParseString(document, "region", "us", "eu", "kr"),

                BattlenetExecutable = ParseString(document, "battlenetExecutable", new OverwatchInfoAuto().BattlenetExecutableFilePath),
                OverwatchSettingsFile = ParseString(document, "overwatchSettingsFile", new OverwatchInfoAuto().OverwatchSettingsFilePath)
                                        .Replace("{username}", Environment.UserName),

                Local = Exists(document, "local")
            });
        }
示例#2
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();
                }
            }
        }