Decompiled source of AntroShaders v1.1.0

Antro.Shaders.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Antro.Shaders")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Antro.Shaders")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyProduct("Antro.Shaders")]
[assembly: AssemblyTitle("Antro.Shaders")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Antro.Shaders
{
	public class CameraShaderEffect : MonoBehaviour
	{
		public Material ScreenMaterial;

		public static CameraShaderEffect Instance { get; private set; }

		public CameraShaderEffect(IntPtr ptr)
			: base(ptr)
		{
		}

		public void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Camera component = ((Component)this).GetComponent<Camera>();
			if ((Object)(object)component != (Object)null)
			{
				component.depthTextureMode = (DepthTextureMode)(component.depthTextureMode | 3);
			}
		}

		public void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		public void OnRenderImage(RenderTexture source, RenderTexture destination)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name.ToLower().Contains("win"))
			{
				Graphics.Blit((Texture)(object)source, destination);
				return;
			}
			List<Material> list = new List<Material>();
			foreach (string item in ShaderManager.ActiveShaderOrder)
			{
				if (ShaderManager.ActiveMaterials.TryGetValue(item, out var value) && (Object)(object)value != (Object)null && !((Il2CppObjectBase)value).WasCollected)
				{
					list.Add(value);
				}
			}
			if (list.Count == 0)
			{
				Graphics.Blit((Texture)(object)source, destination);
				return;
			}
			if (list.Count == 1)
			{
				Graphics.Blit((Texture)(object)source, destination, list[0]);
				return;
			}
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, source.format);
			RenderTexture temporary2 = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, source.format);
			Graphics.Blit((Texture)(object)source, temporary, list[0]);
			bool flag = true;
			for (int i = 1; i < list.Count - 1; i++)
			{
				if (flag)
				{
					Graphics.Blit((Texture)(object)temporary, temporary2, list[i]);
				}
				else
				{
					Graphics.Blit((Texture)(object)temporary2, temporary, list[i]);
				}
				flag = !flag;
			}
			if (flag)
			{
				Graphics.Blit((Texture)(object)temporary, destination, list[list.Count - 1]);
			}
			else
			{
				Graphics.Blit((Texture)(object)temporary2, destination, list[list.Count - 1]);
			}
			RenderTexture.ReleaseTemporary(temporary);
			RenderTexture.ReleaseTemporary(temporary2);
		}
	}
	internal static class Patches
	{
		[HarmonyPatch(typeof(MonoBehaviourPublicObInVoAwVoVoVoVoVoVoUnique), "Awake")]
		[HarmonyPostfix]
		public static void SpawnSystem()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if ((Object)(object)GameObject.Find("AntroShaderSystem") == (Object)null)
			{
				GameObject val = new GameObject("AntroShaderSystem");
				Object.DontDestroyOnLoad((Object)(object)val);
				val.AddComponent<ShaderMenu>();
				((BasePlugin)Plugin.Instance).Log.LogInfo((object)"Antro Shaders: System successfully created! Press F6.");
			}
		}
	}
	[BepInPlugin("Antro.Shaders", "Antro Shaders", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public ConfigEntry<KeyCode> MenuKeyConfig;

		public ConfigEntry<bool> RememberStateConfig;

		public static Plugin Instance { get; private set; }

		public override void Load()
		{
			Instance = this;
			MenuKeyConfig = ((BasePlugin)this).Config.Bind<KeyCode>("General", "MenuKey", (KeyCode)287, "Key to open the Shader Menu");
			RememberStateConfig = ((BasePlugin)this).Config.Bind<bool>("Settings", "RememberState", false, "Remember active shaders and settings between sessions");
			ClassInjector.RegisterTypeInIl2Cpp<CameraShaderEffect>();
			ClassInjector.RegisterTypeInIl2Cpp<ShaderMenu>();
			ShaderManager.Init();
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
			((BasePlugin)this).Log.LogInfo((object)"Antro Shaders загружен! Ожидание инициализации Unity...");
		}
	}
	public static class ShaderManager
	{
		public static Dictionary<string, Material> ActiveMaterials = new Dictionary<string, Material>();

		public static Dictionary<string, GameObject> ActivePrefabs = new Dictionary<string, GameObject>();

		private static Dictionary<string, AssetBundle> _loadedBundles = new Dictionary<string, AssetBundle>();

		public static List<string> ActiveShaderOrder = new List<string>();

		public static Dictionary<string, string> WorldReplacements = new Dictionary<string, string>();

		public static List<string> AvailableShaders = new List<string>();

		public static Dictionary<string, Dictionary<string, float>> CachedFloats = new Dictionary<string, Dictionary<string, float>>();

		public static Dictionary<string, Dictionary<string, Color>> CachedColors = new Dictionary<string, Dictionary<string, Color>>();

		public static string ShadersFolder => Path.Combine(Paths.PluginPath, "AntroShaders");

		public static string PresetsFolder => Path.Combine(Paths.ConfigPath, "AntroShadersPresets");

		public static void Init()
		{
			if (!Directory.Exists(ShadersFolder))
			{
				Directory.CreateDirectory(ShadersFolder);
			}
			if (!Directory.Exists(PresetsFolder))
			{
				Directory.CreateDirectory(PresetsFolder);
			}
			RefreshList();
		}

		public static void RefreshList()
		{
			if (Directory.Exists(ShadersFolder))
			{
				AvailableShaders = Directory.GetFiles(ShadersFolder, "*.bundle").ToList();
			}
		}

		public static void SaveFloatToCache(string bundle, string prop, float val)
		{
			if (!CachedFloats.ContainsKey(bundle))
			{
				CachedFloats[bundle] = new Dictionary<string, float>();
			}
			CachedFloats[bundle][prop] = val;
		}

		public static void SaveColorToCache(string bundle, string prop, Color val)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (!CachedColors.ContainsKey(bundle))
			{
				CachedColors[bundle] = new Dictionary<string, Color>();
			}
			CachedColors[bundle][prop] = val;
		}

		public static void ForceApplyCache(string bundlePath)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			if (!ActiveMaterials.TryGetValue(bundlePath, out var value) || !((Object)(object)value != (Object)null) || ((Il2CppObjectBase)value).WasCollected)
			{
				return;
			}
			if (CachedFloats.ContainsKey(bundlePath))
			{
				foreach (KeyValuePair<string, float> item in CachedFloats[bundlePath])
				{
					value.SetFloat(item.Key, item.Value);
				}
			}
			if (!CachedColors.ContainsKey(bundlePath))
			{
				return;
			}
			foreach (KeyValuePair<string, Color> item2 in CachedColors[bundlePath])
			{
				value.SetColor(item2.Key, item2.Value);
			}
		}

		public static void ResetMaterialToDefaults(string bundlePath)
		{
			if (CachedFloats.ContainsKey(bundlePath))
			{
				CachedFloats.Remove(bundlePath);
			}
			if (CachedColors.ContainsKey(bundlePath))
			{
				CachedColors.Remove(bundlePath);
			}
			if (ActiveMaterials.TryGetValue(bundlePath, out var value))
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)value);
				}
				ActiveMaterials.Remove(bundlePath);
			}
			RestoreAsset(bundlePath);
		}

		public static void TogglePostProcess(string bundlePath)
		{
			if (ActiveShaderOrder.Contains(bundlePath))
			{
				ActiveShaderOrder.Remove(bundlePath);
				CheckAndUnloadUnused(bundlePath);
				return;
			}
			RestoreAsset(bundlePath);
			if (ActiveMaterials.ContainsKey(bundlePath) || ActivePrefabs.ContainsKey(bundlePath))
			{
				ActiveShaderOrder.Add(bundlePath);
			}
		}

		public static void EnsureAssetsAlive()
		{
			foreach (string item in ActiveShaderOrder.ToList())
			{
				bool flag = true;
				if (ActiveMaterials.TryGetValue(item, out var value) && (Object)(object)value != (Object)null && !((Il2CppObjectBase)value).WasCollected)
				{
					flag = false;
				}
				if (ActivePrefabs.TryGetValue(item, out var value2) && (Object)(object)value2 != (Object)null && !((Il2CppObjectBase)value2).WasCollected)
				{
					flag = false;
				}
				if (flag)
				{
					RestoreAsset(item);
				}
				ForceApplyCache(item);
			}
			foreach (KeyValuePair<string, string> item2 in WorldReplacements.ToList())
			{
				if (ActiveMaterials.TryGetValue(item2.Value, out var value3) && ((Object)(object)value3 == (Object)null || ((Il2CppObjectBase)value3).WasCollected))
				{
					RestoreAsset(item2.Value);
				}
				ForceApplyCache(item2.Value);
			}
		}

		private static void RestoreAsset(string bundlePath)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			AssetBundle val = LoadBundle(bundlePath);
			if (val == null)
			{
				return;
			}
			foreach (Object item in (Il2CppArrayBase<Object>)(object)val.LoadAllAssets())
			{
				Material val2 = ((Il2CppObjectBase)item).TryCast<Material>();
				if ((Object)(object)val2 != (Object)null)
				{
					Material val3 = ((Il2CppObjectBase)Object.Instantiate<Material>(val2)).Cast<Material>();
					Object.DontDestroyOnLoad((Object)(object)val3);
					ActiveMaterials[bundlePath] = val3;
					ForceApplyCache(bundlePath);
					break;
				}
				GameObject val4 = ((Il2CppObjectBase)item).TryCast<GameObject>();
				if ((Object)(object)val4 != (Object)null)
				{
					GameObject val5 = Object.Instantiate<GameObject>(val4);
					Object.DontDestroyOnLoad((Object)(object)val5);
					if ((Object)(object)Camera.main != (Object)null)
					{
						val5.transform.position = ((Component)Camera.main).transform.position;
					}
					ActivePrefabs[bundlePath] = val5;
					break;
				}
			}
		}

		private static AssetBundle LoadBundle(string bundlePath)
		{
			if (_loadedBundles.ContainsKey(bundlePath))
			{
				return _loadedBundles[bundlePath];
			}
			AssetBundle val = AssetBundle.LoadFromFile(bundlePath);
			if (val != null)
			{
				_loadedBundles[bundlePath] = val;
			}
			return val;
		}

		public static Material LoadAndGetMaterial(string bundlePath)
		{
			RestoreAsset(bundlePath);
			if (ActiveMaterials.ContainsKey(bundlePath))
			{
				return ActiveMaterials[bundlePath];
			}
			return null;
		}

		public static void MoveLayerUp(string bundlePath)
		{
			int num = ActiveShaderOrder.IndexOf(bundlePath);
			if (num > 0)
			{
				ActiveShaderOrder[num] = ActiveShaderOrder[num - 1];
				ActiveShaderOrder[num - 1] = bundlePath;
			}
		}

		public static void MoveLayerDown(string bundlePath)
		{
			int num = ActiveShaderOrder.IndexOf(bundlePath);
			if (num < ActiveShaderOrder.Count - 1 && num != -1)
			{
				ActiveShaderOrder[num] = ActiveShaderOrder[num + 1];
				ActiveShaderOrder[num + 1] = bundlePath;
			}
		}

		public static void SetWorldMaterial(string target, string bundlePath)
		{
			if (string.IsNullOrEmpty(bundlePath))
			{
				if (WorldReplacements.ContainsKey(target))
				{
					string bundlePath2 = WorldReplacements[target];
					WorldReplacements.Remove(target);
					CheckAndUnloadUnused(bundlePath2);
				}
				return;
			}
			Material val = LoadAndGetMaterial(bundlePath);
			if ((Object)(object)val != (Object)null)
			{
				if (WorldReplacements.ContainsKey(target))
				{
					string bundlePath3 = WorldReplacements[target];
					WorldReplacements[target] = bundlePath;
					CheckAndUnloadUnused(bundlePath3);
				}
				else
				{
					WorldReplacements[target] = bundlePath;
				}
			}
		}

		private static void CheckAndUnloadUnused(string bundlePath)
		{
			if (!ActiveShaderOrder.Contains(bundlePath) && !WorldReplacements.Values.Contains(bundlePath))
			{
				if (ActiveMaterials.ContainsKey(bundlePath))
				{
					Object.Destroy((Object)(object)ActiveMaterials[bundlePath]);
					ActiveMaterials.Remove(bundlePath);
				}
				if (ActivePrefabs.ContainsKey(bundlePath))
				{
					Object.Destroy((Object)(object)ActivePrefabs[bundlePath]);
					ActivePrefabs.Remove(bundlePath);
				}
				if (_loadedBundles.TryGetValue(bundlePath, out var value))
				{
					value.Unload(true);
					_loadedBundles.Remove(bundlePath);
				}
			}
		}

		public static void UpdateWorldMaterials()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				foreach (GameObject value5 in ActivePrefabs.Values)
				{
					if ((Object)(object)value5 != (Object)null && !((Il2CppObjectBase)value5).WasCollected)
					{
						value5.transform.position = ((Component)main).transform.position;
					}
				}
			}
			if (WorldReplacements.TryGetValue("Skybox", out var value) && ActiveMaterials.TryGetValue(value, out var value2))
			{
				RenderSettings.skybox = value2;
			}
			if (!WorldReplacements.TryGetValue("WaterTop", out var value3) || !ActiveMaterials.TryGetValue(value3, out var value4))
			{
				return;
			}
			Il2CppArrayBase<Renderer> val = Object.FindObjectsOfType<Renderer>();
			foreach (Renderer item in val)
			{
				if (((Object)((Component)item).gameObject).name.Contains("WaterTop") || ((Object)((Component)item).gameObject).name.Contains("LavaPiece"))
				{
					item.material = value4;
				}
			}
		}

		public static void DisableAllShaders()
		{
			ActiveShaderOrder.Clear();
			WorldReplacements.Clear();
			foreach (Material value in ActiveMaterials.Values)
			{
				if ((Object)(object)value != (Object)null && !((Il2CppObjectBase)value).WasCollected)
				{
					Object.Destroy((Object)(object)value);
				}
			}
			ActiveMaterials.Clear();
			foreach (GameObject value2 in ActivePrefabs.Values)
			{
				if ((Object)(object)value2 != (Object)null && !((Il2CppObjectBase)value2).WasCollected)
				{
					Object.Destroy((Object)(object)value2);
				}
			}
			ActivePrefabs.Clear();
			foreach (AssetBundle value3 in _loadedBundles.Values)
			{
				if (value3 != null)
				{
					value3.Unload(true);
				}
			}
			_loadedBundles.Clear();
		}

		public static void SaveAutoSave()
		{
			if (Plugin.Instance.RememberStateConfig.Value)
			{
				SavePreset("_AutoSave");
			}
		}

		public static void LoadAutoSave()
		{
			if (Plugin.Instance.RememberStateConfig.Value)
			{
				LoadPreset("_AutoSave");
			}
		}

		public static void SavePreset(string name)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Invalid comparison between Unknown and I4
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Invalid comparison between Unknown and I4
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Invalid comparison between Unknown and I4
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(PresetsFolder, name + ".txt");
			using StreamWriter streamWriter = new StreamWriter(path);
			streamWriter.WriteLine("[POST_PROCESS]");
			foreach (string item in ActiveShaderOrder)
			{
				streamWriter.WriteLine(item);
			}
			streamWriter.WriteLine("[WORLD_MODS]");
			foreach (KeyValuePair<string, string> worldReplacement in WorldReplacements)
			{
				streamWriter.WriteLine(worldReplacement.Key + "=" + worldReplacement.Value);
			}
			streamWriter.WriteLine("[PROPERTIES]");
			foreach (KeyValuePair<string, Material> activeMaterial in ActiveMaterials)
			{
				string key = activeMaterial.Key;
				Material value = activeMaterial.Value;
				for (int i = 0; i < value.shader.GetPropertyCount(); i++)
				{
					ShaderPropertyType propertyType = value.shader.GetPropertyType(i);
					string propertyName = value.shader.GetPropertyName(i);
					if ((int)propertyType == 2 || (int)propertyType == 3)
					{
						streamWriter.WriteLine($"{key}|FLOAT|{propertyName}={value.GetFloat(propertyName)}");
					}
					else if ((int)propertyType == 0)
					{
						Color color = value.GetColor(propertyName);
						streamWriter.WriteLine($"{key}|COLOR|{propertyName}={color.r},{color.g},{color.b},{color.a}");
					}
				}
			}
		}

		public static void LoadPreset(string name)
		{
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(PresetsFolder, name + ".txt");
			if (!File.Exists(path))
			{
				return;
			}
			DisableAllShaders();
			string[] array = File.ReadAllLines(path);
			string text = "";
			string[] array2 = array;
			Color val = default(Color);
			foreach (string text2 in array2)
			{
				if (text2.StartsWith("["))
				{
					text = text2;
				}
				else
				{
					if (string.IsNullOrWhiteSpace(text2))
					{
						continue;
					}
					switch (text)
					{
					case "[POST_PROCESS]":
						TogglePostProcess(text2);
						break;
					case "[WORLD_MODS]":
					{
						string[] array6 = text2.Split(new char[1] { '=' });
						if (array6.Length == 2)
						{
							SetWorldMaterial(array6[0], array6[1]);
						}
						break;
					}
					case "[PROPERTIES]":
					{
						string[] array3 = text2.Split(new char[1] { '=' });
						string[] array4 = array3[0].Split(new char[1] { '|' });
						if (array3.Length != 2 || array4.Length != 3)
						{
							break;
						}
						string text3 = array4[0];
						string text4 = array4[1];
						string text5 = array4[2];
						if (!ActiveMaterials.TryGetValue(text3, out var value))
						{
							break;
						}
						if (text4 == "FLOAT" && float.TryParse(array3[1], out var result))
						{
							value.SetFloat(text5, result);
							SaveFloatToCache(text3, text5, result);
						}
						else if (text4 == "COLOR")
						{
							string[] array5 = array3[1].Split(new char[1] { ',' });
							if (array5.Length == 4)
							{
								((Color)(ref val))..ctor(float.Parse(array5[0]), float.Parse(array5[1]), float.Parse(array5[2]), float.Parse(array5[3]));
								value.SetColor(text5, val);
								SaveColorToCache(text3, text5, val);
							}
						}
						break;
					}
					}
				}
			}
		}
	}
	public class ShaderMenu : MonoBehaviour
	{
		public static KeyCode MenuKey = (KeyCode)287;

		private bool _isWaitingForKey = false;

		private bool _isMenuOpen = false;

		private Rect _windowRect = new Rect(20f, 20f, 480f, 680f);

		private Vector2 _scrollPos = Vector2.zero;

		private int _currentTab = 0;

		private string[] _tabs = new string[3] { "Post-Process", "World Mods", "Presets" };

		private string _presetInputName = "MyPreset";

		private string _selectedMaterialProperties = "";

		private float _worldUpdateTimer = 0f;

		private Dictionary<string, string> _textInputCache = new Dictionary<string, string>();

		public ShaderMenu(IntPtr ptr)
			: base(ptr)
		{
		}//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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)


		public void Start()
		{
			//IL_000b: 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)
			MenuKey = Plugin.Instance.MenuKeyConfig.Value;
			ShaderManager.LoadAutoSave();
		}

		public void Update()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (!_isWaitingForKey && Input.GetKeyDown(MenuKey))
			{
				bool isMenuOpen = _isMenuOpen;
				_isMenuOpen = !_isMenuOpen;
				UpdateCursor();
				if (isMenuOpen && !_isMenuOpen)
				{
					ShaderManager.SaveAutoSave();
				}
			}
			_worldUpdateTimer += Time.deltaTime;
			if (_worldUpdateTimer > 1f)
			{
				_worldUpdateTimer = 0f;
				ShaderManager.EnsureAssetsAlive();
				ShaderManager.UpdateWorldMaterials();
			}
			foreach (Camera item in (Il2CppArrayBase<Camera>)(object)Camera.allCameras)
			{
				if (!((Object)(object)item == (Object)null))
				{
					string text = ((Object)item).name.ToLower();
					if (!text.Contains("ui") && !text.Contains("overlay") && !text.Contains("canvas") && (Object)(object)((Component)item).gameObject.GetComponent<CameraShaderEffect>() == (Object)null)
					{
						((Component)item).gameObject.AddComponent<CameraShaderEffect>();
					}
				}
			}
		}

		private void UpdateCursor()
		{
			Cursor.lockState = (CursorLockMode)((!_isMenuOpen) ? 1 : 0);
			Cursor.visible = _isMenuOpen;
		}

		public void OnGUI()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (_isWaitingForKey)
			{
				Event current = Event.current;
				if (current.isKey && (int)current.type == 4 && (int)current.keyCode > 0)
				{
					MenuKey = current.keyCode;
					Plugin.Instance.MenuKeyConfig.Value = MenuKey;
					((BasePlugin)Plugin.Instance).Config.Save();
					_isWaitingForKey = false;
					current.Use();
				}
			}
			if (_isMenuOpen)
			{
				_windowRect = GUI.Window(6969, _windowRect, DelegateSupport.ConvertDelegate<WindowFunction>((Delegate)new Action<int>(DrawMenuWindow)), "Antro Shaders Engine");
			}
		}

		private void DrawMenuWindow(int windowID)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Menu Key:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
			GUI.color = (_isWaitingForKey ? Color.yellow : Color.white);
			if (GUILayout.Button(_isWaitingForKey ? "Press key..." : ((object)(KeyCode)(ref MenuKey)).ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(20f) }))
			{
				_isWaitingForKey = true;
			}
			GUI.color = Color.white;
			if (GUILayout.Button("Refresh Folders", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(20f) }))
			{
				ShaderManager.RefreshList();
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(5f);
			bool flag = GUILayout.Toggle(Plugin.Instance.RememberStateConfig.Value, " Remember Settings Between Sessions (Auto-Load)", Array.Empty<GUILayoutOption>());
			if (flag != Plugin.Instance.RememberStateConfig.Value)
			{
				Plugin.Instance.RememberStateConfig.Value = flag;
				((BasePlugin)Plugin.Instance).Config.Save();
				if (flag)
				{
					ShaderManager.SaveAutoSave();
				}
			}
			GUILayout.Space(10f);
			_currentTab = GUILayout.Toolbar(_currentTab, Il2CppStringArray.op_Implicit(_tabs), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
			GUILayout.Space(10f);
			_scrollPos = GUILayout.BeginScrollView(_scrollPos, GUI.skin.box);
			if (_currentTab == 0)
			{
				DrawPostProcessTab();
			}
			else if (_currentTab == 1)
			{
				DrawWorldModsTab();
			}
			else if (_currentTab == 2)
			{
				DrawPresetsTab();
			}
			GUILayout.EndScrollView();
			if (GUILayout.Button("DISABLE ALL SHADERS", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				ShaderManager.DisableAllShaders();
				_selectedMaterialProperties = "";
				ShaderManager.SaveAutoSave();
			}
			GUI.DragWindow();
		}

		private void DrawPostProcessTab()
		{
			//IL_004c: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Label("--- Active Camera Shaders ---", Array.Empty<GUILayoutOption>());
			for (int i = 0; i < ShaderManager.ActiveShaderOrder.Count; i++)
			{
				string text = ShaderManager.ActiveShaderOrder[i];
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUI.color = ((_selectedMaterialProperties == text) ? Color.cyan : Color.green);
				if (GUILayout.Button("[ON] " + fileNameWithoutExtension, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) }))
				{
					if (Event.current.button == 1)
					{
						if (ShaderManager.ActiveMaterials.ContainsKey(text))
						{
							_selectedMaterialProperties = ((_selectedMaterialProperties == text) ? "" : text);
						}
					}
					else
					{
						ShaderManager.TogglePostProcess(text);
						if (_selectedMaterialProperties == text)
						{
							_selectedMaterialProperties = "";
						}
						ShaderManager.SaveAutoSave();
					}
				}
				GUI.color = Color.white;
				GUI.enabled = i > 0;
				if (GUILayout.Button("↑", (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(25f),
					GUILayout.Height(25f)
				}))
				{
					ShaderManager.MoveLayerUp(text);
					ShaderManager.SaveAutoSave();
				}
				GUI.enabled = i < ShaderManager.ActiveShaderOrder.Count - 1;
				if (GUILayout.Button("↓", (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(25f),
					GUILayout.Height(25f)
				}))
				{
					ShaderManager.MoveLayerDown(text);
					ShaderManager.SaveAutoSave();
				}
				GUI.enabled = true;
				GUILayout.EndHorizontal();
				if (_selectedMaterialProperties == text)
				{
					DrawMaterialProperties(ShaderManager.ActiveMaterials[text], text);
				}
			}
			GUILayout.Space(10f);
			GUILayout.Label("--- Available Bundles ---", Array.Empty<GUILayoutOption>());
			foreach (string item in ShaderManager.AvailableShaders.Where((string s) => !ShaderManager.ActiveShaderOrder.Contains(s)))
			{
				if (GUILayout.Button("[OFF] " + Path.GetFileNameWithoutExtension(item), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) }))
				{
					ShaderManager.TogglePostProcess(item);
					ShaderManager.SaveAutoSave();
				}
			}
		}

		private void DrawWorldModsTab()
		{
			//IL_0041: 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)
			//IL_0058: Expected O, but got Unknown
			string[] array = new string[2] { "Skybox", "WaterTop" };
			string[] array2 = array;
			foreach (string text in array2)
			{
				GUILayout.Label("[ " + text + " Material ]", new GUIStyle(GUI.skin.label)
				{
					fontStyle = (FontStyle)1
				}, Array.Empty<GUILayoutOption>());
				string text2 = (ShaderManager.WorldReplacements.ContainsKey(text) ? ShaderManager.WorldReplacements[text] : null);
				if (GUILayout.Button((text2 == null) ? "None (Default)" : ("ACTIVE: " + Path.GetFileNameWithoutExtension(text2)), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) }))
				{
					if (Event.current.button == 1 && text2 != null)
					{
						_selectedMaterialProperties = ((_selectedMaterialProperties == text2) ? "" : text2);
					}
					else
					{
						ShaderManager.SetWorldMaterial(text, null);
						ShaderManager.SaveAutoSave();
					}
				}
				if (_selectedMaterialProperties == text2 && text2 != null)
				{
					DrawMaterialProperties(ShaderManager.ActiveMaterials[text2], text2);
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				foreach (string availableShader in ShaderManager.AvailableShaders)
				{
					if (text2 != availableShader && GUILayout.Button(Path.GetFileNameWithoutExtension(availableShader), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }))
					{
						ShaderManager.SetWorldMaterial(text, availableShader);
						ShaderManager.UpdateWorldMaterials();
						ShaderManager.SaveAutoSave();
					}
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(10f);
			}
		}

		private void DrawMaterialProperties(Material mat, string uniqueID)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Invalid comparison between Unknown and I4
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Invalid comparison between Unknown and I4
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Invalid comparison between Unknown and I4
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mat == (Object)null)
			{
				return;
			}
			GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			FontStyle val = (FontStyle)1;
			GUILayout.Label("Shader Settings:", GUIStyle.op_Implicit(((object)(FontStyle)(ref val)).ToString()), Array.Empty<GUILayoutOption>());
			GUI.color = new Color(1f, 0.5f, 0.5f);
			if (GUILayout.Button("Reset Defaults", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) }))
			{
				ShaderManager.ResetMaterialToDefaults(uniqueID);
				List<string> list = _textInputCache.Keys.Where((string k) => k.StartsWith(uniqueID + "_")).ToList();
				foreach (string item in list)
				{
					_textInputCache.Remove(item);
				}
				ShaderManager.SaveAutoSave();
				GUI.color = Color.white;
				GUILayout.EndHorizontal();
				GUILayout.EndVertical();
				return;
			}
			GUI.color = Color.white;
			GUILayout.EndHorizontal();
			Event current2 = Event.current;
			for (int i = 0; i < mat.shader.GetPropertyCount(); i++)
			{
				string propertyName = mat.shader.GetPropertyName(i);
				ShaderPropertyType propertyType = mat.shader.GetPropertyType(i);
				string text = uniqueID + "_" + propertyName;
				string text2 = text + "_text";
				if ((int)propertyType == 2 || (int)propertyType == 3)
				{
					float num = mat.GetFloat(propertyName);
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					GUILayout.Label(propertyName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) });
					float num2 = GUILayout.HorizontalSlider(num, -10f, 10f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
					GUI.SetNextControlName(text2);
					bool flag = GUI.GetNameOfFocusedControl() == text2;
					if (Mathf.Abs(num2 - num) > 0.001f)
					{
						num = num2;
						_textInputCache[text2] = num.ToString("0.00");
					}
					else
					{
						if (!_textInputCache.ContainsKey(text2) && !flag)
						{
							_textInputCache[text2] = num.ToString("0.00");
						}
						string text3 = GUILayout.TextField(_textInputCache[text2], (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
						_textInputCache[text2] = text3;
						if (flag && float.TryParse(text3, out var result))
						{
							num = result;
						}
					}
					GUILayout.EndHorizontal();
					mat.SetFloat(propertyName, num);
					ShaderManager.SaveFloatToCache(uniqueID, propertyName, num);
				}
				else if ((int)propertyType == 0)
				{
					Color color = mat.GetColor(propertyName);
					GUILayout.Label(propertyName + " (RGBA):", Array.Empty<GUILayoutOption>());
					color.r = DrawColorSlider(text + "_R", "R", color.r);
					color.g = DrawColorSlider(text + "_G", "G", color.g);
					color.b = DrawColorSlider(text + "_B", "B", color.b);
					color.a = DrawColorSlider(text + "_A", "A", color.a);
					mat.SetColor(propertyName, color);
					ShaderManager.SaveColorToCache(uniqueID, propertyName, color);
				}
			}
			GUILayout.EndVertical();
		}

		private float DrawColorSlider(string controlName, string label, float val)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(20f) });
			string text = controlName + "_text";
			float num = GUILayout.HorizontalSlider(val, 0f, 2f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUI.SetNextControlName(text);
			bool flag = GUI.GetNameOfFocusedControl() == text;
			if (Mathf.Abs(num - val) > 0.001f)
			{
				val = num;
				_textInputCache[text] = val.ToString("0.00");
			}
			else
			{
				if (!_textInputCache.ContainsKey(text) && !flag)
				{
					_textInputCache[text] = val.ToString("0.00");
				}
				string text2 = GUILayout.TextField(_textInputCache[text], (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
				_textInputCache[text] = text2;
				if (flag && float.TryParse(text2, out var result))
				{
					val = result;
				}
			}
			GUILayout.EndHorizontal();
			return val;
		}

		private void DrawPresetsTab()
		{
			GUILayout.Label("Save Current Configuration:", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			_presetInputName = GUILayout.TextField(_presetInputName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			if (GUILayout.Button("SAVE", Array.Empty<GUILayoutOption>()))
			{
				ShaderManager.SavePreset(_presetInputName);
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(20f);
			GUILayout.Label("Saved Presets:", Array.Empty<GUILayoutOption>());
			if (!Directory.Exists(ShaderManager.PresetsFolder))
			{
				return;
			}
			string[] array = (from f in Directory.GetFiles(ShaderManager.PresetsFolder, "*.txt")
				where !f.EndsWith("_AutoSave.txt")
				select f).ToArray();
			string[] array2 = array;
			foreach (string path in array2)
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label(fileNameWithoutExtension, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) });
				if (GUILayout.Button("LOAD", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }))
				{
					ShaderManager.LoadPreset(fileNameWithoutExtension);
					ShaderManager.SaveAutoSave();
				}
				if (GUILayout.Button("DELETE", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }))
				{
					File.Delete(path);
				}
				GUILayout.EndHorizontal();
			}
		}
	}
}