diff --git a/Makefile b/Makefile index 902f54e2..572deaa3 100644 --- a/Makefile +++ b/Makefile @@ -873,9 +873,6 @@ ifeq ($(WINDOWS_BUILD),1) ifeq ($(CROSS),) LDFLAGS += -no-pie endif - ifeq ($(WINDOWS_CONSOLE),1) - LDFLAGS += -mconsole - endif else ifeq ($(TARGET_RPI),1) LDFLAGS := $(OPT_FLAGS) -lm $(BACKEND_LDFLAGS) -no-pie else ifeq ($(OSX_BUILD),1) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index e89989f3..0b79af88 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -57,6 +57,11 @@ bool parse_cli_opts(int argc, char* argv[]) { else if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode gCLIOpts.FullScreen = 2; +#if defined(_WIN32) || defined(_WIN64) + else if (strcmp(argv[i], "--console") == 0) // Open game with console + gCLIOpts.Console = 1; +#endif + else if (strcmp(argv[i], "--server") == 0 && (i + 1) < argc) { // Host server gCLIOpts.Network = NT_SERVER; arg_uint("--server ", argv[++i], &gCLIOpts.NetworkPort); diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index 6d729ba1..eb8948ee 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -16,6 +16,9 @@ enum NetworkType { struct PCCLIOptions { unsigned int SkipIntro; unsigned int FullScreen; +#if defined(_WIN32) || defined(_WIN64) + unsigned int Console; +#endif enum NetworkType Network; char JoinIp[IP_MAX_LEN]; unsigned int NetworkPort; diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 6d5e8c2c..03ba1603 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -294,7 +294,7 @@ struct QueuedMods { static struct QueuedMods *sQueuedEnableModsHead = NULL; -void enable_queued_mods() { +void enable_queued_mods(void) { while (sQueuedEnableModsHead) { struct QueuedMods *next = sQueuedEnableModsHead->next; mods_enable(sQueuedEnableModsHead->path); @@ -630,14 +630,14 @@ void configfile_load(void) { void configfile_save(const char *filename) { FILE *file; - printf("Saving configuration to '%s'\n", filename); - file = fopen(fs_get_write_path(filename), "w"); if (file == NULL) { // error return; } + printf("Saving configuration to '%s'\n", filename); + for (unsigned int i = 0; i < ARRAY_LEN(options); i++) { const struct ConfigOption *option = &options[i]; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 7a71ac9d..cab8879d 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -56,6 +56,10 @@ #include "pc/discord/discord.h" #endif +#if defined(_WIN32) || defined(_WIN64) +#include +#endif + bool gCoopCompatibility; OSMesg D_80339BEC; @@ -344,6 +348,16 @@ int main(int argc, char *argv[]) { // Handle terminal arguments if (!parse_cli_opts(argc, argv)) { return 0; } +#if defined(_WIN32) || defined(_WIN64) + // Handle Windows console + if (gCLIOpts.Console && AllocConsole()) { + FILE* fDummy; + freopen_s(&fDummy, "CONOUT$", "w", stdout); + freopen_s(&fDummy, "CONOUT$", "w", stderr); + freopen_s(&fDummy, "CONIN$", "r", stdin); + } +#endif + // Create the window straight away if (!gGfxInited) { gfx_init(&WAPI, &RAPI, TITLE);