Skip to content

Commit 314684c

Browse files
committed
Fix issue with save game filenames containing paths
1 parent 058d81e commit 314684c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Misc/SavedGamesInSubdir.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,30 @@ DEFINE_HOOK(0x67E4DC, LoadGame_AdditionalInfoForClient, 0x7)
315315

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

0 commit comments

Comments
 (0)