using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CombatStatistics")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CombatStatistics")]
[assembly: AssemblyTitle("CombatStatistics")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace CombatStatistics
{
internal sealed class CombatHud
{
private enum RendererMode
{
Pending,
Native,
Fallback
}
private const float Width = 340f;
private const float Height = 430f;
private readonly ConfigEntry<float> xConfig;
private readonly ConfigEntry<float> yConfig;
private bool dragging;
private readonly NativeHud native = new NativeHud();
private bool nativeDrawing;
private RendererMode rendererMode;
private float unavailableSince = -1f;
private const float NativeGraceSeconds = 3f;
private bool previousNativeSetting = true;
private Vector2 dragOffset;
private Rect panel;
private GUIStyle title;
private GUIStyle small;
private GUIStyle normal;
private GUIStyle value;
private GUIStyle large;
private GUIStyle largeRight;
private static readonly Color TextColor = Color.white;
private static readonly Color Muted = Color.white;
private static readonly Color Green = new Color(0.48f, 0.91f, 0.69f);
private static readonly Color Red = new Color(1f, 0.57f, 0.54f);
private static readonly Color Gold = new Color(0.97f, 0.8f, 0.48f);
internal void HideNative()
{
native.Hide();
unavailableSince = -1f;
}
internal void ResetRenderer()
{
native.Reset();
rendererMode = RendererMode.Pending;
unavailableSince = -1f;
}
private void SelectFallback(string reason)
{
native.Dispose();
rendererMode = RendererMode.Fallback;
Plugin.Log.LogWarning((object)("HUD renderer: IMGUI for this HUD session (" + reason + "). Toggle HUD to retry NGUI."));
}
internal void Dispose()
{
native.Dispose();
}
internal CombatHud(ConfigEntry<float> x, ConfigEntry<float> y)
{
xConfig = x;
yConfig = y;
}
private static GUIStyle Style(int size, Color color, TextAnchor align, bool bold = false)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Expected O, but got Unknown
GUIStyle val = new GUIStyle(GUI.skin.label)
{
fontSize = size,
fontStyle = (FontStyle)(bold ? 1 : 0),
alignment = align,
padding = new RectOffset(0, 0, 0, 0),
clipping = (TextClipping)1
};
val.normal.textColor = color;
return val;
}
private void EnsureStyles()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
if (title == null)
{
title = Style(16, TextColor, (TextAnchor)3, bold: true);
small = Style(11, Muted, (TextAnchor)3);
normal = Style(13, Muted, (TextAnchor)3);
value = Style(13, TextColor, (TextAnchor)5, bold: true);
large = Style(27, Green, (TextAnchor)3, bold: true);
largeRight = Style(18, Gold, (TextAnchor)5, bold: true);
}
}
private void Fill(Rect r, Color color)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
if (nativeDrawing)
{
native.Fill(r, color);
return;
}
Color color2 = GUI.color;
GUI.color = color;
GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture);
GUI.color = color2;
}
private static Rect Clamp(Rect r)
{
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
((Rect)(ref r)).x = Mathf.Clamp(((Rect)(ref r)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref r)).width));
((Rect)(ref r)).y = Mathf.Clamp(((Rect)(ref r)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref r)).height));
return r;
}
private Rect ConfigPosition()
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
float num = xConfig.Value;
float num2 = yConfig.Value;
if (float.IsNaN(num) || float.IsInfinity(num))
{
num = -1f;
}
if (float.IsNaN(num2) || float.IsInfinity(num2))
{
num2 = 28f;
}
return Clamp(new Rect((num < 0f) ? ((float)Screen.width - 340f - 24f) : num, num2, 340f, 430f));
}
internal void BeginEdit()
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
dragging = false;
panel = ConfigPosition();
}
internal void EndEdit()
{
dragging = false;
xConfig.Value = ((Rect)(ref panel)).x;
yConfig.Value = ((Rect)(ref panel)).y;
}
internal void UpdateDrag()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
Vector3 mousePosition = Input.mousePosition;
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(mousePosition.x, (float)Screen.height - mousePosition.y);
Rect val2 = default(Rect);
((Rect)(ref val2))..ctor(((Rect)(ref panel)).x, ((Rect)(ref panel)).y, 340f, 34f);
if (Input.GetMouseButtonDown(0) && ((Rect)(ref val2)).Contains(val))
{
dragging = true;
dragOffset = val - ((Rect)(ref panel)).position;
}
if (dragging && Input.GetMouseButton(0))
{
((Rect)(ref panel)).position = val - dragOffset;
}
else if (!Input.GetMouseButton(0))
{
dragging = false;
}
float num = 420f * Time.unscaledDeltaTime;
if (Input.GetKey((KeyCode)276))
{
ref Rect reference = ref panel;
((Rect)(ref reference)).x = ((Rect)(ref reference)).x - num;
}
if (Input.GetKey((KeyCode)275))
{
ref Rect reference2 = ref panel;
((Rect)(ref reference2)).x = ((Rect)(ref reference2)).x + num;
}
if (Input.GetKey((KeyCode)273))
{
ref Rect reference3 = ref panel;
((Rect)(ref reference3)).y = ((Rect)(ref reference3)).y - num;
}
if (Input.GetKey((KeyCode)274))
{
ref Rect reference4 = ref panel;
((Rect)(ref reference4)).y = ((Rect)(ref reference4)).y + num;
}
panel = Clamp(panel);
}
internal void Draw(string toggle, string reset, string edit, bool editing, bool useNative)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0592: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Invalid comparison between Unknown and I4
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_038d: Unknown result type (might be due to invalid IL or missing references)
//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
//IL_03db: Unknown result type (might be due to invalid IL or missing references)
//IL_0400: Unknown result type (might be due to invalid IL or missing references)
//IL_0420: Unknown result type (might be due to invalid IL or missing references)
//IL_043f: Unknown result type (might be due to invalid IL or missing references)
//IL_048d: Unknown result type (might be due to invalid IL or missing references)
//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
if (!editing)
{
panel = ConfigPosition();
}
if (Event.current == null || (int)Event.current.type != 7)
{
return;
}
EnsureStyles();
nativeDrawing = false;
if (useNative != previousNativeSetting)
{
ResetRenderer();
previousNativeSetting = useNative;
}
if (useNative && rendererMode != RendererMode.Fallback)
{
try
{
nativeDrawing = native.Begin(panel);
}
catch (Exception ex)
{
native.Fail(ex);
}
if (nativeDrawing)
{
if (rendererMode != RendererMode.Native)
{
Plugin.Log.LogInfo((object)"HUD renderer: native NGUI selected for this HUD session.");
}
rendererMode = RendererMode.Native;
unavailableSince = -1f;
}
else
{
native.Hide();
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (unavailableSince < 0f)
{
unavailableSince = realtimeSinceStartup;
}
if (!native.HasFailed && realtimeSinceStartup - unavailableSince < 3f)
{
return;
}
SelectFallback(native.HasFailed ? "native renderer exception" : "NGUI unavailable for 3 seconds");
}
}
if (!nativeDrawing)
{
native.Hide();
}
bool flag = nativeDrawing;
Color color = GUI.color;
int depth = GUI.depth;
GUI.color = Color.white;
GUI.depth = -100;
if (!nativeDrawing)
{
GUI.BeginGroup(panel);
}
try
{
Fill(new Rect(0f, 0f, 340f, 430f), nativeDrawing ? new Color(0.15f, 0.11f, 0.07f, 0.88f) : new Color(0.065f, 0.085f, 0.115f, 0.94f));
Fill(new Rect(0f, 0f, 340f, 34f), editing ? new Color(0.28f, 0.23f, 0.12f) : (nativeDrawing ? new Color(0.24f, 0.17f, 0.09f, 0.84f) : new Color(0.13f, 0.17f, 0.22f)));
Fill(new Rect(0f, 0f, 3f, 34f), editing ? Gold : Green);
Label(new Rect(13f, 0f, 314f, 34f), editing ? "MOVE HUD / DRAG HERE" : "COMBAT STATISTICS", title);
Label(new Rect(13f, 42f, 150f, 16f), "DPS / LAST 5 SEC", small);
Label(new Rect(13f, 58f, 150f, 34f), CombatLog.Dps.ToString("N2"), large);
Label(new Rect(190f, 42f, 135f, 16f), "PEAK DPS", small);
Label(new Rect(175f, 58f, 150f, 34f), CombatLog.PeakDps.ToString("N2"), largeRight);
Line(98f);
DrawGraph();
Line(205f);
Row(210f, "Total damage", CombatLog.PlayerTotal + CombatLog.PetTotal, Green);
Row(230f, "Player damage", CombatLog.PlayerTotal, TextColor);
Row(250f, "Pet damage", CombatLog.PetTotal, Gold);
Row(270f, "Damage received", CombatLog.IncomingTotal, Red);
DrawShare();
Label(new Rect(13f, 311f, 190f, 18f), "Hits dealt / received", normal);
value.normal.textColor = TextColor;
Label(new Rect(200f, 311f, 125f, 18f), $"{CombatLog.OutgoingHits} / {CombatLog.IncomingHits}", value);
Line(333f);
Label(new Rect(13f, 336f, 312f, 16f), "TOP SOURCES / TOTAL DAMAGE", small);
DrawSources();
Line(401f);
Label(new Rect(13f, 403f, 314f, 16f), editing ? (edit + ": Save | Drag or arrow keys") : (toggle + ": HUD | " + edit + ": Move | " + reset + ": Reset"), small);
}
catch (Exception ex2) when (nativeDrawing)
{
native.Fail(ex2);
SelectFallback("native drawing exception");
}
finally
{
if (flag)
{
if (rendererMode == RendererMode.Native)
{
try
{
native.End();
}
catch (Exception ex3)
{
native.Fail(ex3);
SelectFallback("native cleanup exception");
}
}
}
else
{
GUI.EndGroup();
}
nativeDrawing = false;
GUI.color = color;
GUI.depth = depth;
}
}
private void Label(Rect rect, string text, GUIStyle style)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
if (nativeDrawing)
{
native.Text(rect, text, style);
}
else
{
GUI.Label(rect, text, style);
}
}
private void DrawGraph()
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
float realtimeSinceStartup = Time.realtimeSinceStartup;
double num = 1.0;
for (int i = 0; i < 30; i++)
{
num = Math.Max(num, CombatLog.GetHistory(i, realtimeSinceStartup));
}
Label(new Rect(13f, 102f, 310f, 18f), "DAMAGE PER SECOND / 30 SEC", small);
Rect val = default(Rect);
((Rect)(ref val))..ctor(45f, 122f, 280f, 62f);
for (int j = 0; j <= 2; j++)
{
float num2 = ((Rect)(ref val)).y + (float)j * ((Rect)(ref val)).height / 2f;
Fill(new Rect(((Rect)(ref val)).x, num2, ((Rect)(ref val)).width, 1f), new Color(0.25f, 0.3f, 0.37f, 0.8f));
Label(new Rect(13f, num2 - 7f, 32f, 14f), (num * (double)(2 - j) / 2.0).ToString("0.#"), small);
}
float num3 = ((Rect)(ref val)).width / 30f;
for (int k = 0; k < 30; k++)
{
float num4 = (float)(CombatLog.GetHistory(29 - k, realtimeSinceStartup) / num) * ((Rect)(ref val)).height;
if (!(num4 <= 0f))
{
Fill(new Rect(((Rect)(ref val)).x + (float)k * num3 + 1f, ((Rect)(ref val)).yMax - num4, num3 - 2f, num4), (k == 29) ? Gold : Green);
}
}
Label(new Rect(45f, 185f, 140f, 16f), "-30s", small);
Label(new Rect(238f, 185f, 90f, 16f), "Now (partial)", small);
}
private void DrawShare()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
double num = CombatLog.PlayerTotal + CombatLog.PetTotal;
float num2 = ((num > 0.0) ? ((float)(CombatLog.PlayerTotal / num)) : 0f);
float num3 = 314f;
Fill(new Rect(13f, 293f, num3, 5f), new Color(0.25f, 0.3f, 0.37f));
if (num > 0.0)
{
Fill(new Rect(13f, 293f, num3 * num2, 5f), Green);
Fill(new Rect(13f + num3 * num2, 293f, num3 * (1f - num2), 5f), Gold);
}
Label(new Rect(13f, 298f, 312f, 13f), $"Player {num2 * 100f:0.#}% / Pets {((num > 0.0) ? ((1f - num2) * 100f) : 0f):0.#}%", small);
}
private void DrawSources()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
IReadOnlyList<CombatLog.SourceStat> sources = CombatLog.GetSources();
if (sources.Count == 0)
{
Label(new Rect(13f, 352f, 310f, 18f), "No outgoing damage yet", normal);
return;
}
for (int i = 0; i < Math.Min(3, sources.Count); i++)
{
CombatLog.SourceStat sourceStat = sources[i];
float num = 351 + i * 16;
Label(new Rect(13f, num, 195f, 16f), sourceStat.Name + " (" + sourceStat.Hits + ")", normal);
value.normal.textColor = ((sourceStat.Category == "PLAYER") ? Green : Gold);
Label(new Rect(205f, num, 120f, 16f), sourceStat.Damage.ToString("N2"), value);
}
}
private void Line(float y)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
Fill(new Rect(13f, y, 314f, 1f), new Color(0.25f, 0.3f, 0.37f, 0.8f));
}
private void Row(float y, string label, double amount, Color color)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
Label(new Rect(13f, y, 150f, 21f), label, normal);
value.normal.textColor = color;
Label(new Rect(170f, y, 155f, 21f), amount.ToString("N2"), value);
}
}
internal static class NativeBindings
{
internal static InputActionAsset Asset;
internal static InputActionMap Map;
internal static InputAction Toggle;
internal static InputAction Move;
internal static InputAction Reset;
private static InputActionReference[] refs;
private static bool failed;
internal static bool Ready
{
get
{
if (refs != null && (Object)(object)refs[0] != (Object)null && (Object)(object)refs[1] != (Object)null)
{
return (Object)(object)refs[2] != (Object)null;
}
return false;
}
}
internal static bool TryInitWhenReady()
{
if (!Plugin.Operational || Plugin.UseNativeBindings == null || !Plugin.UseNativeBindings.Value || failed)
{
return false;
}
if (Ready)
{
return true;
}
try
{
Init();
Plugin.Log.LogInfo((object)"Native Controls initialized after game input became available.");
return true;
}
catch (Exception ex)
{
failed = true;
try
{
Shutdown();
}
catch (Exception ex2)
{
Plugin.Warn("Native Controls cleanup", ex2);
}
Plugin.Warn("Native Controls initialization failed; using config keys", ex);
return false;
}
}
private static void Init()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
Asset = ScriptableObject.CreateInstance<InputActionAsset>();
Map = new InputActionMap("CombatStatistics");
Toggle = Add("Combat Statistics: HUD", "f6");
Move = Add("Combat Statistics: Move HUD", "f7");
Reset = Add("Combat Statistics: Reset", "f8");
InputActionSetupExtensions.AddActionMap(Asset, Map);
refs = (InputActionReference[])(object)new InputActionReference[3];
refs[0] = InputActionReference.Create(Toggle);
refs[1] = InputActionReference.Create(Move);
refs[2] = InputActionReference.Create(Reset);
InputActionReference[] array = refs;
foreach (InputActionReference val in array)
{
for (int j = 0; j < 2; j++)
{
string text = PlayerPrefs.GetString($"Rebind_{val.action.name}_{j}", "");
if (!string.IsNullOrEmpty(text) && text.Length <= 512)
{
InputActionRebindingExtensions.ApplyBindingOverride(val.action, j, text);
}
}
}
Map.Enable();
}
private static InputAction Add(string name, string key)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
InputAction obj = InputActionSetupExtensions.AddAction(Map, name, (InputActionType)1, "<Keyboard>/" + key, (string)null, (string)null, (string)null, (string)null);
InputBinding val = default(InputBinding);
((InputBinding)(ref val)).path = "";
InputActionSetupExtensions.AddBinding(obj, val);
return obj;
}
internal static bool Own(InputActionReference reference)
{
if (Ready && (Object)(object)reference != (Object)null && reference.action != null)
{
return reference.action.actionMap == Map;
}
return false;
}
internal unsafe static string Display(InputAction action, KeyCode fallback)
{
if (!Ready || action == null)
{
return ((object)(*(KeyCode*)(&fallback))/*cast due to .constrained prefix*/).ToString();
}
string bindingDisplayString = InputActionRebindingExtensions.GetBindingDisplayString(action, 0, (DisplayStringOptions)0);
string bindingDisplayString2 = InputActionRebindingExtensions.GetBindingDisplayString(action, 1, (DisplayStringOptions)0);
if (!string.IsNullOrEmpty(bindingDisplayString))
{
return bindingDisplayString;
}
if (!string.IsNullOrEmpty(bindingDisplayString2))
{
return bindingDisplayString2;
}
return "-";
}
internal static bool Pressed(InputAction action, KeyCode fallback)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
if (!Ready)
{
if ((int)fallback != 0)
{
return Input.GetKeyDown(fallback);
}
return false;
}
if (action != null && action.enabled)
{
return action.WasPressedThisFrame();
}
return false;
}
internal static void Append(LoadKeybindings menu)
{
if (!Ready || (Object)(object)menu == (Object)null || menu.actions == null)
{
return;
}
List<InputActionReference> list = new List<InputActionReference>(menu.actions);
InputActionReference[] array = refs;
foreach (InputActionReference item in array)
{
if (!list.Contains(item))
{
list.Add(item);
}
}
menu.actions = list.ToArray();
Plugin.Log.LogInfo((object)$"Native Controls: {refs.Length} mod actions in menu; total {menu.actions.Length}.");
}
internal static void Shutdown()
{
try
{
if (!Ready)
{
return;
}
LoadKeybindings[] array = Resources.FindObjectsOfTypeAll<LoadKeybindings>();
foreach (LoadKeybindings val in array)
{
if ((Object)(object)val == (Object)null || val.actions == null)
{
continue;
}
List<InputActionReference> list = new List<InputActionReference>(val.actions);
if (list.RemoveAll((InputActionReference r) => (Object)(object)r != (Object)null && Array.IndexOf(refs, r) >= 0) == 0)
{
continue;
}
val.actions = list.ToArray();
if ((Object)(object)val.container == (Object)null)
{
continue;
}
BindKey[] componentsInChildren = ((Component)val.container).GetComponentsInChildren<BindKey>(true);
foreach (BindKey val2 in componentsInChildren)
{
if (!((Object)(object)val2 == (Object)null) && Own(val2.actionReference))
{
KeybindingEntry componentInParent = ((Component)val2).GetComponentInParent<KeybindingEntry>();
GameObject obj = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).gameObject : ((Component)val2).gameObject);
obj.SetActive(false);
Object.Destroy((Object)(object)obj);
}
}
}
}
finally
{
try
{
if (Map != null)
{
Map.Disable();
}
}
finally
{
if (refs != null)
{
InputActionReference[] array2 = refs;
foreach (InputActionReference val3 in array2)
{
if ((Object)(object)val3 != (Object)null)
{
Object.Destroy((Object)(object)val3);
}
}
}
if ((Object)(object)Asset != (Object)null)
{
Object.Destroy((Object)(object)Asset);
}
refs = null;
Asset = null;
Map = null;
Toggle = (Move = (Reset = null));
}
}
}
}
[HarmonyPatch(typeof(LoadKeybindings), "loadAllKeybinds")]
internal static class NativeMenuPatch
{
[HarmonyPrepare]
private static bool Prepare()
{
if (Plugin.UseNativeBindings != null)
{
return Plugin.UseNativeBindings.Value;
}
return false;
}
[HarmonyPrefix]
private static void Prefix(LoadKeybindings __instance)
{
try
{
if (__instance.actions != null && __instance.actions.Length != 0 && NativeBindings.TryInitWhenReady())
{
NativeBindings.Append(__instance);
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Controls integration: " + ex));
}
}
[HarmonyPostfix]
private static void Postfix(LoadKeybindings __instance)
{
try
{
if (!Plugin.Operational || !NativeBindings.Ready || (Object)(object)__instance.container == (Object)null)
{
return;
}
int num = 0;
BindKey[] componentsInChildren = ((Component)__instance.container).GetComponentsInChildren<BindKey>(true);
foreach (BindKey val in componentsInChildren)
{
if (NativeBindings.Own(val.actionReference))
{
val.LoadBinding();
num++;
}
}
Plugin.Log.LogInfo((object)$"Native Controls: {num} binding slots created (expected 6).");
UIDraggablePanel componentInParent = ((Component)__instance.container).GetComponentInParent<UIDraggablePanel>();
if ((Object)(object)componentInParent != (Object)null)
{
componentInParent.UpdateScrollbars(true);
}
SettingsPageNavigation componentInParent2 = ((Component)__instance.container).GetComponentInParent<SettingsPageNavigation>();
if ((Object)(object)componentInParent2 != (Object)null)
{
componentInParent2.Rebuild();
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Controls rows: " + ex));
}
}
}
[HarmonyPatch(typeof(KeybindingEntry), "SetParams")]
internal static class NativeBindingLabelPatch
{
[HarmonyPrepare]
private static bool Prepare()
{
if (Plugin.UseNativeBindings != null)
{
return Plugin.UseNativeBindings.Value;
}
return false;
}
[HarmonyPrefix]
private static void Prefix(ref string __0, InputActionReference __3)
{
if (NativeBindings.Own(__3))
{
if (__3.action == NativeBindings.Toggle)
{
__0 = "Toggle HUD";
}
else if (__3.action == NativeBindings.Move)
{
__0 = "Move HUD";
}
else if (__3.action == NativeBindings.Reset)
{
__0 = "Reset Statistics";
}
}
}
}
[HarmonyPatch(typeof(BindKey), "OnDisable")]
internal static class NativeRebindCleanupPatch
{
[HarmonyPrepare]
private static bool Prepare()
{
if (Plugin.UseNativeBindings != null)
{
return Plugin.UseNativeBindings.Value;
}
return false;
}
[HarmonyPostfix]
private static void Postfix(BindKey __instance)
{
if (NativeBindings.Own(__instance.actionReference) && NativeBindings.Map != null)
{
NativeBindings.Map.Enable();
}
}
}
internal sealed class NativeHud
{
private GameObject holder;
private UIRoot uiRoot;
private Camera camera;
private UIFont font;
private float renderDepth;
private string lastStatus;
private UISprite background;
private Material solid;
private int labelIndex;
private int rectIndex;
private readonly List<UILabel> labels = new List<UILabel>();
private readonly List<UITexture> rects = new List<UITexture>();
private float nextTry;
private bool failed;
internal bool HasFailed => failed;
internal bool Begin(Rect panel)
{
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
if (failed)
{
return false;
}
if ((Object)(object)holder == (Object)null || (Object)(object)uiRoot == (Object)null || !((Component)uiRoot).gameObject.activeInHierarchy || (Object)(object)camera == (Object)null || !((Behaviour)camera).isActiveAndEnabled || (Object)(object)font == (Object)null || (Object)(object)font.material == (Object)null || (camera.cullingMask & (1 << holder.layer)) == 0)
{
Hide();
if (Time.realtimeSinceStartup < nextTry)
{
return false;
}
nextTry = Time.realtimeSinceStartup + 1f;
Dispose();
if (!Build())
{
return false;
}
}
holder.SetActive(true);
Transform transform = ((Component)uiRoot).transform;
float num = renderDepth;
Vector3 val = transform.InverseTransformPoint(camera.ScreenToWorldPoint(new Vector3(((Rect)(ref panel)).x, (float)Screen.height - ((Rect)(ref panel)).y, num)));
Vector3 val2 = transform.InverseTransformPoint(camera.ScreenToWorldPoint(new Vector3(((Rect)(ref panel)).x + 100f, (float)Screen.height - ((Rect)(ref panel)).y, num)));
Vector3 val3 = transform.InverseTransformPoint(camera.ScreenToWorldPoint(new Vector3(((Rect)(ref panel)).x, (float)Screen.height - ((Rect)(ref panel)).y - 100f, num)));
Vector3 val4 = val2 - val;
float num2 = ((Vector3)(ref val4)).magnitude / 100f;
val4 = val3 - val;
float num3 = ((Vector3)(ref val4)).magnitude / 100f;
if (float.IsNaN(num2) || float.IsNaN(num3) || float.IsInfinity(num2) || float.IsInfinity(num3) || num2 <= 0f || num3 <= 0f || num <= camera.nearClipPlane || num >= camera.farClipPlane)
{
Status("Native HUD waiting: widget plane outside camera clipping range.");
Dispose();
return false;
}
holder.transform.localPosition = val;
holder.transform.localScale = new Vector3(num2, num3, Mathf.Max(num2, num3));
labelIndex = (rectIndex = 0);
return true;
}
private void Status(string message)
{
if (!(lastStatus == message))
{
lastStatus = message;
Plugin.Log.LogInfo((object)message);
}
}
private Camera FindCamera(UILabel sample)
{
UICamera val = UICamera.FindCameraForLayer(((Component)sample).gameObject.layer);
if ((Object)(object)val != (Object)null && ValidCamera(val.cachedCamera, sample))
{
return val.cachedCamera;
}
Camera val2 = null;
Camera[] allCameras = Camera.allCameras;
foreach (Camera val3 in allCameras)
{
if (ValidCamera(val3, sample) && ((Object)(object)val2 == (Object)null || val3.depth > val2.depth))
{
val2 = val3;
}
}
return val2;
}
private static bool ValidCamera(Camera c, UILabel sample)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)c == (Object)null || !((Behaviour)c).isActiveAndEnabled || !c.orthographic || (c.cullingMask & (1 << ((Component)sample).gameObject.layer)) == 0)
{
return false;
}
float z = c.WorldToScreenPoint(((Component)sample).transform.position).z;
if (z > c.nearClipPlane)
{
return z < c.farClipPlane;
}
return false;
}
private bool Build()
{
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Expected O, but got Unknown
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Invalid comparison between Unknown and I4
//IL_033b: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < 2; i++)
{
foreach (UIRoot item in UIRoot.list)
{
if ((Object)(object)item == (Object)null || !((Component)item).gameObject.activeInHierarchy)
{
continue;
}
HUDController componentInChildren = ((Component)item).GetComponentInChildren<HUDController>(true);
HUDQuickAccess componentInChildren2 = ((Component)item).GetComponentInChildren<HUDQuickAccess>(true);
HUDFPS componentInChildren3 = ((Component)item).GetComponentInChildren<HUDFPS>(true);
if (i == 0 && (Object)(object)componentInChildren == (Object)null && (Object)(object)componentInChildren2 == (Object)null && (Object)(object)componentInChildren3 == (Object)null)
{
continue;
}
UILabel val = null;
Camera val2 = null;
UILabel[] componentsInChildren = ((Component)item).GetComponentsInChildren<UILabel>(false);
foreach (UILabel val3 in componentsInChildren)
{
if (!((Object)(object)val3 == (Object)null) && ((Behaviour)val3).isActiveAndEnabled && !((Object)(object)val3.font == (Object)null) && !((Object)(object)val3.font.material == (Object)null) && !(((UIWidget)val3).alpha <= 0f))
{
Camera val4 = FindCamera(val3);
if (!((Object)(object)val4 == (Object)null))
{
val = val3;
val2 = val4;
break;
}
}
}
if ((Object)(object)val == (Object)null)
{
continue;
}
uiRoot = item;
camera = val2;
font = val.font;
renderDepth = val2.WorldToScreenPoint(((Component)val).transform.position).z;
Shader val5 = Shader.Find("Unlit/Transparent Colored");
if ((Object)(object)val5 == (Object)null || !val5.isSupported)
{
val5 = font.material.shader;
}
if ((Object)(object)val5 == (Object)null || !val5.isSupported)
{
Status("Native HUD waiting: no supported NGUI shader.");
continue;
}
solid = new Material(val5)
{
hideFlags = (HideFlags)52,
mainTexture = (Texture)(object)Texture2D.whiteTexture
};
holder = NGUITools.AddChild(((Component)item).gameObject);
((Object)holder).name = "CombatStatistics.NativeHUD";
holder.layer = ((Component)val).gameObject.layer;
holder.AddComponent<UIPanel>();
UISprite val6 = null;
int num = -1;
UISprite[] componentsInChildren2 = ((Component)item).GetComponentsInChildren<UISprite>(true);
foreach (UISprite val7 in componentsInChildren2)
{
if (!((Object)(object)val7 == (Object)null) && !((Object)(object)val7.atlas == (Object)null) && (int)val7.type == 1 && !string.IsNullOrEmpty(val7.spriteName))
{
string text = (val7.spriteName + " " + ((Object)((Component)val7).gameObject).name).ToLowerInvariant();
int num2 = ((text.Contains("background") || text.Contains("window") || text.Contains("panel")) ? 3 : ((text.Contains("frame") || text.Contains("box")) ? 2 : 0));
if (num2 > num)
{
val6 = val7;
num = num2;
}
}
}
if ((Object)(object)val6 != (Object)null && num > 0)
{
background = NGUITools.AddWidget<UISprite>(holder);
background.atlas = val6.atlas;
background.spriteName = val6.spriteName;
background.type = val6.type;
((UIWidget)background).pivot = (Pivot)0;
((UIWidget)background).depth = 0;
}
Status("Native HUD attached: root=" + ((Object)item).name + "; camera=" + ((Object)camera).name + "; font=" + ((Object)font).name + "; background=" + (((Object)(object)background != (Object)null) ? background.spriteName : "solid fallback"));
return true;
}
}
Status("Native HUD waiting: no active NGUI label/font with a matching orthographic camera.");
return false;
}
internal void Text(Rect r, string text, GUIStyle style)
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Invalid comparison between Unknown and I4
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
UILabel val;
if (labelIndex == labels.Count)
{
val = NGUITools.AddWidget<UILabel>(holder);
val.font = font;
val.translate = false;
val.supportEncoding = false;
val.multiLine = false;
val.effectStyle = (Effect)2;
val.effectColor = new Color(0f, 0f, 0f, 0.9f);
val.effectDistance = Vector2.one;
((UIWidget)val).depth = 100;
labels.Add(val);
}
else
{
val = labels[labelIndex];
}
labelIndex++;
if (!((Component)val).gameObject.activeSelf)
{
((Component)val).gameObject.SetActive(true);
}
bool flag = (int)style.alignment == 5;
((UIWidget)val).pivot = (Pivot)(flag ? 5 : 3);
((Component)val).transform.localPosition = new Vector3(flag ? ((Rect)(ref r)).xMax : ((Rect)(ref r)).x, 0f - ((Rect)(ref r)).center.y, 0f);
((Component)val).transform.localScale = new Vector3((float)style.fontSize, (float)style.fontSize, 1f);
val.lineWidth = Mathf.Max(1, Mathf.RoundToInt(((Rect)(ref r)).width));
((UIWidget)val).color = style.normal.textColor;
val.text = text;
}
internal void Fill(Rect r, Color color)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
if (rectIndex == 0 && (Object)(object)background != (Object)null)
{
((Component)background).transform.localPosition = new Vector3(((Rect)(ref r)).x, 0f - ((Rect)(ref r)).y, 0f);
((Component)background).transform.localScale = new Vector3(((Rect)(ref r)).width, ((Rect)(ref r)).height, 1f);
((UIWidget)background).color = Color.white;
rectIndex++;
return;
}
int num = rectIndex++ - (((Object)(object)background != (Object)null) ? 1 : 0);
UITexture val;
if (num == rects.Count)
{
val = NGUITools.AddWidget<UITexture>(holder);
((UIWidget)val).material = solid;
((UIWidget)val).pivot = (Pivot)0;
rects.Add(val);
}
else
{
val = rects[num];
}
if (!((Component)val).gameObject.activeSelf)
{
((Component)val).gameObject.SetActive(true);
}
((UIWidget)val).depth = 1 + num;
((Component)val).transform.localPosition = new Vector3(((Rect)(ref r)).x, 0f - ((Rect)(ref r)).y, 0f);
((Component)val).transform.localScale = new Vector3(((Rect)(ref r)).width, ((Rect)(ref r)).height, 1f);
((UIWidget)val).color = color;
}
internal void End()
{
for (int i = labelIndex; i < labels.Count; i++)
{
((Component)labels[i]).gameObject.SetActive(false);
}
int num = rectIndex - (((Object)(object)background != (Object)null) ? 1 : 0);
for (int j = Mathf.Max(0, num); j < rects.Count; j++)
{
((Component)rects[j]).gameObject.SetActive(false);
}
}
internal void Reset()
{
Dispose();
failed = false;
nextTry = 0f;
lastStatus = null;
}
internal void Hide()
{
if ((Object)(object)holder != (Object)null && holder.activeSelf)
{
holder.SetActive(false);
}
}
internal void Fail(Exception ex)
{
failed = true;
Dispose();
Plugin.Log.LogWarning((object)("Native HUD fallback: " + ex));
}
internal void Dispose()
{
if ((Object)(object)holder != (Object)null)
{
holder.SetActive(false);
Object.Destroy((Object)(object)holder);
}
if ((Object)(object)solid != (Object)null)
{
Object.Destroy((Object)(object)solid);
}
holder = null;
uiRoot = null;
camera = null;
font = null;
renderDepth = 0f;
background = null;
solid = null;
labels.Clear();
rects.Clear();
}
}
[BepInPlugin("blockstory.combatstatistics", "Combat Statistics", "1.0.0")]
public sealed class Plugin : BaseUnityPlugin
{
public const string Guid = "blockstory.combatstatistics";
internal static ManualLogSource Log;
private Harmony harmony;
private CombatHud hud;
private bool patched;
private bool focused = true;
private bool observedMultiplayer;
private ushort observedLocalId;
private SceneHandle observedScene;
private static Plugin instance;
private static int mainThread;
private static float nextWarning;
private ConfigEntry<KeyCode> toggleKey;
private ConfigEntry<KeyCode> resetKey;
private ConfigEntry<KeyCode> editKey;
private UICustomCursor editCursor;
private bool savedLocked;
private bool savedVisible;
private bool savedOsVisible;
private CursorLockMode savedLockMode;
private ConfigEntry<bool> nativeHud;
private bool hudVisible;
private PlayerHealth observedPlayer;
private bool wasPlayerPresent;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<bool> LogHits;
internal static ConfigEntry<bool> TrackPets;
internal static ConfigEntry<bool> UseNativeBindings;
internal static long SessionEpoch { get; private set; }
internal static bool Operational
{
get
{
if ((Object)(object)instance != (Object)null && instance.patched)
{
return ((Behaviour)instance).isActiveAndEnabled;
}
return false;
}
}
internal static bool BlockUiInput
{
get
{
if (Operational && Editing && instance.focused && instance.WorldActive && (Object)(object)instance.editCursor != (Object)null && (Object)(object)UICustomCursor.current == (Object)(object)instance.editCursor)
{
return !instance.editCursor.Locked;
}
return false;
}
}
internal static bool Editing { get; private set; }
private bool WorldActive
{
get
{
if ((Object)(object)PlayerHealth.Instance != (Object)null && ((Component)PlayerHealth.Instance).gameObject.activeInHierarchy)
{
return !((HealthBase)PlayerHealth.Instance).IsDead();
}
return false;
}
}
private bool HudAllowed
{
get
{
if (WorldActive)
{
if (!Editing && !((Object)(object)UICustomCursor.current == (Object)null))
{
return UICustomCursor.current.Locked;
}
return true;
}
return false;
}
}
internal static void Warn(string context, Exception ex)
{
try
{
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (!(realtimeSinceStartup < nextWarning))
{
nextWarning = realtimeSinceStartup + 5f;
ManualLogSource log = Log;
if (log != null)
{
log.LogWarning((object)(context + ": " + ex.GetType().Name + ": " + CombatLog.SafeName(ex.Message, 200)));
}
}
}
catch
{
}
}
internal static bool PrepareCapture()
{
if (Thread.CurrentThread.ManagedThreadId != mainThread || !Operational)
{
return false;
}
instance.SyncWorld();
return instance.WorldActive;
}
internal static bool SameSession(long epoch)
{
if (Thread.CurrentThread.ManagedThreadId != mainThread || !Operational)
{
return false;
}
instance.SyncWorld();
return epoch == SessionEpoch;
}
private void Awake()
{
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
instance = this;
mainThread = Thread.CurrentThread.ManagedThreadId;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable combat tracking.");
LogHits = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DetailedHitLogging", false, "Opt-in diagnostic hit logs (rate limited). Older LogHits setting is no longer used.");
TrackPets = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "TrackPets", true, "Track pets; multiplayer requires a confirmed local owner.");
UseNativeBindings = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "UseNativeBindings", true, "Add mod actions to the vanilla Controls menu after game initialization. Restart required.");
nativeHud = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "UseNativeHud", true, "Use vanilla NGUI font and HUD rendering; false = classic IMGUI fallback.");
toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("HUD", "ToggleKey", (KeyCode)287, "Toggle HUD visibility.");
resetKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("HUD", "ResetKey", (KeyCode)289, "Reset accumulated combat statistics.");
editKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("HUD", "EditKey", (KeyCode)288, "Unlock cursor and move HUD; press again to save and exit.");
hud = new CombatHud(((BaseUnityPlugin)this).Config.Bind<float>("HUD", "X", -1f, "HUD left position in pixels. Negative = align right."), ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "Y", 28f, "HUD top position in pixels."));
harmony = new Harmony("blockstory.combatstatistics");
try
{
harmony.PatchAll(typeof(Plugin).Assembly);
patched = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)("Native HUD configured: " + nativeHud.Value));
((BaseUnityPlugin)this).Logger.LogInfo((object)("Native Controls integration: " + (UseNativeBindings.Value ? "enabled, deferred until game input is ready" : "disabled; using config keys")));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Combat Statistics 1.0.0 loaded; Health.Attacked and PlayerHealth.Attacked patched.");
}
catch (Exception ex)
{
patched = false;
try
{
harmony.UnpatchSelf();
}
catch (Exception ex2)
{
Warn("Unpatch failed initialization", ex2);
}
try
{
NativeBindings.Shutdown();
}
catch (Exception ex3)
{
Warn("Bindings failed initialization", ex3);
}
((BaseUnityPlugin)this).Logger.LogError((object)ex);
}
}
private void SyncWorld()
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
PlayerHealth val = PlayerHealth.Instance;
bool flag = (Object)(object)val != (Object)null && ((Component)val).gameObject.activeInHierarchy;
bool isMultiplayer = MultiplayerSessionSettings.IsMultiplayer;
ushort localPlayerId = MultiplayerSessionSettings.LocalPlayerId;
Scene activeScene = SceneManager.GetActiveScene();
SceneHandle handle = ((Scene)(ref activeScene)).handle;
if (flag != wasPlayerPresent || (flag && val != observedPlayer) || isMultiplayer != observedMultiplayer || localPlayerId != observedLocalId || handle != observedScene)
{
EndEdit();
hudVisible = false;
CombatLog.Reset();
observedPlayer = (flag ? val : null);
wasPlayerPresent = flag;
observedMultiplayer = isMultiplayer;
observedLocalId = localPlayerId;
observedScene = handle;
SessionEpoch++;
hud.ResetRenderer();
}
}
private void Update()
{
if (!patched)
{
return;
}
try
{
UpdateCore();
}
catch (Exception ex)
{
EndEdit();
Warn("HUD update", ex);
}
}
private void UpdateCore()
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
SyncWorld();
CombatLog.Prune(Time.realtimeSinceStartup);
if (UseNativeBindings.Value && WorldActive && (Object)(object)UICustomCursor.current != (Object)null)
{
NativeBindings.TryInitWhenReady();
}
int num;
if (focused)
{
if (Editing)
{
num = 1;
goto IL_007b;
}
if (WorldActive && (Object)(object)UICustomCursor.current != (Object)null && UICustomCursor.current.Locked)
{
num = ((!UICamera.inputHasFocus) ? 1 : 0);
if (num != 0)
{
goto IL_007b;
}
}
else
{
num = 0;
}
}
else
{
num = 0;
}
goto IL_00ba;
IL_007b:
if (NativeBindings.Pressed(NativeBindings.Toggle, toggleKey.Value))
{
hudVisible = !hudVisible;
if (!hudVisible)
{
EndEdit();
hud.ResetRenderer();
}
}
goto IL_00ba;
IL_00ba:
if (num != 0 && NativeBindings.Pressed(NativeBindings.Reset, resetKey.Value))
{
CombatLog.Reset();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Combat statistics reset.");
}
if (Editing && (!focused || !WorldActive || !Enabled.Value || !hudVisible || (Object)(object)editCursor == (Object)null || (Object)(object)UICustomCursor.current != (Object)(object)editCursor || editCursor.Locked))
{
EndEdit();
}
if (num != 0 && NativeBindings.Pressed(NativeBindings.Move, editKey.Value))
{
if (Editing)
{
EndEdit();
}
else if (focused && WorldActive && Enabled.Value)
{
BeginEdit();
}
}
if (Editing && (Input.GetKeyDown((KeyCode)27) || !focused))
{
EndEdit();
}
if (Editing)
{
hud.UpdateDrag();
}
if (!hudVisible || !Enabled.Value || !HudAllowed || !nativeHud.Value)
{
hud.HideNative();
}
}
private void BeginEdit()
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
UICustomCursor current = UICustomCursor.current;
if ((Object)(object)current == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Game cursor not available.");
return;
}
editCursor = current;
savedLocked = current.Locked;
savedVisible = current.Visible;
savedOsVisible = Cursor.visible;
savedLockMode = Cursor.lockState;
hudVisible = true;
Editing = true;
try
{
hud.BeginEdit();
current.Locked = false;
current.Visible = true;
Cursor.visible = true;
}
catch (Exception ex)
{
EndEdit();
Warn("Begin HUD edit", ex);
}
}
private void LateUpdate()
{
if (!Editing)
{
return;
}
try
{
if (!BlockUiInput)
{
EndEdit();
}
else
{
Cursor.visible = true;
}
}
catch (Exception ex)
{
EndEdit();
Warn("HUD cursor", ex);
}
}
private void EndEdit()
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
if (!Editing)
{
return;
}
Editing = false;
UICustomCursor val = editCursor;
editCursor = null;
try
{
hud?.EndEdit();
}
catch (Exception ex)
{
Warn("Save HUD position", ex);
}
finally
{
try
{
if ((Object)(object)val != (Object)null && (Object)(object)UICustomCursor.current == (Object)(object)val && !val.Locked)
{
try
{
val.Locked = savedLocked;
}
finally
{
try
{
val.Visible = savedVisible;
}
finally
{
try
{
Cursor.lockState = savedLockMode;
}
finally
{
Cursor.visible = savedOsVisible;
}
}
}
}
}
catch (Exception ex2)
{
Warn("Restore game cursor", ex2);
}
try
{
((BaseUnityPlugin)this).Config.Save();
}
catch (Exception ex3)
{
Warn("Save settings", ex3);
}
}
}
private void OnApplicationFocus(bool hasFocus)
{
focused = hasFocus;
if (!focused)
{
EndEdit();
}
}
private void OnGUI()
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
if (!patched)
{
return;
}
try
{
if (!hudVisible || !Enabled.Value || !HudAllowed)
{
hud?.HideNative();
}
else
{
hud.Draw(NativeBindings.Display(NativeBindings.Toggle, toggleKey.Value), NativeBindings.Display(NativeBindings.Reset, resetKey.Value), NativeBindings.Display(NativeBindings.Move, editKey.Value), Editing, nativeHud.Value);
}
}
catch (Exception ex)
{
EndEdit();
hudVisible = false;
try
{
hud?.ResetRenderer();
}
catch (Exception ex2)
{
Warn("HUD cleanup", ex2);
}
Warn("HUD drawing", ex);
}
}
private void OnDisable()
{
EndEdit();
hudVisible = false;
try
{
hud?.ResetRenderer();
}
catch (Exception ex)
{
Warn("HUD disable", ex);
}
}
private void OnDestroy()
{
patched = false;
try
{
EndEdit();
}
finally
{
try
{
hud?.Dispose();
}
catch (Exception ex)
{
Warn("HUD disposal", ex);
}
try
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
catch (Exception ex2)
{
Warn("Unpatch", ex2);
}
try
{
NativeBindings.Shutdown();
}
catch (Exception ex3)
{
Warn("Bindings disposal", ex3);
}
CombatLog.Reset();
if (instance == this)
{
instance = null;
}
}
}
}
[HarmonyPatch(typeof(UICamera), "Update")]
internal static class HudUiInputPatch
{
[HarmonyPrefix]
private static bool Prefix()
{
try
{
return !Plugin.BlockUiInput;
}
catch
{
return true;
}
}
}
[HarmonyPatch(typeof(MouseLook), "LateUpdate")]
internal static class HudLookPatch
{
[HarmonyPrefix]
private static bool Prefix()
{
try
{
return !Plugin.BlockUiInput;
}
catch
{
return true;
}
}
}
internal struct HitState
{
public bool Active;
public long Session;
public float Before;
public string Source;
public string Target;
public string Category;
public EntityId SourceId;
public string DisplayName;
}
internal static class CombatLog
{
private struct Sample
{
public float Time;
public float Damage;
}
internal sealed class SourceStat
{
public string Name;
public string Category;
public double Damage;
public long Hits;
public float LastSeen;
}
private static readonly Queue<Sample> Recent = new Queue<Sample>();
private static double playerTotal;
private static double petTotal;
private static double incomingTotal;
private static long outgoingHits;
private static long incomingHits;
private static double recentDamage;
private const int MaxSamples = 8192;
private const int MaxSources = 128;
private const float SourceLifetime = 900f;
private static float nextSourcePrune;
private static int logSecond = -1;
private static int logCount;
private const double MaxTotal = 1E+100;
private const float Window = 5f;
private static float streakStarted;
private const int HistoryLength = 30;
private static readonly double[] History = new double[30];
private static readonly int[] HistorySeconds = new int[30];
private static readonly Dictionary<EntityId, SourceStat> Sources = new Dictionary<EntityId, SourceStat>();
private static readonly List<SourceStat> SortedSources = new List<SourceStat>();
private static bool sourcesDirty;
private static double peakDps;
internal static double PlayerTotal => playerTotal;
internal static double PetTotal => petTotal;
internal static double IncomingTotal => incomingTotal;
internal static long OutgoingHits => outgoingHits;
internal static long IncomingHits => incomingHits;
internal static double Dps
{
get
{
if (Recent.Count == 0)
{
return 0.0;
}
float num = Mathf.Clamp(Time.realtimeSinceStartup - streakStarted, 1f, 5f);
return Math.Max(0.0, recentDamage) / (double)num;
}
}
internal static double PeakDps => peakDps;
internal static IReadOnlyList<SourceStat> GetSources()
{
if (sourcesDirty)
{
SortedSources.Clear();
SortedSources.AddRange(Sources.Values);
SortedSources.Sort((SourceStat a, SourceStat b) => b.Damage.CompareTo(a.Damage));
sourcesDirty = false;
}
return SortedSources;
}
internal static double GetHistory(int secondsAgo, float now)
{
int num = Mathf.FloorToInt(now) - secondsAgo;
if (num < 0 || secondsAgo < 0 || secondsAgo >= 30)
{
return 0.0;
}
int num2 = num % 30;
if (HistorySeconds[num2] != num)
{
return 0.0;
}
return History[num2];
}
private static void AddHistory(float now, float damage)
{
int num = Mathf.FloorToInt(now);
int num2 = num % 30;
if (HistorySeconds[num2] != num)
{
HistorySeconds[num2] = num;
History[num2] = 0.0;
}
History[num2] = Add(History[num2], damage);
}
internal static void Prune(float now)
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
while (Recent.Count > 0 && now - Recent.Peek().Time >= 5f)
{
recentDamage -= Recent.Dequeue().Damage;
}
if (Recent.Count == 0)
{
recentDamage = 0.0;
}
if (!(now >= nextSourcePrune))
{
return;
}
nextSourcePrune = now + 5f;
List<EntityId> list = new List<EntityId>();
foreach (KeyValuePair<EntityId, SourceStat> source in Sources)
{
EntityId key = source.Key;
if (!((EntityId)(ref key)).Equals(EntityId.None) && now - source.Value.LastSeen >= 900f)
{
list.Add(source.Key);
}
}
foreach (EntityId item in list)
{
Sources.Remove(item);
sourcesDirty = true;
}
}
private static double Add(double total, double damage)
{
return Math.Min(1E+100, total + damage);
}
private static long Increment(long count)
{
if (count != long.MaxValue)
{
return count + 1;
}
return count;
}
internal static string SafeName(string text, int limit = 80)
{
if (string.IsNullOrEmpty(text))
{
return "Unknown";
}
StringBuilder stringBuilder = new StringBuilder(Math.Min(text.Length, limit));
for (int i = 0; i < Math.Min(text.Length, limit * 8); i++)
{
if (stringBuilder.Length >= limit)
{
break;
}
char c = text[i];
UnicodeCategory unicodeCategory = char.GetUnicodeCategory(c);
if (char.IsControl(c) || unicodeCategory == UnicodeCategory.Format || unicodeCategory == UnicodeCategory.LineSeparator || unicodeCategory == UnicodeCategory.ParagraphSeparator)
{
continue;
}
if (char.IsHighSurrogate(c))
{
if (i + 1 < text.Length && char.IsLowSurrogate(text[i + 1]) && stringBuilder.Length + 2 <= limit)
{
stringBuilder.Append(c);
stringBuilder.Append(text[++i]);
}
}
else if (!char.IsLowSurrogate(c))
{
stringBuilder.Append(c);
}
}
string text2 = stringBuilder.ToString().Trim();
if (text2.Length != 0)
{
return text2;
}
return "Unknown";
}
private static bool CanLogHit(float now)
{
if (!Plugin.LogHits.Value)
{
return false;
}
int num = Mathf.FloorToInt(now);
if (num != logSecond)
{
logSecond = num;
logCount = 0;
}
if (logCount >= 20)
{
return false;
}
logCount++;
return true;
}
private static bool OwnPet(HealthBase from)
{
if (!((Component)from).CompareTag("Pet"))
{
return false;
}
NetworkPet componentInParent = ((Component)from).GetComponentInParent<NetworkPet>();
if (!MultiplayerSessionSettings.IsMultiplayer)
{
if (!((Object)(object)componentInParent == (Object)null))
{
return componentInParent.NetworkId == 0;
}
return true;
}
if ((Object)(object)componentInParent != (Object)null && componentInParent.NetworkId != 0)
{
return componentInParent.IsLocalOwner;
}
return false;
}
internal static void Reset()
{
Recent.Clear();
recentDamage = 0.0;
streakStarted = 0f;
peakDps = 0.0;
playerTotal = (petTotal = (incomingTotal = 0.0));
outgoingHits = (incomingHits = 0L);
Array.Clear(History, 0, History.Length);
Array.Clear(HistorySeconds, 0, HistorySeconds.Length);
Sources.Clear();
SortedSources.Clear();
sourcesDirty = false;
nextSourcePrune = 0f;
}
internal static HitState Capture(HealthBase target, HealthBase from, bool incoming)
{
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.PrepareCapture() || Plugin.Enabled == null || !Plugin.Enabled.Value || (Object)(object)target == (Object)null || target.IsDead())
{
return default(HitState);
}
string text;
if (incoming && (Object)(object)target == (Object)(object)PlayerHealth.Instance)
{
text = "INCOMING";
}
else
{
if (incoming)
{
return default(HitState);
}
if ((Object)(object)from != (Object)null && (Object)(object)from != (Object)(object)target && (Object)(object)from == (Object)(object)PlayerHealth.Instance)
{
text = "PLAYER";
}
else
{
if (!((Object)(object)from != (Object)null) || !((Object)(object)from != (Object)(object)target) || !Plugin.TrackPets.Value || !OwnPet(from))
{
return default(HitState);
}
text = "PET";
}
}
string text2 = (((Object)(object)from != (Object)null) ? ((Object)((Component)from).gameObject).name.Replace("(Clone)", "").Trim() : "Environment");
if (text == "PLAYER")
{
text2 = "Player";
}
else if (text == "PET")
{
Health val = (Health)(object)((from is Health) ? from : null);
if (val != null)
{
string displayName = val.GetDisplayName();
if (!string.IsNullOrWhiteSpace(displayName))
{
text2 = displayName;
}
}
}
return new HitState
{
Active = true,
Session = Plugin.SessionEpoch,
Before = target.GetHealth(),
Source = (((Object)(object)from != (Object)null) ? SafeName(((Object)((Component)from).gameObject).name) : "unknown/environment"),
Target = SafeName(((Object)((Component)target).gameObject).name),
Category = text,
SourceId = ((text == "PLAYER" || (Object)(object)from == (Object)null) ? EntityId.None : ((Object)((Component)from).gameObject).GetEntityId()),
DisplayName = SafeName(text2)
};
}
internal static void Record(HealthBase target, HitState state, Identifier type, bool timed)
{
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_0377: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
if (!state.Active || (Object)(object)target == (Object)null || !Plugin.SameSession(state.Session) || !Plugin.Enabled.Value)
{
return;
}
float health = target.GetHealth();
float num = Mathf.Max(0f, state.Before) - Mathf.Max(0f, health);
if (num <= 0f || float.IsNaN(num) || float.IsInfinity(num))
{
return;
}
if (state.Category == "INCOMING")
{
incomingTotal = Add(incomingTotal, num);
incomingHits = Increment(incomingHits);
if (CanLogHit(Time.realtimeSinceStartup))
{
Plugin.Log.LogInfo((object)$"[INCOMING] {state.Source} -> {state.Target} | damage={num:F2} | type={type} | timed={timed} | received={incomingTotal:F2} | hits={incomingHits}");
}
return;
}
if (state.Category == "PLAYER")
{
playerTotal = Add(playerTotal, num);
}
else
{
petTotal = Add(petTotal, num);
}
outgoingHits = Increment(outgoingHits);
float realtimeSinceStartup = Time.realtimeSinceStartup;
Prune(realtimeSinceStartup);
if (Recent.Count == 0)
{
streakStarted = realtimeSinceStartup;
}
if (Recent.Count >= 8192)
{
recentDamage -= Recent.Dequeue().Damage;
}
Recent.Enqueue(new Sample
{
Time = realtimeSinceStartup,
Damage = num
});
recentDamage += num;
AddHistory(realtimeSinceStartup, num);
if (!Sources.TryGetValue(state.SourceId, out var value))
{
if (Sources.Count >= 128)
{
EntityId key = EntityId.None;
float num2 = float.PositiveInfinity;
foreach (KeyValuePair<EntityId, SourceStat> source in Sources)
{
EntityId key2 = source.Key;
if (!((EntityId)(ref key2)).Equals(EntityId.None) && source.Value.LastSeen < num2)
{
key = source.Key;
num2 = source.Value.LastSeen;
}
}
if (!((EntityId)(ref key)).Equals(EntityId.None))
{
Sources.Remove(key);
}
}
value = new SourceStat
{
Name = state.DisplayName,
Category = state.Category
};
Sources.Add(state.SourceId, value);
}
value.Name = state.DisplayName;
value.Damage = Add(value.Damage, num);
value.Hits = Increment(value.Hits);
value.LastSeen = realtimeSinceStartup;
sourcesDirty = true;
peakDps = Math.Max(peakDps, Dps);
if (CanLogHit(realtimeSinceStartup))
{
Plugin.Log.LogInfo((object)$"[{state.Category}] {state.Source} -> {state.Target} | damage={num:F2} | HP={state.Before:F2}->{Mathf.Max(0f, health):F2} | type={type} | timed={timed} | DPS5={Dps:F2} | player={playerTotal:F2} | pets={petTotal:F2} | hits={outgoingHits}");
}
}
}
[HarmonyPatch(typeof(Health), "Attacked", new Type[]
{
typeof(float),
typeof(HealthBase),
typeof(InvBaseItem),
typeof(Identifier),
typeof(bool)
})]
internal static class MobDamagePatch
{
[HarmonyPrefix]
private static void Prefix(Health __instance, HealthBase __1, out HitState __state)
{
__state = default(HitState);
try
{
__state = CombatLog.Capture((HealthBase)(object)__instance, __1, incoming: false);
}
catch (Exception ex)
{
Plugin.Warn("Combat tracking", ex);
}
}
[HarmonyPostfix]
private static void Postfix(Health __instance, Identifier __3, bool __4, HitState __state)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
try
{
CombatLog.Record((HealthBase)(object)__instance, __state, __3, __4);
}
catch (Exception ex)
{
Plugin.Warn("Combat tracking", ex);
}
}
}
[HarmonyPatch(typeof(PlayerHealth), "Attacked", new Type[]
{
typeof(float),
typeof(HealthBase),
typeof(InvBaseItem),
typeof(Identifier),
typeof(bool)
})]
internal static class PlayerDamagePatch
{
[HarmonyPrefix]
private static void Prefix(PlayerHealth __instance, HealthBase __1, out HitState __state)
{
__state = default(HitState);
try
{
__state = CombatLog.Capture((HealthBase)(object)__instance, __1, incoming: true);
}
catch (Exception ex)
{
Plugin.Warn("Combat tracking", ex);
}
}
[HarmonyPostfix]
private static void Postfix(PlayerHealth __instance, Identifier __3, bool __4, HitState __state)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
try
{
CombatLog.Record((HealthBase)(object)__instance, __state, __3, __4);
}
catch (Exception ex)
{
Plugin.Warn("Combat tracking", ex);
}
}
}
}