1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: .360 file creation of miscellaneous resource and data files
//
//=====================================================================================//
#include "MakeGameData.h"
#include "captioncompiler.h"
//-----------------------------------------------------------------------------
// Purpose: Generate .360 compiled caption files
//-----------------------------------------------------------------------------
bool CreateTargetFile_CCDAT( const char *pSourceName, const char *pTargetName, bool bWriteToZip )
{
CUtlBuffer targetBuffer;
bool bOk = false;
if ( !scriptlib->ReadFileToBuffer( pSourceName, targetBuffer ) )
{
return false;
}
if ( SwapClosecaptionFile( targetBuffer.Base() ) )
{
bOk = WriteBufferToFile( pTargetName, targetBuffer, bWriteToZip, g_WriteModeForConversions );
}
return bOk;
}
static bool ReslistLessFunc( CUtlString const &pLHS, CUtlString const &pRHS )
{
return CaselessStringLessThan( pLHS.Get(), pRHS.Get() );
}
//-----------------------------------------------------------------------------
// Find or Add, prevents duplicates. Returns TRUE if found.
//-----------------------------------------------------------------------------
bool FindOrAddFileToResourceList( const char *pFilename, CUtlRBTree< CUtlString, int > *pTree, bool bAdd = true )
{
char szOutName[MAX_PATH];
char *pOutName;
V_strncpy( szOutName, pFilename, sizeof( szOutName ) );
V_FixSlashes( szOutName );
V_RemoveDotSlashes( szOutName );
V_strlower( szOutName );
pOutName = szOutName;
// strip any prefixed game name
for ( int i = 0; g_GameNames[i] != NULL; i++ )
{
size_t len = strlen( g_GameNames[i] );
if ( !V_strnicmp( pOutName, g_GameNames[i], len ) && pOutName[len] == '\\' )
{
// skip past game name and slash
pOutName += len+1;
break;
}
}
if ( pTree->Find( pOutName ) != pTree->InvalidIndex() )
{
// found
return true;
}
if ( bAdd )
{
pTree->Insert( pOutName );
}
return false;
}
//-----------------------------------------------------------------------------
// Remove entry from dictionary, Returns TRUE if removed.
//-----------------------------------------------------------------------------
bool RemoveFileFromResourceList( const char *pFilename, CUtlRBTree< CUtlString, int > *pTree )
{
char szOutName[MAX_PATH];
char *pOutName;
V_strncpy( szOutName, pFilename, sizeof( szOutName ) );
V_FixSlashes( szOutName );
V_RemoveDotSlashes( szOutName );
V_strlower( szOutName );
pOutName = szOutName;
// strip any prefixed game name
for ( int i = 0; g_GameNames[i] != NULL; i++ )
{
size_t len = strlen( g_GameNames[i] );
if ( !V_strnicmp( pOutName, g_GameNames[i], len ) && pOutName[len] == '\\' )
{
// skip past game name and slash
pOutName += len+1;
break;
}
}
if ( pTree->Find( pOutName ) != pTree->InvalidIndex() )
{
pTree->Remove( pOutName );
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Generate a tree containing files from a reslist. Returns TRUE if successful.
//-----------------------------------------------------------------------------
bool LoadReslist( const char *pReslistName, CUtlRBTree< CUtlString, int > *pTree )
{
CUtlBuffer buffer;
if ( !scriptlib->ReadFileToBuffer( pReslistName, buffer, true ) )
{
return false;
}
char szBasename[MAX_PATH];
V_FileBase( pReslistName, szBasename, sizeof( szBasename ) );
characterset_t breakSet;
CharacterSetBuild( &breakSet, "" );
// parse reslist
char szToken[MAX_PATH];
char szBspName[MAX_PATH];
szBspName[0] = '\0';
for ( ;; )
{
int nTokenSize = buffer.ParseToken( &breakSet, szToken, sizeof( szToken ) );
if ( nTokenSize <= 0 )
{
break;
}
// reslists are pc built, filenames can be sloppy
V_strlower( szToken );
V_FixSlashes( szToken );
V_RemoveDotSlashes( szToken );
// can safely cull filetypes that are ignored by queued loader at runtime
bool bKeep = false;
const char *pExt = V_GetFileExtension( szToken );
if ( !pExt )
{
// unknown
continue;
}
else if ( !V_stricmp( pExt, "vmt" ) ||
!V_stricmp( pExt, "vhv" ) ||
!V_stricmp( pExt, "mdl" ) ||
!V_stricmp( pExt, "raw" ) ||
!V_stricmp( pExt, "wav" ) )
{
bKeep = true;
}
else if ( !V_stricmp( pExt, "mp3" ) )
{
// change to .wav
V_SetExtension( szToken, ".wav", sizeof( szToken ) );
bKeep = true;
}
else if ( !V_stricmp( pExt, "bsp" ) )
{
// reslists erroneously have multiple bsps
if ( !V_stristr( szToken, szBasename ) )
{
// wrong one, cull it
continue;
}
else
{
// right one, save it
strcpy( szBspName, szToken );
bKeep = true;
}
}
if ( bKeep )
{
FindOrAddFileToResourceList( szToken, pTree );
}
}
if ( !szBspName[0] )
{
// reslist is not bsp derived, nothing more to do
return true;
}
CUtlVector< CUtlString > bspList;
bool bOK = GetDependants_BSP( szBspName, &bspList );
if ( !bOK )
{
return false;
}
// add all the bsp dependants to the resource list
for ( int i=0; i<bspList.Count(); i++ )
{
FindOrAddFileToResourceList( bspList[i].String(), pTree );
}
// iterate all the models in the resource list, get all their dependents
CUtlVector< CUtlString > modelList;
for ( int i = pTree->FirstInorder(); i != pTree->InvalidIndex(); i = pTree->NextInorder( i ) )
{
const char *pExt = V_GetFileExtension( pTree->Element( i ).String() );
if ( !pExt || V_stricmp( pExt, "mdl" ) )
{
continue;
}
if ( !GetDependants_MDL( pTree->Element( i ).String(), &modelList ) )
{
return false;
}
}
// add all the model dependents to the resource list
for ( int i=0; i<modelList.Count(); i++ )
{
FindOrAddFileToResourceList( modelList[i].String(), pTree );
}
// check for optional commentary, include wav dependencies
char szCommentaryName[MAX_PATH];
V_ComposeFileName( g_szGamePath, szBspName, szCommentaryName, sizeof( szCommentaryName ) );
V_StripExtension( szCommentaryName, szCommentaryName, sizeof( szCommentaryName ) );
V_strncat( szCommentaryName, "_commentary.txt", sizeof( szCommentaryName ) );
CUtlBuffer commentaryBuffer;
if ( ReadFileToBuffer( szCommentaryName, commentaryBuffer, true, true ) )
{
// any single token may be quite large to due to text
char szCommentaryToken[8192];
for ( ;; )
{
int nTokenSize = commentaryBuffer.ParseToken( &breakSet, szCommentaryToken, sizeof( szCommentaryToken ) );
if ( nTokenSize < 0 )
{
break;
}
if ( nTokenSize > 0 && !V_stricmp( szCommentaryToken, "commentaryfile" ) )
{
// get the commentary file
nTokenSize = commentaryBuffer.ParseToken( &breakSet, szCommentaryToken, sizeof( szCommentaryToken ) );
if ( nTokenSize > 0 )
{
// skip past sound chars
char *pName = szCommentaryToken;
while ( *pName && IsSoundChar( *pName ) )
{
pName++;
}
char szWavFile[MAX_PATH];
V_snprintf( szWavFile, sizeof( szWavFile ), "sound/%s", pName );
FindOrAddFileToResourceList( szWavFile, pTree );
}
}
}
}
// check for optional blacklist
char szBlacklist[MAX_PATH];
V_ComposeFileName( g_szGamePath, "reslistfixes_xbox.xsc", szBlacklist, sizeof( szBlacklist ) );
CUtlBuffer blacklistBuffer;
if ( ReadFileToBuffer( szBlacklist, blacklistBuffer, true, true ) )
{
for ( ;; )
{
int nTokenSize = blacklistBuffer.ParseToken( &breakSet, szToken, sizeof( szToken ) );
if ( nTokenSize <= 0 )
{
break;
}
bool bAdd;
if ( !V_stricmp( szToken, "-" ) )
{
bAdd = false;
}
else if ( !V_stricmp( szToken, "+" ) )
{
bAdd = true;
}
else
{
// bad syntax, skip line
Msg( "Bad Syntax, expecting '+' or '-' as first token in reslist fixup file '%s'.\n", szBlacklist );
continue;
}
// get entry
nTokenSize = blacklistBuffer.ParseToken( &breakSet, szToken, sizeof( szToken ) );
if ( nTokenSize <= 0 )
{
break;
}
if ( bAdd )
{
FindOrAddFileToResourceList( szToken, pTree );
}
else
{
RemoveFileFromResourceList( szToken, pTree );
}
}
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Generate .360 compiled reslist files
// Reslist files are processed for the unique consumption of Queued Loading.
//-----------------------------------------------------------------------------
bool CreateTargetFile_RESLST( const char *pSourceName, const char *pTargetName, bool bWriteToZip )
{
bool bOK = false;
// parse reslist
CUtlRBTree< CUtlString, int > rbTree( 0, 0, ReslistLessFunc );
if ( !LoadReslist( pSourceName, &rbTree ) )
{
return false;
}
CUtlBuffer targetBuffer( 0, 0, CUtlBuffer::TEXT_BUFFER );
for ( int iIndex = rbTree.FirstInorder(); iIndex != rbTree.InvalidIndex(); iIndex = rbTree.NextInorder( iIndex ) )
{
targetBuffer.PutChar( '\"' );
targetBuffer.PutString( rbTree[iIndex].String() );
targetBuffer.PutChar( '\"' );
targetBuffer.PutString( "\n" );
}
bOK = WriteBufferToFile( pTargetName, targetBuffer, bWriteToZip, g_WriteModeForConversions );
return bOK;
}
|