Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 1f76205

Browse files
committed
Updated
1 parent caa300d commit 1f76205

File tree

10 files changed

+29
-104
lines changed

10 files changed

+29
-104
lines changed

TestingDummies/Commands/DummyLookAt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
3636
response = $"The player with the specified ID, '{arguments.At(1)}', dosent exist!";
3737
return false;
3838
}
39-
if (Plugin.Instance.DumRef.Contains(dummy.ReferenceHub))
39+
if (dummy.IsNPC)
4040
{
4141
Quaternion quat = Quaternion.LookRotation(target.Position - dummy.Position, Vector3.up);
4242
var mouseLook = ((IFpcRole)dummy.ReferenceHub.roleManager.CurrentRole).FpcModule.MouseLook;

TestingDummies/Commands/DummyStats.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using CommandSystem;
2-
using CustomPlayerEffects;
3-
using Exiled.API.Extensions;
42
using Exiled.API.Features;
5-
using Mirror;
63
using System;
74
using System.Collections.Generic;
85
using System.Linq;
@@ -32,10 +29,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
3229
response = $"The player with the specified ID, '{arguments.At(0)}', dosent exist!";
3330
return false;
3431
}
35-
if (Plugin.Instance.DumRef.Contains(Dummy.ReferenceHub))
32+
if (Dummy.IsNPC)
3633
{
3734
List<string> effectNames = Dummy.ActiveEffects.Select(effect => effect.name).ToList();
38-
string activeEffectsString = string.Join(", ", effectNames);
35+
string activeEffectsString = effectNames.Count == 0 ? "None" : string.Join(", ", effectNames);
3936

4037
response = $"Stats: Player ID: {Dummy.Id}, Name: {Dummy.Nickname}, Health: {Dummy.Health}, Role: {Dummy.Role.Name}, Active Effects: {activeEffectsString}";
4138
return true;

TestingDummies/Commands/RemoveDummy.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
2929
response = $"The player with the specified ID, '{arguments.At(0)}', dosent exist!";
3030
return false;
3131
}
32-
if(Plugin.Instance.DumRef.Contains(Dummy.ReferenceHub))
32+
if(Dummy.IsNPC)
3333
{
3434
Dummy.ReferenceHub.OnDestroy();
3535

3636
LeftEventArgs newLeft = new(Dummy);
3737
Exiled.Events.Handlers.Player.OnLeft(newLeft);
3838

39-
Plugin.Instance.DumRef.Remove(Dummy.ReferenceHub);
40-
4139
response = $"Removed {Dummy.Nickname}!";
4240
return true;
4341
}

TestingDummies/Commands/SpawnDummy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
3434
}
3535
if (player == null)
3636
{
37-
response = $"Invalid player with the specified ID OR Nickname: {arguments.At(2)}";
37+
response = $"Invalid player with the specified ID or Nickname: {arguments.At(2)}";
3838
return false;
3939
}
40-
MECExtensionMethods1.RunCoroutine(Plugin.Instance.spawning.SpawnDum(name, role, player));
40+
Plugin.Instance.spawning.SpawnDummy(name, role, player);
4141
response = $"Spawned dummy with name '{name}', role '{role}', for player '{player.Nickname}'";
4242
return true;
4343
}

TestingDummies/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Config : IConfig
1616

1717
[Description("If NPCBadge is enabled, sets the name")]
1818
public string NPCBadgeName { get; set; } = "NPC";
19+
1920
[Description("Gives spawned NPCs AFK Immunity (HIGHLY RECOMMENED TO KEEP TRUE AS NPCS ARE CONSTANTLY AFK)")]
2021
public bool NPCAFKImmunity { get; set; } = true;
2122
}

TestingDummies/Patches/RotationPatch.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using HarmonyLib;
1+
using Exiled.API.Features;
2+
using HarmonyLib;
23
using NorthwoodLib.Pools;
34
using PlayerRoles.FirstPersonControl;
45
using System.Collections.Generic;
56
using System.Reflection.Emit;
67

