mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix dropping stuff, fix an annoying NRE when spawning, fix time loop in other systems when doing vessel warp shit
This commit is contained in:
parent
86f889fef8
commit
bfbf02a5c3
@ -17,7 +17,7 @@ public static class HeldItemHandler
|
|||||||
/// Dictionary of system name to item path
|
/// Dictionary of system name to item path
|
||||||
/// If we travel to multiple systems within a single loop, this will hold the items we move between systems
|
/// If we travel to multiple systems within a single loop, this will hold the items we move between systems
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static Dictionary<string, List<string>> _pathOfItemTakenFromSystem = new();
|
private static Dictionary<string, HashSet<string>> _pathOfItemTakenFromSystem = new();
|
||||||
|
|
||||||
public static bool WasAWCTakenFromATP => _pathOfItemTakenFromSystem.TryGetValue("SolarSystem", out var list) && list.Contains(ADVANCED_WARP_CORE);
|
public static bool WasAWCTakenFromATP => _pathOfItemTakenFromSystem.TryGetValue("SolarSystem", out var list) && list.Contains(ADVANCED_WARP_CORE);
|
||||||
|
|
||||||
@ -45,16 +45,10 @@ public static class HeldItemHandler
|
|||||||
|
|
||||||
_currentStarSystem = Main.Instance.CurrentStarSystem;
|
_currentStarSystem = Main.Instance.CurrentStarSystem;
|
||||||
|
|
||||||
// If we took the AWC out of the main system make sure to disable time loop
|
|
||||||
if (_currentStarSystem != "SolarSystem" && WasAWCTakenFromATP)
|
|
||||||
{
|
|
||||||
TimeLoop.SetTimeLoopEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_isInitialized)
|
if (!_isInitialized)
|
||||||
{
|
{
|
||||||
_isInitialized = true;
|
_isInitialized = true;
|
||||||
Main.Instance.StarSystemChanging += OnStarSystemChanging;
|
Main.Instance.OnChangeStarSystem.AddListener(OnStarSystemChanging);
|
||||||
Main.Instance.OnStarSystemLoaded.AddListener(OnSystemReady);
|
Main.Instance.OnStarSystemLoaded.AddListener(OnSystemReady);
|
||||||
GlobalMessenger<DeathType>.AddListener("PlayerDeath", OnPlayerDeath);
|
GlobalMessenger<DeathType>.AddListener("PlayerDeath", OnPlayerDeath);
|
||||||
}
|
}
|
||||||
@ -71,8 +65,6 @@ public static class HeldItemHandler
|
|||||||
|
|
||||||
private static GameObject MakePerfectCopy(GameObject go)
|
private static GameObject MakePerfectCopy(GameObject go)
|
||||||
{
|
{
|
||||||
//go.SetActive(false);
|
|
||||||
|
|
||||||
var owItem = go.GetComponent<OWItem>();
|
var owItem = go.GetComponent<OWItem>();
|
||||||
|
|
||||||
var tempParent = new GameObject();
|
var tempParent = new GameObject();
|
||||||
@ -98,7 +90,7 @@ public static class HeldItemHandler
|
|||||||
_pathOfItemTakenFromSystem[Main.Instance.CurrentStarSystem].Add(path);
|
_pathOfItemTakenFromSystem[Main.Instance.CurrentStarSystem].Add(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnStarSystemChanging()
|
private static void OnStarSystemChanging(string _)
|
||||||
{
|
{
|
||||||
if (_currentlyHeldItem != null)
|
if (_currentlyHeldItem != null)
|
||||||
{
|
{
|
||||||
@ -109,7 +101,7 @@ public static class HeldItemHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
NHLogger.Log($"Scene unloaded, preserved inactive held item {_currentlyHeldItem.name}");
|
NHLogger.Log($"Scene unloaded, preserved inactive held item {_currentlyHeldItem.name}");
|
||||||
// For some reason, the original will get destroyed no matter what do we make a copy
|
// For some reason, the original will get destroyed no matter what we do. To avoid, we make a copy
|
||||||
_currentlyHeldItem = MakePerfectCopy(_currentlyHeldItem).DontDestroyOnLoad();
|
_currentlyHeldItem = MakePerfectCopy(_currentlyHeldItem).DontDestroyOnLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +147,7 @@ public static class HeldItemHandler
|
|||||||
}
|
}
|
||||||
NHLogger.Log($"Unsocketed {item.name}");
|
NHLogger.Log($"Unsocketed {item.name}");
|
||||||
}
|
}
|
||||||
GameObject.Destroy(item.gameObject);
|
item.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -219,4 +211,19 @@ public static class HeldItemHandler
|
|||||||
NHLogger.Log($"Player is now holding {item?.name ?? "nothing"}");
|
NHLogger.Log($"Player is now holding {item?.name ?? "nothing"}");
|
||||||
_currentlyHeldItem = item?.gameObject;
|
_currentlyHeldItem = item?.gameObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix, HarmonyPatch(typeof(ItemTool))]
|
||||||
|
[HarmonyPatch(nameof(ItemTool.SocketItem))]
|
||||||
|
[HarmonyPatch(nameof(ItemTool.DropItem))]
|
||||||
|
[HarmonyPatch(nameof(ItemTool.StartUnsocketItem))]
|
||||||
|
private static void HeldItemChanged2(ItemTool __instance)
|
||||||
|
{
|
||||||
|
if (!_isSystemReady)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NHLogger.Log($"Player is now holding nothing");
|
||||||
|
_currentlyHeldItem = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,12 +51,22 @@ namespace NewHorizons.Handlers
|
|||||||
Delay.StartCoroutine(SpawnCoroutine(30));
|
Delay.StartCoroutine(SpawnCoroutine(30));
|
||||||
}
|
}
|
||||||
|
|
||||||
var cloak = GetDefaultSpawn()?.GetAttachedOWRigidbody()?.GetComponentInChildren<CloakFieldController>();
|
|
||||||
|
// It was NREing in here when it was all ?. so explicit null checks
|
||||||
|
var spawn = GetDefaultSpawn();
|
||||||
|
if (spawn != null)
|
||||||
|
{
|
||||||
|
var attachedOWRigidBody = spawn.GetAttachedOWRigidbody();
|
||||||
|
if (attachedOWRigidBody != null)
|
||||||
|
{
|
||||||
|
var cloak = attachedOWRigidBody.GetComponentInChildren<CloakFieldController>();
|
||||||
if (cloak != null)
|
if (cloak != null)
|
||||||
{
|
{
|
||||||
// Ensures it has invoked everything and actually placed the player in the cloaking field #671
|
// Ensures it has invoked everything and actually placed the player in the cloaking field #671
|
||||||
cloak._firstUpdate = true;
|
cloak._firstUpdate = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Spawn ship
|
// Spawn ship
|
||||||
Delay.FireInNUpdates(SpawnShip, 30);
|
Delay.FireInNUpdates(SpawnShip, 30);
|
||||||
|
|||||||
@ -949,7 +949,6 @@ namespace NewHorizons
|
|||||||
#endregion Load
|
#endregion Load
|
||||||
|
|
||||||
#region Change star system
|
#region Change star system
|
||||||
public Action StarSystemChanging { get; set; }
|
|
||||||
public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false, bool vessel = false)
|
public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false, bool vessel = false)
|
||||||
{
|
{
|
||||||
// If we're just on the title screen set the system for later
|
// If we're just on the title screen set the system for later
|
||||||
@ -978,8 +977,6 @@ namespace NewHorizons
|
|||||||
|
|
||||||
if (LoadManager.GetCurrentScene() == OWScene.SolarSystem || LoadManager.GetCurrentScene() == OWScene.EyeOfTheUniverse)
|
if (LoadManager.GetCurrentScene() == OWScene.SolarSystem || LoadManager.GetCurrentScene() == OWScene.EyeOfTheUniverse)
|
||||||
{
|
{
|
||||||
StarSystemChanging?.Invoke();
|
|
||||||
|
|
||||||
IsWarpingFromShip = warp;
|
IsWarpingFromShip = warp;
|
||||||
IsWarpingFromVessel = vessel;
|
IsWarpingFromVessel = vessel;
|
||||||
DidWarpFromVessel = false;
|
DidWarpFromVessel = false;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using NewHorizons.Handlers;
|
||||||
|
|
||||||
namespace NewHorizons.Patches
|
namespace NewHorizons.Patches
|
||||||
{
|
{
|
||||||
@ -14,5 +15,16 @@ namespace NewHorizons.Patches
|
|||||||
[HarmonyPatch(typeof(GlobalMusicController), nameof(GlobalMusicController.UpdateEndTimesMusic))]
|
[HarmonyPatch(typeof(GlobalMusicController), nameof(GlobalMusicController.UpdateEndTimesMusic))]
|
||||||
[HarmonyPatch(typeof(TimeLoop), nameof(TimeLoop.Update))]
|
[HarmonyPatch(typeof(TimeLoop), nameof(TimeLoop.Update))]
|
||||||
public static bool DisableWithoutTimeLoop() => Main.Instance.TimeLoopEnabled;
|
public static bool DisableWithoutTimeLoop() => Main.Instance.TimeLoopEnabled;
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(TimeLoop), nameof(TimeLoop.Start))]
|
||||||
|
public static void TimeLoop_Start(TimeLoop __instance)
|
||||||
|
{
|
||||||
|
// If we took the AWC out of the main system make sure to disable time loop
|
||||||
|
if (Main.Instance.CurrentStarSystem != "SolarSystem" && HeldItemHandler.WasAWCTakenFromATP)
|
||||||
|
{
|
||||||
|
TimeLoop.SetTimeLoopEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user