diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-12-26 02:08:53 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-12-26 02:08:53 -0500 |
commit | 49c192fc4772417428d490dabf93b790f82c94c9 (patch) | |
tree | 8e0553b793085ea831ee09339a93e58a146302d2 /src/SMAPI/Framework/SCore.cs | |
parent | 5a8a684e22b2eec0b318c68adbc6780479d8efd4 (diff) | |
download | SMAPI-49c192fc4772417428d490dabf93b790f82c94c9.tar.gz SMAPI-49c192fc4772417428d490dabf93b790f82c94c9.tar.bz2 SMAPI-49c192fc4772417428d490dabf93b790f82c94c9.zip |
detect & fix broken community center bundles
Diffstat (limited to 'src/SMAPI/Framework/SCore.cs')
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index a7f8fbed..6b8098cd 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -765,6 +765,9 @@ namespace StardewModdingAPI.Framework this.Monitor.Log(context); + // apply save fixes + this.ApplySaveFixes(); + // raise events this.OnLoadStageChanged(LoadStage.Ready); events.SaveLoaded.RaiseEmpty(); @@ -1054,6 +1057,44 @@ namespace StardewModdingAPI.Framework this.EventManager.ReturnedToTitle.RaiseEmpty(); } + /// <summary>Apply fixes to the save after it's loaded.</summary> + private void ApplySaveFixes() + { + // get last SMAPI version used with this save + const string migrationKey = "Pathoschild.SMAPI/last-version"; + if (!Game1.CustomData.TryGetValue(migrationKey, out string rawVersion) || !SemanticVersion.TryParse(rawVersion, out ISemanticVersion lastVersionRun)) + lastVersionRun = new SemanticVersion(3, 8, 0); + + // fix bundle corruption in SMAPI 3.8.0 + // For non-English players who created a new save in SMAPI 3.8.0, bundle data was + // incorrectly translated which caused the code to crash whenever the game tried to + // read it. + if (lastVersionRun.IsOlderThan(new SemanticVersion(3, 8, 1))) + { + bool? hasInvalidBundleData = Game1.netWorldState?.Value + ?.BundleData + ?.Values + ?.Any(raw => raw != null && raw.Split('/').Length > 5); + + if (hasInvalidBundleData == true) + { + try + { + Game1.applySaveFix(SaveGame.SaveFixes.FixBotchedBundleData); + this.Monitor.Log("Found corrupted community center data due to a previous version of SMAPI, and fixed it automatically.", LogLevel.Info); + } + catch (Exception ex) + { + this.Monitor.Log("Found corrupted community center data due to a previous version of SMAPI, but was unable to fix it automatically.", LogLevel.Error); + this.Monitor.Log($"Technical details: {ex}"); + } + } + } + + // update last run + Game1.CustomData[migrationKey] = Constants.ApiVersion.ToString(); + } + /// <summary>Raised after custom content is removed from the save data to avoid a crash.</summary> internal void OnSaveContentRemoved() { |