Skip to content

Commit

Permalink
GRIM/GROOVIE: Move StuffIt archive code to Common (#2509)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 committed Oct 11, 2020
1 parent f2a7b58 commit d1d305d
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 595 deletions.
1 change: 1 addition & 0 deletions common/module.mk
Expand Up @@ -35,6 +35,7 @@ MODULE_OBJS := \
str-enc.o \
stream.o \
streamdebug.o \
stuffit.o \
system.o \
textconsole.o \
tokenizer.o \
Expand Down
28 changes: 14 additions & 14 deletions engines/groovie/stuffit.cpp → common/stuffit.cpp
Expand Up @@ -20,11 +20,10 @@
*
*/

// Based on the StuffIt code in ResidualVM
// StuffIt parsing based on http://code.google.com/p/theunarchiver/wiki/StuffItFormat
// Compression 14 based on libxad (http://sourceforge.net/projects/libxad/)

#include "groovie/stuffit.h"
#include "common/stuffit.h"

#include "common/archive.h"
#include "common/bitstream.h"
Expand All @@ -34,7 +33,7 @@
#include "common/memstream.h"
#include "common/substream.h"

namespace Groovie {
namespace Common {

struct SIT14Data;

Expand Down Expand Up @@ -75,15 +74,15 @@ class StuffItArchive : public Common::Archive {
};

StuffItArchive::StuffItArchive() : Common::Archive() {
_stream = 0;
_stream = nullptr;
}

StuffItArchive::~StuffItArchive() {
close();
}

// Some known values of StuffIt FourCC's
// 11H Mac in particular uses ST46
// 11H Mac in particular uses ST46, while EMI Mac uses ST65
static const uint32 s_magicNumbers[] = {
MKTAG('S', 'I', 'T', '!'), MKTAG('S', 'T', '6', '5'), MKTAG('S', 'T', '5', '0'),
MKTAG('S', 'T', '6', '0'), MKTAG('S', 'T', 'i', 'n'), MKTAG('S', 'T', 'i', '2'),
Expand Down Expand Up @@ -196,7 +195,7 @@ bool StuffItArchive::open(const Common::String &filename) {
}

void StuffItArchive::close() {
delete _stream; _stream = 0;
delete _stream; _stream = nullptr;
_map.clear();
}

Expand All @@ -217,7 +216,7 @@ const Common::ArchiveMemberPtr StuffItArchive::getMember(const Common::String &n

Common::SeekableReadStream *StuffItArchive::createReadStreamForMember(const Common::String &name) const {
if (!_stream || !_map.contains(name))
return 0;
return nullptr;

const FileEntry &entry = _map[name];

Expand All @@ -236,7 +235,7 @@ Common::SeekableReadStream *StuffItArchive::createReadStreamForMember(const Comm
error("Unhandled StuffIt compression %d", entry.compression);
}

return 0;
return nullptr;
}

void StuffItArchive::update14(uint16 first, uint16 last, byte *code, uint16 *freq) const {
Expand Down Expand Up @@ -352,15 +351,15 @@ void StuffItArchive::readTree14(Common::BitStream8LSB *bits, SIT14Data *dat, uin
l = bits->getBits(j);

if (k != l) {
if (l == m) {
if (l == m) {
l = bits->getBits(j) + 3;

while (l--) {
dat->code[i] = dat->code[i - 1];
++i;
}
} else {
dat->code[i++] = l+o;
dat->code[i++] = l + o;
}
} else {
dat->code[i++] = 0;
Expand All @@ -382,7 +381,8 @@ void StuffItArchive::readTree14(Common::BitStream8LSB *bits, SIT14Data *dat, uin
if (i)
j <<= (dat->codecopy[i] - dat->codecopy[i - 1]);

k = dat->codecopy[i]; m = 0;
k = dat->codecopy[i];
m = 0;

for (l = j; k--; l >>= 1)
m = (m << 1) | (l & 1);
Expand Down Expand Up @@ -445,7 +445,7 @@ Common::SeekableReadStream *StuffItArchive::decompress14(Common::SeekableReadStr
dat->var8[i] = i;

for (m = 1, l = 4; i < 0x4000; m <<= 1) // i is 4
for (n = l+4; l < n; ++l)
for (n = l + 4; l < n; ++l)
for (j = 0; j < m; ++j)
dat->var8[i++] = l;

Expand Down Expand Up @@ -484,7 +484,7 @@ Common::SeekableReadStream *StuffItArchive::decompress14(Common::SeekableReadStr
--n;
} else {
i -= 0x100;
k = dat->var2[i]+4;
k = dat->var2[i] + 4;
i = dat->var1[i];

if (i)
Expand Down Expand Up @@ -534,4 +534,4 @@ Common::Archive *createStuffItArchive(const Common::String &fileName) {
return archive;
}

} // End of namespace Groovie
} // End of namespace Common
32 changes: 24 additions & 8 deletions engines/groovie/stuffit.h → common/stuffit.h
Expand Up @@ -20,24 +20,40 @@
*
*/

#ifndef GROOVIE_STUFFIT_H
#define GROOVIE_STUFFIT_H
/**
* @file
* StuffIt decompressor used in engines:
* - grim
* - groovie
*/

#ifndef COMMON_STUFFIT_H
#define COMMON_STUFFIT_H

namespace Common {

/**
* @defgroup common_stuffit StuffIt decompressor
* @ingroup common
*
* @brief API related to StuffIt archive files.
*
* @{
*/

class Archive;
class String;
}

namespace Groovie {

/**
* This factory method creates an Archive instance corresponding to the content
* of the StuffIt compressed file.
* of the StuffIt compressed file with the given name.
*
* May return 0 in case of a failure.
*/
Common::Archive *createStuffItArchive(const Common::String &fileName);
Archive *createStuffItArchive(const String &fileName);

/** @} */

} // End of namespace Groovie
} // End of namespace Common

#endif
15 changes: 5 additions & 10 deletions engines/grim/grim.cpp
Expand Up @@ -32,6 +32,7 @@
#include "common/foreach.h"
#include "common/fs.h"
#include "common/config-manager.h"
#include "common/stuffit.h"
#include "common/translation.h"

#include "backends/keymapper/action.h"
Expand Down Expand Up @@ -75,7 +76,6 @@
#include "engines/grim/objectstate.h"
#include "engines/grim/set.h"
#include "engines/grim/sound.h"
#include "engines/grim/stuffit.h"
#include "engines/grim/debugger.h"
#include "engines/grim/remastered/overlay.h"
#include "engines/grim/remastered/lua_remastered.h"
Expand Down Expand Up @@ -319,21 +319,16 @@ Common::Error GrimEngine::run() {
// Currently, this requires the data fork to be standalone
if (getGameType() == GType_MONKEY4) {
if (SearchMan.hasFile("Monkey Island 4 Installer")) {
StuffItArchive *archive = new StuffItArchive();
Common::Archive *archive = Common::createStuffItArchive("Monkey Island 4 Installer");

if (archive->open("Monkey Island 4 Installer"))
if (archive)
SearchMan.add("Monkey Island 4 Installer", archive, 0, true);
else
delete archive;
}
if (SearchMan.hasFile("EFMI Installer")) {
StuffItArchive *archive = new StuffItArchive();
Common::Archive *archive = Common::createStuffItArchive("EFMI Installer");

if (archive->open("EFMI Installer"))
if (archive)
SearchMan.add("EFMI Installer", archive, 0, true);
else
delete archive;

}
}

Expand Down
1 change: 0 additions & 1 deletion engines/grim/module.mk
Expand Up @@ -132,7 +132,6 @@ MODULE_OBJS := \
sector.o \
sound.o \
sprite.o \
stuffit.o \
textobject.o \
textsplit.o \
object.o \
Expand Down

0 comments on commit d1d305d

Please sign in to comment.