-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreatureTrackerPatch.cs
86 lines (74 loc) · 3.27 KB
/
CreatureTrackerPatch.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
using HarmonyLib;
using UnityEngine;
namespace CreatureTrackerMinimap
{
[HarmonyPatch]
internal class CreatureTrackerPatch
{
[HarmonyPatch(typeof(Character), "Awake")]
[HarmonyPostfix]
static void Character_Awake(Character __instance)
{
GameObject gameObject = __instance.gameObject;
Character character = gameObject.GetComponent<Character>();
if (character.IsPlayer()) return;
string displayName = character.m_name;
Sprite displayIcon = null;
CharacterDrop drops = gameObject.GetComponent<CharacterDrop>();
if (drops != null)
{
foreach (CharacterDrop.Drop drop in drops.m_drops)
{
bool trophy = drop.m_prefab.name.ToLower().StartsWith("trophy");
if (trophy || (displayIcon == null))
{
// Greylings don't have a trophy, so always assign the icon
// for the first drop in the table. Then, if we find a trophy,
// use it instead.
ItemDrop item = drop.m_prefab.GetComponent<ItemDrop>();
displayIcon = item.m_itemData.GetIcon();
if (trophy) break;
}
}
}
gameObject.AddComponent<CreatureTrackerComponent>().Initialize(displayName, displayIcon, __instance.GetLevel(), false);
}
[HarmonyPatch(typeof(Fish), "Awake")]
[HarmonyPostfix]
static void Fish_Awake(Fish __instance)
{
GameObject gameObject = __instance.gameObject;
ItemDrop item = __instance.GetComponent<ItemDrop>();
if (item == null) return;
string displayName = __instance.m_name;
Sprite displayIcon = item.m_itemData.GetIcon();
gameObject.AddComponent<CreatureTrackerComponent>().Initialize(displayName, displayIcon, 0, true);
}
[HarmonyPatch(typeof(Character), "SetLevel")]
[HarmonyPostfix]
static void Character_SetLevel(Character __instance, int level)
{
__instance.GetComponent<CreatureTrackerComponent>().SetLevel(__instance.GetLevel());
}
[HarmonyPatch(typeof(Tameable), "Awake")]
[HarmonyPostfix]
static void Tameable_Awake(Tameable __instance, Character ___m_character)
{
if (!___m_character.IsTamed()) return;
___m_character.GetComponent<CreatureTrackerComponent>().SetName(__instance.GetHoverName());
}
[HarmonyPatch(typeof(Tameable), "RPC_SetName")]
[HarmonyPostfix]
static void Tameable_RPC_SetName(Tameable __instance, long sender, string name, string authorId)
{
__instance.GetComponent<CreatureTrackerComponent>().SetName(__instance.GetHoverName());
}
[HarmonyPatch(typeof(EnemyHud), "UpdateHuds")]
[HarmonyPrefix]
static void EnemyHud_UpdateHuds(EnemyHud __instance, Player player, Sadle sadle, float dt)
{
__instance.m_maxShowDistance = CreatureTrackerMinimap.cfgHudDistance.Value;
__instance.m_hoverShowDuration = CreatureTrackerMinimap.cfgHudDuration.Value;
}
}
}