From f9a97985da5d30cb67243837726a5d853648b3d6 Mon Sep 17 00:00:00 2001 From: uniboi <64006268+uniboi@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:01:36 +0000 Subject: [PATCH 1/9] plugins: Remove duplicate sqvm destroy log (#822) --- primedev/plugins/plugins.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/primedev/plugins/plugins.cpp b/primedev/plugins/plugins.cpp index f0a9c3c5f..92be9d5cf 100644 --- a/primedev/plugins/plugins.cpp +++ b/primedev/plugins/plugins.cpp @@ -219,7 +219,6 @@ void Plugin::OnSqvmCreated(CSquirrelVM* sqvm) const void Plugin::OnSqvmDestroying(CSquirrelVM* sqvm) const { - NS::log::PLUGINSYS->info("destroying sqvm {}", sqvm->vmContext); m_callbacks->OnSqvmDestroying(sqvm); } From 1f4765d4a82d2ae3a17f66330f30d16f2eab2be7 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 16 Sep 2024 17:47:32 +0100 Subject: [PATCH 2/9] dedicated: Remove uses of Autohook from `dedicated.cpp` (#799) Removes use of AUTOHOOK macro from dedicated.cpp --- primedev/dedicated/dedicated.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/primedev/dedicated/dedicated.cpp b/primedev/dedicated/dedicated.cpp index eca9b9f1f..8b0604fcf 100644 --- a/primedev/dedicated/dedicated.cpp +++ b/primedev/dedicated/dedicated.cpp @@ -8,8 +8,6 @@ #include "masterserver/masterserver.h" #include "util/printcommands.h" -AUTOHOOK_INIT() - bool IsDedicatedServer() { static bool result = strstr(GetCommandLineA(), "-dedicated"); @@ -114,10 +112,8 @@ DWORD WINAPI ConsoleInputThread(PVOID pThreadParameter) return 0; } -// clang-format off -AUTOHOOK(IsGameActiveWindow, engine.dll + 0x1CDC80, -bool,, ()) -// clang-format on +static bool (*o_pIsGameActiveWindow)() = nullptr; +static bool h_IsGameActiveWindow() { return true; } @@ -126,7 +122,8 @@ ON_DLL_LOAD_DEDI_RELIESON("engine.dll", DedicatedServer, ServerPresence, (CModul { spdlog::info("InitialiseDedicated"); - AUTOHOOK_DISPATCH_MODULE(engine.dll) + o_pIsGameActiveWindow = module.Offset(0x1CDC80).RCast(); + HookAttach(&(PVOID&)o_pIsGameActiveWindow, (PVOID)h_IsGameActiveWindow); // Host_Init // prevent a particle init that relies on client dll @@ -270,12 +267,10 @@ ON_DLL_LOAD_DEDI("tier0.dll", DedicatedServerOrigin, (CModule module)) module.GetExportedFunction("Tier0_InitOrigin").Patch("C3"); } -// clang-format off -AUTOHOOK(PrintSquirrelError, server.dll + 0x794D0, -void, __fastcall, (void* sqvm)) -// clang-format on +static void(__fastcall* o_pPrintSquirrelError)(void* sqvm) = nullptr; +static void __fastcall h_PrintSquirrelError(void* sqvm) { - PrintSquirrelError(sqvm); + o_pPrintSquirrelError(sqvm); // close dedicated server if a fatal error is hit // atm, this will crash if not aborted, so this just closes more gracefully @@ -289,7 +284,8 @@ void, __fastcall, (void* sqvm)) ON_DLL_LOAD_DEDI("server.dll", DedicatedServerGameDLL, (CModule module)) { - AUTOHOOK_DISPATCH_MODULE(server.dll) + o_pPrintSquirrelError = module.Offset(0x794D0).RCast(); + HookAttach(&(PVOID&)o_pPrintSquirrelError, (PVOID)h_PrintSquirrelError); if (CommandLine()->CheckParm("-nopakdedi")) { From ba485e9826c13a37945e06f3c00101ea16089266 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:08:47 +0100 Subject: [PATCH 3/9] dedicated: Remove uses of Autohook from `dedicatedmaterialsystem.cpp` (#800) Removes AUTOHOOK macro from dedicatedmaterialsystem.cpp --- .../dedicated/dedicatedmaterialsystem.cpp | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/primedev/dedicated/dedicatedmaterialsystem.cpp b/primedev/dedicated/dedicatedmaterialsystem.cpp index 010780862..f74cbfe39 100644 --- a/primedev/dedicated/dedicatedmaterialsystem.cpp +++ b/primedev/dedicated/dedicatedmaterialsystem.cpp @@ -1,11 +1,18 @@ #include "dedicated.h" #include "core/tier0.h" -AUTOHOOK_INIT() - -// clang-format off -AUTOHOOK(D3D11CreateDevice, materialsystem_dx11.dll + 0xD9A0E, -HRESULT, __stdcall, ( +static HRESULT(__stdcall* o_pD3D11CreateDevice)( + void* pAdapter, + int DriverType, + HMODULE Software, + UINT Flags, + int* pFeatureLevels, + UINT FeatureLevels, + UINT SDKVersion, + void** ppDevice, + int* pFeatureLevel, + void** ppImmediateContext) = nullptr; +static HRESULT __stdcall h_D3D11CreateDevice( void* pAdapter, int DriverType, HMODULE Software, @@ -15,8 +22,7 @@ HRESULT, __stdcall, ( UINT SDKVersion, void** ppDevice, int* pFeatureLevel, - void** ppImmediateContext)) -// clang-format on + void** ppImmediateContext) { // note: this is super duper temp pretty much just messing around with it // does run surprisingly well on dedi for a software driver tho if you ignore the +1gb ram usage at times, seems like dedi doesn't @@ -26,13 +32,14 @@ HRESULT, __stdcall, ( if (CommandLine()->CheckParm("-softwared3d11")) DriverType = 5; // D3D_DRIVER_TYPE_WARP - return D3D11CreateDevice( + return o_pD3D11CreateDevice( pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext); } ON_DLL_LOAD_DEDI("materialsystem_dx11.dll", DedicatedServerMaterialSystem, (CModule module)) { - AUTOHOOK_DISPATCH() + o_pD3D11CreateDevice = module.Offset(0xD9A0E).RCast(); + HookAttach(&(PVOID&)o_pD3D11CreateDevice, (PVOID)h_D3D11CreateDevice); // CMaterialSystem::FindMaterial // make the game always use the error material From 6737a344c012c0f7fd19cd593949dd3dbe5a0cb7 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:26:05 +0100 Subject: [PATCH 4/9] engine: Remove uses of Autohook from `hoststate.cpp` (#806) Removes use of AUTOHOOK macro from hoststate.cpp. --- primedev/engine/hoststate.cpp | 64 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/primedev/engine/hoststate.cpp b/primedev/engine/hoststate.cpp index d5942551a..4a4d909da 100644 --- a/primedev/engine/hoststate.cpp +++ b/primedev/engine/hoststate.cpp @@ -9,14 +9,12 @@ #include "squirrel/squirrel.h" #include "plugins/pluginmanager.h" -AUTOHOOK_INIT() - CHostState* g_pHostState; std::string sLastMode; -VAR_AT(engine.dll + 0x13FA6070, ConVar*, Cvar_hostport); -FUNCTION_AT(engine.dll + 0x1232C0, void, __fastcall, _Cmd_Exec_f, (const CCommand& arg, bool bOnlyIfExists, bool bUseWhitelists)); +static ConVar* Cvar_hostport = nullptr; +static void(__fastcall* _Cmd_Exec_f)(const CCommand& arg, bool bOnlyIfExists, bool bUseWhitelists) = nullptr; void ServerStartingOrChangingMap() { @@ -53,10 +51,8 @@ void ServerStartingOrChangingMap() g_pServerAuthentication->m_bStartingLocalSPGame = false; } -// clang-format off -AUTOHOOK(CHostState__State_NewGame, engine.dll + 0x16E7D0, -void, __fastcall, (CHostState* self)) -// clang-format on +static void(__fastcall* o_pCHostState__State_NewGame)(CHostState* self) = nullptr; +static void __fastcall h_CHostState__State_NewGame(CHostState* self) { spdlog::info("HostState: NewGame"); @@ -70,7 +66,7 @@ void, __fastcall, (CHostState* self)) ServerStartingOrChangingMap(); double dStartTime = Plat_FloatTime(); - CHostState__State_NewGame(self); + o_pCHostState__State_NewGame(self); spdlog::info("loading took {}s", Plat_FloatTime() - dStartTime); // setup server presence @@ -82,10 +78,8 @@ void, __fastcall, (CHostState* self)) g_pServerAuthentication->m_bNeedLocalAuthForNewgame = false; } -// clang-format off -AUTOHOOK(CHostState__State_LoadGame, engine.dll + 0x16E730, -void, __fastcall, (CHostState* self)) -// clang-format on +static void(__fastcall* o_pCHostState__State_LoadGame)(CHostState* self) = nullptr; +static void __fastcall h_CHostState__State_LoadGame(CHostState* self) { // singleplayer server starting // useless in 99% of cases but without it things could potentially break very much @@ -100,7 +94,7 @@ void, __fastcall, (CHostState* self)) g_pServerAuthentication->m_bStartingLocalSPGame = true; double dStartTime = Plat_FloatTime(); - CHostState__State_LoadGame(self); + o_pCHostState__State_LoadGame(self); spdlog::info("loading took {}s", Plat_FloatTime() - dStartTime); // no server presence, can't do it because no map name in hoststate @@ -109,32 +103,28 @@ void, __fastcall, (CHostState* self)) g_pServerAuthentication->m_bNeedLocalAuthForNewgame = false; } -// clang-format off -AUTOHOOK(CHostState__State_ChangeLevelMP, engine.dll + 0x16E520, -void, __fastcall, (CHostState* self)) -// clang-format on +static void(__fastcall* o_pCHostState__State_ChangeLevelMP)(CHostState* self) = nullptr; +static void __fastcall h_CHostState__State_ChangeLevelMP(CHostState* self) { spdlog::info("HostState: ChangeLevelMP"); ServerStartingOrChangingMap(); double dStartTime = Plat_FloatTime(); - CHostState__State_ChangeLevelMP(self); + o_pCHostState__State_ChangeLevelMP(self); spdlog::info("loading took {}s", Plat_FloatTime() - dStartTime); g_pServerPresence->SetMap(g_pHostState->m_levelName); } -// clang-format off -AUTOHOOK(CHostState__State_GameShutdown, engine.dll + 0x16E640, -void, __fastcall, (CHostState* self)) -// clang-format on +static void(__fastcall* o_pCHostState__State_GameShutdown)(CHostState* self) = nullptr; +static void __fastcall h_CHostState__State_GameShutdown(CHostState* self) { spdlog::info("HostState: GameShutdown"); g_pServerPresence->DestroyPresence(); - CHostState__State_GameShutdown(self); + o_pCHostState__State_GameShutdown(self); // run gamemode cleanup cfg now instead of when we start next map if (sLastMode.length()) @@ -153,12 +143,10 @@ void, __fastcall, (CHostState* self)) } } -// clang-format off -AUTOHOOK(CHostState__FrameUpdate, engine.dll + 0x16DB00, -void, __fastcall, (CHostState* self, double flCurrentTime, float flFrameTime)) -// clang-format on +static void(__fastcall* o_pCHostState__FrameUpdate)(CHostState* self, double flCurrentTime, float flFrameTime) = nullptr; +static void __fastcall h_CHostState__FrameUpdate(CHostState* self, double flCurrentTime, float flFrameTime) { - CHostState__FrameUpdate(self, flCurrentTime, flFrameTime); + o_pCHostState__FrameUpdate(self, flCurrentTime, flFrameTime); if (*g_pServerState == server_state_t::ss_active) { @@ -184,7 +172,23 @@ void, __fastcall, (CHostState* self, double flCurrentTime, float flFrameTime)) ON_DLL_LOAD_RELIESON("engine.dll", HostState, ConVar, (CModule module)) { - AUTOHOOK_DISPATCH() + o_pCHostState__State_NewGame = module.Offset(0x16E7D0).RCast(); + HookAttach(&(PVOID&)o_pCHostState__State_NewGame, (PVOID)h_CHostState__State_NewGame); + + o_pCHostState__State_LoadGame = module.Offset(0x16E730).RCast(); + HookAttach(&(PVOID&)o_pCHostState__State_LoadGame, (PVOID)h_CHostState__State_LoadGame); + + o_pCHostState__State_ChangeLevelMP = module.Offset(0x16E520).RCast(); + HookAttach(&(PVOID&)o_pCHostState__State_ChangeLevelMP, (PVOID)h_CHostState__State_ChangeLevelMP); + + o_pCHostState__State_GameShutdown = module.Offset(0x16E640).RCast(); + HookAttach(&(PVOID&)o_pCHostState__State_GameShutdown, (PVOID)h_CHostState__State_GameShutdown); + + o_pCHostState__FrameUpdate = module.Offset(0x16DB00).RCast(); + HookAttach(&(PVOID&)o_pCHostState__FrameUpdate, (PVOID)h_CHostState__FrameUpdate); + + Cvar_hostport = module.Offset(0x13FA6070).RCast(); + _Cmd_Exec_f = module.Offset(0x1232C0).RCast(); g_pHostState = module.Offset(0x7CF180).RCast(); } From 71349f05b69923dbf091d27f8e256bcc3022e859 Mon Sep 17 00:00:00 2001 From: Gazyi Date: Tue, 1 Oct 2024 15:28:58 +0300 Subject: [PATCH 5/9] Force `_WIN32_WINNT` variable (#770) to avoid instant crashes on older Windows platforms. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9646ae10..c9516e521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,3 +50,7 @@ include_directories(primedev/thirdparty) # Targets add_subdirectory(primedev) +# Forces Minizip to not use functions that are not available in Win 7 libraries. +if(WIN32) + target_compile_definitions(minizip PUBLIC -D_WIN32_WINNT=0x0601) +endif() From 8a29c5bbd05cf52007a8aa3ff833c8fed237a625 Mon Sep 17 00:00:00 2001 From: F1F7Y <64418963+F1F7Y@users.noreply.github.com> Date: Sun, 6 Oct 2024 09:59:22 +0200 Subject: [PATCH 6/9] core: Remove unused SourceInterface class (#816) Removes unused `SourceInterface` class, moves `InterfaceStatus` enum to `tier1.h`. --- primedev/Northstar.cmake | 1 - primedev/core/convar/convar.h | 1 - primedev/core/sourceinterface.cpp | 1 - primedev/core/sourceinterface.h | 32 ----------------------- primedev/core/tier1.h | 6 +++++ primedev/logging/sourceconsole.h | 1 - primedev/plugins/interfaces/interface.cpp | 1 + primedev/plugins/interfaces/sys/ISys.cpp | 1 + primedev/plugins/plugins.cpp | 1 - primedev/plugins/plugins.h | 2 +- 10 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 primedev/core/sourceinterface.h diff --git a/primedev/Northstar.cmake b/primedev/Northstar.cmake index 4e8ec973b..35383e69c 100644 --- a/primedev/Northstar.cmake +++ b/primedev/Northstar.cmake @@ -52,7 +52,6 @@ add_library( "core/memalloc.cpp" "core/memalloc.h" "core/sourceinterface.cpp" - "core/sourceinterface.h" "core/tier0.cpp" "core/tier0.h" "core/tier1.cpp" diff --git a/primedev/core/convar/convar.h b/primedev/core/convar/convar.h index f0366b466..33a50c1c4 100644 --- a/primedev/core/convar/convar.h +++ b/primedev/core/convar/convar.h @@ -1,5 +1,4 @@ #pragma once -#include "core/sourceinterface.h" #include "core/math/color.h" #include "cvar.h" #include "concommand.h" diff --git a/primedev/core/sourceinterface.cpp b/primedev/core/sourceinterface.cpp index 74e4a9963..7ce339255 100644 --- a/primedev/core/sourceinterface.cpp +++ b/primedev/core/sourceinterface.cpp @@ -1,4 +1,3 @@ -#include "sourceinterface.h" #include "logging/sourceconsole.h" // really wanted to do a modular callback system here but honestly couldn't be bothered so hardcoding stuff for now: todo later diff --git a/primedev/core/sourceinterface.h b/primedev/core/sourceinterface.h deleted file mode 100644 index 730339daa..000000000 --- a/primedev/core/sourceinterface.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include - -// interface return status -enum class InterfaceStatus : int -{ - IFACE_OK = 0, - IFACE_FAILED, -}; - -// literally just copied from ttf2sdk definition -typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode); - -template class SourceInterface -{ -private: - T* m_interface; - -public: - SourceInterface(const std::string& moduleName, const std::string& interfaceName) - { - HMODULE handle = GetModuleHandleA(moduleName.c_str()); - CreateInterfaceFn createInterface = (CreateInterfaceFn)GetProcAddress(handle, "CreateInterface"); - m_interface = (T*)createInterface(interfaceName.c_str(), NULL); - if (m_interface == nullptr) - spdlog::error("Failed to call CreateInterface for %s in %s", interfaceName, moduleName); - } - - T* operator->() const { return m_interface; } - - operator T*() const { return m_interface; } -}; diff --git a/primedev/core/tier1.h b/primedev/core/tier1.h index d162e7c84..36f577cc2 100644 --- a/primedev/core/tier1.h +++ b/primedev/core/tier1.h @@ -7,6 +7,12 @@ #define CREATEINTERFACE_PROCNAME "CreateInterface" +enum class InterfaceStatus : int +{ + IFACE_OK = 0, + IFACE_FAILED, +}; + typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode); CMemory Sys_GetFactoryPtr(const std::string& svModuleName, const std::string& svFact); diff --git a/primedev/logging/sourceconsole.h b/primedev/logging/sourceconsole.h index 35cc1723c..8c647fb42 100644 --- a/primedev/logging/sourceconsole.h +++ b/primedev/logging/sourceconsole.h @@ -1,5 +1,4 @@ #pragma once -#include "core/sourceinterface.h" #include "spdlog/sinks/base_sink.h" #include diff --git a/primedev/plugins/interfaces/interface.cpp b/primedev/plugins/interfaces/interface.cpp index bc9005421..e82005604 100644 --- a/primedev/plugins/interfaces/interface.cpp +++ b/primedev/plugins/interfaces/interface.cpp @@ -1,4 +1,5 @@ #include +#include "core/tier1.h" #include "interface.h" InterfaceReg* s_pInterfaceRegs; diff --git a/primedev/plugins/interfaces/sys/ISys.cpp b/primedev/plugins/interfaces/sys/ISys.cpp index 6b0b41ddf..948e7d90b 100644 --- a/primedev/plugins/interfaces/sys/ISys.cpp +++ b/primedev/plugins/interfaces/sys/ISys.cpp @@ -1,3 +1,4 @@ +#include "core/tier1.h" #include "plugins/interfaces/interface.h" #include "ISys.h" #include "plugins/plugins.h" diff --git a/primedev/plugins/plugins.cpp b/primedev/plugins/plugins.cpp index 92be9d5cf..21169c061 100644 --- a/primedev/plugins/plugins.cpp +++ b/primedev/plugins/plugins.cpp @@ -2,7 +2,6 @@ #include "pluginmanager.h" #include "squirrel/squirrel.h" #include "util/wininfo.h" -#include "core/sourceinterface.h" #include "logging/logging.h" #include "dedicated/dedicated.h" diff --git a/primedev/plugins/plugins.h b/primedev/plugins/plugins.h index d004038c4..71e184c7c 100644 --- a/primedev/plugins/plugins.h +++ b/primedev/plugins/plugins.h @@ -1,5 +1,5 @@ #pragma once -#include "core/sourceinterface.h" +#include "core/tier1.h" #include "plugins/interfaces/interface.h" #include "plugins/interfaces/IPluginId.h" #include "plugins/interfaces/IPluginCallbacks.h" From 42d97028e1a474e7fecc1de7e76c5d92ecf2c28f Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sun, 6 Oct 2024 17:01:50 +0100 Subject: [PATCH 7/9] Fix rpak aliasing not working when trying to alias towards a vanilla rpak (#825) Replace incorrect variable with hardcoded `-1` Don't account for the modded path in pak aliases --- primedev/core/filesystem/rpakfilesystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/primedev/core/filesystem/rpakfilesystem.cpp b/primedev/core/filesystem/rpakfilesystem.cpp index ebb9085a7..c3e5e74ee 100644 --- a/primedev/core/filesystem/rpakfilesystem.cpp +++ b/primedev/core/filesystem/rpakfilesystem.cpp @@ -342,7 +342,7 @@ void PakLoadManager::UnloadDependentPaks(PakHandle handle) static void HandlePakAliases(std::string& originalPath) { // convert the pak being loaded to its aliased one, e.g. aliasing mp_hub_timeshift => sp_hub_timeshift - for (int64_t i = g_pModManager->m_LoadedMods.size() - 1; i > PakHandle::INVALID; i--) + for (int64_t i = g_pModManager->m_LoadedMods.size() - 1; i > -1; i--) { Mod* mod = &g_pModManager->m_LoadedMods[i]; if (!mod->m_bEnabled) @@ -350,7 +350,7 @@ static void HandlePakAliases(std::string& originalPath) if (mod->RpakAliases.find(originalPath) != mod->RpakAliases.end()) { - originalPath = (mod->m_ModDirectory / "paks" / mod->RpakAliases[originalPath]).string(); + originalPath = mod->RpakAliases[originalPath]; return; } } From 27e17113161323b5a6269d395dbcc04162f50319 Mon Sep 17 00:00:00 2001 From: uniboi <64006268+uniboi@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:20:54 +0000 Subject: [PATCH 8/9] plugins: Allow plugins to customize their log colors (#823) Allows plugins to specify a custom colour for their indicator in the logs --- primedev/plugins/interfaces/IPluginId.h | 1 + primedev/plugins/plugins.cpp | 10 +++++++++- primedev/plugins/plugins.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/primedev/plugins/interfaces/IPluginId.h b/primedev/plugins/interfaces/IPluginId.h index dc4c548b3..0b025224b 100644 --- a/primedev/plugins/interfaces/IPluginId.h +++ b/primedev/plugins/interfaces/IPluginId.h @@ -18,6 +18,7 @@ enum class PluginString : int enum class PluginField : int { CONTEXT = 0, + COLOR = 1, }; // an interface that is required from every plugin to query data about it diff --git a/primedev/plugins/plugins.cpp b/primedev/plugins/plugins.cpp index 21169c061..3e6231676 100644 --- a/primedev/plugins/plugins.cpp +++ b/primedev/plugins/plugins.cpp @@ -23,6 +23,7 @@ bool isValidSquirrelIdentifier(std::string s) Plugin::Plugin(std::string path) : m_location(path) + , m_logColor(NS::Colors::PLUGIN) { HMODULE pluginModule = GetModuleHandleA(path.c_str()); @@ -69,6 +70,13 @@ Plugin::Plugin(std::string path) m_runOnServer = context & PluginContext::DEDICATED; m_runOnClient = context & PluginContext::CLIENT; + int64_t logColor = m_pluginId->GetField(PluginField::COLOR); + // Apply custom colour if plugin has specified one + if ((logColor & 0xFFFFFF) != 0) + { + m_logColor = Color((int)(logColor & 0xFF), (int)((logColor >> 8) & 0xFF), (int)((logColor >> 16) & 0xFF)); + } + if (!name) { NS::log::PLUGINSYS->error("Could not load name of plugin at '{}'", path); @@ -105,7 +113,7 @@ Plugin::Plugin(std::string path) return; } - m_logger = std::make_shared(m_logName, NS::Colors::PLUGIN); + m_logger = std::make_shared(m_logName, m_logColor); RegisterLogger(m_logger); if (IsDedicatedServer() && !m_runOnServer) diff --git a/primedev/plugins/plugins.h b/primedev/plugins/plugins.h index 71e184c7c..95ec08b5c 100644 --- a/primedev/plugins/plugins.h +++ b/primedev/plugins/plugins.h @@ -20,6 +20,7 @@ class Plugin std::string m_location; // path of the dll bool m_runOnServer; bool m_runOnClient; + Color m_logColor; public: HMODULE m_handle; From 41583e4f690686095e728d61bb13b4526b29a69e Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:15:40 +0000 Subject: [PATCH 9/9] server: Remove uses of Autohook from `serverauthentication.cpp` (#820) Manually hook - `CBaseServer__ConnectClient` - `CBaseClient__Connect` - `CBaseClient__ActivatePlayer` - `CBaseClient__Disconnect` Remove `AUTOHOOK_INIT` and `AUTOHOOK_DISPATCH` --- primedev/server/auth/serverauthentication.cpp | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/primedev/server/auth/serverauthentication.cpp b/primedev/server/auth/serverauthentication.cpp index d0d4c698f..58268bcfa 100644 --- a/primedev/server/auth/serverauthentication.cpp +++ b/primedev/server/auth/serverauthentication.cpp @@ -19,8 +19,6 @@ #include #include -AUTOHOOK_INIT() - // global vars ServerAuthenticationManager* g_pServerAuthentication; CBaseServer__RejectConnectionType CBaseServer__RejectConnection; @@ -207,9 +205,25 @@ void ServerAuthenticationManager::WritePersistentData(CBaseClient* pPlayer) char* pNextPlayerToken; uint64_t iNextPlayerUid; -// clang-format off -AUTOHOOK(CBaseServer__ConnectClient, engine.dll + 0x114430, -void*,, ( +static void* (*o_pCBaseServer__ConnectClient)( + void* self, + void* addr, + void* a3, + uint32_t a4, + uint32_t a5, + int32_t a6, + void* a7, + char* playerName, + char* serverFilter, + void* a10, + char a11, + void* a12, + char a13, + char a14, + int64_t uid, + uint32_t a16, + uint32_t a17) = nullptr; +static void* h_CBaseServer__ConnectClient( void* self, void* addr, void* a3, @@ -226,22 +240,21 @@ void*,, ( char a14, int64_t uid, uint32_t a16, - uint32_t a17)) -// clang-format on + uint32_t a17) { // auth tokens are sent with serverfilter, can't be accessed from player struct to my knowledge, so have to do this here pNextPlayerToken = serverFilter; iNextPlayerUid = uid; - return CBaseServer__ConnectClient(self, addr, a3, a4, a5, a6, a7, playerName, serverFilter, a10, a11, a12, a13, a14, uid, a16, a17); + return o_pCBaseServer__ConnectClient(self, addr, a3, a4, a5, a6, a7, playerName, serverFilter, a10, a11, a12, a13, a14, uid, a16, a17); } ConVar* Cvar_ns_allowuserclantags; -// clang-format off -AUTOHOOK(CBaseClient__Connect, engine.dll + 0x101740, -bool,, (CBaseClient* self, char* pName, void* pNetChannel, char bFakePlayer, void* a5, char pDisconnectReason[256], void* a7)) -// clang-format on +static bool (*o_pCBaseClient__Connect)( + CBaseClient* self, char* pName, void* pNetChannel, char bFakePlayer, void* a5, char pDisconnectReason[256], void* a7) = nullptr; +static bool +h_CBaseClient__Connect(CBaseClient* self, char* pName, void* pNetChannel, char bFakePlayer, void* a5, char pDisconnectReason[256], void* a7) { const char* pAuthenticationFailure = nullptr; char pVerifiedName[64]; @@ -267,7 +280,7 @@ bool,, (CBaseClient* self, char* pName, void* pNetChannel, char bFakePlayer, voi } // try to actually connect the player - if (!CBaseClient__Connect(self, pVerifiedName, pNetChannel, bFakePlayer, a5, pDisconnectReason, a7)) + if (!o_pCBaseClient__Connect(self, pVerifiedName, pNetChannel, bFakePlayer, a5, pDisconnectReason, a7)) return false; // we already know this player's authentication data is legit, actually write it to them now @@ -279,10 +292,8 @@ bool,, (CBaseClient* self, char* pName, void* pNetChannel, char bFakePlayer, voi return true; } -// clang-format off -AUTOHOOK(CBaseClient__ActivatePlayer, engine.dll + 0x100F80, -void,, (CBaseClient* self)) -// clang-format on +static void (*o_pCBaseClient__ActivatePlayer)(CBaseClient* self) = nullptr; +static void h_CBaseClient__ActivatePlayer(CBaseClient* self) { // if we're authed, write our persistent data // RemovePlayerAuthData returns true if it removed successfully, i.e. on first call only, and we only want to write on >= second call @@ -294,13 +305,11 @@ void,, (CBaseClient* self)) g_pServerPresence->SetPlayerCount((int)g_pServerAuthentication->m_PlayerAuthenticationData.size()); } - CBaseClient__ActivatePlayer(self); + o_pCBaseClient__ActivatePlayer(self); } -// clang-format off -AUTOHOOK(_CBaseClient__Disconnect, engine.dll + 0x1012C0, -void,, (CBaseClient* self, uint32_t unknownButAlways1, const char* pReason, ...)) -// clang-format on +static void (*o_pCBaseClient__Disconnect)(CBaseClient* self, uint32_t unknownButAlways1, const char* pReason, ...) = nullptr; +static void h_CBaseClient__Disconnect(CBaseClient* self, uint32_t unknownButAlways1, const char* pReason, ...) { // have to manually format message because can't pass varargs to original func char buf[1024]; @@ -328,7 +337,7 @@ void,, (CBaseClient* self, uint32_t unknownButAlways1, const char* pReason, ...) g_pServerPresence->SetPlayerCount((int)g_pServerAuthentication->m_PlayerAuthenticationData.size()); - _CBaseClient__Disconnect(self, unknownButAlways1, buf); + o_pCBaseClient__Disconnect(self, unknownButAlways1, buf); } void ConCommand_ns_resetpersistence(const CCommand& args) @@ -346,7 +355,17 @@ void ConCommand_ns_resetpersistence(const CCommand& args) ON_DLL_LOAD_RELIESON("engine.dll", ServerAuthentication, (ConCommand, ConVar), (CModule module)) { - AUTOHOOK_DISPATCH() + o_pCBaseServer__ConnectClient = module.Offset(0x114430).RCast(); + HookAttach(&(PVOID&)o_pCBaseServer__ConnectClient, (PVOID)h_CBaseServer__ConnectClient); + + o_pCBaseClient__Connect = module.Offset(0x101740).RCast(); + HookAttach(&(PVOID&)o_pCBaseClient__Connect, (PVOID)h_CBaseClient__Connect); + + o_pCBaseClient__ActivatePlayer = module.Offset(0x100F80).RCast(); + HookAttach(&(PVOID&)o_pCBaseClient__ActivatePlayer, (PVOID)h_CBaseClient__ActivatePlayer); + + o_pCBaseClient__Disconnect = module.Offset(0x1012C0).RCast(); + HookAttach(&(PVOID&)o_pCBaseClient__Disconnect, (PVOID)h_CBaseClient__Disconnect); g_pServerAuthentication = new ServerAuthenticationManager;