using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace Erskine.LethalEscapeThrottle; [BepInPlugin("Erskine.LethalEscapeThrottle", "LethalEscapeThrottle", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string GUID = "Erskine.LethalEscapeThrottle"; public const string NAME = "LethalEscapeThrottle"; public const string VERSION = "1.0.1"; internal static ManualLogSource Log; internal static ConfigEntry Cooldown; internal static ConfigEntry Enabled; private static readonly Dictionary _next = new Dictionary(); private void Awake() { //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Cooldown = ((BaseUnityPlugin)this).Config.Bind("General", "CooldownSeconds", 2f, "Minimum seconds between an enemy's repeated 'go outside' path attempts. Higher = fewer retries (less lag) but a stuck enemy reacts a little slower once a path opens up. Set 0 to disable throttling."); Enabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Master toggle for the throttle patch."); try { Type type = AccessTools.TypeByName("UpdatedEscape.Plugin+AIBridge"); if (type == null) { Log.LogError((object)"Couldn't find UpdatedEscape.Plugin+AIBridge. Is LethalEscapeUpdated installed? Throttle NOT applied."); return; } MethodInfo methodInfo = AccessTools.Method(type, "RequestTransition", (Type[])null, (Type[])null); if (methodInfo == null) { Log.LogError((object)"Couldn't find AIBridge.RequestTransition (mod version may differ). Throttle NOT applied."); return; } HarmonyMethod val = new HarmonyMethod(typeof(Plugin).GetMethod("RequestTransition_Prefix", BindingFlags.Static | BindingFlags.NonPublic)); new Harmony("Erskine.LethalEscapeThrottle").Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Log.LogInfo((object)("LethalEscapeThrottle v1.0.1: throttling AIBridge.RequestTransition (cooldown " + Cooldown.Value + "s).")); } catch (Exception ex) { Log.LogError((object)("Setup failed, throttle not applied: " + ex)); } } private static bool RequestTransition_Prefix(EnemyAI enemy) { try { if (!Enabled.Value) { return true; } float value = Cooldown.Value; if (value <= 0f || (Object)(object)enemy == (Object)null) { return true; } int instanceID = ((Object)enemy).GetInstanceID(); float time = Time.time; if (_next.TryGetValue(instanceID, out var value2) && time < value2) { return false; } _next[instanceID] = time + value; if (_next.Count > 2048) { _next.Clear(); } return true; } catch { return true; } } }