diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-09-26 01:24:13 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-09-26 01:24:13 +0100 |
commit | e98fc31a93dfc9a14db7bb5510d25df0226d6fd3 (patch) | |
tree | 0a14184023e46394ee7bc83846c4466f7e3f14c9 /NorthstarDedicatedTest | |
parent | f083706eb05a22ec166d8e29b565f93785ad3cb0 (diff) | |
download | NorthstarLauncher-e98fc31a93dfc9a14db7bb5510d25df0226d6fd3.tar.gz NorthstarLauncher-e98fc31a93dfc9a14db7bb5510d25df0226d6fd3.zip |
add CommandLine() and Cbuf_Execute
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r-- | NorthstarDedicatedTest/chatcommand.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/dedicated.cpp | 34 | ||||
-rw-r--r-- | NorthstarDedicatedTest/dedicatedmaterialsystem.cpp | 6 | ||||
-rw-r--r-- | NorthstarDedicatedTest/dllmain.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/gameutils.cpp | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/gameutils.h | 27 | ||||
-rw-r--r-- | NorthstarDedicatedTest/masterserver.cpp | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modlocalisation.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptmodmenu.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptserverbrowser.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/securitypatches.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/sourceconsole.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/squirrel.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/tier0.cpp | 10 | ||||
-rw-r--r-- | NorthstarDedicatedTest/tier0.h | 5 |
15 files changed, 91 insertions, 27 deletions
diff --git a/NorthstarDedicatedTest/chatcommand.cpp b/NorthstarDedicatedTest/chatcommand.cpp index 0009cf1c..c0f91e66 100644 --- a/NorthstarDedicatedTest/chatcommand.cpp +++ b/NorthstarDedicatedTest/chatcommand.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "chatcommand.h" #include "concommand.h" +#include "dedicated.h" // note: isIngameChat is an int64 because the whole register the arg is stored in needs to be 0'd out to work // if isIngameChat is false, we use network chat instead @@ -21,6 +22,9 @@ void ConCommand_say_team(const CCommand& args) void InitialiseChatCommands(HMODULE baseAddress) { + if (IsDedicated()) + return; + ClientSayText = (ClientSayTextType)((char*)baseAddress + 0x54780); RegisterConCommand("say", ConCommand_say, "Enters a message in public chat", FCVAR_CLIENTDLL); RegisterConCommand("say_team", ConCommand_say_team, "Enters a message in team chat", FCVAR_CLIENTDLL); diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 089ca467..01917f50 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -1,14 +1,14 @@ #include "pch.h" #include "dedicated.h" #include "hookutils.h" +#include "tier0.h" +#include "gameutils.h" #include <iostream> bool IsDedicated() { - // temp: should get this from commandline - //return true; - return false; + return CommandLine()->HasParm("-dedicated"); } enum EngineState_t @@ -47,26 +47,11 @@ enum HostState_t HS_RESTART, }; -struct CHostState -{ - HostState_t m_currentState; - HostState_t m_nextState; - - float m_vecLocationX; - float m_vecLocationY; - float m_vecLocationZ; - - float m_angLocationX; - float m_angLocationY; - float m_angLocationZ; - - char m_levelName[32]; - - // there's more stuff here, just this is all i use atm -}; - void InitialiseDedicated(HMODULE engineAddress) { + if (!IsDedicated()) + return; + spdlog::info("InitialiseDedicated"); //while (!IsDebuggerPresent()) @@ -231,6 +216,11 @@ void InitialiseDedicated(HMODULE engineAddress) // also look into launcher.dll+d381, seems to cause renderthread to get made // this crashes HARD if no window which makes sense tbh // also look into materialsystem + 5B344 since it seems to be the base of all the renderthread stuff + + // add cmdline args that are good for dedi + CommandLine()->AppendParm("-nomenuvid", 0); + CommandLine()->AppendParm("+host_preload_shaders", 0); + CommandLine()->AppendParm("-nosound", 0); } void Sys_Printf(CDedicatedExports* dedicated, char* msg) @@ -261,7 +251,7 @@ void RunServer(CDedicatedExports* dedicated) // set up engine and host states to allow us to enter CHostState::FrameUpdate, with the state HS_NEW_GAME cEnginePtr->m_nNextDllState = EngineState_t::DLL_ACTIVE; - cHostStatePtr->m_nextState = HostState_t::HS_NEW_GAME; + cHostStatePtr->m_iNextState = HostState_t::HS_NEW_GAME; strcpy(cHostStatePtr->m_levelName, "mp_lobby"); // set map to load into while (true) diff --git a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp index 93e0a0eb..48ade24d 100644 --- a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp +++ b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp @@ -1,16 +1,20 @@ #pragma once #include "pch.h" +#include "dedicated.h" #include "dedicatedmaterialsystem.h" #include "hookutils.h" void InitialiseDedicatedMaterialSystem(HMODULE baseAddress) { + if (!IsDedicated()) + return; + { // CMaterialSystem::FindMaterial char* ptr = (char*)baseAddress + 0x5F0F1; TempReadWrite rw(ptr); - // make the game use the error material + // make the game always use the error material *ptr = 0xE9; *(ptr + 1) = (char)0x34; *(ptr + 2) = (char)0x03; diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index 0a5eb388..3efe38c0 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -54,7 +54,7 @@ void InitialiseNorthstar() AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions); - if (IsDedicated()) + // dedi patches { AddDllLoadCallback("engine.dll", InitialiseDedicated); AddDllLoadCallback("materialsystem_dx11.dll", InitialiseDedicatedMaterialSystem); @@ -63,7 +63,7 @@ void InitialiseNorthstar() AddDllLoadCallback("engine.dll", InitialiseConVars); AddDllLoadCallback("engine.dll", InitialiseConCommands); - if (!IsDedicated()) + // client-exclusive patches { AddDllLoadCallback("engine.dll", InitialiseClientEngineSecurityPatches); AddDllLoadCallback("client.dll", InitialiseClientSquirrel); diff --git a/NorthstarDedicatedTest/gameutils.cpp b/NorthstarDedicatedTest/gameutils.cpp index add2639c..bf9ae3e5 100644 --- a/NorthstarDedicatedTest/gameutils.cpp +++ b/NorthstarDedicatedTest/gameutils.cpp @@ -6,6 +6,7 @@ // cmd.h Cbuf_GetCurrentPlayerType Cbuf_GetCurrentPlayer; Cbuf_AddTextType Cbuf_AddText; +Cbuf_ExecuteType Cbuf_Execute; // hoststate stuff CHostState* g_GameCHostStateSingleton; @@ -24,6 +25,7 @@ void InitialiseEngineGameUtilFunctions(HMODULE baseAddress) { Cbuf_GetCurrentPlayer = (Cbuf_GetCurrentPlayerType)((char*)baseAddress + 0x120630); Cbuf_AddText = (Cbuf_AddTextType)((char*)baseAddress + 0x1203B0); + Cbuf_Execute = (Cbuf_ExecuteType)((char*)baseAddress + 0x1204B0); g_GameCHostStateSingleton = (CHostState*)((char*)baseAddress + 0x7CF180); diff --git a/NorthstarDedicatedTest/gameutils.h b/NorthstarDedicatedTest/gameutils.h index b637dfa7..8db63fd7 100644 --- a/NorthstarDedicatedTest/gameutils.h +++ b/NorthstarDedicatedTest/gameutils.h @@ -55,6 +55,33 @@ extern Cbuf_GetCurrentPlayerType Cbuf_GetCurrentPlayer; typedef void(*Cbuf_AddTextType)(ECommandTarget_t eTarget, const char* text, cmd_source_t source); extern Cbuf_AddTextType Cbuf_AddText; +typedef void(*Cbuf_ExecuteType)(); +extern Cbuf_ExecuteType Cbuf_Execute; + +// commandline stuff +class CCommandLine +{ +public: + virtual void CreateCmdLine(const char* commandline) {} + virtual void CreateCmdLine(int argc, char** argv) {} + virtual const char* GetCmdLine(void) const {} + virtual const char* CheckParm(const char* psz, const char** ppszValue = 0) const {} + virtual bool HasParm(const char* psz) const {} + + virtual void RemoveParm() const {} + virtual void AppendParm(const char* pszParm, const char* pszValues) {} + + virtual int ParmCount() const {} + virtual int FindParm(const char* psz) const {} + virtual const char* GetParm(int nIndex) const {} + + virtual const char* ParmValue(const char* psz, const char* pDefaultVal = 0) const {} + virtual int ParmValue(const char* psz, int nDefaultVal) const {} + virtual float ParmValue(const char* psz, float flDefaultVal) const {} + virtual void SetParm(int nIndex, char const* pParm) {} + + virtual const char** GetParms() const {} +}; // hoststate stuff diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index d82be8f0..d7f966db 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -557,8 +557,8 @@ void ConCommand_ns_fetchservers(const CCommand& args) void CHostState__State_NewGameHook(CHostState* hostState) { - // not 100% we should do this here, but whatever Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_server", cmd_source_t::kCommandSrcCode); + Cbuf_Execute(); g_MasterServerManager->AddSelfToServerList(Cvar_hostport->m_nValue, Cvar_ns_player_auth_port->m_nValue, Cvar_ns_server_name->m_pszString, Cvar_ns_server_desc->m_pszString, hostState->m_levelName, (char*)GetCurrentPlaylistName(), 16, Cvar_ns_server_password->m_pszString); g_ServerAuthenticationManager->StartPlayerAuthServer(); diff --git a/NorthstarDedicatedTest/modlocalisation.cpp b/NorthstarDedicatedTest/modlocalisation.cpp index 25c9e19f..d8168d0c 100644 --- a/NorthstarDedicatedTest/modlocalisation.cpp +++ b/NorthstarDedicatedTest/modlocalisation.cpp @@ -2,6 +2,7 @@ #include "modlocalisation.h" #include "hookutils.h" #include "modmanager.h" +#include "dedicated.h" typedef bool(*AddLocalisationFileType)(void* g_pVguiLocalize, const char* path, const char* pathId, char unknown); AddLocalisationFileType AddLocalisationFile; @@ -31,6 +32,9 @@ bool AddLocalisationFileHook(void* g_pVguiLocalize, const char* path, const char void InitialiseModLocalisation(HMODULE baseAddress) { + if (IsDedicated()) + return; + HookEnabler hook; ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x6D80, AddLocalisationFileHook, reinterpret_cast<LPVOID*>(&AddLocalisationFile)); }
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp index cb19e48f..ca7d047d 100644 --- a/NorthstarDedicatedTest/scriptmodmenu.cpp +++ b/NorthstarDedicatedTest/scriptmodmenu.cpp @@ -2,6 +2,7 @@ #include "scriptmodmenu.h" #include "modmanager.h" #include "squirrel.h" +#include "dedicated.h" // array<string> NSGetModNames() SQInteger SQ_GetModNames(void* sqvm) @@ -122,6 +123,9 @@ SQInteger SQ_ReloadMods(void* sqvm) void InitialiseScriptModMenu(HMODULE baseAddress) { + if (IsDedicated()) + return; + g_UISquirrelManager->AddFuncRegistration("array<string>", "NSGetModNames", "", "Returns the names of all loaded mods", SQ_GetModNames); g_UISquirrelManager->AddFuncRegistration("string", "NSGetModDescriptionByModName", "string modName", "Returns a given mod's description", SQ_GetModDescription); g_UISquirrelManager->AddFuncRegistration("string", "NSGetModVersionByModName", "string modName", "Returns a given mod's version", SQ_GetModVersion); diff --git a/NorthstarDedicatedTest/scriptserverbrowser.cpp b/NorthstarDedicatedTest/scriptserverbrowser.cpp index 022aa582..588dff23 100644 --- a/NorthstarDedicatedTest/scriptserverbrowser.cpp +++ b/NorthstarDedicatedTest/scriptserverbrowser.cpp @@ -4,6 +4,7 @@ #include "masterserver.h" #include "gameutils.h" #include "serverauthentication.h" +#include "dedicated.h" // functions for viewing server browser @@ -242,6 +243,9 @@ SQInteger SQ_CompleteAuthWithLocalServer(void* sqvm) void InitialiseScriptServerBrowser(HMODULE baseAddress) { + if (IsDedicated()) + return; + g_UISquirrelManager->AddFuncRegistration("void", "NSRequestServerList", "", "", SQ_RequestServerList); g_UISquirrelManager->AddFuncRegistration("bool", "NSIsRequestingServerList", "", "", SQ_IsRequestingServerList); g_UISquirrelManager->AddFuncRegistration("bool", "NSMasterServerConnectionSuccessful", "", "", SQ_MasterServerConnectionSuccessful); diff --git a/NorthstarDedicatedTest/securitypatches.cpp b/NorthstarDedicatedTest/securitypatches.cpp index 23c96520..f13d778e 100644 --- a/NorthstarDedicatedTest/securitypatches.cpp +++ b/NorthstarDedicatedTest/securitypatches.cpp @@ -2,6 +2,7 @@ #include "securitypatches.h" #include "hookutils.h" #include "concommand.h" +#include "dedicated.h" typedef bool(*IsValveModType)(); IsValveModType IsValveMod; @@ -18,6 +19,9 @@ bool IsValveModHook() void InitialiseClientEngineSecurityPatches(HMODULE baseAddress) { + if (IsDedicated()) + return; + HookEnabler hook; // note: this could break some things diff --git a/NorthstarDedicatedTest/sourceconsole.cpp b/NorthstarDedicatedTest/sourceconsole.cpp index d5c7e347..64c6565c 100644 --- a/NorthstarDedicatedTest/sourceconsole.cpp +++ b/NorthstarDedicatedTest/sourceconsole.cpp @@ -3,6 +3,7 @@ #include "sourceinterface.h" #include "concommand.h" #include "hookutils.h" +#include "dedicated.h" SourceInterface<CGameConsole>* g_SourceGameConsole; @@ -52,6 +53,9 @@ void InitialiseConsoleOnInterfaceCreation() void InitialiseSourceConsole(HMODULE baseAddress) { + if (IsDedicated()) + return; + g_SourceGameConsole = new SourceInterface<CGameConsole>("client.dll", "GameConsole004"); RegisterConCommand("toggleconsole", ConCommand_toggleconsole, "toggles the console", FCVAR_NONE); } diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index 4aa8b3da..85e26c45 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -5,6 +5,7 @@ #include "sigscanning.h" #include "concommand.h" #include "modmanager.h" +#include "dedicated.h" #include <iostream> // hook forward declarations @@ -95,6 +96,9 @@ SQInteger NSTestFunc(void* sqvm) void InitialiseClientSquirrel(HMODULE baseAddress) { + if (IsDedicated()) + return; + HookEnabler hook; // client inits diff --git a/NorthstarDedicatedTest/tier0.cpp b/NorthstarDedicatedTest/tier0.cpp index 4b5234d0..bc1bbf46 100644 --- a/NorthstarDedicatedTest/tier0.cpp +++ b/NorthstarDedicatedTest/tier0.cpp @@ -55,6 +55,8 @@ void operator delete(void* p) throw() //(*alloc)->m_vtable->Free(*alloc, p); } +// honestly this all really sucks and should be reworked + typedef void(*Tier0Error)(const char* fmt, ...); void Error(const char* fmt, ...) { @@ -84,4 +86,12 @@ double Plat_FloatTime() return tier0Func(); else return 0.0f; +} + +typedef CCommandLine*(*Tier0CommandLine)(); +CCommandLine* CommandLine() +{ + Tier0CommandLine tier0Func = (Tier0CommandLine)ResolveTier0Function("CommandLine"); + + return tier0Func(); }
\ No newline at end of file diff --git a/NorthstarDedicatedTest/tier0.h b/NorthstarDedicatedTest/tier0.h index 07d91fe5..5375608c 100644 --- a/NorthstarDedicatedTest/tier0.h +++ b/NorthstarDedicatedTest/tier0.h @@ -1,5 +1,6 @@ #pragma once #include "pch.h" +#include "gameutils.h" // get exported tier0 by name void* ResolveTier0Function(const char* name); @@ -26,4 +27,6 @@ void operator delete(void* p) throw(); // would've liked to resolve these at compile time, but we load before tier0 so not really possible void Error(const char* fmt, ...); -double Plat_FloatTime();
\ No newline at end of file +double Plat_FloatTime(); + +CCommandLine* CommandLine();
\ No newline at end of file |