From 831b304f203b44bf996739a1173835b6b6d17903 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:35:03 +0800 Subject: [PATCH] [bot] Implement/match `n_GetMyFacingAngle(...)` * Rename `unnamed_9` to `byteState` * Implement/match `CNetGame::GetMyZAngle()` * Update `CNetGame::Init(...)` --- bot/net/netgame.cpp | 38 ++++++++++++++++++++++++++++++++++++-- bot/net/netgame.h | 1 + bot/scrcustom.cpp | 7 +++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/bot/net/netgame.cpp b/bot/net/netgame.cpp index 4d55530..577f3f3 100644 --- a/bot/net/netgame.cpp +++ b/bot/net/netgame.cpp @@ -29,8 +29,8 @@ typedef struct _TRAILER_SYNC_DATA // size: 54 char unnamed_2[63]; PASSENGER_SYNC_DATA unnamed_5[MAX_PLAYERS]; -char unnamed_9; BOOL bPlayerSlotState[MAX_PLAYERS]; +BYTE byteState; ONFOOT_SYNC_DATA ofSync; ONFOOT_SYNC_DATA unnamed_3[MAX_PLAYERS]; BYTE bytePlayerState[MAX_PLAYERS]; @@ -237,6 +237,40 @@ BOOL CNetGame::IsVehicleAdded(VEHICLEID VehicleID) return bVehicleSlotState[VehicleID] != FALSE; } +//---------------------------------------------------- +float CNetGame::GetMyZAngle() +{ + MATRIX4X4 mat; + + if(byteState == PLAYER_STATE_ONFOOT) + { + QuaternionToMatrix(&ofSync.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(byteState == PLAYER_STATE_DRIVER) + { + QuaternionToMatrix(&icSync.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; + } + + return 0.0f; +} + //---------------------------------------------------- // MATCH void CNetGame::SetMyZAngle(float fAngle) @@ -402,7 +436,7 @@ void CNetGame::Init(PCHAR szHostOrIp, int iPort, field_1DE = 0; field_1E2 = 0; field_1F2 = GetTickCount(); - unnamed_9 = 0; + byteState = PLAYER_STATE_NONE; field_1FA = -1; field_1FE = -1; srand(0); diff --git a/bot/net/netgame.h b/bot/net/netgame.h index e33ec40..c6d100c 100644 --- a/bot/net/netgame.h +++ b/bot/net/netgame.h @@ -115,6 +115,7 @@ public: BYTE GetPlayerArmour(PLAYERID playerId); BOOL GetPlayerKeys(PLAYERID playerId, WORD *udAnalog, WORD *lrAnalog, WORD *wKeys); BOOL IsVehicleAdded(VEHICLEID VehicleID); + float GetMyZAngle(); void StopRecordingPlayback(); void PauseRecordingPlayback(); diff --git a/bot/scrcustom.cpp b/bot/scrcustom.cpp index e700dcf..1386c03 100644 --- a/bot/scrcustom.cpp +++ b/bot/scrcustom.cpp @@ -266,8 +266,11 @@ static cell AMX_NATIVE_CALL n_SetMyPos(AMX *amx, cell *params) // native GetMyFacingAngle(&Float:ang) static cell AMX_NATIVE_CALL n_GetMyFacingAngle(AMX *amx, cell *params) { - // TODO: n_GetMyFacingAngle - return 0; + cell* cptr; + amx_GetAddr(amx, params[1], &cptr); + float fResult = pNetGame->GetMyZAngle(); + *cptr = amx_ftoc(fResult); + return 1; } // native SetMyFacingAngle(Float:ang)