Example #1
0
        // TODO: DRY
        /// <summary>
        /// Returns false if no player config file was found, in which case a new file is created.
        /// </summary>
        private bool LoadPlayerConfigInternal()
        {
            XDocument doc = XMLExtensions.LoadXml(playerSavePath);

            if (doc == null || doc.Root == null)
            {
                ShowUserStatisticsPrompt = true;
                return(false);
            }
            LoadGeneralSettings(doc);
            LoadGraphicSettings(doc);
            LoadAudioSettings(doc);
            LoadControls(doc);
            LoadContentPackages(doc);

            XElement tutorialsElement = doc.Root.Element("tutorials");

            if (tutorialsElement != null)
            {
                foreach (XElement element in tutorialsElement.Elements())
                {
                    CompletedTutorialNames.Add(element.GetAttributeString("name", ""));
                }
            }

            UnsavedSettings = false;
            return(true);
        }
Example #2
0
        // TODO: DRY
        /// <summary>
        /// Returns false if no player config file was found, in which case a new file is created.
        /// </summary>
        private bool LoadPlayerConfigInternal()
        {
            XDocument doc = XMLExtensions.LoadXml(playerSavePath);

            if (doc == null || doc.Root == null)
            {
                ShowUserStatisticsPrompt = true;
                return(false);
            }
            LoadGeneralSettings(doc);
            LoadGraphicSettings(doc);
            LoadAudioSettings(doc);
            LoadControls(doc);
            LoadContentPackages(doc);

            //allow overriding the save paths in the config file
            if (doc.Root.Attribute("overridesavefolder") != null)
            {
                overrideSaveFolder            = SaveUtil.SaveFolder = doc.Root.GetAttributeString("overridesavefolder", "");
                overrideMultiplayerSaveFolder = SaveUtil.MultiplayerSaveFolder = Path.Combine(overrideSaveFolder, "Multiplayer");
            }
            if (doc.Root.Attribute("overridemultiplayersavefolder") != null)
            {
                overrideMultiplayerSaveFolder = SaveUtil.MultiplayerSaveFolder = doc.Root.GetAttributeString("overridemultiplayersavefolder", "");
            }

            XElement tutorialsElement = doc.Root.Element("tutorials");

            if (tutorialsElement != null)
            {
                foreach (XElement element in tutorialsElement.Elements())
                {
                    CompletedTutorialNames.Add(element.GetAttributeString("name", ""));
                }
            }

            UnsavedSettings = false;
            return(true);
        }
