Add --console, remove WINDOWS_CONSOLE=1

This commit is contained in:
Agent X 2023-12-24 10:26:44 -05:00
parent c7e996f53e
commit c27da0e382
5 changed files with 25 additions and 6 deletions

View File

@ -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)

View File

@ -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 <port>", argv[++i], &gCLIOpts.NetworkPort);

View File

@ -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;

View File

@ -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];

View File

@ -56,6 +56,10 @@
#include "pc/discord/discord.h"
#endif
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#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);