This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatching.cs
More file actions
49 lines (40 loc) · 1.43 KB
/
Patching.cs
File metadata and controls
49 lines (40 loc) · 1.43 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
using GameNetcodeStuff;
using HarmonyLib;
using System;
using UnityEngine.InputSystem;
namespace LethalSanity
{
public class Patching
{
// ===========================================================[ Connect Client To Player Object ]=========================================================== \\
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyPostfix]
private static void _CONNECT(PlayerControllerB __instance)
{
if (GameNetworkManager.Instance.localPlayerController == __instance)
{
Connect?.Invoke(__instance);
}
}
internal static event Action<PlayerControllerB> Connect;
// ===============================================================[ Set Player Sanity Level ]================================================================ \\
[HarmonyPatch(typeof(PlayerControllerB), "SetPlayerSanityLevel")]
[HarmonyPostfix]
private static void _SANITY_SET()
{
// If the player does not exist or is dead.
if (!LocalPlayer.Player || LocalPlayer.PlayerController.isPlayerDead) return;
// if the previous value is not the same as the current value
float parsed = float.Parse(LocalPlayer.Insanity.ToString("0.0"));
if (_prev_san != parsed)
{
// Set prev value to new
_prev_san = parsed;
// Invoke virtual
SanityChanged?.Invoke(parsed);
}
}
private static float _prev_san { get; set; } = -3.141f;
internal static event Action<float> SanityChanged;
}
}