Fix vpk support.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6048 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2021-08-28 07:04:37 +00:00
parent c73b9774da
commit 8c7c69a4ea
3 changed files with 32 additions and 19 deletions

View file

@ -907,6 +907,7 @@ COMMON_OBJS = \
fs_stdio.o \ fs_stdio.o \
fs_pak.o \ fs_pak.o \
fs_zip.o \ fs_zip.o \
fs_vpk.o \
fs_dzip.o \ fs_dzip.o \
fs_xz.o \ fs_xz.o \
m_download.o \ m_download.o \

View file

@ -54,7 +54,7 @@
#define PACKAGE_PK3 //aka zips. we support utf8,zip64,spans,weakcrypto,(deflate),(bzip2),symlinks. we do not support strongcrypto nor any of the other compression schemes. #define PACKAGE_PK3 //aka zips. we support utf8,zip64,spans,weakcrypto,(deflate),(bzip2),symlinks. we do not support strongcrypto nor any of the other compression schemes.
#define PACKAGE_Q1PAK //also q2 #define PACKAGE_Q1PAK //also q2
//#define PACKAGE_DOOMWAD //doom wad support (generates various file names, and adds support for doom's audio, sprites, etc) //#define PACKAGE_DOOMWAD //doom wad support (generates various file names, and adds support for doom's audio, sprites, etc)
//#define PACKAGE_VPK //hl2 packages #define PACKAGE_VPK //HalfLife2's packages
#define AVAIL_XZDEC //.xz decompression #define AVAIL_XZDEC //.xz decompression
#define AVAIL_GZDEC //.gz decompression #define AVAIL_GZDEC //.gz decompression
#define AVAIL_ZLIB //whether pk3s can be compressed or not. #define AVAIL_ZLIB //whether pk3s can be compressed or not.

View file

