-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmap_state_runtime.cpp
More file actions
198 lines (179 loc) · 5.48 KB
/
Copy pathmap_state_runtime.cpp
File metadata and controls
198 lines (179 loc) · 5.48 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "map_state_runtime.h"
#include "map_state_capture.h"
#include "plugin_helpers.h"
#if defined(MODLOADER_CLIENT_BUILD)
#include "map_state_http.h"
#endif
#if defined(MODLOADER_CLIENT_BUILD)
#include "client/map_sync_client.h"
#endif
#if defined(MODLOADER_SERVER_BUILD)
#include "server/map_sync_server.h"
#endif
namespace
{
bool g_registered = false;
}
namespace MapStateRuntime
{
bool RegisterCallbacks()
{
IPluginHooks* hooks = GetHooks();
if (!hooks)
{
LOG_ERROR("Cannot register callbacks: hooks interface is null");
return false;
}
if (g_registered)
{
return true;
}
#if defined(MODLOADER_CLIENT_BUILD)
if (!Detail::StartHttpServer())
{
return false;
}
#endif
if (hooks->Engine && hooks->Engine->RegisterOnInit)
{
hooks->Engine->RegisterOnInit(OnEngineInit);
}
if (hooks->Engine && hooks->Engine->RegisterOnShutdown)
{
hooks->Engine->RegisterOnShutdown(OnEngineShutdown);
}
if (hooks->Engine && hooks->Engine->RegisterOnTick)
{
hooks->Engine->RegisterOnTick(OnEngineTick);
LOG_INFO("Requested EngineTick callback for realtime cargo refresh; confirm [EngineTick] logs in modloader.log.");
}
else
{
LOG_WARN("Engine tick callbacks are unavailable; realtime cargo refresh is disabled.");
}
if (hooks->Actors && hooks->Actors->RegisterOnActorBeginPlay)
{
hooks->Actors->RegisterOnActorBeginPlay(OnActorBeginPlay);
}
else
{
LOG_WARN("ActorBeginPlay callbacks are unavailable; spawn-driven snapshot refresh is disabled.");
}
if (hooks->World && hooks->World->RegisterOnAnyWorldBeginPlay)
{
hooks->World->RegisterOnAnyWorldBeginPlay(OnAnyWorldBeginPlay);
}
if (hooks->World && hooks->World->RegisterOnSaveLoaded)
{
// Disabled on the current build line: the process dies during OnSaveLoaded
// before the plugin callback is entered, so keep runtime refresh on the
// safer world/experience/tick paths instead.
LOG_WARN("SaveLoaded callback registration is disabled on this build line.");
}
if (hooks->World && hooks->World->RegisterOnExperienceLoadComplete)
{
// Disabled on the current client build line: world begin play is observed,
// then EngineTick marks ChimeraMain ready and drives the first refresh.
// This avoids an early transition-time refresh path that can still be fragile.
LOG_WARN("ExperienceLoadComplete callback registration is disabled on this client build line.");
}
// WorldEndPlay hooks (v20)
if (hooks->World && hooks->World->RegisterOnBeforeWorldEndPlay)
{
hooks->World->RegisterOnBeforeWorldEndPlay(OnBeforeWorldEndPlay);
}
if (hooks->World && hooks->World->RegisterOnAfterWorldEndPlay)
{
hooks->World->RegisterOnAfterWorldEndPlay(OnAfterWorldEndPlay);
}
// PlayerJoined hook (v14)
if (hooks->Players && hooks->Players->RegisterOnPlayerJoined)
{
hooks->Players->RegisterOnPlayerJoined(OnPlayerJoined);
}
// Initialize network sync modules
#if defined(MODLOADER_CLIENT_BUILD)
if (!MapExtensionClient::Sync::Initialize())
{
LOG_WARN("Client network sync initialization failed; dedicated snapshot sync disabled.");
}
#endif
#if defined(MODLOADER_SERVER_BUILD)
if (!MapExtensionServer::Sync::Initialize())
{
LOG_WARN("Server network sync initialization failed; snapshot requests will not be served.");
}
#endif
g_registered = true;
LOG_INFO("Runtime callbacks registered");
Detail::LogRuntimePlanIfNeeded();
Detail::TryRefreshCurrentWorld("RegisterCallbacks");
return true;
}
void UnregisterCallbacks()
{
// Remove the rupture-cycle delegate splices first: they live in the
// engine's InvocationList and must be gone before the DLL is unloaded.
Detail::ShutdownRuptureCycleDelegateHooks();
IPluginHooks* hooks = GetHooks();
if (hooks && g_registered)
{
if (hooks->Engine && hooks->Engine->UnregisterOnInit)
{
hooks->Engine->UnregisterOnInit(OnEngineInit);
}
if (hooks->Engine && hooks->Engine->UnregisterOnShutdown)
{
hooks->Engine->UnregisterOnShutdown(OnEngineShutdown);
}
if (hooks->Engine && hooks->Engine->UnregisterOnTick)
{
hooks->Engine->UnregisterOnTick(OnEngineTick);
}
if (hooks->Actors && hooks->Actors->UnregisterOnActorBeginPlay)
{
hooks->Actors->UnregisterOnActorBeginPlay(OnActorBeginPlay);
}
if (hooks->World && hooks->World->UnregisterOnAnyWorldBeginPlay)
{
hooks->World->UnregisterOnAnyWorldBeginPlay(OnAnyWorldBeginPlay);
}
if (hooks->World && hooks->World->UnregisterOnExperienceLoadComplete)
{
hooks->World->UnregisterOnExperienceLoadComplete(OnExperienceLoadComplete);
}
if (hooks->World && hooks->World->UnregisterOnBeforeWorldEndPlay)
{
hooks->World->UnregisterOnBeforeWorldEndPlay(OnBeforeWorldEndPlay);
}
if (hooks->World && hooks->World->UnregisterOnAfterWorldEndPlay)
{
hooks->World->UnregisterOnAfterWorldEndPlay(OnAfterWorldEndPlay);
}
if (hooks->Players && hooks->Players->UnregisterOnPlayerJoined)
{
hooks->Players->UnregisterOnPlayerJoined(OnPlayerJoined);
}
}
// Shutdown network sync modules
#if defined(MODLOADER_CLIENT_BUILD)
MapExtensionClient::Sync::Shutdown();
#endif
#if defined(MODLOADER_SERVER_BUILD)
MapExtensionServer::Sync::Shutdown();
#endif
g_registered = false;
#if defined(MODLOADER_CLIENT_BUILD)
Detail::StopHttpServer();
#endif
LOG_INFO("Runtime callbacks unregistered");
}
void HandleProcessDetach(bool processTerminating)
{
#if defined(MODLOADER_CLIENT_BUILD)
Detail::HandleHttpProcessDetach(processTerminating);
#else
(void)processTerminating;
#endif
}
}