Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/User/Core/UserCore.cpp
1162 views
1
#include "RSDK/Core/RetroEngine.hpp"
2
3
#include "iniparser/iniparser.h"
4
5
// ====================
6
// API Cores
7
// ====================
8
9
namespace RSDK
10
{
11
namespace SKU
12
{
13
// Dummy API
14
#if RETRO_USERCORE_DUMMY
15
#include "RSDK/User/Dummy/DummyCore.cpp"
16
#endif
17
18
// Steam API
19
#if RETRO_USERCORE_STEAM
20
#include "RSDK/User/Steam/SteamCore.cpp"
21
#endif
22
23
// Epic Games API
24
#if RETRO_USERCORE_EOS
25
#include "RSDK/User/EOS/EOSCore.cpp"
26
#endif
27
28
// Switch API
29
#if RETRO_USERCORE_NX
30
#include "RSDK/User/NX/NXCore.cpp"
31
#endif
32
33
} // namespace SKU
34
} // namespace RSDK
35
36
using namespace RSDK;
37
38
#if RETRO_REV02
39
SKU::UserCore *RSDK::SKU::userCore = NULL;
40
#endif
41
42
void RSDK::SKU::InitUserCore()
43
{
44
InitUserDirectory();
45
46
#if RETRO_REV02
47
#if RETRO_USERCORE_DUMMY
48
if (dummyCore)
49
delete dummyCore;
50
dummyCore = InitDummyCore();
51
#endif
52
53
// Initalize platform-specific subsystems here
54
55
#if RETRO_USERCORE_STEAM
56
userCore = InitSteamCore();
57
#endif
58
59
#if RETRO_USERCORE_EOS
60
userCore = InitEOSCore();
61
#endif
62
63
#if RETRO_USERCORE_NX
64
userCore = InitNXCore();
65
#endif
66
67
#if RETRO_USERCORE_DUMMY
68
if (!userCore) { // no platform core, so default to dummy funcs
69
userCore = dummyCore;
70
}
71
else if (dummyCore) {
72
delete dummyCore;
73
dummyCore = nullptr;
74
}
75
#endif
76
77
if (!userDBStorage)
78
userDBStorage = new UserDBStorage;
79
#endif
80
81
#if RETRO_REV02
82
curSKU.platform = userCore->GetUserPlatform();
83
curSKU.language = userCore->GetUserLanguage();
84
curSKU.region = userCore->GetUserRegion();
85
engine.confirmFlip = userCore->GetConfirmButtonFlip();
86
#else
87
88
#if RETRO_PLATFORM == RETRO_PS4
89
gameVerInfo.platform = PLATFORM_PS4;
90
#elif RETRO_PLATFORM == RETRO_XB1
91
gameVerInfo.platform = PLATFORM_XB1;
92
#elif RETRO_PLATFORM == RETRO_SWITCH || RETRO_PLATFORM == RETRO_ANDROID
93
gameVerInfo.platform = PLATFORM_SWITCH;
94
#else
95
// default to PC (or dev if dev stuff is enabled)
96
gameVerInfo.platform = engine.devMenu ? PLATFORM_DEV : PLATFORM_PC;
97
#endif
98
99
gameVerInfo.language = LANGUAGE_EN;
100
gameVerInfo.region = REGION_US;
101
engine.confirmFlip = false;
102
#endif
103
104
#if !RETRO_USE_ORIGINAL_CODE
105
// Add achievements
106
achievementList.clear();
107
achievementStack.clear();
108
RegisterAchievement("ACH_GOLD_MEDAL", "No Way? No Way!", "Collect gold medallions in Blue Spheres Bonus stage");
109
RegisterAchievement("ACH_SILVER_MEDAL", "Full Medal Jacket", "Collect silver medallions in Blue Spheres Bonus stage");
110
RegisterAchievement("ACH_EMERALDS", "Magnificent Seven", "Collect all seven Chaos Emeralds");
111
RegisterAchievement("ACH_GAME_CLEARED", "See You Next Game", "Achieve any ending");
112
RegisterAchievement("ACH_STARPOST", "Superstar", "Spin the Star Post!");
113
RegisterAchievement("ACH_SIGNPOST", "That's a Two-fer", "Find the hidden item boxes at the end of the Zone");
114
RegisterAchievement("ACH_GHZ", "Now It Can't Hurt You Anymore", "What would happen if you cross a bridge with a fire shield?");
115
RegisterAchievement("ACH_CPZ", "Triple Trouble", "Try for a 3 chain combo!");
116
RegisterAchievement("ACH_SPZ", "The Most Famous Hedgehog in the World", "Have your photos taken in Studiopolis Zone");
117
RegisterAchievement("ACH_FBZ", "Window Shopping", "Let the wind take you through");
118
RegisterAchievement("ACH_PGZ", "Crate Expectations", "Wreak havoc at the propaganda factory");
119
RegisterAchievement("ACH_SSZ", "King of Speed", "Get through Stardust Speedway Zone as quickly as possible");
120
RegisterAchievement("ACH_HCZ", "Boat Enthusiast", "We really like boats");
121
RegisterAchievement("ACH_MSZ", "The Password is \"Special Stage\"", "Try pushing a barrel to see how far it goes");
122
RegisterAchievement("ACH_OOZ", "Secret Sub", "You might have to submerge to find it");
123
RegisterAchievement("ACH_LRZ", "Without a Trace", "Barrel through the lava, don't let anything stop you");
124
RegisterAchievement("ACH_MMZ", "Collect 'Em All", "Gotta gacha 'em all");
125
RegisterAchievement("ACH_TMZ", "Professional Hedgehog", "That elusive perfect run, only a professional can achieve");
126
127
#if RETRO_USERCORE_DUMMY
128
int32 achievementsRAM[0x100];
129
memset(achievementsRAM, 0, 0x100 * sizeof(int32));
130
bool32 loaded = false;
131
loaded = LoadUserFile("Achievements.bin", achievementsRAM, 0x100 * sizeof(int32));
132
(void)loaded;
133
for (int32 i = 0; i < (int32)achievementList.size(); ++i) {
134
achievementList[i].achieved = achievementsRAM[i];
135
}
136
#endif
137
#endif
138
}
139
void RSDK::SKU::ReleaseUserCore()
140
{
141
SaveUserData();
142
143
#if RETRO_REV02
144
145
if (achievements)
146
delete achievements;
147
achievements = nullptr;
148
149
if (leaderboards)
150
delete leaderboards;
151
leaderboards = nullptr;
152
153
if (richPresence)
154
delete richPresence;
155
richPresence = nullptr;
156
157
if (stats)
158
delete stats;
159
stats = nullptr;
160
161
if (userStorage)
162
delete userStorage;
163
userStorage = nullptr;
164
165
if (userDBStorage)
166
delete userDBStorage;
167
userDBStorage = nullptr;
168
169
if (userCore) {
170
userCore->Shutdown();
171
delete userCore;
172
}
173
174
#if RETRO_USERCORE_DUMMY
175
dummyCore = nullptr;
176
#endif
177
userCore = nullptr;
178
#endif
179
}
180
181
void RSDK::SKU::SaveUserData()
182
{
183
#if RETRO_USERCORE_DUMMY
184
int32 achievementsRAM[0x100];
185
memset(achievementsRAM, 0, 0x100 * sizeof(int32));
186
for (int32 i = 0; i < (int32)achievementList.size(); ++i) {
187
achievementsRAM[i] = achievementList[i].achieved;
188
}
189
SaveUserFile("Achievements.bin", achievementsRAM, 0x100 * sizeof(int32));
190
#endif
191
}
192
193
// Found this in Switch 1.00, doesn't seem to show up in rev02 variants but its neat nonetheless
194
bool32 RSDK::SKU::GetXYButtonFlip() { return engine.XYFlip; }
195
196
#if RETRO_REV02
197
void RSDK::SKU::UserCore::StageLoad()
198
{
199
achievements->StageLoad();
200
leaderboards->StageLoad();
201
richPresence->StageLoad();
202
stats->StageLoad();
203
userStorage->StageLoad();
204
}
205
void RSDK::SKU::UserCore::FrameInit()
206
{
207
achievements->FrameInit();
208
leaderboards->FrameInit();
209
richPresence->FrameInit();
210
stats->FrameInit();
211
userStorage->FrameInit();
212
}
213
void RSDK::SKU::UserCore::OnUnknownEvent()
214
{
215
achievements->OnUnknownEvent();
216
leaderboards->OnUnknownEvent();
217
richPresence->OnUnknownEvent();
218
stats->OnUnknownEvent();
219
userStorage->OnUnknownEvent();
220
}
221
#else
222
bool32 RSDK::SKU::GetConfirmButtonFlip() { return engine.confirmFlip; }
223
void RSDK::SKU::LaunchManual()
224
{
225
// LaunchManual() just opens the mania manual URL, thats it
226
#if RETRO_RENDERDEVICE_SDL2
227
// SDL_OpenURL("http://www.sonicthehedgehog.com/mania/manual");
228
PrintLog(PRINT_NORMAL, "DUMMY LaunchManual()");
229
#else
230
PrintLog(PRINT_NORMAL, "EMPTY LaunchManual()");
231
#endif
232
}
233
void RSDK::SKU::ExitGame() { RenderDevice::isRunning = false; }
234
235
int32 RSDK::SKU::GetDefaultGamepadType()
236
{
237
#if RETRO_REV02
238
int32 platform = curSKU.platform = PLATFORM_SWITCH;
239
#else
240
int32 platform = gameVerInfo.platform = PLATFORM_SWITCH;
241
#endif
242
243
switch (platform) {
244
case PLATFORM_SWITCH: return (DEVICE_API_NONE << 16) | (DEVICE_TYPE_CONTROLLER << 8) | (DEVICE_SWITCH_HANDHELD << 0);
245
case PLATFORM_PC:
246
case PLATFORM_DEV:
247
default: return (DEVICE_API_NONE << 16) | (DEVICE_TYPE_CONTROLLER << 8) | (0 << 0); break;
248
}
249
}
250
251
bool32 RSDK::SKU::ShowExtensionOverlay(uint8 overlay)
252
{
253
switch (overlay) {
254
default: PrintLog(PRINT_POPUP, "Show Extension Overlay: %d", overlay); break;
255
}
256
return false;
257
}
258
#endif
259
260
#if RETRO_PLATFORM == RETRO_ANDROID
261
#include <jni.h>
262
#endif
263
264
#if !RETRO_USE_ORIGINAL_CODE
265
CustomSettings RSDK::customSettings;
266
#endif
267
268
char buttonNames[18][8] = { "U", "D", "L", "R", "START", "SELECT", "LSTICK", "RSTICK", "L1", "R1", "C", "Z", "A", "B", "X", "Y", "L2", "R2" };
269
270
void RSDK::LoadSettingsINI()
271
{
272
videoSettings.screenCount = 1;
273
videoSettings.pixHeight = SCREEN_YSIZE;
274
videoSettings.windowState = WINDOWSTATE_UNINITIALIZED;
275
276
int32 platform = PLATFORM_DEV;
277
#if RETRO_REV02
278
platform = SKU::curSKU.platform;
279
#else
280
platform = gameVerInfo.platform;
281
#endif
282
283
// Consoles load the entire file and buffer it, while PC just io's the file when needed
284
bool32 useBuffer = !(platform == PLATFORM_PC || platform == PLATFORM_DEV);
285
286
char pathBuffer[0x100];
287
sprintf_s(pathBuffer, sizeof(pathBuffer), "%sSettings.ini", SKU::userFileDir);
288
289
dictionary *ini = iniparser_load(pathBuffer);
290
291
int32 defaultKeyMaps[PLAYER_COUNT + 1][KEY_MAX] = {
292
{ KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING,
293
KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING },
294
295
{ VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_A, VK_S, VK_D, VK_Q, VK_W, VK_E, VK_RETURN, VK_TAB },
296
{ VK_NUMPAD8, VK_NUMPAD5, VK_NUMPAD4, VK_NUMPAD6, VK_J, VK_K, KEYMAP_NO_MAPPING, VK_U, VK_I, KEYMAP_NO_MAPPING, VK_OEM_4, VK_OEM_6 },
297
298
{ KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING,
299
KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING },
300
301
{ KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING,
302
KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING, KEYMAP_NO_MAPPING }
303
};
304
305
if (ini) {
306
#if RETRO_REV02
307
SKU::curSKU.language = iniparser_getint(ini, "Game:language", LANGUAGE_EN);
308
#else
309
gameVerInfo.language = iniparser_getint(ini, "Game:language", LANGUAGE_EN);
310
#endif
311
312
engine.devMenu = true;
313
if (LoadDataPack(iniparser_getstring(ini, "Game:dataFile", "Data.rsdk"), 0, useBuffer))
314
engine.devMenu = iniparser_getboolean(ini, "Game:devMenu", false);
315
316
#if !RETRO_USE_ORIGINAL_CODE
317
customSettings.region = iniparser_getint(ini, "Game:region", -1);
318
// customSettings.confirmButtonFlip = iniparser_getboolean(ini, "Game:confirmButtonFlip", false);
319
// customSettings.xyButtonFlip = iniparser_getboolean(ini, "Game:xyButtonFlip", false);
320
customSettings.confirmButtonFlip = iniparser_getboolean(ini, "Game:faceButtonFlip", false);
321
customSettings.xyButtonFlip = customSettings.confirmButtonFlip;
322
customSettings.enableControllerDebugging = iniparser_getboolean(ini, "Game:enableControllerDebugging", false);
323
customSettings.disableFocusPause = iniparser_getboolean(ini, "Game:disableFocusPause", false);
324
engine.fastForwardSpeed = iniparser_getint(ini, "Game:fastForwardSpeed", 8);
325
326
#if RETRO_REV0U
327
customSettings.forceScripts = iniparser_getboolean(ini, "Game:txtScripts", false);
328
engine.gameReleaseID = iniparser_getint(ini, "Game:gameType", 1);
329
#endif
330
331
sprintf_s(gameLogicName, sizeof(gameLogicName), "%s", iniparser_getstring(ini, "Game:gameLogic", "Game"));
332
sprintf_s(customSettings.username, sizeof(customSettings.username), "%s", iniparser_getstring(ini, "Game:username", ""));
333
334
if (customSettings.region >= 0) {
335
#if RETRO_REV02
336
SKU::curSKU.region = customSettings.region;
337
#else
338
gameVerInfo.region = customSettings.region;
339
#endif
340
}
341
342
engine.confirmFlip = customSettings.confirmButtonFlip;
343
engine.XYFlip = customSettings.xyButtonFlip;
344
#else
345
sprintf_s(gameLogicName, sizeof(gameLogicName), "Game");
346
#endif
347
348
videoSettings.windowed = iniparser_getboolean(ini, "Video:windowed", true);
349
videoSettings.bordered = iniparser_getboolean(ini, "Video:border", true);
350
videoSettings.exclusiveFS = iniparser_getboolean(ini, "Video:exclusiveFS", false);
351
videoSettings.vsync = iniparser_getboolean(ini, "Video:vsync", false);
352
videoSettings.tripleBuffered = iniparser_getboolean(ini, "Video:tripleBuffering", false);
353
354
videoSettings.pixWidth = iniparser_getint(ini, "Video:pixWidth", DEFAULT_PIXWIDTH);
355
356
videoSettings.windowWidth = iniparser_getint(ini, "Video:winWidth", DEFAULT_PIXWIDTH);
357
videoSettings.windowHeight = iniparser_getint(ini, "Video:winHeight", SCREEN_YSIZE);
358
videoSettings.fsWidth = iniparser_getint(ini, "Video:fsWidth", 0);
359
videoSettings.fsHeight = iniparser_getint(ini, "Video:fsHeight", 0);
360
videoSettings.refreshRate = iniparser_getint(ini, "Video:refreshRate", 60);
361
videoSettings.shaderSupport = iniparser_getboolean(ini, "Video:shaderSupport", true);
362
videoSettings.shaderID = iniparser_getint(ini, "Video:screenShader", SHADER_NONE);
363
364
#if !RETRO_USE_ORIGINAL_CODE
365
customSettings.maxPixWidth = iniparser_getint(ini, "Video:maxPixWidth", DEFAULT_PIXWIDTH);
366
#endif
367
368
engine.streamsEnabled = iniparser_getboolean(ini, "Audio:streamsEnabled", true);
369
engine.streamVolume = (float)iniparser_getdouble(ini, "Audio:streamVolume", 0.8);
370
engine.soundFXVolume = (float)iniparser_getdouble(ini, "Audio:sfxVolume", 1.0);
371
372
for (int32 i = CONT_P1; i <= PLAYER_COUNT; ++i) {
373
char buffer[0x30];
374
375
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:up", i);
376
controller[i].keyUp.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_UP]);
377
378
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:down", i);
379
controller[i].keyDown.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_DOWN]);
380
381
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:left", i);
382
controller[i].keyLeft.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_LEFT]);
383
384
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:right", i);
385
controller[i].keyRight.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_RIGHT]);
386
387
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:buttonA", i);
388
controller[i].keyA.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_A]);
389
390
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:buttonB", i);
391
controller[i].keyB.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_B]);
392
393
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:buttonC", i);
394
controller[i].keyC.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_C]);
395
396
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:buttonX", i);
397
controller[i].keyX.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_X]);
398
399
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:buttonY", i);
400
controller[i].keyY.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_Y]);
401
402
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:buttonZ", i);
403
controller[i].keyZ.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_Z]);
404
405
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:start", i);
406
controller[i].keyStart.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_START]);
407
408
sprintf_s(buffer, sizeof(buffer), "Keyboard Map %d:select", i);
409
controller[i].keySelect.keyMap = iniparser_getint(ini, buffer, defaultKeyMaps[i][KEY_SELECT]);
410
}
411
412
gamePadCount = 0;
413
while (true) {
414
char buffer[0x30];
415
sprintf_s(buffer, sizeof(buffer), "GamePad Map %d:name", CONT_P1 + gamePadCount);
416
if (strcmp(iniparser_getstring(ini, buffer, ";unknown;"), ";unknown;") != 0) {
417
gamePadCount++;
418
}
419
else {
420
break;
421
}
422
}
423
424
#if !RETRO_USE_ORIGINAL_CODE
425
if (gamePadCount) {
426
#endif
427
#if RETRO_USE_MOD_LOADER
428
// using standard allocation here due to mod loader trickery
429
gamePadMappings = new GamePadMappings[gamePadCount];
430
#else
431
AllocateStorage((void **)&gamePadMappings, sizeof(GamePadMappings) * gamePadCount, DATASET_STG, true);
432
#endif
433
#if !RETRO_USE_ORIGINAL_CODE
434
}
435
#endif
436
437
for (int32 i = 0; i < gamePadCount; ++i) {
438
char buffer[0x30];
439
char mappings[0x100];
440
441
sprintf_s(buffer, sizeof(buffer), "GamePad Map %d:name", CONT_P1 + i);
442
sprintf_s(gamePadMappings[i].name, sizeof(gamePadMappings[i].name), "%s", iniparser_getstring(ini, buffer, 0));
443
444
sprintf_s(buffer, sizeof(buffer), "GamePad Map %d:type", CONT_P1 + i);
445
gamePadMappings[i].type = iniparser_getint(ini, buffer, 0);
446
447
sprintf_s(buffer, sizeof(buffer), "GamePad Map %d:vendorID", CONT_P1 + i);
448
gamePadMappings[i].vendorID = iniparser_getint(ini, buffer, 0);
449
450
sprintf_s(buffer, sizeof(buffer), "GamePad Map %d:productID", CONT_P1 + i);
451
gamePadMappings[i].productID = iniparser_getint(ini, buffer, 0);
452
453
sprintf_s(buffer, sizeof(buffer), "GamePad Map %d:mappingTypes", CONT_P1 + i);
454
sprintf_s(mappings, sizeof(mappings), "%s", iniparser_getstring(ini, buffer, 0));
455
456
char *tok = strtok(mappings, ", ");
457
for (int32 b = 0; tok; ++b) {
458
gamePadMappings[i].buttons[b].mappingType = atoi(tok);
459
tok = strtok(0, " ,.-");
460
}
461
462
sprintf_s(buffer, sizeof(buffer), "GamePad Map %d:offsets", CONT_P1 + i);
463
sprintf_s(mappings, sizeof(mappings), "%s", iniparser_getstring(ini, buffer, 0));
464
465
tok = strtok(mappings, ", ");
466
for (int32 b = 0; tok; ++b) {
467
gamePadMappings[i].buttons[b].offset = atoi(tok);
468
tok = strtok(0, " ,.-");
469
}
470
471
sprintf_s(buffer, sizeof(buffer), "GamePad Map %d:maskVals", CONT_P1 + i);
472
sprintf_s(mappings, sizeof(mappings), "%s", iniparser_getstring(ini, buffer, 0));
473
tok = strtok(mappings, ", ");
474
for (int32 b = 0; tok; ++b) {
475
int32 mask = 1;
476
for (int32 m = 0; m < 18; ++m) {
477
if (strcmp(buttonNames[m], tok) == 0) {
478
gamePadMappings[i].buttons[b].maskVal = mask;
479
break;
480
}
481
mask <<= 1;
482
}
483
484
tok = strtok(0, " ,.-");
485
}
486
}
487
488
iniparser_freedict(ini);
489
}
490
else {
491
videoSettings.windowed = true;
492
videoSettings.bordered = false;
493
videoSettings.exclusiveFS = true;
494
videoSettings.vsync = true;
495
videoSettings.tripleBuffered = false;
496
videoSettings.shaderSupport = true;
497
videoSettings.pixWidth = DEFAULT_PIXWIDTH;
498
videoSettings.fsWidth = 0;
499
videoSettings.windowWidth = videoSettings.pixWidth * 1;
500
videoSettings.windowHeight = SCREEN_YSIZE * 1;
501
videoSettings.fsHeight = 0;
502
videoSettings.refreshRate = 60;
503
videoSettings.shaderID = SHADER_NONE;
504
505
engine.streamsEnabled = true;
506
engine.streamVolume = 1.0f;
507
engine.soundFXVolume = 1.0f;
508
engine.devMenu = false;
509
510
#if !RETRO_USE_ORIGINAL_CODE
511
customSettings.region = -1;
512
customSettings.confirmButtonFlip = false;
513
customSettings.xyButtonFlip = false;
514
customSettings.enableControllerDebugging = false;
515
customSettings.disableFocusPause = false;
516
517
#if RETRO_REV0U
518
customSettings.forceScripts = false;
519
engine.gameReleaseID = 0;
520
#endif
521
522
sprintf_s(gameLogicName, sizeof(gameLogicName), "Game");
523
customSettings.username[0] = 0;
524
525
customSettings.maxPixWidth = DEFAULT_PIXWIDTH;
526
527
if (customSettings.region >= 0) {
528
#if RETRO_REV02
529
SKU::curSKU.region = customSettings.region;
530
#else
531
gameVerInfo.region = customSettings.region;
532
#endif
533
}
534
535
engine.confirmFlip = customSettings.confirmButtonFlip;
536
engine.XYFlip = customSettings.xyButtonFlip;
537
#else
538
sprintf_s(gameLogicName, sizeof(gameLogicName), "Game");
539
#endif
540
541
for (int32 i = CONT_P1; i <= PLAYER_COUNT; ++i) {
542
controller[i].keyUp.keyMap = defaultKeyMaps[i][KEY_UP];
543
controller[i].keyDown.keyMap = defaultKeyMaps[i][KEY_DOWN];
544
controller[i].keyLeft.keyMap = defaultKeyMaps[i][KEY_LEFT];
545
controller[i].keyRight.keyMap = defaultKeyMaps[i][KEY_RIGHT];
546
controller[i].keyA.keyMap = defaultKeyMaps[i][KEY_A];
547
controller[i].keyB.keyMap = defaultKeyMaps[i][KEY_B];
548
controller[i].keyC.keyMap = defaultKeyMaps[i][KEY_C];
549
controller[i].keyX.keyMap = defaultKeyMaps[i][KEY_X];
550
controller[i].keyY.keyMap = defaultKeyMaps[i][KEY_Y];
551
controller[i].keyZ.keyMap = defaultKeyMaps[i][KEY_Z];
552
controller[i].keyStart.keyMap = defaultKeyMaps[i][KEY_START];
553
controller[i].keySelect.keyMap = defaultKeyMaps[i][KEY_SELECT];
554
}
555
556
SaveSettingsINI(true);
557
engine.devMenu = LoadDataPack("Data.rsdk", 0, useBuffer);
558
}
559
}
560
561
void RSDK::SaveSettingsINI(bool32 writeToFile)
562
{
563
// the original only saves this file on windows and "dev", consoles use "options.bin"
564
// for the decomp, however, we want to save it regardless of platform
565
#if RETRO_USE_ORIGINAL_CODE
566
#if RETRO_REV02
567
if (SKU::curSKU.platform != PLATFORM_PC && SKU::curSKU.platform != PLATFORM_DEV)
568
return;
569
#else
570
if (gameVerInfo.platform != PLATFORM_PC && gameVerInfo.platform != PLATFORM_DEV)
571
return;
572
#endif
573
#endif
574
575
if (changedVideoSettings || writeToFile) {
576
char pathBuffer[0x100];
577
sprintf_s(pathBuffer, sizeof(pathBuffer), "%sSettings.ini", SKU::userFileDir);
578
579
dictionary *ini = iniparser_load(pathBuffer);
580
FileIO *file = fOpen(pathBuffer, "wb");
581
582
// ================
583
// SIGNATURE
584
// ================
585
WriteText(file, "; Retro Engine Config File\n\n");
586
587
// ================
588
// GAME
589
// ================
590
WriteText(file, "[Game]\n");
591
if (ini) {
592
if (strcmp(iniparser_getstring(ini, "Game:dataFile", ";unknown;"), ";unknown;") != 0 || (!RETRO_USE_ORIGINAL_CODE && RETRO_REV0U)) {
593
WriteText(file, "dataFile=%s\n", iniparser_getstring(ini, "Game:dataFile", "Data.rsdk"));
594
}
595
596
if (strcmp(iniparser_getstring(ini, "Game:devMenu", ";unknown;"), ";unknown;") != 0 || (!RETRO_USE_ORIGINAL_CODE && RETRO_REV0U))
597
WriteText(file, "devMenu=%s\n", (engine.devMenu ? "y" : "n"));
598
599
#if !RETRO_USE_ORIGINAL_CODE
600
if (strcmp(iniparser_getstring(ini, "Game:gameLogic", ";unknown;"), ";unknown;") != 0)
601
WriteText(file, "gameLogic=%s\n", iniparser_getstring(ini, "Game:gameLogic", "Game"));
602
603
WriteText(file, "faceButtonFlip=%s\n", (customSettings.confirmButtonFlip ? "y" : "n"));
604
// WriteText(file, "confirmButtonFlip=%s\n", (customSettings.confirmButtonFlip ? "y" : "n"));
605
// WriteText(file, "xyButtonFlip=%s\n", (customSettings.xyButtonFlip ? "y" : "n"));
606
607
if (engine.devMenu)
608
WriteText(file, "enableControllerDebugging=%s\n", (customSettings.enableControllerDebugging ? "y" : "n"));
609
610
WriteText(file, "; Determines if the engine should pause when window focus is lost or not\n");
611
WriteText(file, "disableFocusPause=%s\n", (customSettings.disableFocusPause ? "y" : "n"));
612
613
WriteText(file, "; The speed to run the game at while holding backspace. Defaults to x8 speed\n");
614
WriteText(file, "fastForwardSpeed=%d\n", engine.fastForwardSpeed);
615
616
if (strcmp(iniparser_getstring(ini, "Game:username", ";unknown;"), ";unknown;") != 0)
617
WriteText(file, "username=%s\n", iniparser_getstring(ini, "Game:username", ""));
618
619
WriteText(file, "; if -1, the game will decide what region to use, if 0 or higher, forces a specific region\n");
620
WriteText(file, "region=%d\n", customSettings.region);
621
622
#if RETRO_REV0U
623
WriteText(file, "; Determines if legacy modes are forced to load from the scripts folder instead of bytecode\n");
624
WriteText(file, "txtScripts=%s\n", (customSettings.forceScripts ? "y" : "n"));
625
626
WriteText(file, "; Determines game type in scripts (0 = Standalone/Original releases, 1 = Origins release)\n");
627
WriteText(file, "gameType=%d\n", engine.gameReleaseID);
628
#endif
629
#endif
630
}
631
632
#if RETRO_REV02
633
WriteText(file, "language=%d\n", SKU::curSKU.language);
634
#else
635
WriteText(file, "language=%d\n", gameVerInfo.language);
636
#endif
637
638
// ================
639
// VIDEO
640
// ================
641
WriteText(file, "\n[Video]\n");
642
WriteText(file, "; NB: Fullscreen Resolution can be explicitly set with values fsWidth and fsHeight\n");
643
WriteText(file, "; If not listed, fullscreen will just use the desktop resolution\n");
644
WriteText(file, "windowed=%s\n", (videoSettings.windowed ? "y" : "n"));
645
WriteText(file, "border=%s\n", (videoSettings.bordered ? "y" : "n"));
646
WriteText(file, "exclusiveFS=%s\n", (videoSettings.exclusiveFS ? "y" : "n"));
647
WriteText(file, "vsync=%s\n", (videoSettings.vsync ? "y" : "n"));
648
WriteText(file, "tripleBuffering=%s\n", (videoSettings.tripleBuffered ? "y" : "n"));
649
if (ini) {
650
if (strcmp(iniparser_getstring(ini, "Video:pixWidth", ";unknown;"), ";unknown;") == 0)
651
WriteText(file, "pixWidth=%d\n", videoSettings.pixWidth);
652
}
653
WriteText(file, "winWidth=%d\n", videoSettings.windowWidth);
654
WriteText(file, "winHeight=%d\n", videoSettings.windowHeight);
655
if (videoSettings.fsWidth > 0)
656
WriteText(file, "fsWidth=%d\n", videoSettings.fsWidth);
657
if (videoSettings.fsHeight > 0)
658
WriteText(file, "fsHeight=%d\n", videoSettings.fsHeight);
659
if (videoSettings.refreshRate > 0)
660
WriteText(file, "refreshRate=%d\n", videoSettings.refreshRate);
661
662
WriteText(file, "shaderSupport=%s\n", (videoSettings.shaderSupport ? "y" : "n"));
663
WriteText(file, "screenShader=%d\n", videoSettings.shaderID);
664
665
#if !RETRO_USE_ORIGINAL_CODE
666
WriteText(file, "; Maximum width the screen will be allowed to be. A value of 0 will disable the maximum width\n");
667
WriteText(file, "maxPixWidth=%d\n", customSettings.maxPixWidth);
668
#endif
669
670
// ================
671
// AUDIO
672
// ================
673
WriteText(file, "\n[Audio]\n");
674
WriteText(file, "streamsEnabled=%s\n", (engine.streamsEnabled ? "y" : "n"));
675
WriteText(file, "streamVolume=%f\n", engine.streamVolume);
676
WriteText(file, "sfxVolume=%f\n", engine.soundFXVolume);
677
678
// ==========================
679
// OPTIONS (decomp only)
680
// ==========================
681
682
// ================
683
// KEYBOARD MAP
684
// ================
685
for (int32 i = 1; i <= PLAYER_COUNT; ++i) {
686
WriteText(file, "\n[Keyboard Map %d]\n", i);
687
WriteText(file, "up=0x%x\n", controller[i].keyUp.keyMap);
688
WriteText(file, "down=0x%x\n", controller[i].keyDown.keyMap);
689
WriteText(file, "left=0x%x\n", controller[i].keyLeft.keyMap);
690
WriteText(file, "right=0x%x\n", controller[i].keyRight.keyMap);
691
WriteText(file, "buttonA=0x%x\n", controller[i].keyA.keyMap);
692
WriteText(file, "buttonB=0x%x\n", controller[i].keyB.keyMap);
693
WriteText(file, "buttonC=0x%x\n", controller[i].keyC.keyMap);
694
WriteText(file, "buttonX=0x%x\n", controller[i].keyX.keyMap);
695
WriteText(file, "buttonY=0x%x\n", controller[i].keyY.keyMap);
696
WriteText(file, "buttonZ=0x%x\n", controller[i].keyZ.keyMap);
697
WriteText(file, "start=0x%x\n", controller[i].keyStart.keyMap);
698
WriteText(file, "select=0x%x\n", controller[i].keySelect.keyMap);
699
}
700
701
for (int32 i = 0; i < gamePadCount; ++i) {
702
WriteText(file, "\n[Keyboard Map %d]\n", i + 1);
703
WriteText(file, "name=%s\n", gamePadMappings[i].name);
704
WriteText(file, "type=0x%x\n", gamePadMappings[i].type);
705
WriteText(file, "vendorID=0x%x\n", gamePadMappings[i].vendorID);
706
WriteText(file, "productID=0x%x\n", gamePadMappings[i].productID);
707
708
WriteText(file, "mappingTypes=");
709
for (int32 b = 0; b < 24; ++b) {
710
WriteText(file, "%d,", gamePadMappings[i].buttons[b].mappingType);
711
}
712
WriteText(file, "\n");
713
WriteText(file, "offsets=");
714
for (int32 b = 0; b < 24; ++b) {
715
WriteText(file, "%d,", gamePadMappings[i].buttons[b].offset);
716
}
717
WriteText(file, "\n");
718
WriteText(file, "maskVals=");
719
for (int32 b = 0; b < 24; ++b) {
720
if (gamePadMappings[i].buttons[b].maskVal) {
721
int32 m = 0;
722
while (true) {
723
if (1 << m == gamePadMappings[i].buttons[b].maskVal) {
724
WriteText(file, "%d,", gamePadMappings[i].buttons[b].maskVal);
725
break;
726
}
727
}
728
729
if (m == 18)
730
WriteText(file, "?,");
731
}
732
else {
733
WriteText(file, "?,");
734
}
735
}
736
WriteText(file, "\n");
737
}
738
739
iniparser_freedict(ini);
740
fClose(file);
741
}
742
743
#if RETRO_USE_MOD_LOADER
744
if (gamePadCount && gamePadMappings)
745
delete[] gamePadMappings;
746
gamePadMappings = NULL;
747
gamePadCount = 0;
748
#endif
749
}
750
751