using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CombatIndicator")]
[assembly: AssemblyProduct("CombatIndicator")]
[assembly: AssemblyCompany("CombatIndicator")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace CombatIndicator;
public class CombatIndicatorBehaviour : MonoBehaviour
{
internal const string ChildName = "CombatIndicatorText";
private static TextMeshPro _text;
private static PUI_LocalPlayerStatus _owner;
private static int _lastState = int.MinValue;
private static bool _crosshairTinted;
private static float _nextAttach;
private static float _nextWatch;
internal static TextMeshPro CurrentText => _text;
internal static void OnStateChanged(int state)
{
if (Plugin.Enabled.Value && state != _lastState)
{
_lastState = state;
Apply(state);
}
}
private void Update()
{
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.Enabled.Value)
{
if (_lastState != int.MinValue)
{
_lastState = int.MinValue;
Clear();
}
return;
}
if (!Plugin.ShowText.Value && IsAlive())
{
Object.Destroy((Object)(object)((Component)_text).gameObject);
_text = null;
_owner = null;
}
if (Time.unscaledTime < _nextWatch)
{
return;
}
_nextWatch = Time.unscaledTime + 2f;
if (Plugin.ShowText.Value && !IsAlive() && Time.unscaledTime >= _nextAttach)
{
_nextAttach = Time.unscaledTime + 0.5f;
PlayerGuiLayer playerLayer = GuiManager.PlayerLayer;
if (playerLayer != null)
{
EnsureText(playerLayer.m_playerStatus);
}
}
Apply(_lastState = ((_lastState != int.MinValue) ? _lastState : ((int)DramaManager.CurrentStateEnum)));
}
private void OnDestroy()
{
Clear();
}
private static bool IsAlive()
{
if ((Object)(object)_text != (Object)null)
{
return (Object)(object)((Component)_text).gameObject != (Object)null;
}
return false;
}
private static bool InCombat(int state)
{
return state >= 5;
}
private static void Apply(int state)
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
bool flag = InCombat(state);
if (Plugin.RedCrosshair.Value)
{
SetCrosshair(flag);
}
if (Plugin.ShowText.Value)
{
PlayerGuiLayer playerLayer = GuiManager.PlayerLayer;
TextMeshPro val = EnsureText((playerLayer != null) ? playerLayer.m_playerStatus : null);
if ((Object)(object)val != (Object)null)
{
val.transform.localPosition = new Vector3(Plugin.TextOffsetX.Value, Plugin.TextOffsetY.Value, 0f);
float num = Mathf.Clamp(Plugin.TextScale.Value, 0.2f, 2f);
val.transform.localScale = new Vector3(num, num, num);
Color white = Color.white;
white.a = Mathf.Clamp01(Plugin.TextAlpha.Value);
((Graphic)val).color = white;
((TMP_Text)val).text = (flag ? Plugin.TextInCombat.Value : Plugin.TextOutOfCombat.Value);
}
}
}
private static void SetCrosshair(bool red)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
CrosshairGuiLayer crosshairLayer = GuiManager.CrosshairLayer;
if (crosshairLayer == null)
{
return;
}
CircleCrosshair circleCrosshair = crosshairLayer.m_circleCrosshair;
if (!((Object)(object)circleCrosshair == (Object)null))
{
if (red)
{
circleCrosshair.SetColor(Color.red);
}
else
{
circleCrosshair.ResetColor();
}
_crosshairTinted = red;
}
}
private static void Clear()
{
if ((Object)(object)_text != (Object)null && (Object)(object)((Component)_text).gameObject != (Object)null)
{
Object.Destroy((Object)(object)((Component)_text).gameObject);
}
_text = null;
_owner = null;
if (_crosshairTinted)
{
_crosshairTinted = false;
CrosshairGuiLayer crosshairLayer = GuiManager.CrosshairLayer;
if (crosshairLayer != null && (Object)(object)crosshairLayer.m_circleCrosshair != (Object)null)
{
crosshairLayer.m_circleCrosshair.ResetColor();
}
}
}
internal static TextMeshPro EnsureText(PUI_LocalPlayerStatus status)
{
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Expected I4, but got Unknown
if ((Object)(object)status == (Object)null)
{
return null;
}
if (IsAlive() && (Object)(object)_owner == (Object)(object)status)
{
return _text;
}
if (IsAlive() && (Object)(object)_owner != (Object)(object)status)
{
_text = null;
}
Transform val = FindChild(((Component)status).transform, "CombatIndicatorText");
if ((Object)(object)val != (Object)null)
{
_text = ((Component)val).GetComponent<TextMeshPro>();
_owner = status;
return _text;
}
TextMeshPro healthText = status.m_healthText;
if ((Object)(object)healthText == (Object)null)
{
return null;
}
TextMeshPro val2 = Object.Instantiate<TextMeshPro>(healthText);
((Object)val2).name = "CombatIndicatorText";
val2.transform.SetParent(((Component)status).transform, false);
val2.transform.localPosition = new Vector3(Plugin.TextOffsetX.Value, Plugin.TextOffsetY.Value, 0f);
float num = Mathf.Clamp(Plugin.TextScale.Value, 0.2f, 2f);
val2.transform.localScale = new Vector3(num, num, num);
((TMP_Text)val2).rectTransform.sizeDelta = new Vector2(300f, 25f);
((TMP_Text)val2).alignment = (TextAlignmentOptions)516;
((TMP_Text)val2).characterSpacing = -4.5f;
((TMP_Text)val2).enableWordWrapping = false;
((TMP_Text)val2).enableAutoSizing = false;
Color white = Color.white;
white.a = Mathf.Clamp01(Plugin.TextAlpha.Value);
((Graphic)val2).color = white;
((TMP_Text)val2).text = (InCombat((int)DramaManager.CurrentStateEnum) ? Plugin.TextInCombat.Value : Plugin.TextOutOfCombat.Value);
try
{
((TMP_Text)val2).ForceMeshUpdate(false, false);
}
catch
{
}
_text = val2;
_owner = status;
return _text;
}
private static Transform FindChild(Transform root, string name)
{
if ((Object)(object)root == (Object)null)
{
return null;
}
int childCount = root.childCount;
for (int i = 0; i < childCount; i++)
{
Transform child = root.GetChild(i);
if (!((Object)(object)child == (Object)null))
{
if (((Object)child).name == name)
{
return child;
}
Transform val = FindChild(child, name);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
}
return null;
}
}
[HarmonyPatch(typeof(PUI_LocalPlayerStatus))]
internal static class PUI_LocalPlayerStatus_Patches
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
[HarmonyWrapSafe]
private static void Start_Postfix(PUI_LocalPlayerStatus __instance)
{
if (Plugin.ShowText.Value)
{
CombatIndicatorBehaviour.EnsureText(__instance);
}
}
[HarmonyPatch("UpdateBPM")]
[HarmonyPostfix]
[HarmonyWrapSafe]
private static void UpdateBPM_Postfix(PUI_LocalPlayerStatus __instance)
{
if (Plugin.ShowText.Value)
{
CombatIndicatorBehaviour.EnsureText(__instance);
}
}
}
[HarmonyPatch(typeof(DramaManager))]
internal static class DramaManager_Patches
{
[HarmonyPatch("ChangeState")]
[HarmonyPostfix]
[HarmonyWrapSafe]
private static void ChangeState_Postfix(DRAMA_State state)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected I4, but got Unknown
CombatIndicatorBehaviour.OnStateChanged((int)state);
}
}
[BepInPlugin("CombatIndicator", "CombatIndicator", "1.1.0")]
public class Plugin : BasePlugin
{
internal const string PluginGuid = "CombatIndicator";
internal static Plugin Instance;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<bool> RedCrosshair;
internal static ConfigEntry<bool> ShowText;
internal static ConfigEntry<string> TextInCombat;
internal static ConfigEntry<string> TextOutOfCombat;
internal static ConfigEntry<float> TextAlpha;
internal static ConfigEntry<float> TextOffsetX;
internal static ConfigEntry<float> TextOffsetY;
internal static ConfigEntry<float> TextScale;
public override void Load()
{
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Expected O, but got Unknown
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Expected O, but got Unknown
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Enabled = ((BasePlugin)this).Config.Bind<bool>("1-General", "Enabled", true, "总开关。\nMaster switch.");
RedCrosshair = ((BasePlugin)this).Config.Bind<bool>("1-General", "RedCrosshair", false, "战斗中将准心染红(原版行为)。\nTint the circle crosshair red while in combat (original behaviour).");
ShowText = ((BasePlugin)this).Config.Bind<bool>("1-General", "ShowText", true, "在状态面板右侧显示战斗状态文字。\nShow the combat state text next to the player status panel.");
TextInCombat = ((BasePlugin)this).Config.Bind<string>("2-Text", "InCombat", "InCombat", "战斗中的文字。\nText shown while in combat.");
TextOutOfCombat = ((BasePlugin)this).Config.Bind<string>("2-Text", "OutOfCombat", "OutOfCombat", "非战斗时的文字。\nText shown while out of combat.");
TextAlpha = ((BasePlugin)this).Config.Bind<float>("2-Text", "Alpha", 0.1961f, new ConfigDescription("文字不透明度。\nText opacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), Array.Empty<object>()));
TextOffsetX = ((BasePlugin)this).Config.Bind<float>("2-Text", "OffsetX", 245f, "相对状态面板的横向位置(像素)。\nHorizontal offset from the status panel (px).");
TextOffsetY = ((BasePlugin)this).Config.Bind<float>("2-Text", "OffsetY", 27.5f, "相对状态面板的纵向位置(像素)。\nVertical offset from the status panel (px).");
TextScale = ((BasePlugin)this).Config.Bind<float>("2-Text", "Scale", 0.625f, new ConfigDescription("文字缩放。\nText scale.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 2f), Array.Empty<object>()));
try
{
new Harmony("CombatIndicator").PatchAll(typeof(Plugin).Assembly);
((BasePlugin)this).Log.LogInfo((object)"[CombatIndicator] Harmony patches applied.");
}
catch (Exception ex)
{
((BasePlugin)this).Log.LogWarning((object)("[CombatIndicator] Harmony patch failed: " + ex.Message));
}
((BasePlugin)this).AddComponent<CombatIndicatorBehaviour>();
((BasePlugin)this).Log.LogInfo((object)"[CombatIndicator] v1.1.0 loaded (PreciseUI-safe build).");
}
}