author | Wuzzy <Wuzzy2@mail.ru> |
Sun, 02 Sep 2018 00:07:33 +0200 | |
changeset 13741 | 2ac3658a2a13 |
parent 12218 | bb5522e88ab2 |
permissions | -rw-r--r-- |
7768 | 1 |
/* |
2 |
* QPAK support routines for PhysicsFS. |
|
3 |
* |
|
4 |
* This archiver handles the archive format utilized by Quake 1 and 2. |
|
5 |
* Quake3-based games use the PkZip/Info-Zip format (which our zip.c |
|
6 |
* archiver handles). |
|
7 |
* |
|
8 |
* ======================================================================== |
|
9 |
* |
|
10 |
* This format info (in more detail) comes from: |
|
11 |
* http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/pak.txt |
|
12 |
* |
|
13 |
* Quake PAK Format |
|
14 |
* |
|
15 |
* Header |
|
16 |
* (4 bytes) signature = 'PACK' |
|
17 |
* (4 bytes) directory offset |
|
18 |
* (4 bytes) directory length |
|
19 |
* |
|
20 |
* Directory |
|
21 |
* (56 bytes) file name |
|
22 |
* (4 bytes) file position |
|
23 |
* (4 bytes) file length |
|
24 |
* |
|
25 |
* ======================================================================== |
|
26 |
* |
|
27 |
* Please see the file LICENSE.txt in the source's root directory. |
|
28 |
* |
|
29 |
* This file written by Ryan C. Gordon. |
|
30 |
*/ |
|
31 |
||
32 |
#define __PHYSICSFS_INTERNAL__ |
|
33 |
#include "physfs_internal.h" |
|
34 |
||
35 |
#if PHYSFS_SUPPORTS_QPAK |
|
36 |
||
37 |
#define QPAK_SIG 0x4B434150 /* "PACK" in ASCII. */ |
|
38 |
||
39 |
static UNPKentry *qpakLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 fileCount) |
|
40 |
{ |
|
41 |
UNPKentry *entries = NULL; |
|
42 |
UNPKentry *entry = NULL; |
|
43 |
||
44 |
entries = (UNPKentry *) allocator.Malloc(sizeof (UNPKentry) * fileCount); |
|
45 |
BAIL_IF_MACRO(entries == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
|
46 |
||
47 |
for (entry = entries; fileCount > 0; fileCount--, entry++) |
|
48 |
{ |
|
49 |
if (!__PHYSFS_readAll(io, &entry->name, 56)) goto failed; |
|
50 |
if (!__PHYSFS_readAll(io, &entry->startPos, 4)) goto failed; |
|
51 |
if (!__PHYSFS_readAll(io, &entry->size, 4)) goto failed; |
|
52 |
entry->size = PHYSFS_swapULE32(entry->size); |
|
53 |
entry->startPos = PHYSFS_swapULE32(entry->startPos); |
|
54 |
} /* for */ |
|
55 |
||
56 |
return entries; |
|
57 |
||
58 |
failed: |
|
59 |
allocator.Free(entries); |
|
60 |
return NULL; |
|
61 |
} /* qpakLoadEntries */ |
|
62 |
||
63 |
||
64 |
static void *QPAK_openArchive(PHYSFS_Io *io, const char *name, int forWriting) |
|
65 |
{ |
|
66 |
UNPKentry *entries = NULL; |
|
67 |
PHYSFS_uint32 val = 0; |
|
68 |
PHYSFS_uint32 pos = 0; |
|
69 |
PHYSFS_uint32 count = 0; |
|
70 |
||
71 |
assert(io != NULL); /* shouldn't ever happen. */ |
|
72 |
||
73 |
BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); |
|
74 |
||
75 |
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL); |
|
76 |
if (PHYSFS_swapULE32(val) != QPAK_SIG) |
|
77 |
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); |
|
78 |
||
79 |
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL); |
|
80 |
pos = PHYSFS_swapULE32(val); /* directory table offset. */ |
|
81 |
||
82 |
BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL); |
|
83 |
count = PHYSFS_swapULE32(val); |
|
84 |
||
85 |
/* corrupted archive? */ |
|
86 |
BAIL_IF_MACRO((count % 64) != 0, PHYSFS_ERR_CORRUPT, NULL); |
|
87 |
count /= 64; |
|
88 |
||
89 |
BAIL_IF_MACRO(!io->seek(io, pos), ERRPASS, NULL); |
|
90 |
||
91 |
entries = qpakLoadEntries(io, count); |
|
92 |
BAIL_IF_MACRO(!entries, ERRPASS, NULL); |
|
93 |
return UNPK_openArchive(io, entries, count); |
|
94 |
} /* QPAK_openArchive */ |
|
95 |
||
96 |
||
97 |
const PHYSFS_Archiver __PHYSFS_Archiver_QPAK = |
|
98 |
{ |
|
12218
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
99 |
CURRENT_PHYSFS_ARCHIVER_API_VERSION, |
7768 | 100 |
{ |
101 |
"PAK", |
|
102 |
"Quake I/II format", |
|
103 |
"Ryan C. Gordon <icculus@icculus.org>", |
|
12218
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
104 |
"https://icculus.org/physfs/", |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
105 |
0, /* supportsSymlinks */ |
7768 | 106 |
}, |
12218
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
107 |
QPAK_openArchive, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
108 |
UNPK_enumerateFiles, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
109 |
UNPK_openRead, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
110 |
UNPK_openWrite, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
111 |
UNPK_openAppend, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
112 |
UNPK_remove, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
113 |
UNPK_mkdir, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
114 |
UNPK_stat, |
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
115 |
UNPK_closeArchive |
7768 | 116 |
}; |
117 |
||
118 |
#endif /* defined PHYSFS_SUPPORTS_QPAK */ |
|
119 |
||
12218
bb5522e88ab2
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents:
8524
diff
changeset
|
120 |
/* end of archiver_qpak.c ... */ |
7768 | 121 |