Decompiled source of SVDFixed v1.0.0

SVD_Dragunov.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using ModularWorkshop;
using OpenScripts2;
using OtherLoader;
using Sodalite.Api;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class BipodAThon : MonoBehaviour
{
	private void Start()
	{
	}

	private void Update()
	{
	}
}
namespace NotWolfie.Maxwell
{
	public class GameObjectToggleOnInteract : FVRInteractiveObject
	{
		[Header("GameObjectToggleOnInteract Config")]
		public GameObject ToggleGameObject;

		public GameObject InvertedToggleGameObject;

		public GameObject InvertedToggleGameObject2;

		public GameObject InvertedToggleGameObject3;

		private bool _isToggled = false;

		public override void SimpleInteraction(FVRViveHand hand)
		{
			((FVRInteractiveObject)this).SimpleInteraction(hand);
			_isToggled = !_isToggled;
			ToggleGameObject.SetActive(_isToggled);
			InvertedToggleGameObject.SetActive(!_isToggled);
			InvertedToggleGameObject2.SetActive(!_isToggled);
			InvertedToggleGameObject3.SetActive(!_isToggled);
		}
	}
}
namespace NotWolfie.SVD_Dragunov
{
	[BepInDependency("h3vr.cityrobo.ModularWorkshopManager", "1.0.0")]
	[BepInDependency("nrgill28.Sodalite", "1.4.2")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	[BepInPlugin("NotWolfie.SVD_Dragunov", "SVD_Dragunov", "1.3.1")]
	public class SVD_DragunovPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"SVD_Dragunov: Plugin Awake - Systems Initialized.");
			LoadAssets();
		}

		private void LoadAssets()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "NotWolfie.SVD_Dragunov");
			OtherLoader.RegisterDirectLoad(BasePath, "NotWolfie.SVD_Dragunov", "", "", "svd", "");
			GameAPI.PreloadAllAssets(Path.Combine(BasePath, "mw_svd_dragunov"));
		}
	}
	[HarmonyPatch(typeof(UnityEngineExtensions), "GoToTransformProxy", new Type[]
	{
		typeof(Transform),
		typeof(TransformProxy)
	})]
	public static class NullFixPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(object __1)
		{
			if (__1 == null || (Object)((__1 is Object) ? __1 : null) == (Object)null)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(FVRInteractiveObject), "Start")]
	public static class SVDInjectionPatch
	{
		[HarmonyPostfix]
		public static void Postfix(FVRInteractiveObject __instance)
		{
			FVRFireArm val = (FVRFireArm)(object)((__instance is FVRFireArm) ? __instance : null);
			if ((Object)(object)val != (Object)null && (Object)(object)((FVRPhysicalObject)val).ObjectWrapper != (Object)null && ((FVRPhysicalObject)val).ObjectWrapper.ItemID.ToUpper().Trim() == "NWSVD" && (Object)(object)((Component)val).GetComponent<SVDRuntimeFixer>() == (Object)null)
			{
				((Component)val).gameObject.AddComponent<SVDRuntimeFixer>();
			}
		}
	}
	public class SVDRuntimeFixer : MonoBehaviour
	{
		private FVRFireArm _fa;

		private Vector3 _origMuzzleLocPos;

		private int _lastConfigHash = -1;

		private float _cachedMuzzleZ = 0f;

		private Transform _cachedMuzzleAnchor = null;

		private List<Transform> _cachedSmokeObjects = new List<Transform>();

		private float _checkTimer = 0f;

		private void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			_fa = ((Component)this).GetComponent<FVRFireArm>();
			if ((Object)(object)_fa != (Object)null)
			{
				_origMuzzleLocPos = _fa.MuzzlePos.localPosition;
			}
		}

		private void Update()
		{
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0625: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0872: Unknown result type (might be due to invalid IL or missing references)
			//IL_087f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0764: Unknown result type (might be due to invalid IL or missing references)
			//IL_0776: Unknown result type (might be due to invalid IL or missing references)
			//IL_0788: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_fa == (Object)null)
			{
				return;
			}
			_checkTimer += Time.deltaTime;
			if (_checkTimer < 0.12f)
			{
				return;
			}
			_checkTimer = 0f;
			ModularBarrel componentInChildren = ((Component)_fa).GetComponentInChildren<ModularBarrel>(true);
			ModularBarrelExtension componentInChildren2 = ((Component)_fa).GetComponentInChildren<ModularBarrelExtension>(true);
			int num = (((Object)(object)componentInChildren != (Object)null) ? ((Object)((Component)componentInChildren).gameObject).GetInstanceID() : 0) ^ (((Object)(object)componentInChildren2 != (Object)null) ? ((Object)((Component)componentInChildren2).gameObject).GetInstanceID() : 0);
			Transform[] componentsInChildren2;
			if (_lastConfigHash != num)
			{
				_lastConfigHash = num;
				SVD_DragunovPlugin.Logger.LogInfo((object)("SVD Fixer: Configuration shift (" + num + "). Re-measuring..."));
				float num2 = -100f;
				List<Transform> list = new List<Transform>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					list.Add(((Component)componentInChildren).transform);
				}
				if ((Object)(object)componentInChildren2 != (Object)null)
				{
					list.Add(((Component)componentInChildren2).transform);
				}
				foreach (Transform item in list)
				{
					Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val in componentsInChildren)
					{
						if (!(val is MeshRenderer) && !(val is SkinnedMeshRenderer))
						{
							continue;
						}
						Bounds bounds = val.bounds;
						Vector3 center = ((Bounds)(ref bounds)).center;
						bounds = val.bounds;
						Vector3 extents = ((Bounds)(ref bounds)).extents;
						for (int j = -1; j <= 1; j += 2)
						{
							for (int k = -1; k <= 1; k += 2)
							{
								for (int l = -1; l <= 1; l += 2)
								{
									Vector3 val2 = center + new Vector3(extents.x * (float)j, extents.y * (float)k, extents.z * (float)l);
									float z = ((Component)_fa).transform.InverseTransformPoint(val2).z;
									if (z > num2)
									{
										num2 = z;
									}
								}
							}
						}
					}
				}
				Transform val3 = null;
				string[] array = new string[4] { "fxpoint", "muzzle", "muz", "point" };
				float num3 = -100f;
				foreach (Transform item2 in list)
				{
					componentsInChildren2 = ((Component)item2).GetComponentsInChildren<Transform>(true);
					foreach (Transform val4 in componentsInChildren2)
					{
						string text = ((Object)val4).name.ToLower();
						if (text.Contains("smoke") || text.Contains("flash") || text.Contains("mount"))
						{
							continue;
						}
						bool flag = false;
						string[] array2 = array;
						foreach (string value in array2)
						{
							if (text.Contains(value))
							{
								flag = true;
								break;
							}
						}
						if (flag)
						{
							float z2 = ((Component)_fa).transform.InverseTransformPoint(val4.position).z;
							if (z2 > num3)
							{
								num3 = z2;
								val3 = val4;
							}
						}
					}
				}
				float num4 = num2 + 0.005f;
				if ((Object)(object)val3 != (Object)null)
				{
					float z3 = ((Component)_fa).transform.InverseTransformPoint(val3.position).z;
					if (num2 - z3 < 0.03f)
					{
						num4 = z3;
					}
				}
				_cachedMuzzleZ = ((num2 > -50f) ? num4 : _origMuzzleLocPos.z);
				_cachedMuzzleAnchor = val3;
				_cachedSmokeObjects.Clear();
				componentsInChildren2 = ((Component)_fa).GetComponentsInChildren<Transform>(true);
				foreach (Transform val4 in componentsInChildren2)
				{
					if (((Object)val4).name.ToLower().Contains("smoke"))
					{
						_cachedSmokeObjects.Add(val4);
					}
				}
				if ((Object)(object)_cachedMuzzleAnchor != (Object)null && num2 > -50f)
				{
					_cachedMuzzleAnchor.position = ((Component)_fa).transform.TransformPoint(new Vector3(0f, 0f, num4));
				}
				SVD_DragunovPlugin.Logger.LogInfo((object)("SVD Fixer: Alignment locked at Z:" + _cachedMuzzleZ));
			}
			Vector3 position = ((Component)_fa).transform.TransformPoint(new Vector3(0f, 0f, _cachedMuzzleZ));
			_fa.MuzzlePos.position = position;
			if ((Object)(object)_cachedMuzzleAnchor != (Object)null)
			{
				_fa.MuzzlePos.rotation = _cachedMuzzleAnchor.rotation;
				_cachedMuzzleAnchor.position = position;
			}
			else
			{
				_fa.MuzzlePos.rotation = ((Component)_fa).transform.rotation;
			}
			foreach (Transform cachedSmokeObject in _cachedSmokeObjects)
			{
				if ((Object)(object)cachedSmokeObject != (Object)null)
				{
					cachedSmokeObject.position = position;
					cachedSmokeObject.rotation = _fa.MuzzlePos.rotation;
				}
			}
			ModularHandguard componentInChildren3 = ((Component)_fa).GetComponentInChildren<ModularHandguard>(true);
			if (!((Object)(object)componentInChildren3 != (Object)null))
			{
				return;
			}
			Transform val5 = null;
			componentsInChildren2 = ((Component)_fa).GetComponentsInChildren<Transform>(true);
			foreach (Transform val4 in componentsInChildren2)
			{
				if (((Object)val4).name == "Handguard_Grip")
				{
					val5 = val4;
					break;
				}
			}
			if ((Object)(object)val5 == (Object)null)
			{
				Transform val6 = ((Component)_fa).transform.Find("_Trigger_Foregrip");
				if ((Object)(object)val6 != (Object)null)
				{
					GameObject val7 = Object.Instantiate<GameObject>(((Component)val6).gameObject);
					((Object)val7).name = "Handguard_Grip";
					val7.transform.SetParent(((Component)componentInChildren3).transform);
					val7.transform.localPosition = new Vector3(0f, 0.05f, 0.15f);
					val7.transform.localRotation = Quaternion.identity;
					val7.transform.localScale = Vector3.one;
					FVRAlternateGrip component = val7.GetComponent<FVRAlternateGrip>();
					if ((Object)(object)component != (Object)null)
					{
						component.PrimaryObject = (FVRPhysicalObject)(object)_fa;
					}
					Collider[] components = val7.GetComponents<Collider>();
					foreach (Collider val8 in components)
					{
						Object.Destroy((Object)(object)val8);
					}
					CapsuleCollider val9 = val7.AddComponent<CapsuleCollider>();
					((Collider)val9).isTrigger = true;
					val9.radius = 0.05f;
					val9.height = 0.45f;
					val9.direction = 2;
					SVD_DragunovPlugin.Logger.LogWarning((object)"SVD Fixer: Interaction Grip Injected.");
				}
			}
			else if ((Object)(object)val5.parent != (Object)(object)((Component)componentInChildren3).transform)
			{
				val5.SetParent(((Component)componentInChildren3).transform);
				val5.localPosition = new Vector3(0f, 0.05f, 0.15f);
				val5.localScale = Vector3.one;
			}
		}
	}
}