Decompiled source of RockCamDepthOfField v1.0.0

Mods/RockCamDepthOfField.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
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 Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Utilities;
using Il2CppRootMotion;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using RockCamDepthOfField;
using UIFramework;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "RockCamDepthOfField", "1.0.0", "Saveforth", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonAdditionalDependencies(new string[] { "UIFramework" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RockCamDepthOfField")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RockCamDepthOfField")]
[assembly: AssemblyTitle("RockCamDepthOfField")]
[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 RockCamDepthOfField
{
	public class Core : MelonMod
	{
		[CompilerGenerated]
		private sealed class <waitForLoad>d__8 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Core <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <waitForLoad>d__8(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.addPostProcessing();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private MelonPreferences_Category dofOptions;

		private const string USER_DATA = "UserData/DepthOfField/";

		private const string CONFIG_FILE = "config.cfg";

		private MelonPreferences_Entry<bool> toggle;

		private MelonPreferences_Entry<float> focusDistance;

		private MelonPreferences_Entry<float> focalLength;

		private DepthOfField depthOfField;

		public override void OnInitializeMelon()
		{
			dofOptions = MelonPreferences.CreateCategory("dofOptions", "Depth of Field");
			if (!Directory.Exists("UserData/DepthOfField/"))
			{
				Directory.CreateDirectory("UserData/DepthOfField/");
			}
			dofOptions.SetFilePath(Path.Combine("UserData/DepthOfField/", "config.cfg"));
			toggle = dofOptions.CreateEntry<bool>("Entry 1-0", true, "Depth Of Field", "Turn on or off depth of field", false, false, (ValueValidator)null, (string)null);
			focusDistance = dofOptions.CreateEntry<float>("Entry 1-1", 3.38f, "Focus Distance", "Changes focal point", false, false, (ValueValidator)null, (string)null);
			focalLength = dofOptions.CreateEntry<float>("Entry 1-2", 130f, "Focal Length", "Strength of Blur", false, false, (ValueValidator)null, (string)null);
			((MelonEventBase<LemonAction<bool, bool>>)(object)toggle.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate(bool oldVal, bool newVal)
			{
				setDOF(newVal);
			}, 0, false);
			((MelonEventBase<LemonAction<float, float>>)(object)focusDistance.OnEntryValueChanged).Subscribe((LemonAction<float, float>)delegate(float oldVal, float newVal)
			{
				setFocusDistance(newVal);
			}, 0, false);
			((MelonEventBase<LemonAction<float, float>>)(object)focalLength.OnEntryValueChanged).Subscribe((LemonAction<float, float>)delegate(float oldVal, float newVal)
			{
				setFocalLength(newVal);
			}, 0, false);
			UI.RegisterMelon((MelonBase)(object)this, (MelonPreferences_Category[])(object)new MelonPreferences_Category[1] { dofOptions });
		}

		[IteratorStateMachine(typeof(<waitForLoad>d__8))]
		private IEnumerator waitForLoad()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <waitForLoad>d__8(0)
			{
				<>4__this = this
			};
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (buildIndex != 0)
			{
				MelonCoroutines.Start(waitForLoad());
			}
		}

		private void addPostProcessing()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			GameObject gameObject = ((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(7).GetChild(0).GetChild(2)
				.GetChild(1)
				.GetChild(0)
				.GetChild(0)
				.GetChild(0)).gameObject;
			GameObject gameObject2 = ((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(7).GetChild(1).GetChild(0)
				.GetChild(0)
				.GetChild(0)).gameObject;
			GameObject gameObject3 = ((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(7).GetChild(1).GetChild(1)
				.GetChild(0)
				.GetChild(0)).gameObject;
			GameObject val = new GameObject();
			Volume val2 = val.AddComponent<Volume>();
			VolumeProfile val4 = (val2.profile = new VolumeProfile());
			depthOfField = val4.Add<DepthOfField>(true);
			if (toggle != null && !toggle.Value)
			{
				((VolumeParameter<DepthOfFieldMode>)(object)depthOfField.mode).m_Value = (DepthOfFieldMode)0;
				((VolumeParameter<DepthOfFieldMode>)(object)depthOfField.mode).value = (DepthOfFieldMode)0;
			}
			((VolumeParameter<DepthOfFieldMode>)(object)depthOfField.mode).m_Value = (DepthOfFieldMode)2;
			((VolumeParameter<DepthOfFieldMode>)(object)depthOfField.mode).value = (DepthOfFieldMode)2;
			if (focusDistance != null)
			{
				((VolumeParameter<float>)(object)depthOfField.focusDistance).value = focusDistance.Value;
			}
			else
			{
				((VolumeParameter<float>)(object)depthOfField.focusDistance).value = 3.38f;
			}
			if (focalLength != null)
			{
				((VolumeParameter<float>)(object)depthOfField.focalLength).value = focalLength.Value;
			}
			else
			{
				((VolumeParameter<float>)(object)depthOfField.focalLength).value = 130f;
			}
			((Object)val).name = "volumeObject";
			((VolumeParameter)depthOfField.mode).overrideState = true;
			val.layer = 24;
			addLayerMaskToCam(gameObject.GetComponent<Camera>());
			addLayerMaskToCam(gameObject2.GetComponent<Camera>());
			addLayerMaskToCam(gameObject3.GetComponent<Camera>());
		}

		private void addLayerMaskToCam(Camera cam)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			UniversalAdditionalCameraData universalAdditionalCameraData = CameraExtensions.GetUniversalAdditionalCameraData(cam);
			string[] array = new string[1] { "PlayerFeet" };
			universalAdditionalCameraData.volumeLayerMask = LayerMaskExtensions.AddToMask(universalAdditionalCameraData.volumeLayerMask, Il2CppStringArray.op_Implicit(array));
			universalAdditionalCameraData.renderPostProcessing = true;
			universalAdditionalCameraData.m_RenderPostProcessing = true;
		}

		private void setDOF(bool isOn)
		{
			MelonLogger.Msg("toggled");
			if (isOn)
			{
				((VolumeParameter<DepthOfFieldMode>)(object)depthOfField.mode).m_Value = (DepthOfFieldMode)2;
				((VolumeParameter<DepthOfFieldMode>)(object)depthOfField.mode).value = (DepthOfFieldMode)2;
				MelonLogger.Msg("on");
			}
			else
			{
				((VolumeParameter<DepthOfFieldMode>)(object)depthOfField.mode).m_Value = (DepthOfFieldMode)0;
				((VolumeParameter<DepthOfFieldMode>)(object)depthOfField.mode).value = (DepthOfFieldMode)0;
				MelonLogger.Msg("off");
			}
		}

		private void setFocusDistance(float distance)
		{
			((VolumeParameter<float>)(object)depthOfField.focusDistance).value = distance;
			MelonLogger.Msg("distance: " + distance);
		}

		private void setFocalLength(float focalLength)
		{
			((VolumeParameter<float>)(object)depthOfField.focalLength).value = focalLength;
			MelonLogger.Msg("length" + focalLength);
		}
	}
}