- fix LoadCurrentProfile infinite loop/crash when called from Frontend

This commit is contained in:
Ilya Shurumov 2021-05-15 20:04:06 +06:00 committed by InspirationByte
parent cb3486668c
commit 7fcb416a78
4 changed files with 42 additions and 17 deletions

View File

@ -15,6 +15,7 @@
#ifndef PSX #ifndef PSX
#include <stdlib.h> // getenv #include <stdlib.h> // getenv
#endif // PSX
// [A] // [A]
void ShowSavingWaitMessage(char *message, int height) void ShowSavingWaitMessage(char *message, int height)
@ -53,6 +54,7 @@ void ShowSavingWaitMessage(char *message, int height)
#endif // PSX #endif // PSX
} }
#ifndef PSX
void GetGameProfilePath(char* str) void GetGameProfilePath(char* str)
{ {
char* homepath; char* homepath;
@ -72,18 +74,14 @@ void GetGameProfilePath(char* str)
str[0] = 0; str[0] = 0;
} }
} }
#endif // PSX
// [A] loads current game config // [A] loads current game config
void LoadCurrentProfile() void LoadCurrentProfile(int init)
{ {
char filePath[2048];
int fileSize;
int error; int error;
GetGameProfilePath(filePath); if(init)
strcat(filePath, "/config.dat");
{ {
RECT16 rect; RECT16 rect;
@ -100,7 +98,7 @@ void LoadCurrentProfile()
SetTextColour(128, 128, 64); SetTextColour(128, 128, 64);
ShowSavingWaitMessage(G_LTXT(GTXT_LoadingConfiguration), 0); ShowSavingWaitMessage(G_LTXT(GTXT_LoadingConfiguration), 0);
/*
{ {
RECT16 rect; RECT16 rect;
rect.x = 0; rect.x = 0;
@ -111,9 +109,17 @@ void LoadCurrentProfile()
ClearImage(&rect, 0, 0, 0); ClearImage(&rect, 0, 0, 0);
DrawSync(0); DrawSync(0);
} }
*/
error = 1; error = 1;
#ifndef PSX
char filePath[2048];
int fileSize;
GetGameProfilePath(filePath);
strcat(filePath, "/config.dat");
// load config // load config
FILE* fp = fopen(filePath, "rb"); FILE* fp = fopen(filePath, "rb");
if (fp) if (fp)
@ -137,6 +143,9 @@ void LoadCurrentProfile()
ShowSavingWaitMessage(G_LTXT(GTXT_NoSavedData), 0); ShowSavingWaitMessage(G_LTXT(GTXT_NoSavedData), 0);
return; return;
} }
#else
// TODO: PSX memory card code
#endif
if (error) if (error)
{ {
@ -154,6 +163,7 @@ void LoadCurrentProfile()
// [A] saves config to file // [A] saves config to file
void SaveCurrentProfile() void SaveCurrentProfile()
{ {
#ifndef PSX
int dataSize; int dataSize;
char filePath[2048]; char filePath[2048];
int error; int error;
@ -190,11 +200,15 @@ void SaveCurrentProfile()
{ {
ShowSavingWaitMessage(G_LTXT(GTXT_OK), 0); ShowSavingWaitMessage(G_LTXT(GTXT_OK), 0);
} }
#else
// TODO: PSX memory card code
#endif
} }
// [A] loads current game progress // [A] loads current game progress
int LoadCurrentGame() int LoadCurrentGame()
{ {
#ifndef PSX
char filePath[2048]; char filePath[2048];
int fileSize; int fileSize;
@ -223,6 +237,9 @@ int LoadCurrentGame()
return 1; return 1;
} }
} }
#else
// TODO: PSX memory card code
#endif
return 0; return 0;
} }
@ -230,6 +247,7 @@ int LoadCurrentGame()
// [A] saves current game progress // [A] saves current game progress
void SaveCurrentGame() void SaveCurrentGame()
{ {
#ifndef PSX
int dataSize = 0; int dataSize = 0;
char filePath[2048]; char filePath[2048];
@ -251,8 +269,13 @@ void SaveCurrentGame()
fwrite((char*)_other_buffer, 1, dataSize, fp); fwrite((char*)_other_buffer, 1, dataSize, fp);
fclose(fp); fclose(fp);
} }
#else
// TODO: PSX memory card code
#endif
} }
#ifndef PSX
char gCurrentReplayFilename[64] = { 0 }; char gCurrentReplayFilename[64] = { 0 };
int LoadReplayFromFile(char* fileName) int LoadReplayFromFile(char* fileName)

View File

@ -3,15 +3,19 @@
extern char gCurrentReplayFilename[64]; extern char gCurrentReplayFilename[64];
extern void LoadCurrentProfile(); extern void LoadCurrentProfile(int init);
extern void SaveCurrentProfile(); extern void SaveCurrentProfile();
extern int LoadCurrentGame(); extern int LoadCurrentGame();
extern void SaveCurrentGame(); extern void SaveCurrentGame();
#ifndef PSX
extern int LoadReplayFromFile(char* fileName); extern int LoadReplayFromFile(char* fileName);
extern int SaveReplayToFile(char* filename); extern int SaveReplayToFile(char* filename);
#endif // PSX
//-------- //--------
extern int CalcReplayDataSize(); // 0x00057FD4 extern int CalcReplayDataSize(); // 0x00057FD4

View File

@ -1989,10 +1989,10 @@ int redriver2_main(int argc, char** argv)
// by default go to frontend // by default go to frontend
SetState(STATE_INITFRONTEND, (void*)2); SetState(STATE_INITFRONTEND, (void*)2);
LoadCurrentProfile(1);
#ifndef PSX #ifndef PSX
LoadCurrentProfile();
int commandLinePropsShown; int commandLinePropsShown;
commandLinePropsShown = 0; commandLinePropsShown = 0;

View File

@ -513,12 +513,10 @@ void SetVariable(int var)
} }
else else
{ {
#ifndef PSX
// [A] load configuration // [A] load configuration
LoadCurrentProfile(); LoadCurrentProfile(0);
#endif
SetState(STATE_INITFRONTEND); //SetState(STATE_INITFRONTEND);
SetMasterVolume(gMasterVolume); SetMasterVolume(gMasterVolume);
SetXMVolume(gMusicVolume); SetXMVolume(gMusicVolume);
} }