78
namespace TestingDummies.Patches
89
{
9-
//Thank you to the SCP-575 Plugin that I st- borrowed this code from :3
1010
[HarmonyPatch(typeof(FpcMouseLook), nameof(FpcMouseLook.UpdateRotation))]
1111
public class RotationPatch
1212
{
@@ -22,8 +22,9 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
2222
{
2323
new(OpCodes.Ldarg_0),
2424
new(OpCodes.Ldfld, AccessTools.Field(typeof(FpcMouseLook), nameof(FpcMouseLook._hub))),
25-
new(OpCodes.Call, AccessTools.Method(typeof(Plugin), nameof(Plugin.IsAI))),
26-
new(OpCodes.Brtrue_S, skip)
25+
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Player), "Get", new[] { typeof(ReferenceHub) })),
26+
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(Player), nameof(Player.IsNPC))),
27+
new CodeInstruction(OpCodes.Brtrue_S, skip),
2728
});
2829

2930
foreach (CodeInstruction instruction in newInstructions)

TestingDummies/Plugin.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
using Exiled.API.Enums;
22
using Exiled.API.Features;
33
using System;
4-
using System.Collections.Generic;
54
using TestingDummies.SpawningHandler;
65
using HarmonyLib;
7-
using System.Linq;
86

97
namespace TestingDummies
108
{
119
public class Plugin : Plugin<Config>
1210
{
1311
public static Plugin Instance;
1412

15-
public List<ReferenceHub> DumRef = new();
1613
public Spawn spawning;
1714
private Harmony _harmony;
1815

@@ -32,7 +29,7 @@ public override void OnEnabled()
3229

3330
base.OnEnabled();
3431

35-
Log.Warn($"{Name.ToUpper()} DOES AND WILL VIOLATE NORTHWOOD VSR. USE ON PRIVATE SERVERS ONLY AND AT YOUR OWN RISK.");
32+
Log.Warn($"{Name.ToUpper()} DOES AND WILL VIOLATE NORTHWOOD VSR WHEN DUMMIES ARE SPAWNED. USE ON PRIVATE SERVERS ONLY AND AT YOUR OWN RISK.");
3633
}
3734

3835
public override void OnDisabled()
@@ -43,12 +40,6 @@ public override void OnDisabled()
4340
spawning = null;
4441

4542
base.OnDisabled();
46-
}
47-
48-
public static bool IsAI(ReferenceHub hub)
49-
{
50-
bool isDummy = Instance.DumRef.Contains(hub);
51-
return isDummy;
52-
}
43+
}
5344
}
5445
}

TestingDummies/SpawningHandler/FakeConnection.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,20 @@
11
using Exiled.API.Features;
2-
using Mirror;
32
using PlayerRoles;
4-
using System;
5-
using System.Collections.Generic;
63
using UnityEngine;
7-
using MEC;
8-
using Exiled.Events.EventArgs.Player;
94

