Decompiled source of CustomRulesPresets v1.0.2

plugins/com.github.ryaghain.CustomRulesPresets.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CustomRulesPresets.Core;
using CustomRulesPresets.UI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization.Components;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.ryaghain.CustomRulesPresets")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+e30537f45cdf8704236ce5274058de2f517fe0b3")]
[assembly: AssemblyProduct("com.github.ryaghain.CustomRulesPresets")]
[assembly: AssemblyTitle("CustomRulesPresets")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace CustomRulesPresets
{
	public enum Error
	{
		Success,
		GenericFailure,
		ArgumentNull,
		ArgumentOutOfRange,
		LocalVariableIsNull,
		GlobalVariableIsNull,
		FileDoesNotExist,
		ObjectNotFound
	}
	[BepInProcess("Super Battle Golf.exe")]
	[BepInPlugin("com.github.ryaghain.CustomRulesPresets", "CustomRulesPresets", "1.0.2")]
	public class CustomRulesPresetsPlugin : BaseUnityPlugin
	{
		internal static string cache_path = "";

		public static UIManager ui_manager = null;

		public static CustomRulesPresetsManager custom_rules_presets_manager = null;

		public static ConfigManager config_manager = null;

		public static Harmony harmony = null;

		public const string Id = "com.github.ryaghain.CustomRulesPresets";

		internal static ManualLogSource Log { get; private set; } = null;


		public static string Name => "CustomRulesPresets";

		public static string Version => "1.0.2";

		private void Awake()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			cache_path = Paths.CachePath + "/";
			Log.LogInfo((object)"Loading config file...");
			config_manager = new ConfigManager(((BaseUnityPlugin)this).Config);
			Error error = config_manager.load_config_values();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Config load status: " + error));
			((BaseUnityPlugin)this).Logger.LogInfo((object)(Utilities.do_log_debug ? "Debug logging is enabled." : "Debug logging is disabled, set 'EnableLogDebugMessages' to 'true' to enable."));
			Log.LogInfo((object)"Beginning patches...");
			harmony = new Harmony("com.github.ryaghain.CustomRulesPresets");
			harmony.PatchAll(Assembly.GetExecutingAssembly());
			Log.LogInfo((object)(Name + " is ready :D"));
		}
	}
	[HarmonyPatch]
	public static class Patches
	{
		public static CustomRulesPresetsManager custom_rules_presets_manager;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MatchSetupMenu), "OnStartClient")]
		public static void hook(MatchSetupMenu __instance)
		{
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "MatchSetupMenu.OnStartClient postfix hook called, setting up...");
			}
			if (CustomRulesPresetsPlugin.custom_rules_presets_manager == null)
			{
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "Setting up CustomRulesPresetsManager...");
				}
				custom_rules_presets_manager = new CustomRulesPresetsManager(__instance.rules);
				CustomRulesPresetsPlugin.custom_rules_presets_manager = custom_rules_presets_manager;
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "CustomRulesPresetsManager exited setup with error: " + custom_rules_presets_manager.construction_error);
				}
			}
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "Setting up UIManager...");
			}
			CustomRulesPresetsPlugin.ui_manager = new UIManager(__instance);
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "UIManager exited setup with error: " + CustomRulesPresetsPlugin.ui_manager.construction_error);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MatchSetupMenu), "OnDestroy")]
		public static void reset()
		{
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "MatchSetupMenu.OnDestroy postfix hook called, freeing UIManager...");
			}
			CustomRulesPresetsPlugin.ui_manager = null;
		}
	}
	public static class Utilities
	{
		public enum LogType
		{
			Error,
			Debug
		}

		public static bool do_log_debug;

		public static void log_verbose(LogType log_type, string message)
		{
			switch (log_type)
			{
			case LogType.Error:
				CustomRulesPresetsPlugin.Log.LogError((object)(message + "\nStack trace: " + Environment.StackTrace));
				return;
			case LogType.Debug:
				CustomRulesPresetsPlugin.Log.LogDebug((object)message);
				return;
			}
			CustomRulesPresetsPlugin.Log.LogError((object)("Invalid log type " + log_type.ToString() + " when trying to log message: " + message + "\nStack trace: " + Environment.StackTrace));
		}

		public static string item_spawn_chance_weights_dict_to_json(Dictionary<ItemPoolId, float> source, bool prettyPrint = true)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (KeyValuePair<ItemPoolId, float> item in source)
			{
				ItemPoolId key = item.Key;
				string key2 = $"Item Type: {((object)(ItemType)(ref key.itemType)).ToString()}, Item Index: {item.Key.itemPoolIndex}";
				dictionary[key2] = item.Value.ToString();
			}
			return JsonConvert.SerializeObject((object)dictionary, (Formatting)(prettyPrint ? 1 : 0));
		}

		public static string rules_dict_to_json(Dictionary<Rule, float> source, bool prettyPrint = true)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (KeyValuePair<Rule, float> item in source)
			{
				Rule key = item.Key;
				string key2 = ((object)(Rule)(ref key)).ToString();
				dictionary[key2] = item.Value.ToString();
			}
			return JsonConvert.SerializeObject((object)dictionary, (Formatting)(prettyPrint ? 1 : 0));
		}

		public static Dictionary<GameObject, object> get_all_children_and_components(GameObject root, GameObject? parent = null, int root_path_count = 0)
		{
			Dictionary<GameObject, object> dictionary = new Dictionary<GameObject, object>();
			if ((Object)(object)parent == (Object)null)
			{
				Dictionary<string, object> dictionary2 = new Dictionary<string, object>();
				string source = (string)(dictionary2["path"] = TransformExtensions.GetFullPath(root.transform));
				dictionary2["components"] = (from c in root.GetComponents<Component>()
					select ((object)c).GetType().ToString()).ToList();
				dictionary2["children"] = ((root.transform.childCount > 0) ? ((object)get_all_children_and_components(root, root, source.Count() + 1)) : ((object)new Dictionary<GameObject, object>()));
				dictionary.Add(root, dictionary2);
			}
			else
			{
				for (int i = 0; i < parent.transform.childCount; i++)
				{
					GameObject gameObject = ((Component)parent.transform.GetChild(i)).gameObject;
					Dictionary<string, object> dictionary3 = new Dictionary<string, object>();
					dictionary3["path from root"] = TransformExtensions.GetFullPath(gameObject.transform).Substring(root_path_count);
					dictionary3["components"] = (from c in gameObject.GetComponents<Component>()
						select ((object)c).GetType().ToString()).ToList();
					dictionary3["children"] = ((gameObject.transform.childCount > 0) ? ((object)get_all_children_and_components(root, gameObject, root_path_count)) : ((object)new Dictionary<GameObject, object>()));
					dictionary.Add(gameObject, dictionary3);
				}
			}
			return dictionary;
		}

		public static void save_tree_info_to_disk(GameObject root)
		{
			string text = CustomRulesPresetsPlugin.cache_path + ((Object)root).name + "_tree.json";
			FileStream stream = new FileStream(text, FileMode.Create, FileAccess.Write, FileShare.None);
			StreamWriter streamWriter = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
			streamWriter.Write(JsonConvert.SerializeObject((object)get_all_children_and_components(root), (Formatting)1));
			streamWriter.Close();
			log_verbose(LogType.Debug, "Saved '" + ((Object)root).name + "' object tree data to '" + text + "'.");
		}
	}
}
namespace CustomRulesPresets.UI
{
	public class ActiveStateListener : MonoBehaviour
	{
		public Action<bool>? OnActiveChanged;

