Skip to content

Commit 71d335f

Browse files
committed
Changes & review
1 parent 7ad9e20 commit 71d335f

File tree

7 files changed

+66
-40
lines changed

7 files changed

+66
-40
lines changed

Client/game_sa/CVehicleSA.cpp

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,27 @@ void _declspec(naked) HOOK_Vehicle_PreRender(void)
5252
}
5353
}
5454

55-
bool CanProcessFlyingCarStuff(CHeliSAInterface* heliInterface)
55+
static bool __fastcall CanProcessFlyingCarStuff(CAutomobileSAInterface* vehicleInterface)
5656
{
57-
SClientEntity<CVehicleSA>* vehicle = pGame->GetPools()->GetVehicle((DWORD*)heliInterface);
57+
SClientEntity<CVehicleSA>* vehicle = pGame->GetPools()->GetVehicle((DWORD*)vehicleInterface);
5858
if (!vehicle || !vehicle->pEntity)
5959
return true;
6060

61-
return vehicle->pEntity->GetHeliRotorState();
61+
return vehicle->pEntity->GetVehicleRotorState();
6262
}
6363

64-
void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff()
64+
static constexpr DWORD CONTINUE_CHeli_ProcessFlyingCarStuff = 0x6C4E82;
65+
static constexpr DWORD RETURN_CHeli_ProcessFlyingCarStuff = 0x6C5404;
66+
static void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff()
6567
{
6668
_asm
6769
{
6870
mov esi, ecx
6971
mov al, [esi+36h]
7072

7173
pushad
72-
push ecx
7374
call CanProcessFlyingCarStuff
74-
add esp, 4
75-
76-
movzx eax, al
77-
test eax, eax
75+
test al, al
7876
jz skip
7977

8078
popad
@@ -86,6 +84,30 @@ void _declspec(naked) HOOK_CHeli_ProcessFlyingCarStuff()
8684
}
8785
}
8886

87+
static constexpr DWORD CONTINUE_CPlane_ProcessFlyingCarStuff = 0x6CB7D7;
88+
static constexpr DWORD RETURN_CPlane_ProcessFlyingCarStuff = 0x6CC482;
89+
static void _declspec(naked) HOOK_CPlane_ProcessFlyingCarStuff()
90+
{
91+
_asm
92+
{
93+
push esi
94+
mov esi, ecx
95+
fnstsw ax
96+
97+
pushad
98+
call CanProcessFlyingCarStuff
99+
test al, al
100+
jz skip
101+
102+
popad
103+
jmp CONTINUE_CPlane_ProcessFlyingCarStuff
104+
105+
skip:
106+
popad
107+
jmp RETURN_CPlane_ProcessFlyingCarStuff
108+
}
109+
}
110+
89111
namespace
90112
{
91113
bool ClumpDumpCB(RpAtomic* pAtomic, void* data)
@@ -534,12 +556,17 @@ void CVehicleSA::SetHeliRotorSpeed(float speed)
534556
static_cast<CHeliSAInterface*>(GetInterface())->m_wheelSpeed[1] = speed;
535557
}
536558

537-
void CVehicleSA::SetHeliRotorState(bool state, bool stopRotor) noexcept
559+
void CVehicleSA::SetVehicleRotorState(bool state, bool stopRotor, bool isHeli) noexcept
538560
{
539-
m_heliRotorState = state;
561+
m_rotorState = state;
540562

541-
if (!state && stopRotor)
563+
if (state || !stopRotor)
564+
return;
565+
566+
if (isHeli)
542567
SetHeliRotorSpeed(0.0f);
568+
else
569+
SetPlaneRotorSpeed(0.0f);
543570
}
544571

545572
void CVehicleSA::SetPlaneRotorSpeed(float fSpeed)
@@ -1828,8 +1855,9 @@ void CVehicleSA::StaticSetHooks()
18281855
// Setup vehicle sun glare hook
18291856
HookInstall(FUNC_CAutomobile_OnVehiclePreRender, (DWORD)HOOK_Vehicle_PreRender, 5);
18301857

