if( !fs->directory_tree )
return NULL;
+
+ if( !asset )
+ return NULL;
char wbuf[ 512 ];
strcpy( wbuf, asset );
if( entry->ArchiveIndex == 0x7fff )
{
snprintf( pak, 1023, "%scsgo/pak01_dir.vpk", fs->exedir );
+ cxr_log( "locate %s\n", pak );
}
else
{
snprintf( pak, 1023, "%scsgo/pak01_%03hu.vpk",
fs->exedir, entry->ArchiveIndex );
+ cxr_log( "locate %s\n", pak );
}
fs->current_archive = fopen( pak, "rb" );
* File is stored in the index, after the tree
*/
if( entry->ArchiveIndex == 0x7fff )
+ {
offset += fs->vpk.TreeSize + sizeof(VPKHeader);
+ }
/*
* Entire file is stored in the preload bytes;
fseek( fs->current_archive, offset, SEEK_SET );
size_t alloc_size = stringbuffer? length+1: length;
- char *filebuf = malloc( alloc_size );
+ char *filebuf = malloc( alloc_size ),
+ *fullfile = filebuf;
if( stringbuffer )
- filebuf[length] = 0x00;
+ fullfile[length] = 0x00;
+
+ if( entry->PreloadBytes )
+ {
+ memcpy( filebuf, ((char *)entry) + sizeof(VPKDirectoryEntry),
+ entry->PreloadBytes );
+
+ filebuf += entry->PreloadBytes;
+ length -= entry->PreloadBytes;
+
+ /* TODO, this can sometimes come from the same index file.
+ * very small performance gain can be made */
+ }
if( fread( filebuf, 1, length, fs->current_archive ) == length )
- return filebuf;
+ {
+ return fullfile;
+ }
else
{
/* Invalid read */
{
char **sp = cxr_ab_ptr( &fs->searchpaths, i );
- snprintf( locator->path, 1023, "%s%s", *sp, path );
+ snprintf( locator->path, 1024, "%s%s", *sp, path );
if( cxr_file_exists( locator->path ) )
return 1;
int sznameindex;
int flags;
int used;
-
- /* There is some extra unused stuff that was here...
- * Luckily since byte offsets are used, structure size doesn't matter */
+ int unused1;
+ int garbage[12]; /* contains some studiomdl pointers */
}
mstudiotexture_t;
const char *name = mstudiotexture_pszName( tex );
model->materials[i] = NULL;
+
+ cxr_log( "search: %s\n", name );
for( int j=0; j<model->studiohdr->numcdtextures; j++ )
{
char *cdpath = studiohdr_pCdtexture( model->studiohdr, j );
snprintf( material_path, 1023, "materials/%s%s.vmt", cdpath, name );
cxr_unixpath( material_path );
+ cxr_lowercase( material_path );
if( cxr_fs_find( material_path, &locator ))
{
break;
}
}
+
}
u32 i_index = 0,
return buf;
}
+static void cxr_str_debug( const char *str )
+{
+ cxr_log( "\n=== string debug ( %p ) === \n'", str );
+ const char *y = str;
+
+ while(*y)
+ {
+ if( *y == '\r' )
+ cxr_log( "<CR>" );
+ else if( *y == '\n' )
+ cxr_log( "<LF>\n" );
+ else
+ cxr_log( "%c", *y);
+ y ++;
+ }
+ cxr_log( "<EOF>'\n" );
+}
+
CXR_API valve_material *valve_load_material( const char *path )
{
char *vmt = cxr_fs_get( path, 1 );
if( vmt )
{
+#if 0
+ cxr_str_debug( vmt );
+#endif
valve_material *material = malloc( sizeof(valve_material) );
vdf_node *vmt_root = vdf_from_buffer( vmt );
{
cxr_log( "Error: vmt has no nodes\n" );
free( vmt );
+ free( material );
vdf_free_r( vmt_root );
- return 0;
+ return NULL;
}
vdf_node **body = cxr_ab_ptr( &vmt_root->abnodes, 0 );
{
free( material->basetexture );
free( material->bumpmap );
+ free( material );
}
#endif /* CXR_VALVE_BIN_H */