-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurityPlugin..cs
More file actions
48 lines (38 loc) · 1.54 KB
/
Copy pathSecurityPlugin..cs
File metadata and controls
48 lines (38 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using BepInEx;
using HarmonyLib;
using Assets.Scripts.Networking;
using Assets.Scripts;
using System;
[BepInPlugin("com.tokinjesus.securityplugin", "Stationeers Security Plugin", "0.0.1")]
public class SecurityPlugin : BaseUnityPlugin
{
private void Awake()
{
var harmony = new Harmony("com.tokinjesus.securityplugin");
harmony.PatchAll();
Logger.LogInfo("[Security] Network Message Interceptor Loaded.");
}
}
// This blocks the specific network packet sent by the client's 'thing spawn' command
[HarmonyPatch(typeof(SpawnDynamicThingMaxStackMessage), nameof(SpawnDynamicThingMaxStackMessage.Process))]
public class Patch_SpawnMessage_Security
{
static bool Prefix(SpawnDynamicThingMaxStackMessage __instance)
{
// When this runs on the server, we log it and return false to stop the spawn.
ConsoleWindow.Print($"[Security] Blocked spawn request for '{__instance.PrefabName}'.", ConsoleColor.Red);
// Returning false prevents base.Process and OnServer.SpawnDynamicThingMaxStack from running.
return false;
}
}
[HarmonyPatch(typeof(AddGasCommand), nameof(AddGasCommand.Process))]
public class Patch_AddGassCommand_Security
{
static bool Prefix(long hostId)
{
// When this runs on the server, we log it and return false to stop the spawn.
ConsoleWindow.Print($"[Security] Blocked gas spawn request.", ConsoleColor.Red);
// Returning false prevents base.Process and OnServer.SpawnDynamicThingMaxStack from running.
return false;
}
}