105
namespace TestingDummies.SpawningHandler
116
{
127
public class Spawn : MonoBehaviour
138
{
14-
readonly int IDs = 1000;
15-
public Dictionary<Player, GameObject> PlayerPrefabs = new();
16-
public Dictionary<Player, FakeConnection> PlayerConnIDs = new();
17-
public Dictionary<ReferenceHub, Player> DumPlayerHubs = new();
18-
19-
public IEnumerator<float> SpawnDum(string Name, RoleTypeId Role, Player target)
9+
public void SpawnDummy(string Name, RoleTypeId Role, Player Target)
2010
{
21-
GameObject newPlayer = Instantiate(NetworkManager.singleton.playerPrefab);
22-
Player NewPlayer = new(newPlayer);
23-
try
24-
{
25-
NewPlayer.Role.Set(RoleTypeId.None);
26-
}
27-
catch (Exception e)
28-
{
29-
Log.Debug($"Ignore: {e}");
30-
}
31-
PlayerPrefabs.Add(NewPlayer, newPlayer);
32-
var fakeConnection = new FakeConnection(IDs + Plugin.Instance.DumRef.Count);
33-
ReferenceHub hubPlayer = NewPlayer.ReferenceHub;
34-
Plugin.Instance.DumRef.Add(hubPlayer);
35-
NetworkServer.AddPlayerForConnection(fakeConnection, newPlayer);
36-
PlayerConnIDs.Add(NewPlayer, fakeConnection);
37-
try
38-
{
39-
hubPlayer.characterClassManager.UserId = $"DevDummy{Plugin.Instance.DumRef.Count}@server";
40-
}
41-
catch (Exception e)
42-
{
43-
Log.Debug(e);
44-
}
45-
hubPlayer.nicknameSync.Network_myNickSync = $"{Name}-{Plugin.Instance.DumRef.Count}";
46-
hubPlayer.serverRoles.DoNotTrack = true;
47-
Player.Dictionary.Add(newPlayer, NewPlayer);
11+
Npc GeneratedNPC = Npc.Spawn(Name, Role, position: Target.Position);
12+
if (Plugin.Instance.Config.NPCAFKImmunity) GeneratedNPC.RemoteAdminPermissions = PlayerPermissions.AFKImmunity;
4813
if (Plugin.Instance.Config.NPCBadgeEnabled)
4914
{
50-
NewPlayer.RankName = Plugin.Instance.Config.NPCBadgeName;
51-
NewPlayer.RankColor = Plugin.Instance.Config.NPCBadgeColor;
52-
}
53-
hubPlayer.characterClassManager.GodMode = false;
54-
if (Plugin.Instance.Config.NPCAFKImmunity) NewPlayer.RemoteAdminPermissions = PlayerPermissions.AFKImmunity;
55-
yield return Timing.WaitForSeconds(0.3f);
56-
NewPlayer.Role.Set(Role, Exiled.API.Enums.SpawnReason.ForceClass);
57-
NewPlayer.Position = target.Position;
58-
NewPlayer.SessionVariables.Add("npc", true);
59-
VerifiedEventArgs newVerified = new(NewPlayer);
60-
Exiled.Events.Handlers.Player.OnVerified(newVerified);
61-
yield break;
15+
GeneratedNPC.RankName = Plugin.Instance.Config.NPCBadgeName;
16+
GeneratedNPC.RankColor = Plugin.Instance.Config.NPCBadgeColor;
17+
}
6218
}
6319
}
6420
}

TestingDummies/TestingDummies.csproj

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<ItemGroup>
36-
<Reference Include="0Harmony">
37-
<HintPath>..\..\..\..\OneDrive\Desktop\references\References\0Harmony.dll</HintPath>
36+
<Reference Include="0Harmony, Version=2.2.2.0, Culture=neutral, processorArchitecture=MSIL">
37+
<SpecificVersion>False</SpecificVersion>
38+
<HintPath>..\..\..\..\AppData\Roaming\EXILED\Plugins\dependencies\0Harmony.dll</HintPath>
3839
</Reference>
3940
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
4041
<SpecificVersion>False</SpecificVersion>
41-
<HintPath>..\..\..\..\OneDrive\Desktop\references\References\Assembly-CSharp-firstpass.dll</HintPath>
42+
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
4243
</Reference>
43-
<Reference Include="Mirror">
44+
<Reference Include="Mirror, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
45+
<SpecificVersion>False</SpecificVersion>
4446
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Mirror.dll</HintPath>
4547
</Reference>
46-
<Reference Include="NPCAPI">
47-
<HintPath>..\..\NpcAPI\NPCAPI\obj\Debug\NPCAPI.dll</HintPath>
48-
</Reference>
49-
<Reference Include="Pooling">
48+
<Reference Include="Pooling, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
49+
<SpecificVersion>False</SpecificVersion>
5050
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Pooling.dll</HintPath>
5151
</Reference>
5252
<Reference Include="System" />
@@ -79,12 +79,11 @@
7979
<Compile Include="Patches\RotationPatch.cs" />
8080
<Compile Include="Plugin.cs" />
8181
<Compile Include="Properties\AssemblyInfo.cs" />
82-
<Compile Include="SpawningHandler\FakeConnection.cs" />
8382
<Compile Include="SpawningHandler\Spawn.cs" />
8483
</ItemGroup>
8584
<ItemGroup>
8685
<PackageReference Include="EXILED">
87-
<Version>7.0.0-rc.5</Version>
86+
<Version>7.2.0</Version>
8887
</PackageReference>
8988
</ItemGroup>
9089
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

0 commit comments

Comments
 (0)