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 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 dictionary = new Dictionary(); foreach (KeyValuePair 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 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 dictionary = new Dictionary(); foreach (KeyValuePair 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 get_all_children_and_components(GameObject root, GameObject? parent = null, int root_path_count = 0) { Dictionary dictionary = new Dictionary(); if ((Object)(object)parent == (Object)null) { Dictionary dictionary2 = new Dictionary(); string source = (string)(dictionary2["path"] = TransformExtensions.GetFullPath(root.transform)); dictionary2["components"] = (from c in root.GetComponents() 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())); dictionary.Add(root, dictionary2); } else { for (int i = 0; i < parent.transform.childCount; i++) { GameObject gameObject = ((Component)parent.transform.GetChild(i)).gameObject; Dictionary dictionary3 = new Dictionary(); dictionary3["path from root"] = TransformExtensions.GetFullPath(gameObject.transform).Substring(root_path_count); dictionary3["components"] = (from c in gameObject.GetComponents() 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())); 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? 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