Decompiled source of GladioSizer v1.1.4

BepInEx/plugins/Morse_Code_Guy-GladioSizer/GladioSizer.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Newtonsoft.Json;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("GladioSizer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GladioSizer")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ff174d88-048f-4b40-92e4-254b4853bc52")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PlayerHealthMenuMod;

[BepInPlugin("com.morsecodeguy.gladiosizer", "GladioSizer", "1.1.4")]
public class GladioSizer : BaseUnityPlugin
{
	private enum Tab
	{
		Scale,
		Presets
	}

	private ConfigEntry<KeyCode> ToggleMenuKeyConfig;

	private const float CheckInterval = 1f;

	private const string PresetsFolderName = "Presets";

	private bool _menuOpen = false;

	private bool _creatingPreset = false;

	private bool _editingPreset = false;

	private bool _showConfirmation = false;

	private string _confirmationMessage = "";

	private GameObject _playerHealthObject;

	private float _nextCheckTime = 0f;

	private Vector2 _scrollPositionScale;

	private Vector2 _scrollPositionPresets;

	private string _presetName = "";

	private string _presetDescription = "";

	private string _presetAuthor = "";

	private readonly Dictionary<string, List<GameObject>> _hookedObjects = new Dictionary<string, List<GameObject>>();

	private readonly Dictionary<string, ScaleData> _resizeInputs = new Dictionary<string, ScaleData>();

	private readonly Dictionary<string, ScaleInput> _scaleInputTexts = new Dictionary<string, ScaleInput>();

	private readonly Dictionary<GameObject, Vector3> _originalChildScales = new Dictionary<GameObject, Vector3>();

	private readonly List<string> _objectNames = new List<string> { "Shield", "ShortSword", "BeardedAxe", "Bardiche", "Longsword", "PlayerCharacter" };

	private readonly List<Preset> _presets = new List<Preset>();

	private string _presetsFolderPath;

	private Tab _currentTab = Tab.Scale;

	private const int PresetCreationWindowID = 1001;

	private const int PresetEditWindowID = 1003;

	private const int ConfirmationWindowID = 1002;

	private Preset _presetBeingEdited;

	private string _originalPresetName = "";

	private Preset _presetToDelete;

	private void Awake()
	{
		ToggleMenuKeyConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleMenuKey", (KeyCode)283, "Key to toggle the GladioSizer menu");
		_presetsFolderPath = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Presets");
		if (!Directory.Exists(_presetsFolderPath))
		{
			Directory.CreateDirectory(_presetsFolderPath);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Created Presets folder at " + _presetsFolderPath));
		}
	}

	private void Start()
	{
		HookObjects();
		_playerHealthObject = FindPlayerHealthObject();
		LoadPresets();
	}

	private void HookObjects()
	{
		foreach (string objectName in _objectNames)
		{
			if (!_hookedObjects.ContainsKey(objectName))
			{
				HookObject(objectName);
			}
		}
	}

	private void HookObject(string objectName)
	{
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		List<GameObject> list = ((!(objectName == "PlayerCharacter")) ? (from obj in Resources.FindObjectsOfTypeAll<GameObject>()
			where ((Object)obj).name.Equals(objectName, StringComparison.OrdinalIgnoreCase)
			where !HasParentWithName(obj, objectName)
			select obj).ToList() : (from obj in Resources.FindObjectsOfTypeAll<GameObject>()
			where ((Object)obj).name.Equals("PlayerCharacter", StringComparison.OrdinalIgnoreCase) || ((Object)obj).name.Equals("PlayerCharacterMultiplayer", StringComparison.OrdinalIgnoreCase)
			where !HasParentWithName(obj, objectName)
			select obj).ToList());
		if (list.Count > 0)
		{
			_hookedObjects[objectName] = list;
			foreach (GameObject item in list)
			{
				Debug.Log((object)("GladioSizer: Hooked object '" + ((Object)item).name + "'."));
				foreach (Transform item2 in item.transform)
				{
					Transform val = item2;
					if (!_originalChildScales.ContainsKey(((Component)val).gameObject))
					{
						_originalChildScales[((Component)val).gameObject] = val.localScale;
					}
				}
				if (!_scaleInputTexts.ContainsKey(objectName))
				{
					_scaleInputTexts[objectName] = new ScaleInput
					{
						x = (_resizeInputs.ContainsKey(objectName) ? _resizeInputs[objectName].x.ToString("0.##") : "1"),
						y = (_resizeInputs.ContainsKey(objectName) ? _resizeInputs[objectName].y.ToString("0.##") : "1"),
						z = (_resizeInputs.ContainsKey(objectName) ? _resizeInputs[objectName].z.ToString("0.##") : "1")
					};
				}
			}
			if (!_resizeInputs.ContainsKey(objectName))
			{
				_resizeInputs[objectName] = new ScaleData
				{
					x = 1f,
					y = 1f,
					z = 1f
				};
			}
		}
		else
		{
			Debug.LogWarning((object)("GladioSizer: Could not find object(s) for '" + objectName + "'."));
		}
	}

