diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 3a4bcdfe..03eb27d2 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -305,15 +305,15 @@ namespace NewHorizons.Builder.ShipLog public List children; public MapModeObject parent; public MapModeObject lastSibling; - public void Increment_width() + public void IncrementWidth() { branch_width++; - parent?.Increment_width(); + parent?.IncrementWidth(); } - public void Increment_height() + public void IncrementHeight() { branch_height++; - parent?.Increment_height(); + parent?.IncrementHeight(); } } @@ -416,12 +416,12 @@ namespace NewHorizons.Builder.ShipLog if (even) { newY += newNode.branch_height; - parent.Increment_height(); + parent.IncrementHeight(); } else { newX += newNode.branch_width; - parent.Increment_width(); + parent.IncrementWidth(); } lastSibling = newNode; diff --git a/NewHorizons/External/NewHorizonsData.cs b/NewHorizons/External/NewHorizonsData.cs index db7a96fa..124729b2 100644 --- a/NewHorizons/External/NewHorizonsData.cs +++ b/NewHorizons/External/NewHorizonsData.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using NewHorizons.Handlers; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.External @@ -59,12 +60,14 @@ namespace NewHorizons.External { Load(); } - Logger.Log($"Reseting save data for {_activeProfileName}"); + Logger.Log($"Resetting save data for {_activeProfileName}"); _activeProfile = new NewHorizonsProfile(); _saveFile.Profiles[_activeProfileName] = _activeProfile; Save(); } + + # region Frequencies public static bool KnowsFrequency(string frequency) { @@ -81,7 +84,16 @@ namespace NewHorizons.External Save(); } } + + public static bool KnowsMultipleFrequencies() + { + return (_activeProfile != null && _activeProfile.KnownFrequencies.Count > 0); + } + + # endregion + # region Signals + public static bool KnowsSignal(string signal) { if (_activeProfile == null) return true; @@ -97,12 +109,30 @@ namespace NewHorizons.External Save(); } } + + # endregion + + # region Newly Revealed Facts - public static bool KnowsMultipleFrequencies() + public static void AddNewlyRevealedFactID(string id) { - return (_activeProfile != null && _activeProfile.KnownFrequencies.Count > 0); + _activeProfile?.NewlyRevealedFactIDs.Add(id); + Save(); } + public static List GetNewlyRevealedFactIDs() + { + return _activeProfile?.NewlyRevealedFactIDs; + } + + public static void ClearNewlyRevealedFactIDs() + { + _activeProfile?.NewlyRevealedFactIDs.Clear(); + Save(); + } + + # endregion + private class NewHorizonsSaveFile { public NewHorizonsSaveFile() @@ -119,10 +149,13 @@ namespace NewHorizons.External { KnownFrequencies = new List(); KnownSignals = new List(); + NewlyRevealedFactIDs = new List(); } public List KnownFrequencies { get; set; } public List KnownSignals { get; set; } + + public List NewlyRevealedFactIDs { get; set; } } } } diff --git a/NewHorizons/Handlers/ShipLogHandler.cs b/NewHorizons/Handlers/ShipLogHandler.cs index 114d8d75..103e6d7d 100644 --- a/NewHorizons/Handlers/ShipLogHandler.cs +++ b/NewHorizons/Handlers/ShipLogHandler.cs @@ -23,8 +23,9 @@ namespace NewHorizons.Handlers // NewHorizonsBody -> AstroID private static Dictionary _nhBodyToAstroIDs; - private static string[] vanillaBodies; - private static string[] vanillaIDs; + private static string[] _vanillaBodies; + private static string[] _vanillaBodyIDs; + private static string[] _moddedFactsIDs; public static void Init() { @@ -33,13 +34,19 @@ namespace NewHorizons.Handlers _nhBodyToAstroIDs = new Dictionary(); List gameObjects = SearchUtilities.GetAllChildren(GameObject.Find(PAN_ROOT_PATH)); - vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray(); - vanillaIDs = gameObjects.ConvertAll(g => g.GetComponent()?.GetID()).ToArray(); + _vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray(); + _vanillaBodyIDs = gameObjects.ConvertAll(g => g.GetComponent()?.GetID()).ToArray(); + } + + public static void CheckForModdedFacts(ShipLogManager manager) + { + List moddedFacts = manager._factList.Where(e => manager._entryDataDict.ContainsKey(e._entryID) == false).ToList(); + _moddedFactsIDs = moddedFacts.ConvertAll(e => e.GetID()).ToArray(); } public static bool IsVanillaAstroID(string astroId) { - return vanillaIDs.Contains(astroId); + return _vanillaBodyIDs.Contains(astroId); } public static bool IsVanillaBody(NewHorizonsBody body) @@ -48,7 +55,7 @@ namespace NewHorizons.Handlers if (existingBody != null && existingBody.GetAstroObjectName() != AstroObject.Name.CustomString) return true; - return vanillaBodies.Contains(body.Config.Name.Replace(" ", "")); + return _vanillaBodies.Contains(body.Config.Name.Replace(" ", "")); } public static string GetNameFromAstroID(string astroID) @@ -66,6 +73,11 @@ namespace NewHorizons.Handlers } } + public static bool IsModdedFact(string FactID) + { + return _moddedFactsIDs.Contains(FactID); + } + public static void AddConfig(string astroID, List entryIDs, NewHorizonsBody body) { // Nice to be able to just get the AstroID from the body diff --git a/NewHorizons/Tools/Patches.cs b/NewHorizons/Tools/Patches.cs index 97d7b54a..4fd7ad9a 100644 --- a/NewHorizons/Tools/Patches.cs +++ b/NewHorizons/Tools/Patches.cs @@ -55,6 +55,14 @@ namespace NewHorizons.Tools var playerDataResetGame = typeof(PlayerData).GetMethod("ResetGame"); Main.Instance.ModHelper.HarmonyHelper.AddPostfix(playerDataResetGame, typeof(Patches), nameof(Patches.OnPlayerDataResetGame)); + var playerDataAddNewlyRevealedFactID = typeof(PlayerData).GetMethod("AddNewlyRevealedFactID"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataAddNewlyRevealedFactID, typeof(Patches), nameof(Patches.OnPlayerDataAddNewlyRevealedFactID)); + var playerDataGetNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("GetNewlyRevealedFactIDs"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataGetNewlyRevealedFactIDs, typeof(Patches), nameof(Patches.OnPlayerDataGetNewlyRevealedFactIDs)); + var playerDataClearNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("ClearNewlyRevealedFactIDs"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataClearNewlyRevealedFactIDs, typeof(Patches), nameof(Patches.OnPlayerDataClearNewlyRevealedFactIDs)); + + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Start", typeof(Patches), nameof(Patches.OnBlackHoleVolumeStart)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Awake", typeof(Patches), nameof(Patches.OnWhiteHoleVolumeAwake)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("UpdateOrbitalLaunchValues", typeof(Patches), nameof(Patches.OnProbeLauncherUpdateOrbitalLaunchValues)); @@ -310,6 +318,32 @@ namespace NewHorizons.Tools } return true; } + + public static bool OnPlayerDataAddNewlyRevealedFactID(string __0) + { + if (ShipLogHandler.IsModdedFact(__0)) + { + NewHorizonsData.AddNewlyRevealedFactID(__0); + return false; + } + else + { + return true; + } + } + + public static bool OnPlayerDataGetNewlyRevealedFactIDs(ref List __result) + { + __result = PlayerData._currentGameSave.newlyRevealedFactIDs.Concat(NewHorizonsData.GetNewlyRevealedFactIDs()).ToList(); + return false; + } + + public static bool OnPlayerDataClearNewlyRevealedFactIDs() + { + PlayerData._currentGameSave.newlyRevealedFactIDs.Clear(); + NewHorizonsData.ClearNewlyRevealedFactIDs(); + return false; + } public static void OnPlayerDataResetGame() { diff --git a/NewHorizons/Tools/ShipLogPatches.cs b/NewHorizons/Tools/ShipLogPatches.cs index 84966110..439073af 100644 --- a/NewHorizons/Tools/ShipLogPatches.cs +++ b/NewHorizons/Tools/ShipLogPatches.cs @@ -66,6 +66,7 @@ namespace NewHorizons.Tools public static void OnShipLogManagerAwakeComplete(ShipLogManager __instance) { + ShipLogHandler.CheckForModdedFacts(__instance); RumorModeBuilder.GenerateEntryData(__instance); for (var i = 0; i < __instance._entryList.Count; i++) {