コード例 #1
0
        private void BtnLaunch_LeftClick(object sender, EventArgs e)
        {
            SavedGame sg = savedGames[lbSaveGameList.SelectedIndex];

            Logger.Log("Loading saved game " + sg.FileName);

            File.Delete(ProgramConstants.GamePath + ProgramConstants.SPAWNER_SETTINGS);
            StreamWriter sw = new StreamWriter(ProgramConstants.GamePath + ProgramConstants.SPAWNER_SETTINGS);

            sw.WriteLine("; generated by DTA Client");
            sw.WriteLine("[Settings]");
            sw.WriteLine("Scenario=spawnmap.ini");
            sw.WriteLine("SaveGameName=" + sg.FileName);
            sw.WriteLine("LoadSaveGame=Yes");
            sw.WriteLine("SidebarHack=" + ClientConfiguration.Instance.SidebarHack);
            sw.WriteLine("Firestorm=No");
            sw.WriteLine("GameSpeed=" + UserINISettings.Instance.GameSpeed);
            sw.WriteLine();
            sw.Close();

            File.Delete(ProgramConstants.GamePath + "spawnmap.ini");
            sw = new StreamWriter(ProgramConstants.GamePath + "spawnmap.ini");
            sw.WriteLine("[Map]");
            sw.WriteLine("Size=0,0,50,50");
            sw.WriteLine("LocalSize=0,0,50,50");
            sw.WriteLine();
            sw.Close();

            discordHandler?.UpdatePresence(sg.GUIName, true);

            Enabled = false;
            GameProcessLogic.GameProcessExited += GameProcessExited_Callback;

            GameProcessLogic.StartGameProcess();
        }
コード例 #2
0
        /// <summary>
        /// Starts a singleplayer mission.
        /// </summary>
        /// <param name="scenario">The internal name of the scenario.</param>
        /// <param name="requiresAddon">True if the mission is for Firestorm / Enhanced Mode.</param>
        private void LaunchMission(Mission mission)
        {
            bool copyMapsToSpawnmapINI = ClientConfiguration.Instance.CopyMissionsToSpawnmapINI;

            // Gather global flag information
            var globalFlagInfo = new Dictionary <int, bool>();

            if (mission.UsedGlobalVariables.Length > 0)
            {
                for (int i = 0; i < mission.UsedGlobalVariables.Length && i < MAX_GLOBAL_COUNT; i++)
                {
                    string globalFlagName = mission.UsedGlobalVariables[i];

                    CampaignGlobalVariable globalVariable = CampaignHandler.Instance.GlobalVariables.Find(gv => gv.InternalName == globalFlagName);
                    if (globalVariable != null)
                    {
                        // Global flag values default to disabled/false by default,
                        // so we only need to care about enabled flags
                        if (globalVariableValues[i].SelectedIndex > 0)
                        {
                            string flagIndex = globalVariable.Index.ToString(CultureInfo.InvariantCulture);
                            globalFlagInfo.Add(globalVariable.Index, true);
                        }
                    }
                }
            }

            CampaignHandler.Instance.WriteFilesForMission(mission, trbDifficultySelector.Value, globalFlagInfo);

            string difficultyName = DifficultyNames[trbDifficultySelector.Value];

            UserINISettings.Instance.Difficulty.Value = trbDifficultySelector.Value;
            UserINISettings.Instance.SaveSettings();

            ((MainMenuDarkeningPanel)Parent).Hide();

            discordHandler?.UpdatePresence(mission.GUIName, difficultyName, mission.IconPath, true);
            GameProcessLogic.GameProcessExited += GameProcessExited_Callback;

            GameProcessLogic.StartGameProcess(new GameSessionManager(
                                                  new GameSessionInfo(GameSessionType.SINGLEPLAYER,
                                                                      DateTime.Now.Ticks,
                                                                      mission.InternalName,
                                                                      mission.Side,
                                                                      (DifficultyRank)(trbDifficultySelector.Value + 1),
                                                                      globalFlagInfo,
                                                                      isCheater),
                                                  WindowManager.AddCallback));
        }
