Code cleanup, prepare fo ProjectileSync

This commit is contained in:
sausage
2022-05-23 15:27:51 +08:00
parent d1ffab6058
commit 7523be02b5
9 changed files with 92 additions and 120 deletions

View File

@ -68,7 +68,6 @@ namespace RageCoop.Client.Menus.Sub
Main.Settings.PassengerKey.ToString(), 20));
_passengerKey.AltTitle=Main.Settings.PassengerKey.ToString();
Util.SaveSettings();
}
catch { }
}

View File

@ -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; }
}
}

View File

@ -82,12 +82,6 @@ namespace RageCoop.Client
public Dictionary<byte, short> Clothes { get; set; }
public float Heading { get; set; }
/// <summary>
/// The latest character position (may not have been applied yet)
/// </summary>
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
/// <summary>
/// The latest character rotation (may not have been applied yet)
/// </summary>
public Vector3 Rotation { get; internal set; }
public byte Speed { get; set; }
private bool _lastIsJumping = false;
public bool IsJumping { get; set; }

View File

@ -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; }

View File

@ -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
}

View File

@ -34,11 +34,11 @@ namespace RageCoop.Core
List<byte> byteArray = new List<byte>();
// 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<byte> byteArray = new List<byte>();
// 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();

View File

@ -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<byte> byteArray = new List<byte>();
// 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
}
}
}

View File

@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Lidgren.Network;
namespace RageCoop.Core
{
public partial class Packets
{
/// <summary>
/// Non-critical stuff, such as damage model, landing gear, health, etc..
/// </summary>
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<byte> byteArray = new List<byte>();
// 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();
}
}
}
}

View File

@ -228,7 +228,7 @@ namespace RageCoop.Core
List<byte> byteArray = new List<byte>();
// Write vehicle id
byteArray.AddRange(BitConverter.GetBytes(ID));
byteArray.AddInt(ID);
// Write position
byteArray.AddLVector3(Position);