Decompiled source of FOV Changer v1.3.0

mod/fovchanger.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib.BoneMenu;
using FOVChanger;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(FOVChangerMod), "FOV Changer", "3.0.0", "bend62352 & nicebud", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("armstretch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("armstretch")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8499ef9c-7a39-4309-88a0-ab764a503be2")]
[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 FOVChanger;

public class FOVChangerMod : MelonMod
{
	private const float MIN_FOV = 40f;

	private const float MAX_FOV = 360f;

	private const float DEFAULT_FOV = 90f;

	private static readonly float[] INCREMENT_STEPS = new float[7] { 1f, 5f, 10f, 15f, 20f, 25f, 30f };

	private static float _currentFov = 90f;

	private static MelonPreferences_Category _prefsCategory;

	private static MelonPreferences_Entry<float> _incrementEntry;

	private static MelonPreferences_Entry<bool> _modEnabledEntry;

	private static MelonPreferences_Entry<KeyCode> _increaseKeyEntry;

	private static MelonPreferences_Entry<KeyCode> _decreaseKeyEntry;

	private static FloatElement _fovSliderElement;

	private static BoolElement _modEnabledElement;

	private static float _currentIncrement = 1f;

	public override void OnInitializeMelon()
	{
		PrintCredits();
		SetupPreferences();
		BuildMenu();
		_currentFov = 90f;
	}

	private void PrintCredits()
	{
		((MelonBase)this).LoggerInstance.Msg("========================================");
		((MelonBase)this).LoggerInstance.Msg("FOV Changer v3.0.0 loaded!");
		((MelonBase)this).LoggerInstance.Msg("Credits: bend62352, nicebud");
		((MelonBase)this).LoggerInstance.Msg("Creators: bend62352, nicebud");
		((MelonBase)this).LoggerInstance.Msg("========================================");
	}

	private void SetupPreferences()
	{
		_prefsCategory = MelonPreferences.CreateCategory("FOVChanger");
		_incrementEntry = _prefsCategory.CreateEntry<float>("IncrementAmount", INCREMENT_STEPS[0], "Increment Amount", (string)null, false, false, (ValueValidator)null, (string)null);
		_modEnabledEntry = _prefsCategory.CreateEntry<bool>("ModEnabled", true, "Mod Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		_increaseKeyEntry = _prefsCategory.CreateEntry<KeyCode>("IncreaseKey", (KeyCode)280, "Increase FOV Key", (string)null, false, false, (ValueValidator)null, (string)null);
		_decreaseKeyEntry = _prefsCategory.CreateEntry<KeyCode>("DecreaseKey", (KeyCode)281, "Decrease FOV Key", (string)null, false, false, (ValueValidator)null, (string)null);
		_currentIncrement = SnapToNearestStep(_incrementEntry.Value);
	}

	private void BuildMenu()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Page val = Page.Root.CreatePage("FOV Changer", Color.cyan, 0, true);
			_modEnabledElement = val.CreateBool("Mod Enabled", Color.white, _modEnabledEntry.Value, (Action<bool>)OnModEnabledChanged);
			_fovSliderElement = val.CreateFloat("Field of View", Color.white, 90f, 1f, 40f, 360f, (Action<float>)OnFovChanged);
			val.CreateFunction("+ Increase FOV", Color.green, (Action)delegate
			{
				AdjustFov(_currentIncrement);
			});
			val.CreateFunction("- Decrease FOV", Color.red, (Action)delegate
			{
				AdjustFov(0f - _currentIncrement);
			});
			val.CreateFunction("Reset FOV to Default (90)", Color.yellow, (Action)ResetFov);
			val.CreateFunction("Print Current Status", Color.gray, (Action)PrintStatus);
			Page val2 = val.CreatePage("Increment Amount", Color.green, 0, true);
			float[] iNCREMENT_STEPS = INCREMENT_STEPS;
			foreach (float num2 in iNCREMENT_STEPS)
			{
				float capturedStep = num2;
				val2.CreateFunction("Set Increment: " + FormatStep(capturedStep), Color.green, (Action)delegate
				{
					SetIncrement(capturedStep);
				});
			}
			Page obj = val.CreatePage("Keybinds", Color.blue, 0, true);
			obj.CreateFunction("Increase: " + ((object)_increaseKeyEntry.Value/*cast due to .constrained prefix*/).ToString(), Color.white, (Action)null);
			obj.CreateFunction("Decrease: " + ((object)_decreaseKeyEntry.Value/*cast due to .constrained prefix*/).ToString(), Color.white, (Action)null);
			obj.CreateFunction("Edit in UserData\\MelonPreferences.cfg", Color.gray, (Action)null);
			Page obj2 = val.CreatePage("Credits", Color.magenta, 0, true);
			obj2.CreateFunction("Mod by: bend62352", Color.white, (Action)null);
			obj2.CreateFunction("Mod by: nicebud", Color.white, (Action)null);
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Error("Failed to build BoneMenu UI: " + ex);
		}
	}

	private static string FormatStep(float step)
	{
		return step.ToString("0") + "°";
	}

	private static string BuildStatusText()
	{
		return "Current: " + _currentFov.ToString("0") + "° | Step: " + FormatStep(_currentIncrement);
	}

	private void PrintStatus()
	{
		((MelonBase)this).LoggerInstance.Msg(BuildStatusText());
	}

	private void OnModEnabledChanged(bool enabled)
	{
		_modEnabledEntry.Value = enabled;
		_prefsCategory.SaveToFile(false);
		if (!enabled)
		{
			ReleaseVrOverride();
		}
		else
		{
			ApplyFov(_currentFov);
		}
		((MelonBase)this).LoggerInstance.Msg(enabled ? "FOV Changer enabled" : "FOV Changer disabled (FOV control released)");
	}

	private static float SnapToNearestStep(float value)
	{
		float num = INCREMENT_STEPS[0];
		float num2 = Math.Abs(value - num);
		float[] iNCREMENT_STEPS = INCREMENT_STEPS;
		foreach (float num3 in iNCREMENT_STEPS)
		{
			float num4 = Math.Abs(value - num3);
			if (num4 < num2)
			{
				num2 = num4;
				num = num3;
			}
		}
		return num;
	}

	private void SetIncrement(float step)
	{
		_currentIncrement = step;
		_incrementEntry.Value = step;
		_prefsCategory.SaveToFile(false);
		((MelonBase)this).LoggerInstance.Msg("FOV increment set to " + FormatStep(step));
	}

	private void AdjustFov(float delta)
	{
		if (_modEnabledEntry.Value)
		{
			float fov = Mathf.Clamp(_currentFov + delta, 40f, 360f);
			SetFov(fov);
		}
	}

	private void OnFovChanged(float newValue)
	{
		SetFov(Mathf.Clamp(newValue, 40f, 360f));
	}

	private void ResetFov()
	{
		SetFov(90f);
		((MelonBase)this).LoggerInstance.Msg("FOV reset to default (" + 90f.ToString("0") + "°)");
	}

	private void SetFov(float value)
	{
		_currentFov = value;
		ApplyFov(value);
		if (_fovSliderElement != null)
		{
			_fovSliderElement.Value = value;
		}
	}

	private void ApplyFov(float value)
	{
		if (_modEnabledEntry.Value)
		{
			Camera[] array = Il2CppArrayBase<Camera>.op_Implicit((Il2CppArrayBase<Camera>)(object)Camera.allCameras);
			for (int i = 0; i < array.Length; i++)
			{
				ApplyFovToCamera(array[i], value);
			}
		}
	}

	private void ApplyFovToCamera(Camera cam, float value)
	{
		if (!((Object)(object)cam == (Object)null))
		{
			if (IsVrActive(cam))
			{
				ApplyVrFov(cam, value);
			}
			else
			{
				cam.fieldOfView = value;
			}
		}
	}

	private void ApplyVrFov(Camera cam, float value)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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)
		float eyeAspect = GetEyeAspect(cam);
		Matrix4x4 val = Matrix4x4.Perspective(value, eyeAspect, cam.nearClipPlane, cam.farClipPlane);
		cam.SetStereoProjectionMatrix((StereoscopicEye)0, val);
		cam.SetStereoProjectionMatrix((StereoscopicEye)1, val);
		cam.fieldOfView = value;
	}

	private float GetEyeAspect(Camera cam)
	{
		return cam.aspect;
	}

	private bool IsVrActive(Camera cam)
	{
		if ((Object)(object)cam != (Object)null)
		{
			return cam.stereoEnabled;
		}
		return false;
	}

	private void ReleaseVrOverride()
	{
		Camera[] array = Il2CppArrayBase<Camera>.op_Implicit((Il2CppArrayBase<Camera>)(object)Camera.allCameras);
		foreach (Camera val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				try
				{
					val.ResetStereoProjectionMatrices();
					val.ResetProjectionMatrix();
				}
				catch
				{
				}
			}
		}
	}

	public override void OnUpdate()
	{
		HandleInput();
	}

	public override void OnLateUpdate()
	{
		if (_modEnabledEntry.Value)
		{
			ApplyFov(_currentFov);
		}
	}

	private void HandleInput()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if (_modEnabledEntry.Value)
		{
			if (Input.GetKeyDown(_increaseKeyEntry.Value))
			{
				AdjustFov(_currentIncrement);
			}
			else if (Input.GetKeyDown(_decreaseKeyEntry.Value))
			{
				AdjustFov(0f - _currentIncrement);
			}
		}
	}
}