Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,9 @@ void CClientGame::PreWorldProcessHandler()

void CClientGame::PostWorldProcessHandler()
{
if (m_pManager->IsGameLoaded())
m_pManager->GetPedManager()->ReapplyScriptRotations();

m_pManager->GetMarkerManager()->DoPulse();
m_pManager->GetPointLightsManager()->DoPulse();
m_pManager->GetObjectManager()->DoPulse();
Expand All @@ -3958,6 +3961,9 @@ void CClientGame::PostWorldProcessHandler()

void CClientGame::PostWorldProcessPedsAfterPreRenderHandler()
{
if (m_pManager->IsGameLoaded())
m_pManager->GetPedManager()->ReapplyScriptRotations();

CLuaArguments Arguments;
m_pRootEntity->CallEvent("onClientPedsProcessed", Arguments, false);
}
Expand Down
22 changes: 22 additions & 0 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,27 @@ void CClientPed::SetCurrentRotationNew(float fRotation)
SetRotationRadiansNew(CVector(0, 0, fRotation));
}

void CClientPed::SetScriptRotationOverride(const CVector& vecRotationRadians, bool bNewWay)
{
m_bHasScriptRotationOverride = true;
m_bScriptRotationNewWay = bNewWay;
m_vecScriptRotation = vecRotationRadians;
}

void CClientPed::ReapplyScriptRotationIfNeeded()
{
if (!m_bHasScriptRotationOverride || !m_pPlayerPed)
return;

if (GetRealOccupiedVehicle())
return;

if (m_bScriptRotationNewWay)
SetRotationRadiansNew(m_vecScriptRotation);
else
SetRotationRadians(m_vecScriptRotation);
}

