Decompiled source of CrossbowSaveCharge v1.0.0

CrossbowSaveCharge.dll

Decompiled 2 weeks ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
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("CrossbowSaveCharge")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CrossbowSaveCharge")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5a7b042b-6761-486f-bd9c-8f71923dbe78")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CrossbowSaveCharge;

[BepInPlugin("com.author.crossbowsavecharge", "CrossbowSaveCharge", "1.0.0")]
public class CrossbowSaveChargePlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Character), "CustomFixedUpdate")]
	internal static class Character_CustomFixedUpdate_Patch
	{
		private static void Postfix(Character __instance)
		{
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val != null && (Object)(object)val == (Object)(object)Player.m_localPlayer)
			{
				ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
				if (currentWeapon != null && IsCrossbowOrGrapple(currentWeapon) && ((Humanoid)val).IsWeaponLoaded())
				{
					SavedLoadedItems.Add(((object)currentWeapon).GetHashCode());
				}
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid), "EquipItem")]
	internal static class Humanoid_EquipItem_Patch
	{
		private static void Postfix(Humanoid __instance, ItemData item, bool __result)
		{
			if (!__result)
			{
				return;
			}
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val == null || !((Object)(object)val == (Object)(object)Player.m_localPlayer) || item == null || !IsCrossbowOrGrapple(item))
			{
				return;
			}
			int hashCode = ((object)item).GetHashCode();
			if (SavedLoadedItems.Contains(hashCode))
			{
				item.m_shared.m_attack.m_requiresReload = false;
				Animator val2 = CharacterAnimatorRef.Invoke((Character)(object)val);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.SetBool("reload", true);
				}
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid), "IsWeaponLoaded")]
	internal static class Humanoid_IsWeaponLoaded_Patch
	{
		private static void Postfix(Humanoid __instance, ref bool __result)
		{
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val != null && (Object)(object)val == (Object)(object)Player.m_localPlayer)
			{
				ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
				if (currentWeapon != null && IsCrossbowOrGrapple(currentWeapon) && SavedLoadedItems.Contains(((object)currentWeapon).GetHashCode()))
				{
					__result = true;
				}
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid), "StartAttack")]
	internal static class Humanoid_StartAttack_Patch
	{
		private static void Postfix(Humanoid __instance, bool __result)
		{
			if (!__result)
			{
				return;
			}
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val == null || !((Object)(object)val == (Object)(object)Player.m_localPlayer))
			{
				return;
			}
			ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
			if (currentWeapon != null && IsCrossbowOrGrapple(currentWeapon))
			{
				int hashCode = ((object)currentWeapon).GetHashCode();
				if (SavedLoadedItems.Contains(hashCode))
				{
					currentWeapon.m_shared.m_attack.m_requiresReload = true;
					SavedLoadedItems.Remove(hashCode);
				}
			}
		}
	}

	[HarmonyPatch(typeof(Game), "Logout")]
	internal static class Game_Logout_Patch
	{
		private static void Postfix()
		{
			SavedLoadedItems.Clear();
		}
	}

	public const string PluginGUID = "com.author.crossbowsavecharge";

	public const string PluginName = "CrossbowSaveCharge";

	public const string PluginVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("com.author.crossbowsavecharge");

	private static readonly HashSet<int> SavedLoadedItems = new HashSet<int>();

	private static readonly FieldRef<Character, Animator> CharacterAnimatorRef = AccessTools.FieldRefAccess<Character, Animator>("m_animator");

	private void Awake()
	{
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"CrossbowSaveCharge 1.0.0 успешно загружен!");
	}

	public static bool IsCrossbowOrGrapple(ItemData item)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Invalid comparison between Unknown and I4
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Invalid comparison between Unknown and I4
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Invalid comparison between Unknown and I4
		if (item == null || item.m_shared == null)
		{
			return false;
		}
		SkillType skillType = item.m_shared.m_skillType;
		if ((int)skillType == 9 || (int)skillType == 14 || (int)skillType == 8)
		{
			return true;
		}
		string text = (((Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name.ToLower() : "");
		string text2 = item.m_shared.m_name.ToLower();
		return text.Contains("crossbow") || text.Contains("grapple") || text.Contains("arbalest") || text.Contains("ripper") || text.Contains("hook") || text2.Contains("crossbow") || text2.Contains("grapple") || text2.Contains("arbalest") || text2.Contains("hook") || text2.Contains("ripper");
	}
}