From dd61fa89534e68ee6093aabf234894bab253bb81 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Sun, 7 Sep 2025 22:59:41 -0400 Subject: [PATCH] Add --show-console option --- CMakeLists.txt | 2 +- launch.vs.json | 3 ++- src/main/main.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82093fc..d2878b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,7 +290,7 @@ if (WIN32) ) # target_sources(BanjoRecompiled PRIVATE ${CMAKE_SOURCE_DIR}/icons/app.rc) - target_link_libraries(BanjoRecompiled PRIVATE SDL2) + target_link_libraries(BanjoRecompiled PRIVATE SDL2 Winmm.lib) endif() if (APPLE) diff --git a/launch.vs.json b/launch.vs.json index bdec2da..64d0201 100644 --- a/launch.vs.json +++ b/launch.vs.json @@ -7,7 +7,8 @@ "project": "CMakeLists.txt", "projectTarget": "BanjoRecompiled.exe", "name": "BanjoRecompiled.exe", - "currentDir": "${workspaceRoot}" + "currentDir": "${workspaceRoot}", + "args": ["--show-console"] } ] } \ No newline at end of file diff --git a/src/main/main.cpp b/src/main/main.cpp index 984b44b..2e74bd6 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -42,6 +42,7 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include +#include #include "SDL_syswm.h" #endif @@ -543,6 +544,26 @@ int main(int argc, char** argv) { } #ifdef _WIN32 + // Set up high resolution timing period. + timeBeginPeriod(1); + + // Process arguments. + for (int i = 1; i < argc; i++) + { + if (strcmp(argv[i], "--show-console") == 0) + { + if (GetConsoleWindow() == nullptr) + { + AllocConsole(); + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stderr); + freopen("CONOUT$", "w", stdout); + } + + break; + } + } + // Set up console output to accept UTF-8 on windows SetConsoleOutputCP(CP_UTF8); @@ -683,5 +704,10 @@ int main(int argc, char** argv) { release_preload(preload_context); } +#ifdef _WIN32 + // End high resolution timing period. + timeEndPeriod(1); +#endif + return EXIT_SUCCESS; }