Decompiled source of GladioSizer v2.0.0

GladioSizer.dll

Decompiled a month 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.Bootstrap;
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 GladioSizer;

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

	[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;
	}

	private ConfigEntry<KeyCode> ToggleMenuKeyConfig;

	private bool _menuOpen = false;

	private bool _creatingPreset = false;

	private bool _editingPreset = false;

	private bool _showConfirmation = false;

	private string _confirmationMessage = "";

	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<string, List<string>> _objectGroups = new Dictionary<string, List<string>>
	{
		{
			"Player Model",
			new List<string> { "PlayerCharacter", "PlayerCharacterMultiplayer" }
		},
		{
			"Short Sword",
			new List<string> { "ShortSword" }
		},
		{
			"Bearded Axe",
			new List<string> { "BeardedAxe" }
		},
		{
			"Bardiche",
			new List<string> { "Bardiche" }
		},
		{
			"Longsword",
			new List<string> { "Longsword" }
		},
		{
			"SteelSlab",
			new List<string> { "SteelSlab" }
		},
		{
			"Spear",
			new List<string> { "Spear" }
		},
		{
			"Rapier",
			new List<string> { "Rapier" }
		},
		{
			"Dagger",
			new List<string> { "Dagger" }
		},
		{
			"Katana",
			new List<string> { "Katana" }
		},
		{
			"Halberd",
			new List<string> { "Halberd" }
		},
		{
			"Katar",
			new List<string> { "Katar" }
		},
		{
			"Zweihander",
			new List<string> { "Zweihander" }
		},
		{
			"DaneAxe",
			new List<string> { "DaneAxe" }
		},
		{
			"Gladius",
			new List<string> { "Gladius" }
		},
		{
			"Claymore",
			new List<string> { "Claymore" }
		},
		{
			"Scutum",
			new List<string> { "Scutum" }
		},
		{
			"Shield",
			new List<string> { "Shield" }
		},
		{
			"GreatHelmet",
			new List<string> { "GreatHelmet" }
		},
		{
			"Cuisses",
			new List<string> { "Cuisses" }
		},
		{
			"Greaves",
			new List<string> { "Greaves" }
		},
		{
			"Cuirass",
			new List<string> { "Cuirass" }
		},
		{
			"Rerebrace",
			new List<string> { "Rerebrace" }
		},
		{
			"Vambrace",
			new List<string> { "Vambrace" }
		},
		{
			"Plackart",
			new List<string> { "Plackart" }
		},
		{
			"Faulds",
			new List<string> { "Faulds" }
		},
		{
			"NasalSpangenhelm",
			new List<string> { "NasalSpangenhelm" }
		},
		{
			"KettleHelmet",
			new List<string> { "KettleHelmet" }
		}
	};

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

	private readonly 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 List<string> _playerCharacterGroups = new List<string> { "Player Model" };

	private List<string> _weaponGroups = new List<string>
	{
		"Short Sword", "Bearded Axe", "Bardiche", "Longsword", "SteelSlab", "Spear", "Rapier", "Dagger", "Katana", "Halberd",
		"Katar", "Zweihander", "DaneAxe", "Gladius", "Claymore"
	};

	private List<string> _shieldGroups = new List<string> { "Scutum", "Shield" };

	private List<string> _armourGroups = new List<string> { "GreatHelmet", "Cuisses", "Greaves", "Cuirass", "Rerebrace", "Vambrace", "Plackart", "Faulds", "NasalSpangenhelm", "KettleHelmet" };

	private bool IsPopupOpen => _creatingPreset || _editingPreset || _showConfirmation;

	public GladioSizer()
	{
		string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Low", "Plebeian Studio", "Gladio Mori");
		_presetsFolderPath = Path.Combine(path, "GladioSizer", "Presets");
		if (!Directory.Exists(_presetsFolderPath))
		{
			Directory.CreateDirectory(_presetsFolderPath);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Created Presets folder at " + _presetsFolderPath));
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"GladioSizer: Constructor called.");
	}

	private void Awake()
	{
		((Object)Chainloader.ManagerObject).hideFlags = (HideFlags)61;
		ToggleMenuKeyConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleMenuKey", (KeyCode)283, "Key to toggle the GladioSizer menu");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"GladioSizer: Awake called.");
	}

	private void Start()
	{
		HookObjects();
		LoadPresets();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"GladioSizer: Start called.");
	}

	private void HookObjects()
	{
		foreach (KeyValuePair<string, List<string>> objectGroup in _objectGroups)
		{
			string key = objectGroup.Key;
			List<string> value = objectGroup.Value;
			List<GameObject> list2 = new List<GameObject>();
			foreach (string objName in value)
			{
				List<GameObject> list3 = (from obj in Resources.FindObjectsOfTypeAll<GameObject>()
					where ((Object)obj).name.Equals(objName, StringComparison.OrdinalIgnoreCase)
					where !HasParentWithName(obj, objName)
					select obj).ToList();
				if (list3.Count > 0)
				{
					list2.AddRange(list3);
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"GladioSizer: Hooked {list3.Count} instance(s) of '{objName}'.");
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("GladioSizer: Could not find object(s) for '" + objName + "'."));
				}
			}
			if (list2.Count > 0)
			{
				_hookedObjects[key] = list2;
				if (!_scaleInputTexts.ContainsKey(key))
				{
					_scaleInputTexts[key] = new ScaleInput
					{
						x = (_resizeInputs.ContainsKey(key) ? _resizeInputs[key].x.ToString("0.##") : "1"),
						y = (_resizeInputs.ContainsKey(key) ? _resizeInputs[key].y.ToString("0.##") : "1"),
						z = (_resizeInputs.ContainsKey(key) ? _resizeInputs[key].z.ToString("0.##") : "1")
					};
				}
				if (!_resizeInputs.ContainsKey(key))
				{
					_resizeInputs[key] = new ScaleData
					{
						x = 1f,
						y = 1f,
						z = 1f
					};
				}
			}
		}
		int num = _hookedObjects.Values.Sum((List<GameObject> list) => list.Count);
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"GladioSizer: Total hooked objects: {num}");
	}

	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_000f: Unknown result type (might be due to invalid IL or missing references)
		if (!IsPopupOpen && Input.GetKeyDown(ToggleMenuKeyConfig.Value))
		{
			_menuOpen = !_menuOpen;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"GladioSizer: Menu toggled to {_menuOpen}");
		}
	}

	private void OnGUI()
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Expected O, but got Unknown
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		if (_menuOpen && !IsPopupOpen)
		{
			DrawMainMenu();
		}
		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 - 500) / 2), 500f, 500f), 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 DrawMainMenu()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		int width = Screen.width;
		int num = (width - 600) / 2;
		int num2 = 50;
		GUILayout.BeginArea(new Rect((float)num, (float)num2, 600f, 800f), "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();
	}

	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(700f)
		});
		GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
		GUILayout.Label("PLAYER CHARACTER", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
		foreach (string playerCharacterGroup in _playerCharacterGroups)
		{
			if (_hookedObjects.ContainsKey(playerCharacterGroup))
			{
				DrawGroupScalingOptions(playerCharacterGroup);
			}
		}
		GUILayout.EndVertical();
		GUILayout.Space(10f);
		GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
		GUILayout.Label("WEAPONS", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
		foreach (string weaponGroup in _weaponGroups)
		{
			if (_hookedObjects.ContainsKey(weaponGroup))
			{
				DrawGroupScalingOptions(weaponGroup);
			}
		}
		GUILayout.EndVertical();
		GUILayout.Space(10f);
		GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
		GUILayout.Label("SHIELDS", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
		foreach (string shieldGroup in _shieldGroups)
		{
			if (_hookedObjects.ContainsKey(shieldGroup))
			{
				DrawGroupScalingOptions(shieldGroup);
			}
		}
		GUILayout.EndVertical();
		GUILayout.Space(10f);
		GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
		GUILayout.Label("ARMOUR", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
		foreach (string armourGroup in _armourGroups)
		{
			if (_hookedObjects.ContainsKey(armourGroup))
			{
				DrawGroupScalingOptions(armourGroup);
			}
		}
		GUILayout.EndVertical();
		GUILayout.EndScrollView();
		GUILayout.Space(10f);
		if (GUILayout.Button("Create Preset", Array.Empty<GUILayoutOption>()))
		{
			_creatingPreset = true;
			_presetName = "";
			_presetDescription = "";
			_presetAuthor = "";
			_menuOpen = false;
		}
	}

	private void DrawGroupScalingOptions(string groupName)
	{
		if (!_scaleInputTexts.TryGetValue(groupName, out var value))
		{
			return;
		}
		GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
		GUILayout.Label("RESIZE: " + groupName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
		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 " + groupName, 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)
			{
				ResizeGroup(groupName, new ScaleData
				{
					x = result,
					y = result2,
					z = result3
				});
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"GladioSizer: Invalid input for scaling. Using previous valid values.");
			}
		}
		if (GUILayout.Button("Reset " + groupName, Array.Empty<GUILayoutOption>()))
		{
			ResetGroup(groupName);
			if (_scaleInputTexts.ContainsKey(groupName))
			{
				_scaleInputTexts[groupName].x = "1";
				_scaleInputTexts[groupName].y = "1";
				_scaleInputTexts[groupName].z = "1";
			}
		}
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUILayout.Space(5f);
	}

	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(700f)
		});
		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);
					_menuOpen = false;
				}
				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;
					InitializeEditPresetScaleInputs(item);
					_editingPreset = true;
					_menuOpen = false;
				}
				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;
					_menuOpen = false;
				}
				GUILayout.EndHorizontal();
				GUILayout.EndVertical();
				GUILayout.Space(5f);
			}
		}
		GUILayout.Space(10f);
		if (GUILayout.Button("Reload Presets", Array.Empty<GUILayoutOption>()))
		{
			LoadPresets();
		}
		GUILayout.EndScrollView();
	}

	private void InitializeEditPresetScaleInputs(Preset preset)
	{
		_scaleInputTexts.Clear();
		foreach (ObjectScale objectScale in preset.ObjectScales)
		{
			_scaleInputTexts[objectScale.ObjectName] = new ScaleInput
			{
				x = objectScale.Scale.x.ToString("0.##"),
				y = objectScale.Scale.y.ToString("0.##"),
				z = objectScale.Scale.z.ToString("0.##")
			};
		}
	}

	private void ResizeGroup(string groupName, ScaleData newScale)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		if (_hookedObjects.TryGetValue(groupName, out var value))
		{
			foreach (GameObject item in value)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.transform.localScale = new Vector3(newScale.x, newScale.y, newScale.z);
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"GladioSizer: Resized '{((Object)item).name}' to ({newScale.x}, {newScale.y}, {newScale.z}).");
				}
			}
			if (_resizeInputs.ContainsKey(groupName))
			{
				_resizeInputs[groupName] = newScale;
			}
			if (_scaleInputTexts.ContainsKey(groupName))
			{
				_scaleInputTexts[groupName].x = newScale.x.ToString("0.##");
				_scaleInputTexts[groupName].y = newScale.y.ToString("0.##");
				_scaleInputTexts[groupName].z = newScale.z.ToString("0.##");
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("GladioSizer: Cannot resize '" + groupName + "' because it is not hooked."));
		}
	}

	private void ResetGroup(string groupName)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if (_hookedObjects.TryGetValue(groupName, out var value))
		{
			foreach (GameObject item in value)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.transform.localScale = Vector3.one;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Reset '" + ((Object)item).name + "' scale to (1, 1, 1)."));
				}
			}
			if (_resizeInputs.ContainsKey(groupName))
			{
				_resizeInputs[groupName] = new ScaleData
				{
					x = 1f,
					y = 1f,
					z = 1f
				};
			}
			if (_scaleInputTexts.ContainsKey(groupName))
			{
				_scaleInputTexts[groupName].x = "1";
				_scaleInputTexts[groupName].y = "1";
				_scaleInputTexts[groupName].z = "1";
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("GladioSizer: Cannot reset '" + groupName + "' because it is not hooked."));
		}
	}

	private void LoadPresets()
	{
		_presets.Clear();
		if (!Directory.Exists(_presetsFolderPath))
		{
			((BaseUnityPlugin)this).Logger.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))
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("GladioSizer: Invalid preset in file '" + Path.GetFileName(path) + "'. Skipping."));
					continue;
				}
				List<ObjectScale> list = preset.ObjectScales.Where((ObjectScale objScale) => _objectGroups.ContainsKey(objScale.ObjectName)).ToList();
				List<ObjectScale> list2 = preset.ObjectScales.Where((ObjectScale objScale) => !_objectGroups.ContainsKey(objScale.ObjectName)).ToList();
				if (list.Count > 0)
				{
					preset.ObjectScales = list;
					_presets.Add(preset);
					((BaseUnityPlugin)this).Logger.LogInfo((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)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("GladioSizer: Preset '" + preset.Name + "' contains invalid object '" + item.ObjectName + "'. Skipping this object."));
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("GladioSizer: Failed to load preset from '" + Path.GetFileName(path) + "'. Exception: " + ex.Message));
			}
		}
		if (_presets.Count == 0)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"GladioSizer: No valid presets loaded.");
		}
	}

	private void ApplyPreset(Preset preset)
	{
		foreach (ObjectScale objectScale in preset.ObjectScales)
		{
			ResizeGroup(objectScale.ObjectName, objectScale.Scale);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Applied preset '" + preset.Name + "'."));
		_confirmationMessage = "\"" + preset.Name + "\" has been activated successfully.";
		_showConfirmation = true;
		_menuOpen = false;
	}

	private void CreatePreset()
	{
		List<ObjectScale> list = new List<ObjectScale>();
		foreach (string key in _hookedObjects.Keys)
		{
			if (_resizeInputs.ContainsKey(key))
			{
				ObjectScale item = new ObjectScale
				{
					ObjectName = key,
					Scale = _resizeInputs[key]
				};
				list.Add(item);
			}
		}
		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);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Created preset '" + preset.Name + "' at '" + text2 + "'."));
		LoadPresets();
		_confirmationMessage = "\"" + preset.Name + "\" has been created. Please refresh Presets to see your preset.";
		_showConfirmation = true;
		_menuOpen = false;
	}

	private void EditPreset(Preset preset)
	{
		preset.Name = _presetName;
		preset.Description = _presetDescription;
		preset.Author = _presetAuthor;
		foreach (ObjectScale objectScale in preset.ObjectScales)
		{
			if (_scaleInputTexts.TryGetValue(objectScale.ObjectName, out var value))
			{
				if (float.TryParse(value.x, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					objectScale.Scale.x = result;
				}
				if (float.TryParse(value.y, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
				{
					objectScale.Scale.y = result2;
				}
				if (float.TryParse(value.z, NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
				{
					objectScale.Scale.z = result3;
				}
			}
		}
		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);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Deleted old preset file '" + text3 + "' due to name change."));
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("GladioSizer: Failed to delete old preset file '" + text3 + "'. Exception: " + ex.Message));
				}
			}
		}
		try
		{
			File.WriteAllText(text2, contents);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Edited and saved preset '" + preset.Name + "' at '" + text2 + "'."));
			LoadPresets();
			_confirmationMessage = "\"" + preset.Name + "\" has been edited and saved successfully.";
			_showConfirmation = true;
			_menuOpen = false;
		}
		catch (Exception ex2)
		{
			((BaseUnityPlugin)this).Logger.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;
			_menuOpen = false;
		}
	}

	private void DeletePreset(Preset preset)
	{
		string text = string.Join("_", preset.Name.Split(Path.GetInvalidFileNameChars()));
		string text2 = Path.Combine(_presetsFolderPath, text + ".json");
		((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Attempting to delete preset '" + preset.Name + "' at '" + text2 + "'."));
		try
		{
			if (File.Exists(text2))
			{
				File.Delete(text2);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("GladioSizer: Successfully deleted preset '" + preset.Name + "' from '" + text2 + "'."));
				_presets.Remove(preset);
				_confirmationMessage = "\"" + preset.Name + "\" has been deleted successfully.";
				_showConfirmation = true;
				_menuOpen = false;
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("GladioSizer: Preset file '" + text2 + "' does not exist."));
				_confirmationMessage = "Preset \"" + preset.Name + "\" could not be found.";
				_showConfirmation = true;
				_menuOpen = false;
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.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;
			_menuOpen = false;
		}
	}

	private void DrawPresetCreationWindow(int windowID)
	{
		//IL_01f6: 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))
			{
				((BaseUnityPlugin)this).Logger.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;
			_menuOpen = true;
		}
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}

	private void DrawPresetEditWindow(int windowID)
	{
		//IL_0444: Unknown result type (might be due to invalid IL or missing references)
		if (_presetBeingEdited == null)
		{
			_editingPreset = false;
			_menuOpen = true;
			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.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);
		foreach (ObjectScale objectScale in _presetBeingEdited.ObjectScales)
		{
			string objectName = objectScale.ObjectName;
			if (_objectGroups.ContainsKey(objectName) && _scaleInputTexts.ContainsKey(objectName))
			{
				GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
				GUILayout.Label("Object: " + objectName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("Scale", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
				ScaleInput scaleInput = _scaleInputTexts[objectName];
				scaleInput.x = GUILayout.TextField(scaleInput.x, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
				scaleInput.x = new string(scaleInput.x.Where((char c) => !char.IsLetter(c)).ToArray());
				scaleInput.y = GUILayout.TextField(scaleInput.y, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
				scaleInput.y = new string(scaleInput.y.Where((char c) => !char.IsLetter(c)).ToArray());
				scaleInput.z = GUILayout.TextField(scaleInput.z, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
				scaleInput.z = new string(scaleInput.z.Where((char c) => !char.IsLetter(c)).ToArray());
				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))
			{
				((BaseUnityPlugin)this).Logger.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;
			_menuOpen = true;
		}
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}

	private void DrawConfirmationWindow(int windowID)
	{
		//IL_011e: 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);
				_presetToDelete = null;
			}
			if (GUILayout.Button("No", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				_presetToDelete = null;
				_showConfirmation = false;
				_menuOpen = true;
			}
			GUILayout.EndHorizontal();
		}
		else if (GUILayout.Button("OK", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
		{
			_showConfirmation = false;
			_menuOpen = true;
		}
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}
}