Decompiled source of Intermission v1.5.0

plugins/Intermission.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComfyLib;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Intermission")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Intermission")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("746fb90c-3d18-4ef5-8e0f-6ac9ca2b36fe")]
[assembly: AssemblyFileVersion("1.5.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.0.0")]
[module: UnverifiableCode]
namespace ComfyLib
{
	public static class ConfigFileExtensions
	{
		internal sealed class ConfigurationManagerAttributes
		{
			public Action<ConfigEntryBase> CustomDrawer;

			public bool? Browsable;

			public bool? HideDefaultButton;

			public int? Order;
		}

		private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>();

		private static int GetSettingOrder(string section)
		{
			if (!_sectionToSettingOrder.TryGetValue(section, out var value))
			{
				value = 0;
			}
			_sectionToSettingOrder[section] = value - 1;
			return value;
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = GetSettingOrder(section)
				}
			}));
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Browsable = browsable,
					CustomDrawer = customDrawer,
					HideDefaultButton = hideDefaultButton,
					Order = GetSettingOrder(section)
				}
			}));
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler)
		{
			configEntry.SettingChanged += delegate
			{
				settingChangedHandler();
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}
	}
	public static class ComponentExtensions
	{
		public static T GetOrAddComponent<T>(this Component component) where T : Component
		{
			T result = default(T);
			if (!component.TryGetComponent<T>(ref result))
			{
				return component.gameObject.AddComponent<T>();
			}
			return result;
		}

		public static T SetActive<T>(this T component, bool active) where T : Component
		{
			((Component)component).gameObject.SetActive(active);
			return component;
		}
	}
	public static class ImageExtensions
	{
		public static Image SetColor(this Image image, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)image).color = color;
			return image;
		}

		public static Image SetPreserveAspect(this Image image, bool preserveAspect)
		{
			image.preserveAspect = preserveAspect;
			return image;
		}

		public static Image SetSprite(this Image image, Sprite sprite)
		{
			image.sprite = sprite;
			return image;
		}

		public static Image SetType(this Image image, Type type)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			image.type = type;
			return image;
		}
	}
	public static class ObjectExtensions
	{
		public static T Ref<T>(this T unityObject) where T : Object
		{
			if (!Object.op_Implicit((Object)(object)unityObject))
			{
				return default(T);
			}
			return unityObject;
		}

		public static T SetName<T>(this T unityObject, string name) where T : Object
		{
			((Object)unityObject).name = name;
			return unityObject;
		}
	}
	public static class OutlineExtensions
	{
		public static Outline SetEnabled(this Outline outline, bool enabled)
		{
			((Behaviour)outline).enabled = enabled;
			return outline;
		}
	}
	public static class RectTransformExtensions
	{
		public static RectTransform SetAnchorMin(this RectTransform rectTransform, Vector2 anchorMin)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchorMin = anchorMin;
			return rectTransform;
		}

		public static RectTransform SetAnchorMax(this RectTransform rectTransform, Vector2 anchorMax)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchorMax = anchorMax;
			return rectTransform;
		}

		public static RectTransform SetPosition(this RectTransform rectTransform, Vector2 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchoredPosition = position;
			return rectTransform;
		}

		public static RectTransform SetSizeDelta(this RectTransform rectTransform, Vector2 sizeDelta)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.sizeDelta = sizeDelta;
			return rectTransform;
		}
	}
	public static class ShadowExtensions
	{
		public static Shadow SetEnabled(this Shadow shadow, bool enabled)
		{
			((Behaviour)shadow).enabled = enabled;
			return shadow;
		}

		public static Shadow SetEffectColor(this Shadow shadow, Color effectColor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			shadow.effectColor = effectColor;
			return shadow;
		}

		public static Shadow SetEffectDistance(this Shadow shadow, Vector2 effectDistance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			shadow.effectDistance = effectDistance;
			return shadow;
		}
	}
	public static class TMPTextExtensions
	{
		public static T SetAlignment<T>(this T tmpText, TextAlignmentOptions alignment) where T : TMP_Text
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			((TMP_Text)tmpText).alignment = alignment;
			return tmpText;
		}

		public static T SetColor<T>(this T tmpText, Color color) where T : TMP_Text
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)(object)tmpText).color = color;
			return tmpText;
		}

		public static T SetFontSize<T>(this T tmpText, float fontSize) where T : TMP_Text
		{
			((TMP_Text)tmpText).fontSize = fontSize;
			return tmpText;
		}

		public static T SetTextWrappingMode<T>(this T tmpText, TextWrappingModes textWrappingMode) where T : TMP_Text
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			((TMP_Text)tmpText).textWrappingMode = textWrappingMode;
			return tmpText;
		}
	}
}
namespace Intermission
{
	public static class CustomAssets
	{
		private static readonly Dictionary<string, Sprite> _loadingImageCache = new Dictionary<string, Sprite>();

