From 669437e30b82d5cf8081b837fb1364be4c73aab2 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Wed, 7 Aug 2024 19:01:32 +0800 Subject: [PATCH] [saco] Implement/match `CEntity::GetDistanceFromLocalPlayerPed()` * Update CLocalPlayer constructor * Update `CLocalPlayer::ResetAllSyncAttributes()` --- saco/game/entity.cpp | 33 +++++++++++++++++++++++++++++++++ saco/game/entity.h | 1 + saco/net/localplayer.cpp | 6 +++--- saco/net/localplayer.h | 7 +++++-- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/saco/game/entity.cpp b/saco/game/entity.cpp index 97149f3..838075c 100644 --- a/saco/game/entity.cpp +++ b/saco/game/entity.cpp @@ -230,6 +230,39 @@ void CEntity::TeleportTo(float x, float y, float z) //----------------------------------------------------------- +float CEntity::GetDistanceFromLocalPlayerPed() +{ + MATRIX4X4 matFromPlayer; + MATRIX4X4 matThis; + float fSX,fSY,fSZ; + + CPlayerPed *pLocalPlayerPed = pGame->FindPlayerPed(); + CLocalPlayer *pLocalPlayer=NULL; + + if(!pLocalPlayerPed) return 10000.0f; + + GetMatrix(&matThis); + + if(pNetGame) { + pLocalPlayer = pNetGame->GetPlayerPool()->GetLocalPlayer(); + if(pLocalPlayer && (pLocalPlayer->IsSpectating() || pLocalPlayer->IsInRCMode())) { + pGame->GetCamera()->GetMatrix(&matFromPlayer); + } else { + pLocalPlayerPed->GetMatrix(&matFromPlayer); + } + } else { + pLocalPlayerPed->GetMatrix(&matFromPlayer); + } + + fSX = (matThis.pos.X - matFromPlayer.pos.X) * (matThis.pos.X - matFromPlayer.pos.X); + fSY = (matThis.pos.Y - matFromPlayer.pos.Y) * (matThis.pos.Y - matFromPlayer.pos.Y); + fSZ = (matThis.pos.Z - matFromPlayer.pos.Z) * (matThis.pos.Z - matFromPlayer.pos.Z); + + return (float)sqrt(fSX + fSY + fSZ); +} + +//----------------------------------------------------------- + float CEntity::GetDistanceFromPoint(float X, float Y, float Z) { MATRIX4X4 matThis; diff --git a/saco/game/entity.h b/saco/game/entity.h index 2cc9ed4..d32683a 100644 --- a/saco/game/entity.h +++ b/saco/game/entity.h @@ -25,6 +25,7 @@ public: void GetBoundRect(PFRECT Rect); // unused UINT GetModelIndex(); void TeleportTo(float x, float y, float z); + float GetDistanceFromLocalPlayerPed(); float GetDistanceFromPoint(float X, float Y, float Z); BOOL IsStationary(); diff --git a/saco/net/localplayer.cpp b/saco/net/localplayer.cpp index 64d7336..c5b38ec 100644 --- a/saco/net/localplayer.cpp +++ b/saco/net/localplayer.cpp @@ -10,7 +10,7 @@ CLocalPlayer::CLocalPlayer() field_147 = GetTickCount(); field_137 = GetTickCount(); field_13B = GetTickCount(); - field_1D0 = 0; + m_bInRCMode = FALSE; field_2E2 = 0; field_2D6 = GetTickCount(); field_2F6 = 0; @@ -24,7 +24,7 @@ CLocalPlayer::CLocalPlayer() field_13F = GetTickCount(); field_117 = field_10F; field_11B = field_10F; - field_108 = 0; + m_bIsSpectating = FALSE; field_30F = 0; field_310 = -1; field_306 = 0; @@ -51,7 +51,7 @@ void CLocalPlayer::ResetAllSyncAttributes() field_2FE = 0; field_1CF = 0; field_FA = -1; - field_1D0 = 0; + m_bInRCMode = FALSE; field_318 = -1; field_11F = -1; field_121 = -1; diff --git a/saco/net/localplayer.h b/saco/net/localplayer.h index 0d53316..f2fd620 100644 --- a/saco/net/localplayer.h +++ b/saco/net/localplayer.h @@ -23,7 +23,7 @@ public: int field_FC; int field_100; CPlayerPed *m_pPlayerPed; - int field_108; + BOOL m_bIsSpectating; char field_10C; short field_10D; DWORD field_10F; @@ -59,7 +59,7 @@ public: char _gap1CB[4]; char field_1CF; - int field_1D0; + BOOL m_bInRCMode; char _gap1D4[258]; @@ -94,6 +94,9 @@ public: void Say(PCHAR szText); + BOOL IsSpectating() { return m_bIsSpectating; }; + + BOOL IsInRCMode() { return m_bInRCMode; }; }; //----------------------------------------------------------