/// <summary> /// Resets the <see cref="SaveFile"/> of the specified index, equal to the Erase option on the title screen. /// </summary> /// <param name="index">The zero-based index of the save file to reset. Refer to <see cref="SaveUtils.SAVE_FILE_COUNT"/> for the highest index.</param> /// <param name="force"> /// When <c>true</c>, reset the save file regardless of it being the active <see cref="GM.SaveFile"/> or not. /// This is a DANGEROUS option and has the potential to corrupt your save file. /// </param> /// <returns><c>True</c> when the save file was reset, <c>false</c> when it was not found or when it is the active save file and <paramref name="force"/> is <c>false</c>.</returns> public static bool ResetSaveFile(int index, bool force = false) { if (index < 0 || index >= SaveUtils.SAVE_FILE_COUNT) { throw new ArgumentOutOfRangeException(nameof(index), $"Minimum: 0 Maximum: {SaveUtils.SAVE_FILE_COUNT - 1}"); } if (GM.System != null) { var saveFile = SaveUtils.GetSaveFile(index); if (saveFile != null && (force || saveFile != GM.System.SaveFile)) { saveFile.ResetFile(); SaveUtils.Save(); return(true); } } return(false); }
/// <summary> /// Loads the <see cref="SaveFile"/> of the specified index and begins a game session with it. /// </summary> /// <param name="index">The index of the save file to load and start a game with.</param> /// <param name="gender">The gender to use when starting a new game when the specified <paramref name="index"/> is an empty save file.</param> public static void LoadSaveFile(int index, SettingsGender gender = SettingsGender.MALE) { if (index < 0 || index >= SaveUtils.SAVE_FILE_COUNT) { throw new ArgumentOutOfRangeException(nameof(index), $"Min: 0 Max: {SaveUtils.SAVE_FILE_COUNT - 1}"); } if (GM.System != null) { SaveFile saveFile = SaveUtils.GetSaveFile(index); if (saveFile != null) { if (GM.Stage != null) { // Remove all subscriptions from event AccessTools.Field(typeof(UITitle), "SaveFileSelectedEvent").SetValue(GM.Stage.uiTitle, null, BindingFlags.Public, null, null); GM.Stage.uiTitle.HideTitleScreen(); GM.Stage.SetPausable(true); GM.Stage.uiTop.buttonHuniebee.interactive = true; } if (!saveFile.started) { BaseHunieModPlugin.hasReturned = false; saveFile.settingsGender = (int)gender; } // Set the active save file AccessTools.Field(typeof(GM), "_saveFile").SetValue(GM.System, saveFile); // Start game session AccessTools.Method(typeof(GM), "BeginGameSession").Invoke(GM.System, null); } } }