Decompiled source of ConfigStudio v1.1.1

ConfigStudio.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CommonAPI.Phone;
using Reptile;
using Reptile.Phone;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ConfigStudio")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ConfigStudio")]
[assembly: AssemblyTitle("ConfigStudio")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ConfigStudio;

public class AppConfigStudio : CustomApp
{
	private string _selectedConfigName;

	private string _selectedConfigGuid;

	private static List<(string name, string guid)> _cachedPluginsWithConfig;

	public static void Initialize()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		Sprite val = null;
		string appIconPath = ConfigStudioPlugin.GetAppIconPath("AppIcon.png");
		if (!string.IsNullOrEmpty(appIconPath) && File.Exists(appIconPath))
		{
			try
			{
				byte[] array = File.ReadAllBytes(appIconPath);
				Texture2D val2 = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val2, array))
				{
					((Texture)val2).wrapMode = (TextureWrapMode)1;
					((Texture)val2).filterMode = (FilterMode)1;
					val2.Apply();
					val = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
				}
			}
			catch
			{
			}
		}
		if ((Object)(object)val != (Object)null)
		{
			PhoneAPI.RegisterApp<AppConfigStudio>("Config Studio", val);
		}
		else
		{
			PhoneAPI.RegisterApp<AppConfigStudio>("Config Studio", (Sprite)null);
		}
	}

	public override void OnAppInit()
	{
		((CustomApp)this).OnAppInit();
		((CustomApp)this).CreateIconlessTitleBar("Config Studio", 80f);
		base.ScrollView = PhoneScrollView.Create((CustomApp)(object)this, 275f, 1600f);
		PopulateButtons();
	}

	public override void OnAppEnable()
	{
		((App)this).OnAppEnable();
		PopulateButtons();
	}

	private void PopulateButtons()
	{
		base.ScrollView.RemoveAllButtons();
		SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("Configs");
		((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
		{
			ShowConfigFilesView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val);
		SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Groups");
		((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
		{
			ShowGroupsView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val2);
		SimplePhoneButton val3 = PhoneUIUtility.CreateSimpleButton("Reload Stage");
		((PhoneButton)val3).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val3).OnConfirm, new Action(ReloadStage));
		base.ScrollView.AddButton((PhoneButton)(object)val3);
		SimplePhoneButton val4 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val4).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val4).OnConfirm, (Action)delegate
		{
			((App)this).MyPhone.CloseCurrentApp();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val4);
	}

	private void ReloadStage()
	{
		Core instance = Core.Instance;
		if ((Object)(object)((instance != null) ? instance.BaseModule : null) == (Object)null)
		{
			return;
		}
		BaseModule baseModule = instance.BaseModule;
		if (baseModule.IsLoading)
		{
			return;
		}
		StageManager stageManager = baseModule.StageManager;
		if (stageManager != null && baseModule.IsPlayingInStage)
		{
			if (baseModule.IsInGamePaused)
			{
				baseModule.UnPauseGame((PauseType)65535);
			}
			((App)this).MyPhone.TurnOff(true);
			stageManager.RestartStage();
		}
	}

	private void ShowGroupsView()
	{
		base.ScrollView.RemoveAllButtons();
		SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("Change Group");
		((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
		{
			ShowChangeGroupView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val);
		SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Make New Group");
		((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
		{
			MakeNewGroup();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val2);
		SimplePhoneButton val3 = PhoneUIUtility.CreateSimpleButton("Open Groups Folder");
		((PhoneButton)val3).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val3).OnConfirm, (Action)delegate
		{
			OpenGroupsFolder();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val3);
		SimplePhoneButton val4 = PhoneUIUtility.CreateSimpleButton("Delete Group");
		((PhoneButton)val4).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val4).OnConfirm, (Action)delegate
		{
			ShowDeleteGroupView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val4);
		SimplePhoneButton val5 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val5).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val5).OnConfirm, (Action)delegate
		{
			PopulateButtons();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val5);
	}

	private void ShowDeleteGroupView()
	{
		base.ScrollView.RemoveAllButtons();
		foreach (string groupFolderName in GetGroupFolderNames())
		{
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton(groupFolderName);
			string capturedFolder = groupFolderName;
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				DeleteGroup(capturedFolder);
				ShowGroupsView();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
		}
		SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
		{
			ShowGroupsView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val2);
	}

	private void DeleteGroup(string groupFolderName)
	{
		string path = Path.Combine(GetGroupsFolderPath(), groupFolderName);
		if (!Directory.Exists(path))
		{
			return;
		}
		try
		{
			Directory.Delete(path, recursive: true);
			GroupMadeMessage.Instance?.ShowMessage("Group deleted: " + groupFolderName);
		}
		catch (Exception arg)
		{
			ManualLogSource log = ConfigStudioPlugin.Log;
			if (log != null)
			{
				log.LogWarning((object)$"ConfigStudio: Failed to delete group {groupFolderName}: {arg}");
			}
		}
	}

	private void ShowChangeGroupView()
	{
		base.ScrollView.RemoveAllButtons();
		foreach (string groupFolderName in GetGroupFolderNames())
		{
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton(groupFolderName);
			string capturedFolder = groupFolderName;
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				ApplyGroupToActiveConfigs(capturedFolder);
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
		}
		SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
		{
			ShowGroupsView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val2);
	}

	private static string GetGroupsFolderPath()
	{
		return Path.Combine(ConfigStudioPlugin.ConfigStudioFolderPath, "groups");
	}

	private static List<string> GetGroupFolderNames()
	{
		return GetGroupFolderNamesFromPath(GetGroupsFolderPath());
	}

	private static List<string> GetGroupFolderNamesFromPath(string groupsPath)
	{
		List<string> list = new List<string>();
		if (!Directory.Exists(groupsPath))
		{
			return list;
		}
		try
		{
			string[] directories = Directory.GetDirectories(groupsPath);
			foreach (string path in directories)
			{
				list.Add(Path.GetFileName(path));
			}
		}
		catch
		{
		}
		return list.OrderBy((string x) => x).ToList();
	}

	private void ShowConfigFilesView()
	{
		base.ScrollView.RemoveAllButtons();
		foreach (var item3 in GetPluginsWithConfig())
		{
			string item = item3.name;
			string item2 = item3.guid;
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton(item);
			string capturedName = item;
			string capturedGuid = item2;
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				_selectedConfigName = capturedName;
				_selectedConfigGuid = capturedGuid;
				ShowConfigOptionsView();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
		}
		SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
		{
			PopulateButtons();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val2);
	}

	private void ShowConfigOptionsView()
	{
		base.ScrollView.RemoveAllButtons();
		SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("Switch To Saved Copy");
		((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
		{
			ShowSavedCopiesView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val);
		SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Save Current Config");
		((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
		{
			SaveCurrentConfigToDupes();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val2);
		SimplePhoneButton val3 = PhoneUIUtility.CreateSimpleButton("Open Copies Folder");
		((PhoneButton)val3).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val3).OnConfirm, (Action)delegate
		{
			OpenCopiesFolder();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val3);
		SimplePhoneButton val4 = PhoneUIUtility.CreateSimpleButton("Add Current Config To A Group");
		((PhoneButton)val4).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val4).OnConfirm, (Action)delegate
		{
			ShowAddConfigToGroupView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val4);
		SimplePhoneButton val5 = PhoneUIUtility.CreateSimpleButton("Reset Config");
		((PhoneButton)val5).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val5).OnConfirm, (Action)delegate
		{
			ResetConfigToDefaults();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val5);
		SimplePhoneButton val6 = PhoneUIUtility.CreateSimpleButton("Delete Copies");
		((PhoneButton)val6).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val6).OnConfirm, (Action)delegate
		{
			ShowDeleteCopiesView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val6);
		SimplePhoneButton val7 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val7).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val7).OnConfirm, (Action)delegate
		{
			ShowConfigFilesView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val7);
	}

	private void ShowDeleteCopiesView()
	{
		base.ScrollView.RemoveAllButtons();
		if (string.IsNullOrEmpty(_selectedConfigGuid))
		{
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("Back");
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				ShowConfigOptionsView();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
			return;
		}
		foreach (string item in GetSavedCopyFileNamesForSelectedConfig())
		{
			SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton(item);
			string capturedFileName = item;
			((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
			{
				DeleteSavedCopy(capturedFileName);
				ShowConfigOptionsView();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val2);
		}
		SimplePhoneButton val3 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val3).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val3).OnConfirm, (Action)delegate
		{
			ShowConfigOptionsView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val3);
	}

	private void DeleteSavedCopy(string fileName)
	{
		string selectedConfigDupesFolderPath = GetSelectedConfigDupesFolderPath();
		if (string.IsNullOrEmpty(selectedConfigDupesFolderPath))
		{
			return;
		}
		string path = Path.Combine(selectedConfigDupesFolderPath, fileName);
		if (!File.Exists(path))
		{
			return;
		}
		try
		{
			File.Delete(path);
			GroupMadeMessage.Instance?.ShowMessage("Copy deleted: " + fileName);
		}
		catch (Exception arg)
		{
			ManualLogSource log = ConfigStudioPlugin.Log;
			if (log != null)
			{
				log.LogWarning((object)$"ConfigStudio: Failed to delete copy {fileName}: {arg}");
			}
		}
	}

	private void ShowSavedCopiesView()
	{
		base.ScrollView.RemoveAllButtons();
		if (string.IsNullOrEmpty(_selectedConfigGuid))
		{
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("Back");
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				ShowConfigOptionsView();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
			return;
		}
		foreach (string item in GetSavedCopyFileNamesForSelectedConfig())
		{
			SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton(item);
			string capturedFileName = item;
			((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
			{
				ApplySavedCopyToCurrentConfig(capturedFileName);
				GroupMadeMessage.Instance?.ShowMessage("Config Switched To: " + capturedFileName);
				ShowConfigOptionsView();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val2);
		}
		SimplePhoneButton val3 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val3).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val3).OnConfirm, (Action)delegate
		{
			ShowConfigOptionsView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val3);
	}

	private void ApplyGroupToActiveConfigs(string groupFolderName)
	{
		string path = Path.Combine(GetGroupsFolderPath(), groupFolderName);
		if (!Directory.Exists(path))
		{
			return;
		}
		string[] files;
		try
		{
			files = Directory.GetFiles(path, "*.cfg");
		}
		catch
		{
			return;
		}
		string[] array = files;
		foreach (string text in array)
		{
			string fileName = Path.GetFileName(text);
			if (string.IsNullOrEmpty(fileName))
			{
				continue;
			}
			string guid = Path.GetFileNameWithoutExtension(fileName);
			if (string.IsNullOrEmpty(guid))
			{
				continue;
			}
			PluginInfo? obj2 = ((IEnumerable<PluginInfo>)Chainloader.PluginInfos.Values).FirstOrDefault((Func<PluginInfo, bool>)delegate(PluginInfo x)
			{
				BepInPlugin metadata = x.Metadata;
				return ((metadata != null) ? metadata.GUID : null) == guid;
			});
			BaseUnityPlugin val = ((obj2 != null) ? obj2.Instance : null);
			if (((val != null) ? val.Config : null) == null)
			{
				continue;
			}
			try
			{
				ApplyConfigFileToPlugin(text, val);
				val.Config.Save();
			}
			catch (Exception arg)
			{
				ManualLogSource log = ConfigStudioPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)$"ConfigStudio: Failed to apply group config from {Path.GetFileName(text)}: {arg}");
				}
			}
		}
		GroupMadeMessage.Instance?.ShowMessage("Changed Group!: " + groupFolderName);
	}

	private static void ApplyConfigFileToPlugin(string configFilePath, BaseUnityPlugin plugin)
	{
		if (!File.Exists(configFilePath) || ((plugin != null) ? plugin.Config : null) == null)
		{
			return;
		}
		List<(string, string, string)> list = ParseConfigFile(configFilePath);
		if (list == null)
		{
			return;
		}
		foreach (var item4 in list)
		{
			string item = item4.Item1;
			string item2 = item4.Item2;
			string item3 = item4.Item3;
			ConfigEntryBase val = null;
			foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item5 in plugin.Config)
			{
				ConfigEntryBase value = item5.Value;
				ConfigDefinition val2 = ((value != null) ? value.Definition : null);
				if (!(val2 == (ConfigDefinition)null) && !(val2.Section != item) && !(val2.Key != item2))
				{
					val = item5.Value;
					break;
				}
			}
			if (val == null || string.IsNullOrEmpty(item3))
			{
				continue;
			}
			TypeConverter converter = TomlTypeConverter.GetConverter(val.SettingType);
			if (converter == null)
			{
				continue;
			}
			try
			{
				object obj = converter.ConvertToObject(item3, val.SettingType);
				if (obj != null)
				{
					val.BoxedValue = obj;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ConfigStudioPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)$"ConfigStudio: Failed to apply config value [{item}] {item2} = {item3}: {ex}");
				}
			}
		}
	}

	private static List<(string section, string key, string value)> ParseConfigFile(string path)
	{
		List<(string, string, string)> list = new List<(string, string, string)>();
		string item = "";
		try
		{
			string[] array = File.ReadAllLines(path);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (string.IsNullOrEmpty(text) || text.StartsWith("#"))
				{
					continue;
				}
				if (text.StartsWith("[") && text.EndsWith("]"))
				{
					item = text.Substring(1, text.Length - 2).Trim();
					continue;
				}
				int num = text.IndexOf('=');
				if (num >= 0)
				{
					string item2 = text.Substring(0, num).Trim();
					string text2 = text.Substring(num + 1).Trim();
					if (text2.StartsWith("\"") && text2.EndsWith("\"") && text2.Length >= 2)
					{
						text2 = text2.Substring(1, text2.Length - 2).Replace("\\\"", "\"");
					}
					else if (text2.StartsWith("'") && text2.EndsWith("'") && text2.Length >= 2)
					{
						text2 = text2.Substring(1, text2.Length - 2);
					}
					list.Add((item, item2, text2));
				}
			}
			return list;
		}
		catch (Exception arg)
		{
			ManualLogSource log = ConfigStudioPlugin.Log;
			if (log != null)
			{
				log.LogWarning((object)$"ConfigStudio: Failed to parse config file {path}: {arg}");
			}
			return null;
		}
	}

	private void ApplySavedCopyToCurrentConfig(string duplicateFileName)
	{
		string selectedConfigDupesFolderPath = GetSelectedConfigDupesFolderPath();
		if (string.IsNullOrEmpty(selectedConfigDupesFolderPath))
		{
			return;
		}
		PluginInfo? obj = ((IEnumerable<PluginInfo>)Chainloader.PluginInfos.Values).FirstOrDefault((Func<PluginInfo, bool>)delegate(PluginInfo x)
		{
			BepInPlugin metadata = x.Metadata;
			return ((metadata != null) ? metadata.GUID : null) == _selectedConfigGuid;
		});
		BaseUnityPlugin val = ((obj != null) ? obj.Instance : null);
		if (((val != null) ? val.Config : null) == null)
		{
			return;
		}
		string text = Path.Combine(selectedConfigDupesFolderPath, duplicateFileName);
		if (!File.Exists(text))
		{
			return;
		}
		try
		{
			ApplyConfigFileToPlugin(text, val);
			val.Config.Save();
		}
		catch (Exception arg)
		{
			ManualLogSource log = ConfigStudioPlugin.Log;
			if (log != null)
			{
				log.LogWarning((object)$"ConfigStudio: Failed to apply saved copy {duplicateFileName}: {arg}");
			}
		}
	}

	private string GetSelectedConfigDupesFolderPath()
	{
		if (string.IsNullOrEmpty(_selectedConfigGuid))
		{
			return null;
		}
		return Path.Combine(ConfigStudioPlugin.ConfigStudioFolderPath, "Dupes", _selectedConfigGuid);
	}

	private List<string> GetSavedCopyFileNamesForSelectedConfig()
	{
		string selectedConfigDupesFolderPath = GetSelectedConfigDupesFolderPath();
		if (string.IsNullOrEmpty(selectedConfigDupesFolderPath))
		{
			return new List<string>();
		}
		return GetSavedCopyFileNamesFromPath(selectedConfigDupesFolderPath);
	}

	private static List<string> GetSavedCopyFileNamesFromPath(string folderPath)
	{
		List<string> list = new List<string>();
		if (!Directory.Exists(folderPath))
		{
			return list;
		}
		try
		{
			string[] files = Directory.GetFiles(folderPath, "*.cfg");
			foreach (string path in files)
			{
				list.Add(Path.GetFileName(path));
			}
		}
		catch
		{
		}
		return list.OrderBy((string x) => x).ToList();
	}

	private void ShowAddConfigToGroupView()
	{
		base.ScrollView.RemoveAllButtons();
		foreach (string groupFolderName in GetGroupFolderNames())
		{
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton(groupFolderName);
			string capturedFolder = groupFolderName;
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				CopyConfigToGroup(capturedFolder);
				ShowConfigOptionsView();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
		}
		SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Back");
		((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
		{
			ShowConfigOptionsView();
		});
		base.ScrollView.AddButton((PhoneButton)(object)val2);
	}

	private void OpenCopiesFolder()
	{
		string selectedConfigDupesFolderPath = GetSelectedConfigDupesFolderPath();
		if (string.IsNullOrEmpty(selectedConfigDupesFolderPath))
		{
			return;
		}
		if (!Directory.Exists(selectedConfigDupesFolderPath))
		{
			Directory.CreateDirectory(selectedConfigDupesFolderPath);
		}
		try
		{
			Application.OpenURL("file:///" + selectedConfigDupesFolderPath.Replace('\\', '/'));
		}
		catch
		{
		}
	}

	private void SaveCurrentConfigToDupes()
	{
		string selectedConfigDupesFolderPath = GetSelectedConfigDupesFolderPath();
		if (string.IsNullOrEmpty(selectedConfigDupesFolderPath))
		{
			return;
		}
		if (!Directory.Exists(selectedConfigDupesFolderPath))
		{
			Directory.CreateDirectory(selectedConfigDupesFolderPath);
		}
		string text = Path.Combine(Paths.ConfigPath, _selectedConfigGuid + ".cfg");
		if (!File.Exists(text))
		{
			return;
		}
		string text2 = _selectedConfigGuid + "_" + DateTime.UtcNow.Ticks + "_" + Random.Range(1, 1000000) + ".cfg";
		string destFileName = Path.Combine(selectedConfigDupesFolderPath, text2);
		try
		{
			File.Copy(text, destFileName, overwrite: false);
		}
		catch (Exception arg)
		{
			ManualLogSource log = ConfigStudioPlugin.Log;
			if (log != null)
			{
				log.LogWarning((object)$"ConfigStudio: Failed to save config copy to {text2}: {arg}");
			}
		}
		string text3 = (string.IsNullOrEmpty(_selectedConfigName) ? text2 : _selectedConfigName);
		string message = "Config Saved!: " + text3 + "\n<color=#00FF00>You can rename this file whatever you want!</color>";
		GroupMadeMessage.Instance?.ShowMessage(message);
	}

	private void CopyConfigToGroup(string groupFolderName)
	{
		if (string.IsNullOrEmpty(_selectedConfigGuid))
		{
			return;
		}
		string path = _selectedConfigGuid + ".cfg";
		string text = Path.Combine(Paths.ConfigPath, path);
		if (!File.Exists(text))
		{
			return;
		}
		string text2 = Path.Combine(GetGroupsFolderPath(), groupFolderName);
		Directory.CreateDirectory(text2);
		string destFileName = Path.Combine(text2, path);
		try
		{
			File.Copy(text, destFileName, overwrite: true);
		}
		catch (Exception arg)
		{
			ManualLogSource log = ConfigStudioPlugin.Log;
			if (log != null)
			{
				log.LogWarning((object)$"ConfigStudio: Failed to copy config to group {groupFolderName}: {arg}");
			}
		}
	}

	private void ResetConfigToDefaults()
	{
		if (string.IsNullOrEmpty(_selectedConfigGuid))
		{
			return;
		}
		PluginInfo? obj = ((IEnumerable<PluginInfo>)Chainloader.PluginInfos.Values).FirstOrDefault((Func<PluginInfo, bool>)delegate(PluginInfo x)
		{
			BepInPlugin metadata = x.Metadata;
			return ((metadata != null) ? metadata.GUID : null) == _selectedConfigGuid;
		});
		BaseUnityPlugin val = ((obj != null) ? obj.Instance : null);
		if (((val != null) ? val.Config : null) == null)
		{
			return;
		}
		foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in val.Config)
		{
			ConfigEntryBase value = item.Value;
			if (value != null)
			{
				value.BoxedValue = value.DefaultValue;
			}
		}
		try
		{
			val.Config.Save();
		}
		catch
		{
		}
		string text = (string.IsNullOrEmpty(_selectedConfigName) ? "Config" : _selectedConfigName);
		GroupMadeMessage.Instance?.ShowMessage(text + " Config file has been reset to defaults");
	}

	private static List<(string name, string guid)> GetPluginsWithConfig()
	{
		if (_cachedPluginsWithConfig != null)
		{
			return _cachedPluginsWithConfig;
		}
		List<(string, string)> list = new List<(string, string)>();
		if (Chainloader.PluginInfos == null)
		{
			return list;
		}
		foreach (PluginInfo value in Chainloader.PluginInfos.Values)
		{
			BaseUnityPlugin instance = value.Instance;
			if (!((Object)(object)instance == (Object)null) && instance.Config != null && ((IEnumerable<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)instance.Config).Any())
			{
				BepInPlugin metadata = value.Metadata;
				string item = ((metadata != null) ? metadata.Name : null) ?? ((object)instance).GetType().Name ?? "Unknown";
				BepInPlugin metadata2 = value.Metadata;
				string item2 = ((metadata2 != null) ? metadata2.GUID : null) ?? "";
				list.Add((item, item2));
			}
		}
		_cachedPluginsWithConfig = list.OrderBy<(string, string), string>(((string name, string guid) x) => x.name).ToList();
		return _cachedPluginsWithConfig;
	}

	private static void MakeNewGroup()
	{
		string text = "NewGroup_" + Random.Range(1, 1000000);
		Directory.CreateDirectory(Path.Combine(GetGroupsFolderPath(), text));
		string message = "Group Made! Folder Name: " + text + "\n<color=#00FF00>You can rename the folder, not the config files inside of it</color>";
		GroupMadeMessage.Instance?.ShowMessage(message);
	}

	private static void OpenGroupsFolder()
	{
		string groupsFolderPath = GetGroupsFolderPath();
		if (!Directory.Exists(groupsFolderPath))
		{
			Directory.CreateDirectory(groupsFolderPath);
		}
		try
		{
			Application.OpenURL("file:///" + groupsFolderPath.Replace('\\', '/'));
		}
		catch
		{
		}
	}
}
[BepInPlugin("com.configstudio", "ConfigStudio", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ConfigStudioPlugin : BaseUnityPlugin
{
	private static string _modFolder;

	public static string ConfigStudioFolderPath { get; private set; }

	internal static ManualLogSource Log { get; private set; }

	public static string GetAppIconPath(string filename)
	{
		if (!string.IsNullOrEmpty(_modFolder))
		{
			return Path.Combine(_modFolder, filename);
		}
		return null;
	}

	private void Awake()
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		_modFolder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
		ConfigStudioFolderPath = Path.Combine(Paths.BepInExRootPath, "ConfigStudio");
		Directory.CreateDirectory(ConfigStudioFolderPath);
		Directory.CreateDirectory(Path.Combine(ConfigStudioFolderPath, "groups"));
		Directory.CreateDirectory(Path.Combine(ConfigStudioFolderPath, "Dupes"));
		GameObject val = new GameObject("ConfigStudio_GroupMadeMessage");
		val.AddComponent<GroupMadeMessage>();
		Object.DontDestroyOnLoad((Object)val);
		AppConfigStudio.Initialize();
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "com.configstudio";

	public const string PLUGIN_NAME = "ConfigStudio";

	public const string PLUGIN_VERSION = "1.0.0";
}
public class GroupMadeMessage : MonoBehaviour
{
	private GameObject _canvasGo;

	private TextMeshProUGUI _label;

	private Coroutine _hideCoroutine;

	public static GroupMadeMessage Instance { get; private set; }

	private void Awake()
	{
		Instance = this;
	}

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

	private void EnsureCreated()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_canvasGo != (Object)null))
		{
			Core instance = Core.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				UIManager uIManager = instance.UIManager;
				obj = ((uIManager != null) ? ((Component)uIManager).transform : null);
			}
			Transform val = (Transform)obj;
			if (!((Object)(object)val == (Object)null))
			{
				_canvasGo = new GameObject("ConfigStudio_GroupMadeMessage");
				_canvasGo.transform.SetParent(val, false);
				Canvas obj2 = _canvasGo.AddComponent<Canvas>();
				obj2.renderMode = (RenderMode)0;
				obj2.sortingOrder = 200;
				_canvasGo.AddComponent<CanvasScaler>();
				_canvasGo.AddComponent<GraphicRaycaster>();
				GameObject val2 = new GameObject("MessageLabel");
				val2.transform.SetParent(_canvasGo.transform, false);
				_label = val2.AddComponent<TextMeshProUGUI>();
				((TMP_Text)_label).text = "";
				((TMP_Text)_label).fontSize = 22f;
				((Graphic)_label).color = Color.white;
				((TMP_Text)_label).alignment = (TextAlignmentOptions)260;
				RectTransform component = val2.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(1f, 1f);
				component.anchorMax = new Vector2(1f, 1f);
				component.pivot = new Vector2(1f, 1f);
				component.sizeDelta = new Vector2(600f, 100f);
				((TMP_Text)_label).enableWordWrapping = true;
				component.anchoredPosition = new Vector2(-16f, -10f);
				_canvasGo.SetActive(false);
			}
		}
	}

	public void ShowMessage(string message)
	{
		EnsureCreated();
		if (!((Object)(object)_canvasGo == (Object)null) && !((Object)(object)_label == (Object)null))
		{
			if (_hideCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_hideCoroutine);
			}
			((TMP_Text)_label).text = message;
			_canvasGo.SetActive(true);
			_hideCoroutine = ((MonoBehaviour)this).StartCoroutine(HideAfterDelay(4f));
		}
	}

	private IEnumerator HideAfterDelay(float seconds)
	{
		yield return (object)new WaitForSecondsRealtime(seconds);
		_hideCoroutine = null;
		if ((Object)(object)_canvasGo != (Object)null)
		{
			_canvasGo.SetActive(false);
		}
		if ((Object)(object)_label != (Object)null)
		{
			((TMP_Text)_label).text = "";
		}
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "ConfigStudio";

	public const string PLUGIN_NAME = "ConfigStudio";

	public const string PLUGIN_VERSION = "1.0.0";
}