Skip to content

Commit 2931f5e

Browse files
stuff
1 parent 7ddd0b6 commit 2931f5e

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

AdvancedHints/Components/HudManager.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,24 @@ private void UpdateHints()
128128

129129
string newHint = string.Format(Plugin.Singleton.Config.HudTemplate, toFormat);
130130
if (Debug && newHint != hint)
131-
player.SendConsoleMessage(newHint, "white");
131+
player.SendConsoleMessage(CleanseString(newHint), "white");
132132
hint = newHint;
133133

134-
player.ShowHint(Plugin.HintPrefix + hint, Plugin.Singleton.Config.HintDuration);
134+
player.ShowHint(Plugin.HintPrefixSkip + hint, Plugin.Singleton.Config.HintDuration);
135+
}
136+
137+
private string CleanseString(string text)
138+
{
139+
return text.Replace("\n", "nl")
140+
.Replace('<', '[')
141+
.Replace('>', ']');
135142
}
136143

137144
private string FormatStringForHud(string text, int needNewLine)
138145
{
146+
if (text.StartsWith(Plugin.HintPrefixNoFormat))
147+
return text.Substring(Plugin.HintPrefixNoFormat.Length);
148+
139149
int curNewLine = text.Count(x => x == '\n');
140150
for (int i = 0; i < needNewLine - curNewLine; i++)
141151
text += '\n';

AdvancedHints/Patches/ShowHint.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,44 @@ namespace AdvancedHints.Patches
1010
#pragma warning disable SA1313
1111
using System;
1212
using System.Linq;
13+
using System.Reflection;
1314
using AdvancedHints.Components;
1415
using AdvancedHints.Enums;
1516
using Exiled.API.Features;
1617
using Exiled.Loader;
1718
using HarmonyLib;
19+
using Hints;
20+
using Hint = Hints.Hint;
1821

1922
/// <summary>
20-
/// Hijacks <see cref="Player.ShowHint(string, float)"/> and directs it towards <see cref="ShowHint"/>.
23+
/// Hijacks <see cref="HintDisplay.Show"/> and directs it towards <see cref="ShowHint"/>.
2124
/// </summary>
22-
[HarmonyPatch(typeof(Player), nameof(Player.ShowHint), typeof(string), typeof(float))]
25+
[HarmonyPatch(typeof(HintDisplay), nameof(HintDisplay.Show))]
2326
internal static class ShowHint
2427
{
25-
private static bool Prefix(Player __instance, ref string message, float duration = 3f)
28+
private static bool Prefix(HintDisplay __instance, Hint hint)
2629
{
27-
if (message.StartsWith(Plugin.HintPrefix))
30+
if (hint is not TextHint textHint || !Player.TryGet(__instance.gameObject, out Player player))
31+
return true;
32+
33+
if (textHint.Text.StartsWith(Plugin.HintPrefixSkip))
2834
{
29-
message = message.Substring(Plugin.HintPrefix.Length);
35+
textHint.Text = textHint.Text.Substring(Plugin.HintPrefixSkip.Length);
36+
if (textHint.Parameters.ElementAtOrDefault(0) is StringHintParameter stringHintParameter)
37+
{
38+
if (stringHintParameter.Value.StartsWith(Plugin.HintPrefixSkip))
39+
stringHintParameter.Value = stringHintParameter.Value.Substring(Plugin.HintPrefixSkip.Length); // idk if this is necessary
40+
}
41+
3042
return true;
3143
}
3244

45+
ProcessHint(player, textHint.Text, textHint.DurationScalar);
46+
return false;
47+
}
48+
49+
private static void ProcessHint(Player player, string message, float duration)
50+
{
3351
DisplayLocation displayLocation = DisplayLocation.MiddleBottom;
3452

3553
if (Plugin.Singleton.Config.EnableMessageStartsWithOverrides)
@@ -51,7 +69,7 @@ private static bool Prefix(Player __instance, ref string message, float duration
5169
var stackTrace = new System.Diagnostics.StackTrace();
5270
if (stackTrace.FrameCount >= 3)
5371
{
54-
var caller = stackTrace.GetFrame(2).GetMethod().DeclaringType?.Assembly;
72+
Assembly caller = stackTrace.GetFrame(2).GetMethod().DeclaringType?.Assembly;
5573
if (caller != null)
5674
{
5775
var plugin = Loader.Plugins.FirstOrDefault(x => x?.Assembly == caller);
@@ -71,12 +89,11 @@ private static bool Prefix(Player __instance, ref string message, float duration
7189
}
7290
catch (Exception e)
7391
{
74-
Log.Debug("Patch override: " + e.GetType());
92+
Log.Debug("Patch override error: " + e.GetType());
7593
}
7694
}
7795

78-
HudManager.ShowHint(__instance, message, duration, true, displayLocation);
79-
return false;
96+
HudManager.ShowHint(player, message, duration, true, displayLocation);
8097
}
8198
}
8299
}

AdvancedHints/Plugin.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ public class Plugin : Plugin<Config>
2121
/// <summary>
2222
/// The prefix that makes the patch ignore the hint.
2323
/// </summary>
24-
public const string HintPrefix = "ADVHINTS";
24+
public const string HintPrefixSkip = "ADVHINTSIGNORE";
25+
26+
/// <summary>
27+
/// The prefix that makes the plugin not add formatting (new lines for positions) to it.
28+
/// </summary>
29+
public const string HintPrefixNoFormat = "ADVHINTSNF";
30+
2531
private EventHandlers eventHandlers;
2632
private Harmony harmony;
2733

0 commit comments

Comments
 (0)