From d13020cef066d217d86bbe23da9076f0ec287ca0 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:41:30 +0800 Subject: [PATCH] [saco] Implement `CNetGame::GetPlayerFacingAngle(...)` --- bot/net/netgame.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ bot/net/netgame.h | 1 + 2 files changed, 42 insertions(+) diff --git a/bot/net/netgame.cpp b/bot/net/netgame.cpp index 72f3c1d..ca319eb 100644 --- a/bot/net/netgame.cpp +++ b/bot/net/netgame.cpp @@ -221,6 +221,47 @@ BOOL CNetGame::GetPlayerKeys(PLAYERID playerId, WORD *udAnalog, WORD *lrAnalog, } } +float CNetGame::GetPlayerFacingAngle(PLAYERID playerId) +{ + if(playerId >= MAX_PLAYERS) return 0.0f; + if(bPlayerSlotState[playerId] == FALSE) return 0.0f; + + MATRIX4X4 mat; + + if(bytePlayerState[playerId] == PLAYER_STATE_ONFOOT) + { + QuaternionToMatrix(&unnamed_3[playerId].quatRotation, &mat); + + float fZAngle = atan2(-mat.up.X, mat.up.Y) * 180.0f/PI; + + // Bound it to [0, 360) + if ( fZAngle < 0.0f ) + fZAngle += 360.0f; + else if ( fZAngle >= 360.0f ) + fZAngle -= 360.0f; + + return fZAngle; + } + else if(bytePlayerState[playerId] == PLAYER_STATE_DRIVER) + { + QuaternionToMatrix(&unnamed_4[playerId].quatRotation, &mat); + + float fZAngle = atan2(-mat.up.X, mat.up.Y) * 180.0f/PI; + + // Bound it to [0, 360) + if ( fZAngle < 0.0f ) + fZAngle += 360.0f; + else if ( fZAngle >= 360.0f ) + fZAngle -= 360.0f; + + return fZAngle; + } + else + { + return 0.0f; + } +} + BYTE CNetGame::GetPlayerSpecialAction(PLAYERID playerId) { if(playerId >= MAX_PLAYERS) return SPECIAL_ACTION_NONE; diff --git a/bot/net/netgame.h b/bot/net/netgame.h index 030714a..d05a9ba 100644 --- a/bot/net/netgame.h +++ b/bot/net/netgame.h @@ -118,6 +118,7 @@ public: BYTE GetPlayerHealth(PLAYERID playerId); BYTE GetPlayerArmour(PLAYERID playerId); BOOL GetPlayerKeys(PLAYERID playerId, WORD *udAnalog, WORD *lrAnalog, WORD *wKeys); + float GetPlayerFacingAngle(PLAYERID playerId); BYTE GetPlayerSpecialAction(PLAYERID playerId); BOOL IsPlayerAdded(PLAYERID playerId); BOOL IsVehicleAdded(VEHICLEID VehicleID);