-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCore.cs
More file actions
129 lines (113 loc) · 4.78 KB
/
Core.cs
File metadata and controls
129 lines (113 loc) · 4.78 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
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
122
123
124
125
126
127
128
129
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using ProjectM;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Sequencer;
using ProjectM.UI;
using RetroCamera.Behaviours;
using RetroCamera.Patches;
using RetroCamera.Utilities;
using System.Collections;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
namespace RetroCamera;
internal static class Core
{
public static World _client;
static Entity _localCharacter = Entity.Null;
static Entity _localUser = Entity.Null;
public static Entity LocalCharacter =>
_localCharacter.Exists()
? _localCharacter
: (ConsoleShared.TryGetLocalCharacterInCurrentWorld(out _localCharacter, _client) && _localCharacter.Exists()
? _localCharacter
: Entity.Null);
public static Entity LocalUser =>
_localUser.Exists()
? _localUser
: (ConsoleShared.TryGetLocalUserInCurrentWorld(out _localUser, _client) && _localUser.Exists()
? _localUser
: Entity.Null);
public static EntityManager EntityManager => _client.EntityManager;
public static ClientScriptMapper ClientScriptMapper { get; set; }
public static ClientGameManager ClientGameManager { get; set; }
public static GameDataSystem GameDataSystem { get; set; }
public static ZoomModifierSystem ZoomModifierSystem { get; set; }
public static TopdownCameraSystem TopdownCameraSystem { get; set; }
public static TargetInfoParentSystem TargetInfoParentSystem { get; set; }
public static PrefabCollectionSystem PrefabCollectionSystem { get; set; }
public static ActionWheelSystem ActionWheelSystem { get; set; }
public static UIDataSystem UIDataSystem { get; set; }
public static CursorPositionSystem CursorPositionSystem { get; set; }
public static InputActionSystem InputActionSystem { get; set; }
public static LocalUserSystem LocalUserSystem { get; set; }
public static ManualLogSource Log => Plugin.LogInstance;
static MonoBehaviour _monoBehaviour;
public static bool _initialized = false;
public static void Initialize(GameDataManager __instance)
{
if (_initialized) return;
_client = __instance.World;
ZoomModifierSystem = _client.GetExistingSystemManaged<ZoomModifierSystem>();
ZoomModifierSystem.Enabled = false; // necessary?
TopdownCameraSystem = _client.GetExistingSystemManaged<TopdownCameraSystem>();
TargetInfoParentSystem = _client.GetExistingSystemManaged<TargetInfoParentSystem>();
PrefabCollectionSystem = _client.GetExistingSystemManaged<PrefabCollectionSystem>();
ActionWheelSystem = _client.GetExistingSystemManaged<ActionWheelSystem>();
UIDataSystem = _client.GetExistingSystemManaged<UIDataSystem>();
CursorPositionSystem = _client.GetExistingSystemManaged<CursorPositionSystem>();
ClientScriptMapper = _client.GetExistingSystemManaged<ClientScriptMapper>();
ClientGameManager = ClientScriptMapper._ClientGameManager;
GameDataSystem = _client.GetExistingSystemManaged<GameDataSystem>();
InputActionSystem = _client.GetExistingSystemManaged<InputActionSystem>();
LocalUserSystem = _client.GetExistingSystemManaged<LocalUserSystem>();
TopdownCameraSystemHooks.Initialize();
_initialized = true;
}
public static Coroutine StartCoroutine(IEnumerator routine)
{
if (_monoBehaviour == null)
{
var go = new GameObject(MyPluginInfo.PLUGIN_NAME);
_monoBehaviour = go.AddComponent<IgnorePhysicsDebugSystem>();
UnityEngine.Object.DontDestroyOnLoad(go);
}
return _monoBehaviour.StartCoroutine(routine.WrapToIl2Cpp());
}
public static void ResetStates()
{
ClearSkies.Reset();
TopdownCameraSystemHooks.Dispose();
Systems.RetroCamera.ResetState();
CameraBehaviour.ResetState();
_initialized = false;
_localCharacter = Entity.Null;
_localUser = Entity.Null;
}
public static void LogEntity(World world, Entity entity)
{
Il2CppSystem.Text.StringBuilder sb = new();
try
{
EntityDebuggingUtility.DumpEntity(world, entity, true, sb);
Log.LogInfo($"Entity Dump:\n{sb.ToString()}");
}
catch (Exception e)
{
Log.LogWarning($"Error dumping entity: {e.Message}");
}
}
public static EntityQuery BuildEntityQuery(
EntityManager entityManager,
ComponentType[] all,
EntityQueryOptions options)
{
var builder = new EntityQueryBuilder(Allocator.Temp);
foreach (var componentType in all)
builder.AddAll(componentType);
builder.WithOptions(options);
return entityManager.CreateEntityQuery(ref builder);
}
}