Settings registry refactoring (#371)

* Refactor settings save/load to use registry pattern

- Some AI work, needs review

* Fix player_speedup having incorrect cfg key, move config file names to cc, clang format code

* Missing for previous commit

* Remove config key aliases used only for registry, remove unused prefence names, some code cleanup after AI

* Move path normalization to settings.cc, skip mapper config outside of mapper,

* Simplify code by using template constructors

* Move ui_anim_speed to ui section

* chore: auto-format with clang-format

* Build fix attempt

* Format

* Compile fix attempt 2

* chore: auto-format with clang-format

* Code review fixes

* Init debug mode ASAP, log setting clamping, remove unused sound settings

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Vlad K
2026-04-14 00:43:41 +02:00
committed by GitHub
co-authored by github-actions[bot]
parent 14839db4f9
commit 9e8eaa13f5
13 changed files with 292 additions and 450 deletions
+1 -7
View File
@@ -32,7 +32,6 @@ game_difficulty=1
item_highlight=1
language_filter=0
mouse_sensitivity=1.000000
player_speed=1
player_speedup=0
running=1
running_burning_guy=1
@@ -40,7 +39,6 @@ subtitles=1
target_highlight=1
text_base_delay=6.000000
text_line_delay=2.000000
ui_anim_speed=3.000000
violence_level=3
[screen]
@@ -53,16 +51,12 @@ windowed=1
cache_size=448
debug=1
debug_sfxc=1
device=-1
dma=-1
initialize=1
irq=-1
master_volume=22281
music=1
music_path1=data\sound\music\
music_path2=sound\music\
music_volume=22281
port=-1
sndfx_volume=22281
sounds=1
speech=1
@@ -91,4 +85,4 @@ iface_bar_sides_ori=0
iface_bar_width=800
ignore_map_edges=0
splash_screen_size=1
ui_anim_speed=2.000000
+16
View File
@@ -33,6 +33,22 @@ static int _cury = 0;
// 0x51DF04
static DebugPrintProc* gDebugPrintProc = nullptr;
void debugModeInit(const char* debugMode)
{
// CE: Handle debug mode (exactly as seen in `mapper2.exe`).
if (compat_stricmp(debugMode, "environment") == 0) {
_debug_register_env();
} else if (compat_stricmp(debugMode, "screen") == 0) {
_debug_register_screen();
} else if (compat_stricmp(debugMode, "log") == 0) {
_debug_register_log("debug.log", "wt");
} else if (compat_stricmp(debugMode, "mono") == 0) {
_debug_register_mono();
} else if (compat_stricmp(debugMode, "gnw") == 0) {
_debug_register_func(_win_debug);
}
}
// 0x4C6CD0
void _GNW_debug_init()
{
+1
View File
@@ -5,6 +5,7 @@ namespace fallout {
typedef int(DebugPrintProc)(char* string);
void debugModeInit(const char* debugMode);
void _GNW_debug_init();
void _debug_register_mono();
void _debug_register_log(const char* fileName, const char* mode);
-19
View File
@@ -126,23 +126,6 @@ bool gGameLoaded = false;
// CE: Sonora folks like to store objects in global variables.
static void** gGameGlobalPointers = nullptr;
static void debugModeInit()
{
// CE: Handle debug mode (exactly as seen in `mapper2.exe`).
const char* debugMode = settings.debug.mode.c_str();
if (compat_stricmp(debugMode, "environment") == 0) {
_debug_register_env();
} else if (compat_stricmp(debugMode, "screen") == 0) {
_debug_register_screen();
} else if (compat_stricmp(debugMode, "log") == 0) {
_debug_register_log("debug.log", "wt");
} else if (compat_stricmp(debugMode, "mono") == 0) {
_debug_register_mono();
} else if (compat_stricmp(debugMode, "gnw") == 0) {
_debug_register_func(_win_debug);
}
}
// 0x442580
int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int flags, int argc, char** argv)
{
@@ -161,8 +144,6 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int fl
settingsInit(isMapper, argc, argv);
debugModeInit();
gIsMapper = isMapper;
if (gameDbInit() == -1) {
+21 -93
View File
@@ -1,6 +1,7 @@
#include "game_config.h"
#include "debug.h"
#include "game_config_migration.h"
#include "settings.h"
#include "sfall_config.h"
#include <stdio.h>
@@ -17,7 +18,8 @@
namespace fallout {
static void gameConfigResolvePath(const char* section, const char* key);
constexpr char kDefaultGameConfigFileName[] = "fallout2.cfg";
constexpr char kMapperConfigFileName[] = "mapper2.cfg";
// A flag indicating if [gGameConfig] was initialized.
//
@@ -63,78 +65,12 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
return false;
}
// TODO: consolidate settings setup in one place; not sure if this is needed when we have settings field initializers
// Initialize defaults.
configSetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_EXECUTABLE_KEY, "game");
configSetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_DAT_KEY, "master.dat");
configSetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, "data");
configSetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_DAT_KEY, "critter.dat");
configSetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_PATCHES_KEY, "data");
configSetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, ENGLISH);
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_SCROLL_LOCK_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_INTERRUPT_WALK_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_ART_CACHE_SIZE_KEY, 8);
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_COLOR_CYCLING_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_HASHING_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_SPLASH_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_FREE_SPACE_KEY, 20480);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_GAME_DIFFICULTY_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_DIFFICULTY_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_VIOLENCE_LEVEL_KEY, 3);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TARGET_HIGHLIGHT_KEY, 2);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_ITEM_HIGHLIGHT_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_LOOKS_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_MESSAGES_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_TAUNTS_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_LANGUAGE_FILTER_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_RUNNING_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_SUBTITLES_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_SPEED_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_PLAYER_SPEED_KEY, 0);
configSetDouble(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TEXT_BASE_DELAY_KEY, 3.5);
configSetDouble(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TEXT_LINE_DELAY_KEY, 1.399994);
configSetDouble(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_BRIGHTNESS_KEY, 1.0);
configSetDouble(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_MOUSE_SENSITIVITY_KEY, 1.0);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_INITIALIZE_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DEVICE_KEY, -1);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_PORT_KEY, -1);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_IRQ_KEY, -1);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DMA_KEY, -1);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SOUNDS_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SPEECH_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MASTER_VOLUME_KEY, 22281);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_VOLUME_KEY, 22281);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SNDFX_VOLUME_KEY, 22281);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SPEECH_VOLUME_KEY, 22281);
configSetInt(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_CACHE_SIZE_KEY, 448);
configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH1_KEY, "sound\\music\\");
configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH2_KEY, "sound\\music\\");
configSetString(&gGameConfig, GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_MODE_KEY, "environment");
configSetInt(&gGameConfig, GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_TILE_NUM_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_SCRIPT_MESSAGES_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_LOAD_INFO_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_OUTPUT_MAP_DATA_INFO_KEY, 0);
if (isMapper) {
configSetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_EXECUTABLE_KEY, "mapper");
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_OVERRIDE_LIBRARIAN_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_LIBRARIAN_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_USE_ART_NOT_PROTOS_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_REBUILD_PROTOS_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_FIX_MAP_OBJECTS_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_FIX_MAP_INVENTORY_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_IGNORE_REBUILD_ERRORS_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SHOW_PID_NUMBERS_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SAVE_TEXT_MAPS_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_RUN_MAPPER_AS_GAME_KEY, 0);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_DEFAULT_F8_AS_GAME_KEY, 1);
configSetInt(&gGameConfig, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SORT_SCRIPT_LIST_KEY, 0);
}
// Writes default values to config.
settingsWriteToConfig();
// CE: Detect alternative default music directory.
char alternativeMusicPath[COMPAT_MAX_PATH];
strcpy(alternativeMusicPath, "data\\sound\\music\\*.acm");
strcpy(alternativeMusicPath, R"(data\sound\music\*.acm)");
compat_windows_path_to_native(alternativeMusicPath);
compat_resolve_path(alternativeMusicPath);
@@ -142,8 +78,9 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
int acmsLength = fileNameListInit(alternativeMusicPath, &acms);
if (acmsLength != -1) {
if (acmsLength > 0) {
configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH1_KEY, "data\\sound\\music\\");
configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH2_KEY, "data\\sound\\music\\");
// TODO: apply these to settings directly instead of config
configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH1_KEY, R"(data\sound\music\)");
configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH2_KEY, R"(data\sound\music\)");
}
fileNameListFree(&acms, 0);
}
@@ -154,7 +91,7 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
const char* configFileName = customConfigFileName != nullptr && *customConfigFileName != '\0'
? customConfigFileName
: DEFAULT_GAME_CONFIG_FILE_NAME;
: kDefaultGameConfigFileName;
// Make `fallout2.cfg` file path.
char* executable = argv[0];
@@ -166,7 +103,7 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
sizeof(gGameConfigFilePath),
"%s\\%s",
executable,
MAPPER_CONFIG_FILE_NAME);
kMapperConfigFileName);
} else {
snprintf(gGameConfigFilePath,
sizeof(gGameConfigFilePath),
@@ -177,7 +114,7 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
*ch = '\\';
} else {
if (isMapper) {
strcpy(gGameConfigFilePath, MAPPER_CONFIG_FILE_NAME);
strcpy(gGameConfigFilePath, kMapperConfigFileName);
} else {
strcpy(gGameConfigFilePath, configFileName);
}
@@ -187,8 +124,16 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
// Read contents of `fallout2.cfg` into config. The values from the file
// will override the defaults above.
configRead(&gGameConfig, gGameConfigFilePath, false);
// Init debug mode ASAP to catch early debug messages.
char* debugMode;
configGetString(&gGameConfig, GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_MODE_KEY, &debugMode);
debugModeInit(debugMode);
debugPrint("Game config loaded from %s.\n", gGameConfigFilePath);
if (!isMapper && gameConfigMigrateFromF2Res(gGameConfigFilePath, &gGameConfig)) {
debugPrint("Migrated settings from f2_res.ini to %s.\n", gGameConfigFilePath);
debugPrint("Migrated settings from f2_res.ini.\n");
configWrite(&gGameConfig, gGameConfigFilePath, false);
}
configChecker.check(gGameConfig);
@@ -197,15 +142,6 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
// whatever was loaded from `fallout2.cfg`.
configParseCommandLineArguments(&gGameConfig, argc, argv);
// CE: Normalize and resolve asset bundle paths.
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_DAT_KEY);
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY);
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_DAT_KEY);
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_PATCHES_KEY);
gameConfigResolvePath(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_PATCHES_KEY);
gameConfigResolvePath(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH1_KEY);
gameConfigResolvePath(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH2_KEY);
gGameConfigInitialized = true;
return true;
@@ -263,12 +199,4 @@ bool gameConfigExit(bool shouldSave)
return result;
}
static void gameConfigResolvePath(const char* section, const char* key)
{
char* path;
configGetString(&gGameConfig, section, key, &path);
compat_windows_path_to_native(path);
compat_resolve_path(path);
}
} // namespace fallout
+2 -70
View File
@@ -5,88 +5,20 @@
namespace fallout {
#define DEFAULT_GAME_CONFIG_FILE_NAME "fallout2.cfg"
#define MAPPER_CONFIG_FILE_NAME "mapper2.cfg"
#define GAME_CONFIG_DEBUG_KEY "debug"
#define GAME_CONFIG_SYSTEM_KEY "system"
#define GAME_CONFIG_SCREEN_KEY "screen"
#define GAME_CONFIG_UI_KEY "ui"
#define GAME_CONFIG_PREFERENCES_KEY "preferences"
#define GAME_CONFIG_SOUND_KEY "sound"
#define GAME_CONFIG_MAPPER_KEY "mapper"
#define GAME_CONFIG_DEBUG_KEY "debug"
#define GAME_CONFIG_EXECUTABLE_KEY "executable"
#define GAME_CONFIG_MASTER_DAT_KEY "master_dat"
#define GAME_CONFIG_MASTER_PATCHES_KEY "master_patches"
#define GAME_CONFIG_CRITTER_DAT_KEY "critter_dat"
#define GAME_CONFIG_CRITTER_PATCHES_KEY "critter_patches"
#define GAME_CONFIG_LANGUAGE_KEY "language"
#define GAME_CONFIG_SCROLL_LOCK_KEY "scroll_lock"
#define GAME_CONFIG_INTERRUPT_WALK_KEY "interrupt_walk"
#define GAME_CONFIG_ART_CACHE_SIZE_KEY "art_cache_size"
#define GAME_CONFIG_COLOR_CYCLING_KEY "color_cycling"
#define GAME_CONFIG_CYCLE_SPEED_FACTOR_KEY "cycle_speed_factor"
#define GAME_CONFIG_HASHING_KEY "hashing"
#define GAME_CONFIG_SPLASH_KEY "splash"
#define GAME_CONFIG_FREE_SPACE_KEY "free_space"
#define GAME_CONFIG_TIMES_RUN_KEY "times_run"
#define GAME_CONFIG_GAME_DIFFICULTY_KEY "game_difficulty"
#define GAME_CONFIG_RUNNING_BURNING_GUY_KEY "running_burning_guy"
#define GAME_CONFIG_COMBAT_DIFFICULTY_KEY "combat_difficulty"
#define GAME_CONFIG_VIOLENCE_LEVEL_KEY "violence_level"
#define GAME_CONFIG_TARGET_HIGHLIGHT_KEY "target_highlight"
#define GAME_CONFIG_ITEM_HIGHLIGHT_KEY "item_highlight"
#define GAME_CONFIG_COMBAT_LOOKS_KEY "combat_looks"
#define GAME_CONFIG_COMBAT_MESSAGES_KEY "combat_messages"
#define GAME_CONFIG_COMBAT_TAUNTS_KEY "combat_taunts"
#define GAME_CONFIG_LANGUAGE_FILTER_KEY "language_filter"
#define GAME_CONFIG_RUNNING_KEY "running"
#define GAME_CONFIG_SUBTITLES_KEY "subtitles"
#define GAME_CONFIG_COMBAT_SPEED_KEY "combat_speed"
#define GAME_CONFIG_PLAYER_SPEED_KEY "player_speed"
#define GAME_CONFIG_TEXT_BASE_DELAY_KEY "text_base_delay"
#define GAME_CONFIG_TEXT_LINE_DELAY_KEY "text_line_delay"
#define GAME_CONFIG_BRIGHTNESS_KEY "brightness"
#define GAME_CONFIG_MOUSE_SENSITIVITY_KEY "mouse_sensitivity"
#define GAME_CONFIG_INITIALIZE_KEY "initialize"
#define GAME_CONFIG_DEVICE_KEY "device"
#define GAME_CONFIG_PORT_KEY "port"
#define GAME_CONFIG_IRQ_KEY "irq"
#define GAME_CONFIG_DMA_KEY "dma"
#define GAME_CONFIG_SOUNDS_KEY "sounds"
#define GAME_CONFIG_MUSIC_KEY "music"
#define GAME_CONFIG_SPEECH_KEY "speech"
#define GAME_CONFIG_MASTER_VOLUME_KEY "master_volume"
#define GAME_CONFIG_MUSIC_VOLUME_KEY "music_volume"
#define GAME_CONFIG_SNDFX_VOLUME_KEY "sndfx_volume"
#define GAME_CONFIG_SPEECH_VOLUME_KEY "speech_volume"
#define GAME_CONFIG_CACHE_SIZE_KEY "cache_size"
#define GAME_CONFIG_MUSIC_PATH1_KEY "music_path1"
#define GAME_CONFIG_MUSIC_PATH2_KEY "music_path2"
#define GAME_CONFIG_DEBUG_SFXC_KEY "debug_sfxc"
#define GAME_CONFIG_MODE_KEY "mode"
#define GAME_CONFIG_SHOW_TILE_NUM_KEY "show_tile_num"
#define GAME_CONFIG_SHOW_SCRIPT_MESSAGES_KEY "show_script_messages"
#define GAME_CONFIG_SHOW_LOAD_INFO_KEY "show_load_info"
#define GAME_CONFIG_OUTPUT_MAP_DATA_INFO_KEY "output_map_data_info"
#define GAME_CONFIG_DEBUG_WINDOW_WIDTH_KEY "window_width"
#define GAME_CONFIG_DEBUG_WINDOW_HEIGHT_KEY "window_height"
#define GAME_CONFIG_OVERRIDE_LIBRARIAN_KEY "override_librarian"
#define GAME_CONFIG_LIBRARIAN_KEY "librarian"
#define GAME_CONFIG_USE_ART_NOT_PROTOS_KEY "use_art_not_protos"
#define GAME_CONFIG_REBUILD_PROTOS_KEY "rebuild_protos"
#define GAME_CONFIG_FIX_MAP_OBJECTS_KEY "fix_map_objects"
#define GAME_CONFIG_FIX_MAP_INVENTORY_KEY "fix_map_inventory"
#define GAME_CONFIG_IGNORE_REBUILD_ERRORS_KEY "ignore_rebuild_errors"
#define GAME_CONFIG_SHOW_PID_NUMBERS_KEY "show_pid_numbers"
#define GAME_CONFIG_SAVE_TEXT_MAPS_KEY "save_text_maps"
#define GAME_CONFIG_RUN_MAPPER_AS_GAME_KEY "run_mapper_as_game"
#define GAME_CONFIG_DEFAULT_F8_AS_GAME_KEY "default_f8_as_game"
#define GAME_CONFIG_SORT_SCRIPT_LIST_KEY "sort_script_list"
#define GAME_CONFIG_PLAYER_SPEEDUP_KEY "player_speedup"
#define GAME_CONFIG_UI_ANIM_SPEED_KEY "ui_anim_speed"
#define GAME_CONFIG_MODE_KEY "mode"
#define GAME_CONFIG_RESOLUTION_X_KEY "resolution_x"
#define GAME_CONFIG_RESOLUTION_Y_KEY "resolution_y"
#define GAME_CONFIG_WINDOWED_KEY "windowed"
+1 -1
View File
@@ -2995,7 +2995,7 @@ void _gdialog_scroll_subwin(int windowIdx, bool scrollUp, unsigned char* windowF
unsigned char* dest = windowBuf;
Rect rect;
const int delayMs = std::max(static_cast<int>(33.0 / settings.preferences.ui_anim_speed), 1);
const int delayMs = std::max(static_cast<int>(33.0 / settings.ui.anim_speed), 1);
if (scrollUp) {
rect.left = 0;
+2 -2
View File
@@ -870,7 +870,7 @@ void interfaceBarRefresh()
static int counterAnimationBaseDelayMs()
{
return std::max(static_cast<int>(250.0 / settings.preferences.ui_anim_speed), 25);
return std::max(static_cast<int>(250.0 / settings.ui.anim_speed), 25);
}
// Render hit points.
@@ -1379,7 +1379,7 @@ int _intface_update_ammo_lights()
static int interfaceBarBaseDelayMs()
{
return std::max(static_cast<int>(1000.0 / settings.preferences.ui_anim_speed), 100);
return std::max(static_cast<int>(1000.0 / settings.ui.anim_speed), 100);
}
// 0x45F96C
+1 -1
View File
@@ -48,7 +48,7 @@ void paletteInit()
unsigned int actualFadeDuration = getTicksSince(tick);
constexpr int vanillaFadeDurationMs = 700;
const unsigned int fadeDurationMs = static_cast<int>(vanillaFadeDurationMs / settings.preferences.ui_anim_speed);
const unsigned int fadeDurationMs = static_cast<int>(vanillaFadeDurationMs / settings.ui.anim_speed);
// Calculate fade steps needed to perform fading in about 700 ms.
gPaletteFadeSteps = static_cast<int>(referenceFadeSteps * fadeDurationMs / actualFadeDuration);
+1 -1
View File
@@ -2220,7 +2220,7 @@ static bool pipboyRest(int hours, int minutes, int duration)
double v2 = v1 * (1.0 / 1440.0) * 3.5 + 0.25;
double v3 = (double)minutes / v1 * v2;
const unsigned int uiDelayMs = std::max(static_cast<int>(50.0 / settings.preferences.ui_anim_speed), 5);
const unsigned int uiDelayMs = std::max(static_cast<int>(50.0 / settings.ui.anim_speed), 5);
if (minutes != 0) {
unsigned int gameTime = gameTimeGetTime();
+19 -20
View File
@@ -99,7 +99,6 @@ typedef struct PreferenceDescription {
short maxX;
short labelIds[PRIMARY_OPTION_VALUE_COUNT];
int btn;
char name[32];
double minValue;
double maxValue;
int* valuePtr;
@@ -372,25 +371,25 @@ static int gPreferencesCombatLooks1;
// 0x5197F8
static PreferenceDescription gPreferenceDescriptions[PREF_COUNT] = {
{ 3, 0, 76, 71, 0, 0, { 203, 204, 205, 0 }, 0, GAME_CONFIG_GAME_DIFFICULTY_KEY, 0, 0, &gPreferencesGameDifficulty1 },
{ 3, 0, 76, 149, 0, 0, { 206, 204, 208, 0 }, 0, GAME_CONFIG_COMBAT_DIFFICULTY_KEY, 0, 0, &gPreferencesCombatDifficulty1 },
{ 4, 0, 76, 226, 0, 0, { 214, 215, 204, 216 }, 0, GAME_CONFIG_VIOLENCE_LEVEL_KEY, 0, 0, &gPreferencesViolenceLevel1 },
{ 3, 0, 76, 309, 0, 0, { 202, 201, 213, 0 }, 0, GAME_CONFIG_TARGET_HIGHLIGHT_KEY, 0, 0, &gPreferencesTargetHighlight1 },
{ 2, 0, 76, 387, 0, 0, { 202, 201, 0, 0 }, 0, GAME_CONFIG_COMBAT_LOOKS_KEY, 0, 0, &gPreferencesCombatLooks1 },
{ 2, 0, 299, 74, 0, 0, { 211, 212, 0, 0 }, 0, GAME_CONFIG_COMBAT_MESSAGES_KEY, 0, 0, &gPreferencesCombatMessages1 },
{ 2, 0, 299, 141, 0, 0, { 202, 201, 0, 0 }, 0, GAME_CONFIG_COMBAT_TAUNTS_KEY, 0, 0, &gPreferencesCombatTaunts1 },
{ 2, 0, 299, 207, 0, 0, { 202, 201, 0, 0 }, 0, GAME_CONFIG_LANGUAGE_FILTER_KEY, 0, 0, &gPreferencesLanguageFilter1 },
{ 2, 0, 299, 271, 0, 0, { 209, 219, 0, 0 }, 0, GAME_CONFIG_RUNNING_KEY, 0, 0, &gPreferencesRunning1 },
{ 2, 0, 299, 338, 0, 0, { 202, 201, 0, 0 }, 0, GAME_CONFIG_SUBTITLES_KEY, 0, 0, &gPreferencesSubtitles1 },
{ 2, 0, 299, 404, 0, 0, { 202, 201, 0, 0 }, 0, GAME_CONFIG_ITEM_HIGHLIGHT_KEY, 0, 0, &gPreferencesItemHighlight1 },
{ 2, 0, 374, 50, 0, 0, { 207, 210, 0, 0 }, 0, GAME_CONFIG_COMBAT_SPEED_KEY, 0.0, 50.0, &gPreferencesCombatSpeed1 },
{ 3, 0, 374, 125, 0, 0, { 217, 209, 218, 0 }, 0, GAME_CONFIG_TEXT_BASE_DELAY_KEY, 1.0, 6.0, nullptr },
{ 4, 0, 374, 196, 0, 0, { 202, 221, 209, 222 }, 0, GAME_CONFIG_MASTER_VOLUME_KEY, 0, 32767.0, &gPreferencesMasterVolume1 },
{ 4, 0, 374, 247, 0, 0, { 202, 221, 209, 222 }, 0, GAME_CONFIG_MUSIC_VOLUME_KEY, 0, 32767.0, &gPreferencesMusicVolume1 },
{ 4, 0, 374, 298, 0, 0, { 202, 221, 209, 222 }, 0, GAME_CONFIG_SNDFX_VOLUME_KEY, 0, 32767.0, &gPreferencesSoundEffectsVolume1 },
{ 4, 0, 374, 349, 0, 0, { 202, 221, 209, 222 }, 0, GAME_CONFIG_SPEECH_VOLUME_KEY, 0, 32767.0, &gPreferencesSpeechVolume1 },
{ 2, 0, 374, 400, 0, 0, { 207, 223, 0, 0 }, 0, GAME_CONFIG_BRIGHTNESS_KEY, 1.0, 1.17999267578125, nullptr },
{ 2, 0, 374, 451, 0, 0, { 207, 218, 0, 0 }, 0, GAME_CONFIG_MOUSE_SENSITIVITY_KEY, MOUSE_SENSITIVITY_MIN, MOUSE_SENSITIVITY_MAX, nullptr },
{ 3, 0, 76, 71, 0, 0, { 203, 204, 205, 0 }, 0, 0, 0, &gPreferencesGameDifficulty1 },
{ 3, 0, 76, 149, 0, 0, { 206, 204, 208, 0 }, 0, 0, 0, &gPreferencesCombatDifficulty1 },
{ 4, 0, 76, 226, 0, 0, { 214, 215, 204, 216 }, 0, 0, 0, &gPreferencesViolenceLevel1 },
{ 3, 0, 76, 309, 0, 0, { 202, 201, 213, 0 }, 0, 0, 0, &gPreferencesTargetHighlight1 },
{ 2, 0, 76, 387, 0, 0, { 202, 201, 0, 0 }, 0, 0, 0, &gPreferencesCombatLooks1 },
{ 2, 0, 299, 74, 0, 0, { 211, 212, 0, 0 }, 0, 0, 0, &gPreferencesCombatMessages1 },
{ 2, 0, 299, 141, 0, 0, { 202, 201, 0, 0 }, 0, 0, 0, &gPreferencesCombatTaunts1 },
{ 2, 0, 299, 207, 0, 0, { 202, 201, 0, 0 }, 0, 0, 0, &gPreferencesLanguageFilter1 },
{ 2, 0, 299, 271, 0, 0, { 209, 219, 0, 0 }, 0, 0, 0, &gPreferencesRunning1 },
{ 2, 0, 299, 338, 0, 0, { 202, 201, 0, 0 }, 0, 0, 0, &gPreferencesSubtitles1 },
{ 2, 0, 299, 404, 0, 0, { 202, 201, 0, 0 }, 0, 0, 0, &gPreferencesItemHighlight1 },
{ 2, 0, 374, 50, 0, 0, { 207, 210, 0, 0 }, 0, 0.0, 50.0, &gPreferencesCombatSpeed1 },
{ 3, 0, 374, 125, 0, 0, { 217, 209, 218, 0 }, 0, 1.0, 6.0, nullptr },
{ 4, 0, 374, 196, 0, 0, { 202, 221, 209, 222 }, 0, 0, 32767.0, &gPreferencesMasterVolume1 },
{ 4, 0, 374, 247, 0, 0, { 202, 221, 209, 222 }, 0, 0, 32767.0, &gPreferencesMusicVolume1 },
{ 4, 0, 374, 298, 0, 0, { 202, 221, 209, 222 }, 0, 0, 32767.0, &gPreferencesSoundEffectsVolume1 },
{ 4, 0, 374, 349, 0, 0, { 202, 221, 209, 222 }, 0, 0, 32767.0, &gPreferencesSpeechVolume1 },
{ 2, 0, 374, 400, 0, 0, { 207, 223, 0, 0 }, 0, 1.0, 1.17999267578125, nullptr },
{ 2, 0, 374, 451, 0, 0, { 207, 218, 0, 0 }, 0, MOUSE_SENSITIVITY_MIN, MOUSE_SENSITIVITY_MAX, nullptr },
};
static FrmImage _preferencesFrmImages[PREFERENCES_WINDOW_FRM_COUNT];
+221 -228
View File
@@ -1,228 +1,25 @@
#include "settings.h"
#include "debug.h"
#include "game_config.h"
#include "platform_compat.h"
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
namespace fallout {
static void settingsFromConfig();
static void settingsToConfig();
static void settingsRead(const char* section, const char* key, std::string& value);
static void settingsRead(const char* section, const char* key, int& value);
static void settingsRead(const char* section, const char* key, int& value, int minValue, int maxValue);
static void settingsRead(const char* section, const char* key, bool& value);
static void settingsRead(const char* section, const char* key, double& value);
static void settingsRead(const char* section, const char* key, double& value, double minValue, double maxValue);
static void settingsWrite(const char* section, const char* key, const std::string& value);
static void settingsWrite(const char* section, const char* key, int value);
static void settingsWrite(const char* section, const char* key, bool value);
static void settingsWrite(const char* section, const char* key, double value);
struct SettingDescriptor {
std::function<void()> read;
std::function<void()> write;
};
static std::vector<SettingDescriptor> settingsRegistry;
Settings settings;
bool settingsInit(bool isMapper, int argc, char** argv)
{
if (!gameConfigInit(isMapper, argc, argv)) {
return false;
}
settingsFromConfig();
return true;
}
bool settingsSave()
{
settingsToConfig();
return gameConfigSave();
}
bool settingsExit(bool shouldSave)
{
if (shouldSave) {
settingsToConfig();
}
return gameConfigExit(shouldSave);
}
static void settingsFromConfig()
{
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_EXECUTABLE_KEY, settings.system.executable);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_DAT_KEY, settings.system.master_dat_path);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, settings.system.master_patches_path);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_DAT_KEY, settings.system.critter_dat_path);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_PATCHES_KEY, settings.system.critter_patches_path);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, settings.system.language);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_SCROLL_LOCK_KEY, settings.system.scroll_lock);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_INTERRUPT_WALK_KEY, settings.system.interrupt_walk);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_ART_CACHE_SIZE_KEY, settings.system.art_cache_size);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_COLOR_CYCLING_KEY, settings.system.color_cycling);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CYCLE_SPEED_FACTOR_KEY, settings.system.cycle_speed_factor);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_HASHING_KEY, settings.system.hashing);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_SPLASH_KEY, settings.system.splash);
settingsRead(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_FREE_SPACE_KEY, settings.system.free_space);
settingsRead(GAME_CONFIG_SCREEN_KEY, GAME_CONFIG_RESOLUTION_X_KEY, settings.screen.resolution_x, 640, 7680);
settingsRead(GAME_CONFIG_SCREEN_KEY, GAME_CONFIG_RESOLUTION_Y_KEY, settings.screen.resolution_y, 480, 4320);
settingsRead(GAME_CONFIG_SCREEN_KEY, GAME_CONFIG_WINDOWED_KEY, settings.screen.windowed);
settingsRead(GAME_CONFIG_SCREEN_KEY, GAME_CONFIG_SCALE_KEY, settings.screen.scale, 1, 4);
settingsRead(GAME_CONFIG_UI_KEY, GAME_CONFIG_IFACE_BAR_MODE_KEY, settings.ui.iface_bar_mode);
settingsRead(GAME_CONFIG_UI_KEY, GAME_CONFIG_IFACE_BAR_WIDTH_KEY, settings.ui.iface_bar_width, 640, 4320);
settingsRead(GAME_CONFIG_UI_KEY, GAME_CONFIG_IFACE_BAR_SIDE_ART_KEY, settings.ui.iface_bar_side_art, 0, 999);
settingsRead(GAME_CONFIG_UI_KEY, GAME_CONFIG_IFACE_BAR_SIDES_ORI_KEY, settings.ui.iface_bar_sides_ori);
settingsRead(GAME_CONFIG_UI_KEY, GAME_CONFIG_SPLASH_SCREEN_SIZE_KEY, settings.ui.splash_screen_size, 0, 2);
settingsRead(GAME_CONFIG_UI_KEY, GAME_CONFIG_IGNORE_MAP_EDGES_KEY, settings.ui.ignore_map_edges);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_GAME_DIFFICULTY_KEY, settings.preferences.game_difficulty);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_DIFFICULTY_KEY, settings.preferences.combat_difficulty);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_VIOLENCE_LEVEL_KEY, settings.preferences.violence_level);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TARGET_HIGHLIGHT_KEY, settings.preferences.target_highlight);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_ITEM_HIGHLIGHT_KEY, settings.preferences.item_highlight);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_LOOKS_KEY, settings.preferences.combat_looks);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_MESSAGES_KEY, settings.preferences.combat_messages);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_TAUNTS_KEY, settings.preferences.combat_taunts);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_LANGUAGE_FILTER_KEY, settings.preferences.language_filter);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_RUNNING_KEY, settings.preferences.running);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_SUBTITLES_KEY, settings.preferences.subtitles);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_SPEED_KEY, settings.preferences.combat_speed);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_PLAYER_SPEED_KEY, settings.preferences.player_speedup);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TEXT_BASE_DELAY_KEY, settings.preferences.text_base_delay);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TEXT_LINE_DELAY_KEY, settings.preferences.text_line_delay);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_BRIGHTNESS_KEY, settings.preferences.brightness);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_MOUSE_SENSITIVITY_KEY, settings.preferences.mouse_sensitivity);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_RUNNING_BURNING_GUY_KEY, settings.preferences.running_burning_guy);
settingsRead(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_UI_ANIM_SPEED_KEY, settings.preferences.ui_anim_speed, 0.1, 100.0);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_INITIALIZE_KEY, settings.sound.initialize);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DEBUG_KEY, settings.sound.debug);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DEBUG_SFXC_KEY, settings.sound.debug_sfxc);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DEVICE_KEY, settings.sound.device);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_PORT_KEY, settings.sound.port);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_IRQ_KEY, settings.sound.irq);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DMA_KEY, settings.sound.dma);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SOUNDS_KEY, settings.sound.sounds);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_KEY, settings.sound.music);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SPEECH_KEY, settings.sound.speech);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MASTER_VOLUME_KEY, settings.sound.master_volume);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_VOLUME_KEY, settings.sound.music_volume);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SNDFX_VOLUME_KEY, settings.sound.sndfx_volume);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SPEECH_VOLUME_KEY, settings.sound.speech_volume);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_CACHE_SIZE_KEY, settings.sound.cache_size);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH1_KEY, settings.sound.music_path1);
settingsRead(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH2_KEY, settings.sound.music_path2);
settingsRead(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_MODE_KEY, settings.debug.mode);
settingsRead(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_TILE_NUM_KEY, settings.debug.show_tile_num);
settingsRead(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_SCRIPT_MESSAGES_KEY, settings.debug.show_script_messages);
settingsRead(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_LOAD_INFO_KEY, settings.debug.show_load_info);
settingsRead(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_OUTPUT_MAP_DATA_INFO_KEY, settings.debug.output_map_data_info);
settingsRead(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_DEBUG_WINDOW_WIDTH_KEY, settings.debug.debug_window_width, 200, 1920);
settingsRead(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_DEBUG_WINDOW_HEIGHT_KEY, settings.debug.debug_window_height, 100, 1080);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_OVERRIDE_LIBRARIAN_KEY, settings.mapper.override_librarian);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_LIBRARIAN_KEY, settings.mapper.librarian);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_USE_ART_NOT_PROTOS_KEY, settings.mapper.user_art_not_protos);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_REBUILD_PROTOS_KEY, settings.mapper.rebuild_protos);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_FIX_MAP_OBJECTS_KEY, settings.mapper.fix_map_objects);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_FIX_MAP_INVENTORY_KEY, settings.mapper.fix_map_inventory);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_IGNORE_REBUILD_ERRORS_KEY, settings.mapper.rebuild_protos);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SHOW_PID_NUMBERS_KEY, settings.mapper.show_pid_numbers);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SAVE_TEXT_MAPS_KEY, settings.mapper.save_text_maps);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_RUN_MAPPER_AS_GAME_KEY, settings.mapper.run_mapper_as_game);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_DEFAULT_F8_AS_GAME_KEY, settings.mapper.default_f8_as_game);
settingsRead(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SORT_SCRIPT_LIST_KEY, settings.mapper.sort_script_list);
}
static void settingsToConfig()
{
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_EXECUTABLE_KEY, settings.system.executable);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_DAT_KEY, settings.system.master_dat_path);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, settings.system.master_patches_path);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_DAT_KEY, settings.system.critter_dat_path);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CRITTER_PATCHES_KEY, settings.system.critter_patches_path);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, settings.system.language);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_SCROLL_LOCK_KEY, settings.system.scroll_lock);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_INTERRUPT_WALK_KEY, settings.system.interrupt_walk);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_ART_CACHE_SIZE_KEY, settings.system.art_cache_size);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_COLOR_CYCLING_KEY, settings.system.color_cycling);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_CYCLE_SPEED_FACTOR_KEY, settings.system.cycle_speed_factor);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_HASHING_KEY, settings.system.hashing);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_SPLASH_KEY, settings.system.splash);
settingsWrite(GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_FREE_SPACE_KEY, settings.system.free_space);
settingsWrite(GAME_CONFIG_SCREEN_KEY, GAME_CONFIG_RESOLUTION_X_KEY, settings.screen.resolution_x);
settingsWrite(GAME_CONFIG_SCREEN_KEY, GAME_CONFIG_RESOLUTION_Y_KEY, settings.screen.resolution_y);
settingsWrite(GAME_CONFIG_SCREEN_KEY, GAME_CONFIG_WINDOWED_KEY, settings.screen.windowed);
settingsWrite(GAME_CONFIG_SCREEN_KEY, GAME_CONFIG_SCALE_KEY, settings.screen.scale);
settingsWrite(GAME_CONFIG_UI_KEY, GAME_CONFIG_IFACE_BAR_MODE_KEY, settings.ui.iface_bar_mode);
settingsWrite(GAME_CONFIG_UI_KEY, GAME_CONFIG_IFACE_BAR_WIDTH_KEY, settings.ui.iface_bar_width);
settingsWrite(GAME_CONFIG_UI_KEY, GAME_CONFIG_IFACE_BAR_SIDE_ART_KEY, settings.ui.iface_bar_side_art);
settingsWrite(GAME_CONFIG_UI_KEY, GAME_CONFIG_IFACE_BAR_SIDES_ORI_KEY, settings.ui.iface_bar_sides_ori);
settingsWrite(GAME_CONFIG_UI_KEY, GAME_CONFIG_SPLASH_SCREEN_SIZE_KEY, settings.ui.splash_screen_size);
settingsWrite(GAME_CONFIG_UI_KEY, GAME_CONFIG_IGNORE_MAP_EDGES_KEY, settings.ui.ignore_map_edges);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_GAME_DIFFICULTY_KEY, settings.preferences.game_difficulty);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_DIFFICULTY_KEY, settings.preferences.combat_difficulty);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_VIOLENCE_LEVEL_KEY, settings.preferences.violence_level);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TARGET_HIGHLIGHT_KEY, settings.preferences.target_highlight);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_ITEM_HIGHLIGHT_KEY, settings.preferences.item_highlight);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_LOOKS_KEY, settings.preferences.combat_looks);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_MESSAGES_KEY, settings.preferences.combat_messages);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_TAUNTS_KEY, settings.preferences.combat_taunts);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_LANGUAGE_FILTER_KEY, settings.preferences.language_filter);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_RUNNING_KEY, settings.preferences.running);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_SUBTITLES_KEY, settings.preferences.subtitles);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_COMBAT_SPEED_KEY, settings.preferences.combat_speed);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_PLAYER_SPEED_KEY, settings.preferences.player_speedup);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TEXT_BASE_DELAY_KEY, settings.preferences.text_base_delay);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TEXT_LINE_DELAY_KEY, settings.preferences.text_line_delay);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_BRIGHTNESS_KEY, settings.preferences.brightness);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_MOUSE_SENSITIVITY_KEY, settings.preferences.mouse_sensitivity);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_RUNNING_BURNING_GUY_KEY, settings.preferences.running_burning_guy);
settingsWrite(GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_UI_ANIM_SPEED_KEY, settings.preferences.ui_anim_speed);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_INITIALIZE_KEY, settings.sound.initialize);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DEBUG_KEY, settings.sound.debug);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DEBUG_SFXC_KEY, settings.sound.debug_sfxc);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DEVICE_KEY, settings.sound.device);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_PORT_KEY, settings.sound.port);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_IRQ_KEY, settings.sound.irq);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_DMA_KEY, settings.sound.dma);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SOUNDS_KEY, settings.sound.sounds);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_KEY, settings.sound.music);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SPEECH_KEY, settings.sound.speech);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MASTER_VOLUME_KEY, settings.sound.master_volume);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_VOLUME_KEY, settings.sound.music_volume);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SNDFX_VOLUME_KEY, settings.sound.sndfx_volume);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_SPEECH_VOLUME_KEY, settings.sound.speech_volume);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_CACHE_SIZE_KEY, settings.sound.cache_size);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH1_KEY, settings.sound.music_path1);
settingsWrite(GAME_CONFIG_SOUND_KEY, GAME_CONFIG_MUSIC_PATH2_KEY, settings.sound.music_path2);
settingsWrite(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_MODE_KEY, settings.debug.mode);
settingsWrite(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_TILE_NUM_KEY, settings.debug.show_tile_num);
settingsWrite(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_SCRIPT_MESSAGES_KEY, settings.debug.show_script_messages);
settingsWrite(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_SHOW_LOAD_INFO_KEY, settings.debug.show_load_info);
settingsWrite(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_OUTPUT_MAP_DATA_INFO_KEY, settings.debug.output_map_data_info);
settingsWrite(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_DEBUG_WINDOW_WIDTH_KEY, settings.debug.debug_window_width);
settingsWrite(GAME_CONFIG_DEBUG_KEY, GAME_CONFIG_DEBUG_WINDOW_HEIGHT_KEY, settings.debug.debug_window_height);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_OVERRIDE_LIBRARIAN_KEY, settings.mapper.override_librarian);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_LIBRARIAN_KEY, settings.mapper.librarian);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_USE_ART_NOT_PROTOS_KEY, settings.mapper.user_art_not_protos);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_REBUILD_PROTOS_KEY, settings.mapper.rebuild_protos);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_FIX_MAP_OBJECTS_KEY, settings.mapper.fix_map_objects);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_FIX_MAP_INVENTORY_KEY, settings.mapper.fix_map_inventory);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_IGNORE_REBUILD_ERRORS_KEY, settings.mapper.rebuild_protos);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SHOW_PID_NUMBERS_KEY, settings.mapper.show_pid_numbers);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SAVE_TEXT_MAPS_KEY, settings.mapper.save_text_maps);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_RUN_MAPPER_AS_GAME_KEY, settings.mapper.run_mapper_as_game);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_DEFAULT_F8_AS_GAME_KEY, settings.mapper.default_f8_as_game);
settingsWrite(GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_SORT_SCRIPT_LIST_KEY, settings.mapper.sort_script_list);
}
static void settingsRead(const char* section, const char* key, std::string& value)
{
char* v;
@@ -239,12 +36,6 @@ static void settingsRead(const char* section, const char* key, int& value)
}
}
void settingsRead(const char* section, const char* key, int& value, int minValue, int maxValue)
{
settingsRead(section, key, value);
value = std::clamp(value, minValue, maxValue);
}
static void settingsRead(const char* section, const char* key, bool& value)
{
bool v;
@@ -261,12 +52,6 @@ static void settingsRead(const char* section, const char* key, double& value)
}
}
void settingsRead(const char* section, const char* key, double& value, double minValue, double maxValue)
{
settingsRead(section, key, value);
value = std::clamp(value, minValue, maxValue);
}
static void settingsWrite(const char* section, const char* key, const std::string& value)
{
configSetString(&gGameConfig, section, key, value.c_str());
@@ -287,4 +72,212 @@ static void settingsWrite(const char* section, const char* key, double value)
configSetDouble(&gGameConfig, section, key, value);
}
static void normalizePath(std::string& value, const char* section, const char* key)
{
char* path = value.data();
compat_windows_path_to_native(path);
compat_resolve_path(path);
}
template <typename T>
static std::function<void(T&, const char*, const char*)> clamp(T min, T max)
{
return [min, max](T& value, const char* section, const char* key) {
const T origValue = value;
value = std::clamp(value, min, max);
if (value != origValue) {
debugPrint("config value %s.%s was clamped.\n", section, key);
}
};
}
template <typename T>
void registerSetting(const char* section, const char* key, T& variable)
{
settingsRegistry.push_back(
{ [&, section, key]() { settingsRead(section, key, variable); },
[&, section, key]() { settingsWrite(section, key, variable); } });
}
template <typename T, typename P>
void registerSetting(const char* section, const char* key, T& variable, P postProcess)
{
settingsRegistry.push_back(
{ [&, section, key, postProcess]() {
settingsRead(section, key, variable);
postProcess(variable, section, key);
},
[&, section, key]() { settingsWrite(section, key, variable); } });
}
struct SettingEntry {
std::function<void(const char*)> registerFunc;
template <typename T>
SettingEntry(const char* key, T& variable)
: registerFunc([key, &variable](const char* section) { registerSetting(section, key, variable); })
{
}
template <typename T, typename P>
SettingEntry(const char* key, T& variable, P postProcess)
: registerFunc([key, &variable, postProcess](const char* section) { registerSetting(section, key, variable, postProcess); })
{
}
};
static void addSection(const char* section, const std::initializer_list<SettingEntry> entries)
{
for (const auto& entry : entries) {
entry.registerFunc(section);
}
}
void initSettingsRegistry(bool isMapper)
{
if (!settingsRegistry.empty()) return;
addSection(GAME_CONFIG_SYSTEM_KEY,
{
{ "executable", settings.system.executable },
{ GAME_CONFIG_MASTER_DAT_KEY, settings.system.master_dat_path, normalizePath },
{ GAME_CONFIG_MASTER_PATCHES_KEY, settings.system.master_patches_path, normalizePath },
{ GAME_CONFIG_CRITTER_DAT_KEY, settings.system.critter_dat_path, normalizePath },
{ GAME_CONFIG_CRITTER_PATCHES_KEY, settings.system.critter_patches_path, normalizePath },
{ "language", settings.system.language },
{ "scroll_lock", settings.system.scroll_lock },
{ "interrupt_walk", settings.system.interrupt_walk },
{ "art_cache_size", settings.system.art_cache_size },
{ "color_cycling", settings.system.color_cycling },
{ "cycle_speed_factor", settings.system.cycle_speed_factor },
{ "hashing", settings.system.hashing },
{ "splash", settings.system.splash },
{ "free_space", settings.system.free_space },
});
addSection(GAME_CONFIG_SCREEN_KEY,
{
{ GAME_CONFIG_RESOLUTION_X_KEY, settings.screen.resolution_x, clamp(640, 7680) },
{ GAME_CONFIG_RESOLUTION_Y_KEY, settings.screen.resolution_y, clamp(480, 4320) },
{ GAME_CONFIG_WINDOWED_KEY, settings.screen.windowed },
{ GAME_CONFIG_SCALE_KEY, settings.screen.scale, clamp(1, 4) },
});
addSection(GAME_CONFIG_UI_KEY,
{
{ GAME_CONFIG_IFACE_BAR_MODE_KEY, settings.ui.iface_bar_mode },
{ GAME_CONFIG_IFACE_BAR_WIDTH_KEY, settings.ui.iface_bar_width, clamp(640, 4320) },
{ GAME_CONFIG_IFACE_BAR_SIDE_ART_KEY, settings.ui.iface_bar_side_art, clamp(0, 999) },
{ GAME_CONFIG_IFACE_BAR_SIDES_ORI_KEY, settings.ui.iface_bar_sides_ori },
{ GAME_CONFIG_SPLASH_SCREEN_SIZE_KEY, settings.ui.splash_screen_size, clamp(0, 2) },
{ GAME_CONFIG_IGNORE_MAP_EDGES_KEY, settings.ui.ignore_map_edges },
{ "ui_anim_speed", settings.ui.anim_speed, clamp(0.1, 100.0) },
});
addSection("preferences",
{
// Clamping for most of these values is handled in preferences.cc
{ "game_difficulty", settings.preferences.game_difficulty },
{ "combat_difficulty", settings.preferences.combat_difficulty },
{ "violence_level", settings.preferences.violence_level },
{ "target_highlight", settings.preferences.target_highlight },
{ "item_highlight", settings.preferences.item_highlight },
{ "combat_looks", settings.preferences.combat_looks },
{ "combat_messages", settings.preferences.combat_messages },
{ "combat_taunts", settings.preferences.combat_taunts },
{ "language_filter", settings.preferences.language_filter },
{ "running", settings.preferences.running },
{ "subtitles", settings.preferences.subtitles },
{ "combat_speed", settings.preferences.combat_speed },
{ "player_speedup", settings.preferences.player_speedup },
{ "text_base_delay", settings.preferences.text_base_delay },
{ "text_line_delay", settings.preferences.text_line_delay },
{ "brightness", settings.preferences.brightness },
{ "mouse_sensitivity", settings.preferences.mouse_sensitivity },
{ "running_burning_guy", settings.preferences.running_burning_guy },
});
addSection(GAME_CONFIG_SOUND_KEY,
{
{ "initialize", settings.sound.initialize },
{ "debug", settings.sound.debug },
{ "debug_sfxc", settings.sound.debug_sfxc },
{ "sounds", settings.sound.sounds },
{ "music", settings.sound.music },
{ "speech", settings.sound.speech },
{ "master_volume", settings.sound.master_volume },
{ "music_volume", settings.sound.music_volume },
{ "sndfx_volume", settings.sound.sndfx_volume },
{ "speech_volume", settings.sound.speech_volume },
{ "cache_size", settings.sound.cache_size },
{ GAME_CONFIG_MUSIC_PATH1_KEY, settings.sound.music_path1, normalizePath },
{ GAME_CONFIG_MUSIC_PATH2_KEY, settings.sound.music_path2, normalizePath },
});
addSection(GAME_CONFIG_DEBUG_KEY,
{
{ GAME_CONFIG_MODE_KEY, settings.debug.mode },
{ "show_tile_num", settings.debug.show_tile_num },
{ "show_script_messages", settings.debug.show_script_messages },
{ "show_load_info", settings.debug.show_load_info },
{ "output_map_data_info", settings.debug.output_map_data_info },
{ "window_width", settings.debug.debug_window_width, clamp(200, 1920) },
{ "window_height", settings.debug.debug_window_height, clamp(100, 1080) },
});
if (isMapper) {
addSection("mapper",
{
{ "override_librarian", settings.mapper.override_librarian },
{ "librarian", settings.mapper.librarian },
{ "use_art_not_protos", settings.mapper.user_art_not_protos },
{ "rebuild_protos", settings.mapper.rebuild_protos },
{ "fix_map_objects", settings.mapper.fix_map_objects },
{ "fix_map_inventory", settings.mapper.fix_map_inventory },
{ "ignore_rebuild_errors", settings.mapper.ignore_rebuild_errors },
{ "show_pid_numbers", settings.mapper.show_pid_numbers },
{ "save_text_maps", settings.mapper.save_text_maps },
{ "run_mapper_as_game", settings.mapper.run_mapper_as_game },
{ "default_f8_as_game", settings.mapper.default_f8_as_game },
{ "sort_script_list", settings.mapper.sort_script_list },
});
}
}
bool settingsInit(bool isMapper, int argc, char** argv)
{
initSettingsRegistry(isMapper);
if (!gameConfigInit(isMapper, argc, argv)) {
return false;
}
for (const auto& descriptor : settingsRegistry) {
descriptor.read();
}
return true;
}
void settingsWriteToConfig()
{
for (const auto& descriptor : settingsRegistry) {
descriptor.write();
}
}
bool settingsSave()
{
settingsWriteToConfig();
return gameConfigSave();
}
bool settingsExit(bool shouldSave)
{
if (shouldSave) {
settingsWriteToConfig();
}
return gameConfigExit(shouldSave);
}
} // namespace fallout
+6 -8
View File
@@ -50,8 +50,13 @@ struct UISettings {
int splash_screen_size = 0;
bool ignore_map_edges = false;
// TODO: add to setting window
// Speed of various UI transition animations. 1.0 represents vanilla speeds.
double anim_speed = 1.0;
};
// These are settings handled by preferences UI and saved in save games.
struct PreferencesSettings {
int game_difficulty = GAME_DIFFICULTY_NORMAL;
int combat_difficulty = COMBAT_DIFFICULTY_NORMAL;
@@ -71,20 +76,12 @@ struct PreferencesSettings {
double brightness = 1.0;
double mouse_sensitivity = 1.0;
bool running_burning_guy = true;
// TODO: add to setting window
// Speed of various UI transition animations. 1.0 represents vanilla speeds.
double ui_anim_speed = 1.0;
};
struct SoundSettings {
bool initialize = true;
bool debug = false;
bool debug_sfxc = true;
int device = -1;
int port = -1;
int irq = -1;
int dma = -1;
bool sounds = true;
bool music = true;
bool speech = true;
@@ -136,6 +133,7 @@ extern Settings settings;
bool settingsInit(bool isMapper, int argc, char** argv);
bool settingsSave();
void settingsWriteToConfig();
bool settingsExit(bool shouldSave);
} // namespace fallout