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 isVehicleNitroActivated to serverside #3735

Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions Client/mods/deathmatch/logic/CNetAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,15 @@ void CNetAPI::ReadVehiclePuresync(CClientPlayer* pPlayer, CClientVehicle* pVehic
pPlayer->SetLastPuresyncTime(CClientTime::GetTime());
pPlayer->IncrementVehicleSync();
pPlayer->SetLastPuresyncType(PURESYNC_TYPE_PURESYNC);

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
{
float vehicleNitro;
if (!BitStream.Read(vehicleNitro))
return;

pVehicle->SetNitroLevel(vehicleNitro);
}
}

void CNetAPI::WriteVehiclePuresync(CClientPed* pPlayerModel, CClientVehicle* pVehicle, NetBitStreamInterface& BitStream)
Expand Down Expand Up @@ -1768,6 +1777,9 @@ void CNetAPI::WriteVehiclePuresync(CClientPed* pPlayerModel, CClientVehicle* pVe

// Write the sent position to the interpolator
AddInterpolation(vecPosition);

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
BitStream.Write(static_cast<std::int8_t>(pVehicle->GetNitroLevel()));
}

bool CNetAPI::ReadSmallKeysync(CControllerState& ControllerState, NetBitStreamInterface& BitStream)
Expand Down
8 changes: 8 additions & 0 deletions Server/mods/deathmatch/logic/CVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ class CVehicle final : public CElement
CPed* GetJackingPed() { return m_pJackingPed; }
void SetJackingPed(CPed* pPed);

float GetNitroLevel() const noexcept { return m_nitroLevel; }
void SetNitroLevel(float level) noexcept { m_nitroLevel = level; }

bool IsNitroActivated() const noexcept { return m_nitroLevel > 0; }
void SetNitroActivated(bool activated) noexcept { m_nitroLevel = activated ? 1 : 0; }

bool IsInWater() { return m_bInWater; }
void SetInWater(bool bInWater) { m_bInWater = bInWater; }

Expand Down Expand Up @@ -453,6 +459,8 @@ class CVehicle final : public CElement
bool m_bNeedsDimensionResync;
ushort m_usLastUnoccupiedSyncDimension;

float m_nitroLevel;

public: // 'Safe' variables (that have no need for accessors)
bool m_bDamageProof;
uint m_uiDamageInfoSendPhase;
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class CLuaVehicleDefs : public CLuaDefs
LUA_DECLARE(GetVehicleHeadLightColor);
LUA_DECLARE(GetVehicleDoorOpenRatio);

static bool IsVehicleNitroActivated(CVehicle* vehicle) noexcept;
static float GetVehicleNitroLevel(CVehicle* vehicle) noexcept;
static void SetVehicleNitroLevel(CVehicle* vehicle, std::int8_t level) noexcept;

// Vehicle set functions
LUA_DECLARE(FixVehicle);
LUA_DECLARE(SetVehicleRotation);
Expand Down
15 changes: 15 additions & 0 deletions Server/mods/deathmatch/logic/net/CSimVehiclePuresyncPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ bool CSimVehiclePuresyncPacket::Read(NetBitStreamInterface& BitStream)
m_sharedControllerState.RightShoulder2 = BitStream.ReadBit() * 255;
}


if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
{
float vehicleNitro;
if (!BitStream.Read(vehicleNitro))
return false;

m_Cache.VehNitroLevel = vehicleNitro;
}

// Success
return true;
}
Expand Down Expand Up @@ -418,6 +428,11 @@ bool CSimVehiclePuresyncPacket::Write(NetBitStreamInterface& BitStream) const
BitStream.Write(&damage);
}

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
{
BitStream.Write(m_Cache.VehNitroLevel);
}

// Success
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CSimVehiclePuresyncPacket : public CSimPacket
CVector VehRotationDeg;
CVector BothVelocity;
CVector VehTurnSpeed;
float VehNitroLevel;

float fVehHealth;

Expand Down
14 changes: 14 additions & 0 deletions Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,15 @@ bool CVehiclePuresyncPacket::Read(NetBitStreamInterface& BitStream)

pSourcePlayer->GetPad()->NewControllerState(ControllerState);

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
{
float vehicleNitro;
if (!BitStream.Read(vehicleNitro))
return false;

pVehicle->SetNitroLevel(vehicleNitro);
}

// Success
return true;
}
Expand Down Expand Up @@ -676,6 +685,11 @@ bool CVehiclePuresyncPacket::Write(NetBitStreamInterface& BitStream) const
BitStream.Write(&damage);
}

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
{
BitStream.Write(pVehicle->GetNitroLevel());
}

// Success
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ enum class eBitStreamVersion : unsigned short
// 2024-09-04
RespawnObject_Serverside,

// Add "isVehicleNitroActivated" to serverside
// 2024-09-18
IsVehicleNitroActivated_Serverside,

// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
// Make sure you only add things above this comment.
Next,
Expand Down
Loading