mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix signal related bugs, save only when base game does
This commit is contained in:
parent
086757a46c
commit
962e04994b
@ -1,9 +1,11 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using NewHorizons.External;
|
||||||
using NewHorizons.External.Modules.Props.Audio;
|
using NewHorizons.External.Modules.Props.Audio;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using NewHorizons.Utility.OWML;
|
using NewHorizons.Utility.OWML;
|
||||||
using OWML.Common;
|
using OWML.Common;
|
||||||
using OWML.Utils;
|
using OWML.Utils;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -43,20 +45,9 @@ namespace NewHorizons.Builder.Props.Audio
|
|||||||
|
|
||||||
SceneManager.sceneUnloaded -= OnSceneUnloaded;
|
SceneManager.sceneUnloaded -= OnSceneUnloaded;
|
||||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||||
Main.Instance.OnStarSystemLoaded.RemoveListener(OnStarSystemLoaded);
|
|
||||||
Main.Instance.OnStarSystemLoaded.AddListener(OnStarSystemLoaded);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static HashSet<SignalFrequency> _frequenciesInUse = new();
|
|
||||||
|
|
||||||
private static void OnSceneUnloaded(Scene _)
|
|
||||||
{
|
|
||||||
_frequenciesInUse.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnStarSystemLoaded(string starSystem)
|
|
||||||
{
|
|
||||||
// If its the base game solar system or eye we get all the main frequencies
|
// If its the base game solar system or eye we get all the main frequencies
|
||||||
|
var starSystem = Main.Instance.CurrentStarSystem;
|
||||||
if (starSystem == "SolarSystem" || starSystem == "EyeOfTheUniverse")
|
if (starSystem == "SolarSystem" || starSystem == "EyeOfTheUniverse")
|
||||||
{
|
{
|
||||||
_frequenciesInUse.Add(SignalFrequency.Quantum);
|
_frequenciesInUse.Add(SignalFrequency.Quantum);
|
||||||
@ -69,19 +60,43 @@ namespace NewHorizons.Builder.Props.Audio
|
|||||||
// We don't want a scenario where the player knows no frequencies
|
// We don't want a scenario where the player knows no frequencies
|
||||||
_frequenciesInUse.Add(SignalFrequency.Traveler);
|
_frequenciesInUse.Add(SignalFrequency.Traveler);
|
||||||
|
|
||||||
|
// Make sure the NH save file has all the right frequencies
|
||||||
|
// Skip "default"
|
||||||
|
for (int i = 1; i < PlayerData._currentGameSave.knownFrequencies.Length; i++)
|
||||||
|
{
|
||||||
|
if (PlayerData._currentGameSave.knownFrequencies[i])
|
||||||
|
{
|
||||||
|
NewHorizonsData.LearnFrequency(AudioSignal.IndexToFrequency(i).ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NHLogger.LogVerbose($"Frequencies in use in {starSystem}: {_frequenciesInUse.Join(x => x.ToString())}");
|
NHLogger.LogVerbose($"Frequencies in use in {starSystem}: {_frequenciesInUse.Join(x => x.ToString())}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static HashSet<SignalFrequency> _frequenciesInUse = new();
|
||||||
|
|
||||||
|
private static void OnSceneUnloaded(Scene _)
|
||||||
|
{
|
||||||
|
_frequenciesInUse.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsFrequencyInUse(SignalFrequency freq) => _frequenciesInUse.Contains(freq);
|
public static bool IsFrequencyInUse(SignalFrequency freq) => _frequenciesInUse.Contains(freq);
|
||||||
|
|
||||||
|
public static bool IsFrequencyInUse(string freqString)
|
||||||
|
{
|
||||||
|
if (Enum.TryParse<SignalFrequency>(freqString, out var freq))
|
||||||
|
{
|
||||||
|
return IsFrequencyInUse(freq);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsCloaked(this AudioSignal signal) => _cloakedSignals.Contains(signal);
|
public static bool IsCloaked(this AudioSignal signal) => _cloakedSignals.Contains(signal);
|
||||||
|
|
||||||
public static bool IsOnQuantumMoon(this AudioSignal signal) => _qmSignals.Contains(signal);
|
public static bool IsOnQuantumMoon(this AudioSignal signal) => _qmSignals.Contains(signal);
|
||||||
|
|
||||||
public static SignalFrequency AddFrequency(string str)
|
public static SignalFrequency AddFrequency(string str)
|
||||||
{
|
{
|
||||||
if (_customFrequencyNames == null) Init();
|
|
||||||
|
|
||||||
var freq = CollectionUtilities.KeyByValue(_customFrequencyNames, str);
|
var freq = CollectionUtilities.KeyByValue(_customFrequencyNames, str);
|
||||||
if (freq != default) return freq;
|
if (freq != default) return freq;
|
||||||
|
|
||||||
@ -99,23 +114,19 @@ namespace NewHorizons.Builder.Props.Audio
|
|||||||
NumberOfFrequencies = EnumUtils.GetValues<SignalFrequency>().Length;
|
NumberOfFrequencies = EnumUtils.GetValues<SignalFrequency>().Length;
|
||||||
|
|
||||||
// This stuff happens after the signalscope is Awake so we have to change the number of frequencies now
|
// This stuff happens after the signalscope is Awake so we have to change the number of frequencies now
|
||||||
Object.FindObjectOfType<Signalscope>()._strongestSignals = new AudioSignal[NumberOfFrequencies + 1];
|
GameObject.FindObjectOfType<Signalscope>()._strongestSignals = new AudioSignal[NumberOfFrequencies + 1];
|
||||||
|
|
||||||
return freq;
|
return freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetCustomFrequencyName(SignalFrequency frequencyName)
|
public static string GetCustomFrequencyName(SignalFrequency frequencyName)
|
||||||
{
|
{
|
||||||
if (_customFrequencyNames == null) Init();
|
|
||||||
|
|
||||||
_customFrequencyNames.TryGetValue(frequencyName, out string name);
|
_customFrequencyNames.TryGetValue(frequencyName, out string name);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SignalName AddSignalName(string str)
|
public static SignalName AddSignalName(string str)
|
||||||
{
|
{
|
||||||
if (_customSignalNames == null) Init();
|
|
||||||
|
|
||||||
var name = CollectionUtilities.KeyByValue(_customSignalNames, str);
|
var name = CollectionUtilities.KeyByValue(_customSignalNames, str);
|
||||||
if (name != default) return name;
|
if (name != default) return name;
|
||||||
|
|
||||||
@ -129,8 +140,6 @@ namespace NewHorizons.Builder.Props.Audio
|
|||||||
|
|
||||||
public static string GetCustomSignalName(SignalName signalName)
|
public static string GetCustomSignalName(SignalName signalName)
|
||||||
{
|
{
|
||||||
if (_customSignalNames == null) Init();
|
|
||||||
|
|
||||||
_customSignalNames.TryGetValue(signalName, out string name);
|
_customSignalNames.TryGetValue(signalName, out string name);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|||||||
11
NewHorizons/External/NewHorizonsData.cs
vendored
11
NewHorizons/External/NewHorizonsData.cs
vendored
@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NewHorizons.Builder.Props.Audio;
|
||||||
using NewHorizons.Utility.OWML;
|
using NewHorizons.Utility.OWML;
|
||||||
|
|
||||||
namespace NewHorizons.External
|
namespace NewHorizons.External
|
||||||
@ -124,7 +126,6 @@ namespace NewHorizons.External
|
|||||||
if (!KnowsFrequency(frequency))
|
if (!KnowsFrequency(frequency))
|
||||||
{
|
{
|
||||||
_activeProfile.KnownFrequencies.Add(frequency);
|
_activeProfile.KnownFrequencies.Add(frequency);
|
||||||
Save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,13 +135,12 @@ namespace NewHorizons.External
|
|||||||
if (KnowsFrequency(frequency))
|
if (KnowsFrequency(frequency))
|
||||||
{
|
{
|
||||||
_activeProfile.KnownFrequencies.Remove(frequency);
|
_activeProfile.KnownFrequencies.Remove(frequency);
|
||||||
Save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool KnowsMultipleFrequencies()
|
public static bool KnowsMultipleFrequencies()
|
||||||
{
|
{
|
||||||
return _activeProfile != null && _activeProfile.KnownFrequencies.Count > 0;
|
return _activeProfile?.KnownFrequencies != null && _activeProfile.KnownFrequencies.Count(SignalBuilder.IsFrequencyInUse) > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -159,7 +159,6 @@ namespace NewHorizons.External
|
|||||||
if (!KnowsSignal(signal))
|
if (!KnowsSignal(signal))
|
||||||
{
|
{
|
||||||
_activeProfile.KnownSignals.Add(signal);
|
_activeProfile.KnownSignals.Add(signal);
|
||||||
Save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +169,6 @@ namespace NewHorizons.External
|
|||||||
public static void AddNewlyRevealedFactID(string id)
|
public static void AddNewlyRevealedFactID(string id)
|
||||||
{
|
{
|
||||||
_activeProfile?.NewlyRevealedFactIDs.Add(id);
|
_activeProfile?.NewlyRevealedFactIDs.Add(id);
|
||||||
Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<string> GetNewlyRevealedFactIDs()
|
public static List<string> GetNewlyRevealedFactIDs()
|
||||||
@ -181,7 +179,6 @@ namespace NewHorizons.External
|
|||||||
public static void ClearNewlyRevealedFactIDs()
|
public static void ClearNewlyRevealedFactIDs()
|
||||||
{
|
{
|
||||||
_activeProfile?.NewlyRevealedFactIDs.Clear();
|
_activeProfile?.NewlyRevealedFactIDs.Clear();
|
||||||
Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -191,7 +188,6 @@ namespace NewHorizons.External
|
|||||||
public static void ReadOneTimePopup(string id)
|
public static void ReadOneTimePopup(string id)
|
||||||
{
|
{
|
||||||
_activeProfile?.PopupsRead.Add(id);
|
_activeProfile?.PopupsRead.Add(id);
|
||||||
Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasReadOneTimePopup(string id)
|
public static bool HasReadOneTimePopup(string id)
|
||||||
@ -208,7 +204,6 @@ namespace NewHorizons.External
|
|||||||
{
|
{
|
||||||
if (name == CharacterDialogueTree.RECORDING_NAME || name == CharacterDialogueTree.SIGN_NAME) return;
|
if (name == CharacterDialogueTree.RECORDING_NAME || name == CharacterDialogueTree.SIGN_NAME) return;
|
||||||
_activeProfile?.CharactersTalkedTo.SafeAdd(name);
|
_activeProfile?.CharactersTalkedTo.SafeAdd(name);
|
||||||
Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasTalkedToFiveCharacters()
|
public static bool HasTalkedToFiveCharacters()
|
||||||
|
|||||||
@ -85,13 +85,9 @@ namespace NewHorizons.Patches.PlayerPatches
|
|||||||
[HarmonyPatch(nameof(PlayerData.KnowsMultipleFrequencies))]
|
[HarmonyPatch(nameof(PlayerData.KnowsMultipleFrequencies))]
|
||||||
public static bool PlayerData_KnowsMultipleFrequencies(ref bool __result)
|
public static bool PlayerData_KnowsMultipleFrequencies(ref bool __result)
|
||||||
{
|
{
|
||||||
if (NewHorizonsData.KnowsMultipleFrequencies())
|
__result = NewHorizonsData.KnowsMultipleFrequencies();
|
||||||
{
|
|
||||||
__result = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(nameof(PlayerData.AddNewlyRevealedFactID))]
|
[HarmonyPatch(nameof(PlayerData.AddNewlyRevealedFactID))]
|
||||||
@ -140,5 +136,12 @@ namespace NewHorizons.Patches.PlayerPatches
|
|||||||
{
|
{
|
||||||
NewHorizonsData.Reset();
|
NewHorizonsData.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(nameof(PlayerData.SaveCurrentGame))]
|
||||||
|
public static void PlayerData_SaveCurrentGame()
|
||||||
|
{
|
||||||
|
NewHorizonsData.Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using NewHorizons.Builder.Props.Audio;
|
using NewHorizons.Builder.Props.Audio;
|
||||||
|
using NewHorizons.Utility.OWML;
|
||||||
|
|
||||||
namespace NewHorizons.Patches.SignalPatches
|
namespace NewHorizons.Patches.SignalPatches
|
||||||
{
|
{
|
||||||
@ -19,13 +20,17 @@ namespace NewHorizons.Patches.SignalPatches
|
|||||||
{
|
{
|
||||||
var count = SignalBuilder.NumberOfFrequencies;
|
var count = SignalBuilder.NumberOfFrequencies;
|
||||||
__instance._frequencyFilterIndex += increment;
|
__instance._frequencyFilterIndex += increment;
|
||||||
__instance._frequencyFilterIndex = __instance._frequencyFilterIndex >= count ? 0 : __instance._frequencyFilterIndex;
|
__instance._frequencyFilterIndex = __instance._frequencyFilterIndex >= count ? 1 : __instance._frequencyFilterIndex;
|
||||||
__instance._frequencyFilterIndex = __instance._frequencyFilterIndex < 0 ? count - 1 : __instance._frequencyFilterIndex;
|
__instance._frequencyFilterIndex = __instance._frequencyFilterIndex < 1 ? count - 1 : __instance._frequencyFilterIndex;
|
||||||
var signalFrequency = AudioSignal.IndexToFrequency(__instance._frequencyFilterIndex);
|
var signalFrequency = AudioSignal.IndexToFrequency(__instance._frequencyFilterIndex);
|
||||||
|
|
||||||
|
NHLogger.Log($"Changed freq to {signalFrequency} at {__instance._frequencyFilterIndex}");
|
||||||
|
|
||||||
// Skip over this frequency
|
// Skip over this frequency
|
||||||
var isUnknown = !PlayerData.KnowsFrequency(signalFrequency) && !(__instance._isUnknownFreqNearby && __instance._unknownFrequency == signalFrequency);
|
// Never skip traveler (always known)
|
||||||
if (isUnknown || !SignalBuilder.IsFrequencyInUse(signalFrequency))
|
var isTraveler = __instance._frequencyFilterIndex == 1;
|
||||||
|
var isUnknown = !PlayerData.KnowsFrequency(signalFrequency) && (!__instance._isUnknownFreqNearby || __instance._unknownFrequency != signalFrequency);
|
||||||
|
if (!isTraveler && (isUnknown || !SignalBuilder.IsFrequencyInUse(signalFrequency)))
|
||||||
{
|
{
|
||||||
__instance.SwitchFrequencyFilter(increment);
|
__instance.SwitchFrequencyFilter(increment);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user