From 393a401860dc167b5e43940e73232c397e58baeb Mon Sep 17 00:00:00 2001 From: oldnapalm <38410858+oldnapalm@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:27:14 -0300 Subject: [PATCH] Always sync vehicles with synced peds --- RageCoop.Client/Networking/Receive.cs | 5 +++-- RageCoop.Client/Sync/EntityPool.cs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs index fcea6539..a2b1357d 100644 --- a/RageCoop.Client/Networking/Receive.cs +++ b/RageCoop.Client/Networking/Receive.cs @@ -3,6 +3,7 @@ using RageCoop.Client.Menus; using RageCoop.Core; using System; +using System.Linq; using System.Threading; namespace RageCoop.Client @@ -306,7 +307,7 @@ private static void PedSync(Packets.PedSync packet) if (c == null) { // Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}"); - if (EntityPool.allPeds.Length < Main.Settings.GlobalPedSoftLimit || PlayerList.Players.ContainsKey(packet.ID)) + if (EntityPool.allPeds.Length < Main.Settings.GlobalPedSoftLimit + PlayerList.Players.Count || PlayerList.Players.ContainsKey(packet.ID)) EntityPool.ThreadSafe.Add(c = new SyncedPed(packet.ID)); else return; } @@ -356,7 +357,7 @@ private static void VehicleSync(Packets.VehicleSync packet) SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID); if (v == null) { - if (EntityPool.allVehicles.Length < Main.Settings.GlobalVehicleSoftLimit) + if (EntityPool.allVehicles.Length < Main.Settings.GlobalVehicleSoftLimit || EntityPool.PedsByID.Any(x => x.Value.Position.DistanceTo(packet.Position) < 2f)) EntityPool.ThreadSafe.Add(v = new SyncedVehicle(packet.ID)); else return; } diff --git a/RageCoop.Client/Sync/EntityPool.cs b/RageCoop.Client/Sync/EntityPool.cs index 891e3861..9b37b603 100644 --- a/RageCoop.Client/Sync/EntityPool.cs +++ b/RageCoop.Client/Sync/EntityPool.cs @@ -51,7 +51,7 @@ public static void Cleanup(bool keepPlayer = true, bool keepMine = true) PedsByID.Clear(); PedsByHandle.Clear(); - foreach (int id in new List(VehiclesByID.Keys)) + foreach (int id in VehiclesByID.Keys.ToArray()) { if (keepMine && (VehiclesByID[id].OwnerID == Main.LocalPlayerID)) { continue; } RemoveVehicle(id); @@ -359,11 +359,11 @@ public static void DoSync() lock (PedsLock) { AddPlayer(); + var mainCharacters = new List { PedHash.Michael, PedHash.Franklin, PedHash.Franklin02, PedHash.Trevor }; foreach (Ped p in allPeds) { SyncedPed c = GetPedByHandle(p.Handle); - List mainCharacters = new List { PedHash.Michael, PedHash.Franklin, PedHash.Franklin02, PedHash.Trevor }; if (c == null && p != Game.Player.Character && !mainCharacters.Contains((PedHash)p.Model.Hash)) { if (allPeds.Length > Main.Settings.WorldPedSoftLimit && p.PopulationType == EntityPopulationType.RandomAmbient && !p.IsInVehicle())