summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ConsoleCommands/Framework/Commands
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-03-21 00:44:42 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-03-21 00:44:42 -0400
commitc070e34c2f18a18d03dbe9f86f5d17491215b6e2 (patch)
tree2788c5077dcc44711322866b94c44ca655c2a2aa /src/SMAPI.Mods.ConsoleCommands/Framework/Commands
parentc39b2b17663f79da92f3d0abe8c01ea73187cbab (diff)
downloadSMAPI-c070e34c2f18a18d03dbe9f86f5d17491215b6e2.tar.gz
SMAPI-c070e34c2f18a18d03dbe9f86f5d17491215b6e2.tar.bz2
SMAPI-c070e34c2f18a18d03dbe9f86f5d17491215b6e2.zip
fix double-localization issue in regenerated bundles
Diffstat (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework/Commands')
-rw-r--r--src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/RegenerateBundles.cs33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/RegenerateBundles.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/RegenerateBundles.cs
index d28abd13..9beedb96 100644
--- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/RegenerateBundles.cs
+++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/RegenerateBundles.cs
@@ -1,6 +1,10 @@
using System;
+using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
+using Netcode;
using StardewValley;
+using StardewValley.Network;
namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
{
@@ -56,9 +60,34 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
return;
}
+ // get private fields
+ IWorldState state = Game1.netWorldState.Value;
+ var bundleData = state.GetType().GetField("_bundleData", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)?.GetValue(state) as IDictionary<string, string>
+ ?? throw new InvalidOperationException("Can't access '_bundleData' field on world state.");
+ var netBundleData = state.GetType().GetField("netBundleData", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)?.GetValue(state) as NetStringDictionary<string, NetString>
+ ?? throw new InvalidOperationException("Can't access 'netBundleData' field on world state.");
+
+ // clear bundle data
+ state.BundleData.Clear();
+ state.Bundles.Clear();
+ state.BundleRewards.Clear();
+ bundleData.Clear();
+ netBundleData.Clear();
+
// regenerate bundles
- Game1.bundleType = bundleType;
- Game1.GenerateBundles(bundleType, use_seed: useSeed);
+ var locale = LocalizedContentManager.CurrentLanguageCode;
+ try
+ {
+ LocalizedContentManager.CurrentLanguageCode = LocalizedContentManager.LanguageCode.en; // the base bundle data needs to be unlocalized (the game will add localized names later)
+
+ Game1.bundleType = bundleType;
+ Game1.GenerateBundles(bundleType, use_seed: useSeed);
+ }
+ finally
+ {
+ LocalizedContentManager.CurrentLanguageCode = locale;
+ }
+
monitor.Log("Regenerated bundles and reset bundle progress.", LogLevel.Info);
monitor.Log("This may have unintended effects if you've already completed any bundles. If you're not sure, exit your game without saving to cancel.", LogLevel.Warn);
}