Example #3
0
        public void SaveNewPlayerConfig()
        {
            XDocument doc = new XDocument();

            UnsavedSettings = false;

            if (doc.Root == null)
            {
                doc.Add(new XElement("config"));
            }

            doc.Root.Add(
                new XAttribute("language", TextManager.Language),
                new XAttribute("masterserverurl", MasterServerUrl),
                new XAttribute("autocheckupdates", AutoCheckUpdates),
                new XAttribute("musicvolume", musicVolume),
                new XAttribute("soundvolume", soundVolume),
                new XAttribute("verboselogging", VerboseLogging),
                new XAttribute("savedebugconsolelogs", SaveDebugConsoleLogs),
                new XAttribute("enablesplashscreen", EnableSplashScreen),
                new XAttribute("usesteammatchmaking", useSteamMatchmaking),
                new XAttribute("quickstartsub", QuickStartSubmarineName),
                new XAttribute("requiresteamauthentication", requireSteamAuthentication),
                new XAttribute("autoupdateworkshopitems", AutoUpdateWorkshopItems),
                new XAttribute("pauseonfocuslost", PauseOnFocusLost),
                new XAttribute("aimassistamount", aimAssistAmount),
                new XAttribute("enablemouselook", EnableMouseLook),
                new XAttribute("chatopen", ChatOpen),
                new XAttribute("crewmenuopen", CrewMenuOpen),
                new XAttribute("campaigndisclaimershown", CampaignDisclaimerShown),
                new XAttribute("editordisclaimershown", EditorDisclaimerShown));

            if (!string.IsNullOrEmpty(overrideSaveFolder))
            {
                doc.Root.Add(new XAttribute("overridesavefolder", overrideSaveFolder));
            }
            if (!string.IsNullOrEmpty(overrideMultiplayerSaveFolder))
            {
                doc.Root.Add(new XAttribute("overridemultiplayersavefolder", overrideMultiplayerSaveFolder));
            }

            if (!ShowUserStatisticsPrompt)
            {
                doc.Root.Add(new XAttribute("senduserstatistics", sendUserStatistics));
            }

            XElement gMode = doc.Root.Element("graphicsmode");

            if (gMode == null)
            {
                gMode = new XElement("graphicsmode");
                doc.Root.Add(gMode);
            }

            if (GraphicsWidth == 0 || GraphicsHeight == 0)
            {
                gMode.ReplaceAttributes(new XAttribute("displaymode", windowMode));
            }
            else
            {
                gMode.ReplaceAttributes(
                    new XAttribute("width", GraphicsWidth),
                    new XAttribute("height", GraphicsHeight),
                    new XAttribute("vsync", VSyncEnabled),
                    new XAttribute("displaymode", windowMode));
            }

            XElement audio = doc.Root.Element("audio");

            if (audio == null)
            {
                audio = new XElement("audio");
                doc.Root.Add(audio);
            }
            audio.ReplaceAttributes(
                new XAttribute("musicvolume", musicVolume),
                new XAttribute("soundvolume", soundVolume),
                new XAttribute("voicechatvolume", voiceChatVolume),
                new XAttribute("microphonevolume", microphoneVolume),
                new XAttribute("muteonfocuslost", MuteOnFocusLost),
                new XAttribute("usedirectionalvoicechat", UseDirectionalVoiceChat),
                new XAttribute("voicesetting", VoiceSetting),
                new XAttribute("voicecapturedevice", VoiceCaptureDevice ?? ""),
                new XAttribute("noisegatethreshold", NoiseGateThreshold));

            XElement gSettings = doc.Root.Element("graphicssettings");

            if (gSettings == null)
            {
                gSettings = new XElement("graphicssettings");
                doc.Root.Add(gSettings);
            }

            gSettings.ReplaceAttributes(
                new XAttribute("particlelimit", ParticleLimit),
                new XAttribute("lightmapscale", LightMapScale),
                new XAttribute("specularity", SpecularityEnabled),
                new XAttribute("chromaticaberration", ChromaticAberrationEnabled),
                new XAttribute("losmode", LosMode),
                new XAttribute("hudscale", HUDScale),
                new XAttribute("inventoryscale", InventoryScale));

            foreach (ContentPackage contentPackage in SelectedContentPackages)
            {
                doc.Root.Add(new XElement("contentpackage",
                                          new XAttribute("path", contentPackage.Path)));
            }

            var keyMappingElement = new XElement("keymapping");

            doc.Root.Add(keyMappingElement);
            for (int i = 0; i < keyMapping.Length; i++)
            {
                if (keyMapping[i].MouseButton == null)
                {
                    keyMappingElement.Add(new XAttribute(((InputType)i).ToString(), keyMapping[i].Key));
                }
                else
                {
                    keyMappingElement.Add(new XAttribute(((InputType)i).ToString(), keyMapping[i].MouseButton));
                }
            }

            var gameplay       = new XElement("gameplay");
            var jobPreferences = new XElement("jobpreferences");

            foreach (string jobName in JobPreferences)
            {
                jobPreferences.Add(new XElement("job", new XAttribute("identifier", jobName)));
            }
            gameplay.Add(jobPreferences);
            doc.Root.Add(gameplay);

            var playerElement = new XElement("player",
                                             new XAttribute("name", defaultPlayerName ?? ""),
                                             new XAttribute("headindex", CharacterHeadIndex),
                                             new XAttribute("gender", CharacterGender),
                                             new XAttribute("race", CharacterRace),
                                             new XAttribute("hairindex", CharacterHairIndex),
                                             new XAttribute("beardindex", CharacterBeardIndex),
                                             new XAttribute("moustacheindex", CharacterMoustacheIndex),
                                             new XAttribute("faceattachmentindex", CharacterFaceAttachmentIndex));

            doc.Root.Add(playerElement);

#if CLIENT
            if (Tutorial.Tutorials != null)
            {
                foreach (Tutorial tutorial in Tutorial.Tutorials)
                {
                    if (tutorial.Completed && !CompletedTutorialNames.Contains(tutorial.Identifier))
                    {
                        CompletedTutorialNames.Add(tutorial.Identifier);
                    }
                }
            }
#endif
            var tutorialElement = new XElement("tutorials");
            foreach (string tutorialName in CompletedTutorialNames)
            {
                tutorialElement.Add(new XElement("Tutorial", new XAttribute("name", tutorialName)));
            }
            doc.Root.Add(tutorialElement);

            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent              = true,
                OmitXmlDeclaration  = true,
                NewLineOnAttributes = true
            };

            try
            {
                using (var writer = XmlWriter.Create(playerSavePath, settings))
                {
                    doc.WriteTo(writer);
                    writer.Flush();
                }
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Saving game settings failed.", e);
                GameAnalyticsManager.AddErrorEventOnce("GameSettings.Save:SaveFailed", GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
                                                       "Saving game settings failed.\n" + e.Message + "\n" + e.StackTrace);
            }
        }
