diff --git a/Winch/Data/ExtendedSaveData.cs b/Winch/Data/ExtendedSaveData.cs index 0e62b063..09d8afd9 100644 --- a/Winch/Data/ExtendedSaveData.cs +++ b/Winch/Data/ExtendedSaveData.cs @@ -34,6 +34,8 @@ internal ExtendedSaveData(int slot) internal class ModdedSaveData { public List mods = new List(); + public string dockId = string.Empty; + public int dockSlotIndex = 0; public Dictionary grids = new Dictionary(); public List serializedCrabPotPOIs = new List(); public Dictionary> modData = new Dictionary>(); @@ -70,6 +72,11 @@ internal void Create() internal void ExtractModdedData() { + saveData.dockId = baseSaveData.dockId; + saveData.dockSlotIndex = baseSaveData.dockSlotIndex; + if (baseSaveData.dockId.IsDockModded()) + DockUtil.ResetSaveData(baseSaveData); + var gridsToRemove = new List(); foreach (var gridByKey in baseSaveData.grids) { @@ -127,6 +134,17 @@ internal void ExtractModdedData() internal void InsertModdedData() { + if (!string.IsNullOrWhiteSpace(saveData.dockId)) + { + if (saveData.dockId.DoesDockExist()) + { + baseSaveData.dockId = saveData.dockId; + baseSaveData.dockSlotIndex = saveData.dockSlotIndex; + } + else + WinchCore.Log.Error($"Failed to find dock with id \"{saveData.dockId}\". Resetting to Blackstone Isle."); + } + var gridsToRemove = new List(); foreach (var gridByKey in saveData.grids) { diff --git a/Winch/Patches/API/GameSceneInitializerPatch.cs b/Winch/Patches/API/GameSceneInitializerPatch.cs index 8221a4b6..bd38e9d6 100644 --- a/Winch/Patches/API/GameSceneInitializerPatch.cs +++ b/Winch/Patches/API/GameSceneInitializerPatch.cs @@ -21,7 +21,6 @@ public static void Prefix(GameSceneInitializer __instance) HarvestZoneUtil.CreateModdedHarvestZones(); WorldEventUtil.CreateModdedStaticWorldEvents(); ItemUtil.Encyclopedia(); - DockUtil.Fix(); DredgeEvent.TriggerGameLoading(__instance); } catch (Exception ex) diff --git a/Winch/Util/DockUtil.cs b/Winch/Util/DockUtil.cs index 6f03bb8a..fb4f4f61 100644 --- a/Winch/Util/DockUtil.cs +++ b/Winch/Util/DockUtil.cs @@ -241,6 +241,34 @@ internal static bool PopulateDestinationFromMetaWithConverters(T item, Dictio return UtilHelpers.PopulateObjectFromMeta(item, meta, DestinationConverters); } + internal static List VanillaDockIDList = new List { + "dock.pontoon-tpr", + "dock.pontoon-ts", + "dock.pontoon-sb", + "dock.pontoon-ds", + "dock.old-mayor-sb", + "dock.old-mayor-gc", + "dock.old-fort", + "dock.photographer-camp", + "dock.pontoon-gc", + "dock.tpr-middle", + "dock.tpr-south", + "dock.tpr-west", + "dock.tpr-east", + "dock.steel-point", + "dock.research-pontoon", + "dock.greater-marrow", + "dock.ingfell", + "dock.old-mayor-ds", + "dock.old-mayor-ts", + "dock.ancient-ruins", + "dock.gale-cliffs", + "dock.soldier-camp", + "dock.outcast-isle", + "dock.little-marrow", + "dock.ds-temple", + "dock.the-iron-rig" + }; internal static Dictionary ModdedDockDataDict = new(); internal static Dictionary AllDockDataDict = new(); @@ -322,6 +350,7 @@ internal static void Populate() foreach (var dock in Resources.FindObjectsOfTypeAll()) { + if (!VanillaDockIDList.Contains(dock.Data.Id)) WinchCore.Log.Warn($"Possible missing dock ID \"{dock.Data.Id}\" from the vanilla list!"); PopulateDock(dock); } @@ -331,14 +360,10 @@ internal static void Populate() ResearchBottomlessLines = hceds.FirstOrDefault(hced => hced.name == "ResearchBottomlessLines"); } - internal static void Fix() + internal static void ResetSaveData(SaveData saveData) { - var id = GameManager.Instance.SaveData.dockId; - if (!AllDockDict.ContainsKey(id) && !ModdedDockDict.Values.Any(dock => dock.Data.Id == id)) - { - GameManager.Instance.SaveData.dockId = "dock.outcast-isle"; - GameManager.Instance.SaveData.dockSlotIndex = 0; - } + saveData.dockId = "dock.outcast-isle"; + saveData.dockSlotIndex = 0; } internal static void Clear() diff --git a/Winch/Util/WinchExtensions.cs b/Winch/Util/WinchExtensions.cs index f56a8105..b633cb68 100644 --- a/Winch/Util/WinchExtensions.cs +++ b/Winch/Util/WinchExtensions.cs @@ -71,7 +71,7 @@ public static class WinchExtensions /// public static bool IsModded(this WorldEventData worldEvent) => worldEvent is ModdedWorldEventData || !WorldEventUtil.VanillaWorldEventIDList.Contains(worldEvent.name); /// - public static bool IsModded(this DockData dockData) => dockData is DeferredDockData || DockUtil.ModdedDockDataDict.ContainsKey(dockData.id); + public static bool IsModded(this DockData dockData) => dockData is DeferredDockData || DockUtil.ModdedDockDataDict.ContainsKey(dockData.id) || !DockUtil.VanillaDockIDList.Contains(dockData.id); /// public static bool IsModded(this Dock dock) => dock is ModdedDock || dock.dockData.IsModded(); /// @@ -154,6 +154,18 @@ public static class WinchExtensions /// public static bool DoesItemDataNotExist(this SerializedCrabPotPOIData crabPotPOI) => !crabPotPOI.DoesItemDataExist(); + /// + internal static bool IsDockModded(this string dockID) => DockUtil.ModdedDockDataDict.ContainsKey(dockID) || !DockUtil.VanillaDockIDList.Contains(dockID); + /// + /// Check if the associated dock data exists + /// + /// Whether the associated dock data exists or not + internal static bool DoesDockExist(this string dockID) => DockUtil.ModdedDockDataDict.ContainsKey(dockID) || DockUtil.VanillaDockIDList.Contains(dockID); + /// + /// Opposite of s + /// + internal static bool DoesDockNotExist(this string dockID) => !dockID.DoesDockExist(); + public static void Reinit(this SerializableGrid grid) => grid.Init(grid.gridConfiguration, false); ///