From 7fcb416a789541c3df7008d768d219b36ab9975a Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sat, 15 May 2021 20:04:06 +0600 Subject: [PATCH] - fix LoadCurrentProfile infinite loop/crash when called from Frontend --- src_rebuild/Game/C/loadsave.c | 41 +++++++++++++++++++++++------- src_rebuild/Game/C/loadsave.h | 6 ++++- src_rebuild/Game/C/main.c | 6 ++--- src_rebuild/Game/Frontend/FEmain.c | 6 ++--- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src_rebuild/Game/C/loadsave.c b/src_rebuild/Game/C/loadsave.c index 5b6b23af..7f29352c 100644 --- a/src_rebuild/Game/C/loadsave.c +++ b/src_rebuild/Game/C/loadsave.c @@ -15,6 +15,7 @@ #ifndef PSX #include // getenv +#endif // PSX // [A] void ShowSavingWaitMessage(char *message, int height) @@ -53,6 +54,7 @@ void ShowSavingWaitMessage(char *message, int height) #endif // PSX } +#ifndef PSX void GetGameProfilePath(char* str) { char* homepath; @@ -72,18 +74,14 @@ void GetGameProfilePath(char* str) str[0] = 0; } } +#endif // PSX // [A] loads current game config -void LoadCurrentProfile() +void LoadCurrentProfile(int init) { - char filePath[2048]; - int fileSize; int error; - GetGameProfilePath(filePath); - - strcat(filePath, "/config.dat"); - + if(init) { RECT16 rect; @@ -100,7 +98,7 @@ void LoadCurrentProfile() SetTextColour(128, 128, 64); ShowSavingWaitMessage(G_LTXT(GTXT_LoadingConfiguration), 0); - + /* { RECT16 rect; rect.x = 0; @@ -111,9 +109,17 @@ void LoadCurrentProfile() ClearImage(&rect, 0, 0, 0); DrawSync(0); } - + */ error = 1; +#ifndef PSX + + char filePath[2048]; + int fileSize; + + GetGameProfilePath(filePath); + strcat(filePath, "/config.dat"); + // load config FILE* fp = fopen(filePath, "rb"); if (fp) @@ -137,6 +143,9 @@ void LoadCurrentProfile() ShowSavingWaitMessage(G_LTXT(GTXT_NoSavedData), 0); return; } +#else + // TODO: PSX memory card code +#endif if (error) { @@ -154,6 +163,7 @@ void LoadCurrentProfile() // [A] saves config to file void SaveCurrentProfile() { +#ifndef PSX int dataSize; char filePath[2048]; int error; @@ -190,11 +200,15 @@ void SaveCurrentProfile() { ShowSavingWaitMessage(G_LTXT(GTXT_OK), 0); } +#else + // TODO: PSX memory card code +#endif } // [A] loads current game progress int LoadCurrentGame() { +#ifndef PSX char filePath[2048]; int fileSize; @@ -223,6 +237,9 @@ int LoadCurrentGame() return 1; } } +#else + // TODO: PSX memory card code +#endif return 0; } @@ -230,6 +247,7 @@ int LoadCurrentGame() // [A] saves current game progress void SaveCurrentGame() { +#ifndef PSX int dataSize = 0; char filePath[2048]; @@ -251,8 +269,13 @@ void SaveCurrentGame() fwrite((char*)_other_buffer, 1, dataSize, fp); fclose(fp); } +#else + // TODO: PSX memory card code +#endif } +#ifndef PSX + char gCurrentReplayFilename[64] = { 0 }; int LoadReplayFromFile(char* fileName) diff --git a/src_rebuild/Game/C/loadsave.h b/src_rebuild/Game/C/loadsave.h index 772db715..d840f1a1 100644 --- a/src_rebuild/Game/C/loadsave.h +++ b/src_rebuild/Game/C/loadsave.h @@ -3,15 +3,19 @@ extern char gCurrentReplayFilename[64]; -extern void LoadCurrentProfile(); +extern void LoadCurrentProfile(int init); extern void SaveCurrentProfile(); extern int LoadCurrentGame(); extern void SaveCurrentGame(); +#ifndef PSX + extern int LoadReplayFromFile(char* fileName); extern int SaveReplayToFile(char* filename); +#endif // PSX + //-------- extern int CalcReplayDataSize(); // 0x00057FD4 diff --git a/src_rebuild/Game/C/main.c b/src_rebuild/Game/C/main.c index 1d451165..c647cb9b 100644 --- a/src_rebuild/Game/C/main.c +++ b/src_rebuild/Game/C/main.c @@ -1989,10 +1989,10 @@ int redriver2_main(int argc, char** argv) // by default go to frontend SetState(STATE_INITFRONTEND, (void*)2); + + LoadCurrentProfile(1); -#ifndef PSX - LoadCurrentProfile(); - +#ifndef PSX int commandLinePropsShown; commandLinePropsShown = 0; diff --git a/src_rebuild/Game/Frontend/FEmain.c b/src_rebuild/Game/Frontend/FEmain.c index deaf43ea..2fd03293 100644 --- a/src_rebuild/Game/Frontend/FEmain.c +++ b/src_rebuild/Game/Frontend/FEmain.c @@ -513,12 +513,10 @@ void SetVariable(int var) } else { -#ifndef PSX // [A] load configuration - LoadCurrentProfile(); -#endif + LoadCurrentProfile(0); - SetState(STATE_INITFRONTEND); + //SetState(STATE_INITFRONTEND); SetMasterVolume(gMasterVolume); SetXMVolume(gMusicVolume); }