This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/game_launch/game.cpp

64 lines
1.9 KiB
C++
Raw Normal View History

2010-07-29 22:00:00 +02:00
//=======================================================================
2011-03-22 22:00:00 +01:00
// Copyright XashXT Group 2011 <20>
2010-07-29 22:00:00 +02:00
// game.cpp -- executable to run Xash Engine
//=======================================================================
#include <windows.h>
2011-03-12 22:00:00 +01:00
#define GAME_PATH "valve" // default dir to start from
2010-07-29 22:00:00 +02:00
2011-03-12 22:00:00 +01:00
typedef void (*pfnChangeGame)( const char *progname );
typedef int (*pfnInit)( const char *progname, int bChangeGame, pfnChangeGame func );
typedef void (*pfnShutdown)( void );
2010-07-29 22:00:00 +02:00
2011-03-12 22:00:00 +01:00
pfnInit Host_Main;
2011-03-21 22:00:00 +01:00
pfnShutdown Host_Shutdown = NULL;
2011-03-12 22:00:00 +01:00
char szGameDir[128]; // safe place to keep gamedir
HINSTANCE hEngine;
2010-07-29 22:00:00 +02:00
void Sys_Error( const char *errorstring )
{
MessageBox( NULL, errorstring, "Xash Error", MB_OK|MB_SETFOREGROUND|MB_ICONSTOP );
exit( 1 );
}
2011-03-12 22:00:00 +01:00
void Sys_LoadEngine( void )
2010-07-29 22:00:00 +02:00
{
2011-03-12 22:00:00 +01:00
if(( hEngine = LoadLibrary( "xash.dll" )) == NULL )
{
Sys_Error( "Unable to load the xash.dll" );
}
2010-07-29 22:00:00 +02:00
2011-03-12 22:00:00 +01:00
if(( Host_Main = (pfnInit)GetProcAddress( hEngine, "Host_Main" )) == NULL )
2010-07-29 22:00:00 +02:00
{
2011-03-12 22:00:00 +01:00
Sys_Error( "xash.dll missed 'Host_Main' export" );
2010-07-29 22:00:00 +02:00
}
2011-03-12 22:00:00 +01:00
// this is non-fatal for us but change game will not working
Host_Shutdown = (pfnShutdown)GetProcAddress( hEngine, "Host_Shutdown" );
}
2010-07-29 22:00:00 +02:00
2011-03-12 22:00:00 +01:00
void Sys_UnloadEngine( void )
{
if( Host_Shutdown ) Host_Shutdown( );
if( hEngine ) FreeLibrary( hEngine );
}
void Sys_ChangeGame( const char *progname )
{
if( !progname || !progname[0] ) Sys_Error( "Sys_ChangeGame: NULL gamedir" );
if( Host_Shutdown == NULL ) Sys_Error( "Sys_ChangeGame: missed 'Host_Shutdown' export\n" );
strncpy( szGameDir, progname, sizeof( szGameDir ) - 1 );
Sys_UnloadEngine ();
Sys_LoadEngine ();
Host_Main( szGameDir, TRUE, ( Host_Shutdown != NULL ) ? Sys_ChangeGame : NULL );
}
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
Sys_LoadEngine();
2010-07-29 22:00:00 +02:00
2011-03-12 22:00:00 +01:00
return Host_Main( GAME_PATH, FALSE, ( Host_Shutdown != NULL ) ? Sys_ChangeGame : NULL );
2010-07-29 22:00:00 +02:00
}