using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("StatusEffectMonitor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StatusEffectMonitor")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ab906be3-5112-494e-98e3-d2e724fc84e2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.Abozos.StatusEffectMonitor", "StatusEffectMonitor", "1.3.0")]
public class StatusEffectMonitor : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <DelayedStart>d__10 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public StatusEffectMonitor <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DelayedStart>d__10(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
int num = <>1__state;
StatusEffectMonitor statusEffectMonitor = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if ((Object)(object)statusEffectMonitor._iconContainer == (Object)null)
{
((BaseUnityPlugin)statusEffectMonitor).Logger.LogError((object)"Canvas was not initialized correctly.");
return false;
}
((MonoBehaviour)statusEffectMonitor).InvokeRepeating("UpdateUI", 0f, 1f);
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private GameObject _canvasRoot;
private RectTransform _iconContainer;
private readonly Dictionary<string, Sprite> _effectIcons = new Dictionary<string, Sprite>();
private readonly Dictionary<string, string> _monitoredEffects = new Dictionary<string, string>();
private readonly Dictionary<string, ConfigEntry<bool>> _effectToggles = new Dictionary<string, ConfigEntry<bool>>();
private readonly Dictionary<string, string> _effectToIconMap = new Dictionary<string, string>();
private const float IconSize = 40f;
private const float Padding = 5f;
private readonly Dictionary<string, List<int>> _resistanceHashes = new Dictionary<string, List<int>>();
private void Awake()
{
_effectToIconMap.Add("Rested", "Rested");
_effectToIconMap.Add("FrostResist", "Frost");
_effectToIconMap.Add("PoisonResist", "Poison");
_effectToIconMap.Add("FireResist", "Burning");
_effectToIconMap.Add("Wet", "Wet");
_effectToIconMap.Add("Cold", "Cold");
_resistanceHashes["FrostResist"] = new List<int>
{
StringExtensionMethods.GetStableHashCode("Potion_frostresist"),
StringExtensionMethods.GetStableHashCode("SE_Potion_frostresist")
};
_resistanceHashes["PoisonResist"] = new List<int>
{
StringExtensionMethods.GetStableHashCode("Potion_poisonresist"),
StringExtensionMethods.GetStableHashCode("SE_Potion_poisonresist")
};
_resistanceHashes["FireResist"] = new List<int>
{
StringExtensionMethods.GetStableHashCode("Potion_barleywine"),
StringExtensionMethods.GetStableHashCode("SE_Potion_barleywine")
};
AddEffect("Rested");
AddEffect("FrostResist");
AddEffect("PoisonResist");
AddEffect("FireResist");
AddEffect("Wet", invertCheck: true);
AddEffect("Cold", invertCheck: true);
CreateCanvas();
_canvasRoot.SetActive(false);
((MonoBehaviour)this).StartCoroutine(DelayedStart());
}
[IteratorStateMachine(typeof(<DelayedStart>d__10))]
private IEnumerator DelayedStart()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DelayedStart>d__10(0)
{
<>4__this = this
};
}
private void AddEffect(string name, bool invertCheck = false, string iconKey = null)
{
iconKey = iconKey ?? name;
_monitoredEffects[name] = iconKey + (invertCheck ? "_inv" : "");
_effectToggles[name] = ((BaseUnityPlugin)this).Config.Bind<bool>("TrackedEffects", name, true, "Track " + name + " effect?");
}
private void CreateCanvas()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Expected O, but got Unknown
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
_canvasRoot = new GameObject("StatusEffectReminderCanvas");
Object.DontDestroyOnLoad((Object)(object)_canvasRoot);
Canvas obj = _canvasRoot.AddComponent<Canvas>();
obj.renderMode = (RenderMode)0;
obj.sortingOrder = 1000;
CanvasScaler obj2 = _canvasRoot.AddComponent<CanvasScaler>();
obj2.uiScaleMode = (ScaleMode)1;
obj2.referenceResolution = new Vector2(1920f, 1080f);
obj2.matchWidthOrHeight = 0.5f;
_canvasRoot.AddComponent<GraphicRaycaster>();
GameObject val = new GameObject("Panel");
val.transform.SetParent(_canvasRoot.transform, false);
_iconContainer = val.AddComponent<RectTransform>();
_iconContainer.anchorMin = new Vector2(0.5f, 0f);
_iconContainer.anchorMax = new Vector2(0.5f, 0f);
_iconContainer.pivot = new Vector2(0.5f, 0.5f);
_iconContainer.anchoredPosition = new Vector2(0f, 80f);
_iconContainer.sizeDelta = new Vector2(225f, 90f);
}
private void UpdateUI()
{
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Player.m_localPlayer == (Object)null || ((Character)Player.m_localPlayer).GetSEMan() == null)
{
if (_canvasRoot.activeSelf)
{
_canvasRoot.SetActive(false);
}
return;
}
if (!_canvasRoot.activeSelf)
{
_canvasRoot.SetActive(true);
}
if ((Object)(object)_iconContainer == (Object)null)
{
return;
}
SEMan sEMan = ((Character)Player.m_localPlayer).GetSEMan();
List<string> list = new List<string>();
foreach (KeyValuePair<string, string> monitoredEffect in _monitoredEffects)
{
string key = monitoredEffect.Key;
string value = monitoredEffect.Value;
if (!_effectToggles[key].Value)
{
continue;
}
bool flag = false;
bool flag2 = value.EndsWith("_inv");
if (_resistanceHashes.ContainsKey(key))
{
foreach (int item in _resistanceHashes[key])
{
if (sEMan.HaveStatusEffect(item))
{
flag = true;
break;
}
}
}
else
{
int stableHashCode = StringExtensionMethods.GetStableHashCode(key);
flag = sEMan.HaveStatusEffect(stableHashCode);
}
if ((!flag2 && !flag) || (flag2 && flag))
{
list.Add(key);
}
}
foreach (Transform item2 in (Transform)_iconContainer)
{
Object.Destroy((Object)(object)((Component)item2).gameObject);
}
if (list.Count != 0)
{
int count = list.Count;
int num = Mathf.CeilToInt((float)count / 5f);
int num2 = Mathf.Min(count, 5);
float num3 = 45f * (float)num2;
float num4 = 45f * (float)num;
_iconContainer.sizeDelta = new Vector2(num3, num4);
for (int i = 0; i < list.Count && i < 10; i++)
{
GameObject val = new GameObject("Icon_" + i);
val.transform.SetParent((Transform)(object)_iconContainer, false);
RectTransform obj = val.AddComponent<RectTransform>();
obj.sizeDelta = new Vector2(40f, 40f);
int num5 = i / 5;
int num6 = i % 5;
float num7 = 0f - num3 / 2f + 20f + (float)num6 * 45f;
float num8 = num4 / 2f - 20f - (float)num5 * 45f;
obj.anchoredPosition = new Vector2(num7, num8);
Image obj2 = val.AddComponent<Image>();
obj2.sprite = GetEffectIcon(list[i]);
((Graphic)obj2).color = new Color(1f, 1f, 1f, 0.7f);
}
}
}
private Sprite GetEffectIcon(string effectKey)
{
if (_effectIcons.TryGetValue(effectKey, out var value))
{
return value;
}
if ((Object)(object)ObjectDB.instance == (Object)null)
{
return null;
}
string text = _monitoredEffects[effectKey]?.Replace("_inv", "");
if (string.IsNullOrEmpty(text))
{
return null;
}
if (_effectToIconMap.ContainsKey(text))
{
text = _effectToIconMap[text];
}
foreach (StatusEffect statusEffect in ObjectDB.instance.m_StatusEffects)
{
if (!((Object)(object)statusEffect == (Object)null) && !((Object)(object)statusEffect.m_icon == (Object)null) && (((Object)statusEffect).name.Equals(text, StringComparison.OrdinalIgnoreCase) || ((Object)statusEffect).name.Contains(text)))
{
_effectIcons[effectKey] = statusEffect.m_icon;
return statusEffect.m_icon;
}
}
foreach (StatusEffect statusEffect2 in ObjectDB.instance.m_StatusEffects)
{
if (!((Object)(object)statusEffect2 == (Object)null) && !((Object)(object)statusEffect2.m_icon == (Object)null) && ((Object)statusEffect2).name.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
{
_effectIcons[effectKey] = statusEffect2.m_icon;
return statusEffect2.m_icon;
}
}
foreach (StatusEffect statusEffect3 in ObjectDB.instance.m_StatusEffects)
{
if (!((Object)(object)statusEffect3 == (Object)null) && !((Object)(object)statusEffect3.m_icon == (Object)null) && ((text.Contains("Frost") && ((Object)statusEffect3).name.Contains("Frost")) || (text.Contains("Cold") && ((Object)statusEffect3).name.Contains("Cold")) || (text.Contains("Poison") && ((Object)statusEffect3).name.Contains("Poison")) || (text.Contains("Fire") && ((Object)statusEffect3).name.Contains("Fire")) || (text.Contains("Burn") && ((Object)statusEffect3).name.Contains("Burn")) || (text.Contains("Wet") && ((Object)statusEffect3).name.Contains("Wet")) || (text.Contains("Rest") && ((Object)statusEffect3).name.Contains("Rest"))))
{
_effectIcons[effectKey] = statusEffect3.m_icon;
return statusEffect3.m_icon;
}
}
return null;
}
}