Decompiled source of ReloadAnimations v0.1.0

NGA.MagAnimations.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("NGA")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Persistent player progression! Raid, stash loot, and deploy with seemless scene/loadout saving.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("NGA.MagAnimations")]
[assembly: AssemblyTitle("BepInEx Plugin Title")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace NGA
{
	[BepInPlugin("NGA.MagAnimations", "MagAnimations", "0.1.0")]
	[BepInDependency("nrgill28.Sodalite", "1.4.1")]
	[BepInProcess("h3vr.exe")]
	public class MagAnimations : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(FVRFireArmMagazine))]
		[HarmonyPatch("FVRFixedUpdate")]
		private class FVRFireArmMagazineFVRFixedUpdate
		{
			private static void Postfix(FVRFireArmMagazine __instance)
			{
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_045a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0471: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_0250: Unknown result type (might be due to invalid IL or missing references)
				//IL_0255: Unknown result type (might be due to invalid IL or missing references)
				//IL_025d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0264: Unknown result type (might be due to invalid IL or missing references)
				//IL_0269: Unknown result type (might be due to invalid IL or missing references)
				//IL_026e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0270: Unknown result type (might be due to invalid IL or missing references)
				//IL_0272: Unknown result type (might be due to invalid IL or missing references)
				//IL_0274: Unknown result type (might be due to invalid IL or missing references)
				//IL_0279: Unknown result type (might be due to invalid IL or missing references)
				//IL_0299: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0412: Unknown result type (might be due to invalid IL or missing references)
				//IL_0429: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03be: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0301: Unknown result type (might be due to invalid IL or missing references)
				//IL_0306: Unknown result type (might be due to invalid IL or missing references)
				//IL_030a: Unknown result type (might be due to invalid IL or missing references)
				//IL_030f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0313: Unknown result type (might be due to invalid IL or missing references)
				//IL_0318: Unknown result type (might be due to invalid IL or missing references)
				//IL_031f: Unknown result type (might be due to invalid IL or missing references)
				//IL_032e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0333: Unknown result type (might be due to invalid IL or missing references)
				//IL_0338: Unknown result type (might be due to invalid IL or missing references)
				//IL_0340: Unknown result type (might be due to invalid IL or missing references)
				//IL_0350: Unknown result type (might be due to invalid IL or missing references)
				//IL_0385: Unknown result type (might be due to invalid IL or missing references)
				//IL_038a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0393: Unknown result type (might be due to invalid IL or missing references)
				//IL_0398: Unknown result type (might be due to invalid IL or missing references)
				//IL_039a: Unknown result type (might be due to invalid IL or missing references)
				if (!config_enable.Value)
				{
					return;
				}
				if ((Object)(object)__instance.FireArm != (Object)null)
				{
					FVRFireArm fireArm = __instance.FireArm;
					Transform magMountPos = fireArm.GetMagMountPos(__instance.IsBeltBox);
					if ((Object)(object)magMountPos != (Object)null && (Object)(object)__instance.Viz != (Object)null)
					{
						__instance.Viz.position = magMountPos.position;
						__instance.Viz.rotation = magMountPos.rotation;
						((Component)__instance).transform.position = magMountPos.position;
						((Component)__instance).transform.rotation = magMountPos.rotation;
					}
				}
				if ((Object)(object)__instance == (Object)null || !((FVRInteractiveObject)__instance).IsHeld || (Object)(object)((FVRInteractiveObject)__instance).m_hand == (Object)null)
				{
					return;
				}
				if (((FVRInteractiveObject)__instance).IsHeld && (Object)(object)((FVRInteractiveObject)__instance).m_hand != (Object)null && (Object)(object)((FVRInteractiveObject)__instance).m_hand.OtherHand != (Object)null && (Object)(object)((FVRInteractiveObject)__instance).m_hand.OtherHand.CurrentInteractable != (Object)null && ((FVRInteractiveObject)__instance).m_hand.OtherHand.CurrentInteractable is FVRFireArm)
				{
					FVRInteractiveObject currentInteractable = ((FVRInteractiveObject)__instance).m_hand.OtherHand.CurrentInteractable;
					FVRFireArm val = (FVRFireArm)(object)((currentInteractable is FVRFireArm) ? currentInteractable : null);
					if (forbiddenNames.Contains(((Object)((Component)__instance).gameObject).name))
					{
						return;
					}
					Transform magMountPos2 = val.GetMagMountPos(__instance.IsBeltBox);
					if ((Object)(object)magMountPos2 == (Object)null)
					{
						return;
					}
					bool flag = (Object)(object)__instance.m_magChild != (Object)null || (Object)(object)__instance.m_magParent != (Object)null;
					if (!((Object)(object)val.Magazine == (Object)null) || val.MagazineType != __instance.MagazineType || !((Object)(object)val.GetMagMountPos(__instance.IsBeltBox) != (Object)null) || flag)
					{
						return;
					}
					__instance.IsNonPhysForLoad = true;
					((FVRInteractiveObject)__instance).SetAllCollidersToLayer(false, "NoCol");
					bool flag2 = false;
					if (enable_rock_anm.Value && rockNames.Any(((Object)((Component)__instance).gameObject).name.StartsWith))
					{
						flag2 = true;
					}
					Vector3 up = magMountPos2.up;
					Vector3 val2 = __instance.RoundEjectionPos.position - magMountPos2.position;
					Vector3 val3 = Vector3.ProjectOnPlane(val2, up);
					float magnitude = ((Vector3)(ref val3)).magnitude;
					float num = DistanceAlongUpAxis(((Component)__instance).transform, magMountPos2);
					float num2 = Vector3.Distance(__instance.RoundEjectionPos.position, magMountPos2.position);
					if (num2 <= config_mag_lock_dist.Value)
					{
						if (flag2)
						{
							float num3 = (float)Math.Tanh(num / config_mag_lock_dist.Value);
							up -= magMountPos2.forward * rock_rot_d.Value;
							Vector3 position = magMountPos2.position - up * num + magMountPos2.forward * rock_ford.Value;
							__instance.Viz.position = position;
							__instance.Viz.rotation = magMountPos2.rotation;
							float num4 = (float)(Math.Atan(rock_rot_d.Value) * (180.0 / Math.PI));
							Quaternion val4 = Quaternion.Euler(0f - num4, 0f, 0f);
							Transform viz = __instance.Viz;
							viz.rotation *= val4;
						}
						else
						{
							Vector3 position2 = magMountPos2.position - up * num;
							__instance.Viz.position = position2;
							__instance.Viz.rotation = magMountPos2.rotation;
						}
						if (num < 0f - config_mag_auto_load_above.Value)
						{
							__instance.Load(val);
						}
					}
					else
					{
						__instance.Viz.position = ((Component)__instance).transform.position;
						__instance.Viz.rotation = ((Component)__instance).transform.rotation;
						((FVRInteractiveObject)__instance).SetAllCollidersToLayer(false, "Default");
						__instance.IsNonPhysForLoad = false;
					}
				}
				else
				{
					__instance.Viz.position = ((Component)__instance).transform.position;
					__instance.Viz.rotation = ((Component)__instance).transform.rotation;
					((FVRInteractiveObject)__instance).SetAllCollidersToLayer(false, "Default");
					__instance.IsNonPhysForLoad = false;
				}
			}

			private static float DistanceAlongUpAxis(Transform mag, Transform hole)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = hole.position - mag.position;
				Vector3 up = hole.up;
				return Vector3.Dot(val, up);
			}
		}

		private static ConfigEntry<bool> config_enable;

		private static ConfigEntry<bool> enable_rock_anm;

		private static ConfigEntry<float> config_mag_lock_dist;

		private static ConfigEntry<float> config_mag_auto_load_above;

		private static ConfigEntry<float> rock_rot_d;

		private static ConfigEntry<float> rock_ford;

		private static ConfigEntry<string> comma_forbids;

		private static ConfigEntry<string> rock_prefx;

		private static ConfigEntry<bool> config_enable_reload_trig;

		private static ConfigEntry<bool> test_bool_1;

		private static ConfigEntry<bool> test_bool_2;

		private static HashSet<string> forbiddenNames = new HashSet<string>
		{
			"P90_Mag(Clone)", "LaserPistol_Magazine(Clone)", "HandCrankFrank_Magazine(Clone)", "Mk19_BeltBox(Clone)", "BerthierCarbine_Magazine(Clone)", "Carcano1891_Magazine(Clone)", "M2Tombstone_BeltBox(Clone)", "KWG_Magazine(Clone)", "SustenanceCrossbow_Battery(Clone)", "Minigun_Box(Clone)",
			"S9R Derringer_Mag(Clone)", "G11_Mag(Clone)"
		};

		private static List<string> rockNames = new List<string> { "Saiga12k", "AK", "VZ61", "RPK", "SKS", "VZ58" };

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("NGA.MagAnimations");
			Logger.LogMessage((object)"New harmony");
			SetUpConfigFields();
			Logger.LogMessage((object)"Setted the fields");
			UpdateForbidden();
			UpdateRockNames();
			Logger.LogMessage((object)"Updated forbidden guns.");
			val.PatchAll();
			Logger.LogMessage((object)"Hello, world! Sent from NGA.MagAnimations 0.0.1");
		}

		private void SetUpConfigFields()
		{
			config_enable = ((BaseUnityPlugin)this).Config.Bind<bool>("Magazine", "ON/OFF", true, "Enable or disable feature.");
			config_mag_lock_dist = ((BaseUnityPlugin)this).Config.Bind<float>("Magazine", "Vertical Distance to start mag insert animation", 0.15f, "How far before mag starts insert animation in vertical dir");
			config_mag_auto_load_above = ((BaseUnityPlugin)this).Config.Bind<float>("Magazine", "Auto Load distance above entered", 0.02f, "How far above mag entry point is needed to push to auto load.");
			config_enable_reload_trig = ((BaseUnityPlugin)this).Config.Bind<bool>("Magazine", "Auto-Insert Enabled", true, "Option to disable Antons trigger zone that auto loads magazine.");
			comma_forbids = ((BaseUnityPlugin)this).Config.Bind<string>("Excluded Mags", "List to Forbid", "G11_Mag(Clone),Minigun_Box(Clone)", "Use toolbox object info tool to find name of magazine, Comma separated, add (Clone) postfix. Needs game restart.");
			enable_rock_anm = ((BaseUnityPlugin)this).Config.Bind<bool>("Rocking Animation", "ON/OFF", true, "Enable or disable AK rocking animation mag insert.");
			rock_prefx = ((BaseUnityPlugin)this).Config.Bind<string>("Rocking Animation", "Prefix of Mag Name", "Dragonuv", "Use toolbox object info tool to find prefix name of magazine, Comma separated. Needs game restart.");
			rock_ford = ((BaseUnityPlugin)this).Config.Bind<float>("Rocking Animation", "Offset-forward", 0.011f, "How far mag moves forward for rotation clipping.");
			rock_rot_d = ((BaseUnityPlugin)this).Config.Bind<float>("Rocking Animation", "Multiplier trajectory rotation", 0.2f, "How far ahead the insert trajectory starts.");
			test_bool_1 = ((BaseUnityPlugin)this).Config.Bind<bool>("Fun", "Hand stays after", false, "The your hand isn't automatically kicked off after reloading.");
			test_bool_2 = ((BaseUnityPlugin)this).Config.Bind<bool>("TEST", "BOOL2", true, "Enable or disable.");
		}

		private void UpdateForbidden()
		{
			string[] array = comma_forbids.Value.Split(new char[1] { ',' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				forbiddenNames.Add(text.Trim());
			}
			Logger.LogMessage((object)"Excluded guns for Mag Animations:");
			foreach (string forbiddenName in forbiddenNames)
			{
				Logger.LogMessage((object)forbiddenName);
			}
		}

		private void UpdateRockNames()
		{
			string[] array = rock_prefx.Value.Split(new char[1] { ',' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				rockNames.Add(text.Trim());
			}
			Logger.LogMessage((object)"Mag name prefixes with rocking animation:");
			foreach (string rockName in rockNames)
			{
				Logger.LogMessage((object)rockName);
			}
		}
	}
}