-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpacebuilder2020PatchMod.cs
More file actions
106 lines (94 loc) · 4.34 KB
/
Spacebuilder2020PatchMod.cs
File metadata and controls
106 lines (94 loc) · 4.34 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using Assets.Scripts;
using HarmonyLib;
using StationeersMods.Interface;
using System.Threading;
using System.Threading.Tasks;
using Assets.Scripts.Networking;
using Assets.Scripts.Objects;
using LaunchPadBooster.Patching;
using Steamworks;
using Util.Commands;
namespace Spacebuilder2020PatchMod
{
[StationeersMod("Spacebuilder2020PatchMod", "Spacebuilder2020PatchMod [StationeersMods]", "1.2")]
class Spacebuilder2020PatchMod : ModBehaviour
{
public override void OnLoaded(ContentHandler contentHandler)
{
ConsoleWindow.Print("Loading Patches for Spacebuilder2020's PatchMod");
Harmony harmony = new Harmony("Spacebuilder2020PatchMod");
harmony.ConditionalPatchAll();
ConsoleWindow.Print("Patches Loaded!");
}
}
[HarmonyPatch]
class Spacebuilder2020Patches
{
[HarmonyPatch(typeof(NetworkServer), "HandleBlacklisting"), HarmonyPostfix]
static void NetworkServer_HandleBlacklisting(ref NetworkMessages.VerifyPlayer msg, ref Client client) => DelayedClose(client);
[HarmonyPatch(typeof(NetworkServer), "HandleIncorrectPassword"), HarmonyPostfix]
static void NetworkServer_HandleIncorrectPassword(ref Client client) => DelayedClose(client);
[HarmonyPatch(typeof(NetworkServer), "HandleIncorrectVersion"), HarmonyPostfix]
static void NetworkServer_HandleIncorrectVersion(ref Client client, NetworkMessages.VerifyPlayer msg) => DelayedClose(client);
static void DelayedClose(Client client)
{
Task.Run(() =>
{
Thread.Sleep(500);
NetworkManager.CloseP2PConnectionServer(client);
});
}
[HarmonyPatch(typeof(KickCommand), "Kick"), HarmonyPrefix]
static bool KickCommand_Kick(ref string[] lineSplit)
{
if (!NetworkManager.IsActiveAsClient && (NetworkManager.IsClient || NetworkManager.IsServer) && lineSplit.Length == 1)
{
string nameOrID = lineSplit[0];
bool parsed = ulong.TryParse(lineSplit[0], out var clientId);
Client user = parsed ? Client.Find(clientId) : NetworkBase.Clients.Find(client => client.name == nameOrID);
if (user != null)
{
ConsoleWindow.PrintAction($"client '{user.name}' kicked from game");
user.Disconnect();
}
else
{
ConsoleWindow.PrintError($"Unable to find client by {(parsed ? "id" :"name")}: '{nameOrID}' in list", true);
if (!parsed)
{
var clients = NetworkBase.Clients.FindAll(client =>
client.name.ToLower().StartsWith(nameOrID.ToLower()) ||
client.name.ToLower().Contains(nameOrID.ToLower()));
if (clients.Count > 0)
{
ConsoleWindow.Print("Possible Options:");
clients.ForEach(client => ConsoleWindow.Print(client.name));
}
}
else
{
ConsoleWindow.PrintAction("Trying a kick by exact steam id");
if (SteamNetworking.CloseP2PSessionWithUser(clientId))
{
ConsoleWindow.Print("Successfully kicked by Steam!");
}
else
{
ConsoleWindow.PrintError("Error kicking by id, user may not be connected!", true);
}
}
}
return false;
}
return true;
}
[HarmonyPatch(typeof(Item), "UpdateDecayTimes"), HarmonyPrefix]
[HarmonyGameVersionPatch("0.0.0.0","0.2.5959.26190")]
static bool Item_UpdateDecayTimes(ref Item __instance) {
Traverse.Create(__instance).Method("set_TimeToDecayFromNowInSeconds",
(int) ((__instance.DamageState.MaxDamage - (double) __instance.DamageState.Decay) / ( __instance.CurrentDecayRate * 60.0)))
.GetValue();
return false;
}
}
}