From 5a8a684e22b2eec0b318c68adbc6780479d8efd4 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 26 Dec 2020 01:30:27 -0500 Subject: add apply_save_fix command --- .../Commands/Other/ApplySaveFixCommand.cs | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/ApplySaveFixCommand.cs (limited to 'src/SMAPI.Mods.ConsoleCommands') diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/ApplySaveFixCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/ApplySaveFixCommand.cs new file mode 100644 index 00000000..8f59342e --- /dev/null +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/ApplySaveFixCommand.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using StardewValley; + +namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other +{ + /// A command which runs one of the game's save migrations. + internal class ApplySaveFixCommand : TrainerCommand + { + /********* + ** Public methods + *********/ + /// Construct an instance. + public ApplySaveFixCommand() + : base("apply_save_fix", "Apply one of the game's save migrations to the currently loaded save. WARNING: This may corrupt or make permanent changes to your save. DO NOT USE THIS unless you're absolutely sure.\n\nUsage: apply_save_fix list\nList all valid save IDs.\n\nUsage: apply_save_fix \nApply the named save fix.") { } + + /// Handle the command. + /// Writes messages to the console and log file. + /// The command name. + /// The command arguments. + public override void Handle(IMonitor monitor, string command, ArgumentParser args) + { + // get fix ID + if (!args.TryGet(0, "fix_id", out string rawFixId, required: false)) + { + monitor.Log("Invalid usage. Type 'help apply_save_fix' for details.", LogLevel.Error); + return; + } + rawFixId = rawFixId.Trim(); + + + // list mode + if (rawFixId == "list") + { + monitor.Log("Valid save fix IDs:\n - " + string.Join("\n - ", this.GetSaveIds()), LogLevel.Info); + return; + } + + // validate fix ID + if (!Enum.TryParse(rawFixId, ignoreCase: true, out SaveGame.SaveFixes fixId)) + { + monitor.Log($"Invalid save ID '{rawFixId}'. Type 'help apply_save_fix' for details.", LogLevel.Error); + return; + } + + // apply + monitor.Log("THIS MAY CAUSE PERMANENT CHANGES TO YOUR SAVE FILE. If you're not sure, exit your game without saving to avoid issues.", LogLevel.Warn); + monitor.Log($"Trying to apply save fix ID: '{fixId}'.", LogLevel.Warn); + try + { + Game1.applySaveFix(fixId); + monitor.Log("Save fix applied.", LogLevel.Info); + } + catch (Exception ex) + { + monitor.Log("Applying save fix failed. The save may be in an invalid state; you should exit your game now without saving to avoid issues.", LogLevel.Error); + monitor.Log($"Technical details: {ex}", LogLevel.Debug); + } + } + + + /********* + ** Private methods + *********/ + /// Get the valid save fix IDs. + private IEnumerable GetSaveIds() + { + foreach (SaveGame.SaveFixes id in Enum.GetValues(typeof(SaveGame.SaveFixes))) + { + if (id == SaveGame.SaveFixes.MAX) + continue; + + yield return id.ToString(); + } + } + } +} -- cgit From 5ac46b7ab22ad5d6ce558a6b6d6d020971c178bd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 26 Dec 2020 11:22:09 -0500 Subject: prepare for release --- build/common.targets | 2 +- docs/release-notes.md | 10 ++++++---- src/SMAPI.Mods.ConsoleCommands/manifest.json | 4 ++-- src/SMAPI.Mods.SaveBackup/manifest.json | 4 ++-- src/SMAPI/Constants.cs | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/SMAPI.Mods.ConsoleCommands') diff --git a/build/common.targets b/build/common.targets index ee4f918f..6c79d290 100644 --- a/build/common.targets +++ b/build/common.targets @@ -4,7 +4,7 @@ - 3.8.0 + 3.8.1 SMAPI latest diff --git a/docs/release-notes.md b/docs/release-notes.md index 0cc45116..90557c54 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -7,13 +7,15 @@ * Migrated to Harmony 2.0 (see [_migrate to Harmony 2.0_](https://stardewvalleywiki.com/Modding:Migrate_to_Harmony_2.0) for more info). --> -## Upcoming release +## 3.8.1 +Released 26 December 2020 for Stardew Valley 1.5.1 or later. + * For players: - * Fixed community center bundles broken for non-English saves created in SMAPI 3.8.0. Affected saves will be fixed automatically next time you load them. + * Fixed broken community center bundles for non-English saves created in Stardew Valley 1.5. Affected saves will be fixed automatically on load. * For modders: - * World events are now raised for the volcano levels. - * Added `apply_save_fix` command to reapply a save migration in exceptional cases. This should be used with extreme care. Type `help apply_save_fix` for details. + * World events are now raised for volcano dungeon levels. + * Added `apply_save_fix` command to reapply a save migration in exceptional cases. This should be used very carefully. Type `help apply_save_fix` for details. * **Deprecation notice:** the `Helper.ConsoleCommands.Trigger` method is now deprecated and should no longer be used. See [integration APIs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Integrations) for better mod integration options. It will eventually be removed in SMAPI 4.0. For the web UI: diff --git a/src/SMAPI.Mods.ConsoleCommands/manifest.json b/src/SMAPI.Mods.ConsoleCommands/manifest.json index a1a137a1..61c610d0 100644 --- a/src/SMAPI.Mods.ConsoleCommands/manifest.json +++ b/src/SMAPI.Mods.ConsoleCommands/manifest.json @@ -1,9 +1,9 @@ { "Name": "Console Commands", "Author": "SMAPI", - "Version": "3.8.0", + "Version": "3.8.1", "Description": "Adds SMAPI console commands that let you manipulate the game.", "UniqueID": "SMAPI.ConsoleCommands", "EntryDll": "ConsoleCommands.dll", - "MinimumApiVersion": "3.8.0" + "MinimumApiVersion": "3.8.1" } diff --git a/src/SMAPI.Mods.SaveBackup/manifest.json b/src/SMAPI.Mods.SaveBackup/manifest.json index 96822f4a..7cf63e66 100644 --- a/src/SMAPI.Mods.SaveBackup/manifest.json +++ b/src/SMAPI.Mods.SaveBackup/manifest.json @@ -1,9 +1,9 @@ { "Name": "Save Backup", "Author": "SMAPI", - "Version": "3.8.0", + "Version": "3.8.1", "Description": "Automatically backs up all your saves once per day into its folder.", "UniqueID": "SMAPI.SaveBackup", "EntryDll": "SaveBackup.dll", - "MinimumApiVersion": "3.8.0" + "MinimumApiVersion": "3.8.1" } diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 98d0277b..9d5501a3 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -54,10 +54,10 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.8.0"); + public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("3.8.1"); /// The minimum supported version of Stardew Valley. - public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.5.0"); + public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.5.1"); /// The maximum supported version of Stardew Valley. public static ISemanticVersion MaximumGameVersion { get; } = null; -- cgit