using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("DamageStyleHUD")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DamageStyleHUD")]
[assembly: AssemblyTitle("DamageStyleHUD")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 DamageStyleHUD
{
[BepInPlugin("DamageStyleHUD.adry.ultrakill", "Damage Style HUD", "1.1.3")]
public class DamageStyleHUD : BaseUnityPlugin
{
[HarmonyPatch(typeof(EnemyIdentifier), "DeliverDamage")]
public static class EnemyIdentifier_DeliverDamage_Patch
{
private static float oldHealth;
private static bool wasAlive;
[HarmonyPrefix]
public static void Prefix(EnemyIdentifier __instance)
{
if ((Object)(object)__instance != (Object)null)
{
oldHealth = __instance.health;
wasAlive = !__instance.dead;
}
}
[HarmonyPostfix]
public static void Postfix(EnemyIdentifier __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
float health = __instance.health;
float num = oldHealth - health;
if (num <= 0f)
{
return;
}
if (__instance.puppet)
{
ManualLogSource log = DamageStyleHUD.log;
if (log != null)
{
log.LogInfo((object)"Damage ignored: enemy is a puppet.");
}
return;
}
if (!wasAlive)
{
ManualLogSource log2 = DamageStyleHUD.log;
if (log2 != null)
{
log2.LogInfo((object)"Damage ignored: enemy was already dead.");
}
return;
}
if (health < 0f)
{
num = oldHealth;
}
float time = Time.time;
if (time - lastDamageTime < damageWindow)
{
lastDamageDone += num;
}
else
{
lastDamageDone = num;
}
lastDamageTime = time;
ManualLogSource log3 = DamageStyleHUD.log;
if (log3 != null)
{
log3.LogInfo((object)$"Damage logged: {num} | Enemy: {((Object)__instance).name}");
}
}
}
[HarmonyPatch(typeof(StyleHUD), "UpdateHUD")]
public class StyleHUD_UpdateHUD_Patch
{
[HarmonyPostfix]
public static void Postfix(StyleHUD __instance)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
try
{
FieldInfo fieldInfo = AccessTools.Field(typeof(StyleHUD), "styleInfo");
TMP_Text val = (TMP_Text)fieldInfo.GetValue(__instance);
if ((Object)(object)val == (Object)null)
{
return;
}
string text = val.text;
string[] array = text.Split(new char[1] { '\n' });
List<string> list = new List<string>(array.Length);
string[] array2 = array;
foreach (string text2 in array2)
{
if (!text2.Contains("DAMAGE:"))
{
list.Add(text2);
}
}
float num = Time.time - lastDamageTime;
if (lastDamageDone > 0f && num < damageWindow)
{
Color damageColor = GetDamageColor(lastDamageDone);
string arg = ColorUtility.ToHtmlStringRGB(damageColor);
string item = $"<color=#{arg}>DAMAGE: -{lastDamageDone:F0}</color>";
list.Insert(0, item);
}
else if (num >= damageWindow && lastDamageDone != 0f)
{
lastDamageDone = 0f;
}
val.text = string.Join("\n", list);
}
catch (Exception ex)
{
ManualLogSource log = DamageStyleHUD.log;
if (log != null)
{
log.LogError((object)("Error updating HUD: " + ex.Message));
}
}
}
}
[HarmonyPatch(typeof(NewMovement), "Respawn")]
public class NewMovement_Respawn_Patch
{
[HarmonyPostfix]
public static void Postfix()
{
lastDamageDone = 0f;
lastDamageTime = 0f;
ManualLogSource log = DamageStyleHUD.log;
if (log != null)
{
log.LogInfo((object)"Damage data reset after respawn.");
}
}
}
private static ManualLogSource log;
public static float lastDamageDone = 0f;
public static float lastDamageTime = 0f;
private static float damageWindow = 10f;
private static float maxDamage = 1000f;
private void Awake()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
try
{
log = ((BaseUnityPlugin)this).Logger;
Harmony val = new Harmony("DamageStyleHUD.adry.ultrakill");
val.PatchAll();
log.LogInfo((object)"DamageStyleHUD initialized and patches applied.");
}
catch (Exception ex)
{
log.LogError((object)("Error initializing DamageStyleHUD: " + ex.Message));
}
}
private static Color GetDamageColor(float damage)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: 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)
if (damage > maxDamage)
{
return Color.red;
}
float num = Mathf.Clamp01(damage / maxDamage);
float num2 = Mathf.Lerp(2f / 3f, 0f, num);
return Color.HSVToRGB(num2, 1f, 1f);
}
}
}