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 System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.UI;
using StunShared.UI;
using Stunlock.Network;
using Stunlock.Network.Steam;
using TMPro;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("KinCreator")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+cd8c5fa2aae26cb359d47bd9fa79df877f0d7dd6")]
[assembly: AssemblyProduct("KinCreator")]
[assembly: AssemblyTitle("KinCreator")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace KinCreator
{
[BepInPlugin("Kindred.KinCreator", "KinCreator", "1.0.1")]
internal class Plugin : BasePlugin
{
private Harmony _harmony;
private static MonoBehaviour _monoBehaviour;
public static readonly string DirectoryPath = Path.Combine(Paths.ConfigPath, "KinCreator");
public static ConfigEntry<string> _serverAddress;
public static ConfigEntry<string> _password;
public static ConfigEntry<bool> _autoReconnect;
public static ConfigEntry<int> _retryInterval;
internal static Plugin Instance { get; set; }
public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;
public static PresetManager Presets { get; set; }
public override void Load()
{
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Expected O, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
Instance = this;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val;
if (Application.productName == "VRisingServer")
{
ManualLogSource logInstance = LogInstance;
val = new BepInExInfoLogInterpolatedStringHandler(22, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("KinCreator");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.1");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] is a client mod! (");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Application.productName);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
}
logInstance.LogInfo(val);
return;
}
ClassInjector.RegisterTypeInIl2Cpp<CoroutineHost>();
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
InitConfig();
Presets = new PresetManager();
ManualLogSource logInstance2 = LogInstance;
val = new BepInExInfoLogInterpolatedStringHandler(20, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("KinCreator");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.1");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] loaded on client!");
}
logInstance2.LogInfo(val);
}
public override bool Unload()
{
((BasePlugin)this).Config.Clear();
_harmony.UnpatchSelf();
return true;
}
private static void InitConfig()
{
if (!Directory.Exists(DirectoryPath))
{
Directory.CreateDirectory(DirectoryPath);
}
_autoReconnect = ((BasePlugin)Instance).Config.Bind<bool>("AutoReconnect", "Enabled", true, "Enables automatic reconnections when attempting to join full servers.");
_retryInterval = ((BasePlugin)Instance).Config.Bind<int>("AutoReconnect", "RetryInterval", 15, "Time in seconds between reconnection attempts.");
_serverAddress = ((BasePlugin)Instance).Config.Bind<string>("AutoReconnect", "ServerAddress", "", "Server address to use for auto-reconnect (stored automatically on connect).");
_password = ((BasePlugin)Instance).Config.Bind<string>("AutoReconnect", "Password", "", "Password to use when auto-reconnecting (blank for none).");
}
public static Coroutine StartCoroutine(IEnumerator routine)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
if ((Object)(object)_monoBehaviour == (Object)null)
{
GameObject val = new GameObject("KinCreator");
_monoBehaviour = (MonoBehaviour)(object)val.AddComponent<CoroutineHost>();
Object.DontDestroyOnLoad((Object)val);
}
return _monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
}
public static void Delayed(Action action, float delay = 0.25f)
{
RunDelayed(delay, action).Run();
}
private static IEnumerator RunDelayed(float delay, Action action)
{
yield return (object)new WaitForSeconds(delay);
action?.Invoke();
}
}
internal static class CoroutineExtensions
{
public static void Run(this IEnumerator routine, float delay = 0f)
{
if (delay > 0f)
{
Plugin.StartCoroutine(Delay(routine, delay));
}
else
{
Plugin.StartCoroutine(routine);
}
}
private static IEnumerator Delay(IEnumerator routine, float delay)
{
yield return (object)new WaitForSeconds(delay);
routine.Run();
}
}
internal class CoroutineHost : MonoBehaviour
{
public CoroutineHost(IntPtr ptr)
: base(ptr)
{
}
}
public class CharacterPreset
{
public string Name { get; set; } = "";
public int BodyTypeIndex { get; set; }
public int SkinToneColorIndex { get; set; }
public int FaceIndex { get; set; }
public int EyeColorIndex { get; set; }
public int HairIndex { get; set; }
public int HairColorIndex { get; set; }
public int FeaturesIndex { get; set; }
public int AccessoriesIndex { get; set; }
}
internal class PresetManager
{
private static readonly string _filePath = Path.Combine(Plugin.DirectoryPath, "presets.json");
private static readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
{
WriteIndented = true
};
public Dictionary<string, CharacterPreset> SavedPresets { get; private set; } = new Dictionary<string, CharacterPreset>();
public List<string> PresetNames => SavedPresets.Keys.ToList();
public bool HasPresets => SavedPresets.Count > 0;
public PresetManager()
{
Load();
}
public CharacterPreset GetPreset(string name)
{
if (!SavedPresets.TryGetValue(name, out var value))
{
return null;
}
return value;
}
public string GetNextPresetName()
{
int num = 1;
string text;
while (true)
{
text = $"Preset {num}";
if (!SavedPresets.ContainsKey(text))
{
break;
}
num++;
}
return text;
}
public void SavePreset(string name, CharacterPreset preset)
{
SavedPresets[name] = preset;
Save();
}
public void DeletePreset(string name)
{
if (SavedPresets.Remove(name))
{
Save();
}
}
public bool RenamePreset(string oldName, string newName)
{
if (!SavedPresets.TryGetValue(oldName, out var value))
{
return false;
}
if (SavedPresets.ContainsKey(newName))
{
return false;
}
SavedPresets.Remove(oldName);
value.Name = newName;
SavedPresets[newName] = value;
Save();
return true;
}
private void Save()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
try
{
string contents = JsonSerializer.Serialize(SavedPresets, _jsonOptions);
File.WriteAllText(_filePath, contents);
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(40, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[PresetManager] Failed to save presets: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val);
}
}
private void Load()
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
try
{
if (File.Exists(_filePath))
{
string json = File.ReadAllText(_filePath);
SavedPresets = JsonSerializer.Deserialize<Dictionary<string, CharacterPreset>>(json, _jsonOptions) ?? new Dictionary<string, CharacterPreset>();
}
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(40, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[PresetManager] Failed to load presets: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val);
SavedPresets = new Dictionary<string, CharacterPreset>();
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Kindred.KinCreator";
public const string PLUGIN_NAME = "KinCreator";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace KinCreator.Patches
{
[HarmonyPatch]
internal static class AutoReconnectPatch
{
private const ushort DEFAULT_PORT = 9876;
private static string _serverSession = string.Empty;
private static string _serverPassword = string.Empty;
public static bool _allowRetry;
private static DefaultWorldConsoleCommandSystem DefaultWorldConsoleCommandSystem => World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged<DefaultWorldConsoleCommandSystem>();
[HarmonyPatch(typeof(MainMenuNewView), "Update")]
[HarmonyPrefix]
private static void UpdatePrefix()
{
_allowRetry = false;
}
[HarmonyPatch(typeof(ClientBootstrapSystem), "OnStatusChangedEvent")]
[HarmonyPostfix]
private static void OnStatusChangedEventPostfix(ClientBootstrapSystem __instance, StatusChangedEvent statusChangedEvent)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(30, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ClientBootstrapSystem] -> ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ClientConnectState>(statusChangedEvent.Status);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ? ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ConnectionStatusChangeReason>(__instance.DisconnectChangeReason);
}
logInstance.LogWarning(val);
if (Plugin._autoReconnect.Value && ((object)__instance.DisconnectChangeReason/*cast due to .constrained prefix*/).Equals((object)(ConnectionStatusChangeReason)11))
{
ConnectAddress connectAddress = GetConnectAddress(_serverSession);
_allowRetry = true;
Plugin.Delayed(delegate
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
DoReconnect(connectAddress);
}, Plugin._retryInterval.Value);
}
}
[HarmonyPatch(typeof(ClientSteamTransportLayer), "Connect")]
[HarmonyPostfix]
private static void ClientConnectPostfix(ConnectAddress connectAddress)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(31, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ClientSteamTransportLayer] -> ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ConnectAddress>(connectAddress);
}
logInstance.LogWarning(val);
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(1, 2);
FixedString32Bytes address = connectAddress.Address;
defaultInterpolatedStringHandler.AppendFormatted(((FixedString32Bytes)(ref address)).Value);
defaultInterpolatedStringHandler.AppendLiteral(":");
defaultInterpolatedStringHandler.AppendFormatted(connectAddress.Port);
_serverSession = defaultInterpolatedStringHandler.ToStringAndClear();
}
private static ConnectAddress GetConnectAddress(string address)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
string[] array = address.Split(':');
string text = array[0];
ushort result;
ushort num = (ushort)((array.Length > 1 && ushort.TryParse(array[1], out result)) ? result : 0);
if (num <= 0)
{
return ConnectAddressUtility.CreateIPv4(text, (ushort)9876, false);
}
return ConnectAddressUtility.CreateIPv4(text, num, false);
}
private static void DoReconnect(ConnectAddress connectAddress)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (_allowRetry)
{
Plugin.LogInstance.LogWarning((object)"[AutoReconnect] Retrying...");
DefaultWorldConsoleCommandSystem.DoConnect(connectAddress, _serverPassword);
}
}
}
[HarmonyPatch]
internal static class CharacterCreationMenuPatch
{
private static LocalizedText _saveButtonText;
private static GameObject _saveButtonObject;
private static GameObject _presetButtonObject;
private static GameObject _editDeleteContainer;
private static GameObject _editButtonObject;
private static GameObject _deleteButtonObject;
private static CharacterCreationMenuMapper _activeMenuMapper;
private static string _selectedPresetName;
private static TMP_Dropdown _nativeDropdown;
private static string _editingPreset;
private static bool _isEditMode;
private static bool _suppressDropdownCallback;
private static bool _labelLocTextKilled;
private static GenericTextInputPopup _textPopup;
private static Action<string> _textPopupOnConfirm;
private static LocalizedText _editButtonText;
private static LocalizedText _deleteButtonText;
private static string _pendingCharacterName;
private static UnityAction _confirmNameAction;
private static readonly string[] InjectedButtonNames = new string[3] { "SavePreset_StandardButton", "PresetDropdown", "EditDeleteContainer" };
private const float COMPACT_FONT_SIZE = 18f;
private const float COMPACT_BUTTON_WIDTH = 110f;
private const float DROPDOWN_FONT_SIZE = 20f;
private static readonly Color EditAccent = new Color(1f, 0.79f, 0.28f, 1f);
private static readonly Color EditAccentLight = new Color(1f, 0.89f, 0.58f, 1f);
private static Color _defaultButtonTextColor = Color.white;
private const string BUTTON_PARENT = "HUDCanvas(Clone)/HUDMenuParent/CharacterCreationMenu(Clone)/Root/NewContainer/CharacterCreationScreen(Clone)/Content/LeftMenu/Container_BottomKBAMButtonBar";
private static PresetManager Presets => Plugin.Presets;
[HarmonyPatch(typeof(CharacterCreationMenuMapper), "OnStartRunning")]
[HarmonyPostfix]
public static void OnStartRunningPostfix(CharacterCreationMenuMapper __instance)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
try
{
_activeMenuMapper = __instance;
_editingPreset = null;
_isEditMode = false;
_selectedPresetName = null;
_pendingCharacterName = null;
_nativeDropdown = null;
_labelLocTextKilled = false;
BuildPresetButtons(__instance);
Plugin.StartCoroutine(EnsurePresetButtons(__instance));
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(31, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[CharacterCreationMenuMapper]: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val);
}
}
private static IEnumerator EnsurePresetButtons(CharacterCreationMenuMapper menuMapper)
{
for (int frame = 0; frame < 150; frame++)
{
yield return null;
if (_activeMenuMapper != menuMapper)
{
break;
}
GameObject val = GameObject.Find("HUDCanvas(Clone)/HUDMenuParent/CharacterCreationMenu(Clone)/Root/NewContainer/CharacterCreationScreen(Clone)/Content/LeftMenu/Container_BottomKBAMButtonBar");
if (!((Object)(object)val == (Object)null))
{
if ((Object)(object)val.transform.Find("SavePreset_StandardButton") == (Object)null)
{
BuildPresetButtons(menuMapper);
}
RectTransform component = val.GetComponent<RectTransform>();
if ((Object)(object)component != (Object)null)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(component);
}
}
}
}
private static void BuildPresetButtons(CharacterCreationMenuMapper menuMapper)
{
//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
//IL_03b7: Expected O, but got Unknown
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Expected O, but got Unknown
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_0230: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Expected O, but got Unknown
//IL_025e: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
try
{
GameObject val = GameObject.Find("HUDCanvas(Clone)/HUDMenuParent/CharacterCreationMenu(Clone)/Root/NewContainer/CharacterCreationScreen(Clone)/Content/LeftMenu/Container_BottomKBAMButtonBar");
if ((Object)(object)val == (Object)null)
{
Plugin.LogInstance.LogWarning((object)"[BuildPresetButtons]: button bar not found");
return;
}
for (int num = val.transform.childCount - 1; num >= 0; num--)
{
Transform child = val.transform.GetChild(num);
if (Array.IndexOf(InjectedButtonNames, ((Object)child).name) >= 0)
{
Object.DestroyImmediate((Object)(object)((Component)child).gameObject);
}
}
GameObject val2 = null;
for (int i = 0; i < val.transform.childCount; i++)
{
Transform child2 = val.transform.GetChild(i);
if (((Object)child2).name.Contains("Randomize"))
{
val2 = ((Component)child2).gameObject;
break;
}
}
if ((Object)(object)val2 == (Object)null)
{
val2 = ((Component)val.transform.GetChild(0)).gameObject;
}
GameObject val3 = UIHelper.InstantiateGameObjectUnderAnchor(val2, val.transform);
val3.transform.SetSiblingIndex(val2.transform.GetSiblingIndex() + 1);
((Object)val3).name = "SavePreset_StandardButton";
_saveButtonObject = val3;
_saveButtonText = val3.GetComponentInChildren<LocalizedText>();
_saveButtonText.ForceSet("Save New Preset");
SimpleStunButton component = val3.GetComponent<SimpleStunButton>();
((UnityEventBase)component.onClick).RemoveAllListeners();
((UnityEvent)component.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
{
OnSaveClicked(menuMapper);
}));
val3.SetActive(true);
BuildNativeDropdown(val, val3);
_editDeleteContainer = new GameObject("EditDeleteContainer");
_editDeleteContainer.transform.SetParent(val.transform, false);
_editDeleteContainer.transform.SetSiblingIndex(_presetButtonObject.transform.GetSiblingIndex() + 1);
LayoutElement obj = _editDeleteContainer.AddComponent<LayoutElement>();
obj.preferredHeight = 35f;
obj.minHeight = 35f;
obj.flexibleHeight = 0f;
_editDeleteContainer.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
HorizontalLayoutGroup obj2 = _editDeleteContainer.AddComponent<HorizontalLayoutGroup>();
((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = true;
((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
((HorizontalOrVerticalLayoutGroup)obj2).spacing = 30f;
((LayoutGroup)obj2).padding = new RectOffset
{
left = 0,
right = 0,
top = 0,
bottom = 0
};
TextMeshProUGUI componentInChildren = val3.GetComponentInChildren<TextMeshProUGUI>();
if ((Object)(object)componentInChildren != (Object)null)
{
_defaultButtonTextColor = ((Graphic)componentInChildren).color;
}
_editButtonObject = UIHelper.InstantiateGameObjectUnderAnchor(val2, _editDeleteContainer.transform);
((Object)_editButtonObject).name = "EditPreset_StandardButton";
ConfigureCompactButton(_editButtonObject, "Edit", componentInChildren);
_editButtonText = _editButtonObject.GetComponentInChildren<LocalizedText>();
SimpleStunButton component2 = _editButtonObject.GetComponent<SimpleStunButton>();
((UnityEventBase)component2.onClick).RemoveAllListeners();
((UnityEvent)component2.onClick).AddListener(UnityAction.op_Implicit((Action)OnEditClicked));
_editButtonObject.SetActive(true);
_deleteButtonObject = UIHelper.InstantiateGameObjectUnderAnchor(val2, _editDeleteContainer.transform);
((Object)_deleteButtonObject).name = "DeletePreset_StandardButton";
ConfigureCompactButton(_deleteButtonObject, "Delete", componentInChildren);
_deleteButtonText = _deleteButtonObject.GetComponentInChildren<LocalizedText>();
SimpleStunButton component3 = _deleteButtonObject.GetComponent<SimpleStunButton>();
((UnityEventBase)component3.onClick).RemoveAllListeners();
((UnityEvent)component3.onClick).AddListener(UnityAction.op_Implicit((Action)OnDeleteClicked));
_deleteButtonObject.SetActive(true);
UpdatePresetUIVisibility();
RectTransform component4 = val.GetComponent<RectTransform>();
if ((Object)(object)component4 != (Object)null)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(component4);
}
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(22, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[BuildPresetButtons]: ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val4);
}
}
private static void LockCaptionFont(TextMeshProUGUI tmp)
{
((TMP_Text)tmp).enableAutoSizing = false;
((TMP_Text)tmp).fontSize = 20f;
((TMP_Text)tmp).fontSizeMin = 20f;
((TMP_Text)tmp).fontSizeMax = 20f;
}
private static void ConfigureCompactButton(GameObject btnObj, string label, TextMeshProUGUI reference)
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
LocalizedText componentInChildren = btnObj.GetComponentInChildren<LocalizedText>();
if (componentInChildren != null)
{
componentInChildren.ForceSet(label);
}
foreach (TextAccessibilityScaler componentsInChild in btnObj.GetComponentsInChildren<TextAccessibilityScaler>(true))
{
Object.DestroyImmediate((Object)(object)componentsInChild);
}
TextMeshProUGUI componentInChildren2 = btnObj.GetComponentInChildren<TextMeshProUGUI>();
if ((Object)(object)componentInChildren2 != (Object)null)
{
if ((Object)(object)reference != (Object)null)
{
((TMP_Text)componentInChildren2).font = ((TMP_Text)reference).font;
((TMP_Text)componentInChildren2).fontStyle = ((TMP_Text)reference).fontStyle;
((Graphic)componentInChildren2).color = ((Graphic)reference).color;
}
((TMP_Text)componentInChildren2).enableAutoSizing = false;
((TMP_Text)componentInChildren2).fontSize = 18f;
((TMP_Text)componentInChildren2).alignment = (TextAlignmentOptions)514;
((TMP_Text)componentInChildren2).enableWordWrapping = false;
((TMP_Text)componentInChildren2).overflowMode = (TextOverflowModes)0;
}
ContentSizeFitter component = btnObj.GetComponent<ContentSizeFitter>();
if ((Object)(object)component != (Object)null)
{
Object.DestroyImmediate((Object)(object)component);
}
LayoutElement val = btnObj.GetComponent<LayoutElement>();
if ((Object)(object)val == (Object)null)
{
val = btnObj.AddComponent<LayoutElement>();
}
val.preferredWidth = 110f;
val.minWidth = 110f;
val.preferredHeight = 35f;
val.minHeight = 35f;
val.flexibleWidth = 0f;
val.flexibleHeight = 0f;
RectTransform component2 = btnObj.GetComponent<RectTransform>();
if ((Object)(object)component2 != (Object)null)
{
component2.sizeDelta = new Vector2(110f, 35f);
}
StretchChildren(btnObj.transform);
}
private static void StretchChildren(Transform parent, int depth = 0)
{
//IL_001d: 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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < parent.childCount; i++)
{
Transform child = parent.GetChild(i);
RectTransform component = ((Component)child).GetComponent<RectTransform>();
if ((Object)(object)component != (Object)null)
{
component.anchorMin = Vector2.zero;
component.anchorMax = Vector2.one;
component.offsetMin = Vector2.zero;
component.offsetMax = Vector2.zero;
}
if (depth < 1)
{
StretchChildren(child, depth + 1);
}
}
}
private static void BuildNativeDropdown(GameObject buttonParent, GameObject saveButtonObject)
{
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_02de: Unknown result type (might be due to invalid IL or missing references)
//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
//IL_038a: Unknown result type (might be due to invalid IL or missing references)
//IL_057c: Unknown result type (might be due to invalid IL or missing references)
//IL_0416: Unknown result type (might be due to invalid IL or missing references)
//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
//IL_0506: Unknown result type (might be due to invalid IL or missing references)
//IL_053d: Unknown result type (might be due to invalid IL or missing references)
GameObject val = null;
foreach (TMP_Dropdown item in Resources.FindObjectsOfTypeAll<TMP_Dropdown>())
{
if ((Object)(object)item != (Object)null && (Object)(object)((Component)item).gameObject != (Object)null && ((Object)((Component)item).gameObject).name == "FacialhairDropdown")
{
val = ((Component)item).gameObject;
break;
}
}
if ((Object)(object)val == (Object)null)
{
Plugin.LogInstance.LogWarning((object)"[BuildNativeDropdown]: FacialhairDropdown not found");
return;
}
_presetButtonObject = UIHelper.InstantiateGameObjectUnderAnchor(val, buttonParent.transform);
_presetButtonObject.transform.SetSiblingIndex(saveButtonObject.transform.GetSiblingIndex() + 1);
((Object)_presetButtonObject).name = "PresetDropdown";
_nativeDropdown = _presetButtonObject.GetComponent<TMP_Dropdown>();
if ((Object)(object)_nativeDropdown == (Object)null)
{
Plugin.LogInstance.LogWarning((object)"[BuildNativeDropdown]: Cloned object missing TMP_Dropdown component");
Object.Destroy((Object)(object)_presetButtonObject);
_presetButtonObject = null;
return;
}
((UnityEventBase)_nativeDropdown.onValueChanged).RemoveAllListeners();
((UnityEvent<int>)(object)_nativeDropdown.onValueChanged).AddListener(UnityAction<int>.op_Implicit((Action<int>)OnNativeDropdownChanged));
foreach (TextAccessibilityScaler componentsInChild in _presetButtonObject.GetComponentsInChildren<TextAccessibilityScaler>(true))
{
Object.DestroyImmediate((Object)(object)componentsInChild);
}
foreach (LocalizedText componentsInChild2 in _presetButtonObject.GetComponentsInChildren<LocalizedText>(true))
{
Object.DestroyImmediate((Object)(object)componentsInChild2);
}
_labelLocTextKilled = true;
LayoutElement component = saveButtonObject.GetComponent<LayoutElement>();
LayoutElement val2 = _presetButtonObject.GetComponent<LayoutElement>();
if ((Object)(object)val2 == (Object)null)
{
val2 = _presetButtonObject.AddComponent<LayoutElement>();
}
if ((Object)(object)component != (Object)null)
{
val2.preferredWidth = component.preferredWidth;
val2.preferredHeight = component.preferredHeight;
val2.minWidth = component.minWidth;
val2.minHeight = component.minHeight;
val2.flexibleWidth = component.flexibleWidth;
val2.flexibleHeight = component.flexibleHeight;
}
val2.flexibleHeight = 0f;
ContentSizeFitter component2 = _presetButtonObject.GetComponent<ContentSizeFitter>();
if ((Object)(object)component2 != (Object)null)
{
component2.horizontalFit = (FitMode)0;
component2.verticalFit = (FitMode)0;
}
RectTransform component3 = saveButtonObject.GetComponent<RectTransform>();
RectTransform component4 = _presetButtonObject.GetComponent<RectTransform>();
if ((Object)(object)component3 != (Object)null && (Object)(object)component4 != (Object)null)
{
component4.sizeDelta = component3.sizeDelta;
component4.anchorMin = component3.anchorMin;
component4.anchorMax = component3.anchorMax;
}
Image component5 = saveButtonObject.GetComponent<Image>();
Image component6 = _presetButtonObject.GetComponent<Image>();
if ((Object)(object)component6 != (Object)null && (Object)(object)component5 != (Object)null)
{
component6.sprite = component5.sprite;
component6.type = component5.type;
((Graphic)component6).color = ((Graphic)component5).color;
((Graphic)component6).material = ((Graphic)component5).material;
}
Selectable component7 = _presetButtonObject.GetComponent<Selectable>();
if ((Object)(object)component7 != (Object)null)
{
component7.transition = (Transition)3;
}
TextMeshProUGUI componentInChildren = saveButtonObject.GetComponentInChildren<TextMeshProUGUI>();
Transform val3 = _presetButtonObject.transform.Find("Label");
if ((Object)(object)val3 != (Object)null)
{
TextMeshProUGUI component8 = ((Component)val3).GetComponent<TextMeshProUGUI>();
if ((Object)(object)component8 != (Object)null)
{
if ((Object)(object)componentInChildren != (Object)null)
{
((TMP_Text)component8).font = ((TMP_Text)componentInChildren).font;
}
LockCaptionFont(component8);
((TMP_Text)component8).alignment = (TextAlignmentOptions)514;
((Graphic)component8).color = Color.white;
}
_nativeDropdown.captionText = null;
}
Transform val4 = _presetButtonObject.transform.Find("Template");
if ((Object)(object)val4 != (Object)null)
{
Image component9 = ((Component)val4).GetComponent<Image>();
if ((Object)(object)component9 != (Object)null)
{
((Graphic)component9).color = new Color(0.1f, 0.1f, 0.15f, 0.97f);
}
Il2CppArrayBase<TextMeshProUGUI> componentsInChildren = ((Component)val4).GetComponentsInChildren<TextMeshProUGUI>(true);
if (componentsInChildren != null)
{
foreach (TextMeshProUGUI item2 in componentsInChildren)
{
((Graphic)item2).color = Color.white;
((TMP_Text)item2).fontSize = 16f;
}
}
Transform val5 = val4.Find("Viewport");
if ((Object)(object)val5 != (Object)null)
{
Transform val6 = val5.Find("Content");
if ((Object)(object)val6 != (Object)null)
{
Transform val7 = val6.Find("Item");
if ((Object)(object)val7 != (Object)null)
{
Image component10 = ((Component)val7).GetComponent<Image>();
if ((Object)(object)component10 != (Object)null)
{
((Graphic)component10).color = new Color(0.12f, 0.12f, 0.18f, 0.95f);
}
Transform val8 = val7.Find("Item Background");
if ((Object)(object)val8 != (Object)null)
{
Image component11 = ((Component)val8).GetComponent<Image>();
if ((Object)(object)component11 != (Object)null)
{
((Graphic)component11).color = new Color(0.2f, 0.2f, 0.3f, 0.8f);
}
}
Transform val9 = val7.Find("Item Checkmark");
if ((Object)(object)val9 != (Object)null)
{
Image component12 = ((Component)val9).GetComponent<Image>();
if ((Object)(object)component12 != (Object)null)
{
((Graphic)component12).color = Color.white;
}
}
}
}
}
}
Transform val10 = _presetButtonObject.transform.Find("Arrow");
if ((Object)(object)val10 != (Object)null)
{
Image component13 = ((Component)val10).GetComponent<Image>();
if ((Object)(object)component13 != (Object)null)
{
((Graphic)component13).color = Color.white;
}
}
RefreshNativeDropdown();
_presetButtonObject.SetActive(Presets.HasPresets);
}
private static void RefreshNativeDropdown()
{
if ((Object)(object)_nativeDropdown == (Object)null)
{
return;
}
if (!_labelLocTextKilled)
{
GameObject presetButtonObject = _presetButtonObject;
Transform val = ((presetButtonObject != null) ? presetButtonObject.transform.Find("Label") : null);
if ((Object)(object)val != (Object)null)
{
LocalizedText component = ((Component)val).GetComponent<LocalizedText>();
if ((Object)(object)component != (Object)null)
{
Object.Destroy((Object)(object)component);
}
_labelLocTextKilled = true;
}
}
_suppressDropdownCallback = true;
_nativeDropdown.ClearOptions();
List<string> val2 = new List<string>();
val2.Add("Load Preset");
if (Presets.HasPresets)
{
foreach (string presetName in Presets.PresetNames)
{
val2.Add(presetName);
}
}
_nativeDropdown.AddOptions(val2);
string labelText = "Load Preset";
if (!string.IsNullOrEmpty(_selectedPresetName) && Presets.HasPresets)
{
List<string> presetNames = Presets.PresetNames;
for (int i = 0; i < presetNames.Count; i++)
{
if (presetNames[i] == _selectedPresetName)
{
_nativeDropdown.SetValueWithoutNotify(i + 1);
labelText = _selectedPresetName;
break;
}
}
}
else
{
_selectedPresetName = null;
_nativeDropdown.SetValueWithoutNotify(0);
}
_suppressDropdownCallback = false;
SetLabelText(labelText);
UpdatePresetUIVisibility();
}
private static IEnumerator FlashSaveButtonText(string message)
{
_saveButtonText.ForceSet(message);
yield return (object)new WaitForSeconds(5f);
if ((Object)(object)_saveButtonText != (Object)null)
{
_saveButtonText.ForceSet(_isEditMode ? "Save Edit" : "Save New Preset");
}
}
private static void SetLabelText(string text)
{
if ((Object)(object)_presetButtonObject == (Object)null)
{
return;
}
Transform val = _presetButtonObject.transform.Find("Label");
if ((Object)(object)val != (Object)null)
{
TextMeshProUGUI component = ((Component)val).GetComponent<TextMeshProUGUI>();
if ((Object)(object)component != (Object)null)
{
((TMP_Text)component).text = text;
LockCaptionFont(component);
}
}
}
private static void SetLabelColor(Color color)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_presetButtonObject == (Object)null))
{
Transform val = _presetButtonObject.transform.Find("Label");
TextMeshProUGUI val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<TextMeshProUGUI>() : null);
if ((Object)(object)val2 != (Object)null)
{
((Graphic)val2).color = color;
}
}
}
private static void SetEditOutline(bool on)
{
ApplyOutline(_saveButtonObject, on);
ApplyOutline(_presetButtonObject, on);
ApplyOutline(_editButtonObject, on);
ApplyOutline(_deleteButtonObject, on);
}
private static void SetEditButtonTextColor(Color color)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
SetButtonTextColor(_saveButtonObject, color);
SetButtonTextColor(_editButtonObject, color);
SetButtonTextColor(_deleteButtonObject, color);
}
private static void SetButtonTextColor(GameObject obj, Color color)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
TextMeshProUGUI val = (((Object)(object)obj != (Object)null) ? obj.GetComponentInChildren<TextMeshProUGUI>() : null);
if ((Object)(object)val != (Object)null)
{
((Graphic)val).color = color;
}
}
private static void ApplyOutline(GameObject obj, bool on)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)obj == (Object)null)
{
return;
}
Image component = obj.GetComponent<Image>();
if ((Object)(object)component == (Object)null)
{
return;
}
Outline val = ((Component)component).GetComponent<Outline>();
if (on)
{
if ((Object)(object)val == (Object)null)
{
val = ((Component)component).gameObject.AddComponent<Outline>();
}
((Shadow)val).effectColor = EditAccent;
((Shadow)val).effectDistance = new Vector2(2.5f, 2.5f);
((Shadow)val).useGraphicAlpha = false;
}
else if ((Object)(object)val != (Object)null)
{
Object.Destroy((Object)(object)val);
}
}
private static void OnNativeDropdownChanged(int index)
{
if (_suppressDropdownCallback)
{
return;
}
if (index <= 0)
{
if (_isEditMode)
{
ExitEditMode();
}
_selectedPresetName = null;
_pendingCharacterName = null;
SetLabelText("Load Preset");
UpdatePresetUIVisibility();
return;
}
int num = index - 1;
List<string> presetNames = Presets.PresetNames;
if (num >= 0 && num < presetNames.Count)
{
_selectedPresetName = presetNames[num];
SetLabelText(_selectedPresetName);
OnPresetSelected(_selectedPresetName);
UpdatePresetUIVisibility();
}
}
private static void OnEditClicked()
{
if (_isEditMode)
{
ExitEditMode();
}
else if (!string.IsNullOrEmpty(_selectedPresetName))
{
StartEdit(_selectedPresetName);
}
}
private static void OnDeleteClicked()
{
if (!string.IsNullOrEmpty(_selectedPresetName))
{
OpenDeleteConfirm(_selectedPresetName);
}
}
private static void UpdatePresetUIVisibility()
{
bool hasPresets = Presets.HasPresets;
bool flag = hasPresets && !string.IsNullOrEmpty(_selectedPresetName);
if ((Object)(object)_presetButtonObject != (Object)null)
{
_presetButtonObject.SetActive(hasPresets);
}
bool flag2 = (Object)(object)_editDeleteContainer != (Object)null && _editDeleteContainer.activeSelf;
if ((Object)(object)_editDeleteContainer != (Object)null)
{
_editDeleteContainer.SetActive(flag);
}
if (flag && !flag2)
{
Plugin.StartCoroutine(SettleBarLayout());
}
}
private static IEnumerator SettleBarLayout()
{
for (int i = 0; i < 8; i++)
{
Transform val = (((Object)(object)_editDeleteContainer != (Object)null) ? _editDeleteContainer.transform.parent : null);
RectTransform val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<RectTransform>() : null);
if ((Object)(object)val2 != (Object)null)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(val2);
}
yield return null;
}
}
private static void StartEdit(string presetName)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
_editingPreset = presetName;
_isEditMode = true;
_saveButtonText.ForceSet("Save Edit");
LocalizedText editButtonText = _editButtonText;
if (editButtonText != null)
{
editButtonText.ForceSet("Back");
}
SetEditOutline(on: true);
SetEditButtonTextColor(EditAccentLight);
SetLabelText("Editing: " + presetName);
SetLabelColor(EditAccent);
LocalizedText deleteButtonText = _deleteButtonText;
if (deleteButtonText != null)
{
deleteButtonText.ForceSet("Rename");
}
GameObject deleteButtonObject = _deleteButtonObject;
SimpleStunButton val = ((deleteButtonObject != null) ? deleteButtonObject.GetComponent<SimpleStunButton>() : null);
if ((Object)(object)val != (Object)null)
{
((UnityEventBase)val.onClick).RemoveAllListeners();
((UnityEvent)val.onClick).AddListener(UnityAction.op_Implicit((Action)OpenRenameBox));
}
}
private static void OpenRenameBox()
{
string oldName = _editingPreset;
OpenTextPopup("Rename Preset", oldName, "Confirm Rename", delegate(string newName)
{
if (string.IsNullOrWhiteSpace(newName))
{
newName = oldName;
}
newName = newName?.Trim();
string text = null;
bool flag = false;
if (!string.IsNullOrEmpty(oldName) && !string.IsNullOrEmpty(newName) && oldName != newName)
{
if (Presets.RenamePreset(oldName, newName))
{
_selectedPresetName = newName;
flag = true;
text = "Renamed!";
}
else
{
text = "Name taken!";
}
}
ExitEditMode();
if (flag && (Object)(object)_nativeDropdown != (Object)null)
{
RefreshNativeDropdown();
}
if (text != null)
{
Plugin.StartCoroutine(FlashSaveButtonText(text));
}
});
}
private static void OpenTextPopup(string header, string prefill, string confirmLabel, Action<string> onConfirm)
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
try
{
CharacterCreationMenuMapper activeMenuMapper = _activeMenuMapper;
GenericPopupSystem val = ((activeMenuMapper != null) ? activeMenuMapper._PopupSystem : null);
_textPopup = ((val != null) ? val.GenericTextInputPopup : null);
if ((Object)(object)_textPopup == (Object)null)
{
Plugin.LogInstance.LogWarning((object)"[OpenTextPopup]: text input popup unavailable");
return;
}
_textPopupOnConfirm = onConfirm;
_textPopup.Show(new Data());
_textPopup._IgnoreValidation = true;
Plugin.StartCoroutine(SetupTextPopup(_textPopup, header, prefill, confirmLabel));
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(17, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[OpenTextPopup]: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val2);
}
}
private static IEnumerator SetupTextPopup(GenericTextInputPopup popup, string header, string prefill, string confirmLabel)
{
for (int i = 0; i < 30; i++)
{
if ((Object)(object)popup == (Object)null)
{
yield break;
}
if (popup.IsOpen)
{
break;
}
yield return null;
}
try
{
popup._IgnoreValidation = true;
LocalizedText errorMessage = popup.ErrorMessage;
if (errorMessage != null)
{
errorMessage.ForceSet("");
}
if ((Object)(object)popup.ConfirmButton != (Object)null)
{
((Selectable)popup.ConfirmButton).interactable = true;
}
if ((Object)(object)popup.InputField != (Object)null)
{
popup.InputField.text = prefill ?? "";
try
{
popup.InputField.caretPosition = popup.InputField.text.Length;
}
catch
{
}
}
LocalizedText header2 = popup.Header;
if (header2 != null)
{
header2.ForceSet(header);
}
if ((Object)(object)popup.ConfirmButton != (Object)null)
{
((Component)popup.ConfirmButton).gameObject.SetActive(true);
LocalizedText confirmButtonText = popup.ConfirmButtonText;
if (confirmButtonText != null)
{
confirmButtonText.ForceSet(confirmLabel);
}
((UnityEventBase)popup.ConfirmButton.onClick).RemoveAllListeners();
((UnityEvent)popup.ConfirmButton.onClick).AddListener(UnityAction.op_Implicit((Action)OnTextPopupConfirmed));
}
if ((Object)(object)popup.CancelButton != (Object)null)
{
((Component)popup.CancelButton).gameObject.SetActive(true);
LocalizedText cancelButtonText = popup.CancelButtonText;
if (cancelButtonText != null)
{
cancelButtonText.ForceSet("Cancel");
}
((UnityEventBase)popup.CancelButton.onClick).RemoveAllListeners();
((UnityEvent)popup.CancelButton.onClick).AddListener(UnityAction.op_Implicit((Action)OnTextPopupCancelled));
}
if ((Object)(object)popup.RandomizeButton != (Object)null)
{
((Component)popup.RandomizeButton).gameObject.SetActive(false);
}
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[SetupTextPopup]: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val);
}
}
private static void OnTextPopupConfirmed()
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
GenericTextInputPopup textPopup = _textPopup;
string obj = (((Object)(object)((textPopup != null) ? textPopup.InputField : null) != (Object)null) ? _textPopup.InputField.text : null);
Action<string> textPopupOnConfirm = _textPopupOnConfirm;
_textPopupOnConfirm = null;
try
{
GenericTextInputPopup textPopup2 = _textPopup;
if (textPopup2 != null)
{
textPopup2.Hide();
}
}
catch
{
}
try
{
textPopupOnConfirm?.Invoke(obj);
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[OnTextPopupConfirmed]: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val);
}
}
private static void OnTextPopupCancelled()
{
_textPopupOnConfirm = null;
try
{
GenericTextInputPopup textPopup = _textPopup;
if (textPopup != null)
{
textPopup.Hide();
}
}
catch
{
}
}
private static void OpenDeleteConfirm(string presetName)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
try
{
CharacterCreationMenuMapper activeMenuMapper = _activeMenuMapper;
GenericPopupSystem val = ((activeMenuMapper != null) ? activeMenuMapper._PopupSystem : null);
CommonPopup val2 = ((val != null) ? val.GenericPopup : null);
if ((Object)(object)val2 == (Object)null)
{
Plugin.LogInstance.LogWarning((object)"[OpenDeleteConfirm]: confirm popup unavailable, deleting directly");
DeletePreset(presetName);
}
else
{
val2.Show(new Data());
Plugin.StartCoroutine(SetupDeleteConfirmPopup(val2, presetName));
}
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(21, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[OpenDeleteConfirm]: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val3);
}
}
private static IEnumerator SetupDeleteConfirmPopup(CommonPopup popup, string presetName)
{
for (int i = 0; i < 30; i++)
{
if ((Object)(object)popup == (Object)null)
{
yield break;
}
if (popup.IsOpen)
{
break;
}
yield return null;
}
try
{
LocalizedText header = popup.Header;
if (header != null)
{
header.ForceSet("Delete Preset");
}
if ((Object)(object)popup.DescriptionContainer != (Object)null)
{
popup.DescriptionContainer.SetActive(true);
}
LocalizedText description = popup.Description;
if (description != null)
{
description.ForceSet("Permanently delete preset \"" + presetName + "\"?");
}
if ((Object)(object)popup.PrimaryButton != (Object)null)
{
((Component)popup.PrimaryButton).gameObject.SetActive(true);
LocalizedText primaryButtonText = popup.PrimaryButtonText;
if (primaryButtonText != null)
{
primaryButtonText.ForceSet("Delete");
}
((UnityEventBase)popup.PrimaryButton.onClick).RemoveAllListeners();
((UnityEvent)popup.PrimaryButton.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
{
try
{
popup.Hide();
}
catch
{
}
DeletePreset(presetName);
}));
}
if (!((Object)(object)popup.SecondaryButton != (Object)null))
{
yield break;
}
((Component)popup.SecondaryButton).gameObject.SetActive(true);
LocalizedText secondaryButtonText = popup.SecondaryButtonText;
if (secondaryButtonText != null)
{
secondaryButtonText.ForceSet("Cancel");
}
((UnityEventBase)popup.SecondaryButton.onClick).RemoveAllListeners();
((UnityEvent)popup.SecondaryButton.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
{
try
{
popup.Hide();
}
catch
{
}
}));
}
catch (Exception ex)
{
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[SetupDeleteConfirmPopup]: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logInstance.LogWarning(val);
}
}
private static void ExitEditMode()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
string editingPreset = _editingPreset;
_editingPreset = null;
_isEditMode = false;
if ((Object)(object)_saveButtonText != (Object)null)
{
_saveButtonText.ForceSet("Save New Preset");
}
LocalizedText editButtonText = _editButtonText;
if (editButtonText != null)
{
editButtonText.ForceSet("Edit");
}
SetEditOutline(on: false);
SetEditButtonTextColor(_defaultButtonTextColor);
SetLabelColor(Color.white);
if (!string.IsNullOrEmpty(_selectedPresetName))
{
SetLabelText(_selectedPresetName);
}
else if (!string.IsNullOrEmpty(editingPreset))
{
SetLabelText(editingPreset);
}
LocalizedText deleteButtonText = _deleteButtonText;
if (deleteButtonText != null)
{
deleteButtonText.ForceSet("Delete");
}
GameObject deleteButtonObject = _deleteButtonObject;
SimpleStunButton val = ((deleteButtonObject != null) ? deleteButtonObject.GetComponent<SimpleStunButton>() : null);
if ((Object)(object)val != (Object)null)
{
((UnityEventBase)val.onClick).RemoveAllListeners();
((UnityEvent)val.onClick).AddListener(UnityAction.op_Implicit((Action)OnDeleteClicked));
}
}
private static void DeletePreset(string presetName)
{
Presets.DeletePreset(presetName);
_selectedPresetName = null;
_pendingCharacterName = null;
if (_isEditMode)
{
ExitEditMode();
}
if ((Object)(object)_nativeDropdown != (Object)null)
{
RefreshNativeDropdown();
}
UpdatePresetUIVisibility();
}
private static void OnPresetSelected(string presetName)
{
if (_activeMenuMapper == null)
{
return;
}
CharacterPreset preset = Presets.GetPreset(presetName);
if (preset != null)
{
_activeMenuMapper._SelectedBodyTypeIndex = preset.BodyTypeIndex;
_activeMenuMapper._SkinToneColorIndex = preset.SkinToneColorIndex;
_activeMenuMapper._FaceIndex = preset.FaceIndex;
_activeMenuMapper._EyeColorIndex = preset.EyeColorIndex;
_activeMenuMapper._HairIndex = preset.HairIndex;
_activeMenuMapper._HairColorIndex = preset.HairColorIndex;
_activeMenuMapper._FeaturesIndex = preset.FeaturesIndex;
_activeMenuMapper._AccessoriesIndex = preset.AccessoriesIndex;
_pendingCharacterName = (string.IsNullOrEmpty(preset.Name) ? null : preset.Name);
EnsureConfirmNameListener();
if (_isEditMode)
{
ExitEditMode();
}
}
}
private static void EnsureConfirmNameListener()
{
CharacterCreationMenuMapper activeMenuMapper = _activeMenuMapper;
object obj;
if (activeMenuMapper == null)
{
obj = null;
}
else
{
CharacterCreationScreen characterCreationScreen = activeMenuMapper._CharacterCreationScreen;
obj = ((characterCreationScreen != null) ? characterCreationScreen.ConfirmCharacter : null);
}
SimpleStunButton val = (SimpleStunButton)obj;
if (!((Object)(object)val == (Object)null))
{
if (_confirmNameAction == null)
{
_confirmNameAction = UnityAction.op_Implicit((Action)ApplyPendingName);
}
((UnityEvent)val.onClick).RemoveListener(_confirmNameAction);
((UnityEvent)val.onClick).AddListener(_confirmNameAction);
}
}
private static void ApplyPendingName()
{
if (string.IsNullOrEmpty(_pendingCharacterName))
{
return;
}
try
{
CharacterCreationMenuMapper activeMenuMapper = _activeMenuMapper;
if (activeMenuMapper == null)
{
return;
}
CharacterCreationScreen characterCreationScreen = activeMenuMapper._CharacterCreationScreen;
if (characterCreationScreen != null)
{
TMP_InputField nameInputField = characterCreationScreen.NameInputField;
if (nameInputField != null)
{
nameInputField.SetText(_pendingCharacterName, true);
}
}
}
catch
{
}
}
private static void OnSaveClicked(CharacterCreationMenuMapper menuMapper)
{
if (_isEditMode)
{
string editingPreset = _editingPreset;
ExitEditMode();
CommitPreset(menuMapper, editingPreset);
return;
}
OpenTextPopup("Name Preset", Presets.GetNextPresetName(), "Save Preset", delegate(string name)
{
name = name?.Trim();
if (string.IsNullOrEmpty(name))
{
name = Presets.GetNextPresetName();
}
if (Presets.GetPreset(name) != null)
{
Plugin.StartCoroutine(FlashSaveButtonText("Name taken!"));
}
else
{
CommitPreset(menuMapper, name);
}
});
}
private static void CommitPreset(CharacterCreationMenuMapper menuMapper, string name)
{
CharacterPreset preset = new CharacterPreset
{
Name = name,
BodyTypeIndex = menuMapper._SelectedBodyTypeIndex,
SkinToneColorIndex = menuMapper._SkinToneColorIndex,
FaceIndex = menuMapper._FaceIndex,
EyeColorIndex = menuMapper._EyeColorIndex,
HairIndex = menuMapper._HairIndex,
HairColorIndex = menuMapper._HairColorIndex,
FeaturesIndex = menuMapper._FeaturesIndex,
AccessoriesIndex = menuMapper._AccessoriesIndex
};
Presets.SavePreset(name, preset);
Plugin.StartCoroutine(FlashSaveButtonText("Saved!"));
_selectedPresetName = name;
_pendingCharacterName = name;
EnsureConfirmNameListener();
if ((Object)(object)_nativeDropdown != (Object)null)
{
RefreshNativeDropdown();
}
UpdatePresetUIVisibility();
}
}
}