aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNipun Garg2019-03-13 13:53:47 +0530
committerEugene Sandulenko2019-09-03 17:16:41 +0200
commit74ff415903df1a93eada3843db1f85831b88d151 (patch)
tree9e228606daaf90acdc5ca489314bb4ea346e8bfc
parent50e2b5b5bf09caa20d2d2088d997fe8991efb93e (diff)
downloadscummvm-rg350-74ff415903df1a93eada3843db1f85831b88d151.tar.gz
scummvm-rg350-74ff415903df1a93eada3843db1f85831b88d151.tar.bz2
scummvm-rg350-74ff415903df1a93eada3843db1f85831b88d151.zip
HDB: Add decompresser to readMPC()
The .MPC decompression methods are added to readMPC(). The position and length of each data file in held in the struct DataFile, which are stored in the Array gameData. To extract a file, you need to access its entry in gameData and read the file from the given position.
-rw-r--r--engines/hdb/detection.cpp2
-rw-r--r--engines/hdb/hdb.cpp80
-rw-r--r--engines/hdb/hdb.h36
3 files changed, 108 insertions, 10 deletions
diff --git a/engines/hdb/detection.cpp b/engines/hdb/detection.cpp
index e8421cfbe8..aae4ad9b5b 100644
--- a/engines/hdb/detection.cpp
+++ b/engines/hdb/detection.cpp
@@ -44,7 +44,7 @@ static const ADGameDescription gameDescriptions[] = {
AD_ENTRY1s("hyperdemo.mpc", "d8743b3b8be56486bcfb1398b2f2aad4", 13816461),
Common::EN_ANY,
Common::kPlatformUnknown,
- ADGF_NO_FLAGS,
+ ADGF_DEMO,
GUIO1(GUIO_NONE)
},
AD_TABLE_END_MARKER
diff --git a/engines/hdb/hdb.cpp b/engines/hdb/hdb.cpp
index dc1b7b8889..83e29cb06a 100644
--- a/engines/hdb/hdb.cpp
+++ b/engines/hdb/hdb.cpp
@@ -23,37 +23,105 @@
#include "common/scummsys.h"
#include "common/system.h"
#include "common/config-manager.h"
+#include "common/debug.h"
#include "common/debug-channels.h"
#include "common/file.h"
-
#include "common/error.h"
#include "hdb.h"
+#include "console.h"
namespace HDB {
-HDBGame::HDBGame(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), _random("HDB") {
+HDBGame::HDBGame(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
+ _console = nullptr;
+
DebugMan.addDebugChannel(kDebugExample1, "Example1", "This is just an example to test");
DebugMan.addDebugChannel(kDebugExample2, "Example2", "This is also an example");
}
HDBGame::~HDBGame() {
+ delete _console;
DebugMan.clearAllDebugChannels();
}
Common::Error HDBGame::run() {
+ // Initializes Graphics
+ initGraphics(800, 600);
+ _console = new Console();
+
+
+ readMPC("hyperdemo.mpc");
+ bool quit = false;
+
+ while (!quit) {
+ Common::Event event;
+ while (g_system->getEventManager()->pollEvent(event)) {
+ switch (event.type) {
+ case Common::EVENT_QUIT:
+ quit = true;
+ break;
+ default:
+ break;
+ }
+ }
+
+ g_system->updateScreen();
+ g_system->delayMillis(10);
+ }
return Common::kNoError;
}
-void HDBGame::readMPC(const Common::String &filename) {
- Common::File file;
-
+void HDBGame::readMPC(const Common::String &filename) {
if (!file.open(filename)) {
- error("sReadMPC(): Error reading MPC file");
+ error("readMPC(): Error reading MPC file");
}
+ else {
+ dataHeader.signature[0] = file.readByte();
+ dataHeader.signature[1] = file.readByte();
+ dataHeader.signature[2] = file.readByte();
+ dataHeader.signature[3] = file.readByte();
+ dataHeader.signature[4] = '\0';
+ if (dataHeader.isValid()) {
+ debug("Valid MPC file");
+ dataHeader.dirOffset = file.readUint32LE();
+
+ /* FIXME: Temporary Hack
+
+ The MPC archive format uses uint32 to store the dirOffset,
+ however, the File::seekg() function takes an int32 as the offset.
+ This does not cause a problem yet because the offset is
+ within the range of 2^31. Extending this functionality to another
+ game file with a larger offset may cause problems.
+ */
+
+ file.seek((int32)dataHeader.dirOffset, SEEK_SET);
+
+ dataHeader.dirSize = file.readUint32LE();
+
+ for (uint32 fileIndex = 0; fileIndex < dataHeader.dirSize; fileIndex++) {
+ DataFile* dirEntry = new DataFile();
+
+ for (int fileNameIndex = 0; fileNameIndex < 64; fileNameIndex++) {
+ dirEntry->fileName[fileNameIndex] = file.readByte();
+ }
+ dirEntry->fileName[64] = '\0';
+
+ dirEntry->filePosition = file.readUint32LE();
+ dirEntry->fileLength = file.readUint32LE();
+ dirEntry->unknownField1 = file.readUint32LE();
+ dirEntry->unknownField2 = file.readUint32LE();
+
+ gameData.push_back(dirEntry);
+ }
+
+ } else {
+ debug("Invalid MPC file");
+ }
+ }
}
} // End of namespace HDB \ No newline at end of file
diff --git a/engines/hdb/hdb.h b/engines/hdb/hdb.h
index 8954cc0b01..4fe1156a23 100644
--- a/engines/hdb/hdb.h
+++ b/engines/hdb/hdb.h
@@ -24,12 +24,16 @@
#define HDB_HDB_H
#include "common/scummsys.h"
+#include "common/array.h"
#include "common/error.h"
-#include "common/random.h"
#include "common/file.h"
-#include "common/array.h"
+#include "common/events.h"
+#include "common/str.h"
+
#include "gui/debugger.h"
#include "engines/engine.h"
+#include "engines/util.h"
+#include "console.h"
struct ADGameDescription;
@@ -53,8 +57,34 @@ public:
Common::Platform getPlatform() const;
private:
+
+ Console *_console;
+ Common::File file;
+
+ struct {
+ byte signature[5]; // 4 Bytes + '\0'
+ uint32 dirOffset;
+ uint32 dirSize;
+
+ bool isValid() {
+ return (signature[0] == 'M') &&
+ (signature[1] == 'P') &&
+ (signature[2] == 'C') &&
+ (signature[3] == 'U') &&
+ (signature[4] == '\0');
+ }
+
+ } dataHeader;
+
+ struct DataFile {
+ byte fileName[65]; // 65 Bytes + '\0'
+ uint32 filePosition;
+ uint32 fileLength;
+ uint32 unknownField1;
+ uint32 unknownField2;
+ };
- Common::RandomSource _random;
+ Common::Array<DataFile*> gameData;
void readMPC(const Common::String &fileName);
};