From 5e46ec57021e4aba354b3344b94d22cb133aa9fd Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:34:21 +0800 Subject: [PATCH] [saco] Implement/match `ScrSetPlayerColor(...)` --- saco/net/localplayer.cpp | 8 ++++++++ saco/net/localplayer.h | 1 + saco/net/playerpool.cpp | 2 +- saco/net/playerpool.h | 12 +++++++++++- saco/net/remoteplayer.cpp | 9 +++++++++ saco/net/remoteplayer.h | 1 + saco/net/scriptrpc.cpp | 26 +++++++++++++++++++++++++- 7 files changed, 56 insertions(+), 3 deletions(-) diff --git a/saco/net/localplayer.cpp b/saco/net/localplayer.cpp index dc0efb4..253c4d8 100644 --- a/saco/net/localplayer.cpp +++ b/saco/net/localplayer.cpp @@ -1,5 +1,6 @@ #include "../main.h" +#include "../game/util.h" extern CGame *pGame; @@ -84,3 +85,10 @@ void CLocalPlayer::Say(PCHAR szText) //---------------------------------------------------------- +void CLocalPlayer::SetPlayerColor(DWORD dwColor) +{ + SetRadarColor(pNetGame->GetPlayerPool()->GetLocalPlayerID(),dwColor); +} + +//---------------------------------------------------- + diff --git a/saco/net/localplayer.h b/saco/net/localplayer.h index 4afceec..7ede16b 100644 --- a/saco/net/localplayer.h +++ b/saco/net/localplayer.h @@ -96,6 +96,7 @@ public: void Say(PCHAR szText); + void SetPlayerColor(DWORD dwColor); BOOL IsSpectating() { return m_bIsSpectating; }; void ReturnToClassSelection() { m_bWantsAnotherClass = TRUE; }; diff --git a/saco/net/playerpool.cpp b/saco/net/playerpool.cpp index 07655be..ca388b7 100644 --- a/saco/net/playerpool.cpp +++ b/saco/net/playerpool.cpp @@ -13,7 +13,7 @@ CPlayerPool::CPlayerPool() m_pLocalPlayer = new CLocalPlayer(); field_0 = 0; field_22 = 0; - field_4 = 0; + m_LocalPlayerID = 0; field_2F3A = 0; } diff --git a/saco/net/playerpool.h b/saco/net/playerpool.h index a477e4a..bb777c9 100644 --- a/saco/net/playerpool.h +++ b/saco/net/playerpool.h @@ -8,8 +8,9 @@ class CPlayerPool { private: + int field_0; - short field_4; + PLAYERID m_LocalPlayerID; std::string field_6; int field_22; CLocalPlayer *m_pLocalPlayer; @@ -33,6 +34,15 @@ public: CLocalPlayer * GetLocalPlayer() { return m_pLocalPlayer; }; + CRemotePlayer* GetAt(PLAYERID playerId) { + if(playerId > MAX_PLAYERS) { return NULL; } + CNetPlayer *pNetPlayer = m_pPlayers[playerId]; + if(pNetPlayer) return pNetPlayer->m_pRemotePlayer; + return NULL; + }; + + PLAYERID GetLocalPlayerID() { return m_LocalPlayerID; }; + CPlayerPool(); }; diff --git a/saco/net/remoteplayer.cpp b/saco/net/remoteplayer.cpp index 8eb3686..0f8001d 100644 --- a/saco/net/remoteplayer.cpp +++ b/saco/net/remoteplayer.cpp @@ -1,5 +1,6 @@ #include "../main.h" +#include "../game/util.h" extern CGame *pGame; @@ -61,3 +62,11 @@ void CRemotePlayer::ResetAllSyncAttributes() } //---------------------------------------------------- + +void CRemotePlayer::SetPlayerColor(DWORD dwColor) +{ + SetRadarColor(m_PlayerID,dwColor); +} + +//---------------------------------------------------- + diff --git a/saco/net/remoteplayer.h b/saco/net/remoteplayer.h index d771347..db0ebbf 100644 --- a/saco/net/remoteplayer.h +++ b/saco/net/remoteplayer.h @@ -57,6 +57,7 @@ public: void ResetAllSyncAttributes(); + void SetPlayerColor(DWORD dwColor); }; //---------------------------------------------------- diff --git a/saco/net/scriptrpc.cpp b/saco/net/scriptrpc.cpp index ad80e40..c000286 100644 --- a/saco/net/scriptrpc.cpp +++ b/saco/net/scriptrpc.cpp @@ -60,7 +60,6 @@ void ScrSetPlayerPos(RPCParameters *rpcParams) {} void ScrUnk0D(RPCParameters *rpcParams) {} void ScrPutPlayerInVehicle(RPCParameters *rpcParams) {} void ScrRemovePlayerFromVehicle(RPCParameters *rpcParams) {} -void ScrSetPlayerColor(RPCParameters *rpcParams) {} void ScrDisplayGameText(RPCParameters *rpcParams) {} void ScrSetInterior(RPCParameters *rpcParams) {} void ScrUnk9F(RPCParameters *rpcParams) {} @@ -149,6 +148,31 @@ void ScrSetPlayerHealth(RPCParameters *rpcParams) pLocalPlayer->GetPlayerPed()->SetHealth(fHealth); } +//---------------------------------------------------- + +void ScrSetPlayerColor(RPCParameters *rpcParams) +{ + PCHAR Data = reinterpret_cast(rpcParams->input); + int iBitLength = rpcParams->numberOfBitsOfData; + PlayerID sender = rpcParams->sender; + + RakNet::BitStream bsData(Data,(iBitLength/8)+1,false); + CPlayerPool *pPlayerPool = pNetGame->GetPlayerPool(); + PLAYERID playerId; + DWORD dwColor; + + bsData.Read(playerId); + bsData.Read(dwColor); + + if(playerId == pPlayerPool->GetLocalPlayerID()) { + pPlayerPool->GetLocalPlayer()->SetPlayerColor(dwColor); + } else { + CRemotePlayer *pPlayer = pPlayerPool->GetAt(playerId); + if(pPlayer) pPlayer->SetPlayerColor(dwColor); + } +} + + //---------------------------------------------------- void ScrSetCameraPos(RPCParameters *rpcParams)