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 GladioSizer;
[BepInPlugin("com.yourname.gladiosizer", "GladioSizer", "1.1.7")]
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<GameObject, Vector3> _originalChildScales = new Dictionary<GameObject, Vector3>();
private readonly Dictionary<string, List<string>> _objectGroups = new Dictionary<string, List<string>>
{
{
"Player Model",
new List<string> { "PlayerCharacter", "PlayerCharacterMultiplayer" }
},
{
"Shield",
new List<string> { "Shield" }
},
{
"Short Sword",
new List<string> { "ShortSword" }
},
{
"Bearded Axe",
new List<string> { "BeardedAxe" }
},
{
"Bardiche",
new List<string> { "Bardiche" }
},
{
"Longsword",
new List<string> { "Longsword" }
}
};
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 Dictionary<string, ScaleInput> _editPresetScaleInputs = new Dictionary<string, ScaleInput>();
private bool IsPopupOpen => _creatingPreset || _editingPreset || _showConfirmation;
private void Awake()
{
ToggleMenuKeyConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleMenuKey", (KeyCode)283, "Key to toggle the GladioSizer menu");
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: Awake called.");
}
private void Start()
{
HookObjects();
LoadPresets();
((BaseUnityPlugin)this).Logger.LogInfo((object)"GladioSizer: Start called.");
}
private void HookObjects()
{
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Expected O, but got Unknown
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
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}'.");
foreach (GameObject item in list3)
{
foreach (Transform item2 in item.transform)
{
Transform val = item2;
if (!_originalChildScales.ContainsKey(((Component)val).gameObject))
{
_originalChildScales[((Component)val).gameObject] = val.localScale;
}
}
}
}
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 - 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 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, 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();
}
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 (KeyValuePair<string, List<string>> objectGroup in _objectGroups)
{
string key = objectGroup.Key;
if (!_hookedObjects.TryGetValue(key, out var _))
{
continue;
}
GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
GUILayout.Label("RESIZE: " + key, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
if (_scaleInputTexts.TryGetValue(key, out var value2))
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Label("Scale", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
value2.x = GUILayout.TextField(value2.x, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
value2.x = new string(value2.x.Where((char c) => !char.IsLetter(c)).ToArray());
value2.y = GUILayout.TextField(value2.y, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
value2.y = new string(value2.y.Where((char c) => !char.IsLetter(c)).ToArray());
value2.z = GUILayout.TextField(value2.z, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
value2.z = new string(value2.z.Where((char c) => !char.IsLetter(c)).ToArray());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
if (GUILayout.Button("Resize " + key, Array.Empty<GUILayoutOption>()))
{
float result;
bool flag = float.TryParse(value2.x, NumberStyles.Float, CultureInfo.InvariantCulture, out result);
float result2;
bool flag2 = float.TryParse(value2.y, NumberStyles.Float, CultureInfo.InvariantCulture, out result2);
float result3;
bool flag3 = float.TryParse(value2.z, NumberStyles.Float, CultureInfo.InvariantCulture, out result3);
if (flag && flag2 && flag3)
{
ResizeGroup(key, 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 " + key, Array.Empty<GUILayoutOption>()))
{
ResetGroup(key);
if (_scaleInputTexts.ContainsKey(key))
{
_scaleInputTexts[key].x = "1";
_scaleInputTexts[key].y = "1";
_scaleInputTexts[key].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 = "";
_menuOpen = false;
}
}
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);
_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)
{
_editPresetScaleInputs.Clear();
foreach (ObjectScale objectScale in preset.ObjectScales)
{
_editPresetScaleInputs[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_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Expected O, but got Unknown
//IL_00ec: 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))
{
continue;
}
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}).");
foreach (Transform item2 in item.transform)
{
Transform val = item2;
if (_originalChildScales.TryGetValue(((Component)val).gameObject, out var value2))
{
val.localScale = value2;
}
}
}
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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
//IL_00ac: 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))
{
continue;
}
item.transform.localScale = Vector3.one;
((BaseUnityPlugin)this).Logger.LogInfo((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(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))
{
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);
((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 (_editPresetScaleInputs.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_046a: Unknown result type (might be due to invalid IL or missing references)
if (_presetBeingEdited == null)
{
_editingPreset = false;
_menuOpen = true;
return;
}
if (_editPresetScaleInputs.Count == 0)
{
InitializeEditPresetScaleInputs(_presetBeingEdited);
}
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) && _editPresetScaleInputs.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 = _editPresetScaleInputs[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_010d: 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;
}
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));
}
}