1831-
// Setup hook to handle setHelicopterRotorState function
1858+
// Setup hooks to handle setVehicleRotorState function
18321859
HookInstall(FUNC_CHeli_ProcessFlyingCarStuff, (DWORD)HOOK_CHeli_ProcessFlyingCarStuff, 5);
1860+
HookInstall(FUNC_CPlane_ProcessFlyingCarStuff, (DWORD)HOOK_CPlane_ProcessFlyingCarStuff, 5);
18331861
}
18341862

18351863
void CVehicleSA::SetVehiclesSunGlareEnabled(bool bEnabled)

Client/game_sa/CVehicleSA.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ struct RwTexture;
9595
#define FUNC_CVehicle_DoSunGlare 0x6DD6F0
9696

9797
#define FUNC_CHeli_ProcessFlyingCarStuff 0x6C4E7D
98-
99-
static constexpr DWORD CONTINUE_CHeli_ProcessFlyingCarStuff = 0x6C4E82;
100-
static constexpr DWORD RETURN_CHeli_ProcessFlyingCarStuff = 0x6C5404;
98+
#define FUNC_CPlane_ProcessFlyingCarStuff 0x6CB7D2
10199

102100
struct SRailNodeSA
103101
{
@@ -415,7 +413,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
415413
unsigned char m_ucVariant2;
416414
unsigned char m_ucVariantCount{0};
417415
bool m_doorsUndamageable{false};
418-
bool m_heliRotorState{true};
416+
bool m_rotorState{true};
419417

420418
std::array<CVector, VEHICLE_DUMMY_COUNT> m_dummyPositions;
421419

@@ -547,7 +545,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
547545
bool GetTyresDontBurst() { return GetVehicleInterface()->m_nVehicleFlags.bTyresDontBurst; };
548546
unsigned short GetAdjustablePropertyValue() { return *reinterpret_cast<unsigned short*>(reinterpret_cast<unsigned long>(m_pInterface) + 2156); };
549547
float GetHeliRotorSpeed() const;
550-
bool GetHeliRotorState() const noexcept override { return m_heliRotorState; }
548+
bool GetVehicleRotorState() const noexcept override { return m_rotorState; }
551549
float GetPlaneRotorSpeed();
552550

553551
unsigned long GetExplodeTime() { return *reinterpret_cast<unsigned long*>(reinterpret_cast<unsigned int>(m_pInterface) + 1240); };
@@ -574,7 +572,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
574572
*reinterpret_cast<unsigned short*>(reinterpret_cast<unsigned int>(m_pInterface) + 2156) = usAdjustableProperty;
575573
};
576574
void SetHeliRotorSpeed(float speed);
577-
void SetHeliRotorState(bool state, bool stopRotor) noexcept override;
575+
void SetVehicleRotorState(bool state, bool stopRotor, bool isHeli) noexcept override;
578576
void SetPlaneRotorSpeed(float fSpeed);
579577
bool SetVehicleWheelRotation(float fWheelRot1, float fWheelRot2, float fWheelRot3, float fWheelRot4) noexcept;
580578
void SetExplodeTime(unsigned long ulTime) { *reinterpret_cast<unsigned long*>(reinterpret_cast<unsigned int>(m_pInterface) + 1240) = ulTime; };

Client/mods/deathmatch/logic/CClientVehicle.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,15 +1576,15 @@ void CClientVehicle::SetHeliRotorSpeed(float fSpeed)
15761576
m_fHeliRotorSpeed = fSpeed;
15771577
}
15781578

1579-
bool CClientVehicle::GetHeliRotorState() const noexcept
1579+
bool CClientVehicle::GetVehicleRotorState() const noexcept
15801580
{
1581-
return m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI ? m_pVehicle->GetHeliRotorState() : m_heliRotorState;
1581+
return m_pVehicle && (m_eVehicleType == CLIENTVEHICLE_HELI || m_eVehicleType == CLIENTVEHICLE_PLANE) ? m_pVehicle->GetVehicleRotorState() : m_heliRotorState;
15821582
}
15831583

