From 376830d6dc7da1cf6bfadffab02a56e242156ac0 Mon Sep 17 00:00:00 2001 From: Sardelka Date: Sun, 19 Jun 2022 13:36:23 +0800 Subject: [PATCH] Add RoofState sync. --- RageCoop.Client/Networking/Receive.cs | 1 + RageCoop.Client/Networking/Send.cs | 1 + RageCoop.Client/Sync/Entities/SyncedPed.cs | 1 - RageCoop.Client/Sync/Entities/SyncedVehicle.cs | 17 ++++------------- RageCoop.Client/Util/VehicleExtensions.cs | 5 ++++- RageCoop.Core/Packets/Packets.cs | 1 + RageCoop.Core/Packets/VehiclePackets.cs | 13 +++++++++++-- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs index e8fb84b..6a4f676 100644 --- a/RageCoop.Client/Networking/Receive.cs +++ b/RageCoop.Client/Networking/Receive.cs @@ -358,6 +358,7 @@ namespace RageCoop.Client v.ModelHash=packet.ModelHash; v.Colors=packet.Colors; v.LandingGear=packet.LandingGear; + v.RoofState=(VehicleRoofState)packet.RoofState; v.EngineRunning = packet.Flag.HasFlag(VehicleDataFlags.IsEngineRunning); v.LightsOn = packet.Flag.HasFlag(VehicleDataFlags.AreLightsOn); v.BrakeLightsOn = packet.Flag.HasFlag(VehicleDataFlags.AreBrakeLightsOn); diff --git a/RageCoop.Client/Networking/Send.cs b/RageCoop.Client/Networking/Send.cs index d832352..916c755 100644 --- a/RageCoop.Client/Networking/Send.cs +++ b/RageCoop.Client/Networking/Send.cs @@ -105,6 +105,7 @@ namespace RageCoop.Client Colors=new byte[] { primaryColor, secondaryColor }, DamageModel=veh.GetVehicleDamageModel(), LandingGear = veh.IsAircraft ? (byte)veh.LandingGearState : (byte)0, + RoofState=(byte)veh.RoofState, Mods = veh.Mods.GetVehicleMods(), ModelHash=veh.Model.Hash, EngineHealth=veh.EngineHealth, diff --git a/RageCoop.Client/Sync/Entities/SyncedPed.cs b/RageCoop.Client/Sync/Entities/SyncedPed.cs index b672531..e79813c 100644 --- a/RageCoop.Client/Sync/Entities/SyncedPed.cs +++ b/RageCoop.Client/Sync/Entities/SyncedPed.cs @@ -598,7 +598,6 @@ namespace RageCoop.Client Function.Call(Hash.GIVE_WEAPON_OBJECT_TO_PED, _lastWeaponObj, MainPed.Handle); } - _lastWeaponComponents = WeaponComponents; } if (Function.Call(Hash.GET_PED_WEAPON_TINT_INDEX,MainPed,CurrentWeaponHash)!=WeaponTint) diff --git a/RageCoop.Client/Sync/Entities/SyncedVehicle.cs b/RageCoop.Client/Sync/Entities/SyncedVehicle.cs index f8da8cd..a43a030 100644 --- a/RageCoop.Client/Sync/Entities/SyncedVehicle.cs +++ b/RageCoop.Client/Sync/Entities/SyncedVehicle.cs @@ -83,7 +83,7 @@ namespace RageCoop.Client internal bool BrakeLightsOn { get; set; } = false; internal bool HighBeamsOn { get; set; } internal byte LandingGear { get; set; } - internal bool RoofOpened { get; set; } + internal VehicleRoofState RoofState { get; set; } internal bool SireneActive { get; set; } internal VehicleDamageModel DamageModel { get; set; } internal int ModelHash { get; set; } @@ -308,13 +308,9 @@ namespace RageCoop.Client MainVehicle.SoundHorn(1); } - if (MainVehicle.HasRoof) + if (MainVehicle.HasRoof && MainVehicle.RoofState!=RoofState) { - bool roofOpened = MainVehicle.RoofState == VehicleRoofState.Opened || MainVehicle.RoofState == VehicleRoofState.Opening; - if (roofOpened != RoofOpened) - { - MainVehicle.RoofState = RoofOpened ? VehicleRoofState.Opening : VehicleRoofState.Closing; - } + MainVehicle.RoofState=RoofState; } Function.Call(Hash.SET_VEHICLE_BRAKE_LIGHTS, MainVehicle.Handle, BrakeLightsOn); @@ -373,14 +369,9 @@ namespace RageCoop.Client EntityPool.Add( this); } MainVehicle.Quaternion = Quaternion; - if (MainVehicle.HasRoof) { - bool roofOpened = MainVehicle.RoofState == VehicleRoofState.Opened || MainVehicle.RoofState == VehicleRoofState.Opening; - if (roofOpened != RoofOpened) - { - MainVehicle.RoofState = RoofOpened ? VehicleRoofState.Opened : VehicleRoofState.Closed; - } + MainVehicle.RoofState=RoofState; } vehicleModel.MarkAsNoLongerNeeded(); } diff --git a/RageCoop.Client/Util/VehicleExtensions.cs b/RageCoop.Client/Util/VehicleExtensions.cs index 9b545f3..4b9429d 100644 --- a/RageCoop.Client/Util/VehicleExtensions.cs +++ b/RageCoop.Client/Util/VehicleExtensions.cs @@ -72,7 +72,10 @@ namespace RageCoop.Client { flags|= VehicleDataFlags.IsDeluxoHovering; } - + if (veh.HasRoof) + { + flags|=VehicleDataFlags.HasRoof; + } return flags; diff --git a/RageCoop.Core/Packets/Packets.cs b/RageCoop.Core/Packets/Packets.cs index 7478143..d52ed00 100644 --- a/RageCoop.Core/Packets/Packets.cs +++ b/RageCoop.Core/Packets/Packets.cs @@ -103,6 +103,7 @@ namespace RageCoop.Core OnTurretSeat = 1 << 9, IsAircraft = 1 << 10, IsDeluxoHovering=1 << 11, + HasRoof=1 << 12, } diff --git a/RageCoop.Core/Packets/VehiclePackets.cs b/RageCoop.Core/Packets/VehiclePackets.cs index ee83d36..ac433fa 100644 --- a/RageCoop.Core/Packets/VehiclePackets.cs +++ b/RageCoop.Core/Packets/VehiclePackets.cs @@ -30,6 +30,7 @@ namespace RageCoop.Core public VehicleDamageModel DamageModel { get; set; } public byte LandingGear { get; set; } + public byte RoofState { get; set; } public VehicleDataFlags Flag { get; set; } @@ -66,7 +67,11 @@ namespace RageCoop.Core if (Flag.HasFlag(VehicleDataFlags.IsAircraft)) { // Write the vehicle landing gear - byteArray.AddRange(BitConverter.GetBytes(LandingGear)); + byteArray.Add(LandingGear); + } + if (Flag.HasFlag(VehicleDataFlags.HasRoof)) + { + byteArray.Add(RoofState); } // Write vehicle colors @@ -151,7 +156,11 @@ namespace RageCoop.Core if (Flag.HasFlag(VehicleDataFlags.IsAircraft)) { // Read vehicle landing gear - LandingGear = (byte)reader.ReadShort(); + LandingGear = reader.ReadByte(); + } + if (Flag.HasFlag(VehicleDataFlags.HasRoof)) + { + RoofState=reader.ReadByte(); } // Read vehicle colors