From c4cbf0b18d5ba61f2a56bbfa603250ea8667ff2e Mon Sep 17 00:00:00 2001 From: xChipseq Date: Wed, 17 Sep 2025 19:19:47 +0200 Subject: [PATCH] use the old system instead of role children --- .../SettingTypes/LocalSettingBase.cs | 2 +- MiraAPI/Patches/Freeplay/TaskAdderPatches.cs | 91 ++++++++++++++----- 2 files changed, 70 insertions(+), 23 deletions(-) diff --git a/MiraAPI/LocalSettings/SettingTypes/LocalSettingBase.cs b/MiraAPI/LocalSettings/SettingTypes/LocalSettingBase.cs index d144ce42..629cd451 100644 --- a/MiraAPI/LocalSettings/SettingTypes/LocalSettingBase.cs +++ b/MiraAPI/LocalSettings/SettingTypes/LocalSettingBase.cs @@ -53,7 +53,7 @@ public abstract class LocalSettingBase : ILocalSetting } /// - /// Gets the value of the config entry, casted to the setting type. + /// Gets the value of the config entry, cast to the setting type. /// /// The value. public virtual T GetValue() diff --git a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs index 6ae86cf8..9e89db88 100644 --- a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs +++ b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs @@ -3,16 +3,15 @@ using System.Globalization; using System.Linq; using System.Text; using AmongUs.GameOptions; -using BepInEx.Unity.IL2CPP.Utils.Collections; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes.Arrays; -using Il2CppSystem; using MiraAPI.LocalSettings; using MiraAPI.Modifiers; using MiraAPI.Modifiers.Types; using MiraAPI.PluginLoading; using MiraAPI.Roles; using MiraAPI.Utilities.Assets; +using Reactor.Utilities; using Reactor.Utilities.Extensions; using UnityEngine; using UnityEngine.Events; @@ -99,10 +98,9 @@ internal static class TaskAdderPatches if (!pluginFolders.TryGetValue(folderName, out var pluginFolder)) { pluginFolder = __instance.CreateFolder(plugin.PluginInfo.Metadata.Name, teamFolder); + pluginFolder.name = $"Roles:{folderName}:{plugin.PluginId}"; pluginFolders.Add(folderName, teamFolder); } - - pluginFolder.RoleChildren.Add(role); } if (plugin.InternalModifiers.Exists(x => x.ShowInFreeplay)) @@ -348,7 +346,7 @@ internal static class TaskAdderPatches var roleChildren = taskFolder.RoleChildren .ToArray() - .Where(x => !(taskFolder.IsChildOf(__instance.Root) && x is ICustomRole)) + .Where(x => x is not ICustomRole) .ToArray(); foreach (var role in roleChildren) { @@ -363,21 +361,7 @@ internal static class TaskAdderPatches ? MiraAssets.ImpostorFile.LoadAsset() : MiraAssets.CrewmateFile.LoadAsset(); } - if (role is ICustomRole custom) - { - if (prettyEnabled && custom.Team == ModdedRoleTeams.Custom) roleAddButton.FileImage.sprite = MiraAssets.CustomTeamFile.LoadAsset(); - var customColor = custom.IntroConfiguration?.IntroTeamColor ?? Color.gray; - if (custom.Team is ModdedRoleTeams.Crewmate) - { - customColor = Palette.CrewmateBlue; - } - else if (custom.Team is ModdedRoleTeams.Impostor) - { - customColor = Palette.ImpostorRed; - } - roleAddButton.FileImage.color = customColor; - roleAddButton.RolloverHandler.OutColor = customColor; - } + __instance.AddFileAsChildCustom(roleAddButton, ref num, ref num2, ref num3); if (roleAddButton != null && roleAddButton.Button != null) { @@ -385,9 +369,73 @@ internal static class TaskAdderPatches } } + var split = taskFolder + .name + .Replace("(Clone)", string.Empty) + .Split(':'); + if (split is ["Roles", _, _] && folders.Any(x => taskFolder.IsChildOf(x.Value))) + { + var plugin = MiraPluginManager.GetPluginByGuid(split[2]); + if (plugin != null) + { + foreach (var role in plugin.InternalRoles) + { + var roleBehaviour = role.Value; + if (roleBehaviour.Role == RoleTypes.ImpostorGhost || roleBehaviour.Role == RoleTypes.CrewmateGhost || + roleBehaviour is ICustomRole { Configuration.ShowInFreeplay: false }) + { + continue; + } + + var teamFolder = roleBehaviour.IsImpostor ? "Impostor" : "Crewmate"; + if (roleBehaviour is ICustomRole cs) + { + teamFolder = cs.Configuration.FreeplayFolder; + } + if (split[1] != teamFolder) + { + continue; + } + + var roleAddButton = Object.Instantiate(__instance.RoleButton); + roleAddButton.MyTask = null; + roleAddButton.SafePositionWorld = __instance.SafePositionWorld; + roleAddButton.Text.text = prettyEnabled ? roleBehaviour.NiceName : "Be_" + roleBehaviour.NiceName + ".exe"; + roleAddButton.Text.fontSizeMin = 1; + roleAddButton.Text.EnableMasking(); + roleAddButton.role = roleBehaviour; + if (prettyEnabled) + { + roleAddButton.Text.fontSizeMin = 1; + roleAddButton.FileImage.sprite = roleBehaviour.IsImpostor + ? MiraAssets.ImpostorFile.LoadAsset() + : MiraAssets.CrewmateFile.LoadAsset(); + } + if (roleBehaviour is ICustomRole custom) + { + if (prettyEnabled && custom.Team == ModdedRoleTeams.Custom) roleAddButton.FileImage.sprite = MiraAssets.CustomTeamFile.LoadAsset(); + var customColor = custom.IntroConfiguration?.IntroTeamColor ?? Color.gray; + if (custom.Team is ModdedRoleTeams.Crewmate) + { + customColor = Palette.CrewmateBlue; + } + else if (custom.Team is ModdedRoleTeams.Impostor) + { + customColor = Palette.ImpostorRed; + } + roleAddButton.FileImage.color = customColor; + roleAddButton.RolloverHandler.OutColor = customColor; + } + + __instance.AddFileAsChildCustom(roleAddButton, ref num, ref num2, ref num3); + ControllerManager.Instance.AddSelectableUiElement(roleAddButton.Button); + } + } + } + if (folders.TryGetValue("Modifiers", out var modifiersFolder) && taskFolder.IsChildOf(modifiersFolder)) { - var plugin = MiraPluginManager.GetPluginByGuid(taskFolder.gameObject.name.Replace("(Clone)", string.Empty)); + var plugin = MiraPluginManager.GetPluginByGuid(taskFolder.name.Replace("(Clone)", string.Empty)); if (plugin != null) { foreach (var modifier in plugin.InternalModifiers) @@ -435,7 +483,6 @@ internal static class TaskAdderPatches })); __instance.AddFileAsChildCustom(taskAddButton, ref num, ref num2, ref num3); - ControllerManager.Instance.AddSelectableUiElement(taskAddButton.Button); } }