コード例 #3
0
        /// <summary>
        /// Starts a singleplayer mission.
        /// </summary>
        /// <param name="scenario">The internal name of the scenario.</param>
        /// <param name="requiresAddon">True if the mission is for Firestorm / Enhanced Mode.</param>
        private void LaunchMission(Mission mission)
        {
            bool copyMapsToSpawnmapINI = ClientConfiguration.Instance.CopyMissionsToSpawnmapINI;

            Logger.Log("About to write spawn.ini.");
            StreamWriter swriter = new StreamWriter(ProgramConstants.GamePath + "spawn.ini");

            swriter.WriteLine("; Generated by DTA Client");
            swriter.WriteLine("[Settings]");
            if (copyMapsToSpawnmapINI)
            {
                swriter.WriteLine("Scenario=spawnmap.ini");
            }
            else
            {
                swriter.WriteLine("Scenario=" + mission.Scenario);
            }

            // No one wants to play missions on Fastest, so we'll change it to Faster
            if (UserINISettings.Instance.GameSpeed == 0)
            {
                UserINISettings.Instance.GameSpeed.Value = 1;
            }

            swriter.WriteLine("GameSpeed=" + UserINISettings.Instance.GameSpeed);
            swriter.WriteLine("Firestorm=" + mission.RequiredAddon);
            swriter.WriteLine("CustomLoadScreen=" + LoadingScreenController.GetLoadScreenName(mission.Side.ToString()));
            swriter.WriteLine("IsSinglePlayer=Yes");
            swriter.WriteLine("SidebarHack=" + ClientConfiguration.Instance.SidebarHack);
            swriter.WriteLine("Side=" + mission.Side);
            swriter.WriteLine("BuildOffAlly=" + mission.BuildOffAlly);

            UserINISettings.Instance.Difficulty.Value = trbDifficultySelector.Value;

            swriter.WriteLine("DifficultyModeHuman=" + (mission.PlayerAlwaysOnNormalDifficulty ? "1" : trbDifficultySelector.Value.ToString()));
            swriter.WriteLine("DifficultyModeComputer=" + GetComputerDifficulty());

            IniFile difficultyIni  = new IniFile(ProgramConstants.GamePath + DifficultyIniPaths[trbDifficultySelector.Value]);
            string  difficultyName = DifficultyNames[trbDifficultySelector.Value];

            swriter.WriteLine();
            swriter.WriteLine();
            swriter.WriteLine();
            swriter.Close();

            if (copyMapsToSpawnmapINI)
            {
                IniFile mapIni = new IniFile(ProgramConstants.GamePath + mission.Scenario);
                IniFile.ConsolidateIniFiles(mapIni, difficultyIni);
                mapIni.WriteIniFile(ProgramConstants.GamePath + "spawnmap.ini");
            }

            UserINISettings.Instance.Difficulty.Value = trbDifficultySelector.Value;
            UserINISettings.Instance.SaveSettings();

            ((MainMenuDarkeningPanel)Parent).Hide();

            discordHandler?.UpdatePresence(mission.GUIName, difficultyName, mission.IconPath, true);
            GameProcessLogic.GameProcessExited += GameProcessExited_Callback;

            GameProcessLogic.StartGameProcess();
        }