	private bool HasParentWithName(GameObject obj, string name)
	{
		Transform parent = obj.transform.parent;
		while ((Object)(object)parent != (Object)null)
		{
			if (((Object)((Component)parent).gameObject).name.Equals(name, StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			parent = parent.parent;
		}
		return false;
	}

	private void Update()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time >= _nextCheckTime)
		{
			_nextCheckTime = Time.time + 1f;
			_playerHealthObject = FindPlayerHealthObject();
			HookObjects();
		}
		if (Input.GetKeyDown(ToggleMenuKeyConfig.Value) && (Object)(object)_playerHealthObject != (Object)null)
		{
			_menuOpen = !_menuOpen;
		}
	}

	private void OnGUI()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Expected O, but got Unknown
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: 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_01a5: Expected O, but got Unknown
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Expected O, but got Unknown
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		if (_menuOpen)
		{
			int width = Screen.width;
			int num = (width - 600) / 2;
			int num2 = 50;
			GUILayout.BeginArea(new Rect((float)num, (float)num2, 600f, 700f), "GladioSizer", GUI.skin.box);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Scale", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(290f) }))
			{
				_currentTab = Tab.Scale;
			}
			if (GUILayout.Button("Presets", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(290f) }))
			{
				_currentTab = Tab.Presets;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(10f);
			switch (_currentTab)
			{
			case Tab.Scale:
				DrawScaleTab();
				break;
			case Tab.Presets:
				DrawPresetsTab();
				break;
			}
			GUILayout.EndArea();
			if (_creatingPreset)
			{
				GUILayout.Window(1001, new Rect((float)((Screen.width - 400) / 2), (float)((Screen.height - 300) / 2), 400f, 300f), new WindowFunction(DrawPresetCreationWindow), "Create New Preset", Array.Empty<GUILayoutOption>());
			}
			if (_editingPreset)
			{
				GUILayout.Window(1003, new Rect((float)((Screen.width - 500) / 2), (float)((Screen.height - 400) / 2), 500f, 400f), new WindowFunction(DrawPresetEditWindow), "Edit Preset", Array.Empty<GUILayoutOption>());
			}
			if (_showConfirmation)
			{
				GUILayout.Window(1002, new Rect((float)((Screen.width - 400) / 2), (float)((Screen.height - 150) / 2), 400f, 150f), new WindowFunction(DrawConfirmationWindow), "Preset Notification", Array.Empty<GUILayoutOption>());
			}
		}
	}

	private void DrawScaleTab()
	{
		//IL_0003: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		_scrollPositionScale = GUILayout.BeginScrollView(_scrollPositionScale, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(580f),
			GUILayout.Height(600f)
		});
		foreach (string item in _hookedObjects.Keys.ToList())
		{
			GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
			GUILayout.Label("RESIZE: " + item, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			if (_scaleInputTexts.TryGetValue(item, out var value))
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("Scale", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
				value.x = GUILayout.TextField(value.x, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
				value.x = new string(value.x.Where((char c) => !char.IsLetter(c)).ToArray());
				value.y = GUILayout.TextField(value.y, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
				value.y = new string(value.y.Where((char c) => !char.IsLetter(c)).ToArray());
				value.z = GUILayout.TextField(value.z, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
				value.z = new string(value.z.Where((char c) => !char.IsLetter(c)).ToArray());
				GUILayout.EndHorizontal();
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Resize " + item, Array.Empty<GUILayoutOption>()))
				{
					float result;
					bool flag = float.TryParse(value.x, NumberStyles.Float, CultureInfo.InvariantCulture, out result);
					float result2;
					bool flag2 = float.TryParse(value.y, NumberStyles.Float, CultureInfo.InvariantCulture, out result2);
					float result3;
					bool flag3 = float.TryParse(value.z, NumberStyles.Float, CultureInfo.InvariantCulture, out result3);
					if (flag && flag2 && flag3)
					{
						ResizeObject(item, new ScaleData
						{
							x = result,
							y = result2,
							z = result3
						});
					}
					else
					{
						Debug.LogWarning((object)"GladioSizer: Invalid input for scaling. Using previous valid values.");
					}
				}
				if (GUILayout.Button("Reset " + item, Array.Empty<GUILayoutOption>()))
				{
					ResetScale(item);
					if (_scaleInputTexts.ContainsKey(item))
					{
						_scaleInputTexts[item].x = "1";
						_scaleInputTexts[item].y = "1";
						_scaleInputTexts[item].z = "1";
					}
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndVertical();
			GUILayout.Space(5f);
		}
		GUILayout.EndScrollView();
		GUILayout.Space(10f);
		if (GUILayout.Button("Create Preset", Array.Empty<GUILayoutOption>()))
		{
			_creatingPreset = true;
			_presetName = "";
			_presetDescription = "";
			_presetAuthor = "";
		}
	}

	private void DrawPresetsTab()
	{
		//IL_0003: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		_scrollPositionPresets = GUILayout.BeginScrollView(_scrollPositionPresets, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(580f),
			GUILayout.Height(650f)
		});
		if (_presets.Count == 0)
		{
			GUILayout.Label("No presets found. Please add .json preset files to the Presets folder.", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
		}
		else
		{
			foreach (Preset item in _presets.ToList())
			{
				GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
				GUILayout.Label("Preset: " + item.Name, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
				GUILayout.Label("Description: " + item.Description, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
				GUILayout.Label("Author: " + item.Author, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Activate " + item.Name, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
				{
					ApplyPreset(item);
				}
				if (GUILayout.Button("Edit Preset", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
				{
					_presetBeingEdited = item;
					_originalPresetName = item.Name;
					_presetName = item.Name;
					_presetDescription = item.Description;
					_presetAuthor = item.Author;
					_editingPreset = true;
				}
				if (GUILayout.Button("Delete Preset", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
				{
					_presetToDelete = item;
					_confirmationMessage = "Are you sure you want to delete the preset \"" + item.Name + "\"?";
					_showConfirmation = true;
				}
				GUILayout.EndHorizontal();
				GUILayout.EndVertical();
				GUILayout.Space(5f);
			}
		}
		GUILayout.Space(10f);
		if (GUILayout.Button("Reload Presets", Array.Empty<GUILayoutOption>()))
		{
			LoadPresets();
		}
		GUILayout.EndScrollView();
	}

	private void ResizeObject(string objectName, ScaleData newScale)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		if (_hookedObjects.TryGetValue(objectName, out var value))
		{
			foreach (GameObject item in value)
			{
				if (!((Object)(object)item != (Object)null))
				{
					continue;
				}
				item.transform.localScale = new Vector3(newScale.x, newScale.y, newScale.z);
				Debug.Log((object)$"GladioSizer: Resized '{((Object)item).name}' to ({newScale.x}, {newScale.y}, {newScale.z}).");
				foreach (Transform item2 in item.transform)
				{
					Transform val = item2;
					if (_originalChildScales.TryGetValue(((Component)val).gameObject, out var value2))
					{
						val.localScale = value2;
					}
				}
			}
			if (_resizeInputs.ContainsKey(objectName))
			{
				_resizeInputs[objectName] = newScale;
			}
		}
		else
		{
			Debug.LogWarning((object)("GladioSizer: Cannot resize '" + objectName + "' because it is not hooked."));
		}
	}

	private void ResetScale(string objectName)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		if (_hookedObjects.TryGetValue(objectName, out var value))
		{
			foreach (GameObject item in value)
			{
				if (!((Object)(object)item != (Object)null))
				{
					continue;
				}
				item.transform.localScale = Vector3.one;
				Debug.Log((object)("GladioSizer: Reset '" + ((Object)item).name + "' scale to (1, 1, 1)."));
				foreach (Transform item2 in item.transform)
				{
					Transform val = item2;
					if (_originalChildScales.TryGetValue(((Component)val).gameObject, out var value2))
					{
						val.localScale = value2;
					}
				}
			}
			if (_resizeInputs.ContainsKey(objectName))
			{
				_resizeInputs[objectName] = new ScaleData
				{
					x = 1f,
					y = 1f,
					z = 1f
				};
			}
			if (_scaleInputTexts.ContainsKey(objectName))
			{
				_scaleInputTexts[objectName].x = "1";
				_scaleInputTexts[objectName].y = "1";
				_scaleInputTexts[objectName].z = "1";
			}
		}
		else
		{
			Debug.LogWarning((object)("GladioSizer: Cannot reset '" + objectName + "' because it is not hooked."));
		}
	}

	private GameObject FindPlayerHealthObject()
	{
		MonoBehaviour val = ((IEnumerable<MonoBehaviour>)Resources.FindObjectsOfTypeAll<MonoBehaviour>()).FirstOrDefault((Func<MonoBehaviour, bool>)((MonoBehaviour obj) => ((object)obj).GetType().Name.Equals("PlayerHealth", StringComparison.OrdinalIgnoreCase)));
		return (val != null) ? ((Component)val).gameObject : null;
	}

	private void LoadPresets()
	{
		_presets.Clear();
		if (!Directory.Exists(_presetsFolderPath))
		{
			Debug.LogWarning((object)("GladioSizer: Presets folder '" + _presetsFolderPath + "' does not exist."));
			return;
		}
		string[] files = Directory.GetFiles(_presetsFolderPath, "*.json");
		string[] array = files;
		foreach (string path in array)
		{
			try
			{
				string text = File.ReadAllText(path);
				Preset preset = JsonConvert.DeserializeObject<Preset>(text);
				if (preset == null || string.IsNullOrEmpty(preset.Name))
				{
					Debug.LogWarning((object)("GladioSizer: Invalid preset in file '" + Path.GetFileName(path) + "'. Skipping."));
					continue;
				}
				List<ObjectScale> list = preset.ObjectScales.Where((ObjectScale objScale) => _hookedObjects.ContainsKey(objScale.ObjectName)).ToList();
				List<ObjectScale> list2 = preset.ObjectScales.Where((ObjectScale objScale) => !_hookedObjects.ContainsKey(objScale.ObjectName)).ToList();
				if (list.Count > 0)
				{
					preset.ObjectScales = list;
					_presets.Add(preset);
					Debug.Log((object)$"GladioSizer: Loaded preset '{preset.Name}' from '{Path.GetFileName(path)}' with {list.Count} valid objects.");
				}
				if (list2.Count <= 0)
				{
					continue;
				}
				foreach (ObjectScale item in list2)
				{
					Debug.LogWarning((object)("GladioSizer: Preset '" + preset.Name + "' contains invalid object '" + item.ObjectName + "'. Skipping this object."));
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("GladioSizer: Failed to load preset from '" + Path.GetFileName(path) + "'. Exception: " + ex.Message));
			}
		}
		if (_presets.Count == 0)
		{
			Debug.LogWarning((object)"GladioSizer: No valid presets loaded.");
		}
	}

	private void ApplyPreset(Preset preset)
	{
		foreach (ObjectScale objectScale in preset.ObjectScales)
		{
			ResizeObject(objectScale.ObjectName, objectScale.Scale);
			if (_scaleInputTexts.ContainsKey(objectScale.ObjectName))
			{
				_scaleInputTexts[objectScale.ObjectName].x = objectScale.Scale.x.ToString("0.##");
				_scaleInputTexts[objectScale.ObjectName].y = objectScale.Scale.y.ToString("0.##");
				_scaleInputTexts[objectScale.ObjectName].z = objectScale.Scale.z.ToString("0.##");
			}
		}
		Debug.Log((object)("GladioSizer: Applied preset '" + preset.Name + "'."));
		_confirmationMessage = "\"" + preset.Name + "\" has been activated successfully.";
		_showConfirmation = true;
	}

	private void CreatePreset()
	{
		List<ObjectScale> list = new List<ObjectScale>();
		foreach (string key in _hookedObjects.Keys)
		{
			if (_resizeInputs.ContainsKey(key))
			{
				list.Add(new ObjectScale
				{
					ObjectName = key,
					Scale = _resizeInputs[key]
				});
			}
		}
		Preset preset = new Preset
		{
			Name = _presetName,
			Description = _presetDescription,
			Author = _presetAuthor,
			ObjectScales = list
		};
		string contents = JsonConvert.SerializeObject((object)preset, (Formatting)1);
		string text = string.Join("_", preset.Name.Split(Path.GetInvalidFileNameChars()));
		string text2 = Path.Combine(_presetsFolderPath, text + ".json");
		File.WriteAllText(text2, contents);
		Debug.Log((object)("GladioSizer: Created preset '" + preset.Name + "' at '" + text2 + "'."));
		LoadPresets();
		_confirmationMessage = "\"" + preset.Name + "\" has been created. Please refresh Presets to see your preset.";
		_showConfirmation = true;
	}

	private void EditPreset(Preset preset)
	{
		preset.Name = _presetName;
		preset.Description = _presetDescription;
		preset.Author = _presetAuthor;
		string contents = JsonConvert.SerializeObject((object)preset, (Formatting)1);
		string text = string.Join("_", preset.Name.Split(Path.GetInvalidFileNameChars()));
		string text2 = Path.Combine(_presetsFolderPath, text + ".json");
		if (!text.Equals(_originalPresetName.Replace(' ', '_'), StringComparison.OrdinalIgnoreCase))
		{
			string text3 = Path.Combine(_presetsFolderPath, _originalPresetName.Replace(' ', '_') + ".json");
			if (File.Exists(text3))
			{
				try
				{
					File.Delete(text3);
					Debug.Log((object)("GladioSizer: Deleted old preset file '" + text3 + "' due to name change."));
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("GladioSizer: Failed to delete old preset file '" + text3 + "'. Exception: " + ex.Message));
				}
			}
		}
		try
		{
			File.WriteAllText(text2, contents);
			Debug.Log((object)("GladioSizer: Edited and saved preset '" + preset.Name + "' at '" + text2 + "'."));
			LoadPresets();
			_confirmationMessage = "\"" + preset.Name + "\" has been edited and saved successfully.";
			_showConfirmation = true;
		}
		catch (Exception ex2)
		{
			Debug.LogError((object)("GladioSizer: Failed to save edited preset '" + preset.Name + "'. Exception: " + ex2.Message));
			_confirmationMessage = "Failed to save preset \"" + preset.Name + "\". See logs for details.";
			_showConfirmation = true;
		}
	}

	private void DeletePreset(Preset preset)
	{
		string text = string.Join("_", preset.Name.Split(Path.GetInvalidFileNameChars()));
		string text2 = Path.Combine(_presetsFolderPath, text + ".json");
		Debug.Log((object)("GladioSizer: Attempting to delete preset '" + preset.Name + "' at '" + text2 + "'."));
		try
		{
			if (File.Exists(text2))
			{
				File.Delete(text2);
				Debug.Log((object)("GladioSizer: Successfully deleted preset '" + preset.Name + "' from '" + text2 + "'."));
				_presets.Remove(preset);
				_confirmationMessage = "\"" + preset.Name + "\" has been deleted successfully.";
				_showConfirmation = true;
			}
			else
			{
				Debug.LogWarning((object)("GladioSizer: Preset file '" + text2 + "' does not exist."));
				_confirmationMessage = "Preset \"" + preset.Name + "\" could not be found.";
				_showConfirmation = true;
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("GladioSizer: Failed to delete preset '" + preset.Name + "'. Exception: " + ex.Message));
			_confirmationMessage = "Failed to delete preset \"" + preset.Name + "\". See logs for details.";
			_showConfirmation = true;
		}
	}

	private void DrawPresetCreationWindow(int windowID)
	{
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Name:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		_presetName = GUILayout.TextField(_presetName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
		GUILayout.EndHorizontal();
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Description:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		_presetDescription = GUILayout.TextField(_presetDescription, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
		GUILayout.EndHorizontal();
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Author:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		_presetAuthor = GUILayout.TextField(_presetAuthor, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
		GUILayout.EndHorizontal();
		GUILayout.Space(20f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Save Preset", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
		{
			if (string.IsNullOrWhiteSpace(_presetName))
			{
				Debug.LogWarning((object)"GladioSizer: Preset name cannot be empty.");
				_confirmationMessage = "Preset name cannot be empty.";
				_showConfirmation = true;
			}
			else
			{
				CreatePreset();
				_creatingPreset = false;
			}
		}
		if (GUILayout.Button("Cancel", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
		{
			_creatingPreset = false;
		}
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}

	private void DrawPresetEditWindow(int windowID)
	{
		//IL_041e: Unknown result type (might be due to invalid IL or missing references)
		if (_presetBeingEdited == null)
		{
			_editingPreset = false;
			return;
		}
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Name:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		_presetName = GUILayout.TextField(_presetName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
		GUILayout.EndHorizontal();
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Description:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		_presetDescription = GUILayout.TextArea(_presetDescription, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(200f),
			GUILayout.Height(60f)
		});
		GUILayout.EndHorizontal();
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Author:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		_presetAuthor = GUILayout.TextField(_presetAuthor, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
		GUILayout.EndHorizontal();
		GUILayout.Space(20f);
		foreach (ObjectScale objectScale in _presetBeingEdited.ObjectScales)
		{
			GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
			GUILayout.Label("Object: " + objectScale.ObjectName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Scale X:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			string s = GUILayout.TextField(objectScale.Scale.x.ToString("0.##"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			if (float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				objectScale.Scale.x = result;
			}
			GUILayout.Label("Y:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(20f) });
			string s2 = GUILayout.TextField(objectScale.Scale.y.ToString("0.##"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			if (float.TryParse(s2, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
			{
				objectScale.Scale.y = result2;
			}
			GUILayout.Label("Z:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(20f) });
			string s3 = GUILayout.TextField(objectScale.Scale.z.ToString("0.##"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			if (float.TryParse(s3, NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
			{
				objectScale.Scale.z = result3;
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			GUILayout.Space(5f);
		}
		GUILayout.Space(20f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Save Changes", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) }))
		{
			if (string.IsNullOrWhiteSpace(_presetName))
			{
				Debug.LogWarning((object)"GladioSizer: Preset name cannot be empty.");
				_confirmationMessage = "Preset name cannot be empty.";
				_showConfirmation = true;
			}
			else
			{
				EditPreset(_presetBeingEdited);
				_editingPreset = false;
			}
		}
		if (GUILayout.Button("Cancel", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
		{
			_editingPreset = false;
		}
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}

	private void DrawConfirmationWindow(int windowID)
	{
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Space(20f);
		GUILayout.Label(_confirmationMessage, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
		GUILayout.Space(20f);
		if (_presetToDelete != null)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Yes", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				DeletePreset(_presetToDelete);
				_showConfirmation = false;
				_presetToDelete = null;
			}
			if (GUILayout.Button("No", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				_showConfirmation = false;
				_presetToDelete = null;
			}
			GUILayout.EndHorizontal();
		}
		else if (GUILayout.Button("OK", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
		{
			_showConfirmation = false;
		}
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}
}
[Serializable]
public class Preset
{
	public string Name;

	public string Description;

	public string Author;

	public List<ObjectScale> ObjectScales;
}
[Serializable]
public class ObjectScale
{
	public string ObjectName;

	public ScaleData Scale;
}
[Serializable]
public class ScaleData
{
	public float x;

	public float y;

	public float z;
}
public class ScaleInput
{
	public string x;

	public string y;

	public string z;
}