using System;
using System.Diagnostics;
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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BetterStaminaRegen")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+e2433bb74677e3c036a72ffecb88039e408047c6")]
[assembly: AssemblyProduct("BetterStaminaRegen")]
[assembly: AssemblyTitle("BetterStaminaRegen")]
[assembly: AssemblyVersion("1.0.1.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 ABUF.BetterStaminaRegen
{
[HarmonyPatch(typeof(Character), "UpdateVariablesFixed")]
internal static class RegenContextPatch
{
public static bool InNaturalRegen;
[HarmonyPrefix]
private static void Prefix(Character __instance)
{
InNaturalRegen = false;
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.data == (Object)null) && __instance.IsLocal)
{
float value = Plugin.DelayReduction.Value;
if (value > 0f)
{
float num = Mathf.Clamp(value, 0f, 0.5f);
float num2 = num / Mathf.Max(0.01f, 1f - num);
CharacterData data = __instance.data;
data.sinceUseStamina += Time.fixedDeltaTime * num2;
}
InNaturalRegen = true;
}
}
[HarmonyPostfix]
private static void Postfix()
{
InNaturalRegen = false;
}
}
[HarmonyPatch(typeof(Character), "AddStamina")]
internal static class RegenSpeedPatch
{
[HarmonyPrefix]
private static void Prefix(Character __instance, ref float add)
{
if (RegenContextPatch.InNaturalRegen && !(add <= 0f) && !((Object)(object)__instance == (Object)null) && __instance.IsLocal)
{
float num = Mathf.Clamp(Plugin.SpeedBonus.Value, 0f, 0.5f);
if (num > 0f)
{
add *= 1f + num;
}
}
}
}
[BepInPlugin("abuf.betterstaminaregen", "Better Stamina Regeneration", "1.0.1")]
public sealed class Plugin : BaseUnityPlugin
{
public const string Guid = "abuf.betterstaminaregen";
public const string PluginName = "Better Stamina Regeneration";
public const string PluginVersion = "1.0.1";
public static Plugin Instance;
public static ManualLogSource Log;
public static ConfigEntry<float> SpeedBonus;
public static ConfigEntry<float> DelayReduction;
private static readonly Harmony Harmony = new Harmony("abuf.betterstaminaregen");
private void Awake()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Expected O, but got Unknown
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
SpeedBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "SpeedBonus", 0.5f, new ConfigDescription("自然回体速度加成。0 = 原版,0.5 = 快 50%(默认,也是上限)。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.5f), Array.Empty<object>()));
DelayReduction = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "DelayReduction", 0.5f, new ConfigDescription("停止消耗体力后等待时间的缩短比例。0 = 原版,0.5 = 等待时间减半(默认,也是上限)。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.5f), Array.Empty<object>()));
SpeedBonus.Value = Clamp01(SpeedBonus.Value, 0.5f);
DelayReduction.Value = Clamp01(DelayReduction.Value, 0.5f);
Harmony.PatchAll();
Log.LogInfo((object)("Better Stamina Regeneration 1.0.1 loaded. speed +" + SpeedBonus.Value * 100f + "%, delay -" + DelayReduction.Value * 100f + "%"));
}
private void OnDestroy()
{
Harmony.UnpatchSelf();
}
private static float Clamp01(float value, float max)
{
if (value < 0f)
{
return 0f;
}
if (!(value > max))
{
return value;
}
return max;
}
}
}