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.

112 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "bsplib.h"
  8. #include "ibsppack.h"
  9. #include "cmdlib.h"
  10. #include "zip_utils.h"
  11. class CBSPPack : public IBSPPack
  12. {
  13. public:
  14. void LoadBSPFile( IFileSystem *pFileSystem, char *filename );
  15. void WriteBSPFile( char *filename );
  16. void ClearPackFile( void );
  17. void AddFileToPack( const char *relativename, const char *fullpath );
  18. void AddBufferToPack( const char *relativename, void *data, int length, bool bTextMode );
  19. void SetHDRMode( bool bHDR );
  20. bool SwapBSPFile( IFileSystem *pFileSystem, const char *filename, const char *swapFilename, bool bSwapOnLoad, VTFConvertFunc_t pVTFConvertFunc, VHVFixupFunc_t pVHVFixupFunc, CompressFunc_t pCompressFunc );
  21. bool RepackBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, eRepackBSPFlags repackFlags );
  22. bool GetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, void **pPakData, int *pPakSize );
  23. bool SetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, const char *pNewFilename, void *pPakData, int pakSize );
  24. bool GetBSPDependants( IFileSystem *pFileSystem, const char *pBSPFilename, CUtlVector< CUtlString > *pList );
  25. };
  26. void CBSPPack::LoadBSPFile( IFileSystem *pFileSystem, char *filename )
  27. {
  28. MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
  29. // This is shady, but the engine is the only client here and we want the same search paths it has.
  30. g_pFileSystem = g_pFullFileSystem = pFileSystem;
  31. ::LoadBSPFile( filename );
  32. }
  33. void CBSPPack::WriteBSPFile( char *filename )
  34. {
  35. ::WriteBSPFile( filename );
  36. }
  37. void CBSPPack::ClearPackFile( void )
  38. {
  39. ::ClearPakFile( GetPakFile() );
  40. }
  41. void CBSPPack::AddFileToPack( const char *relativename, const char *fullpath )
  42. {
  43. // Compressing at this point would work, but the usual usage is creating a BSP and using RepackBSP() to apply lump
  44. // and pack compression as a final pass
  45. ::AddFileToPak( GetPakFile(), relativename, fullpath, IZip::eCompressionType_None );
  46. }
  47. void CBSPPack::AddBufferToPack( const char *relativename, void *data, int length, bool bTextMode )
  48. {
  49. // Compressing at this point would work, but the usual usage is creating a BSP and using RepackBSP() to apply lump
  50. // and pack compression as a final pass
  51. ::AddBufferToPak( GetPakFile(), relativename, data, length, bTextMode, IZip::eCompressionType_None );
  52. }
  53. void CBSPPack::SetHDRMode( bool bHDR )
  54. {
  55. ::SetHDRMode( bHDR );
  56. }
  57. bool CBSPPack::SwapBSPFile(
  58. IFileSystem *pFileSystem,
  59. const char *filename,
  60. const char *swapFilename,
  61. bool bSwapOnLoad,
  62. VTFConvertFunc_t pVTFConvertFunc,
  63. VHVFixupFunc_t pVHVFixupFunc,
  64. CompressFunc_t pCompressFunc )
  65. {
  66. // This is shady, but the engine is the only client here and we want the same search paths it has.
  67. g_pFileSystem = g_pFullFileSystem = pFileSystem;
  68. return ::SwapBSPFile( filename, swapFilename, bSwapOnLoad, pVTFConvertFunc, pVHVFixupFunc, pCompressFunc );
  69. }
  70. bool CBSPPack::RepackBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, eRepackBSPFlags repackFlags )
  71. {
  72. return ::RepackBSP( inputBuffer, outputBuffer,
  73. ( repackFlags & eRepackBSP_CompressLumps ) ? RepackBSPCallback_LZMA : NULL,
  74. ( repackFlags & eRepackBSP_CompressPackfile ) ? IZip::eCompressionType_LZMA : IZip::eCompressionType_None );
  75. }
  76. bool CBSPPack::GetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, void **pPakData, int *pPakSize )
  77. {
  78. g_pFileSystem = g_pFullFileSystem = pFileSystem;
  79. return ::GetPakFileLump( pBSPFilename, pPakData, pPakSize );
  80. }
  81. bool CBSPPack::SetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, const char *pNewFilename, void *pPakData, int pakSize )
  82. {
  83. g_pFileSystem = g_pFullFileSystem = pFileSystem;
  84. return ::SetPakFileLump( pBSPFilename, pNewFilename, pPakData, pakSize );
  85. }
  86. bool CBSPPack::GetBSPDependants( IFileSystem *pFileSystem, const char *pBSPFilename, CUtlVector< CUtlString > *pList )
  87. {
  88. g_pFileSystem = g_pFullFileSystem = pFileSystem;
  89. return ::GetBSPDependants( pBSPFilename, pList );
  90. }
  91. EXPOSE_SINGLE_INTERFACE( CBSPPack, IBSPPack, IBSPPACK_VERSION_STRING );