Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
7.1 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Launcher for hammer, which is sitting in its own DLL
  4. //
  5. //===========================================================================//
  6. #include <windows.h>
  7. #include <eh.h>
  8. #include "appframework/AppFramework.h"
  9. #include "ihammer.h"
  10. #include "tier0/dbg.h"
  11. #include "vstdlib/cvar.h"
  12. #include "filesystem.h"
  13. #include "materialsystem/imaterialsystem.h"
  14. #include "istudiorender.h"
  15. #include "filesystem_init.h"
  16. #include "datacache/idatacache.h"
  17. #include "datacache/imdlcache.h"
  18. #include "vphysics_interface.h"
  19. #include "vgui/ivgui.h"
  20. #include "vgui/isurface.h"
  21. #include "inputsystem/iinputsystem.h"
  22. #include "tier0/icommandline.h"
  23. #include "SteamWriteMinidump.h"
  24. #include "p4lib/ip4.h"
  25. //-----------------------------------------------------------------------------
  26. // Global systems
  27. //-----------------------------------------------------------------------------
  28. IHammer *g_pHammer;
  29. IFileSystem *g_pFileSystem;
  30. extern "C" void WriteMiniDumpUsingExceptionInfo
  31. (
  32. unsigned int uStructuredExceptionCode,
  33. struct _EXCEPTION_POINTERS * pExceptionInfo
  34. )
  35. {
  36. // TODO: dynamically set the minidump comment from contextual info about the crash (i.e current VPROF node)?
  37. SteamWriteMiniDumpUsingExceptionInfoWithBuildId( uStructuredExceptionCode, pExceptionInfo, 0 );
  38. }
  39. //-----------------------------------------------------------------------------
  40. // The application object
  41. //-----------------------------------------------------------------------------
  42. class CHammerApp : public CAppSystemGroup
  43. {
  44. public:
  45. // Methods of IApplication
  46. virtual bool Create( );
  47. virtual bool PreInit( );
  48. virtual int Main( );
  49. virtual void PostShutdown();
  50. virtual void Destroy();
  51. private:
  52. int MainLoop();
  53. };
  54. //-----------------------------------------------------------------------------
  55. // Define the application object
  56. //-----------------------------------------------------------------------------
  57. CHammerApp g_ApplicationObject;
  58. DEFINE_WINDOWED_APPLICATION_OBJECT_GLOBALVAR( g_ApplicationObject );
  59. static CSimpleWindowsLoggingListener s_SimpleWindowsLoggingListener;
  60. //-----------------------------------------------------------------------------
  61. // Create all singleton systems
  62. //-----------------------------------------------------------------------------
  63. bool CHammerApp::Create()
  64. {
  65. LoggingSystem_PushLoggingState();
  66. LoggingSystem_RegisterLoggingListener( &s_SimpleWindowsLoggingListener );
  67. // Save some memory so engine/hammer isn't so painful
  68. CommandLine()->AppendParm( "-disallowhwmorph", NULL );
  69. IAppSystem *pSystem;
  70. // Add in the cvar factory
  71. AppModule_t cvarModule = LoadModule( VStdLib_GetICVarFactory() );
  72. pSystem = AddSystem( cvarModule, CVAR_INTERFACE_VERSION );
  73. if ( !pSystem )
  74. return false;
  75. bool bSteam;
  76. char pFileSystemDLL[MAX_PATH];
  77. if ( FileSystem_GetFileSystemDLLName( pFileSystemDLL, MAX_PATH, bSteam ) != FS_OK )
  78. return false;
  79. FileSystem_SetupSteamInstallPath();
  80. AppModule_t fileSystemModule = LoadModule( pFileSystemDLL );
  81. g_pFileSystem = (IFileSystem*)AddSystem( fileSystemModule, FILESYSTEM_INTERFACE_VERSION );
  82. AppSystemInfo_t appSystems[] =
  83. {
  84. { "materialsystem.dll", MATERIAL_SYSTEM_INTERFACE_VERSION },
  85. { "inputsystem.dll", INPUTSYSTEM_INTERFACE_VERSION },
  86. { "studiorender.dll", STUDIO_RENDER_INTERFACE_VERSION },
  87. { "vphysics.dll", VPHYSICS_INTERFACE_VERSION },
  88. { "datacache.dll", DATACACHE_INTERFACE_VERSION },
  89. { "datacache.dll", MDLCACHE_INTERFACE_VERSION },
  90. { "datacache.dll", STUDIO_DATA_CACHE_INTERFACE_VERSION },
  91. { "vguimatsurface.dll", VGUI_SURFACE_INTERFACE_VERSION },
  92. { "vgui2.dll", VGUI_IVGUI_INTERFACE_VERSION },
  93. { "p4lib.dll", P4_INTERFACE_VERSION },
  94. { "hammer_dll.dll", INTERFACEVERSION_HAMMER },
  95. { "", "" } // Required to terminate the list
  96. };
  97. AppSystemInfo_t appSystemsNoP4[] =
  98. {
  99. { "materialsystem.dll", MATERIAL_SYSTEM_INTERFACE_VERSION },
  100. { "inputsystem.dll", INPUTSYSTEM_INTERFACE_VERSION },
  101. { "studiorender.dll", STUDIO_RENDER_INTERFACE_VERSION },
  102. { "vphysics.dll", VPHYSICS_INTERFACE_VERSION },
  103. { "datacache.dll", DATACACHE_INTERFACE_VERSION },
  104. { "datacache.dll", MDLCACHE_INTERFACE_VERSION },
  105. { "datacache.dll", STUDIO_DATA_CACHE_INTERFACE_VERSION },
  106. { "vguimatsurface.dll", VGUI_SURFACE_INTERFACE_VERSION },
  107. { "vgui2.dll", VGUI_IVGUI_INTERFACE_VERSION },
  108. { "hammer_dll.dll", INTERFACEVERSION_HAMMER },
  109. { "", "" } // Required to terminate the list
  110. };
  111. if ( !AddSystems( CommandLine()->FindParm( "-nop4" ) ? appSystemsNoP4 : appSystems ) )
  112. return false;
  113. // Connect to interfaces loaded in AddSystems that we need locally
  114. g_pMaterialSystem = (IMaterialSystem*)FindSystem( MATERIAL_SYSTEM_INTERFACE_VERSION );
  115. g_pHammer = (IHammer*)FindSystem( INTERFACEVERSION_HAMMER );
  116. g_pDataCache = (IDataCache*)FindSystem( DATACACHE_INTERFACE_VERSION );
  117. g_pInputSystem = (IInputSystem*)FindSystem( INPUTSYSTEM_INTERFACE_VERSION );
  118. p4 = ( IP4 * )FindSystem( P4_INTERFACE_VERSION );
  119. // This has to be done before connection.
  120. g_pMaterialSystem->SetShaderAPI( "shaderapidx9.dll" );
  121. return true;
  122. }
  123. void CHammerApp::Destroy()
  124. {
  125. LoggingSystem_PopLoggingState();
  126. g_pFileSystem = NULL;
  127. g_pMaterialSystem = NULL;
  128. g_pDataCache = NULL;
  129. g_pHammer = NULL;
  130. g_pInputSystem = NULL;
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Init, shutdown
  134. //-----------------------------------------------------------------------------
  135. bool CHammerApp::PreInit( )
  136. {
  137. if ( !g_pHammer->InitSessionGameConfig( GetVProjectCmdLineValue() ) )
  138. return false;
  139. bool bDone = false;
  140. do
  141. {
  142. CFSSteamSetupInfo steamInfo;
  143. steamInfo.m_pDirectoryName = g_pHammer->GetDefaultModFullPath();
  144. steamInfo.m_bOnlyUseDirectoryName = true;
  145. steamInfo.m_bToolsMode = true;
  146. steamInfo.m_bSetSteamDLLPath = true;
  147. steamInfo.m_bSteam = g_pFileSystem->IsSteam();
  148. if ( FileSystem_SetupSteamEnvironment( steamInfo ) != FS_OK )
  149. {
  150. MessageBox( NULL, "Failed to setup steam environment.", "Error", MB_OK );
  151. return false;
  152. }
  153. CFSMountContentInfo fsInfo;
  154. fsInfo.m_pFileSystem = g_pFileSystem;
  155. fsInfo.m_bToolsMode = true;
  156. fsInfo.m_pDirectoryName = steamInfo.m_GameInfoPath;
  157. if ( !fsInfo.m_pDirectoryName )
  158. {
  159. Error( "FileSystem_LoadFileSystemModule: no -defaultgamedir or -game specified." );
  160. }
  161. if ( FileSystem_MountContent( fsInfo ) == FS_OK )
  162. {
  163. bDone = true;
  164. }
  165. else
  166. {
  167. char str[512];
  168. Q_snprintf( str, sizeof( str ), "%s", FileSystem_GetLastErrorString() );
  169. MessageBox( NULL, str, "Warning", MB_OK );
  170. if ( g_pHammer->RequestNewConfig() == REQUEST_QUIT )
  171. return false;
  172. }
  173. FileSystem_AddSearchPath_Platform( fsInfo.m_pFileSystem, steamInfo.m_GameInfoPath );
  174. } while (!bDone);
  175. // Required to run through the editor
  176. g_pMaterialSystem->EnableEditorMaterials();
  177. // needed for VGUI model rendering
  178. g_pMaterialSystem->SetAdapter( 0, MATERIAL_INIT_ALLOCATE_FULLSCREEN_TEXTURE );
  179. return true;
  180. }
  181. void CHammerApp::PostShutdown()
  182. {
  183. }
  184. //-----------------------------------------------------------------------------
  185. // main application
  186. //-----------------------------------------------------------------------------
  187. int CHammerApp::Main( )
  188. {
  189. return g_pHammer->MainLoop();
  190. }