From 54f174d2620b3f31282132d15586d1b503ad7505 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sat, 17 Sep 2022 18:25:20 +0300 Subject: [PATCH] modify original vtex and add png support for it --- common/imageutils.cpp | 52 ++++- gameui/wscript | 3 +- lib | 2 +- thirdparty | 2 +- utils/vtex/vtex.cpp | 336 ++++++++----------------------- utils/vtex/wscript | 58 ++++++ utils/vtexconv/vtex_launcher.cpp | 46 +++++ utils/vtexconv/wscript | 48 +++++ 8 files changed, 291 insertions(+), 256 deletions(-) create mode 100755 utils/vtex/wscript create mode 100644 utils/vtexconv/vtex_launcher.cpp create mode 100755 utils/vtexconv/wscript diff --git a/common/imageutils.cpp b/common/imageutils.cpp index b9490f9c..5f32ae15 100644 --- a/common/imageutils.cpp +++ b/common/imageutils.cpp @@ -54,6 +54,8 @@ extern void longjmp( jmp_buf, int ) __attribute__((noreturn)); extern IEngineReplay *g_pEngine; #elif ENGINE_DLL #include "EngineInterface.h" +#elif UTILS + // OwO #else #include "cdll_int.h" extern IVEngineClient *engine; @@ -61,10 +63,23 @@ extern void longjmp( jmp_buf, int ) __attribute__((noreturn)); // use the JPEGLIB_USE_STDIO define so that we can read in jpeg's from outside the game directory tree. #define JPEGLIB_USE_STDIO +#if ANDROID +#include "android/jpeglib/jpeglib.h" +#else #include "jpeglib/jpeglib.h" +#endif #undef JPEGLIB_USE_STDIO + +#if HAVE_PNG + +#if ANDROID #include "libpng/png.h" +#else +#include +#endif + +#endif #include @@ -665,11 +680,29 @@ unsigned char *ImgUtl_ReadPNGAsRGBA( const char *pngPath, int &width, int &heigh // Just load the whole file into a memory buffer CUtlBuffer bufFileContents; + +#if UTILS + static char buf[8192]; + FILE *readfile = fopen(pngPath, "rb"); + if( !readfile ) + { + errcode = CE_CANT_OPEN_SOURCE_FILE; + return NULL; + } + + size_t size; + while( ( size = fread(buf, 1, sizeof(buf), readfile ) ) > 0 ) + bufFileContents.Put( buf, size ); + + // Load it + return ImgUtl_ReadPNGAsRGBAFromBuffer( bufFileContents, width, height, errcode ); +#else if ( !g_pFullFileSystem->ReadFile( pngPath, NULL, bufFileContents ) ) { errcode = CE_CANT_OPEN_SOURCE_FILE; return NULL; } +#endif // Load it return ImgUtl_ReadPNGAsRGBAFromBuffer( bufFileContents, width, height, errcode ); @@ -1473,7 +1506,7 @@ ConversionErrorType ImgUtl_ConvertTGAToVTF(const char *tgaPath, int nMaxWidth/*= inbuf.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead ); // load vtex_dll.dll and get the interface to it. - CSysModule *vtexmod = Sys_LoadModule("vtex_dll"); + CSysModule *vtexmod = Sys_LoadModule("vtex_dll" DLL_EXT_STRING); if (vtexmod == NULL) { Msg( "Failed to open TGA conversion module vtex_dll: %s\n", tgaPath); @@ -1522,6 +1555,17 @@ static void DoCopyFile( const char *source, const char *destination ) ::COM_CopyFile( source, destination ); #elif REPLAY_DLL g_pEngine->CopyFile( source, destination ); +#elif UTILS + static char buf[16384]; + FILE *readfile = fopen(source, "rb"); + FILE *writefile = fopen(destination, "wb"); + + size_t size = 0; + while( (size = fread(buf, sizeof(buf), 1, readfile)) != 0 ) + fwrite(buf, size, 1, writefile); + + fclose(readfile); + fclose(writefile); #else engine->CopyLocalFile( source, destination ); #endif @@ -1712,12 +1756,12 @@ ConversionErrorType ImgUtl_ConvertToVTFAndDumpVMT( const char *pInPath, const ch Q_strncpy(finalPath, com_gamedir, sizeof(finalPath)); #elif REPLAY_DLL Q_strncpy(finalPath, g_pEngine->GetGameDir(), sizeof(finalPath)); -#else +#elif !UTILS Q_strncpy(finalPath, engine->GetGameDirectory(), sizeof(finalPath)); #endif Q_strncat(finalPath, szOutDir, sizeof(finalPath), COPY_ALL_CHARACTERS); Q_strncat(finalPath, vtfFilename, sizeof(finalPath), COPY_ALL_CHARACTERS); - + c = finalPath + strlen(finalPath); while ((c > finalPath) && (*(c-1) != '.')) { @@ -1829,6 +1873,7 @@ ConversionErrorType ImgUtl_WriteGenericVMT( const char *vtfPath, const char *pMa return CE_SUCCESS; } +#if HAVE_PNG static void WritePNGData( png_structp png_ptr, png_bytep inBytes, png_size_t byteCountToWrite ) { @@ -1847,7 +1892,6 @@ static void FlushPNGData( png_structp png_ptr ) // We're writing to a memory buffer, it's a NOP } -#if HAVE_PNG ConversionErrorType ImgUtl_WriteRGBAAsPNGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride ) { #if !defined( _X360 ) diff --git a/gameui/wscript b/gameui/wscript index 5502746d..2cbbe180 100755 --- a/gameui/wscript +++ b/gameui/wscript @@ -109,7 +109,8 @@ def build(bld): '../public/tier0', '../public/tier1', '../common', - '../common/GameUI' + '../common/GameUI', + '../thirdparty' ] defines = [] diff --git a/lib b/lib index dd9c273d..9ffeba56 160000 --- a/lib +++ b/lib @@ -1 +1 @@ -Subproject commit dd9c273d2deaf4d75b6e371a9707755e65d26010 +Subproject commit 9ffeba566ef076b829041f19f015155e21f325ed diff --git a/thirdparty b/thirdparty index 2e8dde2e..cc41c319 160000 --- a/thirdparty +++ b/thirdparty @@ -1 +1 @@ -Subproject commit 2e8dde2e935d4779da5cdaa6c6e5c1b872b0401e +Subproject commit cc41c319aabc287b1f7439228af5a9edeb31ee05 diff --git a/utils/vtex/vtex.cpp b/utils/vtex/vtex.cpp index 7a43b3f8..d09a32d2 100644 --- a/utils/vtex/vtex.cpp +++ b/utils/vtex/vtex.cpp @@ -42,10 +42,8 @@ #include "appframework/IAppSystemGroup.h" #include "tier2/tier2.h" -#include "tier2/p4helpers.h" -#include "p4lib/ip4.h" - #include "tier1/checksum_crc.h" +#include "imageutils.h" #define FF_TRYAGAIN 1 #define FF_DONTPROCESS 2 @@ -59,20 +57,14 @@ #endif //#define DEBUG_NO_COMPRESSION -static bool g_NoPause = false; static bool g_Quiet = false; static const char *g_ShaderName = NULL; static bool g_CreateDir = true; static bool g_UseGameDir = true; -static bool g_bUseStandardError = false; static bool g_bWarningsAsErrors = false; - static bool g_bUsedAsLaunchableDLL = false; -static bool g_bNoTga = false; -static bool g_bNoPsd = false; - static char g_ForcedOutputDir[MAX_PATH]; @@ -110,22 +102,11 @@ protected: static VTexVMTParam_t g_VMTParams[MAX_VMT_PARAMS]; static int g_NumVMTParams = 0; -static enum Mode { eModePSD, eModeTGA, eModePFM } g_eMode = eModePSD; +static enum Mode { eModePSD, eModeTGA, eModePFM, eModePNG } g_eMode = eModePSD; // NOTE: these must stay in the same order as CubeMapFaceIndex_t. static const char *g_CubemapFacingNames[7] = { "rt", "lf", "bk", "ft", "up", "dn", "sph" }; -static void Pause( void ) -{ - if( !g_NoPause ) - { - printf( "Hit a key to continue\n" ); -#ifdef WIN32 - getch(); -#endif - } -} - static bool VTexErrorAborts() { if ( CommandLine()->FindParm( "-crcvalidate" ) ) @@ -149,16 +130,9 @@ static void VTexError( const char *pFormat, ... ) return; } - if ( g_bUseStandardError ) - { - Error( "ERROR: %s", str ); - } - else - { - fprintf( stderr, "ERROR: %s", str ); - Pause(); - exit( 1 ); - } + + fprintf( stderr, "ERROR: %s", str ); + exit( 1 ); } @@ -177,7 +151,6 @@ static void VTexWarning( const char *pFormat, ... ) else { fprintf( stderr, "WARN: %s", str ); - Pause(); } } @@ -666,6 +639,8 @@ static const char *GetSourceExtension( void ) return ".tga"; case eModePFM: return ".pfm"; + case eModePNG: + return ".png"; default: return ".tga"; } @@ -932,8 +907,6 @@ static bool LoadFile( const char *pFileName, CUtlBuffer &buf, bool bFailOnError, buf.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead ); - { CP4AutoAddFile autop4( pFileName ); /* add loaded file to P4 */ } - // Auto-compute buffer hash if necessary if ( puiHash ) ComputeBufferHash( buf.Base(), nBytesRead, *puiHash ); @@ -991,6 +964,34 @@ static void InitializeSrcTexture_TGA( IVTFTexture *pTexture, const char *pInputF } } +static void InitializeSrcTexture_PNG( IVTFTexture *pTexture, const char *pInputFileName, + CUtlBuffer &pngBuffer, int nDepth, int nFrameCount, + const VTexConfigInfo_t &info ) +{ + int nWidth, nHeight; + ImageFormat imageFormat; + float flSrcGamma; + + ConversionErrorType error = CE_SUCCESS; + unsigned char *data = ImgUtl_ReadPNGAsRGBAFromBuffer( pngBuffer, nWidth, nHeight, error ); + if (error != CE_SUCCESS) + Error( "PNG %s is bogus!\n", pInputFileName ); + + pngBuffer.SeekPut( CUtlBuffer::SEEK_HEAD, 0 ); + pngBuffer.Put( data, nWidth*nHeight*4 ); + + nWidth /= info.m_nReduceX; + nHeight /= info.m_nReduceY; + + FILE *f = fopen("shit", "wb"); + fwrite(pngBuffer.Base(), 1, 256*256*4, f); + fclose(f); + + if (!pTexture->Init( nWidth, nHeight, nDepth, IMAGE_FORMAT_DEFAULT, info.m_nFlags, nFrameCount )) + { + Error( "Error initializing texture %s\n", pInputFileName ); + } +} // HDRFIXME: Put this somewhere better than this. // This reads an integer from a binary CUtlBuffer. @@ -1089,6 +1090,9 @@ static void InitializeSrcTexture( IVTFTexture *pTexture, const char *pInputFileN case eModeTGA: InitializeSrcTexture_TGA( pTexture, pInputFileName, tgaBuffer, nDepth, nFrameCount, info ); break; + case eModePNG: + InitializeSrcTexture_PNG( pTexture, pInputFileName, tgaBuffer, nDepth, nFrameCount, info ); + break; case eModePFM: InitializeSrcTexture_PFM( pTexture, pInputFileName, tgaBuffer, nDepth, nFrameCount, info ); break; @@ -1388,6 +1392,31 @@ static bool LoadFaceFromTGA( IVTFTexture *pTexture, CUtlBuffer &tgaBuffer, int z } } + +//----------------------------------------------------------------------------- +// Loads a face from a PNG image +//----------------------------------------------------------------------------- +static bool LoadFaceFromPNG( IVTFTexture *pTexture, CUtlBuffer &tgaBuffer, int z, int nFrame, int nFace, float flGamma, const VTexConfigInfo_t &info ) +{ + // NOTE: This only works because all mip levels are stored sequentially + // in memory, starting with the highest mip level. It also only works + // because the VTF Texture store *all* mip levels down to 1x1 + + // Get the information from the file... + int nWidth, nHeight; + ImageFormat imageFormat; + float flSrcGamma; + + ConversionErrorType error = CE_SUCCESS; + + // Load the tga and create all mipmap levels + unsigned char *pDestBits = pTexture->ImageData( nFrame, nFace, 0, 0, 0, z ); + + memcpy( pDestBits, tgaBuffer.Base(), tgaBuffer.TellPut() ); + + return true; +} + //----------------------------------------------------------------------------- // Loads a face from a PFM image //----------------------------------------------------------------------------- @@ -1451,6 +1480,9 @@ static bool LoadFaceFromX( IVTFTexture *pTexture, CUtlBuffer &tgaBuffer, int z, case eModeTGA: return LoadFaceFromTGA( pTexture, tgaBuffer, z, nFrame, nFace, flGamma, info ); break; + case eModePNG: + return LoadFaceFromPNG( pTexture, tgaBuffer, z, nFrame, nFace, flGamma, info ); + break; case eModePFM: return LoadFaceFromPFM( pTexture, tgaBuffer, z, nFrame, nFace, flGamma, info ); break; @@ -1905,7 +1937,7 @@ bool ProcessFiles( const char *pFullNameWithoutExtension, } // Write it! - if ( g_CreateDir == true ) + if ( g_CreateDir ) MakeDirHier( pOutputDir ); //It'll create it if it doesn't exist. // Make sure the CRC hasn't been modified since finalized @@ -1918,7 +1950,6 @@ bool ProcessFiles( const char *pFullNameWithoutExtension, } { - CP4AutoEditAddFile autop4( dstFileName ); FILE *fp = fopen( dstFileName, "wb" ); if( !fp ) { @@ -2022,10 +2053,9 @@ static bool LoadConfigFile( const char *pFileBaseName, VTexConfigInfo_t &info, b info.m_LookDir = LOOK_DOWN_Z; - // Try TGA file with config memcpy( pFileName + lenBaseName, ".tga", 4 ); - if ( !bOK && !g_bNoTga && ( 00 == access( pFileName, 00 ) ) ) // TGA file exists + if ( !bOK && ( 00 == access( pFileName, 00 ) ) ) // TGA file exists { g_eMode = eModeTGA; @@ -2059,14 +2089,10 @@ static bool LoadConfigFile( const char *pFileBaseName, VTexConfigInfo_t &info, b } } memcpy( pFileName + lenBaseName, ".tga", 4 ); - if ( g_bNoTga && ( 00 == access( pFileName, 00 ) ) ) - { - printf( "Warning: -notga disables \"%s\"\n", pFileName ); - } // PSD file attempt memcpy( pFileName + lenBaseName, ".psd", 4 ); - if ( !bOK && !g_bNoPsd ) // If PSD mode was not disabled + if ( !bOK && ( 00 == access( pFileName, 00 ) ) ) // If PSD mode was not disabled { g_eMode = eModePSD; @@ -2108,12 +2134,14 @@ static bool LoadConfigFile( const char *pFileBaseName, VTexConfigInfo_t &info, b } } } - else if ( 00 == access( pFileName, 00 ) ) + + // PNG file attempt + memcpy( pFileName + lenBaseName, ".png", 4 ); + if ( !bOK ) // If PNG mode was not disabled { - if ( !bOK ) - printf( "Warning: -nopsd disables \"%s\"\n", pFileName ); - else - printf( "Warning: psd file \"%s\" exists, but not used, delete tga and txt files to use psd file directly\n", pFileName ); + g_eMode = eModePNG; + info.m_nFlags |= TEXTUREFLAGS_NOMIP; + bOK = true; } // Try TXT file as config again for TGA cubemap / PFM @@ -2155,11 +2183,7 @@ static bool LoadConfigFile( const char *pFileBaseName, VTexConfigInfo_t &info, b if ( !bOK ) { - VTexError( "\"%s\" does not specify valid %s%sPFM+TXT files!\n", - pFileBaseName, - g_bNoPsd ? "" : "PSD or ", - g_bNoTga ? "" : "TGA or " - ); + VTexError( "\"%s\" does not specify valid PSD or TGA or PFM+TXT files!\n"); return false; } @@ -2242,15 +2266,13 @@ static bool LoadConfigFile( const char *pFileBaseName, VTexConfigInfo_t &info, b void Usage( void ) { VTexError( - "Usage: vtex [-outdir dir] [-quiet] [-nopause] [-mkdir] [-shader ShaderName] [-vmtparam Param Value] tex1.txt tex2.txt . . .\n" + "Usage: vtex [-quiet] [-mkdir] [-shader ShaderName] [-vmtparam Param Value] tex1.txt tex2.txt . . .\n" "-quiet : don't print anything out, don't pause for input\n" "-warningsaserrors : treat warnings as errors\n" - "-nopause : don't pause for input\n" "-nomkdir : don't create destination folder if it doesn't exist\n" "-vmtparam : adds parameter and value to the .vmt file\n" - "-outdir : write output to the specified dir regardless of source filename and vproject\n" "-deducepath : deduce path of sources by target file names\n" - "-quickconvert : use with \"-nop4 -dontusegamedir -quickconvert\" to upgrade old .vmt files\n" + "-quickconvert : use with \"-dontusegamedir -quickconvert\" to upgrade old .vmt files\n" "-crcvalidate : validate .vmt against the sources\n" "-crcforce : generate a new .vmt even if sources crc matches\n" "\teg: -vmtparam $ignorez 1 -vmtparam $translucent 1\n" @@ -2431,7 +2453,7 @@ bool Process_File( char *pInputBaseName, int maxlen ) } // Usage: - // vtex -nop4 -dontusegamedir -quickconvert u:\data\game\tf\texture.vtf + // vtex -dontusegamedir -quickconvert u:\data\game\tf\texture.vtf // Will read the old texture format and write the new texture format // if ( CommandLine()->FindParm( "-quickconvert" ) ) @@ -2550,8 +2572,6 @@ bool Process_File( char *pInputBaseName, int maxlen ) fprintf( fp, "}\n" ); fclose( fp ); - - CP4AutoAddFile autop4( buf ); } else { @@ -2574,7 +2594,6 @@ static SpewRetval_t VTexOutputFunc( SpewType_t spewType, char const *pMsg ) printf( "%s", pMsg ); if (spewType == SPEW_ERROR) { - Pause(); return SPEW_ABORT; } return (spewType == SPEW_ASSERT) ? SPEW_DEBUGGER : SPEW_CONTINUE; @@ -2665,7 +2684,7 @@ bool CSuggestGameDirHelper::MySuggestFn( CFSSteamSetupInfo const *pFsSteamSetupI int CVTex::VTex( int argc, char **argv ) { - CommandLine()->CreateCmdLine( argc, argv ); +// CommandLine()->CreateCmdLine( argc, argv ); if ( g_bUsedAsLaunchableDLL ) { @@ -2679,8 +2698,7 @@ int CVTex::VTex( int argc, char **argv ) return -1; } - g_UseGameDir = true; // make sure this is initialized to true. - const char *p4ChangelistLabel = "VTex Auto Checkout"; + g_UseGameDir = false; // make sure this is initialized to true. bool bCreatedFilesystem = false; int i; @@ -2691,67 +2709,22 @@ int CVTex::VTex( int argc, char **argv ) { i++; g_Quiet = true; - g_NoPause = true; // no point in pausing if we aren't going to print anything out. } - else if( stricmp( argv[i], "-nopause" ) == 0 ) - { - i++; - g_NoPause = true; - } - else if ( stricmp( argv[i], "-WarningsAsErrors" ) == 0 ) + else if ( stricmp( argv[i], "-warningsaserrors" ) == 0 ) { i++; g_bWarningsAsErrors = true; } - else if ( stricmp( argv[i], "-UseStandardError" ) == 0 ) - { - i++; - g_bUseStandardError = true; - } - else if ( stricmp( argv[i], "-nopsd" ) == 0 ) - { - i++; - g_bNoPsd = true; - } - else if ( stricmp( argv[i], "-notga" ) == 0 ) - { - i++; - g_bNoTga = true; - } else if ( stricmp( argv[i], "-nomkdir" ) == 0 ) { i++; g_CreateDir = false; } - else if ( stricmp( argv[i], "-mkdir" ) == 0 ) - { - i++; - g_CreateDir = true; - } - else if ( stricmp( argv[i], "-game" ) == 0 ) - { - i += 2; - } else if ( stricmp( argv[i], "-outdir" ) == 0 ) { V_strcpy_safe( g_ForcedOutputDir, argv[i+1] ); i += 2; } - else if ( stricmp( argv[i], "-p4changelistlabel" ) == 0 ) - { - p4ChangelistLabel = argv[i+1]; - i += 2; - } - else if ( stricmp( argv[i], "-p4skipchangelistlabel" ) == 0 ) - { - p4ChangelistLabel = NULL; - i++; - } - else if ( stricmp( argv[i], "-dontusegamedir" ) == 0) - { - ++i; - g_UseGameDir = false; - } else if( stricmp( argv[i], "-shader" ) == 0 ) { i++; @@ -2761,14 +2734,12 @@ int CVTex::VTex( int argc, char **argv ) i++; } } - else if( stricmp( argv[i], "-vproject" ) == 0 ) + else if( stricmp(argv[i], "-crcvalidate") == 0 ) { - // skip this one. . we dont' use it internally. - i += 2; + i++; } - else if( stricmp( argv[i], "-allowdebug" ) == 0 ) + else if( stricmp(argv[i], "-crcforce") == 0 ) { - // skip this one. . we dont' use it internally. i++; } else if( stricmp( argv[i], "-vmtparam" ) == 0 ) @@ -2806,36 +2777,6 @@ int CVTex::VTex( int argc, char **argv ) fprintf( stderr, "Exceeded max number of vmt parameters, extra ignored ( max %d )\n", MAX_VMT_PARAMS ); } } - else if( stricmp( argv[i], "-nop4" ) == 0 ) - { - // Just here to signify that -nop4 is a valid flag - ++ i; - } - else if( stricmp( argv[i], "-deducepath" ) == 0 ) - { - // Just here to signify that -deducepath is a valid flag - ++ i; - } - else if( stricmp( argv[i], "-quickconvert" ) == 0 ) - { - // Just here to signify that -quickconvert is a valid flag - ++ i; - } - else if( stricmp( argv[i], "-crcvalidate" ) == 0 ) - { - // Just here to signify that -crcvalidate is a valid flag - ++ i; - } - else if( stricmp( argv[i], "-crcforce" ) == 0 ) - { - // Just here to signify that -crcforce is a valid flag - ++ i; - } - else if( stricmp( argv[i], "-p4skip" ) == 0 ) - { - // Just here to signify that -p4skip is a valid flag - ++ i; - } else { break; @@ -2848,6 +2789,7 @@ int CVTex::VTex( int argc, char **argv ) SetSuggestGameInfoDirFn( CSuggestGameDirHelper::SuggestFn ); // g_pFileSystem may have been inherited with -inherit_filesystem. + if (g_UseGameDir && !g_pFileSystem) { FileSystem_Init( argv[i] ); @@ -2856,56 +2798,6 @@ int CVTex::VTex( int argc, char **argv ) Q_FixSlashes( gamedir, '/' ); } - if ( !CommandLine()->FindParm( "-p4skip" ) ) - { - // Initialize P4 - bool bP4DLLExists = false; - if ( g_pFullFileSystem ) - { - bP4DLLExists = g_pFullFileSystem->FileExists( "p4lib.dll", "EXECUTABLE_PATH" ); - } - - if ( g_bUsedAsLaunchableDLL && !CommandLine()->FindParm( "-nop4" ) && bP4DLLExists ) - { - const char *pModuleName = "p4lib.dll"; - CSysModule *pModule = Sys_LoadModule( pModuleName ); - if ( !pModule ) - { - printf( "Can't load %s.\n", pModuleName ); - return -1; - } - CreateInterfaceFn fn = Sys_GetFactory( pModule ); - if ( !fn ) - { - printf( "Can't get factory from %s.\n", pModuleName ); - Sys_UnloadModule( pModule ); - return -1; - } - p4 = (IP4 *)fn( P4_INTERFACE_VERSION, NULL ); - if ( !p4 ) - { - printf( "Can't get IP4 interface from %s, proceeding with -nop4.\n", pModuleName ); - g_p4factory->SetDummyMode( true ); - } - else - { - p4->Connect( FileSystem_GetFactory() ); - p4->Init(); - } - } - else - { - g_p4factory->SetDummyMode( true ); - } - - // Setup p4 factory - if ( p4ChangelistLabel && p4ChangelistLabel[0] != '\000' ) - { - // Set the named changelist - g_p4factory->SetOpenFileChangeList( p4ChangelistLabel ); - } - } - // Parse args for( ; i < argc; i++ ) { @@ -2921,59 +2813,6 @@ int CVTex::VTex( int argc, char **argv ) Process_File( pInputBaseName, sizeof(pInputBaseName) ); continue; } - -#ifdef WIN32 - char search[ 128 ]; - char basedir[MAX_PATH]; - char ext[_MAX_EXT]; - char filename[_MAX_FNAME]; - - _splitpath( pInputBaseName, NULL, NULL, NULL, ext ); //find extension wanted - - if ( !Q_ExtractFilePath ( pInputBaseName, basedir, sizeof( basedir ) ) ) - strcpy( basedir, ".\\" ); - - sprintf( search, "%s\\*.*", basedir ); - - WIN32_FIND_DATA wfd; - HANDLE hResult; - memset(&wfd, 0, sizeof(WIN32_FIND_DATA)); - - hResult = FindFirstFile( search, &wfd ); - - if ( hResult != INVALID_HANDLE_VALUE ) - { - sprintf( filename, "%s%s", basedir, wfd.cFileName ); - - if ( wfd.cFileName[0] != '.' ) - Process_File( filename, sizeof( filename ) ); - - int iFFType = Find_Files( wfd, hResult, basedir, ext ); - - while ( iFFType ) - { - sprintf( filename, "%s%s", basedir, wfd.cFileName ); - - if ( wfd.cFileName[0] != '.' && iFFType != FF_DONTPROCESS ) - Process_File( filename, sizeof( filename ) ); - - iFFType = Find_Files( wfd, hResult, basedir, ext ); - } - - if ( iFFType == 0 ) - { - FindClose( hResult ); - } - } -#endif - - } - - // Shutdown P4 - if ( g_bUsedAsLaunchableDLL && p4 && !CommandLine()->FindParm( "-p4skip" ) ) - { - p4->Shutdown(); - p4->Disconnect(); } if ( bCreatedFilesystem ) @@ -2987,7 +2826,6 @@ int CVTex::VTex( int argc, char **argv ) SpewOutputFunc( NULL ); } - Pause(); return 0; } diff --git a/utils/vtex/wscript b/utils/vtex/wscript new file mode 100755 index 00000000..c117a53e --- /dev/null +++ b/utils/vtex/wscript @@ -0,0 +1,58 @@ +#! /usr/bin/env python +# encoding: utf-8 + +from waflib import Utils +import os + +top = '.' +PROJECT_NAME = 'vtex_dll' + +def options(opt): + # stub + return + +def configure(conf): + conf.define('VTEX_DLL', 1) + conf.define('UTILS', 1) + conf.define('VTEX_DLL_EXPORTS', 1) + conf.define('PROTECTED_THINGS_DISABLE', 1) + + +def build(bld): + source = [ + '../common/cmdlib.cpp', + '../../public/filesystem_helpers.cpp', + '../../public/filesystem_init.cpp', + '../common/filesystem_tools.cpp', + 'vtex.cpp', + '../../common/imageutils.cpp' + ] + + includes = [ + '.', + '../../public', + '../../public/tier0', + '../../public/tier1', + '../common', + '../../common' + ] + + defines = [] + + libs = ['tier0', 'tier1', 'bitmap', 'tier2', 'vstdlib', 'mathlib', 'vtf', 'JPEG', 'PNG'] + + install_path = bld.env.LIBDIR + + bld.shlib( + source = source, + target = PROJECT_NAME, + name = PROJECT_NAME, + features = 'c cxx', + includes = includes, + defines = defines, + use = libs, + install_path = install_path, + subsystem = bld.env.MSVC_SUBSYSTEM, + idx = bld.get_taskgen_count() + ) + diff --git a/utils/vtexconv/vtex_launcher.cpp b/utils/vtexconv/vtex_launcher.cpp new file mode 100644 index 00000000..88a40a58 --- /dev/null +++ b/utils/vtexconv/vtex_launcher.cpp @@ -0,0 +1,46 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include +#include "tier1/interface.h" +#include "ilaunchabledll.h" + + +int main( int argc, char **argv ) +{ + const char *pModuleName = "vtex_dll" DLL_EXT_STRING; + + CSysModule *pModule = Sys_LoadModule( pModuleName ); + if ( !pModule ) + { + printf( "Can't load %s.", pModuleName ); + return 1; + } + + CreateInterfaceFn fn = Sys_GetFactory( pModule ); + if ( !fn ) + { + printf( "Can't get factory from %s.", pModuleName ); + Sys_UnloadModule( pModule ); + return 1; + } + + ILaunchableDLL *pInterface = (ILaunchableDLL*)fn( LAUNCHABLE_DLL_INTERFACE_VERSION, NULL ); + if ( !pInterface ) + { + printf( "Can't get '%s' interface from %s.", LAUNCHABLE_DLL_INTERFACE_VERSION, pModuleName ); + Sys_UnloadModule( pModule ); + return 1; + } + + int iRet = pInterface->main( argc, argv ); + Sys_UnloadModule( pModule ); + return iRet; +} + + + diff --git a/utils/vtexconv/wscript b/utils/vtexconv/wscript new file mode 100755 index 00000000..806d0b3f --- /dev/null +++ b/utils/vtexconv/wscript @@ -0,0 +1,48 @@ +#! /usr/bin/env python +# encoding: utf-8 + +from waflib import Utils +import os + +top = '.' +PROJECT_NAME = 'vtexconv' + +def options(opt): + # stub + return + +def configure(conf): + conf.define('PROTECTED_THINGS_DISABLE', 1) + +def build(bld): + source = [ + 'vtex_launcher.cpp' + ] + + includes = [ + '.', + '../../public', + '../../public/tier0', + '../../public/tier1', + '../../common' + ] + + defines = [] + + libs = ['tier0', 'appframework','tier1','tier2','tier3','vstdlib'] + + install_path = bld.env.BINDIR + + bld( + source = source, + target = PROJECT_NAME, + name = PROJECT_NAME, + features = 'c cxx cxxprogram', + includes = includes, + defines = defines, + use = libs, + install_path = install_path, + subsystem = bld.env.MSVC_SUBSYSTEM, + idx = bld.get_taskgen_count() + ) +