From 31ba12c800f55d3611c36838a18e4276dec239ff Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 12 Oct 2003 19:10:17 +0000 Subject: some more target<->game cleanup svn-id: r10769 --- base/gameDetector.cpp | 5 ----- scumm/debugger.cpp | 7 ++++--- scumm/resource.cpp | 12 ++++++------ scumm/saveload.cpp | 2 +- scumm/scumm.h | 6 +++--- scumm/scummvm.cpp | 13 +++++++------ scumm/smush/smush_player.cpp | 2 +- scumm/sound.cpp | 10 +++++----- sword2/controls.cpp | 4 ++-- sword2/save_rest.cpp | 8 ++++---- sword2/sword2.cpp | 4 ++-- sword2/sword2.h | 2 +- 12 files changed, 36 insertions(+), 39 deletions(-) diff --git a/base/gameDetector.cpp b/base/gameDetector.cpp index 06430a5f58..1d5578e115 100644 --- a/base/gameDetector.cpp +++ b/base/gameDetector.cpp @@ -559,11 +559,6 @@ bool GameDetector::detectGame() { if (target) { _game = *target; - if (ConfMan.hasKey("basename")) { - // FIXME: What is this good for? - // FIXME: This leaks now! - _game.gameName = strdup(ConfMan.get("basename").c_str()); - } printf("Trying to start game '%s'\n", _game.description); return true; } else { diff --git a/scumm/debugger.cpp b/scumm/debugger.cpp index e095fcf4bd..bd7b1a9ba9 100644 --- a/scumm/debugger.cpp +++ b/scumm/debugger.cpp @@ -21,6 +21,7 @@ #include "stdafx.h" #include "common/file.h" +#include "common/str.h" #include "common/util.h" #include "scumm/actor.h" @@ -64,8 +65,8 @@ ScummDebugger::ScummDebugger(ScummEngine *s) { DVar_Register("scumm_roomresource", &_vm->_roomResource, DVAR_INT, 0); DVar_Register("scumm_vars", &_vm->_scummVars, DVAR_INTARRAY, _vm->_numVariables); - DVar_Register("scumm_gamename", &_vm->_game_name, DVAR_STRING, 0); - DVar_Register("scumm_exename", &_vm->_exe_name, DVAR_STRING, 0); + DVar_Register("scumm_gamename", &_vm->_targetName, DVAR_STRING, 0); + DVar_Register("scumm_exename", &_vm->_gameName, DVAR_STRING, 0); DVar_Register("scumm_gameid", &_vm->_gameId, DVAR_INT, 0); // Register commands @@ -325,7 +326,7 @@ bool ScummDebugger::RunCommand(const char *inputOrig) { break; // String case DVAR_STRING: - Debug_Printf("(string)%s = %s\n", param[0], *(char **)_dvars[i].variable); + Debug_Printf("(string)%s = %s\n", param[0], ((Common::String *)_dvars[i].variable)->c_str()); break; default: Debug_Printf("%s = (unknown type)\n", param[0]); diff --git a/scumm/resource.cpp b/scumm/resource.cpp index 9cf1919537..d42041f991 100644 --- a/scumm/resource.cpp +++ b/scumm/resource.cpp @@ -83,18 +83,18 @@ void ScummEngine::openRoom(int room) { if (!(_features & GF_SMALL_HEADER)) { if (_features & GF_AFTER_HEV7) { - sprintf(buf, "%s.he%.1d", _exe_name, room == 0 ? 0 : 1); + sprintf(buf, "%s.he%.1d", _gameName.c_str(), room == 0 ? 0 : 1); } else if (_version >= 7) { if (room > 0 && (_version == 8)) VAR(VAR_CURRENTDISK) = res.roomno[rtRoom][room]; - sprintf(buf, "%s.la%d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]); - sprintf(buf2, "%s.%.3d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]); + sprintf(buf, "%s.la%d", _gameName.c_str(), room == 0 ? 0 : res.roomno[rtRoom][room]); + sprintf(buf2, "%s.%.3d", _gameName.c_str(), room == 0 ? 0 : res.roomno[rtRoom][room]); } else if (_features & GF_HUMONGOUS) - sprintf(buf, "%s.he%.1d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]); + sprintf(buf, "%s.he%.1d", _gameName.c_str(), room == 0 ? 0 : res.roomno[rtRoom][room]); else { - sprintf(buf, "%s.%.3d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]); + sprintf(buf, "%s.%.3d", _gameName.c_str(), room == 0 ? 0 : res.roomno[rtRoom][room]); if (_gameId == GID_SAMNMAX) - sprintf(buf2, "%s.sm%.1d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]); + sprintf(buf2, "%s.sm%.1d", _gameName.c_str(), room == 0 ? 0 : res.roomno[rtRoom][room]); } encByte = (_features & GF_USE_KEY) ? 0x69 : 0; diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp index 142e9417b4..13dc1d2609 100644 --- a/scumm/saveload.cpp +++ b/scumm/saveload.cpp @@ -228,7 +228,7 @@ bool ScummEngine::loadState(int slot, bool compat, SaveFileManager *mgr) { } void ScummEngine::makeSavegameName(char *out, int slot, bool compatible) { - sprintf(out, "%s.%c%.2d", _game_name, compatible ? 'c' : 's', slot); + sprintf(out, "%s.%c%.2d", _targetName.c_str(), compatible ? 'c' : 's', slot); } void ScummEngine::listSavegames(bool *marks, int num, SaveFileManager *mgr) { diff --git a/scumm/scumm.h b/scumm/scumm.h index 9f04ddc9f1..52b4f72044 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -311,7 +311,7 @@ public: void clearClickedStatus(); // Misc utility functions - const char *getExeName() const { return _exe_name; } + const char *getGameName() const { return _gameName.c_str(); } const char *getGameDataPath() const; // Cursor/palette @@ -556,8 +556,8 @@ protected: File _fileHandle; uint32 _fileOffset; int _resourceHeaderSize; - char *_exe_name; // This is the name we use for opening resource files - char *_game_name; // This is the game the user calls it, so use for saving + Common::String _gameName; // This is the name we use for opening resource files + Common::String _targetName; // This is the game the user calls it, so use for saving bool _dynamicRoomOffsets; byte _resourceMapper[128]; uint32 _allocatedSize; diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index 65d2ce355a..1e72191943 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -364,8 +364,6 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst) _keyScriptKey = 0; _keyScriptNo = 0; _fileOffset = 0; - _exe_name = NULL; - _game_name = NULL; _dynamicRoomOffsets = false; memset(_resourceMapper, 0, sizeof(_resourceMapper)); _allocatedSize = 0; @@ -595,8 +593,13 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst) _debugLevel = ConfMan.getInt("debuglevel"); _dumpScripts = detector->_dumpScripts; _bootParam = ConfMan.getInt("boot_param"); - _exe_name = strdup(detector->_game.gameName); - _game_name = strdup(detector->_targetName.c_str()); + + // Allow the user to override the game name with a custom string. + // This allows some game versions to work which use filenames + // differing from the regular version(s) of that game. + _gameName = ConfMan.hasKey("basename") ? ConfMan.get("basename") : detector->_game.gameName; + + _targetName = detector->_targetName; _gameId = detector->_game.id; _version = detector->_game.version; setFeatures(detector->_game.features); @@ -786,8 +789,6 @@ ScummEngine::~ScummEngine() { free(_bitVars); free(_newNames); free(_classData); - free(_exe_name); - free(_game_name); free(_roomStrips); free(_languageIndex); diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp index 161c6ff3cd..c00c493ce5 100644 --- a/scumm/smush/smush_player.cpp +++ b/scumm/smush/smush_player.cpp @@ -887,7 +887,7 @@ void SmushPlayer::updateScreen() { #ifdef DUMP_SMUSH_FRAMES char fileName[100]; // change path below for dump png files - sprintf(fileName, "/path/to/somethere/%s%04d.png", _scumm->getExeName, _frame); + sprintf(fileName, "/path/to/somethere/%s%04d.png", _scumm->getGameName(), _frame); FILE *file = fopen(fileName, "wb"); if (file == NULL) error("can't open file for writing png"); diff --git a/scumm/sound.cpp b/scumm/sound.cpp index fd55633bd1..b8df43cb63 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -895,13 +895,13 @@ File *Sound::openSfxFile() { char buf[256]; File *file = new File(); - /* Try opening the file <_exe_name>.sou first, eg tentacle.sou. + /* Try opening the file <_gameName>.sou first, eg tentacle.sou. * That way, you can keep .sou files for multiple games in the * same directory */ offset_table = NULL; #ifdef USE_MAD - sprintf(buf, "%s.so3", _scumm->getExeName()); + sprintf(buf, "%s.so3", _scumm->getGameName()); if (!file->open(buf, _scumm->getGameDataPath())) { file->open("monster.so3", _scumm->getGameDataPath()); } @@ -911,7 +911,7 @@ File *Sound::openSfxFile() { #ifdef USE_VORBIS if (!file->isOpen()) { - sprintf(buf, "%s.sog", _scumm->getExeName()); + sprintf(buf, "%s.sog", _scumm->getGameName()); if (!file->open(buf, _scumm->getGameDataPath())) file->open("monster.sog", _scumm->getGameDataPath()); if (file->isOpen()) @@ -953,13 +953,13 @@ File *Sound::openSfxFile() { return file; } - sprintf(buf, "%s.sou", _scumm->getExeName()); + sprintf(buf, "%s.sou", _scumm->getGameName()); if (!file->open(buf, _scumm->getGameDataPath())) { file->open("monster.sou", _scumm->getGameDataPath()); } if (!file->isOpen()) { - sprintf(buf, "%s.tlk", _scumm->getExeName()); + sprintf(buf, "%s.tlk", _scumm->getGameName()); file->open(buf, _scumm->getGameDataPath(), 1, 0x69); } return file; diff --git a/sword2/controls.cpp b/sword2/controls.cpp index ced13f899b..80e1226645 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -893,7 +893,7 @@ int32 OptionsDialog::writeOptionSettings(void) { SaveFile *fp; SaveFileManager *mgr = g_system->get_savefile_manager(); - sprintf(filename, "%s-settings.dat", g_sword2->_gameName); + sprintf(filename, "%s-settings.dat", g_sword2->_targetName); buff[0] = g_sound->getMusicVolume(); buff[1] = g_sound->getSpeechVolume(); @@ -1483,7 +1483,7 @@ int32 Gui::readOptionSettings(void) { SaveFile *fp; SaveFileManager *mgr = g_system->get_savefile_manager(); - sprintf(filename, "%s-settings.dat", g_sword2->_gameName); + sprintf(filename, "%s-settings.dat", g_sword2->_targetName); if (!(fp = mgr->open_savefile(filename, g_sword2->getSavePath(), false))) return 1; diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp index 2f24fb8c77..acd3ae70f3 100644 --- a/sword2/save_rest.cpp +++ b/sword2/save_rest.cpp @@ -241,7 +241,7 @@ uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) { SaveFileManager *mgr = g_system->get_savefile_manager(); // construct filename - sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo); + sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo); if (!(out = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), true))) { // error: couldn't open file @@ -304,7 +304,7 @@ uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) { uint32 itemsRead; // construct filename - sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo); + sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo); if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) { // error: couldn't open file @@ -469,7 +469,7 @@ uint32 GetSaveDescription(uint16 slotNo, uint8 *description) { SaveFileManager *mgr = g_system->get_savefile_manager(); // construct filename - sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo); + sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo); if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) { // error: couldn't open file @@ -492,7 +492,7 @@ bool SaveExists(uint16 slotNo) { SaveFile *in; // construct filename - sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo); + sprintf(saveFileName, "%s.%.3d", g_sword2->_targetName, slotNo); if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) { delete mgr; diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index 3e7491261d..d4cadde9de 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -104,7 +104,7 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) g_sword2 = this; _features = detector->_game.features; _gameId = detector->_game.id; - _gameName = strdup(detector->_targetName.c_str()); + _targetName = strdup(detector->_targetName.c_str()); _bootParam = ConfMan.getInt("boot_param"); _saveSlot = ConfMan.getInt("save_slot"); _debugLevel = ConfMan.getInt("debuglevel"); @@ -123,7 +123,7 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) } Sword2Engine::~Sword2Engine() { - free(_gameName); + free(_targetName); delete _sound; } diff --git a/sword2/sword2.h b/sword2/sword2.h index 282d8334fe..a8a7354491 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -75,7 +75,7 @@ public: GameDetector *_detector; uint32 _features; byte _gameId; - char *_gameName; // target name for saves + char *_targetName; // target name for saves Sound *_sound; Common::RandomSource _rnd; -- cgit v1.2.3