Skip to content

Commit

Permalink
FALLOUT2: Complete .sav map handling, implemented MapErase
Browse files Browse the repository at this point in the history
  • Loading branch information
tag2015 committed Jan 4, 2025
1 parent c64eea5 commit a9075fb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 35 deletions.
6 changes: 2 additions & 4 deletions engines/fallout2/fallout2.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ class Fallout2Engine : public Engine {
return _randomSource.getRandomNumber(maxNum);
}

// TODO: Save/load from GMM
bool hasFeature(EngineFeature f) const override {
return
(f == kSupportsLoadingDuringRuntime) ||
(f == kSupportsSavingDuringRuntime) ||
(f == kSupportsReturnToLauncher);
return (f == kSupportsReturnToLauncher);
};

bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
Expand Down
72 changes: 50 additions & 22 deletions engines/fallout2/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,21 @@ void _InitLoadSave() {
_slot_cursor = 0;
_patches = settings.system.master_patches_path.c_str();

/* MapDirErase("MAPS\\", "SAV"); TODO delete temp map files
MapDirErase("MAPS\\", "SAV");
MapDirErase(PROTO_DIR_NAME "\\" CRITTERS_DIR_NAME "\\", PROTO_FILE_EXT);
MapDirErase(PROTO_DIR_NAME "\\" ITEMS_DIR_NAME "\\", PROTO_FILE_EXT);*/
MapDirErase(PROTO_DIR_NAME "\\" ITEMS_DIR_NAME "\\", PROTO_FILE_EXT);

// configGetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_AUTO_QUICK_SAVE, &quickSaveSlots); TODO sfall
// if (quickSaveSlots > 0 && quickSaveSlots <= 10) {
// autoQuickSaveSlots = true;
// }
configGetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_AUTO_QUICK_SAVE, &quickSaveSlots);
if (quickSaveSlots > 0 && quickSaveSlots <= 10) {
autoQuickSaveSlots = true;
}
}

// 0x47B85C
void _ResetLoadSave() {
/* MapDirErase("MAPS\\", "SAV"); TODO delete temp map files
MapDirErase("MAPS\\", "SAV");
MapDirErase(PROTO_DIR_NAME "\\" CRITTERS_DIR_NAME "\\", PROTO_FILE_EXT);
MapDirErase(PROTO_DIR_NAME "\\" ITEMS_DIR_NAME "\\", PROTO_FILE_EXT);*/
MapDirErase(PROTO_DIR_NAME "\\" ITEMS_DIR_NAME "\\", PROTO_FILE_EXT);
}

