Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Core/ModAPI.hpp
1163 views
1
#ifndef MOD_API_H
2
#define MOD_API_H
3
4
#if RETRO_USE_MOD_LOADER
5
#include <vector>
6
#include <string>
7
#include <sstream>
8
#include <map>
9
#include <regex>
10
#include "tinyxml2.h"
11
12
#include <functional>
13
#endif
14
15
namespace RSDK
16
{
17
18
#if RETRO_USE_MOD_LOADER
19
20
#define LEGACY_PLAYERNAME_COUNT (0x10)
21
22
extern std::map<uint32, uint32> superLevels;
23
extern int32 inheritLevel;
24
25
enum ModCallbackEvents {
26
MODCB_ONGAMESTARTUP,
27
MODCB_ONSTATICLOAD,
28
MODCB_ONSTAGELOAD,
29
MODCB_ONUPDATE,
30
MODCB_ONLATEUPDATE,
31
MODCB_ONSTATICUPDATE,
32
MODCB_ONDRAW,
33
MODCB_ONSTAGEUNLOAD,
34
MODCB_ONSHADERLOAD,
35
MODCB_ONVIDEOSKIPCB,
36
MODCB_ONSCANLINECB,
37
MODCB_MAX,
38
};
39
40
enum ModSuper {
41
SUPER_UPDATE,
42
SUPER_LATEUPDATE,
43
SUPER_STATICUPDATE,
44
SUPER_DRAW,
45
SUPER_CREATE,
46
SUPER_STAGELOAD,
47
SUPER_EDITORLOAD,
48
SUPER_EDITORDRAW,
49
SUPER_SERIALIZE
50
};
51
52
enum ModFunctionTableIDs {
53
ModTable_RegisterGlobals,
54
ModTable_RegisterObject,
55
ModTable_RegisterObjectSTD,
56
ModTable_RegisterObjectHook,
57
ModTable_FindObject,
58
ModTable_GetGlobals,
59
ModTable_Super,
60
ModTable_LoadModInfo,
61
ModTable_GetModPath,
62
ModTable_GetModCount,
63
ModTable_GetModIDByIndex,
64
ModTable_ForeachModID,
65
ModTable_AddModCallback,
66
ModTable_AddModCallbackSTD,
67
ModTable_AddPublicFunction,
68
ModTable_GetPublicFunction,
69
ModTable_GetSettingsBool,
70
ModTable_GetSettingsInt,
71
ModTable_GetSettingsFloat,
72
ModTable_GetSettingsString,
73
ModTable_SetSettingsBool,
74
ModTable_SetSettingsInt,
75
ModTable_SetSettingsFloat,
76
ModTable_SetSettingsString,
77
ModTable_SaveSettings,
78
ModTable_GetConfigBool,
79
ModTable_GetConfigInt,
80
ModTable_GetConfigFloat,
81
ModTable_GetConfigString,
82
ModTable_ForeachConfig,
83
ModTable_ForeachConfigCategory,
84
ModTable_RegisterAchievement,
85
ModTable_GetAchievementInfo,
86
ModTable_GetAchievementIndexByID,
87
ModTable_GetAchievementCount,
88
ModTable_LoadShader,
89
ModTable_StateMachineRun,
90
ModTable_RegisterStateHook,
91
ModTable_HandleRunState_HighPriority,
92
ModTable_HandleRunState_LowPriority,
93
94
#if RETRO_MOD_LOADER_VER >= 2
95
// Mod Settings (Part 2)
96
ModTable_ForeachSetting,
97
ModTable_ForeachSettingCategory,
98
99
// Files
100
ModTable_ExcludeFile,
101
ModTable_ExcludeAllFiles,
102
ModTable_ReloadFile,
103
ModTable_ReloadAllFiles,
104
105
// Graphics
106
ModTable_GetSpriteAnimation,
107
ModTable_GetSpriteSurface,
108
ModTable_GetPaletteBank,
109
ModTable_GetActivePaletteBuffer,
110
ModTable_GetRGB32To16Buffer,
111
ModTable_GetBlendLookupTable,
112
ModTable_GetSubtractLookupTable,
113
ModTable_GetTintLookupTable,
114
ModTable_GetMaskColor,
115
ModTable_GetScanEdgeBuffer,
116
ModTable_GetCamera,
117
ModTable_GetShader,
118
ModTable_GetModel,
119
ModTable_GetScene3D,
120
ModTable_DrawDynamicAniTile,
121
122
// Audio
123
ModTable_GetSfx,
124
ModTable_GetChannel,
125
126
// Objects/Entities
127
ModTable_GetGroupEntities,
128
129
// Collision
130
ModTable_SetPathGripSensors,
131
ModTable_FloorCollision,
132
ModTable_LWallCollision,
133
ModTable_RoofCollision,
134
ModTable_RWallCollision,
135
ModTable_FindFloorPosition,
136
ModTable_FindLWallPosition,
137
ModTable_FindRoofPosition,
138
ModTable_FindRWallPosition,
139
ModTable_CopyCollisionMask,
140
ModTable_GetCollisionInfo,
141
#endif
142
143
ModTable_Count
144
};
145
146
typedef void (*ModCallback)(void *data);
147
typedef std::function<void(void *data)> ModCallbackSTD;
148
149
typedef bool (*modLink)(EngineInfo *, const char *);
150
typedef std::function<bool(EngineInfo *, const char *)> modLinkSTD;
151
152
struct ModPublicFunctionInfo {
153
std::string name;
154
void *ptr;
155
};
156
157
struct ObjectHook {
158
RETRO_HASH_MD5(hash);
159
Object **staticVars;
160
};
161
162
struct ModVersionInfo {
163
uint8 engineVer;
164
uint8 gameVer;
165
uint8 modLoaderVer;
166
// uint8 engineVer; // 5, 4 or 3
167
};
168
169
struct ModSVInfo {
170
std::string name;
171
Object **staticVars;
172
uint32 size;
173
};
174
175
struct ModInfo {
176
std::string path;
177
std::string id;
178
std::string name;
179
std::string desc;
180
std::string author;
181
std::string version;
182
std::string folderName;
183
bool active;
184
bool redirectSaveRAM;
185
bool disableGameLogic;
186
bool forceScripts;
187
int32 targetVersion;
188
int32 forceVersion;
189
std::map<std::string, std::string> fileMap;
190
std::vector<std::string> excludedFiles;
191
std::vector<ModPublicFunctionInfo> functionList;
192
std::vector<Link::Handle> modLogicHandles;
193
std::vector<modLinkSTD> linkModLogic;
194
void (*unloadMod)();
195
std::map<std::string, std::map<std::string, std::string>> settings;
196
std::map<std::string, std::map<std::string, std::string>> config;
197
198
// mapped to base hash
199
std::map<uint32 *, ModSVInfo> staticVars;
200
};
201
202
struct StateHook {
203
void (*state)();
204
bool32 (*hook)(bool32 skippedState);
205
bool32 priority;
206
};
207
208
struct ModSettings {
209
int32 activeMod = -1;
210
bool32 redirectSaveRAM = false;
211
bool32 disableGameLogic = false;
212
213
#if RETRO_REV0U
214
int32 versionOverride = 0;
215
bool32 forceScripts = false;
216
217
char playerNames[LEGACY_PLAYERNAME_COUNT][0x20];
218
int32 playerCount = 0;
219
#endif
220
};
221
222
extern ModSettings modSettings;
223
extern std::vector<ModInfo> modList;
224
extern std::vector<ModCallbackSTD> modCallbackList[MODCB_MAX];
225
extern std::vector<StateHook> stateHookList;
226
extern std::vector<ObjectHook> objectHookList;
227
extern ModVersionInfo targetModVersion;
228
229
extern char customUserFileDir[0x100];
230
231
extern void *modFunctionTable[ModTable_Count];
232
extern int32 currentObjectID;
233
234
extern ModInfo *currentMod;
235
236
inline void SetActiveMod(int32 id) { modSettings.activeMod = id; }
237
238
void InitModAPI(bool32 getVersion = false);
239
void UnloadMods();
240
void LoadMods(bool newOnly = false, bool32 getVersion = false);
241
bool32 LoadMod(ModInfo *info, const std::string& modsPath, const std::string& folder, bool32 active, bool32 getVersion);
242
void SaveMods();
243
void SortMods();
244
void LoadModSettings();
245
void ApplyModChanges();
246
247
bool32 ScanModFolder(ModInfo *info, const char *targetFile = nullptr, bool32 fromLoadMod = false, bool32 loadingBar = true);
248
inline void RefreshModFolders(bool32 versionOnly = false, bool32 loadingBar = true)
249
{
250
SortMods();
251
for (int32 m = 0; m < modList.size(); ++m) {
252
if (!modList[m].active)
253
break;
254
ScanModFolder(&modList[m], versionOnly ? "Data/Game/GameConfig.bin" : nullptr, true, loadingBar);
255
}
256
}
257
258
void RunModCallbacks(int32 callbackID, void *data);
259
260
// Mod API
261
#if RETRO_REV0U
262
void ModRegisterGlobalVariables(const char *globalsPath, void **globals, uint32 size);
263
264
void ModRegisterObject(Object **staticVars, Object **modStaticVars, const char *name, uint32 entityClassSize, uint32 staticClassSize,
265
uint32 modClassSize, void (*update)(), void (*lateUpdate)(), void (*staticUpdate)(), void (*draw)(), void (*create)(void *),
266
void (*stageLoad)(), void (*editorLoad)(), void (*editorDraw)(), void (*serialize)(), void (*staticLoad)(Object *),
267
const char *inherited);
268
269
void ModRegisterObject_STD(Object **staticVars, Object **modStaticVars, const char *name, uint32 entityClassSize, uint32 staticClassSize,
270
uint32 modClassSize, std::function<void()> update, std::function<void()> lateUpdate, std::function<void()> staticUpdate,
271
std::function<void()> draw, std::function<void(void *)> create, std::function<void()> stageLoad,
272
std::function<void()> editorLoad, std::function<void()> editorDraw, std::function<void()> serialize,
273
std::function<void(Object *)> staticLoad, const char *inherited);
274
#else
275
void ModRegisterGlobalVariables(const char *globalsPath, void **globals, uint32 size);
276
277
void ModRegisterObject(Object **staticVars, Object **modStaticVars, const char *name, uint32 entityClassSize, uint32 staticClassSize,
278
uint32 modClassSize, void (*update)(), void (*lateUpdate)(), void (*staticUpdate)(), void (*draw)(), void (*create)(void *),
279
void (*stageLoad)(), void (*editorLoad)(), void (*editorDraw)(), void (*serialize)(), const char *inherited);
280
281
void ModRegisterObject_STD(Object **staticVars, Object **modStaticVars, const char *name, uint32 entityClassSize, uint32 staticClassSize,
282
uint32 modClassSize, std::function<void()> update, std::function<void()> lateUpdate, std::function<void()> staticUpdate,
283
std::function<void()> draw, std::function<void(void *)> create, std::function<void()> stageLoad,
284
std::function<void()> editorLoad, std::function<void()> editorDraw, std::function<void()> serialize,
285
const char *inherited);
286
#endif
287
288
void ModRegisterObjectHook(Object **staticVars, const char *staticName);
289
Object *ModFindObject(const char *name);
290
291
void *GetGlobals();
292
293
bool32 LoadModInfo(const char *id, String *name, String *description, String *version, bool32 *active);
294
void GetModPath(const char *id, String *result);
295
int32 GetModCount(bool32 active);
296
const char *GetModIDByIndex(uint32 index);
297
bool32 ForeachModID(String *id);
298
299
void AddModCallback(int32 callbackID, ModCallback callback);
300
void AddModCallback_STD(int32 callbackID, ModCallbackSTD callback);
301
void AddPublicFunction(const char *functionName, void *functionPtr);
302
void *GetPublicFunction(const char *id, const char *functionName);
303
304
bool32 GetSettingsBool(const char *id, const char *key, bool32 fallback);
305
int32 GetSettingsInteger(const char *id, const char *key, int32 fallback);
306
float GetSettingsFloat(const char *id, const char *key, float fallback);
307
void GetSettingsString(const char *id, const char *key, String *result, const char *fallback);
308
309
void SetSettingsBool(const char *key, bool32 val);
310
void SetSettingsInteger(const char *key, int32 val);
311
void SetSettingsFloat(const char *key, float val);
312
void SetSettingsString(const char *key, String *val);
313
314
void SaveSettings();
315
316
bool32 GetConfigBool(const char *key, bool32 fallback);
317
int32 GetConfigInteger(const char *key, int32 fallback);
318
float GetConfigFloat(const char *key, float fallback);
319
void GetConfigString(const char *key, String *result, const char *fallback);
320
bool32 ForeachConfig(String *config);
321
bool32 ForeachConfigCategory(String *category);
322
#if RETRO_MOD_LOADER_VER >= 2
323
bool32 ForeachSetting(const char *id, String *setting);
324
bool32 ForeachSettingCategory(const char *id, String *category);
325
#endif
326
327
void Super(int32 objectID, ModSuper callback, void *data);
328
329
void GetAchievementInfo(uint32 id, String *name, String *description, String *identifer, bool32 *achieved);
330
int32 GetAchievementIndexByID(const char *id);
331
int32 GetAchievementCount();
332
333
void StateMachineRun(void (*state)(void));
334
bool32 HandleRunState_HighPriority(void (*state)(void));
335
void HandleRunState_LowPriority(void (*state)(void), bool32 skipState);
336
void RegisterStateHook(void (*state)(void), bool32 (*hook)(bool32 skippedState), bool32 priority);
337
338
#if RETRO_MOD_LOADER_VER >= 2
339
340
// Files
341
bool32 ExcludeFile(const char *id, const char *path);
342
bool32 ExcludeAllFiles(const char *id);
343
bool32 ReloadFile(const char *id, const char *path);
344
bool32 ReloadAllFiles(const char *id);
345
346
// Graphics
347
inline void *GetSpriteAnimation(uint16 id)
348
{
349
if (id >= SPRFILE_COUNT)
350
return NULL;
351
return &spriteAnimationList[id];
352
}
353
inline void *GetSpriteSurface(uint16 id)
354
{
355
if (id >= SURFACE_COUNT)
356
return NULL;
357
return &gfxSurface[id];
358
}
359
inline uint16 *GetPaletteBank(uint8 id)
360
{
361
if (id >= PALETTE_BANK_COUNT)
362
return NULL;
363
return fullPalette[id];
364
}
365
inline uint8 *GetActivePaletteBuffer() { return gfxLineBuffer; }
366
inline void GetRGB32To16Buffer(uint16 **rgb32To16_R, uint16 **rgb32To16_G, uint16 **rgb32To16_B)
367
{
368
if (rgb32To16_R)
369
*rgb32To16_R = RSDK::rgb32To16_R;
370
371
if (rgb32To16_G)
372
*rgb32To16_G = RSDK::rgb32To16_G;
373
374
if (rgb32To16_B)
375
*rgb32To16_B = RSDK::rgb32To16_B;
376
}
377
inline uint16 *GetBlendLookupTable() { return blendLookupTable; }
378
inline uint16 *GetSubtractLookupTable() { return subtractLookupTable; }
379
inline color GetMaskColor() { return maskColor; }
380
inline void *GetScanEdgeBuffer() { return scanEdgeBuffer; }
381
inline void *GetCamera(uint8 id)
382
{
383
if (id >= CAMERA_COUNT)
384
return NULL;
385
return &cameras[id];
386
}
387
inline void *GetShader(uint8 id)
388
{
389
if (id >= SHADER_COUNT)
390
return NULL;
391
return &shaderList[id];
392
}
393
inline void *GetModel(uint16 id)
394
{
395
if (id >= MODEL_COUNT)
396
return NULL;
397
return &modelList[id];
398
}
399
inline void *GetScene3D(uint16 id)
400
{
401
if (id >= SCENE3D_COUNT)
402
return NULL;
403
return &scene3DList[id];
404
}
405
406
// Audio
407
inline void *GetSfxEntry(uint16 id)
408
{
409
if (id >= SFX_COUNT)
410
return NULL;
411
return &sfxList[id];
412
}
413
inline void *GetChannel(uint8 id)
414
{
415
if (id >= CHANNEL_COUNT)
416
return NULL;
417
return &channels[id];
418
}
419
420
// Objects/Entities
421
bool32 GetGroupEntities(uint16 group, void **entity);
422
#endif
423
424
#endif
425
426
#if RETRO_REV0U
427
#include "Legacy/ModAPILegacy.hpp"
428
#endif
429
430
} // namespace RSDK
431
432
#if RETRO_USE_MOD_LOADER && RETRO_PLATFORM == RETRO_ANDROID
433
#if _INTELLISENSE_ANDROID
434
#include "RetroEngine.hpp"
435
#endif
436
437
#include <iterator>
438
#include <cstddef>
439
#include <forward_list>
440
441
extern jmethodID fsExists;
442
extern jmethodID fsIsDir;
443
extern jmethodID fsDirIter;
444
extern jmethodID fsRecurseIter;
445
446
namespace fs
447
{
448
struct filesystem_error {
449
const char *what() { return err.c_str(); }
450
451
private:
452
std::string err;
453
};
454
455
struct path {
456
path() = default;
457
path(std::string str) : pathStr(str){};
458
const std::string &string() const { return pathStr; }
459
path filename() { return pathStr.substr(pathStr.find_last_of('/') + 1); }
460
461
private:
462
std::string pathStr = "";
463
};
464
465
bool exists(path path);
466
467
bool is_directory(path path);
468
469
struct directory_entry {
470
directory_entry() = default;
471
directory_entry(fs::path p) : m_path(p){};
472
473
bool exists() { return fs::exists(m_path); }
474
475
bool is_directory() { return fs::is_directory(m_path); }
476
477
bool is_regular_file() { return !fs::is_directory(m_path); }
478
479
const path &path() { return m_path; }
480
481
private:
482
fs::path m_path;
483
};
484
485
class path_list : public std::vector<directory_entry>
486
{
487
public:
488
path_list(jobjectArray array)
489
{
490
vector();
491
auto *jni = GetJNISetup();
492
int len = jni->env->GetArrayLength(array);
493
for (int i = 0; i < len; ++i) {
494
jstring jstr = (jstring)jni->env->GetObjectArrayElement(array, i);
495
const char *str = jni->env->GetStringUTFChars(jstr, NULL);
496
this->push_back(directory_entry(std::string(str)));
497
jni->env->ReleaseStringUTFChars(jstr, str);
498
}
499
}
500
};
501
502
enum class directory_options { follow_directory_symlink = 0 };
503
504
path_list directory_iterator(path path);
505
506
class recursive_directory_iterator
507
{
508
struct JNISetup *jni = nullptr;
509
directory_entry current;
510
511
jstring jstr;
512
const char *str = nullptr;
513
514
jbyteArray jpath;
515
516
public:
517
using iterator_category = std::input_iterator_tag;
518
using value_type = directory_entry;
519
using difference_type = ptrdiff_t;
520
using pointer = const directory_entry *;
521
using reference = const directory_entry &;
522
523
recursive_directory_iterator() = default;
524
recursive_directory_iterator(path path, directory_options _)
525
{
526
(void)_;
527
jni = GetJNISetup();
528
jpath = jni->env->NewByteArray(path.string().length());
529
jni->env->SetByteArrayRegion(jpath, 0, path.string().length(), (jbyte *)path.string().c_str());
530
operator++();
531
};
532
533
// this class is modified from the MSVC headers LMAO
534
535
bool operator==(const recursive_directory_iterator &rhs) const noexcept { return jni == rhs.jni; }
536
bool operator!=(const recursive_directory_iterator &rhs) const noexcept { return jni != rhs.jni; }
537
const directory_entry &operator*() const noexcept { return current; }
538
539
const directory_entry *operator->() const noexcept { return &**this; }
540
541
recursive_directory_iterator &operator++()
542
{
543
if (str) {
544
jni->env->ReleaseStringUTFChars(jstr, str);
545
}
546
jstr = (jstring)jni->env->CallObjectMethod(jni->thiz, fsRecurseIter, jpath);
547
if (jstr == NULL) {
548
*this = {};
549
}
550
else {
551
str = jni->env->GetStringUTFChars(jstr, NULL);
552
current = directory_entry(fs::path(str));
553
}
554
return *this;
555
}
556
557
inline recursive_directory_iterator begin() noexcept { return *this; }
558
559
inline recursive_directory_iterator end() noexcept { return {}; }
560
};
561
562
}; // namespace fs
563
#endif
564
565
#endif // !MOD_API_H
566
567