Skip to content

Commit 047a5aa

Browse files
committed
utils\common: Add changes from recent TF2 SDK
1 parent 7863493 commit 047a5aa

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

utils/common/bsplib.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,12 @@ bool LoadBSPFile( const char *filename )
22862286
CopyLump( header, FIELD_CHARACTER, LUMP_TEXDATA_STRING_DATA, g_TexDataStringData );
22872287
CopyLump( header, FIELD_INTEGER, LUMP_TEXDATA_STRING_TABLE, g_TexDataStringTable );
22882288

2289+
// It's assumed by other code that the data lump is filled with C strings. We need to make sure that
2290+
// the buffer as a whole ends with a '\0'.
2291+
// dimhotepus: TF2 backport.
2292+
if ( g_TexDataStringData.Count() > 0 && g_TexDataStringData.Tail() != '\0' )
2293+
Error( "BSP file %s is corrupted", filename );
2294+
22892295
g_nOverlayCount = CopyLump(header, LUMP_OVERLAYS, g_Overlays);
22902296
g_nWaterOverlayCount = CopyLump( header, LUMP_WATEROVERLAYS, g_WaterOverlays );
22912297
CopyLump( header, LUMP_OVERLAY_FADES, g_OverlayFades );
@@ -3123,7 +3129,8 @@ Generates the dentdata string from all the entities
31233129
void UnparseEntities (void)
31243130
{
31253131
epair_t *ep;
3126-
char line[2048];
3132+
// dimhotepus: +16 is from TF2 backport.
3133+
char line[2048 + 16];
31273134
int i;
31283135
char key[1020], value[1020];
31293136

utils/common/cmdlib.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ void Q_mkdir(char *path) {
458458
if (!mkdir(path, 0777) || errno == EEXIST) return;
459459
#endif
460460

461-
Error( "Unable to create directory '%s': %s.\n",
462-
path, std::generic_category().message(errno).c_str() );
461+
Error("Unable to create directory '%s': %s.\n", path,
462+
std::generic_category().message(errno).c_str());
463463
}
464464

465465
void CmdLib_InitFileSystem(const char *pFilename, int maxMemoryUsage) {
@@ -545,9 +545,9 @@ bool CmdLib_HasBasePath(const char *pFileName_, intp &pathLength) {
545545

546546
for (intp i = 0; i < g_NumBasePaths; i++) {
547547
// see if we can rip the base off of the filename.
548-
if (Q_strncasecmp(g_pBasePaths[i], pFileName, strlen(g_pBasePaths[i])) ==
549-
0) {
550-
pathLength = strlen(g_pBasePaths[i]);
548+
const intp len = V_strlen(g_pBasePaths[i]);
549+
if (Q_strncasecmp(g_pBasePaths[i], pFileName, len) == 0) {
550+
pathLength = len;
551551
return true;
552552
}
553553
}
@@ -718,7 +718,7 @@ void CreatePath(char *path) {
718718
}
719719

720720
#if defined(_WIN32) || defined(WIN32)
721-
// Creates a path, path may already exist
721+
// Creates a path, path may already exist. This is kinda janky, avoid.
722722
void SafeCreatePath(char *path) {
723723
char *ptr;
724724

@@ -738,6 +738,24 @@ void SafeCreatePath(char *path) {
738738
}
739739
}
740740
}
741+
#elif defined(POSIX)
742+
// dimhotepus: TF2 backport.
743+
void SafeCreatePath(char *path) {
744+
char *ptr = path;
745+
// Ignore leading slashes (don't mkdir /)
746+
while (*ptr == '/') {
747+
ptr++;
748+
};
749+
750+
while (ptr && *ptr) {
751+
ptr = strchr(ptr + 1, '/');
752+
if (ptr) {
753+
*ptr = '\0';
754+
Q_mkdir(path);
755+
*ptr = '/';
756+
}
757+
}
758+
}
741759
#endif
742760

743761
// Used to archive source files

utils/common/scriplib.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ bool ExpandMacroToken( char *&token_p )
312312
}
313313

314314
// paste token into
315-
len = strlen( script->macrovalue[index] );
315+
len = V_strlen( script->macrovalue[index] );
316316
strcpy( token_p, script->macrovalue[index] );
317317
token_p += len;
318318

@@ -949,7 +949,7 @@ class CScriptLib final : public IScriptLib
949949
bool ReadFileToBuffer( const char *pSourceName, CUtlBuffer &buffer, bool bText = false, bool bNoOpenFailureWarning = false ) override;
950950
bool WriteBufferToFile( const char *pTargetName, CUtlBuffer &buffer, DiskWriteMode_t writeMode ) override;
951951
intp FindFiles( char* pFileMask, bool bRecurse, CUtlVector<fileList_t> &fileList ) override;
952-
char *MakeTemporaryFilename( char const *pchModPath, char *pPath, intp pathSize ) override;
952+
[[deprecated]] char *MakeTemporaryFilename( char const *pchModPath, char *pPath, intp pathSize ) override;
953953
void DeleteTemporaryFiles( const char *pFileMask ) override;
954954
int CompareFileTime( const char *pFilenameA, const char *pFilenameB ) override;
955955
bool DoesFileExist( const char *pFilename ) override;
@@ -1081,8 +1081,9 @@ int CScriptLib::CompareFileTime( const char *pFilenameA, const char *pFilenameB
10811081
//-----------------------------------------------------------------------------
10821082
// Make a temporary filename
10831083
//-----------------------------------------------------------------------------
1084-
char *CScriptLib::MakeTemporaryFilename( char const *pchModPath, char *pPath, intp pathSize )
1084+
[[deprecated]] char *CScriptLib::MakeTemporaryFilename( char const *pchModPath, char *pPath, intp pathSize )
10851085
{
1086+
#if 0
10861087
char *pBuffer = _tempnam( pchModPath, "mgd_" );
10871088
if ( pBuffer[0] == '\\' )
10881089
{
@@ -1099,6 +1100,11 @@ char *CScriptLib::MakeTemporaryFilename( char const *pchModPath, char *pPath, in
10991100
free( pBuffer );
11001101

11011102
return pPath;
1103+
#else
1104+
AssertMsg( false, "Deprecated MakeTemporaryFilename." );
1105+
1106+
return nullptr;
1107+
#endif
11021108
}
11031109

11041110
//-----------------------------------------------------------------------------
@@ -1213,7 +1219,7 @@ intp CScriptLib::GetFileList( const char* pDirPath, const char* pPattern, CUtlVe
12131219
FIND_DATA findData;
12141220
Q_FixSlashes( fullPath );
12151221
void *h = FindFirstFile( fullPath, &findData );
1216-
if ( (int)h == -1 )
1222+
if ( (intp)h == -1 )
12171223
{
12181224
return 0;
12191225
}

utils/common/scriplib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class IScriptLib
8787
virtual bool ReadFileToBuffer( const char *pSourceName, CUtlBuffer &buffer, bool bText = false, bool bNoOpenFailureWarning = false ) = 0;
8888
virtual bool WriteBufferToFile( const char *pTargetName, CUtlBuffer &buffer, DiskWriteMode_t writeMode ) = 0;
8989
virtual intp FindFiles( char* pFileMask, bool bRecurse, CUtlVector<fileList_t> &fileList ) = 0;
90-
virtual char *MakeTemporaryFilename( char const *pchModPath, char *pPath, intp pathSize ) = 0;
90+
[[deprecated]] virtual char *MakeTemporaryFilename( char const *pchModPath, char *pPath, intp pathSize ) = 0;
9191
virtual void DeleteTemporaryFiles( const char *pFileMask ) = 0;
9292
virtual int CompareFileTime( const char *pFilenameA, const char *pFilenameB ) = 0;
9393
virtual bool DoesFileExist( const char *pFilename ) = 0;

0 commit comments

Comments
 (0)