aboutsummaryrefslogtreecommitdiff
path: root/engines/hdb/hdb.cpp
diff options
context:
space:
mode:
authorNipun Garg2019-03-13 13:53:47 +0530
committerEugene Sandulenko2019-09-03 17:16:41 +0200
commit74ff415903df1a93eada3843db1f85831b88d151 (patch)
tree9e228606daaf90acdc5ca489314bb4ea346e8bfc /engines/hdb/hdb.cpp
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.
Diffstat (limited to 'engines/hdb/hdb.cpp')
-rw-r--r--engines/hdb/hdb.cpp80
1 files changed, 74 insertions, 6 deletions
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