		private void OnEnable()
		{
			OnActiveChanged?.Invoke(obj: true);
		}

		private void OnDisable()
		{
			OnActiveChanged?.Invoke(obj: false);
		}
	}
	public class UIManager
	{
		public Error construction_error;

		private const string NEW_PRESET_OPTION_TEXT = "New Preset";

		public MatchSetupMenu instance_match_setup_menu;

		public GameObject presets_header_container;

		public GameObject presets_top_row_container;

		public GameObject presets_bottom_row_container;

		public TMP_InputField preset_rename_input_field;

		public TMP_Dropdown presets_dropdown;

		public bool presets_is_updating;

		public int current_selected_preset_index = -1;

		private CustomRulesPresetsManager custom_rules_presets_manager => CustomRulesPresetsPlugin.custom_rules_presets_manager;

		public void add_listeners_to_category_buttons()
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			if ((Object)(object)instance_match_setup_menu == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Cannot add listeners to category buttons because 'instance_match_setup_menu' is null.");
				return;
			}
			string text = "Menu/Background/Rules/Header/Presets";
			Transform val = instance_match_setup_menu.menu.transform.Find(text);
			if ((Object)(object)val == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Could not find '" + text + "'.");
				return;
			}
			if ((Object)(object)presets_header_container == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "'presets_header_container' is null.");
				return;
			}
			if ((Object)(object)presets_top_row_container == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "'presets_top_row_container' is null.");
				return;
			}
			if ((Object)(object)presets_bottom_row_container == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "'presets_bottom_row_container' is null.");
				return;
			}
			bool active = false;
			for (int i = 0; i < val.childCount; i++)
			{
				Transform child = val.GetChild(i);
				Button component = ((Component)child).GetComponent<Button>();
				Transform val2 = child.Find("Selection");
				Transform obj = child.Find("Text (TMP)");
				TMP_Text val3 = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null);
				if ((Object)(object)component == (Object)null || (Object)(object)val3 == (Object)null)
				{
					continue;
				}
				switch (val3.text.Trim())
				{
				case "Custom":
					((UnityEvent)component.onClick).AddListener((UnityAction)delegate
					{
						presets_header_container.SetActive(true);
						presets_top_row_container.SetActive(true);
						presets_bottom_row_container.SetActive(true);
					});
					break;
				case "Classic":
				case "Pro Golf":
					((UnityEvent)component.onClick).AddListener((UnityAction)delegate
					{
						presets_header_container.SetActive(false);
						presets_top_row_container.SetActive(false);
						presets_bottom_row_container.SetActive(false);
					});
					break;
				}
				if ((Object)(object)val2 != (Object)null && ((Component)val2).gameObject.activeSelf && (Object)(object)val3 != (Object)null && val3.text.Trim() == "Custom")
				{
					active = true;
				}
			}
			presets_header_container.SetActive(active);
			presets_top_row_container.SetActive(active);
			presets_bottom_row_container.SetActive(active);
		}

		public Error clone_and_insert_ui_elements()
		{
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Expected O, but got Unknown
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Expected O, but got Unknown
			string text2 = "Menu/Background/Rules/Rules/Scroll View/Viewport/Content";
			Transform val = instance_match_setup_menu.menu.transform.Find(text2);
			if ((Object)(object)val == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Unable to find object '" + text2 + "'.");
				return Error.ObjectNotFound;
			}
			string text3 = "Time";
			Transform val2 = val.Find(text3);
			if ((Object)(object)val2 == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Unable to find object '" + text3 + "'.");
				return Error.ObjectNotFound;
			}
			string text4 = "Time Rules";
			Transform val3 = val.Find(text4);
			if ((Object)(object)val3 == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Unable to find object '" + text4 + "'.");
				return Error.ObjectNotFound;
			}
			string text5 = "Time Rules (1)";
			Transform val4 = val.Find(text5);
			if ((Object)(object)val4 == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Unable to find object '" + text5 + "'.");
				return Error.ObjectNotFound;
			}
			string text6 = "Reset Container";
			Transform val5 = val.Find(text6);
			if ((Object)(object)val5 == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Unable to find object '" + text6 + "'.");
				return Error.ObjectNotFound;
			}
			string text7 = "Menu/Background/Match Setup/Header/Server Name";
			Transform val6 = instance_match_setup_menu.menu.transform.Find(text7);
			if ((Object)(object)val6 == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Unable to find object '" + text7 + "'.");
				return Error.ObjectNotFound;
			}
			presets_header_container = Object.Instantiate<GameObject>(((Component)val2).gameObject, val);
			presets_header_container.transform.SetSiblingIndex(0);
			reset_styling_to_enabled(presets_header_container);
			((Object)presets_header_container).name = "PresetsHeaderContainer";
			LocalizeStringEvent component = presets_header_container.GetComponent<LocalizeStringEvent>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			TMP_Text component2 = presets_header_container.GetComponent<TMP_Text>();
			if ((Object)(object)component2 == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, $"Unable to find the text component of '{presets_header_container}'.");
				return Error.ObjectNotFound;
			}
			component2.text = "Presets";
			presets_top_row_container = Object.Instantiate<GameObject>(((Component)val3).gameObject, val);
			presets_top_row_container.transform.SetSiblingIndex(1);
			((Object)presets_top_row_container).name = "PresetsTopRowContainer";
			for (int num = presets_top_row_container.transform.childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)presets_top_row_container.transform.GetChild(num)).gameObject);
			}
			GameObject val7 = Object.Instantiate<GameObject>(((Component)val6).gameObject, presets_top_row_container.transform);
			reset_styling_to_enabled(val7);
			((Object)val7).name = "PresetRenameContainer";
			preset_rename_input_field = val7.GetComponent<TMP_InputField>();
			((Object)preset_rename_input_field).name = "PresetRenameInputField";
			((UnityEventBase)preset_rename_input_field.onValueChanged).RemoveAllListeners();
			((UnityEventBase)preset_rename_input_field.onEndEdit).RemoveAllListeners();
			((UnityEventBase)preset_rename_input_field.onSubmit).RemoveAllListeners();
			((UnityEventBase)preset_rename_input_field.onSelect).RemoveAllListeners();
			((UnityEventBase)preset_rename_input_field.onDeselect).RemoveAllListeners();
			preset_rename_input_field.SetTextWithoutNotify("Preset 1");
			((UnityEvent<string>)(object)preset_rename_input_field.onSubmit).AddListener((UnityAction<string>)delegate(string text)
			{
				handle_preset_renaming(text);
			});
			GameObject val8 = Object.Instantiate<GameObject>(((Component)val5).gameObject, presets_top_row_container.transform);
			reset_styling_to_enabled(val8);
			((Object)val8).name = "PresetDeleteContainer";
			Transform val9 = val8.transform.Find("Option Container/Reset Probabilites");
			((Object)((Component)val9).gameObject).name = "PresetDeleteButtonContainer";
			Button component3 = ((Component)val9).gameObject.GetComponent<Button>();
			((UnityEventBase)component3.onClick).RemoveAllListeners();
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				handle_preset_delete();
			});
			GameObject gameObject = ((Component)val9.Find("Text")).gameObject;
			LocalizeStringEvent component4 = gameObject.GetComponent<LocalizeStringEvent>();
			if ((Object)(object)component4 != (Object)null)
			{
				Object.Destroy((Object)(object)component4);
			}
			TextMeshProUGUI component5 = gameObject.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component5).text = "Delete Preset";
			presets_bottom_row_container = Object.Instantiate<GameObject>(((Component)val4).gameObject, val);
			presets_bottom_row_container.transform.SetSiblingIndex(2);
			((Object)presets_bottom_row_container).name = "PresetsBottomRowContainer";
			Transform val10 = presets_bottom_row_container.transform.Find("Max Time Based On Par");
			reset_styling_to_enabled(((Component)val10).gameObject);
			((Object)((Component)val10).gameObject).name = "PresetsDropdown";
			Transform val11 = val10.Find("Max Time Based On Par Dropdown/Option Contents/Dropdown");
			presets_dropdown = ((Component)val11).GetComponent<TMP_Dropdown>();
			Object.Destroy((Object)(object)((Component)val11).GetComponent("LocalizeDropdown"));
			presets_dropdown.options.Clear();
			presets_dropdown.options.Add(new OptionData("New Preset"));
			presets_dropdown.value = 0;
			current_selected_preset_index = 0;
			presets_dropdown.RefreshShownValue();
			((UnityEventBase)presets_dropdown.onValueChanged).RemoveAllListeners();
			((UnityEvent<int>)(object)presets_dropdown.onValueChanged).AddListener((UnityAction<int>)delegate(int index)
			{
				handle_selected_dropdown_option(index);
			});
			Transform obj = val10.Find("Max Time Based On Par Dropdown/Label Text");
			TMP_Text val12 = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null);
			LocalizeStringEvent component6 = ((Component)val12).GetComponent<LocalizeStringEvent>();
			if ((Object)(object)component6 != (Object)null)
			{
				Object.Destroy((Object)(object)component6);
			}
			val12.text = "Change Preset";
			LayoutRebuilder.ForceRebuildLayoutImmediate(presets_header_container.GetComponent<RectTransform>());
			LayoutRebuilder.ForceRebuildLayoutImmediate(val7.GetComponent<RectTransform>());
			LayoutRebuilder.ForceRebuildLayoutImmediate(val8.GetComponent<RectTransform>());
			LayoutRebuilder.ForceRebuildLayoutImmediate(presets_top_row_container.GetComponent<RectTransform>());
			LayoutRebuilder.ForceRebuildLayoutImmediate(((Component)val10).GetComponent<RectTransform>());
			LayoutRebuilder.ForceRebuildLayoutImmediate(presets_bottom_row_container.GetComponent<RectTransform>());
			LayoutRebuilder.ForceRebuildLayoutImmediate(((Component)val).GetComponent<RectTransform>());
			add_listeners_to_category_buttons();
			return Error.Success;
		}

		private void handle_preset_delete()
		{
			if (current_selected_preset_index == presets_dropdown.options.Count - 1)
			{
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "Preset delete button click detected, but 'New Preset' is selected.");
				}
				return;
			}
			if (presets_dropdown.options.Count < 3)
			{
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "Preset delete button click detected, but no preset to switch to, after deleting, exists. Create another preset first.");
				}
				return;
			}
			if (presets_is_updating)
			{
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "Preset delete button click detected, but presets are still updating.");
				}
				return;
			}
			int num = ((current_selected_preset_index > 0) ? (current_selected_preset_index - 1) : (current_selected_preset_index + 1));
			if (custom_rules_presets_manager.custom_rules_presets_data.preset_delete(presets_dropdown.options[current_selected_preset_index].text) != 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, $"Unable to delete preset at dropdown index '{current_selected_preset_index}'.");
				return;
			}
			presets_dropdown.options.RemoveAt(current_selected_preset_index);
			custom_rules_presets_manager.preset_load_settings(presets_dropdown.options[num].text);
			update_values(num);
		}

		private void handle_preset_renaming(string new_preset_name)
		{
			if (string.IsNullOrEmpty(new_preset_name))
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Provided new preset name is null or empty.");
				return;
			}
			string text = presets_dropdown.options[current_selected_preset_index].text;
			new_preset_name = new_preset_name.Trim();
			if (custom_rules_presets_manager.custom_rules_presets_data.preset_rename(text, new_preset_name) != 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Unable to rename preset '" + text + "' to '" + new_preset_name + "'.");
				update_values(current_selected_preset_index);
			}
			else
			{
				presets_dropdown.options[current_selected_preset_index].text = new_preset_name;
				update_values(current_selected_preset_index);
			}
		}

		private void handle_selected_dropdown_option(int selected_index)
		{
			presets_is_updating = true;
			if (selected_index < 0 || selected_index >= presets_dropdown.options.Count)
			{
				presets_is_updating = false;
				return;
			}
			string text = presets_dropdown.options[current_selected_preset_index].text;
			int new_index = selected_index;
			string text2 = presets_dropdown.options[selected_index].text;
			if (custom_rules_presets_manager.preset_save_settings(text) != 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to save the current preset " + text + " before switching. Restoring previous dropdown selection...");
				update_values(current_selected_preset_index);
				presets_is_updating = false;
			}
			else if (text2 == "New Preset")
			{
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "New Preset option selected, creating new preset...");
				}
				List<string> preset_names = custom_rules_presets_manager.custom_rules_presets_data.get_preset_names();
				int num = preset_names.Count + 1;
				text2 = $"Preset {num}";
				while (preset_names.Contains(text2))
				{
					num++;
					text2 = $"Preset {num}";
				}
				new_index = presets_dropdown.options.Count - 1;
				Error error = custom_rules_presets_manager.custom_rules_presets_data.preset_duplicate(text, text2);
				if (error != 0)
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Failed to duplicate preset '" + text + "' with error: " + error);
					update_values(current_selected_preset_index);
				}
				else
				{
					insert_new_dropdown_option(text2, new_index);
					if (Utilities.do_log_debug)
					{
						Utilities.log_verbose(Utilities.LogType.Debug, "Preset '" + text + "' duplicated to '" + text2 + "'.");
					}
				}
				presets_is_updating = false;
			}
			else if (!custom_rules_presets_manager.custom_rules_presets_data.has_preset(text2))
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Selected preset '" + text2 + "' not found in presets data.");
				update_values(current_selected_preset_index);
				presets_is_updating = false;
			}
			else if (custom_rules_presets_manager.preset_load_settings(text2) != 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to load preset " + text2 + ". Restoring previous dropdown selection...");
				update_values(current_selected_preset_index);
				presets_is_updating = false;
			}
			else
			{
				Error error2 = custom_rules_presets_manager.save_presets_to_file();
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, $"Save presets to file error: {error2}");
				}
				update_values(new_index);
				presets_is_updating = false;
			}
		}

		public Error insert_new_dropdown_option(string option_text, int option_index = -1, bool set_value = true)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			if ((Object)(object)presets_dropdown == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Cannot insert new dropdown option because presets_dropdown is null.");
				return Error.GlobalVariableIsNull;
			}
			int num = ((option_index == -1) ? (presets_dropdown.options.Count - 1) : option_index);
			presets_dropdown.options.Insert(num, new OptionData(option_text));
			if (set_value)
			{
				update_values(num);
			}
			return Error.Success;
		}

		public void reset_styling_to_enabled(GameObject root)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			CanvasGroup[] componentsInChildren = root.GetComponentsInChildren<CanvasGroup>(true);
			foreach (CanvasGroup val in componentsInChildren)
			{
				val.alpha = 1f;
				val.interactable = true;
				val.blocksRaycasts = true;
			}
			Selectable[] componentsInChildren2 = root.GetComponentsInChildren<Selectable>(true);
			foreach (Selectable val2 in componentsInChildren2)
			{
				val2.interactable = true;
			}
			Graphic[] componentsInChildren3 = root.GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val3 in componentsInChildren3)
			{
				Color color = val3.color;
				color.a = 1f;
				val3.color = color;
			}
			TMP_Text[] componentsInChildren4 = root.GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text val4 in componentsInChildren4)
			{
				Color color2 = ((Graphic)val4).color;
				color2.a = 1f;
				((Graphic)val4).color = color2;
			}
		}

		public void update_values(int new_index)
		{
			current_selected_preset_index = new_index;
			presets_dropdown.SetValueWithoutNotify(current_selected_preset_index);
			presets_dropdown.RefreshShownValue();
			preset_rename_input_field.SetTextWithoutNotify(presets_dropdown.options[current_selected_preset_index].text);
		}

		public UIManager(MatchSetupMenu new_instance_match_setup_menu)
		{
			UIManager uIManager = this;
			if ((Object)(object)new_instance_match_setup_menu == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "UIManager is not set up properly.");
				construction_error = Error.ArgumentNull;
				return;
			}
			if (custom_rules_presets_manager == null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "custom_rules_presets_manager is null");
				return;
			}
			instance_match_setup_menu = new_instance_match_setup_menu;
			GameObject instance_match_setup_menu_ui = instance_match_setup_menu.menu;
			ActiveStateListener activeStateListener = instance_match_setup_menu_ui.GetComponent<ActiveStateListener>();
			if ((Object)(object)activeStateListener == (Object)null)
			{
				activeStateListener = instance_match_setup_menu_ui.AddComponent<ActiveStateListener>();
			}
			ActiveStateListener activeStateListener2 = activeStateListener;
			activeStateListener2.OnActiveChanged = (Action<bool>)Delegate.Combine(activeStateListener2.OnActiveChanged, (Action<bool>)delegate(bool isActive)
			{
				if (!isActive)
				{
					if (Utilities.do_log_debug)
					{
						Utilities.log_verbose(Utilities.LogType.Debug, ((Object)instance_match_setup_menu_ui).name + " was closed, saving currently selected preset...");
					}
					Error error4 = uIManager.custom_rules_presets_manager.preset_save_settings(uIManager.presets_dropdown.options[uIManager.current_selected_preset_index].text);
					Error error5 = uIManager.custom_rules_presets_manager.save_presets_to_file();
					if (Utilities.do_log_debug)
					{
						Utilities.log_verbose(Utilities.LogType.Debug, $"Preset save on menu close error: {error4}");
					}
					if (Utilities.do_log_debug)
					{
						Utilities.log_verbose(Utilities.LogType.Debug, $"Save presets to file error: {error5}");
					}
				}
			});
			ConfigManager config_manager = CustomRulesPresetsPlugin.config_manager;
			if (config_manager.do_save_tree_to_disk)
			{
				Utilities.save_tree_info_to_disk(instance_match_setup_menu.menu);
				config_manager.do_save_tree_to_disk = false;
			}
			if (!((NetworkBehaviour)instance_match_setup_menu).isServer)
			{
				return;
			}
			Error error = clone_and_insert_ui_elements();
			if (custom_rules_presets_manager.custom_rules_presets_data.get_preset_count() == 0)
			{
				Error error2 = custom_rules_presets_manager.custom_rules_presets_data.preset_create("Preset 1");
				if (error2 != 0)
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Failed to create default preset 'Preset 1' with error: " + error2);
					return;
				}
				custom_rules_presets_manager.preset_save_settings();
			}
			foreach (string preset_name in custom_rules_presets_manager.custom_rules_presets_data.get_preset_names())
			{
				Error error3 = insert_new_dropdown_option(preset_name, -1, set_value: false);
				if (error3 != 0)
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Failed to insert dropdown option for preset '" + preset_name + "' with error: " + error3);
				}
			}
			int num = 0;
			string text = custom_rules_presets_manager.custom_rules_presets_data.current_selected_preset_name;
			if (custom_rules_presets_manager.custom_rules_presets_data.has_preset(text))
			{
				int count = presets_dropdown.options.Count;
				for (int i = 0; i < count; i++)
				{
					if (presets_dropdown.options[i].text == text)
					{
						num = i;
						break;
					}
				}
			}
			else
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Could not find preset '" + text + "', defaulting to index 0...");
				text = presets_dropdown.options[num].text;
			}
			if (custom_rules_presets_manager.preset_load_settings(text) != 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to load preset " + text + " during setup, defaulting to index 0...");
				current_selected_preset_index = 0;
				if (num == 0 || custom_rules_presets_manager.preset_load_settings(presets_dropdown.options[0].text) != 0)
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Failed to load backup preset during setup. I recommend closing the game, delete the file " + custom_rules_presets_manager.presets_file_path + ", then launch the game. *This will delete all but the current rules settings*.");
				}
			}
			else
			{
				current_selected_preset_index = num;
			}
			presets_dropdown.SetValueWithoutNotify(current_selected_preset_index);
			presets_dropdown.RefreshShownValue();
			preset_rename_input_field.SetTextWithoutNotify(presets_dropdown.options[current_selected_preset_index].text);
		}
	}
}
namespace CustomRulesPresets.Core
{
	public class ConfigManager
	{
		private readonly ConfigFile _config_file;

