diff options
author | johndoe123 | 2011-06-24 13:12:42 +0000 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-05-08 20:30:57 +0200 |
commit | 3b00cfa669a94490e727b065f14fb9216d43351c (patch) | |
tree | 0c7c99882cc330b842fd3e170ebf633c4aac0461 | |
parent | 52e0ac85db1b1bc7f2670498d019cf982c16d413 (diff) | |
download | scummvm-rg350-3b00cfa669a94490e727b065f14fb9216d43351c.tar.gz scummvm-rg350-3b00cfa669a94490e727b065f14fb9216d43351c.tar.bz2 scummvm-rg350-3b00cfa669a94490e727b065f14fb9216d43351c.zip |
NEVERHOOD: Start with the blb archive class
-rw-r--r-- | engines/neverhood/blbarchive.cpp | 107 | ||||
-rw-r--r-- | engines/neverhood/blbarchive.h | 66 | ||||
-rw-r--r-- | engines/neverhood/module.mk | 1 | ||||
-rw-r--r-- | engines/neverhood/neverhood.cpp | 9 | ||||
-rw-r--r-- | engines/neverhood/neverhood.h | 2 |
5 files changed, 182 insertions, 3 deletions
diff --git a/engines/neverhood/blbarchive.cpp b/engines/neverhood/blbarchive.cpp new file mode 100644 index 0000000000..48452efa8b --- /dev/null +++ b/engines/neverhood/blbarchive.cpp @@ -0,0 +1,107 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/dcl.h" +#include "neverhood/blbarchive.h" + +namespace Neverhood { + +BlbArchive::BlbArchive() : _extData(NULL) { +} + +BlbArchive::~BlbArchive() { + delete[] _extData; +} + +void BlbArchive::open(const Common::String &filename) { + BlbHeader header; + + _entries.clear(); + + if (!_fd.open(filename)) + error("BlbArchive::open() Could not open %s", filename.c_str()); + + header.id1 = _fd.readUint32LE(); + header.id2 = _fd.readUint16LE(); + header.extDataSize = _fd.readUint16LE(); + header.fileSize = _fd.readUint32LE(); + header.fileCount = _fd.readUint32LE(); + + if (header.id1 != 0x2004940 || header.id2 != 7 || header.fileSize != _fd.size()) + error("BlbArchive::open() %s seems to be corrupt", filename.c_str()); + + debug("fileCount = %d", header.fileCount); + + _entries.reserve(header.fileCount); + + // Load file hashes + for (uint i = 0; i < header.fileCount; i++) { + BlbArchiveEntry entry; + entry.fileHash = _fd.readUint32LE(); + _entries.push_back(entry); + } + + // Load file records + for (uint i = 0; i < header.fileCount; i++) { + BlbArchiveEntry &entry = _entries[i]; + entry.type = _fd.readByte(); + entry.comprType = _fd.readByte(); + entry.extDataOfs = _fd.readUint16LE(); + entry.timeStamp = _fd.readUint32LE(); + entry.offset = _fd.readUint32LE(); + entry.diskSize = _fd.readUint32LE(); + entry.size = _fd.readUint32LE(); + debug("%08X: %03d, %02X, %04X, %08X, %08X, %08X, %08X", + entry.fileHash, entry.type, entry.comprType, entry.extDataOfs, entry.timeStamp, + entry.offset, entry.diskSize, entry.size); + } + + // Load ext data + if (header.extDataSize > 0) { + _extData = new byte[header.extDataSize]; + _fd.read(_extData, header.extDataSize); + } + +} + +void BlbArchive::load(uint index, byte *buffer, uint32 size) { + + BlbArchiveEntry &entry = _entries[index]; + + _fd.seek(entry.offset); + + switch (entry.comprType) { + case 1: // Uncompressed + if (size == 0) + size = entry.diskSize; + _fd.read(buffer, size); + break; + case 3: // DCL-compressed + Common::decompressDCL(&_fd, buffer, entry.diskSize, entry.size); + break; + default: + ; + } + +} + +} // End of namespace Neverhood diff --git a/engines/neverhood/blbarchive.h b/engines/neverhood/blbarchive.h new file mode 100644 index 0000000000..7fc54d90a7 --- /dev/null +++ b/engines/neverhood/blbarchive.h @@ -0,0 +1,66 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef NEVERHOOD_BLBARCHIVE_H +#define NEVERHOOD_BLBARCHIVE_H + +#include "common/array.h" +#include "common/file.h" +#include "neverhood/neverhood.h" + +namespace Neverhood { + +struct BlbHeader { + uint32 id1; + uint16 id2; + uint16 extDataSize; + int32 fileSize; + uint32 fileCount; +}; + +struct BlbArchiveEntry { + uint32 fileHash; + byte type; + byte comprType; + uint16 extDataOfs; + uint32 timeStamp; + uint32 offset; + uint32 diskSize; + uint32 size; +}; + +class BlbArchive { +public: + BlbArchive(); + ~BlbArchive(); + void open(const Common::String &filename); + void load(uint index, byte *buffer, uint32 size); + uint32 getSize(uint index) { return _entries[index].size; } +private: + Common::File _fd; + Common::Array<BlbArchiveEntry> _entries; + byte *_extData; +}; + +} // End of namespace Neverhood + +#endif /* NEVERHOOD_BLBARCHIVE_H */ diff --git a/engines/neverhood/module.mk b/engines/neverhood/module.mk index d46d6a67ba..0601f54d82 100644 --- a/engines/neverhood/module.mk +++ b/engines/neverhood/module.mk @@ -1,6 +1,7 @@ MODULE := engines/neverhood MODULE_OBJS = \ + blbarchive.o \ detection.o \ neverhood.o diff --git a/engines/neverhood/neverhood.cpp b/engines/neverhood/neverhood.cpp index 9c464b9a83..873d7ff8ed 100644 --- a/engines/neverhood/neverhood.cpp +++ b/engines/neverhood/neverhood.cpp @@ -20,7 +20,6 @@ * */ -#include "common/algorithm.h" #include "common/events.h" #include "common/keyboard.h" #include "common/file.h" @@ -35,10 +34,10 @@ #include "engines/util.h" -#include "audio/mididrv.h" #include "audio/mixer.h" #include "neverhood/neverhood.h" +#include "neverhood/blbarchive.h" namespace Neverhood { @@ -68,6 +67,12 @@ Common::Error NeverhoodEngine::run() { _isSaveAllowed = false; + + BlbArchive *blb = new BlbArchive(); + blb->open("m.blb"); + + delete blb; + return Common::kNoError; } diff --git a/engines/neverhood/neverhood.h b/engines/neverhood/neverhood.h index c17116d2dd..63862dde54 100644 --- a/engines/neverhood/neverhood.h +++ b/engines/neverhood/neverhood.h @@ -66,7 +66,7 @@ public: Common::KeyCode _keyState; uint16 _buttonState; - void updateEvents(); + void updateEvents(); public: |