From ac0c658516d8eaef2c788624f94e974ef47acbb8 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Mon, 29 Nov 2021 01:06:10 +0000 Subject: web browser changes and dedi fixes --- .../NorthstarDedicatedTest.vcxproj | 2 + .../NorthstarDedicatedTest.vcxproj.filters | 6 ++ NorthstarDedicatedTest/dedicated.cpp | 87 ++++++++++++++++++++-- NorthstarDedicatedTest/dedicated.h | 3 +- NorthstarDedicatedTest/dllmain.cpp | 3 + NorthstarDedicatedTest/gameutils.cpp | 11 +++ NorthstarDedicatedTest/gameutils.h | 7 ++ NorthstarDedicatedTest/masterserver.cpp | 4 +- NorthstarDedicatedTest/scriptbrowserhooks.cpp | 30 ++++++++ NorthstarDedicatedTest/scriptbrowserhooks.h | 3 + 10 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 NorthstarDedicatedTest/scriptbrowserhooks.cpp create mode 100644 NorthstarDedicatedTest/scriptbrowserhooks.h diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 9c48644d..2fa7ff1c 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -319,6 +319,7 @@ + @@ -357,6 +358,7 @@ + diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index 7572deb6..9a9c6b84 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -585,6 +585,9 @@ Header Files\Client + + Header Files\Client + @@ -683,6 +686,9 @@ Source Files\Client + + Source Files\Client + diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index cebcd8ad..b3c576ac 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -50,7 +50,7 @@ void RunServer(CDedicatedExports* dedicated) // set host state to allow us to enter CHostState::FrameUpdate, with the state HS_NEW_GAME g_pHostState->m_iNextState = HostState_t::HS_NEW_GAME; - strncpy(g_pHostState->m_levelName, CommandLine()->ParmValue("+map", "mp_lobby"), sizeof(g_pHostState->m_levelName)); // set map to load into + strncpy(g_pHostState->m_levelName, CommandLine()->ParmValue("+map", Cvar_match_defaultMap->m_pszString), sizeof(g_pHostState->m_levelName)); // set map to load into spdlog::info(CommandLine()->GetCmdLine()); @@ -64,7 +64,7 @@ void RunServer(CDedicatedExports* dedicated) maxPlayers = "6"; SetConsoleTitleA(fmt::format("Titanfall 2 dedicated server - {} {}/{} players", g_pHostState->m_levelName, g_ServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers).c_str()); - Sleep(50); + Sleep(1.0 / Cvar_base_tickinterval_mp->m_fValue); // currently only supports mp, doesnt really matter rn though since most sp levels crash on dedi } } @@ -278,6 +278,65 @@ void InitialiseDedicated(HMODULE engineAddress) *(ptr + 4) = (char)0x90; } + { + // func that checks if origin is inited + char* ptr = (char*)engineAddress + 0x183B70; + TempReadWrite rw(ptr); + + // always return 1 + *ptr = (char)0xB0; // mov al,01 + *(ptr + 1) = (char)0x01; + *(ptr + 2) = (char)0xC3; // ret + } + + { + // HostState_State_ChangeLevel + char* ptr = (char*)engineAddress + 0x1552ED; + TempReadWrite rw(ptr); + + // nop clientinterface call + *ptr = (char)0x90; + *(ptr + 1) = (char)0x90; + *(ptr + 2) = (char)0x90; + *(ptr + 3) = (char)0x90; + *(ptr + 4) = (char)0x90; + *(ptr + 5) = (char)0x90; + *(ptr + 6) = (char)0x90; + *(ptr + 7) = (char)0x90; + *(ptr + 8) = (char)0x90; + *(ptr + 9) = (char)0x90; + *(ptr + 10) = (char)0x90; + *(ptr + 11) = (char)0x90; + *(ptr + 12) = (char)0x90; + *(ptr + 13) = (char)0x90; + *(ptr + 14) = (char)0x90; + *(ptr + 15) = (char)0x90; + } + + { + // HostState_State_ChangeLevel + char* ptr = (char*)engineAddress + 0x155363; + TempReadWrite rw(ptr); + + // nop clientinterface call + *ptr = (char)0x90; + *(ptr + 1) = (char)0x90; + *(ptr + 2) = (char)0x90; + *(ptr + 3) = (char)0x90; + *(ptr + 4) = (char)0x90; + *(ptr + 5) = (char)0x90; + *(ptr + 6) = (char)0x90; + *(ptr + 7) = (char)0x90; + *(ptr + 8) = (char)0x90; + *(ptr + 9) = (char)0x90; + *(ptr + 10) = (char)0x90; + *(ptr + 11) = (char)0x90; + *(ptr + 12) = (char)0x90; + *(ptr + 13) = (char)0x90; + *(ptr + 14) = (char)0x90; + *(ptr + 15) = (char)0x90; + } + // stuff that disables renderer/window creation: unstable atm if (DisableDedicatedWindowCreation()) { @@ -407,13 +466,31 @@ void Tier0_InitOriginHook() // disable origin on dedicated // for any big ea lawyers, this can't be used to play the game without origin, game will throw a fit if you try to do anything without an origin id as a client // for dedi it's fine though, game doesn't care if origin is disabled as long as there's only a server - - if (!IsDedicated()) - Tier0_InitOrigin(); + Tier0_InitOrigin(); } void InitialiseDedicatedOrigin(HMODULE baseAddress) { + if (!IsDedicated()) + return; + HookEnabler hook; ENABLER_CREATEHOOK(hook, GetProcAddress(GetModuleHandleA("tier0.dll"), "Tier0_InitOrigin"), &Tier0_InitOriginHook, reinterpret_cast(&Tier0_InitOrigin)); +} + +typedef void(*PrintFatalSquirrelErrorType)(void* sqvm); +PrintFatalSquirrelErrorType PrintFatalSquirrelError; +void PrintFatalSquirrelErrorHook(void* sqvm) +{ + PrintFatalSquirrelError(sqvm); + abort(); +} + +void InitialiseDedicatedServerGameDLL(HMODULE baseAddress) +{ + if (!IsDedicated()) + return; + + HookEnabler hook; + ENABLER_CREATEHOOK(hook, baseAddress + 0x794D0, &PrintFatalSquirrelErrorHook, reinterpret_cast(&PrintFatalSquirrelError)); } \ No newline at end of file diff --git a/NorthstarDedicatedTest/dedicated.h b/NorthstarDedicatedTest/dedicated.h index 459f47ee..3b958203 100644 --- a/NorthstarDedicatedTest/dedicated.h +++ b/NorthstarDedicatedTest/dedicated.h @@ -4,4 +4,5 @@ bool IsDedicated(); bool DisableDedicatedWindowCreation(); void InitialiseDedicated(HMODULE moduleAddress); -void InitialiseDedicatedOrigin(HMODULE baseAddress); \ No newline at end of file +void InitialiseDedicatedOrigin(HMODULE baseAddress); +void InitialiseDedicatedServerGameDLL(HMODULE baseAddress); \ No newline at end of file diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp index dc1489e3..878800bd 100644 --- a/NorthstarDedicatedTest/dllmain.cpp +++ b/NorthstarDedicatedTest/dllmain.cpp @@ -22,6 +22,7 @@ #include "securitypatches.h" #include "miscserverscript.h" #include "clientauthhooks.h" +#include "scriptbrowserhooks.h" bool initialised = false; @@ -74,6 +75,7 @@ void InitialiseNorthstar() { AddDllLoadCallback("engine.dll", InitialiseDedicated); AddDllLoadCallback("launcher.dll", InitialiseDedicatedOrigin); + AddDllLoadCallback("server.dll", InitialiseDedicatedServerGameDLL); AddDllLoadCallback("materialsystem_dx11.dll", InitialiseDedicatedMaterialSystem); // this fucking sucks, but seemingly we somehow load after rtech_game???? unsure how, but because of this we have to apply patches here, not on rtech_game load AddDllLoadCallback("engine.dll", InitialiseDedicatedRtechGame); @@ -92,6 +94,7 @@ void InitialiseNorthstar() AddDllLoadCallback("client.dll", InitialiseScriptServerBrowser); AddDllLoadCallback("localize.dll", InitialiseModLocalisation); AddDllLoadCallback("engine.dll", InitialiseClientAuthHooks); + AddDllLoadCallback("engine.dll", InitialiseScriptExternalBrowserHooks); } AddDllLoadCallback("server.dll", InitialiseServerSquirrel); diff --git a/NorthstarDedicatedTest/gameutils.cpp b/NorthstarDedicatedTest/gameutils.cpp index adf13be7..2ad2821c 100644 --- a/NorthstarDedicatedTest/gameutils.cpp +++ b/NorthstarDedicatedTest/gameutils.cpp @@ -26,10 +26,17 @@ 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; + void InitialiseEngineGameUtilFunctions(HMODULE baseAddress) { Cbuf_GetCurrentPlayer = (Cbuf_GetCurrentPlayerType)((char*)baseAddress + 0x120630); @@ -48,9 +55,13 @@ void InitialiseEngineGameUtilFunctions(HMODULE baseAddress) g_LocalPlayerUserID = (char*)baseAddress + 0x13F8E688; g_LocalPlayerOriginToken = (char*)baseAddress + 0x13979C80; + + Cvar_match_defaultMap = (ConVar*)((char*)baseAddress + 0x8AB530); } void InitialiseServerGameUtilFunctions(HMODULE baseAddress) { Server_GetEntityByIndex = (Server_GetEntityByIndexType)((char*)baseAddress + 0xFB820); + Cvar_base_tickinterval_mp = (ConVar*)((char*)baseAddress + 0xBFC360); + Cvar_base_tickinterval_mp = (ConVar*)((char*)baseAddress + 0xBFBEA0); } \ No newline at end of file diff --git a/NorthstarDedicatedTest/gameutils.h b/NorthstarDedicatedTest/gameutils.h index 3970bfdb..5b0a04a5 100644 --- a/NorthstarDedicatedTest/gameutils.h +++ b/NorthstarDedicatedTest/gameutils.h @@ -185,9 +185,16 @@ 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; + void InitialiseEngineGameUtilFunctions(HMODULE baseAddress); void InitialiseServerGameUtilFunctions(HMODULE baseAddress); \ No newline at end of file diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index 43db66e7..e8b1e1d9 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -480,7 +480,7 @@ void MasterServerManager::AddSelfToServerList(int port, int authPort, char* name int currentModIndex = 0; for (Mod& mod : g_ModManager->m_loadedMods) { - if (!mod.RequiredOnClient && !mod.Pdiff.size()) + if (!mod.Enabled || (!mod.RequiredOnClient && !mod.Pdiff.size())) continue; modinfoDoc["Mods"].PushBack(rapidjson::Value(rapidjson::kObjectType), modinfoDoc.GetAllocator()); @@ -685,7 +685,7 @@ void CHostState__State_NewGameHook(CHostState* hostState) Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_server", cmd_source_t::kCommandSrcCode); Cbuf_Execute(); - // need to do this to ensure + // need to do this to ensure we don't go to private match if (g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame) SetCurrentPlaylist("tdm"); diff --git a/NorthstarDedicatedTest/scriptbrowserhooks.cpp b/NorthstarDedicatedTest/scriptbrowserhooks.cpp new file mode 100644 index 00000000..c5379da9 --- /dev/null +++ b/NorthstarDedicatedTest/scriptbrowserhooks.cpp @@ -0,0 +1,30 @@ +#include "pch.h" +#include "scriptbrowserhooks.h" +#include "hookutils.h" +#include "dedicated.h" + +typedef void(*OpenExternalWebBrowserType)(char* url, char flags); +OpenExternalWebBrowserType OpenExternalWebBrowser; + +bool* bIsOriginOverlayEnabled; + +void OpenExternalWebBrowserHook(char* url, char flags) +{ + bool bIsOriginOverlayEnabledOriginal = *bIsOriginOverlayEnabled; + if (flags & 2 && !strncmp(url, "http", 4)) // custom force external browser flag + *bIsOriginOverlayEnabled = false; // if this bool is false, game will use an external browser rather than the origin overlay one + + OpenExternalWebBrowser(url, flags); + *bIsOriginOverlayEnabled = bIsOriginOverlayEnabledOriginal; +} + +void InitialiseScriptExternalBrowserHooks(HMODULE baseAddress) +{ + if (IsDedicated()) + return; + + bIsOriginOverlayEnabled = (bool*)baseAddress + 0x13978255; + + HookEnabler hook; + ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x184E40, &OpenExternalWebBrowserHook, reinterpret_cast(&OpenExternalWebBrowser)); +} \ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptbrowserhooks.h b/NorthstarDedicatedTest/scriptbrowserhooks.h new file mode 100644 index 00000000..919cc92e --- /dev/null +++ b/NorthstarDedicatedTest/scriptbrowserhooks.h @@ -0,0 +1,3 @@ +#pragma once + +void InitialiseScriptExternalBrowserHooks(HMODULE baseAddress); \ No newline at end of file -- cgit v1.2.3