|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Reflection; |
| 5 | +using Exiled.API.Features; |
| 6 | +using Exiled.Loader; |
| 7 | + |
| 8 | +namespace EffectDisplay.Extension |
| 9 | +{ |
| 10 | + public class RueIHints |
| 11 | + { |
| 12 | + public static bool IsEnabled { get; private set; } = false; |
| 13 | + |
| 14 | + public static void ShowHint(ReferenceHub hub, string content, TimeSpan duration, float position = 0) |
| 15 | + { |
| 16 | + if (IsEnabled) { _shower(hub, content, position, duration); } |
| 17 | + else |
| 18 | + { |
| 19 | + Log.Debug("RueI not inited"); |
| 20 | + return; |
| 21 | + } |
| 22 | + } |
| 23 | + public static void ShowHint(Player player, string content, TimeSpan duration, float position = 0) |
| 24 | + { |
| 25 | + if (IsEnabled) { _shower(player.ReferenceHub, content, position, duration); } |
| 26 | + else |
| 27 | + { |
| 28 | + Log.Debug("RueI not inited"); |
| 29 | + return; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + public static void InitRue() |
| 34 | + { |
| 35 | + IsEnabled = false; |
| 36 | + _shower = null; |
| 37 | + Assembly ruei = Loader.Dependencies.FirstOrDefault(x => x.GetName().Name == "RueI"); |
| 38 | + if (ruei == null) { Log.Debug("RueI not found in dependencies"); return; } |
| 39 | + else |
| 40 | + { |
| 41 | + MethodInfo els = ruei.GetType("RueI.Extensions.ReflectionHelpers").GetMethod("GetElementShower"); |
| 42 | + object action = els.Invoke(null, new object[] { }); |
| 43 | + if (action is Action<ReferenceHub, string, float, TimeSpan> elst) |
| 44 | + { |
| 45 | + MethodInfo init = ruei.GetType("RueI.RueIMain").GetMethod("EnsureInit"); |
| 46 | + if (init == null) return; |
| 47 | + else |
| 48 | + { |
| 49 | + init.Invoke(null, new object[] { }); |
| 50 | + _shower = elst; |
| 51 | + IsEnabled = true; |
| 52 | + } |
| 53 | + } |
| 54 | + else |
| 55 | + { |
| 56 | + return; |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + private static Action<ReferenceHub, string, float, TimeSpan> _shower; |
| 61 | + } |
| 62 | +} |
0 commit comments