@ -90,7 +90,7 @@ static void QDECL FSVPK_ClosePath(searchpathfuncs_t *handle)
for (i = 0; i < pak->numfragments; i++) for (i = 0; i < pak->numfragments; i++)
{ {
if (pak->fragments[i]) if (pak->fragments[i])
pak->fragments[i]->Close(pak->fragments[i]); pak->fragments[i]->pub.ClosePath(&pak->fragments[i]->pub);
pak->fragments[i] = NULL; pak->fragments[i] = NULL;
} }
Z_Free(pak->fragments); Z_Free(pak->fragments);
@ -188,27 +188,34 @@ typedef struct {
static int QDECL VFSVPK_ReadBytes (struct vfsfile_s *vfs, void *buffer, int bytestoread) static int QDECL VFSVPK_ReadBytes (struct vfsfile_s *vfs, void *buffer, int bytestoread)
{ {
vfsvpk_t *vfsp = (void*)vfs; vfsvpk_t *vfsp = (void*)vfs;
int read; int read, preread;
if (bytestoread <= 0) if (bytestoread <= 0)
return 0; return 0;
if (vfsp->currentpos < vfsp->preloadsize) if (vfsp->currentpos < vfsp->preloadsize)
{ {
read = bytestoread; preread = bytestoread;
if (read > vfsp->preloadsize-vfsp->currentpos) if (preread > vfsp->preloadsize-vfsp->currentpos)
read = vfsp->preloadsize-vfsp->currentpos; preread = vfsp->preloadsize-vfsp->currentpos;
memcpy(buffer, vfsp->preloaddata, read); if (preread < 0)
vfsp->currentpos += read; return -1; //erk...
if (read == bytestoread) memcpy(buffer, vfsp->preloaddata+vfsp->currentpos, preread);
return read; //we're done, no need to seek etc vfsp->currentpos += preread;
bytestoread -= read; if (preread == bytestoread)
return preread; //we're done, no need to seek etc
bytestoread -= preread;
buffer = (char*)buffer+preread;
} }
else
preread = 0;
if (vfsp->currentpos-vfsp->preloadsize + bytestoread > vfsp->length) if (vfsp->currentpos + bytestoread > vfsp->length)
bytestoread = vfsp->length - (vfsp->currentpos-vfsp->preloadsize); bytestoread = vfsp->length - vfsp->currentpos;
if (bytestoread <= 0) if (bytestoread <= 0)
{ {
if (preread)
return preread;
return -1; return -1;
} }
@ -218,12 +225,17 @@ static int QDECL VFSVPK_ReadBytes (struct vfsfile_s *vfs, void *buffer, int byte
VFS_SEEK(vfsp->parentpak->handle, vfsp->startpos+vfsp->currentpos-vfsp->preloadsize); VFS_SEEK(vfsp->parentpak->handle, vfsp->startpos+vfsp->currentpos-vfsp->preloadsize);
read = VFS_READ(vfsp->parentpak->handle, buffer, bytestoread); read = VFS_READ(vfsp->parentpak->handle, buffer, bytestoread);
if (read > 0) if (read > 0)
{
vfsp->currentpos += read; vfsp->currentpos += read;
read += preread;
}
else if (preread)
read = preread;
vfsp->parentpak->filepos = vfsp->startpos+vfsp->currentpos-vfsp->preloadsize; vfsp->parentpak->filepos = vfsp->startpos+vfsp->currentpos-vfsp->preloadsize;
Sys_UnlockMutex(vfsp->parentpak->mutex); Sys_UnlockMutex(vfsp->parentpak->mutex);
} }
else else
read = 0; read = preread;
return read; return read;
} }
@ -237,14 +249,14 @@ static qboolean QDECL VFSVPK_Seek (struct vfsfile_s *vfs, qofs_t pos)
vfsvpk_t *vfsp = (void*)vfs; vfsvpk_t *vfsp = (void*)vfs;
if (pos > vfsp->length) if (pos > vfsp->length)
return false; return false;
vfsp->currentpos = pos + vfsp->startpos; vfsp->currentpos = pos;// + vfsp->startpos;
return true; return true;
} }
static qofs_t QDECL VFSVPK_Tell (struct vfsfile_s *vfs) static qofs_t QDECL VFSVPK_Tell (struct vfsfile_s *vfs)
{ {
vfsvpk_t *vfsp = (void*)vfs; vfsvpk_t *vfsp = (void*)vfs;
return vfsp->currentpos - vfsp->startpos; return vfsp->currentpos;// - vfsp->startpos;
} }
static qofs_t QDECL VFSVPK_GetLen (struct vfsfile_s *vfs) static qofs_t QDECL VFSVPK_GetLen (struct vfsfile_s *vfs)
{ {
@ -293,7 +305,7 @@ static vfsfile_t *QDECL FSVPK_OpenVFS(searchpathfuncs_t *handle, flocation_t *lo
#ifdef _DEBUG #ifdef _DEBUG
{ {
mpackfile_t *pf = loc->fhandle; mvpkfile_t *pf = loc->fhandle;
Q_strncpyz(vfs->funcs.dbgname, pf->name, sizeof(vfs->funcs.dbgname)); Q_strncpyz(vfs->funcs.dbgname, pf->name, sizeof(vfs->funcs.dbgname));
} }
#endif #endif
@ -430,8 +442,8 @@ searchpathfuncs_t *QDECL FSVPK_LoadArchive (vfsfile_t *file, searchpathfuncs_t *
i = LittleLong(header.version); i = LittleLong(header.version);
if (i == 2) if (i == 2)
;//VFS_SEEK(packhandle, 7*sizeof(int)); ;//VFS_SEEK(packhandle, 7*sizeof(int));
// else if (i == 1) else if (i == 1)
// VFS_SEEK(packhandle, 3*sizeof(int)); VFS_SEEK(packhandle, 3*sizeof(int));
else else
{ {
Con_Printf("vpk %s is version %x (unspported)\n", desc, i); Con_Printf("vpk %s is version %x (unspported)\n", desc, i);