diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-07-17 22:33:00 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-07-17 22:33:00 +0100 |
commit | ca5db71e8215a6c5660fe03088a6d7349f55f817 (patch) | |
tree | 534b79d2599475b1da3edb4f232223d9e32d3174 /NorthstarDedicatedTest/sourceconsole.cpp | |
parent | 51d3d4a40c8579e29571bc80d35bbb62fa50661b (diff) | |
download | NorthstarLauncher-ca5db71e8215a6c5660fe03088a6d7349f55f817.tar.gz NorthstarLauncher-ca5db71e8215a6c5660fe03088a6d7349f55f817.zip |
add support for custom convars and concommands
Diffstat (limited to 'NorthstarDedicatedTest/sourceconsole.cpp')
-rw-r--r-- | NorthstarDedicatedTest/sourceconsole.cpp | 76 |
1 files changed, 57 insertions, 19 deletions
diff --git a/NorthstarDedicatedTest/sourceconsole.cpp b/NorthstarDedicatedTest/sourceconsole.cpp index 775ec856..0aeacb86 100644 --- a/NorthstarDedicatedTest/sourceconsole.cpp +++ b/NorthstarDedicatedTest/sourceconsole.cpp @@ -1,37 +1,75 @@ #include "pch.h" #include "sourceconsole.h" #include "sourceinterface.h" +#include "concommand.h" #include "hookutils.h" -#include <iostream> -SourceInterface<CGameConsole>* g_pSourceGameConsole; +SourceInterface<CGameConsole>* g_SourceGameConsole; -typedef void(*weaponlisttype)(); -weaponlisttype weaponlist; -void CommandWeaponListHook() +void ConCommand_toggleconsole(const CCommand& arg) { - std::cout << "TEMP: toggling console... REPLACE THIS WITH ACTUAL CONCOMMAND SUPPORT SOON" << std::endl; + if ((*g_SourceGameConsole)->IsConsoleVisible()) + (*g_SourceGameConsole)->Hide(); + else + (*g_SourceGameConsole)->Activate(); +} - (*g_pSourceGameConsole)->Activate(); +void ConCommand_help(const CCommand& arg) +{ + } -CreateInterfaceFn createInterface; -void* __fastcall InitialiseConsoleOnUIInit(const char* pName, int* pReturnCode) +typedef void(*OnCommandSubmittedType)(CConsoleDialog* consoleDialog, const char* pCommand); +OnCommandSubmittedType onCommandSubmittedOriginal; +void OnCommandSubmittedHook(CConsoleDialog* consoleDialog, const char* pCommand) { - std::cout << pName << std::endl; - void* ret = createInterface(pName, pReturnCode); + consoleDialog->m_pConsolePanel->Print("] "); + consoleDialog->m_pConsolePanel->Print(pCommand); + consoleDialog->m_pConsolePanel->Print("\n"); - if (!strcmp(pName, "GameClientExports001")) - (*g_pSourceGameConsole)->Initialize(); + // todo: call the help command in the future +} + +// called from sourceinterface.cpp in client createinterface hooks, on GameClientExports001 +void InitialiseConsoleOnInterfaceCreation() +{ + (*g_SourceGameConsole)->Initialize(); - return ret; + auto consoleLogger = std::make_shared<SourceConsoleSink>(); + consoleLogger->set_pattern("[%l] %v"); + + spdlog::default_logger()->sinks().push_back(consoleLogger); + + // hook OnCommandSubmitted so we print inputted commands + HookEnabler hook; + ENABLER_CREATEHOOK(hook, (void*)((*g_SourceGameConsole)->m_pConsole->m_vtable->OnCommandSubmitted), &OnCommandSubmittedHook, reinterpret_cast<LPVOID*>(&onCommandSubmittedOriginal)); } void InitialiseSourceConsole(HMODULE baseAddress) { - g_pSourceGameConsole = new SourceInterface<CGameConsole>("client.dll", "GameConsole004"); + g_SourceGameConsole = new SourceInterface<CGameConsole>("client.dll", "GameConsole004"); + RegisterConCommand("toggleconsole", ConCommand_toggleconsole, "toggles the console", FCVAR_NONE); +} - HookEnabler hook; - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x73BA00, &InitialiseConsoleOnUIInit, reinterpret_cast<LPVOID*>(&createInterface)); - ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x10C080, &CommandWeaponListHook, reinterpret_cast<LPVOID*>(&weaponlist)); -}
\ No newline at end of file +SourceConsoleSink::SourceConsoleSink() +{ + logColours.emplace(spdlog::level::trace, SourceColor(0, 255, 255, 255)); + logColours.emplace(spdlog::level::debug, SourceColor(0, 255, 255, 255)); + logColours.emplace(spdlog::level::info, SourceColor(255, 255, 255, 255)); + logColours.emplace(spdlog::level::warn, SourceColor(255, 255, 0, 255)); + logColours.emplace(spdlog::level::err, SourceColor(255, 0, 0, 255)); + logColours.emplace(spdlog::level::critical, SourceColor(255, 0, 0, 255)); + logColours.emplace(spdlog::level::off, SourceColor(0, 0, 0, 0)); +} + +void SourceConsoleSink::sink_it_(const spdlog::details::log_msg& msg) +{ + if (!(*g_SourceGameConsole)->m_bInitialized) + return; + + spdlog::memory_buf_t formatted; + spdlog::sinks::base_sink<std::mutex>::formatter_->format(msg, formatted); + (*g_SourceGameConsole)->m_pConsole->m_pConsolePanel->ColorPrint(logColours[msg.level], fmt::to_string(formatted).c_str()); // todo needs colour support +} + +void SourceConsoleSink::flush_() {}
\ No newline at end of file |