Decompiled source of SteveCore v2.0.4

plugins/BadgersShadingOverhaul.dll

Decompiled 10 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);
				});
			}
		}
	}
}

plugins/BadgersValheimTweaksLite.dll

Decompiled 10 months ago
using System.Collections.Generic;
using System.Diagnostics;
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 BadgersValheimTweaks.Gui;
using BadgersValheimTweaks.Gui.GUIScriptComponents;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.PostProcessing;
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("BadgersValheimTweaksLite")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BadgersValheimTweaksLite")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3cc9f8d4-1a37-4e52-b46e-5510ede58f7e")]
[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 BadgersValheimTweaks
{
	[BepInPlugin("Badgers.ValheimTweaksLite", "badgers Valheim Tweaks Lite", "0.21.2")]
	[BepInProcess("valheim.exe")]
	public class BadgersValheimTweaksLite : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Heightmap), "OnEnable")]
		private class Heightmap_OnEnable
		{
			private static void Postfix(Heightmap __instance)
			{
				if (Object.op_Implicit((Object)(object)__instance.m_renderMesh))
				{
					__instance.m_materialInstance.SetFloat("_Tess", bvtConfig.TesselationAmount.Value);
				}
			}
		}

		[HarmonyPatch(typeof(ParticleMist), "Awake")]
		private class ParticleMist_Awake
		{
			private static void Postfix(ParticleMist __instance)
			{
				//IL_0020: 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_0050: Unknown result type (might be due to invalid IL or missing references)
				mistPS = __instance.m_ps;
				Color color = ((Component)mistPS).GetComponent<Renderer>().material.GetColor("_Color");
				color.a = bvtConfig.MistlandsMistOpacity.Value;
				((Component)mistPS).GetComponent<Renderer>().material.SetColor("_Color", color);
			}
		}

		[HarmonyPatch(typeof(GameCamera), "AddShake")]
		private class GameCamera_AddShake
		{
			[HarmonyPrefix]
			private static bool Prefix(GameCamera __instance)
			{
				__instance.m_shakeFreq = bvtConfig.CameraShakeSpeed.Value;
				return true;
			}
		}

		[HarmonyPatch(typeof(GameCamera), "UpdateCameraShake")]
		private class GameCamera_UpdateCameraShake
		{
			[HarmonyPrefix]
			private static bool Prefix(GameCamera __instance, float dt)
			{
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				__instance.m_shakeMovement = 1f * bvtConfig.CameraShakeAmount.Value;
				__instance.m_shakeIntensity -= dt;
				if (__instance.m_shakeIntensity <= 0f)
				{
					__instance.m_shakeIntensity = 0f;
					return false;
				}
				float num = __instance.m_shakeIntensity * __instance.m_shakeIntensity * __instance.m_shakeIntensity;
				__instance.m_shakeTimer += dt * Mathf.Clamp01(__instance.m_shakeIntensity) * __instance.m_shakeFreq;
				Quaternion val = Quaternion.Euler(Mathf.Sin(__instance.m_shakeTimer) * num * __instance.m_shakeMovement, Mathf.Cos(__instance.m_shakeTimer * 0.9f) * num * __instance.m_shakeMovement, 0f);
				((Component)__instance).transform.rotation = ((Component)__instance).transform.rotation * val;
				return false;
			}
		}

		[HarmonyPatch(typeof(EnvMan), "Awake")]
		private class EnvMan_Awake
		{
			[HarmonyPostfix]
			private static void Postfix(EnvMan __instance)
			{
				envMan = __instance;
			}
		}

		[HarmonyPatch(typeof(Player), "Update")]
		private class Player_Update
		{
			[HarmonyPrefix]
			private static void Prefix(Player __instance)
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return;
				}
				if (Input.GetKeyDown(bvtConfig.MenuHotkey.Value) && !Console.IsVisible() && !Chat.instance.IsChatDialogWindowVisible())
				{
					bLog.Log("Showing menu");
					if (!bvtUI.showMenu)
					{
						enableUpdateErrorMSG = true;
					}
					bvtUI.ToggleMenu();
				}
				if (bvtUI.showMenu)
				{
					ppSettings.bloomSettings.bloom.intensity = bvtConfig.BloomIntensity.Value;
					ppSettings.bloomSettings.lensDirt.intensity = bvtConfig.LensDirtIntensity.Value;
					ppSettings.aoSettings.intensity = bvtConfig.AOIntensity.Value;
					ppSettings.aoSettings.intensityFar = bvtConfig.AOFarIntensity.Value;
					ppSettings.aaSettings.taaSettings.jitterSpread = bvtConfig.TAAJitterSpread.Value;
					ppSettings.aaSettings.taaSettings.motionBlending = bvtConfig.TAAMotionBlending.Value;
					ppSettings.aaSettings.taaSettings.stationaryBlending = bvtConfig.TAAStationaryBlending.Value;
					ppSettings.aaSettings.taaSettings.sharpen = bvtConfig.TAASharpen.Value;
					QualitySettings.shadowDistance = bvtConfig.ShadowDrawDistance.Value;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "TakeInput")]
		private class Player_LateUpdate
		{
			[HarmonyPrefix]
			private static bool Prefix(bool __result)
			{
				if (bvtUI.showMenu)
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Player), "Awake")]
		private class Player_Awake
		{
			[HarmonyPostfix]
			private static void Postfix(Player __instance)
			{
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				if (((Character)__instance).m_nview.GetZDO() == null)
				{
					return;
				}
				player = __instance;
				QualitySettings.shadowDistance = bvtConfig.ShadowDrawDistance.Value;
				if ((Object)(object)envMan != (Object)null)
				{
					for (int i = 0; i < envMan.m_environments.Count; i++)
					{
						nightColors.Add(envMan.m_environments[i].m_ambColorNight);
						dayColors.Add(envMan.m_environments[i].m_ambColorDay);
						envMan.m_environments[i].m_ambColorNight = nightColors[i] * bvtConfig.NightAmbientLightModifier.Value;
						envMan.m_environments[i].m_ambColorDay = dayColors[i] * bvtConfig.DayAmbientLightModifier.Value;
					}
					UpdateAmbientModifiers();
				}
			}
		}

		[HarmonyPatch(typeof(ClutterSystem), "Awake")]
		private class ClutterSystem_AwakePatch
		{
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			private static void Postfix(ClutterSystem __instance)
			{
				for (int i = 0; i < __instance.m_clutter.Count; i++)
				{
					float[] item = new float[2]
					{
						__instance.m_clutter[i].m_scaleMin,
						__instance.m_clutter[i].m_scaleMax
					};
					clutterScale.Add(item);
					__instance.m_clutter[i].m_scaleMin = clutterScale[i][0] * bvtConfig.ClutterScaleMin.Value;
					__instance.m_clutter[i].m_scaleMax = clutterScale[i][1] * bvtConfig.ClutterScaleMax.Value;
					if (__instance.m_clutter[i].m_instanced)
					{
						__instance.m_clutter[i].m_prefab.GetComponent<InstanceRenderer>().m_useLod = false;
						__instance.m_clutter[i].m_prefab.GetComponent<InstanceRenderer>().m_useXZLodDistance = false;
					}
				}
				__instance.m_distance = bvtConfig.ClutterdrawDistance.Value;
				__instance.m_grassPatchSize = bvtConfig.ClutterPatchSize.Value;
				__instance.m_amountScale = bvtConfig.ClutterPatchAmountMultiplier.Value;
			}
		}

		[HarmonyPatch(typeof(ClutterSystem), "LateUpdate")]
		private class ClutterSysten_LateUpdatePatch
		{
			[HarmonyPrefix]
			private static void Prefix(ClutterSystem __instance)
			{
				__instance.m_distance = bvtConfig.ClutterdrawDistance.Value;
				if (forceRebuildGrass)
				{
					for (int i = 0; i < __instance.m_clutter.Count; i++)
					{
						__instance.m_clutter[i].m_scaleMin = clutterScale[i][0] * bvtConfig.ClutterScaleMin.Value;
						__instance.m_clutter[i].m_scaleMax = clutterScale[i][1] * bvtConfig.ClutterScaleMax.Value;
					}
					__instance.m_amountScale = bvtConfig.ClutterPatchAmountMultiplier.Value;
					__instance.m_grassPatchSize = bvtConfig.ClutterPatchSize.Value;
					forceRebuildGrass = false;
					__instance.ClearAll();
					bLog.Log("Rebuilding Grass");
				}
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private class ZNetScene_Awake
		{
			[HarmonyPostfix]
			private static void Postfix(ZNetScene __instance)
			{
				CreateUI();
			}
		}

		[HarmonyPatch(typeof(Minimap), "CenterMap")]
		private class Minimap_CenterMap
		{
			[HarmonyPostfix]
			private static void Postfix(Minimap __instance, ref float ___m_largeZoom, ref float ___m_smallZoom)
			{
				if (bvtConfig.hdMapEnable.Value)
				{
					((Graphic)__instance.m_mapImageLarge).material.SetFloat("_zoom", 1f);
					((Graphic)__instance.m_mapImageSmall).material.SetFloat("_zoom", 1f);
				}
				else
				{
					((Graphic)__instance.m_mapImageLarge).material.SetFloat("_zoom", ___m_largeZoom);
					((Graphic)__instance.m_mapImageSmall).material.SetFloat("_zoom", ___m_smallZoom);
				}
			}
		}

		[HarmonyPatch(typeof(PostProcessingBehaviour), "OnEnable")]
		private class PostProcessingBehaviour_OnEnable
		{
			[HarmonyPostfix]
			private static void Postfix(PostProcessingBehaviour __instance, ref BloomComponent ___m_Bloom, ref AmbientOcclusionComponent ___m_AmbientOcclusion, ref TaaComponent ___m_Taa)
			{
				//IL_0039: 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_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance != (Object)null && ___m_Bloom != null && ___m_AmbientOcclusion != null && ___m_Taa != null)
				{
					bLog.Log("Creating ppsettings");
					Settings settings = __instance.profile.bloom.settings;
					Settings settings2 = __instance.profile.ambientOcclusion.settings;
					Settings settings3 = __instance.profile.antialiasing.settings;
					ppSettings = new PostProcess(settings, settings2, settings3);
					ppSettings.bloomSettings.bloom.intensity = bvtConfig.BloomIntensity.Value;
					ppSettings.bloomSettings.lensDirt.intensity = bvtConfig.LensDirtIntensity.Value;
					ppSettings.aoSettings.intensity = bvtConfig.AOIntensity.Value;
					ppSettings.aoSettings.intensityFar = bvtConfig.AOFarIntensity.Value;
					ppSettings.aaSettings.taaSettings.jitterSpread = bvtConfig.TAAJitterSpread.Value;
					ppSettings.aaSettings.taaSettings.motionBlending = bvtConfig.TAAMotionBlending.Value;
					ppSettings.aaSettings.taaSettings.sharpen = bvtConfig.TAASharpen.Value;
					ppSettings.aaSettings.taaSettings.stationaryBlending = bvtConfig.TAAStationaryBlending.Value;
				}
				else
				{
					bLog.Log("Error creating ppsettings");
				}
			}
		}

		[HarmonyPatch(typeof(PostProcessingBehaviour), "OnPreCull")]
		private class PostProcessinigBehaviour_OnPreCull
		{
			[HarmonyPostfix]
			private static void Postfix(ref BloomComponent ___m_Bloom, ref AmbientOcclusionComponent ___m_AmbientOcclusion, ref TaaComponent ___m_Taa)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				if (ppSettings != null)
				{
					((PostProcessingComponent<BloomModel>)(object)___m_Bloom).model.settings = ppSettings.bloomSettings;
					((PostProcessingComponent<AmbientOcclusionModel>)(object)___m_AmbientOcclusion).model.settings = ppSettings.aoSettings;
					((PostProcessingComponent<AntialiasingModel>)(object)___m_Taa).model.settings = ppSettings.aaSettings;
				}
			}
		}

		[HarmonyPatch(typeof(CameraEffects), "UpdateDOF")]
		private class CameraEffect_UpdateDOF
		{
			[HarmonyPrefix]
			private static void Prefix(CameraEffects __instance)
			{
				__instance.m_dofMinDistance = 100f - bvtConfig.DOFStrength.Value;
			}
		}

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

		private static string assetPath = Path.Combine(Paths.PluginPath, "BadgersValheimTweaks\\Assets");

		private static ConfigFile cf = new ConfigFile(Path.Combine(Paths.ConfigPath, "Badgers.ValheimTweaksLite.cfg"), true);

		private static BVTConfig bvtConfig = new BVTConfig(cf);

		private static BVTAssets bvtAssets = new BVTAssets();

		private static BVTUI bvtUI = new BVTUI(bvtAssets);

		private static PostProcess ppSettings;

		private static List<string> Category = new List<string> { "Clutter (Grass / Bushes)", "Post Processing", "Visual", "Player" };

		private static List<float[]> clutterScale = new List<float[]>();

		public static bool forceRebuildGrass = false;

		public static bool enableUpdateErrorMSG = false;

		public static int frameCounter = Time.frameCount;

		public static int reflectionUpdateDelay = 3;

		public static EnvMan envMan;

		public static List<Color> nightColors = new List<Color>();

		public static List<Color> dayColors = new List<Color>();

		public static CamShaker camShaker;

		public static float updateSupportDelay = 2f;

		public static float updateWearDelay = 2f;

		public static float updateSupportCounter = 0f;

		public static float updateWearCounter = 0f;

		public static float UpdateDelay = 1f;

		public static float UpdateTimer = 0f;

		public static float TesselationAmount = 1f;

		private static ParticleSystem mistPS = null;

		private static Player player = null;

		public static GameObject ClockWidget = null;

		public static TextMeshProUGUI ClockText = null;

		private void Awake()
		{
			bvtAssets.LoadAssets(assetPath);
			harmony.PatchAll();
		}

		private static void CreateUI()
		{
			bvtUI = new BVTUI(bvtAssets);
			if (!bvtUI.UICreated)
			{
				return;
			}
			bLog.Log("Creating UI Panels");
			bvtUI.SetupMainPanel(HandleCavasDropDown, Category);
			foreach (string item in Category)
			{
				switch (item)
				{
				case "Clutter (Grass / Bushes)":
					SetClutterUI(item);
					break;
				case "Post Processing":
					SetPostProcessUI(item);
					break;
				case "Visual":
					SetVisualUI(item);
					break;
				case "Player":
					SetPlayerUI(item);
					break;
				}
			}
		}

		private static void SetClutterUI(string PanelName)
		{
			UIPanel uIPanel = bvtUI.CreateUIPanel(PanelName);
			if (uIPanel != null)
			{
				bLog.Log("Created " + PanelName + " UI Panel");
				uIPanel.AddSliderWidget(ref bvtConfig.ClutterScaleMin, 0f, 2f);
				uIPanel.AddSliderWidget(ref bvtConfig.ClutterScaleMax, 0f, 2f);
				uIPanel.AddSliderWidget(ref bvtConfig.ClutterPatchSize, 5f, 20f);
				uIPanel.AddSliderWidget(ref bvtConfig.ClutterPatchAmountMultiplier, 0f, 20f);
				uIPanel.AddSliderWidget(ref bvtConfig.ClutterdrawDistance, 0f, 200f);
				uIPanel.AddBUttonWidget("Apply Clutter Settings", HandleClutterApply);
			}
			bvtUI.AddUIPanel(uIPanel, SetActive: true);
		}

		private static void SetPostProcessUI(string PanelName)
		{
			UIPanel uIPanel = bvtUI.CreateUIPanel(PanelName);
			if (uIPanel != null)
			{
				bLog.Log("Created " + PanelName + " UI Panel");
				uIPanel.AddSliderWidget(ref bvtConfig.BloomIntensity, 0f, 1f);
				uIPanel.AddSliderWidget(ref bvtConfig.LensDirtIntensity, 0f, 20f);
				uIPanel.AddSliderWidget(ref bvtConfig.AOIntensity, 0f, 5f);
				uIPanel.AddSliderWidget(ref bvtConfig.AOFarIntensity, 0f, 5f);
				uIPanel.AddSliderWidget(ref bvtConfig.DOFStrength, 0f, 100f);
				uIPanel.AddSliderWidget(ref bvtConfig.TAAJitterSpread, 0f, 2f);
				uIPanel.AddSliderWidget(ref bvtConfig.TAAMotionBlending, 0f, 2f);
				uIPanel.AddSliderWidget(ref bvtConfig.TAAStationaryBlending, 0f, 1f);
				uIPanel.AddSliderWidget(ref bvtConfig.TAASharpen, 0f, 2f);
			}
			bvtUI.AddUIPanel(uIPanel);
		}

		private static void SetVisualUI(string PanelName)
		{
			UIPanel uIPanel = bvtUI.CreateUIPanel(PanelName);
			if (uIPanel != null)
			{
				bLog.Log("Created " + PanelName + " UI Panel");
				uIPanel.AddToggleWidget("Enable high resolution map", bvtConfig.hdMapEnable.Value, HandleHDMapEnable);
				uIPanel.AddSliderWidget(ref bvtConfig.NightAmbientLightModifier, 0.1f, 2f, HandleNightAmbient);
				uIPanel.AddSliderWidget(ref bvtConfig.DayAmbientLightModifier, 0.1f, 2f, HandleDayAmbient);
				uIPanel.AddSliderWidget(ref bvtConfig.ShadowDrawDistance, 10f, 200f);
				uIPanel.AddSliderWidget(ref bvtConfig.MistlandsMistOpacity, 0f, 1f, HandleMistSlider);
				uIPanel.AddSliderWidget(ref bvtConfig.TesselationAmount, 0.1f, 4f, HandleTesselationAmount);
			}
			bvtUI.AddUIPanel(uIPanel);
		}

		private static void SetPlayerUI(string PanelName)
		{
			UIPanel uIPanel = bvtUI.CreateUIPanel(PanelName);
			if (uIPanel != null)
			{
				bLog.Log("Created " + PanelName + " UI Panel");
				uIPanel.AddSliderWidget(ref bvtConfig.CameraShakeSpeed, 0f, 100f);
				uIPanel.AddSliderWidget(ref bvtConfig.CameraShakeAmount, 0f, 2f);
			}
			bvtUI.AddUIPanel(uIPanel);
		}

		private static void HandleTesselationAmount(float value, string title)
		{
			foreach (Heightmap instance in Heightmap.Instances)
			{
				instance.m_materialInstance.SetFloat("_Tess", value);
			}
		}

		private static void UpdateAmbientModifiers()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)envMan != (Object)null)
			{
				for (int i = 0; i < envMan.m_environments.Count; i++)
				{
					envMan.m_environments[i].m_ambColorNight = nightColors[i] * bvtConfig.NightAmbientLightModifier.Value;
					envMan.m_environments[i].m_ambColorDay = dayColors[i] * bvtConfig.DayAmbientLightModifier.Value;
				}
			}
		}

		private static void HandleDayAmbient(float value, string title)
		{
			bvtConfig.DayAmbientLightModifier.Value = value;
			UpdateAmbientModifiers();
		}

		private static void HandleNightAmbient(float value, string title)
		{
			bvtConfig.NightAmbientLightModifier.Value = value;
			UpdateAmbientModifiers();
		}

		private static void HandleMistSlider(float value, string title)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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 ((Object)(object)mistPS != (Object)null)
			{
				Color color = ((Component)mistPS).GetComponent<Renderer>().material.GetColor("_Color");
				color.a = value;
				((Component)mistPS).GetComponent<Renderer>().material.SetColor("_Color", color);
			}
		}

		private static void HandleClutterApply()
		{
			forceRebuildGrass = true;
		}

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

		private static void HandleHDMapEnable(Toggle t)
		{
			if (t.isOn)
			{
				bLog.Log("HD map enabled");
				bvtConfig.hdMapEnable.Value = true;
			}
			else
			{
				bLog.Log("HD map disabled");
				bvtConfig.hdMapEnable.Value = false;
			}
		}
	}
	internal class bLog
	{
		private static bool debugEnabled = true;

		public static void Log(string LogMessage, bool force = false)
		{
			if (debugEnabled || force)
			{
				Debug.Log((object)("BVT: " + LogMessage));
			}
		}
	}
	public class BVTConfig
	{
		public ConfigFile config;

		public ConfigEntry<KeyCode> MenuHotkey;

		public ConfigEntry<Vector3> LastWindowPosition;

		public ConfigEntry<float> ClutterPatchSize;

		public ConfigEntry<float> ClutterdrawDistance;

		public ConfigEntry<float> ClutterPatchAmountMultiplier;

		public ConfigEntry<float> ClutterScaleMin;

		public ConfigEntry<float> ClutterScaleMax;

		public ConfigEntry<float> CameraShakeSpeed;

		public ConfigEntry<float> CameraShakeAmount;

		public ConfigEntry<bool> hdMapEnable;

		public ConfigEntry<float> NightAmbientLightModifier;

		public ConfigEntry<float> DayAmbientLightModifier;

		public ConfigEntry<float> ShadowDrawDistance;

		public ConfigEntry<float> MistlandsMistOpacity;

		public ConfigEntry<float> TesselationAmount;

		public ConfigEntry<float> LensDirtIntensity;

		public ConfigEntry<float> BloomIntensity;

		public ConfigEntry<float> AOIntensity;

		public ConfigEntry<float> AOFarIntensity;

		public ConfigEntry<float> DOFStrength;

		public ConfigEntry<float> TAAJitterSpread;

		public ConfigEntry<float> TAAMotionBlending;

		public ConfigEntry<float> TAASharpen;

		public ConfigEntry<float> TAAStationaryBlending;

		public BVTConfig(ConfigFile ConfigFile)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			config = ConfigFile;
			MenuHotkey = config.Bind<KeyCode>("Mod General", "enable/disable key", (KeyCode)116, "Key to show/hide menu");
			LastWindowPosition = config.Bind<Vector3>("Mod General", "Last Window Position", new Vector3(0f, 0f, 0f), "Last window position");
			ClutterPatchSize = config.Bind<float>("Clutter Settings", "Patch Size", 8f, "Clutter Patch Size");
			ClutterdrawDistance = config.Bind<float>("Clutter Settings", "Draw Distance", 40f, "Clutter Draw Distance");
			ClutterPatchAmountMultiplier = config.Bind<float>("Clutter Settings", "Patch Amount Multiplier", 1f, "Patch clutter content multiplier");
			ClutterScaleMin = config.Bind<float>("Clutter Settings", "Clutter Minimum Scale", 1f, "Minimum scale for clutter objects");
			ClutterScaleMax = config.Bind<float>("Clutter Settings", "Clutter Max Scale", 1f, "Maximum scale for clutter objects");
			CameraShakeSpeed = config.Bind<float>("Player", "Camera Shake Speed", 100f, "Camera Shake Speed");
			CameraShakeAmount = config.Bind<float>("Player", "Camera Shake Amount", 1f, "Camera Shake Amount");
			hdMapEnable = config.Bind<bool>("Visual", "Enable HD Map", false, "Enable HD Map");
			NightAmbientLightModifier = config.Bind<float>("Visual", "Night Ambient Light Modifier", 1f, "Night Ambient Light Modifier");
			DayAmbientLightModifier = config.Bind<float>("Visual", "Day Ambient Light Modifier", 1f, "Day Ambient Light Modifier");
			ShadowDrawDistance = config.Bind<float>("Visual", "Shadow Draw Distance", 150f, "Shadow Draw Distance");
			MistlandsMistOpacity = config.Bind<float>("Visual", "Opacity of Mistlands Mist", 1f, "Opacity of Mistlands Mist");
			TesselationAmount = config.Bind<float>("Visual", "Tesselation Amount", 4f, "Tesselation Amount");
			BloomIntensity = config.Bind<float>("Post Processing", "Bloom Intensity", 0.3f, "Intensity of the Bloom effect");
			LensDirtIntensity = config.Bind<float>("Post Processing", "Lens Dirt Intensity", 10.4f, "Intensity of camera lens dirt");
			AOIntensity = config.Bind<float>("Post Processing", "AO Intensity", 1f, "Intensity of Ambient Occlusion");
			AOFarIntensity = config.Bind<float>("Post Processing", "AO Far Intensity", 1.5f, "Intensity of far Ambient Occlusion");
			DOFStrength = config.Bind<float>("Post Processing", "Depth of Field Strength", 65f, "Depth of Field Strength");
			TAAJitterSpread = config.Bind<float>("Post Processing", "TAA Jitter Spread", 0.2f, "Amount of TAA jitter spread");
			TAAMotionBlending = config.Bind<float>("Post Processing", "TAA Motion Blending", 0.85f, "Amount of TAA motion blending");
			TAASharpen = config.Bind<float>("Post Processing", "TAA Sharpening", 0.3f, "Amount of TAA sharpening");
			TAAStationaryBlending = config.Bind<float>("Post Processing", "TAA Stationary Blending", 1f, "Amount of TAA stationary blending");
		}
	}
	internal class BVTAssets
	{
		private AssetBundle bvtAssetBundle;

		private string assetFile;

		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 void LoadAssets(string AssetPath)
		{
			assetFile = Path.Combine(AssetPath, "bvtassets");
			bLog.Log("Loading BVT assets");
			if (File.Exists(assetFile))
			{
				bLog.Log("Found asset file");
				bvtAssetBundle = AssetBundle.LoadFromFile(assetFile);
				string[] allAssetNames = bvtAssetBundle.GetAllAssetNames();
				foreach (string text in allAssetNames)
				{
					GameObject val = bvtAssetBundle.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;
					case "ClockHolder":
						bLog.Log("Adding Clock Widgets");
						ClockWidget = val;
						break;
					}
				}
				assetsLoaded = true;
				bvtAssetBundle.Unload(false);
			}
			else
			{
				bLog.Log("Asset file not found");
			}
		}

		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;
		}
	}
	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 PostProcess
	{
		public Settings bloomSettings;

		public Settings aoSettings;

		public Settings aaSettings;

		public PostProcess(Settings BloomSettings, Settings AOSettings, Settings AASettings)
		{
			//IL_0009: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			bloomSettings = BloomSettings;
			aoSettings = AOSettings;
			aaSettings = AASettings;
		}
	}
}
namespace BadgersValheimTweaks.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)
		{
			mainPanel.GetComponent<DropdownComponent>().PopulateItems(Category);
			mainPanel.GetComponent<DropdownComponent>().ValueChangedHandler(dropDownHandler);
		}

		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)
			{
				if (!showMenu)
				{
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
					((Behaviour)GameCamera.instance).enabled = false;
					((Behaviour)((Component)Player.m_localPlayer).GetComponent<PlayerController>()).enabled = false;
					showMenu = true;
					BVTCanvas.SetActive(true);
				}
				else
				{
					Cursor.lockState = (CursorLockMode)1;
					Cursor.visible = false;
					((Behaviour)GameCamera.instance).enabled = true;
					((Behaviour)((Component)Player.m_localPlayer).GetComponent<PlayerController>()).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;

		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_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 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>();
					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;
		}
	}
}
namespace BadgersValheimTweaks.Gui.GUIScriptComponents
{
	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);
				});
			}
		}
	}
	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;
		}
	}
}