		private static int _loadingImageIndex = -1;

		public static List<string> LoadingTips { get; } = new List<string>();


		public static List<string> LoadingImageFiles { get; } = new List<string>();


		public static void Initialize(string pluginDir)
		{
			LoadingTips.Clear();
			LoadingTips.AddRange(ReadLoadingTips(Path.Combine(pluginDir, "tips.txt")));
			LoadingImageFiles.Clear();
			LoadingImageFiles.AddRange(ReadLoadingImageFiles(pluginDir, ".png"));
			LoadingImageFiles.AddRange(ReadLoadingImageFiles(pluginDir, ".jpg"));
		}

		public static IEnumerable<string> ReadLoadingTips(string path)
		{
			if (File.Exists(path))
			{
				string[] array = File.ReadAllLines(path);
				Intermission.LogInfo($"Found {array.Length} custom tips in file: {path}");
				return array;
			}
			Intermission.LogInfo("Creating new empty custom tips file: " + path);
			Directory.CreateDirectory(Path.GetDirectoryName(path));
			File.Create(path);
			return Array.Empty<string>();
		}

		public static IEnumerable<string> ReadLoadingImageFiles(string path, string extension)
		{
			Directory.CreateDirectory(Path.GetDirectoryName(path));
			string[] files = Directory.GetFiles(path, "*" + extension, SearchOption.TopDirectoryOnly);
			Intermission.LogInfo($"Found {files.Length} custom loading images ({extension}) in directory: {path}");
			return files;
		}

