Skip to content

Commit ca1eaea

Browse files
- SCP-330 use count is now kept after viewing cameras
- Added try catch to ensure errors don't result in the player being kicked
1 parent 0a6a214 commit ca1eaea

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

CameraSystem-LabAPI/CameraSystem-LabAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="Models\Watcher.cs" />
9090
<Compile Include="Models\WorkstationConfig.cs" />
9191
<Compile Include="Patches\Scp079ScanningPossiblePatch.cs" />
92+
<Compile Include="Patches\Scp330InterobjectPatch.cs" />
9293
<Compile Include="Patches\WorkstationActivationPatch.cs" />
9394
<Compile Include="Properties\AssemblyInfo.cs"/>
9495
</ItemGroup>

CameraSystem-LabAPI/Managers/CameraManager.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using CameraSystem.Models;
5+
using Footprinting;
6+
using Interactables.Interobjects;
57
using InventorySystem.Items.Firearms.Attachments;
68
using LabApi.Features.Wrappers;
79
using MEC;
@@ -23,6 +25,7 @@ internal sealed class CameraManager : IDisposable
2325
internal bool IsCameraSystemEnabled { get; private set; } =
2426
CameraSystem.Instance.Config.IsCameraSystemEnabledByDefault;
2527

28+
internal static Scp330Interobject Scp330Interobject;
2629
internal List<WorkstationController> WorkstationControllers { get; set; } = new();
2730

2831
private readonly List<Watcher> _watchers = new();
@@ -56,6 +59,16 @@ internal void Disconnect(Player player, DamageHandlerBase damageHandler = null)
5659
watcher.Player.ArtificialHealth = watcher.PlayerSnapshot.ArtificialHealth;
5760
watcher.Player.Health = watcher.PlayerSnapshot.Health;
5861

62+
if (Scp330Interobject != null)
63+
{
64+
var current330Count = Scp330Interobject.PreviousUses
65+
.Count(x => x.LifeIdentifier == watcher.Player.RoleBase.UniqueLifeIdentifier);
66+
for (var i = current330Count; i < watcher.PlayerSnapshot.Scp330Uses; i++)
67+
{
68+
Scp330Interobject.PreviousUses.Add(new Footprint(watcher.Player.ReferenceHub));
69+
}
70+
}
71+
5972
foreach (var pair in watcher.PlayerSnapshot.Ammo)
6073
{
6174
watcher.Player.SetAmmo(pair.Key, pair.Value);

CameraSystem-LabAPI/Models/PlayerSnapshot.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using CameraSystem.Managers;
34
using CustomPlayerEffects;
45
using LabApi.Features.Wrappers;
56
using PlayerRoles;
@@ -22,6 +23,7 @@ internal class PlayerSnapshot
2223
internal Vector3 Scale { get; }
2324
internal Quaternion Rotation { get; }
2425
internal string Nickname { get; }
26+
internal int Scp330Uses { get; }
2527

2628
internal PlayerSnapshot(Player player)
2729
{
@@ -40,5 +42,11 @@ internal PlayerSnapshot(Player player)
4042
Scale = player.Scale;
4143
Rotation = player.Rotation;
4244
Nickname = player.Nickname;
45+
46+
if (CameraManager.Scp330Interobject != null)
47+
{
48+
Scp330Uses = CameraManager.Scp330Interobject.PreviousUses
49+
.Count(x => x.LifeIdentifier == player.RoleBase.UniqueLifeIdentifier);
50+
}
4351
}
4452
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using CameraSystem.Managers;
2+
using HarmonyLib;
3+
using Interactables.Interobjects;
4+
5+
namespace CameraSystem.Patches;
6+
7+
[HarmonyPatch]
8+
public static class Scp330InterobjectPatch
9+
{
10+
[HarmonyPatch(typeof(Scp330Interobject), nameof(Scp330Interobject.ServerInteract))]
11+
[HarmonyPostfix]
12+
// ReSharper disable once InconsistentNaming
13+
public static void On330Interact(Scp330Interobject __instance)
14+
{
15+
CameraManager.Scp330Interobject = __instance;
16+
}
17+
}

CameraSystem-LabAPI/Patches/WorkstationActivationPatch.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using HarmonyLib;
1+
using System;
2+
using HarmonyLib;
23
using InventorySystem.Items.Firearms.Attachments;
4+
using LabApi.Features.Console;
35
using LabApi.Features.Wrappers;
46

57
namespace CameraSystem.Patches;
@@ -11,6 +13,14 @@ public static class WorkstationActivationPatch
1113
// ReSharper disable once InconsistentNaming
1214
public static bool OnEnterWorkstation(ReferenceHub ply, WorkstationController __instance)
1315
{
14-
return EventHandlers.OnActivatingWorkstation(Player.Get(ply), __instance);
16+
try
17+
{
18+
return EventHandlers.OnActivatingWorkstation(Player.Get(ply), __instance);
19+
}
20+
catch (Exception e)
21+
{
22+
Logger.Error($"Failed to connect player: {e}");
23+
return true;
24+
}
1525
}
1626
}

0 commit comments

Comments
 (0)