Skip to content

Commit

Permalink
Sfall: add VersionString, ConfigFile, PatchFile (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
c6-dev committed Jan 16, 2024
1 parent 16f4ab7 commit c6565ac
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1363,8 +1363,16 @@ static int gameDbInit()
return -1;
}

// SFALL: custom patch file name.
char* patch_filename = nullptr;
if (configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_PATCH_FILE, &patch_filename)) {
if (patch_filename == nullptr || *patch_file_name == '\0') {
patch_filename = "patch%03d.dat";
}
}

for (patch_index = 0; patch_index < 1000; patch_index++) {
snprintf(filename, sizeof(filename), "patch%03d.dat", patch_index);
snprintf(filename, sizeof(filename), patch_filename, patch_index);

if (compat_access(filename, 0) == 0) {
dbOpen(filename, 0, NULL, 1);
Expand Down
13 changes: 11 additions & 2 deletions src/game_config.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "game_config.h"
#include "sfall_config.h"

#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -120,6 +121,14 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SORT_SCRIPT_LIST_KEY, 0);
}

// SFALL: custom config file name.
char* configFileName = nullptr;
if (configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_CONFIG_FILE, &configFileName)) {
if (configFileName == nullptr || *configFileName == '\0') {
configFileName = DEFAULT_GAME_CONFIG_FILE_NAME;
}
}

// Make `fallout2.cfg` file path.
char* executable = argv[0];
char* ch = strrchr(executable, '\\');
Expand All @@ -136,14 +145,14 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
sizeof(gGameConfigFilePath),
"%s\\%s",
executable,
GAME_CONFIG_FILE_NAME);
configFileName);
}
*ch = '\\';
} else {
if (isMapper) {
strcpy(gGameConfigFilePath, MAPPER_CONFIG_FILE_NAME);
} else {
strcpy(gGameConfigFilePath, GAME_CONFIG_FILE_NAME);
strcpy(gGameConfigFilePath, configFileName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace fallout {

#define GAME_CONFIG_FILE_NAME "fallout2.cfg"
#define DEFAULT_GAME_CONFIG_FILE_NAME "fallout2.cfg"
#define MAPPER_CONFIG_FILE_NAME "mapper2.cfg"

#define GAME_CONFIG_SYSTEM_KEY "system"
Expand Down
3 changes: 3 additions & 0 deletions src/sfall_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ bool sfallConfigInit(int argc, char** argv)
configSetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_MOVIE_TIMER_ARTIMER3, 270);
configSetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_MOVIE_TIMER_ARTIMER4, 360);
configSetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_AUTO_QUICK_SAVE, 0);
configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_VERSION_STRING, "");
configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_CONFIG_FILE, "");
configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_PATCH_FILE, "");

configSetString(&gSfallConfig, SFALL_CONFIG_SCRIPTS_KEY, SFALL_CONFIG_INI_CONFIG_FOLDER, "");
configSetString(&gSfallConfig, SFALL_CONFIG_SCRIPTS_KEY, SFALL_CONFIG_GLOBAL_SCRIPT_PATHS, "");
Expand Down
3 changes: 3 additions & 0 deletions src/sfall_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ namespace fallout {
#define SFALL_CONFIG_INI_CONFIG_FOLDER "IniConfigFolder"
#define SFALL_CONFIG_GLOBAL_SCRIPT_PATHS "GlobalScriptPaths"
#define SFALL_CONFIG_AUTO_QUICK_SAVE "AutoQuickSave"
#define SFALL_CONFIG_VERSION_STRING "VersionString"
#define SFALL_CONFIG_CONFIG_FILE "ConfigFile"
#define SFALL_CONFIG_PATCH_FILE "PatchFile"

#define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_MULTIPLIER 1
#define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_DIVISOR 3
Expand Down
10 changes: 9 additions & 1 deletion src/version.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "version.h"
#include "sfall_config.h"

#include <stdio.h>

Expand All @@ -7,7 +8,14 @@ namespace fallout {
// 0x4B4580
void versionGetVersion(char* dest, size_t size)
{
snprintf(dest, size, "FALLOUT II %d.%02d", VERSION_MAJOR, VERSION_MINOR);
// SFALL: custom version string.
char* versionString = nullptr;
if (configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_VERSION_STRING, &versionString)) {
if (*versionString == '\0') {
versionString = nullptr;
}
}
snprintf(dest, size, (versionString != nullptr ? versionString : "FALLOUT II %d.%02d"), VERSION_MAJOR, VERSION_MINOR);
}

} // namespace fallout

0 comments on commit c6565ac

Please sign in to comment.