// SaveGame
Expand Down Expand Up @@ -3191,32 +3191,60 @@ void lsgInit() {

// 0x480040
int MapDirErase(const char *relativePath, const char *extension) {
/* char path[COMPAT_MAX_PATH];
snprintf(path, sizeof(path), "%s*.%s", relativePath, extension);
/* char path[COMPAT_MAX_PATH];
snprintf(path, sizeof(path), "%s*.%s", relativePath, extension);
char **fileList;
int fileListLength = fileNameListInit(path, &fileList, 0, 0);
while (--fileListLength >= 0) {
snprintf(path, sizeof(path), "%s\\%s%s", _patches, relativePath, fileList[fileListLength]);
compat_remove(path);
char **fileList;
int fileListLength = fileNameListInit(path, &fileList, 0, 0);
while (--fileListLength >= 0) {
snprintf(path, sizeof(path), "%s\\%s%s", _patches, relativePath, fileList[fileListLength]);
compat_remove(path);
}
fileNameListFree(&fileList, 0);
*/
Common::SaveFileManager *saveMan = g_system->getSavefileManager();

Common::String restrictedPath(g_engine->getTargetName());
restrictedPath += "_";
restrictedPath += relativePath;
restrictedPath.replace('\\', '_');
restrictedPath.chop(1); // remove last char

Common::StringArray filenames;
filenames = saveMan->listSavefiles(restrictedPath + "*." + extension);
debug("MapDirErase: %s", (restrictedPath + "*." + extension).c_str());

for (Common::StringArray::iterator filename = filenames.begin(); filename != filenames.end(); filename++) {
if (!saveMan->removeSavefile(filename->c_str()))
warning("Error removing %s", filename->c_str());
}
fileNameListFree(&fileList, 0);
*/
warning("MapDirErase not implemented");

return 0;
}

// 0x4800C8
int _MapDirEraseFile_(const char *a1, const char *a2) {
/* char path[COMPAT_MAX_PATH];
char path[COMPAT_MAX_PATH];

snprintf(path, sizeof(path), "%s\\%s%s", _patches, a1, a2);
/*snprintf(path, sizeof(path), "%s\\%s%s", _patches, a1, a2);
if (compat_remove(path) != 0) {
return -1;
} */

warning("MapDirEraseFile not implemented");
return 0;
snprintf(path, sizeof(path), "_maps_%s", a2);
Common::String mapName(g_engine->getTargetName());
mapName += path;

if (!Common::String(mapName).contains(".SAV")) {
warning("Can only delete .SAV maps!");
return -1;
}

debug("Deleting map: %s", mapName.c_str());
if (g_system->getSavefileManager()->removeSavefile(mapName))
return 0;
else
return -1;
}

// 0x480104
Expand Down
15 changes: 6 additions & 9 deletions engines/fallout2/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,6 @@ int mapLoadByName(char *fileName) {
if (saveMan->exists(filePath)) {
debug("Found a saved .SAV map!");
Common::InSaveFile *stream = saveMan->openForLoading(Common::String(filePath));
//debug(".SAV map loading is not yet supported! Falling back to .MAP"); // TODO saveload
//stream = nullptr; // TODO remove
if (stream != nullptr) {
// fileClose(stream);
delete stream;
Expand All @@ -786,6 +784,7 @@ int mapLoadByName(char *fileName) {
Common::SaveFileManager *saveMan = g_system->getSavefileManager();
Common::InSaveFile *stream = saveMan->openForLoading(Common::String(filePath));
rc = mapLoadScumm(stream);
delete stream;
} else {
newPath = "MAPS\\";
newPath += Common::String(fileName);
Expand Down Expand Up @@ -1318,7 +1317,7 @@ int mapLoadSaved(char *fileName) {
}
}

if (!wmMapIsSaveable()) { // TODO map delete
if (!wmMapIsSaveable()) {
debugPrint("\nDestroying RANDOM encounter map.");

char v15[16];
Expand Down Expand Up @@ -1557,16 +1556,16 @@ static int _map_save() {
Common::SaveFileManager *saveMan = g_system->getSavefileManager();

Common::OutSaveFile *stream = saveMan->openForSaving(Common::String(mapFileName), false);
// File *stream = fileOpen(mapFileName, "wb");
if (stream != nullptr) {
rc = _map_save_file(stream);
stream->finalize();
delete stream;
// fileClose(stream);
if (stream->err())
rc = -1;
} else {
snprintf(temp, sizeof(temp), "Unable to open %s to write!", gMapHeader.name);
debugPrint(temp);
}
delete stream;

if (rc == 0) {
snprintf(temp, sizeof(temp), "%s saved.", gMapHeader.name);
Expand Down Expand Up @@ -1625,7 +1624,6 @@ static int _map_save_file(Common::OutSaveFile *stream) {
}

gMapHeader.localVariablesCount = gMapLocalVarsLength;
debug("map_save_file - gMapLocalVarsLength %d", gMapLocalVarsLength);
gMapHeader.globalVariablesCount = gMapGlobalVarsLength;
gMapHeader.darkness = 1;

Expand Down Expand Up @@ -1709,7 +1707,7 @@ int _map_save_in_game(bool a1) {

strncpy(name, gMapHeader.name, sizeof(name));
_strmfe(gMapHeader.name, name, "SAV");
_MapDirEraseFile_("MAPS\\", gMapHeader.name); // TODO map delete
_MapDirEraseFile_("MAPS\\", gMapHeader.name);
strncpy(gMapHeader.name, name, sizeof(gMapHeader.name));
} else {
debugPrint("\n Saving \".SAV\" map.");
Expand Down Expand Up @@ -2047,7 +2045,6 @@ static int mapHeaderWrite(MapHeader *ptr, Common::OutSaveFile *stream) {
stream->writeSint32BE(ptr->version);
for (i = 0; i < 16; i++)
stream->writeByte(ptr->name[i]);
debug("mapHeaderWrite - EnteringTile: %d",ptr->enteringTile);
stream->writeSint32BE(ptr->enteringTile);
stream->writeSint32BE(ptr->enteringElevation);
stream->writeSint32BE(ptr->enteringRotation);
Expand Down

0 comments on commit a9075fb

Please sign in to comment.