TITANIC: Change engine to use titanic.dat

This commit is contained in:
Paul Gilbert 2016-05-15 18:44:47 -04:00
parent 2680caa5bd
commit 053ff7ab75
4 changed files with 50 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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");

View File

@ -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();