Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of CombatRegen v1.0.1
CombatRegen.dll
Decompiled a day agousing System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.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 CombatRegen { internal static class Combat { private static float _lastEvent = float.NegativeInfinity; private static string _reason; private static Player _player; private static bool _wasActive; private static float _start; private static float _added; internal static void Mark(string reason) { BindTo(Player.m_localPlayer); if (!_wasActive) { _reason = reason; } _lastEvent = Time.time; } internal static bool Update(Player player) { BindTo(player); bool flag = Time.time - _lastEvent < Plugin.CombatTimeout.Value; if (flag == _wasActive) { return flag; } _wasActive = flag; string text; if (flag) { _start = Time.time; _added = 0f; text = $"In combat ({_reason}): +{Plugin.AdrenalinePerSecond.Value:0.##} adrenaline/s"; } else { text = $"Out of combat: +{_added:0.0} adrenaline in {Time.time - _start:0} s"; } Plugin.Log.LogInfo((object)text); if (Plugin.ShowCombatMessage.Value) { Plugin.Notify(text, (MessageType)1); } return flag; } internal static void Added(float amount) { _added += amount; } private static void BindTo(Player player) { if (!((Object)(object)player == (Object)(object)_player)) { _player = player; _lastEvent = float.NegativeInfinity; _wasActive = false; } } } internal sealed class ConfigurationManagerAttributes { public string Category; public string DispName; public int? Order; } [HarmonyPatch(typeof(Player), "UpdateStats", new Type[] { typeof(float) })] internal static class UpdateStatsPatch { private static void Postfix(Player __instance, float dt, ref float ___m_adrenaline, ref float ___m_adrenalineDegenTimer) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !Combat.Update(__instance) || ((Character)__instance).InIntro() || ((Character)__instance).IsTeleporting()) { return; } float maxAdrenaline = ((Character)__instance).GetMaxAdrenaline(); if (!(maxAdrenaline <= 0f)) { float num = __instance.m_adrenalineDegenDelay.Evaluate(___m_adrenaline / maxAdrenaline); ___m_adrenalineDegenTimer = Mathf.Max(new float[3] { ___m_adrenalineDegenTimer, num, 1f }); float num2 = Mathf.Min(Plugin.AdrenalinePerSecond.Value * dt, maxAdrenaline - ___m_adrenaline); if (!(num2 <= 0f)) { ___m_adrenaline += num2; Combat.Added(num2); ((Character)__instance).AddAdrenaline(0f); } } } } [HarmonyPatch(typeof(Player), "RPC_OnTargeted")] internal static class OnTargetedPatch { private static void Postfix(Player __instance, bool sensed, bool alerted) { if (sensed && alerted && (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { Combat.Mark("enemy hunting you"); } } } [HarmonyPatch(typeof(Character), "RPC_Damage")] internal static class TakeHitPatch { private static void Prefix(Character __instance, HitData hit) { //IL_0016: 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) if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && hit.HaveAttacker() && !(hit.m_attacker == __instance.GetZDOID())) { Character attacker = hit.GetAttacker(); if (!((Object)(object)attacker != (Object)null) || !attacker.IsPlayer() || (__instance.IsPVPEnabled() && attacker.IsPVPEnabled())) { Combat.Mark("hit taken"); } } } } [HarmonyPatch(typeof(Character), "Damage")] internal static class DealHitPatch { private static void Prefix(Character __instance, HitData hit) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)__instance == (Object)(object)localPlayer) && !(hit.m_attacker != ((Character)localPlayer).GetZDOID()) && !__instance.IsTamed() && (!__instance.IsPlayer() || (((Character)localPlayer).IsPVPEnabled() && __instance.IsPVPEnabled()))) { Combat.Mark("hit landed"); } } } [BepInPlugin("vh.combatregen", "CombatRegen", "1.0.1")] public class Plugin : BaseUnityPlugin { public const string Guid = "vh.combatregen"; public const string Name = "CombatRegen"; public const string Version = "1.0.1"; internal static ManualLogSource Log; internal static ConfigEntry<float> AdrenalinePerSecond; internal static ConfigEntry<float> CombatTimeout; internal static ConfigEntry<bool> ShowCombatMessage; private const string Regen = "1. Combat regen"; private const string Messages = "2. Messages"; private Harmony _harmony; private FileSystemWatcher _watcher; private DateTime _lastReload; private static ConfigurationManagerAttributes Display(string category, string name, int order) { return new ConfigurationManagerAttributes { Category = category, DispName = name, Order = order }; } private void Awake() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; AdrenalinePerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("General", "AdrenalinePerSecond", 0.5f, new ConfigDescription("Adrenaline added per second while you are in combat, on top of what hits, blocks and dodges give. The bar also stops draining during combat. When it is full your trinket procs and the bar resets, as in the normal game. Default 0.5.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), new object[1] { Display("1. Combat regen", "Adrenaline per second in combat", 2) })); CombatTimeout = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CombatTimeout", 5f, new ConfigDescription("Seconds after the last combat event before combat ends. A combat event is an enemy hunting you while it can see or hear you, a hit you take from a creature (or from a player when both of you have PvP on), or a hit you land on a creature (or on such a player). Default 5.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), new object[1] { Display("1. Combat regen", "Combat ends after (seconds)", 1) })); ShowCombatMessage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowCombatMessage", false, new ConfigDescription("Show a message in the top-left corner when combat starts (with what started it) and ends.", (AcceptableValueBase)null, new object[1] { Display("2. Messages", "Show combat start/end message", 1) })); _harmony = new Harmony("vh.combatregen"); _harmony.PatchAll(); SetupWatcher(); Log.LogInfo((object)$"Loaded: {AdrenalinePerSecond.Value:0.##} adrenaline/s, combat ends after {CombatTimeout.Value:0.#} s."); } private void OnDestroy() { _watcher?.Dispose(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void SetupWatcher() { _watcher = new FileSystemWatcher(Paths.ConfigPath, Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath)); _watcher.Changed += ReloadConfig; _watcher.Created += ReloadConfig; _watcher.Renamed += ReloadConfig; _watcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; _watcher.EnableRaisingEvents = true; } private void ReloadConfig(object sender, FileSystemEventArgs e) { if ((DateTime.Now - _lastReload).TotalSeconds < 1.0 || !File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath)) { return; } _lastReload = DateTime.Now; ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; try { ((BaseUnityPlugin)this).Config.Reload(); Log.LogInfo((object)$"Configuration reloaded: {AdrenalinePerSecond.Value:0.##} adrenaline/s, combat ends after {CombatTimeout.Value:0.#} s."); } catch (Exception ex) { Log.LogError((object)("Error reloading configuration: " + ex.Message)); } finally { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = true; } } internal static void Notify(string message, MessageType type = (MessageType)1) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)MessageHud.instance != (Object)null) { MessageHud.instance.ShowMessage(type, message, 0, (Sprite)null, false, true); } } } }