Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting game directory from CLI; add -v flag #85

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ endif()
if(WIN32)
target_link_libraries(${EXECUTABLE_NAME}
winmm
Shlwapi
)
endif()

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Download and copy `fallout-ce.exe` to your `Fallout` folder. It serves as a drop

- Use Windows installation as a base - it contains data assets needed to play. Copy `Fallout` folder somewhere, for example `/home/john/Desktop/Fallout`.

- Make sure the `DATA` directory is in lower-case.

- Download and copy `fallout-ce` to this folder.

- Install [SDL2](https://libsdl.org/download-2.0.php):
Expand Down Expand Up @@ -77,15 +79,26 @@ The second configuration file is `f1_res.ini`. Use it to change game window size
SCR_WIDTH=1280
SCR_HEIGHT=720
WINDOWED=1
SCALE_2X=1
```

It only reads these values from `f1_res.ini`; all other values are ignored.

Recommendations:
- **Desktops**: Use any size you see fit.
- **Tablets**: Set these values to logical resolution of your device, for example iPad Pro 11 is 1668x2388 (pixels), but it's logical resolution is 834x1194 (points).
- **Mobile phones**: Set height to 480, calculate width according to your device screen (aspect) ratio, for example Samsung S21 is 20:9 device, so the width should be 480 * 20 / 9 = 1067.

In time this stuff will receive in-game interface, right now you have to do it manually.

You can use `[section]name=value` from the commandline to override values from the configuration file. For example:

% ./fallout1-ce ~/games/fallout '[preferences]brightness=2'

Note that the CLI values will be written to `fallout.cfg`! Overriding values from `f1_res.ini` is not supported.

Add `-v` to show more debug information.

## Contributing

Here is a couple of current goals. Open up an issue if you have suggestion or feature request.
Expand Down
4 changes: 2 additions & 2 deletions src/game/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ static int game_init_databases()

master_db_handle = db_init(main_file_name, NULL, patch_file_name, 1);
if (master_db_handle == INVALID_DATABASE_HANDLE) {
GNWSystemError("Could not find the master datafile. Please make sure the FALLOUT CD is in the drive and that you are running FALLOUT from the directory you installed it to.");
GNWSystemError("Could not find MASTER.DAT. Please make sure that you are running FALLOUT from the directory you installed it to.");
return -1;
}

Expand All @@ -1228,7 +1228,7 @@ static int game_init_databases()
critter_db_handle = db_init(main_file_name, NULL, patch_file_name, 1);
if (critter_db_handle == INVALID_DATABASE_HANDLE) {
db_select(master_db_handle);
GNWSystemError("Could not find the critter datafile. Please make sure the FALLOUT CD is in the drive and that you are running FALLOUT from the directory you installed it to.");
GNWSystemError("Could not find CRITTER.DAT. Please make sure that you are running FALLOUT from the directory you installed it to.");
return -1;
}

Expand Down
56 changes: 56 additions & 0 deletions src/game/gconfig.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#include "game/gconfig.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef _WIN32
#include <direct.h>
#include <shlwapi.h>
#else
#include <libgen.h>
#include <unistd.h>
#endif

#include "platform_compat.h"
#include "plib/gnw/debug.h"

namespace fallout {

Expand Down Expand Up @@ -119,6 +129,52 @@ bool gconfig_init(bool isMapper, int argc, char** argv)
config_set_value(&game_config, GAME_CONFIG_MAPPER_KEY, GAME_CONFIG_DEFAULT_F8_AS_GAME_KEY, 1);
}

char* gamedir = NULL;
for (int i = 1; i < argc; i++) {
if (strlen(argv[i]) < 2 || argv[i][0] != '-') {
if (gamedir == NULL && strchr(argv[i], '[') == NULL && strchr(argv[i], ']') == NULL)
gamedir = argv[i];
continue;
}

switch (argv[i][1]) {
case 'v':
do_debug = true;
break;
case 'h':
printf("usage: %s [-v] [game_dir] [option...]\n"
"\n"
"Flags:\n"
" -v Print more information.\n\n"
" game_dir Fallout installation directory; defaults to directory binary\n"
" is in.\n\n"
" option Any list of option to override from fallout.cfg\n"
" as \"[section]key=value\" Note that new value will be written\n"
" to fallout.cfg! Overriding values from f1_res.ini is not\n"
" supported.\n\n",
argv[0]);
exit(0);
}
}
if (gamedir == NULL) {
#if _WIN32
gamedir = (char*)calloc(strlen(argv[0]), sizeof(char));
strcpy(gamedir, argv[0]);
PathRemoveFileSpecA(gamedir);
#else
gamedir = dirname(argv[0]);
#endif
if (gamedir == NULL) {
perror("resolving argv[0]");
exit(1);
}
}
debug_printf("game directory: %s\n", gamedir);
if (chdir(gamedir) == -1) {
perror("changing to game directory");
exit(1);
}

// Make `fallout.cfg` file path.
sep = strrchr(argv[0], '\\');
if (sep != NULL) {
Expand Down
7 changes: 4 additions & 3 deletions src/plib/gnw/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace fallout {

bool do_debug = false;

static int debug_mono(char* string);
static int debug_log(char* string);
static int debug_screen(char* string);
Expand Down Expand Up @@ -143,9 +145,8 @@ int debug_printf(const char* format, ...)

rc = debug_func(string);
} else {
#ifdef _DEBUG
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, format, args);
#endif
if (do_debug)
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, format, args);
rc = -1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/plib/gnw/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace fallout {

typedef int(DebugFunc)(char* string);

extern bool do_debug;

void GNW_debug_init();
void debug_register_mono();
void debug_register_log(const char* fileName, const char* mode);
Expand Down
2 changes: 2 additions & 0 deletions src/plib/gnw/gnw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,8 @@ static int colorClose(void* handle)
// 0x4C42B8
bool GNWSystemError(const char* text)
{
fprintf(stderr, "%s\n", text);

SDL_Cursor* prev = SDL_GetCursor();
SDL_Cursor* cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
SDL_SetCursor(cursor);
Expand Down