void CClientPed::Spawn(const CVector& vecPosition, float fRotation, unsigned short usModel, unsigned char ucInterior)
{
// Remove us from our car
Expand Down Expand Up @@ -779,6 +800,7 @@ void CClientPed::Spawn(const CVector& vecPosition, float fRotation, unsigned sho

// Set some states
SetFrozen(false);
ClearScriptRotationOverride();
Teleport(vecPosition);
SetCurrentRotationNew(fRotation);
SetHealth(GetMaxHealth());
Expand Down
8 changes: 8 additions & 0 deletions Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
void SetRotationRadiansNew(const CVector& vecRotation);
void SetCurrentRotationNew(float fRotation);

void SetScriptRotationOverride(const CVector& vecRotationRadians, bool bNewWay);
void ClearScriptRotationOverride() noexcept { m_bHasScriptRotationOverride = false; }
void ReapplyScriptRotationIfNeeded();
bool HasScriptRotationOverride() const noexcept { return m_bHasScriptRotationOverride; }

void Teleport(const CVector& vecPosition);

// This function spawns/respawns this ped in any location. This will force a recreation
Expand Down Expand Up @@ -748,6 +753,9 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
uint m_uiFrameLastRebuildPlayer;
bool m_bIsSyncing;
bool m_shouldRecreate{false};
bool m_bHasScriptRotationOverride{};
bool m_bScriptRotationNewWay{};
CVector m_vecScriptRotation{};

bool m_bBulletImpactData;
CClientEntityPtr m_pBulletImpactEntity;
Expand Down
6 changes: 6 additions & 0 deletions Client/mods/deathmatch/logic/CClientPedManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ bool CClientPedManager::Exists(CClientPed* pPed)
return false;
}

void CClientPedManager::ReapplyScriptRotations()
{
for (uint i = 0; i < m_StreamedIn.size(); i++)
m_StreamedIn[i]->ReapplyScriptRotationIfNeeded();
}

void CClientPedManager::RemoveFromList(CClientPed* pPed)
{
if (m_bRemoveFromList)
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientPedManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CClientPedManager
void RestreamAllPeds();
void RestreamWeapon(unsigned short usModel);

void ReapplyScriptRotations();

protected:
CClientPedManager(class CClientManager* pManager);
~CClientPedManager();
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4187,6 +4187,7 @@ void CClientVehicle::SetPedOccupiedVehicle(CClientPed* pClientPed, CClientVehicl
// Ped vars
pClientPed->m_pOccupiedVehicle = pVehicle;
pClientPed->m_uiOccupiedVehicleSeat = uiSeat;
pClientPed->ClearScriptRotationOverride();

if (ucDoor != 0xFF)
pVehicle->AllowDoorRatioSetting(ucDoor, true);
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CNetAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ void CNetAPI::WriteKeysync(CClientPed* pPlayerModel, NetBitStreamInterface& BitS
WriteSmallKeysync(ControllerState, BitStream);

// Write the rotations
pPlayerModel->ReapplyScriptRotationIfNeeded();
SKeysyncRotation rotation;
rotation.data.fPlayerRotation = pPlayerModel->GetCurrentRotation();
rotation.data.fCameraRotation = pPlayerModel->GetCameraRotation();
Expand Down Expand Up @@ -1187,6 +1188,7 @@ void CNetAPI::WritePlayerPuresync(CClientPlayer* pPlayerModel, NetBitStreamInter
BitStream.Write(&position);

// Player rotation
pPlayerModel->ReapplyScriptRotationIfNeeded();
SPedRotationSync rotation;
rotation.data.fRotation = pPlayerModel->GetCurrentRotation();
BitStream.Write(&rotation);
Expand Down
26 changes: 13 additions & 13 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,20 +1092,18 @@ bool CStaticFunctionDefinitions::SetElementRotation(CClientEntity& Entity, const
case CCLIENTPLAYER:
{
CClientPed& Ped = static_cast<CClientPed&>(Entity);
if (argumentRotOrder == EULER_DEFAULT || argumentRotOrder == EULER_MINUS_ZYX)
{
if (bNewWay)
Ped.SetRotationDegreesNew(vecRotation);
else
Ped.SetRotationDegrees(vecRotation);
}
CVector vecUseRotation = vecRotation;
if (argumentRotOrder != EULER_DEFAULT && argumentRotOrder != EULER_MINUS_ZYX)
vecUseRotation = ConvertEulerRotationOrder(vecRotation, argumentRotOrder, EULER_MINUS_ZYX);

if (bNewWay)
Ped.SetRotationDegreesNew(vecUseRotation);
else
{
if (bNewWay)
Ped.SetRotationDegreesNew(ConvertEulerRotationOrder(vecRotation, argumentRotOrder, EULER_MINUS_ZYX));
else
Ped.SetRotationDegrees(ConvertEulerRotationOrder(vecRotation, argumentRotOrder, EULER_MINUS_ZYX));
}
Ped.SetRotationDegrees(vecUseRotation);

CVector vecRotationRadians = vecUseRotation;
ConvertDegreesToRadiansNoWrap(vecRotationRadians);
Ped.SetScriptRotationOverride(vecRotationRadians, bNewWay);
break;
}
case CCLIENTVEHICLE:
Expand Down Expand Up @@ -2225,6 +2223,8 @@ bool CStaticFunctionDefinitions::SetPedRotation(CClientEntity& Entity, float fRo

if (!IS_PLAYER(&Entity))
Ped.SetCameraRotation(-fRadians);

Ped.SetScriptRotationOverride(CVector(0.0f, 0.0f, fRadians), bNewWay);
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CPedRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ void CPedRPCs::SetPedRotation(CClientEntity* pSource, NetBitStreamInterface& bit

if (!IS_PLAYER(pPed))
pPed->SetCameraRotation(rotation.data.fRotation);

pPed->SetScriptRotationOverride(CVector(0.0f, 0.0f, rotation.data.fRotation), ucNewWay == 1);
pPed->SetSyncTimeContext(ucTimeContext);
}
}
Expand Down
Loading