-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
109 lines (100 loc) · 3.63 KB
/
Copy pathPlugin.cs
File metadata and controls
109 lines (100 loc) · 3.63 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
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
103
104
105
106
107
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.Mono;
using HarmonyLib;
using TMPro;
using UnityEngine;
namespace Zombie_Counter
{
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public static int DemonsLeft = 0;
internal static new ManualLogSource Logger;
private static TextMeshProUGUI _DemonsText;
public static GameObject Hud;
private void Awake()
{
// Plugin startup logic
Logger = base.Logger;
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
var harmony = new Harmony("test");
harmony.PatchAll();
}
public static void UpdateDemonsLeft(AgentBehaviourSpawner spawner)
{
int previousDemonsLeft = DemonsLeft;
DemonsLeft = Traverse.Create(spawner)
.Field("curSpawnedDemons")
.GetValue<int>();
if (previousDemonsLeft == DemonsLeft)
return;
Plugin.Logger.LogInfo($"Demons left: {Plugin.DemonsLeft}");
if (_DemonsText == null)
{
if (Hud == null)
Hud = GameObject.Find("GameHUD_UI");
CreateHudText(Hud);
}
_DemonsText.SetText($"Demons: {DemonsLeft}");
}
private static void CreateHudText(GameObject parent)
{
Logger.LogInfo("Creating HUD text...");
if (_DemonsText != null)
return;
GameObject textObj = new GameObject("DemonsCounterText");
textObj.transform.SetParent(parent.transform, false);
RectTransform rect = textObj.AddComponent<RectTransform>();
_DemonsText = textObj.AddComponent<TextMeshProUGUI>();
_DemonsText.text = "Demons: 0";
_DemonsText.fontSize = 28;
_DemonsText.color = Color.red;
_DemonsText.alignment = TextAlignmentOptions.Center;
rect.anchorMin = new Vector2(0.5f, 1f);
rect.anchorMax = new Vector2(0.5f, 1f);
rect.pivot = new Vector2(0.5f, 1f);
rect.anchoredPosition = new Vector2(0f, -5f);
}
}
[HarmonyPatch(typeof(AgentBehaviourSpawner), nameof(AgentBehaviourSpawner.DespawnAll))]
public class AgentBehaviourSpawner_DespawnAll_Patch
{
public static void Postfix(AgentBehaviourSpawner __instance)
{
Plugin.UpdateDemonsLeft(__instance);
}
}
[HarmonyPatch(typeof(AgentBehaviourSpawner), "LowerCount")]
public class AgentBehaviourSpawner_LowerCount_Patch
{
public static void Postfix(AgentBehaviourSpawner __instance)
{
Plugin.UpdateDemonsLeft(__instance);
}
}
[HarmonyPatch(typeof(AgentBehaviourSpawner), nameof(AgentBehaviourSpawner.OverrideCheck))]
public class AgentBehaviourSpawner_OverrideCheck_Patch
{
public static void Postfix(AgentBehaviourSpawner __instance)
{
Plugin.UpdateDemonsLeft(__instance);
}
}
[HarmonyPatch(typeof(AgentBehaviourSpawner), "ReturnToPool")]
public class AgentBehaviourSpawner_ReturnToPool_Patch
{
public static void Postfix(AgentBehaviourSpawner __instance)
{
Plugin.UpdateDemonsLeft(__instance);
}
}
[HarmonyPatch(typeof(AgentBehaviourSpawner), "SpawnAgent")]
public class AgentBehaviourSpawner_SpawnAgent_Patch
{
public static void Postfix(AgentBehaviourSpawner __instance)
{
Plugin.UpdateDemonsLeft(__instance);
}
}
}