		public static Sprite ReadLoadingImage(string imageFile)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (_loadingImageCache.TryGetValue(imageFile, out var value))
			{
				return value;
			}
			if (!File.Exists(imageFile))
			{
				Intermission.LogError("Could not find custom loading image: " + imageFile);
				return null;
			}
			Texture2D val = new Texture2D(1, 1);
			val.SetName<Texture2D>("intermission.texture-" + Path.GetFileName(imageFile));
			ImageConversion.LoadImage(val, File.ReadAllBytes(imageFile));
			value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero, 1f);
			value.SetName<Sprite>("intermission.sprite-" + Path.GetFileName(imageFile));
			_loadingImageCache[imageFile] = value;
			return value;
		}

		public static bool GetRandomLoadingTip(out string tipText)
		{
			if (LoadingTips.Count > 0)
			{
				tipText = LoadingTips[Random.Range(0, LoadingTips.Count)];
				return true;
			}
			tipText = null;
			return false;
		}

		public static bool GetRandomLoadingImage(out Sprite loadingImageSprite)
		{
			if (LoadingImageFiles.Count > 0)
			{
				if (_loadingImageIndex < 0 || _loadingImageIndex >= LoadingImageFiles.Count)
				{
					LoadingImageFiles.Sort(RandomStringComparer.Instance);
					_loadingImageIndex = 0;
				}
				loadingImageSprite = ReadLoadingImage(LoadingImageFiles[_loadingImageIndex]);
				_loadingImageIndex++;
				return Object.op_Implicit((Object)(object)loadingImageSprite);
			}
			loadingImageSprite = null;
			return false;
		}
	}
	public static class ImageScaleUtils
	{
		private static Coroutine _scaleLerpCoroutine;

		public static IEnumerator ScaleLerp(Transform transform, Vector3 startScale, Vector3 endScale, float lerpDuration)
		{
			//IL_000e: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			transform.localScale = startScale;
			float timeElapsed = 0f;
			while (timeElapsed < lerpDuration)
			{
				float num = timeElapsed / lerpDuration;
				num = num * num * (3f - 2f * num);
				transform.localScale = Vector3.Lerp(startScale, endScale, num);
				timeElapsed += Time.deltaTime;
				yield return null;
			}
			transform.localScale = endScale;
		}

		public static void ScaleLerpLoadingImage(this MonoBehaviour component, Image loadingImage)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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)
			if (_scaleLerpCoroutine != null)
			{
				component.StopCoroutine(_scaleLerpCoroutine);
				_scaleLerpCoroutine = null;
			}
			if (PluginConfig.LoadingImageUseScaleLerp.Value && Object.op_Implicit((Object)(object)loadingImage))
			{
				_scaleLerpCoroutine = component.StartCoroutine(ScaleLerp(((Component)loadingImage).transform, Vector3.one, Vector3.one * PluginConfig.LoadingImageScaleLerpEndScale.Value, PluginConfig.LoadingImageScaleLerpDuration.Value));
			}
		}
	}
	public static class HudUtils
	{
		private static TMP_Text _cachedTipText;

		private static Image _cachedLoadingImage;

		private static Transform _cachedPanelSeparator;

		public static void SetLoadingImage(Image loadingImage)
		{
			if (Object.op_Implicit((Object)(object)loadingImage) && CustomAssets.GetRandomLoadingImage(out var loadingImageSprite))
			{
				loadingImage.SetSprite(loadingImageSprite);
			}
		}

		public static void SetLoadingTip(TMP_Text tipText)
		{
			if (Object.op_Implicit((Object)(object)tipText) && CustomAssets.GetRandomLoadingTip(out var tipText2))
			{
				tipText.SetText(tipText2);
			}
		}

		public static void SetupLoadingImage(Image loadingImage = null)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)loadingImage))
			{
				_cachedLoadingImage = loadingImage;
			}
			else if (Object.op_Implicit((Object)(object)_cachedLoadingImage))
			{
				loadingImage = _cachedLoadingImage;
			}
			else
			{
				Intermission.LogError("Could not find a LoadingImage to setup!");
			}
			loadingImage.SetType((Type)0).SetColor(PluginConfig.LoadingImageBaseColor.Value).SetPreserveAspect(preserveAspect: true);
		}

		public static void SetupPanelSeparator(Transform panelSeparator = null)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)panelSeparator))
			{
				_cachedPanelSeparator = panelSeparator;
			}
			else if (Object.op_Implicit((Object)(object)_cachedPanelSeparator))
			{
				panelSeparator = _cachedPanelSeparator;
			}
			else
			{
				Intermission.LogError("Could not find a PanelSeparator to setup!");
			}
			panelSeparator.SetActive<Transform>(PluginConfig.LoadingScreenShowPanelSeparator.Value);
			((Component)panelSeparator).GetComponent<RectTransform>().SetAnchorMin(new Vector2(0.5f, 0f)).SetAnchorMax(new Vector2(0.5f, 0f))
				.SetPosition(PluginConfig.LoadingScreenPanelSeparatorPosition.Value);
		}

		public static void SetupTipText(TMP_Text tipText = null)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)tipText))
			{
				_cachedTipText = tipText;
			}
			else if (Object.op_Implicit((Object)(object)_cachedTipText))
			{
				tipText = _cachedTipText;
			}
			else
			{
				Intermission.LogError("Could not find a TipText to setup!");
			}
			tipText.SetAlignment<TMP_Text>((TextAlignmentOptions)258).SetTextWrappingMode<TMP_Text>((TextWrappingModes)1).SetFontSize<TMP_Text>((float)PluginConfig.LoadingTipTextFontSize.Value)
				.SetColor<TMP_Text>(PluginConfig.LoadingTipTextColor.Value);
			((Component)tipText).GetComponent<RectTransform>().SetAnchorMin(Vector2.zero).SetAnchorMax(Vector2.right)
				.SetPosition(PluginConfig.LoadingTipTextPosition.Value)
				.SetSizeDelta(new Vector2(-50f, 78f));
		}
	}
	public sealed class RandomStringComparer : Comparer<string>
	{
		public static readonly RandomStringComparer Instance = new RandomStringComparer();

		public override int Compare(string x, string y)
		{
			return Random.Range(-1, 2);
		}
	}
	[BepInPlugin("redseiko.valheim.intermission", "Intermission", "1.5.0")]
	public sealed class Intermission : BaseUnityPlugin
	{
		public const string PluginGuid = "redseiko.valheim.intermission";

		public const string PluginName = "Intermission";

		public const string PluginVersion = "1.5.0";

		private static ManualLogSource _logger;

		private Harmony _harmony;

		private void Awake()
		{
			_logger = ((BaseUnityPlugin)this).Logger;
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			if (PluginConfig.IsModEnabled.Value)
			{
				CustomAssets.Initialize(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath), "Intermission"));
				_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.intermission");
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		public static void LogInfo(object o)
		{
			_logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {o}");
		}

		public static void LogError(object o)
		{
			_logger.LogError((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {o}");
		}
	}
	[HarmonyPatch(typeof(FejdStartup))]
	internal static class FejdStartupPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(ref FejdStartup __instance)
		{
			Image component = ((Component)__instance.m_loading.transform.Find("Bkg")).GetComponent<Image>();
			TMP_Text component2 = ((Component)__instance.m_loading.transform.Find("Text")).GetComponent<TMP_Text>();
			TMP_Text val = Object.Instantiate<TMP_Text>(component2, __instance.m_loading.transform);
			((Object)val).name = ((Object)component2).name;
			Object.Destroy((Object)(object)((Component)component2).gameObject);
			Transform panelSeparator = Object.Instantiate<Transform>(__instance.m_menuList.transform.Find("ornament"), __instance.m_loading.transform);
			HudUtils.SetupTipText(val);
			HudUtils.SetupLoadingImage(component);
			HudUtils.SetupPanelSeparator(panelSeparator);
			HudUtils.SetLoadingTip(val);
			HudUtils.SetLoadingImage(component);
		}
	}
	[HarmonyPatch(typeof(Hud))]
	internal static class HudPatch
	{
		private static bool _loadingScreenState;

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(ref Hud __instance)
		{
			Transform obj = __instance.m_loadingProgress.transform.Find("panel_separator");
			HudUtils.SetupTipText(__instance.m_loadingTip);
			HudUtils.SetupLoadingImage(__instance.m_loadingImage);
			HudUtils.SetupPanelSeparator(obj);
			HudUtils.SetLoadingTip(__instance.m_loadingTip);
			HudUtils.SetLoadingImage(__instance.m_loadingImage);
			Transform obj2 = __instance.m_loadingProgress.transform.Find("TopFade").Ref<Transform>();
			if (obj2 != null)
			{
				((Component)obj2).gameObject.SetActive(false);
			}
			Transform obj3 = __instance.m_loadingProgress.transform.Find("BottomFade").Ref<Transform>();
			if (obj3 != null)
			{
				((Component)obj3).gameObject.SetActive(false);
			}
			Transform obj4 = __instance.m_loadingProgress.transform.Find("text_darken").Ref<Transform>();
			if (obj4 != null)
			{
				((Component)obj4).gameObject.SetActive(false);
			}
			__instance.m_teleportingProgress = __instance.m_loadingProgress;
			Transform val = ((Component)__instance).transform.Find("LoadingBlack");
			((Component)__instance.m_loadingImage).transform.SetParent(val, false);
			__instance.m_loadingTip.transform.SetParent(val, false);
			obj.SetParent(val, false);
		}

		[HarmonyPrefix]
		[HarmonyPatch("UpdateBlackScreen")]
		private static void UpdateBlackScreenPrefix(ref Hud __instance)
		{
			_loadingScreenState = ((Component)__instance.m_loadingImage).gameObject.activeInHierarchy;
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateBlackScreen")]
		private static void UpdateBlackScreenPostfix(Hud __instance)
		{
			if (!_loadingScreenState && ((Component)__instance.m_loadingScreen).gameObject.activeInHierarchy)
			{
				HudUtils.SetLoadingImage(__instance.m_loadingImage);
				HudUtils.SetLoadingTip(__instance.m_loadingTip);
				((MonoBehaviour)(object)__instance).ScaleLerpLoadingImage(__instance.m_loadingImage);
			}
		}
	}
	public static class PluginConfig
	{
		public static ConfigEntry<bool> IsModEnabled { get; private set; }

		public static ConfigEntry<bool> SceneLoaderUseLoadingImages { get; private set; }

		public static ConfigEntry<bool> SceneLoaderShowProgressText { get; private set; }

		public static ConfigEntry<bool> SceneLoaderCenterProgressIndicator { get; private set; }

		public static ConfigEntry<Color> LoadingImageBaseColor { get; private set; }

		public static ConfigEntry<bool> LoadingImageUseScaleLerp { get; private set; }

		public static ConfigEntry<float> LoadingImageScaleLerpEndScale { get; private set; }

		public static ConfigEntry<float> LoadingImageScaleLerpDuration { get; private set; }

		public static ConfigEntry<bool> LoadingScreenShowPanelSeparator { get; private set; }

		public static ConfigEntry<Vector2> LoadingScreenPanelSeparatorPosition { get; private set; }

		public static ConfigEntry<Vector2> LoadingTipTextPosition { get; private set; }

		public static ConfigEntry<int> LoadingTipTextFontSize { get; private set; }

		public static ConfigEntry<Color> LoadingTipTextColor { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod (restart required).");
			SceneLoaderUseLoadingImages = config.BindInOrder("SceneLoader", "useLoadingImages", defaultValue: true, "If set, will use custom loading images on the initial SceneLoader scene.");
			SceneLoaderShowProgressText = config.BindInOrder("SceneLoader", "showProgressText", defaultValue: true, "If set, will show loading progress text on the initial SceneLoader scene.");
			SceneLoaderCenterProgressIndicator = config.BindInOrder("SceneLoader", "centerProgressIndicator", defaultValue: true, "If set, will center the loading progress indicator (instead of being on the lower-right).");
			LoadingImageBaseColor = config.BindInOrder<Color>("LoadingImage.Image", "baseColor", Color.white, "The base color to apply to the loading image.");
			LoadingImageBaseColor.SettingChanged += OnLoadingImageConfigChanged;
			LoadingImageUseScaleLerp = config.BindInOrder("LoadingImage.ScaleLerp", "useScaleLerp", defaultValue: true, "If true, performs a scale lerp animation on the loading image.");
			LoadingImageScaleLerpEndScale = config.BindInOrder("LoadingImage.ScaleLerp", "lerpEndScale", 1.05f, "Image.scale ending factor for the scale lerp animation.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 1.5f));
			LoadingImageScaleLerpDuration = config.BindInOrder("LoadingImage.ScaleLerp", "lerpDuration", 15f, "Duration for the scale lerp animation.");
			LoadingTipTextPosition = config.BindInOrder<Vector2>("LoadingTip.Text", "textPosition", new Vector2(0f, 90f), "LoadingTip.Text.position value.");
			LoadingTipTextPosition.SettingChanged += OnLoadingTipConfigChanged;
			LoadingTipTextFontSize = config.BindInOrder("LoadingTip.Text", "textFontSize", 24, "LoadingTip.Text.fontSize value.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 64));
			LoadingTipTextFontSize.SettingChanged += OnLoadingTipConfigChanged;
			LoadingTipTextColor = config.BindInOrder<Color>("LoadingTip.Text", "textColor", Color.white, "LoadingTip.Text.color value.");
			LoadingTipTextColor.SettingChanged += OnLoadingTipConfigChanged;
			LoadingScreenShowPanelSeparator = config.BindInOrder("LoadingScreen.PanelSeparator", "showPanelSeparator", defaultValue: true, "Show the panel separator image on the loading screen.");
			LoadingScreenShowPanelSeparator.SettingChanged += OnPanelSeparatorConfigChanged;
			LoadingScreenPanelSeparatorPosition = config.BindInOrder<Vector2>("LoadingScreen.PanelSeparator", "panelSeparatorPosition", new Vector2(0f, 150f), "The position of the panel separator image on the loading screen.");
			LoadingScreenPanelSeparatorPosition.SettingChanged += OnPanelSeparatorConfigChanged;
		}

		private static void OnLoadingImageConfigChanged(object sender, EventArgs args)
		{
			HudUtils.SetupLoadingImage();
		}

		private static void OnLoadingTipConfigChanged(object sender, EventArgs args)
		{
			HudUtils.SetupTipText();
		}

		private static void OnPanelSeparatorConfigChanged(object sender, EventArgs args)
		{
			HudUtils.SetupPanelSeparator();
		}
	}
	[HarmonyPatch(typeof(SceneLoader))]
	internal static class SceneLoaderPatch
	{
		private static Image _loadingImage;

		private static TMP_Text _loadingText;

		private static float _startTime;

		private static float _lastImageTime;

		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		private static void StartPrefix(SceneLoader __instance)
		{
			_loadingImage = ((Component)__instance.gameLogo.transform.parent.Find("Bkg")).GetComponent<Image>();
			if (PluginConfig.SceneLoaderUseLoadingImages.Value && CustomAssets.LoadingImageFiles.Count > 0)
			{
				__instance._showLogos = false;
				__instance._showSaveNotification = false;
				__instance._showHealthWarning = false;
				HudUtils.SetupLoadingImage(_loadingImage);
				HudUtils.SetLoadingImage(_loadingImage);
				((MonoBehaviour)(object)__instance).ScaleLerpLoadingImage(_loadingImage);
				__instance.gameLogo = ((Component)_loadingImage).gameObject;
			}
			if (PluginConfig.SceneLoaderShowProgressText.Value)
			{
				_loadingText = Object.Instantiate<TMP_Text>(((Component)__instance.savingNotification).GetComponentInChildren<TMP_Text>(), ((Component)_loadingImage).transform.parent);
				HudUtils.SetupTipText(_loadingText);
				HudUtils.SetLoadingTip(_loadingText);
			}
			if (PluginConfig.SceneLoaderCenterProgressIndicator.Value)
			{
				SetupLoadingIndicator(LoadingIndicator.s_instance);
			}
			_startTime = Time.time;
			_lastImageTime = _startTime;
		}

		private static void SetupLoadingIndicator(LoadingIndicator indicator)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			indicator.m_showProgressIndicator = true;
			RectTransform component = ((Component)((Component)indicator.m_background).transform.parent).GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0f);
			component.anchorMax = new Vector2(0.5f, 0f);
			component.anchoredPosition = new Vector2(0f, 250f);
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void UpdatePostfix(SceneLoader __instance)
		{
			float time = Time.time;
			if (PluginConfig.SceneLoaderUseLoadingImages.Value && time - _lastImageTime >= 10f)
			{
				_lastImageTime = time;
				HudUtils.SetLoadingImage(_loadingImage);
				((MonoBehaviour)(object)__instance).ScaleLerpLoadingImage(_loadingImage);
			}
			if (PluginConfig.SceneLoaderShowProgressText.Value && Object.op_Implicit((Object)(object)_loadingText))
			{
				_loadingText.text = $"<b>{__instance._fakeProgress * 100f:F0}%</b>\n<size=-4>({time - _startTime:F1}s)</size>";
			}
		}
	}
}