From 149c1cc22be7b4f4d3a073ed3f430d595ff4802d Mon Sep 17 00:00:00 2001 From: ricardoofnl Date: Sun, 30 Aug 2026 14:35:29 +0700 Subject: [PATCH] [saco] Implement/match `CWorld__ProcessLineOfSight_Hook` --- saco/game/hooks.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++-- saco/game/util.cpp | 2 +- saco/game/util.h | 3 +- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/saco/game/hooks.cpp b/saco/game/hooks.cpp index 280b0a4..4e6f5b3 100644 --- a/saco/game/hooks.cpp +++ b/saco/game/hooks.cpp @@ -2542,9 +2542,75 @@ NUDE CWeapon__FireInstantHit_Hook() //----------------------------------------------------------- -NUDE CWorld__ProcessLineOfSight_Hook() +extern DWORD unnamed_10118990; // 0x10118990, lives in another translation unit + +// where a synced shot came from, snapshotted by CPlayerPed::FUNC_100AFA70 +struct SHOT_SYNC_DATA { - // TODO: CWorld__ProcessLineOfSight_Hook + char _gap0[0x1C]; + VECTOR vecOffset; + ENTITY_TYPE *pAttachedTo; +}; + +// todo: implement sub_100A5410 +void __stdcall sub_100A5410(VECTOR *vecOrigin, VECTOR *vecLine, VECTOR *colPoint, DWORD *pHitEntity); + +VECTOR vecShotOrigin; // 0x10150CE4 +BOOL bLineOfSightResult = 0; // 0x101517B0 +CPlayerPed *pShotSyncPlayer = 0; // 0x101517CC +SHOT_SYNC_DATA *pShotSyncData = 0; // 0x101517D0 + +BOOL CWorld__ProcessLineOfSight_Hook(VECTOR *vecOrigin, VECTOR *vecLine, VECTOR *colPoint, + DWORD *pHitEntity, int bCheckBuildings, int bCheckVehicles, int bCheckPeds, + int bCheckObjects, int bCheckDummies, int bSeeThroughStuff, + int bIgnoreSomeObjectsForCamera, int bUnk1) +{ + // aim the ray at where the remote player actually shot from + if(unnamed_10118990 != 2 && pShotSyncPlayer && pShotSyncPlayer != pGame->FindPlayerPed() && + pShotSyncData && pShotSyncData->pAttachedTo && + pShotSyncData->pAttachedTo->vtable != 0x863C40 && + pShotSyncData->pAttachedTo->mat) + { + if(unnamed_10118990 == 0) + { + FUNC_100B4D10(&vecShotOrigin, pShotSyncData->pAttachedTo->mat, &pShotSyncData->vecOffset); + } + else + { + vecShotOrigin.X = pShotSyncData->pAttachedTo->mat->pos.X + pShotSyncData->vecOffset.X; + vecShotOrigin.Y = pShotSyncData->pAttachedTo->mat->pos.Y + pShotSyncData->vecOffset.Y; + vecShotOrigin.Z = pShotSyncData->pAttachedTo->mat->pos.Z + pShotSyncData->vecOffset.Z; + } + + vecLine->X = vecShotOrigin.X - vecOrigin->X + vecShotOrigin.X; + vecLine->Y = vecShotOrigin.Y - vecOrigin->Y + vecShotOrigin.Y; + vecLine->Z = vecShotOrigin.Z - vecOrigin->Z + vecShotOrigin.Z; + } + + bLineOfSightResult = ProcessLineOfSight(vecOrigin, vecLine, colPoint, pHitEntity, + bCheckBuildings, bCheckVehicles, bCheckPeds, bCheckObjects, bCheckDummies, + bSeeThroughStuff, bIgnoreSomeObjectsForCamera, bUnk1); + + // a remote player's shot must not collide with the local player + if(unnamed_10118990 != 2 && pShotSyncPlayer && pShotSyncPlayer != pGame->FindPlayerPed() && + pShotSyncData && !pShotSyncData->pAttachedTo) + { + if(*pHitEntity == (DWORD)GamePool_FindPlayerPed() || + (IN_VEHICLE(GamePool_FindPlayerPed()) && + *pHitEntity == GamePool_FindPlayerPed()->pVehicle)) + { + *pHitEntity = 0; + colPoint->X = 0.0f; + colPoint->Y = 0.0f; + colPoint->Z = 0.0f; + return FALSE; + } + } + + if(pShotSyncPlayer && pShotSyncPlayer == pGame->FindPlayerPed()) + sub_100A5410(vecOrigin, vecLine, colPoint, pHitEntity); + + return bLineOfSightResult; } //----------------------------------------------------------- diff --git a/saco/game/util.cpp b/saco/game/util.cpp index b430805..486dc8b 100644 --- a/saco/game/util.cpp +++ b/saco/game/util.cpp @@ -13,7 +13,7 @@ struc_13 VAR_1026C258[PLAYER_PED_SLOTS]; //----------------------------------------------------------- -void __declspec(naked) ProcessLineOfSight(VECTOR *vecOrigin, VECTOR *vecLine, VECTOR *colPoint, +BOOL __declspec(naked) ProcessLineOfSight(VECTOR *vecOrigin, VECTOR *vecLine, VECTOR *colPoint, DWORD *pHitEntity, int bCheckBuildings, int bCheckVehicles, int bCheckPeds, int bCheckObjects, int bCheckDummies, int bSeeThroughStuff, int bIgnoreSomeObjectsForCamera, int bUnk1) diff --git a/saco/game/util.h b/saco/game/util.h index 5001a17..d7333cd 100644 --- a/saco/game/util.h +++ b/saco/game/util.h @@ -9,7 +9,7 @@ struct struc_13 DWORD field_C; }; -void ProcessLineOfSight(VECTOR *vecOrigin, VECTOR *vecLine, VECTOR *colPoint, +BOOL ProcessLineOfSight(VECTOR *vecOrigin, VECTOR *vecLine, VECTOR *colPoint, DWORD *pHitEntity, int bCheckBuildings, int bCheckVehicles, int bCheckPeds, int bCheckObjects, int bCheckDummies, int bSeeThroughStuff, int bIgnoreSomeObjectsForCamera, int bUnk1); @@ -60,6 +60,7 @@ BOOL IsFileOrDirectoryExists(char * szPath); DWORD unnamed_100B6100(char *szString, int nMaxLen); bool FUNC_100B4B50(VECTOR *vecPos); +void FUNC_100B4D10(VECTOR *vecOut, MATRIX4X4 *pMatrix, VECTOR *vecOffset); BUILDING_TYPE * GamePool_GetBuilding(); DUMMY_TYPE * GamePool_GetDummy();