Decompiled source of AntroTextures v1.0.0

Antro.Textures.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.IL2CPP;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using UnityEngine;
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.Textures")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Antro.Textures")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyProduct("Antro.Textures")]
[assembly: AssemblyTitle("Antro.Textures")]
[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.Textures
{
	internal static class Patches
	{
		[HarmonyPatch(typeof(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique), "Awake")]
		[HarmonyPostfix]
		public static void SpawnSystemSteam()
		{
			InitSystem();
		}

		[HarmonyPatch(typeof(MonoBehaviourPublicObInVoAwVoVoVoVoVoVoUnique), "Awake")]
		[HarmonyPostfix]
		public static void SpawnSystemMain()
		{
			InitSystem();
		}

		private static void InitSystem()
		{
			//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("AntroTextureSystem") == (Object)null)
			{
				GameObject val = new GameObject("AntroTextureSystem");
				Object.DontDestroyOnLoad((Object)(object)val);
				val.AddComponent<TextureMenu>();
				((BasePlugin)Plugin.Instance).Log.LogInfo((object)"Antro Textures: System successfully created! Press T.");
			}
		}
	}
	[BepInPlugin("Antro.Textures", "Antro Textures Engine", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public ConfigEntry<KeyCode> MenuKeyConfig;

		public ConfigEntry<string> ActivePackConfig;

		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)116, "Key to open the Texture Menu");
			ActivePackConfig = ((BasePlugin)this).Config.Bind<string>("Settings", "ActivePack", "None", "Currently active texture pack");
			RememberStateConfig = ((BasePlugin)this).Config.Bind<bool>("Settings", "RememberState", false, "Remember active texture pack between sessions");
			ClassInjector.RegisterTypeInIl2Cpp<TextureMenu>();
			TextureManager.Init();
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
			((BasePlugin)this).Log.LogInfo((object)"Antro Textures Engine загружен! Ожидание инициализации Unity...");
		}
	}
	public static class TextureManager
	{
		private class OriginalMatData
		{
			public Texture BaseMap;

			public Texture MainTex;

			public string BaseMapName;

			public string MainTexName;
		}

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

		public static string ActivePack = "None";

		private static Dictionary<string, Dictionary<string, Texture2D>> _packCache = new Dictionary<string, Dictionary<string, Texture2D>>();

		private static Dictionary<string, Texture2D> _cachedCustomTextures = new Dictionary<string, Texture2D>();

		private static Dictionary<Material, OriginalMatData> _originalMaterials = new Dictionary<Material, OriginalMatData>();

		public static string BaseFolder => Path.Combine(Paths.PluginPath, "AntroTextures");

		public static string DefaultOriginalFolder => Path.Combine(BaseFolder, "Original");

		public static void Init()
		{
			if (!Directory.Exists(BaseFolder))
			{
				Directory.CreateDirectory(BaseFolder);
			}
			if (!Directory.Exists(DefaultOriginalFolder))
			{
				Directory.CreateDirectory(DefaultOriginalFolder);
			}
			RefreshPacks();
			if (Plugin.Instance.RememberStateConfig.Value)
			{
				string value = Plugin.Instance.ActivePackConfig.Value;
				if (value != "None" && AvailablePacks.Contains(value))
				{
					SetActivePack(value);
				}
			}
			else
			{
				Plugin.Instance.ActivePackConfig.Value = "None";
				((BasePlugin)Plugin.Instance).Config.Save();
			}
		}

		public static void RefreshPacks()
		{
			if (!Directory.Exists(BaseFolder))
			{
				Directory.CreateDirectory(BaseFolder);
			}
			AvailablePacks.Clear();
			string[] directories = Directory.GetDirectories(BaseFolder);
			string[] array = directories;
			foreach (string path in array)
			{
				AvailablePacks.Add(new DirectoryInfo(path).Name);
			}
		}

		public static void SetActivePack(string packName)
		{
			if (ActivePack == packName && packName != "None")
			{
				return;
			}
			RestoreOriginalTextures();
			if (packName == "None")
			{
				ActivePack = "None";
				_cachedCustomTextures = new Dictionary<string, Texture2D>();
				if (Plugin.Instance.RememberStateConfig.Value)
				{
					Plugin.Instance.ActivePackConfig.Value = "None";
					((BasePlugin)Plugin.Instance).Config.Save();
				}
				return;
			}
			string path = Path.Combine(BaseFolder, packName);
			if (Directory.Exists(path))
			{
				ActivePack = packName;
				if (!_packCache.ContainsKey(packName))
				{
					LoadPackToCache(packName, path);
				}
				_cachedCustomTextures = _packCache[packName];
				if (Plugin.Instance.RememberStateConfig.Value)
				{
					Plugin.Instance.ActivePackConfig.Value = packName;
					((BasePlugin)Plugin.Instance).Config.Save();
				}
			}
		}

		public static void ClearAllCaches()
		{
			RestoreOriginalTextures();
			ActivePack = "None";
			_cachedCustomTextures = new Dictionary<string, Texture2D>();
			foreach (Dictionary<string, Texture2D> value in _packCache.Values)
			{
				foreach (Texture2D value2 in value.Values)
				{
					if ((Object)(object)value2 != (Object)null && !((Il2CppObjectBase)value2).WasCollected)
					{
						Object.Destroy((Object)(object)value2);
					}
				}
			}
			_packCache.Clear();
			if (Plugin.Instance.RememberStateConfig.Value)
			{
				Plugin.Instance.ActivePackConfig.Value = "None";
				((BasePlugin)Plugin.Instance).Config.Save();
			}
			((BasePlugin)Plugin.Instance).Log.LogInfo((object)"Texture RAM Cache cleared!");
		}

		private static void RestoreOriginalTextures()
		{
			foreach (KeyValuePair<Material, OriginalMatData> originalMaterial in _originalMaterials)
			{
				Material key = originalMaterial.Key;
				if (!((Object)(object)key == (Object)null) && !((Il2CppObjectBase)key).WasCollected)
				{
					if (key.HasProperty("_BaseMap"))
					{
						key.SetTexture("_BaseMap", originalMaterial.Value.BaseMap);
					}
					if (key.HasProperty("_MainTex"))
					{
						key.SetTexture("_MainTex", originalMaterial.Value.MainTex);
					}
					key.mainTexture = originalMaterial.Value.BaseMap ?? originalMaterial.Value.MainTex;
				}
			}
		}

		private static void LoadPackToCache(string packName, string path)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loading pack '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(packName);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' from disk...");
			}
			log.LogInfo(val);
			Dictionary<string, Texture2D> dictionary = new Dictionary<string, Texture2D>();
			string[] files = Directory.GetFiles(path, "*.png");
			QualitySettings.masterTextureLimit = 0;
			QualitySettings.anisotropicFiltering = (AnisotropicFiltering)2;
			string[] array = files;
			foreach (string path2 in array)
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path2);
				byte[] data = File.ReadAllBytes(path2);
				Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, true, false);
				((Object)val2).hideFlags = (HideFlags)61;
				SafeLoadImage(val2, data);
				((Object)val2).name = fileNameWithoutExtension;
				((Texture)val2).filterMode = (FilterMode)1;
				((Texture)val2).anisoLevel = 16;
				((Texture)val2).wrapMode = (TextureWrapMode)0;
				((Texture)val2).mipMapBias = -1.5f;
				val2.Apply(false, true);
				dictionary[fileNameWithoutExtension] = val2;
			}
			_packCache[packName] = dictionary;
		}

		public static void ApplyActiveTextures()
		{
			if (ActivePack == "None" || _cachedCustomTextures.Count == 0)
			{
				return;
			}
			Renderer[] array = Il2CppArrayBase<Renderer>.op_Implicit(Object.FindObjectsOfType<Renderer>());
			Renderer[] array2 = array;
			foreach (Renderer val in array2)
			{
				if ((Object)(object)val == (Object)null || ((Il2CppObjectBase)val).WasCollected)
				{
					continue;
				}
				foreach (Material item in (Il2CppArrayBase<Material>)(object)val.sharedMaterials)
				{
					if ((Object)(object)item == (Object)null || ((Il2CppObjectBase)item).WasCollected)
					{
						continue;
					}
					if (!_originalMaterials.ContainsKey(item))
					{
						OriginalMatData originalMatData = new OriginalMatData();
						if (item.HasProperty("_BaseMap"))
						{
							originalMatData.BaseMap = item.GetTexture("_BaseMap");
						}
						if (item.HasProperty("_MainTex"))
						{
							originalMatData.MainTex = item.GetTexture("_MainTex");
						}
						originalMatData.BaseMapName = (((Object)(object)originalMatData.BaseMap != (Object)null) ? SanitizeFileName(((Object)originalMatData.BaseMap).name) : "");
						originalMatData.MainTexName = (((Object)(object)originalMatData.MainTex != (Object)null) ? SanitizeFileName(((Object)originalMatData.MainTex).name) : "");
						_originalMaterials[item] = originalMatData;
					}
					OriginalMatData originalMatData2 = _originalMaterials[item];
					if (!string.IsNullOrEmpty(originalMatData2.BaseMapName) && _cachedCustomTextures.TryGetValue(originalMatData2.BaseMapName, out var value) && (Object)(object)item.GetTexture("_BaseMap") != (Object)(object)value)
					{
						item.SetTexture("_BaseMap", (Texture)(object)value);
						item.mainTexture = (Texture)(object)value;
					}
					if (!string.IsNullOrEmpty(originalMatData2.MainTexName) && _cachedCustomTextures.TryGetValue(originalMatData2.MainTexName, out var value2) && (Object)(object)item.GetTexture("_MainTex") != (Object)(object)value2)
					{
						item.SetTexture("_MainTex", (Texture)(object)value2);
						item.mainTexture = (Texture)(object)value2;
					}
				}
			}
		}

		public static void DumpAllOriginalTextures(string targetFolderName)
		{
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Expected O, but got Unknown
			string text = Path.Combine(BaseFolder, targetFolderName);
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			int savedCount = 0;
			HashSet<string> hashSet = new HashSet<string>();
			string[] files = Directory.GetFiles(text, "*.png");
			foreach (string path in files)
			{
				hashSet.Add(Path.GetFileNameWithoutExtension(path));
			}
			Renderer[] array = Il2CppArrayBase<Renderer>.op_Implicit(Object.FindObjectsOfType<Renderer>());
			Renderer[] array2 = array;
			foreach (Renderer val in array2)
			{
				if ((Object)(object)val == (Object)null || ((Il2CppObjectBase)val).WasCollected)
				{
					continue;
				}
				foreach (Material item in (Il2CppArrayBase<Material>)(object)val.sharedMaterials)
				{
					if ((Object)(object)item == (Object)null || ((Il2CppObjectBase)item).WasCollected)
					{
						continue;
					}
					Texture val2 = (item.HasProperty("_BaseMap") ? item.GetTexture("_BaseMap") : null);
					Texture val3 = (item.HasProperty("_MainTex") ? item.GetTexture("_MainTex") : null);
					Texture tex = (item.HasProperty("_EmissionMap") ? item.GetTexture("_EmissionMap") : null);
					if (_originalMaterials.TryGetValue(item, out var value))
					{
						if ((Object)(object)val2 != (Object)null && _cachedCustomTextures.ContainsValue((Texture2D)(object)((val2 is Texture2D) ? val2 : null)))
						{
							val2 = value.BaseMap;
						}
						if ((Object)(object)val3 != (Object)null && _cachedCustomTextures.ContainsValue((Texture2D)(object)((val3 is Texture2D) ? val3 : null)))
						{
							val3 = value.MainTex;
						}
					}
					ProcessTextureForDump(val2, text, hashSet, ref savedCount);
					ProcessTextureForDump(val3, text, hashSet, ref savedCount);
					ProcessTextureForDump(tex, text, hashSet, ref savedCount);
				}
			}
			ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(38, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Successfully Dumped ");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(savedCount);
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" textures into '");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(targetFolderName);
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("'.");
			}
			log.LogInfo(val4);
		}

		private static void ProcessTextureForDump(Texture tex, string folderPath, HashSet<string> alreadySaved, ref int savedCount)
		{
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			if ((Object)(object)tex == (Object)null || ((Il2CppObjectBase)tex).WasCollected || string.IsNullOrEmpty(((Object)tex).name))
			{
				return;
			}
			string text = SanitizeFileName(((Object)tex).name);
			if (alreadySaved.Contains(text) || text.StartsWith("unity_") || text.StartsWith("Font") || text.StartsWith("default"))
			{
				return;
			}
			Texture2D val = ((Il2CppObjectBase)tex).TryCast<Texture2D>();
			if ((Object)(object)val == (Object)null || ((Il2CppObjectBase)val).WasCollected || ((Texture)val).width <= 0 || ((Texture)val).height <= 0 || ((Texture)val).width > 8192 || ((Texture)val).height > 8192)
			{
				return;
			}
			try
			{
				Texture2D val2 = MakeReadableTexture(val);
				if ((Object)(object)val2 != (Object)null && !((Il2CppObjectBase)val2).WasCollected)
				{
					byte[] array = SafeEncodeToPNG(val2);
					if (array != null && array.Length != 0)
					{
						File.WriteAllBytes(Path.Combine(folderPath, text + ".png"), array);
						alreadySaved.Add(text);
						savedCount++;
					}
					Object.Destroy((Object)(object)val2);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(19, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to dump '");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("': ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
				}
				log.LogError(val3);
			}
		}

		private static byte[] SafeEncodeToPNG(Texture2D tex)
		{
			try
			{
				MethodInfo method = typeof(ImageConversion).GetMethod("EncodeToPNG", BindingFlags.Static | BindingFlags.Public);
				if (method != null)
				{
					object obj = method.Invoke(null, new object[1] { tex });
					if (obj is Il2CppStructArray<byte> val)
					{
						return Il2CppArrayBase<byte>.op_Implicit((Il2CppArrayBase<byte>)(object)val);
					}
					if (obj is byte[] result)
					{
						return result;
					}
				}
			}
			catch (Exception)
			{
			}
			return null;
		}

		private static void SafeLoadImage(Texture2D tex, byte[] data)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = null;
				MethodInfo[] methods = typeof(ImageConversion).GetMethods(BindingFlags.Static | BindingFlags.Public);
				foreach (MethodInfo methodInfo2 in methods)
				{
					if (methodInfo2.Name == "LoadImage" && methodInfo2.GetParameters().Length == 2)
					{
						methodInfo = methodInfo2;
						break;
					}
				}
				if (methodInfo != null)
				{
					Type parameterType = methodInfo.GetParameters()[1].ParameterType;
					object obj = data;
					if (parameterType == typeof(Il2CppStructArray<byte>))
					{
						obj = new Il2CppStructArray<byte>(data);
					}
					methodInfo.Invoke(null, new object[2] { tex, obj });
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("SafeLoadImage Exception: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogError(val);
			}
		}

		private static Texture2D MakeReadableTexture(Texture2D source)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			RenderTexture val = null;
			try
			{
				val = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)2);
				Graphics.Blit((Texture)(object)source, val);
				RenderTexture active = RenderTexture.active;
				RenderTexture.active = val;
				Texture2D val2 = new Texture2D(((Texture)source).width, ((Texture)source).height, (TextureFormat)4, false);
				val2.ReadPixels(new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), 0, 0);
				val2.Apply();
				RenderTexture.active = active;
				return val2;
			}
			finally
			{
				if ((Object)(object)val != (Object)null)
				{
					RenderTexture.ReleaseTemporary(val);
				}
			}
		}

		private static string SanitizeFileName(string name)
		{
			string text = name;
			char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
			foreach (char c in invalidFileNameChars)
			{
				text = text.Replace(c.ToString(), "_");
			}
			return text;
		}
	}
	public class TextureMenu : MonoBehaviour
	{
		public static KeyCode MenuKey = (KeyCode)116;

		private bool _isWaitingForKey = false;

		private bool _isMenuOpen = false;

		private Rect _windowRect = new Rect(20f, 20f, 420f, 580f);

		private Vector2 _scrollPos = Vector2.zero;

		private float _worldUpdateTimer = 0f;

		private string _dumpStatusText = "";

		private string _selectedPack = "Original";

		private string _newFolderInput = "MyTexturePack";

		private bool _isAutoDumping = false;

		private int _dumpSceneIndex = 0;

		private int _dumpState = 0;

		private int _waitFrames = 0;

		private bool _showDumpConfirmation = false;

		public TextureMenu(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;
		}

		public void Update()
		{
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			if (!_isWaitingForKey && Input.GetKeyDown(MenuKey))
			{
				_isMenuOpen = !_isMenuOpen;
				UpdateCursor();
			}
			if (_isAutoDumping)
			{
				if (_dumpState == 0)
				{
					_dumpStatusText = $"Loading Scene {_dumpSceneIndex} / {SceneManager.sceneCountInBuildSettings - 1}...";
					SceneManager.LoadScene(_dumpSceneIndex, (LoadSceneMode)0);
					_dumpState = 1;
				}
				else if (_dumpState == 1)
				{
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).buildIndex == _dumpSceneIndex)
					{
						_waitFrames = 60;
						_dumpState = 2;
					}
				}
				else if (_dumpState == 2)
				{
					if (_waitFrames > 0)
					{
						_waitFrames--;
						return;
					}
					_dumpState = 3;
				}
				else if (_dumpState == 3)
				{
					_dumpStatusText = $"Dumping Textures from Scene {_dumpSceneIndex} into '{_selectedPack}'...";
					try
					{
						TextureManager.DumpAllOriginalTextures(_selectedPack);
					}
					catch (Exception ex)
					{
						ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
						bool flag = default(bool);
						BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(23, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Dump failed on scene ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_dumpSceneIndex);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
						}
						log.LogError(val);
					}
					_dumpState = 4;
				}
				else if (_dumpState == 4)
				{
					_dumpSceneIndex++;
					if (_dumpSceneIndex >= SceneManager.sceneCountInBuildSettings)
					{
						_isAutoDumping = false;
						_dumpStatusText = "FULL AUTO-DUMP COMPLETE! Returned to Menu.";
						SceneManager.LoadScene(0);
						TextureManager.RefreshPacks();
					}
					else
					{
						_dumpState = 0;
					}
				}
			}
			_worldUpdateTimer += Time.deltaTime;
			if (_worldUpdateTimer > 1f && !_isAutoDumping)
			{
				_worldUpdateTimer = 0f;
				if (TextureManager.ActivePack != "None")
				{
					TextureManager.ApplyActiveTextures();
				}
			}
		}

		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(8989, _windowRect, DelegateSupport.ConvertDelegate<WindowFunction>((Delegate)new Action<int>(DrawMenuWindow)), "Antro Textures 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Expected O, but got Unknown
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Expected O, but got Unknown
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_066a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0711: Unknown result type (might be due to invalid IL or missing references)
			//IL_068c: Unknown result type (might be due to invalid IL or missing references)
			//IL_067f: 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;
			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;
				if (flag)
				{
					Plugin.Instance.ActivePackConfig.Value = TextureManager.ActivePack;
				}
				else
				{
					Plugin.Instance.ActivePackConfig.Value = "None";
				}
				((BasePlugin)Plugin.Instance).Config.Save();
			}
			GUILayout.Space(10f);
			GUILayout.Label("--- Dumper ---", new GUIStyle(GUI.skin.label)
			{
				fontStyle = (FontStyle)1
			}, Array.Empty<GUILayoutOption>());
			if (!_isAutoDumping)
			{
				if (!_showDumpConfirmation)
				{
					GUI.color = new Color(1f, 0.7f, 0.7f);
					if (GUILayout.Button("FULL DUMP (All Maps) into '" + _selectedPack + "'", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
					{
						_showDumpConfirmation = true;
					}
					GUI.color = Color.white;
				}
				else
				{
					GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
					GUI.color = Color.red;
					GUILayout.Label("WARNING: This will load ALL maps. The game will freeze. Are you sure?", new GUIStyle(GUI.skin.label)
					{
						fontStyle = (FontStyle)1
					}, Array.Empty<GUILayoutOption>());
					GUI.color = Color.white;
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					GUI.color = Color.green;
					if (GUILayout.Button("YES, START DUMP", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
					{
						_showDumpConfirmation = false;
						_isAutoDumping = true;
						_dumpSceneIndex = 0;
						_dumpState = 0;
						_dumpStatusText = "Initializing Full Dump into " + _selectedPack + "...";
					}
					GUI.color = Color.red;
					if (GUILayout.Button("CANCEL", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
					{
						_showDumpConfirmation = false;
					}
					GUI.color = Color.white;
					GUILayout.EndHorizontal();
					GUILayout.EndVertical();
				}
			}
			else
			{
				GUI.color = Color.yellow;
				GUILayout.Button("DUMPING IN PROGRESS... DO NOT TOUCH", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
				GUI.color = Color.white;
			}
			if (!string.IsNullOrEmpty(_dumpStatusText))
			{
				GUI.color = Color.green;
				GUILayout.Label(_dumpStatusText, Array.Empty<GUILayoutOption>());
				GUI.color = Color.white;
			}
			GUILayout.Space(15f);
			GUILayout.Label("--- Texture Packs ---", new GUIStyle(GUI.skin.label)
			{
				fontStyle = (FontStyle)1
			}, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			_newFolderInput = GUILayout.TextField(_newFolderInput, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			if (GUILayout.Button("Create Folder", Array.Empty<GUILayoutOption>()))
			{
				string path = Path.Combine(TextureManager.BaseFolder, _newFolderInput);
				if (!Directory.Exists(path))
				{
					Directory.CreateDirectory(path);
				}
				TextureManager.RefreshPacks();
				_selectedPack = _newFolderInput;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUI.color = Color.green;
			if (GUILayout.Button("APPLY: '" + _selectedPack + "'", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				TextureManager.SetActivePack(_selectedPack);
				TextureManager.ApplyActiveTextures();
			}
			GUI.color = new Color(1f, 0.4f, 0.4f);
			if (GUILayout.Button("DISABLE", (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(80f),
				GUILayout.Height(30f)
			}))
			{
				TextureManager.SetActivePack("None");
			}
			GUI.color = Color.white;
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Refresh Folders", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(20f) }))
			{
				TextureManager.RefreshPacks();
			}
			GUI.color = new Color(1f, 0.8f, 0.2f);
			if (GUILayout.Button("Force Reload Files", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(20f) }))
			{
				TextureManager.ClearAllCaches();
				if (_selectedPack != "None" && _selectedPack != "Original")
				{
					TextureManager.SetActivePack(_selectedPack);
					TextureManager.ApplyActiveTextures();
				}
			}
			GUI.color = Color.white;
			GUILayout.EndHorizontal();
			GUILayout.Space(5f);
			_scrollPos = GUILayout.BeginScrollView(_scrollPos, GUI.skin.box);
			if (TextureManager.AvailablePacks.Count == 0)
			{
				GUILayout.Label("No texture packs found.", Array.Empty<GUILayoutOption>());
			}
			else
			{
				foreach (string availablePack in TextureManager.AvailablePacks)
				{
					bool flag2 = TextureManager.ActivePack == availablePack;
					bool flag3 = _selectedPack == availablePack;
					if (flag2)
					{
						GUI.color = Color.green;
					}
					else if (flag3)
					{
						GUI.color = Color.cyan;
					}
					else
					{
						GUI.color = Color.white;
					}
					string text = availablePack;
					if (flag2)
					{
						text = "[ACTIVE] " + availablePack;
					}
					else if (flag3)
					{
						text = "[SELECTED] " + availablePack;
					}
					if (GUILayout.Button(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
					{
						_selectedPack = availablePack;
					}
				}
				GUI.color = Color.white;
			}
			GUILayout.EndScrollView();
			GUI.DragWindow();
		}
	}
}