Decompiled source of BetterCamera v1.0.6

BetterCamera.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BetterCamera;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.UI;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "BetterCamera", "1.0.6", "sav", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BetterCamera")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterCamera")]
[assembly: AssemblyTitle("BetterCamera")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 BetterCamera
{
	public class Core : MelonMod
	{
		private Transform CameraTransform;

		private static PlayerCamera PlayerCam;

		private float zRotation;

		private float xRotation;

		private float SmoothTime = 0.1f;

		private float zVelocity;

		private float xVelocity;

		private float TargetZRotation;

		private float TargetXRotation;

		private float MouseTiltSpeed = 0.02f;

		private float WalkTiltSpeed = 3f;

		private bool InitializedNeededObjects;

		private static bool CameraOverride;

		private GameObject Crosshair;

		private bool InMainGame;

		private static bool HasPlayerSpawned;

		private static float SmoothLookAmount;

		private static int CurrentSmoothingSetting;

		private bool ShowKeybinds = true;

		private Rect KeyBindBox = new Rect(1550f, 475f, 300f, 155f);

		private bool InConsole;

		private static ConsoleUI CUI;

		private static Sprite CameraLogo;

		private bool IsZooming;

		private float ZoomAmount = 25f;

		private MelonPreferences_Category ConfigCategory;

		private static MelonPreferences_Entry<int> SmoothingSetting;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("sav's Better Camera mod loaded successfully!!");
			ConfigCategory = MelonPreferences.CreateCategory("BetterCamera");
			SmoothingSetting = ConfigCategory.CreateEntry<int>("Smoothing", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			CurrentSmoothingSetting = SmoothingSetting.Value;
			((MelonBase)this).HarmonyInstance.PatchAll();
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Main")
			{
				InMainGame = true;
				MelonCoroutines.Start(WaitForPlayer());
				return;
			}
			InMainGame = false;
			CameraOverride = false;
			HasPlayerSpawned = false;
			InitializedNeededObjects = false;
		}

		private static IEnumerator WaitForPlayer()
		{
			while ((Object)(object)Player.Local == (Object)null || (Object)(object)((Component)Player.Local).gameObject == (Object)null)
			{
				yield return null;
			}
			if (!HasPlayerSpawned)
			{
				MelonCoroutines.Start(OnPlayerSpawned());
			}
		}

		public static IEnumerator OnPlayerSpawned()
		{
			yield return (object)new WaitForSeconds(1f);
			HasPlayerSpawned = true;
			CameraOverride = true;
			PlayerCam = PlayerSingleton<PlayerCamera>.instance;
			PlayerCam.SmoothLook = true;
			if ((Object)(object)PlayerCam != (Object)null)
			{
				PlayerCam.SmoothLookSpeed = SmoothLookAmount;
			}
			CUI = Object.FindObjectOfType<ConsoleUI>();
			ChangeSmoothness();
			LoadCameraLogo();
		}

		private static void LoadCameraLogo()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string name = "BetterCamera.Resources.BetterCamIcon.png";
			using Stream stream = executingAssembly.GetManifestResourceStream(name);
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array));
			((Texture)val).filterMode = (FilterMode)0;
			CameraLogo = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		private static void ChangeSmoothness()
		{
			SmoothingSetting.Value = CurrentSmoothingSetting;
			MelonPreferences.Save();
			Sprite cameraLogo = CameraLogo;
			switch (CurrentSmoothingSetting)
			{
			case 0:
				SmoothLookAmount = 4f;
				PlayerCam.SmoothLookSpeed = SmoothLookAmount;
				Singleton<NotificationsManager>.instance.SendNotification("BetterCamera", "Smoothness: <color=purple>Very High</color>", cameraLogo, 2f, true);
				break;
			case 1:
				SmoothLookAmount = 7f;
				PlayerCam.SmoothLookSpeed = SmoothLookAmount;
				Singleton<NotificationsManager>.instance.SendNotification("BetterCamera", "Smoothness: <color=blue>High</color>", cameraLogo, 2f, true);
				break;
			case 2:
				SmoothLookAmount = 9f;
				PlayerCam.SmoothLookSpeed = SmoothLookAmount;
				Singleton<NotificationsManager>.instance.SendNotification("BetterCamera", "Smoothness: <color=green>Default</color>", cameraLogo, 2f, true);
				break;
			case 3:
				SmoothLookAmount = 11f;
				PlayerCam.SmoothLookSpeed = SmoothLookAmount;
				Singleton<NotificationsManager>.instance.SendNotification("BetterCamera", "Smoothness: <color=yellow>Low</color>", cameraLogo, 2f, true);
				break;
			case 4:
				SmoothLookAmount = 14f;
				PlayerCam.SmoothLookSpeed = SmoothLookAmount;
				PlayerSingleton<PlayerCamera>.instance.SmoothLook = true;
				Singleton<NotificationsManager>.instance.SendNotification("BetterCamera", "Smoothness: <color=orange>Very Low</color>", cameraLogo, 2f, true);
				break;
			case 5:
				PlayerSingleton<PlayerCamera>.instance.SmoothLook = false;
				PlayerCam.SmoothLookSpeed = SmoothLookAmount;
				Singleton<NotificationsManager>.instance.SendNotification("BetterCamera", "Smoothness: <color=red>Off</color>", cameraLogo, 2f, true);
				break;
			}
		}

		public override void OnLateUpdate()
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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)
			if (InMainGame)
			{
				if (!CameraOverride)
				{
					return;
				}
				if (!InitializedNeededObjects)
				{
					GameObject val = GameObject.Find("UI/HUD/Crosshair");
					if ((Object)(object)val != (Object)null)
					{
						Crosshair = val;
						Camera main = Camera.main;
						CameraTransform = ((main != null) ? ((Component)main).transform : null);
						InitializedNeededObjects = true;
					}
				}
				if ((Object)(object)Crosshair == (Object)null || !Crosshair.activeSelf || (Object)(object)CameraTransform == (Object)null || PlayerCam.ViewingAvatar || Mouse.current == null || Keyboard.current == null)
				{
					return;
				}
				float num = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).delta).ReadValue().x * MouseTiltSpeed * Singleton<Settings>.instance.LookSensitivity;
				float num2 = 0f;
				if (!InConsole)
				{
					if (((ButtonControl)Keyboard.current.aKey).isPressed)
					{
						num2 = WalkTiltSpeed;
					}
					if (((ButtonControl)Keyboard.current.dKey).isPressed)
					{
						num2 = 0f - WalkTiltSpeed;
					}
				}
				TargetZRotation = num + num2;
				zRotation = Mathf.SmoothDamp(zRotation, TargetZRotation, ref zVelocity, SmoothTime);
				xRotation = Mathf.SmoothDamp(xRotation, TargetXRotation, ref xVelocity, SmoothTime);
				CameraTransform.localRotation = Quaternion.Euler(CameraTransform.localEulerAngles.x + xRotation, CameraTransform.localEulerAngles.y, zRotation);
				if (((Behaviour)CUI.canvas).enabled)
				{
					InConsole = true;
				}
				else
				{
					InConsole = false;
				}
				if (((ButtonControl)Keyboard.current.cKey).isPressed && ((ButtonControl)Keyboard.current.equalsKey).wasPressedThisFrame && HasPlayerSpawned)
				{
					CurrentSmoothingSetting--;
					ChangeSmoothness();
				}
				if (((ButtonControl)Keyboard.current.cKey).isPressed && ((ButtonControl)Keyboard.current.minusKey).wasPressedThisFrame && HasPlayerSpawned)
				{
					CurrentSmoothingSetting++;
					ChangeSmoothness();
				}
				if (((ButtonControl)Keyboard.current.xKey).isPressed && HasPlayerSpawned)
				{
					PlayerCam.OverrideFOV(ZoomAmount, 0.1f);
					PlayerCam.SmoothLookSpeed = 2f;
					IsZooming = true;
				}
				else if (!((ButtonControl)Keyboard.current.xKey).isPressed && HasPlayerSpawned)
				{
					PlayerCam.StopFOVOverride(0.1f);
					PlayerCam.SmoothLookSpeed = SmoothLookAmount;
					IsZooming = false;
				}
				if (((ButtonControl)Keyboard.current.downArrowKey).wasPressedThisFrame && IsZooming)
				{
					ZoomAmount += 3f;
				}
				if (((ButtonControl)Keyboard.current.upArrowKey).wasPressedThisFrame && IsZooming)
				{
					ZoomAmount -= 3f;
				}
			}
			if (CurrentSmoothingSetting > 5)
			{
				CurrentSmoothingSetting = 5;
			}
			if (CurrentSmoothingSetting < 0)
			{
				CurrentSmoothingSetting = 0;
			}
		}

		public override void OnGUI()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (ShowKeybinds)
			{
				GUIStyle val = new GUIStyle(GUI.skin.label);
				val.alignment = (TextAnchor)4;
				val.fontStyle = (FontStyle)1;
				GUI.Box(KeyBindBox, "<b>BetterCamera Keybinds</b>", UITextures.GetBackgroundStyle());
				GUILayout.BeginArea(KeyBindBox);
				GUILayout.Space(30f);
				GUILayout.Label("Pressing 'C' and '=' will turn up the smoothing!", val, (Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Label("Pressing 'C' and '-' will turn down the smoothing!", val, (Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Label("Pressing 'X' will zoom in!", val, (Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Space(15f);
				if (GUILayout.Button("<b>Close</b>", UITextures.GetButtonStyle(), Array.Empty<GUILayoutOption>()))
				{
					ShowKeybinds = false;
				}
				GUILayout.EndArea();
			}
		}
	}
	internal class UITextures
	{
		public static GUIStyle GetBackgroundStyle()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00fc: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.box);
			val.normal.background = MakeTex(2, 2, new Color(0.1f, 0.1f, 0.1f, 1f));
			val.hover.background = MakeTex(2, 2, new Color(0.1f, 0.1f, 0.1f, 1f));
			val.focused.background = MakeTex(2, 2, new Color(0.1f, 0.1f, 0.1f, 1f));
			val.onFocused.background = MakeTex(2, 2, new Color(0.1f, 0.1f, 0.1f, 1f));
			val.normal.textColor = Color.white;
			val.hover.textColor = Color.white;
			val.focused.textColor = Color.white;
			val.onFocused.textColor = Color.white;
			return val;
		}

		public static GUIStyle GetButtonStyle()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_011c: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.button);
			val.normal.background = MakeTex(2, 2, new Color(0.4f, 0.4f, 0.4f, 1f));
			val.hover.background = MakeTex(2, 2, new Color(0.4f, 0.4f, 0.4f, 1f));
			val.focused.background = MakeTex(2, 2, new Color(0.4f, 0.4f, 0.4f, 1f));
			val.onFocused.background = MakeTex(2, 2, new Color(0.4f, 0.4f, 0.4f, 1f));
			val.onActive.background = MakeTex(2, 2, new Color(0.4f, 0.4f, 0.4f, 1f));
			val.normal.textColor = Color.white;
			val.hover.textColor = Color.white;
			val.focused.textColor = Color.white;
			val.onFocused.textColor = Color.white;
			val.onActive.textColor = Color.white;
			return val;
		}

		private static Texture2D MakeTex(int width, int height, Color col)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = col;
			}
			Texture2D val = new Texture2D(width, height);
			val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
			val.Apply();
			return val;
		}
	}
}
namespace BetterCamera.Patches
{
	public class GunPatch
	{
		[HarmonyPatch(typeof(Equippable_RangedWeapon), "Update")]
		public static class Patch
		{
			[HarmonyPostfix]
			public static void Postfix(Equippable_RangedWeapon __instance)
			{
				Singleton<HUD>.Instance.SetCrosshairVisible(true);
				PlayerSingleton<PlayerMovement>.Instance.RemoveSprintBlocker("Aiming");
			}
		}
	}
}