[Scummvm-git-logs] scummvm master -> 6f7c62b81e61b1251b5c6fb8df244bc6270dd4f9
dreammaster
noreply at scummvm.org
Sat Feb 11 06:35:01 UTC 2023
This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
a05dfc9cd8 MM: Starting to separate out shared code
a3550a9cb0 MM: Create common engine base engine class
14715b4a59 MM: XEEN: Remove deprecated StringArray class
6f7c62b81e MM: Move CCArchive into Shared namespace
Commit: a05dfc9cd8b4dbb85d95d1efa8c6910457fabd36
https://github.com/scummvm/scummvm/commit/a05dfc9cd8b4dbb85d95d1efa8c6910457fabd36
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-02-10T22:33:29-08:00
Commit Message:
MM: Starting to separate out shared code
Changed paths:
A engines/mm/shared/xeen/xsurface.cpp
A engines/mm/shared/xeen/xsurface.h
R engines/mm/xeen/xsurface.cpp
R engines/mm/xeen/xsurface.h
engines/mm/module.mk
engines/mm/xeen/dialogs/dialogs.h
engines/mm/xeen/font.h
engines/mm/xeen/sprites.h
diff --git a/engines/mm/module.mk b/engines/mm/module.mk
index c888e560cb9..0d770761e36 100644
--- a/engines/mm/module.mk
+++ b/engines/mm/module.mk
@@ -245,7 +245,7 @@ MODULE_OBJS := \
xeen/subtitles.o \
xeen/window.o \
xeen/xeen.o \
- xeen/xsurface.o
+ shared/xeen/xsurface.o
# This module can be built as a plugin
ifeq ($(ENABLE_MM), DYNAMIC_PLUGIN)
diff --git a/engines/mm/xeen/xsurface.cpp b/engines/mm/shared/xeen/xsurface.cpp
similarity index 92%
rename from engines/mm/xeen/xsurface.cpp
rename to engines/mm/shared/xeen/xsurface.cpp
index b92d5e16a19..af2656245ce 100644
--- a/engines/mm/xeen/xsurface.cpp
+++ b/engines/mm/shared/xeen/xsurface.cpp
@@ -21,12 +21,14 @@
#include "common/algorithm.h"
#include "common/util.h"
-#include "mm/xeen/xsurface.h"
+#include "mm/shared/xeen/xsurface.h"
#include "mm/xeen/resources.h"
#include "mm/xeen/screen.h"
namespace MM {
+namespace Shared {
namespace Xeen {
} // End of namespace Xeen
+} // End of namespace Shared
} // End of namespace MM
diff --git a/engines/mm/xeen/xsurface.h b/engines/mm/shared/xeen/xsurface.h
similarity index 81%
rename from engines/mm/xeen/xsurface.h
rename to engines/mm/shared/xeen/xsurface.h
index d4c32403e31..58454c2c660 100644
--- a/engines/mm/xeen/xsurface.h
+++ b/engines/mm/shared/xeen/xsurface.h
@@ -19,8 +19,8 @@
*
*/
-#ifndef XEEN_XSURFACE_H
-#define XEEN_XSURFACE_H
+#ifndef XEEN_SHARED_XSURFACE_H
+#define XEEN_SHARED_XSURFACE_H
#include "common/scummsys.h"
#include "common/system.h"
@@ -28,6 +28,7 @@
#include "graphics/managed_surface.h"
namespace MM {
+namespace Shared {
namespace Xeen {
class BaseSurface : public Graphics::ManagedSurface {
@@ -36,25 +37,20 @@ public:
Graphics::ManagedSurface::addDirtyRect(r);
}
public:
- BaseSurface() : Graphics::ManagedSurface() {
- }
- BaseSurface(int width, int height) : Graphics::ManagedSurface(width, height) {
- }
- ~BaseSurface() override {
- }
+ BaseSurface() : Graphics::ManagedSurface() {}
+ BaseSurface(int width, int height) : Graphics::ManagedSurface(width, height) {}
+ ~BaseSurface() override {}
};
class XSurface : public BaseSurface {
public:
- XSurface() : BaseSurface() {
- }
- XSurface(int width, int height) : BaseSurface(width, height) {
- }
- ~XSurface() override {
- }
+ XSurface() : BaseSurface() {}
+ XSurface(int width, int height) : BaseSurface(width, height) {}
+ ~XSurface() override {}
};
} // End of namespace Xeen
+} // End of namespace Shared
} // End of namespace MM
#endif
diff --git a/engines/mm/xeen/dialogs/dialogs.h b/engines/mm/xeen/dialogs/dialogs.h
index a6d047c757f..c9095827826 100644
--- a/engines/mm/xeen/dialogs/dialogs.h
+++ b/engines/mm/xeen/dialogs/dialogs.h
@@ -27,7 +27,7 @@
#include "common/rect.h"
#include "mm/xeen/cutscenes.h"
#include "mm/xeen/sprites.h"
-#include "mm/xeen/xsurface.h"
+#include "mm/shared/xeen/xsurface.h"
namespace MM {
namespace Xeen {
diff --git a/engines/mm/xeen/font.h b/engines/mm/xeen/font.h
index 58cfd46dc1f..6767c4bc2c7 100644
--- a/engines/mm/xeen/font.h
+++ b/engines/mm/xeen/font.h
@@ -23,7 +23,7 @@
#define XEEN_FONT_H
#include "common/language.h"
-#include "mm/xeen/xsurface.h"
+#include "mm/shared/xeen/xsurface.h"
namespace MM {
namespace Xeen {
@@ -43,7 +43,7 @@ struct FontData {
static Justify _fontJustify;
};
-class FontSurface: public XSurface, public FontData {
+class FontSurface: public Shared::Xeen::XSurface, public FontData {
private:
const char *_displayString;
bool _msgWraps;
diff --git a/engines/mm/xeen/sprites.h b/engines/mm/xeen/sprites.h
index 5c791f99f3e..8a173d51c35 100644
--- a/engines/mm/xeen/sprites.h
+++ b/engines/mm/xeen/sprites.h
@@ -27,11 +27,13 @@
#include "common/file.h"
#include "graphics/surface.h"
#include "mm/xeen/files.h"
-#include "mm/xeen/xsurface.h"
+#include "mm/shared/xeen/xsurface.h"
namespace MM {
namespace Xeen {
+using Shared::Xeen::XSurface;
+
class XeenEngine;
class Window;
Commit: a3550a9cb0510c18b3cfe3bd019640af952be30a
https://github.com/scummvm/scummvm/commit/a3550a9cb0510c18b3cfe3bd019640af952be30a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-02-10T22:33:29-08:00
Commit Message:
MM: Create common engine base engine class
Changed paths:
A engines/mm/mm.cpp
engines/mm/mm.h
engines/mm/mm1/mm1.cpp
engines/mm/mm1/mm1.h
engines/mm/module.mk
engines/mm/xeen/xeen.cpp
engines/mm/xeen/xeen.h
diff --git a/engines/mm/mm.cpp b/engines/mm/mm.cpp
new file mode 100644
index 00000000000..8dfe75bc068
--- /dev/null
+++ b/engines/mm/mm.cpp
@@ -0,0 +1,53 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "mm/mm.h"
+
+namespace MM {
+
+MMEngine::MMEngine(OSystem *syst, const MM::MightAndMagicGameDescription *gameDesc) :
+ Engine(syst), _gameDescription(gameDesc), _randomSource("MightAndMagic") {
+}
+
+bool MMEngine::hasFeature(EngineFeature f) const {
+ return
+ (f == kSupportsReturnToLauncher) ||
+ (f == kSupportsLoadingDuringRuntime) ||
+ (f == kSupportsSavingDuringRuntime);
+}
+
+uint32 MMEngine::getGameID() const {
+ return _gameDescription->gameID;
+}
+
+uint32 MMEngine::getFeatures() const {
+ return _gameDescription->desc.flags;
+}
+
+Common::Language MMEngine::getLanguage() const {
+ return _gameDescription->desc.language;
+}
+
+Common::Platform MMEngine::getPlatform() const {
+ return _gameDescription->desc.platform;
+}
+
+} // namespace MM
diff --git a/engines/mm/mm.h b/engines/mm/mm.h
index e288edaf212..dec644e669e 100644
--- a/engines/mm/mm.h
+++ b/engines/mm/mm.h
@@ -22,6 +22,9 @@
#ifndef MM_MM_H
#define MM_MM_H
+#include "common/random.h"
+#include "mm/detection.h"
+
namespace MM {
enum MightAndMagicDebugChannels {
@@ -31,6 +34,41 @@ enum MightAndMagicDebugChannels {
kDebugSound = 1 << 3
};
+class MMEngine : public Engine {
+protected:
+ const MightAndMagicGameDescription *_gameDescription;
+ Common::RandomSource _randomSource;
+public:
+ MMEngine(OSystem *syst, const MM::MightAndMagicGameDescription *gameDesc);
+ ~MMEngine() override {}
+
+ /**
+ * Checks for feature flag
+ */
+ bool hasFeature(EngineFeature f) const override;
+
+ /**
+ * Returns the features
+ */
+ uint32 getFeatures() const;
+
+ /**
+ * Returns the game language
+ */
+ Common::Language getLanguage() const;
+
+ /**
+ * Returns the game's platform
+ */
+ Common::Platform getPlatform() const;
+
+ /**
+ * Gets the game Id
+ */
+ uint32 getGameID() const;
+
+};
+
} // namespace MM
#endif // MM_MM_H
diff --git a/engines/mm/mm1/mm1.cpp b/engines/mm/mm1/mm1.cpp
index 062e9634fc9..5e3932793db 100644
--- a/engines/mm/mm1/mm1.cpp
+++ b/engines/mm/mm1/mm1.cpp
@@ -40,8 +40,7 @@ namespace MM1 {
MM1Engine *g_engine = nullptr;
MM1Engine::MM1Engine(OSystem *syst, const MightAndMagicGameDescription *gameDesc)
- : Engine(syst), Events(gameDesc->features & GF_ENHANCED),
- _gameDescription(gameDesc), _randomSource("MM1") {
+ : MMEngine(syst, gameDesc), Events(gameDesc->features & GF_ENHANCED) {
g_engine = this;
}
@@ -118,13 +117,6 @@ bool MM1Engine::setupEnhanced() {
return true;
}
-bool MM1Engine::hasFeature(EngineFeature f) const {
- return
- (f == kSupportsReturnToLauncher) ||
- (f == kSupportsLoadingDuringRuntime) ||
- (f == kSupportsSavingDuringRuntime);
-}
-
bool MM1Engine::canSaveGameStateCurrently() {
if (!g_events)
return false;
diff --git a/engines/mm/mm1/mm1.h b/engines/mm/mm1/mm1.h
index 85aa57ffa27..24021f2dc51 100644
--- a/engines/mm/mm1/mm1.h
+++ b/engines/mm/mm1/mm1.h
@@ -35,10 +35,7 @@
namespace MM {
namespace MM1 {
-class MM1Engine : public Engine, public Events {
-private:
- const MightAndMagicGameDescription *_gameDescription;
- Common::RandomSource _randomSource;
+class MM1Engine : public MMEngine, public Events {
private:
// Engine APIs
Common::Error run() override;
@@ -51,8 +48,6 @@ public:
MM1Engine(OSystem *syst, const MightAndMagicGameDescription *gameDesc);
~MM1Engine() override;
- bool hasFeature(EngineFeature f) const override;
-
bool isEnhanced() const;
/**
diff --git a/engines/mm/module.mk b/engines/mm/module.mk
index 0d770761e36..75ee3633d3f 100644
--- a/engines/mm/module.mk
+++ b/engines/mm/module.mk
@@ -2,6 +2,7 @@ MODULE := engines/mm
MODULE_OBJS := \
metaengine.o \
+ mm.o \
utils/bitmap_font.o \
utils/engine_data.o \
utils/strings.o \
diff --git a/engines/mm/xeen/xeen.cpp b/engines/mm/xeen/xeen.cpp
index cd59dae2e75..8b622b4e554 100644
--- a/engines/mm/xeen/xeen.cpp
+++ b/engines/mm/xeen/xeen.cpp
@@ -34,8 +34,7 @@ namespace Xeen {
XeenEngine *g_vm = nullptr;
XeenEngine::XeenEngine(OSystem *syst, const MightAndMagicGameDescription *gameDesc)
- : Engine(syst), _gameDescription(gameDesc), _randomSource("Xeen") {
-
+ : MMEngine(syst, gameDesc) {
_combat = nullptr;
_debugger = nullptr;
_events = nullptr;
@@ -118,13 +117,6 @@ bool XeenEngine::initialize() {
return true;
}
-bool XeenEngine::hasFeature(EngineFeature f) const {
- return
- (f == kSupportsReturnToLauncher) ||
- (f == kSupportsLoadingDuringRuntime) ||
- (f == kSupportsSavingDuringRuntime);
-}
-
void XeenEngine::loadSettings() {
_gameWon[0] = ConfMan.hasKey("game_won") && ConfMan.getBool("game_won");
_gameWon[1] = ConfMan.hasKey("game_won2") && ConfMan.getBool("game_won2");
@@ -335,10 +327,6 @@ void XeenEngine::GUIError(const Common::U32String &msg) {
}
-uint32 XeenEngine::getGameID() const {
- return _gameDescription->gameID;
-}
-
uint32 XeenEngine::getSpecificGameId() const {
uint gameId = g_vm->getGameID();
if (gameId == GType_WorldOfXeen)
@@ -351,18 +339,6 @@ uint32 XeenEngine::getGameFeatures() const {
return _gameDescription->features;
}
-uint32 XeenEngine::getFeatures() const {
- return _gameDescription->desc.flags;
-}
-
-Common::Language XeenEngine::getLanguage() const {
- return _gameDescription->desc.language;
-}
-
-Common::Platform XeenEngine::getPlatform() const {
- return _gameDescription->desc.platform;
-}
-
bool XeenEngine::getIsCD() const {
return getFeatures() & ADGF_CD;
}
diff --git a/engines/mm/xeen/xeen.h b/engines/mm/xeen/xeen.h
index f15a1da2300..2f6b52fed3d 100644
--- a/engines/mm/xeen/xeen.h
+++ b/engines/mm/xeen/xeen.h
@@ -90,7 +90,7 @@ enum GameMode {
#define XEEN_SAVEGAME_VERSION 2
-class XeenEngine : public Engine {
+class XeenEngine : public MMEngine {
/**
* Container to a set of options newly introduced under ScummVM
*/
@@ -101,9 +101,6 @@ class XeenEngine : public Engine {
ExtendedOptions() : _showItemCosts(false), _durableArmor(false) {
}
};
-private:
- const MightAndMagicGameDescription *_gameDescription;
- Common::RandomSource _randomSource;
private:
/**
* Initializes all the engine sub-objects
@@ -117,7 +114,6 @@ private:
// Engine APIs
Common::Error run() override;
- bool hasFeature(EngineFeature f) const override;
/**
* Outer gameplay loop responsible for dispatching control to game-specific
@@ -185,26 +181,6 @@ public:
XeenEngine(OSystem *syst, const MM::MightAndMagicGameDescription *gameDesc);
~XeenEngine() override;
- /**
- * Returns the features
- */
- uint32 getFeatures() const;
-
- /**
- * Returns the game language
- */
- Common::Language getLanguage() const;
-
- /**
- * Returns the game's platform
- */
- Common::Platform getPlatform() const;
-
- /**
- * Gets the game Id
- */
- uint32 getGameID() const;
-
/**
* Returns the game Id, but with a reuslt of Clouds or Dark Side for World of Xeen,
* depending on which side the player is currently on
Commit: 14715b4a59ca91521588a7447d24e5f962bcc3ae
https://github.com/scummvm/scummvm/commit/14715b4a59ca91521588a7447d24e5f962bcc3ae
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-02-10T22:33:29-08:00
Commit Message:
MM: XEEN: Remove deprecated StringArray class
Changed paths:
engines/mm/xeen/files.cpp
engines/mm/xeen/files.h
diff --git a/engines/mm/xeen/files.cpp b/engines/mm/xeen/files.cpp
index 3d3f0235c68..6dcf984c34a 100644
--- a/engines/mm/xeen/files.cpp
+++ b/engines/mm/xeen/files.cpp
@@ -435,22 +435,6 @@ void File::syncBitFlags(Common::Serializer &s, bool *startP, bool *endP) {
/*------------------------------------------------------------------------*/
-void StringArray::load(const Common::String &name) {
- File f(name);
- clear();
- while (f.pos() < f.size())
- push_back(f.readString());
-}
-
-void StringArray::load(const Common::String &name, int ccMode) {
- File f(name, ccMode);
- clear();
- while (f.pos() < f.size())
- push_back(f.readString());
-}
-
-/*------------------------------------------------------------------------*/
-
SaveArchive::SaveArchive(Party *party) : BaseCCArchive(), _party(party), _data(nullptr), _dataSize(0) {
}
diff --git a/engines/mm/xeen/files.h b/engines/mm/xeen/files.h
index 2bafc97663a..5e28ed174a1 100644
--- a/engines/mm/xeen/files.h
+++ b/engines/mm/xeen/files.h
@@ -226,22 +226,6 @@ public:
int64 pos() const override { return _parentStream->pos() - _begin; }
};
-class StringArray : public Common::StringArray {
-public:
- StringArray() {}
- StringArray(const Common::String &name) { load(name); }
-
- /**
- * Loads a string array from the specified file
- */
- void load(const Common::String &name);
-
- /**
- * Loads a string array from the specified file
- */
- void load(const Common::String &name, int ccMode);
-};
-
class XeenSerializer : public Common::Serializer {
private:
Common::SeekableReadStream *_in;
Commit: 6f7c62b81e61b1251b5c6fb8df244bc6270dd4f9
https://github.com/scummvm/scummvm/commit/6f7c62b81e61b1251b5c6fb8df244bc6270dd4f9
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-02-10T22:33:29-08:00
Commit Message:
MM: Move CCArchive into Shared namespace
Changed paths:
A engines/mm/shared/xeen/cc_archive.cpp
A engines/mm/shared/xeen/cc_archive.h
engines/mm/module.mk
engines/mm/shared/xeen/xsurface.h
engines/mm/xeen/files.cpp
engines/mm/xeen/files.h
diff --git a/engines/mm/module.mk b/engines/mm/module.mk
index 75ee3633d3f..4ad5c853d9a 100644
--- a/engines/mm/module.mk
+++ b/engines/mm/module.mk
@@ -246,6 +246,7 @@ MODULE_OBJS := \
xeen/subtitles.o \
xeen/window.o \
xeen/xeen.o \
+ shared/xeen/cc_archive.o \
shared/xeen/xsurface.o
# This module can be built as a plugin
diff --git a/engines/mm/shared/xeen/cc_archive.cpp b/engines/mm/shared/xeen/cc_archive.cpp
new file mode 100644
index 00000000000..3cbad2a9e5d
--- /dev/null
+++ b/engines/mm/shared/xeen/cc_archive.cpp
@@ -0,0 +1,239 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "common/file.h"
+#include "common/memstream.h"
+#include "common/textconsole.h"
+#include "mm/shared/xeen/cc_archive.h"
+
+namespace MM {
+namespace Shared {
+namespace Xeen {
+
+uint16 BaseCCArchive::convertNameToId(const Common::String &resourceName) {
+ if (resourceName.empty())
+ return 0xffff;
+
+ Common::String name = resourceName;
+ name.toUppercase();
+
+ // Check if a resource number is being directly specified
+ if (name.size() == 4) {
+ char *endPtr;
+ uint16 num = (uint16)strtol(name.c_str(), &endPtr, 16);
+ if (!*endPtr)
+ return num;
+ }
+
+ const byte *msgP = (const byte *)name.c_str();
+ int total = *msgP++;
+ for (; *msgP; total += *msgP++) {
+ // Rotate the bits in 'total' right 7 places
+ total = (total & 0x007F) << 9 | (total & 0xFF80) >> 7;
+ }
+
+ return total;
+}
+
+void BaseCCArchive::loadIndex(Common::SeekableReadStream &stream) {
+ int count = stream.readUint16LE();
+ size_t size = count * 8;
+
+ // Read in the data for the archive's index
+ byte *rawIndex = new byte[size];
+
+ if (stream.read(rawIndex, size) != size) {
+ delete[] rawIndex;
+ error("Failed to read %zu bytes from CC file", size);
+ }
+
+ // Decrypt the index
+ int seed = 0xac;
+ for (int i = 0; i < count * 8; ++i, seed += 0x67) {
+ rawIndex[i] = (byte)((((rawIndex[i] << 2) | (rawIndex[i] >> 6)) + seed) & 0xff);
+ }
+
+ // Extract the index data into entry structures
+ _index.resize(count);
+ const byte *entryP = &rawIndex[0];
+ for (int idx = 0; idx < count; ++idx, entryP += 8) {
+ CCEntry entry;
+ entry._id = READ_LE_UINT16(entryP);
+ entry._offset = READ_LE_UINT32(entryP + 2) & 0xffffff;
+ entry._size = READ_LE_UINT16(entryP + 5);
+ assert(!entryP[7]);
+
+ _index[idx] = entry;
+ }
+
+ delete[] rawIndex;
+}
+
+void BaseCCArchive::saveIndex(Common::WriteStream &stream) {
+ // Fill up the data for the index entries into a raw data block
+ byte *rawIndex = new byte[_index.size() * 8];
+ byte b;
+
+ byte *entryP = rawIndex;
+ for (uint i = 0; i < _index.size(); ++i, entryP += 8) {
+ CCEntry &entry = _index[i];
+ WRITE_LE_UINT16(&entryP[0], entry._id);
+ WRITE_LE_UINT32(&entryP[2], entry._writeOffset);
+ WRITE_LE_UINT16(&entryP[5], entry._size);
+ entryP[7] = 0;
+ }
+
+ // Encrypt the index
+ int seed = 0xac;
+ for (uint i = 0; i < _index.size() * 8; ++i, seed += 0x67) {
+ b = (rawIndex[i] - seed) & 0xff;
+ b = (byte)((b >> 2) | (b << 6));
+
+ assert(rawIndex[i] == (byte)((((b << 2) | (b >> 6)) + seed) & 0xff));
+ rawIndex[i] = b;
+ }
+
+ // Write out the number of entries and the encrypted index data
+ stream.writeUint16LE(_index.size());
+ stream.write(rawIndex, _index.size() * 8);
+
+ delete[] rawIndex;
+}
+
+bool BaseCCArchive::hasFile(const Common::Path &path) const {
+ Common::String name = path.toString();
+ CCEntry ccEntry;
+ return getHeaderEntry(name, ccEntry);
+}
+
+bool BaseCCArchive::getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const {
+ return getHeaderEntry(convertNameToId(resourceName), ccEntry);
+}
+
+bool BaseCCArchive::getHeaderEntry(uint16 id, CCEntry &ccEntry) const {
+ // Loop through the index
+ for (uint i = 0; i < _index.size(); ++i) {
+ if (_index[i]._id == id) {
+ ccEntry = _index[i];
+ return true;
+ }
+ }
+
+ // Could not find an entry
+ return false;
+}
+
+const Common::ArchiveMemberPtr BaseCCArchive::getMember(const Common::Path &path) const {
+ Common::String name = path.toString();
+ if (!hasFile(name))
+ return Common::ArchiveMemberPtr();
+
+ return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this));
+}
+
+int BaseCCArchive::listMembers(Common::ArchiveMemberList &list) const {
+ // CC files don't maintain the original filenames, so we can't list it
+ return 0;
+}
+
+/*------------------------------------------------------------------------*/
+
+CCArchive::CCArchive(const Common::String &filename, bool encoded) :
+ BaseCCArchive(), _filename(filename), _encoded(encoded) {
+
+ Common::File f;
+ if (!f.open(filename, SearchMan))
+ error("Could not open file - %s", filename.c_str());
+
+ loadIndex(f);
+}
+
+CCArchive::CCArchive(const Common::String &filename, const Common::String &prefix,
+ bool encoded) : BaseCCArchive(), _filename(filename),
+ _prefix(prefix), _encoded(encoded) {
+ _prefix.toLowercase();
+
+ Common::File f;
+ if (!f.open(filename, SearchMan))
+ error("Could not open file - %s", filename.c_str());
+
+ loadIndex(f);
+}
+
+CCArchive::~CCArchive() {
+}
+
+bool CCArchive::getHeaderEntry(const Common::String &resourceName, Shared::Xeen::CCEntry &ccEntry) const {
+ Common::String resName = resourceName;
+
+ if (!_prefix.empty() && resName.contains('|')) {
+ resName.toLowercase();
+ Common::String prefix = _prefix + "|";
+
+ if (!strncmp(resName.c_str(), prefix.c_str(), prefix.size()))
+ // Matching CC prefix, so strip it off and allow processing to
+ // continue onto the base getHeaderEntry method
+ resName = Common::String(resName.c_str() + prefix.size());
+ else
+ // Not matching prefix, so don't allow a match
+ return false;
+ }
+
+ return BaseCCArchive::getHeaderEntry(resName, ccEntry);
+}
+
+Common::SeekableReadStream *CCArchive::createReadStreamForMember(const Common::Path &path) const {
+ Common::String name = path.toString();
+ Shared::Xeen::CCEntry ccEntry;
+
+ if (getHeaderEntry(name, ccEntry)) {
+ // Open the correct CC file
+ Common::File f;
+ if (!f.open(_filename))
+ error("Could not open CC file");
+
+ // Read in the data for the specific resource
+ if (!f.seek(ccEntry._offset))
+ error("Failed to seek to %d bytes in CC file", ccEntry._offset);
+
+ byte *data = (byte *)malloc(ccEntry._size);
+
+ if (f.read(data, ccEntry._size) != ccEntry._size) {
+ free(data);
+ error("Failed to read %hu bytes in CC file", ccEntry._size);
+ }
+
+ if (_encoded) {
+ // Decrypt the data
+ for (int i = 0; i < ccEntry._size; ++i)
+ data[i] ^= 0x35;
+ }
+
+ // Return the data as a stream
+ return new Common::MemoryReadStream(data, ccEntry._size, DisposeAfterUse::YES);
+ }
+
+ return nullptr;
+}
+
+} // namespace Xeen
+} // namespace Shared
+} // namespace MM
diff --git a/engines/mm/shared/xeen/cc_archive.h b/engines/mm/shared/xeen/cc_archive.h
new file mode 100644
index 00000000000..21be50fd22a
--- /dev/null
+++ b/engines/mm/shared/xeen/cc_archive.h
@@ -0,0 +1,114 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MM_SHARED_XEEN_CC_ARCHIVE_H
+#define MM_SHARED_XEEN_CC_ARCHIVE_H
+
+#include "common/archive.h"
+#include "common/stream.h"
+
+namespace MM {
+namespace Shared {
+namespace Xeen {
+
+/**
+ * Details of a single entry in a CC file index
+ */
+struct CCEntry {
+ uint16 _id;
+ int _offset;
+ uint16 _size;
+ int _writeOffset;
+
+ CCEntry() : _id(0), _offset(0), _size(0), _writeOffset(0) {
+ }
+ CCEntry(uint16 id, uint32 offset, uint32 size)
+ : _id(id), _offset(offset), _size(size) {
+ }
+};
+
+/**
+ * Base Xeen CC file implementation
+ */
+class BaseCCArchive : public Common::Archive {
+protected:
+ Common::Array<CCEntry> _index;
+
+ /**
+ * Load the index of a given CC file
+ */
+ void loadIndex(Common::SeekableReadStream &stream);
+
+ /**
+ * Saves out the contents of the index. Used when creating savegames
+ */
+ void saveIndex(Common::WriteStream &stream);
+
+ /**
+ * Given a resource name, returns whether an entry exists, and returns
+ * the header index data for that entry
+ */
+ virtual bool getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const;
+
+ /**
+ * Given a resource Id, returns whether an entry exists, and returns
+ * the header index data for that entry
+ */
+ virtual bool getHeaderEntry(uint16 id, CCEntry &ccEntry) const;
+public:
+ /**
+ * Hash a given filename to produce the Id that represents it
+ */
+ static uint16 convertNameToId(const Common::String &resourceName);
+public:
+ BaseCCArchive() {
+ }
+
+ // Archive implementation
+ bool hasFile(const Common::Path &path) const override;
+ int listMembers(Common::ArchiveMemberList &list) const override;
+ const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
+};
+
+/**
+ * Xeen CC file implementation
+ */
+class CCArchive : public BaseCCArchive {
+private:
+ Common::String _filename;
+ Common::String _prefix;
+ bool _encoded;
+protected:
+ bool getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const override;
+public:
+ CCArchive(const Common::String &filename, bool encoded);
+ CCArchive(const Common::String &filename, const Common::String &prefix, bool encoded);
+ ~CCArchive() override;
+
+ // Archive implementation
+ Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
+};
+
+} // namespace Xeen
+} // namespace Shared
+} // namespace MM
+
+#endif
diff --git a/engines/mm/shared/xeen/xsurface.h b/engines/mm/shared/xeen/xsurface.h
index 58454c2c660..8c25cb8c48f 100644
--- a/engines/mm/shared/xeen/xsurface.h
+++ b/engines/mm/shared/xeen/xsurface.h
@@ -19,8 +19,8 @@
*
*/
-#ifndef XEEN_SHARED_XSURFACE_H
-#define XEEN_SHARED_XSURFACE_H
+#ifndef MM_SHARED_XEEN_XSURFACE_H
+#define MM_SHARED_XEEN_XSURFACE_H
#include "common/scummsys.h"
#include "common/system.h"
diff --git a/engines/mm/xeen/files.cpp b/engines/mm/xeen/files.cpp
index 6dcf984c34a..b26c48eb43c 100644
--- a/engines/mm/xeen/files.cpp
+++ b/engines/mm/xeen/files.cpp
@@ -32,206 +32,6 @@
namespace MM {
namespace Xeen {
-uint16 BaseCCArchive::convertNameToId(const Common::String &resourceName) {
- if (resourceName.empty())
- return 0xffff;
-
- Common::String name = resourceName;
- name.toUppercase();
-
- // Check if a resource number is being directly specified
- if (name.size() == 4) {
- char *endPtr;
- uint16 num = (uint16)strtol(name.c_str(), &endPtr, 16);
- if (!*endPtr)
- return num;
- }
-
- const byte *msgP = (const byte *)name.c_str();
- int total = *msgP++;
- for (; *msgP; total += *msgP++) {
- // Rotate the bits in 'total' right 7 places
- total = (total & 0x007F) << 9 | (total & 0xFF80) >> 7;
- }
-
- return total;
-}
-
-void BaseCCArchive::loadIndex(Common::SeekableReadStream &stream) {
- int count = stream.readUint16LE();
- size_t size = count * 8;
-
- // Read in the data for the archive's index
- byte *rawIndex = new byte[size];
-
- if (stream.read(rawIndex, size) != size) {
- delete[] rawIndex;
- error("Failed to read %zu bytes from CC file", size);
- }
-
- // Decrypt the index
- int seed = 0xac;
- for (int i = 0; i < count * 8; ++i, seed += 0x67) {
- rawIndex[i] = (byte)((((rawIndex[i] << 2) | (rawIndex[i] >> 6)) + seed) & 0xff);
- }
-
- // Extract the index data into entry structures
- _index.resize(count);
- const byte *entryP = &rawIndex[0];
- for (int idx = 0; idx < count; ++idx, entryP += 8) {
- CCEntry entry;
- entry._id = READ_LE_UINT16(entryP);
- entry._offset = READ_LE_UINT32(entryP + 2) & 0xffffff;
- entry._size = READ_LE_UINT16(entryP + 5);
- assert(!entryP[7]);
-
- _index[idx] = entry;
- }
-
- delete[] rawIndex;
-}
-
-void BaseCCArchive::saveIndex(Common::WriteStream &stream) {
- // Fill up the data for the index entries into a raw data block
- byte *rawIndex = new byte[_index.size() * 8];
- byte b;
-
- byte *entryP = rawIndex;
- for (uint i = 0; i < _index.size(); ++i, entryP += 8) {
- CCEntry &entry = _index[i];
- WRITE_LE_UINT16(&entryP[0], entry._id);
- WRITE_LE_UINT32(&entryP[2], entry._writeOffset);
- WRITE_LE_UINT16(&entryP[5], entry._size);
- entryP[7] = 0;
- }
-
- // Encrypt the index
- int seed = 0xac;
- for (uint i = 0; i < _index.size() * 8; ++i, seed += 0x67) {
- b = (rawIndex[i] - seed) & 0xff;
- b = (byte)((b >> 2) | (b << 6));
-
- assert(rawIndex[i] == (byte)((((b << 2) | (b >> 6)) + seed) & 0xff));
- rawIndex[i] = b;
- }
-
- // Write out the number of entries and the encrypted index data
- stream.writeUint16LE(_index.size());
- stream.write(rawIndex, _index.size() * 8);
-
- delete[] rawIndex;
-}
-
-bool BaseCCArchive::hasFile(const Common::Path &path) const {
- Common::String name = path.toString();
- CCEntry ccEntry;
- return getHeaderEntry(name, ccEntry);
-}
-
-bool BaseCCArchive::getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const {
- return getHeaderEntry(convertNameToId(resourceName), ccEntry);
-}
-
-bool BaseCCArchive::getHeaderEntry(uint16 id, CCEntry &ccEntry) const {
- // Loop through the index
- for (uint i = 0; i < _index.size(); ++i) {
- if (_index[i]._id == id) {
- ccEntry = _index[i];
- return true;
- }
- }
-
- // Could not find an entry
- return false;
-}
-
-const Common::ArchiveMemberPtr BaseCCArchive::getMember(const Common::Path &path) const {
- Common::String name = path.toString();
- if (!hasFile(name))
- return Common::ArchiveMemberPtr();
-
- return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this));
-}
-
-int BaseCCArchive::listMembers(Common::ArchiveMemberList &list) const {
- // CC files don't maintain the original filenames, so we can't list it
- return 0;
-}
-
-/*------------------------------------------------------------------------*/
-
-CCArchive::CCArchive(const Common::String &filename, bool encoded):
- BaseCCArchive(), _filename(filename), _encoded(encoded) {
- File f(filename, SearchMan);
- loadIndex(f);
-}
-
-CCArchive::CCArchive(const Common::String &filename, const Common::String &prefix,
- bool encoded): BaseCCArchive(), _filename(filename),
- _prefix(prefix), _encoded(encoded) {
- _prefix.toLowercase();
- File f(filename, SearchMan);
- loadIndex(f);
-}
-
-CCArchive::~CCArchive() {
-}
-
-bool CCArchive::getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const {
- Common::String resName = resourceName;
-
- if (!_prefix.empty() && resName.contains('|')) {
- resName.toLowercase();
- Common::String prefix = _prefix + "|";
-
- if (!strncmp(resName.c_str(), prefix.c_str(), prefix.size()))
- // Matching CC prefix, so strip it off and allow processing to
- // continue onto the base getHeaderEntry method
- resName = Common::String(resName.c_str() + prefix.size());
- else
- // Not matching prefix, so don't allow a match
- return false;
- }
-
- return BaseCCArchive::getHeaderEntry(resName, ccEntry);
-}
-
-Common::SeekableReadStream *CCArchive::createReadStreamForMember(const Common::Path &path) const {
- Common::String name = path.toString();
- CCEntry ccEntry;
-
- if (getHeaderEntry(name, ccEntry)) {
- // Open the correct CC file
- Common::File f;
- if (!f.open(_filename))
- error("Could not open CC file");
-
- // Read in the data for the specific resource
- if (!f.seek(ccEntry._offset))
- error("Failed to seek to %d bytes in CC file", ccEntry._offset);
-
- byte *data = (byte *)malloc(ccEntry._size);
-
- if (f.read(data, ccEntry._size) != ccEntry._size) {
- free(data);
- error("Failed to read %hu bytes in CC file", ccEntry._size);
- }
-
- if (_encoded) {
- // Decrypt the data
- for (int i = 0; i < ccEntry._size; ++i)
- data[i] ^= 0x35;
- }
-
- // Return the data as a stream
- return new Common::MemoryReadStream(data, ccEntry._size, DisposeAfterUse::YES);
- }
-
- return nullptr;
-}
-
-/*------------------------------------------------------------------------*/
-
FileManager::FileManager(XeenEngine *vm) {
_ccNum = vm->getGameID() == GType_DarkSide;
File::_xeenCc = File::_darkCc = File::_introCc = nullptr;
diff --git a/engines/mm/xeen/files.h b/engines/mm/xeen/files.h
index 5e28ed174a1..f5702a74aa7 100644
--- a/engines/mm/xeen/files.h
+++ b/engines/mm/xeen/files.h
@@ -30,13 +30,16 @@
#include "common/serializer.h"
#include "common/str-array.h"
#include "graphics/surface.h"
+#include "mm/shared/xeen/cc_archive.h"
namespace MM {
namespace Xeen {
+using Shared::Xeen::BaseCCArchive;
+using Shared::Xeen::CCArchive;
+using Shared::Xeen::CCEntry;
+
class XeenEngine;
-class CCArchive;
-class BaseCCArchive;
class File;
class SaveArchive;
class Party;
@@ -57,21 +60,6 @@ class SavesManager;
_bytesSynced += SIZE; \
}
-/**
- * Details of a single entry in a CC file index
- */
-struct CCEntry {
- uint16 _id;
- int _offset;
- uint16 _size;
- int _writeOffset;
-
- CCEntry() : _id(0), _offset(0), _size(0), _writeOffset(0) {}
- CCEntry(uint16 id, uint32 offset, uint32 size)
- : _id(id), _offset(offset), _size(size) {
- }
-};
-
/*
* Main resource manager
*/
@@ -243,67 +231,6 @@ public:
}
};
-/**
- * Base Xeen CC file implementation
- */
-class BaseCCArchive : public Common::Archive {
-protected:
- Common::Array<CCEntry> _index;
-
- /**
- * Load the index of a given CC file
- */
- void loadIndex(Common::SeekableReadStream &stream);
-
- /**
- * Saves out the contents of the index. Used when creating savegames
- */
- void saveIndex(Common::WriteStream &stream);
-
- /**
- * Given a resource name, returns whether an entry exists, and returns
- * the header index data for that entry
- */
- virtual bool getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const;
-
- /**
- * Given a resource Id, returns whether an entry exists, and returns
- * the header index data for that entry
- */
- virtual bool getHeaderEntry(uint16 id, CCEntry &ccEntry) const;
-public:
- /**
- * Hash a given filename to produce the Id that represents it
- */
- static uint16 convertNameToId(const Common::String &resourceName);
-public:
- BaseCCArchive() {}
-
- // Archive implementation
- bool hasFile(const Common::Path &path) const override;
- int listMembers(Common::ArchiveMemberList &list) const override;
- const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
-};
-
-/**
- * Xeen CC file implementation
- */
-class CCArchive : public BaseCCArchive {
-private:
- Common::String _filename;
- Common::String _prefix;
- bool _encoded;
-protected:
- bool getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const override;
-public:
- CCArchive(const Common::String &filename, bool encoded);
- CCArchive(const Common::String &filename, const Common::String &prefix, bool encoded);
- ~CCArchive() override;
-
- // Archive implementation
- Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
-};
-
class SaveArchive : public BaseCCArchive {
friend class OutFile;
private:
More information about the Scummvm-git-logs
mailing list