From 86b618702f4ea904b6791030100d56e29b2f1f1a Mon Sep 17 00:00:00 2001 From: Dreamy Cecil <21009796+DreamyCecil@users.noreply.github.com> Date: Thu, 11 Jul 2024 23:22:08 +0300 Subject: [PATCH] Relaunch SeriousSam with a mod using the same executable. - Remove old functions for launching mods and teasers after the game. --- Sources/SeriousSam/SeriousSam.cpp | 80 +++++++++---------------------- 1 file changed, 23 insertions(+), 57 deletions(-) diff --git a/Sources/SeriousSam/SeriousSam.cpp b/Sources/SeriousSam/SeriousSam.cpp index eed51bec0..9c5c25c21 100644 --- a/Sources/SeriousSam/SeriousSam.cpp +++ b/Sources/SeriousSam/SeriousSam.cpp @@ -1167,28 +1167,30 @@ int SubMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int _pInput->DisableInput(); _pGame->StopGame(); - if (_fnmModToLoad!="") { - - char strCmd [64] = {0}; - char strParam [128] = {0}; - STARTUPINFOA cif; - ZeroMemory(&cif,sizeof(STARTUPINFOA)); - PROCESS_INFORMATION pi; - - strcpy(strCmd,"SeriousSam.exe"); - strcpy(strParam," +game "); - strcat(strParam,_fnmModToLoad.FileName()); - if (_strModServerJoin!="") { - strcat(strParam," +connect "); - strcat(strParam,_strModServerJoin); - strcat(strParam," +quickjoin"); - } - - if (CreateProcessA(strCmd,strParam,NULL,NULL,FALSE,CREATE_DEFAULT_ERROR_MODE,NULL,NULL,&cif,&pi) == FALSE) - { - MessageBox(0, "error launching the Mod!\n", "Serious Sam", MB_OK|MB_ICONERROR); - } + if (_fnmModToLoad != "") { + STARTUPINFOA cif; + ZeroMemory(&cif, sizeof(STARTUPINFOA)); + PROCESS_INFORMATION pi; + + const CTString strMod = _fnmModToLoad.FileName(); + + // [Cecil] Use executable filename + CTString strCmd = _fnmApplicationPath + _fnmApplicationExe; + CTString strParam = " +game " + strMod; + + if (_strModServerJoin != "") { + strParam += " +connect " + _strModServerJoin + " +quickjoin"; + } + + if (!CreateProcessA(strCmd.str_String, strParam.str_String, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &cif, &pi)) { + // [Cecil] Proper error message + CTString strError; + strError.PrintF("Cannot start '%s' mod:\n%s\n", strMod, GetWindowsError(GetLastError())); + + MessageBoxA(0, strError, "Serious Sam", MB_OK | MB_ICONERROR); + } } + // invoke quit screen if needed if( _bQuitScreen && _fnmModToLoad=="") QuitScreenLoop(); @@ -1196,38 +1198,6 @@ int SubMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int return TRUE; } -/* -void CheckModReload(void) -{ - if (_fnmModToLoad!="") { - CTString strCommand = _fnmApplicationExe.FileDir()+"SeriousSam.exe"; - //+mod "+_fnmModToLoad.FileName()+"\""; - CTString strMod = _fnmModToLoad.FileName(); - const char *argv[7]; - argv[0] = strCommand; - argv[1] = "+game"; - argv[2] = strMod; - argv[3] = NULL; - if (_strModServerJoin!="") { - argv[3] = "+connect"; - argv[4] = _strModServerJoin; - argv[5] = "+quickjoin"; - argv[6] = NULL; - } - - _execv(strCommand, argv); - } -}*/ - -void CheckTeaser(void) -{ - CTFileName fnmTeaser = _fnmApplicationExe.FileDir()+CTString("AfterSam.exe"); - if (fopen(fnmTeaser, "r")!=NULL) { - Sleep(500); - _execl(fnmTeaser, "\""+fnmTeaser+"\"", NULL); - } -} - void CheckBrowser(void) { if (_strURLToVisit!="") { @@ -1244,10 +1214,6 @@ int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, CTSTREAM_BEGIN { iResult = SubMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow); } CTSTREAM_END; - - //CheckModReload(); - - CheckTeaser(); CheckBrowser();