		private ConfigEntry<bool> _config_enable_log_debug;

		private ConfigEntry<bool> _config_do_save_tree_to_disk;

		public bool do_save_tree_to_disk
		{
			get
			{
				return _config_do_save_tree_to_disk.Value;
			}
			set
			{
				_config_do_save_tree_to_disk.Value = value;
			}
		}

		private void clear_orphaned_entries()
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(_config_file);
			dictionary.Clear();
		}

		public Error load_config_values()
		{
			_config_file.SaveOnConfigSet = false;
			_config_enable_log_debug = _config_file.Bind<bool>("Debug", "EnableLogDebugMessages", false, "Whether to log debug messages. Set this to true to enable debug logging.");
			Utilities.do_log_debug = _config_enable_log_debug.Value;
			_config_do_save_tree_to_disk = _config_file.Bind<bool>("Debug", "SaveMenuTreeToFileOnNextRun", false, "When toggled on, will save the rules menu object tree information to your BepInEx folder the next time you load into a lobby, then it will toggle back off.");
			clear_orphaned_entries();
			_config_file.Save();
			_config_file.SaveOnConfigSet = true;
			return Error.Success;
		}

		public ConfigManager(ConfigFile new_config_file)
		{
			if (new_config_file == null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Config file provided to ConfigManager constructor is null.");
			}
			else
			{
				_config_file = new_config_file;
			}
		}
	}
	public class CustomRulesPresetsManager
	{
		[Serializable]
		public class CustomRulesPresetsData
		{
			private Dictionary<string, CustomRulesPreset> data;

			public string current_selected_preset_name = "";

			public int get_preset_count()
			{
				return data.Count;
			}

			public List<string> get_preset_names()
			{
				return data.Keys.ToList();
			}

			public string get_preset_names_string()
			{
				string text = "";
				foreach (string item in data.Keys.ToList())
				{
					text = text + item + ", ";
				}
				return text.Substring(0, text.Length - ", ".Length);
			}

			public bool has_preset(string preset_name)
			{
				if (!string.IsNullOrEmpty(preset_name))
				{
					return data.ContainsKey(preset_name);
				}
				return false;
			}

			public Error preset_create(string preset_name, bool set_current = true)
			{
				if (string.IsNullOrEmpty(preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Provided argument 'preset_name' is null or empty in preset_create.");
					return Error.ArgumentNull;
				}
				data.Add(preset_name, new CustomRulesPreset());
				if (set_current)
				{
					current_selected_preset_name = preset_name;
				}
				return Error.Success;
			}

			public Error preset_delete(string preset_name)
			{
				if (!data.ContainsKey(preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Preset to be deleted '" + preset_name + "' not found.");
					return Error.ArgumentOutOfRange;
				}
				if (data.Keys.Count <= 1)
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Cannot delete the last preset.");
					return Error.GenericFailure;
				}
				data.Remove(preset_name);
				return Error.Success;
			}

			public Error preset_duplicate(string source_preset_name, string new_preset_name, bool set_new_preset_as_current = true)
			{
				if (!data.ContainsKey(source_preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Source preset '" + source_preset_name + "' not found.");
					return Error.ArgumentOutOfRange;
				}
				if (string.IsNullOrEmpty(new_preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Provided argument 'new_preset_name' is null or empty.");
					return Error.ArgumentNull;
				}
				if (data.ContainsKey(new_preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "A preset with the name '" + new_preset_name + "' already exists.");
					return Error.GenericFailure;
				}
				data.Add(new_preset_name, new CustomRulesPreset(data[source_preset_name]));
				if (set_new_preset_as_current)
				{
					current_selected_preset_name = new_preset_name;
				}
				return Error.Success;
			}

			public CustomRulesPreset preset_get(string preset_name)
			{
				if (!data.ContainsKey(preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Preset '" + preset_name + "' not found.");
					return new CustomRulesPreset();
				}
				CustomRulesPreset result = data[preset_name];
				if (result.rules_settings == null || result.item_spawn_chance_weights == null)
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Preset '" + preset_name + "' is not properly initialized, returning empty preset...");
					return new CustomRulesPreset();
				}
				return result;
			}

			public bool preset_is_empty(string preset_name)
			{
				if (!data.ContainsKey(preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Preset '" + preset_name + "' not found.");
					return false;
				}
				return preset_get(preset_name).is_empty();
			}

			public Error preset_rename(string preset_name, string new_preset_name)
			{
				if (!data.ContainsKey(preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Preset '" + preset_name + "' not found.");
					return Error.ArgumentOutOfRange;
				}
				if (string.IsNullOrEmpty(new_preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Provided argument 'new_preset_name' is null or empty.");
					return Error.ArgumentNull;
				}
				if (data.ContainsKey(new_preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "A preset with the name '" + new_preset_name + "' already exists.");
					return Error.GenericFailure;
				}
				CustomRulesPreset value = data[preset_name];
				data.Remove(preset_name);
				data.Add(new_preset_name, value);
				if (current_selected_preset_name == preset_name)
				{
					current_selected_preset_name = new_preset_name;
				}
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "Preset renamed from '" + preset_name + "' to '" + new_preset_name + "'. Current selected preset: '" + current_selected_preset_name + "'.");
				}
				return Error.Success;
			}

			public Error preset_set(string preset_name, CustomRulesPreset new_preset)
			{
				if (!data.ContainsKey(preset_name))
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Preset '" + preset_name + "' not found.");
					return Error.ArgumentOutOfRange;
				}
				if (new_preset.is_empty())
				{
					Utilities.log_verbose(Utilities.LogType.Error, "Invalid new preset, is_empty = true");
					return Error.ArgumentOutOfRange;
				}
				data[preset_name] = new_preset;
				return Error.Success;
			}

			public CustomRulesPresetsData()
			{
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "CustomRulesPresetsData constructed empty, manually creating 'Preset 1'.");
				}
				data = new Dictionary<string, CustomRulesPreset>();
			}
		}

		[Serializable]
		public struct CustomRulesPreset
		{
			public Dictionary<Rule, float> rules_settings;

			public Dictionary<ItemPoolId, float> item_spawn_chance_weights;

			public Dictionary<string, object> get_data()
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				Dictionary<string, object> dictionary = new Dictionary<string, object>();
				dictionary["rules_settings"] = rules_settings;
				Dictionary<string, float> dictionary2 = new Dictionary<string, float>();
				foreach (KeyValuePair<ItemPoolId, float> item_spawn_chance_weight in item_spawn_chance_weights)
				{
					ItemPoolId key = item_spawn_chance_weight.Key;
					dictionary2[$"{((object)(ItemType)(ref key.itemType)).ToString()}, {item_spawn_chance_weight.Key.itemPoolIndex}"] = item_spawn_chance_weight.Value;
				}
				dictionary["item_spawn_chance_weights"] = dictionary2;
				return dictionary;
			}

			public bool is_empty()
			{
				if (rules_settings.Count == 0)
				{
					return item_spawn_chance_weights.Count == 0;
				}
				return false;
			}

			public CustomRulesPreset()
			{
				rules_settings = new Dictionary<Rule, float>();
				item_spawn_chance_weights = new Dictionary<ItemPoolId, float>();
			}

			public CustomRulesPreset(CustomRulesPreset source)
			{
				rules_settings = source.rules_settings.ToDictionary((KeyValuePair<Rule, float> entry) => entry.Key, (KeyValuePair<Rule, float> entry) => entry.Value);
				item_spawn_chance_weights = source.item_spawn_chance_weights.ToDictionary((KeyValuePair<ItemPoolId, float> entry) => entry.Key, (KeyValuePair<ItemPoolId, float> entry) => entry.Value);
			}
		}

		public Error construction_error;

		public string presets_file_path = "";

		public MatchSetupRules instance_match_setup_rules;

		public CustomRulesPresetsData custom_rules_presets_data;

		public Error load_presets_from_file()
		{
			if (!File.Exists(presets_file_path))
			{
				if (Utilities.do_log_debug)
				{
					Utilities.log_verbose(Utilities.LogType.Debug, "File '" + presets_file_path + "' does not exist, skipping load.");
				}
				return Error.FileDoesNotExist;
			}
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using Stream serializationStream = new FileStream(presets_file_path, FileMode.Open, FileAccess.Read, FileShare.Read);
			CustomRulesPresetsData customRulesPresetsData = (CustomRulesPresetsData)binaryFormatter.Deserialize(serializationStream);
			if (customRulesPresetsData == null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to deserialize presets from file: " + presets_file_path);
				return Error.GenericFailure;
			}
			custom_rules_presets_data = customRulesPresetsData;
			preset_load_settings(custom_rules_presets_data.current_selected_preset_name);
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "Successfully loaded presets '" + custom_rules_presets_data.get_preset_names_string() + "' from '" + presets_file_path + "'.");
			}
			return Error.Success;
		}

		public Error preset_load_settings(string preset_name)
		{
			if (preset_name == null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Provided argument '" + preset_name + "' is null in preset_load_settings.");
				return Error.ArgumentNull;
			}
			if (!custom_rules_presets_data.has_preset(preset_name))
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Preset '" + preset_name + "' does not exist.");
				return Error.ArgumentOutOfRange;
			}
			CustomRulesPreset customRulesPreset = custom_rules_presets_data.preset_get(preset_name);
			if (customRulesPreset.is_empty())
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to get preset '" + preset_name + "' or preset is empty.");
				return Error.GenericFailure;
			}
			Error error = set_rules(customRulesPreset.rules_settings);
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "Loaded preset '" + preset_name + "'s rules status: " + error);
			}
			if (error != 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to load preset '" + preset_name + "' due to error in setting rules.");
				return Error.GenericFailure;
			}
			Error error2 = set_item_spawn_chance_weights(customRulesPreset.item_spawn_chance_weights);
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "Loaded preset '" + preset_name + "'s item spawn chance weights status: " + error2);
			}
			if (error2 != 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to load preset '" + preset_name + "' due to error in setting item spawn chance weights.");
				return Error.GenericFailure;
			}
			custom_rules_presets_data.current_selected_preset_name = preset_name;
			return Error.Success;
		}

		public Error preset_save_settings(string preset_name = "")
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			if (preset_name == "")
			{
				preset_name = custom_rules_presets_data.current_selected_preset_name;
			}
			if (!custom_rules_presets_data.has_preset(preset_name))
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Preset '" + preset_name + "' does not exist.");
				return Error.ArgumentOutOfRange;
			}
			if ((Object)(object)instance_match_setup_rules == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "CustomRulesPresetsManager is not set up properly.");
				return Error.GlobalVariableIsNull;
			}
			CustomRulesPreset new_preset = custom_rules_presets_data.preset_get(preset_name);
			Dictionary<Rule, float> dictionary = new Dictionary<Rule, float>();
			foreach (KeyValuePair<Rule, float> rule in instance_match_setup_rules.rules)
			{
				dictionary.Add(rule.Key, rule.Value);
			}
			if (dictionary.Count == 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, $"Failed to save rules settings from the MatchSetupRules instance. Source rules dict == null: {instance_match_setup_rules.rules == null}");
				return Error.GenericFailure;
			}
			new_preset.rules_settings = dictionary;
			Dictionary<ItemPoolId, float> dictionary2 = new Dictionary<ItemPoolId, float>();
			foreach (KeyValuePair<ItemPoolId, float> spawnChanceWeight in instance_match_setup_rules.spawnChanceWeights)
			{
				dictionary2.Add(spawnChanceWeight.Key, spawnChanceWeight.Value);
			}
			if (dictionary2.Count == 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, $"Failed to save item spawn chance weights from the MatchSetupRules instance. Source spawnChanceWeights dict == null: {instance_match_setup_rules.spawnChanceWeights == null}");
				return Error.GenericFailure;
			}
			new_preset.item_spawn_chance_weights = dictionary2;
			Error error = custom_rules_presets_data.preset_set(preset_name, new_preset);
			if (error != 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to save preset '" + preset_name + "' with error: " + error);
				return Error.GenericFailure;
			}
			return Error.Success;
		}

		public Error save_presets_to_file()
		{
			if (custom_rules_presets_data == null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "presets_data is null. Cannot save to config.");
				return Error.ArgumentNull;
			}
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using FileStream serializationStream = new FileStream(presets_file_path, FileMode.Create, FileAccess.Write, FileShare.None);
			binaryFormatter.Serialize(serializationStream, custom_rules_presets_data);
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "Presets '" + custom_rules_presets_data.get_preset_names_string() + "' saved to '" + presets_file_path + "'.");
			}
			return Error.Success;
		}

		public Error set_item_spawn_chance_weights(Dictionary<ItemPoolId, float> item_spawn_chance_weights)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)instance_match_setup_rules == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "CustomRulesPresetsManager is not set up properly.");
				return Error.GlobalVariableIsNull;
			}
			if (item_spawn_chance_weights == null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Provided argument 'item_spawn_chance_weights' is null.");
				return Error.ArgumentNull;
			}
			if (item_spawn_chance_weights.Count == 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Provided argument 'item_spawn_chance_weights' is empty.");
				return Error.ArgumentOutOfRange;
			}
			foreach (KeyValuePair<ItemPoolId, float> item_spawn_chance_weight in item_spawn_chance_weights)
			{
				instance_match_setup_rules.SetSpawnChance(item_spawn_chance_weight.Key.itemPoolIndex, item_spawn_chance_weight.Key.itemType, item_spawn_chance_weight.Value);
			}
			foreach (ItemPoolId key in item_spawn_chance_weights.Keys)
			{
				instance_match_setup_rules.ServerUpdateSpawnChanceValue(key);
			}
			return Error.Success;
		}

		public Error set_rules(Dictionary<Rule, float> rules_settings)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Invalid comparison between Unknown and I4
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)instance_match_setup_rules == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "CustomRulesPresetsManager is not set up properly.");
				return Error.GlobalVariableIsNull;
			}
			if (rules_settings == null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Provided rules settings are null.");
				return Error.ArgumentNull;
			}
			if (rules_settings.Count == 0)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Provided rules settings are empty.");
				return Error.ArgumentOutOfRange;
			}
			foreach (KeyValuePair<Rule, float> rules_setting in rules_settings)
			{
				instance_match_setup_rules.SetValue(rules_setting.Key, rules_setting.Value);
				SliderOption value2;
				if (instance_match_setup_rules.onOffDropdownLookup.TryGetValue(rules_setting.Key, out var value))
				{
					value.SetValue((!instance_match_setup_rules.GetValueAsBoolInternal(rules_setting.Key)) ? 1 : 0);
				}
				else if (instance_match_setup_rules.sliderLookup.TryGetValue(rules_setting.Key, out value2))
				{
					value2.SetValue(instance_match_setup_rules.GetValueInternal(rules_setting.Key));
				}
				instance_match_setup_rules.UpdateRule(rules_setting.Key);
				if ((int)rules_setting.Key == 11)
				{
					instance_match_setup_rules.CheckAndShowCheatsWarning();
				}
			}
			return Error.Success;
		}

		public CustomRulesPresetsManager(MatchSetupRules? new_instance_match_setup_rules)
		{
			if ((Object)(object)new_instance_match_setup_rules == (Object)null)
			{
				Utilities.log_verbose(Utilities.LogType.Error, "Failed to set up CustomRulesPresetsManager: the provided instance is null.");
				construction_error = Error.ArgumentNull;
				return;
			}
			instance_match_setup_rules = new_instance_match_setup_rules;
			presets_file_path = CustomRulesPresetsPlugin.cache_path + "SavedCustomRulesPresets.dat";
			if (load_presets_from_file() != 0)
			{
				custom_rules_presets_data = new CustomRulesPresetsData();
			}
			if (Utilities.do_log_debug)
			{
				Utilities.log_verbose(Utilities.LogType.Debug, "Loaded presets file has current selected name '" + custom_rules_presets_data.current_selected_preset_name + "'. CustomRulesPresetsManager setup done.");
			}
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ConstantExpectedAttribute : Attribute
	{
		public object? Min { get; set; }

		public object? Max { get; set; }
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ExperimentalAttribute : Attribute
	{
		public string DiagnosticId { get; }

		public string? UrlFormat { get; set; }

		public ExperimentalAttribute(string diagnosticId)
		{
			DiagnosticId = diagnosticId;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class SetsRequiredMembersAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class StringSyntaxAttribute : Attribute
	{
		public const string CompositeFormat = "CompositeFormat";

		public const string DateOnlyFormat = "DateOnlyFormat";

		public const string DateTimeFormat = "DateTimeFormat";

		public const string EnumFormat = "EnumFormat";

		public const string GuidFormat = "GuidFormat";

		public const string Json = "Json";

		public const string NumericFormat = "NumericFormat";

		public const string Regex = "Regex";

		public const string TimeOnlyFormat = "TimeOnlyFormat";

		public const string TimeSpanFormat = "TimeSpanFormat";

		public const string Uri = "Uri";

		public const string Xml = "Xml";

		public string Syntax { get; }

		public object?[] Arguments { get; }

		public StringSyntaxAttribute(string syntax)
		{
			Syntax = syntax;
			Arguments = new object[0];
		}

		public StringSyntaxAttribute(string syntax, params object?[] arguments)
		{
			Syntax = syntax;
			Arguments = arguments;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class UnscopedRefAttribute : Attribute
	{
	}
}
namespace System.Runtime.Versioning
{
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiresPreviewFeaturesAttribute : Attribute
	{
		public string? Message { get; }

		public string? Url { get; set; }

		public RequiresPreviewFeaturesAttribute()
		{
		}

		public RequiresPreviewFeaturesAttribute(string? message)
		{
			Message = message;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CallerArgumentExpressionAttribute : Attribute
	{
		public string ParameterName { get; }

		public CallerArgumentExpressionAttribute(string parameterName)
		{
			ParameterName = parameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CollectionBuilderAttribute : Attribute
	{
		public Type BuilderType { get; }

		public string MethodName { get; }

		public CollectionBuilderAttribute(Type builderType, string methodName)
		{
			BuilderType = builderType;
			MethodName = methodName;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CompilerFeatureRequiredAttribute : Attribute
	{
		public const string RefStructs = "RefStructs";

		public const string RequiredMembers = "RequiredMembers";

		public string FeatureName { get; }

		public bool IsOptional { get; set; }

		public CompilerFeatureRequiredAttribute(string featureName)
		{
			FeatureName = featureName;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
	{
		public string[] Arguments { get; }

		public InterpolatedStringHandlerArgumentAttribute(string argument)
		{
			Arguments = new string[1] { argument };
		}

		public InterpolatedStringHandlerArgumentAttribute(params string[] arguments)
		{
			Arguments = arguments;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class InterpolatedStringHandlerAttribute : Attribute
	{
	}
	[EditorBrowsable(EditorBrowsableState.Never)]
	[ExcludeFromCodeCoverage]
	internal static class IsExternalInit
	{
	}
	[AttributeUsage(AttributeTargets.Method, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ModuleInitializerAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class OverloadResolutionPriorityAttribute : Attribute
	{
		public int Priority { get; }

		public OverloadResolutionPriorityAttribute(int priority)
		{
			Priority = priority;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ParamCollectionAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiredMemberAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[EditorBrowsable(EditorBrowsableState.Never)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiresLocationAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class SkipLocalsInitAttribute : Attribute
	{
	}
}