diff --git a/Client/Menus/Sub/SettingsMenu.cs b/Client/Menus/Sub/SettingsMenu.cs index da24022..049b7b6 100644 --- a/Client/Menus/Sub/SettingsMenu.cs +++ b/Client/Menus/Sub/SettingsMenu.cs @@ -68,7 +68,6 @@ namespace RageCoop.Client.Menus.Sub Main.Settings.PassengerKey.ToString(), 20)); _passengerKey.AltTitle=Main.Settings.PassengerKey.ToString(); Util.SaveSettings(); - } catch { } } diff --git a/Client/Sync/Entities/SyncedEntity.cs b/Client/Sync/Entities/SyncedEntity.cs index b7d0910..969e4f5 100644 --- a/Client/Sync/Entities/SyncedEntity.cs +++ b/Client/Sync/Entities/SyncedEntity.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using GTA; +using GTA.Math; namespace RageCoop.Client { @@ -45,5 +46,9 @@ namespace RageCoop.Client public ulong LastUpdated { get; set; } = 0; #endregion + public Vector3 Position { get; set; } + public Vector3 Rotation { get; set; } + public Vector3 Velocity { get; set; } + } } diff --git a/Client/Sync/Entities/SyncedPed.cs b/Client/Sync/Entities/SyncedPed.cs index 2ac490d..c00a1e4 100644 --- a/Client/Sync/Entities/SyncedPed.cs +++ b/Client/Sync/Entities/SyncedPed.cs @@ -82,12 +82,6 @@ namespace RageCoop.Client public Dictionary Clothes { get; set; } public float Heading { get; set; } - - /// - /// The latest character position (may not have been applied yet) - /// - public Vector3 Position { get; internal set; } - public Vector3 Velocity { get; set; } public Vector3 RotationVelocity { get; set; } public Vector3 AimCoords { get; set; } @@ -311,7 +305,6 @@ namespace RageCoop.Client /// /// The latest character rotation (may not have been applied yet) /// - public Vector3 Rotation { get; internal set; } public byte Speed { get; set; } private bool _lastIsJumping = false; public bool IsJumping { get; set; } diff --git a/Client/Sync/Entities/SyncedVehicle.cs b/Client/Sync/Entities/SyncedVehicle.cs index 813af82..cae94ad 100644 --- a/Client/Sync/Entities/SyncedVehicle.cs +++ b/Client/Sync/Entities/SyncedVehicle.cs @@ -66,10 +66,7 @@ namespace RageCoop.Client #endregion #region -- CRITICAL STUFF -- - public Vector3 Position { get; set; } - public Vector3 Velocity { get; set; } public Vector3 RotationVelocity { get; set; } - public Vector3 Rotation { get; set; } public float SteeringAngle { get; set; } public float ThrottlePower { get; set; } public float BrakePower { get; set; } diff --git a/Core/Packets/Packets.cs b/Core/Packets/Packets.cs index 475900d..02f11e3 100644 --- a/Core/Packets/Packets.cs +++ b/Core/Packets/Packets.cs @@ -135,31 +135,20 @@ namespace RageCoop.Core VehicleStateSync = 21, CharacterSync = 22, CharacterStateSync = 23, + ProjectileSync=24, #endregion #region EVENT PedKilled=30, BulletShot=31, - ProjectileShot=32, - ProjectileExploded=33, - EnteringVehicle=34, - LeaveVehicle = 35, - EnteredVehicle=36, - OwnerChanged=37, - VehicleBulletShot = 38, + EnteringVehicle=32, + LeaveVehicle = 33, + EnteredVehicle=34, + OwnerChanged=35, + VehicleBulletShot = 36, #endregion - /// obsolete sync method - /* - FullSyncPlayer = 3, - FullSyncPlayerVeh = 4, - LightSyncPlayer = 5, - LightSyncPlayerVeh = 6, - SuperLightSync = 7, - FullSyncNpc = 8, - FullSyncNpcVeh = 9, - */ #endregion } diff --git a/Core/Packets/PedPackets.cs b/Core/Packets/PedPackets.cs index b17e62a..0775a98 100644 --- a/Core/Packets/PedPackets.cs +++ b/Core/Packets/PedPackets.cs @@ -34,11 +34,11 @@ namespace RageCoop.Core List byteArray = new List(); - // Write player netHandle - byteArray.AddRange(BitConverter.GetBytes(ID)); + // Write ID + byteArray.AddInt(ID); - // Write player model hash - byteArray.AddRange(BitConverter.GetBytes(ModelHash)); + // Write model hash + byteArray.AddInt(ModelHash); // Write player clothes // Write the count of clothes @@ -150,7 +150,7 @@ namespace RageCoop.Core List byteArray = new List(); // Write ped ID - byteArray.AddRange(BitConverter.GetBytes(ID)); + byteArray.AddInt(ID); // Write ped flags @@ -160,19 +160,13 @@ namespace RageCoop.Core byteArray.AddRange(BitConverter.GetBytes(Health)); // Write ped position - byteArray.AddRange(BitConverter.GetBytes(Position.X)); - byteArray.AddRange(BitConverter.GetBytes(Position.Y)); - byteArray.AddRange(BitConverter.GetBytes(Position.Z)); + byteArray.AddLVector3(Position); // Write ped rotation - byteArray.AddRange(BitConverter.GetBytes(Rotation.X)); - byteArray.AddRange(BitConverter.GetBytes(Rotation.Y)); - byteArray.AddRange(BitConverter.GetBytes(Rotation.Z)); + byteArray.AddLVector3(Rotation); // Write ped velocity - byteArray.AddRange(BitConverter.GetBytes(Velocity.X)); - byteArray.AddRange(BitConverter.GetBytes(Velocity.Y)); - byteArray.AddRange(BitConverter.GetBytes(Velocity.Z)); + byteArray.AddLVector3(Velocity); if (Flag.HasFlag(PedDataFlags.IsRagdoll)) { @@ -188,9 +182,7 @@ namespace RageCoop.Core if (Flag.HasFlag(PedDataFlags.IsAiming)) { // Write ped aim coords - byteArray.AddRange(BitConverter.GetBytes(AimCoords.X)); - byteArray.AddRange(BitConverter.GetBytes(AimCoords.Y)); - byteArray.AddRange(BitConverter.GetBytes(AimCoords.Z)); + byteArray.AddLVector3(AimCoords); } byteArray.AddFloat(Heading); @@ -217,28 +209,13 @@ namespace RageCoop.Core Health = reader.ReadInt(); // Read player position - Position = new LVector3() - { - X = reader.ReadFloat(), - Y = reader.ReadFloat(), - Z = reader.ReadFloat() - }; + Position = reader.ReadLVector3(); // Read player rotation - Rotation = new LVector3() - { - X = reader.ReadFloat(), - Y = reader.ReadFloat(), - Z = reader.ReadFloat() - }; + Rotation = reader.ReadLVector3(); // Read player velocity - Velocity = new LVector3() - { - X = reader.ReadFloat(), - Y = reader.ReadFloat(), - Z = reader.ReadFloat() - }; + Velocity = reader.ReadLVector3(); // Read rotation velocity if in ragdoll if (Flag.HasFlag(PedDataFlags.IsRagdoll)) @@ -256,12 +233,7 @@ namespace RageCoop.Core if (Flag.HasFlag(PedDataFlags.IsAiming)) { // Read player aim coords - AimCoords = new LVector3() - { - X = reader.ReadFloat(), - Y = reader.ReadFloat(), - Z = reader.ReadFloat() - }; + AimCoords = reader.ReadLVector3(); } Heading=reader.ReadFloat(); diff --git a/Core/Packets/ProjectileSync.cs b/Core/Packets/ProjectileSync.cs new file mode 100644 index 0000000..92763a6 --- /dev/null +++ b/Core/Packets/ProjectileSync.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Lidgren.Network; + +namespace RageCoop.Core +{ + internal class ProjectileSync:Packet + { + + public int ID { get; set; } + + public LVector3 Position { get; set; } + + public LVector3 Rotation { get; set; } + + public LVector3 Velocity { get; set; } + + + public override void Pack(NetOutgoingMessage message) + { + #region PacketToNetOutGoingMessage + message.Write((byte)PacketTypes.ProjectileSync); + + List byteArray = new List(); + + // Write vehicle id + byteArray.AddInt(ID); + + // Write position + byteArray.AddLVector3(Position); + + + // Write rotation + byteArray.AddLVector3(Rotation); + + // Write velocity + byteArray.AddLVector3(Velocity); + + byte[] result = byteArray.ToArray(); + + message.Write(result.Length); + message.Write(result); + #endregion + } + + public override void Unpack(byte[] array) + { + #region NetIncomingMessageToPacket + BitReader reader = new BitReader(array); + + // Read id + ID = reader.ReadInt(); + + // Read position + Position = reader.ReadLVector3(); + + // Read rotation + Rotation = reader.ReadLVector3(); + + // Read velocity + Velocity =reader.ReadLVector3(); + + #endregion + } + } +} diff --git a/Core/Packets/UpdateOwnerPacket.cs b/Core/Packets/UpdateOwnerPacket.cs deleted file mode 100644 index 7fedf75..0000000 --- a/Core/Packets/UpdateOwnerPacket.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -using Lidgren.Network; - -namespace RageCoop.Core -{ - public partial class Packets - { - /// - /// Non-critical stuff, such as damage model, landing gear, health, etc.. - /// - public class UpdateOwner : Packet - { - public int ID { get; set; } - public int OwnerID { get; set; } - public override void Pack(NetOutgoingMessage message) - { - #region PacketToNetOutGoingMessage - message.Write((byte)PacketTypes.PlayerConnect); - - List byteArray = new List(); - - // Write ID - byteArray.AddRange(BitConverter.GetBytes(ID)); - - // Write OwnerID - byteArray.AddRange(BitConverter.GetBytes(OwnerID)); - - byte[] result = byteArray.ToArray(); - - message.Write(result.Length); - message.Write(result); - #endregion - } - - public override void Unpack(byte[] array) - { - BitReader reader = new BitReader(array); - - // Read player ID - ID = reader.ReadInt(); - - // Read Username - OwnerID = reader.ReadInt(); - } - } - } -} diff --git a/Core/Packets/VehiclePackets.cs b/Core/Packets/VehiclePackets.cs index 3997fdc..28c43bc 100644 --- a/Core/Packets/VehiclePackets.cs +++ b/Core/Packets/VehiclePackets.cs @@ -228,7 +228,7 @@ namespace RageCoop.Core List byteArray = new List(); // Write vehicle id - byteArray.AddRange(BitConverter.GetBytes(ID)); + byteArray.AddInt(ID); // Write position byteArray.AddLVector3(Position);