Example #1
0
void CClientVGUI::Initialize( CreateInterfaceFn* pFactories, int iNumFactories )
{
	/*
	*	Factories in the given array:
	*	engine
	*	vgui2
	*	filesystem
	*	chrome HTML
	*	GameUI
	*	client (this library)
	*/

	//4 factories to use.
	assert( static_cast<size_t>( iNumFactories ) >= NUM_FACTORIES - 1 );

	m_FactoryList[ 0 ] = Sys_GetFactoryThis();

	for( size_t uiIndex = 0; uiIndex < NUM_FACTORIES - 1; ++uiIndex )
	{
		m_FactoryList[ uiIndex + 1 ] = pFactories[ uiIndex ];
	}

	vgui2::VGui_InitInterfacesList( "CLIENT", pFactories, NUM_FACTORIES );

	vgui2::scheme()->LoadSchemeFromFile( "Resource/ClientScheme.res", "ClientScheme" );
	vgui2::scheme()->LoadSchemeFromFile( "Resource/TutorScheme.res", "TutorScheme" );
	g_GameUIFuncs = ( IGameUIFuncs* ) pFactories[ 0 ]( IGAMEUIFUNCS_NAME, nullptr );
}
Example #2
0
void InitStudioRender( void )
{
    if ( g_pStudioRenderModule )
        return;
    Assert( g_MatSysFactory );

    g_pStudioRenderModule = g_pFullFileSystem->LoadModule( "StudioRender.dll" );
    if( !g_pStudioRenderModule )
    {
        MdlError( "Can't load StudioRender.dll\n" );
    }
    CreateInterfaceFn studioRenderFactory = Sys_GetFactory( g_pStudioRenderModule );
    if (!studioRenderFactory )
    {
        MdlError( "Can't get factory for StudioRender.dll\n" );
    }
    g_pStudioRender = ( IStudioRender * )studioRenderFactory( STUDIO_RENDER_INTERFACE_VERSION, NULL );
    if (!g_pStudioRender)
    {
        MdlError( "Unable to init studio render system version %s\n", STUDIO_RENDER_INTERFACE_VERSION );
    }

    g_pStudioRender->Init( g_MatSysFactory, g_ShaderAPIFactory, g_ShaderAPIFactory, Sys_GetFactoryThis() );
    UpdateStudioRenderConfig();
}
IMaterialProxy *CMaterialProxyFactory::CreateProxy( const char *proxyName )
{
	// assumes that the client.dll is already LoadLibraried
	CreateInterfaceFn clientFactory = Sys_GetFactoryThis();

	// allocate exactly enough memory for the versioned name on the stack.
	char proxyVersionedName[512];
	Q_snprintf( proxyVersionedName, sizeof( proxyVersionedName ), "%s%s", proxyName, IMATERIAL_PROXY_INTERFACE_VERSION );
	return ( IMaterialProxy * )clientFactory( proxyVersionedName, NULL );
}
//-----------------------------------------------------------------------------
// Purpose: Sets up the networking
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CTrackerNET::Initialize(unsigned short portMin, unsigned short portMax)
{
	// initialize threading
	CreateInterfaceFn factory = Sys_GetFactoryThis();
	m_pThreads = (IThreads *)factory(THREADS_INTERFACE_VERSION, NULL);

	// initialize socket layer
	m_pThreadedSocket = (IThreadedSocket *)factory(THREADEDSOCKET_INTERFACE_VERSION, NULL);
	m_pSockets = m_pThreadedSocket->GetSocket();
	if (!m_pSockets->InitializeSockets(portMin, portMax))
		return false;

	return true;
}
Example #5
0
bool FileSystem_Init_Normal( const char *pFilename, FSInitType_t initType, bool bOnlyUseDirectoryName )
{
	if ( initType == FS_INIT_FULL )
	{
		// First, get the name of the module
		char fileSystemDLLName[MAX_PATH];
		bool bSteam;
		if ( FileSystem_GetFileSystemDLLName( fileSystemDLLName, MAX_PATH, bSteam ) != FS_OK )
			return false;

		// If we're under Steam we need extra setup to let us find the proper modules
		FileSystem_SetupSteamInstallPath();

		// Next, load the module, call Connect/Init.
		CFSLoadModuleInfo loadModuleInfo;
		loadModuleInfo.m_pFileSystemDLLName = fileSystemDLLName;
		loadModuleInfo.m_pDirectoryName = pFilename;
		loadModuleInfo.m_bOnlyUseDirectoryName = bOnlyUseDirectoryName;
		loadModuleInfo.m_ConnectFactory = Sys_GetFactoryThis();
		loadModuleInfo.m_bSteam = bSteam;
		loadModuleInfo.m_bToolsMode = true;
		if ( FileSystem_LoadFileSystemModule( loadModuleInfo ) != FS_OK )
			return false;

		// Next, mount the content
		CFSMountContentInfo mountContentInfo;
		mountContentInfo.m_pDirectoryName=  loadModuleInfo.m_GameInfoPath;
		mountContentInfo.m_pFileSystem = loadModuleInfo.m_pFileSystem;
		mountContentInfo.m_bToolsMode = true;
		if ( FileSystem_MountContent( mountContentInfo ) != FS_OK )
			return false;
		
		// Finally, load the search paths.
		CFSSearchPathsInit searchPathsInit;
		searchPathsInit.m_pDirectoryName = loadModuleInfo.m_GameInfoPath;
		searchPathsInit.m_pFileSystem = loadModuleInfo.m_pFileSystem;
		if ( FileSystem_LoadSearchPaths( searchPathsInit ) != FS_OK )
			return false;

		// Store the data we got from filesystem_init.
		g_pFileSystem = g_pFullFileSystem = loadModuleInfo.m_pFileSystem;
		g_pFullFileSystemModule = loadModuleInfo.m_pModule;

		FileSystem_AddSearchPath_Platform( g_pFullFileSystem, loadModuleInfo.m_GameInfoPath );

		// Set qdir.
		if ( !pFilename )
			pFilename = ".";

		Q_MakeAbsolutePath( qdir, sizeof( qdir ), pFilename, NULL );
		Q_StripFilename( qdir );
		strlwr( qdir );
		if ( qdir[0] != 0 )
			Q_AppendSlash( qdir, sizeof( qdir ) );

		// Set gamedir.
		Q_MakeAbsolutePath( gamedir, sizeof( gamedir ), loadModuleInfo.m_GameInfoPath );
		Q_AppendSlash( gamedir, sizeof( gamedir ) );
	}
	else
	{
		if ( !Sys_LoadInterface(
			"filesystem_stdio",
			FILESYSTEM_INTERFACE_VERSION,
			&g_pFullFileSystemModule,
			(void**)&g_pFullFileSystem ) )
		{
			return false;
		}

		if ( g_pFullFileSystem->Init() != INIT_OK )
			return false;

		g_pFullFileSystem->RemoveAllSearchPaths();
		g_pFullFileSystem->AddSearchPath( "../platform", "PLATFORM" );
		g_pFullFileSystem->AddSearchPath( ".", "GAME" );

		g_pFileSystem = g_pFullFileSystem;
	}

	return true;
}
void CGameUI::Initialize( CreateInterfaceFn *factories, int count )
{
//	TRACE_FUNCTION("CGameUI::Initialize");

/*	CreateInterfaceFn fileSystemFactory = factories[ 2 ];
	CreateInterfaceFn vguiFactory = factories[ 1 ];
	CreateInterfaceFn engineFactory = factories[ 0 ];
	CreateInterfaceFn clientFactory = factories[ 4 ];

	m_FactoryList[ 0 ] = Sys_GetFactoryThis();
	m_FactoryList[ 1 ] = engineFactory;
	m_FactoryList[ 2 ] = vguiFactory;
	m_FactoryList[ 3 ] = fileSystemFactory;
	m_FactoryList[ 4 ] = clientFactory;
	m_iNumFactories = count;

	vgui::VGui_InitInterfacesList("GameUI", m_FactoryList, count); // client factory may not be passed in
*/
	CreateInterfaceFn factory = factories[ 0 ];
	CreateInterfaceFn fileSystemFactory = factories[ 0 ];
	CreateInterfaceFn vguiFactory = factories[ 0 ];
	CreateInterfaceFn engineFactory = factories[ 0 ];
	CreateInterfaceFn clientFactory = factories[ 0 ];


	enginesound = (IEngineSound *)factory(IENGINESOUND_CLIENT_INTERFACE_VERSION, NULL);
	cvar		= (ICvar *)factory( VENGINE_CVAR_INTERFACE_VERSION, NULL );
	engine		= (IVEngineClient *)factory( VENGINE_CLIENT_INTERFACE_VERSION, NULL );

	m_FactoryList[ 0 ] = Sys_GetFactoryThis();
	m_FactoryList[ 1 ] = factory;
	m_iNumFactories = count;

	vgui::VGui_InitInterfacesList( "GameUI", m_FactoryList, 2 );

		// load localization file
	vgui::localize()->AddFile(vgui::filesystem(), "Resource/gameui_%language%.txt");

	// load localization file for kb_act.lst
	vgui::localize()->AddFile(vgui::filesystem(), "Resource/valve_%language%.txt");

	// setup base panel
	staticPanel = new CBasePanel();
	staticPanel->SetBounds(0, 0, 400, 300);
	staticPanel->SetPaintBorderEnabled(false);
	staticPanel->SetPaintBackgroundEnabled(true);
	staticPanel->SetPaintEnabled(false);
	staticPanel->SetVisible( true );
	staticPanel->SetMouseInputEnabled( false );
	staticPanel->SetKeyBoardInputEnabled( false );

	enginevguifuncs = (IEngineVGui * )engineFactory( VENGINE_VGUI_VERSION, NULL);
	if(enginevguifuncs)
	{
		vgui::VPANEL rootpanel = enginevguifuncs->GetPanel(PANEL_GAMEUIDLL);
		staticPanel->SetParent(rootpanel);
	}

	gameuifuncs = (IGameUIFuncs * )engineFactory( VENGINE_GAMEUIFUNCS_VERSION, NULL );
	enginesurfacefuncs = (vgui::ISurface * )engineFactory(VGUI_SURFACE_INTERFACE_VERSION,NULL);
	baseuifuncs = (IBaseUI *)engineFactory( BASEUI_INTERFACE_VERSION, NULL);
	if (clientFactory)
	{
		g_pGameClientExports = (IGameClientExports *)clientFactory(GAMECLIENTEXPORTS_INTERFACE_VERSION, NULL);
	}
}
Example #7
0
//-----------------------------------------------------------------------------
// 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);

}
CreateInterfaceFn VMPI_FileSystem_GetFactory()
{
	return Sys_GetFactoryThis();
}
Example #9
0
void EXPORT F(IEngineAPI **api)
{
	CreateInterfaceFn fn;
	fn = Sys_GetFactoryThis();
	*api = (IEngineAPI *)fn(VENGINE_LAUNCHER_API_VERSION, NULL);
}
bool FileSystem_Init_Normal( const char *pFilename, FSInitType_t initType, bool bOnlyUseDirectoryName )
{
	if ( initType == FS_INIT_FULL )
	{
		// First, get the name of the module
		char fileSystemDLLName[MAX_PATH];
		bool bSteam;
		if ( FileSystem_GetFileSystemDLLName( fileSystemDLLName, MAX_PATH, bSteam ) != FS_OK )
			return false;

		// Next, load the module, call Connect/Init.
		CFSLoadModuleInfo loadModuleInfo;
		loadModuleInfo.m_pFileSystemDLLName = fileSystemDLLName;
		loadModuleInfo.m_pDirectoryName = pFilename;
		loadModuleInfo.m_bOnlyUseDirectoryName = bOnlyUseDirectoryName;
		loadModuleInfo.m_ConnectFactory = Sys_GetFactoryThis();
		loadModuleInfo.m_bSteam = bSteam;
		loadModuleInfo.m_bToolsMode = true;
		if ( FileSystem_LoadFileSystemModule( loadModuleInfo ) != FS_OK )
			return false;

		// Next, mount the content
		CFSMountContentInfo mountContentInfo;
		mountContentInfo.m_pDirectoryName=  loadModuleInfo.m_GameInfoPath;
		mountContentInfo.m_pFileSystem = loadModuleInfo.m_pFileSystem;
		mountContentInfo.m_bToolsMode = true;
		if ( FileSystem_MountContent( mountContentInfo ) != FS_OK )
			return false;
		
		// Finally, load the search paths.
		CFSSearchPathsInit searchPathsInit;
		searchPathsInit.m_pDirectoryName = loadModuleInfo.m_GameInfoPath;
		searchPathsInit.m_pFileSystem = loadModuleInfo.m_pFileSystem;
		if ( FileSystem_LoadSearchPaths( searchPathsInit ) != FS_OK )
			return false;

		// Store the data we got from filesystem_init.
		g_pFileSystem = g_pFullFileSystem = loadModuleInfo.m_pFileSystem;
		g_pFullFileSystemModule = loadModuleInfo.m_pModule;

		FileSystem_AddSearchPath_Platform( g_pFullFileSystem, loadModuleInfo.m_GameInfoPath );

		FileSystem_SetupStandardDirectories( pFilename, loadModuleInfo.m_GameInfoPath );
	}
	else
	{
		if ( !Sys_LoadInterface(
			"filesystem_stdio",
			FILESYSTEM_INTERFACE_VERSION,
			&g_pFullFileSystemModule,
			(void**)&g_pFullFileSystem ) )
		{
			return false;
		}

		if ( g_pFullFileSystem->Init() != INIT_OK )
			return false;

		g_pFullFileSystem->RemoveAllSearchPaths();
		g_pFullFileSystem->AddSearchPath( "../platform", "PLATFORM" );
		g_pFullFileSystem->AddSearchPath( ".", "GAME" );

		g_pFileSystem = g_pFullFileSystem;
	}

	return true;
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	HANDLE hObject = NULL;
	BOOL (*IsDebuggerPresent)(void) = (BOOL (*)(void))GetProcAddress(GetModuleHandle("kernel32.dll"), "IsDebuggerPresent");

	if (!IsDebuggerPresent())
	{
		hObject = CreateMutex(NULL, FALSE, "ValveHalfLifeLauncherMutex");

		DWORD dwStatus = WaitForSingleObject(hObject, 0);

		if (dwStatus && dwStatus != WAIT_ABANDONED)
		{
			MessageBox(NULL, "Could not launch game.\nOnly one instance of this game can be run at a time.", "Error", MB_ICONERROR);
			return 0;
		}
	}

	WSAData WSAData;
	WSAStartup(2, &WSAData);

	registry->Init();
	CommandLine()->CreateCmdLine(GetCommandLine());
	CommandLine()->AppendParm("-nomaster", NULL);

	char szFileName[256];
	Sys_GetExecutableName(szFileName, sizeof(szFileName));
	char *szExeName = strrchr(szFileName, '\\') + 1;

	if (stricmp(szExeName, "hl.exe") && CommandLine()->CheckParm("-game") == NULL)
	{
		szExeName[strlen(szExeName) - 4] = '\0';
		CommandLine()->AppendParm("-game", szExeName);
	}

	const char *_szGameName;
	static char szGameName[32];
	const char *szGameStr = CommandLine()->CheckParm("-game", &_szGameName);
	strcpy(szGameName, _szGameName);

	if (szGameStr && !strnicmp(&szGameStr[6], "czero", 5))
		CommandLine()->AppendParm("-forcevalve", NULL);

	if (registry->ReadInt("CrashInitializingVideoMode", FALSE))
	{
		registry->WriteInt("CrashInitializingVideoMode", FALSE);

		if (strcmp(registry->ReadString("EngineDLL", "hw.dll"), "hw.dll"))
		{
			if (registry->ReadInt("EngineD3D", FALSE))
			{
				registry->WriteInt("EngineD3D", FALSE);

				if (MessageBox(NULL, "The game has detected that the previous attempt to start in D3D video mode failed.\nThe game will now run attempt to run in openGL mode.", "Video mode change failure", MB_OKCANCEL | MB_ICONWARNING) != IDOK)
					return 0;
			}
			else
			{
				registry->WriteString("EngineDLL", "sw.dll");

				if (MessageBox(NULL, "The game has detected that the previous attempt to start in openGL video mode failed.\nThe game will now run in software mode.", "Video mode change failure", MB_OKCANCEL | MB_ICONWARNING) != IDOK)
					return 0;
			}

			registry->WriteInt("ScreenWidth", 640);
			registry->WriteInt("ScreenHeight", 480);
			registry->WriteInt("ScreenBPP", 16);
		}
	}

	while (1)
	{
		HINTERFACEMODULE hFileSystem = LoadFilesystemModule();

		if (!hFileSystem)
			break;

		MH_Init(szGameName);

		CreateInterfaceFn fsCreateInterface = (CreateInterfaceFn)Sys_GetFactory(hFileSystem);
		g_pFileSystem = (IFileSystem *)fsCreateInterface(FILESYSTEM_INTERFACE_VERSION, NULL);
		g_pFileSystem->Mount();
		g_pFileSystem->AddSearchPath(Sys_GetLongPathName(), "ROOT");

		static char szNewCommandParams[2048];
		const char *pszEngineDLL;
		int iResult = ENGINE_RESULT_NONE;

		szNewCommandParams[0] = 0;
		SetEngineDLL(pszEngineDLL);

		g_blobfootprintClient.m_hDll = NULL;

		IEngine *engineAPI = NULL;
		HINTERFACEMODULE hEngine;
		bool bUseBlobDLL = false;

		if (FIsBlob(pszEngineDLL))
		{
			Sys_CloseDEP();
			SetupExceptHandler3();
			NLoadBlobFile(pszEngineDLL, &g_blobfootprintClient, (void **)&engineAPI);
			bUseBlobDLL = true;
		}
		else
		{
			hEngine = Sys_LoadModule(pszEngineDLL);

			if (!hEngine)
			{
				static char msg[512];
				wsprintf(msg, "Could not load %s.\nPlease try again at a later time.", pszEngineDLL);
				MessageBox(NULL, msg, "Fatal Error", MB_ICONERROR);
				break;
			}

			CreateInterfaceFn engineCreateInterface = (CreateInterfaceFn)Sys_GetFactory(hEngine);
			engineAPI = (IEngine *)engineCreateInterface(VENGINE_LAUNCHER_API_VERSION, NULL);

			if (!engineCreateInterface || !engineAPI)
				Sys_FreeModule(hEngine);
		}

		if (engineAPI)
		{
			MH_LoadEngine(bUseBlobDLL ? NULL : (HMODULE)hEngine);
			iResult = engineAPI->Run(hInstance, Sys_GetLongPathName(), CommandLine()->GetCmdLine(), szNewCommandParams, Sys_GetFactoryThis(), Sys_GetFactory(hFileSystem));
			MH_ExitGame(iResult);

			if (bUseBlobDLL)
				FreeBlob(&g_blobfootprintClient);
			else
				Sys_FreeModule(hEngine);
		}

		if (iResult == ENGINE_RESULT_NONE || iResult > ENGINE_RESULT_UNSUPPORTEDVIDEO)
			break;

		bool bContinue;

		switch (iResult)
		{
			case ENGINE_RESULT_RESTART:
			{
				bContinue = true;
				break;
			}

			case ENGINE_RESULT_UNSUPPORTEDVIDEO:
			{
				bContinue = OnVideoModeFailed();
				break;
			}
		}

		CommandLine()->RemoveParm("-sw");
		CommandLine()->RemoveParm("-startwindowed");
		CommandLine()->RemoveParm("-windowed");
		CommandLine()->RemoveParm("-window");
		CommandLine()->RemoveParm("-full");
		CommandLine()->RemoveParm("-fullscreen");
		CommandLine()->RemoveParm("-soft");
		CommandLine()->RemoveParm("-software");
		CommandLine()->RemoveParm("-gl");
		CommandLine()->RemoveParm("-d3d");
		CommandLine()->RemoveParm("-w");
		CommandLine()->RemoveParm("-width");
		CommandLine()->RemoveParm("-h");
		CommandLine()->RemoveParm("-height");
		CommandLine()->RemoveParm("-novid");

		if (strstr(szNewCommandParams, "-game"))
			CommandLine()->RemoveParm("-game");

		if (strstr(szNewCommandParams, "+load"))
			CommandLine()->RemoveParm("+load");

		CommandLine()->AppendParm(szNewCommandParams, NULL);

		g_pFileSystem->Unmount();
		Sys_FreeModule(hFileSystem);
		MH_Shutdown();

		if (!bContinue)
			break;
	}

	registry->Shutdown();

	if (hObject)
	{
		ReleaseMutex(hObject);
		CloseHandle(hObject);
	}

	WSACleanup();
	MH_Shutdown();
	TerminateProcess(GetCurrentProcess(), 1);
	return 1;
}
Example #12
0
//-----------------------------------------------------------------------------
// Query interface
//-----------------------------------------------------------------------------
void *CEngineAPI::QueryInterface( const char *pInterfaceName )
{
	// Loading the engine DLL mounts *all* engine interfaces
	CreateInterfaceFn factory = Sys_GetFactoryThis();	// This silly construction is necessary
	return factory( pInterfaceName, NULL );				// to prevent the LTCG compiler from crashing.
}
Example #13
0
//-----------------------------------------------------------------------------
// Purpose: exports an interface that can be used by the launcher to run the engine
//			this is the exported function when compiled as a blob
//-----------------------------------------------------------------------------
void EXPORT F( IEngineAPI **api )
{
	CreateInterfaceFn factory = Sys_GetFactoryThis();	// This silly construction is necessary to prevent the LTCG compiler from crashing.
	*api = ( IEngineAPI * )(factory(VENGINE_LAUNCHER_API_VERSION, NULL));
}
Example #14
0
//-----------------------------------------------------------------------------
// Query interface
//-----------------------------------------------------------------------------
void *CWarsExtension::QueryInterface( const char *pInterfaceName )
{
	CreateInterfaceFn factory = Sys_GetFactoryThis();	// This silly construction is necessary
	return factory( pInterfaceName, NULL );				// to prevent the LTCG compiler from crashing.
}
Example #15
0
//-----------------------------------------------------------------------------
// Query interface
//-----------------------------------------------------------------------------
void *CMdlLib::QueryInterface( const char *pInterfaceName )
{
	return Sys_GetFactoryThis()( pInterfaceName, NULL );
}