2022-05-04 04:20:59 +00:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Patches;
|
2020-11-04 09:34:01 +00:00
|
|
|
|
using QSB.Utility;
|
2021-03-23 13:18:29 +00:00
|
|
|
|
using QSB.WorldSync;
|
2020-11-04 09:34:01 +00:00
|
|
|
|
using System;
|
2022-05-04 04:41:05 +00:00
|
|
|
|
using UnityEngine;
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB;
|
|
|
|
|
|
|
|
|
|
public static class QSBSceneManager
|
2020-08-16 20:39:21 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static OWScene CurrentScene => LoadManager.GetCurrentScene();
|
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
public static bool IsInUniverse => CurrentScene.IsUniverseScene();
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
[Obsolete]
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static event Action<OWScene, OWScene, bool> OnSceneLoaded;
|
2022-05-04 04:41:05 +00:00
|
|
|
|
[Obsolete]
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static event Action<OWScene, OWScene> OnUniverseSceneLoaded;
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-05-04 04:20:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// runs before objects are destroyed
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event LoadManager.SceneLoadEvent OnPreSceneLoad;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// runs after objects are awakened and started
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event LoadManager.SceneLoadEvent OnPostSceneLoad;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
static QSBSceneManager()
|
|
|
|
|
{
|
2022-05-04 04:20:59 +00:00
|
|
|
|
LoadManager.OnStartSceneLoad += (originalScene, loadScene) =>
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"PRE SCENE LOAD ({originalScene} -> {loadScene})", MessageType.Info);
|
|
|
|
|
OnPreSceneLoad?.SafeInvoke(originalScene, loadScene);
|
|
|
|
|
};
|
|
|
|
|
LoadManager.OnCompleteSceneLoad += (originalScene, loadScene) =>
|
|
|
|
|
Delay.RunNextFrame(() =>
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"POST SCENE LOAD ({originalScene} -> {loadScene})", MessageType.Info);
|
|
|
|
|
OnPostSceneLoad?.SafeInvoke(originalScene, loadScene);
|
|
|
|
|
});
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
OnPreSceneLoad += (_, _) =>
|
|
|
|
|
QSBWorldSync.RemoveWorldObjects();
|
|
|
|
|
OnPostSceneLoad += (_, loadScene) =>
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
2022-05-04 04:41:05 +00:00
|
|
|
|
if (QSBCore.IsInMultiplayer)
|
|
|
|
|
{
|
|
|
|
|
if (loadScene.IsUniverseScene())
|
|
|
|
|
{
|
|
|
|
|
QSBWorldSync.BuildWorldObjects(loadScene).Forget();
|
|
|
|
|
}
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
if (loadScene == OWScene.TitleScreen)
|
|
|
|
|
{
|
|
|
|
|
QSBNetworkManager.singleton.StopHost();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
public static bool IsUniverseScene(this OWScene scene) =>
|
2022-03-03 03:46:33 +00:00
|
|
|
|
scene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse;
|
2022-05-04 04:20:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(GhostBrain))]
|
2022-05-04 04:41:05 +00:00
|
|
|
|
internal class TestPatch : QSBPatch
|
2022-05-04 04:20:59 +00:00
|
|
|
|
{
|
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(GhostBrain.Awake))]
|
|
|
|
|
private static void Awake() => DebugLog.DebugWrite("GhostBrain.Awake");
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(GhostBrain.Start))]
|
|
|
|
|
private static void Start() => DebugLog.DebugWrite("GhostBrain.Start");
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(GhostBrain.OnDestroy))]
|
|
|
|
|
private static void OnDestroy() => DebugLog.DebugWrite("GhostBrain.OnDestroy");
|
|
|
|
|
}
|