1584-
void CClientVehicle::SetHeliRotorState(bool state, bool stopRotor) noexcept
1584+
void CClientVehicle::SetVehicleRotorState(bool state, bool stopRotor) noexcept
15851585
{
1586-
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI)
1587-
m_pVehicle->SetHeliRotorState(state, stopRotor);
1586+
if (m_pVehicle && (m_eVehicleType == CLIENTVEHICLE_HELI || m_eVehicleType == CLIENTVEHICLE_PLANE))
1587+
m_pVehicle->SetVehicleRotorState(state, stopRotor, GetVehicleType() == CLIENTVEHICLE_HELI);
15881588

15891589
m_heliRotorState = state;
15901590
}

Client/mods/deathmatch/logic/CClientVehicle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,12 @@ class CClientVehicle : public CClientStreamElement
299299
// TODO: Make the class remember on virtualization
300300
float GetHeliRotorSpeed();
301301
float GetPlaneRotorSpeed();
302-
bool GetHeliRotorState() const noexcept;
302+
bool GetVehicleRotorState() const noexcept;
303303

304304
bool GetRotorSpeed(float&);
305305
bool SetRotorSpeed(float);
306306
bool SetWheelsRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept;
307-
void SetHeliRotorState(bool state, bool stopRotor) noexcept;
307+
void SetVehicleRotorState(bool state, bool stopRotor) noexcept;
308308
void SetHeliRotorSpeed(float fSpeed);
309309
void SetPlaneRotorSpeed(float fSpeed);
310310
bool IsHeliSearchLightVisible();

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void CLuaVehicleDefs::LoadFunctions()
9292
{"getVehicleModelWheelSize", ArgumentParser<GetVehicleModelWheelSize>},
9393
{"getVehicleWheelFrictionState", ArgumentParser<GetVehicleWheelFrictionState>},
9494
{"getVehicleEntryPoints", ArgumentParser<GetVehicleEntryPoints>},
95-
{"getHelicopterRotorState", ArgumentParser<GetHeliRotorState>},
95+
{"getVehicleRotorState", ArgumentParser<GetVehicleRotorState>},
9696

9797
// Vehicle set funcs
9898
{"createVehicle", CreateVehicle},
@@ -156,7 +156,7 @@ void CLuaVehicleDefs::LoadFunctions()
156156
{"setVehicleVariant", ArgumentParser<SetVehicleVariant>},
157157
{"setVehicleWheelScale", ArgumentParser<SetVehicleWheelScale>},
158158
{"setVehicleModelWheelSize", ArgumentParser<SetVehicleModelWheelSize>},
159-
{"setHelicopterRotorState", ArgumentParser<SetHeliRotorState>},
159+
{"setVehicleRotorState", ArgumentParser<SetVehicleRotorState>},
160160
};
161161

162162
// Add functions
@@ -245,7 +245,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
245245
lua_classfunction(luaVM, "getModelWheelSize", "getVehicleModelWheelSize");
246246
lua_classfunction(luaVM, "getWheelFrictionState", "getVehicleWheelFrictionState");
247247
lua_classfunction(luaVM, "getEntryPoints", ArgumentParser<OOP_GetVehicleEntryPoints>);
248-
lua_classfunction(luaVM, "getRotorState", "getHelicopterRotorState");
248+
lua_classfunction(luaVM, "getRotorState", "getVehicleRotorState");
249249

250250
lua_classfunction(luaVM, "setComponentVisible", "setVehicleComponentVisible");
251251
lua_classfunction(luaVM, "setSirensOn", "setVehicleSirensOn");
@@ -294,7 +294,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
294294
lua_classfunction(luaVM, "setVariant", "setVehicleVariant");
295295
lua_classfunction(luaVM, "setWheelScale", "setVehicleWheelScale");
296296
lua_classfunction(luaVM, "setModelWheelSize", "setVehicleModelWheelSize");
297-
lua_classfunction(luaVM, "setRotorState", "setHelicopterRotorState");
297+
lua_classfunction(luaVM, "setRotorState", "setVehicleRotorState");
298298

