MYST3: Change the room name to the String type
And remove slightly hazardous C string handling
This commit is contained in:
parent
bd24134c8d
commit
4c9ae35e88
15 changed files with 63 additions and 57 deletions
|
@ -83,10 +83,11 @@ Common::MemoryReadStream *Archive::dumpToMemory(uint32 offset, uint32 size) {
|
|||
return static_cast<Common::MemoryReadStream *>(_file.readStream(size));
|
||||
}
|
||||
|
||||
const DirectorySubEntry *Archive::getDescription(const char *room, uint32 index, uint16 face, DirectorySubEntry::ResourceType type) {
|
||||
const DirectorySubEntry *Archive::getDescription(const Common::String &room, uint32 index, uint16 face,
|
||||
DirectorySubEntry::ResourceType type) {
|
||||
for (uint i = 0; i < _directory.size(); i++) {
|
||||
if (_directory[i].getIndex() == index
|
||||
&& !strcmp(_directory[i].getRoom(), room)) {
|
||||
&& _directory[i].getRoom() == room) {
|
||||
return _directory[i].getItemDescription(face, type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ private:
|
|||
void _readDirectory();
|
||||
public:
|
||||
|
||||
const DirectorySubEntry *getDescription(const char *room, uint32 index, uint16 face, DirectorySubEntry::ResourceType type);
|
||||
const DirectorySubEntry *getDescription(const Common::String &room, uint32 index, uint16 face,
|
||||
DirectorySubEntry::ResourceType type);
|
||||
Common::MemoryReadStream *dumpToMemory(uint32 offset, uint32 size);
|
||||
void dumpToFiles();
|
||||
|
||||
|
|
|
@ -77,10 +77,9 @@ bool Console::Cmd_Infos(int argc, const char **argv) {
|
|||
return true;
|
||||
}
|
||||
|
||||
char roomName[8];
|
||||
_vm->_db->getRoomName(roomName, roomId);
|
||||
Common::String roomName = _vm->_db->getRoomName(roomId);
|
||||
|
||||
debugPrintf("node: %s %d ", roomName, nodeId);
|
||||
debugPrintf("node: %s %d ", roomName.c_str(), nodeId);
|
||||
|
||||
for (uint i = 0; i < nodeData->scripts.size(); i++) {
|
||||
debugPrintf("\ninit %d > %s (%s)\n", i,
|
||||
|
@ -279,7 +278,7 @@ bool Console::Cmd_Extract(int argc, const char **argv) {
|
|||
uint16 face = atoi(argv[3]);
|
||||
DirectorySubEntry::ResourceType type = (DirectorySubEntry::ResourceType) atoi(argv[4]);
|
||||
|
||||
const DirectorySubEntry *desc = _vm->getFileDescription(room.c_str(), id, face, type);
|
||||
const DirectorySubEntry *desc = _vm->getFileDescription(room, id, face, type);
|
||||
|
||||
if (!desc) {
|
||||
debugPrintf("File with room %s, id %d, face %d and type %d does not exist\n", room.c_str(), id, face, type);
|
||||
|
@ -381,7 +380,7 @@ bool Console::Cmd_DumpMasks(int argc, const char **argv) {
|
|||
}
|
||||
|
||||
bool Console::dumpFaceMask(uint16 index, int face, DirectorySubEntry::ResourceType type) {
|
||||
const DirectorySubEntry *maskDesc = _vm->getFileDescription(0, index, face, type);
|
||||
const DirectorySubEntry *maskDesc = _vm->getFileDescription("", index, face, type);
|
||||
|
||||
if (!maskDesc)
|
||||
return false;
|
||||
|
|
|
@ -555,7 +555,9 @@ RoomData Database::loadRoomDescription(Common::ReadStreamEndian &s) {
|
|||
|
||||
if (_vm->getPlatform() == Common::kPlatformPS2) {
|
||||
room.id = s.readUint32LE(); s.readUint32LE();
|
||||
s.read(&room.name, 8);
|
||||
char name[8];
|
||||
s.read(&name, ARRAYSIZE(name));
|
||||
room.name = Common::String(name);
|
||||
room.scriptsOffset = s.readUint32LE(); s.readUint32LE();
|
||||
room.ambSoundsOffset = s.readUint32LE(); s.readUint32LE();
|
||||
room.unkOffset = s.readUint32LE(); // not 64-bit -- otherwise roomUnk5 is incorrect
|
||||
|
@ -563,7 +565,9 @@ RoomData Database::loadRoomDescription(Common::ReadStreamEndian &s) {
|
|||
room.roomUnk5 = s.readUint32LE();
|
||||
} else {
|
||||
room.id = s.readUint32();
|
||||
s.read(&room.name, 8);
|
||||
char name[8];
|
||||
s.read(&name, ARRAYSIZE(name));
|
||||
room.name = Common::String(name);
|
||||
room.scriptsOffset = s.readUint32();
|
||||
room.ambSoundsOffset = s.readUint32();
|
||||
room.unkOffset = s.readUint32();
|
||||
|
@ -583,19 +587,21 @@ RoomData Database::loadRoomDescription(Common::ReadStreamEndian &s) {
|
|||
return room;
|
||||
}
|
||||
|
||||
void Database::getRoomName(char name[8], uint32 roomID) {
|
||||
Common::String Database::getRoomName(uint32 roomID) {
|
||||
if (roomID != 0 && roomID != _currentRoomID) {
|
||||
RoomData *data = findRoomData(roomID);
|
||||
memcpy(&name[0], &data->name, 8);
|
||||
return data->name;
|
||||
} else if (_currentRoomData) {
|
||||
memcpy(&name[0], &_currentRoomData->name, 8);
|
||||
return _currentRoomData->name;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
uint32 Database::getRoomId(const char *name) {
|
||||
for (uint i = 0; i < _ages.size(); i++)
|
||||
for (uint j = 0; j < _ages[i].rooms.size(); j++) {
|
||||
if (!scumm_stricmp(_ages[i].rooms[j].name, name)) {
|
||||
if (_ages[i].rooms[j].name.equalsIgnoreCase(name)) {
|
||||
return _ages[i].rooms[j].id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ typedef Common::SharedPtr<NodeData> NodePtr;
|
|||
|
||||
struct RoomData {
|
||||
uint32 id;
|
||||
char name[8];
|
||||
Common::String name;
|
||||
uint32 scriptsOffset;
|
||||
uint32 ambSoundsOffset;
|
||||
uint32 unkOffset;
|
||||
|
@ -111,7 +111,7 @@ public:
|
|||
/**
|
||||
* Returns the name of the currently loaded room
|
||||
*/
|
||||
void getRoomName(char name[8], uint32 roomID = 0);
|
||||
Common::String getRoomName(uint32 roomID = 0);
|
||||
|
||||
/**
|
||||
* Returns the id of a room from its name
|
||||
|
|
|
@ -61,7 +61,7 @@ Effect::~Effect() {
|
|||
}
|
||||
}
|
||||
|
||||
bool Effect::loadMasks(const char *room, uint32 id, DirectorySubEntry::ResourceType type) {
|
||||
bool Effect::loadMasks(const Common::String &room, uint32 id, DirectorySubEntry::ResourceType type) {
|
||||
bool isFrame = _vm->_state->getViewType() == kFrame;
|
||||
|
||||
// Load the mask of each face
|
||||
|
@ -167,7 +167,7 @@ WaterEffect::~WaterEffect() {
|
|||
WaterEffect *WaterEffect::create(Myst3Engine *vm, uint32 id) {
|
||||
WaterEffect *s = new WaterEffect(vm);
|
||||
|
||||
if (!s->loadMasks(0, id, DirectorySubEntry::kWaterEffectMask)) {
|
||||
if (!s->loadMasks("", id, DirectorySubEntry::kWaterEffectMask)) {
|
||||
delete s;
|
||||
return 0;
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ LavaEffect::~LavaEffect() {
|
|||
LavaEffect *LavaEffect::create(Myst3Engine *vm, uint32 id) {
|
||||
LavaEffect *s = new LavaEffect(vm);
|
||||
|
||||
if (!s->loadMasks(0, id, DirectorySubEntry::kLavaEffectMask)) {
|
||||
if (!s->loadMasks("", id, DirectorySubEntry::kLavaEffectMask)) {
|
||||
delete s;
|
||||
return 0;
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ MagnetEffect::~MagnetEffect() {
|
|||
MagnetEffect *MagnetEffect::create(Myst3Engine *vm, uint32 id) {
|
||||
MagnetEffect *s = new MagnetEffect(vm);
|
||||
|
||||
if (!s->loadMasks(0, id, DirectorySubEntry::kMagneticEffectMask)) {
|
||||
if (!s->loadMasks("", id, DirectorySubEntry::kMagneticEffectMask)) {
|
||||
delete s;
|
||||
return 0;
|
||||
}
|
||||
|
@ -459,7 +459,7 @@ bool MagnetEffect::update() {
|
|||
// The sound changed since last update
|
||||
_lastSoundId = soundId;
|
||||
|
||||
const DirectorySubEntry *desc = _vm->getFileDescription(0, _vm->_state->getMagnetEffectNode(), 0, DirectorySubEntry::kRawData);
|
||||
const DirectorySubEntry *desc = _vm->getFileDescription("", _vm->_state->getMagnetEffectNode(), 0, DirectorySubEntry::kRawData);
|
||||
if (!desc)
|
||||
error("Magnet effect support file %d does not exist", _vm->_state->getMagnetEffectNode());
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
protected:
|
||||
Effect(Myst3Engine *vm);
|
||||
|
||||
bool loadMasks(const char *room, uint32 id, DirectorySubEntry::ResourceType type);
|
||||
bool loadMasks(const Common::String &room, uint32 id, DirectorySubEntry::ResourceType type);
|
||||
|
||||
Myst3Engine *_vm;
|
||||
|
||||
|
|
|
@ -47,16 +47,16 @@ Movie::Movie(Myst3Engine *vm, uint16 id) :
|
|||
_additiveBlending(false),
|
||||
_transparency(100) {
|
||||
|
||||
const DirectorySubEntry *binkDesc = _vm->getFileDescription(0, id, 0, DirectorySubEntry::kMultitrackMovie);
|
||||
const DirectorySubEntry *binkDesc = _vm->getFileDescription("", id, 0, DirectorySubEntry::kMultitrackMovie);
|
||||
|
||||
if (!binkDesc)
|
||||
binkDesc = _vm->getFileDescription(0, id, 0, DirectorySubEntry::kDialogMovie);
|
||||
binkDesc = _vm->getFileDescription("", id, 0, DirectorySubEntry::kDialogMovie);
|
||||
|
||||
if (!binkDesc)
|
||||
binkDesc = _vm->getFileDescription(0, id, 0, DirectorySubEntry::kStillMovie);
|
||||
binkDesc = _vm->getFileDescription("", id, 0, DirectorySubEntry::kStillMovie);
|
||||
|
||||
if (!binkDesc)
|
||||
binkDesc = _vm->getFileDescription(0, id, 0, DirectorySubEntry::kMovie);
|
||||
binkDesc = _vm->getFileDescription("", id, 0, DirectorySubEntry::kMovie);
|
||||
|
||||
// Check whether the video is optional
|
||||
bool optional = false;
|
||||
|
|
|
@ -772,19 +772,17 @@ void Myst3Engine::loadNode(uint16 nodeID, uint32 roomID, uint32 ageID) {
|
|||
if (ageID)
|
||||
_state->setLocationAge(_state->valueOrVarValue(ageID));
|
||||
|
||||
char oldRoomName[8];
|
||||
char newRoomName[8];
|
||||
_db->getRoomName(oldRoomName);
|
||||
_db->getRoomName(newRoomName, roomID);
|
||||
Common::String oldRoomName = _db->getRoomName();
|
||||
Common::String newRoomName = _db->getRoomName(roomID);
|
||||
|
||||
if (strcmp(newRoomName, "JRNL") && strcmp(newRoomName, "XXXX")
|
||||
&& strcmp(newRoomName, "MENU") && strcmp(newRoomName, oldRoomName)) {
|
||||
if (newRoomName != "JRNL" && newRoomName != "XXXX"
|
||||
&& newRoomName != "MENU" && newRoomName != oldRoomName) {
|
||||
|
||||
_db->setCurrentRoom(roomID);
|
||||
Common::String nodeFile = Common::String::format("%snodes.m3a", newRoomName);
|
||||
Common::String nodeFile = Common::String::format("%snodes.m3a", newRoomName.c_str());
|
||||
|
||||
_archiveNode->close();
|
||||
if (!_archiveNode->open(nodeFile.c_str(), newRoomName)) {
|
||||
if (!_archiveNode->open(nodeFile.c_str(), newRoomName.c_str())) {
|
||||
error("Unable to open archive %s", nodeFile.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -1230,11 +1228,11 @@ void Myst3Engine::loadNodeSubtitles(uint32 id) {
|
|||
_node->loadSubtitles(id);
|
||||
}
|
||||
|
||||
const DirectorySubEntry *Myst3Engine::getFileDescription(const char* room, uint32 index, uint16 face, DirectorySubEntry::ResourceType type) {
|
||||
char currentRoom[8];
|
||||
if (!room) {
|
||||
_db->getRoomName(currentRoom, _state->getLocationRoom());
|
||||
room = currentRoom;
|
||||
const DirectorySubEntry *Myst3Engine::getFileDescription(const Common::String &room, uint32 index, uint16 face,
|
||||
DirectorySubEntry::ResourceType type) {
|
||||
Common::String archiveRoom = room;
|
||||
if (archiveRoom == "") {
|
||||
archiveRoom = _db->getRoomName(_state->getLocationRoom());
|
||||
}
|
||||
|
||||
const DirectorySubEntry *desc = 0;
|
||||
|
@ -1242,13 +1240,13 @@ const DirectorySubEntry *Myst3Engine::getFileDescription(const char* room, uint3
|
|||
// Search common archives
|
||||
uint i = 0;
|
||||
while (!desc && i < _archivesCommon.size()) {
|
||||
desc = _archivesCommon[i]->getDescription(room, index, face, type);
|
||||
desc = _archivesCommon[i]->getDescription(archiveRoom, index, face, type);
|
||||
i++;
|
||||
}
|
||||
|
||||
// Search currently loaded node archive
|
||||
if (!desc && _archiveNode)
|
||||
desc = _archiveNode->getDescription(room, index, face, type);
|
||||
desc = _archiveNode->getDescription(archiveRoom, index, face, type);
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
@ -1480,10 +1478,10 @@ void Myst3Engine::animateDirectionChange(float targetPitch, float targetHeading,
|
|||
}
|
||||
|
||||
void Myst3Engine::getMovieLookAt(uint16 id, bool start, float &pitch, float &heading) {
|
||||
const DirectorySubEntry *desc = getFileDescription(0, id, 0, DirectorySubEntry::kMovie);
|
||||
const DirectorySubEntry *desc = getFileDescription("", id, 0, DirectorySubEntry::kMovie);
|
||||
|
||||
if (!desc)
|
||||
desc = getFileDescription(0, id, 0, DirectorySubEntry::kMultitrackMovie);
|
||||
desc = getFileDescription("", id, 0, DirectorySubEntry::kMultitrackMovie);
|
||||
|
||||
if (!desc)
|
||||
error("Movie %d does not exist", id);
|
||||
|
|
|
@ -134,7 +134,8 @@ public:
|
|||
Common::Error loadGameState(int slot) override;
|
||||
Common::Error loadGameState(Common::String fileName, TransitionType transition);
|
||||
|
||||
const DirectorySubEntry *getFileDescription(const char* room, uint32 index, uint16 face, DirectorySubEntry::ResourceType type);
|
||||
const DirectorySubEntry *getFileDescription(const Common::String &room, uint32 index, uint16 face,
|
||||
DirectorySubEntry::ResourceType type);
|
||||
Graphics::Surface *loadTexture(uint16 id);
|
||||
static Graphics::Surface *decodeJpeg(const DirectorySubEntry *jpegDesc);
|
||||
|
||||
|
|
|
@ -146,10 +146,10 @@ void Node::loadSpotItem(uint16 id, int16 condition, bool fade) {
|
|||
spotItem->setFadeVar(abs(condition));
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
const DirectorySubEntry *jpegDesc = _vm->getFileDescription(0, id, i + 1, DirectorySubEntry::kLocalizedSpotItem);
|
||||
const DirectorySubEntry *jpegDesc = _vm->getFileDescription("", id, i + 1, DirectorySubEntry::kLocalizedSpotItem);
|
||||
|
||||
if (!jpegDesc)
|
||||
jpegDesc = _vm->getFileDescription(0, id, i + 1, DirectorySubEntry::kSpotItem);
|
||||
jpegDesc = _vm->getFileDescription("", id, i + 1, DirectorySubEntry::kSpotItem);
|
||||
|
||||
if (!jpegDesc) continue;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Myst3 {
|
|||
NodeCube::NodeCube(Myst3Engine *vm, uint16 id) :
|
||||
Node(vm, id) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
const DirectorySubEntry *jpegDesc = _vm->getFileDescription(0, id, i + 1, DirectorySubEntry::kCubeFace);
|
||||
const DirectorySubEntry *jpegDesc = _vm->getFileDescription("", id, i + 1, DirectorySubEntry::kCubeFace);
|
||||
|
||||
if (!jpegDesc)
|
||||
error("Face %d does not exist", id);
|
||||
|
|
|
@ -30,13 +30,13 @@ namespace Myst3 {
|
|||
|
||||
NodeFrame::NodeFrame(Myst3Engine *vm, uint16 id) :
|
||||
Node(vm, id) {
|
||||
const DirectorySubEntry *jpegDesc = _vm->getFileDescription(0, id, 1, DirectorySubEntry::kLocalizedFrame);
|
||||
const DirectorySubEntry *jpegDesc = _vm->getFileDescription("", id, 1, DirectorySubEntry::kLocalizedFrame);
|
||||
|
||||
if (!jpegDesc)
|
||||
jpegDesc = _vm->getFileDescription(0, id, 0, DirectorySubEntry::kFrame);
|
||||
jpegDesc = _vm->getFileDescription("", id, 0, DirectorySubEntry::kFrame);
|
||||
|
||||
if (!jpegDesc)
|
||||
jpegDesc = _vm->getFileDescription(0, id, 1, DirectorySubEntry::kFrame);
|
||||
jpegDesc = _vm->getFileDescription("", id, 1, DirectorySubEntry::kFrame);
|
||||
|
||||
if (!jpegDesc)
|
||||
error("Frame %d does not exist", id);
|
||||
|
|
|
@ -1138,7 +1138,7 @@ void Puzzles::journalSaavedro(int16 move) {
|
|||
|
||||
// Does the left page need to be loaded from a different node?
|
||||
if (nodeLeft != nodeRight) {
|
||||
const DirectorySubEntry *jpegDesc = _vm->getFileDescription(0, nodeLeft, 0, DirectorySubEntry::kFrame);
|
||||
const DirectorySubEntry *jpegDesc = _vm->getFileDescription("", nodeLeft, 0, DirectorySubEntry::kFrame);
|
||||
|
||||
if (!jpegDesc)
|
||||
error("Frame %d does not exist", nodeLeft);
|
||||
|
@ -1180,7 +1180,7 @@ int16 Puzzles::_journalSaavedroLastPageLastChapterValue() {
|
|||
}
|
||||
|
||||
uint16 Puzzles::_journalSaavedroGetNode(uint16 chapter) {
|
||||
const DirectorySubEntry *desc = _vm->getFileDescription(0, 1200, 0, DirectorySubEntry::kNumMetadata);
|
||||
const DirectorySubEntry *desc = _vm->getFileDescription("", 1200, 0, DirectorySubEntry::kNumMetadata);
|
||||
|
||||
if (!desc)
|
||||
error("Node 1200 does not exist");
|
||||
|
@ -1214,7 +1214,7 @@ uint16 Puzzles::_journalSaavedroNextChapter(uint16 chapter, bool forward) {
|
|||
void Puzzles::journalAtrus(uint16 node, uint16 var) {
|
||||
uint numPages = 0;
|
||||
|
||||
while (_vm->getFileDescription(0, node++, 0, DirectorySubEntry::kFrame))
|
||||
while (_vm->getFileDescription("", node++, 0, DirectorySubEntry::kFrame))
|
||||
numPages++;
|
||||
|
||||
_vm->_state->setVar(var, numPages - 1);
|
||||
|
@ -1523,7 +1523,7 @@ void Puzzles::projectorLoadBitmap(uint16 bitmap) {
|
|||
_vm->_projectorBackground = new Graphics::Surface();
|
||||
_vm->_projectorBackground->create(1024, 1024, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
|
||||
|
||||
const DirectorySubEntry *movieDesc = _vm->getFileDescription(0, bitmap, 0, DirectorySubEntry::kStillMovie);
|
||||
const DirectorySubEntry *movieDesc = _vm->getFileDescription("", bitmap, 0, DirectorySubEntry::kStillMovie);
|
||||
|
||||
if (!movieDesc)
|
||||
error("Movie %d does not exist", bitmap);
|
||||
|
@ -1550,7 +1550,7 @@ void Puzzles::projectorAddSpotItem(uint16 bitmap, uint16 x, uint16 y) {
|
|||
if (!_vm->_state->getVar(26))
|
||||
return;
|
||||
|
||||
const DirectorySubEntry *movieDesc = _vm->getFileDescription(0, bitmap, 0, DirectorySubEntry::kStillMovie);
|
||||
const DirectorySubEntry *movieDesc = _vm->getFileDescription("", bitmap, 0, DirectorySubEntry::kStillMovie);
|
||||
|
||||
if (!movieDesc)
|
||||
error("Movie %d does not exist", bitmap);
|
||||
|
|
|
@ -293,7 +293,7 @@ const DirectorySubEntry *MovieSubtitles::loadMovie(int32 id, bool overriden) {
|
|||
if (overriden) {
|
||||
desc = _vm->getFileDescription("IMGR", 200000 + id, 0, DirectorySubEntry::kMovie);
|
||||
} else {
|
||||
desc = _vm->getFileDescription(0, 200000 + id, 0, DirectorySubEntry::kMovie);
|
||||
desc = _vm->getFileDescription("", 200000 + id, 0, DirectorySubEntry::kMovie);
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ const DirectorySubEntry *Subtitles::loadText(int32 id, bool overriden) {
|
|||
if (overriden) {
|
||||
desc = _vm->getFileDescription("IMGR", 100000 + id, 0, DirectorySubEntry::kText);
|
||||
} else {
|
||||
desc = _vm->getFileDescription(0, 100000 + id, 0, DirectorySubEntry::kText);
|
||||
desc = _vm->getFileDescription("", 100000 + id, 0, DirectorySubEntry::kText);
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue