Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Core/Link.hpp
1163 views
1
#ifndef LINK_H
2
#define LINK_H
3
4
namespace RSDK
5
{
6
7
#if RETRO_REV02
8
enum APITableIDs {
9
APITable_GetUserLanguage,
10
APITable_GetConfirmButtonFlip,
11
APITable_ExitGame,
12
APITable_LaunchManual,
13
#if RETRO_REV0U
14
APITable_GetDefaultGamepadType,
15
#endif
16
APITable_IsOverlayEnabled,
17
APITable_CheckDLC,
18
#if RETRO_VER_EGS
19
APITable_SetupExtensionOverlay,
20
APITable_CanShowExtensionOverlay,
21
APITable_ShowExtensionOverlay,
22
APITable_CanShowAltExtensionOverlay,
23
APITable_ShowAltExtensionOverlay,
24
APITable_GetConnectingStringID,
25
APITable_ShowLimitedVideoOptions,
26
#else
27
APITable_ShowExtensionOverlay,
28
#endif
29
APITable_UnlockAchievement,
30
APITable_GetAchievementsEnabled,
31
APITable_SetAchievementsEnabled,
32
#if RETRO_VER_EGS
33
APITable_CheckAchievementsEnabled,
34
APITable_SetAchievementNames,
35
#endif
36
APITable_InitLeaderboards,
37
#if RETRO_VER_EGS
38
APITable_CheckLeaderboardsEnabled,
39
#endif
40
APITable_FetchLeaderboard,
41
APITable_TrackScore,
42
APITable_GetLeaderboardsStatus,
43
APITable_LeaderboardEntryViewSize,
44
APITable_LeaderboardEntryLoadSize,
45
APITable_LoadLeaderboardEntries,
46
APITable_ResetLeaderboardInfo,
47
APITable_ReadLeaderboardEntry,
48
APITable_SetPresence,
49
APITable_TryTrackStat,
50
APITable_GetStatsEnabled,
51
APITable_SetStatsEnabled,
52
APITable_ClearPrerollErrors,
53
APITable_TryAuth,
54
APITable_GetUserAuthStatus,
55
APITable_GetUsername,
56
APITable_TryInitStorage,
57
APITable_GetUserStorageStatus,
58
APITable_GetSaveStatus,
59
APITable_ClearSaveStatus,
60
APITable_SetSaveStatusContinue,
61
APITable_SetSaveStatusOK,
62
APITable_SetSaveStatusForbidden,
63
APITable_SetSaveStatusError,
64
APITable_SetUserStorageNoSave,
65
APITable_GetUserStorageNoSave,
66
APITable_LoadUserFile,
67
APITable_SaveUserFile,
68
APITable_DeleteUserFile,
69
APITable_InitUserDB,
70
APITable_OpenUserDB,
71
APITable_SaveUserDB,
72
APITable_ClearUserDB,
73
APITable_ClearAllUserDBs,
74
APITable_SetupUserDBRowSorting,
75
APITable_GetUserDBRowsChanged,
76
APITable_AddUserDBRowSortFilter,
77
APITable_SortUserDBRows,
78
APITable_GetSortedUserDBRowCount,
79
APITable_GetSortedUserDBRowID,
80
APITable_AddUserDBRow,
81
APITable_SetUserDBValue,
82
APITable_GetUserDBValue,
83
APITable_GetRowUUID,
84
APITable_GetUserDBRowByID,
85
APITable_GetUserDBRowCreationTime,
86
APITable_RemoveDBRow,
87
APITable_RemoveAllDBRows,
88
APITable_Count,
89
};
90
#else
91
#define APITABLE_COUNT (32)
92
#endif
93
94
enum FunctionTableIDs {
95
FunctionTable_RegisterGlobalVariables,
96
FunctionTable_RegisterObject,
97
#if RETRO_REV02
98
FunctionTable_RegisterStaticVariables,
99
#endif
100
FunctionTable_GetActiveEntities,
101
FunctionTable_GetAllEntities,
102
FunctionTable_BreakForeachLoop,
103
FunctionTable_SetEditableVar,
104
FunctionTable_GetEntity,
105
FunctionTable_GetEntitySlot,
106
FunctionTable_GetEntityCount,
107
FunctionTable_GetDrawListRefSlot,
108
FunctionTable_GetDrawListRef,
109
FunctionTable_ResetEntity,
110
FunctionTable_ResetEntitySlot,
111
FunctionTable_CreateEntity,
112
FunctionTable_CopyEntity,
113
FunctionTable_CheckOnScreen,
114
FunctionTable_CheckPosOnScreen,
115
FunctionTable_AddDrawListRef,
116
FunctionTable_SwapDrawListEntries,
117
FunctionTable_SetDrawGroupProperties,
118
FunctionTable_SetScene,
119
FunctionTable_SetEngineState,
120
#if RETRO_REV02
121
FunctionTable_ForceHardReset,
122
#endif
123
FunctionTable_CheckValidScene,
124
FunctionTable_CheckSceneFolder,
125
FunctionTable_LoadScene,
126
FunctionTable_FindObject,
127
FunctionTable_ClearCameras,
128
FunctionTable_AddCamera,
129
#if !RETRO_REV02
130
FunctionTable_GetAPIFunction,
131
#endif
132
FunctionTable_GetVideoSetting,
133
FunctionTable_SetVideoSetting,
134
FunctionTable_UpdateWindow,
135
FunctionTable_Sin1024,
136
FunctionTable_Cos1024,
137
FunctionTable_ATan1024,
138
FunctionTable_ASin1024,
139
FunctionTable_ACos1024,
140
FunctionTable_Sin512,
141
FunctionTable_Cos512,
142
FunctionTable_ATan512,
143
FunctionTable_ASin512,
144
FunctionTable_ACos512,
145
FunctionTable_Sin256,
146
FunctionTable_Cos256,
147
FunctionTable_ATan256,
148
FunctionTable_ASin256,
149
FunctionTable_ACos256,
150
FunctionTable_Rand,
151
FunctionTable_RandSeeded,
152
FunctionTable_SetRandSeed,
153
FunctionTable_ATan2,
154
FunctionTable_SetIdentityMatrix,
155
FunctionTable_MatrixMultiply,
156
FunctionTable_MatrixTranslateXYZ,
157
FunctionTable_MatrixScaleXYZ,
158
FunctionTable_MatrixRotateX,
159
FunctionTable_MatrixRotateY,
160
FunctionTable_MatrixRotateZ,
161
FunctionTable_MatrixRotateXYZ,
162
FunctionTable_MatrixInverse,
163
FunctionTable_MatrixCopy,
164
FunctionTable_InitString,
165
FunctionTable_CopyString,
166
FunctionTable_SetString,
167
FunctionTable_AppendString,
168
FunctionTable_AppendText,
169
FunctionTable_LoadStringList,
170
FunctionTable_SplitStringList,
171
FunctionTable_GetCString,
172
FunctionTable_CompareStrings,
173
FunctionTable_GetDisplayInfo,
174
FunctionTable_GetWindowSize,
175
FunctionTable_SetScreenSize,
176
FunctionTable_SetClipBounds,
177
#if RETRO_REV02
178
FunctionTable_SetScreenVertices,
179
#endif
180
FunctionTable_LoadSpriteSheet,
181
FunctionTable_SetTintLookupTable,
182
FunctionTable_SetPaletteMask,
183
FunctionTable_SetPaletteEntry,
184
FunctionTable_GetPaletteEntry,
185
FunctionTable_SetActivePalette,
186
FunctionTable_CopyPalette,
187
#if RETRO_REV02
188
FunctionTable_LoadPalette,
189
#endif
190
FunctionTable_RotatePalette,
191
FunctionTable_SetLimitedFade,
192
#if RETRO_REV02
193
FunctionTable_BlendColors,
194
#endif
195
FunctionTable_DrawRect,
196
FunctionTable_DrawLine,
197
FunctionTable_DrawCircle,
198
FunctionTable_DrawCircleOutline,
199
FunctionTable_DrawFace,
200
FunctionTable_DrawBlendedFace,
201
FunctionTable_DrawSprite,
202
FunctionTable_DrawDeformedSprite,
203
FunctionTable_DrawString,
204
FunctionTable_DrawTile,
205
FunctionTable_CopyTile,
206
FunctionTable_DrawAniTile,
207
#if RETRO_REV0U
208
FunctionTable_DrawDynamicAniTile,
209
#endif
210
FunctionTable_FillScreen,
211
FunctionTable_LoadMesh,
212
FunctionTable_Create3DScene,
213
FunctionTable_Prepare3DScene,
214
FunctionTable_SetDiffuseColor,
215
FunctionTable_SetDiffuseIntensity,
216
FunctionTable_SetSpecularIntensity,
217
FunctionTable_AddModelToScene,
218
FunctionTable_SetModelAnimation,
219
FunctionTable_AddMeshFrameToScene,
220
FunctionTable_Draw3DScene,
221
FunctionTable_LoadSpriteAnimation,
222
FunctionTable_CreateSpriteAnimation,
223
FunctionTable_SetSpriteAnimation,
224
FunctionTable_EditSpriteAnimation,
225
FunctionTable_SetSpriteString,
226
FunctionTable_FindSpriteAnimation,
227
FunctionTable_GetFrame,
228
FunctionTable_GetHitbox,
229
FunctionTable_GetFrameID,
230
FunctionTable_GetStringWidth,
231
FunctionTable_ProcessAnimation,
232
FunctionTable_GetTileLayerID,
233
FunctionTable_GetTileLayer,
234
FunctionTable_GetLayerSize,
235
FunctionTable_GetTile,
236
FunctionTable_SetTile,
237
FunctionTable_CopyTileLayer,
238
FunctionTable_ProcessParallax,
239
FunctionTable_GetScanlines,
240
FunctionTable_CheckObjectCollisionTouch,
241
FunctionTable_CheckObjectCollisionCircle,
242
FunctionTable_CheckObjectCollisionBox,
243
FunctionTable_CheckObjectCollisionPlatform,
244
FunctionTable_ObjectTileCollision,
245
FunctionTable_ObjectTileGrip,
246
FunctionTable_ProcessObjectMovement,
247
#if RETRO_REV0U
248
FunctionTable_SetupCollisionConfig,
249
FunctionTable_SetPathGripSensors,
250
FunctionTable_FloorCollision,
251
FunctionTable_LWallCollision,
252
FunctionTable_RoofCollision,
253
FunctionTable_RWallCollision,
254
FunctionTable_FindFloorPosition,
255
FunctionTable_FindLWallPosition,
256
FunctionTable_FindRoofPosition,
257
FunctionTable_FindRWallPosition,
258
#endif
259
FunctionTable_GetTileAngle,
260
FunctionTable_SetTileAngle,
261
FunctionTable_GetTileFlags,
262
FunctionTable_SetTileFlags,
263
#if RETRO_REV0U
264
FunctionTable_CopyCollisionMask,
265
FunctionTable_GetCollisionInfo,
266
#endif
267
FunctionTable_GetSfx,
268
FunctionTable_PlaySfx,
269
FunctionTable_StopSfx,
270
FunctionTable_PlayMusic,
271
FunctionTable_SetChannelAttributes,
272
FunctionTable_StopChannel,
273
FunctionTable_PauseChannel,
274
FunctionTable_ResumeChannel,
275
FunctionTable_SfxPlaying,
276
FunctionTable_ChannelActive,
277
FunctionTable_GetChannelPos,
278
FunctionTable_LoadVideo,
279
FunctionTable_LoadImage,
280
#if RETRO_REV02
281
FunctionTable_GetInputDeviceID,
282
FunctionTable_GetFilteredInputDeviceID,
283
FunctionTable_GetInputDeviceType,
284
FunctionTable_IsInputDeviceAssigned,
285
FunctionTable_GetInputDeviceUnknown,
286
FunctionTable_InputDeviceUnknown1,
287
FunctionTable_InputDeviceUnknown2,
288
FunctionTable_GetInputSlotUnknown,
289
FunctionTable_InputSlotUnknown1,
290
FunctionTable_InputSlotUnknown2,
291
FunctionTable_AssignInputSlotToDevice,
292
FunctionTable_IsInputSlotAssigned,
293
FunctionTable_ResetInputSlotAssignments,
294
#endif
295
#if !RETRO_REV02
296
FunctionTable_GetUnknownInputValue,
297
#endif
298
FunctionTable_LoadUserFile,
299
FunctionTable_SaveUserFile,
300
#if RETRO_REV02
301
FunctionTable_PrintLog,
302
FunctionTable_PrintText,
303
FunctionTable_PrintString,
304
FunctionTable_PrintUInt32,
305
FunctionTable_PrintInt32,
306
FunctionTable_PrintFloat,
307
FunctionTable_PrintVector2,
308
FunctionTable_PrintHitbox,
309
#endif
310
FunctionTable_SetActiveVariable,
311
FunctionTable_AddEnumVariable,
312
#if !RETRO_REV02
313
FunctionTable_PrintMessage,
314
#endif
315
#if RETRO_REV02
316
FunctionTable_ClearDebugValues,
317
FunctionTable_SetDebugValue,
318
#endif
319
#if RETRO_REV0U
320
FunctionTable_NotifyCallback,
321
FunctionTable_SetGameFinished,
322
FunctionTable_StopAllSfx,
323
#endif
324
FunctionTable_Count,
325
};
326
327
extern void *RSDKFunctionTable[FunctionTable_Count];
328
#if RETRO_REV02
329
extern void *APIFunctionTable[APITable_Count];
330
#else
331
struct APITableEntry {
332
void *ptr;
333
RETRO_HASH_MD5(hash);
334
};
335
336
extern APITableEntry APIFunctionTable[APITABLE_COUNT];
337
extern int32 APIFunctionTableCount;
338
#endif
339
340
#if RETRO_REV02
341
struct EngineInfo {
342
void *functionTable;
343
void *APITable;
344
345
GameVersionInfo *gameInfo;
346
SKU::SKUInfo *currentSKU;
347
SceneInfo *sceneInfo;
348
349
ControllerState *controller;
350
AnalogState *stickL;
351
AnalogState *stickR;
352
TriggerState *triggerL;
353
TriggerState *triggerR;
354
TouchInfo *touchMouse;
355
356
SKU::UnknownInfo *unknown;
357
358
ScreenInfo *screenInfo;
359
360
#if RETRO_REV0U
361
// only for origins, not technically needed for v5U if standalone I think
362
void *hedgehogLink;
363
#endif
364
365
#if RETRO_USE_MOD_LOADER
366
void *modTable;
367
#endif
368
};
369
#else
370
struct EngineInfo {
371
void *functionTable;
372
373
GameVersionInfo *gameInfo;
374
SceneInfo *sceneInfo;
375
376
ControllerState *controllerInfo;
377
AnalogState *stickInfo;
378
379
TouchInfo *touchInfo;
380
381
ScreenInfo *screenInfo;
382
383
#if RETRO_USE_MOD_LOADER
384
void *modTable;
385
#endif
386
};
387
#endif
388
389
void SetupFunctionTables();
390
391
#if RETRO_REV02
392
void LinkGameLogic(void *info);
393
#else
394
void LinkGameLogic(EngineInfo info);
395
#endif
396
397
// ORIGINAL CLASS
398
399
// Windows.h already included by master header
400
#if !(RETRO_PLATFORM == RETRO_WIN || RETRO_PLATFORM == RETRO_SWITCH)
401
#include <dlfcn.h>
402
#endif
403
404
// Only define this if you want to prioritize checking libraries first (Game_x64.dll then Game.dll)
405
// e.x. -DRETRO_ARCHIITECTURE="x64"
406
#ifndef RETRO_ARCHITECTURE
407
#define RETRO_ARCHITECTURE NULL
408
#endif
409
410
class Link
411
{
412
public:
413
#if RETRO_PLATFORM == RETRO_WIN
414
typedef HMODULE Handle;
415
// constexpr was added in C++11 this is safe don't kill me
416
static constexpr const char *extention = ".dll";
417
static constexpr const char *prefix = NULL;
418
#elif RETRO_PLATFORM == RETRO_SWITCH
419
typedef DynModule *Handle;
420
static constexpr const char *extention = ".elf";
421
static constexpr const char *prefix = NULL;
422
423
static Handle dlopen(const char *, int);
424
static void *dlsym(Handle, const char *);
425
static int dlclose(Handle);
426
static char *dlerror();
427
428
static constexpr const int RTLD_LOCAL = 0;
429
static constexpr const int RTLD_LAZY = 0;
430
431
private:
432
static Result err;
433
434
public:
435
#else
436
typedef void *Handle;
437
static constexpr const char *prefix = "lib";
438
#if RETRO_PLATFORM == RETRO_OSX
439
static constexpr const char *extention = ".dylib";
440
#else
441
static constexpr const char *extention = ".so";
442
#endif
443
#endif
444
445
static inline Handle PlatformLoadLibrary(std::string path)
446
{
447
Handle ret;
448
#if RETRO_PLATFORM == RETRO_WIN
449
ret = (Handle)LoadLibraryA(path.c_str());
450
#else
451
#if RETRO_PLATFORM == RETRO_ANDROID
452
// path should only load local libs
453
if (path.find_last_of('/') != std::string::npos)
454
path = path.substr(path.find_last_of('/') + 1);
455
path = "lib" + path;
456
#endif // ! RETRO_PLATFORM == ANDROID
457
ret = (Handle)dlopen(path.c_str(), RTLD_LOCAL | RTLD_LAZY);
458
#if RETRO_PLATFORM != RETRO_SWITCH
459
// try loading the library globally on linux
460
if (!ret) {
461
if (path.find_last_of('/') != std::string::npos)
462
path = path.substr(path.find_last_of('/') + 1);
463
ret = (Handle)dlopen(path.c_str(), RTLD_LOCAL | RTLD_LAZY);
464
}
465
#endif // ! RETRO_PLATFORM != SWITCH
466
#endif // ! RETRO_PLATFORM == WIN
467
return ret;
468
}
469
470
static inline Handle Open(std::string path)
471
{
472
std::string original_path = path;
473
474
// if it ends with extension
475
if (path.length() >= strlen(extention) && 0 == path.compare(path.length() - strlen(extention), strlen(extention), extention)) {
476
// remove it!
477
path = path.substr(0, path.size() - strlen(extention));
478
}
479
480
#if RETRO_ARCHITECTURE
481
path += "_" RETRO_ARCHITECTURE;
482
#endif // ! RETRO_ARCHITECTURE
483
484
// put it again!
485
path += extention;
486
487
Handle ret = NULL;
488
if (prefix) {
489
int32 last = (int32)path.find_last_of('/') + 1;
490
if (last == std::string::npos + 1)
491
ret = PlatformLoadLibrary(prefix + path);
492
else
493
ret = PlatformLoadLibrary(path.substr(0, last) + prefix + path.substr(last));
494
}
495
if (!ret)
496
ret = PlatformLoadLibrary(path);
497
498
#if RETRO_ARCHITECTURE
499
if (!ret) {
500
if (prefix) {
501
int32 last = original_path.find_last_of('/') + 1;
502
if (last == std::string::npos + 1)
503
ret = PlatformLoadLibrary(prefix + original_path);
504
else
505
ret = PlatformLoadLibrary(original_path.substr(0, last) + prefix + original_path.substr(last));
506
}
507
if (!ret)
508
ret = PlatformLoadLibrary(original_path);
509
}
510
#endif // ! RETRO_ARCHITECTURE
511
return ret;
512
}
513
514
static inline void Close(Handle handle)
515
{
516
if (handle)
517
#if RETRO_PLATFORM == RETRO_WIN
518
FreeLibrary(handle);
519
#else
520
dlclose(handle);
521
#endif
522
}
523
524
static inline void *GetSymbol(Handle handle, const char *symbol)
525
{
526
if (!handle)
527
return NULL;
528
#if RETRO_PLATFORM == RETRO_WIN
529
return (void *)GetProcAddress(handle, symbol);
530
#else
531
return (void *)dlsym(handle, symbol);
532
#endif
533
}
534
535
static inline char *GetError()
536
{
537
#if RETRO_PLATFORM == RETRO_WIN
538
return (char *)GetLastErrorAsString();
539
#else
540
return dlerror();
541
#endif
542
}
543
544
private:
545
#if RETRO_PLATFORM == RETRO_WIN
546
#if _MSC_VER
547
// from here: https://stackoverflow.com/a/17387176
548
// WINAPI sucks lol
549
// Returns the last Win32 error, in string format. Returns an empty string if there is no error.
550
static inline char *GetLastErrorAsString()
551
{
552
// Get the error message ID, if any.
553
DWORD errorMessageID = ::GetLastError();
554
if (errorMessageID == 0) {
555
return (char *)""; // No error message has been recorded
556
}
557
558
LPSTR messageBuffer = nullptr;
559
560
// Ask Win32 to give us the string version of that message ID.
561
// The parameters we pass in, tell Win32 to create the buffer that holds the message for us (because we don't yet know how long the message
562
// string will be).
563
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
564
errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
565
566
// Copy the error message into a std::string.
567
std::string message(messageBuffer, size);
568
569
// Free the Win32's string's buffer.
570
LocalFree(messageBuffer);
571
572
strcpy(textBuffer, message.c_str());
573
return textBuffer;
574
}
575
#else
576
static inline char *GetLastErrorAsString() { return (char *)""; }
577
#endif
578
#endif
579
};
580
581
} // namespace RSDK
582
583
#endif
584
585