From bd4119d0d70567325e7e979a3305f6d631c98dad Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Wed, 11 May 2022 17:03:30 +0100 Subject: make cvar print work on dedi, move demo fix stuff, add findflags --- .../NorthstarDedicatedTest.vcxproj | 6 + .../NorthstarDedicatedTest.vcxproj.filters | 69 ++++++--- NorthstarDedicatedTest/commandprint.cpp | 161 +++++++++++++++++++++ NorthstarDedicatedTest/commandprint.h | 6 + NorthstarDedicatedTest/dedicated.cpp | 2 + NorthstarDedicatedTest/demofixes.cpp | 25 ++++ NorthstarDedicatedTest/demofixes.h | 1 + NorthstarDedicatedTest/host.cpp | 6 + NorthstarDedicatedTest/mapsprint.cpp | 7 + NorthstarDedicatedTest/mapsprint.h | 2 + NorthstarDedicatedTest/miscclientfixes.cpp | 15 -- NorthstarDedicatedTest/sourceconsole.cpp | 117 +-------------- 12 files changed, 266 insertions(+), 151 deletions(-) create mode 100644 NorthstarDedicatedTest/commandprint.cpp create mode 100644 NorthstarDedicatedTest/commandprint.h create mode 100644 NorthstarDedicatedTest/demofixes.cpp create mode 100644 NorthstarDedicatedTest/demofixes.h create mode 100644 NorthstarDedicatedTest/mapsprint.cpp create mode 100644 NorthstarDedicatedTest/mapsprint.h (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index a12a10f5..172ad4ca 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -120,12 +120,15 @@ + + + @@ -592,6 +595,7 @@ + @@ -602,6 +606,7 @@ + @@ -619,6 +624,7 @@ + diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index 0dc606d2..8f63935b 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -25,9 +25,6 @@ {4f525372-34a8-40b3-8a95-81d77cdfcf7f} - - {8b8ed12a-9269-4dc3-b932-0daefdf6a388} - {b6f79919-9735-476d-8798-067a75cbeca0} @@ -142,6 +139,18 @@ {04fd662a-6e70-494c-b720-c694a5cc2fb1} + + {325e0d7d-6832-496d-8d8e-968fdfa5dd40} + + + {802d0771-62f1-4733-89f9-57a4d8864b8d} + + + {0f1ba4c4-78ee-4b05-afa5-6f598063f5c1} + + + {bf0769d8-40fd-4701-85e9-7ed94aab2283} + @@ -159,9 +168,6 @@ Header Files - - Header Files\Dedicated - Header Files\Client @@ -585,15 +591,9 @@ Header Files\Client - - Header Files\Dedicated - Header Files\Shared\Convar - - Header Files\Server - Header Files\Shared\Mods\Compiled @@ -1458,9 +1458,6 @@ Header Files\Shared\Math - - Header Files\Server - Header Files\Client @@ -1527,6 +1524,27 @@ Header Files\Shared + + Header Files\Server\Scripted + + + Header Files\Server\Scripted + + + Header Files\Server\Dedicated + + + Header Files\Server\Dedicated + + + Header Files\Shared\Console + + + Header Files\Shared\Console + + + Header Files\Client + @@ -1598,9 +1616,6 @@ Source Files\Shared\Convar - - Source Files\Server - Source Files\Shared\Mods\Compiled Assets @@ -1646,9 +1661,6 @@ Source Files\Shared\Math - - Source Files\Server - Source Files\Client @@ -1700,6 +1712,21 @@ Source Files\Client\Scripted + + Source Files\Server\Scripted + + + Source Files\Server\Scripted + + + Source Files\Shared\Console + + + Source Files\Client + + + Source Files\Shared\Console + diff --git a/NorthstarDedicatedTest/commandprint.cpp b/NorthstarDedicatedTest/commandprint.cpp new file mode 100644 index 00000000..5d78a1b4 --- /dev/null +++ b/NorthstarDedicatedTest/commandprint.cpp @@ -0,0 +1,161 @@ +#include "pch.h" +#include "commandprint.h" +#include "convar.h" +#include "concommand.h" + +void PrintCommandHelpDialogue(const ConCommandBase* command, const char* name) +{ + if (!command) + { + spdlog::info("unknown command {}", name); + return; + } + + // build string for flags if not FCVAR_NONE + std::string flagString; + if (command->GetFlags() != FCVAR_NONE) + { + flagString = "( "; + + for (auto& flagPair : g_PrintCommandFlags) + { + if (command->GetFlags() & flagPair.first) + { + flagString += flagPair.second; + flagString += " "; + } + } + + flagString += ") "; + } + + // temp because command->IsCommand does not currently work + ConVar* cvar = g_pCVar->FindVar(command->m_pszName); + if (cvar) + spdlog::info("\"{}\" = \"{}\" {}- {}", cvar->GetBaseName(), cvar->GetString(), flagString, cvar->GetHelpText()); + else + spdlog::info("\"{}\" {} - {}", command->m_pszName, flagString, command->GetHelpText()); +} + +void TryPrintCvarHelpForCommand(const char* pCommand) +{ + // try to display help text for an inputted command string from the console + int pCommandLen = strlen(pCommand); + char* pCvarStr = new char[pCommandLen]; + strcpy(pCvarStr, pCommand); + + // trim whitespace from right + for (int i = pCommandLen - 1; i; i--) + { + if (isspace(pCvarStr[i])) + pCvarStr[i] = '\0'; + else + break; + } + + // check if we're inputting a cvar, but not setting it at all + ConVar* cvar = g_pCVar->FindVar(pCvarStr); + if (cvar) + PrintCommandHelpDialogue(&cvar->m_ConCommandBase, pCvarStr); + + delete[] pCvarStr; +} + +void ConCommand_help(const CCommand& arg) +{ + if (arg.ArgC() < 2) + { + spdlog::info("Usage: help "); + return; + } + + PrintCommandHelpDialogue(g_pCVar->FindCommandBase(arg.Arg(1)), arg.Arg(1)); +} + +void ConCommand_find(const CCommand& arg) +{ + if (arg.ArgC() < 2) + { + spdlog::info("Usage: find [...]"); + return; + } + + char pTempName[256]; + char pTempSearchTerm[256]; + + for (auto& map : g_pCVar->DumpToMap()) + { + bool bPrintCommand = true; + for (int i = 0; i < arg.ArgC() - 1; i++) + { + // make lowercase to avoid case sensitivity + strncpy(pTempName, map.second->m_pszName, sizeof(pTempName)); + strncpy(pTempSearchTerm, arg.Arg(i + 1), sizeof(pTempSearchTerm)); + + for (int i = 0; pTempName[i]; i++) + pTempName[i] = tolower(pTempName[i]); + + for (int i = 0; pTempSearchTerm[i]; i++) + pTempSearchTerm[i] = tolower(pTempSearchTerm[i]); + + if (!strstr(pTempName, pTempSearchTerm)) + { + bPrintCommand = false; + break; + } + } + + if (bPrintCommand) + PrintCommandHelpDialogue(map.second, map.second->m_pszName); + } +} + +void ConCommand_findflags(const CCommand& arg) +{ + if (arg.ArgC() < 2) + { + spdlog::info("Usage: findflags "); + for (auto& flagPair : g_PrintCommandFlags) + spdlog::info(" - {}", flagPair.second); + + return; + } + + // convert input flag to uppercase + char* upperFlag = new char[strlen(arg.Arg(1))]; + strcpy(upperFlag, arg.Arg(1)); + + for (int i = 0; upperFlag[i]; i++) + upperFlag[i] = toupper(upperFlag[i]); + + // resolve flag name => int flags + int resolvedFlag = FCVAR_NONE; + for (auto& flagPair : g_PrintCommandFlags) + { + if (!strcmp(flagPair.second, upperFlag)) + { + resolvedFlag = flagPair.first; + break; + } + } + + // print cvars + for (auto& map : g_pCVar->DumpToMap()) + { + if (map.second->m_nFlags & resolvedFlag) + PrintCommandHelpDialogue(map.second, map.second->m_pszName); + } + + delete[] upperFlag; +} + +void InitialiseCommandPrint() +{ + RegisterConCommand("find", ConCommand_find, "Find concommands with the specified string in their name/help text.", FCVAR_NONE); + RegisterConCommand("findflags", ConCommand_findflags, "Find concommands by flags.", FCVAR_NONE); + // help is already a command, so we need to modify the preexisting command to use our func instead + // and clear the flags also + ConCommand* helpCommand = g_pCVar->FindCommand("help"); + helpCommand->m_nFlags = FCVAR_NONE; + helpCommand->m_pCommandCallback = ConCommand_help; +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/commandprint.h b/NorthstarDedicatedTest/commandprint.h new file mode 100644 index 00000000..803cccc4 --- /dev/null +++ b/NorthstarDedicatedTest/commandprint.h @@ -0,0 +1,6 @@ +#pragma once +#include "concommand.h" + +void PrintCommandHelpDialogue(const ConCommandBase* command, const char* name); +void TryPrintCvarHelpForCommand(const char* pCommand); +void InitialiseCommandPrint(); \ No newline at end of file diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 280a9889..2df43fe9 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -8,6 +8,7 @@ #include "hoststate.h" #include "serverauthentication.h" #include "masterserver.h" +#include "commandprint.h" using namespace Tier0; using namespace R2; @@ -125,6 +126,7 @@ DWORD WINAPI ConsoleInputThread(PVOID pThreadParameter) { input += "\n"; Cbuf_AddText(Cbuf_GetCurrentPlayer(), input.c_str(), cmd_source_t::kCommandSrcCode); + TryPrintCvarHelpForCommand(input.c_str()); } } diff --git a/NorthstarDedicatedTest/demofixes.cpp b/NorthstarDedicatedTest/demofixes.cpp new file mode 100644 index 00000000..0cfb35f4 --- /dev/null +++ b/NorthstarDedicatedTest/demofixes.cpp @@ -0,0 +1,25 @@ +#include "pch.h" +#include "demofixes.h" +#include "convar.h" +#include "NSMem.h" + +ON_DLL_LOAD_CLIENT_RELIESON("client.dll", DemoFixes, ConVar, [](HMODULE baseAddress) +{ + // allow demo recording on loopback + NSMem::NOP((uintptr_t)GetModuleHandleA("engine.dll") + 0x8E1B1, 2); + NSMem::NOP((uintptr_t)GetModuleHandleA("engine.dll") + 0x56CC3, 2); + + // change default values of demo cvars to enable them by default, but not autorecord + // this is before Host_Init, the setvalue calls here will get overwritten by custom cfgs/launch options + ConVar* Cvar_demo_enableDemos = g_pCVar->FindVar("demo_enabledemos"); + Cvar_demo_enableDemos->m_pszDefaultValue = "1"; + Cvar_demo_enableDemos->SetValue(true); + + ConVar* Cvar_demo_writeLocalFile = g_pCVar->FindVar("demo_writeLocalFile"); + Cvar_demo_writeLocalFile->m_pszDefaultValue = "1"; + Cvar_demo_writeLocalFile->SetValue(true); + + ConVar* Cvar_demo_autoRecord = g_pCVar->FindVar("demo_autoRecord"); + Cvar_demo_autoRecord->m_pszDefaultValue = "0"; + Cvar_demo_autoRecord->SetValue(false); +}) \ No newline at end of file diff --git a/NorthstarDedicatedTest/demofixes.h b/NorthstarDedicatedTest/demofixes.h new file mode 100644 index 00000000..7b9637ef --- /dev/null +++ b/NorthstarDedicatedTest/demofixes.h @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/NorthstarDedicatedTest/host.cpp b/NorthstarDedicatedTest/host.cpp index 5f56be4e..624809b5 100644 --- a/NorthstarDedicatedTest/host.cpp +++ b/NorthstarDedicatedTest/host.cpp @@ -3,6 +3,8 @@ #include "convar.h" #include "modmanager.h" #include "gameutils.h" +#include "commandprint.h" +#include "mapsprint.h" typedef void (*Host_InitType)(bool bDedicated); Host_InitType Host_Init; @@ -46,6 +48,10 @@ void Host_InitHook(bool bDedicated) // make servers able to run disconnect on clients g_pCVar->FindCommand("disconnect")->m_nFlags |= FCVAR_SERVER_CAN_EXECUTE; + // need to initialise these after host_init since they do stuff to preexisting concommands/convars + InitialiseCommandPrint(); + InitialiseMapsPrint(); + // run client autoexec if on client if (!bDedicated) Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_client", cmd_source_t::kCommandSrcCode); diff --git a/NorthstarDedicatedTest/mapsprint.cpp b/NorthstarDedicatedTest/mapsprint.cpp new file mode 100644 index 00000000..770fb9cf --- /dev/null +++ b/NorthstarDedicatedTest/mapsprint.cpp @@ -0,0 +1,7 @@ +#include "pch.h" +#include "mapsprint.h" + +void InitialiseMapsPrint() +{ + +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/mapsprint.h b/NorthstarDedicatedTest/mapsprint.h new file mode 100644 index 00000000..daa1df8c --- /dev/null +++ b/NorthstarDedicatedTest/mapsprint.h @@ -0,0 +1,2 @@ +#pragma once +void InitialiseMapsPrint(); \ No newline at end of file diff --git a/NorthstarDedicatedTest/miscclientfixes.cpp b/NorthstarDedicatedTest/miscclientfixes.cpp index a72e1893..777d5696 100644 --- a/NorthstarDedicatedTest/miscclientfixes.cpp +++ b/NorthstarDedicatedTest/miscclientfixes.cpp @@ -33,21 +33,6 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", MiscClientFixes, ConVar, [](HMODULE ba { HookEnabler hook; - // these functions will occasionally pass a null pointer on respawn, unsure what causes this but seems easiest just to return null if - // null, which seems to work fine fucking sucks this has to be fixed like this but unsure what exactly causes this serverside, breaks - // vanilla compatibility to a degree tho will say i have about 0 clue what exactly these functions do, testing this it doesn't even seem - // like they do much of anything i can see tbh - ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x5A92D0, &CrashingWeaponActivityFunc0Hook, reinterpret_cast(&CrashingWeaponActivityFunc0)); - ENABLER_CREATEHOOK( - hook, (char*)baseAddress + 0x5A9310, &CrashingWeaponActivityFunc1Hook, reinterpret_cast(&CrashingWeaponActivityFunc1)); - - // experimental: allow cl_extrapolate to be enabled without cheats - { - void* ptr = (char*)baseAddress + 0x275F9D9; - *((char*)ptr) = (char)0; - } - // allow demo recording on loopback NSMem::NOP((uintptr_t)GetModuleHandleA("engine.dll") + 0x8E1B1, 2); NSMem::NOP((uintptr_t)GetModuleHandleA("engine.dll") + 0x56CC3, 2); diff --git a/NorthstarDedicatedTest/sourceconsole.cpp b/NorthstarDedicatedTest/sourceconsole.cpp index ee05cc66..e6035ac5 100644 --- a/NorthstarDedicatedTest/sourceconsole.cpp +++ b/NorthstarDedicatedTest/sourceconsole.cpp @@ -4,7 +4,7 @@ #include "sourceconsole.h" #include "sourceinterface.h" #include "concommand.h" -#include "hookutils.h" +#include "commandprint.h" SourceInterface* g_SourceGameConsole; @@ -26,89 +26,6 @@ void ConCommand_hideconsole(const CCommand& arg) (*g_SourceGameConsole)->Hide(); } -void PrintCommandHelpDialogue(const ConCommandBase* command, const char* name) -{ - if (!command) - { - spdlog::info("unknown command {}", name); - return; - } - - // build string for flags if not FCVAR_NONE - std::string flagString; - if (command->GetFlags() != FCVAR_NONE) - { - flagString = "( "; - - for (auto& flagPair : g_PrintCommandFlags) - { - if (command->GetFlags() & flagPair.first) - { - flagString += flagPair.second; - flagString += " "; - } - } - - flagString += ") "; - } - - // temp because command->IsCommand does not currently work - ConVar* cvar = g_pCVar->FindVar(command->m_pszName); - if (cvar) - spdlog::info("\"{}\" = \"{}\" {}- {}", cvar->GetBaseName(), cvar->GetString(), flagString, cvar->GetHelpText()); - else - spdlog::info("\"{}\" {} - {}", command->m_pszName, flagString, command->GetHelpText()); -} - -void ConCommand_help(const CCommand& arg) -{ - if (arg.ArgC() < 2) - { - spdlog::info("Usage: help "); - return; - } - - PrintCommandHelpDialogue(g_pCVar->FindCommandBase(arg.Arg(1)), arg.Arg(1)); -} - -void ConCommand_find(const CCommand& arg) -{ - if (arg.ArgC() < 2) - { - spdlog::info("Usage: find [...]"); - return; - } - - char pTempName[256]; - char pTempSearchTerm[256]; - - for (auto& map : g_pCVar->DumpToMap()) - { - bool bPrintCommand = true; - for (int i = 0; i < arg.ArgC() - 1; i++) - { - // make lowercase to avoid case sensitivity - strncpy(pTempName, map.second->m_pszName, sizeof(pTempName)); - strncpy(pTempSearchTerm, arg.Arg(i + 1), sizeof(pTempSearchTerm)); - - for (int i = 0; pTempName[i]; i++) - pTempName[i] = tolower(pTempName[i]); - - for (int i = 0; pTempSearchTerm[i]; i++) - pTempSearchTerm[i] = tolower(pTempSearchTerm[i]); - - if (!strstr(pTempName, pTempSearchTerm)) - { - bPrintCommand = false; - break; - } - } - - if (bPrintCommand) - PrintCommandHelpDialogue(map.second, map.second->m_pszName); - } -} - typedef void (*OnCommandSubmittedType)(CConsoleDialog* consoleDialog, const char* pCommand); OnCommandSubmittedType onCommandSubmittedOriginal; void OnCommandSubmittedHook(CConsoleDialog* consoleDialog, const char* pCommand) @@ -117,28 +34,7 @@ void OnCommandSubmittedHook(CConsoleDialog* consoleDialog, const char* pCommand) consoleDialog->m_pConsolePanel->Print(pCommand); consoleDialog->m_pConsolePanel->Print("\n"); - // try to display help text for this cvar - { - int pCommandLen = strlen(pCommand); - char* pCvarStr = new char[pCommandLen]; - strcpy(pCvarStr, pCommand); - - // trim whitespace from right - for (int i = pCommandLen - 1; i; i--) - { - if (isspace(pCvarStr[i])) - pCvarStr[i] = '\0'; - else - break; - } - - // check if we're inputting a cvar, but not setting it at all - ConVar* cvar = g_pCVar->FindVar(pCvarStr); - if (cvar) - PrintCommandHelpDialogue(&cvar->m_ConCommandBase, pCvarStr); - - delete[] pCvarStr; - } + TryPrintCvarHelpForCommand(pCommand); onCommandSubmittedOriginal(consoleDialog, pCommand); } @@ -162,8 +58,6 @@ void InitialiseConsoleOnInterfaceCreation() reinterpret_cast(&onCommandSubmittedOriginal)); } -// logging stuff - SourceConsoleSink::SourceConsoleSink() { logColours.emplace(spdlog::level::trace, SourceColor(0, 255, 255, 255)); @@ -194,11 +88,4 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", SourceConsole, ConCommand, [](HMODULE RegisterConCommand("toggleconsole", ConCommand_toggleconsole, "Show/hide the console.", FCVAR_DONTRECORD); RegisterConCommand("showconsole", ConCommand_showconsole, "Show the console.", FCVAR_DONTRECORD); RegisterConCommand("hideconsole", ConCommand_hideconsole, "Hide the console.", FCVAR_DONTRECORD); - RegisterConCommand("find", ConCommand_find, "Find concommands with the specified string in their name/help text.", FCVAR_NONE); - - // help is already a command, so we need to modify the preexisting command to use our func instead - // and clear the flags also - ConCommand* helpCommand = g_pCVar->FindCommand("help"); - helpCommand->m_nFlags = 0; - helpCommand->m_pCommandCallback = ConCommand_help; }) \ No newline at end of file -- cgit v1.2.3