Introduce sfall config

This commit is contained in:
Alexander Batalov 2022-05-26 00:16:20 +03:00
parent bc8db9e8c2
commit b467198f16
6 changed files with 94 additions and 18 deletions

View File

@ -229,6 +229,8 @@ add_executable(fallout2-ce WIN32
target_sources(fallout2-ce PUBLIC
"src/fps_limiter.cc"
"src/fps_limiter.h"
"src/sfall_config.cc"
"src/sfall_config.h"
)
target_compile_definitions(fallout2-ce PUBLIC

View File

@ -43,6 +43,7 @@
#include "queue.h"
#include "random.h"
#include "scripts.h"
#include "sfall_config.h"
#include "skill.h"
#include "skilldex.h"
#include "stat.h"
@ -115,12 +116,17 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4
return -1;
}
// Sfall config should be initialized before game config, since it can
// override it's file name.
sfallConfigInit(argc, argv);
gameConfigInit(isMapper, argc, argv);
gIsMapper = isMapper;
if (gameDbInit() == -1) {
gameConfigExit(false);
sfallConfigExit();
return -1;
}
@ -402,6 +408,7 @@ void gameExit()
_windowClose();
dbExit();
gameConfigExit(true);
sfallConfigExit();
}
// 0x442D44

View File

@ -21,7 +21,7 @@ Config gGameConfig;
// 0x58E978
char gGameConfigFilePath[FILENAME_MAX];
// Inits main game config and optionally Sfall config.
// Inits main game config.
//
// [isMapper] is a flag indicating whether we're initing config for a main
// game, or a mapper. This value is `false` for the game itself.
@ -136,22 +136,6 @@ bool gameConfigInit(bool isMapper, int argc, char** argv)
// whatever was loaded from `fallout2.cfg`.
configParseCommandLineArguments(&gGameConfig, argc, argv);
// Optional Sfall extension
Config sfallConfig;
if (configInit(&sfallConfig)) {
configRead(&sfallConfig, "ddraw.ini", false);
configParseCommandLineArguments(&sfallConfig, argc, argv);
char* startingMap;
if (configGetString(&sfallConfig, "misc", "StartingMap", &startingMap)) {
if (*startingMap != '\0') {
strncpy(_mainMap, startingMap, 16);
}
}
}
configFree(&sfallConfig);
gGameConfigInitialized = true;
return true;

View File

@ -22,6 +22,7 @@
#include "palette.h"
#include "random.h"
#include "scripts.h"
#include "sfall_config.h"
#include "selfrun.h"
#include "text_font.h"
#include "version.h"
@ -155,7 +156,19 @@ int falloutMain(int argc, char** argv)
if (characterSelectorOpen() == 2) {
gameMoviePlay(MOVIE_ELDER, GAME_MOVIE_STOP_MUSIC);
randomSeedPrerandom(-1);
_main_load_new(_mainMap);
// SFALL: Override starting map.
char* mapName = NULL;
if (configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_STARTING_MAP_KEY, &mapName)) {
if (*mapName == '\0') {
mapName = NULL;
}
}
char* mapNameCopy = strdup(mapName != NULL ? mapName : _mainMap);
_main_load_new(mapNameCopy);
free(mapNameCopy);
mainLoop(fpsLimiter);
paletteFadeTo(gPaletteWhite);
objectHide(gDude, NULL);

50
src/sfall_config.cc Normal file
View File

@ -0,0 +1,50 @@
#include "sfall_config.h"
#include <stdio.h>
#include <string.h>
#define SFALL_CONFIG_FILE_NAME "ddraw.ini"
bool gSfallConfigInitialized = false;
Config gSfallConfig;
bool sfallConfigInit(int argc, char** argv)
{
if (gSfallConfigInitialized) {
return false;
}
if (!configInit(&gSfallConfig)) {
return false;
}
// Initialize defaults.
configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_STARTING_MAP_KEY, "");
char path[FILENAME_MAX];
char* executable = argv[0];
char* ch = strrchr(executable, '\\');
if (ch != NULL) {
*ch = '\0';
sprintf(path, "%s\\%s", executable, SFALL_CONFIG_FILE_NAME);
*ch = '\\';
} else {
strcpy(path, SFALL_CONFIG_FILE_NAME);
}
configRead(&gSfallConfig, path, false);
configParseCommandLineArguments(&gSfallConfig, argc, argv);
gSfallConfigInitialized = true;
return true;
}
void sfallConfigExit()
{
if (gSfallConfigInitialized) {
configFree(&gSfallConfig);
gSfallConfigInitialized = false;
}
}

20
src/sfall_config.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef SFALL_CONFIG_H
#define SFALL_CONFIG_H
#include "config.h"
#include <stdbool.h>
#define SFALL_CONFIG_FILE_NAME "ddraw.ini"
#define SFALL_CONFIG_MISC_KEY "Misc"
#define SFALL_CONFIG_STARTING_MAP_KEY "StartingMap"
extern bool gSfallConfigInitialized;
extern Config gSfallConfig;
bool sfallConfigInit(int argc, char** argv);
void sfallConfigExit();
#endif /* SFALL_CONFIG_H */