From 0e46c809d10dcd8fd766d7adcb966785e7955f5b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 18 Feb 2014 20:08:58 -0500 Subject: MADS: Initial implementation of MSurface class and dependant classes --- engines/mads/resources.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 engines/mads/resources.cpp (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp new file mode 100644 index 0000000000..27b94a9e55 --- /dev/null +++ b/engines/mads/resources.cpp @@ -0,0 +1,32 @@ +/* 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/scummsys.h" +#include "mads/resources.h" + +namespace MADS { + +ResourcesManager::ResourcesManager(MADSEngine *vm) { + _vm = vm; +} + +} // End of namespace MADS -- cgit v1.2.3 From 4581b26b12d21801eee0c5df2dbd1b260300498c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 20 Feb 2014 22:27:01 -0500 Subject: MADS: Implemented resource manager using ScummVM Archive interface --- engines/mads/resources.cpp | 259 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 257 insertions(+), 2 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 27b94a9e55..0630230bec 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -21,12 +21,267 @@ */ #include "common/scummsys.h" +#include "common/archive.h" +#include "common/substream.h" +#include "common/textconsole.h" +#include "mads/mads.h" #include "mads/resources.h" namespace MADS { -ResourcesManager::ResourcesManager(MADSEngine *vm) { - _vm = vm; +enum ResourceType {RESTYPE_ROOM, RESTYPE_SC, RESTYPE_TEXT, RESTYPE_QUO, RESTYPE_I, + RESTYPE_OB, RESTYPE_FONT, RESTYPE_SOUND, RESTYPE_SPEECH, RESTYPE_HAS_EXT, RESTYPE_NO_EXT}; + +/** + * HAG Archives implementation + */ +class HagArchive : public Common::Archive { +private: + /** + * Details of a single entry in a HAG file index + */ + struct HagEntry { + Common::String _resourceName; + uint32 _offset; + uint32 _size; + + HagEntry(): _offset(0), _size(0) {} + HagEntry(Common::String resourceName, uint32 offset, uint32 size): + _resourceName(resourceName), _offset(offset), _size(size) {} + }; + + class HagIndex { + public: + Common::List _entries; + Common::String _filename; + }; + + Common::Array _index; + + /** + * Load the index of all the game's HAG files + */ + void loadIndex(); + + /** + * Given a resource name, opens up the correct HAG file and returns whether + * an entry with the given name exists. + */ + bool getHeaderEntry(const Common::String &resourceName, HagIndex &hagIndex, HagEntry &hagEntry) const; + + /** + * Returns the HAG resource filename that will contain a given resource + */ + Common::String getResourceFilename(const Common::String &resourceName) const; + + /** + * Return a resource type given a resource name + */ + ResourceType getResourceType(const Common::String &resourceName) const; +public: + HagArchive(); + virtual ~HagArchive(); + + // Archive implementation + virtual bool hasFile(const Common::String &name) const; + virtual int listMembers(Common::ArchiveMemberList &list) const; + virtual const Common::ArchiveMemberPtr getMember(const Common::String &name) const; + virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; +}; + +void ResourcesManager::init(MADSEngine *vm) { + if (vm->getGameFeatures() & GF_MADS) + SearchMan.add("HAG", new HagArchive()); + else + error("Unsupported game engine"); +} + +/*------------------------------------------------------------------------*/ + +void File::openFile(const Common::String &filename) { + if (!Common::File::open(filename)) + error("Could not open file - %s", filename.c_str()); +} + +/*------------------------------------------------------------------------*/ + +const char *const MADSCONCAT_STRING = "MADSCONCAT"; + +HagArchive::HagArchive() { + loadIndex(); +} + +HagArchive::~HagArchive() { +} + +// Archive implementation +bool HagArchive::hasFile(const Common::String &name) const { + HagIndex hagIndex; + HagEntry hagEntry; + return getHeaderEntry(name, hagIndex, hagEntry); +} + +int HagArchive::listMembers(Common::ArchiveMemberList &list) const { + int members = 0; + + for (uint hagCtr = 0; hagCtr < _index.size(); ++hagCtr) { + HagIndex hagIndex = _index[hagCtr]; + Common::List::iterator i; + + for (i = hagIndex._entries.begin(); i != hagIndex._entries.end(); ++i) { + list.push_back(Common::ArchiveMemberList::value_type( + new Common::GenericArchiveMember((*i)._resourceName, this))); + ++members; + } + } + + return members; +} + +const Common::ArchiveMemberPtr HagArchive::getMember(const Common::String &name) const { + if (!hasFile(name)) + return Common::ArchiveMemberPtr(); + + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); +} + +Common::SeekableReadStream *HagArchive::createReadStreamForMember(const Common::String &name) const { + HagIndex hagIndex; + HagEntry hagEntry; + + if (getHeaderEntry(name, hagIndex, hagEntry)) { + // Entry found. If the correct file is not already open, open it + Common::File f; + if (!f.open(hagIndex._filename)) + error("Could not open HAG file"); + + // Return a substream for the specific resource + return new Common::SeekableSubReadStream(&f, + hagEntry._offset, hagEntry._size, DisposeAfterUse::YES); + } + + return nullptr; +} + +void HagArchive::loadIndex() { + Common::File hagFile; + + for (int sectionIndex = -1; sectionIndex < 10; ++sectionIndex) { + Common::String filename = (sectionIndex == -1) ? "GLOBAL.HAG" : + Common::String::format("SECTION%d.HAG", sectionIndex); + if (!hagFile.open(filename)) + error("Could not locate HAG file - %s", filename.c_str()); + + // Check for header + char headerBuffer[16]; + if ((hagFile.read(headerBuffer, 16) != 16) || + (strncmp(headerBuffer, MADSCONCAT_STRING, 10) != 0)) + error("Invalid HAG file opened"); + + // Scan through the HAG index + int numEntries = hagFile.readUint16LE(); + + HagIndex hagIndex; + for (int idx = 0; idx < numEntries; ++idx) { + // Read in the details of the next resource + char resourceBuffer[14]; + uint32 offset = hagFile.readUint32LE(); + uint32 size = hagFile.readUint32LE(); + hagFile.read(resourceBuffer, 14); + + hagIndex._entries.push_back(HagEntry(resourceBuffer, offset, size)); + } + + hagFile.close(); + _index.push_back(hagIndex); + } +} + +bool HagArchive::getHeaderEntry(const Common::String &resourceName, + HagIndex &hagIndex, HagEntry &hagEntry) const { + Common::String resName = resourceName; + resName.toUppercase(); + if (resName[0] == '*') + resName.deleteChar(0); + + Common::String hagFilename = getResourceFilename(resName); + + // Find the index for the given file + for (uint hagCtr = 0; hagCtr < _index.size(); ++hagCtr) { + hagIndex = _index[hagCtr]; + + if (hagIndex._filename == hagFilename) { + Common::List::iterator ei; + for (ei = hagIndex._entries.begin(); ei != hagIndex._entries.end(); ++ei) { + hagEntry = *ei; + if (hagEntry._resourceName == resName) + return true; + } + } + } + + return false; +} + +Common::String HagArchive::getResourceFilename(const Common::String &resourceName) const { + ResourceType resType = getResourceType(resourceName); + Common::String outputFilename = "GLOBAL.HAG"; + + if ((resType == RESTYPE_ROOM) || (resType == RESTYPE_SC)) { + int value = atoi(resourceName.c_str() + 2); + int hagFileNum = (resType == RESTYPE_ROOM) ? value / 100 : value; + + if (hagFileNum > 0) + outputFilename = Common::String::format("SECTION%d.HAG", hagFileNum); + } + + if (resType == RESTYPE_SPEECH) + outputFilename = "SPEECH.HAG"; + + return outputFilename; +} + +ResourceType HagArchive::getResourceType(const Common::String &resourceName) const { + if (resourceName.hasPrefix("RM")) { + // Room resource + return RESTYPE_ROOM; + } else if (resourceName.hasPrefix("SC")) { + // SC resource + return RESTYPE_SC; + } else if (resourceName.hasSuffix(".TXT")) { + // Text resource + return RESTYPE_TEXT; + } else if (resourceName.hasSuffix(".QUO")) { + // QUO resource + return RESTYPE_QUO; + } else if (resourceName.hasPrefix("I")) { + // I resource + return RESTYPE_I; + } else if (resourceName.hasPrefix("OB")) { + // OB resource + return RESTYPE_OB; + } else if (resourceName.hasPrefix("FONT")) { + // FONT resource + return RESTYPE_FONT; + } else if (resourceName.hasPrefix("SOUND")) { + // SOUND resource + return RESTYPE_SOUND; + } else if (resourceName.hasPrefix("SPCHC")) { + // SPEECH resource + return RESTYPE_SPEECH; + } + + // Check for a known extension + const char *extPos = strchr(resourceName.c_str(), '.'); + if (extPos) { + ++extPos; + if (!strcmp(extPos, "FL") || !strcmp(extPos, "LBM") || !strcmp(extPos, "ANM") || + !strcmp(extPos, "AA") || !strcmp(extPos, "SS")) { + return RESTYPE_HAS_EXT; + } + } + + return RESTYPE_NO_EXT; } } // End of namespace MADS -- cgit v1.2.3 From 7020dbea6a56e41dc199257e898240451bb5bfb1 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 21 Feb 2014 21:03:15 -0500 Subject: MADS: Fixes for the HagArchive reading resources --- engines/mads/resources.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 0630230bec..ac46df96c5 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -22,7 +22,6 @@ #include "common/scummsys.h" #include "common/archive.h" -#include "common/substream.h" #include "common/textconsole.h" #include "mads/mads.h" #include "mads/resources.h" @@ -155,9 +154,9 @@ Common::SeekableReadStream *HagArchive::createReadStreamForMember(const Common:: if (!f.open(hagIndex._filename)) error("Could not open HAG file"); - // Return a substream for the specific resource - return new Common::SeekableSubReadStream(&f, - hagEntry._offset, hagEntry._size, DisposeAfterUse::YES); + // Return a new stream for the specific resource + f.seek(hagEntry._offset); + return f.readStream(hagEntry._size); } return nullptr; @@ -182,6 +181,8 @@ void HagArchive::loadIndex() { int numEntries = hagFile.readUint16LE(); HagIndex hagIndex; + hagIndex._filename = filename; + for (int idx = 0; idx < numEntries; ++idx) { // Read in the details of the next resource char resourceBuffer[14]; -- cgit v1.2.3 From 3df12371873cb8e3380422aa3095e367408526af Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 22 Feb 2014 14:20:34 -0500 Subject: MADS: Removed M4-specific code. Keeping engine MADS-specific for now --- engines/mads/resources.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index ac46df96c5..fe021fcfd8 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -89,10 +89,7 @@ public: }; void ResourcesManager::init(MADSEngine *vm) { - if (vm->getGameFeatures() & GF_MADS) - SearchMan.add("HAG", new HagArchive()); - else - error("Unsupported game engine"); + SearchMan.add("HAG", new HagArchive()); } /*------------------------------------------------------------------------*/ -- cgit v1.2.3 From cc16e42f2029955e066450d63bfb666b9ab47109 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 24 Feb 2014 20:05:35 -0500 Subject: MADS: Beginnings of scene-specific data loading --- engines/mads/resources.cpp | 54 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index fe021fcfd8..9f856eeefc 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -88,19 +88,6 @@ public: virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; }; -void ResourcesManager::init(MADSEngine *vm) { - SearchMan.add("HAG", new HagArchive()); -} - -/*------------------------------------------------------------------------*/ - -void File::openFile(const Common::String &filename) { - if (!Common::File::open(filename)) - error("Could not open file - %s", filename.c_str()); -} - -/*------------------------------------------------------------------------*/ - const char *const MADSCONCAT_STRING = "MADSCONCAT"; HagArchive::HagArchive() { @@ -282,4 +269,45 @@ ResourceType HagArchive::getResourceType(const Common::String &resourceName) con return RESTYPE_NO_EXT; } +/*------------------------------------------------------------------------*/ + +void Resources::init(MADSEngine *vm) { + SearchMan.add("HAG", new HagArchive()); +} + +Common::String Resources::formatName(RESPREFIX resType, int id, const Common::String &ext) { + Common::String result = "*"; + + if (resType == 3 && !id) { + id = id / 100; + } + + if (!ext.empty()) { + switch (resType) { + case RESPREFIX_GL: + result += "GL000"; + break; + case RESPREFIX_SC: + result += Common::String::format("SC%.3d", id); + break; + case RESPREFIX_RM: + result += Common::String::format("RM%.3d", id); + break; + default: + break; + } + + result += ext; + } + + return result; +} + +/*------------------------------------------------------------------------*/ + +void File::openFile(const Common::String &filename) { + if (!Common::File::open(filename)) + error("Could not open file - %s", filename.c_str()); +} + } // End of namespace MADS -- cgit v1.2.3 From c49d7196fcabf18d9e97711f67b864808ca7848a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 25 Feb 2014 23:10:51 -0500 Subject: MADS: In progress implementation of loadScene --- engines/mads/resources.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 9f856eeefc..f24f7d2fc7 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -303,6 +303,19 @@ Common::String Resources::formatName(RESPREFIX resType, int id, const Common::St return result; } +Common::String Resources::formatResource(const Common::String &resName, + const Common::String &hagFilename) { + int v1 = 0, v2 = 0; + + if (resName.hasPrefix("*")) { + // Resource file specified + error("TODO: formatResource"); + } else { + // File outside of hag file + return resName; + } +} + /*------------------------------------------------------------------------*/ void File::openFile(const Common::String &filename) { -- cgit v1.2.3 From badb8d97444767b7d8fea0f877ac044249696a5f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 28 Feb 2014 20:37:42 -0500 Subject: MADS: More work implementing scene info loading --- engines/mads/resources.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index f24f7d2fc7..8cfc1a290a 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -305,7 +305,7 @@ Common::String Resources::formatName(RESPREFIX resType, int id, const Common::St Common::String Resources::formatResource(const Common::String &resName, const Common::String &hagFilename) { - int v1 = 0, v2 = 0; +// int v1 = 0, v2 = 0; if (resName.hasPrefix("*")) { // Resource file specified -- cgit v1.2.3 From 73a7140be775693533db183f353fc9c82c14fa53 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 5 Mar 2014 21:36:02 -0500 Subject: MADS: Starting implementation of scene group 8 --- engines/mads/resources.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 8cfc1a290a..5e490c2719 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -303,6 +303,47 @@ Common::String Resources::formatName(RESPREFIX resType, int id, const Common::St return result; } +Common::String Resources::formatName(int prefix, char asciiCh, int id, EXTTYPE extType, + const Common::String &suffix) { + Common::String result; + if (prefix <= 0) { + result = "*"; + } + else { + result = Common::String::format("%s%.3d", + (prefix < 100) ? "*SC" : "*RM", prefix); + } + + result += Common::String::format("%c%d", asciiCh, id); + if (!suffix.empty()) + result += suffix; + + switch (extType) { + case EXT_SS: + result += ".SS"; + break; + case EXT_AA: + result += ".AA"; + break; + case EXT_DAT: + result += ".DAT"; + break; + case EXT_HH: + result += ".HH"; + break; + case EXT_ART: + result += ".ART"; + break; + case EXT_INT: + result += ".INT"; + break; + default: + break; + } + + return result; +} + Common::String Resources::formatResource(const Common::String &resName, const Common::String &hagFilename) { // int v1 = 0, v2 = 0; @@ -316,6 +357,10 @@ Common::String Resources::formatResource(const Common::String &resName, } } +Common::String Resources::formatAAName(int idx) { + return formatName(0, 'I', idx, EXT_AA, ""); +} + /*------------------------------------------------------------------------*/ void File::openFile(const Common::String &filename) { -- cgit v1.2.3 From 8bfa5f1da2d84fafdda88aac0cdd5e17ebfbc100 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 8 Mar 2014 08:25:46 -0500 Subject: MADS: Make resource file access case insensitive --- engines/mads/resources.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 5e490c2719..f85d5ce340 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -199,7 +199,7 @@ bool HagArchive::getHeaderEntry(const Common::String &resourceName, Common::List::iterator ei; for (ei = hagIndex._entries.begin(); ei != hagIndex._entries.end(); ++ei) { hagEntry = *ei; - if (hagEntry._resourceName == resName) + if (hagEntry._resourceName.compareToIgnoreCase(resName) == 0) return true; } } -- cgit v1.2.3 From 408f5e79df5e8a33367fdf2a9c17b424953edace Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 12 Mar 2014 22:45:33 -0400 Subject: MADS: General cleanup and minor fixes --- engines/mads/resources.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index f85d5ce340..140a34749a 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -308,8 +308,7 @@ Common::String Resources::formatName(int prefix, char asciiCh, int id, EXTTYPE e Common::String result; if (prefix <= 0) { result = "*"; - } - else { + } else { result = Common::String::format("%s%.3d", (prefix < 100) ? "*SC" : "*RM", prefix); } -- cgit v1.2.3 From 17870490873bd9ba040b58cb5fbfc1c8480d5461 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 16 Mar 2014 01:29:02 -0400 Subject: MADS: Add loading of game inventory list and quotes --- engines/mads/resources.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 140a34749a..2742b5b435 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -313,7 +313,9 @@ Common::String Resources::formatName(int prefix, char asciiCh, int id, EXTTYPE e (prefix < 100) ? "*SC" : "*RM", prefix); } - result += Common::String::format("%c%d", asciiCh, id); + result += Common::String::format("%c", asciiCh); + if (id >= 0) + result += Common::String::format("%d", id); if (!suffix.empty()) result += suffix; -- cgit v1.2.3 From 3813eddf023e25692d92402ddcbdbe491359c698 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 18 Apr 2014 09:01:04 -0400 Subject: MADS: Skip the unused SECTION0.HAG for now --- engines/mads/resources.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 2742b5b435..aef22d3734 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -150,6 +150,9 @@ void HagArchive::loadIndex() { Common::File hagFile; for (int sectionIndex = -1; sectionIndex < 10; ++sectionIndex) { + if (sectionIndex == 0) + continue; + Common::String filename = (sectionIndex == -1) ? "GLOBAL.HAG" : Common::String::format("SECTION%d.HAG", sectionIndex); if (!hagFile.open(filename)) -- cgit v1.2.3 From 16bbc100ddf15da2c321bf54cf1f66f580dcdc93 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 27 Apr 2014 21:15:46 +0300 Subject: MADS: Handle the missing sections in Phantom and Dragonsphere --- engines/mads/resources.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index aef22d3734..b6caed7b0c 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -60,7 +60,7 @@ private: /** * Load the index of all the game's HAG files */ - void loadIndex(); + void loadIndex(MADSEngine *vm); /** * Given a resource name, opens up the correct HAG file and returns whether @@ -78,7 +78,7 @@ private: */ ResourceType getResourceType(const Common::String &resourceName) const; public: - HagArchive(); + HagArchive(MADSEngine *vm); virtual ~HagArchive(); // Archive implementation @@ -90,8 +90,8 @@ public: const char *const MADSCONCAT_STRING = "MADSCONCAT"; -HagArchive::HagArchive() { - loadIndex(); +HagArchive::HagArchive(MADSEngine *vm) { + loadIndex(vm); } HagArchive::~HagArchive() { @@ -146,13 +146,25 @@ Common::SeekableReadStream *HagArchive::createReadStreamForMember(const Common:: return nullptr; } -void HagArchive::loadIndex() { +void HagArchive::loadIndex(MADSEngine *vm) { Common::File hagFile; for (int sectionIndex = -1; sectionIndex < 10; ++sectionIndex) { if (sectionIndex == 0) continue; + // Dragonsphere does not have some sections - skip them + if (vm->getGameID() == GType_Dragonsphere) { + if (sectionIndex == 7 || sectionIndex == 8) + continue; + } + + // Phantom does not have some sections - skip them + if (vm->getGameID() == GType_Phantom) { + if (sectionIndex == 6 || sectionIndex == 7 || sectionIndex == 8) + continue; + } + Common::String filename = (sectionIndex == -1) ? "GLOBAL.HAG" : Common::String::format("SECTION%d.HAG", sectionIndex); if (!hagFile.open(filename)) @@ -275,7 +287,7 @@ ResourceType HagArchive::getResourceType(const Common::String &resourceName) con /*------------------------------------------------------------------------*/ void Resources::init(MADSEngine *vm) { - SearchMan.add("HAG", new HagArchive()); + SearchMan.add("HAG", new HagArchive(vm)); } Common::String Resources::formatName(RESPREFIX resType, int id, const Common::String &ext) { -- cgit v1.2.3 From b5949010a61e3d12f22ea762ed8d09cc1a79b850 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 1 May 2014 22:36:36 -0400 Subject: MADS: Implemented more savegame synchronization --- engines/mads/resources.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index b6caed7b0c..f0609448bb 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -384,4 +384,45 @@ void File::openFile(const Common::String &filename) { error("Could not open file - %s", filename.c_str()); } +/*------------------------------------------------------------------------*/ + +void SynchronizedList::synchronize(Common::Serializer &s) { + int v; + int count = size(); + s.syncAsUint16LE(count); + + if (s.isSaving()) { + for (int idx = 0; idx < count; ++idx) { + v = (*this)[idx]; + s.syncAsSint32LE(v); + } + } else { + clear(); + reserve(count); + for (int idx = 0; idx < count; ++idx) { + s.syncAsSint32LE(v); + push_back(v); + } + } +} + +/*------------------------------------------------------------------------*/ + +void synchronizeString(Common::Serializer &s, Common::String &str) { + int len = str.size(); + char c; + s.syncAsUint16LE(len); + + if (s.isSaving()) { + s.syncBytes((byte *)str.c_str(), len); + } else { + str.clear(); + for (int i = 0; i < len; ++i) { + s.syncAsByte(c); + str += c; + } + } +} + + } // End of namespace MADS -- cgit v1.2.3 From b7dd01fdefd910c3c0f6291145ceab4060ae1a70 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 8 May 2014 11:43:23 +0300 Subject: MADS: Remove trailing whitespace --- engines/mads/resources.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index f0609448bb..4f5596dea6 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -169,10 +169,10 @@ void HagArchive::loadIndex(MADSEngine *vm) { Common::String::format("SECTION%d.HAG", sectionIndex); if (!hagFile.open(filename)) error("Could not locate HAG file - %s", filename.c_str()); - + // Check for header char headerBuffer[16]; - if ((hagFile.read(headerBuffer, 16) != 16) || + if ((hagFile.read(headerBuffer, 16) != 16) || (strncmp(headerBuffer, MADSCONCAT_STRING, 10) != 0)) error("Invalid HAG file opened"); @@ -269,7 +269,7 @@ ResourceType HagArchive::getResourceType(const Common::String &resourceName) con } else if (resourceName.hasPrefix("SPCHC")) { // SPEECH resource return RESTYPE_SPEECH; - } + } // Check for a known extension const char *extPos = strchr(resourceName.c_str(), '.'); @@ -360,7 +360,7 @@ Common::String Resources::formatName(int prefix, char asciiCh, int id, EXTTYPE e return result; } -Common::String Resources::formatResource(const Common::String &resName, +Common::String Resources::formatResource(const Common::String &resName, const Common::String &hagFilename) { // int v1 = 0, v2 = 0; -- cgit v1.2.3 From 9613db3edf71787eb211076081281a9bc5c2f6ba Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 19 May 2014 22:21:58 +0200 Subject: MADS: Reduce the scope of a variable in Resource --- engines/mads/resources.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 4f5596dea6..83077b602f 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -410,13 +410,13 @@ void SynchronizedList::synchronize(Common::Serializer &s) { void synchronizeString(Common::Serializer &s, Common::String &str) { int len = str.size(); - char c; s.syncAsUint16LE(len); if (s.isSaving()) { s.syncBytes((byte *)str.c_str(), len); } else { str.clear(); + char c; for (int i = 0; i < len; ++i) { s.syncAsByte(c); str += c; -- cgit v1.2.3 From 555b4dfd6e076dd5ef5cfc982fb5dbf3e211d198 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 20 May 2014 15:07:45 +0300 Subject: MADS: Load scene speech resources for V2 CD games --- engines/mads/resources.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 83077b602f..0d5aee1526 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -149,7 +149,7 @@ Common::SeekableReadStream *HagArchive::createReadStreamForMember(const Common:: void HagArchive::loadIndex(MADSEngine *vm) { Common::File hagFile; - for (int sectionIndex = -1; sectionIndex < 10; ++sectionIndex) { + for (int sectionIndex = -1; sectionIndex < 11; ++sectionIndex) { if (sectionIndex == 0) continue; @@ -167,6 +167,13 @@ void HagArchive::loadIndex(MADSEngine *vm) { Common::String filename = (sectionIndex == -1) ? "GLOBAL.HAG" : Common::String::format("SECTION%d.HAG", sectionIndex); + if (sectionIndex == 10) { + // Speech + if (!Common::File::exists("SPEECH.HAG")) + break; + else + filename = "SPEECH.HAG"; + } if (!hagFile.open(filename)) error("Could not locate HAG file - %s", filename.c_str()); -- cgit v1.2.3 From 6bfc9ce8f25d5d08e3a0aa1d5fa55e3dfe93b97f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 20 May 2014 21:22:01 -0400 Subject: MADS: Completely remove synchronizeString in favour of syncString --- engines/mads/resources.cpp | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 0d5aee1526..745583b516 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -413,23 +413,4 @@ void SynchronizedList::synchronize(Common::Serializer &s) { } } -/*------------------------------------------------------------------------*/ - -void synchronizeString(Common::Serializer &s, Common::String &str) { - int len = str.size(); - s.syncAsUint16LE(len); - - if (s.isSaving()) { - s.syncBytes((byte *)str.c_str(), len); - } else { - str.clear(); - char c; - for (int i = 0; i < len; ++i) { - s.syncAsByte(c); - str += c; - } - } -} - - } // End of namespace MADS -- cgit v1.2.3 From 6f8517a2770b6c20496cb70460a8ddfc9964b8f3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 26 May 2014 12:33:24 -0400 Subject: MADS: Fix compiler warning --- engines/mads/resources.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 745583b516..0bb95debdf 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -394,7 +394,7 @@ void File::openFile(const Common::String &filename) { /*------------------------------------------------------------------------*/ void SynchronizedList::synchronize(Common::Serializer &s) { - int v; + int v = 0; int count = size(); s.syncAsUint16LE(count); -- cgit v1.2.3 From 9866aba2e43da914a17d17b695456ca25a875469 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 27 May 2014 00:58:25 +0200 Subject: MADS: Slight formatting fixes. --- engines/mads/resources.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'engines/mads/resources.cpp') diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index 0bb95debdf..1fb75e6ba2 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -44,9 +44,10 @@ private: uint32 _offset; uint32 _size; - HagEntry(): _offset(0), _size(0) {} - HagEntry(Common::String resourceName, uint32 offset, uint32 size): - _resourceName(resourceName), _offset(offset), _size(size) {} + HagEntry() : _offset(0), _size(0) {} + HagEntry(Common::String resourceName, uint32 offset, uint32 size) + : _resourceName(resourceName), _offset(offset), _size(size) { + } }; class HagIndex { -- cgit v1.2.3