/
PlayerPatch.cs
39 lines (33 loc) · 1.21 KB
/
PlayerPatch.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
using HarmonyLib;
namespace DiscordNotifier.Patches
{
internal class PlayerPatch
{
private static bool hasSpawned = false;
private static ZNet.PlayerInfo getBasicPlayerInfoFromPlayer(Player player) => new ZNet.PlayerInfo
{
m_characterID = player.GetZDOID(),
m_name = player.GetPlayerName(),
m_position = player.transform.position
};
[HarmonyPatch(typeof(Player), "OnSpawned")]
internal class OnSpawned
{
private static void Prefix(ref Player __instance)
{
if (hasSpawned || !ZNet.instance.IsServer() || ZNet.instance.IsDedicated()) return;
hasSpawned = true;
ValheimEventHandler.OnPlayerJoined(getBasicPlayerInfoFromPlayer(__instance));
}
}
[HarmonyPatch(typeof(Player), "OnDeath")]
internal class OnDeath
{
private static void Postfix(ref Player __instance)
{
if (!ZNet.instance.IsServer() || ZNet.instance.IsDedicated()) return;
ValheimEventHandler.OnPlayerDeath(getBasicPlayerInfoFromPlayer(__instance));
}
}
}
}