コード例 #4
0
        /// <summary>
        /// Starts a singleplayer mission.
        /// </summary>
        /// <param name="scenario">The internal name of the scenario.</param>
        /// <param name="requiresAddon">True if the mission is for Firestorm / Enhanced Mode.</param>
        private void LaunchMission(Mission mission)
        {
            bool copyMapsToSpawnmapINI = ClientConfiguration.Instance.CopyMissionsToSpawnmapINI;

            Logger.Log("About to write spawn.ini.");
            StreamWriter swriter = new StreamWriter(MainClientConstants.gamepath + "spawn.ini");

            swriter.WriteLine("; Generated by DTA Client");
            swriter.WriteLine("[Settings]");
            if (copyMapsToSpawnmapINI)
            {
                swriter.WriteLine("Scenario=spawnmap.ini");
            }
            else
            {
                swriter.WriteLine("Scenario=" + mission.Scenario);
            }

            // No one wants to play missions on Fastest, so we'll change it to Faster
            if (UserINISettings.Instance.GameSpeed == 0)
            {
                UserINISettings.Instance.GameSpeed.Value = 1;
            }

            swriter.WriteLine("GameSpeed=" + UserINISettings.Instance.GameSpeed);
            swriter.WriteLine("Firestorm=" + mission.RequiredAddon);
            swriter.WriteLine("CustomLoadScreen=" + LoadingScreenController.GetLoadScreenName(mission.Side));
            swriter.WriteLine("IsSinglePlayer=Yes");
            swriter.WriteLine("SidebarHack=" + ClientConfiguration.Instance.SidebarHack);
            swriter.WriteLine("Side=" + mission.Side);
            swriter.WriteLine("BuildOffAlly=" + mission.BuildOffAlly);

            IniFile difficultyIni;

            UserINISettings.Instance.Difficulty.Value = trbDifficultySelector.Value;
            if (trbDifficultySelector.Value == 0) // Easy
            {
                swriter.WriteLine("DifficultyModeHuman=0");
                swriter.WriteLine("DifficultyModeComputer=2");
                difficultyIni = new IniFile(ProgramConstants.GamePath + "INI\\Map Code\\Difficulty Easy.ini");
            }
            else if (trbDifficultySelector.Value == 1) // Normal
            {
                swriter.WriteLine("DifficultyModeHuman=1");
                swriter.WriteLine("DifficultyModeComputer=1");
                difficultyIni = new IniFile(ProgramConstants.GamePath + "INI\\Map Code\\Difficulty Medium.ini");
            }
            else //if (tbDifficultyLevel.Value == 2) // Hard
            {
                swriter.WriteLine("DifficultyModeHuman=2");
                swriter.WriteLine("DifficultyModeComputer=0");
                difficultyIni = new IniFile(ProgramConstants.GamePath + "INI\\Map Code\\Difficulty Hard.ini");
            }
            swriter.WriteLine();
            swriter.WriteLine();
            swriter.WriteLine();
            swriter.Close();

            if (copyMapsToSpawnmapINI)
            {
                IniFile mapIni = new IniFile(ProgramConstants.GamePath + mission.Scenario);
                IniFile.ConsolidateIniFiles(mapIni, difficultyIni);
                mapIni.WriteIniFile(ProgramConstants.GamePath + "spawnmap.ini");
            }

            UserINISettings.Instance.Difficulty.Value = trbDifficultySelector.Value;
            UserINISettings.Instance.SaveSettings();

            Logger.Log("About to launch main executable.");

            ((MainMenuDarkeningPanel)Parent).Hide();
            GameProcessLogic.StartGameProcess(0);
        }
コード例 #5
0
        protected void LoadGame()
        {
            File.Delete(ProgramConstants.GamePath + "spawn.ini");

            File.Copy(ProgramConstants.GamePath + "Saved Games\\spawnSG.ini", ProgramConstants.GamePath + "spawn.ini");

            IniFile spawnIni = new IniFile(ProgramConstants.GamePath + "spawn.ini");

            int sgIndex = (ddSavedGame.Items.Count - 1) - ddSavedGame.SelectedIndex;

            spawnIni.SetStringValue("Settings", "SaveGameName",
                                    string.Format("SVGM_{0}.NET", sgIndex.ToString("D3")));
            spawnIni.SetBooleanValue("Settings", "LoadSaveGame", true);

            PlayerInfo localPlayer = Players.Find(p => p.Name == ProgramConstants.PLAYERNAME);

            if (localPlayer == null)
            {
                return;
            }

            spawnIni.SetIntValue("Settings", "Port", localPlayer.Port);

            for (int i = 1; i < Players.Count; i++)
            {
                string otherName = spawnIni.GetStringValue("Other" + i, "Name", string.Empty);

                if (string.IsNullOrEmpty(otherName))
                {
                    continue;
                }

                PlayerInfo otherPlayer = Players.Find(p => p.Name == otherName);

                if (otherPlayer == null)
                {
                    continue;
                }

                spawnIni.SetStringValue("Other" + i, "Ip", otherPlayer.IPAddress);
                spawnIni.SetIntValue("Other" + i, "Port", otherPlayer.Port);
            }

            WriteSpawnIniAdditions(spawnIni);
            spawnIni.WriteIniFile();

            File.Delete(ProgramConstants.GamePath + "spawnmap.ini");
            StreamWriter sw = new StreamWriter(ProgramConstants.GamePath + "spawnmap.ini");

            sw.WriteLine("[Map]");
            sw.WriteLine("Size=0,0,50,50");
            sw.WriteLine("LocalSize=0,0,50,50");
            sw.WriteLine();
            sw.Close();

            gameLoadTime = DateTime.Now;

            GameProcessLogic.GameProcessExited += SharedUILogic_GameProcessExited;
            GameProcessLogic.StartGameProcess();

            fsw.EnableRaisingEvents = true;
        }
