forked from decaprime/CommunityCommands
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Core.cs
121 lines (100 loc) · 4.11 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System.Collections;
using System.Runtime.CompilerServices;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using KindredCommands.Services;
using ProjectM;
using ProjectM.Physics;
using ProjectM.Scripting;
using Unity.Entities;
using UnityEngine;
namespace KindredCommands;
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 RelicDestroySystem RelicDestroySystem { get; internal set; }
public static ServerScriptMapper ServerScriptMapper { get; internal set; }
public static double ServerTime => ServerGameManager.ServerTime;
public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();
public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }
public static ManualLogSource Log { get; } = Plugin.PluginLog;
public static AnnouncementsService AnnouncementsService { get; internal set; }
public static BoostedPlayerService BoostedPlayerService { get; internal set; }
public static BossService Boss { get; internal set; }
public static CastleTerritoryService CastleTerritory { get; private set; }
public static ConfigSettingsService ConfigSettings { get; internal set; }
public static DropItemService DropItem { get; internal set; }
public static GearService GearService { get; internal set; }
public static LocalizationService Localization { get; } = new();
public static PlayerService Players { get; internal set; }
public static PrefabService Prefabs { get; internal set; }
public static RegionService Regions { get; internal set; }
public static SoulshardService SoulshardService { get; internal set; }
public static StealthAdminService StealthAdminService { get; internal set; }
public static TrackPlayerEquipmentService TrackPlayerEquipment { get; internal set; }
public static UnitSpawnerService UnitSpawner { get; internal set; }
static MonoBehaviour monoBehaviour;
public const int MAX_REPLY_LENGTH = 509;
public static void LogException(System.Exception e, [CallerMemberName] string caller = null)
{
Core.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>();
RelicDestroySystem = Server.GetExistingSystemManaged<RelicDestroySystem>();
ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
Players = new();
Prefabs = new();
ConfigSettings = new();
AnnouncementsService = new();
BoostedPlayerService = new();
Boss = new();
CastleTerritory = new();
DropItem = new();
GearService = new();
Regions = new();
SoulshardService = new();
StealthAdminService = new();
TrackPlayerEquipment = new();
UnitSpawner = new();
Data.Character.Populate();
_hasInitialized = true;
Log.LogInfo($"{nameof(InitializeAfterLoaded)} completed");
}
private static bool _hasInitialized = false;
private static World GetWorld(string name)
{
foreach (var world in World.s_AllWorlds)
{
if (world.Name == name)
{
return world;
}
}
return null;
}
public static Coroutine StartCoroutine(IEnumerator routine)
{
if (monoBehaviour == null)
{
var go = new GameObject("KindredCommands");
monoBehaviour = go.AddComponent<IgnorePhysicsDebugSystem>();
Object.DontDestroyOnLoad(go);
}
return monoBehaviour.StartCoroutine(routine.WrapToIl2Cpp());
}
public static void StopCoroutine(Coroutine coroutine)
{
if (monoBehaviour == null)
{
return;
}
monoBehaviour.StopCoroutine(coroutine);
}
}