dont use il2cpp lists unless absolutely necessary!

This commit is contained in:
XtraCube committed 2026-10-02 11:52:15 -04:00
1 parent f52c5de4cd
commit 79dc3280e8
10 files changed
+33 -42

No files matched your search

@@ -1,5 +1,4 @@
using Il2CppSystem;
using MiraAPI.Example.Roles;
using MiraAPI.Example.Roles;
using MiraAPI.Modifiers.Types;
using MiraAPI.Translation;
using UnityEngine;
@@ -28,7 +27,7 @@ public class FreezeModifier : TimedModifier
if (Player.AmOwner || PlayerControl.LocalPlayer.Data.Role is FreezerRole)
{
Player.cosmetics.SetOutline(true, new Nullable<Color>(Palette.LightBlue));
Player.cosmetics.SetOutline(true, new Il2CppSystem.Nullable<Color>(Palette.LightBlue));
}
}
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Il2CppSystem.Collections.Generic;
using MiraAPI.Networking;
using MiraAPI.Translation;
using MiraAPI.Utilities;
@@ -43,7 +43,7 @@ public class ModdedPlayerOption : ModdedOption<int>
data.Title = StringName;
data.Type = global::OptionTypes.Player;
Values = new List<NetworkedPlayerInfo>();
Values = new();
AllowNone = allowNone;
Value = DefaultValue;
}
@@ -60,17 +60,16 @@ public class ModdedPlayerOption : ModdedOption<int>
playerOption.name =
$"{ParentMod!.OptionsTitleText}.PlayerOption.{TranslationController.Instance.GetString(StringName)}";
var filteredList = GetFilteredPlayers();
Values = filteredList.ToIl2CppList();
Values = GetFilteredPlayers();
playerOption.SetUpFromData(Data, 20);
playerOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
playerOption.Title = StringName;
playerOption.TitleText.text = Title.Translate();
playerOption.Values = Values;
playerOption.Values = Values.ToIl2CppList();
playerOption.Value = Value;
playerOption.playerIndex = filteredList.FindIndex(p => p.PlayerId == Value);
playerOption.playerIndex = Values.FindIndex(p => p.PlayerId == Value);
OptionBehaviour = playerOption;
ModdedOptionsManager.CreatedPlayerOptions.TryAdd(playerOption, this);
@@ -85,7 +84,7 @@ public class ModdedPlayerOption : ModdedOption<int>
/// Returns a player ran through the filter.
/// </summary>
/// <returns>A list of filtered players.</returns>
public System.Collections.Generic.List<NetworkedPlayerInfo> GetFilteredPlayers()
public List<NetworkedPlayerInfo> GetFilteredPlayers()
{
return [.. GameData.Instance.AllPlayers.ToArray().Where(x => PlayerFilter?.Invoke(x) ?? true)];
}
+2 -3
View File
@@ -1,6 +1,5 @@
using System.Collections;
using HarmonyLib;
using Il2CppSystem;
using MiraAPI.GameModes;
using MiraAPI.Translation;
using Reactor.Utilities;
@@ -16,7 +15,7 @@ internal static class HudPatches
[HarmonyPostfix, HarmonyPatch(nameof(HudManager.Update))]
public static void HudUpdatePatch(HudManager __instance)
{
if (GameManager.Instance != null && GameManager.Instance.GameHasStarted &&
if (GameManager.Instance && GameManager.Instance.GameHasStarted &&
CustomGameModeManager.ActiveMode != null)
{
CustomGameModeManager.ActiveMode.HudUpdate(__instance);
@@ -32,7 +31,7 @@ internal static class HudPatches
private static IEnumerator CoPostHudStart(HudManager instance)
{
yield return new WaitUntil((Func<bool>)(() => GameManager.Instance != null));
yield return new WaitUntil((Il2CppSystem.Func<bool>)(() => GameManager.Instance != null));
if (GameManager.Instance.IsHideAndSeek())
yield return null;
var infoPane = instance.gameObject.transform.FindChild("LobbyInfoPane");
@@ -1,10 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using MiraAPI.GameModes;
using MiraAPI.GameOptions;
using MiraAPI.Modifiers;
@@ -28,9 +28,9 @@ internal static class GameOptionsMenuPatch
private static readonly List<CategoryHeaderMasked> VanillaHeaders = new();
private static readonly List<OptionBehaviour> VanillaOptions = new();
private static readonly List<OptionBehaviour> MainOptions = new();
private static readonly System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<AbstractOptionGroup>> GameModeGroups = [];
private static readonly System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<OptionBehaviour>> GameModeOptions = [];
private static readonly System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<CategoryHeaderMasked>> GameModeHeaders = [];
private static readonly Dictionary<AbstractGameMode, List<AbstractOptionGroup>> GameModeGroups = [];
private static readonly Dictionary<AbstractGameMode, List<OptionBehaviour>> GameModeOptions = [];
private static readonly Dictionary<AbstractGameMode, List<CategoryHeaderMasked>> GameModeHeaders = [];
private static TextMeshPro _gamemodeDescription = null!;
private static SpriteRenderer _modIcon = null!;
@@ -38,7 +38,7 @@ internal static class GameOptionsMenuPatch
[HarmonyPatch(nameof(GameOptionsMenu.Initialize))]
public static bool InitPatch(GameOptionsMenu __instance)
{
__instance.Children ??= new List<OptionBehaviour>();
__instance.Children ??= new();
__instance.Children.Clear();
if (MenuState.Instance.CurrentModIdx == 0)
@@ -324,8 +324,8 @@ internal static class GameOptionsMenuPatch
.ToList();
GameModeGroups.Add(mode, [.. filteredGroups]);
var optionBehaviours = new System.Collections.Generic.List<OptionBehaviour>();
var categoryHeaders = new System.Collections.Generic.List<CategoryHeaderMasked>();
var optionBehaviours = new List<OptionBehaviour>();
var categoryHeaders = new List<CategoryHeaderMasked>();
var newNum = mode.ShowNormalGameSettings ? num : num - additionalVanillaScrollNum;
foreach (var group in filteredGroups)
{
@@ -406,7 +406,7 @@ internal static class GameOptionsMenuPatch
__instance.scrollBar.SetYBoundsMax(-num - 1.65f);
}
private static void CreateGroup(GameOptionsMenu menu, AbstractOptionGroup group, Transform container, ref float num, ref System.Collections.Generic.List<OptionBehaviour> optionBehaviours, ref System.Collections.Generic.List<CategoryHeaderMasked> categoryHeaders)
private static void CreateGroup(GameOptionsMenu menu, AbstractOptionGroup group, Transform container, ref float num, ref List<OptionBehaviour> optionBehaviours, ref List<CategoryHeaderMasked> categoryHeaders)
{
var categoryHeaderMasked = Object.Instantiate(
menu.categoryHeaderOrigin,
+3 -4
View File
@@ -1,5 +1,4 @@
using HarmonyLib;
using Il2CppSystem;
using MiraAPI.GameOptions;
using MiraAPI.Roles;
using MiraAPI.Translation;
@@ -165,7 +164,7 @@ public static class OptionsPatches
return true;
}
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>()).Translate();
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
return false;
}
@@ -314,8 +313,8 @@ public static class OptionsPatches
return true;
}
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title, Array.Empty<Object>()).Translate();
__instance.ValueText.text = TranslationController.Instance.GetString(__instance.Values[__instance.Value], Array.Empty<Object>());
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
__instance.ValueText.text = TranslationController.Instance.GetString(__instance.Values[__instance.Value]);
return false;
}
@@ -26,8 +26,8 @@ public static class PlayerOptionPatches
{
filteredPlayers.Sort((a, b) => a.PlayerId.CompareTo(b.PlayerId));
moddedPlrOpt.Values = filteredPlayers;
__instance.Values = filteredPlayers.ToIl2CppList();
moddedPlrOpt.Values = __instance.Values;
__instance.playerIndex = filteredPlayers.FindIndex(p => p.PlayerId == __instance.Value);
__instance.SetValueText();
}
+2 -3
View File
@@ -1,5 +1,4 @@
using HarmonyLib;
using Il2CppSystem;
using MiraAPI.Networking;
using MiraAPI.Roles;
using UnityEngine;
@@ -31,13 +30,13 @@ public static class KillButtonPatches
if (__instance.currentTarget && __instance.currentTarget != target)
{
__instance.currentTarget.cosmetics.SetOutline(false, new Nullable<Color>(Color.clear));
__instance.currentTarget.cosmetics.SetOutline(false, new Il2CppSystem.Nullable<Color>(Color.clear));
}
__instance.currentTarget = target;
if (__instance.currentTarget)
{
__instance.currentTarget.cosmetics.SetOutline(true, new Nullable<Color>(customRole.Configuration.KillButtonOutlineColor));
__instance.currentTarget.cosmetics.SetOutline(true, new Il2CppSystem.Nullable<Color>(customRole.Configuration.KillButtonOutlineColor));
__instance.SetEnabled();
return false;
}
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AmongUs.GameOptions;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using MiraAPI.Roles;
namespace MiraAPI.Patches.Roles;
@@ -14,7 +14,7 @@ public static class LogicRoleSelectionHnsPatch
[HarmonyPatch(nameof(LogicRoleSelectionHnS.AssignRolesForTeam))]
public static bool AssignRolesForTeam(
LogicRoleSelectionHnS __instance,
List<NetworkedPlayerInfo> players,
Il2CppSystem.Collections.Generic.List<NetworkedPlayerInfo> players,
IGameOptions opts,
RoleTeamTypes team,
int teamMax,
@@ -58,7 +58,7 @@ public static class LogicRoleSelectionHnsPatch
case RoleTeamTypes.Impostor:
Info($"MiraAPI.Patches.Roles.LogicRoleSelectionHnsPatch - AssignRolesForTeam: Before Guaranteed Assignment");
var newImpostors = new List<NetworkedPlayerInfo>();
var newImpostors = new Il2CppSystem.Collections.Generic.List<NetworkedPlayerInfo>();
// Specified Seeker
if (__instance.hnsManager.LogicOptionsHnS.HasImpostorPlayerID() &&
@@ -113,7 +113,7 @@ public static class LogicRoleSelectionHnsPatch
return false;
}
public static void AssignRolesFromList(List<NetworkedPlayerInfo> players, int teamMax, List<RoleTypes> roleList, ref int rolesAssigned)
public static void AssignRolesFromList(Il2CppSystem.Collections.Generic.List<NetworkedPlayerInfo> players, int teamMax, List<RoleTypes> roleList, ref int rolesAssigned)
{
while (roleList.Count > 0 && players.Count > 0 && rolesAssigned < teamMax)
{
@@ -128,7 +128,7 @@ public static class LogicRoleSelectionHnsPatch
}
private static void AddGuaranteedRoles(
System.Collections.Generic.IEnumerable<RoleBehaviour> guaranteedRoles,
IEnumerable<RoleBehaviour> guaranteedRoles,
IGameOptions opts,
List<RoleTypes> list)
{
@@ -146,7 +146,7 @@ public static class LogicRoleSelectionHnsPatch
}
}
private static void AddPotentialRoles(System.Collections.Generic.IEnumerable<RoleBehaviour> source, IGameOptions opts, List<RoleTypes> list)
private static void AddPotentialRoles(IEnumerable<RoleBehaviour> source, IGameOptions opts, List<RoleTypes> list)
{
var roleOptions = opts.RoleOptions;
var potentialRoles = source.Where(x => !x.IsDead).Select(role => new RoleManager.RoleAssignmentData(
+2 -3
View File
@@ -2,7 +2,6 @@
using System.Runtime.CompilerServices;
using HarmonyLib;
using Hazel;
using Il2CppSystem.Text;
namespace MiraAPI.Patches.Stubs;
@@ -45,9 +44,9 @@ public static class RoleBehaviourStubs
/// <param name="instance">The <see cref="RoleBehaviour"/> object.</param>
/// <param name="taskStringBuilder">The <see cref="StringBuilder"/> to append the task hint to.</param>
[HarmonyReversePatch]
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.AppendTaskHint), typeof(StringBuilder))]
[HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.AppendTaskHint), typeof(Il2CppSystem.Text.StringBuilder))]
[MethodImpl(MethodImplOptions.NoInlining)]
public static void AppendTaskHint(RoleBehaviour instance, StringBuilder taskStringBuilder)
public static void AppendTaskHint(RoleBehaviour instance, Il2CppSystem.Text.StringBuilder taskStringBuilder)
{
// nothing needed
}
+1 -4
View File
@@ -300,10 +300,7 @@ public static class VotingUtils
// If modified, these will visually change.
votes = @event.Votes;
MeetingHud.Instance.TitleText.text =
TranslationController.Instance.GetString(
StringNames.MeetingVotingResults,
Il2CppSystem.Array.Empty<Il2CppSystem.Object>());
MeetingHud.Instance.TitleText.text = TranslationController.Instance.GetString(StringNames.MeetingVotingResults);
var delays = new Dictionary<byte, int>();
var num = 0;