コード例 #6
0
        private void BtnLaunch_LeftClick(object sender, EventArgs e)
        {
            SavedGame sg = savedGames[lbSaveGameList.SelectedIndex];

            Logger.Log("Loading saved game " + sg.FilePath);

            var gameSessionInfo = new GameSessionManager(sg.SessionInfo, WindowManager.AddCallback);

            gameSessionInfo.StartSession(); // Starting the session copies the saved games for this session to the main saved games directory

            bool writeNewSpawnIni = true;

            if (sg.SessionInfo.SessionType == GameSessionType.SINGLEPLAYER)
            {
                var mission = CampaignHandler.Instance.Missions.Find(m => m.InternalName == sg.SessionInfo.MissionInternalName);

                if (mission == null)
                {
                    Logger.Log("Mission entry for " + sg.SessionInfo.MissionInternalName + " not found when loading game, " +
                               "unable to write the actual singleplayer mission file to directory for restarts.");
                }
                else
                {
                    CampaignHandler.Instance.WriteFilesForMission(mission, (int)sg.SessionInfo.Difficulty - 1, sg.SessionInfo.GlobalFlagValues);
                    writeNewSpawnIni = false;
                }
            }

            int       nextAutoSaveId       = -1;
            const int AutoSaveStringLength = 8;

            if (sg.FileName.StartsWith("AUTOSAVE") && sg.FileName.Length > AutoSaveStringLength)
            {
                // Parse and assign next auto-save number
                int pointIndex = sg.FileName.IndexOf('.');
                if (pointIndex > -1)
                {
                    // The spawner increments the ID by 1 before actually saving
                    nextAutoSaveId = Conversions.IntFromString(sg.FileName.Substring(AutoSaveStringLength, 1), -1);
                }
            }

            if (writeNewSpawnIni)
            {
                Logger.Log($"Writing new {ProgramConstants.SPAWNER_SETTINGS} for loading game.");

                File.Delete(ProgramConstants.GamePath + ProgramConstants.SPAWNER_SETTINGS);

                using (StreamWriter sw = new StreamWriter(ProgramConstants.GamePath + ProgramConstants.SPAWNER_SETTINGS))
                {
                    sw.WriteLine("; generated by DTA Client");
                    sw.WriteLine("[Settings]");
                    sw.WriteLine("Scenario=spawnmap.ini");
                    sw.WriteLine("SaveGameName=" + sg.FileName);
                    sw.WriteLine("LoadSaveGame=Yes");
                    sw.WriteLine("SidebarHack=" + ClientConfiguration.Instance.SidebarHack);
                    sw.WriteLine("Firestorm=No");
                    sw.WriteLine("GameSpeed=" + UserINISettings.Instance.GameSpeed);
                    if (UserINISettings.Instance.EnableSPAutoSave)
                    {
                        sw.WriteLine("AutoSaveGame=" + ClientConfiguration.Instance.SinglePlayerAutoSaveInterval);
                        sw.WriteLine("NextSPAutoSaveId=" + nextAutoSaveId);
                    }
                }

                File.Delete(ProgramConstants.GamePath + "spawnmap.ini");
                using (var sw = new StreamWriter(ProgramConstants.GamePath + "spawnmap.ini"))
                {
                    sw.WriteLine("[Map]");
                    sw.WriteLine("Size=0,0,50,50");
                    sw.WriteLine("LocalSize=0,0,50,50");
                    sw.WriteLine();
                    sw.Close();
                }
            }
            else
            {
                Logger.Log($"Appending game loading settings to {ProgramConstants.SPAWNER_SETTINGS}.");

                var spawnIni = new IniFile(ProgramConstants.GamePath + ProgramConstants.SPAWNER_SETTINGS);
                spawnIni.SetBooleanValue("Settings", "LoadSaveGame", true);
                spawnIni.SetStringValue("Settings", "SaveGameName", sg.FileName);
                if (UserINISettings.Instance.EnableSPAutoSave)
                {
                    spawnIni.SetIntValue("Settings", "AutoSaveGame", ClientConfiguration.Instance.SinglePlayerAutoSaveInterval);
                    spawnIni.SetIntValue("Settings", "NextSPAutoSaveId", nextAutoSaveId);
                }

                spawnIni.WriteIniFile();
            }

            discordHandler?.UpdatePresence(sg.GUIName, true);

            Enabled = false;
            GameProcessLogic.GameProcessExited += GameProcessExited_Callback;

            GameProcessLogic.StartGameProcess(gameSessionInfo);
        }
