Decompiled source of FovModified v1.0.0

fovModified.dll

Decompiled 4 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
using j_red.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("j-red-lethal")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("j-red-lethal")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c9dfa95d-75b1-4796-9f58-e9aa57cedc41")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace j_red
{
	public class ModConfig
	{
		public ConfigEntry<bool> lockFOV;

		[Range(0f, 132f)]
		public ConfigEntry<float> FOV;

		public ConfigEntry<float> terminalFOV;

		public ConfigEntry<bool> disableMotionSway;

		[Range(0f, 10f)]
		public ConfigEntry<float> motionSwayIntensity;
	}
	[BepInPlugin("jred.RemoveMotionSway", "Remove Motion Sway", "1.2.3")]
	public class ModBase : BaseUnityPlugin
	{
		private const string GUID = "jred.RemoveMotionSway";

		private const string ModName = "Remove Motion Sway";

		private const string ModVersion = "1.2.3";

		private readonly Harmony harmony = new Harmony("jred.RemoveMotionSway");

		private static ModBase Instance;

		public static ModConfig config;

		internal ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				config = new ModConfig();
				config.disableMotionSway = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Disable Motion Sway", true, "If motion sway/head bobbing should be disabled.");
				config.motionSwayIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Motion Sway Intensity", 1f, "If enabled, how strong the motion sway effect will be. Range [0.0, 10.0]. Recommended max 3.0.");
				config.lockFOV = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Lock FOV", true, "Determines if the player field of view should remain locked. Disable for mod compatibility.");
				config.FOV = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Field of View", 66f, "FOV to use when locked. Has no effect if LockFOV is false.");
				config.terminalFOV = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Terminal Field of View", 66f, "FOV to use in terminal window.");
			}
			logger = Logger.CreateLogSource("jred.RemoveMotionSway");
			logger.LogInfo((object)"Remove Motion Sway v1.2.3 initialized.");
			harmony.PatchAll(typeof(ModBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace j_red.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		public static List<Transform> HUDHelmetPositions = new List<Transform>();

		public static Camera playerCam = null;

		private static Vector3 cameraRotation = new Vector3(90f, 0f, 0f);

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void CacheCameraContainer(ref PlayerControllerB __instance)
		{
			Transform transform = ((Component)__instance).transform;
			Transform val = transform.Find("ScavengerModel/metarig/CameraContainer/MainCamera/HUDHelmetPosition");
			if (Object.op_Implicit((Object)(object)val))
			{
				HUDHelmetPositions.Add(val);
			}
			playerCam = ((Component)transform.Find("ScavengerModel/metarig/CameraContainer/MainCamera")).GetComponent<Camera>();
		}

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		private static void LateUpdatePatch(ref PlayerControllerB __instance)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_005d: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			HUDHelmetPositions.Clear();
			CacheCameraContainer(ref __instance);
			if (!__instance.inTerminalMenu)
			{
				if (ModBase.config.disableMotionSway.Value)
				{
					__instance.cameraContainerTransform.position = new Vector3(__instance.cameraContainerTransform.position.x, ((Component)__instance.playerModelArmsMetarig).transform.position.y, __instance.cameraContainerTransform.position.z);
				}
				else
				{
					float num = __instance.cameraContainerTransform.position.y - ((Component)__instance.playerModelArmsMetarig).transform.position.y;
					__instance.cameraContainerTransform.position = new Vector3(__instance.cameraContainerTransform.position.x, ((Component)__instance.playerModelArmsMetarig).transform.position.y + num * ModBase.config.motionSwayIntensity.Value, __instance.cameraContainerTransform.position.z);
				}
				__instance.cameraContainerTransform.localRotation = Quaternion.Euler(cameraRotation);
				if (ModBase.config.lockFOV.Value && Object.op_Implicit((Object)(object)playerCam))
				{
					playerCam.fieldOfView = ModBase.config.FOV.Value;
				}
				{
					foreach (Transform hUDHelmetPosition in HUDHelmetPositions)
					{
						try
						{
							hUDHelmetPosition.position = ((Component)__instance).transform.position - ((Component)__instance).transform.forward * 100f;
						}
						catch
						{
							Debug.LogWarning((object)"Failed to update position for helmet");
						}
					}
					return;
				}
			}
			try
			{
				if (ModBase.config.lockFOV.Value && Object.op_Implicit((Object)(object)playerCam))
				{
					playerCam.fieldOfView = ModBase.config.terminalFOV.Value;
				}
			}
			catch
			{
			}
		}
	}
}