Team Fortress 2 Source Code as on 22/4/2020
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.

138 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "replay_internal.h"
  5. #include "replay/ireplaysystem.h"
  6. #include "replayserver.h"
  7. #include "vgui/ILocalize.h"
  8. #include "server.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. //----------------------------------------------------------------------------------------
  12. IReplaySystem *g_pReplay = NULL;
  13. //----------------------------------------------------------------------------------------
  14. static CSysModule *gs_hReplayModule = NULL;
  15. IServerReplayContext *g_pServerReplayContext = NULL;
  16. CreateInterfaceFn g_fnReplayFactory = NULL;
  17. #if !defined( DEDICATED )
  18. IReplayManager *g_pReplayManager = NULL;
  19. IReplayMovieRenderer *g_pReplayMovieRenderer = NULL;
  20. IReplayPerformanceManager *g_pReplayPerformanceManager = NULL;
  21. IReplayPerformanceController *g_pReplayPerformanceController = NULL;
  22. IReplayMovieManager *g_pReplayMovieManager = NULL;
  23. #endif
  24. //----------------------------------------------------------------------------------------
  25. ConVar replay_debug( "replay_debug", "0", FCVAR_DONTRECORD );
  26. //----------------------------------------------------------------------------------------
  27. // If you modify this list, you will also need to add the following line to the game's
  28. // client_*.vpc and server_*.vpc files:
  29. //
  30. // $include "$SRCDIR\vpc_scripts\source_replay.vpc"
  31. //
  32. static const char *s_pSupportedReplayGames[] =
  33. {
  34. "tf",
  35. "tf_beta",
  36. };
  37. //----------------------------------------------------------------------------------------
  38. void ReplaySystem_Init( bool bDedicated )
  39. {
  40. #if defined( REPLAY_ENABLED )
  41. COM_TimestampedLog( "Loading replay.dll" );
  42. extern IFileSystem *g_pFileSystem;
  43. // Load the replay DLL
  44. const char *szDllName = "replay" DLL_EXT_STRING;
  45. gs_hReplayModule = g_pFileSystem->LoadModule( szDllName );
  46. g_fnReplayFactory = Sys_GetFactory( gs_hReplayModule );
  47. if ( !g_fnReplayFactory )
  48. {
  49. Error( "Could not load: %s\n", szDllName );
  50. }
  51. // Get a ptr to the IReplay instance
  52. g_pReplay = (IReplaySystem *)g_fnReplayFactory( REPLAY_INTERFACE_VERSION, NULL );
  53. if ( !g_pReplay )
  54. {
  55. Error( "Could not get IReplay interface %s from %s\n", REPLAY_INTERFACE_VERSION, szDllName );
  56. }
  57. // Initialize the replay DLL
  58. COM_TimestampedLog( "g_pReplay->Initialize()" );
  59. extern CreateInterfaceFn g_AppSystemFactory;
  60. if ( !g_pReplay->Connect( g_AppSystemFactory ) )
  61. {
  62. Error( "Connect on replay.dll failed!\n" );
  63. }
  64. // Cache some pointers
  65. g_pServerReplayContext = g_pReplay->SV_GetContext();
  66. if ( !bDedicated )
  67. {
  68. // Add replay localization text files
  69. extern vgui::ILocalize *g_pVGuiLocalize;
  70. if ( g_pVGuiLocalize )
  71. {
  72. g_pVGuiLocalize->AddFile( "resource/replay_%language%.txt", "GAME" );
  73. g_pVGuiLocalize->AddFile( "resource/youtube_%language%.txt", "GAME" );
  74. }
  75. }
  76. #endif
  77. }
  78. //----------------------------------------------------------------------------------------
  79. void ReplaySystem_Shutdown()
  80. {
  81. #if defined( REPLAY_ENABLED )
  82. if ( g_pReplay )
  83. {
  84. // Shutdown the DLL
  85. g_pReplay->Shutdown();
  86. g_pReplay = NULL;
  87. }
  88. if ( gs_hReplayModule )
  89. {
  90. // Unload the DLL
  91. Sys_UnloadModule( gs_hReplayModule );
  92. gs_hReplayModule = NULL;
  93. }
  94. #endif
  95. }
  96. //----------------------------------------------------------------------------------------
  97. bool Replay_IsSupportedModAndPlatform()
  98. {
  99. if ( !IsPC() )
  100. return false;
  101. int nNumSupportedReplayGames = ARRAYSIZE( s_pSupportedReplayGames );
  102. for ( int i = 0; i < nNumSupportedReplayGames; ++i )
  103. {
  104. const char *pCurGame = s_pSupportedReplayGames[ i ];
  105. if ( !Q_stricmp( COM_GetModDirectory(), pCurGame ) )
  106. return true;
  107. }
  108. return false;
  109. }
  110. //----------------------------------------------------------------------------------------