Decompiled source of ThirdLaw v0.0.4

NGA.ThirdLaw.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
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.ThirdLaw")]
[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.ThirdLaw", "ThirdLaw", "0.1.0")]
	[BepInDependency("nrgill28.Sodalite", "1.4.1")]
	[BepInProcess("h3vr.exe")]
	public class ThirdLaw : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(FVRFireArm))]
		[HarmonyPatch("LoadMag")]
		private class FVRFireArmLoadMagHook
		{
			private static void Postfix(FVRFireArm __instance, FVRFireArmMagazine mag)
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: 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_007d: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_mag_stuff.Value)
				{
					Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_force_mag_insert.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.up) * value;
						component.AddForce(val, (ForceMode)0);
						float value2 = config_torque_mag_insert.Value;
						Vector3 val2 = ((Component)__instance).transform.TransformDirection(Vector3.forward) * value2;
						component.AddTorque(val2, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody insert.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(FVRFireArm))]
		[HarmonyPatch("EjectMag")]
		private class FVRFireArmEjectMagHook
		{
			private static void Postfix(FVRFireArm __instance, bool PhysicalRelease = false)
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: 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_007d: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_mag_stuff.Value)
				{
					Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_force_mag_eject.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.up) * value;
						component.AddForce(val, (ForceMode)0);
						float value2 = config_torque_mag_eject.Value;
						Vector3 val2 = ((Component)__instance).transform.TransformDirection(Vector3.forward) * value2;
						component.AddTorque(val2, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody eject.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(HandgunSlide))]
		[HarmonyPatch("SlideEvent_ArriveAtFore")]
		private class HandgunSlideSlideEvent_ArriveAtForeHook
		{
			private static void Postfix(HandgunSlide __instance)
			{
				//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: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_pistol_slide_stuff.Value)
				{
					Rigidbody component = ((Component)((Component)__instance.Handgun).transform).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_pistol_torque_slide_fore.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.right) * value;
						component.AddTorque(val, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody handgun slide fore.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(HandgunSlide))]
		[HarmonyPatch("SlideEvent_SmackRear")]
		private class HandgunSlideSlideEvent_SmackRearHook
		{
			private static void Postfix(HandgunSlide __instance)
			{
				//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_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_pistol_slide_stuff.Value)
				{
					Rigidbody component = ((Component)((Component)__instance.Handgun).transform).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_pistol_torque_slide_rear.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.right) * (0f - value);
						component.AddTorque(val, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody handgun slide rear.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(ClosedBoltHandle))]
		[HarmonyPatch("Event_ArriveAtFore")]
		private class ClosedBoltEvent_ArriveAtForeHook
		{
			private static void Postfix(ClosedBoltHandle __instance)
			{
				//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: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_big_slide_stuff.Value)
				{
					Rigidbody component = ((Component)((Component)__instance.Weapon).transform).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_big_torque_slide_fore.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.right) * value;
						component.AddTorque(val, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody handgun slide fore.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(ClosedBoltHandle))]
		[HarmonyPatch("Event_HitLockPosition")]
		private class ClosedBoltEvent_HitLockPositionHook
		{
			private static void Postfix(ClosedBoltHandle __instance)
			{
				//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: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_big_slide_stuff.Value)
				{
					Rigidbody component = ((Component)((Component)__instance.Weapon).transform).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_big_torque_slide_fore.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.right) * value;
						component.AddTorque(val, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody handgun slide fore.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(ClosedBoltHandle))]
		[HarmonyPatch("Event_SmackRear")]
		private class ClosedBoltHandleEvent_SmackRearHook
		{
			private static void Postfix(ClosedBoltHandle __instance)
			{
				//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_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_big_slide_stuff.Value)
				{
					Rigidbody component = ((Component)((Component)__instance.Weapon).transform).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_big_torque_slide_rear.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.right) * (0f - value);
						component.AddTorque(val, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody handgun slide rear.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(ClosedBolt))]
		[HarmonyPatch("BoltEvent_ArriveAtFore")]
		private class ClosedBoltBoltEvent_ArriveAtFore
		{
			private static void Postfix(ClosedBolt __instance)
			{
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_big_slide_stuff.Value && !(__instance.Weapon.m_timeSinceFiredShot < 0.1f))
				{
					Rigidbody component = ((Component)((Component)__instance.Weapon).transform).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_big_torque_slide_fore.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.right) * value;
						component.AddTorque(val, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody handgun slide fore.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(ClosedBolt))]
		[HarmonyPatch("BoltEvent_BoltCaught")]
		private class ClosedBoltBoltEvent_BoltCaught
		{
			private static void Postfix(ClosedBolt __instance)
			{
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_big_slide_stuff.Value && !(__instance.Weapon.m_timeSinceFiredShot < 0.1f))
				{
					Rigidbody component = ((Component)((Component)__instance.Weapon).transform).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_big_torque_slide_fore.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.right) * value;
						component.AddTorque(val, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody handgun slide fore.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(ClosedBolt))]
		[HarmonyPatch("BoltEvent_SmackRear")]
		private class ClosedBoltBoltEvent_SmackRear
		{
			private static void Postfix(ClosedBolt __instance)
			{
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				if (config_enable_big_slide_stuff.Value && !(__instance.Weapon.m_timeSinceFiredShot < 0.1f))
				{
					Rigidbody component = ((Component)((Component)__instance.Weapon).transform).GetComponent<Rigidbody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						float value = config_big_torque_slide_rear.Value;
						Vector3 val = ((Component)__instance).transform.TransformDirection(Vector3.right) * (0f - value);
						component.AddTorque(val, (ForceMode)0);
					}
					else
					{
						Logger.LogMessage((object)"No parent rigidbody handgun slide rear.");
					}
				}
			}
		}

		private static ConfigEntry<bool> config_enable_mag_stuff;

		private static ConfigEntry<bool> config_enable_pistol_slide_stuff;

		private static ConfigEntry<bool> config_enable_big_slide_stuff;

		private static ConfigEntry<float> config_force_mag_insert;

		private static ConfigEntry<float> config_torque_mag_insert;

		private static ConfigEntry<float> config_force_mag_eject;

		private static ConfigEntry<float> config_torque_mag_eject;

		private static ConfigEntry<float> config_pistol_torque_slide_fore;

		private static ConfigEntry<float> config_pistol_torque_slide_rear;

		private static ConfigEntry<float> config_big_torque_slide_fore;

		private static ConfigEntry<float> config_big_torque_slide_rear;

		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.ThirdLaw");
			Logger.LogMessage((object)"New harmony");
			SetUpConfigFields();
			Logger.LogMessage((object)"Setted the fields");
			val.PatchAll();
			Logger.LogMessage((object)"Hello, world! Sent from NGA.ThirdLaw 0.0.1");
		}

		private void SetUpConfigFields()
		{
			config_enable_mag_stuff = ((BaseUnityPlugin)this).Config.Bind<bool>("Overall", "Enable Magazine Reactions", true, "Whether mag insertion/release causes gun movements.");
			config_enable_pistol_slide_stuff = ((BaseUnityPlugin)this).Config.Bind<bool>("Overall", "Enable Pistol Slide Reactions", true, "Whether pistol slide manipulation causes gun movements.");
			config_enable_big_slide_stuff = ((BaseUnityPlugin)this).Config.Bind<bool>("Overall", "Enable Rifles+ Reactions", true, "Whether bolt handle manipulation causes gun movements.");
			config_force_mag_insert = ((BaseUnityPlugin)this).Config.Bind<float>("Magazine", "Force Mag Insert Up", 10f, "How strong an upward force is put on mag INSERT.");
			config_torque_mag_insert = ((BaseUnityPlugin)this).Config.Bind<float>("Magazine", "Force Mag Insert Torque", 1f, "How strong an forward-axis rotation force is put on mag INSERT.");
			config_force_mag_eject = ((BaseUnityPlugin)this).Config.Bind<float>("Magazine", "Force Mag Eject Up", 10f, "How strong an upward force is put on mag EJECT.");
			config_torque_mag_eject = ((BaseUnityPlugin)this).Config.Bind<float>("Magazine", "Torque Mag Eject Sideways", 2.5f, "How strong an forward-axis rotation force is put on mag EJECT.");
			config_pistol_torque_slide_fore = ((BaseUnityPlugin)this).Config.Bind<float>("Handles", "Pistol Torque Slide Reach Fore", 1f, "How strong an trigger-axis rotation force when slide reaches fore.");
			config_pistol_torque_slide_rear = ((BaseUnityPlugin)this).Config.Bind<float>("Handles", "Pistol Torque Slide Reach Back", 1f, "How strong an trigger-axis rotation force when slide reaches rear.");
			config_big_torque_slide_fore = ((BaseUnityPlugin)this).Config.Bind<float>("Handles", "Rifles+ Torque Bolt Reach Fore", 20f, "How strong an trigger-axis rotation force when bolt handle reaches fore.");
			config_big_torque_slide_rear = ((BaseUnityPlugin)this).Config.Bind<float>("Handles", "Rifles+ Torque Bolt Reach Back", 10f, "How strong an trigger-axis rotation force when bolt handle reaches rear.");
		}
	}
}