From 39ace261942c71660b9ad9acbdf64d0211f2f851 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Sun, 26 Jan 2025 23:49:36 +0300 Subject: [PATCH] Make single link node pool unlimited --- Client/multiplayer_sa/CMultiplayerSA.cpp | 1 + Client/multiplayer_sa/CMultiplayerSA.h | 1 + .../CMultiplayerSA_SingleLinkNode.cpp | 58 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Client/multiplayer_sa/CMultiplayerSA_SingleLinkNode.cpp diff --git a/Client/multiplayer_sa/CMultiplayerSA.cpp b/Client/multiplayer_sa/CMultiplayerSA.cpp index f0cd566133..10dec7cce8 100644 --- a/Client/multiplayer_sa/CMultiplayerSA.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA.cpp @@ -1575,6 +1575,7 @@ void CMultiplayerSA::InitHooks() InitHooks_CrashFixHacks(); InitHooks_DeviceSelection(); + InitHooks_SingleLinkNode(); // Init our 1.3 hooks. Init_13(); diff --git a/Client/multiplayer_sa/CMultiplayerSA.h b/Client/multiplayer_sa/CMultiplayerSA.h index 0dd642cb4b..d8493b05a9 100644 --- a/Client/multiplayer_sa/CMultiplayerSA.h +++ b/Client/multiplayer_sa/CMultiplayerSA.h @@ -81,6 +81,7 @@ class CMultiplayerSA : public CMultiplayer void InitHooks_ObjectStreamerOptimization(); void InitHooks_Postprocess(); void InitHooks_DeviceSelection(); + void InitHooks_SingleLinkNode(); CRemoteDataStorage* CreateRemoteDataStorage(); void DestroyRemoteDataStorage(CRemoteDataStorage* pData); void AddRemoteDataStorage(CPlayerPed* pPed, CRemoteDataStorage* pData); diff --git a/Client/multiplayer_sa/CMultiplayerSA_SingleLinkNode.cpp b/Client/multiplayer_sa/CMultiplayerSA_SingleLinkNode.cpp new file mode 100644 index 0000000000..e43d800465 --- /dev/null +++ b/Client/multiplayer_sa/CMultiplayerSA_SingleLinkNode.cpp @@ -0,0 +1,58 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * FILE: multiplayer_sa/CMultiplayerSA_SingleLinkNode.cpp + * PORPOISE: Unlimites the SingleLinkNode pool + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#include "StdInc.h" + +constexpr std::size_t NODE_POOL_CAPACITY = 90000; +constexpr std::size_t NODE_POOL_SIZE_BYTES = NODE_POOL_CAPACITY * 8; + +constexpr std::uint32_t HOOKPOS_SingleLinkNodeConstructor = 0x5522A0; +constexpr std::size_t HOOKSIZE_SingleLinkNodeConstructor = 5; +static void _declspec(naked) HOOK_SingleLinkNodeConstructor() +{ + _asm { + push 0x8 + call malloc + add esp, 4 + pop edi + pop esi + ret + } +} + +constexpr std::uint32_t HOOKPOS_SingleLinkNodeDestructor = 0x552396; +constexpr std::size_t HOOKSIZE_SingleLinkNodeDestructor = 5; +static const std::uint32_t CONTINUE_SingleLinkNodeDestructor = 0x55239B; +static void _declspec(naked) HOOK_SingleLinkNodeDestructor() +{ + _asm { + mov eax, [esp+0x4] ; Node to delete + mov edx, [ecx] ; Pool objects array + cmp edx, eax + ja out_of_pool + add edx, NODE_POOL_SIZE_BYTES ; Pool end + cmp edx, eax + jb out_of_pool + push ebx ; original + jmp CONTINUE_SingleLinkNodeDestructor + out_of_pool: + push eax + call free + pop eax + retn + } +} + +void CMultiplayerSA::InitHooks_SingleLinkNode() +{ + EZHookInstall(SingleLinkNodeConstructor); + EZHookInstall(SingleLinkNodeDestructor); +}