using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Landfall.TABS;
using TooManyDamage;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TooManyDamage")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("GeeztJeez")]
[assembly: AssemblyProduct("TooManyDamage")]
[assembly: AssemblyCopyright("Copyright © Geezt Lifetime")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7acfaef0-7669-4401-8bff-5a9a02e18c75")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TooManyDamage
{
[BepInPlugin("GeeztJeez.TooManyDamage", "TooManyDamage", "1.0.0")]
internal class Loader : BaseUnityPlugin
{
public static bool enableDebug;
public static string modName = "TooManyDamage";
public static ConfigEntry<float> DamageWindow;
public static ConfigEntry<bool> DamageCalibrateEnable;
public static ConfigEntry<float> DamageCalibrateStartAt;
public static ConfigEntry<float> DamageCalibratePercentage;
public static ConfigEntry<float> MinTotalDamage;
public static ConfigEntry<float> MaxTotalDamage;
public static ConfigEntry<bool> IgnoreOutsideCap;
private void ApplyHarmony()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
try
{
new Harmony(modName).PatchAll(Assembly.GetExecutingAssembly());
Log("Harmony patched successfully!");
}
catch (Exception ex)
{
LogError("Harmony patch failed: " + ex);
LogWarning("Please contact Geezt Jeez or try reloading the game...");
}
}
private void Awake()
{
try
{
RegisterConfig();
ApplyHarmony();
}
catch (Exception ex)
{
LogError("Fatal error, mod loading failed: " + ex);
LogWarning("Please contact Geezt Jeez or try reloading the game...");
}
}
public static void Log(string message)
{
if (enableDebug)
{
Debug.Log((object)$"[{modName}] [Log] : {message}");
}
}
public static void LogWarning(string message)
{
if (enableDebug)
{
Debug.LogWarning((object)$"[{modName}] [Warn] : {message}");
}
}
public static void LogError(string message)
{
if (enableDebug)
{
Debug.LogError((object)$"[{modName}] [Error] : {message}");
}
}
private void RegisterConfig()
{
DamageWindow = ((BaseUnityPlugin)this).Config.Bind<float>("Damage Settings", "DamageWindow", 0.01f, "Damage interval. 0 disables it.");
DamageCalibrateEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Damage Calibration", "DamageCalibrateEnable", true, "Enable damage calibration.");
DamageCalibrateStartAt = ((BaseUnityPlugin)this).Config.Bind<float>("Damage Calibration", "DamageCalibrateStartAt", 300f, "Damage calibration threshold.");
DamageCalibratePercentage = ((BaseUnityPlugin)this).Config.Bind<float>("Damage Calibration", "DamageCalibratePercentage", 0.6f, "Retained damage percentage.");
MinTotalDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Damage Limits", "MinTotalDamage", 0f, "Minimum damage limit.");
MaxTotalDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Damage Limits", "MaxTotalDamage", 6000f, "Maximum damage limit.");
IgnoreOutsideCap = ((BaseUnityPlugin)this).Config.Bind<bool>("Damage Limits", "IgnoreOutsideCap", false, "Ignore damage outside limits instead of clamping.");
}
}
}
namespace TooManyDamageHarmonyPatch
{
[HarmonyPatch(typeof(HealthHandler), "TakeDamage")]
public class TakeDamagePatch
{
public static bool enablePatch;
private static void Prefix(HealthHandler __instance, ref float damage, Unit damager, DamageType damageType)
{
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
if (float.IsNaN(damage) || float.IsInfinity(damage) || damage <= 0f || !enablePatch)
{
return;
}
FieldInfo field = typeof(HealthHandler).GetField("data", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
object? obj = ((field != null) ? field.GetValue(__instance) : null);
DataHandler val = (DataHandler)((obj is DataHandler) ? obj : null);
FieldInfo field2 = typeof(HealthHandler).GetField("isInvulnerable", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
bool flag = (((field2 != null) ? field2.GetValue(__instance) : null) as bool?) ?? false;
if (!((Object)(object)val == (Object)null || val.Dead || flag) && val.lifeTime >= 0.3f && val.immunityForSeconds <= 0f && val.health > 0f)
{
CustomPatch(val, ref damage, damager, damageType);
if (damage > 0f && Loader.DamageWindow.Value > 0f)
{
((MonoBehaviour)__instance).StartCoroutine(ApplyImmunity(val));
}
}
}
public static void CustomPatch(DataHandler dataHandler, ref float damage, Unit damager, DamageType damageType)
{
bool value = Loader.DamageCalibrateEnable.Value;
float value2 = Loader.DamageCalibrateStartAt.Value;
float value3 = Loader.DamageCalibratePercentage.Value;
float value4 = Loader.MinTotalDamage.Value;
float value5 = Loader.MaxTotalDamage.Value;
bool value6 = Loader.IgnoreOutsideCap.Value;
if (value && damage > value2)
{
damage *= Mathf.Clamp01(value3);
}
if (value6)
{
if (damage < value4 || damage > value5)
{
damage = 0f;
}
}
else
{
damage = Mathf.Clamp(damage, value4, value5);
}
}
static TakeDamagePatch()
{
enablePatch = true;
}
private static IEnumerator ApplyImmunity(DataHandler dataHandler)
{
yield return null;
if ((Object)(object)dataHandler != (Object)null && !dataHandler.Dead && dataHandler.health > 0f)
{
dataHandler.immunityForSeconds = Loader.DamageWindow.Value;
}
}
}
}