Decompiled source of OverlayLayerFix v1.0.0

OverlayLayerFix.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using H1xl.Shared;
using MonoMod.RuntimeDetour;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OverlayLayerFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8d8b2cce3e1e58a03d5db381bb16048fe7bdbc28")]
[assembly: AssemblyProduct("OverlayLayerFix")]
[assembly: AssemblyTitle("OverlayLayerFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace H1xl.Shared
{
	internal static class Log
	{
		private static ManualLogSource source;

		private static readonly HashSet<string> logged = new HashSet<string>();

		internal static Func<bool> IsVerbose = null;

		internal static bool Verbose
		{
			get
			{
				if (IsVerbose != null)
				{
					return IsVerbose();
				}
				return false;
			}
		}

		internal static void Init(ManualLogSource logger)
		{
			source = logger;
		}

		internal static void Info(object message)
		{
			ManualLogSource obj = source;
			if (obj != null)
			{
				obj.LogInfo(message);
			}
		}

		internal static void Warn(object message)
		{
			ManualLogSource obj = source;
			if (obj != null)
			{
				obj.LogWarning(message);
			}
		}

		internal static void Error(object message)
		{
			ManualLogSource obj = source;
			if (obj != null)
			{
				obj.LogError(message);
			}
		}

		internal static void Debug(object message)
		{
			if (Verbose)
			{
				ManualLogSource obj = source;
				if (obj != null)
				{
					obj.LogInfo(message);
				}
			}
		}

		internal static bool ErrorOnce(string key, object message)
		{
			if (!logged.Add(key))
			{
				return false;
			}
			ManualLogSource obj = source;
			if (obj != null)
			{
				obj.LogError(message);
			}
			return true;
		}

		internal static bool WarnOnce(string key, object message)
		{
			if (!logged.Add(key))
			{
				return false;
			}
			ManualLogSource obj = source;
			if (obj != null)
			{
				obj.LogWarning(message);
			}
			return true;
		}
	}
	internal static class HookUtil
	{
		private static readonly List<Hook> hooks = new List<Hook>();

		internal static bool Add(GameMethod method, Type handlerType, string handler)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			MethodInfo methodInfo = method.Find();
			if (methodInfo == null)
			{
				Log.Warn($"{method} not found (game updated?). The feature using it is disabled.");
				return false;
			}
			MethodInfo method2 = handlerType.GetMethod(handler, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (method2 == null)
			{
				Log.Error($"Hook handler {handlerType.Name}.{handler} not found (mod bug). {method} is not hooked.");
				return false;
			}
			try
			{
				hooks.Add(new Hook((MethodBase)methodInfo, method2));
				return true;
			}
			catch (Exception arg)
			{
				Log.Error($"Failed to hook {method}: {arg}");
				return false;
			}
		}

		internal static void DisposeAll()
		{
			foreach (Hook hook in hooks)
			{
				hook.Dispose();
			}
			hooks.Clear();
		}
	}
	internal abstract class GameMember
	{
		internal const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		internal readonly Type Type;

		internal readonly string Name;

		protected GameMember(Type type, string name)
		{
			Type = type;
			Name = name;
		}

		internal abstract MemberInfo FindMember();

		internal static Type Nested(Type outer, string name)
		{
			return outer.GetNestedType(name, BindingFlags.Public | BindingFlags.NonPublic);
		}

		public override string ToString()
		{
			return (Type?.Name ?? "<missing type>") + "." + Name;
		}
	}
	internal sealed class GameMethod : GameMember
	{
		internal readonly Type[] Args;

		internal GameMethod(Type type, string name, params Type[] args)
			: base(type, name)
		{
			Args = args;
		}

		internal MethodInfo Find()
		{
			try
			{
				return Type?.GetMethod(Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Args, null);
			}
			catch (Exception)
			{
				return null;
			}
		}

		internal override MemberInfo FindMember()
		{
			return Find();
		}
	}
	internal sealed class GameField : GameMember
	{
		internal GameField(Type type, string name)
			: base(type, name)
		{
		}

		internal FieldInfo Find()
		{
			try
			{
				return Type?.GetField(Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
			catch (Exception)
			{
				return null;
			}
		}

		internal override MemberInfo FindMember()
		{
			return Find();
		}
	}
	internal sealed class GameProperty : GameMember
	{
		internal GameProperty(Type type, string name)
			: base(type, name)
		{
		}

		internal PropertyInfo Find()
		{
			try
			{
				return Type?.GetProperty(Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
			catch (Exception)
			{
				return null;
			}
		}

		internal override MemberInfo FindMember()
		{
			return Find();
		}
	}
	internal static class RooPage
	{
		internal const string GUID = "com.rune580.riskofoptions";

		internal static void TryRegister(Action register)
		{
			if (!Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				return;
			}
			try
			{
				register();
			}
			catch (Exception ex)
			{
				Log.Error("Risk Of Options page failed: " + ex);
			}
		}
	}
	internal static class RooHelper
	{
		internal static void Page(string description, string pluginFolder)
		{
			ModSettingsManager.SetModDescription(description);
			Sprite val = LoadIcon(Path.Combine(pluginFolder, "icon.png"));
			if (Object.op_Implicit((Object)(object)val))
			{
				ModSettingsManager.SetModIcon(val);
			}
		}

		internal static void CheckBox(ConfigEntry<bool> entry, IsDisabledDelegate disabled = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(entry, new CheckBoxConfig
			{
				checkIfDisabled = disabled
			}));
		}

		internal static void Choice(ConfigEntryBase entry, IsDisabledDelegate disabled = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new ChoiceOption(entry, new ChoiceConfig
			{
				checkIfDisabled = disabled
			}));
		}

		internal static void Key(ConfigEntry<KeyboardShortcut> entry)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new KeyBindOption(entry));
		}

		internal static void IntSlider(ConfigEntry<int> entry, int min, int max, string format = "{0}", IsDisabledDelegate disabled = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0028: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(entry, new IntSliderConfig
			{
				min = min,
				max = max,
				formatString = format,
				checkIfDisabled = disabled
			}));
		}

		internal static void Slider(ConfigEntry<float> entry, float min, float max, float step, string format, IsDisabledDelegate disabled = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(entry, new StepSliderConfig
			{
				min = min,
				max = max,
				increment = step,
				FormatString = format,
				checkIfDisabled = disabled
			}));
		}

		internal static void Text(ConfigEntry<string> entry, IsDisabledDelegate disabled = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(entry, new InputFieldConfig
			{
				submitOn = (SubmitEnum)6,
				checkIfDisabled = disabled
			}));
		}

		private static Sprite LoadIcon(string path)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!File.Exists(path))
			{
				return null;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
			{
				return null;
			}
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
}
namespace OverlayLayerFix
{
	internal static class GameMembers
	{
		internal static readonly GameMethod CharacterModel_UpdateRendererMaterials = new GameMethod(typeof(CharacterModel), "UpdateRendererMaterials", typeof(Renderer), typeof(Material), typeof(bool));
	}
	internal static class OverlayPatcher
	{
		private sealed class Info
		{
			public bool Supported;

			public bool HasOffset;

			public float Offset;

			public int Cull;

			public int Queue;
		}

		private delegate void OrigUpdateRendererMaterials(CharacterModel self, Renderer renderer, Material defaultMaterial, bool ignoreOverlays);

		private const string CloudRemap = "Hopoo Games/FX/Cloud Remap";

		private const string Distortion = "Hopoo Games/FX/Distortion";

		private const int CullFront = 1;

		private const int CullBack = 2;

		private const int ZTestLess = 2;

		private const int ZTestLEqual = 4;

		private const int TransparentQueue = 2500;

		private const int MaxCachedMaterials = 1024;

		private static readonly int OffsetAmountId = Shader.PropertyToID("_OffsetAmount");

		private static readonly int ShellOffsetOnId = Shader.PropertyToID("_ShellOffsetOn");

		private static readonly int CullId = Shader.PropertyToID("_Cull");

		private static readonly int ZTestId = Shader.PropertyToID("_ZTest");

		private static readonly int BiasFactorId = Shader.PropertyToID("_DepthBiasFactor");

		private static readonly int BiasUnitsId = Shader.PropertyToID("_DepthBiasUnits");

		private static readonly int PullId = Shader.PropertyToID("_PullDistance");

		private static Shader shellShader;

		private static Shader maskShader;

		public static bool RefreshPending;

		private static readonly Dictionary<Material, Info> infos = new Dictionary<Material, Info>();

		private static readonly Dictionary<(int offsetBits, bool useOffset, int cull, int queue), Material> prepasses = new Dictionary<(int, bool, int, int), Material>();

		private static readonly Dictionary<int, Material> masks = new Dictionary<int, Material>();

		private static readonly HashSet<Renderer> thicknessRenderers = new HashSet<Renderer>();

		private static readonly List<Material> current = new List<Material>(8);

		private static readonly List<Material> result = new List<Material>(24);

		private static readonly Material[][] arrays = new Material[32][];

		private static readonly MaterialPropertyBlock block = new MaterialPropertyBlock();

		public static bool Install(Shader shell, Shader mask)
		{
			shellShader = shell;
			maskShader = mask;
			if (!HookUtil.Add(GameMembers.CharacterModel_UpdateRendererMaterials, typeof(OverlayPatcher), "OnUpdateRendererMaterials"))
			{
				Log.Error("CharacterModel.UpdateRendererMaterials(Renderer, Material, bool) could not be hooked. Mod disabled.");
				return false;
			}
			Settings.Changed += delegate
			{
				RefreshPending = true;
			};
			return true;
		}

		public static void Refresh()
		{
			RefreshPending = false;
			foreach (Material value in prepasses.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					value.SetFloat(BiasFactorId, Settings.BiasFactorEntry.Value);
					value.SetFloat(BiasUnitsId, Settings.BiasUnitsEntry.Value);
				}
			}
			foreach (Material value2 in masks.Values)
			{
				if (Object.op_Implicit((Object)(object)value2))
				{
					value2.SetFloat(PullId, Settings.PullEntry.Value);
				}
			}
			if (!Settings.FixShells || Settings.ShellThickness <= 0f)
			{
				foreach (Renderer thicknessRenderer in thicknessRenderers)
				{
					if (Object.op_Implicit((Object)(object)thicknessRenderer))
					{
						thicknessRenderer.SetPropertyBlock((MaterialPropertyBlock)null);
					}
				}
				thicknessRenderers.Clear();
			}
			CharacterModel[] array = Object.FindObjectsOfType<CharacterModel>();
			for (int i = 0; i < array.Length; i++)
			{
				array[i].forceUpdate = true;
			}
		}

		private static void OnUpdateRendererMaterials(OrigUpdateRendererMaterials orig, CharacterModel self, Renderer renderer, Material defaultMaterial, bool ignoreOverlays)
		{
			orig(self, renderer, defaultMaterial, ignoreOverlays);
			bool flag = false;
			if (Settings.Enabled.Value)
			{
				try
				{
					flag = Process(self, renderer);
				}
				catch (Exception ex)
				{
					Log.ErrorOnce("overlay-pass", "Overlay pass failed: " + ex);
				}
			}
			if (!flag && thicknessRenderers.Remove(renderer))
			{
				renderer.SetPropertyBlock((MaterialPropertyBlock)null);
			}
		}

		private static bool Process(CharacterModel model, Renderer renderer)
		{
			if (!(renderer is SkinnedMeshRenderer) && !(renderer is MeshRenderer))
			{
				return false;
			}
			if (Settings.Scope == Scope.PlayersOnly && (!Object.op_Implicit((Object)(object)model.body) || !model.body.isPlayerControlled))
			{
				return false;
			}
			bool fixShells = Settings.FixShells;
			bool fixCloak = Settings.FixCloak;
			if (!fixShells && !fixCloak)
			{
				return false;
			}
			current.Clear();
			renderer.GetSharedMaterials(current);
			int count = current.Count;
			if (count == 0)
			{
				return false;
			}
			float shellThickness = Settings.ShellThickness;
			bool flag = fixShells && Settings.SilhouetteOnly;
			if (flag)
			{
				for (int i = 0; i < count; i++)
				{
					Material val = current[i];
					if (Object.op_Implicit((Object)(object)val))
					{
						Info info = GetInfo(val);
						if (info.Supported && info.HasOffset && info.Cull != 1)
						{
							flag = false;
							break;
						}
					}
				}
			}
			result.Clear();
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			for (int j = 0; j < count; j++)
			{
				Material val2 = current[j];
				if (Object.op_Implicit((Object)(object)val2))
				{
					Info info2 = GetInfo(val2);
					if (info2.Supported)
					{
						bool flag5 = fixShells && info2.HasOffset && (info2.Offset > 0f || shellThickness > 0f);
						bool flag6 = fixCloak && j == 0 && !info2.HasOffset && info2.Queue > 2500;
						if (flag5 || flag6)
						{
							if (flag5 && flag && info2.Cull == 1 && !flag4)
							{
								result.Add(GetMask(info2.Queue - 2));
								flag4 = true;
							}
							result.Add(GetPrepass(flag5 ? info2.Offset : 0f, flag5, info2.Cull, info2.Queue - 1));
							flag3 = flag3 || flag5;
							flag2 = true;
						}
					}
				}
				result.Add(val2);
			}
			if (!flag2)
			{
				return false;
			}
			bool flag7 = flag3 && shellThickness > 0f;
			if (flag7)
			{
				renderer.GetPropertyBlock(block);
				block.SetFloat(OffsetAmountId, shellThickness);
				renderer.SetPropertyBlock(block);
				if (thicknessRenderers.Add(renderer) && thicknessRenderers.Count > 1024)
				{
					thicknessRenderers.RemoveWhere((Renderer r) => !Object.op_Implicit((Object)(object)r));
				}
			}
			int count2 = result.Count;
			if (count2 >= arrays.Length)
			{
				return flag7;
			}
			Material[] array = arrays[count2] ?? (arrays[count2] = (Material[])(object)new Material[count2]);
			result.CopyTo(array);
			renderer.sharedMaterials = array;
			return flag7;
		}

		private static Info GetInfo(Material m)
		{
			if (infos.TryGetValue(m, out var value))
			{
				return value;
			}
			if (infos.Count >= 1024)
			{
				PurgeDestroyed();
			}
			value = new Info
			{
				Cull = 2,
				Queue = m.renderQueue
			};
			Shader shader = m.shader;
			string text = (Object.op_Implicit((Object)(object)shader) ? ((Object)shader).name : string.Empty);
			if (text == "Hopoo Games/FX/Cloud Remap")
			{
				int num = (m.HasProperty(ZTestId) ? Mathf.RoundToInt(m.GetFloat(ZTestId)) : 4);
				value.Supported = num == 4 || num == 2;
				value.HasOffset = m.IsKeywordEnabled("VERTEXOFFSET");
				value.Offset = ((value.HasOffset && m.HasProperty(OffsetAmountId)) ? m.GetFloat(OffsetAmountId) : 0f);
				if (m.HasProperty(CullId))
				{
					value.Cull = Mathf.RoundToInt(m.GetFloat(CullId));
				}
			}
			else if (text == "Hopoo Games/FX/Distortion")
			{
				value.Supported = true;
			}
			infos[m] = value;
			return value;
		}

		private static void PurgeDestroyed()
		{
			List<Material> list = new List<Material>();
			foreach (Material key2 in infos.Keys)
			{
				if (!Object.op_Implicit((Object)(object)key2))
				{
					list.Add(key2);
				}
			}
			foreach (Material item in list)
			{
				infos.Remove(item);
			}
			if (infos.Count >= 1024)
			{
				infos.Clear();
			}
		}

		private static Material GetPrepass(float offset, bool useOffset, int cull, int queue)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			(int, bool, int, int) key = (BitConverter.SingleToInt32Bits(offset), useOffset, cull, queue);
			if (prepasses.TryGetValue(key, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			value = new Material(shellShader)
			{
				name = "OverlayLayerFix_ShellDepth",
				renderQueue = queue,
				hideFlags = (HideFlags)61
			};
			value.SetFloat(OffsetAmountId, offset);
			value.SetFloat(ShellOffsetOnId, useOffset ? 1f : 0f);
			value.SetFloat(CullId, (float)cull);
			value.SetFloat(BiasFactorId, Settings.BiasFactorEntry.Value);
			value.SetFloat(BiasUnitsId, Settings.BiasUnitsEntry.Value);
			prepasses[key] = value;
			return value;
		}

		private static Material GetMask(int queue)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (masks.TryGetValue(queue, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			value = new Material(maskShader)
			{
				name = "OverlayLayerFix_SilhouetteMask",
				renderQueue = queue,
				hideFlags = (HideFlags)61
			};
			value.SetFloat(PullId, Settings.PullEntry.Value);
			masks[queue] = value;
			return value;
		}
	}
	[BepInPlugin("com.H1xl.OverlayLayerFix", "OverlayLayerFix", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string GUID = "com.H1xl.OverlayLayerFix";

		public const string NAME = "OverlayLayerFix";

		public const string VERSION = "1.0.0";

		private void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			Settings.Init(((BaseUnityPlugin)this).Config);
			if (!LoadShaders(out var shell, out var mask) || !OverlayPatcher.Install(shell, mask))
			{
				((Behaviour)this).enabled = false;
				return;
			}
			string folder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			RooPage.TryRegister(delegate
			{
				RiskOfOptionsCompat.Register(folder);
			});
			Log.Info("OverlayLayerFix 1.0.0 ready.");
		}

		private void Update()
		{
			if (OverlayPatcher.RefreshPending)
			{
				OverlayPatcher.Refresh();
			}
		}

		private static bool LoadShaders(out Shader shell, out Shader mask)
		{
			shell = (mask = null);
			byte[] array;
			using (Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("OverlayLayerFix.overlaylayerfix.bundle"))
			{
				if (stream == null)
				{
					Log.Error("Embedded shader bundle is missing. Mod disabled.");
					return false;
				}
				using MemoryStream memoryStream = new MemoryStream((int)stream.Length);
				stream.CopyTo(memoryStream);
				array = memoryStream.ToArray();
			}
			AssetBundle val = AssetBundle.LoadFromMemory(array);
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.Error("Could not load the shader bundle. Mod disabled.");
				return false;
			}
			shell = val.LoadAsset<Shader>("ShellDepth");
			mask = val.LoadAsset<Shader>("SilhouetteMask");
			val.Unload(false);
			if (!Object.op_Implicit((Object)(object)shell) || !shell.isSupported || !Object.op_Implicit((Object)(object)mask) || !mask.isSupported)
			{
				Log.Error("Shaders are missing or not supported by this graphics API (Direct3D 11 is required). Mod disabled.");
				return false;
			}
			return true;
		}
	}
	internal static class RiskOfOptionsCompat
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static IsDisabledDelegate <>9__0_0;

			internal bool <Register>b__0_0()
			{
				if (!ShellsOff())
				{
					return !Settings.SilhouetteEntry.Value;
				}
				return true;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void Register(string pluginFolder)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			RooHelper.Page("Shield, Immune, elite and invisibility overlays are drawn as one clean layer instead of piling up on detailed character models and skins. Turn Enabled off to compare with vanilla.", pluginFolder);
			RooHelper.CheckBox(Settings.Enabled);
			RooHelper.Choice((ConfigEntryBase)(object)Settings.ScopeEntry, new IsDisabledDelegate(Off));
			RooHelper.CheckBox(Settings.FixShellsEntry, new IsDisabledDelegate(Off));
			RooHelper.CheckBox(Settings.FixCloakEntry, new IsDisabledDelegate(Off));
			RooHelper.Slider(Settings.ThicknessEntry, 0f, 0.2f, 0.005f, "{0:0.000}", new IsDisabledDelegate(ShellsOff));
			RooHelper.CheckBox(Settings.SilhouetteEntry, new IsDisabledDelegate(ShellsOff));
			ConfigEntry<float> pullEntry = Settings.PullEntry;
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				IsDisabledDelegate val = () => ShellsOff() || !Settings.SilhouetteEntry.Value;
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			RooHelper.Slider(pullEntry, 0.02f, 1f, 0.01f, "{0:0.00} m", (IsDisabledDelegate)obj);
			RooHelper.Slider(Settings.BiasFactorEntry, 0f, 2f, 0.1f, "{0:0.0}", new IsDisabledDelegate(Off));
			RooHelper.Slider(Settings.BiasUnitsEntry, 0f, 10f, 1f, "{0:0}", new IsDisabledDelegate(Off));
		}

		private static bool Off()
		{
			return !Settings.Enabled.Value;
		}

		private static bool ShellsOff()
		{
			return !Settings.FixShells;
		}
	}
	public enum Scope
	{
		AllCharacters,
		PlayersOnly
	}
	internal static class Settings
	{
		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<Scope> ScopeEntry;

		public static ConfigEntry<bool> FixShellsEntry;

		public static ConfigEntry<bool> FixCloakEntry;

		public static ConfigEntry<float> ThicknessEntry;

		public static ConfigEntry<bool> SilhouetteEntry;

		public static ConfigEntry<float> PullEntry;

		public static ConfigEntry<float> BiasFactorEntry;

		public static ConfigEntry<float> BiasUnitsEntry;

		public static bool FixShells
		{
			get
			{
				if (Enabled.Value)
				{
					return FixShellsEntry.Value;
				}
				return false;
			}
		}

		public static bool FixCloak
		{
			get
			{
				if (Enabled.Value)
				{
					return FixCloakEntry.Value;
				}
				return false;
			}
		}

		public static Scope Scope => ScopeEntry.Value;

		public static float ShellThickness => ThicknessEntry.Value;

		public static bool SilhouetteOnly => SilhouetteEntry.Value;

		public static event Action Changed;

		public static void Init(ConfigFile cfg)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			Enabled = cfg.Bind<bool>("General", "Enabled", true, "Master switch. Turn it off to compare with the vanilla overlays.");
			ScopeEntry = cfg.Bind<Scope>("General", "Scope", Scope.AllCharacters, "AllCharacters: every character. PlayersOnly: only bodies controlled by players.");
			FixShellsEntry = cfg.Bind<bool>("Overlays", "SingleLayerShells", true, "Glowing overlay shells (shield, Immune, elite and buff overlays) are drawn as one layer on the outermost surface instead of once per mesh layer (hair, clothes, body).");
			FixCloakEntry = cfg.Bind<bool>("Overlays", "SingleLayerCloak", true, "The same for invisibility and other see-through materials (Old War Stealthkit, Bandit's cloak).");
			ThicknessEntry = cfg.Bind<float>("Overlays", "ShellThickness", 0f, new ConfigDescription("0 keeps each overlay's own thickness (shield 0.04, Immune 0.1). Above 0 it replaces the thickness of every overlay; 0.015-0.025 gives a thin outline.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.2f), Array.Empty<object>()));
			SilhouetteEntry = cfg.Bind<bool>("Experimental", "SilhouetteOnly", false, "The shield is shown only as an outline around the character, never over the body.");
			PullEntry = cfg.Bind<float>("Experimental", "SilhouettePullDistance", 0.25f, new ConfigDescription("SilhouetteOnly: how far (metres) in front of the body shield parts are still hidden.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.02f, 1f), Array.Empty<object>()));
			BiasFactorEntry = cfg.Bind<float>("Advanced", "DepthBiasFactor", 0f, new ConfigDescription("Raise it (0.5-1) only if an overlay flickers or shows small holes.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			BiasUnitsEntry = cfg.Bind<float>("Advanced", "DepthBiasUnits", 2f, new ConfigDescription("Constant depth bias of the hidden depth pass.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			cfg.SettingChanged += delegate
			{
				Settings.Changed?.Invoke();
			};
		}
	}
}