Skip to content

Commit 72adef9

Browse files
committed
Added isKinematic sync to pickups
1 parent 6ffb360 commit 72adef9

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

LabExtended/API/ExMap.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,26 @@ namespace LabExtended.API;
4646
public static class ExMap
4747
{
4848
private static readonly FacilityZone[] allZones = EnumUtils<FacilityZone>.Values.Except([FacilityZone.None, FacilityZone.Other]).ToArray();
49-
49+
5050
/// <summary>
51-
/// List of spawned pickups.
51+
/// List of spawned lockers.
5252
/// </summary>
53-
public static List<ItemPickupBase> Pickups { get; } = new();
53+
public static List<Locker> Lockers { get; } = new();
5454

5555
/// <summary>
5656
/// List of spawned ragdolls.
5757
/// </summary>
5858
public static List<BasicRagdoll> Ragdolls { get; } = new();
5959

6060
/// <summary>
61-
/// List of spawned lockers.
61+
/// List of spawned pickups.
6262
/// </summary>
63-
public static List<Locker> Lockers { get; } = new();
63+
public static List<ItemPickupBase> Pickups { get; } = new();
64+
65+
/// <summary>
66+
/// List of frozen pickups.
67+
/// </summary>
68+
public static List<ItemPickupBase> FrozenPickups { get; } = new();
6469

6570
/// <summary>
6671
/// List of locker chambers.
@@ -703,6 +708,7 @@ private static void OnRagdollRemoved(BasicRagdoll ragdoll)
703708
private static void OnPickupDestroyed(ItemPickupBase pickup)
704709
{
705710
Pickups.Remove(pickup);
711+
FrozenPickups.Remove(pickup);
706712

707713
ExPlayer.AllPlayers.ForEach(p => p?.Inventory?.droppedItems?.Remove(pickup));
708714
}
@@ -716,6 +722,8 @@ private static void OnGenerationStage(MapGenerationPhase phase)
716722
{
717723
if (phase is MapGenerationPhase.RoomCoordsRegistrations)
718724
{
725+
FrozenPickups.Clear();
726+
719727
Lockers.Clear();
720728

721729
Chambers.Clear();

LabExtended/Extensions/ItemExtensions.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using InventorySystem.Items.Usables.Scp1344;
88

99
using LabExtended.API;
10-
using LabExtended.Utilities;
1110

1211
using Mirror;
1312

@@ -246,13 +245,19 @@ public static bool FreezePickup(this ItemPickupBase itemPickupBase)
246245
if (itemPickupBase.PhysicsModule is not PickupStandardPhysics pickupStandardPhysics)
247246
return false;
248247

249-
if (pickupStandardPhysics.Rb is null)
248+
if (pickupStandardPhysics.Rb == null)
250249
return false;
251250

252-
pickupStandardPhysics.Rb.isKinematic = true;
253-
pickupStandardPhysics.Rb.constraints = RigidbodyConstraints.FreezeAll;
251+
if (!pickupStandardPhysics.Rb.isKinematic)
252+
{
253+
pickupStandardPhysics.Rb.isKinematic = true;
254+
pickupStandardPhysics.Rb.constraints = RigidbodyConstraints.FreezeAll;
255+
256+
pickupStandardPhysics.ClientFrozen = true;
257+
258+
ExMap.FrozenPickups.AddUnique(itemPickupBase);
259+
}
254260

255-
pickupStandardPhysics.ClientFrozen = true;
256261
return true;
257262
}
258263

@@ -273,6 +278,8 @@ public static bool UnfreezePickup(this ItemPickupBase itemPickupBase)
273278
pickupStandardPhysics.Rb.constraints = RigidbodyConstraints.None;
274279

275280
pickupStandardPhysics.ClientFrozen = false;
281+
282+
ExMap.FrozenPickups.Remove(itemPickupBase);
276283
return true;
277284
}
278285

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using HarmonyLib;
2+
using InventorySystem.Items.Pickups;
3+
4+
using LabExtended.API;
5+
6+
namespace LabExtended.Patches.Fixes
7+
{
8+
/// <summary>
9+
/// Provides a Harmony patch for synchronizing the kinematic state of pickups, ensuring that frozen pickups are
10+
/// correctly reported as kinematic during server freeze checks.
11+
/// </summary>
12+
public static class PickupIsKinematicSyncPatch
13+
{
14+
[HarmonyPatch(typeof(PickupStandardPhysics), nameof(PickupStandardPhysics.ServerSendFreeze), MethodType.Getter)]
15+
private static bool Prefix(PickupStandardPhysics __instance, ref bool __result)
16+
{
17+
if (__instance != null
18+
&& __instance.Pickup != null
19+
&& __instance.Rb != null
20+
&& __instance.Rb.isKinematic
21+
&& ExMap.FrozenPickups.Contains(__instance.Pickup))
22+
{
23+
__result = true;
24+
return false;
25+
}
26+
27+
return true;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)