diff --git a/Client/Menus/RageCoopMenu.cs b/Client/Menus/RageCoopMenu.cs
index 76c8996..4b95987 100644
--- a/Client/Menus/RageCoopMenu.cs
+++ b/Client/Menus/RageCoopMenu.cs
@@ -20,7 +20,7 @@ namespace RageCoop.Client.Menus
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
#region SUB
- public Sub.SettingsMenu SubSettings = new Sub.SettingsMenu();
+ public SettingsMenu SubSettings = new SettingsMenu();
#endregion
#region ITEMS
@@ -51,7 +51,6 @@ namespace RageCoop.Client.Menus
MainMenu.Add(_usernameItem);
MainMenu.Add(ServerIpItem);
MainMenu.Add(_serverConnectItem);
- MainMenu.Add(_aboutItem);
MainMenu.AddSubMenu(SubSettings.Menu);
MainMenu.AddSubMenu(DevToolMenu.Menu);
@@ -63,6 +62,8 @@ namespace RageCoop.Client.Menus
MenuPool.Add(DevToolMenu.Menu);
MenuPool.Add(DebugMenu.Menu);
MenuPool.Add(DebugMenu.DiagnosticMenu);
+
+ MainMenu.Add(_aboutItem);
}
public void UsernameActivated(object a, System.EventArgs b)
@@ -91,25 +92,24 @@ namespace RageCoop.Client.Menus
public void InitiateConnectionMenuSetting()
{
- MainMenu.Items[0].Enabled = false;
- MainMenu.Items[1].Enabled = false;
- MainMenu.Items[2].Enabled = false;
+ _usernameItem.Enabled = false;
+ ServerIpItem.Enabled = false;
+ _serverConnectItem.Enabled = false;
}
public void ConnectedMenuSetting()
{
- MainMenu.Items[2].Enabled = true;
- MainMenu.Items[2].Title = "Disconnect";
+ _serverConnectItem.Enabled = true;
+ _serverConnectItem.Title = "Disconnect";
MainMenu.Visible = false;
}
public void DisconnectedMenuSetting()
{
- MainMenu.Items[0].Enabled = true;
- MainMenu.Items[1].Enabled = true;
- MainMenu.Items[2].Enabled = true;
- MainMenu.Items[2].Title = "Connect";
- SubSettings.Menu.Items[1].Enabled = false;
+ _usernameItem.Enabled = true;
+ ServerIpItem.Enabled = true;
+ _serverConnectItem.Enabled = true;
+ _serverConnectItem.Title = "Connect";
}
}
}
diff --git a/Client/Menus/Sub/SettingsMenu.cs b/Client/Menus/Sub/SettingsMenu.cs
index 78efa18..c9f9827 100644
--- a/Client/Menus/Sub/SettingsMenu.cs
+++ b/Client/Menus/Sub/SettingsMenu.cs
@@ -4,7 +4,7 @@ using System.Windows.Forms;
using GTA;
using LemonUI.Menus;
-namespace RageCoop.Client.Menus.Sub
+namespace RageCoop.Client.Menus
{
///
/// Don't use it!
diff --git a/Client/Misc/Util.cs b/Client/Misc/Util.cs
index b76be24..7dfdf6b 100644
--- a/Client/Misc/Util.cs
+++ b/Client/Misc/Util.cs
@@ -275,7 +275,10 @@ namespace RageCoop.Client
{
flags |=PedDataFlags.IsInCover;
}
-
+ if (ped.IsPlayer)
+ {
+ flags|=PedDataFlags.IsPlayer;
+ }
return flags;
}
@@ -911,35 +914,6 @@ namespace RageCoop.Client
};
return result;
}
-
- ///
- ///
- ///
- public static LVector3 ToLVector(this Vector3 vec)
- {
- return new LVector3()
- {
- X = vec.X,
- Y = vec.Y,
- Z = vec.Z
- };
- }
-
- ///
- ///
- ///
- public static LQuaternion ToLQuaternion(this Quaternion vec)
- {
- return new LQuaternion()
- {
- X = vec.X,
- Y = vec.Y,
- Z = vec.Z,
- W = vec.W
- };
- }
-
-
public static double DegToRad(double deg)
{
return deg * Math.PI / 180.0;
diff --git a/Client/Networking/Networking.cs b/Client/Networking/Networking.cs
index 86a769d..57f8b9e 100644
--- a/Client/Networking/Networking.cs
+++ b/Client/Networking/Networking.cs
@@ -6,7 +6,7 @@ using Lidgren.Network;
using RageCoop.Core;
using System.Threading.Tasks;
using System.Threading;
-using GTA;
+using GTA.Math;
using GTA.Native;
namespace RageCoop.Client
@@ -144,8 +144,8 @@ namespace RageCoop.Client
case string _:
arguments.Add((string)x);
break;
- case LVector3 _:
- LVector3 vector = (LVector3)x;
+ case Vector3 _:
+ Vector3 vector = (Vector3)x;
arguments.Add((float)vector.X);
arguments.Add((float)vector.Y);
arguments.Add((float)vector.Z);
@@ -173,7 +173,7 @@ namespace RageCoop.Client
case 0x03: // string
return Function.Call((Hash)hash, arguments.ToArray());
case 0x04: // vector3
- return Function.Call((Hash)hash, arguments.ToArray()).ToLVector();
+ return Function.Call((Hash)hash, arguments.ToArray());
default:
GTA.UI.Notification.Show("[DecodeNativeCall][" + hash + "]: Type of return not found!");
return null;
diff --git a/Client/Networking/Receive.cs b/Client/Networking/Receive.cs
index e71659a..6ce7f3a 100644
--- a/Client/Networking/Receive.cs
+++ b/Client/Networking/Receive.cs
@@ -307,20 +307,19 @@ namespace RageCoop.Client
private static void PedSync(Packets.PedSync packet)
{
- if (!EntityPool.PedExists(packet.ID))
+ SyncedPed c = EntityPool.GetPedByID(packet.ID);
+ if (c==null)
{
Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}");
-
- EntityPool.ThreadSafe.Add(new SyncedPed(packet.ID));
+ EntityPool.ThreadSafe.Add(c=new SyncedPed(packet.ID));
}
PedDataFlags flags = packet.Flag;
- SyncedPed c = EntityPool.GetPedByID(packet.ID);
c.ID=packet.ID;
//c.OwnerID=packet.OwnerID;
c.Health = packet.Health;
- c.Position = packet.Position.ToVector();
- c.Rotation = packet.Rotation.ToVector();
- c.Velocity = packet.Velocity.ToVector();
+ c.Position = packet.Position;
+ c.Rotation = packet.Rotation;
+ c.Velocity = packet.Velocity;
c.Speed = packet.Speed;
c.CurrentWeaponHash = packet.CurrentWeaponHash;
c.IsAiming = flags.HasFlag(PedDataFlags.IsAiming);
@@ -337,22 +336,17 @@ namespace RageCoop.Client
c.LastSynced = Main.Ticked;
if (c.IsAiming)
{
- c.AimCoords = packet.AimCoords.ToVector();
+ c.AimCoords = packet.AimCoords;
}
if (c.IsRagdoll)
{
- c.RotationVelocity=packet.RotationVelocity.ToVector();
+ c.RotationVelocity=packet.RotationVelocity;
}
}
private static void PedStateSync(Packets.PedStateSync packet)
{
- if (!EntityPool.PedExists(packet.ID))
- {
- Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}");
-
- EntityPool.ThreadSafe.Add(new SyncedPed(packet.ID));
- }
SyncedPed c = EntityPool.GetPedByID(packet.ID);
+ if (c==null) { return; }
c.ID=packet.ID;
c.OwnerID=packet.OwnerID;
c.Clothes=packet.Clothes;
@@ -362,30 +356,26 @@ namespace RageCoop.Client
}
private static void VehicleSync(Packets.VehicleSync packet)
{
- if (!EntityPool.VehicleExists(packet.ID))
+ SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID);
+ if (v==null)
{
- EntityPool.ThreadSafe.Add(new SyncedVehicle(packet.ID));
+ EntityPool.ThreadSafe.Add(v=new SyncedVehicle(packet.ID));
}
- SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID);
if (v.IsMine) { return; }
v.ID= packet.ID;
- v.Position=packet.Position.ToVector();
- v.Rotation=packet.Rotation.ToVector();
+ v.Position=packet.Position;
+ v.Rotation=packet.Rotation;
v.SteeringAngle=packet.SteeringAngle;
v.ThrottlePower=packet.ThrottlePower;
v.BrakePower=packet.BrakePower;
- v.Velocity=packet.Velocity.ToVector();
- v.RotationVelocity=packet.RotationVelocity.ToVector();
+ v.Velocity=packet.Velocity;
+ v.RotationVelocity=packet.RotationVelocity;
v.LastSynced=Main.Ticked;
}
private static void VehicleStateSync(Packets.VehicleStateSync packet)
{
- if (!EntityPool.VehicleExists(packet.ID))
- {
- EntityPool.ThreadSafe.Add(new SyncedVehicle(packet.ID));
- }
SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID);
- if (v.IsMine) { return; }
+ if (v==null||v.IsMine) { return; }
v.ID= packet.ID;
v.OwnerID= packet.OwnerID;
v.DamageModel=packet.DamageModel;
@@ -425,9 +415,9 @@ namespace RageCoop.Client
Main.Logger.Debug($"Creating new projectile: {(WeaponHash)packet.WeaponHash}");
EntityPool.ThreadSafe.Add(p=new SyncedProjectile(packet.ID));
}
- p.Position=packet.Position.ToVector();
- p.Rotation=packet.Rotation.ToVector();
- p.Velocity=packet.Velocity.ToVector();
+ p.Position=packet.Position;
+ p.Rotation=packet.Rotation;
+ p.Velocity=packet.Velocity;
p.Hash=(WeaponHash)packet.WeaponHash;
p.ShooterID=packet.ShooterID;
p.Exploded=packet.Exploded;
diff --git a/Client/Networking/Send.cs b/Client/Networking/Send.cs
index 6701fd6..ec4f26e 100644
--- a/Client/Networking/Send.cs
+++ b/Client/Networking/Send.cs
@@ -36,9 +36,9 @@ namespace RageCoop.Client
{
ID =c.ID,
Health = p.Health,
- Position = p.Position.ToLVector(),
- Rotation = p.Rotation.ToLVector(),
- Velocity = p.Velocity.ToLVector(),
+ Position = p.Position,
+ Rotation = p.Rotation,
+ Velocity = p.Velocity,
Speed = p.GetPedSpeed(),
CurrentWeaponHash = (uint)p.Weapons.Current.Hash,
Flag = p.GetPedFlags(),
@@ -46,11 +46,11 @@ namespace RageCoop.Client
};
if (packet.Flag.HasFlag(PedDataFlags.IsAiming))
{
- packet.AimCoords = p.GetAimCoord().ToLVector();
+ packet.AimCoords = p.GetAimCoord();
}
if (packet.Flag.HasFlag(PedDataFlags.IsRagdoll))
{
- packet.RotationVelocity=p.RotationVelocity.ToLVector();
+ packet.RotationVelocity=p.RotationVelocity;
}
Send(packet, ConnectionChannel.PedSync);
}
@@ -76,10 +76,10 @@ namespace RageCoop.Client
{
ID =v.ID,
SteeringAngle = veh.SteeringAngle,
- Position = veh.PredictPosition().ToLVector(),
- Rotation = veh.Rotation.ToLVector(),
- Velocity = veh.Velocity.ToLVector(),
- RotationVelocity=veh.RotationVelocity.ToLVector(),
+ Position = veh.PredictPosition(),
+ Rotation = veh.Rotation,
+ Velocity = veh.Velocity,
+ RotationVelocity=veh.RotationVelocity,
ThrottlePower = veh.ThrottlePower,
BrakePower = veh.BrakePower,
};
@@ -117,9 +117,9 @@ namespace RageCoop.Client
{
ID =sp.ID,
ShooterID=sp.ShooterID,
- Position=p.Position.ToLVector(),
- Rotation=p.Rotation.ToLVector(),
- Velocity=p.Velocity.ToLVector(),
+ Position=p.Position,
+ Rotation=p.Rotation,
+ Velocity=p.Velocity,
WeaponHash=(uint)p.WeaponHash,
Exploded=p.IsDead
};
@@ -133,8 +133,8 @@ namespace RageCoop.Client
{
Send(new Packets.BulletShot()
{
- StartPosition = start.ToLVector(),
- EndPosition = end.ToLVector(),
+ StartPosition = start,
+ EndPosition = end,
OwnerID = ownerID,
WeaponHash=weapon,
}, ConnectionChannel.SyncEvents);
diff --git a/Client/Sync/EntityPool.cs b/Client/Sync/EntityPool.cs
index 74f3185..1753a2f 100644
--- a/Client/Sync/EntityPool.cs
+++ b/Client/Sync/EntityPool.cs
@@ -288,7 +288,7 @@ namespace RageCoop.Client
var allProjectiles=World.GetAllProjectiles();
if (Main.Settings.WorldVehicleSoftLimit>-1)
{
- if (Main.Ticked%100==0) { if (allVehicles.Length>Main.Settings.WorldVehicleSoftLimit) { SetBudget(0); } else { SetBudget(1); } }
+ if (Main.Ticked%100==0) { if (allVehicles.Length>Main.Settings.WorldVehicleSoftLimit) { SetBudget(0); } else { SetBudget(3); } }
}
#if BENCHMARK
diff --git a/Client/Sync/SyncEvents.cs b/Client/Sync/SyncEvents.cs
index d6839ff..925e55b 100644
--- a/Client/Sync/SyncEvents.cs
+++ b/Client/Sync/SyncEvents.cs
@@ -211,7 +211,7 @@ namespace RageCoop.Client {
{
Packets.BulletShot p = new Packets.BulletShot();
p.Unpack(data);
- HandleBulletShot(p.StartPosition.ToVector(), p.EndPosition.ToVector(), p.WeaponHash, p.OwnerID);
+ HandleBulletShot(p.StartPosition, p.EndPosition, p.WeaponHash, p.OwnerID);
break;
}
case PacketTypes.EnteringVehicle:
diff --git a/Client/WorldThread.cs b/Client/WorldThread.cs
index c428b80..e5ca9cf 100644
--- a/Client/WorldThread.cs
+++ b/Client/WorldThread.cs
@@ -49,7 +49,7 @@ namespace RageCoop.Client
// Values of 2.0 or more make for very aggressive waves like you see during a thunderstorm.
Function.Call(Hash.SET_DEEP_OCEAN_SCALER, 0.0f); // Works only ~200 meters around the player
- Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Game.Player.Character.Handle, true, false);
+ // Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Game.Player.Character.Handle, true, false);
if (Main.Settings==null) { return; }
if (Main.Settings.DisableTraffic)
{
@@ -83,8 +83,8 @@ namespace RageCoop.Client
Function.Call(Hash.SET_RANDOM_TRAINS, true);
Function.Call(Hash.SET_RANDOM_BOATS, true);
Function.Call(Hash.SET_GARBAGE_TRUCKS, true);
- Function.Call(Hash.SET_PED_POPULATION_BUDGET, 1); // 0 - 3
- Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 1); // 0 - 3
+ Function.Call(Hash.SET_PED_POPULATION_BUDGET, 3); // 0 - 3
+ Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 3); // 0 - 3
Function.Call(Hash.SET_ALL_VEHICLE_GENERATORS_ACTIVE);
Function.Call(Hash.SET_ALL_LOW_PRIORITY_VEHICLE_GENERATORS_ACTIVE, true);
Function.Call(Hash.SET_NUMBER_OF_PARKED_VEHICLES, -1);
@@ -99,8 +99,8 @@ namespace RageCoop.Client
Function.Call(Hash.SET_RANDOM_BOATS, false);
Function.Call(Hash.SET_GARBAGE_TRUCKS, false);
Function.Call(Hash.DELETE_ALL_TRAINS);
- Function.Call(Hash.SET_PED_POPULATION_BUDGET, 0);
- Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 0);
+ Function.Call(Hash.SET_PED_POPULATION_BUDGET, 3);
+ Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 3);
Function.Call(Hash.SET_ALL_LOW_PRIORITY_VEHICLE_GENERATORS_ACTIVE, false);
Function.Call(Hash.SET_FAR_DRAW_VEHICLES, false);
Function.Call(Hash.SET_NUMBER_OF_PARKED_VEHICLES, 0);
diff --git a/Core/BitReader.cs b/Core/BitReader.cs
index 2e1a0d2..e405f5b 100644
--- a/Core/BitReader.cs
+++ b/Core/BitReader.cs
@@ -1,6 +1,7 @@
using System;
using System.Text;
using System.Linq;
+using GTA.Math;
namespace RageCoop.Core
{
@@ -103,18 +104,18 @@ namespace RageCoop.Core
return value;
}
- public LVector3 ReadLVector3()
+ public Vector3 ReadVector3()
{
- return new LVector3()
+ return new Vector3()
{
X = ReadFloat(),
Y = ReadFloat(),
Z = ReadFloat()
};
}
- public LQuaternion ReadLQuaternion()
+ public Quaternion ReadLQuaternion()
{
- return new LQuaternion()
+ return new Quaternion()
{
X = ReadFloat(),
Y = ReadFloat(),
diff --git a/Core/CoreUtils.cs b/Core/CoreUtils.cs
index d5fb4c2..0172106 100644
--- a/Core/CoreUtils.cs
+++ b/Core/CoreUtils.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using GTA.Math;
namespace RageCoop.Core
{
public class CoreUtils
@@ -37,13 +38,13 @@ namespace RageCoop.Core
}
public static class Extensions
{
- public static void AddLVector3(this List bytes, LVector3 vec3)
+ public static void AddVector3(this List bytes, Vector3 vec3)
{
bytes.AddRange(BitConverter.GetBytes(vec3.X));
bytes.AddRange(BitConverter.GetBytes(vec3.Y));
bytes.AddRange(BitConverter.GetBytes(vec3.Z));
}
- public static void AddLQuaternion(this List bytes, LQuaternion quat)
+ public static void AddQuaternion(this List bytes, Quaternion quat)
{
bytes.AddRange(BitConverter.GetBytes(quat.X));
bytes.AddRange(BitConverter.GetBytes(quat.Y));
diff --git a/Core/Packets/Packets.cs b/Core/Packets/Packets.cs
index 76bebb3..9e147eb 100644
--- a/Core/Packets/Packets.cs
+++ b/Core/Packets/Packets.cs
@@ -7,6 +7,7 @@ using GTA.Math;
namespace RageCoop.Core
{
+ /*
///
///
///
@@ -111,7 +112,7 @@ namespace RageCoop.Core
///
public float W { get; set; }
}
-
+ */
public enum PacketTypes:byte
{
Handshake=0,
@@ -190,6 +191,7 @@ namespace RageCoop.Core
IsOnLadder = 1 << 8,
IsVaulting = 1 << 9,
IsInCover=1<< 10,
+ IsPlayer=1<<11,
}
#region ===== VEHICLE DATA =====
@@ -493,10 +495,10 @@ namespace RageCoop.Core
byteArray.AddRange(BitConverter.GetBytes(stringBytes.Length));
byteArray.AddRange(stringBytes);
}
- else if (type == typeof(LVector3))
+ else if (type == typeof(Vector3))
{
byteArray.Add(0x04);
- LVector3 vector = (LVector3)x;
+ Vector3 vector = (Vector3)x;
byteArray.AddRange(BitConverter.GetBytes(vector.X));
byteArray.AddRange(BitConverter.GetBytes(vector.Y));
byteArray.AddRange(BitConverter.GetBytes(vector.Z));
@@ -540,7 +542,7 @@ namespace RageCoop.Core
Args.Add(reader.ReadString(stringLength));
break;
case 0x04:
- Args.Add(new LVector3()
+ Args.Add(new Vector3()
{
X = reader.ReadFloat(),
Y = reader.ReadFloat(),
@@ -603,10 +605,10 @@ namespace RageCoop.Core
byteArray.AddRange(BitConverter.GetBytes(stringBytes.Length));
byteArray.AddRange(stringBytes);
}
- else if (type == typeof(LVector3))
+ else if (type == typeof(Vector3))
{
byteArray.Add(0x04);
- LVector3 vector = (LVector3)x;
+ Vector3 vector = (Vector3)x;
byteArray.AddRange(BitConverter.GetBytes(vector.X));
byteArray.AddRange(BitConverter.GetBytes(vector.Y));
byteArray.AddRange(BitConverter.GetBytes(vector.Z));
@@ -658,7 +660,7 @@ namespace RageCoop.Core
Args.Add(reader.ReadString(stringLength));
break;
case 0x04:
- Args.Add(new LVector3()
+ Args.Add(new Vector3()
{
X = reader.ReadFloat(),
Y = reader.ReadFloat(),
diff --git a/Core/Packets/PedPackets.cs b/Core/Packets/PedPackets.cs
index 6119df3..03d8385 100644
--- a/Core/Packets/PedPackets.cs
+++ b/Core/Packets/PedPackets.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
-
+using GTA.Math;
using Lidgren.Network;
namespace RageCoop.Core
@@ -126,17 +126,17 @@ namespace RageCoop.Core
public int Health { get; set; }
- public LVector3 Position { get; set; }
+ public Vector3 Position { get; set; }
- public LVector3 Rotation { get; set; }
+ public Vector3 Rotation { get; set; }
- public LVector3 Velocity { get; set; }
+ public Vector3 Velocity { get; set; }
- public LVector3 RotationVelocity { get; set; }
+ public Vector3 RotationVelocity { get; set; }
public byte Speed { get; set; }
- public LVector3 AimCoords { get; set; }
+ public Vector3 AimCoords { get; set; }
public uint CurrentWeaponHash { get; set; }
@@ -160,17 +160,17 @@ namespace RageCoop.Core
byteArray.AddRange(BitConverter.GetBytes(Health));
// Write ped position
- byteArray.AddLVector3(Position);
+ byteArray.AddVector3(Position);
// Write ped rotation
- byteArray.AddLVector3(Rotation);
+ byteArray.AddVector3(Rotation);
// Write ped velocity
- byteArray.AddLVector3(Velocity);
+ byteArray.AddVector3(Velocity);
if (Flag.HasFlag(PedDataFlags.IsRagdoll))
{
- byteArray.AddLVector3(RotationVelocity);
+ byteArray.AddVector3(RotationVelocity);
}
// Write ped speed
@@ -182,7 +182,7 @@ namespace RageCoop.Core
if (Flag.HasFlag(PedDataFlags.IsAiming))
{
// Write ped aim coords
- byteArray.AddLVector3(AimCoords);
+ byteArray.AddVector3(AimCoords);
}
byteArray.AddFloat(Heading);
@@ -209,18 +209,18 @@ namespace RageCoop.Core
Health = reader.ReadInt();
// Read player position
- Position = reader.ReadLVector3();
+ Position = reader.ReadVector3();
// Read player rotation
- Rotation = reader.ReadLVector3();
+ Rotation = reader.ReadVector3();
// Read player velocity
- Velocity = reader.ReadLVector3();
+ Velocity = reader.ReadVector3();
// Read rotation velocity if in ragdoll
if (Flag.HasFlag(PedDataFlags.IsRagdoll))
{
- RotationVelocity=reader.ReadLVector3();
+ RotationVelocity=reader.ReadVector3();
}
// Read player speed
@@ -233,7 +233,7 @@ namespace RageCoop.Core
if (Flag.HasFlag(PedDataFlags.IsAiming))
{
// Read player aim coords
- AimCoords = reader.ReadLVector3();
+ AimCoords = reader.ReadVector3();
}
Heading=reader.ReadFloat();
diff --git a/Core/Packets/ProjectileSync.cs b/Core/Packets/ProjectileSync.cs
index 7429da1..4b2011b 100644
--- a/Core/Packets/ProjectileSync.cs
+++ b/Core/Packets/ProjectileSync.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
+using GTA.Math;
using Lidgren.Network;
namespace RageCoop.Core
@@ -15,11 +16,11 @@ namespace RageCoop.Core
public int ShooterID { get; set; }
public uint WeaponHash { get; set; }
- public LVector3 Position { get; set; }
+ public Vector3 Position { get; set; }
- public LVector3 Rotation { get; set; }
+ public Vector3 Rotation { get; set; }
- public LVector3 Velocity { get; set; }
+ public Vector3 Velocity { get; set; }
public bool Exploded { get; set; }
@@ -41,14 +42,14 @@ namespace RageCoop.Core
byteArray.AddUint(WeaponHash);
// Write position
- byteArray.AddLVector3(Position);
+ byteArray.AddVector3(Position);
// Write rotation
- byteArray.AddLVector3(Rotation);
+ byteArray.AddVector3(Rotation);
// Write velocity
- byteArray.AddLVector3(Velocity);
+ byteArray.AddVector3(Velocity);
if (Exploded) { byteArray.Add(1); }
@@ -73,13 +74,13 @@ namespace RageCoop.Core
WeaponHash= reader.ReadUInt();
// Read position
- Position = reader.ReadLVector3();
+ Position = reader.ReadVector3();
// Read rotation
- Rotation = reader.ReadLVector3();
+ Rotation = reader.ReadVector3();
// Read velocity
- Velocity =reader.ReadLVector3();
+ Velocity =reader.ReadVector3();
if (reader.CanRead(1))
{
diff --git a/Core/Packets/SyncEvents/BulletShot.cs b/Core/Packets/SyncEvents/BulletShot.cs
index 1e6a02f..bc3f745 100644
--- a/Core/Packets/SyncEvents/BulletShot.cs
+++ b/Core/Packets/SyncEvents/BulletShot.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
-
+using GTA.Math;
using Lidgren.Network;
namespace RageCoop.Core
@@ -15,8 +15,8 @@ namespace RageCoop.Core
public uint WeaponHash { get; set; }
- public LVector3 StartPosition { get; set; }
- public LVector3 EndPosition { get; set; }
+ public Vector3 StartPosition { get; set; }
+ public Vector3 EndPosition { get; set; }
public override void Pack(NetOutgoingMessage message)
{
@@ -32,10 +32,10 @@ namespace RageCoop.Core
byteArray.AddRange(BitConverter.GetBytes(WeaponHash));
// Write StartPosition
- byteArray.AddLVector3(StartPosition);
+ byteArray.AddVector3(StartPosition);
// Write EndPosition
- byteArray.AddLVector3(EndPosition);
+ byteArray.AddVector3(EndPosition);
byte[] result = byteArray.ToArray();
@@ -57,10 +57,10 @@ namespace RageCoop.Core
WeaponHash=reader.ReadUInt();
// Read StartPosition
- StartPosition=reader.ReadLVector3();
+ StartPosition=reader.ReadVector3();
// Read EndPosition
- EndPosition=reader.ReadLVector3();
+ EndPosition=reader.ReadVector3();
#endregion
}
}
diff --git a/Core/Packets/VehiclePackets.cs b/Core/Packets/VehiclePackets.cs
index 28c43bc..db160fa 100644
--- a/Core/Packets/VehiclePackets.cs
+++ b/Core/Packets/VehiclePackets.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using GTA;
+using GTA.Math;
using Lidgren.Network;
namespace RageCoop.Core
@@ -207,13 +208,13 @@ namespace RageCoop.Core
{
public int ID { get; set; }
- public LVector3 Position { get; set; }
+ public Vector3 Position { get; set; }
- public LVector3 Rotation { get; set; }
+ public Vector3 Rotation { get; set; }
- public LVector3 Velocity { get; set; }
+ public Vector3 Velocity { get; set; }
- public LVector3 RotationVelocity { get; set; }
+ public Vector3 RotationVelocity { get; set; }
public float ThrottlePower { get; set; }
public float BrakePower { get; set; }
@@ -231,17 +232,17 @@ namespace RageCoop.Core
byteArray.AddInt(ID);
// Write position
- byteArray.AddLVector3(Position);
+ byteArray.AddVector3(Position);
// Write rotation
- byteArray.AddLVector3(Rotation);
+ byteArray.AddVector3(Rotation);
// Write velocity
- byteArray.AddLVector3(Velocity);
+ byteArray.AddVector3(Velocity);
// Write rotation velocity
- byteArray.AddLVector3(RotationVelocity);
+ byteArray.AddVector3(RotationVelocity);
byteArray.AddFloat(ThrottlePower);
@@ -268,16 +269,16 @@ namespace RageCoop.Core
ID = reader.ReadInt();
// Read position
- Position = reader.ReadLVector3();
+ Position = reader.ReadVector3();
// Read rotation
- Rotation = reader.ReadLVector3();
+ Rotation = reader.ReadVector3();
// Read velocity
- Velocity =reader.ReadLVector3();
+ Velocity =reader.ReadVector3();
// Read rotation velocity
- RotationVelocity=reader.ReadLVector3();
+ RotationVelocity=reader.ReadVector3();
// Read throttle power
ThrottlePower=reader.ReadFloat();
diff --git a/Core/PlayerData.cs b/Core/PlayerData.cs
index 4a5d40b..003e2aa 100644
--- a/Core/PlayerData.cs
+++ b/Core/PlayerData.cs
@@ -1,4 +1,5 @@
using System.Linq;
+using GTA.Math;
namespace RageCoop.Core
{
public class PlayerData
@@ -18,17 +19,12 @@ namespace RageCoop.Core
///
public int VehicleID { get; set; }
public bool IsInVehicle { get; internal set; }
- public LVector3 Position { get; set; }
+ public Vector3 Position { get; set; }
///
/// Player Latency in second.
///
public float Latency { get; set; }
public int Health { get; set; }
-
- public bool IsInRangeOf(LVector3 position, float distance)
- {
- return LVector3.Subtract(Position, position).Length() < distance;
- }
}
}
diff --git a/Server/Client.cs b/Server/Client.cs
index 38eab88..7c55e5f 100644
--- a/Server/Client.cs
+++ b/Server/Client.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using RageCoop.Core;
using Lidgren.Network;
+using GTA.Math;
namespace RageCoop.Server
{
@@ -160,7 +161,7 @@ namespace RageCoop.Server
{
returnTypeValue = 0x03;
}
- else if (returnType == typeof(LVector3))
+ else if (returnType == typeof(Vector3))
{
returnTypeValue = 0x04;
}
diff --git a/Server/Server.cs b/Server/Server.cs
index f0080e9..4b7a315 100644
--- a/Server/Server.cs
+++ b/Server/Server.cs
@@ -912,12 +912,26 @@ namespace RageCoop.Server
{
return;
}
-
-
- foreach(var c in Clients.Values)
+ bool isPlayer = packet.Flag.HasFlag(PedDataFlags.IsPlayer);
+ if (isPlayer) { client.Player.Position=packet.Position; }
+ foreach (var c in Clients.Values)
{
+
// Don't send data back
if (c.ClientID==client.ClientID) { continue; }
+
+ // Check streaming distance
+ if (isPlayer)
+ {
+ if ((MainSettings.PlayerStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>MainSettings.PlayerStreamingDistance))
+ {
+ continue;
+ }
+ }
+ else if ((MainSettings.NpcStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>MainSettings.NpcStreamingDistance))
+ {
+ continue;
+ }
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
packet.Pack(outgoingMessage);
MainNetServer.SendMessage(outgoingMessage,c.Connection, NetDeliveryMethod.UnreliableSequenced, (byte)ConnectionChannel.PedSync);
@@ -935,43 +949,27 @@ namespace RageCoop.Server
{
return;
}
-
+ bool isPlayer = packet.ID==client.Player.VehicleID;
foreach (var c in Clients.Values)
{
if (c.ClientID==client.ClientID) { continue; }
+ if (isPlayer)
+ {
+ // Player's vehicle
+ if ((MainSettings.PlayerStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>MainSettings.PlayerStreamingDistance))
+ {
+ continue;
+ }
+
+ }
+ else if((MainSettings.NpcStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>MainSettings.NpcStreamingDistance))
+ {
+ continue;
+ }
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
packet.Pack(outgoingMessage);
MainNetServer.SendMessage(outgoingMessage, c.Connection, NetDeliveryMethod.UnreliableSequenced, (byte)ConnectionChannel.PedSync);
}
- /*
- Client client = Util.GetClientByID(ClientID);
- if (client == null)
- {
- return;
- }
- // Save the new data
- client.Player.PedHandle = packet.PedHandle;
- client.Player.VehicleHandle = packet.VehicleHandle;
- client.Player.IsInVehicle = true;
- client.Player.Position = packet.Position;
- client.Player.Health = packet.Health;
-
- // Override the latency
- packet.Latency = client.Latency;
-
- MainNetServer.Connections.FindAll(x => x.RemoteUniqueIdentifier != ClientID).ForEach(x =>
- {
- NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
- packet.PacketToNetOutGoingMessage(outgoingMessage);
- MainNetServer.SendMessage(outgoingMessage, x, NetDeliveryMethod.UnreliableSequenced, (byte)ConnectionChannel.PlayerFull);
-
- });
-
- if (RunningResource != null)
- {
- RunningResource.InvokePlayerUpdate(client);
- }
- */
}
private static void ProjectileSync(Packets.ProjectileSync packet, long ClientID)
{
diff --git a/Server/Settings.cs b/Server/Settings.cs
index 7636aa1..bc64456 100644
--- a/Server/Settings.cs
+++ b/Server/Settings.cs
@@ -15,9 +15,9 @@
public string MasterServer { get; set; } = "https://ragecoop.online/gtav/servers";
public bool DebugMode { get; set; } = false;
///
- /// NPC data won't be sent to a player if distance is greater than this value. -1 for unlimited.
+ /// NPC data won't be sent to a player if their distance is greater than this value. -1 for unlimited.
///
- public float NpcStreamingDistance { get; set; } = 200;
+ public float NpcStreamingDistance { get; set; } = 1000;
///
/// Player's data won't be sent to another player if their distance is greater than this value. -1 for unlimited.
///
diff --git a/Server/Util.cs b/Server/Util.cs
index 990d235..9247897 100644
--- a/Server/Util.cs
+++ b/Server/Util.cs
@@ -66,25 +66,6 @@ namespace RageCoop.Server
return new(Server.MainNetServer.Connections.Where(e => e.RemoteUniqueIdentifier != local));
}
- // Return a list of players within range of ...
- public static List GetAllInRange(LVector3 position, float range)
- {
- return new(Server.MainNetServer.Connections.FindAll(e =>
- {
- Client client = Server.Clients.Values.First(x => x.ClientID == e.RemoteUniqueIdentifier);
- return client != null && client.Player.IsInRangeOf(position, range);
- }));
- }
- // Return a list of players within range of ... but not the local one
- public static List GetAllInRange(LVector3 position, float range, NetConnection local)
- {
- return new(Server.MainNetServer.Connections.Where(e =>
- {
- Client client = Server.Clients.Values.First(x => x.ClientID == e.RemoteUniqueIdentifier);
- return e != local && client != null && client.Player.IsInRangeOf(position, range);
- }));
- }
-
public static T Read(string file) where T : new()
{
XmlSerializer ser = new(typeof(T));