diff options
author | Paul Gilbert | 2016-05-15 18:44:47 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-15 19:11:06 -0400 |
commit | 053ff7ab75e0ee1f18606dd6c7488c5cc0d31ae5 (patch) | |
tree | cead39d2d48e3ed2d6c2b0ad18afabde4518dd47 | |
parent | 2680caa5bde09e3ecc7a1c8ef6c345e2bc9a134b (diff) | |
download | scummvm-rg350-053ff7ab75e0ee1f18606dd6c7488c5cc0d31ae5.tar.gz scummvm-rg350-053ff7ab75e0ee1f18606dd6c7488c5cc0d31ae5.tar.bz2 scummvm-rg350-053ff7ab75e0ee1f18606dd6c7488c5cc0d31ae5.zip |
TITANIC: Change engine to use titanic.dat
-rw-r--r-- | engines/titanic/support/files_manager.cpp | 38 | ||||
-rw-r--r-- | engines/titanic/support/files_manager.h | 18 | ||||
-rw-r--r-- | engines/titanic/support/font.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/true_talk/title_engine.cpp | 2 |
4 files changed, 50 insertions, 10 deletions
diff --git a/engines/titanic/support/files_manager.cpp b/engines/titanic/support/files_manager.cpp index eb2f95e92e..c415731f16 100644 --- a/engines/titanic/support/files_manager.cpp +++ b/engines/titanic/support/files_manager.cpp @@ -28,10 +28,38 @@ namespace Titanic { CFilesManager::CFilesManager() : _gameManager(nullptr), _assetsPath("Assets"), _field0(0), _drive(-1), _field18(0), _field1C(0), _field3C(0) { - _exeResources.loadFromEXE("st.exe"); + loadResourceIndex(); } CFilesManager::~CFilesManager() { + _datFile.close(); +} + +void CFilesManager::loadResourceIndex() { + if (!_datFile.open("titanic.dat")) + error("Could not find titanic.dat data file"); + + uint headerId = _datFile.readUint32BE(); + uint version = _datFile.readUint16LE(); + if (headerId != MKTAG('S', 'V', 'T', 'N') || version < 1) + error("Invalid data file"); + + // Read in entries + uint offset, size; + char c; + Common::String resourceName; + for (;;) { + offset = _datFile.readUint32LE(); + size = _datFile.readUint32LE(); + if (size == 0) + break; + + Common::String resName; + while ((c = _datFile.readByte()) != '\0') + resName += c; + + _resources[resName] = ResourceEntry(offset, size); + } } bool CFilesManager::fileExists(const CString &name) { @@ -92,9 +120,11 @@ void CFilesManager::preload(const CString &name) { // We don't currently do any preloading of resources } -Common::SeekableReadStream *CFilesManager::getResource( - Common::WinResourceID area, Common::WinResourceID name) { - return _exeResources.getResource(area, name); +Common::SeekableReadStream *CFilesManager::getResource(const CString &str) { + ResourceEntry resEntry = _resources[str]; + _datFile.seek(resEntry._offset); + + return _datFile.readStream(resEntry._size); } } // End of namespace Titanic diff --git a/engines/titanic/support/files_manager.h b/engines/titanic/support/files_manager.h index 6be6a13166..ec0c7fc008 100644 --- a/engines/titanic/support/files_manager.h +++ b/engines/titanic/support/files_manager.h @@ -23,7 +23,7 @@ #ifndef TITANIC_FILES_MANAGER_H #define TITANIC_FILES_MANAGER_H -#include "common/winexe_pe.h" +#include "common/hashmap.h" #include "titanic/core/list.h" #include "titanic/support/screen_manager.h" @@ -35,9 +35,18 @@ class CFilesManagerList : public List<ListItem> { }; class CFilesManager { + struct ResourceEntry { + uint _offset; + uint _size; + + ResourceEntry() : _offset(0), _size(0) {} + ResourceEntry(uint offset, uint size) : _offset(offset), _size(size) {} + }; + typedef Common::HashMap<Common::String, ResourceEntry> ResourceHash; private: CGameManager *_gameManager; - Common::PEResources _exeResources; + Common::File _datFile; + ResourceHash _resources; CFilesManagerList _list; CString _string1; CString _string2; @@ -47,6 +56,8 @@ private: int _field1C; int _field3C; const CString _assetsPath; +private: + void loadResourceIndex(); public: CFilesManager(); ~CFilesManager(); @@ -90,8 +101,7 @@ public: /** * Get a resource from the executable */ - Common::SeekableReadStream *getResource(Common::WinResourceID area, - Common::WinResourceID name); + Common::SeekableReadStream *getResource(const CString &str); }; } // End of namespace Titanic diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp index 916f02097b..c960e2fa9e 100644 --- a/engines/titanic/support/font.cpp +++ b/engines/titanic/support/font.cpp @@ -42,7 +42,7 @@ STFont::~STFont() { void STFont::load(int fontNumber) { assert(!_dataPtr); Common::SeekableReadStream *stream = g_vm->_filesManager->getResource( - Common::WinResourceID("STFONT"), fontNumber); + CString::format("STFONT/%d", fontNumber)); if (!stream) error("Could not locate the specified font"); diff --git a/engines/titanic/true_talk/title_engine.cpp b/engines/titanic/true_talk/title_engine.cpp index 511ee0a8f7..d5f465139e 100644 --- a/engines/titanic/true_talk/title_engine.cpp +++ b/engines/titanic/true_talk/title_engine.cpp @@ -67,7 +67,7 @@ void STtitleEngine::dump(int val1, int val2) { SimpleFile *STtitleEngine::open(const CString &name) { Common::SeekableReadStream *stream = g_vm->_filesManager->getResource( - Common::WinResourceID("TEXT"), name); + CString::format("TEXT/%s", name.c_str())); assert(stream); SimpleFile *file = new SimpleFile(); |