Example #4
0
        // TODO: DRY
        /// <summary>
        /// Returns false if no player config file was found, in which case a new file is created.
        /// </summary>
        private bool LoadPlayerConfigInternal()
        {
            XDocument doc = XMLExtensions.LoadXml(playerSavePath);

            if (doc == null || doc.Root == null)
            {
                ShowUserStatisticsPrompt = true;
                return(false);
            }

            Language           = doc.Root.GetAttributeString("language", Language);
            AutoCheckUpdates   = doc.Root.GetAttributeBool("autocheckupdates", AutoCheckUpdates);
            sendUserStatistics = doc.Root.GetAttributeBool("senduserstatistics", true);

            XElement graphicsMode = doc.Root.Element("graphicsmode");

            GraphicsWidth  = graphicsMode.GetAttributeInt("width", GraphicsWidth);
            GraphicsHeight = graphicsMode.GetAttributeInt("height", GraphicsHeight);
            VSyncEnabled   = graphicsMode.GetAttributeBool("vsync", VSyncEnabled);

            XElement graphicsSettings = doc.Root.Element("graphicssettings");

            ParticleLimit              = graphicsSettings.GetAttributeInt("particlelimit", ParticleLimit);
            LightMapScale              = MathHelper.Clamp(graphicsSettings.GetAttributeFloat("lightmapscale", LightMapScale), 0.1f, 1.0f);
            SpecularityEnabled         = graphicsSettings.GetAttributeBool("specularity", SpecularityEnabled);
            ChromaticAberrationEnabled = graphicsSettings.GetAttributeBool("chromaticaberration", ChromaticAberrationEnabled);
            HUDScale       = graphicsSettings.GetAttributeFloat("hudscale", HUDScale);
            InventoryScale = graphicsSettings.GetAttributeFloat("inventoryscale", InventoryScale);
            var losModeStr = graphicsSettings.GetAttributeString("losmode", "Transparent");

            if (!Enum.TryParse(losModeStr, out losMode))
            {
                losMode = LosMode.Transparent;
            }

#if CLIENT
            if (GraphicsWidth == 0 || GraphicsHeight == 0)
            {
                GraphicsWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
                GraphicsHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            }
#endif

            var windowModeStr = graphicsMode.GetAttributeString("displaymode", "Fullscreen");
            if (!Enum.TryParse(windowModeStr, out windowMode))
            {
                windowMode = WindowMode.Fullscreen;
            }

            XElement audioSettings = doc.Root.Element("audio");
            if (audioSettings != null)
            {
                SoundVolume             = audioSettings.GetAttributeFloat("soundvolume", SoundVolume);
                MusicVolume             = audioSettings.GetAttributeFloat("musicvolume", MusicVolume);
                VoiceChatVolume         = audioSettings.GetAttributeFloat("voicechatvolume", VoiceChatVolume);
                MuteOnFocusLost         = audioSettings.GetAttributeBool("muteonfocuslost", false);
                UseDirectionalVoiceChat = audioSettings.GetAttributeBool("usedirectionalvoicechat", true);
                string voiceSettingStr = audioSettings.GetAttributeString("voicesetting", "Disabled");
                VoiceCaptureDevice = audioSettings.GetAttributeString("voicecapturedevice", "");
                NoiseGateThreshold = audioSettings.GetAttributeFloat("noisegatethreshold", -45);
                var voiceSetting = VoiceMode.Disabled;
                if (Enum.TryParse(voiceSettingStr, out voiceSetting))
                {
                    VoiceSetting = voiceSetting;
                }
            }

            useSteamMatchmaking        = doc.Root.GetAttributeBool("usesteammatchmaking", useSteamMatchmaking);
            requireSteamAuthentication = doc.Root.GetAttributeBool("requiresteamauthentication", requireSteamAuthentication);

            EnableSplashScreen = doc.Root.GetAttributeBool("enablesplashscreen", EnableSplashScreen);

            PauseOnFocusLost = doc.Root.GetAttributeBool("pauseonfocuslost", PauseOnFocusLost);
            AimAssistAmount  = doc.Root.GetAttributeFloat("aimassistamount", AimAssistAmount);
            EnableMouseLook  = doc.Root.GetAttributeBool("enablemouselook", EnableMouseLook);

            CrewMenuOpen = doc.Root.GetAttributeBool("crewmenuopen", CrewMenuOpen);
            ChatOpen     = doc.Root.GetAttributeBool("chatopen", ChatOpen);

            CampaignDisclaimerShown = doc.Root.GetAttributeBool("campaigndisclaimershown", false);
            EditorDisclaimerShown   = doc.Root.GetAttributeBool("editordisclaimershown", false);

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "keymapping":
                    LoadKeyBinds(subElement);
                    break;

                case "gameplay":
                    jobPreferences = new List <string>();
                    foreach (XElement ele in subElement.Element("jobpreferences").Elements("job"))
                    {
                        string jobIdentifier = ele.GetAttributeString("identifier", "");
                        if (string.IsNullOrEmpty(jobIdentifier))
                        {
                            continue;
                        }
                        jobPreferences.Add(jobIdentifier);
                    }
                    break;

                case "player":
                    defaultPlayerName  = subElement.GetAttributeString("name", defaultPlayerName);
                    CharacterHeadIndex = subElement.GetAttributeInt("headindex", CharacterHeadIndex);
                    if (Enum.TryParse(subElement.GetAttributeString("gender", "none"), true, out Gender g))
                    {
                        CharacterGender = g;
                    }
                    if (Enum.TryParse(subElement.GetAttributeString("race", "white"), true, out Race r))
                    {
                        CharacterRace = r;
                    }
                    else
                    {
                        CharacterRace = Race.White;
                    }
                    CharacterHairIndex           = subElement.GetAttributeInt("hairindex", CharacterHairIndex);
                    CharacterBeardIndex          = subElement.GetAttributeInt("beardindex", CharacterBeardIndex);
                    CharacterMoustacheIndex      = subElement.GetAttributeInt("moustacheindex", CharacterMoustacheIndex);
                    CharacterFaceAttachmentIndex = subElement.GetAttributeInt("faceattachmentindex", CharacterFaceAttachmentIndex);
                    break;

                case "tutorials":
                    foreach (XElement tutorialElement in subElement.Elements())
                    {
                        CompletedTutorialNames.Add(tutorialElement.GetAttributeString("name", ""));
                    }
                    break;
                }
            }

            UnsavedSettings = false;

            selectedContentPackagePaths = new HashSet <string>();

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "contentpackage":
                    string path = System.IO.Path.GetFullPath(subElement.GetAttributeString("path", ""));
                    selectedContentPackagePaths.Add(path);
                    break;
                }
            }

            LoadContentPackages(selectedContentPackagePaths);
            return(true);
        }