-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
102 lines (93 loc) · 3.24 KB
/
Plugin.cs
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
using System;
using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using HideVanish.Patches;
using Rocket.Core.Plugins;
using Rocket.Unturned.Player;
using SDG.Unturned;
using UnityEngine;
using RocketLogger = Rocket.Core.Logging.Logger;
namespace HideVanish
{
public class Plugin : RocketPlugin
{
private Harmony harmony;
protected override void Load()
{
HarmonyExceptionHandler.OnReportCleanupRequested += OnReportCleanupRequested;
PatchAlerts.OnPlayerAlertRequested += OnPlayerAlertRequested;
PatchAlerts.OnAlertRequested += OnAlertRequested;
PatchAlerts.OnZombieAlertRequested += OnZombieAlertRequested;
PatchAlerts.OnZombieTick += OnZombieTick;
harmony = new Harmony("com.restoremonarchy.hidevanish");
harmony.PatchAll();
}
protected override void Unload()
{
HarmonyExceptionHandler.OnReportCleanupRequested -= OnReportCleanupRequested;
PatchAlerts.OnPlayerAlertRequested -= OnPlayerAlertRequested;
PatchAlerts.OnAlertRequested -= OnAlertRequested;
PatchAlerts.OnZombieAlertRequested -= OnZombieAlertRequested;
PatchAlerts.OnZombieTick -= OnZombieTick;
if (harmony != null)
{
try
{
harmony.UnpatchAll(harmony.Id);
}
catch
{
// ignored
}
}
}
private void OnReportCleanupRequested(Type type, Exception exception, MethodBase originalMethod)
{
RocketLogger.LogException(exception,
$"Failed to patch original method {originalMethod?.FullDescription()} from patching type {type.FullDescription()}");
UnloadPlugin();
}
private static void OnPlayerAlertRequested(Player player, ref bool allow)
{
if (IsPlayerVanished(player))
{
allow = false;
}
}
private static void OnAlertRequested(Vector3 position, float radius, ref bool allow)
{
var players = new List<Player>();
PlayerTool.getPlayersInRadius(position, 3, players);
if (players.Count != 0)
{
var player = players[0];
if (IsPlayerVanished(player))
{
allow = false;
}
}
}
private static void OnZombieAlertRequested(Zombie zombie, ref bool allow)
{
if (zombie.player != null && IsPlayerVanished(zombie.player))
{
allow = false;
zombie.player = null;
}
}
private static void OnZombieTick(Zombie zombie, ref bool allow)
{
if (zombie.player != null && IsPlayerVanished(zombie.player))
{
allow = false;
zombie.player = null;
}
}
private static bool IsPlayerVanished(Player player)
{
var unturnedPlayer = UnturnedPlayer.FromPlayer(player);
return unturnedPlayer.VanishMode;
}
}
}