From 4a94ec0ac05c9a39248d8ff6866f7dec29fb6de2 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sat, 10 Nov 2018 20:21:52 +0100 Subject: [PATCH] Output --help text to Console window on Windows (that Console thing they wrote for the dedicated server which is also used by Sys_Error()) --- neo/CMakeLists.txt | 1 + neo/framework/Common.cpp | 93 ++++++++++++++++++++++++---------------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 24e63733..68f1d4a0 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -231,6 +231,7 @@ elseif(MSVC) add_compile_options(/wd4714) # 'function' marked as __forceinline not inlined add_compile_options(/wd4996) # 'function': was declared deprecated add_compile_options(/wd4068) # unknown pragma + add_compile_options(/wd4458) # declaration of 'variable' hides class member add_definitions(-D_ALLOW_KEYWORD_MACROS) # because of the "#define private public" and "#define protected public" in TypeInfo.cpp set(CMAKE_C_FLAGS_DEBUG "-D_DEBUG /Od /Zi /MDd") set(CMAKE_C_FLAGS_RELEASE "/Ox /Oy /MD") diff --git a/neo/framework/Common.cpp b/neo/framework/Common.cpp index f6979bcf..5829110b 100644 --- a/neo/framework/Common.cpp +++ b/neo/framework/Common.cpp @@ -2759,6 +2759,10 @@ static unsigned int AsyncTimer(unsigned int interval, void *) { return tick - now; } +#ifdef _WIN32 +#include "../sys/win32/win_local.h" // for Conbuf_AppendText() +#endif // _WIN32 + static bool checkForHelp(int argc, char **argv) { const char* helpArgs[] = { "--help", "-h", "-help", "-?", "/?" }; @@ -2771,48 +2775,56 @@ static bool checkForHelp(int argc, char **argv) { if (idStr::Icmp(arg, helpArgs[h]) == 0) { - // TODO: use Printf() or sth instead? - printf("%s - http://dhewm3.org\n", ENGINE_VERSION); - printf("Commandline arguments:\n"); - printf("-h or --help: Show this help\n"); - printf("+ [command arguments]\n"); - printf(" executes a command (with optional arguments)\n"); +#ifdef _WIN32 + // write it to the Windows-only console window + #define WriteString(s) Conbuf_AppendText(s) +#else // not windows + // write it to stdout + #define WriteString(s) fputs(s, stdout); +#endif // _WIN32 + WriteString(ENGINE_VERSION " - http://dhewm3.org\n"); + WriteString("Commandline arguments:\n"); + WriteString("-h or --help: Show this help\n"); + WriteString("+ [command arguments]\n"); + WriteString(" executes a command (with optional arguments)\n"); - printf("\nSome interesting commands:\n"); - printf("+map \n"); - printf(" directly loads the given level, e.g. +map game/hell1\n"); - printf("+exec \n"); - printf(" execute the given config (mainly relevant for dedicated servers)\n"); - printf("+disconnect\n"); - printf(" starts the game, goes directly into main menu without showing logo video\n"); - printf("+connect [:port]\n"); - printf(" directly connect to multiplayer server at given host/port\n"); - printf(" e.g. +connect d3.example.com\n"); - printf(" e.g. +connect d3.example.com:27667\n"); - printf(" e.g. +connect 192.168.0.42:27666\n"); - printf("+set \n"); - printf(" Set the given cvar to the given value, e.g. +set r_fullscreen 0\n"); - printf("+seta \n"); - printf(" like +set, but also makes sure the changed cvar is saved (\"archived\") in a cfg\n"); + WriteString("\nSome interesting commands:\n"); + WriteString("+map \n"); + WriteString(" directly loads the given level, e.g. +map game/hell1\n"); + WriteString("+exec \n"); + WriteString(" execute the given config (mainly relevant for dedicated servers)\n"); + WriteString("+disconnect\n"); + WriteString(" starts the game, goes directly into main menu without showing\n logo video\n"); + WriteString("+connect [:port]\n"); + WriteString(" directly connect to multiplayer server at given host/port\n"); + WriteString(" e.g. +connect d3.example.com\n"); + WriteString(" e.g. +connect d3.example.com:27667\n"); + WriteString(" e.g. +connect 192.168.0.42:27666\n"); + WriteString("+set \n"); + WriteString(" Set the given cvar to the given value, e.g. +set r_fullscreen 0\n"); + WriteString("+seta \n"); + WriteString(" like +set, but also makes sure the changed cvar is saved (\"archived\")\n in a cfg\n"); - printf("\nSome interesting cvars:\n"); - printf("+set fs_basepath \n"); - printf(" set path to your Doom3 game data (the directory base/ is in)\n"); - printf("+set fs_game \n"); - printf(" start the given addon/mod, e.g. +set fs_game d3xp\n"); + WriteString("\nSome interesting cvars:\n"); + WriteString("+set fs_basepath \n"); + WriteString(" set path to your Doom3 game data (the directory base/ is in)\n"); + WriteString("+set fs_game \n"); + WriteString(" start the given addon/mod, e.g. +set fs_game d3xp\n"); #ifndef ID_DEDICATED - printf("+set r_fullscreen <0 or 1>\n"); - printf(" start game in windowed (0) or fullscreen (1) mode\n"); - printf("+set r_mode \n"); - printf(" start game in resolution belonging to ,\n"); - printf(" use -1 for custom resolutions:\n"); - printf("+set r_customWidth \n"); - printf("+set r_customHeight \n"); - printf(" if r_mode is set to -1, these cvars allow you to specify the\n"); - printf(" width/height of your custom resolution\n"); + WriteString("+set r_fullscreen <0 or 1>\n"); + WriteString(" start game in windowed (0) or fullscreen (1) mode\n"); + WriteString("+set r_mode \n"); + WriteString(" start game in resolution belonging to ,\n"); + WriteString(" use -1 for custom resolutions:\n"); + WriteString("+set r_customWidth \n"); + WriteString("+set r_customHeight \n"); + WriteString(" if r_mode is set to -1, these cvars allow you to specify the\n"); + WriteString(" width/height of your custom resolution\n"); #endif // !ID_DEDICATED - printf("\nSee https://modwiki.xnet.fi/CVars_%%28Doom_3%%29 for more cvars\n"); - printf("See https://modwiki.xnet.fi/Commands_%%28Doom_3%%29 for more commands\n"); + WriteString("\nSee https://modwiki.xnet.fi/CVars_%%28Doom_3%%29 for more cvars\n"); + WriteString("See https://modwiki.xnet.fi/Commands_%%28Doom_3%%29 for more commands\n"); + + #undef WriteString return true; } @@ -2831,6 +2843,11 @@ void idCommonLocal::Init( int argc, char **argv ) { if(checkForHelp(argc, argv)) { // game has been started with --help (or similar), usage message has been shown => quit +#ifdef _WIN32 + // this enforces that the console window is shown until the user closes it + // => checkForHelp() writes to the console window on Windows + Sys_Error("."); +#endif // _WIN32 exit(1); }