Decompiled source of CamFreeModifiyer v1.0.4

CamFreeModifiyer.dll

Decompiled 4 days 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 RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("jpriebe")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Risk of Rain 2 Camera Modifier - Customizable camera settings")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+885c4606aba4d40417c9c1e0472f497f0995d5c5")]
[assembly: AssemblyProduct("CamFreeModifiyer")]
[assembly: AssemblyTitle("CamFreeModifiyer")]
[assembly: AssemblyVersion("1.0.4.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 CamFreeModifiyer
{
	[HarmonyPatch]
	public static class CameraPatches
	{
		private static Vector3 lastAppliedPositionOffset = Vector3.zero;

		private static Vector3 lastAppliedEulerOffset = Vector3.zero;

		private static bool offsetsApplied = false;

		[HarmonyPatch(typeof(CameraRigController), "SetCameraState")]
		[HarmonyPrefix]
		public static void CameraRigController_SetCameraState_Prefix(CameraRigController __instance)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0051: 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)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.sceneCam == (Object)null))
			{
				__instance.baseFov = Plugin.FieldOfView.Value;
				if (offsetsApplied)
				{
					Transform transform = ((Component)__instance.sceneCam).transform;
					transform.position -= lastAppliedPositionOffset;
					Vector3 eulerAngles = transform.eulerAngles;
					eulerAngles.x -= lastAppliedEulerOffset.x;
					transform.eulerAngles = eulerAngles;
					offsetsApplied = false;
				}
			}
		}

		[HarmonyPatch(typeof(CameraRigController), "SetCameraState")]
		[HarmonyPostfix]
		public static void CameraRigController_SetCameraState_Postfix(CameraRigController __instance)
		{
			//IL_0067: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.sceneCam == (Object)null))
			{
				Camera sceneCam = __instance.sceneCam;
				Transform transform = ((Component)sceneCam).transform;
				sceneCam.fieldOfView = Plugin.FieldOfView.Value;
				float num = Plugin.CameraDistance.Value - 10f;
				float value = Plugin.CameraHeight.Value;
				float value2 = Plugin.CameraHorizontal.Value;
				float value3 = Plugin.CameraPitch.Value;
				lastAppliedPositionOffset = Vector3.zero;
				lastAppliedEulerOffset = Vector3.zero;
				if (Mathf.Abs(num) > 0.001f)
				{
					Vector3 val = -transform.forward * num;
					transform.position += val;
					lastAppliedPositionOffset += val;
				}
				if (Mathf.Abs(value) > 0.001f)
				{
					Vector3 val2 = default(Vector3);
					((Vector3)(ref val2))..ctor(0f, value, 0f);
					transform.position += val2;
					lastAppliedPositionOffset += val2;
				}
				if (Mathf.Abs(value2) > 0.001f)
				{
					Vector3 val3 = transform.right * value2;
					transform.position += val3;
					lastAppliedPositionOffset += val3;
				}
				if (Mathf.Abs(value3) > 0.001f)
				{
					Vector3 eulerAngles = transform.eulerAngles;
					eulerAngles.x += value3;
					transform.eulerAngles = eulerAngles;
					lastAppliedEulerOffset.x = value3;
				}
				offsetsApplied = true;
			}
		}
	}
	[BepInPlugin("com.jpriebe.camfreemodifiyer", "CamFreeModifiyer", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.jpriebe.camfreemodifiyer";

		public const string PluginName = "CamFreeModifiyer";

		public const string PluginVersion = "1.0.4";

		public static ConfigEntry<float> FieldOfView;

		public static ConfigEntry<float> CameraDistance;

		public static ConfigEntry<float> CameraPitch;

		public static ConfigEntry<float> CameraHeight;

		public static ConfigEntry<float> CameraHorizontal;

		public static ConfigEntry<KeyCode> ToggleMenuKey;

		private bool showUI;

		private Rect windowRect = new Rect(20f, 20f, 300f, 320f);

		private Harmony harmony;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			Instance = this;
			InitializeConfig();
			harmony = new Harmony("com.jpriebe.camfreemodifiyer");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CamFreeModifiyer v1.0.4 loaded!");
		}

		private void InitializeConfig()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			FieldOfView = ((BaseUnityPlugin)this).Config.Bind<float>("Camera Settings", "Field of View", 60f, new ConfigDescription("Camera field of view in degrees", (AcceptableValueBase)(object)new AcceptableValueRange<float>(30f, 120f), Array.Empty<object>()));
			CameraDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Camera Settings", "Camera Distance", 10f, new ConfigDescription("Distance of the camera from the player", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 30f), Array.Empty<object>()));
			CameraPitch = ((BaseUnityPlugin)this).Config.Bind<float>("Camera Settings", "Camera Pitch", 0f, new ConfigDescription("Vertical angle/tilt of the camera in degrees", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-45f, 45f), Array.Empty<object>()));
			CameraHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Camera Settings", "Camera Height", 0f, new ConfigDescription("Height offset of the camera", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-5f, 10f), Array.Empty<object>()));
			CameraHorizontal = ((BaseUnityPlugin)this).Config.Bind<float>("Camera Settings", "Camera Horizontal", 0f, new ConfigDescription("Horizontal offset of the camera (negative = left, positive = right)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-10f, 10f), Array.Empty<object>()));
			ToggleMenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Toggle Menu Key", (KeyCode)286, "Key to toggle the in-game camera settings menu");
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(ToggleMenuKey.Value))
			{
				showUI = !showUI;
			}
		}

		private void OnGUI()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (showUI)
			{
				windowRect = GUI.Window(0, windowRect, new WindowFunction(DrawSettingsWindow), "CamFreeModifiyer Settings");
			}
		}

		private void DrawSettingsWindow(int windowId)
		{
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"Field of View: {FieldOfView.Value:F1}°", Array.Empty<GUILayoutOption>());
			FieldOfView.Value = GUILayout.HorizontalSlider(FieldOfView.Value, 30f, 120f, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"Camera Distance: {CameraDistance.Value:F1}", Array.Empty<GUILayoutOption>());
			CameraDistance.Value = GUILayout.HorizontalSlider(CameraDistance.Value, 5f, 30f, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"Camera Pitch: {CameraPitch.Value:F1}°", Array.Empty<GUILayoutOption>());
			CameraPitch.Value = GUILayout.HorizontalSlider(CameraPitch.Value, -45f, 45f, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"Camera Height: {CameraHeight.Value:F1}", Array.Empty<GUILayoutOption>());
			CameraHeight.Value = GUILayout.HorizontalSlider(CameraHeight.Value, -5f, 10f, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"Camera Horizontal: {CameraHorizontal.Value:F1}", Array.Empty<GUILayoutOption>());
			CameraHorizontal.Value = GUILayout.HorizontalSlider(CameraHorizontal.Value, -10f, 10f, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			if (GUILayout.Button("Reset to Defaults", Array.Empty<GUILayoutOption>()))
			{
				FieldOfView.Value = (float)((ConfigEntryBase)FieldOfView).DefaultValue;
				CameraDistance.Value = (float)((ConfigEntryBase)CameraDistance).DefaultValue;
				CameraPitch.Value = (float)((ConfigEntryBase)CameraPitch).DefaultValue;
				CameraHeight.Value = (float)((ConfigEntryBase)CameraHeight).DefaultValue;
				CameraHorizontal.Value = (float)((ConfigEntryBase)CameraHorizontal).DefaultValue;
			}
			GUILayout.Space(5f);
			if (GUILayout.Button("Close", Array.Empty<GUILayoutOption>()))
			{
				showUI = false;
			}
			GUILayout.EndVertical();
			GUI.DragWindow();
		}

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