Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Oct 26, 2024
1 parent dd0d38f commit 0d55a24
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Client/game_sa/CBuildingsPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class CBuildingsPoolSA : public CBuildingsPool
SVectorPoolData<CBuildingSA> m_buildingPool{MAX_BUILDINGS};
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;

typedef std::uint8_t building_buffer_t[sizeof(CBuildingSAInterface)];
typedef std::array<std::pair<bool, building_buffer_t>, MAX_BUILDINGS> backup_array_t;
using building_buffer_t = std::uint8_t[sizeof(CBuildingSAInterface)];
using backup_array_t = std::array<std::pair<bool, building_buffer_t>, MAX_BUILDINGS>;

std::unique_ptr<backup_array_t> m_pOriginalBuildingsBackup;
};
2 changes: 0 additions & 2 deletions Client/game_sa/CEntitySA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void**>(*reinterpret_cast<std::uint32_t const*>(this) + 0x20) == (void*)0x00534030; };
};
static_assert(sizeof(CEntitySAInterface) == 0x38, "Invalid size for CEntitySAInterface");

Expand Down
5 changes: 3 additions & 2 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t*>(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<std::size_t*>(pEntity->GetVTBL())[CEntity_DeleteRwObject_VTBL_OFFSET] != 0x00534030);
#endif
pSectorEntry = (DWORD*)pSectorEntry[1];
continue;
Expand Down
6 changes: 4 additions & 2 deletions Client/game_sa/CPlaceableSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class CPlaceableSAInterface
public:
virtual void* Destructor(bool free) = 0;

bool IsPlaceableVTBL() const { return *reinterpret_cast<const void* const*>(this) == (void*)0x863C40; }
bool HasVTBL() const { return *reinterpret_cast<const void* const*>(this) != nullptr; }
void* GetVTBL() const { return *reinterpret_cast<void* const*>(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); }

Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CProjectileSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class CProjectileSAInterface : public CObjectSAInterface // entirely inherited from CObject
{
public:
bool IsProjectableVTBL() const { return *reinterpret_cast<const std::uint32_t*>(this) == 0x867030; };
bool IsProjectableVTBL() const { return GetVTBL() == (void*)0x867030; };
};

class CProjectileSA : public virtual CProjectile, public virtual CObjectSA
Expand Down

0 comments on commit 0d55a24

Please sign in to comment.