-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEC.cpp
More file actions
248 lines (218 loc) · 6.52 KB
/
EC.cpp
File metadata and controls
248 lines (218 loc) · 6.52 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "EC.h"
namespace Init
{
bool Initialize();
bool __cdecl RegisterEntry(LibFuncHandle Entry);
}
bool HasSyringeIH()
{
return SyringeData::HasSyringeIH();
}
bool IHAvailable();
bool HasIH()
{
return IHAvailable();
}
#ifndef SIWIC
bool HasWIC()
{
return SITool::Available();
}
#endif
ECDispatchException::ECDispatchException(const char* info) : Info(info) {};
const char* ECDispatchException::what() const noexcept
{
return Info;
}
std::unordered_map<std::string, LibFuncHandle> ListenerMap;
LibFuncHandle __cdecl ListenerAccess(const char* Name)
{
auto it = ListenerMap.find(Name);
if (it != ListenerMap.end())return it->second;
else return nullptr;
}
namespace ECListener
{
void Set(const char* ListenerType, LibFuncHandle Function)
{
ListenerMap[ListenerType] = Function;
}
LibFuncHandle Get(const char* ListenerType)
{
return ListenerAccess(ListenerType);
}
void Remove(const char* ListenerType)
{
if (ListenerMap.find(ListenerType) != ListenerMap.end())ListenerMap.erase(ListenerType);
}
InitialLoad::Service<InitialLoadParam_RegisterFunction>InternalService_ListenerAccess("EC::Internal::ListenerAccess");
std::vector<LibFuncHandle> GetAll(const char* ListenerType)
{
std::vector<LibFuncHandle> Result;
InternalService_ListenerAccess.RefreshAndProcess([&](const InitialLoadParam_RegisterFunction& Request)
{
if (Request.Handle)
{
auto hd = AsType<decltype(ListenerAccess)>(Request.Handle)(ListenerType);
if (hd)Result.push_back(hd);
}
});
return Result;
}
void Listen_InitBeforeEverything(Listener_InitBeforeEverything Func)
{
Set("EC::InitBeforeEverything", Func);
}
void Listen_LoadBeforeTypeData(Listener_OnLoadGame Func)
{
Set("EC::OnReadingRules", Func);
}
void Listen_LoadAfterTypeData(Listener_OnLoadGame Func)
{
Set("EC::LoadAfterTypeData", Func);
}
void Listen_BeginWritingExceptIH(Listener_BeginWritingExceptIH Func)
{
Set("EC::BeginWritingExceptIH", Func);
}
void Listen_LoadCSFString(Listener_LoadCSFString Func)
{
Set("EC::OnLoadCSFString", Func);
}
void Listen_LoadScenario(Listener_LoadScenario Func)
{
Set("EC::OnLoadScenario", Func);
}
void Listen_AfterLoadGame(Listener_AfterLoadGame Func)
{
Set("EC::AfterLoadGame", Func);
}
void Listen_AfterLoadINI(Listener_AfterLoadINI Func)
{
Set("EC::AfterLoadINI", Func);
}
void Listen_ClearScenario(Listener_ClearScenario Func)
{
Set("EC::ClearScenario", Func);
}
}
FuncInfo* __cdecl NullGetFunc(const char* Name, int Version)
{
return nullptr;
}
using UTF8_SString = std::basic_string< UTF8_CharType, std::char_traits<UTF8_CharType>, std::allocator<UTF8_CharType> >;
std::string Temp_LibraryName;
int Temp_Version;
UTF8_SString Temp_Description;
std::function<void()> Temp_OnFirstInit;
std::function<void()> Temp_OnOrderedInit;
std::vector<InitDependency> Temp_Dependencies;
LibVersionInfo Temp_VersionInfo;
GetFunc_t Temp_GetFunc;
std::unordered_map<std::string, FuncInfo> Temp_FuncList;
FuncInfo* __cdecl GetFuncFromList(const char* Name, int Version)
{
if (Version != DoNotCheckVersion && Temp_Version < Version)return nullptr;
auto it = Temp_FuncList.find(Name);
if (it == Temp_FuncList.end())return nullptr;
else return &it->second;
}
void StoreInitConfig(
const char* LibraryName, //库名
int Version,
int LowestSupportedVersion,
UTF8_CString Description,
const std::function<void()>& OnFirstInit,
const std::function<void()>& OnOrderedInit,
std::initializer_list<InitDependency> Dependencies
)
{
Temp_LibraryName = LibraryName ? LibraryName : "";
Temp_Description = Description ? UTF8_SString(Description) : UTF8_SString();
Temp_OnFirstInit = OnFirstInit;
Temp_OnOrderedInit = OnOrderedInit;
Temp_Dependencies.assign(Dependencies);
Temp_Version = Version;
Temp_VersionInfo.LibName = Temp_LibraryName.c_str();
Temp_VersionInfo.Version = Version;
Temp_VersionInfo.LowestSupportedVersion = LowestSupportedVersion;
Temp_VersionInfo.Description = Temp_Description.c_str();
}
bool ECInitLibrary(
const char* LibraryName, //库名
int Version,
int LowestSupportedVersion,
UTF8_CString Description,
const std::function<void()>& OnFirstInit,
const std::function<void()>& OnOrderedInit,
std::initializer_list<InitDependency> Dependencies
)
{
StoreInitConfig(LibraryName, Version, LowestSupportedVersion, Description, OnFirstInit, OnOrderedInit, Dependencies);
Temp_GetFunc = NullGetFunc;
return Init::Initialize();
}
bool ECInitLibrary(
const char* LibraryName, //库名
int Version,
int LowestSupportedVersion,
UTF8_CString Description,
const std::function<void()>& OnFirstInit,
const std::function<void()>& OnOrderedInit,
GetFunc_t GetFunc,
std::initializer_list<InitDependency> Dependencies
)
{
StoreInitConfig(LibraryName, Version, LowestSupportedVersion, Description, OnFirstInit, OnOrderedInit, Dependencies);
Temp_GetFunc = GetFunc;
return Init::Initialize();
}
bool ECInitLibrary(
const char* LibraryName, //库名
int Version,
int LowestSupportedVersion,
UTF8_CString Description,
const std::function<void()>& OnFirstInit,
const std::function<void()>& OnOrderedInit,
const std::unordered_map<std::string, LibFuncHandle>& ExportFuncs,
std::initializer_list<InitDependency> Dependencies
)
{
StoreInitConfig(LibraryName, Version, LowestSupportedVersion, Description, OnFirstInit, OnOrderedInit, Dependencies);
Temp_GetFunc = GetFuncFromList;
for (const auto& p : ExportFuncs)
Temp_FuncList.insert({ p.first, FuncInfo(p.second , FuncType::Default) });
return Init::Initialize();
}
bool ECInitLibrary(
const char* LibraryName, //库名
int Version,
int LowestSupportedVersion,
UTF8_CString Description,
const std::function<void()>& OnFirstInit,
const std::function<void()>& OnOrderedInit,
const std::unordered_map<std::string, FuncInfo>& ExportFuncs,
std::initializer_list<InitDependency> Dependencies
)
{
StoreInitConfig(LibraryName, Version, LowestSupportedVersion, Description, OnFirstInit, OnOrderedInit, Dependencies);
Temp_GetFunc = GetFuncFromList;
Temp_FuncList = ExportFuncs;
return Init::Initialize();
}
void __cdecl MyOrderedInit()
{
if (Temp_OnOrderedInit)Temp_OnOrderedInit();
}
void MyInit(InitResult& Result)
{
Result.Info = &Temp_VersionInfo;
Result.GetFunc = Temp_GetFunc;
Result.Dependencies = PArray<InitDependency>(Temp_Dependencies);
Result.OrderedInit = MyOrderedInit;
if (Temp_OnFirstInit)
{
Temp_OnFirstInit();
}
}