From 0d55a2441e6fef501ecdda3d6589ad5e32270290 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Sat, 26 Oct 2024 03:58:46 +0300 Subject: [PATCH] Small fixes --- Client/game_sa/CBuildingsPoolSA.h | 4 ++-- Client/game_sa/CEntitySA.h | 2 -- Client/game_sa/CModelInfoSA.cpp | 5 +++-- Client/game_sa/CPlaceableSA.h | 6 ++++-- Client/game_sa/CProjectileSA.h | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Client/game_sa/CBuildingsPoolSA.h b/Client/game_sa/CBuildingsPoolSA.h index 863e916e5f..f9db9f44c9 100644 --- a/Client/game_sa/CBuildingsPoolSA.h +++ b/Client/game_sa/CBuildingsPoolSA.h @@ -43,8 +43,8 @@ class CBuildingsPoolSA : public CBuildingsPool SVectorPoolData m_buildingPool{MAX_BUILDINGS}; CPoolSAInterface** m_ppBuildingPoolInterface; - typedef std::uint8_t building_buffer_t[sizeof(CBuildingSAInterface)]; - typedef std::array, MAX_BUILDINGS> backup_array_t; + using building_buffer_t = std::uint8_t[sizeof(CBuildingSAInterface)]; + using backup_array_t = std::array, MAX_BUILDINGS>; std::unique_ptr m_pOriginalBuildingsBackup; }; diff --git a/Client/game_sa/CEntitySA.h b/Client/game_sa/CEntitySA.h index 067a47e9fc..585dee903a 100644 --- a/Client/game_sa/CEntitySA.h +++ b/Client/game_sa/CEntitySA.h @@ -216,8 +216,6 @@ class CEntitySAInterface : public CPlaceableSAInterface using CStencilShadow_dtorByOwner = void*(__cdecl*)(CEntitySAInterface * pEntity); ((CStencilShadow_dtorByOwner)0x711730)(this); }; - - bool IsUsesEntityDeleteRwObject() const { return *reinterpret_cast(*reinterpret_cast(this) + 0x20) == (void*)0x00534030; }; }; static_assert(sizeof(CEntitySAInterface) == 0x38, "Invalid size for CEntitySAInterface"); diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 3000fa0c75..07f50f0a73 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -985,14 +985,15 @@ void CModelInfoSA::StaticFlushPendingRestreamIPL() CEntitySAInterface* pEntity = (CEntitySAInterface*)pSectorEntry[0]; // Possible bug - pEntity seems to be invalid here occasionally - if (!pEntity->IsUsesEntityDeleteRwObject()) + constexpr auto CEntity_DeleteRwObject_VTBL_OFFSET = 8; + if (static_cast(pEntity->GetVTBL())[CEntity_DeleteRwObject_VTBL_OFFSET] != 0x00534030) { // Log info OutputDebugString(SString("Entity 0x%08x (with model %d) at ARRAY_StreamSectors[%d,%d] is invalid\n", pEntity, pEntity->m_nModelIndex, i / 2 % NUM_StreamSectorRows, i / 2 / NUM_StreamSectorCols)); // Assert in debug #if MTA_DEBUG - assert(pEntity->IsUsesEntityDeleteRwObject()); + assert(static_cast(pEntity->GetVTBL())[CEntity_DeleteRwObject_VTBL_OFFSET] != 0x00534030); #endif pSectorEntry = (DWORD*)pSectorEntry[1]; continue; diff --git a/Client/game_sa/CPlaceableSA.h b/Client/game_sa/CPlaceableSA.h index a0508f07ae..df088b3cbf 100644 --- a/Client/game_sa/CPlaceableSA.h +++ b/Client/game_sa/CPlaceableSA.h @@ -22,8 +22,10 @@ class CPlaceableSAInterface public: virtual void* Destructor(bool free) = 0; - bool IsPlaceableVTBL() const { return *reinterpret_cast(this) == (void*)0x863C40; } - bool HasVTBL() const { return *reinterpret_cast(this) != nullptr; } + void* GetVTBL() const { return *reinterpret_cast(this); } + bool HasVTBL() const { return GetVTBL() != nullptr; } + bool IsPlaceableVTBL() const { return GetVTBL() == (void*)0x863C40; } + bool HasMatrix() const noexcept { return matrix != nullptr; } void RemoveMatrix() { ((void(__thiscall*)(void*))0x54F3B0)(this); } diff --git a/Client/game_sa/CProjectileSA.h b/Client/game_sa/CProjectileSA.h index ee03568a4c..669a566a0f 100644 --- a/Client/game_sa/CProjectileSA.h +++ b/Client/game_sa/CProjectileSA.h @@ -17,7 +17,7 @@ class CProjectileSAInterface : public CObjectSAInterface // entirely inherited from CObject { public: - bool IsProjectableVTBL() const { return *reinterpret_cast(this) == 0x867030; }; + bool IsProjectableVTBL() const { return GetVTBL() == (void*)0x867030; }; }; class CProjectileSA : public virtual CProjectile, public virtual CObjectSA