This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Patches.cs
67 lines (60 loc) · 2.81 KB
/
Patches.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
namespace NameplateStats
{
using System.Linq;
using System.Reflection;
using HarmonyLib;
using MelonLoader;
public class Patches
{
private static readonly System.Collections.Generic.IEnumerable<MethodInfo> NameplateMethods = typeof(PlayerNameplate).GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(x => x.Name.StartsWith("Method_Public_Void_") && x.Name.Length == 20);
private static readonly MethodInfo NameplateMethodsPatch = typeof(Patches).GetMethod(nameof(NameplateBlanketPatch));
private static readonly MethodInfo VRCPlayerAwake = typeof(VRCPlayer).GetMethod("Awake");
private static readonly MethodInfo VRCPlayerPatch = typeof(Patches).GetMethod(nameof(OnVRCPlayerAwake));
public static bool Patched = false;
public static void TogglePatches(bool toggle)
{
if (toggle)
{
Main.Instance.Patch(VRCPlayerAwake,
postfix: new HarmonyMethod(VRCPlayerPatch)
);
foreach (var method in NameplateMethods)
{
Main.Instance.Patch(method,
postfix: new HarmonyMethod(typeof(Patches).GetMethod(nameof(NameplateBlanketPatch))));
}
Patched = true;
}
else if (Patched == false) return;
else
{
Main.Instance.Unpatch(VRCPlayerAwake,VRCPlayerPatch);
foreach (var method in NameplateMethods)
{
Main.Instance.Unpatch(method, NameplateMethodsPatch);
}
Patched = false;
}
var word = (toggle ? "Patched" : "Unpatched");
MelonLogger.Msg($"{word} VRCPlayer.Awake()");
MelonLogger.Msg($"{word} Nameplate Methods: {string.Join(", ",NameplateMethods.Select(methodName=>methodName.Name))}");
}
//"borrowed" from nameplate king https://github.com/ddakebono/BTKSANameplateFix/blob/6a150d520e6a49e2e1ea3484ec673899380f9ccb/BTKSANameplateMod.cs#L715
public static void OnVRCPlayerAwake(VRCPlayer __instance)
{
__instance.Method_Public_add_Void_OnAvatarIsReady_0(new System.Action(() =>
{
if (__instance != null && __instance._player != null && __instance._player.prop_APIUser_0 != null)
{
Nameplate.OnAvatarReady(__instance);
}
}));
}
// "borrowed" with love from https://github.com/ddakebono/BTKSANameplateFix/blob/6a150d520e6a49e2e1ea3484ec673899380f9ccb/BTKSANameplateMod.cs#L646
public static void NameplateBlanketPatch(PlayerNameplate __instance)
{
Nameplate.NameplateBlanketPatch(__instance);
}
}
}