-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.cs
More file actions
83 lines (69 loc) · 3.12 KB
/
Core.cs
File metadata and controls
83 lines (69 loc) · 3.12 KB
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
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using Penumbra.Services;
using ProjectM;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using Stunlock.Core;
using System.Collections;
using Unity.Entities;
using UnityEngine;
using static Penumbra.Plugin;
namespace Penumbra;
internal static class Core
{
public static World Server { get; } = GetServerWorld() ?? throw new Exception("There is no Server world!");
public static EntityManager EntityManager => Server.EntityManager;
public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();
public static PrefabCollectionSystem PrefabCollectionSystem { get; internal set; }
public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }
public static ServerScriptMapper ServerScriptMapper { get; internal set; }
public static DebugEventsSystem DebugEventsSystem { get; internal set; }
public static EntityCommandBufferSystem EntityCommandBufferSystem { get; internal set; }
public static NetworkIdSystem.Singleton NetworkIdSystem { get; internal set; }
public static double ServerTime => ServerGameManager.ServerTime;
public static ManualLogSource Log => LogInstance;
static MonoBehaviour _monoBehaviour;
public static IReadOnlyDictionary<PrefabGUID, string> PrefabGuidsToNames => _prefabGuidsToNames;
static readonly Dictionary<PrefabGUID, string> _prefabGuidsToNames = [];
public static bool _initialized;
public static void Initialize()
{
if (_initialized) return;
PrefabCollectionSystem = Server.GetExistingSystemManaged<PrefabCollectionSystem>();
ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
DebugEventsSystem = Server.GetExistingSystemManaged<DebugEventsSystem>();
ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
EntityCommandBufferSystem = Server.GetExistingSystemManaged<EntityCommandBufferSystem>();
NetworkIdSystem = ServerScriptMapper.GetSingleton<NetworkIdSystem.Singleton>();
InitializePrefabGuidNames();
if (_tokensConfig.TokenSystem || _tokensConfig.DailyLogin)
TokenService.Initialize();
_ = new LocalizationService();
_ = new MerchantService();
_initialized = true;
}
static World GetServerWorld()
{
return World.s_AllWorlds.ToArray().FirstOrDefault(world => world.Name == "Server");
}
static void InitializePrefabGuidNames()
{
var namesToPrefabGuids = PrefabCollectionSystem.SpawnableNameToPrefabGuidDictionary;
foreach (var kvp in namesToPrefabGuids)
{
_prefabGuidsToNames[kvp.Value] = kvp.Key;
}
}
public static void StartCoroutine(IEnumerator routine)
{
if (_monoBehaviour == null)
{
var go = new GameObject(MyPluginInfo.PLUGIN_NAME);
_monoBehaviour = go.AddComponent<IgnorePhysicsDebugSystem>();
UnityEngine.Object.DontDestroyOnLoad(go);
}
_monoBehaviour.StartCoroutine(routine.WrapToIl2Cpp());
}
}