diff --git a/src/module/console.cpp b/src/module/console.cpp index 9e88a39..6960e5f 100644 --- a/src/module/console.cpp +++ b/src/module/console.cpp @@ -4,7 +4,7 @@ #include "console.hpp" #include "scheduler.hpp" - +#include "log_file.hpp" #include @@ -101,6 +101,7 @@ void console::log_message(const std::string& message) void console::dispatch_message([[maybe_unused]] const int type, const std::string& message) { + log_file::info(message); message_queue_.access([&message](message_queue& queue) { queue.emplace(message); diff --git a/src/module/discord.cpp b/src/module/discord.cpp index 0f1ec51..fbf8af4 100644 --- a/src/module/discord.cpp +++ b/src/module/discord.cpp @@ -3,7 +3,7 @@ #include "game/game.hpp" #include "scheduler.hpp" -#include "log_file.hpp" +#include "console.hpp" #include @@ -44,7 +44,7 @@ private: static void errored(const int error_code, const char* message) { - log_file::info("Discord: (%i) %s", error_code, message); + console::error("Discord: (%i) %s", error_code, message); } }; diff --git a/src/module/dvar.cpp b/src/module/dvar.cpp index cc8c7f0..fe6029c 100644 --- a/src/module/dvar.cpp +++ b/src/module/dvar.cpp @@ -3,6 +3,7 @@ #include "game/game.hpp" #include "command.hpp" +#include "console.hpp" #include "log_file.hpp" #include "dvar.hpp" @@ -52,68 +53,68 @@ void dvar::list_single(const game::native::dvar_t* dvar, void* user_data) if (dvar->flags & game::native::DVAR_SERVERINFO) { - log_file::info("S"); + console::info("S"); } else { - log_file::info(" "); + console::info(" "); } if (dvar->flags & game::native::DVAR_USERINFO) { - log_file::info("U"); + console::info("U"); } else { - log_file::info(" "); + console::info(" "); } if (dvar->flags & game::native::DVAR_ROM) { - log_file::info("R"); + console::info("R"); } else { - log_file::info(" "); + console::info(" "); } if (dvar->flags & game::native::DVAR_INIT) { - log_file::info("I"); + console::info("I"); } else { - log_file::info(" "); + console::info(" "); } if (dvar->flags & game::native::DVAR_ARCHIVE) { - log_file::info("A"); + console::info("A"); } else { - log_file::info(" "); + console::info(" "); } if (dvar->flags & game::native::DVAR_LATCH) { - log_file::info("L"); + console::info("L"); } else { - log_file::info(" "); + console::info(" "); } if (dvar->flags & game::native::DVAR_CHEAT) { - log_file::info("C"); + console::info("C"); } else { - log_file::info(" "); + console::info(" "); } - log_file::info(" %s \"%s\"\n", dvar->name, game::native::Dvar_DisplayableValue(dvar)); + console::info(" %s \"%s\"\n", dvar->name, game::native::Dvar_DisplayableValue(dvar)); } void dvar::com_dvar_dump_single(const game::native::dvar_t* dvar, void* user_data) @@ -137,7 +138,7 @@ void dvar::com_dvar_dump_single(const game::native::dvar_t* dvar, void* user_dat sprintf_s(message, " %s \"%s\"\n", dvar->name, game::native::Dvar_DisplayableValue(dvar)); } - log_file::info("%s", message); + console::info("%s", message); } void dvar::com_dvar_dump(int channel, const char* match) @@ -150,14 +151,14 @@ void dvar::com_dvar_dump(int channel, const char* match) return; } - log_file::info("=============================== DVAR DUMP ========================================\n"); + console::info("=============================== DVAR DUMP ========================================\n"); dump_info.count = 0; dump_info.channel = channel; dump_info.match = match; game::native::Dvar_ForEach(com_dvar_dump_single, &dump_info); sprintf_s(summary, "\n%i total dvars\n%i dvar indexes\n", dump_info.count, *game::native::dvarCount); - log_file::info("%s", summary); - log_file::info("=============================== END DVAR DUMP =====================================\n"); + console::info("%s", summary); + console::info("=============================== END DVAR DUMP =====================================\n"); } void dvar::dump_f(const command::params& params) @@ -188,7 +189,7 @@ void dvar::list_f(const command::params& params) } game::native::Dvar_ForEach(list_single, (void*)match); - log_file::info("\n%i total dvars\n", *game::native::dvarCount); + console::info("\n%i total dvars\n", *game::native::dvarCount); } void dvar::post_load() diff --git a/src/module/file_system.cpp b/src/module/file_system.cpp index 18c0665..94c13d6 100644 --- a/src/module/file_system.cpp +++ b/src/module/file_system.cpp @@ -5,8 +5,8 @@ #include #include "command.hpp" +#include "console.hpp" #include "file_system.hpp" -#include "log_file.hpp" namespace { @@ -38,7 +38,7 @@ namespace return file; } - log_file::info("Couldn't open file: %s %s\n", filename, std::strerror(errno)); + console::error("Couldn't open file: %s %s\n", filename, std::strerror(errno)); return nullptr; } @@ -51,7 +51,7 @@ namespace return file; } - log_file::info("Couldn't open file: %s %s\n", filename, std::strerror(errno)); + console::error("Couldn't open file: %s %s\n", filename, std::strerror(errno)); return nullptr; } @@ -158,7 +158,7 @@ namespace build_os_path_for_thread(basepath, game::native::fs_gamedir, filename, ospath, game::native::FS_THREAD_MAIN); if ((*fs_debug)->current.integer) { - log_file::info("FS_FOpenFileAppend: %s\n", ospath); + console::info("FS_FOpenFileAppend: %s\n", ospath); } if (game::native::FS_CreatePath(ospath)) @@ -216,7 +216,7 @@ namespace if ((*fs_debug)->current.integer) { - log_file::info("FS_FOpenFileWriteToDirForThread: %s\n", ospath); + console::info("FS_FOpenFileWriteToDirForThread: %s\n", ospath); } if (game::native::FS_CreatePath(ospath)) @@ -355,13 +355,13 @@ namespace { auto i_language = game::native::SEH_GetCurrentLanguage(); const auto* psz_language_name = game::native::SEH_GetLanguageName(i_language); - log_file::info("Current language: %s\n", psz_language_name); + console::info("Current language: %s\n", psz_language_name); if ((*fs_ignoreLocalized)->current.enabled) { - log_file::info(" localized assets are being ignored\n"); + console::info(" localized assets are being ignored\n"); } - log_file::info("Current search path:\n"); + console::info("Current search path:\n"); for (auto* s = *game::native::fs_searchpaths; s; s = s->next) { if (b_language_cull && !use_search_path(s)) @@ -371,40 +371,40 @@ namespace if (s->iwd) { - log_file::info("%s (%i files)\n", s->iwd->iwdFilename, s->iwd->numfiles); + console::info("%s (%i files)\n", s->iwd->iwdFilename, s->iwd->numfiles); if (s->bLocalized) { - log_file::info(" localized assets iwd file for %s\n", game::native::SEH_GetLanguageName(s->language)); + console::info(" localized assets iwd file for %s\n", game::native::SEH_GetLanguageName(s->language)); } if (*game::native::fs_numServerIwds) { if (iwd_is_pure(s->iwd)) { - log_file::info(" on the pure list\n"); + console::info(" on the pure list\n"); } else { - log_file::info(" not on the pure list\n"); + console::info(" not on the pure list\n"); } } } else { - log_file::info("%s/%s\n", s->dir->path, s->dir->gamedir); + console::info("%s/%s\n", s->dir->path, s->dir->gamedir); if (s->bLocalized) { - log_file::info(" localized assets game folder for %s\n", game::native::SEH_GetLanguageName(s->language)); + console::info(" localized assets game folder for %s\n", game::native::SEH_GetLanguageName(s->language)); } } } - log_file::info("\nFile Handles:\n"); + console::info("\nFile Handles:\n"); for (int i = 1; i < 64; ++i) { if (game::native::fsh[i].handleFiles.file.o) { - log_file::info("handle %i: %s\n", i, game::native::fsh[i].name); + console::info("handle %i: %s\n", i, game::native::fsh[i].name); } } } @@ -434,7 +434,7 @@ namespace if (game::native::Cmd_Argc() < 2 || game::native::Cmd_Argc() > 3) { - log_file::info("usage: dir [extension]\n"); + console::info("usage: dir [extension]\n"); return; } @@ -449,14 +449,14 @@ namespace extension = game::native::Cmd_Argv(2); } - log_file::info("Directory of %s %s\n", path, extension); - log_file::info("---------------\n"); + console::info("Directory of %s %s\n", path, extension); + console::info("---------------\n"); auto** dirnames = list_files(path, extension, game::native::FS_LIST_PURE_ONLY, &ndirs, 3); for (int i = 0; i < ndirs; ++i) { - log_file::info("%s\n", dirnames[i]); + console::info("%s\n", dirnames[i]); } game::native::Sys_FreeFileList(dirnames); @@ -468,14 +468,14 @@ namespace if (game::native::Cmd_Argc() < 2) { - log_file::info("usage: fdir \n"); - log_file::info("example: fdir *q3dm*.bsp\n"); + console::info("usage: fdir \n"); + console::info("example: fdir *q3dm*.bsp\n"); return; } const auto* filter = game::native::Cmd_Argv(1); - log_file::info("---------------\n"); + console::info("---------------\n"); auto** dirnames = game::native::FS_ListFilteredFiles(*game::native::fs_searchpaths, "", "", filter, game::native::FS_LIST_PURE_ONLY, &ndirs, 3); sort_file_list(dirnames, ndirs); @@ -483,9 +483,10 @@ namespace for (auto i = 0; i < ndirs; ++i) { convert_path(dirnames[i]); - log_file::info("%s\n", dirnames[i]); + console::info("%s\n", dirnames[i]); } - log_file::info("%d files listed\n", ndirs); + + console::info("%d files listed\n", ndirs); game::native::Sys_FreeFileList(dirnames); } @@ -493,7 +494,7 @@ namespace { if (game::native::Cmd_Argc() != 2) { - log_file::info("Usage: touchFile \n"); + console::info("Usage: touchFile \n"); return; } @@ -511,15 +512,15 @@ namespace void fs_startup_stub(char* game_name) { - log_file::info("----- FS_Startup -----\n"); + console::info("----- FS_Startup -----\n"); utils::hook::invoke(0x5B1070, game_name); add_commands(); display_path(true); - log_file::info("----------------------\n"); - log_file::info("%d files in iwd files\n", *game::native::fs_iwdFileCount); + console::info("----------------------\n"); + console::info("%d files in iwd files\n", *game::native::fs_iwdFileCount); } void fs_shutdown_stub(int closemfp) diff --git a/src/module/fov.cpp b/src/module/fov.cpp index 6881894..8833aec 100644 --- a/src/module/fov.cpp +++ b/src/module/fov.cpp @@ -2,7 +2,7 @@ #include #include "game/game.hpp" -#include "log_file.hpp" +#include "console.hpp" #include @@ -31,7 +31,7 @@ private: const auto* dvar = game::native::Dvar_FindVar(dvar_name); if (dvar != nullptr && ((dvar->flags & game::native::DVAR_ARCHIVE) != 0)) { - log_file::info("Not allowing server to override archive dvar '%s'\n", dvar_name); + console::info("Not allowing server to override archive dvar '%s'\n", dvar_name); return; } diff --git a/src/module/gsc/script_error.cpp b/src/module/gsc/script_error.cpp index 2c1a768..9c049d6 100644 --- a/src/module/gsc/script_error.cpp +++ b/src/module/gsc/script_error.cpp @@ -5,7 +5,7 @@ #include "script_error.hpp" #include "script_loading.hpp" -#include "module/log_file.hpp" +#include "module/console.hpp" #include "module/scripting.hpp" #include @@ -140,17 +140,17 @@ namespace gsc if (function_id > (scr_func_max_id - 1)) { - log_file::info("in call to builtin method \"%s\"%s\n", xsk::gsc::iw5::resolver::method_name(function_id).data(), error.data()); + console::error("in call to builtin method \"%s\"%s\n", xsk::gsc::iw5::resolver::method_name(function_id).data(), error.data()); } else { - log_file::info("in call to builtin function \"%s\"%s\n", xsk::gsc::iw5::resolver::function_name(function_id).data(), error.data()); + console::error("in call to builtin function \"%s\"%s\n", xsk::gsc::iw5::resolver::function_name(function_id).data(), error.data()); } } void vm_error_stub(int mark_pos) { - log_file::info("******* script runtime error ********\n"); + console::error("******* script runtime error ********\n"); const auto opcode_id = *reinterpret_cast(SELECT_VALUE(0x1BF6928, 0x20B8E28)); const auto error = (*gsc_error_msg) ? std::format(": {}\n", gsc_error_msg) : std::string(); @@ -164,17 +164,17 @@ namespace gsc const auto opcode = get_opcode_name(opcode_id); if (opcode.has_value()) { - log_file::info("while processing instruction %s%s\n", opcode.value().data(), error.data()); + console::error("while processing instruction %s%s\n", opcode.value().data(), error.data()); } else { - log_file::info("while processing instruction 0x%X%s\n", opcode_id, error.data()); + console::error("while processing instruction 0x%X%s\n", opcode_id, error.data()); } } ZeroMemory(gsc_error_msg, sizeof(gsc_error_msg)); - log_file::info("************************************\n"); + console::error("************************************\n"); game::native::LargeLocalResetToMark(mark_pos); } diff --git a/src/module/gsc/script_loading.cpp b/src/module/gsc/script_loading.cpp index 8cc6cec..197d83d 100644 --- a/src/module/gsc/script_loading.cpp +++ b/src/module/gsc/script_loading.cpp @@ -4,7 +4,7 @@ #include "script_loading.hpp" -#include "module/log_file.hpp" +#include "module/console.hpp" #include "module/scripting.hpp" #include @@ -72,9 +72,9 @@ namespace gsc } catch (const std::exception& ex) { - log_file::info("*********** script compile error *************\n"); - log_file::info("failed to compile '%s':\n%s", real_name.data(), ex.what()); - log_file::info("**********************************************\n"); + console::error("*********** script compile error *************\n"); + console::error("failed to compile '%s':\n%s", real_name.data(), ex.what()); + console::error("**********************************************\n"); return nullptr; } @@ -86,9 +86,9 @@ namespace gsc } catch (const std::exception& ex) { - log_file::info("*********** script compile error *************\n"); - log_file::info("failed to assemble '%s':\n%s", real_name.data(), ex.what()); - log_file::info("**********************************************\n"); + console::error("*********** script compile error *************\n"); + console::error("failed to assemble '%s':\n%s", real_name.data(), ex.what()); + console::error("**********************************************\n"); return nullptr; } diff --git a/src/module/log_file.cpp b/src/module/log_file.cpp index 101cbaf..49b5d62 100644 --- a/src/module/log_file.cpp +++ b/src/module/log_file.cpp @@ -30,7 +30,7 @@ void log_file::com_open_log_file() file_system::open_file_by_mode(log_file_name, game::native::logfile, game::native::FS_APPEND_SYNC); asctime_s(time_buffer, sizeof(time_buffer), &new_time); - info("logfile opened on %s\n", time_buffer); + info(std::format("logfile opened on {}\n", time_buffer)); opening_qconsole = 0; com_console_log_open_failed = *game::native::logfile == 0; } @@ -66,21 +66,12 @@ void log_file::com_log_print_message(const std::string& msg) } } -void log_file::info(const char* fmt, ...) +void log_file::info(const std::string& msg) { - char msg[0x1000]{}; - va_list argptr; - - va_start(argptr, fmt); - vsnprintf_s(msg, _TRUNCATE, fmt, argptr); - va_end(argptr); - if (com_logfile && com_logfile->current.integer) { com_log_print_message(msg); } - - console::info("%s", msg); } void log_file::post_load() diff --git a/src/module/log_file.hpp b/src/module/log_file.hpp index 474690a..1ee08a2 100644 --- a/src/module/log_file.hpp +++ b/src/module/log_file.hpp @@ -6,7 +6,8 @@ public: void post_load() override; static void com_log_print_message(const std::string& msg); - static void info(const char* fmt, ...); + + static void info(const std::string& msg); static const game::native::dvar_t* com_logfile; diff --git a/src/module/test_clients.cpp b/src/module/test_clients.cpp index 788052d..b8b88ba 100644 --- a/src/module/test_clients.cpp +++ b/src/module/test_clients.cpp @@ -9,7 +9,7 @@ #include "test_clients.hpp" #include "command.hpp" #include "scheduler.hpp" -#include "log_file.hpp" +#include "console.hpp" bool test_clients::can_add() { @@ -205,7 +205,7 @@ void test_clients::post_load() const auto count = std::strtol(input, &end, 10); if (input == end) { - log_file::info("%s is not a valid input\nUsage: %s \n", input, params.get(0)); + console::info("%s is not a valid input\nUsage: %s \n", input, params.get(0)); return; }