BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { if (fdwReason == DLL_PROCESS_ATTACH) { #ifdef HOOK_GAMEDLL g_ReGameDLLRuntimeConfig.parseFromCommandLine(GetCommandLineA()); g_pOriginalGameDLLModule = Sys_LoadModule(shrPathGameDLL()); g_pOriginalFileSystemModule = Sys_LoadModule(ORIGINAL_FILESYSTEM_DLL_NAME); size_t gameAddr = (size_t)Sys_GetProcAddress((void *)g_pOriginalGameDLLModule, GIVEFNPTRS_TO_DLL_PROCNAME); size_t engAddr = (size_t)Sys_GetProcAddress(ORIGINAL_ENGINE_DLL_NAME, CREATEINTERFACE_PROCNAME); HookGameDLL(gameAddr, engAddr); #endif } else if (fdwReason == DLL_PROCESS_DETACH) { if (g_pOriginalFileSystemModule) { Sys_UnloadModule(g_pOriginalFileSystemModule); g_pOriginalFileSystemModule = NULL; g_OriginalFileSystemFactory = NULL; g_pOriginalFileSystem = NULL; } if (g_pOriginalGameDLLModule) { Sys_UnloadModule(g_pOriginalGameDLLModule); g_pOriginalGameDLLModule = NULL; } } return TRUE; }
//----------------------------------------------------------------------------- // Purpose: returns the instance of the named module // Input : *pModuleName - name of the module // Output : interface_instance_t - instance of that module //----------------------------------------------------------------------------- CreateInterfaceFn Sys_GetFactory( const char *pModuleName ) { #ifdef _WIN32 return static_cast<CreateInterfaceFn>( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) ); #elif defined(POSIX) // see Sys_GetFactory( CSysModule *pModule ) for an explanation return (CreateInterfaceFn)( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) ); #endif }
void __attribute__((constructor)) DllMainLoad() { g_pOriginalGameDLLModule = Sys_LoadModule(shrPathGameDLL()); g_pOriginalFileSystemModule = Sys_LoadModule(ORIGINAL_FILESYSTEM_DLL_NAME); size_t gameAddr = (size_t)Sys_GetProcAddress((void *)g_pOriginalGameDLLModule, GIVEFNPTRS_TO_DLL_PROCNAME); size_t engAddr = (size_t)Sys_GetProcAddress(ORIGINAL_ENGINE_DLL_NAME, CREATEINTERFACE_PROCNAME); HookGameDLL(gameAddr, engAddr); }
//----------------------------------------------------------------------------- // Purpose: returns the instance of the named module // Input : *pModuleName - name of the module // Output : interface_instance_t - instance of that module //----------------------------------------------------------------------------- CreateInterfaceFn Sys_GetFactory( const char *pModuleName ) { #if defined ( _WIN32 ) return static_cast<CreateInterfaceFn>( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) ); #else // Linux gives this error: //../public/interface.cpp: In function `IBaseInterface *(*Sys_GetFactory //(const char *)) (const char *, int *)': //../public/interface.cpp:186: invalid static_cast from type `void *' to //type `IBaseInterface *(*) (const char *, int *)' // // so lets use the old style cast. return (CreateInterfaceFn)( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) ); #endif }
//======================================================================= // DLL'S MANAGER SYSTEM //======================================================================= qboolean Sys_LoadLibrary( dll_info_t *dll ) { const dllfunc_t *func; string errorstring; // check errors if( !dll ) return false; // invalid desc if( dll->link ) return true; // already loaded if( !dll->name || !*dll->name ) return false; // nothing to load MsgDev( D_NOTE, "Sys_LoadLibrary: Loading %s", dll->name ); if( dll->fcts ) { // lookup export table for( func = dll->fcts; func && func->name != NULL; func++ ) *func->func = NULL; } if( !dll->link ) dll->link = LoadLibrary ( dll->name ); // environment pathes // no DLL found if( !dll->link ) { Q_snprintf( errorstring, sizeof( errorstring ), "Sys_LoadLibrary: couldn't load %s\n", dll->name ); goto error; } // Get the function adresses for( func = dll->fcts; func && func->name != NULL; func++ ) { if( !( *func->func = Sys_GetProcAddress( dll, func->name ))) { Q_snprintf( errorstring, sizeof( errorstring ), "Sys_LoadLibrary: %s missing or invalid function (%s)\n", dll->name, func->name ); goto error; } } MsgDev( D_NOTE, " - ok\n" ); return true; error: MsgDev( D_NOTE, " - failed\n" ); Sys_FreeLibrary( dll ); // trying to free if( dll->crash ) Sys_Error( errorstring ); else MsgDev( D_ERROR, errorstring ); return false; }
/* ============== Eng_LoadFunctions Load engine->front end interface, if possible ============== */ int Eng_LoadFunctions( long hMod ) { engine_api_func pfnEngineAPI; pfnEngineAPI = ( engine_api_func )Sys_GetProcAddress( hMod, "Sys_EngineAPI" ); if ( !pfnEngineAPI ) return 0; if ( !(*pfnEngineAPI)( ENGINE_LAUNCHER_API_VERSION, sizeof( engine_api_t ), &engineapi ) ) return 0; // All is okay return 1; }
/* ==================== ModPlug_OpenLibrary Try to load the modplugFile DLL ==================== */ qboolean ModPlug_OpenLibrary (void) { const char* dllnames_modplug [] = { #if defined(WIN32) "libmodplug-1.dll", "modplug.dll", #elif defined(MACOSX) "libmodplug.dylib", #else "libmodplug.so.1", "libmodplug.so", #endif NULL }; // Already loaded? if (modplug_dll) return true; // COMMANDLINEOPTION: Sound: -nomodplug disables modplug sound support if (COM_CheckParm("-nomodplug")) return false; #ifdef __ANDROID__ Con_Print("Warning: no modplug support in Android yet.\n"); return false; #endif // Load the DLLs // We need to load both by hand because some OSes seem to not load // the modplug DLL automatically when loading the modplugFile DLL if(Sys_LoadLibrary (dllnames_modplug, &modplug_dll, modplugfuncs)) { qModPlug_SetMasterVolume = (ModPlug_SetMasterVolume_t *) Sys_GetProcAddress(modplug_dll, "ModPlug_SetMasterVolume"); if(!qModPlug_SetMasterVolume) Con_Print("Warning: modplug volume control not supported. Try getting a newer version of libmodplug.\n"); return true; } else return false; }
/* ==================== ModPlug_OpenLibrary Try to load the modplugFile DLL ==================== */ qboolean ModPlug_OpenLibrary (void) { const char* dllnames_modplug [] = { #if defined(WIN32) "libmodplug-1.dll", "modplug.dll", #elif defined(MACOSX) "libmodplug.dylib", #else "libmodplug.so.1", "libmodplug.so", #endif NULL }; // Already loaded? if (modplug_dll) return true; // COMMANDLINEOPTION: Sound: -nomodplug disables modplug sound support if (COM_CheckParm("-nomodplug")) return false; // Load the DLLs // We need to load both by hand because some OSes seem to not load // the modplug DLL automatically when loading the modplugFile DLL if(Sys_LoadLibrary (dllnames_modplug, &modplug_dll, modplugfuncs)) { qModPlug_SetMasterVolume = (ModPlug_SetMasterVolume_t *) Sys_GetProcAddress(modplug_dll, "ModPlug_SetMasterVolume"); if(!qModPlug_SetMasterVolume) Con_Print("Внимание: контроль громкости modplug не поддерживается. Попробуйте взять новую версию libmodplug.\n"); return true; } else return false; }
/* * Loads the OpenAL shared lib, creates * a context and device handle. */ qboolean QAL_Init() { /* DEFAULT_OPENAL_DRIVER is defined at compile time via the compiler */ al_driver = Cvar_Get("al_driver", DEFAULT_OPENAL_DRIVER, CVAR_ARCHIVE); al_device = Cvar_Get("al_device", "", CVAR_ARCHIVE); Com_Printf("LoadLibrary(%s)\n", al_driver->string); /* Load the library */ Sys_LoadLibrary(al_driver->string, NULL, &handle); if (!handle) { Com_Printf("Loading %s failed! Disabling OpenAL.\n", al_driver->string); return false; } /* Connect function pointers to management functions */ qalcCreateContext = Sys_GetProcAddress(handle, "alcCreateContext"); qalcMakeContextCurrent = Sys_GetProcAddress(handle, "alcMakeContextCurrent"); qalcProcessContext = Sys_GetProcAddress(handle, "alcProcessContext"); qalcSuspendContext = Sys_GetProcAddress(handle, "alcSuspendContext"); qalcDestroyContext = Sys_GetProcAddress(handle, "alcDestroyContext"); qalcGetCurrentContext = Sys_GetProcAddress(handle, "alcGetCurrentContext"); qalcGetContextsDevice = Sys_GetProcAddress(handle, "alcGetContextsDevice"); qalcOpenDevice = Sys_GetProcAddress(handle, "alcOpenDevice"); qalcCloseDevice = Sys_GetProcAddress(handle, "alcCloseDevice"); qalcGetError = Sys_GetProcAddress(handle, "alcGetError"); qalcIsExtensionPresent = Sys_GetProcAddress(handle, "alcIsExtensionPresent"); qalcGetProcAddress = Sys_GetProcAddress(handle, "alcGetProcAddress"); qalcGetEnumValue = Sys_GetProcAddress(handle, "alcGetEnumValue"); qalcGetString = Sys_GetProcAddress(handle, "alcGetString"); qalcGetIntegerv = Sys_GetProcAddress(handle, "alcGetIntegerv"); qalcCaptureOpenDevice = Sys_GetProcAddress(handle, "alcCaptureOpenDevice"); qalcCaptureCloseDevice = Sys_GetProcAddress(handle, "alcCaptureCloseDevice"); qalcCaptureStart = Sys_GetProcAddress(handle, "alcCaptureStart"); qalcCaptureStop = Sys_GetProcAddress(handle, "alcCaptureStop"); qalcCaptureSamples = Sys_GetProcAddress(handle, "alcCaptureSamples"); /* Connect function pointers to to OpenAL API functions */ qalEnable = Sys_GetProcAddress(handle, "alEnable"); qalDisable = Sys_GetProcAddress(handle, "alDisable"); qalIsEnabled = Sys_GetProcAddress(handle, "alIsEnabled"); qalGetString = Sys_GetProcAddress(handle, "alGetString"); qalGetBooleanv = Sys_GetProcAddress(handle, "alGetBooleanv"); qalGetIntegerv = Sys_GetProcAddress(handle, "alGetIntegerv"); qalGetFloatv = Sys_GetProcAddress(handle, "alGetFloatv"); qalGetDoublev = Sys_GetProcAddress(handle, "alGetDoublev"); qalGetBoolean = Sys_GetProcAddress(handle, "alGetBoolean"); qalGetInteger = Sys_GetProcAddress(handle, "alGetInteger"); qalGetFloat = Sys_GetProcAddress(handle, "alGetFloat"); qalGetDouble = Sys_GetProcAddress(handle, "alGetDouble"); qalGetError = Sys_GetProcAddress(handle, "alGetError"); qalIsExtensionPresent = Sys_GetProcAddress(handle, "alIsExtensionPresent"); qalGetProcAddress = Sys_GetProcAddress(handle, "alGetProcAddress"); qalGetEnumValue = Sys_GetProcAddress(handle, "alGetEnumValue"); qalListenerf = Sys_GetProcAddress(handle, "alListenerf"); qalListener3f = Sys_GetProcAddress(handle, "alListener3f"); qalListenerfv = Sys_GetProcAddress(handle, "alListenerfv"); qalListeneri = Sys_GetProcAddress(handle, "alListeneri"); qalListener3i = Sys_GetProcAddress(handle, "alListener3i"); qalListeneriv = Sys_GetProcAddress(handle, "alListeneriv"); qalGetListenerf = Sys_GetProcAddress(handle, "alGetListenerf"); qalGetListener3f = Sys_GetProcAddress(handle, "alGetListener3f"); qalGetListenerfv = Sys_GetProcAddress(handle, "alGetListenerfv"); qalGetListeneri = Sys_GetProcAddress(handle, "alGetListeneri"); qalGetListener3i = Sys_GetProcAddress(handle, "alGetListener3i"); qalGetListeneriv = Sys_GetProcAddress(handle, "alGetListeneriv"); qalGenSources = Sys_GetProcAddress(handle, "alGenSources"); qalDeleteSources = Sys_GetProcAddress(handle, "alDeleteSources"); qalIsSource = Sys_GetProcAddress(handle, "alIsSource"); qalSourcef = Sys_GetProcAddress(handle, "alSourcef"); qalSource3f = Sys_GetProcAddress(handle, "alSource3f"); qalSourcefv = Sys_GetProcAddress(handle, "alSourcefv"); qalSourcei = Sys_GetProcAddress(handle, "alSourcei"); qalSource3i = Sys_GetProcAddress(handle, "alSource3i"); qalSourceiv = Sys_GetProcAddress(handle, "alSourceiv"); qalGetSourcef = Sys_GetProcAddress(handle, "alGetSourcef"); qalGetSource3f = Sys_GetProcAddress(handle, "alGetSource3f"); qalGetSourcefv = Sys_GetProcAddress(handle, "alGetSourcefv"); qalGetSourcei = Sys_GetProcAddress(handle, "alGetSourcei"); qalGetSource3i = Sys_GetProcAddress(handle, "alGetSource3i"); qalGetSourceiv = Sys_GetProcAddress(handle, "alGetSourceiv"); qalSourcePlayv = Sys_GetProcAddress(handle, "alSourcePlayv"); qalSourceStopv = Sys_GetProcAddress(handle, "alSourceStopv"); qalSourceRewindv = Sys_GetProcAddress(handle, "alSourceRewindv"); qalSourcePausev = Sys_GetProcAddress(handle, "alSourcePausev"); qalSourcePlay = Sys_GetProcAddress(handle, "alSourcePlay"); qalSourceStop = Sys_GetProcAddress(handle, "alSourceStop"); qalSourceRewind = Sys_GetProcAddress(handle, "alSourceRewind"); qalSourcePause = Sys_GetProcAddress(handle, "alSourcePause"); qalSourceQueueBuffers = Sys_GetProcAddress(handle, "alSourceQueueBuffers"); qalSourceUnqueueBuffers = Sys_GetProcAddress(handle, "alSourceUnqueueBuffers"); qalGenBuffers = Sys_GetProcAddress(handle, "alGenBuffers"); qalDeleteBuffers = Sys_GetProcAddress(handle, "alDeleteBuffers"); qalIsBuffer = Sys_GetProcAddress(handle, "alIsBuffer"); qalBufferData = Sys_GetProcAddress(handle, "alBufferData"); qalBufferf = Sys_GetProcAddress(handle, "alBufferf"); qalBuffer3f = Sys_GetProcAddress(handle, "alBuffer3f"); qalBufferfv = Sys_GetProcAddress(handle, "alBufferfv"); qalBufferi = Sys_GetProcAddress(handle, "alBufferi"); qalBuffer3i = Sys_GetProcAddress(handle, "alBuffer3i"); qalBufferiv = Sys_GetProcAddress(handle, "alBufferiv"); qalGetBufferf = Sys_GetProcAddress(handle, "alGetBufferf"); qalGetBuffer3f = Sys_GetProcAddress(handle, "alGetBuffer3f"); qalGetBufferfv = Sys_GetProcAddress(handle, "alGetBufferfv"); qalGetBufferi = Sys_GetProcAddress(handle, "alGetBufferi"); qalGetBuffer3i = Sys_GetProcAddress(handle, "alGetBuffer3i"); qalGetBufferiv = Sys_GetProcAddress(handle, "alGetBufferiv"); qalDopplerFactor = Sys_GetProcAddress(handle, "alDopplerFactor"); qalDopplerVelocity = Sys_GetProcAddress(handle, "alDopplerVelocity"); qalSpeedOfSound = Sys_GetProcAddress(handle, "alSpeedOfSound"); qalDistanceModel = Sys_GetProcAddress(handle, "alDistanceModel"); /* Open the OpenAL device */ Com_Printf("...opening OpenAL device:"); device = qalcOpenDevice(al_device->string[0] ? al_device->string : NULL); if(!device) { Com_DPrintf("failed\n"); QAL_Shutdown(); return false; } Com_Printf("ok\n"); /* Create the OpenAL context */ Com_Printf("...creating OpenAL context: "); context = qalcCreateContext(device, NULL); if(!context) { Com_DPrintf("failed\n"); QAL_Shutdown(); return false; } Com_Printf("ok\n"); /* Set the created context as current context */ Com_Printf("...making context current: "); if (!qalcMakeContextCurrent(context)) { Com_DPrintf("failed\n"); QAL_Shutdown(); return false; } #if !defined (__APPLE__) if (qalcIsExtensionPresent(device, "ALC_EXT_EFX") != AL_FALSE) { qalGenFilters = qalGetProcAddress("alGenFilters"); qalFilteri = qalGetProcAddress("alFilteri"); qalFilterf = qalGetProcAddress("alFilterf"); qalDeleteFilters = qalGetProcAddress("alDeleteFilters"); } else { qalGenFilters = NULL; qalFilteri = NULL; qalFilterf = NULL; qalDeleteFilters = NULL; } #endif Com_Printf("ok\n"); /* Print OpenAL informations */ Com_Printf("\n"); QAL_SoundInfo(); Com_Printf("\n"); return true; }
//----------------------------------------------------------------------------- // Purpose: Loads a DLL/component from disk and returns a handle to it // Input : *pModuleName - filename of the component // Output : opaque handle to the module (hides system dependency) //----------------------------------------------------------------------------- CSysModule *Sys_LoadModule( const char *pModuleName, Sys_Flags flags /* = SYS_NOFLAGS (0) */ ) { // If using the Steam filesystem, either the DLL must be a minimum footprint // file in the depot (MFP) or a filesystem GetLocalCopy() call must be made // prior to the call to this routine. char szCwd[1024]; HMODULE hDLL = NULL; if ( !Q_IsAbsolutePath( pModuleName ) ) { // full path wasn't passed in, using the current working dir _getcwd( szCwd, sizeof( szCwd ) ); if ( IsX360() ) { int i = CommandLine()->FindParm( "-basedir" ); if ( i ) { strcpy( szCwd, CommandLine()->GetParm( i+1 ) ); } } if (szCwd[strlen(szCwd) - 1] == '/' || szCwd[strlen(szCwd) - 1] == '\\' ) { szCwd[strlen(szCwd) - 1] = 0; } char szAbsoluteModuleName[1024]; size_t cCwd = strlen( szCwd ); if ( strstr( pModuleName, "bin/") == pModuleName || ( szCwd[ cCwd - 1 ] == 'n' && szCwd[ cCwd - 2 ] == 'i' && szCwd[ cCwd - 3 ] == 'b' ) ) { // don't make bin/bin path Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName ); } else { Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/bin/%s", szCwd, pModuleName ); } hDLL = Sys_LoadLibrary( szAbsoluteModuleName, flags ); } if ( !hDLL ) { // full path failed, let LoadLibrary() try to search the PATH now hDLL = Sys_LoadLibrary( pModuleName, flags ); #if defined( _DEBUG ) if ( !hDLL ) { // So you can see what the error is in the debugger... #if defined( _WIN32 ) && !defined( _X360 ) char *lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); LocalFree( (HLOCAL)lpMsgBuf ); #elif defined( _X360 ) DWORD error = GetLastError(); Msg( "Error(%d) - Failed to load %s:\n", error, pModuleName ); #else Msg( "Failed to load %s: %s\n", pModuleName, dlerror() ); #endif // _WIN32 } #endif // DEBUG } #if !defined(LINUX) // If running in the debugger, assume debug binaries are okay, otherwise they must run with -allowdebug if ( Sys_GetProcAddress( hDLL, "BuiltDebug" ) ) { if ( !IsX360() && hDLL && !CommandLine()->FindParm( "-allowdebug" ) && !Sys_IsDebuggerPresent() ) { Error( "Module %s is a debug build\n", pModuleName ); } DevWarning( "Module %s is a debug build\n", pModuleName ); if ( !s_bRunningWithDebugModules ) { s_bRunningWithDebugModules = true; #if 0 //def IS_WINDOWS_PC char chMemoryName[ MAX_PATH ]; DebugKernelMemoryObjectName( chMemoryName ); (void) CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1024, chMemoryName ); // Created a shared memory kernel object specific to process id // Existence of this object indicates that we have debug modules loaded #endif } } #endif return reinterpret_cast<CSysModule *>(hDLL); }