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; }
int main(int argc, char* argv[]) { CommandLine()->CreateCmdLine( argc, argv ); const char *pDLLName = "vvis_dll.dll"; CSysModule *pModule = Sys_LoadModule( pDLLName ); if ( !pModule ) { printf( "vvis launcher error: can't load %s\n%s", pDLLName, GetLastErrorString() ); return 1; } CreateInterfaceFn fn = Sys_GetFactory( pModule ); if( !fn ) { printf( "vvis launcher error: can't get factory from %s\n", pDLLName ); Sys_UnloadModule( pModule ); return 2; } int retCode = 0; ILaunchableDLL *pDLL = (ILaunchableDLL*)fn( LAUNCHABLE_DLL_INTERFACE_VERSION, &retCode ); if( !pDLL ) { printf( "vvis launcher error: can't get IVVisDLL interface from %s\n", pDLLName ); Sys_UnloadModule( pModule ); return 3; } pDLL->main( argc, argv ); Sys_UnloadModule( pModule ); return 0; }
//----------------------------------------------------------------------------- // Purpose: get the interface for the specified module and version // Input : // Output : //----------------------------------------------------------------------------- bool Sys_LoadInterface( const char *pModuleName, const char *pInterfaceVersionName, CSysModule **pOutModule, void **pOutInterface ) { CSysModule *pMod = Sys_LoadModule( pModuleName ); if ( !pMod ) return false; CreateInterfaceFn fn = Sys_GetFactory( pMod ); if ( !fn ) { Sys_UnloadModule( pMod ); return false; } *pOutInterface = fn( pInterfaceVersionName, NULL ); if ( !( *pOutInterface ) ) { Sys_UnloadModule( pMod ); return false; } if ( pOutModule ) *pOutModule = pMod; return true; }
int main( int argc, char **argv ) { const char *pModuleName = "vtex_dll.dll"; CSysModule *pModule = Sys_LoadModule( pModuleName ); if ( !pModule ) { printf( "Can't load %s.", pModuleName ); return false; } CreateInterfaceFn fn = Sys_GetFactory( pModule ); if ( !fn ) { printf( "Can't get factory from %s.", pModuleName ); Sys_UnloadModule( pModule ); return false; } ILaunchableDLL *pInterface = (ILaunchableDLL*)fn( LAUNCHABLE_DLL_INTERFACE_VERSION, NULL ); if ( !pInterface ) { printf( "Can't get '%s' interface from %s.", LAUNCHABLE_DLL_INTERFACE_VERSION, pModuleName ); Sys_UnloadModule( pModule ); return false; } int iRet = pInterface->main( argc, argv ); Sys_UnloadModule( pModule ); return iRet; }
//----------------------------------------------------------------------------- // Purpose: Adds tool from specified library // Input : *dllname - //----------------------------------------------------------------------------- void CToolFrameworkInternal::LoadToolsFromLibrary( const char *dllname ) { CSysModule *module = Sys_LoadModule( dllname ); if ( !module ) { Warning( "CToolFrameworkInternal::LoadToolsFromLibrary: Unable to load '%s'\n", dllname ); return; } CreateInterfaceFn factory = Sys_GetFactory( module ); if ( !factory ) { Sys_UnloadModule( module ); Warning( "CToolFrameworkInternal::LoadToolsFromLibrary: Dll '%s' has no factory\n", dllname ); return; } IToolDictionary *dictionary = ( IToolDictionary * )factory( VTOOLDICTIONARY_INTERFACE_VERSION, NULL ); if ( !dictionary ) { Sys_UnloadModule( module ); Warning( "CToolFrameworkInternal::LoadToolsFromLibrary: Dll '%s' doesn't support '%s'\n", dllname, VTOOLDICTIONARY_INTERFACE_VERSION ); return; } if ( !dictionary->Connect( g_AppSystemFactory ) ) { Sys_UnloadModule( module ); Warning( "CToolFrameworkInternal::LoadToolsFromLibrary: Dll '%s' connection phase failed.\n", dllname ); return; } if ( dictionary->Init( ) != INIT_OK ) { Sys_UnloadModule( module ); Warning( "CToolFrameworkInternal::LoadToolsFromLibrary: Dll '%s' initialization phase failed.\n", dllname ); return; } dictionary->CreateTools(); int toolCount = dictionary->GetToolCount(); for ( int i = 0; i < toolCount; ++i ) { IToolSystem *tool = dictionary->GetTool( i ); if ( tool ) { Msg( "Loaded tool '%s'\n", tool->GetToolName() ); m_ToolSystems.AddToTail( tool ); } } m_Dictionaries.AddToTail( dictionary ); m_Modules.AddToTail( module ); }
void __attribute__((destructor)) DllMainUnload() { 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; } }
void SystemWrapper::ShutDown() { m_Listener.Clear(); m_Commands.Clear(true); ISystemModule *module = (ISystemModule *)m_Modules.GetFirst(); while (module) { module->ShutDown(); module = (ISystemModule *)m_Modules.GetNext(); } library_t *lib = (library_t *)m_Libraries.RemoveTail(); while (lib) { if (lib->handle) { Sys_UnloadModule(lib->handle); } Mem_Free(lib); lib = (library_t *)m_Libraries.RemoveTail(); } if (m_EngineWrapper) { delete m_EngineWrapper; m_EngineWrapper = nullptr; } Cmd_RemoveWrapperCmds(); m_State = MODULE_DISCONNECTED; }
void CL_UnloadParticleMan( void ) { Sys_UnloadModule( g_hParticleManModule ); g_pParticleMan = nullptr; g_hParticleManModule = nullptr; }
void RunInDLL( const char *pFilename, CUtlVector<char*> &newArgv ) { if ( g_pConnMgr ) g_pConnMgr->SetAppState( VMPI_SERVICE_STATE_BUSY ); bool bSuccess = false; CSysModule *pModule = Sys_LoadModule( pFilename ); if ( pModule ) { CreateInterfaceFn fn = Sys_GetFactory( pModule ); if ( fn ) { ILaunchableDLL *pDLL = (ILaunchableDLL*)fn( LAUNCHABLE_DLL_INTERFACE_VERSION, NULL ); if( pDLL ) { // Do this here because the executables we would have launched usually would do it. CommandLine()->CreateCmdLine( newArgv.Count(), newArgv.Base() ); pDLL->main( newArgv.Count(), newArgv.Base() ); bSuccess = true; SpewOutputFunc( MySpewOutputFunc ); } } Sys_UnloadModule( pModule ); } if ( !bSuccess ) { Msg( "Error running VRAD (or VVIS) out of DLL '%s'\n", pFilename ); } if ( g_pConnMgr ) g_pConnMgr->SetAppState( VMPI_SERVICE_STATE_IDLE ); }
//----------------------------------------------------------------------------- // Purpose: Application entry point // Loads and runs the TrackerSRV //----------------------------------------------------------------------------- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { // winsock aware WSAData wsaData; int nReturnCode = ::WSAStartup(MAKEWORD(2,0), &wsaData); // load the Tracker Server DLL CSysModule *serverDll = Sys_LoadModule("TrackerSRV.dll"); CreateInterfaceFn serverFactory = Sys_GetFactory(serverDll); if (!serverFactory) { ::MessageBox(NULL, "Could not load 'TrackerSRV.dll'", "Fatal Error - TrackerServer", MB_OK | MB_ICONERROR); return 1; } ITrackerSRV *trackerInterface = (ITrackerSRV *)serverFactory(TRACKERSERVER_INTERFACE_VERSION, NULL); // Activate server trackerInterface->RunTrackerServer(lpCmdLine); Sys_UnloadModule(serverDll); ::WSACleanup(); return 0; }
void CL_UnloadParticleMan( void ) { Sys_UnloadModule( g_hParticleManModule ); g_pParticleMan = NULL; g_hParticleManModule = NULL; }
void UnloadFileSystemDialogModule() { if ( g_pFSDialogModule ) { Sys_UnloadModule( g_pFSDialogModule ); g_pFSDialogModule = 0; } }
void CDllDemandLoader::Unload() { if ( m_hModule ) { Sys_UnloadModule( m_hModule ); m_hModule = 0; } }
void FileSystem_UnloadDLL(void) { if (g_pFileSystemModule) { Sys_UnloadModule((CSysModule *)g_pFileSystemModule); g_pFileSystemModule = NULL; g_FileSystemFactory = NULL; g_pFileSystem = NULL; } }
void ShutdownShaderPostprocessInterface() { if ( !__g_shaderExt ) return; __g_shaderExt = NULL; if (__g_pShaderAPIShaderModule) Sys_UnloadModule(__g_pShaderAPIShaderModule); }
//----------------------------------------------------------------------------- // Purpose: Shuts down all modules //----------------------------------------------------------------------------- void CToolFrameworkInternal::ShutdownModules() { // Shutdown dictionaries int i; for ( i = m_Modules.Count(); --i >= 0; ) { Sys_UnloadModule( m_Modules[i] ); } m_Modules.RemoveAll(); }
void DisconnectHaptics() { haptics->ShutdownHaptics(); if(pFalconModule) { Sys_UnloadModule(pFalconModule); pFalconModule = 0; }else{ // delete the stub. delete haptics; } haptics = NULL; }
void UnloadMySQLWrapper() { if ( g_hMySQLDLL ) { if ( g_pSQL ) { g_pSQL->Release(); g_pSQL = NULL; } Sys_UnloadModule( g_hMySQLDLL ); g_hMySQLDLL = NULL; } }
void ShutdownStudioRender( void ) { if ( !g_pStudioRenderModule ) return; if ( g_pStudioRender ) { g_pStudioRender->Shutdown(); } g_pStudioRender = NULL; Sys_UnloadModule( g_pStudioRenderModule ); g_pStudioRenderModule = NULL; }
//----------------------------------------------------------------------------- // The application object //----------------------------------------------------------------------------- bool CUnitTestApp::Create() { // Install a special Spew handler that ignores all assertions and lets us // run for as long as possible SpewOutputFunc( UnitTestSpew ); // FIXME: This list of dlls should come from the unittests themselves AppSystemInfo_t appSystems[] = { { "vstdlib.dll", PROCESS_UTILS_INTERFACE_VERSION }, { "", "" } // Required to terminate the list }; if ( !AddSystems( appSystems ) ) return false; // Very simple... just iterate over all .DLLs in the current directory // see if they export UNITTEST_INTERFACE_VERSION. If not, then unload them // just as quick. // We may want to make this more sophisticated, giving it a search path, // or giving test DLLs special extensions, or statically linking the test DLLs // to this program. WIN32_FIND_DATA findFileData; HANDLE hFind= FindFirstFile("*.dll", &findFileData); while (hFind != INVALID_HANDLE_VALUE) { CSysModule* hLib = Sys_LoadModule(findFileData.cFileName); if ( hLib ) { CreateInterfaceFn factory = Sys_GetFactory( hLib ); if ( factory && factory( UNITTEST_INTERFACE_VERSION, NULL ) ) { AppModule_t module = LoadModule( factory ); AddSystem( module, UNITTEST_INTERFACE_VERSION ); } else { Sys_UnloadModule( hLib ); } } if (!FindNextFile( hFind, &findFileData )) break; } return true; }
// ------------------------------------------------------------------------ // // Global functions. // ------------------------------------------------------------------------ // IFileSystem* ScratchPad3D_SetupFileSystem() { // Get a filesystem interface. CSysModule *pModule = Sys_LoadModule( "filesystem_stdio" ); if( !pModule ) return NULL; CreateInterfaceFn fn = Sys_GetFactory( pModule ); IFileSystem *pFileSystem; if( !fn || (pFileSystem = (IFileSystem *)fn( FILESYSTEM_INTERFACE_VERSION, NULL )) == NULL ) { Sys_UnloadModule( pModule ); return NULL; } return pFileSystem; }
void ConnectHaptics(CreateInterfaceFn appFactory) { bool success = false; // NVNT load haptics module pFalconModule = Sys_LoadModule( HAPTICS_TEST_PREFIX HAPTICS_DLL_NAME ); if(pFalconModule) { CreateInterfaceFn factory = Sys_GetFactory( pFalconModule ); if(factory) { haptics = reinterpret_cast< IHaptics* >( factory( HAPTICS_INTERFACE_VERSION, NULL ) ); if(haptics && haptics->Initialize(engine, view, g_InputInternal, gpGlobals, appFactory, g_pVGuiInput->GetIMEWindow(), filesystem, enginevgui, ActivityList_IndexForName, ActivityList_NameForIndex)) { success = true; hap_HasDevice.SetValue(1); } } } if(!success) { Sys_UnloadModule(pFalconModule); pFalconModule = 0; haptics = new CHapticsStubbed; } if(haptics->HasDevice()) { Assert( (void*)haptics == inputsystem->GetHapticsInterfaceAddress() ); } HookHapticMessages(); }
void LoadFileSystemDialogModule() { Assert( !g_pFSDialogModule ); // Load the module with the file system open dialog. const char *pDLLName = "FileSystemOpenDialog.dll"; g_pFSDialogModule = Sys_LoadModule( pDLLName ); if ( g_pFSDialogModule ) { g_FSDialogFactory = Sys_GetFactory( g_pFSDialogModule ); } if ( !g_pFSDialogModule || !g_FSDialogFactory ) { if ( g_pFSDialogModule ) { Sys_UnloadModule( g_pFSDialogModule ); g_pFSDialogModule = NULL; } } }
void FileSystem_Term() { #if defined( MPI ) if ( g_bUseMPI ) { g_pFileSystem = g_pFullFileSystem = VMPI_FileSystem_Term(); } #endif if ( g_pFullFileSystem ) { g_pFullFileSystem->Shutdown(); g_pFullFileSystem = NULL; g_pFileSystem = NULL; } if ( g_pFullFileSystemModule ) { Sys_UnloadModule( g_pFullFileSystemModule ); g_pFullFileSystemModule = NULL; } }
//----------------------------------------------------------------------------- // Purpose: Entry point //----------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // load vgui CSysModule *vguiModule = Sys_LoadModule("vgui2.dll"); CSysModule *fileSystemModule = Sys_LoadModule("filesystem_stdio.dll"); CSysModule *netModule = Sys_LoadModule("../friends/trackerNET.dll"); CreateInterfaceFn vguiFactory = Sys_GetFactory(vguiModule); CreateInterfaceFn netFactory = Sys_GetFactory(netModule); CreateInterfaceFn fileSystemFactory = Sys_GetFactory(fileSystemModule); if (!vguiFactory) { printf("Fatal error: Could not load vgui2.dll\n"); return 2; } if (!netFactory) { printf("Fatal error: Could not load trackerNET.dll\n"); return 3; } // initialize interfaces CreateInterfaceFn factories[2] = { fileSystemFactory, vguiFactory }; assert(vgui::VGui_InitInterfacesList(factories, 2)); g_pTrackerNET = (ITrackerNET *)netFactory(TRACKERNET_INTERFACE_VERSION, NULL); g_pTrackerNET->Initialize(1300, 1400); vgui::filesystem()->AddSearchPath("../", ""); // Init the surface vgui::Panel *panel = new vgui::Panel(NULL, "TopPanel"); vgui::surface()->Init(panel->GetVPanel()); // load the scheme if (!vgui::scheme()->LoadSchemeFromFile("resource/TrackerScheme.res")) { return false; } // Start vgui vgui::ivgui()->Start(); // add our main window vgui::Panel *main = new CMainDialog(panel); // server list g_pServerList = new CServerList(main); // Run app frame loop while (vgui::ivgui()->IsRunning()) { vgui::ivgui()->RunFrame(); // networking g_pServerList->RunFrame(); } delete g_pServerList; // Shutdown vgui::surface()->Shutdown(); Sys_UnloadModule(vguiModule); Sys_UnloadModule(netModule); return 1; }
//----------------------------------------------------------------------------- // Purpose: the main loop for the dedicated server // Output : value to return to shell //----------------------------------------------------------------------------- DWORD WINAPI ServerThreadFunc( LPVOID threadobject ) { int iret = DLL_NORMAL; IDedicatedServerAPI *engineAPI; char cur[1024]; _getcwd(cur,1024); CSysModule *engineModule = NULL; CreateInterfaceFn engineFactory = NULL; while(iret!=DLL_CLOSE ) { //_chdir(UTIL_GetBaseDir()); vgui::filesystem()->Unmount(); engineModule = Sys_LoadModule( g_pszengine ); if ( !engineModule ) { goto cleanup; } engineFactory = Sys_GetFactory( engineModule ); if ( engineFactory ) { engineAPI = ( IDedicatedServerAPI * )engineFactory( VENGINE_HLDS_API_VERSION, NULL ); } if ( !engineAPI ) { goto cleanup; } server.SetEngineAPI(engineAPI); engineAPI->Init( UTIL_GetBaseDir(),server.GetCmdline(), Sys_GetFactoryThis() ); vgui::filesystem()->Mount(); if(strlen(server.GetCvars())>0) { engineAPI->AddConsoleText(server.GetCvars()); server.ResetCvars(); } while ( 1 ) { // Try to allow other apps to get some CPU Sys_Sleep( 1 ); // Check for shutdown event if ( !engineAPI->RunFrame() ) break; server.UpdateStatus( 0 ); } server.SetEngineAPI(NULL); server.SetInstance(NULL); iret = engineAPI->Shutdown(); Sys_UnloadModule( engineModule ); } // while(iret != DLL_CLOSE && gbAppHasBeenTerminated==FALSE ) cleanup: // this line is IMPORTANT! SetEvent(server.GetShutDownHandle()); // tell the main window we have shut down now //return 0; ExitThread(0); }
int main(int argc, char* argv[]) { char dllName[512]; bool bUseDefault = true; CommandLine()->CreateCmdLine( argc, argv ); // check whether they used the -both switch. If this is specified, vrad will be run // twice, once with -hdr and once without int both_arg=0; for(int arg=1;arg<argc;arg++) if (Q_stricmp(argv[arg],"-both")==0) { both_arg=arg; } char fullPath[512], redirectFilename[512]; MakeFullPath( argv[0], fullPath, sizeof( fullPath ) ); Q_StripFilename( fullPath ); Q_snprintf( redirectFilename, sizeof( redirectFilename ), "%s\\%s", fullPath, "vrad.redirect" ); // First, look for vrad.redirect and load the dll specified in there if possible. CSysModule *pModule = NULL; FILE *fp = fopen( redirectFilename, "rt" ); if ( fp ) { if ( fgets( dllName, sizeof( dllName ), fp ) ) { char *pEnd = strstr( dllName, "\n" ); if ( pEnd ) *pEnd = 0; pModule = Sys_LoadModule( dllName ); if ( pModule ) printf( "Loaded alternate VRAD DLL (%s) specified in vrad.redirect.\n", dllName ); else printf( "Can't find '%s' specified in vrad.redirect.\n", dllName ); } fclose( fp ); } int returnValue; for(int mode=0;mode<2;mode++) { if (mode && (! both_arg)) continue; // If it didn't load the module above, then use the if ( !pModule ) { strcpy( dllName, "vrad.dll" ); pModule = Sys_LoadModule( dllName ); } if( !pModule ) { printf( "vrad_launcher error: can't load %s\n%s", dllName, GetLastErrorString() ); return 1; } CreateInterfaceFn fn = Sys_GetFactory( pModule ); if( !fn ) { printf( "vrad_launcher error: can't get factory from vrad.dll\n" ); Sys_UnloadModule( pModule ); return 2; } int retCode = 0; IVRadDLL *pDLL = (IVRadDLL*)fn( VRAD_INTERFACE_VERSION, &retCode ); if( !pDLL ) { printf( "vrad_launcher error: can't get IVRadDLL interface from vrad.dll\n" ); Sys_UnloadModule( pModule ); return 3; } if (both_arg) strcpy(argv[both_arg],(mode)?"-hdr":"-ldr"); returnValue = pDLL->main( argc, argv ); Sys_UnloadModule( pModule ); pModule=0; } return returnValue; }
int main(int argc, char* argv[]) { char dllName[512]; Pause(); CommandLine()->CreateCmdLine( argc, argv ); char fullPath[512], redirectFilename[512]; MakeFullPath( argv[0], fullPath, sizeof( fullPath ) ); Q_StripFilename( fullPath ); Q_snprintf( redirectFilename, sizeof( redirectFilename ), "%s\\%s", fullPath, "vrad.redirect" ); Pause(); // First, look for vrad.redirect and load the dll specified in there if possible. CSysModule *pModule = NULL; FILE *fp = fopen( redirectFilename, "rt" ); if ( fp ) { if ( fgets( dllName, sizeof( dllName ), fp ) ) { char *pEnd = strstr( dllName, "\n" ); if ( pEnd ) *pEnd = 0; pModule = Sys_LoadModule( dllName ); if ( pModule ) printf( "Loaded alternate VRAD DLL (%s) specified in vrad.redirect.\n", dllName ); else printf( "Can't find '%s' specified in vrad.redirect.\n", dllName ); } fclose( fp ); } Pause(); // If it didn't load the module above, then use the if ( !pModule ) { strcpy( dllName, "shadercompile_dll.dll" ); pModule = Sys_LoadModule( dllName ); } Pause(); if( !pModule ) { printf( "vrad_launcher error: can't load %s\n%s", dllName, GetLastErrorString() ); Pause(); return 1; } Pause(); CreateInterfaceFn fn = Sys_GetFactory( pModule ); if( !fn ) { printf( "vrad_launcher error: can't get factory from vrad_dll.dll\n" ); Sys_UnloadModule( pModule ); return 2; } int retCode = 0; IShaderCompileDLL *pDLL = (IShaderCompileDLL*)fn( SHADER_COMPILE_INTERFACE_VERSION, &retCode ); if( !pDLL ) { printf( "vrad_launcher error: can't get IVRadDLL interface from vrad_dll.dll\n" ); Sys_UnloadModule( pModule ); return 3; } int returnValue = pDLL->main( argc, argv ); Sys_UnloadModule( pModule ); return returnValue; }