-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.cs
77 lines (63 loc) · 2.79 KB
/
Core.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Runtime.CompilerServices;
using BepInEx.Logging;
using ProjectM;
using ProjectM.Scripting;
using Unity.Entities;
using AutoBrazier.Services;
using AutoBrazier.Hooks;
using UnityEngine;
using System.Collections;
using ProjectM.Physics;
using BepInEx.Unity.IL2CPP.Utils.Collections;
namespace AutoBrazier;
internal static class Core
{
public static World Server { get; } = GetWorld("Server") ?? throw new System.Exception("There is no Server world (yet). Did you install a server mod on the client?");
public static EntityManager EntityManager { get; } = Server.EntityManager;
public static GameDataSystem GameDataSystem { get; } = Server.GetExistingSystemManaged<GameDataSystem>();
public static PrefabCollectionSystem PrefabCollectionSystem { get; internal set; }
public static ServerScriptMapper ServerScriptMapper { get; internal set; }
public static double ServerTime => ServerGameManager.ServerTime;
public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();
public static PlayerService PlayerService { get; internal set; }
public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }
public static ManualLogSource Log { get; } = Plugin._logger;
static MonoBehaviour MonoBehaviour;
public static void LogException(System.Exception e, [CallerMemberName] string caller = null)
{
Log.LogError($"Failure in {caller}\nMessage: {e.Message} Inner:{e.InnerException?.Message}\n\nStack: {e.StackTrace}\nInner Stack: {e.InnerException?.StackTrace}");
}
internal static void InitializeAfterLoaded()
{
if (_hasInitialized) return;
PrefabCollectionSystem = Server.GetExistingSystemManaged<PrefabCollectionSystem>();
ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
PlayerService = new();
BonfirePatch.Load();
_hasInitialized = true;
Log.LogInfo($"{nameof(InitializeAfterLoaded)} completed");
}
private static bool _hasInitialized = false;
public static bool HasInitialized { get { return _hasInitialized; } }
private static World GetWorld(string name)
{
foreach (var world in World.s_AllWorlds)
{
if (world.Name == name)
{
return world;
}
}
return null;
}
public static void StartCoroutine(IEnumerator routine)
{
if (MonoBehaviour == null)
{
MonoBehaviour = new GameObject("AutoBrazier").AddComponent<IgnorePhysicsDebugSystem>();
Object.DontDestroyOnLoad(MonoBehaviour.gameObject);
}
MonoBehaviour.StartCoroutine(routine.WrapToIl2Cpp());
}
}