From 96aa95aede1fb1f3fde3d2c08728c37520bea4c2 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Tue, 15 Mar 2022 00:04:33 +0000 Subject: move to using g_pCVar more --- NorthstarDedicatedTest/clientchathooks.cpp | 4 +++ NorthstarDedicatedTest/dedicated.cpp | 5 +++- NorthstarDedicatedTest/filesystem.cpp | 1 - NorthstarDedicatedTest/gameutils.cpp | 16 ++--------- NorthstarDedicatedTest/gameutils.h | 8 ------ NorthstarDedicatedTest/logging.cpp | 2 +- NorthstarDedicatedTest/plugins.cpp | 38 ++++++++++++++----------- NorthstarDedicatedTest/securitypatches.cpp | 1 + NorthstarDedicatedTest/serverauthentication.cpp | 5 ++++ 9 files changed, 38 insertions(+), 42 deletions(-) (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/clientchathooks.cpp b/NorthstarDedicatedTest/clientchathooks.cpp index 74418c06..ca20b0dc 100644 --- a/NorthstarDedicatedTest/clientchathooks.cpp +++ b/NorthstarDedicatedTest/clientchathooks.cpp @@ -2,6 +2,7 @@ #include "clientchathooks.h" #include #include "squirrel.h" +#include "dedicated.h" #include "serverchathooks.h" #include "localchatwriter.h" @@ -86,6 +87,9 @@ static SQRESULT SQ_ChatWriteLine(void* sqvm) void InitialiseClientChatHooks(HMODULE baseAddress) { + if (IsDedicated()) + return; + HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x22E580, &CHudChat__AddGameLineHook, reinterpret_cast(&CHudChat__AddGameLine)); diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 35d45800..52d3802d 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -42,7 +42,7 @@ void RunServer(CDedicatedExports* dedicated) // add +map if not present // don't manually execute this from cbuf as users may have it in their startup args anyway, easier just to run from stuffcmds if present if (!CommandLine()->CheckParm("+map")) - CommandLine()->AppendParm("+map", Cvar_match_defaultMap->GetString()); + CommandLine()->AppendParm("+map", g_pCVar->FindVar("match_defaultMap")->GetString()); // run server autoexec and re-run commandline Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_server", cmd_source_t::kCommandSrcCode); @@ -55,6 +55,9 @@ void RunServer(CDedicatedExports* dedicated) // note: we no longer manually set map and hoststate to start server in g_pHostState, we just use +map which seems to initialise stuff // better + // get tickinterval + ConVar* Cvar_base_tickinterval_mp = g_pCVar->FindVar("base_tickinterval_mp"); + // main loop double frameTitle = 0; while (g_pEngine->m_nQuitting == EngineQuitState::QUIT_NOTQUITTING) diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp index 951198af..0fa14132 100644 --- a/NorthstarDedicatedTest/filesystem.cpp +++ b/NorthstarDedicatedTest/filesystem.cpp @@ -33,7 +33,6 @@ VPKData* MountVPKHook(IFileSystem* fileSystem, const char* vpkPath); bool readingOriginalFile; std::string currentModPath; SourceInterface* g_Filesystem; -void* g_pVGuiLocalize; void InitialiseFilesystem(HMODULE baseAddress) { diff --git a/NorthstarDedicatedTest/gameutils.cpp b/NorthstarDedicatedTest/gameutils.cpp index b8194397..792d8bf2 100644 --- a/NorthstarDedicatedTest/gameutils.cpp +++ b/NorthstarDedicatedTest/gameutils.cpp @@ -1,7 +1,6 @@ #include "pch.h" -#include "gameutils.h" #include "convar.h" -#include "concommand.h" +#include "gameutils.h" // memory IMemAlloc* g_pMemAllocSingleton; @@ -22,7 +21,6 @@ server_state_t* sv_m_State; // network stuff ConVar* Cvar_hostport; -ConVar* Cvar_net_datablock_enabled; // playlist stuff GetCurrentPlaylistType GetCurrentPlaylistName; @@ -33,17 +31,11 @@ GetCurrentPlaylistVarType GetCurrentPlaylistVar; // server entity stuff Server_GetEntityByIndexType Server_GetEntityByIndex; -// server tickrate stuff -ConVar* Cvar_base_tickinterval_mp; -ConVar* Cvar_base_tickinterval_sp; - // auth char* g_LocalPlayerUserID; char* g_LocalPlayerOriginToken; // misc stuff -ConVar* Cvar_match_defaultMap; -ConVar* Cvar_communities_hostname; ErrorType Error; CommandLineType CommandLine; Plat_FloatTimeType Plat_FloatTime; @@ -84,17 +76,13 @@ void InitialiseEngineGameUtilFunctions(HMODULE baseAddress) g_pAllConVars.push_back(pConVar); } }*/ + Cvar_hostport = (ConVar*)((char*)baseAddress + 0x13FA6070); - Cvar_net_datablock_enabled = (ConVar*)((char*)baseAddress + 0x12A4F6D0); - Cvar_match_defaultMap = (ConVar*)((char*)baseAddress + 0x8AB530); - Cvar_communities_hostname = (ConVar*)((char*)baseAddress + 0x13157E50); } void InitialiseServerGameUtilFunctions(HMODULE baseAddress) { Server_GetEntityByIndex = (Server_GetEntityByIndexType)((char*)baseAddress + 0xFB820); - Cvar_base_tickinterval_mp = (ConVar*)((char*)baseAddress + 0xBFC360); - Cvar_base_tickinterval_sp = (ConVar*)((char*)baseAddress + 0xBFBEA0); } void InitialiseTier0GameUtilFunctions(HMODULE baseAddress) diff --git a/NorthstarDedicatedTest/gameutils.h b/NorthstarDedicatedTest/gameutils.h index f382d6c0..d1ac8380 100644 --- a/NorthstarDedicatedTest/gameutils.h +++ b/NorthstarDedicatedTest/gameutils.h @@ -206,7 +206,6 @@ extern server_state_t* sv_m_State; // network stuff extern ConVar* Cvar_hostport; -extern ConVar* Cvar_net_datablock_enabled; // playlist stuff typedef const char* (*GetCurrentPlaylistType)(); @@ -225,18 +224,11 @@ extern GetCurrentPlaylistVarType GetCurrentPlaylistVar; typedef void* (*Server_GetEntityByIndexType)(int index); extern Server_GetEntityByIndexType Server_GetEntityByIndex; -// server tickrate stuff -extern ConVar* Cvar_base_tickinterval_mp; -extern ConVar* Cvar_base_tickinterval_sp; - // auth extern char* g_LocalPlayerUserID; extern char* g_LocalPlayerOriginToken; // misc stuff -extern ConVar* Cvar_match_defaultMap; -extern ConVar* Cvar_communities_hostname; - typedef void (*ErrorType)(const char* fmt, ...); extern ErrorType Error; diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp index 4d31981e..342c18ee 100644 --- a/NorthstarDedicatedTest/logging.cpp +++ b/NorthstarDedicatedTest/logging.cpp @@ -3,7 +3,7 @@ #include "sourceconsole.h" #include "spdlog/sinks/basic_file_sink.h" #include "hookutils.h" -#include "gameutils.h" +#include "convar.h" #include "dedicated.h" #include #include diff --git a/NorthstarDedicatedTest/plugins.cpp b/NorthstarDedicatedTest/plugins.cpp index 383555cf..b725a5a8 100644 --- a/NorthstarDedicatedTest/plugins.cpp +++ b/NorthstarDedicatedTest/plugins.cpp @@ -390,21 +390,25 @@ void InitialisePluginCommands(HMODULE baseAddress) // i swear there's a way to make this not have be run in 2 contexts but i can't figure it out // some funcs i need are just not available in UI or CLIENT - g_UISquirrelManager->AddFuncRegistration( - "void", "NSUpdateGameStateUI", "string gamemode, string gamemodeName, string map, string mapName, bool connected, bool loading", "", - SQ_UpdateGameStateUI); - g_ClientSquirrelManager->AddFuncRegistration( - "void", "NSUpdateGameStateClient", - "int playerCount, int outScore, int secondHighestScore, int highestScore, bool roundBased, int scoreLimit", "", - SQ_UpdateGameStateClient); - g_UISquirrelManager->AddFuncRegistration( - "void", "NSUpdateServerInfo", - "string id, string name, string password, int players, int maxPlayers, string map, string mapDisplayName, string playlist, string " - "playlistDisplayName", - "", SQ_UpdateServerInfo); - g_ClientSquirrelManager->AddFuncRegistration( - "void", "NSUpdateServerInfoReload", "int maxPlayers", "", SQ_UpdateServerInfoBetweenRounds); - g_ClientSquirrelManager->AddFuncRegistration("void", "NSUpdateTimeInfo", "float timeInFuture", "", SQ_UpdateTimeInfo); - g_UISquirrelManager->AddFuncRegistration("void", "NSSetLoading", "bool loading", "", SQ_SetConnected); - g_UISquirrelManager->AddFuncRegistration("void", "NSUpdateListenServer", "", "", SQ_UpdateListenServer); + if (g_UISquirrelManager && g_ClientSquirrelManager) + { + g_UISquirrelManager->AddFuncRegistration( + "void", "NSUpdateGameStateUI", "string gamemode, string gamemodeName, string map, string mapName, bool connected, bool loading", + "", SQ_UpdateGameStateUI); + g_ClientSquirrelManager->AddFuncRegistration( + "void", "NSUpdateGameStateClient", + "int playerCount, int outScore, int secondHighestScore, int highestScore, bool roundBased, int scoreLimit", "", + SQ_UpdateGameStateClient); + g_UISquirrelManager->AddFuncRegistration( + "void", "NSUpdateServerInfo", + "string id, string name, string password, int players, int maxPlayers, string map, string mapDisplayName, string playlist, " + "string " + "playlistDisplayName", + "", SQ_UpdateServerInfo); + g_ClientSquirrelManager->AddFuncRegistration( + "void", "NSUpdateServerInfoReload", "int maxPlayers", "", SQ_UpdateServerInfoBetweenRounds); + g_ClientSquirrelManager->AddFuncRegistration("void", "NSUpdateTimeInfo", "float timeInFuture", "", SQ_UpdateTimeInfo); + g_UISquirrelManager->AddFuncRegistration("void", "NSSetLoading", "bool loading", "", SQ_SetConnected); + g_UISquirrelManager->AddFuncRegistration("void", "NSUpdateListenServer", "", "", SQ_UpdateListenServer); + } } diff --git a/NorthstarDedicatedTest/securitypatches.cpp b/NorthstarDedicatedTest/securitypatches.cpp index 3531ffa5..e684738e 100644 --- a/NorthstarDedicatedTest/securitypatches.cpp +++ b/NorthstarDedicatedTest/securitypatches.cpp @@ -4,6 +4,7 @@ #include "concommand.h" #include "dedicated.h" #include "gameutils.h" +#include "convar.h" typedef bool (*IsValveModType)(); IsValveModType IsValveMod; diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index 84a2bbeb..26352675 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "serverauthentication.h" +#include "cvar.h" #include "convar.h" #include "hookutils.h" #include "masterserver.h" @@ -63,6 +64,8 @@ ConVar* Cvar_net_chan_limit_msec_per_sec; ConVar* Cvar_sv_querylimit_per_sec; ConVar* Cvar_sv_max_chat_messages_per_sec; +ConVar* Cvar_net_datablock_enabled; + void ServerAuthenticationManager::StartPlayerAuthServer() { if (m_runningPlayerAuthThread) @@ -596,6 +599,8 @@ void InitialiseServerAuthentication(HMODULE baseAddress) Cvar_sv_querylimit_per_sec = new ConVar("sv_querylimit_per_sec", "15", FCVAR_GAMEDLL, ""); Cvar_sv_max_chat_messages_per_sec = new ConVar("sv_max_chat_messages_per_sec", "5", FCVAR_GAMEDLL, ""); + Cvar_net_datablock_enabled = g_pCVar->FindVar("net_datablock_enabled"); + RegisterConCommand("ns_resetpersistence", ResetPdataCommand, "resets your pdata when you next enter the lobby", FCVAR_NONE); HookEnabler hook; -- cgit v1.2.3