Decompiled source of FadeEffect v1.1.0

Mods/FadeEffect.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using FadeEffectMod;
using HarmonyLib;
using Il2Cpp;
using Il2CppGB.Core;
using Il2CppGB.Core.Loading;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(FadeEffect), "FadeEffect", "1.0.0", "Zooks", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FadeEffect")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("FadeEffect mod for Gang Beasts")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FadeEffect")]
[assembly: AssemblyTitle("FadeEffect")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 FadeEffectMod
{
	public enum FadeState
	{
		None,
		FadingOut,
		FadedOut,
		FadingIn
	}
	public static class FadeManager
	{
		public static FadeState CurrentState = FadeState.None;

		public static float CurrentAlpha = 0f;

		public static float FadeOutSpeed = 1.15f;

		public static float FadeInSpeed = 3.5f;

		public static float FadeInDelay = 0.33f;

		public static float FadeInExponent = 1f;

		private static float _delayTimer = 0f;

		private static float _fadeProgress = 0f;

		public static void StartFadeOut()
		{
			CurrentState = FadeState.FadingOut;
			_fadeProgress = 0f;
		}

		public static void StartFadeIn()
		{
			CurrentState = FadeState.FadingIn;
			_delayTimer = FadeInDelay;
			_fadeProgress = 0f;
		}

		public static void ForceBlack()
		{
			CurrentState = FadeState.FadedOut;
			CurrentAlpha = 1f;
			_delayTimer = 0f;
			_fadeProgress = 0f;
		}

		public static void Update()
		{
			float unscaledDeltaTime = Time.unscaledDeltaTime;
			if (CurrentState == FadeState.FadingOut)
			{
				_fadeProgress += unscaledDeltaTime * FadeOutSpeed;
				if (_fadeProgress >= 1f)
				{
					_fadeProgress = 1f;
					CurrentState = FadeState.FadedOut;
				}
				CurrentAlpha = _fadeProgress;
			}
			else
			{
				if (CurrentState != FadeState.FadingIn)
				{
					return;
				}
				if (_delayTimer > 0f)
				{
					_delayTimer -= unscaledDeltaTime;
					CurrentAlpha = 1f;
					return;
				}
				_fadeProgress += unscaledDeltaTime * FadeInSpeed;
				if (_fadeProgress >= 1f)
				{
					_fadeProgress = 1f;
					CurrentState = FadeState.None;
				}
				CurrentAlpha = 1f - Mathf.Pow(_fadeProgress, FadeInExponent);
			}
		}
	}
	public class FadeEffect : MelonMod
	{
		private static GameObject _fadeCanvasObject;

		private static Canvas _fadeCanvas;

		private static RawImage _fadeImage;

		private static GameObject _barBackgroundObject;

		private static GameObject _barFillObject;

		private static RawImage _barBackground;

		private static RawImage _barFill;

		public override void OnUpdate()
		{
			//IL_0094: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			EnsureFadeCanvasExists();
			EnsureLoadingBarExists();
			FadeManager.Update();
			float num = 0f;
			try
			{
				Global instance = MonoSingleton<Global>.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					LoadScreenSystem levelLoadSystem = instance.LevelLoadSystem;
					if ((Object)(object)levelLoadSystem != (Object)null)
					{
						LoadScreenDisplayHandler loadingScreen = levelLoadSystem.LoadingScreen;
						if ((Object)(object)loadingScreen != (Object)null)
						{
							Image progressBar = loadingScreen.ProgressBar;
							if ((Object)(object)progressBar != (Object)null)
							{
								num = progressBar.fillAmount;
							}
						}
					}
				}
			}
			catch (Exception)
			{
			}
			if ((Object)(object)_barFillObject != (Object)null)
			{
				RectTransform component = _barFillObject.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.sizeDelta = new Vector2(120f * num, 16f);
				}
			}
			if ((Object)(object)_barBackground != (Object)null && (Object)(object)_barFill != (Object)null)
			{
				((Graphic)_barBackground).color = new Color(0.85f, 0.12f, 0.48f, FadeManager.CurrentAlpha);
				((Graphic)_barFill).color = new Color(1f, 0.8f, 0f, FadeManager.CurrentAlpha);
			}
			if ((Object)(object)_fadeImage != (Object)null && (Object)(object)_fadeCanvasObject != (Object)null)
			{
				((Graphic)_fadeImage).color = new Color(0f, 0f, 0f, FadeManager.CurrentAlpha);
				bool flag = FadeManager.CurrentAlpha > 0f;
				if (_fadeCanvasObject.activeSelf != flag)
				{
					_fadeCanvasObject.SetActive(flag);
				}
			}
		}

		private static void EnsureFadeCanvasExists()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_fadeCanvasObject != (Object)null && (Object)(object)_fadeImage != (Object)null)
			{
				return;
			}
			try
			{
				_fadeCanvasObject = new GameObject("CustomFadeCanvas");
				Object.DontDestroyOnLoad((Object)(object)_fadeCanvasObject);
				_fadeCanvas = _fadeCanvasObject.AddComponent<Canvas>();
				_fadeCanvas.renderMode = (RenderMode)0;
				_fadeCanvas.sortingOrder = 999999;
				GameObject val = new GameObject("FadeImage");
				val.transform.SetParent(_fadeCanvasObject.transform, false);
				_fadeImage = val.AddComponent<RawImage>();
				((Graphic)_fadeImage).color = new Color(0f, 0f, 0f, 0f);
				RectTransform component = ((Component)_fadeImage).GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0f, 0f);
				component.anchorMax = new Vector2(1f, 1f);
				component.pivot = new Vector2(0.5f, 0.5f);
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				_fadeCanvasObject.SetActive(false);
			}
			catch (Exception)
			{
			}
		}

		private static void EnsureLoadingBarExists()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_barBackgroundObject != (Object)null && (Object)(object)_barFillObject != (Object)null)
			{
				return;
			}
			try
			{
				_barBackgroundObject = new GameObject("CustomLoadingBarBackground");
				_barBackgroundObject.transform.SetParent(_fadeCanvasObject.transform, false);
				_barBackground = _barBackgroundObject.AddComponent<RawImage>();
				((Graphic)_barBackground).color = new Color(0.85f, 0.12f, 0.48f, 0f);
				RectTransform component = _barBackgroundObject.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(1f, 0f);
				component.anchorMax = new Vector2(1f, 0f);
				component.pivot = new Vector2(1f, 0f);
				component.sizeDelta = new Vector2(120f, 16f);
				component.anchoredPosition = new Vector2(-60f, 40f);
				_barFillObject = new GameObject("CustomLoadingBarFill");
				_barFillObject.transform.SetParent(_barBackgroundObject.transform, false);
				_barFill = _barFillObject.AddComponent<RawImage>();
				((Graphic)_barFill).color = new Color(1f, 0.8f, 0f, 0f);
				RectTransform component2 = _barFillObject.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0f, 0.5f);
				component2.anchorMax = new Vector2(0f, 0.5f);
				component2.pivot = new Vector2(0f, 0.5f);
				component2.sizeDelta = new Vector2(0f, 16f);
				component2.anchoredPosition = Vector2.zero;
			}
			catch (Exception)
			{
			}
		}
	}
	[HarmonyPatch(typeof(LoadScreenSystem))]
	public static class LoadScreenSystemPatches
	{
		[HarmonyPatch("ShowLoadingScreen")]
		[HarmonyPrefix]
		public static void ShowLoadingScreenPrefix()
		{
			try
			{
				FadeManager.ForceBlack();
			}
			catch (Exception)
			{
			}
		}

		[HarmonyPatch("HideLoadingScreen")]
		[HarmonyPrefix]
		public static void HideLoadingScreenPrefix()
		{
			try
			{
				FadeManager.StartFadeIn();
			}
			catch (Exception)
			{
			}
		}
	}
}