Decompiled source of NoEquipAnimation v1.0.0

NoEquipAnimation.dll

Decompiled 13 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
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("NoEquipAnimation")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Disables weapon and arm equip animations in ULTRAKILL.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9a77156e3015af46793b407ba3c7a63c9e2d775d")]
[assembly: AssemblyProduct("NoEquipAnimation")]
[assembly: AssemblyTitle("NoEquipAnimation")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NoEquipAnimation
{
	public class FastDrawComponent : MonoBehaviour
	{
		private Animator animator;

		private float originalSpeed = 1f;

		private int framesToFast;

		private bool isArm;

		public void Initialize(bool isArmComponent)
		{
			isArm = isArmComponent;
		}

		private void Awake()
		{
			animator = ((Component)this).GetComponentInChildren<Animator>();
		}

		private void OnEnable()
		{
			if ((Object)(object)animator == (Object)null)
			{
				animator = ((Component)this).GetComponentInChildren<Animator>();
			}
			if ((Object)(object)animator != (Object)null)
			{
				originalSpeed = animator.speed;
				if (isArm ? ModConfig.DisableArmEquipAnimation.Value : ModConfig.DisableWeaponEquipAnimation.Value)
				{
					animator.speed = 1000f;
					framesToFast = 2;
				}
			}
		}

		private void Update()
		{
			if ((Object)(object)animator != (Object)null && framesToFast > 0)
			{
				framesToFast--;
				if (framesToFast == 0)
				{
					animator.speed = originalSpeed;
				}
			}
		}
	}
	public static class ModConfig
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static BoolValueChangeEventDelegate <>9__4_0;

			public static BoolValueChangeEventDelegate <>9__4_1;

			public static KeyCodeValueChangeEventDelegate <>9__4_2;

			internal void <InitializePluginConfigurator>b__4_0(BoolValueChangeEvent e)
			{
				DisableWeaponEquipAnimation.Value = e.value;
			}

			internal void <InitializePluginConfigurator>b__4_1(BoolValueChangeEvent e)
			{
				DisableArmEquipAnimation.Value = e.value;
			}

			internal void <InitializePluginConfigurator>b__4_2(KeyCodeValueChangeEvent e)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				ToggleKey.Value = e.value;
			}
		}

		public static ConfigEntry<bool> DisableWeaponEquipAnimation;

		public static ConfigEntry<bool> DisableArmEquipAnimation;

		public static ConfigEntry<KeyCode> ToggleKey;

		public static void Initialize(ConfigFile config)
		{
			DisableWeaponEquipAnimation = config.Bind<bool>("General", "DisableWeaponEquipAnimation", true, "Disable drawing/equip animations for weapons (guns).");
			DisableArmEquipAnimation = config.Bind<bool>("General", "DisableArmEquipAnimation", true, "Disable drawing/equip animations for arms/fists.");
			ToggleKey = config.Bind<KeyCode>("Controls", "ToggleKey", (KeyCode)104, "Key to toggle disabling equip animations in-game.");
			InitializePluginConfigurator();
		}

		private static void InitializePluginConfigurator()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			try
			{
				PluginConfigurator obj = PluginConfigurator.Create("No Equip Animations", "com.antigravity.noequipanimation");
				BoolField val = new BoolField(obj.rootPanel, "Disable Weapon Animations", "disable_weapon_anims", DisableWeaponEquipAnimation.Value);
				object obj2 = <>c.<>9__4_0;
				if (obj2 == null)
				{
					BoolValueChangeEventDelegate val2 = delegate(BoolValueChangeEvent e)
					{
						DisableWeaponEquipAnimation.Value = e.value;
					};
					<>c.<>9__4_0 = val2;
					obj2 = (object)val2;
				}
				val.onValueChange += (BoolValueChangeEventDelegate)obj2;
				BoolField val3 = new BoolField(obj.rootPanel, "Disable Arm/Punch Animations", "disable_arm_anims", DisableArmEquipAnimation.Value);
				object obj3 = <>c.<>9__4_1;
				if (obj3 == null)
				{
					BoolValueChangeEventDelegate val4 = delegate(BoolValueChangeEvent e)
					{
						DisableArmEquipAnimation.Value = e.value;
					};
					<>c.<>9__4_1 = val4;
					obj3 = (object)val4;
				}
				val3.onValueChange += (BoolValueChangeEventDelegate)obj3;
				KeyCodeField val5 = new KeyCodeField(obj.rootPanel, "Toggle Mod Key (H = varsayılan)", "toggle_key", ToggleKey.Value);
				object obj4 = <>c.<>9__4_2;
				if (obj4 == null)
				{
					KeyCodeValueChangeEventDelegate val6 = delegate(KeyCodeValueChangeEvent e)
					{
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						ToggleKey.Value = e.value;
					};
					<>c.<>9__4_2 = val6;
					obj4 = (object)val6;
				}
				val5.onValueChange += (KeyCodeValueChangeEventDelegate)obj4;
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"[NoEquipAnimation] Failed to initialize PluginConfigurator: {arg}");
			}
		}
	}
	public static class Patches
	{
		public static void WeaponOnEnablePostfix(MonoBehaviour __instance)
		{
			EnsureFastDraw(((Component)__instance).gameObject, isArm: false);
		}

		public static void ArmOnEnablePostfix(MonoBehaviour __instance)
		{
			EnsureFastDraw(((Component)__instance).gameObject, isArm: true);
		}

		private static void EnsureFastDraw(GameObject go, bool isArm)
		{
			if (!((Object)(object)go == (Object)null) && (Object)(object)go.GetComponent<FastDrawComponent>() == (Object)null)
			{
				go.AddComponent<FastDrawComponent>().Initialize(isArm);
				Debug.Log((object)$"[NoEquipAnimation] FastDrawComponent eklendi: {((Object)go).name} (kol: {isArm})");
			}
		}
	}
	[BepInPlugin("com.antigravity.noequipanimation", "No Equip Animations", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony harmony;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Initializing ULTRAKILL No Equip Animations mod...");
			ModConfig.Initialize(((BaseUnityPlugin)this).Config);
			harmony = new Harmony("com.antigravity.noequipanimation");
			ApplyPatchesSafely();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ULTRAKILL No Equip Animations mod initialized!");
		}

		private void ApplyPatchesSafely()
		{
			TryPatch(typeof(Revolver), "OnEnable", "WeaponOnEnablePostfix", isArm: false);
			TryPatch(typeof(Shotgun), "OnEnable", "WeaponOnEnablePostfix", isArm: false);
			TryPatch(typeof(Nailgun), "OnEnable", "WeaponOnEnablePostfix", isArm: false);
			TryPatch(typeof(Railcannon), "OnEnable", "WeaponOnEnablePostfix", isArm: false);
			TryPatch(typeof(RocketLauncher), "OnEnable", "WeaponOnEnablePostfix", isArm: false);
			TryPatch(typeof(Punch), "OnEnable", "ArmOnEnablePostfix", isArm: true);
		}

		private void TryPatch(Type targetType, string methodName, string postfixName, bool isArm)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(targetType, methodName, (Type[])null, (Type[])null);
				if (methodInfo == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("[NoEquipAnimation] " + targetType.Name + "." + methodName + " bulunamadı, atlanıyor."));
				}
				else
				{
					HarmonyMethod val = (isArm ? new HarmonyMethod(typeof(Patches), "ArmOnEnablePostfix", (Type[])null) : new HarmonyMethod(typeof(Patches), "WeaponOnEnablePostfix", (Type[])null));
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("[NoEquipAnimation] " + targetType.Name + "." + methodName + " patch edildi."));
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[NoEquipAnimation] " + targetType.Name + "." + methodName + " patch başarısız: " + ex.Message));
			}
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (!Input.GetKeyDown(ModConfig.ToggleKey.Value))
			{
				return;
			}
			bool flag = !ModConfig.DisableWeaponEquipAnimation.Value;
			ModConfig.DisableWeaponEquipAnimation.Value = flag;
			ModConfig.DisableArmEquipAnimation.Value = flag;
			((BaseUnityPlugin)this).Config.Save();
			string text = (flag ? "<color=red>KAPALI</color>" : "<color=lime>AÇIK</color>");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Equip animasyonları: " + (flag ? "Kapalı" : "Açık")));
			try
			{
				if ((Object)(object)MonoSingleton<HudMessageReceiver>.Instance != (Object)null)
				{
					MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage("Equip Animasyonu: " + text, "", "", 0, false, false, true);
				}
			}
			catch
			{
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
}