-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
227 lines (201 loc) · 9.76 KB
/
Plugin.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System.Collections.Generic;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
namespace UKFreshnessCoach
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
[BepInProcess("ULTRAKILL.exe")]
public class UKFreshnessCoach : BaseUnityPlugin
{
private static Harmony harmony;
private static BepInEx.Logging.ManualLogSource _logger;
// Configuration values
// Behavior
private static ConfigEntry<bool> shaking;
private static ConfigEntry<bool> flashing;
// Messages
private static ConfigEntry<string> usedMessage;
private static ConfigEntry<string> staleMessage;
private static ConfigEntry<string> dullMessage;
// Colors
private static ConfigEntry<string> usedPrimaryColor;
private static ConfigEntry<string> usedSecondaryColor;
private static ConfigEntry<string> stalePrimaryColor;
private static ConfigEntry<string> staleSecondaryColor;
private static ConfigEntry<string> dullPrimaryColor;
private static ConfigEntry<string> dullSecondaryColor;
private static GameObject crosshair;
private static GameObject textObject;
private static Vector3 textHomePos;
private static TMPro.TextMeshProUGUI textComp;
private static float freshMin;
private static float usedMin;
private static float staleMin;
private void Awake()
{
harmony = new Harmony(PluginInfo.PLUGIN_GUID);
harmony.PatchAll(typeof(UKFreshnessCoach));
// Plugin startup logic
_logger = Logger;
Logger.LogDebug($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
// Load config
shaking = Config.Bind("General",
"Shaking",
true,
"Shake the text.");
flashing = Config.Bind("General",
"Flashing",
true,
"Flash the text.");
usedMessage = Config.Bind("General",
"UsedMessage",
"USE A DIFFERENT FUCKING GUN",
"Message displayed when the current freshness is \"Used\".");
staleMessage = Config.Bind("General",
"StaleMessage",
"YOU'RE NOT VERY GOOD AT THIS",
"Message displayed when the current freshness is \"Stale\".");
dullMessage = Config.Bind("General",
"DullMessage",
"GO PLAY A VISUAL NOVEL",
"Message displayed when the current freshness is \"Dull\".");
usedPrimaryColor = Config.Bind("Colors",
"UsedPrimaryColor",
"white",
"Primary color used when the current freshness is \"Used\".");
usedSecondaryColor = Config.Bind("Colors",
"UsedSecondaryColor",
"orange",
"Secondary color used when the current freshness is \"Used\".");
stalePrimaryColor = Config.Bind("Colors",
"StalePrimaryColor",
"orange",
"Primary color used when the current freshness is \"Stale\".");
staleSecondaryColor = Config.Bind("Colors",
"StaleSecondaryColor",
"red",
"Secondary color used when the current freshness is \"Stale\".");
dullPrimaryColor = Config.Bind("Colors",
"DullPrimaryColor",
"red",
"Primary color used when the current freshness is \"Dull\".");
dullSecondaryColor = Config.Bind("Colors",
"DullSecondaryColor",
"black",
"Secondary color used when the current freshness is \"Dull\".");
}
// Retrieve the current settings for when the current weapon becomes used and stale
[HarmonyPatch(typeof(StyleHUD), "Start")]
[HarmonyPostfix]
static void InspectStyleHUD(StyleHUD __instance) {
var traverse = Traverse.Create(__instance);
var freshnessStateData = traverse.Field("freshnessStateData").GetValue<List<StyleFreshnessData>>();
foreach (var item in freshnessStateData) {
if (item.state == StyleFreshnessState.Fresh) {
freshMin = item.min;
} else if (item.state == StyleFreshnessState.Used) {
usedMin = item.min;
} else if (item.state == StyleFreshnessState.Stale) {
staleMin = item.min;
}
}
}
// Initialize the text objects
[HarmonyPatch(typeof(Crosshair), "Start")]
[HarmonyPrefix]
static void GetCrosshair()
{
crosshair = GameObject.Find("Canvas/Crosshair Filler/Crosshair");
textObject = new GameObject("FreshnessCoach");
textObject = UnityEngine.Object.Instantiate(textObject, crosshair.transform);
textObject.SetActive(false);
textHomePos = new Vector3 (
textObject.transform.localPosition.x,
textObject.transform.localPosition.y - 60,
textObject.transform.localPosition.z
);
textObject.transform.localPosition = textHomePos;
textComp = textObject.AddComponent<TMPro.TextMeshProUGUI>();
// steal font from another object
var vcrOsdMono = GameObject.Find("Canvas/Boss Healths/Boss Health 1/Panel/Filler/Slider/HP Text")
.GetComponent<TMPro.TextMeshProUGUI>().font;
textComp.font = vcrOsdMono;
textComp.color = Color.red;
textComp.fontSize = 16;
textComp.alignment = TMPro.TextAlignmentOptions.Center;
}
// Update the text object based on the current freshness
[HarmonyPatch(typeof(StyleHUD), nameof(StyleHUD.SetFreshness))]
[HarmonyPostfix]
static void SetFreshnessCoach(GameObject sourceWeapon, float amt, ref GunControl ___gc)
{
if (sourceWeapon != ___gc.currentWeapon) return;
textObject.SetActive(amt < freshMin);
int millisecond = (int) ((UnityEngine.Time.fixedTime - System.Math.Truncate(UnityEngine.Time.fixedTime)) * 100);
string color;
if (amt < staleMin) {
if (flashing.Value && millisecond / 4 % 2 == 0) {
color = dullSecondaryColor.Value;
} else {
color = dullPrimaryColor.Value;
}
textComp.text = $"<color={color}>{dullMessage.Value}</color>";
textComp.fontSize = 22;
if (shaking.Value) {
textObject.transform.localPosition = new Vector3(
textHomePos.x + UnityEngine.Random.Range(-4, 4),
textHomePos.y + UnityEngine.Random.Range(-4, 4),
textHomePos.z
);
}
} else if (amt < usedMin) {
if (flashing.Value && millisecond / 4 % 2 == 0) {
color = staleSecondaryColor.Value;
} else {
color = stalePrimaryColor.Value;
}
textComp.text = $"<color={color}>{staleMessage.Value}</color>";
textComp.fontSize = 20;
if (shaking.Value) {
textObject.transform.localPosition = new Vector3(
textHomePos.x + UnityEngine.Random.Range(-3, 3),
textHomePos.y + UnityEngine.Random.Range(-3, 3),
textHomePos.z
);
}
} else if (amt < freshMin) {
if (flashing.Value && millisecond / 6 % 2 == 0) {
color = usedSecondaryColor.Value;
} else {
color = usedPrimaryColor.Value;
}
textComp.text = $"<color={color}>{usedMessage.Value}</color>";
textComp.fontSize = 16;
if (shaking.Value) {
textObject.transform.localPosition = new Vector3(
textHomePos.x + UnityEngine.Random.Range(-2, 2),
textHomePos.y + UnityEngine.Random.Range(-2, 2),
textHomePos.z
);
}
}
}
// When the player dies, clear the text from the screen
[HarmonyPatch(typeof(NewMovement), "GetHurt")]
[HarmonyPostfix]
static void ClearTextOnDeath(NewMovement __instance) {
if (__instance.dead) {
textObject.SetActive(false);
}
}
// When the combo ends, clear the text from the screen
[HarmonyPatch(typeof(StyleHUD), "ComboOver")]
[HarmonyPostfix]
static void ClearTextOnComboOver() {
if (textObject)
textObject.SetActive(false);
}
}
}