@@ -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}
0 commit comments