Decompiled source of SaveCrossbowState v1.0.1

SaveCrossbowState.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SaveCrossbowState")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("SaveCrossbowState")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 SaveCrossbowState
{
	[BepInPlugin("Azumatt.SaveCrossbowState", "SaveCrossbowState", "1.0.1")]
	public class SaveCrossbowStatePlugin : BaseUnityPlugin
	{
		internal const string ModName = "SaveCrossbowState";

		internal const string ModVersion = "1.0.1";

		internal const string Author = "Azumatt";

		private const string ModGUID = "Azumatt.SaveCrossbowState";

		private readonly Harmony _harmony = new Harmony("Azumatt.SaveCrossbowState");

		public static readonly ManualLogSource SaveCrossbowStateLogger = Logger.CreateLogSource("SaveCrossbowState");

		public const string CrossbowLoaded = "crossbowLoaded";

		public const string CrossbowLoadedChanged = "crossbowLoaded_changed";

		public void Awake()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)SystemInfo.graphicsDeviceType == 4)
			{
				SaveCrossbowStateLogger.LogWarning((object)"This mod is client-side only and is not needed on a dedicated server. Plugin patches will not be applied.");
			}
			else
			{
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
			}
		}

		public static bool IsCrossbowItem(ItemData? possibleCrossbow)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Invalid comparison between Unknown and I4
			SkillType? val = possibleCrossbow?.m_shared.m_skillType;
			if (val.HasValue)
			{
				SkillType valueOrDefault = val.GetValueOrDefault();
				if ((int)valueOrDefault == 9 || (int)valueOrDefault == 14)
				{
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
	internal static class ResetLoaded
	{
		private static void Prefix(Attack __instance)
		{
			ItemData currentWeapon = __instance.m_character.GetCurrentWeapon();
			if (((Character)__instance.m_character).IsPlayer() && !((Object)(object)__instance.m_character != (Object)(object)Player.m_localPlayer) && SaveCrossbowStatePlugin.IsCrossbowItem(currentWeapon))
			{
				currentWeapon.m_customData["crossbowLoaded"] = "false";
				if (currentWeapon.m_customData.TryGetValue("crossbowLoaded_changed", out var value) && bool.TryParse(value, out var result) && result)
				{
					currentWeapon.m_customData.Remove("crossbowLoaded_changed");
					currentWeapon.m_shared.m_attack.m_requiresReload = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
	internal static class CheckIfCrossbowWasUnequipped
	{
		private static void Prefix(Humanoid __instance, ItemData? item, bool triggerEquipEffects = true)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (((Character)__instance).IsPlayer() && !((Object)(object)Player.m_localPlayer == (Object)null) && !Player.m_localPlayer.m_isLoading && SaveCrossbowStatePlugin.IsCrossbowItem(item) && ((Humanoid)(Player)__instance).IsWeaponLoaded())
			{
				item.m_customData["crossbowLoaded"] = "true";
				if (item.m_shared.m_attack.m_requiresReload)
				{
					item.m_customData["crossbowLoaded_changed"] = "true";
					item.m_shared.m_attack.m_requiresReload = false;
				}
			}
		}
	}
}