From 6aefef1647dfe099dc5dd8595401e42a5250d319 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:33:56 +0300 Subject: [PATCH 1/8] adding setVehicleNitroActivated server side --- .../deathmatch/logic/rpc/CVehicleRPCs.cpp | 23 +++++++++++++++++++ .../mods/deathmatch/logic/rpc/CVehicleRPCs.h | 1 + .../logic/luadefs/CLuaVehicleDefs.cpp | 11 +++++++++ .../logic/luadefs/CLuaVehicleDefs.h | 2 ++ Shared/sdk/net/rpc_enums.h | 2 ++ 5 files changed, 39 insertions(+) diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index be586965db..8398bdf54f 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -52,6 +52,7 @@ void CVehicleRPCs::LoadFunctions() AddHandler(REMOVE_VEHICLE_SIRENS, RemoveVehicleSirens, "removeVehicleSirens"); AddHandler(SET_VEHICLE_SIRENS, SetVehicleSirens, "setVehicleSirens"); AddHandler(SET_VEHICLE_PLATE_TEXT, SetVehiclePlateText, "setVehiclePlateText"); + AddHandler(SET_VEHICLE_NITRO_ACTIVATED, SetVehicleNitroActivated, "SetVehicleNitroActivated"); } void CVehicleRPCs::DestroyAllVehicles(NetBitStreamInterface& bitStream) @@ -653,3 +654,25 @@ void CVehicleRPCs::SetVehiclePlateText(CClientEntity* pSourceEntity, NetBitStrea } } } + + +void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBitStreamInterface& bitStream) +{ + bool state; + if (bitStream.ReadBit(state)) + { + CClientVehicle* pVehicle = m_pVehicleManager->Get(pSourceEntity->GetID()); + if (pVehicle) + { + if (pVehicle->IsNitroInstalled()) + { + if (state) + pVehicle->SetNitroLevel(pVehicle->GetNitroLevel() - 1.0001f); + else + pVehicle->SetNitroLevel(pVehicle->GetNitroLevel() + 1.0001f); + + } + } + } + +} diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h index e63d609fdf..c6e4e9b01d 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h @@ -57,4 +57,5 @@ class CVehicleRPCs : public CRPCFunctions DECLARE_ELEMENT_RPC(RemoveVehicleSirens); DECLARE_ELEMENT_RPC(SetVehicleSirens); DECLARE_ELEMENT_RPC(SetVehiclePlateText); + DECLARE_ELEMENT_RPC(SetVehicleNitroActivated); }; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 294ea7310c..1c26b7b1b3 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -126,6 +126,7 @@ void CLuaVehicleDefs::LoadFunctions() {"getVehicleSirens", GetVehicleSirens}, {"getVehicleSirenParams", GetVehicleSirenParams}, {"setVehiclePlateText", SetVehiclePlateText}, + {"setVehicleNitroActivated", ArgumentParser }, }; // Add functions @@ -2982,3 +2983,13 @@ int CLuaVehicleDefs::SetVehiclePlateText(lua_State* luaVM) lua_pushboolean(luaVM, false); return 1; } + + +bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* pVehicle, bool state) +{ + CBitStream BitStream; + BitStream.pBitStream->WriteBit(state); + + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, SET_VEHICLE_NITRO_ACTIVATED, *BitStream.pBitStream)); + return true; +} diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index 3200e2ada3..e7d1e0b81b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -125,4 +125,6 @@ class CLuaVehicleDefs : public CLuaDefs LUA_DECLARE(GetVehicleSirens); LUA_DECLARE(GetVehicleSirenParams); LUA_DECLARE(SetVehiclePlateText); + + static bool SetVehicleNitroActivated(CVehicle* pVehicle, bool state); }; diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index dd4b24b609..9a20b9c6e8 100644 --- a/Shared/sdk/net/rpc_enums.h +++ b/Shared/sdk/net/rpc_enums.h @@ -286,5 +286,7 @@ enum eElementRPCFunctions RESPAWN_OBJECT, TOGGLE_OBJECT_RESPAWN, + SET_VEHICLE_NITRO_ACTIVATED, + NUM_RPC_FUNCS // Add above this line }; From 542586fc8e2663c3d217d59238c7926c23ea0f20 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Sun, 8 Sep 2024 21:27:05 +0300 Subject: [PATCH 2/8] review --- .../deathmatch/logic/rpc/CVehicleRPCs.cpp | 30 +++++++++---------- .../logic/luadefs/CLuaVehicleDefs.cpp | 2 +- .../logic/luadefs/CLuaVehicleDefs.h | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index 8398bdf54f..b6cd8dfbcc 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -659,20 +659,20 @@ void CVehicleRPCs::SetVehiclePlateText(CClientEntity* pSourceEntity, NetBitStrea void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBitStreamInterface& bitStream) { bool state; - if (bitStream.ReadBit(state)) - { - CClientVehicle* pVehicle = m_pVehicleManager->Get(pSourceEntity->GetID()); - if (pVehicle) - { - if (pVehicle->IsNitroInstalled()) - { - if (state) - pVehicle->SetNitroLevel(pVehicle->GetNitroLevel() - 1.0001f); - else - pVehicle->SetNitroLevel(pVehicle->GetNitroLevel() + 1.0001f); - - } - } - } + if (!bitStream.ReadBit(state)) + return; + + CClientVehicle* pVehicle = m_pVehicleManager->Get(pSourceEntity->GetID()); + if (!pVehicle) + return; + + if (!pVehicle->IsNitroInstalled()) + return; + + // Apply nitro level change + if (state) + pVehicle->SetNitroLevel(pVehicle->GetNitroLevel() - 1.0001f); + else + pVehicle->SetNitroLevel(pVehicle->GetNitroLevel() + 1.0001f); } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 1c26b7b1b3..7adfad6090 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -2985,7 +2985,7 @@ int CLuaVehicleDefs::SetVehiclePlateText(lua_State* luaVM) } -bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* pVehicle, bool state) +bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* pVehicle, bool state) noexcept { CBitStream BitStream; BitStream.pBitStream->WriteBit(state); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index e7d1e0b81b..8a57775bd0 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -126,5 +126,5 @@ class CLuaVehicleDefs : public CLuaDefs LUA_DECLARE(GetVehicleSirenParams); LUA_DECLARE(SetVehiclePlateText); - static bool SetVehicleNitroActivated(CVehicle* pVehicle, bool state); + static bool SetVehicleNitroActivated(CVehicle* pVehicle, bool state) noexcept; }; From 53b46d004f5ddd6277838e1558daa58397eb484a Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Sun, 8 Sep 2024 22:01:20 +0300 Subject: [PATCH 3/8] review --- Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp | 10 +++++----- .../mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp | 6 +++--- Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index b6cd8dfbcc..f1b1fb3d04 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -662,17 +662,17 @@ void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBit if (!bitStream.ReadBit(state)) return; - CClientVehicle* pVehicle = m_pVehicleManager->Get(pSourceEntity->GetID()); - if (!pVehicle) + CClientVehicle* vehicle = m_pVehicleManager->Get(pSourceEntity->GetID()); + if (!vehicle) return; - if (!pVehicle->IsNitroInstalled()) + if (!vehicle->IsNitroInstalled()) return; // Apply nitro level change if (state) - pVehicle->SetNitroLevel(pVehicle->GetNitroLevel() - 1.0001f); + vehicle->SetNitroLevel(vehicle->GetNitroLevel() - 1.0001f); else - pVehicle->SetNitroLevel(pVehicle->GetNitroLevel() + 1.0001f); + vehicle->SetNitroLevel(vehicle->GetNitroLevel() + 1.0001f); } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 7adfad6090..4b078bb1eb 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -126,7 +126,7 @@ void CLuaVehicleDefs::LoadFunctions() {"getVehicleSirens", GetVehicleSirens}, {"getVehicleSirenParams", GetVehicleSirenParams}, {"setVehiclePlateText", SetVehiclePlateText}, - {"setVehicleNitroActivated", ArgumentParser }, + {"setVehicleNitroActivated", ArgumentParser}, }; // Add functions @@ -2985,11 +2985,11 @@ int CLuaVehicleDefs::SetVehiclePlateText(lua_State* luaVM) } -bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* pVehicle, bool state) noexcept +bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept { CBitStream BitStream; BitStream.pBitStream->WriteBit(state); - m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, SET_VEHICLE_NITRO_ACTIVATED, *BitStream.pBitStream)); + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(vehicle, SET_VEHICLE_NITRO_ACTIVATED, *BitStream.pBitStream)); return true; } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index 8a57775bd0..e742003c91 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -126,5 +126,5 @@ class CLuaVehicleDefs : public CLuaDefs LUA_DECLARE(GetVehicleSirenParams); LUA_DECLARE(SetVehiclePlateText); - static bool SetVehicleNitroActivated(CVehicle* pVehicle, bool state) noexcept; + static bool SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept; }; From b2d8c17283fee1e49f2902551d4651d1b2e54f88 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Sun, 8 Sep 2024 22:02:38 +0300 Subject: [PATCH 4/8] white space --- Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 4b078bb1eb..106eb26239 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -2984,7 +2984,6 @@ int CLuaVehicleDefs::SetVehiclePlateText(lua_State* luaVM) return 1; } - bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept { CBitStream BitStream; From f10cefe65468bd830e3b60a53ef1442bd6897409 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Tue, 10 Sep 2024 00:55:33 +0300 Subject: [PATCH 5/8] review --- Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index f1b1fb3d04..b7faaf43fd 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -658,9 +658,7 @@ void CVehicleRPCs::SetVehiclePlateText(CClientEntity* pSourceEntity, NetBitStrea void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBitStreamInterface& bitStream) { - bool state; - if (!bitStream.ReadBit(state)) - return; + bool state = bitStream.ReadBit(); CClientVehicle* vehicle = m_pVehicleManager->Get(pSourceEntity->GetID()); if (!vehicle) @@ -674,5 +672,4 @@ void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBit vehicle->SetNitroLevel(vehicle->GetNitroLevel() - 1.0001f); else vehicle->SetNitroLevel(vehicle->GetNitroLevel() + 1.0001f); - } From 96c2a97490e0d38979f140cededa82d2d0567d43 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Tue, 10 Sep 2024 17:29:42 +0300 Subject: [PATCH 6/8] check nitro active or not --- Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index b7faaf43fd..4459c5e464 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -665,7 +665,11 @@ void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBit return; if (!vehicle->IsNitroInstalled()) - return; + return; + + // If nitro level < 0, nitro is activated. (until nitro level reaches -1, at that point it will become 0 and increase instead of decrease) + if ((vehicle->GetNitroLevel() < 0) == state) + return; // Apply nitro level change if (state) From ec6a4ad79fb01b022c2ac002e464f8a65576dacb Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:41:45 +0300 Subject: [PATCH 7/8] correct type --- Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index 4459c5e464..191e02b2d2 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -668,7 +668,7 @@ void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBit return; // If nitro level < 0, nitro is activated. (until nitro level reaches -1, at that point it will become 0 and increase instead of decrease) - if ((vehicle->GetNitroLevel() < 0) == state) + if ((vehicle->GetNitroLevel() < 0.0f) == state) return; // Apply nitro level change From 752a094cfbfa461fed2765f0a907915ef5666c6a Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:17:43 +0300 Subject: [PATCH 8/8] space --- Shared/sdk/net/rpc_enums.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index 4a1cc498e1..769339d393 100644 --- a/Shared/sdk/net/rpc_enums.h +++ b/Shared/sdk/net/rpc_enums.h @@ -285,7 +285,6 @@ enum eElementRPCFunctions RESPAWN_OBJECT, TOGGLE_OBJECT_RESPAWN, - RESET_WORLD_PROPERTIES, SET_VEHICLE_NITRO_ACTIVATED,