summaryrefslogtreecommitdiff
path: root/utils/bsppack/bsppack.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/bsppack/bsppack.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'utils/bsppack/bsppack.cpp')
-rw-r--r--utils/bsppack/bsppack.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/utils/bsppack/bsppack.cpp b/utils/bsppack/bsppack.cpp
new file mode 100644
index 0000000..973d40a
--- /dev/null
+++ b/utils/bsppack/bsppack.cpp
@@ -0,0 +1,112 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "bsplib.h"
+#include "ibsppack.h"
+#include "cmdlib.h"
+#include "zip_utils.h"
+
+class CBSPPack : public IBSPPack
+{
+public:
+ void LoadBSPFile( IFileSystem *pFileSystem, char *filename );
+ void WriteBSPFile( char *filename );
+ void ClearPackFile( void );
+ void AddFileToPack( const char *relativename, const char *fullpath );
+ void AddBufferToPack( const char *relativename, void *data, int length, bool bTextMode );
+ void SetHDRMode( bool bHDR );
+ bool SwapBSPFile( IFileSystem *pFileSystem, const char *filename, const char *swapFilename, bool bSwapOnLoad, VTFConvertFunc_t pVTFConvertFunc, VHVFixupFunc_t pVHVFixupFunc, CompressFunc_t pCompressFunc );
+ bool RepackBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, eRepackBSPFlags repackFlags );
+ bool GetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, void **pPakData, int *pPakSize );
+ bool SetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, const char *pNewFilename, void *pPakData, int pakSize );
+ bool GetBSPDependants( IFileSystem *pFileSystem, const char *pBSPFilename, CUtlVector< CUtlString > *pList );
+};
+
+void CBSPPack::LoadBSPFile( IFileSystem *pFileSystem, char *filename )
+{
+ MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
+
+ // This is shady, but the engine is the only client here and we want the same search paths it has.
+ g_pFileSystem = g_pFullFileSystem = pFileSystem;
+
+ ::LoadBSPFile( filename );
+}
+
+void CBSPPack::WriteBSPFile( char *filename )
+{
+ ::WriteBSPFile( filename );
+}
+
+void CBSPPack::ClearPackFile( void )
+{
+ ::ClearPakFile( GetPakFile() );
+}
+
+void CBSPPack::AddFileToPack( const char *relativename, const char *fullpath )
+{
+ // Compressing at this point would work, but the usual usage is creating a BSP and using RepackBSP() to apply lump
+ // and pack compression as a final pass
+ ::AddFileToPak( GetPakFile(), relativename, fullpath, IZip::eCompressionType_None );
+}
+
+void CBSPPack::AddBufferToPack( const char *relativename, void *data, int length, bool bTextMode )
+{
+ // Compressing at this point would work, but the usual usage is creating a BSP and using RepackBSP() to apply lump
+ // and pack compression as a final pass
+ ::AddBufferToPak( GetPakFile(), relativename, data, length, bTextMode, IZip::eCompressionType_None );
+}
+
+void CBSPPack::SetHDRMode( bool bHDR )
+{
+ ::SetHDRMode( bHDR );
+}
+
+bool CBSPPack::SwapBSPFile(
+IFileSystem *pFileSystem,
+const char *filename,
+const char *swapFilename,
+bool bSwapOnLoad,
+VTFConvertFunc_t pVTFConvertFunc,
+VHVFixupFunc_t pVHVFixupFunc,
+CompressFunc_t pCompressFunc )
+{
+ // This is shady, but the engine is the only client here and we want the same search paths it has.
+ g_pFileSystem = g_pFullFileSystem = pFileSystem;
+
+ return ::SwapBSPFile( filename, swapFilename, bSwapOnLoad, pVTFConvertFunc, pVHVFixupFunc, pCompressFunc );
+}
+
+bool CBSPPack::RepackBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, eRepackBSPFlags repackFlags )
+{
+ return ::RepackBSP( inputBuffer, outputBuffer,
+ ( repackFlags & eRepackBSP_CompressLumps ) ? RepackBSPCallback_LZMA : NULL,
+ ( repackFlags & eRepackBSP_CompressPackfile ) ? IZip::eCompressionType_LZMA : IZip::eCompressionType_None );
+}
+
+bool CBSPPack::GetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, void **pPakData, int *pPakSize )
+{
+ g_pFileSystem = g_pFullFileSystem = pFileSystem;
+
+ return ::GetPakFileLump( pBSPFilename, pPakData, pPakSize );
+}
+
+bool CBSPPack::SetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, const char *pNewFilename, void *pPakData, int pakSize )
+{
+ g_pFileSystem = g_pFullFileSystem = pFileSystem;
+
+ return ::SetPakFileLump( pBSPFilename, pNewFilename, pPakData, pakSize );
+}
+
+bool CBSPPack::GetBSPDependants( IFileSystem *pFileSystem, const char *pBSPFilename, CUtlVector< CUtlString > *pList )
+{
+ g_pFileSystem = g_pFullFileSystem = pFileSystem;
+
+ return ::GetBSPDependants( pBSPFilename, pList );
+}
+
+EXPOSE_SINGLE_INTERFACE( CBSPPack, IBSPPack, IBSPPACK_VERSION_STRING );
+