Skip to content

Commit c068b7f

Browse files
authored
fix: RegisterOnFinishLoading not working BZ (#547)
* OnFinishLoading is now called on finish loading BZ * Converted `OnLoad` to local method
1 parent 1711ac2 commit c068b7f

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

Nautilus/Patchers/SaveUtilsPatcher.cs

+33-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using HarmonyLib;
5+
using Nautilus.Extensions;
6+
using UnityEngine;
57

68
namespace Nautilus.Patchers;
79

@@ -64,17 +66,40 @@ internal static IEnumerator InvokeLoadEvents(IEnumerator enumerator)
6466
{
6567
yield return enumerator.Current;
6668
}
67-
68-
OnFinishLoadingEvents?.Invoke();
69-
70-
if (oneTimeUseOnLoadEvents.Count > 0)
69+
70+
#if SUBNAUTICA
71+
OnLoad();
72+
#elif BELOWZERO
73+
uGUI_MainMenu.main.StartCoroutine(WaitUntilLoaded());
74+
75+
IEnumerator WaitUntilLoaded()
7176
{
72-
foreach (Action action in oneTimeUseOnLoadEvents)
77+
if (uGUI.main.loading.isLoading)
7378
{
74-
action.Invoke();
79+
yield return new WaitWhile(() => uGUI.main.loading.isLoading);
80+
}
81+
82+
if (WaitScreen.main.Exists()?.isShown is true)
83+
{
84+
yield return new WaitWhile(() => WaitScreen.main.isShown);
85+
}
86+
87+
OnLoad();
88+
}
89+
#endif
90+
void OnLoad()
91+
{
92+
OnFinishLoadingEvents?.Invoke();
93+
94+
if (oneTimeUseOnLoadEvents.Count > 0)
95+
{
96+
foreach (Action action in oneTimeUseOnLoadEvents)
97+
{
98+
action.Invoke();
99+
}
100+
101+
oneTimeUseOnLoadEvents.Clear();
75102
}
76-
77-
oneTimeUseOnLoadEvents.Clear();
78103
}
79104
}
80105

0 commit comments

Comments
 (0)