diff --git a/MiraAPI/Colors/PaletteManager.cs b/MiraAPI/Colors/PaletteManager.cs index 3d25b33..fe7e725 100644 --- a/MiraAPI/Colors/PaletteManager.cs +++ b/MiraAPI/Colors/PaletteManager.cs @@ -20,8 +20,7 @@ public static class PaletteManager { var colors = CustomColors.Select(x => x.MainColor).ToArray(); var shadowColors = CustomColors.Select(x => x.ShadowColor).ToArray(); - var stringNames = CustomColors.Select(x => - x.Name).ToArray(); + var stringNames = CustomColors.Select(x => x.Name).ToArray(); Palette.PlayerColors = Palette.PlayerColors.ToArray().AddRangeToArray(colors); Palette.ShadowColors = Palette.ShadowColors.ToArray().AddRangeToArray(shadowColors); diff --git a/MiraAPI/Events/Mira/MiraButtonCancelledEvent.cs b/MiraAPI/Events/Mira/MiraButtonCancelledEvent.cs index 03bb233..69236bf 100644 --- a/MiraAPI/Events/Mira/MiraButtonCancelledEvent.cs +++ b/MiraAPI/Events/Mira/MiraButtonCancelledEvent.cs @@ -3,11 +3,8 @@ namespace MiraAPI.Events.Mira; /// -/// Invoked when a click is cancelled. +/// Invoked when a click is cancelled. Do not use for vanilla s. /// -/// -/// Do not use for vanilla s. -/// /// The type. /// The whose click was cancelled. public sealed class MiraButtonCancelledEvent(T button) : MiraEvent where T : CustomActionButton @@ -19,11 +16,8 @@ public sealed class MiraButtonCancelledEvent(T button) : MiraEvent where T : } /// -/// Invoked when a click is cancelled. +/// Invoked when a click is cancelled. Do not use for vanilla s. /// -/// -/// Do not use for vanilla s. -/// /// The whose click was cancelled. public sealed class MiraButtonCancelledEvent(CustomActionButton button) : MiraEvent { diff --git a/MiraAPI/Events/Mira/MiraButtonClickEvent.cs b/MiraAPI/Events/Mira/MiraButtonClickEvent.cs index 6126483..7c764e4 100644 --- a/MiraAPI/Events/Mira/MiraButtonClickEvent.cs +++ b/MiraAPI/Events/Mira/MiraButtonClickEvent.cs @@ -3,11 +3,8 @@ namespace MiraAPI.Events.Mira; /// -/// Button click event for s only. +/// Button click event for s only. Do not use for vanilla s. /// -/// -/// Do not use for vanilla s. -/// /// The type. /// The that was clicked. /// The generic invoked before button-specific events. @@ -25,11 +22,8 @@ public class MiraButtonClickEvent(T button, MiraButtonClickEvent genericClick } /// -/// Button click event for s only. +/// Button click event for s only. Do not use for vanilla s. /// -/// -/// Do not use for vanilla s. -/// /// The that was clicked. public class MiraButtonClickEvent(CustomActionButton button) : MiraCancelableEvent { diff --git a/MiraAPI/Events/MiraEventManager.cs b/MiraAPI/Events/MiraEventManager.cs index 5aa3c8c..745bb10 100644 --- a/MiraAPI/Events/MiraEventManager.cs +++ b/MiraAPI/Events/MiraEventManager.cs @@ -20,6 +20,7 @@ public static class MiraEventManager public static bool InvokeEvent(this T eventInstance) where T : MiraEvent { EventWrappers.TryGetValue(typeof(T), out var handlers); + if (handlers == null || handlers.Count == 0) { return false; @@ -49,6 +50,7 @@ public static class MiraEventManager public static bool InvokeEvent(this MiraEvent eventInstance, Type type) { EventWrappers.TryGetValue(type, out var handlers); + if (handlers == null || handlers.Count == 0) { return false; @@ -146,6 +148,7 @@ public static class MiraEventManager { EventWrappers.Remove(eventHandle.EventType); } + return true; } } diff --git a/MiraAPI/Events/Vanilla/Meeting/ReportBodyEvent.cs b/MiraAPI/Events/Vanilla/Meeting/ReportBodyEvent.cs index 7847e78..139aa77 100644 --- a/MiraAPI/Events/Vanilla/Meeting/ReportBodyEvent.cs +++ b/MiraAPI/Events/Vanilla/Meeting/ReportBodyEvent.cs @@ -1,7 +1,7 @@ namespace MiraAPI.Events.Vanilla.Meeting; /// -/// The event that is invoked when a body is reported. +/// The event that is invoked when a body is reported.
/// This is invoked in . ///
/// The player who reported the body. diff --git a/MiraAPI/GameModes/AbstractGameMode.cs b/MiraAPI/GameModes/AbstractGameMode.cs index 758c54f..0ea8534 100644 --- a/MiraAPI/GameModes/AbstractGameMode.cs +++ b/MiraAPI/GameModes/AbstractGameMode.cs @@ -275,7 +275,7 @@ public abstract class AbstractGameMode : IOptionable /// The task panel to update. public virtual void UpdateTaskPanel(TaskPanelBehaviour instance) { - instance.background.transform.localScale = (instance.taskText.textBounds.size.x > 0f) + instance.background.transform.localScale = instance.taskText.textBounds.size.x > 0f ? new Vector3(instance.taskText.textBounds.size.x + 0.2f, instance.taskText.textBounds.size.y + 0.2f, 1f) : Vector3.zero; var vector = instance.background.sprite.bounds.extents; @@ -287,6 +287,7 @@ public abstract class AbstractGameMode : IOptionable vector2.y = -vector2.y; vector2.x += vector.x * 2f; instance.tab.transform.localPosition = vector2; + if (GameManager.Instance == null) { return; diff --git a/MiraAPI/GameModes/HideAndSeekMode.cs b/MiraAPI/GameModes/HideAndSeekMode.cs index 9c3ea71..492c3e7 100644 --- a/MiraAPI/GameModes/HideAndSeekMode.cs +++ b/MiraAPI/GameModes/HideAndSeekMode.cs @@ -91,7 +91,7 @@ public class HideAndSeekMode : AbstractGameMode public override void AssignRoles(out bool runOriginal, LogicRoleSelectionNormal instance) { runOriginal = false; - Il2CppSystem.Collections.Generic.List list = new(); + CppCollections.List list = new(); AmongUsClient.Instance.GetAllClients(list); List list2 = [.. list.ToArray() .Where(c => c.Character != null && c.Character.Data != null && !c.Character.Data.Disconnected && diff --git a/MiraAPI/GlobalUsings.cs b/MiraAPI/GlobalUsings.cs new file mode 100644 index 0000000..da49803 --- /dev/null +++ b/MiraAPI/GlobalUsings.cs @@ -0,0 +1,2 @@ +global using CppCollections = Il2CppSystem.Collections.Generic; +global using CppIEnumerator = Il2CppSystem.Collections.IEnumerator; diff --git a/MiraAPI/Hud/CustomPlayerMenu.cs b/MiraAPI/Hud/CustomPlayerMenu.cs index 435ce12..8841144 100644 --- a/MiraAPI/Hud/CustomPlayerMenu.cs +++ b/MiraAPI/Hud/CustomPlayerMenu.cs @@ -51,12 +51,10 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr) customMenu.xOffset = newMenu.XOffset; customMenu.yOffset = newMenu.YOffset; customMenu.backButton = newMenu.BackButton; + var back = customMenu.backButton.GetComponent(); back.OnClick.RemoveAllListeners(); - back.OnClick.AddListener((UnityAction)(() => - { - Instance.Close(); - })); + back.OnClick.AddListener((UnityAction)Instance.Close); customMenu.CloseSound = newMenu.CloseSound; customMenu.logger = newMenu.logger; @@ -99,7 +97,7 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr) DebugAnalytics.Instance.Analytics.MinigameOpened(PlayerControl.LocalPlayer.Data, TaskType); var list = PlayerControl.AllPlayerControls.ToArray().Where(playerMatch).ToList(); potentialVictims = []; - var list2 = new Il2CppSystem.Collections.Generic.List(); + var list2 = new CppCollections.List(); for (var i = 0; i < list.Count; i++) { @@ -109,7 +107,7 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr) var flag = PlayerControl.LocalPlayer.Data.Role.NameColor == player.Data.Role.NameColor; var shapeshifterPanel = Instantiate(panelPrefab, transform); shapeshifterPanel.transform.localPosition = new Vector3(xStart + num * xOffset, yStart + num2 * yOffset, -1f); - shapeshifterPanel.SetPlayer(i, player.Data, (Il2CppSystem.Action)(() => { onClick(player); })); + shapeshifterPanel.SetPlayer(i, player.Data, (Il2CppSystem.Action)(() => onClick(player))); shapeshifterPanel.NameText.color = flag ? player.Data.Role.NameColor : Color.white; potentialVictims.Add(shapeshifterPanel); list2.Add(shapeshifterPanel.Button); diff --git a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs index 27beb06..0e3ab07 100644 --- a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs +++ b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs @@ -122,7 +122,7 @@ public static class TaskAdderPatches [HarmonyPrefix] [HarmonyPatch(nameof(TaskAdderGame.PopulateRoot))] - private static bool PopulateRootPrefix(TaskAdderGame __instance, TaskAdderGame.FolderType folderType, TaskFolder rootFolder, Il2CppSystem.Collections.Generic.Dictionary folders, Il2CppReferenceArray taskList) + private static bool PopulateRootPrefix(TaskAdderGame __instance, TaskAdderGame.FolderType folderType, TaskFolder rootFolder, CppCollections.Dictionary folders, Il2CppReferenceArray taskList) { if (folderType != TaskAdderGame.FolderType.Tasks) { @@ -143,8 +143,8 @@ public static class TaskAdderPatches impFolder.FolderName = ImpostorName; rootFolder.SubFolders.Insert(0, crewFolder); rootFolder.SubFolders.Insert(0, impFolder); - Il2CppSystem.Collections.Generic.List impRoles = new(); - Il2CppSystem.Collections.Generic.List crewRoles = new(); + CppCollections.List impRoles = new(); + CppCollections.List crewRoles = new(); foreach (var role in RoleManager.Instance.AllRoles) { if (role.Role != RoleTypes.ImpostorGhost && role.Role != RoleTypes.CrewmateGhost && !role.IsCustomRole()) diff --git a/MiraAPI/Patches/GameModes/BodyTypePatch.cs b/MiraAPI/Patches/GameModes/BodyTypePatch.cs index afd4cbc..71a0b53 100644 --- a/MiraAPI/Patches/GameModes/BodyTypePatch.cs +++ b/MiraAPI/Patches/GameModes/BodyTypePatch.cs @@ -7,7 +7,7 @@ namespace MiraAPI.Patches.GameModes; [HarmonyPatch(typeof(IntroCutscene), nameof(IntroCutscene.CoBegin))] internal static class BodyTypePatch { - public static bool Prefix(IntroCutscene __instance, ref Il2CppSystem.Collections.IEnumerator __result) + public static bool Prefix(IntroCutscene __instance, ref CppIEnumerator __result) { if (CustomGameModeManager.ActiveMode?.ShowGameModeIntroCutscene != true) return true; __result = CustomGameModeManager.ActiveMode.IntroCutscene(__instance).WrapToIl2Cpp(); diff --git a/MiraAPI/Patches/GameModes/IntroCutscenePatch.cs b/MiraAPI/Patches/GameModes/IntroCutscenePatch.cs index 641c642..5b51373 100644 --- a/MiraAPI/Patches/GameModes/IntroCutscenePatch.cs +++ b/MiraAPI/Patches/GameModes/IntroCutscenePatch.cs @@ -7,7 +7,7 @@ namespace MiraAPI.Patches.GameModes; [HarmonyPatch(typeof(IntroCutscene), nameof(IntroCutscene.CoBegin))] internal static class IntroCutscenePatch { - public static bool Prefix(IntroCutscene __instance, ref Il2CppSystem.Collections.IEnumerator __result) + public static bool Prefix(IntroCutscene __instance, ref CppIEnumerator __result) { if (CustomGameModeManager.ActiveMode?.ShowGameModeIntroCutscene != true) return true; __result = CustomGameModeManager.ActiveMode.IntroCutscene(__instance).WrapToIl2Cpp(); diff --git a/MiraAPI/Patches/IntroCutscenePatches.cs b/MiraAPI/Patches/IntroCutscenePatches.cs index b70964d..d236528 100644 --- a/MiraAPI/Patches/IntroCutscenePatches.cs +++ b/MiraAPI/Patches/IntroCutscenePatches.cs @@ -67,7 +67,7 @@ public static class IntroCutscenePatches [HarmonyPrefix] [HarmonyPatch(nameof(IntroCutscene.BeginImpostor))] [HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))] - public static bool BeginPrefix(IntroCutscene __instance, [HarmonyArgument(0)] ref Il2CppSystem.Collections.Generic.List yourTeam) + public static bool BeginPrefix(IntroCutscene __instance, [HarmonyArgument(0)] ref CppCollections.List yourTeam) { return PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole || customRole.SetupIntroTeam(__instance, ref yourTeam); } diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 3ea9723..645bf57 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -98,7 +98,7 @@ public static class RoleSettingMenuPatches foreach (var r in roleOptionSettings) { roleMenu.roleChances.Add(r); - roleMenu.QuotaTabSelectables.AddRange(new Il2CppSystem.Collections.Generic.IEnumerable(r.ControllerSelectable.Pointer)); + roleMenu.QuotaTabSelectables.AddRange(new CppCollections.IEnumerable(r.ControllerSelectable.Pointer)); } Info($"Already created role options for {MenuState.Instance.CurrentModIdx}"); @@ -387,7 +387,7 @@ public static class RoleSettingMenuPatches if (controllerSelected) { __instance.ControllerSelectable.AddRange( - new Il2CppSystem.Collections.Generic.IEnumerable( + new CppCollections.IEnumerable( __instance.QuotaTabSelectables.Pointer)); } diff --git a/MiraAPI/Patches/Roles/SelectRolesPatch.cs b/MiraAPI/Patches/Roles/SelectRolesPatch.cs index 692e200..f867901 100644 --- a/MiraAPI/Patches/Roles/SelectRolesPatch.cs +++ b/MiraAPI/Patches/Roles/SelectRolesPatch.cs @@ -41,7 +41,7 @@ public static class SelectRolesPatch { return true; } - Il2CppSystem.Collections.Generic.List list = new(); + CppCollections.List list = new(); AmongUsClient.Instance.GetAllClients(list); List list2 = [.. list.ToArray() .Where(c => c.Character != null && c.Character.Data != null && !c.Character.Data.Disconnected && diff --git a/MiraAPI/Patches/Voting/MeetingHudPatches.cs b/MiraAPI/Patches/Voting/MeetingHudPatches.cs index 6cbcd56..a84857c 100644 --- a/MiraAPI/Patches/Voting/MeetingHudPatches.cs +++ b/MiraAPI/Patches/Voting/MeetingHudPatches.cs @@ -16,7 +16,7 @@ using UnityEngine; namespace MiraAPI.Patches.Voting; [HarmonyPatch(typeof(MeetingHud))] -[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony Convention.")] +[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony convention.")] internal static class MeetingHudPatches { [HarmonyPrefix] @@ -55,7 +55,7 @@ internal static class MeetingHudPatches var startPos = __instance.AnimateButtonsFromLeft ? 0.2f : 1.95f; - Il2CppSystem.Collections.Generic.List selectableElements = new(); + CppCollections.List selectableElements = new(); foreach (var btn in __instance.Buttons.GetComponentsInChildren()) { selectableElements.Add(btn); diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs index 4a015ad..060b1a5 100644 --- a/MiraAPI/Roles/CustomRoleManager.cs +++ b/MiraAPI/Roles/CustomRoleManager.cs @@ -53,7 +53,7 @@ public static class CustomRoleManager internal static readonly Dictionary CustomRoles = []; internal static readonly Dictionary RoleIds = []; - private static Il2CppSystem.Collections.Generic.List? _emptySettings; + private static CppCollections.List? _emptySettings; private static Il2CppReferenceArray? _emptyKillAnimations; private static ushort _roleId = 100; diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index adf24d2..e7e34c6 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -249,11 +249,11 @@ public interface ICustomRole : IOptionable /// The intro cutscene instance. /// The reference to the list of player in the team. /// to use the original team intro code, to skip. - bool SetupIntroTeam(IntroCutscene instance, ref Il2CppSystem.Collections.Generic.List yourTeam) + bool SetupIntroTeam(IntroCutscene instance, ref CppCollections.List yourTeam) { if (Team == ModdedRoleTeams.Custom) { - var team = new Il2CppSystem.Collections.Generic.List(); + var team = new CppCollections.List(); team.Add(PlayerControl.LocalPlayer); diff --git a/MiraAPI/Translation/MiraLocaleManager.cs b/MiraAPI/Translation/MiraLocaleManager.cs index ad48158..73de3af 100644 --- a/MiraAPI/Translation/MiraLocaleManager.cs +++ b/MiraAPI/Translation/MiraLocaleManager.cs @@ -352,6 +352,12 @@ public static class MiraLocaleManager } } + /// + /// Parses the provided xml file into translation keys and values and registers them to the locale manager. + /// + /// The xml file being parsed. + /// The language that the xml file corresponds to. + /// Flag that indicates if the xml being parsed is internal or not. public static void ParseXmlFile(string xmlContent, MiraLanguage language, bool loadingInternal) { var dict = Locale[language]; diff --git a/MiraAPI/Utilities/Assets/AddressablesLoader.cs b/MiraAPI/Utilities/Assets/AddressablesLoader.cs index c66c8c3..aefc5cb 100644 --- a/MiraAPI/Utilities/Assets/AddressablesLoader.cs +++ b/MiraAPI/Utilities/Assets/AddressablesLoader.cs @@ -216,7 +216,7 @@ public static class AddressablesLoader { var allLocations = Addressables.LoadResourceLocationsAsync(tag).WaitForCompletion(); var assets = Addressables.LoadAssetsAsync(allLocations, null, false).WaitForCompletion(); - var array = new Il2CppSystem.Collections.Generic.List(assets.Pointer); + var array = new CppCollections.List(assets.Pointer); behaviours.AddRange(array.ToArray()); } catch @@ -237,7 +237,7 @@ public static class AddressablesLoader { var allLocations = Addressables.LoadResourceLocationsAsync(tag.Tag).WaitForCompletion(); var assets = Addressables.LoadAssetsAsync(allLocations, null, false).WaitForCompletion(); - var array = new Il2CppSystem.Collections.Generic.List(assets.Pointer); + var array = new CppCollections.List(assets.Pointer); behaviours.AddRange(array.ToArray().Select(x => (tag.Category, x))); } catch diff --git a/MiraAPI/Utilities/Assets/LoadableAddressableAssets.cs b/MiraAPI/Utilities/Assets/LoadableAddressableAssets.cs index c70100a..cd4dccb 100644 --- a/MiraAPI/Utilities/Assets/LoadableAddressableAssets.cs +++ b/MiraAPI/Utilities/Assets/LoadableAddressableAssets.cs @@ -53,7 +53,7 @@ public class LoadableAddressableAssets(string key) where T : UnityEngine.Obje throw new InvalidOperationException($"INVALID ASSET/s: {key}"); } - var assetsList = new Il2CppSystem.Collections.Generic.List(assetsIList.Pointer); + var assetsList = new CppCollections.List(assetsIList.Pointer); LoadedAssets = assetsList.ToArray().ToList(); _gcAction?.Invoke(this); diff --git a/MiraAPI/Utilities/Assets/TmpSpriteUtils.cs b/MiraAPI/Utilities/Assets/TmpSpriteUtils.cs index b6111fa..3cc8ffc 100644 --- a/MiraAPI/Utilities/Assets/TmpSpriteUtils.cs +++ b/MiraAPI/Utilities/Assets/TmpSpriteUtils.cs @@ -78,7 +78,7 @@ public static class TmpSpriteUtils material.SetFloat(ShaderUtilities.ShaderTag_CullMode, 0); spriteAsset.material = material; - spriteAsset.spriteInfoList = new Il2CppSystem.Collections.Generic.List(); + spriteAsset.spriteInfoList = new CppCollections.List(); AddSpriteToAsset(spriteAsset, rect, assetName, scale); diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 0ae9891..242c0e8 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -185,15 +185,15 @@ public static class Extensions } /// - /// Used to convert a to . + /// Used to convert a to . /// /// The . /// The type in the list. /// The converted list. - public static Il2CppSystem.Collections.Generic.List ToIl2CppList(this List systemList) + public static CppCollections.List ToIl2CppList(this List systemList) { // ReSharper disable once InconsistentNaming (Justification: Acronym.) - var il2cppList = new Il2CppSystem.Collections.Generic.List(); + var il2cppList = new CppCollections.List(); foreach (var item in systemList) { diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index db61953..d8817e4 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -277,7 +277,7 @@ public static class Helpers /// A of s. public static List GetNearestDeadBodies(Vector2 source, float radius, ContactFilter2D filter) { - var results = new Il2CppSystem.Collections.Generic.List(); + var results = new CppCollections.List(); Physics2D.OverlapCircle(source, radius, filter, results); return [.. results.ToArray() .Where(collider2D => collider2D.CompareTag("DeadBody")) @@ -296,7 +296,7 @@ public static class Helpers public static List GetNearestObjectsOfType(Vector2 source, float radius, ContactFilter2D filter, string? colliderTag = null) where T : Component { - var results = new Il2CppSystem.Collections.Generic.List(); + var results = new CppCollections.List(); Physics2D.OverlapCircle(source, radius, filter, results); return [.. results.ToArray() .Where(collider2D => colliderTag == null || collider2D.CompareTag(colliderTag))