Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of KickUI v1.0.0
KickUI.dll
Decompiled 3 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using On.RoR2.UI; using RiskOfOptions; using RiskOfOptions.Components.Options; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using RoR2.Networking; using RoR2.UI; using TMPro; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Events; using UnityEngine.Networking; 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("Fantaz")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Adds a kick button next to each player's name in the scoreboard for the host")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("KickUI")] [assembly: AssemblyTitle("KickUI")] [assembly: AssemblyVersion("1.0.0.0")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace KickUI { [BepInPlugin("com.fantaz.KickUI", "KickUI", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class KickUIPlugin : BaseUnityPlugin { public enum ButtonTheme { None, Red, Orange, Yellow, Green, LightBlue, Blue, Purple, Cyan, Pink } public enum ButtonSize { Small, Default, Big } public static class ModConfig { public static ConfigEntry<bool> ConfirmKick; public static ConfigEntry<bool> BroadcastKick; public static ConfigEntry<ButtonTheme> Theme; public static ConfigEntry<ButtonSize> Size; public static ConfigEntry<float> OffsetX; public static ConfigEntry<float> OffsetY; public static void Init(ConfigFile config) { //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Expected O, but got Unknown //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Expected O, but got Unknown //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Expected O, but got Unknown //IL_0120: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Expected O, but got Unknown ConfirmKick = config.Bind<bool>("General", "Confirm Dialog", true, "If enabled, a confirmation dialog will appear before kicking a player.\n\nDefault: true"); BroadcastKick = config.Bind<bool>("General", "Kick Message", true, "If enabled, a message will be sent to chat when a player is kicked.\n\nDefault: true"); Theme = config.Bind<ButtonTheme>("UI", "Button Theme", ButtonTheme.None, "The color theme of the kick button. 'None' uses the native RoR2 style."); Size = config.Bind<ButtonSize>("UI", "Button Size", ButtonSize.Default, "The size of the kick button."); OffsetX = config.Bind<float>("UI", "Button Offset X", -110f, "The horizontal offset of the kick button relative to the name area.\n\nDefault: -110"); OffsetY = config.Bind<float>("UI", "Button Offset Y", 0f, "The vertical offset of the kick button relative to the name area.\n\nDefault: 0"); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ConfirmKick)); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(BroadcastKick)); ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)Theme)); ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)Size)); ModSettingsManager.AddOption((BaseOption)new StepSliderOption(OffsetX, new StepSliderConfig { min = -250f, max = -90f, increment = 1f })); ModSettingsManager.AddOption((BaseOption)new StepSliderOption(OffsetY, new StepSliderConfig { min = -50f, max = 50f, increment = 1f })); } } private static GameObject buttonPrefab; internal static ManualLogSource Log; public void Awake() { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0082: 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) Log = ((BaseUnityPlugin)this).Logger; try { ModSettingsManager.SetModDescription("Adds a kick button next to each player's name in the scoreboard for the host"); string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string path = Path.Combine(directoryName, "icon.png"); if (!File.Exists(path)) { path = Path.Combine(Path.GetDirectoryName(directoryName), "icon.png"); } if (File.Exists(path)) { Texture2D val = new Texture2D(2, 2); if (ImageConversion.LoadImage(val, File.ReadAllBytes(path))) { ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f))); } } ModConfig.Init(((BaseUnityPlugin)this).Config); ScoreboardStrip.SetMaster += new hook_SetMaster(ScoreboardStrip_SetMaster); buttonPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/UI/GenericMenuButton.prefab").WaitForCompletion(); } catch (Exception ex) { Log.LogError((object)("Failed to initialize KickUI: " + ex.Message)); } } private void ScoreboardStrip_SetMaster(orig_SetMaster orig, ScoreboardStrip self, CharacterMaster newMaster) { orig.Invoke(self, newMaster); TextMeshProUGUI nameLabel = self.nameLabel; Transform obj = ((nameLabel != null) ? ((TMP_Text)nameLabel).transform.parent : null); Transform val = ((obj != null) ? obj.Find("KickButton") : null); if (!NetworkServer.active || (Object)(object)newMaster == (Object)null) { if (Object.op_Implicit((Object)(object)val)) { ((Component)val).gameObject.SetActive(false); } return; } PlayerCharacterMasterController playerCharacterMasterController = newMaster.playerCharacterMasterController; NetworkUser val2 = ((playerCharacterMasterController != null) ? playerCharacterMasterController.networkUser : null); if ((Object)(object)val2 == (Object)null || ((NetworkBehaviour)val2).isLocalPlayer) { if (Object.op_Implicit((Object)(object)val)) { ((Component)val).gameObject.SetActive(false); } } else { CreateOrUpdateKickButton(self, newMaster); } } private void CreateOrUpdateKickButton(ScoreboardStrip strip, CharacterMaster master) { //IL_0093: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Expected O, but got Unknown //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0312: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_0369: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)buttonPrefab)) { return; } TextMeshProUGUI nameLabel = strip.nameLabel; Transform val = ((nameLabel != null) ? ((TMP_Text)nameLabel).transform.parent : null); Transform val2 = ((val != null) ? val.Find("KickButton") : null); GameObject val3; if ((Object)(object)val2 == (Object)null) { val3 = Object.Instantiate<GameObject>(buttonPrefab, ((Component)strip).transform); ((Object)val3).name = "KickButton"; RectTransform component = val3.GetComponent<RectTransform>(); if ((Object)(object)strip.nameLabel != (Object)null) { ((Transform)component).SetParent(val); ((Transform)component).localScale = Vector3.one; component.anchorMin = new Vector2(0f, 0.5f); component.anchorMax = new Vector2(0f, 0.5f); component.anchoredPosition = new Vector2(ModConfig.OffsetX.Value, ModConfig.OffsetY.Value); } LanguageTextMeshController component2 = val3.GetComponent<LanguageTextMeshController>(); if (Object.op_Implicit((Object)(object)component2)) { Object.Destroy((Object)(object)component2); } TextMeshProUGUI componentInChildren = val3.GetComponentInChildren<TextMeshProUGUI>(); if (Object.op_Implicit((Object)(object)componentInChildren)) { ((TMP_Text)componentInChildren).text = "Kick"; ((TMP_Text)componentInChildren).fontSize = 12f; ((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)514; } } else { val3 = ((Component)val2).gameObject; val3.SetActive(true); } RectTransform component3 = val3.GetComponent<RectTransform>(); if (Object.op_Implicit((Object)(object)component3)) { RectTransform val4 = component3; val4.sizeDelta = (Vector2)(ModConfig.Size.Value switch { ButtonSize.Small => new Vector2(45f, 35f), ButtonSize.Default => new Vector2(60f, 45f), ButtonSize.Big => new Vector2(75f, 55f), _ => new Vector2(60f, 45f), }); component3.anchoredPosition = new Vector2(ModConfig.OffsetX.Value, ModConfig.OffsetY.Value); } HGButton component4 = val3.GetComponent<HGButton>(); if (Object.op_Implicit((Object)(object)component4)) { if (ModConfig.Theme.Value != 0) { ColorBlock colors = ((Selectable)component4).colors; ((ColorBlock)(ref colors)).normalColor = (Color)(ModConfig.Theme.Value switch { ButtonTheme.Red => new Color(0.94f, 0.47f, 0.47f, 1f), ButtonTheme.Orange => new Color(0.9f, 0.6f, 0.4f, 1f), ButtonTheme.Yellow => new Color(0.8f, 0.7f, 0.4f, 1f), ButtonTheme.Green => new Color(0.5f, 0.7f, 0.5f, 1f), ButtonTheme.LightBlue => new Color(0.55f, 0.7f, 0.8f, 1f), ButtonTheme.Blue => new Color(0.45f, 0.55f, 0.75f, 1f), ButtonTheme.Purple => new Color(0.6f, 0.5f, 0.75f, 1f), ButtonTheme.Cyan => new Color(0.55f, 0.75f, 0.75f, 1f), ButtonTheme.Pink => new Color(0.8f, 0.6f, 0.7f, 1f), _ => ((ColorBlock)(ref colors)).normalColor, }); ((Selectable)component4).colors = colors; } ((UnityEventBase)((Button)component4).onClick).RemoveAllListeners(); ((UnityEvent)((Button)component4).onClick).AddListener((UnityAction)delegate { OnKickButtonClicked(master); }); } } private void OnKickButtonClicked(CharacterMaster master) { //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Expected O, but got Unknown CharacterMaster obj = master; object obj2; if (obj == null) { obj2 = null; } else { PlayerCharacterMasterController playerCharacterMasterController = obj.playerCharacterMasterController; obj2 = ((playerCharacterMasterController != null) ? playerCharacterMasterController.networkUser : null); } NetworkUser val = (NetworkUser)obj2; if ((Object)(object)val == (Object)null) { return; } if (!ModConfig.ConfirmKick.Value) { KickPlayer(master); return; } SimpleDialogBox dialog = SimpleDialogBox.Create((MPEventSystem)null); ((Component)dialog).gameObject.AddComponent<RooEscapeRouter>().escapePressed.AddListener((UnityAction)delegate { if (Object.op_Implicit((Object)(object)dialog) && Object.op_Implicit((Object)(object)dialog.rootObject)) { Object.Destroy((Object)(object)dialog.rootObject); } }); ((TMP_Text)dialog.headerLabel).text = "Confirm Kick"; ((TMP_Text)dialog.descriptionLabel).text = "Are you sure you want to kick " + val.userName + "?"; dialog.AddActionButton((UnityAction)delegate { KickPlayer(master); }, "Yes", true, Array.Empty<object>()); dialog.AddCancelButton("Cancel", Array.Empty<object>()); } private void KickPlayer(CharacterMaster master) { //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown try { object obj; if (master == null) { obj = null; } else { PlayerCharacterMasterController playerCharacterMasterController = master.playerCharacterMasterController; obj = ((playerCharacterMasterController != null) ? playerCharacterMasterController.networkUser : null); } NetworkUser networkUser = (NetworkUser)obj; if ((Object)(object)networkUser == (Object)null) { return; } if (NetworkUser.readOnlyLocalPlayersList.Contains(networkUser)) { Log.LogWarning((object)("Attempted to kick the host (" + networkUser.userName + "). Action aborted.")); return; } NetworkConnection val = ((NetworkBehaviour)networkUser).connectionToClient; if (val == null) { val = ((IEnumerable<NetworkConnection>)NetworkServer.connections).FirstOrDefault((Func<NetworkConnection, bool>)((NetworkConnection c) => c != null && ((NetworkBehaviour)networkUser).connectionToClient == c)); } if (val != null) { if (ModConfig.BroadcastKick.Value) { Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage { baseToken = "<color=#e57373>Kicking player:</color> <color=#ffffff><noparse>" + networkUser.userName + "</noparse></color>" }); } SimpleLocalizedKickReason val2 = new SimpleLocalizedKickReason("KICK_REASON_KICK", Array.Empty<string>()); NetworkManagerSystem.singleton.ServerKickClient(val, (BaseKickReason)(object)val2); } else { Log.LogError((object)("Could not find network connection for player: " + networkUser.userName)); } } catch (Exception ex) { Log.LogError((object)("Exception in KickPlayer: " + ex.Message + "\n" + ex.StackTrace)); } } } }