Decompiled source of SpeedEffects v1.0.1

Mods/SpeedEffects.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Utilities;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModUI;
using RumbleModdingAPI;
using SpeedEffects;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(SEClass), "SpeedEffects", "1.0.1", "TacoSlayer36", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 255, 248, 231)]
[assembly: MelonAuthorColor(255, 255, 248, 231)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SpeedEffects")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpeedEffects")]
[assembly: AssemblyTitle("SpeedEffects")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace SpeedEffects
{
	public static class BuildInfo
	{
		public const string ModName = "SpeedEffects";

		public const string ModVersion = "1.0.1";

		public const string Description = "Zoom";

		public const string Author = "TacoSlayer36";

		public const string Company = "";
	}
	public class SEClass : MelonMod
	{
		[CompilerGenerated]
		private sealed class <listenForLandButtons>d__33 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public SEClass <>4__this;

			private Exception <ex>5__1;

			private Exception <ex>5__2;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<ex>5__1 = null;
				<ex>5__2 = null;
				<>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(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					try
					{
						if (<>4__this.hasFlatLand)
						{
							GameObject.Find("FlatLand/FlatLandButton/Button").GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
							{
								MelonCoroutines.Start(<>4__this.toLandMap());
							}));
						}
					}
					catch (Exception ex)
					{
						<ex>5__1 = ex;
						((MelonBase)<>4__this).LoggerInstance.Error((object)<ex>5__1);
					}
					try
					{
						if (<>4__this.hasVoidLand)
						{
							GameObject.Find("VoidLand/VoidLandButton/Button").GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
							{
								MelonCoroutines.Start(<>4__this.toLandMap());
							}));
						}
					}
					catch (Exception ex)
					{
						<ex>5__2 = ex;
						((MelonBase)<>4__this).LoggerInstance.Error((object)<ex>5__2);
					}
					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();
			}
		}

		[CompilerGenerated]
		private sealed class <toLandMap>d__34 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public SEClass <>4__this;

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

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

			[DebuggerHidden]
			public <toLandMap>d__34(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(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (<>4__this.doSpeedLines)
					{
						<>4__this.speedLinesOverlay.active = true;
					}
					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 bool init = false;

		private bool hasFlatLand = false;

		private bool hasVoidLand = false;

		private string scene = "Loader";

		private GameObject recordingCameraGO;

		private Camera recordingCameraCAM;

		private RecordingCamera recordingCameraRC;

		private Rigidbody playerRB;

		private Material speedLinesMaterial;

		private GameObject speedLinesOverlay;

		private bool referencesGot = false;

		private Mod Mod = new Mod();

		private bool doDynamicFOV = true;

		private float fovEffectMultiplier = 4f;

		private float interpolationSpeed = 0.24f;

		private float maxFOV = 130f;

		private bool doSpeedLines = true;

		private float speedLinesPowerMultiplier = 0.19f;

		private Vector4 speedLinesColor = Color.op_Implicit(Color.white);

		private bool includeUpwardSpeed = false;

		private bool isRainbow = false;

		private float rainbowHue = 0f;

		private float speed;

		private float fovVelocity = 0f;

		private float baseFOV = 90f;

		public override void OnLateInitializeMelon()
		{
			//IL_0060: 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_0072: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Expected O, but got Unknown
			UI.instance.UI_Initialized += OnUIInit;
			Mod.ModName = "SpeedEffects";
			Mod.ModVersion = "1.0.1";
			Mod.SetFolder("SpeedEffects");
			Mod.AddDescription("Description", "", "Zoom", new Tags
			{
				IsSummary = true
			});
			Mod.AddToList("Do Dynamic FOV", true, 0, "Set to enable the speed-based field of view", new Tags());
			Mod.AddToList("FOV Effect Multiplier", 5.5f, "The strength of the FOV effect\nCalculated as: (base FOV + meters per second * multiplier)", new Tags());
			Mod.AddToList("FOV Smoothing", 0.24f, "The speed at which the FOV interpolates to the target value", new Tags());
			Mod.AddToList("Max FOV", 145f, "The maximum FOV value", new Tags());
			Mod.AddToList("Do Speed Lines", true, 0, "Set to enable anime speed lines", new Tags());
			Mod.AddToList("Speed Lines Strength", 0.19f, "The strength of the speed lines", new Tags());
			Mod.AddToList("Speed Lines Color", "#FFFFFF", "The hex color code for the speed lines, or type \"Rainbow\"", new Tags());
			Mod.AddToList("Include Upward Speed", false, 0, "Set to allow moving upwards to trigger the effects", new Tags());
			Mod.GetFromFile();
			Mod.ModSaved += Save;
			Save();
			Calls.onMapInitialized += OnMapInitialized;
			Calls.onMyModsGathered += checkMods;
		}

		private void checkMods()
		{
			hasFlatLand = Mods.findOwnMod("FlatLand", "1.6.0", false);
			hasVoidLand = Mods.findOwnMod("VoidLand", "1.0.0", false);
		}

		public void OnUIInit()
		{
			UI.instance.AddMod(Mod);
		}

		public void Save()
		{
			//IL_00f3: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			doDynamicFOV = (bool)Mod.Settings[1].SavedValue;
			fovEffectMultiplier = (float)Mod.Settings[2].SavedValue;
			interpolationSpeed = (float)Mod.Settings[3].SavedValue;
			maxFOV = (float)Mod.Settings[4].SavedValue;
			doSpeedLines = (bool)Mod.Settings[5].SavedValue;
			speedLinesPowerMultiplier = (float)Mod.Settings[6].SavedValue;
			Color val = default(Color);
			speedLinesColor = Color.op_Implicit(ColorUtility.TryParseHtmlString((string)Mod.Settings[7].SavedValue, ref val) ? val : Color.white);
			if (((string)Mod.Settings[7].SavedValue).ToLower() == "rainbow")
			{
				isRainbow = true;
			}
			else
			{
				isRainbow = false;
			}
			includeUpwardSpeed = (bool)Mod.Settings[8].SavedValue;
			resetEffects();
		}

		public override void OnUpdate()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_008b: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			if (!init || !referencesGot)
			{
				return;
			}
			try
			{
				Vector3 val;
				if (includeUpwardSpeed)
				{
					val = playerRB.velocity;
					speed = ((Vector3)(ref val)).magnitude;
				}
				else
				{
					val = new Vector3(playerRB.velocity.x, Mathf.Clamp(playerRB.velocity.y, float.MinValue, 0f) * 0.6f, playerRB.velocity.z);
					speed = ((Vector3)(ref val)).magnitude;
				}
			}
			catch
			{
			}
			try
			{
				baseFOV = recordingCameraRC.fovSlider.value;
			}
			catch
			{
			}
			if (doDynamicFOV)
			{
				try
				{
					float num = baseFOV + speed * fovEffectMultiplier;
					float fieldOfView = recordingCameraCAM.fieldOfView;
					float num2 = Mathf.SmoothDamp(fieldOfView, num, ref fovVelocity, interpolationSpeed);
					recordingCameraCAM.fieldOfView = Mathf.Clamp(num2, float.MinValue, maxFOV);
				}
				catch
				{
				}
			}
			if (!doSpeedLines)
			{
				return;
			}
			if (isRainbow)
			{
				float num3 = Mathf.Lerp(2f / 3f, 5f, Mathf.InverseLerp(5f, 9f, speed));
				rainbowHue += Time.deltaTime * num3;
				if (rainbowHue > 1f)
				{
					rainbowHue -= 1f;
				}
				speedLinesColor = Color.op_Implicit(Color.HSVToRGB(rainbowHue, 1f, 1f));
			}
			try
			{
				updateSpeedLinesShader();
			}
			catch
			{
			}
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			scene = sceneName;
			if (scene == "Gym" && !init)
			{
				init = true;
				getReferences();
				speedLinesOverlay = LoadAssetBundle("SpeedEffects.assetbundles.speedeffects", "SpeedLines");
				Object.DontDestroyOnLoad((Object)(object)speedLinesOverlay);
				speedLinesMaterial = ((Graphic)((Component)speedLinesOverlay.transform.GetChild(0)).GetComponent<Image>()).material;
				speedLinesMaterial.renderQueue = 3000;
			}
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			referencesGot = false;
		}

		public void OnMapInitialized()
		{
			if (scene == "Gym")
			{
				MelonCoroutines.Start(listenForLandButtons());
			}
			if (init)
			{
				getReferences();
			}
		}

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

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

		private void getReferences()
		{
			recordingCameraGO = GameObject.Find("RecordingCamera");
			recordingCameraCAM = recordingCameraGO.GetComponent<Camera>();
			recordingCameraRC = recordingCameraGO.GetComponent<RecordingCamera>();
			playerRB = ((Component)((Component)Singleton<PlayerManager>.Instance.localPlayer.Controller).transform.GetChild(1)).GetComponent<Rigidbody>();
			referencesGot = true;
		}

		private void updateSpeedLinesShader()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp(speed, 0.15f, 100f);
			speedLinesMaterial.SetFloat("_MaskScale", 1f / (num * speedLinesPowerMultiplier));
			speedLinesMaterial.SetColor("_Colour", Color.op_Implicit(speedLinesColor));
		}

		private void resetEffects()
		{
			if (!doDynamicFOV)
			{
				recordingCameraCAM.fieldOfView = baseFOV;
			}
			if (!doSpeedLines)
			{
				speedLinesMaterial.SetFloat("_MaskScale", 10f);
			}
		}

		private GameObject? LoadAssetBundle(string bundleName, string objectName)
		{
			using Stream stream = ((MelonBase)this).MelonAssembly.Assembly.GetManifestResourceStream(bundleName);
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Il2CppStructArray<byte> val = new Il2CppStructArray<byte>((long)array.Length);
			for (int i = 0; i < array.Length; i++)
			{
				((Il2CppArrayBase<byte>)(object)val)[i] = array[i];
			}
			Il2CppAssetBundle val2 = Il2CppAssetBundleManager.LoadFromMemory(val);
			return Object.Instantiate<GameObject>(val2.LoadAsset<GameObject>(objectName));
		}
	}
}