Skip to content

Commit

Permalink
Load base game's gamelib if mod has no own gamelib
Browse files Browse the repository at this point in the history
Some mods/mappacks have their own game dir (fs_game) but no own gamelib.
Doom3 defaulted to the base game dll (I think), so we should do the same.

Fixes #44
  • Loading branch information
DanielGibson committed Nov 13, 2012
1 parent c193e0b commit 768fdb5
Showing 1 changed file with 50 additions and 28 deletions.
78 changes: 50 additions & 28 deletions neo/framework/Common.cpp
Expand Up @@ -186,6 +186,7 @@ class idCommonLocal : public idCommon {
void DumpWarnings( void ); void DumpWarnings( void );
void SingleAsyncTic( void ); void SingleAsyncTic( void );
void LoadGameDLL( void ); void LoadGameDLL( void );
void LoadGameDLLbyName( const char *dll, idStr& s );
void UnloadGameDLL( void ); void UnloadGameDLL( void );
void PrintLoadingMessage( const char *msg ); void PrintLoadingMessage( const char *msg );
void FilterLangList( idStrList* list, idStr lang ); void FilterLangList( idStrList* list, idStr lang );
Expand Down Expand Up @@ -2541,6 +2542,49 @@ void idCommonLocal::Async( void ) {
} }
} }


/*
=================
idCommonLocal::LoadGameDLLbyName
Helper for LoadGameDLL() to make it less painfull to try different dll names.
=================
*/
void idCommonLocal::LoadGameDLLbyName( const char *dll, idStr& s ) {
s.CapLength(0);
// try next to the binary first (build tree)
if (Sys_GetPath(PATH_EXE, s)) {
// "s = " seems superfluous, but works around g++ 4.7 bug else StripFilename()
// (and possibly even CapLength()) seems to be "optimized" away and the string contains garbage
s = s.StripFilename();
s.AppendPath(dll);
gameDLL = sys->DLL_Load(s);
}

#if defined(_WIN32)
// then the lib/ dir relative to the binary on windows
if (!gameDLL && Sys_GetPath(PATH_EXE, s)) {
s.StripFilename();
s.AppendPath("lib");
s.AppendPath(dll);
gameDLL = sys->DLL_Load(s);
}
#elif defined(MACOS_X)
// then the binary dir in the bundle on osx
if (!gameDLL && Sys_GetPath(PATH_EXE, s)) {
s.StripFilename();
s.AppendPath(dll);
gameDLL = sys->DLL_Load(s);
}
#else
// then the install folder on *nix
if (!gameDLL) {
s = BUILD_LIBDIR;
s.AppendPath(dll);
gameDLL = sys->DLL_Load(s);
}
#endif
}

/* /*
================= =================
idCommonLocal::LoadGameDLL idCommonLocal::LoadGameDLL
Expand All @@ -2561,38 +2605,16 @@ void idCommonLocal::LoadGameDLL( void ) {
fs_game = BASE_GAMEDIR; fs_game = BASE_GAMEDIR;


gameDLL = 0; gameDLL = 0;
sys->DLL_GetFileName(fs_game, dll, sizeof(dll));


// try next to the binary first (build tree) sys->DLL_GetFileName(fs_game, dll, sizeof(dll));
if (Sys_GetPath(PATH_EXE, s)) { LoadGameDLLbyName(dll, s);
s.StripFilename();
s.AppendPath(dll);
gameDLL = sys->DLL_Load(s);
}


#if defined(_WIN32) // there was no gamelib for this mod, use default one from base game
// then the lib/ dir relative to the binary on windows
if (!gameDLL && Sys_GetPath(PATH_EXE, s)) {
s.StripFilename();
s.AppendPath("lib");
s.AppendPath(dll);
gameDLL = sys->DLL_Load(s);
}
#elif defined(MACOS_X)
// then the binary dir in the bundle on osx
if (!gameDLL && Sys_GetPath(PATH_EXE, s)) {
s.StripFilename();
s.AppendPath(dll);
gameDLL = sys->DLL_Load(s);
}
#else
// then the install folder on *nix
if (!gameDLL) { if (!gameDLL) {
s = BUILD_LIBDIR; common->Warning( "couldn't load mod-specific %s, defaulting to base game's library!", dll );
s.AppendPath(dll); sys->DLL_GetFileName(BASE_GAMEDIR, dll, sizeof(dll));
gameDLL = sys->DLL_Load(s); LoadGameDLLbyName(dll, s);
} }
#endif


if ( !gameDLL ) { if ( !gameDLL ) {
common->FatalError( "couldn't load game dynamic library" ); common->FatalError( "couldn't load game dynamic library" );
Expand Down

0 comments on commit 768fdb5

Please sign in to comment.