Skip to content

Commit 9b0d1f7

Browse files
committed
GOB: Implement an unpackData() extension used in some games
This extension allows larger strings to be copied from the LZ77-sliding window when unpacking.
1 parent 68396c1 commit 9b0d1f7

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

engines/gob/extract_gob_stk.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,33 @@ void ExtractGobStk::extractChunks(Common::Filename &outpath, Common::File &stk)
319319
byte *ExtractGobStk::unpackData(byte *src, uint32 &size) {
320320
uint32 counter;
321321
uint16 cmd;
322-
byte tmpBuf[4114];
322+
byte tmpBuf[4370]; // 4096 + (256 + 18) = 4096 + (max string length)
323323
int16 off;
324-
byte len;
324+
int16 len;
325325
uint16 tmpIndex;
326326

327327
counter = size = READ_LE_UINT32(src);
328+
src += 4;
329+
uint16 magic1 = READ_LE_UINT16(src);
330+
src += 2;
331+
uint16 magic2 = READ_LE_UINT16(src);
332+
src += 2;
328333

329-
for (int i = 0; i < 4078; i++)
330-
tmpBuf[i] = 0x20;
331-
tmpIndex = 4078;
334+
int16 extendedLenCmd;
335+
if ((magic1 == 0x1234) && (magic2 == 0x5678)) {
336+
// Extended format allowing to copy larger strings
337+
// from the window (up to 256 + 18 = 274 bytes).
338+
extendedLenCmd = 18;
339+
tmpIndex = 273;
340+
} else {
341+
// Standard format allowing to copy short strings
342+
// (up to 18 bytes) from the window.
343+
extendedLenCmd = 100; // Cannot be matched
344+
tmpIndex = 4078;
345+
src -= 4;
346+
}
332347

333-
src += 4;
348+
memset(tmpBuf, 0x20, tmpIndex); // Fill initial window with spaces
334349

335350
byte *unpacked = new byte[size];
336351
byte *dest = unpacked;
@@ -358,6 +373,11 @@ byte *ExtractGobStk::unpackData(byte *src, uint32 &size) {
358373
len = (*src & 0x0F) + 3;
359374
src++;
360375

376+
if (len == extendedLenCmd) {
377+
len = *src + 18;
378+
src++;
379+
}
380+
361381
for (int i = 0; i < len; i++) {
362382
*dest++ = tmpBuf[(off + i) % 4096];
363383
if (--counter == 0)

0 commit comments

Comments
 (0)