Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(onesync): fix position getter correctness when players are standi…
…ng on entities
  • Loading branch information
Disquse committed Nov 11, 2020
1 parent 0ceb6ae commit 5a45bf0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Expand Up @@ -911,6 +911,9 @@ class ServerGameState : public fwRefCountable, public fx::IAttached<fx::ServerIn
EntityLockdownMode m_entityLockdownMode;
};

// for use in sync trees
inline ServerGameState* g_serverGameState = nullptr;

std::shared_ptr<sync::SyncTreeBase> MakeSyncTree(sync::NetObjEntityType objectType);
}

Expand Down
39 changes: 34 additions & 5 deletions code/components/citizen-server-impl/include/state/SyncTrees_Five.h
Expand Up @@ -2188,7 +2188,12 @@ struct CPlayerSectorPosNode
float m_sectorPosY;
float m_sectorPosZ;

int isStandingOn;
uint16_t m_standingOnHandle;
float m_standingOffsetX;
float m_standingOffsetY;
float m_standingOffsetZ;

bool isStandingOn;

bool Parse(SyncParseState& state)
{
Expand All @@ -2203,10 +2208,17 @@ struct CPlayerSectorPosNode
bool isStandingOn = state.buffer.ReadBit();
if (isStandingOn)
{
state.buffer.Read<int>(13); // Standing On
state.buffer.ReadFloat(14, 16.0f); // Standing On Local Offset X
state.buffer.ReadFloat(14, 16.0f); // Standing On Local Offset Y
state.buffer.ReadFloat(10, 4.0f); // Standing On Local Offset Z
m_standingOnHandle = state.buffer.Read<int>(13); // Standing On
m_standingOffsetX = state.buffer.ReadSignedFloat(14, 40.0f); // Standing On Local Offset X
m_standingOffsetY = state.buffer.ReadSignedFloat(14, 40.0f); // Standing On Local Offset Y
m_standingOffsetZ = state.buffer.ReadSignedFloat(10, 20.0f); // Standing On Local Offset Z
}
else
{
m_standingOnHandle = 0;
m_standingOffsetX = 0.0f;
m_standingOffsetY = 0.0f;
m_standingOffsetZ = 0.0f;
}

isStandingOn = isStandingOn;
Expand Down Expand Up @@ -2428,6 +2440,23 @@ struct SyncTree : public SyncTreeBase
posOut[1] = doorCreationDataNode->m_posY;
posOut[2] = doorCreationDataNode->m_posZ;
}

if (hasPspdn)
{
if (g_serverGameState && playerSecPosDataNode->isStandingOn)
{
auto entity = g_serverGameState->GetEntity(0, playerSecPosDataNode->m_standingOnHandle);

if (entity && entity->type != sync::NetObjEntityType::Player)
{
entity->syncTree->GetPosition(posOut);

posOut[0] += playerSecPosDataNode->m_standingOffsetX;
posOut[1] += playerSecPosDataNode->m_standingOffsetY;
posOut[2] += playerSecPosDataNode->m_standingOffsetZ;
}
}
}
}

virtual CPlayerCameraNodeData* GetPlayerCamera() override
Expand Down
Expand Up @@ -412,6 +412,7 @@ ServerGameState::ServerGameState()
: m_frameIndex(1), m_entitiesById(MaxObjectId), m_entityLockdownMode(EntityLockdownMode::Inactive)
{
m_tg = std::make_unique<ThreadPool>();
fx::g_serverGameState = this;
}

fx::sync::SyncEntityPtr ServerGameState::GetEntity(uint8_t playerId, uint16_t objectId)
Expand Down

0 comments on commit 5a45bf0

Please sign in to comment.