using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MageConfigurationAPI.Data;
using MageConfigurationAPI.Enums;
using MageConfigurationAPI.Helpers;
using MageConfigurationAPI.Managers;
using MageConfigurationAPI.Modules.Prefab;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MageConfigurationAPI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MageConfigurationAPI")]
[assembly: AssemblyTitle("MageConfigurationAPI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 MageConfigurationAPI
{
[BepInProcess("MageArena")]
[BepInPlugin("com.d1gq.mage.configuration.api", "MageConfigurationAPI", "1.3.1")]
public class MCAPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.d1gq.mage.configuration.api";
private const string PluginName = "MageConfigurationAPI";
private const string VersionString = "1.3.1";
private static Harmony? Harmony;
private ManualLogSource? _log;
internal static MCAPlugin Instance { get; private set; }
internal static ManualLogSource Log => Instance._log;
private void Awake()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
_log = ((BaseUnityPlugin)this).Logger;
Instance = this;
Harmony = new Harmony("com.d1gq.mage.configuration.api");
Harmony.PatchAll();
Log.LogInfo((object)"MageConfigurationAPI v1.3.1 loaded!");
}
}
}
namespace MageConfigurationAPI.Patches.UI
{
[HarmonyPatch(typeof(MainMenuManager))]
internal class MainMenuManagerPatch
{
private static bool menuOpen;
private static Button? modSettingsButton;
private static Dictionary<GameObject?, List<ModConfig>> settingsList = new Dictionary<GameObject, List<ModConfig>>();
private static HashSet<string> plugins = new HashSet<string>();
private static InputBoxPrefab InputBoxPrefab { get; } = new InputBoxPrefab("Canvas (1)/Main/LobbyID");
private static CheckBoxPrefab CheckBoxPrefab { get; } = new CheckBoxPrefab("Canvas (1)/Main/CreateLobbyMenu/Private");
private static MenuButtonPrefab ButtonPrefab { get; } = new MenuButtonPrefab("Canvas (1)/Main/JoinLobby");
private static LobbyMenuPrefab LobbyMenuPrefab { get; } = new LobbyMenuPrefab("Canvas (1)/Main/LobbyID/LobbiesMenu/Scroll View");
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void Awake_Postfix()
{
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
GameObject val = Utils.FindInactive("Canvas (1)/Main");
ScrollRect menu = LobbyMenuPrefab.CreateMenu((val != null) ? val.transform.parent : null);
if ((Object)(object)menu != (Object)null)
{
Object.Destroy((Object)(object)((Component)menu.content).GetComponent<ContentSizeFitter>());
Object.Destroy((Object)(object)((Component)menu.content).GetComponent<VerticalLayoutGroup>());
menu.horizontal = false;
((Component)menu).gameObject.SetActive(false);
((Object)menu).name = "SettingsMenu";
((Component)menu).transform.localPosition = Vector3.zero;
((Component)menu).transform.localScale = new Vector3(1f, 1.5f, 1f);
}
modSettingsButton = ButtonPrefab.CreateButton(delegate
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)menu != (Object)null)
{
if (!((Component)menu).gameObject.activeInHierarchy)
{
if (((Transform)menu.content).childCount == 0)
{
LoadConfigsIntoSettings();
}
((Component)menu.content).transform.localPosition = Vector3.zero;
AlignSettings(settingsList);
((Component)menu).gameObject.SetActive(true);
menuOpen = true;
}
else
{
((Component)menu).gameObject.SetActive(false);
menuOpen = false;
}
}
}, "Mod Settings", (val != null) ? val.transform.parent : null);
if ((Object)(object)modSettingsButton != (Object)null)
{
((Object)modSettingsButton).name = "ModSettingsButton";
((Component)modSettingsButton).transform.localPosition = new Vector3(-772f, 461f, 0f);
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void Update_Postfix()
{
bool flag = Utils.IsInMainMenu() || Utils.IsInLobby() || Utils.IsInPauseMenu();
if (menuOpen && !flag)
{
ScrollRect? instance = LobbyMenuPrefab.Instance;
if (instance != null)
{
((Component)instance).gameObject.SetActive(false);
}
menuOpen = false;
}
Button? obj = modSettingsButton;
if (obj != null)
{
((Component)obj).gameObject.SetActive(flag);
}
}
private static void LoadConfigsIntoSettings()
{
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
settingsList.Clear();
plugins.Clear();
GameObject val = null;
foreach (ModConfig item in from c in ConfigManager.Configs
orderby c.PluginInfo.Metadata.GUID, c.Name
select c)
{
if (!plugins.Contains(item.PluginInfo.Metadata.GUID))
{
string text = item.PluginInfo.Metadata.Name + " Config";
ScrollRect? instance = LobbyMenuPrefab.Instance;
GameObject val2 = CreateText(text, (Transform?)(object)((instance != null) ? instance.content : null));
if ((Object)(object)val2 != (Object)null)
{
((Object)val2).name = "header";
val2.transform.localPosition = new Vector3(0f, 0f, 0f);
val2.transform.localScale = Vector3.one;
Text[] componentsInChildren = val2.GetComponentsInChildren<Text>();
foreach (Text val3 in componentsInChildren)
{
val3.fontSize = 40;
val3.horizontalOverflow = (HorizontalWrapMode)1;
}
}
val = val2;
settingsList[val2] = new List<ModConfig>();
plugins.Add(item.PluginInfo.Metadata.GUID);
}
if (!((Object)(object)val == (Object)null))
{
if (item.GetConfigType() == typeof(bool))
{
string name = item.Name;
ScrollRect? instance2 = LobbyMenuPrefab.Instance;
CreateBoolSetting(name, item, (Transform?)(object)((instance2 != null) ? instance2.content : null));
}
else
{
string name2 = item.Name;
ScrollRect? instance3 = LobbyMenuPrefab.Instance;
CreateInputSetting(name2, item, (Transform?)(object)((instance3 != null) ? instance3.content : null));
}
settingsList[val].Add(item);
}
}
}
private static void AlignSettings(Dictionary<GameObject?, List<ModConfig?>> settingsList)
{
//IL_0050: 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_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0271: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)LobbyMenuPrefab.Instance == (Object)null || (Object)(object)LobbyMenuPrefab.Instance.content == (Object)null)
{
return;
}
float num = 0f;
float num2 = 450f;
Vector3 val = ((Component)LobbyMenuPrefab.Instance).transform.position + new Vector3(0f, 180f, 0f);
foreach (KeyValuePair<GameObject, List<ModConfig>> settings in settingsList)
{
GameObject key = settings.Key;
if ((Object)(object)key == (Object)null)
{
continue;
}
List<GameObject> list = (from con in settings.Value.Where(CheckConfig)
select con?.Instance).ToList();
if (list.Count == 0)
{
key.gameObject.SetActive(false);
continue;
}
key.gameObject.SetActive(true);
key.transform.position = new Vector3(val.x, val.y - num, val.z);
num += 235f;
for (int i = 0; i < list.Count; i++)
{
GameObject val2 = list[i];
if (!((Object)(object)val2 == (Object)null))
{
val2.SetActive(true);
float num3 = ((i == list.Count - 1 && list.Count % 2 == 1) ? val.x : ((i % 2 == 0) ? (val.x - num2 / 2f) : (val.x + num2 / 2f)));
val2.transform.position = new Vector3(num3, val.y - num, val.z);
if (i % 2 == 1 || i == list.Count - 1)
{
num += 235f;
}
}
}
num += 40f;
}
LobbyMenuPrefab.Instance.content.sizeDelta = new Vector2(1f, 180f + num * 0.675f);
static bool CheckConfig(ModConfig? config)
{
if (config == null)
{
return false;
}
if (config.SettingsFlag.HasFlag(SettingsFlag.ShowInMainMenu) && Utils.IsInMainMenu())
{
return true;
}
if (config.SettingsFlag.HasFlag(SettingsFlag.ShowInLobbyMenu) && Utils.IsInLobby())
{
return true;
}
if (config.SettingsFlag.HasFlag(SettingsFlag.ShowInPauseMenu) && Utils.IsInPauseMenu())
{
return true;
}
GameObject? instance = config.Instance;
if (instance != null)
{
instance.SetActive(false);
}
return false;
}
}
private static GameObject? CreateText(string text, Transform? transform)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Text");
val.transform.SetParent(transform);
Button val2 = ButtonPrefab.CreateButton(delegate
{
}, text, val.transform);
GameObject val3 = ((val2 != null) ? ((Component)val2).gameObject : null);
if ((Object)(object)val2 != (Object)null)
{
Transform transform2 = ((Component)val2).transform;
RectTransform val4 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
if (val4 != null)
{
val4.anchoredPosition = Vector2.zero;
}
Object.Destroy((Object)(object)((Component)val2).GetComponent<Button>());
Object.Destroy((Object)(object)((Component)val2).GetComponent<Image>());
Object.Destroy((Object)(object)((Component)val2).GetComponent<EventTrigger>());
}
return val;
}
private static GameObject? CreateBoolSetting(string text, ModConfig modConfig, Transform? transform)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
ModConfig modConfig2 = modConfig;
GameObject val = new GameObject("checkbox");
val.transform.SetParent(transform, false);
modConfig2.Instance = val;
Button val2 = CheckBoxPrefab.CreateCheckBox(delegate(GameObject check)
{
modConfig2.ConfigEntry.BoxedValue = !(bool)modConfig2.ConfigEntry.BoxedValue;
check.gameObject.SetActive((bool)modConfig2.ConfigEntry.BoxedValue);
}, (bool)modConfig2.ConfigEntry.BoxedValue, val.transform);
GameObject val3 = CreateText(text, val.transform);
if ((Object)(object)val3 != (Object)null)
{
((Object)val3).name = "text";
val3.transform.localPosition = new Vector3(0f, 75f, 0f);
Text[] componentsInChildren = val3.GetComponentsInChildren<Text>();
foreach (Text val4 in componentsInChildren)
{
((Component)val4).GetComponent<RectTransform>().sizeDelta = new Vector2(0f, -15f);
val4.alignment = (TextAnchor)4;
val4.resizeTextForBestFit = true;
val4.resizeTextMaxSize = 50;
val4.resizeTextMinSize = 25;
}
}
return val;
}
private static GameObject? CreateInputSetting(string text, ModConfig modConfig, Transform? transform)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
ModConfig modConfig2 = modConfig;
GameObject val = new GameObject("inputbox");
val.transform.SetParent(transform, false);
modConfig2.Instance = val;
TMP_InputField val2 = InputBoxPrefab.CreateInputField(delegate(TMP_InputField inputBox, string str)
{
Type configType = modConfig2.GetConfigType();
Type type = configType;
if ((object)type != null)
{
if (type == typeof(int))
{
if (!int.TryParse(str, out var result))
{
return;
}
if (modConfig2.ConfigEntry.IsValueValid(result))
{
modConfig2.ConfigEntry.BoxedValue = result;
return;
}
}
else
{
Type type2 = type;
if (type2 == typeof(float))
{
if (!float.TryParse(str, out var result2))
{
return;
}
if (modConfig2.ConfigEntry.IsValueValid(result2))
{
modConfig2.ConfigEntry.BoxedValue = result2;
return;
}
}
else
{
Type type3 = type;
if (type3 == typeof(string))
{
if (modConfig2.ConfigEntry.IsValueValid(str))
{
modConfig2.ConfigEntry.BoxedValue = str;
return;
}
}
else
{
Type type4 = type;
if (!type4.IsEnum)
{
goto IL_019e;
}
if (!Enum.TryParse(type4, str.Replace(" ", "_"), out object result3))
{
return;
}
if (modConfig2.ConfigEntry.IsValueValid(result3))
{
modConfig2.ConfigEntry.BoxedValue = Convert.ChangeType(result3, Enum.GetUnderlyingType(type4));
return;
}
}
}
}
inputBox.SetTextWithoutNotify(modConfig2.ConfigEntry.BoxedValue.ToString());
return;
}
goto IL_019e;
IL_019e:
throw new NotSupportedException($"Type {modConfig2.GetConfigType()} is not supported");
}, delegate(TMP_InputField inputBox, string str)
{
inputBox.SetTextWithoutNotify(modConfig2.ConfigEntry.BoxedValue.ToString());
}, val.transform);
if (val2 != null)
{
val2.SetTextWithoutNotify(modConfig2.ConfigEntry.BoxedValue.ToString());
}
GameObject val3 = CreateText(text, val.transform);
if ((Object)(object)val3 != (Object)null)
{
((Object)val3).name = "text";
val3.transform.localPosition = new Vector3(0f, 75f, 0f);
Text[] componentsInChildren = val3.GetComponentsInChildren<Text>();
foreach (Text val4 in componentsInChildren)
{
((Component)val4).GetComponent<RectTransform>().sizeDelta = new Vector2(0f, -15f);
val4.alignment = (TextAnchor)4;
val4.resizeTextForBestFit = true;
val4.resizeTextMaxSize = 50;
val4.resizeTextMinSize = 25;
}
}
return val;
}
}
}
namespace MageConfigurationAPI.Modules.Prefab
{
internal class CheckBoxPrefab : ObjectPrefab<Button>
{
internal CheckBoxPrefab(string path)
: base(path)
{
}
internal Button? CreateCheckBox(Action<GameObject> onClick, bool isCheck, Transform? parent = null)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Expected O, but got Unknown
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Expected O, but got Unknown
Action<GameObject> onClick2 = onClick;
Button val = Instantiate(parent);
if ((Object)(object)val != (Object)null)
{
((Component)val).transform.localPosition = new Vector3(0f, 0f, 0f);
Text[] componentsInChildren = ((Component)val).GetComponentsInChildren<Text>();
foreach (Text val2 in componentsInChildren)
{
Object.Destroy((Object)(object)((Component)val2).gameObject);
}
val.onClick = new ButtonClickedEvent();
((Component)val).GetComponent<RectTransform>().sizeDelta = new Vector2(55f, 40f);
((Graphic)((Component)val).GetComponent<Image>()).color = new Color(1f, 1f, 1f, 0f);
GameObject val3 = Object.Instantiate<GameObject>(Utils.FindInactive("Canvas (1)/Main/CreateLobbyMenu/SmallMap (2)"), ((Component)val).transform, true);
if ((Object)(object)val3 != (Object)null)
{
val3.transform.localPosition = new Vector3(0f, 0f, 0f);
}
GameObject val4 = Object.Instantiate<GameObject>(Utils.FindInactive("Canvas (1)/Main/CreateLobbyMenu/SmallMap (1)"), ((Component)val).transform, true);
if ((Object)(object)val4 != (Object)null)
{
val4.transform.localPosition = new Vector3(0f, 0f, 0f);
}
GameObject check = Object.Instantiate<GameObject>(Utils.FindInactive("Canvas (1)/Main/CreateLobbyMenu/check1"), ((Component)val).transform, true);
if ((Object)(object)check != (Object)null)
{
check.transform.localPosition = new Vector3(0f, 0f, 0f);
check.gameObject.SetActive(isCheck);
((UnityEvent)val.onClick).AddListener((UnityAction)delegate
{
onClick2(check);
});
}
}
return val;
}
}
internal class InputBoxPrefab : ObjectPrefab<TMP_InputField>
{
internal InputBoxPrefab(string path)
: base(path)
{
}
internal TMP_InputField? CreateInputField(Action<TMP_InputField, string> onEnter, Action<TMP_InputField, string> onExit, Transform? parent = null)
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
Action<TMP_InputField, string> onEnter2 = onEnter;
Action<TMP_InputField, string> onExit2 = onExit;
TMP_InputField input = Instantiate(parent);
if ((Object)(object)input != (Object)null)
{
input.onSubmit = new SubmitEvent();
((UnityEvent<string>)(object)input.onSubmit).AddListener((UnityAction<string>)delegate(string str)
{
onEnter2(input, str);
});
input.onEndEdit = new SubmitEvent();
((UnityEvent<string>)(object)input.onEndEdit).AddListener((UnityAction<string>)delegate(string str)
{
onExit2(input, str);
});
((Component)input).GetComponent<RectTransform>().sizeDelta = new Vector2(600f, 150f);
((Component)input).transform.localPosition = Vector3.zero;
((Component)input).transform.localScale = new Vector3(0.5f, 0.5f, 1f);
input.textComponent.alignment = (TextAlignmentOptions)514;
input.textComponent.fontSize = 60f;
for (int i = 0; i < ((Component)input).transform.childCount; i++)
{
Transform child = ((Component)input).transform.GetChild(i);
if (((Object)child).name != "Text Area")
{
Object.Destroy((Object)(object)((Component)child).gameObject);
}
}
((Component)input).gameObject.SetActive(true);
}
return input;
}
}
internal class LobbyMenuPrefab : ObjectPrefab<ScrollRect>
{
internal LobbyMenuPrefab(string path)
: base(path)
{
}
internal ScrollRect? CreateMenu(Transform? parent = null)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
ScrollRect val = Instantiate(parent);
((Graphic)((Component)val).GetComponent<Image>()).color = new Color(0.5098f, 0.4902f, 0.4196f);
return val;
}
}
internal class MenuButtonPrefab : ObjectPrefab<Button>
{
internal MenuButtonPrefab(string path)
: base(path)
{
}
internal Button? CreateButton(Action onClick, string? text = null, Transform? parent = null)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
Action onClick2 = onClick;
Button val = Instantiate(parent);
if ((Object)(object)val != (Object)null)
{
val.onClick = new ButtonClickedEvent();
((UnityEvent)val.onClick).AddListener((UnityAction)delegate
{
onClick2?.Invoke();
});
if (text != null)
{
Text[] componentsInChildren = ((Component)val).GetComponentsInChildren<Text>();
foreach (Text val2 in componentsInChildren)
{
val2.text = text;
}
}
}
return val;
}
}
internal abstract class ObjectPrefab
{
protected GameObject? PrefabGameObject { get; private set; }
internal bool IsValid => (Object)(object)PrefabGameObject != (Object)null;
protected GameObject? Create(string path, Transform? parent = null)
{
PrefabGameObject = Utils.FindInactive(path, "GameScene");
if ((Object)(object)PrefabGameObject == (Object)null)
{
Debug.LogError((object)("[MageConfigurationAPI] Prefab not found at path: " + path));
return null;
}
return Object.Instantiate<GameObject>(PrefabGameObject, parent);
}
}
internal abstract class ObjectPrefab<T> : ObjectPrefab where T : MonoBehaviour
{
internal T? Instance { get; private set; }
private string path { get; }
protected ObjectPrefab(string path)
{
this.path = path;
}
protected T? Instantiate(Transform? parent = null)
{
GameObject val = Create(path, parent);
if ((Object)(object)val == (Object)null)
{
return default(T);
}
T component = val.GetComponent<T>();
if ((Object)(object)component == (Object)null)
{
Object.Destroy((Object)(object)val);
return default(T);
}
Instance = component;
return component;
}
}
}
namespace MageConfigurationAPI.Managers
{
public static class ConfigManager
{
private static readonly HashSet<string> UsedConfigs = new HashSet<string>();
private static readonly List<ModConfig> ModConfigs = new List<ModConfig>();
public static IReadOnlyList<ModConfig> Configs => ModConfigs.AsReadOnly();
public static ModConfig? GetConfigByUUID(string uuid)
{
string uuid2 = uuid;
return ModConfigs.FirstOrDefault((ModConfig c) => c.UUID == uuid2);
}
public static ModConfig? GetConfigByName(string configName)
{
string configName2 = configName;
return ModConfigs.FirstOrDefault((ModConfig c) => c.Name == configName2);
}
public static ModConfig? GetConfigByGUIDAndName(string pluginGuid, string configName)
{
string pluginGuid2 = pluginGuid;
string configName2 = configName;
return ModConfigs.FirstOrDefault((ModConfig c) => c.PluginInfo.Metadata.GUID == pluginGuid2 && c.Name == configName2);
}
private static ModConfig? GetConfigByInstance(GameObject instance)
{
GameObject instance2 = instance;
return ModConfigs.FirstOrDefault((ModConfig c) => (Object)(object)c.Instance == (Object)(object)instance2);
}
internal static void RegisterConfig(ModConfig config)
{
if (!UsedConfigs.Contains(config.UUID))
{
ModConfigs.Add(config);
UsedConfigs.Add(config.UUID);
MCAPlugin.Log.LogInfo((object)("Registered " + config.Name + " config from " + config.PluginInfo.Metadata.GUID));
}
}
public static bool UnregisterConfig(ModConfig config)
{
if (UsedConfigs.Contains(config.UUID))
{
ModConfigs.Remove(config);
UsedConfigs.Remove(config.UUID);
MCAPlugin.Log.LogInfo((object)("Unregistered " + config.Name + " config from " + config.PluginInfo.Metadata.GUID));
return true;
}
return false;
}
}
}
namespace MageConfigurationAPI.Helpers
{
internal static class Utils
{
internal static bool IsInMainMenu()
{
return MainMenuManager.instance.CreateLobbyMenu.activeInHierarchy || MainMenuManager.instance.CreateLobbyb.activeInHierarchy;
}
internal static bool IsInPauseMenu()
{
return MainMenuManager.instance.InGameMenuHolder.activeInHierarchy;
}
internal static bool IsInGame()
{
return MainMenuManager.instance.Crosshair.activeInHierarchy;
}
internal static bool IsInLobby()
{
return MainMenuManager.instance.lobbyScreen.activeInHierarchy;
}
internal static bool IsValueValid(this ConfigEntryBase configEntry, object value)
{
if (configEntry == null)
{
return true;
}
object[] tags = configEntry.Description.Tags;
foreach (object obj in tags)
{
object obj2 = obj;
object obj3 = obj2;
if (!(obj3 is AcceptableValueRange<float> val))
{
if (!(obj3 is AcceptableValueRange<int> val2))
{
if (!(obj3 is AcceptableValueList<float> val3))
{
if (obj3 is AcceptableValueList<string> val4)
{
if (value is string value2)
{
return val4.AcceptableValues.Contains(value2);
}
}
else if (IsEnumAcceptableValue(obj3, value))
{
return true;
}
}
else if (value is float value3)
{
return val3.AcceptableValues.Contains(value3);
}
}
else if (value is int num)
{
return num >= val2.MinValue && num <= val2.MaxValue;
}
}
else if (value is float num2)
{
return num2 >= val.MinValue && num2 <= val.MaxValue;
}
}
return true;
}
private static bool IsEnumAcceptableValue(object tag, object value)
{
Type type = tag.GetType();
if (type.IsGenericType && type.GetGenericTypeDefinition().Name.StartsWith("AcceptableValueEnum"))
{
return type.GetProperty("AcceptableValues")?.GetValue(tag) is IList list && list.Contains(value);
}
return false;
}
internal static bool IsFloatValid(ConfigEntryBase configEntry, float value)
{
return configEntry.IsValueValid(value);
}
internal static bool IsIntValid(ConfigEntryBase configEntry, int value)
{
return configEntry.IsValueValid(value);
}
internal static bool IsStringValid(ConfigEntryBase configEntry, string value)
{
return configEntry.IsValueValid(value);
}
internal static string HashString(string input)
{
using MD5 mD = MD5.Create();
byte[] bytes = Encoding.UTF8.GetBytes(input);
byte[] array = mD.ComputeHash(bytes);
return BitConverter.ToString(array).Replace("-", "").ToLower();
}
internal static GameObject? FindInactive(string path, string sceneName = null)
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrEmpty(path))
{
Debug.LogError((object)"[FindInactive] Path is null or empty");
return null;
}
string[] array = path.Split('/');
if (array.Length == 0)
{
Debug.LogError((object)"[FindInactive] Path has no valid segments");
return null;
}
bool flag = string.IsNullOrEmpty(sceneName);
Transform val = null;
for (int i = 0; i < SceneManager.sceneCount; i++)
{
Scene sceneAt = SceneManager.GetSceneAt(i);
if (!flag && !((Scene)(ref sceneAt)).name.Equals(sceneName))
{
continue;
}
GameObject[] rootGameObjects = ((Scene)(ref sceneAt)).GetRootGameObjects();
foreach (GameObject val2 in rootGameObjects)
{
if (((Object)val2).name.Equals(array[0]))
{
val = val2.transform;
Debug.Log((object)("[FindInactive] Found root '" + array[0] + "' in scene '" + ((Scene)(ref sceneAt)).name + "'"));
break;
}
}
if ((Object)(object)val != (Object)null)
{
break;
}
}
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)("[FindInactive] Root object '" + array[0] + "' not found " + (flag ? "in any scene" : ("in scene '" + sceneName + "'"))));
return null;
}
for (int k = 1; k < array.Length; k++)
{
val = val.Find(array[k]);
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)("[FindInactive] Child '" + array[k] + "' not found under '" + array[k - 1] + "'"));
return null;
}
}
Debug.Log((object)("[FindInactive] Successfully found '" + path + "' " + (flag ? "" : ("in scene '" + sceneName + "'"))));
return ((Component)val).gameObject;
}
}
}
namespace MageConfigurationAPI.Enums
{
[Flags]
public enum SettingsFlag
{
ShowInMainMenu = 1,
ShowInLobbyMenu = 2,
ShowInPauseMenu = 4
}
}
namespace MageConfigurationAPI.Data
{
public class ModConfig
{
public string UUID { get; }
public string Name { get; }
public PluginInfo PluginInfo { get; }
public SettingsFlag SettingsFlag { get; }
internal BaseUnityPlugin Plugin { get; }
internal ConfigEntryBase ConfigEntry { get; }
internal GameObject? Instance { get; set; }
public event EventHandler<SettingChangedEventArgs>? OnSettingChanged;
public ModConfig(BaseUnityPlugin plugin, ConfigEntryBase configEntry, SettingsFlag settingsFlag = SettingsFlag.ShowInMainMenu)
{
UUID = Utils.HashString(plugin.Info.Metadata.GUID + "|" + configEntry.Definition.Key + "|" + configEntry.Definition.Section);
Name = configEntry.Definition.Key;
PluginInfo = plugin.Info;
SettingsFlag = settingsFlag;
Plugin = plugin;
ConfigEntry = configEntry;
ConfigEntry.ConfigFile.SettingChanged += SettingChanged;
ConfigManager.RegisterConfig(this);
}
public Type GetConfigType()
{
return ConfigEntry.SettingType;
}
public T GetConfigValue<T>()
{
return (T)ConfigEntry.BoxedValue;
}
public bool TryGetConfigValue<T>(out T value)
{
if (ConfigEntry.SettingType == typeof(T))
{
value = (T)ConfigEntry.BoxedValue;
return true;
}
value = default(T);
return false;
}
public T GetDefaultConfigValue<T>()
{
return (T)ConfigEntry.DefaultValue;
}
public bool TryGetDefaultConfigValue<T>(out T value)
{
if (ConfigEntry.SettingType == typeof(T))
{
value = (T)ConfigEntry.DefaultValue;
return true;
}
value = default(T);
return false;
}
private void SettingChanged(object sender, SettingChangedEventArgs args)
{
if (args.ChangedSetting == ConfigEntry)
{
this.OnSettingChanged?.Invoke(sender, args);
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}