299299
lua_classfunction(luaVM, "resetComponentPosition", "resetVehicleComponentPosition");
300300
lua_classfunction(luaVM, "resetComponentRotation", "resetVehicleComponentRotation");
@@ -351,7 +351,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
351351
lua_classvariable(luaVM, "gravity", SetVehicleGravity, OOP_GetVehicleGravity);
352352
lua_classvariable(luaVM, "turnVelocity", SetVehicleTurnVelocity, OOP_GetVehicleTurnVelocity);
353353
lua_classvariable(luaVM, "wheelScale", "setVehicleWheelScale", "getVehicleWheelScale");
354-
lua_classvariable(luaVM, "rotorState", "setHelicopterRotorState", "getHelicopterRotorState");
354+
lua_classvariable(luaVM, "rotorState", "setVehicleRotorState", "getVehicleRotorState");
355355

356356
lua_registerclass(luaVM, "Vehicle", "Element");
357357
}
@@ -4279,16 +4279,16 @@ std::variant<bool, std::array<CVector, 4>> CLuaVehicleDefs::OOP_GetVehicleEntryP
42794279
return entryPoints;
42804280
}
42814281

4282-
bool CLuaVehicleDefs::SetHeliRotorState(CClientVehicle* vehicle, bool state, std::optional<bool> stopRotor) noexcept
4282+
bool CLuaVehicleDefs::SetVehicleRotorState(CClientVehicle* vehicle, bool state, std::optional<bool> stopRotor) noexcept
42834283
{
4284-
if (vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_HELI)
4284+
if (vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_HELI && vehicle->GetVehicleType() != eClientVehicleType::CLIENTVEHICLE_PLANE)
42854285
return false;
42864286

4287-
vehicle->SetHeliRotorState(state, stopRotor.value_or(true));
4287+
vehicle->SetVehicleRotorState(state, stopRotor.value_or(true));
42884288
return true;
42894289
}
42904290

4291-
bool CLuaVehicleDefs::GetHeliRotorState(CClientVehicle* vehicle) noexcept
4291+
bool CLuaVehicleDefs::GetVehicleRotorState(CClientVehicle* vehicle) noexcept
42924292
{
4293-
return vehicle->GetHeliRotorState();
4293+
return vehicle->GetVehicleRotorState();
42944294
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ class CLuaVehicleDefs : public CLuaDefs
166166
static bool SetVehicleModelWheelSize(const unsigned short usModel, const eResizableVehicleWheelGroup eWheelGroup, const float fWheelSize);
167167
static int GetVehicleWheelFrictionState(CClientVehicle* pVehicle, unsigned char wheel);
168168

169-
static bool SetHeliRotorState(CClientVehicle* const vehicle, bool state, std::optional<bool> stopRotor) noexcept;
170-
static bool GetHeliRotorState(CClientVehicle* const vehicle) noexcept;
169+
static bool SetVehicleRotorState(CClientVehicle* const vehicle, bool state, std::optional<bool> stopRotor) noexcept;
170+
static bool GetVehicleRotorState(CClientVehicle* const vehicle) noexcept;
171171

172172
// Components
173173
LUA_DECLARE(SetVehicleComponentPosition);

Client/sdk/game/CVehicle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class CVehicle : public virtual CPhysical
199199
virtual bool GetTyresDontBurst() = 0;
200200
virtual unsigned short GetAdjustablePropertyValue() = 0;
201201
virtual float GetHeliRotorSpeed() const = 0;
202-
virtual bool GetHeliRotorState() const noexcept = 0;
202+
virtual bool GetVehicleRotorState() const noexcept = 0;
203203
virtual float GetPlaneRotorSpeed() = 0;
204204
virtual unsigned long GetExplodeTime() = 0;
205205

@@ -221,7 +221,7 @@ class CVehicle : public virtual CPhysical
221221
virtual void SetTyresDontBurst(bool bTyresDontBurst) = 0;
222222
virtual void SetAdjustablePropertyValue(unsigned short usAdjustableProperty) = 0;
223223
virtual void SetHeliRotorSpeed(float fSpeed) = 0;
224-
virtual void SetHeliRotorState(bool state, bool stopRotor) noexcept = 0;
224+
virtual void SetVehicleRotorState(bool state, bool stopRotor, bool isHeli) noexcept = 0;
225225
virtual void SetPlaneRotorSpeed(float fSpeed) = 0;
226226
virtual bool SetVehicleWheelRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept = 0;
227227
virtual void SetTaxiLightOn(bool bLightState) = 0;

0 commit comments

Comments
 (0)