Skip to content

Commit 940cb45

Browse files
committed
SCUMM: Add a tool for extracting nd4 archive as used by floppy version of indy4
1 parent b13559c commit 940cb45

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

Makefile.common

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ PROGRAMS = \
4141
extract_hadesch_img \
4242
extract_lokalizator \
4343
extract_mps \
44+
extract_lfg \
4445
grim_animb2txt \
4546
grim_bm2bmp \
4647
grim_cosb2cos \
@@ -160,6 +161,11 @@ extract_mps_OBJS := \
160161
common/dcl.o \
161162
$(UTILS)
162163

164+
extract_lfg_OBJS := \
165+
engines/scumm/extract_lfg.o \
166+
common/dcl.o \
167+
$(UTILS)
168+
163169
deprince_OBJS := \
164170
engines/prince/deprince.o \
165171
engines/prince/flags.o \

engines/scumm/extract_lfg.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/* ScummVM Tools
2+
*
3+
* ScummVM Tools is the legal property of its developers, whose names
4+
* are too numerous to list here. Please refer to the COPYRIGHT
5+
* file distributed with this source distribution.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#include "common/endian.h"
23+
#include "common/memstream.h"
24+
#include "common/file.h"
25+
#include "common/str.h"
26+
#include "common/util.h"
27+
#include "common/dcl.h"
28+
#include <stdio.h>
29+
#include <stdlib.h>
30+
#include <string.h>
31+
#include <errno.h>
32+
33+
int main (int argc, char **argv) {
34+
unsigned char *buf = nullptr;
35+
size_t inSize = 0;
36+
37+
if (argc < 3) {
38+
fprintf (stderr, "USAGE: %s OUTDIR VOLUMES\n", argv[0]);
39+
return -1;
40+
}
41+
42+
for (int i = 2; i < argc; i++) {
43+
FILE *fin = fopen (argv[i], "rb");
44+
byte head[8];
45+
if (fin == NULL) {
46+
fprintf (stderr, "Unable to open %s: %s\n", argv[i], strerror(errno));
47+
free (buf);
48+
return -2;
49+
}
50+
fread (head, 1, 8, fin);
51+
if (READ_BE_UINT32(head) != MKTAG('L', 'F', 'G', '!')) {
52+
fprintf (stderr, "%s doesn't contain magic\n", argv[i]);
53+
free (buf);
54+
return -2;
55+
}
56+
uint32 volumeSize = READ_LE_UINT32(head + 4);
57+
uint32 oldInSize = inSize;
58+
inSize += volumeSize;
59+
60+
buf = (byte *) realloc (buf, inSize);
61+
fread (buf + oldInSize, 1, volumeSize, fin);
62+
fclose (fin);
63+
}
64+
65+
printf("Archive name: %s\n", buf);
66+
printf("Value A=0x%x\n", buf[13]);
67+
printf("Number of volumes=%d\n", READ_LE_UINT16(buf+14));
68+
printf("Total number of bytes=%d\n", READ_LE_UINT32(buf+16));
69+
70+
for (byte *ptr = buf + 0x14; ptr < buf + inSize;) {
71+
uint32 magic = READ_BE_UINT32(ptr);
72+
if (magic != MKTAG('F', 'I', 'L', 'E')) {
73+
printf("Wrong magic: %x @ %x\n", magic, (int)(ptr - buf));
74+
free (buf);
75+
return 0;
76+
}
77+
uint32 blocklen = READ_LE_UINT32(ptr + 4);
78+
byte *blockend = ptr + 8 + blocklen;
79+
ptr += 8;
80+
Common::String name((char *)ptr, 13);
81+
ptr += 13;
82+
Common::File fout(Common::String::format("%s/%s", argv[1], name.c_str()), "wb");
83+
uint32 uncompressedSize = READ_LE_UINT32(ptr + 1);
84+
printf("name: %s\n", name.c_str());
85+
printf("value B=0x%x\n", ptr[0]);
86+
// ptr[0] seems to be const in the same archive. So far:
87+
// 0x13: indy4 demo
88+
// 0x17: indy4 full
89+
// ptr + 5 is always 02 00 01 00 00 00 so far
90+
printf("value C:\n");
91+
hexdump(ptr + 5, 6);
92+
// Most likely it contains compression somewhere
93+
ptr += 11;
94+
95+
uint32 compressedSize = blockend - ptr;
96+
byte *uncompressedBuf = nullptr;
97+
98+
// DCL. TODO: Support uncompressed if needed
99+
Common::MemoryReadStream compressedReadStream(ptr, compressedSize);
100+
uncompressedBuf = new byte[uncompressedSize];
101+
if (!Common::decompressDCL(&compressedReadStream, uncompressedBuf, compressedSize, uncompressedSize)) {
102+
fprintf (stderr, "Unable to decompress %s\n", name.c_str());
103+
delete[] uncompressedBuf;
104+
continue;
105+
}
106+
107+
fout.write(uncompressedBuf, uncompressedSize);
108+
ptr = blockend;
109+
110+
delete[] uncompressedBuf;
111+
}
112+
113+
free (buf);
114+
115+
return 0;
116+
}

0 commit comments

Comments
 (0)