/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); const char *gamename; #ifdef JK2_MODE gamename = "jospgame" ARCH_STRING DLL_EXT; #else gamename = "jagame" ARCH_STRING DLL_EXT; #endif if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); game_library = Sys_RetrieveDLL(gamename); if(!game_library) { char *buf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buf, 0, NULL ); Com_Printf( "LoadLibrary(\"%s\") failed\n", gamename); Com_Printf( "...reason: '%s'\n", buf ); Com_Error( ERR_FATAL, "Couldn't load game" ); } GetGameAPI = (void *(*)(void *))GetProcAddress (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); char name[MAX_OSPATH]; char curpath[MAX_OSPATH]; char *path; if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); // check the current debug directory first for development purposes getcwd(curpath, sizeof(curpath)); Com_Printf("------- Loading %s -------\n", gamename); Com_sprintf (name, sizeof(name), "%s/%s", curpath, gamename); game_library = dlopen (name, RTLD_LAZY ); if (game_library) Com_DPrintf ("LoadLibrary (%s)\n",name); else { Com_Printf( "LoadLibrary(\"%s\") failed\n", name); Com_Printf( "...reason: '%s'\n", dlerror() ); Com_Error( ERR_FATAL, "Couldn't load game" ); } GetGameAPI = (void *)dlsym (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); const char *gamename; #ifdef JK2_MODE gamename = "jospgame" ARCH_STRING DLL_EXT; #else gamename = "jagame" ARCH_STRING DLL_EXT; #endif if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); game_library = Sys_RetrieveDLL(gamename); if(!game_library) { Com_Printf( "LoadLibrary(\"%s\") failed\n", gamename); Com_Printf( "...reason: '%s'\n", GetErrorString( GetLastError() ) ); Com_Error( ERR_FATAL, "Couldn't load game" ); } GetGameAPI = (void *(*)(void *))GetProcAddress (game_library, "GetGameAPI"); if (!GetGameAPI) { Com_Printf( "Sys_GetGameAPI: Entry point not found in %s. Failed with system error code 0x%X.\n", gamename, GetLastError() ); Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); #if defined _M_IX86 const char *gamename; if(com_jk2 && com_jk2->integer) { gamename = "jk2gamex86.dll"; } else { gamename = "jagamex86.dll"; } #ifdef NDEBUG const char *debugdir = "release"; #elif MEM_DEBUG const char *debugdir = "shdebug"; #else const char *debugdir = "debug"; #endif //NDEBUG #elif defined _M_ALPHA const char *gamename = "jagameaxp.dll"; #ifdef NDEBUG const char *debugdir = "releaseaxp"; #else const char *debugdir = "debugaxp"; #endif //NDEBUG #endif //_M__IX86 if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); game_library = Sys_RetrieveDLL(gamename, debugdir); if(!game_library) { char *buf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buf, 0, NULL ); Com_Printf( "LoadLibrary(\"%s\") failed\n", gamename); Com_Printf( "...reason: '%s'\n", buf ); Com_Error( ERR_FATAL, "Couldn't load game" ); } GetGameAPI = (void *(*)(void *))GetProcAddress (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
void * Sys_GetGameAPI(void *parms) { void *(*GetGameAPI)(void *); char name[MAX_OSPATH]; char *path = NULL; if (game_library) { Com_Error(ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); } /* now run through the search paths */ path = NULL; while (1) { path = FS_NextPath(path); if (!path) { return NULL; /* couldn't find one anywhere */ } /* Try game.dll */ Com_sprintf(name, sizeof(name), "%s/%s", path, "game.dll"); game_library = LoadLibrary(name); if (game_library) { Com_DPrintf("LoadLibrary (%s)\n", name); break; } /* Try gamex86.dll as fallback */ Com_sprintf(name, sizeof(name), "%s/%s", path, "gamex86.dll"); game_library = LoadLibrary(name); if (game_library) { Com_DPrintf("LoadLibrary (%s)\n", name); break; } } GetGameAPI = (void *)GetProcAddress(game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame(); return NULL; } return GetGameAPI(parms); }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { #ifndef REF_HARD_LINKED void *(*GetGameAPI) (void *); char name[MAX_OSPATH]; char curpath[MAX_OSPATH]; char *path; #ifdef __sgi const char *gamename = "gamemips.so"; #else #error Unknown arch #endif setreuid(getuid(), getuid()); setegid(getgid()); if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); getcwd(curpath, sizeof(curpath)); Com_Printf("------- Loading %s -------", gamename); // now run through the search paths path = NULL; while (1) { path = FS_NextPath (path); if (!path) return NULL; // couldn't find one anywhere sprintf (name, "%s/%s/%s", curpath, path, gamename); Com_Printf ("Trying to load library (%s)\n",name); game_library = dlopen (name, RTLD_NOW ); if (game_library) { Com_DPrintf ("LoadLibrary (%s)\n",name); break; } } GetGameAPI = (void *)dlsym (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); #else return (void *)GetGameAPI (parms); #endif }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); char name[MAX_OSPATH]; char curpath[MAX_OSPATH]; char *path; // Knightmare- changed game library name for better cohabitation #ifdef __i386__ const char *gamename = "kmq2gamei386.so"; #elif defined __alpha__ const char *gamename = "kmq2gameaxp.so"; #else #error Unknown arch #endif setreuid(getuid(), getuid()); setegid(getgid()); if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); getcwd(curpath, sizeof(curpath)); Com_Printf("------- Loading %s -------\n", gamename); // now run through the search paths path = NULL; while (1) { path = FS_NextPath (path); if (!path) return NULL; // couldn't find one anywhere sprintf (name, "%s/%s/%s", curpath, path, gamename); game_library = dlopen (name, RTLD_LAZY ); if (game_library) { Com_Printf ("LoadLibrary (%s)\n",name); break; } } GetGameAPI = (void *)dlsym (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); char name[MAX_OSPATH]; char curpath[MAX_OSPATH]; char *path; #ifdef __i386__ const char *gamename = "gamei386.so"; #elif defined __sun__ const char *gamename = "gamesparc.so"; #else #error Unknown arch #endif if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); getcwd(curpath, sizeof(curpath)); Com_Printf("------- Loading %s -------", gamename); // now run through the search paths path = NULL; while (1) { path = FS_NextPath (path); if (!path) return NULL; // couldn't find one anywhere sprintf (name, "%s/%s/%s", curpath, path, gamename); game_library = dlopen (name, RTLD_NOW ); if (game_library) { Com_DPrintf ("LoadLibrary (%s)\n",name); break; } else Com_Printf("error: %s\n", dlerror()); } GetGameAPI = (void *)dlsym (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* Loads the game dll */ void *Sys_GetGameAPI(void *parms){ gameapi_t * GetGameAPI; FILE * fp; char name[MAX_OSPATH]; char * path; setreuid(getuid(), getuid()); setegid(getgid()); if(game_library) Com_Error(ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadGame"); Com_Printf("------- Loading game.so -------\n"); /* now run through the search paths */ path = NULL; while(1){ path = FS_NextPath(path); if(!path) return NULL; snprintf(name, MAX_OSPATH, "%s/game.so", path); /* skip it if it doesn't exist */ fp = fopen(name, "rb"); if(fp == NULL) continue; fclose(fp); game_library = dlopen(name, RTLD_NOW); if(game_library){ Com_MDPrintf("LoadLibrary(%s)\n", name); break; } else { Com_MDPrintf("LoadLibrary(%s)\n", name); Com_MDPrintf("%s\n", dlerror()); } } GetGameAPI =(gameapi_t *) dlsym(game_library, "GetGameAPI"); if(!GetGameAPI){ Sys_UnloadGame(); return NULL; } return GetGameAPI(parms); }
void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); const char *basepath; const char *cdpath; const char *gamedir; const char *homepath; #ifdef MACOS_X const char *apppath; #endif const char *fn; #ifdef JK2_MODE const char *gamename = "jospgame" ARCH_STRING DLL_EXT; #else const char *gamename = "jagame" ARCH_STRING DLL_EXT; #endif if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without calling Sys_UnloadGame"); // check the current debug directory first for development purposes homepath = Cvar_VariableString( "fs_homepath" ); basepath = Cvar_VariableString( "fs_basepath" ); cdpath = Cvar_VariableString( "fs_cdpath" ); gamedir = Cvar_VariableString( "fs_game" ); #ifdef MACOS_X apppath = Cvar_VariableString( "fs_apppath" ); #endif fn = FS_BuildOSPath( basepath, gamedir, gamename ); game_library = Sys_LoadLibrary( fn ); //First try in mod directories. basepath -> homepath -> cdpath if (!game_library) { if (homepath[0]) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( homepath, gamedir, gamename); game_library = Sys_LoadLibrary( fn ); } } #ifdef MACOS_X if (!game_library) { if( apppath[0] ) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( apppath, gamedir, gamename ); game_library = Sys_LoadLibrary( fn ); } } #endif if (!game_library) { if( cdpath[0] ) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( cdpath, gamedir, gamename ); game_library = Sys_LoadLibrary( fn ); } } //Now try in base. basepath -> homepath -> cdpath if (!game_library) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( basepath, BASEGAME, gamename); game_library = Sys_LoadLibrary( fn ); } if (!game_library) { if ( homepath[0] ) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( homepath, BASEGAME, gamename); game_library = Sys_LoadLibrary( fn ); } } #ifdef MACOS_X if (!game_library) { if( apppath[0] ) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( apppath, BASEGAME, gamename ); game_library = Sys_LoadLibrary( fn ); } } #endif if (!game_library) { if( cdpath[0] ) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( cdpath, BASEGAME, gamename ); game_library = Sys_LoadLibrary( fn ); } } //Still couldn't find it. if (!game_library) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); Com_Error( ERR_FATAL, "Couldn't load game" ); } Com_Printf ( "Sys_GetGameAPI(%s): succeeded ...\n", fn ); GetGameAPI = (void *(*)(void *))Sys_LoadFunction (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); FILE *fp; char name[MAX_OSPATH]; char *path; char *str_p; #if defined __i386__ const char *gamename = "gamei386.so"; #elif defined __x86_64__ const char *gamename = "gamex86_64.so"; #elif defined __alpha__ const char *gamename = "gameaxp.so"; #elif defined __powerpc__ const char *gamename = "gameppc.so"; #elif defined __sparc__ const char *gamename = "gamesparc.so"; #elif defined __arm__ const char *gamename = "gamearm.so"; #else #error Unknown arch #endif setreuid(getuid(), getuid()); setegid(getgid()); if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); Com_Printf("------- Loading %s -------\n", gamename); // now run through the search paths path = NULL; while (1) { path = FS_NextPath (path); if (!path) return NULL; // couldn't find one anywhere snprintf (name, MAX_OSPATH, "%s/%s", path, gamename); /* skip it if it just doesn't exist */ fp = fopen(name, "rb"); if (fp == NULL) continue; fclose(fp); game_library = dlopen (name, RTLD_NOW); if (game_library) { Com_MDPrintf ("LoadLibrary (%s)\n",name); break; } else { Com_Printf ("LoadLibrary (%s):", name); path = dlerror(); str_p = strchr(path, ':'); // skip the path (already shown) if (str_p == NULL) str_p = path; else str_p++; Com_Printf ("%s\n", str_p); return NULL; } } GetGameAPI = (void *)dlsym (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); char name[MAX_OSPATH]; char cwd[MAX_OSPATH]; #if defined _M_IX86 const char *gamename = "jk2gamex86.dll"; #ifdef NDEBUG const char *debugdir = "release"; #elif MEM_DEBUG const char *debugdir = "shdebug"; #else const char *debugdir = "debug"; #endif //NDEBUG #elif defined _M_ALPHA const char *gamename = "jk2gameaxp.dll"; #ifdef NDEBUG const char *debugdir = "releaseaxp"; #else const char *debugdir = "debugaxp"; #endif //NDEBUG #endif //_M__IX86 if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); // check the current debug directory first for development purposes _getcwd (cwd, sizeof(cwd)); Com_sprintf (name, sizeof(name), "%s/%s/%s", cwd, debugdir, gamename); game_library = LoadLibrary ( name ); if (game_library) { Com_DPrintf ("LoadLibrary (%s)\n", name); } else { // check the current directory for other development purposes Com_sprintf (name, sizeof(name), "%s/%s", cwd, gamename); game_library = LoadLibrary ( name ); if (game_library) { Com_DPrintf ("LoadLibrary (%s)\n", name); } else { char *buf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buf, 0, NULL ); Com_Printf( "LoadLibrary(\"%s\") failed\n", name); Com_Printf( "...reason: '%s'\n", buf ); Com_Error( ERR_FATAL, "Couldn't load game" ); } } GetGameAPI = (void *(*)(void *))GetProcAddress (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* * Loads the game dll */ void * Sys_GetGameAPI(void *parms) { void *(*GetGameAPI)(void *); FILE *fp; char name[MAX_OSPATH]; char *path; char *str_p; #ifdef __APPLE__ const char *gamename = "game.dylib"; #else const char *gamename = "game.so"; #endif setreuid(getuid(), getuid()); setegid(getgid()); if (game_library) { Com_Error(ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); } Com_Printf("LoadLibrary(\"%s\")\n", gamename); /* now run through the search paths */ path = NULL; while (1) { path = FS_NextPath(path); if (!path) { return NULL; /* couldn't find one anywhere */ } snprintf(name, MAX_OSPATH, "%s/%s", path, gamename); /* skip it if it just doesn't exist */ fp = fopen(name, "rb"); if (fp == NULL) { continue; } fclose(fp); game_library = dlopen(name, RTLD_NOW); if (game_library) { Com_MDPrintf("LoadLibrary (%s)\n", name); break; } else { Com_Printf("LoadLibrary (%s):", name); path = (char *)dlerror(); str_p = strchr(path, ':'); /* skip the path (already shown) */ if (str_p == NULL) { str_p = path; } else { str_p++; } Com_Printf("%s\n", str_p); return NULL; } } GetGameAPI = (void *)dlsym(game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame(); return NULL; } return GetGameAPI(parms); }
void *Sys_GetGameAPI (void *parms) { #ifndef GAME_HARD_LINKED void *(*GetGameAPI) (void *); char name[MAX_OSPATH]; char *path; char cwd[MAX_OSPATH]; #if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) const char *gamename = "gamex64.dll"; #ifdef NDEBUG const char *debugdir = "releasex64"; #else const char *debugdir = "debugx64"; #endif #elif defined(_M_IX86) || defined(__i386__) const char *gamename = "gamex86.dll"; #ifdef NDEBUG const char *debugdir = "release"; #else const char *debugdir = "debug"; #endif #elif defined _M_ALPHA const char *gamename = "gameaxp.dll"; #ifdef NDEBUG const char *debugdir = "releaseaxp"; #else const char *debugdir = "debugaxp"; #endif #endif if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); // check the current debug directory first for development purposes _getcwd (cwd, sizeof(cwd)); Com_sprintf (name, sizeof(name), "%s/%s/%s", cwd, debugdir, gamename); game_library = LoadLibrary ( name ); if (game_library) { Com_DPrintf(DEVELOPER_MSG_STANDARD, "LoadLibrary (%s)\n", name); } else { // check the current directory for other development purposes Com_sprintf (name, sizeof(name), "%s/%s", cwd, gamename); game_library = LoadLibrary ( name ); if (game_library) { Com_DPrintf(DEVELOPER_MSG_STANDARD, "LoadLibrary (%s)\n", name); } else { // now run through the search paths path = NULL; while (1) { path = FS_NextPath (path); if (!path) return NULL; // couldn't find one anywhere Com_sprintf (name, sizeof(name), "%s/%s", path, gamename); game_library = LoadLibrary (name); if (game_library) { Com_DPrintf(DEVELOPER_MSG_STANDARD, "LoadLibrary (%s)\n",name); break; } } } } GetGameAPI = (void *)GetProcAddress (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } #endif /* ! GAME_HARD_LINKED */ return GetGameAPI (parms); }
void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); const char *basepath; const char *cdpath; const char *gamedir; const char *homepath; const char *fn; const char *gamename; if(Cvar_VariableIntegerValue("com_jk2")) { gamename = "jk2game" ARCH_STRING DLL_EXT; } else { gamename = "jagame" ARCH_STRING DLL_EXT; } if (game_library) Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); // check the current debug directory first for development purposes homepath = Cvar_VariableString( "fs_homepath" ); basepath = Cvar_VariableString( "fs_basepath" ); cdpath = Cvar_VariableString( "fs_cdpath" ); gamedir = Cvar_VariableString( "fs_game" ); if(!gamedir || !gamedir[0]) gamedir = BASEGAME; fn = FS_BuildOSPath( basepath, gamedir, gamename ); game_library = Sys_LoadLibrary( fn ); //First try in mod directories. basepath -> homepath -> cdpath if (!game_library) { if (homepath[0]) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( homepath, gamedir, gamename); game_library = Sys_LoadLibrary( fn ); } } if (!game_library) { if( cdpath[0] ) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( cdpath, gamedir, gamename ); game_library = Sys_LoadLibrary( fn ); } } //Now try in base. basepath -> homepath -> cdpath if (!game_library) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( basepath, BASEGAME, gamename); game_library = Sys_LoadLibrary( fn ); } if (!game_library) { if ( homepath[0] ) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( homepath, BASEGAME, gamename); game_library = Sys_LoadLibrary( fn ); } } if (!game_library) { if( cdpath[0] ) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); fn = FS_BuildOSPath( cdpath, BASEGAME, gamename ); game_library = Sys_LoadLibrary( fn ); } } //Still couldn't find it. if (!game_library) { Com_Printf( "Sys_GetGameAPI(%s) failed: \"%s\"\n", fn, Sys_LibraryError() ); Com_Error( ERR_FATAL, "Couldn't load game" ); } Com_Printf ( "Sys_GetGameAPI(%s): succeeded ...\n", fn ); GetGameAPI = (void *(*)(void *))Sys_LoadFunction (game_library, "GetGameAPI"); if (!GetGameAPI) { Sys_UnloadGame (); return NULL; } return GetGameAPI (parms); }
/* ================= Sys_GetGameAPI Loads the game dll ================= */ void *Sys_GetGameAPI (void *parms) { void *(*GetGameAPI) (void *); char name[MAX_OSPATH]; char *path; char cwd[MAX_OSPATH]; #if defined _M_IX86 const char *gamename = "gamex86.dll"; #ifdef NDEBUG const char *debugdir = "release"; #else const char *debugdir = "debug"; #endif #elif defined _M_ALPHA const char *gamename = "gameaxp.dll"; #ifdef NDEBUG const char *debugdir = "releaseaxp"; #else const char *debugdir = "debugaxp"; #endif #elif defined _WIN64 const char *gamename = "gamex86_64.dll"; #ifdef NDEBUG const char *debugdir = "release"; #else const char *debugdir = "debug"; #endif #else #error Don't know what kind of dynamic objects to use for this architecture. #endif if (game_library) { Sys_UnloadGame(); Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); } // check the current debug directory first for development purposes _getcwd (cwd, sizeof(cwd)); Com_sprintf (name, sizeof(name), "%s/%s/%s", cwd, debugdir, gamename); game_library = LoadLibrary ( name ); if (!game_library) { #ifdef DEBUG // check the current directory for other development purposes Com_sprintf (name, sizeof(name), "%s/%s", cwd, gamename); game_library = LoadLibrary ( name ); if (!game_library) #endif { // now run through the search paths path = NULL; while (1) { path = FS_NextPath (path); if (!path) return NULL; // couldn't find one anywhere Com_sprintf (name, sizeof(name), "%s/%s", path, gamename); game_library = LoadLibrary (name); if (game_library) { break; } } } } if( !game_library ) { return NULL; } Com_DPrintf ("LoadLibrary (%s)\n", name); GetGameAPI = (void *)GetProcAddress (game_library, "GetGameAPI"); if (!GetGameAPI) { Com_DPrintf("GetProcAddress from %s failed with error %lu\n", name, GetLastError()); Sys_UnloadGame (); return NULL; } return GetGameAPI(parms); }