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.

140 lines
4.0 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "stdafx.h"
  7. #include "scriplib.h"
  8. #include "choreoscene.h"
  9. #include "iscenetokenprocessor.h"
  10. #include "filesystem_tools.h"
  11. //-----------------------------------------------------------------------------
  12. // Purpose: Helper to scene module for parsing the .vcd file
  13. //-----------------------------------------------------------------------------
  14. class CSceneTokenProcessor : public ISceneTokenProcessor
  15. {
  16. public:
  17. const char *CurrentToken( void );
  18. bool GetToken( bool crossline );
  19. bool TokenAvailable( void );
  20. void Error( const char *fmt, ... );
  21. };
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. // Output : const
  25. //-----------------------------------------------------------------------------
  26. const char *CSceneTokenProcessor::CurrentToken( void )
  27. {
  28. return token;
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose:
  32. // Input : crossline -
  33. // Output : Returns true on success, false on failure.
  34. //-----------------------------------------------------------------------------
  35. bool CSceneTokenProcessor::GetToken( bool crossline )
  36. {
  37. return ::GetToken( crossline ) ? true : false;
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. // Output : Returns true on success, false on failure.
  42. //-----------------------------------------------------------------------------
  43. bool CSceneTokenProcessor::TokenAvailable( void )
  44. {
  45. return ::TokenAvailable() ? true : false;
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. // Input : *fmt -
  50. // ... -
  51. //-----------------------------------------------------------------------------
  52. void CSceneTokenProcessor::Error( const char *fmt, ... )
  53. {
  54. char string[ 2048 ];
  55. va_list argptr;
  56. va_start( argptr, fmt );
  57. vsprintf( string, fmt, argptr );
  58. va_end( argptr );
  59. Warning( "%s", string );
  60. }
  61. static CSceneTokenProcessor g_TokenProcessor;
  62. //-----------------------------------------------------------------------------
  63. // Purpose: Normally implemented in cmdlib.cpp but we don't want that in Hammer.
  64. //-----------------------------------------------------------------------------
  65. char *ExpandPath (char *path)
  66. {
  67. static char fullpath[ 512 ];
  68. g_pFullFileSystem->RelativePathToFullPath( path, "GAME", fullpath, sizeof( fullpath ) );
  69. return fullpath;
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose: Normally implemented in cmdlib.cpp but we don't want that in Hammer.
  73. //-----------------------------------------------------------------------------
  74. int LoadFile( const char *filename, void **bufferptr )
  75. {
  76. FileHandle_t f = g_pFullFileSystem->Open( filename, "rb" );
  77. if ( FILESYSTEM_INVALID_HANDLE != f )
  78. {
  79. int length = g_pFullFileSystem->Size( f );
  80. void *buffer = malloc (length+1);
  81. ((char *)buffer)[length] = 0;
  82. g_pFullFileSystem->Read( buffer, length, f );
  83. g_pFullFileSystem->Close (f);
  84. *bufferptr = buffer;
  85. return length;
  86. }
  87. else
  88. {
  89. *bufferptr = NULL;
  90. return 0;
  91. }
  92. }
  93. CChoreoScene* HammerLoadScene( const char *pFilename )
  94. {
  95. if ( g_pFullFileSystem->FileExists( pFilename ) )
  96. {
  97. LoadScriptFile( (char*)pFilename );
  98. CChoreoScene *scene = ChoreoLoadScene( pFilename, NULL, &g_TokenProcessor, Msg );
  99. return scene;
  100. }
  101. return NULL;
  102. }
  103. bool GetFirstSoundInScene( const char *pSceneFilename, char *pSoundName, int soundNameLen )
  104. {
  105. CChoreoScene *pScene = HammerLoadScene( pSceneFilename );
  106. if ( !pScene )
  107. return false;
  108. for ( int i = 0; i < pScene->GetNumEvents(); i++ )
  109. {
  110. CChoreoEvent *e = pScene->GetEvent( i );
  111. if ( !e || e->GetType() != CChoreoEvent::SPEAK )
  112. continue;
  113. const char *pParameters = e->GetParameters();
  114. V_strncpy( pSoundName, pParameters, soundNameLen );
  115. delete pScene;
  116. return true;
  117. }
  118. delete pScene;
  119. return false;
  120. }