Skip to content

Commit e2bded1

Browse files
Synchronize changes from 1.6 master branch [ci skip]
bf588c1 Add getVehicleEntryPoints (#2566)
2 parents c6f52ba + bf588c1 commit e2bded1

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

Client/game_sa/CCarEnterExitSA.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ bool CCarEnterExitSA::GetNearestCarPassengerDoor(CPed* pPed, CVehicle* pVehicle,
7878
return bReturn;
7979
}
8080

81+
void CCarEnterExitSA::GetPositionToOpenCarDoor(CVector& position, CVehicle* vehicle, std::uint32_t door) const noexcept
82+
{
83+
CVehicleSA* vehicleSA = dynamic_cast<CVehicleSA*>(vehicle);
84+
85+
if (!vehicleSA)
86+
return;
87+
88+
CVehicleSAInterface* vehicleInterface = vehicleSA->GetVehicleInterface();
89+
90+
auto CCarEnterExit_GetPositionToOpenCarDoor = (void(__cdecl*)(CVector&, CVehicleSAInterface*, int))FUNC_GetPositionToOpenCarDoor;
91+
CCarEnterExit_GetPositionToOpenCarDoor(position, vehicleInterface, door);
92+
}
93+
8194
int CCarEnterExitSA::ComputeTargetDoorToExit(CPed* pPed, CVehicle* pVehicle)
8295
{
8396
DWORD dwFunc = FUNC_ComputeTargetDoorToExit;

Client/game_sa/CCarEnterExitSA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
#define FUNC_GetNearestCarPassengerDoor 0x650BB0
1818
#define FUNC_ComputeTargetDoorToExit 0x64F110
1919
#define FUNC_IsRoomForPedToLeaveCar 0x6504C0
20+
#define FUNC_GetPositionToOpenCarDoor 0x64E740
2021

2122
class CCarEnterExitSA : public CCarEnterExit
2223
{
2324
public:
2425
bool GetNearestCarDoor(CPed* pPed, CVehicle* pVehicle, CVector* pVector, int* pDoor);
2526
bool GetNearestCarPassengerDoor(CPed* pPed, CVehicle* pVehicle, CVector* pVector, int* pDoor, bool bUnknown, bool bUnknown2, bool bCheckIfRoomToGetIn);
27+
void GetPositionToOpenCarDoor(CVector& position, CVehicle* vehicle, std::uint32_t door) const noexcept;
2628
int ComputeTargetDoorToExit(CPed* pPed, CVehicle* pVehicle);
2729
bool IsRoomForPedToLeaveCar(CVehicle* pVehicle, int iDoor, CVector* pUnknown = 0);
2830
};

Client/mods/deathmatch/logic/CClientVehicle.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <game/CBikeHandlingEntry.h>
1414
#include <game/CBoat.h>
1515
#include <game/CBoatHandlingEntry.h>
16+
#include <game/CCarEnterExit.h>
1617
#include <game/CDoor.h>
1718
#include <game/CFlyingHandlingEntry.h>
1819
#include <game/CHandlingEntry.h>
@@ -5031,3 +5032,17 @@ void CClientVehicle::ResetWheelScale()
50315032

50325033
m_bWheelScaleChanged = false;
50335034
}
5035+
5036+
CVector CClientVehicle::GetEntryPoint(std::uint32_t entryPointIndex)
5037+
{
5038+
static const uint32_t lookup[4] = {10, 8, 11, 9};
5039+
assert(entryPointIndex < 4);
5040+
const std::uint32_t saDoorIndex = lookup[entryPointIndex];
5041+
5042+
CVector entryPoint;
5043+
CVehicle* gameVehicle = GetGameVehicle();
5044+
5045+
g_pGame->GetCarEnterExit()->GetPositionToOpenCarDoor(entryPoint, gameVehicle, saDoorIndex);
5046+
5047+
return entryPoint;
5048+
}

Client/mods/deathmatch/logic/CClientVehicle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ class CClientVehicle : public CClientStreamElement
543543
bool SetDummyPosition(eVehicleDummies dummy, const CVector& position);
544544
bool ResetDummyPositions();
545545

546+
CVector GetEntryPoint(std::uint32_t entryPointIndex);
547+
546548
protected:
547549
void ConvertComponentRotationBase(const SString& vehicleComponent, CVector& vecInOutRotation, EComponentBaseType inputBase, EComponentBaseType outputBase);
548550
void ConvertComponentPositionBase(const SString& vehicleComponent, CVector& vecInOutPosition, EComponentBaseType inputBase, EComponentBaseType outputBase);

Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void CLuaVehicleDefs::LoadFunctions()
9191
{"getVehicleWheelScale", ArgumentParser<GetVehicleWheelScale>},
9292
{"getVehicleModelWheelSize", ArgumentParser<GetVehicleModelWheelSize>},
9393
{"getVehicleWheelFrictionState", ArgumentParser<GetVehicleWheelFrictionState>},
94+
{"getVehicleEntryPoints", ArgumentParser<GetVehicleEntryPoints>},
9495

9596
// Vehicle set funcs
9697
{"createVehicle", CreateVehicle},
@@ -241,6 +242,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
241242
lua_classfunction(luaVM, "getWheelScale", "getVehicleWheelScale");
242243
lua_classfunction(luaVM, "getModelWheelSize", "getVehicleModelWheelSize");
243244
lua_classfunction(luaVM, "getWheelFrictionState", "getVehicleWheelFrictionState");
245+
lua_classfunction(luaVM, "getEntryPoints", ArgumentParser<OOP_GetVehicleEntryPoints>);
244246

245247
lua_classfunction(luaVM, "setComponentVisible", "setVehicleComponentVisible");
246248
lua_classfunction(luaVM, "setSirensOn", "setVehicleSirensOn");
@@ -4174,3 +4176,43 @@ bool CLuaVehicleDefs::BlowVehicle(CClientEntity* entity, std::optional<bool> wit
41744176
{
41754177
return CStaticFunctionDefinitions::BlowVehicle(*entity, withExplosion);
41764178
}
4179+
4180+
std::variant<bool, std::array<std::array<float, 3>, 4>> CLuaVehicleDefs::GetVehicleEntryPoints(CClientVehicle* vehicle)
4181+
{
4182+
auto entryPointVectors = OOP_GetVehicleEntryPoints(vehicle);
4183+
4184+
if (std::holds_alternative<bool>(entryPointVectors))
4185+
{
4186+
return false;
4187+
}
4188+
4189+
std::array<std::array<float, 3>, 4> entryPoints;
4190+
std::array<CVector, 4> vectorArray = std::get<std::array<CVector, 4>>(entryPointVectors);
4191+
4192+
std::uint32_t i = 0;
4193+
for (auto& entryPoint : entryPoints)
4194+
{
4195+
entryPoints[i] = {vectorArray[i].fX, vectorArray[i].fY, vectorArray[i].fZ};
4196+
i++;
4197+
}
4198+
4199+
return entryPoints;
4200+
}
4201+
4202+
std::variant<bool, std::array<CVector, 4>> CLuaVehicleDefs::OOP_GetVehicleEntryPoints(CClientVehicle* vehicle)
4203+
{
4204+
if (CClientVehicleManager::GetMaxPassengerCount(vehicle->GetModel()) == 255)
4205+
{
4206+
return false;
4207+
}
4208+
4209+
std::array<CVector, 4> entryPoints;
4210+
4211+
std::uint32_t i = 0;
4212+
for (auto& entryPoint : entryPoints)
4213+
{
4214+
entryPoint = vehicle->GetEntryPoint(i++);
4215+
}
4216+
4217+
return entryPoints;
4218+
}

Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ class CLuaVehicleDefs : public CLuaDefs
152152
static std::variant<bool, CVector> OOP_GetVehicleDummyPosition(CClientVehicle* vehicle, eVehicleDummies dummy);
153153
static bool ResetVehicleDummyPositions(CClientVehicle* vehicle);
154154

155+
static std::variant<bool, std::array<std::array<float, 3>, 4>> GetVehicleEntryPoints(CClientVehicle* vehicle);
156+
static std::variant<bool, std::array<CVector, 4>> OOP_GetVehicleEntryPoints(CClientVehicle* vehicle);
157+
155158
LUA_DECLARE(SetVehicleModelExhaustFumesPosition);
156159
LUA_DECLARE_OOP(GetVehicleModelExhaustFumesPosition);
157160

Client/sdk/game/CCarEnterExit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ class CCarEnterExit
2323
bool bCheckIfRoomToGetIn) = 0;
2424
virtual int ComputeTargetDoorToExit(CPed* pPed, CVehicle* pVehicle) = 0;
2525
virtual bool IsRoomForPedToLeaveCar(CVehicle* pVehicle, int iDoor, CVector* pUnknown = 0) = 0;
26+
27+
virtual void GetPositionToOpenCarDoor(CVector& position, CVehicle* vehicle, std::uint32_t door) const noexcept = 0;
2628
};

0 commit comments

Comments
 (0)