diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 62e3cc4440..cf775a55ee 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -743,7 +743,7 @@ CBoundingBox* CModelInfoSA::GetBoundingBox() bool CModelInfoSA::IsValid() { if (m_dwModelID >= MODELINFO_DFF_MAX && m_dwModelID < MODELINFO_TXD_MAX) - return !pGame->GetPools()->IsFreeTextureDictonarySlot(m_dwModelID - MODELINFO_DFF_MAX); + return !pGame->GetPools()->GetTxdPool().IsFreeTextureDictonarySlot(m_dwModelID - MODELINFO_DFF_MAX); if (m_dwModelID >= pGame->GetBaseIDforTXD() && m_dwModelID < pGame->GetCountOfAllFileIDs()) return true; diff --git a/Client/game_sa/CPoolsSA.cpp b/Client/game_sa/CPoolsSA.cpp index 42c534dcaa..1aaac0b40d 100644 --- a/Client/game_sa/CPoolsSA.cpp +++ b/Client/game_sa/CPoolsSA.cpp @@ -24,9 +24,6 @@ #include "CTrailerSA.h" #include "CTrainSA.h" #include "CWorldSA.h" -#include "CKeyGenSA.h" -#include "CFileLoaderSA.h" -#include "CPtrNodeSingleListSA.h" extern CGameSA* pGame; @@ -35,7 +32,6 @@ CPoolsSA::CPoolsSA() m_ppPedPoolInterface = (CPoolSAInterface**)0xB74490; m_ppObjectPoolInterface = (CPoolSAInterface**)0xB7449C; m_ppVehiclePoolInterface = (CPoolSAInterface**)0xB74494; - m_ppTxdPoolInterface = (CPoolSAInterface**)0xC8800C; m_bGetVehicleEnabled = true; } @@ -1107,40 +1103,3 @@ void CPoolsSA::InvalidateLocalPlayerClientEntity() { m_pedPool.arrayOfClientEntities[0] = {m_pedPool.arrayOfClientEntities[0].pEntity, nullptr}; } - -unsigned int CPoolsSA::AllocateTextureDictonarySlot(uint uiSlotId, std::string& strTxdName) -{ - CTextureDictonarySAInterface* pTxd = (*m_ppTxdPoolInterface)->AllocateAt(uiSlotId); - if (!pTxd) - return -1; - - strTxdName.resize(24); - - pTxd->usUsagesCount = 0; - pTxd->hash = pGame->GetKeyGen()->GetUppercaseKey(strTxdName.c_str()); - pTxd->rwTexDictonary = nullptr; - pTxd->usParentIndex = -1; - - return (*m_ppTxdPoolInterface)->GetObjectIndex(pTxd); -} - -void CPoolsSA::RemoveTextureDictonarySlot(uint uiTxdId) -{ - if (!(*m_ppTxdPoolInterface)->IsContains(uiTxdId)) - return; - - typedef uint(__cdecl * Function_TxdReleaseSlot)(uint uiTxdId); - ((Function_TxdReleaseSlot)(0x731E90))(uiTxdId); - - (*m_ppTxdPoolInterface)->Release(uiTxdId); -} - -bool CPoolsSA::IsFreeTextureDictonarySlot(uint uiTxdId) -{ - return (*m_ppTxdPoolInterface)->IsEmpty(uiTxdId); -} - -ushort CPoolsSA::GetFreeTextureDictonarySlot() -{ - return (*m_ppTxdPoolInterface)->GetFreeSlot(); -} diff --git a/Client/game_sa/CPoolsSA.h b/Client/game_sa/CPoolsSA.h index 0e6d3d9634..5718421d6c 100644 --- a/Client/game_sa/CPoolsSA.h +++ b/Client/game_sa/CPoolsSA.h @@ -15,9 +15,9 @@ #include "CVehicleSA.h" #include "CObjectSA.h" #include "CBuildingSA.h" -#include "CTextureDictonarySA.h" #include "CBuildingsPoolSA.h" #include "CDummyPoolSA.h" +#include "CTxdPoolSA.h" #define INVALID_POOL_ARRAY_ID 0xFFFFFFFF @@ -91,14 +91,9 @@ class CPoolsSA : public CPools void ResetPedPoolCount() { m_pedPool.ulCount = 0; } void InvalidateLocalPlayerClientEntity(); - uint AllocateTextureDictonarySlot(uint uiSlotID, std::string& strTxdName); - void RemoveTextureDictonarySlot(uint uiTxdId); - bool IsFreeTextureDictonarySlot(uint uiTxdId); - - ushort GetFreeTextureDictonarySlot(); - CBuildingsPool& GetBuildingsPool() noexcept override { return m_BuildingsPool; }; CDummyPool& GetDummyPool() noexcept { return m_DummyPool; }; + CTxdPool& GetTxdPool() noexcept { return m_TxdPool; }; private: // Pools @@ -109,10 +104,10 @@ class CPoolsSA : public CPools CPoolSAInterface** m_ppPedPoolInterface; CPoolSAInterface** m_ppObjectPoolInterface; CPoolSAInterface** m_ppVehiclePoolInterface; - CPoolSAInterface** m_ppTxdPoolInterface; CBuildingsPoolSA m_BuildingsPool; CDummyPoolSA m_DummyPool; + CTxdPoolSA m_TxdPool; bool m_bGetVehicleEnabled; }; diff --git a/Client/game_sa/CTxdPoolSA.cpp b/Client/game_sa/CTxdPoolSA.cpp new file mode 100644 index 0000000000..248f825836 --- /dev/null +++ b/Client/game_sa/CTxdPoolSA.cpp @@ -0,0 +1,57 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#include "StdInc.h" +#include "CTxdPoolSA.h" +#include "CGameSA.h" +#include "CKeyGenSA.h" + +extern CGameSA* pGame; + +CTxdPoolSA::CTxdPoolSA() +{ + m_ppTxdPoolInterface = (CPoolSAInterface**)0xC8800C; +} + +std::uint32_t CTxdPoolSA::AllocateTextureDictonarySlot(std::uint32_t uiSlotId, std::string& strTxdName) +{ + CTextureDictonarySAInterface* pTxd = (*m_ppTxdPoolInterface)->AllocateAt(uiSlotId); + if (!pTxd) + return -1; + + strTxdName.resize(24); + + pTxd->usUsagesCount = 0; + pTxd->hash = pGame->GetKeyGen()->GetUppercaseKey(strTxdName.c_str()); + pTxd->rwTexDictonary = nullptr; + pTxd->usParentIndex = -1; + + return (*m_ppTxdPoolInterface)->GetObjectIndex(pTxd); +} + +void CTxdPoolSA::RemoveTextureDictonarySlot(std::uint32_t uiTxdId) +{ + if (!(*m_ppTxdPoolInterface)->IsContains(uiTxdId)) + return; + + typedef std::uint32_t(__cdecl * Function_TxdReleaseSlot)(std::uint32_t uiTxdId); + ((Function_TxdReleaseSlot)(0x731E90))(uiTxdId); + + (*m_ppTxdPoolInterface)->Release(uiTxdId); +} + +bool CTxdPoolSA::IsFreeTextureDictonarySlot(std::uint32_t uiTxdId) +{ + return (*m_ppTxdPoolInterface)->IsEmpty(uiTxdId); +} + +std::uint16_t CTxdPoolSA::GetFreeTextureDictonarySlot() +{ + return (*m_ppTxdPoolInterface)->GetFreeSlot(); +} diff --git a/Client/game_sa/CTxdPoolSA.h b/Client/game_sa/CTxdPoolSA.h new file mode 100644 index 0000000000..c1f0ed8ece --- /dev/null +++ b/Client/game_sa/CTxdPoolSA.h @@ -0,0 +1,31 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#pragma once + +#include +#include "CPoolSAInterface.h" +#include "CBuildingSA.h" +#include "CTextureDictonarySA.h" + +class CTxdPoolSA final : public CTxdPool +{ +public: + CTxdPoolSA(); + ~CTxdPoolSA() = default; + + std::uint32_t AllocateTextureDictonarySlot(std::uint32_t uiSlotID, std::string& strTxdName); + void RemoveTextureDictonarySlot(std::uint32_t uiTxdId); + bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdId); + + std::uint16_t GetFreeTextureDictonarySlot(); + +private: + CPoolSAInterface** m_ppTxdPoolInterface; +}; diff --git a/Client/mods/deathmatch/logic/CClientModel.cpp b/Client/mods/deathmatch/logic/CClientModel.cpp index 2a9eeb0c8d..75d6bbfd12 100644 --- a/Client/mods/deathmatch/logic/CClientModel.cpp +++ b/Client/mods/deathmatch/logic/CClientModel.cpp @@ -216,7 +216,7 @@ void CClientModel::RestoreDFF(CModelInfo* pModelInfo) bool CClientModel::AllocateTXD(std::string &strTxdName) { - uint uiSlotID = g_pGame->GetPools()->AllocateTextureDictonarySlot(m_iModelID - MAX_MODEL_DFF_ID, strTxdName); + uint uiSlotID = g_pGame->GetPools()->GetTxdPool().AllocateTextureDictonarySlot(m_iModelID - MAX_MODEL_DFF_ID, strTxdName); if (uiSlotID != -1) { m_bAllocatedByUs = true; @@ -237,6 +237,6 @@ void CClientModel::RestoreTXD(CModelInfo* pModelInfo) pModelInfo->SetTextureDictionaryID(0); } - g_pGame->GetPools()->RemoveTextureDictonarySlot(uiTextureDictonarySlotID); + g_pGame->GetPools()->GetTxdPool().RemoveTextureDictonarySlot(uiTextureDictonarySlotID); g_pGame->GetStreaming()->SetStreamingInfo(pModelInfo->GetModel(), 0, 0, 0, -1); } diff --git a/Client/mods/deathmatch/logic/CClientModelManager.cpp b/Client/mods/deathmatch/logic/CClientModelManager.cpp index 21d795e964..05c80ae26f 100644 --- a/Client/mods/deathmatch/logic/CClientModelManager.cpp +++ b/Client/mods/deathmatch/logic/CClientModelManager.cpp @@ -73,7 +73,7 @@ int CClientModelManager::GetFirstFreeModelID(void) int CClientModelManager::GetFreeTxdModelID() { - ushort usTxdId = g_pGame->GetPools()->GetFreeTextureDictonarySlot(); + ushort usTxdId = g_pGame->GetPools()->GetTxdPool().GetFreeTextureDictonarySlot(); if (usTxdId == -1) return INVALID_MODEL_ID; return MAX_MODEL_DFF_ID + usTxdId; diff --git a/Client/sdk/game/CPools.h b/Client/sdk/game/CPools.h index a5250fb657..5b7dd0bd2b 100644 --- a/Client/sdk/game/CPools.h +++ b/Client/sdk/game/CPools.h @@ -14,6 +14,7 @@ #include "Common.h" #include "CBuildingsPool.h" #include "CDummyPool.h" +#include "CTxdPool.h" class CClientEntity; class CEntity; @@ -107,12 +108,7 @@ class CPools virtual void ResetPedPoolCount() = 0; virtual void InvalidateLocalPlayerClientEntity() = 0; - virtual uint AllocateTextureDictonarySlot(uint uiSlotID, std::string& strTxdName) = 0; - virtual void RemoveTextureDictonarySlot(uint uiTxdID) = 0; - virtual bool IsFreeTextureDictonarySlot(uint uiTxdID) = 0; - - virtual ushort GetFreeTextureDictonarySlot() = 0; - virtual CBuildingsPool& GetBuildingsPool() noexcept = 0; - virtual CDummyPool& GetDummyPool() noexcept = 0; + virtual CDummyPool& GetDummyPool() noexcept = 0; + virtual CTxdPool& GetTxdPool() noexcept = 0; }; diff --git a/Client/sdk/game/CTxdPool.h b/Client/sdk/game/CTxdPool.h new file mode 100644 index 0000000000..1e4ff3493b --- /dev/null +++ b/Client/sdk/game/CTxdPool.h @@ -0,0 +1,22 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#pragma once + +#include "Common.h" + +class CTxdPool +{ +public: + virtual std::uint32_t AllocateTextureDictonarySlot(std::uint32_t uiSlotID, std::string& strTxdName) = 0; + virtual void RemoveTextureDictonarySlot(std::uint32_t uiTxdID) = 0; + virtual bool IsFreeTextureDictonarySlot(std::uint32_t uiTxdID) = 0; + + virtual std::uint16_t GetFreeTextureDictonarySlot() = 0; +};