Our code does a search for the signature.
There's code for this in src/public/zip_utils.cpp. If that's not in the
sdk then here's the relevant code:
//----------------------------------------------------------------------
-------
// Purpose: Load pak file from raw buffer
// Input : *buffer -
// bufferlength -
//----------------------------------------------------------------------
-------
void CZipFile::ParseFromBuffer( void *buffer, int bufferlength )
{
// Throw away old data
Reset();
// Initialize a buffer
CUtlBuffer buf( 0, bufferlength +1 );
// +1 for null termination
// need to swap bytes, so set the buffer opposite the machine's
endian
buf.ActivateByteSwapping( m_Swap.IsSwappingBytes() );
buf.Put( buffer, bufferlength );
buf.SeekGet( CUtlBuffer::SEEK_TAIL, 0 );
unsigned int fileLen = buf.TellGet();
// Start from beginning
buf.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
unsigned int offset;
ZIP_EndOfCentralDirRecord rec = { 0 };
bool bFoundEndOfCentralDirRecord = false;
for ( offset = fileLen - sizeof( ZIP_EndOfCentralDirRecord );
offset >= 0; offset-- )
{
buf.SeekGet( CUtlBuffer::SEEK_HEAD, offset );
buf.GetObjects( &rec );
if ( rec.signature == PKID( 5, 6 ) )
{
bFoundEndOfCentralDirRecord = true;
// Set any xzip configuration
if ( rec.commentLength )
{
char commentString[128];
int commentLength = min(
rec.commentLength, sizeof( commentString ) );
buf.Get( commentString, commentLength );
commentString[commentLength] = '\0';
ParseXZipCommentString( commentString );
}
break;
}
else
{
// wrong record
rec.nCentralDirectoryEntries_Total = 0;
}
}
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Mark Chandler
> Sent: Wednesday, May 14, 2008 8:33 PM
> To: 'Discussion of Half-Life Programming'
> Subject: Re: [hlcoders] Pakfile Lump Reading
>
> Just read in every thing but the comment into the struct.
> Grab the size of the comment then read the comment. Not to
> hard as I have done this about a week ago.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> theY4Kman
> Sent: Thursday, May 15, 2008 10:00 AM
> To: Discussion of Half-Life Programming
> Subject: Re: [hlcoders] Pakfile Lump Reading
>
> I don't believe you understand my message correctly. The
> ZIP_EndOfCentralDirRecord is essentially at the end of the
> file. One would parse the file by fseek'ing to
> (EOF-sizeof(ZIP_EndOfCentralDirRecord)) and fread'ing in the struct.
> However, since the comment is of variable length, there is no
> way to correctly read in the ZIP_EndOfCentralDirRecord. Thus,
> there is no way to access commentLength.
>
> On Wed, May 14, 2008 at 9:53 PM, Mark Chandler
> <[EMAIL PROTECTED]> wrote:
>
> > You can work out the size of the comment by commentLength
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of
> > theY4Kman
> > Sent: Thursday, May 15, 2008 8:18 AM
> > To: Discussion of Half-Life Programming
> > Subject: [hlcoders] Pakfile Lump Reading
> >
> > I'm developing a C++ extension for SourceMod which will extract the
> > files stored in the Pakfile lump of a BSP. I read over the
> page, "The
> > Source Engine BSP File Format
> > <http://www.geocities.com/cofrdrbob/bspformat.html
> > >,"
> > by Rof and it has helped me a lot. I've been trying to retrieve the
> > list
> of
> > ZIP_FileHeaders, but I've had some trouble: I don't know how it's
> > possible to get the ZIP_EndOfCentralDirRecord. Rof's page
> states that
> > this struct
> is
> > at the end of the Pakfile lump. However, the struct has a variable
> > length comment at the end of it. The only way I can know
> the size of
> > that comment is to have the ZIP_EndOfCentralDirRecord at
> hand...You can see my dilemma.
> >
> > struct ZIP_EndOfCentralDirRecord
> > {
> > DECLARE_BYTESWAP_DATADESC();
> > unsigned int signature; // 4 bytes PK56
> > unsigned short numberOfThisDisk; // 2 bytes
> > unsigned short
> numberOfTheDiskWithStartOfCentralDirectory; // 2
> bytes
> > unsigned short nCentralDirectoryEntries_ThisDisk;
> // 2 bytes
> > unsigned short nCentralDirectoryEntries_Total; // 2 bytes
> > unsigned int centralDirectorySize; // 4 bytes
> > unsigned int startOfCentralDirOffset; // 4 bytes
> > unsigned short commentLength; // 2 bytes
> > // zip file comment follows
> > };
> > _______________________________________________
> > To unsubscribe, edit your list preferences, or view the
> list archives,
> > please visit:
> > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >
> > _______________________________________________
> > To unsubscribe, edit your list preferences, or view the
> list archives,
> > please visit:
> > http://list.valvesoftware.com/mailman/listinfo/hlcoders
> >
> >
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list
> archives, please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list
> archives, please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
>
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders