Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new function testSphereAgainstWorld (Close #646) #3787

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Client/game_sa/CWorldSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ bool CWorldSA::ResetSurfaceInfo(short sSurfaceID)
return false;
}

CEntity* CWorldSA::TestSphereAgainstWorld(const CVector& sphereCenter, float radius, CEntity* ignoredEntity, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool cameraIgnore, STestSphereAgainstWorldResult& result)
{
auto entity = ((CEntitySAInterface*(__cdecl*)(CVector, float, CEntitySAInterface*, bool, bool, bool, bool, bool, bool))FUNC_CWorld_TestSphereAgainstWorld)(sphereCenter, radius, ignoredEntity ? ignoredEntity->GetInterface() : nullptr, checkBuildings, checkVehicles, checkPeds, checkObjects, checkDummies, cameraIgnore);
if (!entity)
return nullptr;

result.collisionDetected = true;
result.hitPosition = entity->Placeable.matrix->vPos;
FileEX marked this conversation as resolved.
Show resolved Hide resolved
result.modelID = entity->m_nModelIndex;
result.type = entity->nType;
result.lodID = entity->m_pLod ? entity->m_pLod->m_nModelIndex : 0;

return pGame->GetPools()->GetEntity(reinterpret_cast<DWORD*>(entity));
}

void HOOK_FallenPeds();
void HOOK_FallenCars();

Expand Down
3 changes: 3 additions & 0 deletions Client/game_sa/CWorldSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define VAR_COcclusion_NumActiveOccluders 0xC73CC0
#define CALL_CCullZones_FindTunnelAttributesForCoors 0x55570D
#define FUNC_CWorld_FindPositionForTrackPosition 0x6F59E0
#define FUNC_CWorld_TestSphereAgainstWorld 0x569E20

#define VAR_IgnoredEntity 0xB7CD68
#define VAR_currArea 0xB72914
Expand Down Expand Up @@ -74,6 +75,8 @@ class CWorldSA : public CWorld
void ResetAllSurfaceInfo() override;
bool ResetSurfaceInfo(short sSurfaceID) override;

CEntity* TestSphereAgainstWorld(const CVector& sphereCenter, float radius, CEntity* ignoredEntity, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool cameraIgnore, STestSphereAgainstWorldResult& result) override;

private:
float m_fAircraftMaxHeight;
CSurfaceType* m_pSurfaceInfo;
Expand Down
15 changes: 14 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ void CLuaWorldDefs::LoadFunctions()
{"isWorldSpecialPropertyEnabled", ArgumentParserWarn<false, IsWorldSpecialPropertyEnabled>},
{"isGarageOpen", IsGarageOpen},
{"isTimeFrozen", ArgumentParser<IsTimeFrozen>},
{"isVolumetricShadowsEnabled", ArgumentParser<IsVolumetricShadowsEnabled>}};
{"isVolumetricShadowsEnabled", ArgumentParser<IsVolumetricShadowsEnabled>},
{"testSphereAgainstWorld", ArgumentParser<TestSphereAgainstWorld>}};

// Add functions
for (const auto& [name, func] : functions)
Expand Down Expand Up @@ -2278,3 +2279,15 @@ void CLuaWorldDefs::ResetWorldProperties(std::optional<bool> resetSpecialWorldPr
{
g_pClientGame->ResetWorldProperties(ResetWorldPropsInfo{resetSpecialWorldProperties.value_or(true), resetWorldProperties.value_or(true), resetWeatherProperties.value_or(true), resetLODs.value_or(true), resetSounds.value_or(true)});
}

CLuaMultiReturn<bool, CClientEntity*, float, float, float, int, int, int> CLuaWorldDefs::TestSphereAgainstWorld(CVector sphereCenter, float radius, std::optional<CClientEntity*> ignoredEntity, std::optional<bool> checkBuildings, std::optional<bool> checkVehicles, std::optional<bool> checkPeds, std::optional<bool> checkObjects, std::optional<bool> checkDummies, std::optional<bool> cameraIgnore)
{
STestSphereAgainstWorldResult result;
CClientEntity* collidedEntity = nullptr;

CEntity* entity = g_pGame->GetWorld()->TestSphereAgainstWorld(sphereCenter, radius, ignoredEntity.has_value() ? ignoredEntity.value()->GetGameEntity() : nullptr, checkBuildings.value_or(true), checkVehicles.value_or(true), checkPeds.value_or(true), checkObjects.value_or(true), checkDummies.value_or(true), cameraIgnore.value_or(false), result);
if (entity)
collidedEntity = reinterpret_cast<CClientEntity*>(entity->GetStoredPointer());

return {result.collisionDetected, collidedEntity, result.hitPosition.fX, result.hitPosition.fY, result.hitPosition.fZ, result.modelID, result.lodID, result.type};
}
4 changes: 3 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class CLuaWorldDefs : public CLuaDefs
static bool ResetVolumetricShadows() noexcept;

static void ResetWorldProperties(std::optional<bool> resetSpecialWorldProperties, std::optional<bool> resetWorldProperties, std::optional<bool> resetWeatherProperties, std::optional<bool> resetLODs, std::optional<bool> resetSounds) noexcept;


static CLuaMultiReturn<bool, CClientEntity*, float, float, float, int, int, int> TestSphereAgainstWorld(CVector sphereCenter, float radius, std::optional<CClientEntity*> ignoredEntity, std::optional<bool> checkBuildings, std::optional<bool> checkVehicles, std::optional<bool> checkPeds, std::optional<bool> checkObjects, std::optional<bool> checkDummies, std::optional<bool> cameraIgnore);

};

11 changes: 11 additions & 0 deletions Client/sdk/game/CWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ struct SProcessLineOfSightMaterialInfoResult {
bool valid{}; //< Data found in this struct is only valid if this is `true`!
};

struct STestSphereAgainstWorldResult
{
bool collisionDetected{false};
CVector hitPosition{};
std::uint32_t modelID{0};
std::uint32_t lodID{0};
std::uint8_t type{0};
FileEX marked this conversation as resolved.
Show resolved Hide resolved
};

enum eDebugCaller
{
CEntity_SetMatrix,
Expand Down Expand Up @@ -274,4 +283,6 @@ class CWorld
virtual CSurfaceType* GetSurfaceInfo() = 0;
virtual void ResetAllSurfaceInfo() = 0;
virtual bool ResetSurfaceInfo(short sSurfaceID) = 0;

virtual CEntity* TestSphereAgainstWorld(const CVector& sphereCenter, float radius, CEntity* ignoredEntity, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool cameraIgnore, STestSphereAgainstWorldResult& result) = 0;
};
Loading