コード例 #7
0
        protected void LoadGame()
        {
            File.Delete(ProgramConstants.GamePath + "spawn.ini");

            File.Copy(ProgramConstants.GamePath + ProgramConstants.SAVED_GAME_SPAWN_INI, ProgramConstants.GamePath + "spawn.ini");

            IniFile spawnIni = new IniFile(ProgramConstants.GamePath + "spawn.ini");

            int    sgIndex    = (ddSavedGame.Items.Count - 1) - ddSavedGame.SelectedIndex;
            string sgFileName = string.Format("SVGM_{0}.NET", sgIndex.ToString("D3"));

            spawnIni.SetStringValue("Settings", "SaveGameName", sgFileName);
            spawnIni.SetBooleanValue("Settings", "LoadSaveGame", true);

            PlayerInfo localPlayer = Players.Find(p => p.Name == ProgramConstants.PLAYERNAME);

            if (localPlayer == null)
            {
                return;
            }

            spawnIni.SetIntValue("Settings", "Port", localPlayer.Port);

            for (int i = 1; i < Players.Count; i++)
            {
                string otherName = spawnIni.GetStringValue("Other" + i, "Name", string.Empty);

                if (string.IsNullOrEmpty(otherName))
                {
                    continue;
                }

                PlayerInfo otherPlayer = Players.Find(p => p.Name == otherName);

                if (otherPlayer == null)
                {
                    continue;
                }

                spawnIni.SetStringValue("Other" + i, "Ip", otherPlayer.IPAddress);
                spawnIni.SetIntValue("Other" + i, "Port", otherPlayer.Port);
            }

            WriteSpawnIniAdditions(spawnIni);
            spawnIni.WriteIniFile();

            File.Delete(ProgramConstants.GamePath + "spawnmap.ini");
            StreamWriter sw = new StreamWriter(ProgramConstants.GamePath + "spawnmap.ini");

            sw.WriteLine("[Map]");
            sw.WriteLine("Size=0,0,50,50");
            sw.WriteLine("LocalSize=0,0,50,50");
            sw.WriteLine();
            sw.Close();

            gameLoadTime = DateTime.Now;

            string saveFilePath = ProgramConstants.GamePath + MultiplayerSaveGameManager.SAVED_GAMES_MP_DIRECTORY + "/" + sgFileName;
            string metaFilePath = Path.ChangeExtension(saveFilePath, GameSessionManager.SavedGameMetaExtension);
            var    meta         = GameSessionInfo.ParseFromFile(metaFilePath);

            if (meta == null)
            {
                XNAMessageBox.Show(WindowManager, "Failed to load saved multiplayer game", "Failed to load saved game: saved game meta could not be parsed!");
                return;
            }

            var gameSessionInfo = new GameSessionManager(new GameSessionInfo(GameSessionType.MULTIPLAYER, meta.UniqueId), WindowManager.AddCallback);

            gameSessionInfo.StartSession();
            GameProcessLogic.GameProcessExited += SharedUILogic_GameProcessExited;
            GameProcessLogic.StartGameProcess(gameSessionInfo);

            UpdateDiscordPresence(true);
        }