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 ArbalestStaysLoaded v1.2.1
ArbalestStaysLoaded.dll
Decompiled 40 minutes agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; 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.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("ArbalestStaysLoaded")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ArbalestStaysLoaded")] [assembly: AssemblyTitle("ArbalestStaysLoaded")] [assembly: AssemblyVersion("1.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 ArbalestStaysLoaded { [BepInPlugin("com.arbaleststaysloaded", "ArbalestStaysLoaded", "1.2.1")] public class Plugin : BaseUnityPlugin { public const string PluginGUID = "com.arbaleststaysloaded"; public const string PluginName = "ArbalestStaysLoaded"; public const string PluginVersion = "1.2.1"; internal const string LoadedKey = "ArbalestStaysLoaded"; internal const string ProgressKey = "ArbalestStaysLoadedProgress"; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> IgnoreJumping; internal static ConfigEntry<bool> IgnoreDodging; internal static ConfigEntry<bool> IgnoreSprinting; internal static ConfigEntry<bool> IgnoreAttacking; internal static ConfigEntry<bool> IgnoreGettingHit; internal static ConfigEntry<bool> KeepProgressWhenSwitching; private void Awake() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Expected O, but got Unknown //IL_013d: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, new ConfigDescription("A loaded crossbow stays loaded when you put it away.", (AcceptableValueBase)null, Array.Empty<object>())); IgnoreJumping = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "IgnoreJumping", false, new ConfigDescription("Jumping does not cancel a crossbow that is loading.", (AcceptableValueBase)null, Array.Empty<object>())); IgnoreDodging = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "IgnoreDodging", false, new ConfigDescription("Dodging (rolling) does not cancel a crossbow that is loading.", (AcceptableValueBase)null, Array.Empty<object>())); IgnoreSprinting = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "IgnoreSprinting", false, new ConfigDescription("Sprinting does not cancel a crossbow that is loading. Without this, starting to sprint resets the loading to nothing.", (AcceptableValueBase)null, Array.Empty<object>())); IgnoreAttacking = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "IgnoreAttacking", false, new ConfigDescription("Starting an attack (such as the crossbow's bash) does not cancel a crossbow that is loading.", (AcceptableValueBase)null, Array.Empty<object>())); IgnoreGettingHit = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "IgnoreGettingHit", false, new ConfigDescription("Getting hit (and being staggered or knocked back) does not cancel a crossbow that is loading.", (AcceptableValueBase)null, Array.Empty<object>())); KeepProgressWhenSwitching = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "KeepProgressWhenSwitching", false, new ConfigDescription("Switching to another weapon or putting the crossbow away stops the loading animation (and the switch is not held up), but the progress is kept on the crossbow, and loading it again carries on from there. Off: the loading starts over.", (AcceptableValueBase)null, Array.Empty<object>())); new Harmony("com.arbaleststaysloaded").PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"ArbalestStaysLoaded 1.2.1 loaded"); } } internal enum Cause { None, Jump, Dodge, Attack } internal static class State { internal static Cause Cause; internal static bool Unequipping; internal static float LastHit = -100f; internal static readonly FieldRef<Player, List<MinorActionData>> Queue = AccessTools.FieldRefAccess<Player, List<MinorActionData>>("m_actionQueue"); internal static readonly FieldRef<Player, ItemData> Loaded = AccessTools.FieldRefAccess<Player, ItemData>("m_weaponLoaded"); internal static bool HasReload(Player player) { return Queue.Invoke(player).Exists((MinorActionData a) => (int)a.m_type == 2); } internal static void SaveProgress(Player player) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Invalid comparison between Unknown and I4 if (!Plugin.Enabled.Value || !Plugin.KeepProgressWhenSwitching.Value) { return; } foreach (MinorActionData item in Queue.Invoke(player)) { if ((int)item.m_type == 2 && item.m_item != null && item.m_time > 0f) { item.m_item.m_customData["ArbalestStaysLoadedProgress"] = item.m_time.ToString(CultureInfo.InvariantCulture); Player_FixedUpdate_Patch.Forget(); } } } } [HarmonyPatch(typeof(Player), "SetWeaponLoaded")] internal static class Player_SetWeaponLoaded_Patch { private static void Postfix(ItemData weapon) { if (weapon != null && Plugin.Enabled.Value) { weapon.m_customData["ArbalestStaysLoaded"] = "1"; weapon.m_customData.Remove("ArbalestStaysLoadedProgress"); } } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] internal static class Humanoid_UnequipItem_Patch { private static void Prefix() { State.Unequipping = true; } private static void Finalizer() { State.Unequipping = false; } } [HarmonyPatch(typeof(Player), "ResetLoadedWeapon")] internal static class Player_ResetLoadedWeapon_Patch { [HarmonyPriority(800)] private static void Prefix(Player __instance) { if (State.Unequipping) { State.SaveProgress(__instance); } else { State.Loaded.Invoke(__instance)?.m_customData.Remove("ArbalestStaysLoaded"); } } } [HarmonyPatch(typeof(Player), "UpdateWeaponLoading")] internal static class Player_UpdateWeaponLoading_Patch { private static readonly MethodInfo SetLoaded = AccessTools.Method(typeof(Player), "SetWeaponLoaded", (Type[])null, (Type[])null); private static bool Prefix(Player __instance, ItemData weapon) { if (!Plugin.Enabled.Value || weapon == null || !weapon.m_shared.m_attack.m_requiresReload) { return true; } if (State.Loaded.Invoke(__instance) == weapon) { return true; } if (!weapon.m_customData.ContainsKey("ArbalestStaysLoaded")) { return true; } SetLoaded.Invoke(__instance, new object[1] { weapon }); return false; } } [HarmonyPatch(typeof(Player), "CancelReloadAction")] internal static class Player_CancelReloadAction_Patch { private static void Prefix(Player __instance) { State.SaveProgress(__instance); } } [HarmonyPatch(typeof(Player), "QueueReloadAction")] internal static class Player_QueueReloadAction_Patch { private static void Postfix(Player __instance) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 if (!Plugin.Enabled.Value || !Plugin.KeepProgressWhenSwitching.Value) { return; } foreach (MinorActionData item in State.Queue.Invoke(__instance)) { if ((int)item.m_type == 2 && item.m_item != null && item.m_time == 0f && item.m_item.m_customData.TryGetValue("ArbalestStaysLoadedProgress", out var value) && float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { item.m_time = Mathf.Clamp(result, 0f, item.m_duration * 0.95f); item.m_item.m_customData.Remove("ArbalestStaysLoadedProgress"); } } } } [HarmonyPatch(typeof(Player), "OnJump")] internal static class Player_OnJump_Patch { private static void Prefix() { State.Cause = Cause.Jump; } private static void Finalizer() { State.Cause = Cause.None; } } [HarmonyPatch(typeof(Player), "UpdateDodge")] internal static class Player_UpdateDodge_Patch { private static void Prefix() { State.Cause = Cause.Dodge; } private static void Finalizer() { State.Cause = Cause.None; } } [HarmonyPatch(typeof(Humanoid), "StartAttack")] internal static class Humanoid_StartAttack_Patch { private static void Prefix() { State.Cause = Cause.Attack; } private static void Finalizer() { State.Cause = Cause.None; } } [HarmonyPatch(typeof(Player), "ClearActionQueue")] internal static class Player_ClearActionQueue_Patch { private static bool Prefix(Player __instance) { if (!Plugin.Enabled.Value || !State.HasReload(__instance)) { return true; } if (State.Cause switch { Cause.Jump => Plugin.IgnoreJumping.Value ? 1 : 0, Cause.Dodge => Plugin.IgnoreDodging.Value ? 1 : 0, Cause.Attack => Plugin.IgnoreAttacking.Value ? 1 : 0, _ => 0, } == 0) { if (State.Cause != Cause.None) { Player_FixedUpdate_Patch.Forget(); } return true; } State.Queue.Invoke(__instance).RemoveAll((MinorActionData a) => (int)a.m_type != 2); return false; } } [HarmonyPatch(typeof(Character), "ApplyDamage")] internal static class Character_ApplyDamage_Patch { private static void Postfix(Character __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { State.LastHit = Time.time; } } } [HarmonyPatch(typeof(Player), "FixedUpdate")] internal static class Player_FixedUpdate_Patch { private static MinorActionData _seen; private static float _seenTime; internal static void Forget() { _seen = null; } private static bool Wanted() { if (Plugin.Enabled.Value) { if (!Plugin.IgnoreSprinting.Value) { return Plugin.IgnoreGettingHit.Value; } return true; } return false; } private static void Check(Player player, string when) { if ((Object)(object)player != (Object)(object)Player.m_localPlayer) { return; } List<MinorActionData> list = State.Queue.Invoke(player); MinorActionData val = list.Find((MinorActionData a) => (int)a.m_type == 2); if (_seen != null && val != _seen) { bool flag = Plugin.IgnoreSprinting.Value && ((Character)player).IsRunning(); bool flag2 = Plugin.IgnoreGettingHit.Value && (Time.time - State.LastHit < 1f || ((Character)player).IsStaggering() || ((Character)player).IsKnockedBack()); string text = null; if (((Character)player).IsDead()) { text = "dead"; } else if (_seen.m_time > _seen.m_duration) { text = "finished"; } else if (State.Loaded.Invoke(player) == _seen.m_item) { text = "already loaded"; } else if (_seen.m_item == null || !((Humanoid)player).GetInventory().ContainsItem(_seen.m_item)) { text = "crossbow not in inventory"; } else if (!flag && !flag2) { text = "not something that is ignored"; } Plugin.Log.LogDebug((object)(string.Format("[{0}] Loading {1} at {2:0.00}/{3:0.00}s ", when, (val == null) ? "vanished" : "started over", _seenTime, _seen.m_duration) + $"(running={((Character)player).IsRunning()} queue={list.Count}): " + (text ?? "put back"))); if (text == null) { if (val != null) { list.Remove(val); } list.Insert(0, _seen); val = _seen; } } _seen = val; _seenTime = val?.m_time ?? 0f; } private static void Prefix(Player __instance) { if (Wanted()) { Check(__instance, "before"); } else { _seen = null; } } private static void Postfix(Player __instance) { if (Wanted()) { Check(__instance, "after"); } } } }