1 // This software is not affiliated with Valve Corporation
2 // We are not affiliated, associated, authorized, endorsed by, or in any way officially
3 // connected with Valve Corporation, or any of its subsidiaries or its affiliates.
5 // All trademarks are property of their respective owners
7 // Valve pak file directory reader
10 //=======================================================================================================================
12 typedef struct VPKHeader VPKHeader
;
13 typedef struct VPKDirectoryEntry VPKDirectoryEntry
;
18 // There is no load function, reading the header file as binary is enough.
19 VPKDirectoryEntry
*vpk_find( VPKHeader
*self
, const char *asset
);
20 void vpk_free( VPKHeader
*self
);
28 u32 FileDataSectionSize
;
29 u32 ArchiveMD5SectionSize
;
30 u32 OtherMD5SectionSize
;
31 u32 SignatureSectionSize
;
34 struct VPKDirectoryEntry
45 #ifdef VALVE_IMPLEMENTATION
47 void vpk_free( VPKHeader
*self
)
52 VPKDirectoryEntry
*vpk_find( VPKHeader
*self
, const char *asset
)
58 strcpy( wbuf
, asset
);
60 char *ext
= csr_findext( wbuf
, '.' );
62 char *fn
= csr_findext( wbuf
, '/' );
66 char *pCur
= ((char *)self
) + sizeof( VPKHeader
);
72 int bExt
= !strcmp( ext
, pCur
);
74 while( *( pCur
++ ) ) {};
77 if( !*pCur
) { pCur
++; break; }
79 int bDir
= !strcmp( dir
, pCur
);
81 while( *( pCur
++ ) ) {};
84 if( !*pCur
) { pCur
++; break; }
86 const char *vpk_fn
= pCur
;
88 while( *( pCur
++ ) ) {};
89 VPKDirectoryEntry
*entry
= (VPKDirectoryEntry
*)pCur
;
91 if( !strcmp( vpk_fn
, fn
) && bExt
&& bDir
)
96 pCur
+= entry
->PreloadBytes
+ sizeof( VPKDirectoryEntry
);
99 if( bDir
&& bExt
) return NULL
;
102 if( bExt
) return NULL
;