Decompiled source of ingame camera height v1.1.0

CameraHeight.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Nessie.ATLYSS.EasySettings;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[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("CameraHeight")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("ingame camera height")]
[assembly: AssemblyTitle("CameraHeight")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 sirlan.atlyss.cameraHeight
{
	[BepInPlugin("CameraHeight", "ingame camera height", "1.1.0")]
	[BepInProcess("ATLYSS.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CameraHeight : BaseUnityPlugin
	{
		private enum WhichSlider
		{
			cameraVert,
			cameraHorz
		}

		internal static CameraHeight instance;

		internal static ManualLogSource Logger;

		internal static ConfigEntry<KeyCode> whichKey;

		public static bool CameraControl;

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			whichKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("general", "whichKey", (KeyCode)308, "which key you hold to change height when scrolling");
			if (Chainloader.PluginInfos.ContainsKey("EasySettings"))
			{
				EasySettingsCompat.Setup();
			}
			new Harmony("CameraHeight").PatchAll();
		}

		private void Update()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_002f: 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)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player._mainPlayer == (Object)null || (int)Player._mainPlayer._currentGameCondition != 1 || (Object)(object)CameraFunction._current == (Object)null)
			{
				return;
			}
			if (Input.GetKey(whichKey.Value) && !CameraFunction._current._unlockedCamera)
			{
				bool key = Input.GetKey((KeyCode)304);
				if (Input.GetMouseButtonDown(2))
				{
					ResetPositions(key);
					return;
				}
				CameraControl = true;
				Vector3 dollyDir = ((Component)CameraFunction._current._mainCamera).GetComponent<CameraCollision>().dollyDir;
				float num = dollyDir.y;
				float num2 = dollyDir.x;
				float num3 = 0.025f;
				if (Input.mouseScrollDelta.y > 0f)
				{
					num += num3;
					num2 -= num3;
				}
				else if (Input.mouseScrollDelta.y < 0f)
				{
					num -= num3;
					num2 += num3;
				}
				if (!key)
				{
					SetSlider(WhichSlider.cameraVert, num);
				}
				else
				{
					SetSlider(WhichSlider.cameraHorz, num2);
				}
			}
			else
			{
				CameraControl = false;
			}
		}

		private void ResetPositions(bool modPressed)
		{
			SettingsProfile settingsProfile = SettingsManager._current._settingsProfile;
			if (!modPressed)
			{
				SetSlider(WhichSlider.cameraVert, settingsProfile._cameraVert);
			}
			else
			{
				SetSlider(WhichSlider.cameraHorz, settingsProfile._cameraHoriz);
			}
		}

		private void SetSlider(WhichSlider whichSlider, float to)
		{
			SettingsManager current = SettingsManager._current;
			if ((Object)(object)current != (Object)null)
			{
				FieldInfo field;
				switch (whichSlider)
				{
				case WhichSlider.cameraVert:
					field = typeof(SettingsManager).GetField("_cameraVertPosSlider", BindingFlags.Instance | BindingFlags.NonPublic);
					break;
				case WhichSlider.cameraHorz:
					field = typeof(SettingsManager).GetField("_cameraHorizPosSlider", BindingFlags.Instance | BindingFlags.NonPublic);
					break;
				default:
					Logger.LogError((object)$"Unknown WhichSlider {whichSlider}");
					return;
				}
				if (field == null)
				{
					Logger.LogError((object)"SettingsManager._cameraVertPosSlider or SettingsManager._cameraHorzPosSlider not found!");
					return;
				}
				object value = field.GetValue(current);
				if (value == null)
				{
					Logger.LogError((object)"SettingsManager._cameraVertPosSlider or SettingsManager._cameraHorzPosSlider is null!");
					return;
				}
				Slider val = (Slider)((value is Slider) ? value : null);
				if (val != null)
				{
					val.value = to;
					return;
				}
				GameObject val2 = (GameObject)((value is GameObject) ? value : null);
				Slider val3 = default(Slider);
				if (val2 != null && val2.TryGetComponent<Slider>(ref val3))
				{
					val3.value = to;
					return;
				}
				Logger.LogError((object)"failed to cast SettingsManager._cameraVertPosSlider or SettingsManager._cameraHorzPosSlider to a valid Slider type!");
				Logger.LogError((object)"(the UnityEngine.UI library this mod was compiled against might be different than the one in the game)");
			}
			else
			{
				Logger.LogError((object)"SettingsManager is null!");
			}
		}
	}
	[HarmonyPatch]
	public class PatchCameraControl
	{
		private static MethodInfo TargetMethod()
		{
			return AccessTools.GetDeclaredMethods(typeof(CameraCollision)).First((MethodInfo m) => m.Name.Contains("Handle_DistanceControl"));
		}

		private static bool Prefix()
		{
			if (CameraHeight.CameraControl)
			{
				return false;
			}
			return true;
		}
	}
	public class EasySettingsCompat
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__SettingsSetup;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__0_0;

			internal void <Setup>b__0_0()
			{
				((BaseUnityPlugin)CameraHeight.instance).Config.Save();
			}
		}

		public static void Setup()
		{
			//IL_0015: 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_0020: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			UnityEvent onInitialized = Settings.OnInitialized;
			object obj = <>O.<0>__SettingsSetup;
			if (obj == null)
			{
				UnityAction val = SettingsSetup;
				<>O.<0>__SettingsSetup = val;
				obj = (object)val;
			}
			onInitialized.AddListener((UnityAction)obj);
			UnityEvent onApplySettings = Settings.OnApplySettings;
			object obj2 = <>c.<>9__0_0;
			if (obj2 == null)
			{
				UnityAction val2 = delegate
				{
					((BaseUnityPlugin)CameraHeight.instance).Config.Save();
				};
				<>c.<>9__0_0 = val2;
				obj2 = (object)val2;
			}
			onApplySettings.AddListener((UnityAction)obj2);
		}

		private static void SettingsSetup()
		{
			SettingsTab modTab = Settings.ModTab;
			modTab.AddHeader("ingame camera height");
			modTab.AddKeyButton("which key", CameraHeight.whichKey);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CameraHeight";

		public const string PLUGIN_NAME = "ingame camera height";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}