public static LoadGameResult LoadSaveGameData( string saveName, string[] loadedModuleNames) { List <ModuleInfo> modules = MBSaveLoad.GetModules(loadedModuleNames); MBSaveLoad.InitializeAutoSaveIndex(saveName); string fileName = saveName + ".sav"; ISaveDriver driver = MBSaveLoad._saveDriver; driver.SetFileName(fileName); ApplicationVersion applicationVersion = driver.LoadMetaData().GetApplicationVersion(); if (applicationVersion.Major <= 1 && applicationVersion.Minor <= 4 && applicationVersion.Revision < 2) { driver = (ISaveDriver) new OldFileDriver(); driver.SetFileName(fileName); } LoadResult loadResult = SaveManager.Load(driver, true); if (loadResult.Successful) { MBSaveLoad.ActiveSaveSlotName = !MBSaveLoad.IsSaveFileNameReserved(saveName) ? saveName : (string)null; return(new LoadGameResult(loadResult, MBSaveLoad.CheckModules(loadResult.MetaData, modules))); } Debug.Print("Error: Could not load the game!"); return((LoadGameResult)null); }
private static void InitializeAutoSaveIndex(string saveName) { string str = ""; if (saveName.Contains(MBSaveLoad.AutoSaveNamePrefix)) { str = saveName; } else { foreach (string saveFileName in MBSaveLoad.GetSaveFileNames()) { if (saveFileName.Contains(MBSaveLoad.AutoSaveNamePrefix)) { str = saveFileName; break; } } } if (str.IsStringNoneOrEmpty()) { MBSaveLoad.AutoSaveIndex = 1; } else { string[] strArray = str.Split('_'); int result; if (strArray.Length != 3 || !int.TryParse(strArray[strArray.Length - 1], out result) || (result <= 0 || result > 3)) { return; } MBSaveLoad.AutoSaveIndex = result; } }
public static bool AutoSaveCurrentGame(CampaignSaveMetaDataArgs campaignMetaData) { MetaData saveMetaData = MBSaveLoad.GetSaveMetaData(campaignMetaData); MBSaveLoad.IncrementAutoSaveIndex(); string autoSaveName = MBSaveLoad.GetAutoSaveName(); return(MBSaveLoad.OverwriteSaveFile(saveMetaData, autoSaveName)); }
public static bool SaveAsCurrentGame(CampaignSaveMetaDataArgs campaignMetaData, string saveName) { int num = MBSaveLoad.OverwriteSaveFile(MBSaveLoad.GetSaveMetaData(campaignMetaData), saveName) ? 1 : 0; if (num == 0) { return(num != 0); } MBSaveLoad.ActiveSaveSlotName = saveName; return(num != 0); }
public static bool QuickSaveCurrentGame(CampaignSaveMetaDataArgs campaignMetaData) { MetaData saveMetaData = MBSaveLoad.GetSaveMetaData(campaignMetaData); if (MBSaveLoad.ActiveSaveSlotName == null) { MBSaveLoad.ActiveSaveSlotName = MBSaveLoad.GetNextAvailableSaveName(); } string activeSaveSlotName = MBSaveLoad.ActiveSaveSlotName; return(MBSaveLoad.OverwriteSaveFile(saveMetaData, activeSaveSlotName)); }
private static string GetNextAvailableSaveName() { uint num1 = 0; foreach (string saveFileName in MBSaveLoad.GetSaveFileNames()) { uint result; if (saveFileName.StartsWith(MBSaveLoad.DefaultSaveGamePrefix) && uint.TryParse(saveFileName.Substring(MBSaveLoad.DefaultSaveGamePrefix.Length), out result) && result > num1) { num1 = result; } } uint num2 = num1 + 1U; return(MBSaveLoad.DefaultSaveGamePrefix + num2.ToString("000")); }
private static MetaData GetSaveMetaData(CampaignSaveMetaDataArgs data) { MetaData metaData = new MetaData(); List <ModuleInfo> modules = MBSaveLoad.GetModules(data.ModuleNames); metaData["Modules"] = string.Join(";", modules.Select <ModuleInfo, string>((Func <ModuleInfo, string>)(q => q.Name))); foreach (ModuleInfo moduleInfo in modules) { metaData["Module_" + moduleInfo.Name] = moduleInfo.Version.ToString(); } metaData.Add("ApplicationVersion", ApplicationVersion.FromParametersFile(ApplicationVersionGameType.Singleplayer).ToString()); metaData.Add("CreationTime", DateTime.Now.ToString()); foreach (KeyValuePair <string, string> keyValuePair in data.OtherData) { metaData.Add(keyValuePair.Key, keyValuePair.Value); } return(metaData); }
private static bool OverwriteSaveFile(MetaData metaData, string name) { bool flag; try { flag = MBSaveLoad.SaveGame(name, metaData); } catch { flag = false; } if (flag) { return(true); } if (!MBSaveLoad.DoNotShowSaveErrorAgain) { InformationManager.ShowInquiry(new InquiryData(GameTexts.FindText("str_save_unsuccessful_title").ToString(), GameTexts.FindText("str_save_unsuccessful_cannot_create_save_data").ToString(), true, false, GameTexts.FindText("str_ok").ToString(), GameTexts.FindText("str_dont_show_again").ToString(), (Action)null, (Action)(() => MBSaveLoad.DoNotShowSaveErrorAgain = true))); } return(false); }