-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.cs
119 lines (96 loc) · 3.64 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
using System.Collections;
using System.Runtime.CompilerServices;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using ProjectM;
using ProjectM.Physics;
using ProjectM.Scripting;
using Refined.Services;
using Unity.Entities;
using UnityEngine;
namespace Refined;
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 ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();
public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }
public static ManualLogSource Logger { get; } = Plugin.Logger;
public static AnnouncerService AnnouncerService { get; internal set; }
public static BossService BossService { get; internal set; }
public static GearService GearService { get; internal set; }
public static LocalizationService LocalizationService { get; } = new();
public static MapService MapService { get; internal set; }
public static PlayerService PlayerService { get; internal set; }
public static PrefabService PrefabService { get; internal set; }
public static RegionService RegionService { get; internal set; }
public static SoulShardService SoulShardService { get; internal set; }
public static StashService StashService { get; internal set; }
public static TerritoryService TerritoryService { get; internal set; }
static MonoBehaviour monoBehaviour;
private static bool _hasInitialized = false;
public static void LogException(System.Exception e, [CallerMemberName] string caller = null)
{
Core.Logger.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();
AnnouncerService = new();
BossService = new();
GearService = new();
MapService = new();
RegionService = new();
PlayerService = new();
PrefabService = new();
SoulShardService = new();
StashService = new();
TerritoryService = new();
Data.Character.Populate();
//MapService.RevealMapForAllPlayers();
GearService.SetHeadgearBloodbound();
SoulShardService.SetShardDecayRate();
AnnouncerService.StartAnnounceServerInfo();
_hasInitialized = true;
Logger.LogInfo($"{nameof(InitializeAfterLoaded)} completed");
}
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("Refined");
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);
}
}