Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix class hierarchy. Remove VTBL hacks #3766

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

TheNormalnij
Copy link
Member

@TheNormalnij TheNormalnij commented Oct 3, 2024

This PR:

  • Removes dirty VTBL hacks in CEntitySAInterface. All hacks are replaced with virtual methods.
  • Fixes class hierarchy in CEntitySAInterface and CCameraSAInterface with CPlaceableSAInterface.

Current state: testing.

Comment on lines 211 to 216
void CCameraSA::SetMatrix(CMatrix* matrix)
{
CMatrix_Padded* pCamMatrix = GetInterface()->Placeable.matrix;
CMatrix_Padded* pCamMatrix = GetInterface()->matrix;
if (pCamMatrix)
{
pCamMatrix->vFront = matrix->vFront;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code had no effect previously. matrix was always nullptr because Placeable was misplaced

Comment on lines 168 to 198
// Initialize doors depending on the vehicle type.
DWORD dwOffset = 0;

switch (static_cast<VehicleClass>(GetVehicleInterface()->m_vehicleClass))
{
case VehicleClass::AUTOMOBILE:
case VehicleClass::MONSTER_TRUCK:
case VehicleClass::QUAD:
case VehicleClass::HELI:
case VehicleClass::PLANE:
case VehicleClass::TRAILER:
{
dwOffset = 1464;
}
case VehicleClass::TRAIN:
{
dwOffset = 1496;
}
default:
break;
}

if (dwOffset != 0)
{
for (unsigned int i = 0; i < sizeof(m_doors) / sizeof(m_doors[0]); ++i)
{
DWORD dwInterface = (DWORD)GetInterface();
DWORD dwDoorAddress = dwInterface + 1464 + i * 24;
DWORD dwDoorAddress = dwInterface + dwOffset + i * 24;
m_doors[i].SetInterface((CDoorSAInterface*)dwDoorAddress);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was bugged. The game uses wrong door array positions for CTrain.
It causes train desync issues

@FileEX
Copy link
Contributor

FileEX commented Oct 3, 2024

On this topic, I think we should get rid of two duplicate classes like CMatrix_Padded and CMatrixSAInterface. Only CMatrixSAInterface should remain. In addition, the CMatrix_Padded class is incomplete

@TheNormalnij
Copy link
Member Author

TheNormalnij commented Oct 3, 2024

On this topic, I think we should get rid of two duplicate classes like CMatrix_Padded and CMatrixSAInterface. Only CMatrixSAInterface should remain. In addition, the CMatrix_Padded class is incomplete

CMatrix_Padded and CMatrixSAInterface are different classes. CMatrix_Padded

@FileEX
Copy link
Contributor

FileEX commented Oct 3, 2024

On this topic, I think we should get rid of two duplicate classes like CMatrix_Padded and CMatrixSAInterface. Only CMatrixSAInterface should remain. In addition, the CMatrix_Padded class is incomplete

CMatrix_Padded and CMatrixSAInterface are different classes. CMatrix_Padded

You are right, so CMatrix_Padded should inherit CMatrixSAInterface, because now CMatrix_Paddes is the wrong size

Client/game_sa/CBuildingsPoolSA.h Outdated Show resolved Hide resolved
Client/game_sa/CEntitySA.h Show resolved Hide resolved
Client/game_sa/CEntitySA.h Outdated Show resolved Hide resolved
Client/game_sa/CPlaceableSA.h Outdated Show resolved Hide resolved
Client/game_sa/CPlaceableSA.h Outdated Show resolved Hide resolved
Client/game_sa/CProjectileSA.h Outdated Show resolved Hide resolved
Client/game_sa/CVehicleSA.h Show resolved Hide resolved
Client/game_sa/CVehicleSA.h Show resolved Hide resolved
@TheNormalnij TheNormalnij marked this pull request as ready for review October 26, 2024 00:59
{
// 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->vtbl->DeleteRwObject == 0x00534030);
assert(static_cast<std::size_t*>(pEntity->GetVTBL())[CEntity_DeleteRwObject_VTBL_OFFSET] != 0x00534030);
#endif
pSectorEntry = (DWORD*)pSectorEntry[1];
continue;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check should be removed but not in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants