OBS.dll

Decompiled 2 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Badgers_Shading_Overhaul.Gui;
using Badgers_Shading_Overhaul.Gui.GUIScriptComponents;
using Badgers_Shading_Overhaul.Properties;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
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: AssemblyTitle("Badgers_Shading_Overhaul")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Badgers_Shading_Overhaul")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d972bffe-cbf4-4b17-8276-007e986e6195")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Badgers_Shading_Overhaul
{
	internal class BVTAssets
	{
		private AssetBundle GUIAssetBundle;

		private Dictionary<string, Mesh> bvtMeshes = new Dictionary<string, Mesh>();

		private GameObject BVTCanvas = null;

		private GameObject BVTSliderWidget = null;

		private GameObject BVTButtonWidget = null;

		private GameObject BVTLabelWidget = null;

		private GameObject BVTToggleWidget = null;

		private GameObject ClockWidget = null;

		public bool assetsLoaded = false;

		public BVTAssets()
		{
			LoadAssets();
		}

		public void LoadAssets()
		{
			byte[] guiassets = Resources.guiassets;
			GUIAssetBundle = AssetBundle.LoadFromMemory(guiassets);
			if (!((Object)(object)GUIAssetBundle != (Object)null))
			{
				return;
			}
			bLog.Log("Loading GUI Assets", force: true);
			string[] allAssetNames = GUIAssetBundle.GetAllAssetNames();
			foreach (string text in allAssetNames)
			{
				GameObject val = GUIAssetBundle.LoadAsset<GameObject>(text);
				switch (((Object)val).name)
				{
				case "Canvas":
					BVTCanvas = val;
					break;
				case "SliderWidget":
					BVTSliderWidget = val;
					break;
				case "ButtonWidget":
					BVTButtonWidget = val;
					break;
				case "LabelWidget":
					BVTLabelWidget = val;
					break;
				case "ToggleWidget":
					BVTToggleWidget = val;
					break;
				}
			}
			assetsLoaded = true;
			GUIAssetBundle.Unload(false);
			guiassets = null;
		}

		public GameObject GetCanvas()
		{
			if ((Object)(object)BVTCanvas != (Object)null)
			{
				return BVTCanvas;
			}
			return null;
		}

		public GameObject GetSliderWidget()
		{
			if ((Object)(object)BVTSliderWidget != (Object)null)
			{
				return BVTSliderWidget;
			}
			return null;
		}

		public GameObject GetButtonWidget()
		{
			if ((Object)(object)BVTButtonWidget != (Object)null)
			{
				return BVTButtonWidget;
			}
			return null;
		}

		public GameObject GetLabelWidget()
		{
			if ((Object)(object)BVTLabelWidget != (Object)null)
			{
				return BVTLabelWidget;
			}
			return null;
		}

		public GameObject GetToggleWidget()
		{
			if ((Object)(object)BVTToggleWidget != (Object)null)
			{
				return BVTToggleWidget;
			}
			return null;
		}

		public GameObject GetClockWidget()
		{
			if ((Object)(object)ClockWidget != (Object)null)
			{
				return ClockWidget;
			}
			return null;
		}
	}
	public class CameraPostProcess : MonoBehaviour
	{
		private RenderTexture rt = null;

		private void OnPreRender()
		{
			Mod.mainCamera.targetTexture = rt;
		}

		private void OnRenderImage(RenderTexture src, RenderTexture dest)
		{
			if ((Object)(object)Mod.PostProcessMaterial != (Object)null && Mod.config.CleanShadingOn.Value)
			{
				Mod.mainCamera.targetTexture = null;
				Graphics.Blit((Texture)(object)src, (RenderTexture)null, Mod.PostProcessMaterial);
			}
			else
			{
				Graphics.Blit((Texture)(object)src, dest);
			}
		}
	}
	internal class Config
	{
		private ConfigFile cf = new ConfigFile(Mod.ConfigFile, true);

		public ConfigEntry<float> AmbientLight;

		public ConfigEntry<bool> CleanShadingOn;

		public ConfigEntry<KeyCode> ModToggleKey;

		public ConfigEntry<bool> DebugInfo;

		public ConfigEntry<float> SpecularIntensity;

		public ConfigEntry<float> ColorTemp;

		public ConfigEntry<float> ColorSaturation;

		public Config()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			CleanShadingOn = cf.Bind<bool>("Mod", "Enable Smooth Shading", true, "Enable Smooth Shading");
			ModToggleKey = cf.Bind<KeyCode>("Mod", "Key to enable/disable mod", (KeyCode)281, "Mod Toggle Key");
			DebugInfo = cf.Bind<bool>("Mod", "Enable debug information", false, "Enable debug information");
			SpecularIntensity = cf.Bind<float>("Visual", "Specular Intensity", 0f, "Specular Intensity");
			AmbientLight = cf.Bind<float>("Visual", "Ambient Light Modifier", 0.9f, "Ambient Light Modifier");
			ColorTemp = cf.Bind<float>("Visual", "Colour Temperature", 0f, "Colour Temperature");
			ColorSaturation = cf.Bind<float>("Visual", "Colour Saturation", 1f, "Colour Saturation");
		}
	}
	internal class MouseDragComponent : MonoBehaviour, IDragHandler, IEventSystemHandler, IBeginDragHandler, IEndDragHandler
	{
		private Vector2 dragStartPosition;

		private Vector2 menuPos;

		private Vector2 pointerOffset;

		public void OnBeginDrag(PointerEventData eventData)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			menuPos = Vector2.op_Implicit(((Transform)((Component)this).GetComponent<RectTransform>()).position);
			dragStartPosition = eventData.position;
			pointerOffset = dragStartPosition - menuPos;
		}

		public void OnDrag(PointerEventData eventData)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_000a: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector2 position = eventData.position;
			Vector2 val = position - dragStartPosition;
			menuPos += val;
			((Transform)((Component)this).GetComponent<RectTransform>()).position = Vector2.op_Implicit(menuPos + val);
			dragStartPosition = position;
		}

		public void OnEndDrag(PointerEventData eventData)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			((Transform)((Component)this).GetComponent<RectTransform>()).position = Vector2.op_Implicit(eventData.position - pointerOffset);
		}
	}
	internal class HarmonyPatches
	{
		[HarmonyPatch(typeof(Player), "Awake")]
		private class Player_Awake
		{
			private static void Postfix(Player __instance)
			{
				Mod.UpdateShader();
				Mod.AddConsoleCommands();
				Mod.CreateUI();
				Mod.AddCameraComponents();
				Mod.CreatePostProcessShader();
				Mod.SetShaderProperties();
			}
		}

		[HarmonyPatch(typeof(EnvMan), "Awake")]
		private class EnvMan_Awake
		{
			[HarmonyPriority(0)]
			private static void Postfix(EnvMan __instance)
			{
				Mod.envMan = __instance;
				bLog.Log("Preparing envs");
				Mod.dayIntensities.Clear();
				Mod.nightIntensities.Clear();
				bLog.Log("Existing envs");
				foreach (EnvSetup environment in __instance.m_environments)
				{
					bLog.Log("Preparing env " + environment.m_name);
					if (!Mod.dayIntensities.ContainsKey(environment))
					{
						Mod.dayIntensities.Add(environment, environment.m_lightIntensityDay);
						Mod.nightIntensities.Add(environment, environment.m_lightIntensityNight);
					}
					else
					{
						bLog.Log("Couldn't add environment " + environment.m_name + " as it has already been added.");
					}
				}
			}
		}

		[HarmonyPatch(typeof(EnvMan), "SetEnv")]
		private class EnvMan_SetEnv
		{
			private static void Postfix(EnvMan __instance)
			{
				Mod.UpdateEnvs(__instance);
			}
		}

		private readonly Harmony harmony = new Harmony("Badgers.ShadingOverhaul");

		public HarmonyPatches()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			harmony.PatchAll();
		}
	}
	internal class bLog
	{
		public static bool debugEnabled = Mod.config.DebugInfo.Value;

		public static string logLabel = "BSO";

		public static void Log(string LogMessage, bool force = false)
		{
			if (debugEnabled || force)
			{
				Debug.Log((object)(logLabel + ": " + LogMessage));
			}
		}
	}
	[BepInPlugin("Badgers.ShadingOverhaul", "Badgers Shading Overhaul", "0.3.4")]
	[BepInProcess("valheim.exe")]
	public class Badgers_Shading_Overhaul : BaseUnityPlugin
	{
		private HarmonyPatches ShadingOverhaul;

		private byte[] abBytes;

		private AssetBundle ab;

		private void Awake()
		{
			ShadingOverhaul = new HarmonyPatches();
			abBytes = Resources.deferredshaders;
			ab = AssetBundle.LoadFromMemory(abBytes);
			Mod.ReplacementShader = ab.LoadAsset<Shader>("Internal-DeferredShading");
			Mod.PostProcessShader = ab.LoadAsset<Shader>("PostProcess");
			ab.Unload(false);
			abBytes = null;
			Mod.OriginalShader = GraphicsSettings.GetCustomShader((BuiltinShaderType)0);
		}

		private void Update()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Player.m_localPlayer == (Object)null) || Mod.DevMode)
			{
				if (Input.GetKeyDown(Mod.config.ModToggleKey.Value))
				{
					Mod.UI.ToggleMenu();
				}
				if (Input.GetKeyDown((KeyCode)27) && Mod.UI.showMenu)
				{
					Mod.UI.ToggleMenu();
				}
			}
		}
	}
	internal static class Mod
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__16_0;

			internal void <AddConsoleCommands>b__16_0(ConsoleEventArgs args)
			{
				float value = default(float);
				args.TryParameterFloat(1, ref value);
				config.AmbientLight.Value = value;
			}
		}

		public static string ConfigPath = Paths.ConfigPath;

		public static string PluginPath = Paths.PluginPath;

		public static string ConfigFile = Path.Combine(ConfigPath, "BadgersShadingOverhaul.cfg");

		public static Config config = new Config();

		private static BVTAssets bvtAssets = new BVTAssets();

		public static BVTUI UI;

		private static List<string> Category = new List<string> { "Mod Config" };

		public static Dictionary<EnvSetup, float> dayIntensities = new Dictionary<EnvSetup, float>();

		public static Dictionary<EnvSetup, float> nightIntensities = new Dictionary<EnvSetup, float>();

		public static Shader ReplacementShader;

		public static Shader OriginalShader;

		public static Shader PostProcessShader;

		public static Material PostProcessMaterial;

		public static Camera mainCamera;

		public static EnvMan envMan;

		public static bool DevMode = false;

		public static void AddConsoleCommands()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			//IL_002a: Expected O, but got Unknown
			object obj = <>c.<>9__16_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					float value = default(float);
					args.TryParameterFloat(1, ref value);
					config.AmbientLight.Value = value;
				};
				<>c.<>9__16_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("setambientlight", "Set the ambient light modifier", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}

		public static void UpdateEnvs(EnvMan instance)
		{
			if ((Object)(object)instance != (Object)null && dayIntensities.ContainsKey(instance.m_currentEnv))
			{
				if (config.CleanShadingOn.Value)
				{
					instance.m_currentEnv.m_lightIntensityDay = dayIntensities[instance.m_currentEnv] * config.AmbientLight.Value;
					instance.m_currentEnv.m_lightIntensityNight = nightIntensities[instance.m_currentEnv] * config.AmbientLight.Value;
				}
				else
				{
					instance.m_currentEnv.m_lightIntensityDay = dayIntensities[instance.m_currentEnv];
					instance.m_currentEnv.m_lightIntensityNight = nightIntensities[instance.m_currentEnv];
				}
			}
		}

		public static void SetShaderProperties()
		{
			Shader.SetGlobalFloat("_BSOSpecularIntensity", 1f + config.SpecularIntensity.Value * 0.05f);
		}

		public static void UpdateShader()
		{
			bLog.Log("Updating Shader");
			if (config.CleanShadingOn.Value)
			{
				bLog.Log("Using New Shader");
				GraphicsSettings.SetCustomShader((BuiltinShaderType)0, ReplacementShader);
			}
			else
			{
				GraphicsSettings.SetCustomShader((BuiltinShaderType)0, OriginalShader);
			}
		}

		public static void CreateUI()
		{
			UI = new BVTUI(bvtAssets);
			if (!UI.UICreated)
			{
				return;
			}
			bLog.Log("Creating UI Panels", force: true);
			UI.SetupMainPanel(HandleCanvasDropDown, Category, "Shading Overhaul Configuration");
			foreach (string item in Category)
			{
				string text = item;
				string text2 = text;
				if (text2 == "Mod Config")
				{
					CreateModConfig(item);
				}
			}
		}

		private static void CreateModConfig(string PanelName)
		{
			UIPanel uIPanel = UI.CreateUIPanel(PanelName);
			if (uIPanel != null)
			{
				uIPanel.AddToggleWidget("Mod Enabled", config.CleanShadingOn.Value, HandleModToggle);
				uIPanel.AddSliderWidget(ref config.SpecularIntensity, -1f, 1f, HandleSpecIntensity);
				uIPanel.AddSliderWidget(ref config.AmbientLight, 0f, 2f, HandleAmbientLight);
				uIPanel.AddSliderWidget(ref config.ColorTemp, -1f, 1f, HandleColorTemp);
				uIPanel.AddSliderWidget(ref config.ColorSaturation, 0f, 2f, HandleColorSaturation);
				UI.AddUIPanel(uIPanel, SetActive: true);
			}
		}

		private static void HandleColorSaturation(float value, string title)
		{
			if ((Object)(object)PostProcessMaterial != (Object)null)
			{
				PostProcessMaterial.SetFloat("_Saturation", value);
			}
		}

		private static void HandleColorTemp(float value, string title)
		{
			if ((Object)(object)PostProcessMaterial != (Object)null)
			{
				PostProcessMaterial.SetFloat("_Temperature", value);
			}
		}

		private static void HandleAmbientLight(float value, string title)
		{
			config.AmbientLight.Value = value;
			UpdateEnvs(envMan);
		}

		private static void HandleSpecIntensity(float value, string title)
		{
			config.SpecularIntensity.Value = value;
			SetShaderProperties();
		}

		private static void HandleModToggle(Toggle t)
		{
			config.CleanShadingOn.Value = t.isOn;
			UpdateShader();
		}

		private static void HandleCanvasDropDown(Dropdown dd)
		{
			bLog.Log("setting " + Category[dd.value] + " panel active");
			UI.SetActiveUIPanel(Category[dd.value]);
		}

		public static void AddCameraComponents()
		{
			mainCamera = Utils.GetMainCamera();
			if ((Object)(object)mainCamera != (Object)null)
			{
				((Component)mainCamera).gameObject.AddComponent<CameraPostProcess>();
			}
		}

		public static void CreatePostProcessShader()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			PostProcessMaterial = new Material(PostProcessShader);
			((Object)PostProcessMaterial).name = "BSOPostProcessMaterial";
			((Object)PostProcessMaterial).hideFlags = (HideFlags)61;
			PostProcessMaterial.SetFloat("_Temperature", config.ColorTemp.Value);
			PostProcessMaterial.SetFloat("_Saturation", config.ColorSaturation.Value);
		}
	}
}
namespace Badgers_Shading_Overhaul.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("Badgers_Shading_Overhaul.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] deferredshaders
		{
			get
			{
				object @object = ResourceManager.GetObject("deferredshaders", resourceCulture);
				return (byte[])@object;
			}
		}

		internal static byte[] guiassets
		{
			get
			{
				object @object = ResourceManager.GetObject("guiassets", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace Badgers_Shading_Overhaul.Gui
{
	public delegate void DropdownHandler(Dropdown dd);
	public enum WidgetType
	{
		Slider,
		Button
	}
	internal class BVTUI
	{
		private GameObject BVTCanvas;

		private BVTAssets bvtAssets;

		private GameObject widgetSpace = null;

		private GameObject mainCanvas = null;

		private GameObject mainPanel = null;

		private Dictionary<string, UIPanel> UIPanels = new Dictionary<string, UIPanel>();

		private string ActiveUIPanelName;

		public bool showMenu = false;

		public bool UICreated = false;

		public BVTUI(BVTAssets AssetBundle)
		{
			bLog.Log("Attempting to create UI");
			if (AssetBundle.assetsLoaded)
			{
				bvtAssets = AssetBundle;
				if (CreateUI())
				{
					AddUIComponents();
				}
				bLog.Log("UI created");
				UICreated = true;
			}
			else
			{
				bLog.Log("Unable to create UI due to missing assets");
			}
		}

		private bool CreateUI()
		{
			mainCanvas = bvtAssets.GetCanvas();
			if ((Object)(object)mainCanvas != (Object)null)
			{
				BVTCanvas = Object.Instantiate<GameObject>(mainCanvas);
				widgetSpace = ((Component)((Transform)BVTCanvas.GetComponent<RectTransform>()).Find("Panel/ScrollView/Viewport/Content/WidgetSpace")).gameObject;
				widgetSpace.SetActive(false);
				BVTCanvas.SetActive(false);
				return true;
			}
			BVTCanvas = null;
			return false;
		}

		public void SetupMainPanel(DropdownHandler dropDownHandler, List<string> Category, string Title)
		{
			mainPanel.GetComponent<DropdownComponent>().PopulateItems(Category);
			mainPanel.GetComponent<DropdownComponent>().ValueChangedHandler(dropDownHandler);
			((Component)mainPanel.transform.Find("TitleText")).GetComponent<Text>().text = Title;
		}

		public UIPanel CreateUIPanel(string Name)
		{
			if ((Object)(object)widgetSpace != (Object)null)
			{
				UIPanel uIPanel = new UIPanel(Name, widgetSpace, BVTCanvas, bvtAssets);
				if (uIPanel != null)
				{
					return uIPanel;
				}
			}
			return null;
		}

		public void AddUIPanel(UIPanel Panel, bool SetActive = false)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (SetActive)
			{
				Panel.panel.SetActive(true);
				ActiveUIPanelName = ((Object)Panel.panel).name;
			}
			Panel.panel.GetComponent<RectTransform>().sizeDelta = new Vector2(0f, Panel.totalHeight / 2f);
			UIPanels.Add(Panel.name, Panel);
		}

		public void SetActiveUIPanel(string PanelName)
		{
			if (!(PanelName != ActiveUIPanelName))
			{
				return;
			}
			foreach (UIPanel value in UIPanels.Values)
			{
				if (PanelName == value.name)
				{
					value.panel.SetActive(true);
					ActiveUIPanelName = PanelName;
				}
				else
				{
					value.panel.SetActive(false);
				}
			}
		}

		public void ToggleMenu()
		{
			if (!((Object)(object)BVTCanvas != (Object)null))
			{
				return;
			}
			if (!showMenu)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					((Behaviour)((Component)Player.m_localPlayer).GetComponent<PlayerController>()).enabled = false;
					((Behaviour)GameCamera.instance).enabled = false;
				}
				showMenu = true;
				BVTCanvas.SetActive(true);
			}
			else
			{
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					((Behaviour)((Component)Player.m_localPlayer).GetComponent<PlayerController>()).enabled = true;
					((Behaviour)GameCamera.instance).enabled = true;
				}
				showMenu = false;
				BVTCanvas.SetActive(false);
			}
		}

		private void AddUIComponents()
		{
			mainPanel = ((Component)((Transform)BVTCanvas.GetComponent<RectTransform>()).Find("Panel")).gameObject;
			if ((Object)(object)mainPanel != (Object)null)
			{
				mainPanel.AddComponent<MouseDragComponent>();
				mainPanel.AddComponent<DropdownComponent>();
			}
		}
	}
	internal class DropdownComponent : MonoBehaviour
	{
		private Dropdown dropDown;

		public void PopulateItems(List<string> Items)
		{
			dropDown = ((Component)((Transform)((Component)this).GetComponent<RectTransform>()).Find("CatSelector")).GetComponent<Dropdown>();
			dropDown.AddOptions(Items);
		}

		public void ValueChangedHandler(DropdownHandler dropDownHandler)
		{
			((UnityEvent<int>)(object)dropDown.onValueChanged).AddListener((UnityAction<int>)delegate
			{
				dropDownHandler(dropDown);
			});
		}
	}
	internal class UIPanel
	{
		public GameObject panel = null;

		public string name;

		private BVTAssets bvtAssets;

		private float lastWidgetHeight;

		private float widgetPanelOffset;

		private float widgetPanelSpacing = 80f;

		public float totalHeight = 0f;

		private List<Toggle> Toggles = new List<Toggle>();

		public UIPanel(string Name, GameObject SourcePanel, GameObject MainCanvas, BVTAssets Assets)
		{
			panel = Object.Instantiate<GameObject>(SourcePanel, ((Component)((Transform)MainCanvas.GetComponent<RectTransform>()).Find("Panel/ScrollView/Viewport/Content")).transform);
			name = Name;
			bvtAssets = Assets;
		}

		public bool AddSliderWidget(ref ConfigEntry<float> bvtConfigValue, float MinValue, float MaxValue, SliderHandlerMethod sliderHandlerMethod = null, string precision = "0.00")
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			GameObject sliderWidget = bvtAssets.GetSliderWidget();
			if ((Object)(object)sliderWidget != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(((Component)((Transform)sliderWidget.GetComponent<RectTransform>()).Find("Widget")).gameObject, panel.transform);
				if ((Object)(object)val != (Object)null)
				{
					Rect rect = val.GetComponent<RectTransform>().rect;
					lastWidgetHeight = ((Rect)(ref rect)).height;
					val.AddComponent<SliderWidgetController>();
					val.transform.localPosition = new Vector3(0f, widgetPanelOffset, 0f);
					widgetPanelOffset = lastWidgetHeight + widgetPanelSpacing;
					totalHeight += widgetPanelOffset;
					SliderWidgetController component = val.GetComponent<SliderWidgetController>();
					if ((Object)(object)component != (Object)null)
					{
						bLog.Log("Widget Controller added");
						component.SetParameters(ref bvtConfigValue, MinValue, MaxValue, sliderHandlerMethod, precision);
					}
					return true;
				}
			}
			return false;
		}

		public bool AddBUttonWidget(string Text, handlerMethod HandlerMethod)
		{
			//IL_005f: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			GameObject buttonWidget = bvtAssets.GetButtonWidget();
			if ((Object)(object)buttonWidget != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(((Component)((Transform)buttonWidget.GetComponent<RectTransform>()).Find("Widget")).gameObject, panel.transform);
				if ((Object)(object)val != (Object)null)
				{
					val.AddComponent<ButtonWidgetController>();
					Rect rect = val.GetComponent<RectTransform>().rect;
					lastWidgetHeight = ((Rect)(ref rect)).height;
					val.transform.localPosition = new Vector3(0f, widgetPanelOffset, 0f);
					widgetPanelOffset = lastWidgetHeight + widgetPanelSpacing;
					ButtonWidgetController component = val.GetComponent<ButtonWidgetController>();
					if ((Object)(object)component != (Object)null)
					{
						bLog.Log("Widget controller addded");
						component.SetParameters(Text, HandlerMethod);
					}
					return true;
				}
			}
			return false;
		}

		public bool AddLabelWidget(string Text)
		{
			//IL_006b: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			GameObject labelWidget = bvtAssets.GetLabelWidget();
			if ((Object)(object)labelWidget != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(((Component)((Transform)labelWidget.GetComponent<RectTransform>()).Find("Widget")).gameObject, panel.transform);
				if ((Object)(object)val != (Object)null)
				{
					val.AddComponent<LabelWidgetController>();
					bLog.Log("Added label widget to UI");
					Rect rect = val.GetComponent<RectTransform>().rect;
					lastWidgetHeight = ((Rect)(ref rect)).height;
					val.transform.localPosition = new Vector3(0f, widgetPanelOffset, 0f);
					widgetPanelOffset = lastWidgetHeight + widgetPanelSpacing;
					LabelWidgetController component = val.GetComponent<LabelWidgetController>();
					if ((Object)(object)component != (Object)null)
					{
						component.SetParameters(Text);
					}
					return true;
				}
			}
			return false;
		}

		public bool AddToggleWidget(string Text, bool state, ToggleHandler toggleHandler)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			GameObject toggleWidget = bvtAssets.GetToggleWidget();
			if ((Object)(object)toggleWidget != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(((Component)((Transform)toggleWidget.GetComponent<RectTransform>()).Find("Widget")).gameObject, panel.transform);
				if ((Object)(object)val != (Object)null)
				{
					val.AddComponent<ToggleWidgetController>();
					Toggles.Add(((Component)val.transform.Find("Toggle")).GetComponent<Toggle>());
					bLog.Log("Added toggle widget to UI");
					Rect rect = val.GetComponent<RectTransform>().rect;
					lastWidgetHeight = ((Rect)(ref rect)).height;
					val.transform.localPosition = new Vector3(0f, widgetPanelOffset, 0f);
					widgetPanelOffset = lastWidgetHeight + widgetPanelSpacing;
					ToggleWidgetController component = val.GetComponent<ToggleWidgetController>();
					if ((Object)(object)component != (Object)null)
					{
						component.SetParameters(Text, state, toggleHandler);
					}
					return true;
				}
			}
			return false;
		}

		public void ClearToggles()
		{
			foreach (Toggle toggle in Toggles)
			{
				toggle.isOn = false;
			}
		}
	}
}
namespace Badgers_Shading_Overhaul.Gui.GUIScriptComponents
{
	public delegate void handlerMethod();
	internal class ButtonWidgetController : MonoBehaviour
	{
		public void SetParameters(string Text, handlerMethod HandlerMethod)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			((Component)((Component)this).transform.Find("Button/Text")).GetComponent<Text>().text = Text;
			((UnityEvent)((Component)((Component)this).transform.Find("Button")).GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				HandlerMethod();
			});
		}
	}
	internal class LabelWidgetController : MonoBehaviour
	{
		public void SetParameters(string Text)
		{
			((Component)((Component)this).transform.Find("Text")).GetComponent<Text>().text = Text;
		}
	}
	public delegate void SliderHandlerMethod(float value, string title);
	internal class SliderWidgetController : MonoBehaviour
	{
		private string titleText;

		private Text title;

		private Slider slider;

		private InputField textInput;

		private float sliderValue;

		private float sliderMinValue;

		private float sliderMaxValue;

		private ConfigEntry<float> bvtConfigItem;

		private string precision = "0.00";

		public void SetParameters(ref ConfigEntry<float> ConfigValue, float MinSliderValue, float MaxSliderValue, SliderHandlerMethod sliderHandlerMethod = null, string Precision = "0.00")
		{
			bvtConfigItem = ConfigValue;
			titleText = ((ConfigEntryBase)ConfigValue).Description.Description + ", Default Value: " + ((ConfigEntryBase)ConfigValue).DefaultValue.ToString();
			sliderMinValue = MinSliderValue;
			sliderMaxValue = MaxSliderValue;
			sliderValue = ConfigValue.Value;
			precision = Precision;
			title = ((Component)((Component)this).transform.Find("Title")).GetComponent<Text>();
			if ((Object)(object)title != (Object)null)
			{
				title.text = titleText;
			}
			SetValues(sliderMinValue, sliderMaxValue, sliderValue, sliderHandlerMethod);
		}

		private void SetValues(float MinValue, float MaxValue, float Value, SliderHandlerMethod m = null)
		{
			textInput = ((Component)((Component)this).transform.Find("TextInput")).GetComponent<InputField>();
			if ((Object)(object)textInput != (Object)null)
			{
				((UnityEvent<string>)(object)textInput.onEndEdit).AddListener((UnityAction<string>)delegate
				{
					OnTextInputChanged(textInput);
				});
			}
			slider = ((Component)((Component)this).transform.Find("Slider")).GetComponent<Slider>();
			if (!((Object)(object)slider != (Object)null))
			{
				return;
			}
			((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate
			{
				OnSliderChanged(slider);
			});
			if (m != null)
			{
				((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate
				{
					m(slider.value, ((ConfigEntryBase)bvtConfigItem).Description.Description);
				});
			}
			slider.minValue = MinValue;
			slider.maxValue = MaxValue;
			slider.value = Value;
			textInput.text = Value.ToString(precision);
		}

		private void OnTextInputChanged(InputField textInput)
		{
			slider.value = float.Parse(textInput.text);
		}

		private void OnSliderChanged(Slider slider)
		{
			sliderValue = slider.value;
			textInput.text = sliderValue.ToString(precision);
			bvtConfigItem.Value = sliderValue;
		}
	}
	public delegate void ToggleHandler(Toggle t);
	internal class ToggleWidgetController : MonoBehaviour
	{
		public void SetParameters(string Text, bool state, ToggleHandler toggleHandler)
		{
			((Component)((Component)this).transform.Find("Toggle/Label")).GetComponent<Text>().text = Text;
			Toggle tg = ((Component)((Component)this).transform.Find("Toggle")).GetComponent<Toggle>();
			tg.isOn = state;
			if (toggleHandler != null)
			{
				((UnityEvent<bool>)(object)((Component)((Component)this).transform.Find("Toggle")).GetComponent<Toggle>().onValueChanged).AddListener((UnityAction<bool>)delegate
				{
					toggleHandler(tg);
				});
			}
		}
	}
}