diff --git a/engine/common/common.h b/engine/common/common.h index b1fdd635..b23e3147 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -674,8 +674,11 @@ const char *Q_buildcommit( void ); // // host.c // +typedef void( *pfnChangeGame )( const char *progname ); + qboolean Host_IsQuakeCompatible( void ); void EXPORT Host_Shutdown( void ); +int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGame, pfnChangeGame func ); int Host_CompareFileTime( int ft1, int ft2 ); void Host_NewInstance( const char *name, const char *finalmsg ); void Host_EndGame( qboolean abort, const char *message, ... ) _format( 2 ); diff --git a/engine/common/host.c b/engine/common/host.c index 079cc5c0..0e1223a8 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -42,8 +42,6 @@ GNU General Public License for more details. #include "render_api.h" // decallist_t -typedef void (*pfnChangeGame)( const char *progname ); - pfnChangeGame pChangeGame = NULL; host_parm_t host; // host parms sysinfo_t SI; diff --git a/engine/common/launcher.c b/engine/common/launcher.c index 2100839f..39d8f134 100644 --- a/engine/common/launcher.c +++ b/engine/common/launcher.c @@ -18,6 +18,7 @@ GNU General Public License for more details. #include #include #include "build.h" +#include "common.h" #ifdef XASH_SDLMAIN #include "SDL.h" #endif @@ -25,17 +26,12 @@ GNU General Public License for more details. #if XASH_EMSCRIPTEN #include #endif -typedef void (*pfnChangeGame)( const char *progname ); -char szGameDir[128]; // safe place to keep gamedir -int g_iArgc; +#define XASH_NOCONHOST 1 -void Host_Shutdown( void ); -void Launcher_ChangeGame( const char *progname ); -void *Com_LoadLibrary( char *, int ); -int Host_Main( int szArgc, char **szArgv, const char *szGameDir, int chg, pfnChangeGame callback ); - -char **g_pszArgv; +static char szGameDir[128]; // safe place to keep gamedir +static int g_iArgc; +static char **g_pszArgv; void Launcher_ChangeGame( const char *progname ) { @@ -44,23 +40,32 @@ void Launcher_ChangeGame( const char *progname ) exit( Host_Main( g_iArgc, g_pszArgv, szGameDir, 1, &Launcher_ChangeGame ) ); } -#ifdef XASH_NOCONHOST +#if XASH_NOCONHOST #include +#include // CommandLineToArgvW int __stdcall WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdLine, int nShow) { int szArgc; char **szArgv; LPWSTR* lpArgv = CommandLineToArgvW(GetCommandLineW(), &szArgc); - int size, i = 0; + int i = 0; + szArgv = (char**)malloc(szArgc*sizeof(char*)); for (; i < szArgc; ++i) { - size = wcslen(lpArgv[i]) + 1; + size_t size = wcslen(lpArgv[i]) + 1; szArgv[i] = (char*)malloc(size); wcstombs(szArgv[i], lpArgv[i], size); } + szArgv[i] = NULL; + LocalFree(lpArgv); + main( szArgc, szArgv ); + + for( i = 0; i < szArgc; ++i ) + free( szArgv[i] ); + free( szArgv ); } #endif int main( int argc, char** argv ) @@ -81,9 +86,9 @@ int main( int argc, char** argv ) #if XASH_EMSCRIPTEN #ifdef EMSCRIPTEN_LIB_FS // For some unknown reason emscripten refusing to load libraries later - Com_LoadLibrary("menu", 0 ); - Com_LoadLibrary("server", 0 ); - Com_LoadLibrary("client", 0 ); + COM_LoadLibrary("menu", 0 ); + COM_LoadLibrary("server", 0 ); + COM_LoadLibrary("client", 0 ); #endif #if XASH_DEDICATED // NodeJS support for debug