Skip to content

Commit fb4411a

Browse files
committed
Fix issue with save game filenames containing paths
1 parent 5f78412 commit fb4411a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/Misc/SavedGamesInSubdir.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,29 @@ DEFINE_HOOK(0x67E4DC, LoadGame_AdditionalInfoForClient, 0x7)
317317
return 0;
318318
}
319319

320+
// Custom missions especially can contain paths in scenario filenames which cause
321+
// the initial save game to fail, remove the paths before filename and make the
322+
// filename uppercase to match with usual savegame names.
323+
DEFINE_HOOK(0x55DC85, MainLoop_SaveGame_SanitizeFilename, 0x7)
324+
{
325+
LEA_STACK(char*, pFilename, STACK_OFFSET(0x1C4, -0x178));
326+
LEA_STACK(const wchar_t*, pDescription, STACK_OFFSET(0x1C4, -0x70));
327+
328+
char* slash1 = strrchr(pFilename, '/');
329+
char* slash2 = strrchr(pFilename, '\\');
330+
char* lastSlash = (slash1 > slash2) ? slash1 : slash2;
331+
332+
if (lastSlash != NULL)
333+
{
334+
pFilename = lastSlash + 1;
335+
*lastSlash = '\0';
336+
}
337+
338+
for (char* p = pFilename; *p; ++p)
339+
*p = (char)toupper((unsigned char)*p);
340+
341+
R->ECX(pFilename);
342+
R->EDX(pDescription);
343+
344+
return 0x55DC90;
345+
}

0 commit comments

Comments
 (0)