diff --git a/Items/OptionItems/BetterOptionPlayerItem.cs b/Items/OptionItems/BetterOptionPlayerItem.cs
index ba6947c..7e6a525 100644
--- a/Items/OptionItems/BetterOptionPlayerItem.cs
+++ b/Items/OptionItems/BetterOptionPlayerItem.cs
@@ -91,7 +91,7 @@ public class BetterOptionPlayerItem : BetterOptionItem
ThisOption.ValueText.text = "Random";
}
- if (CurrentIndex >= Main.AllPlayerControls.Length - 1)
+ if (CurrentIndex >= Main.AllPlayerControls.Count - 1)
{
ThisOption.PlusBtn.SetInteractable(false);
ThisOption.MinusBtn.SetInteractable(true);
@@ -112,7 +112,7 @@ public class BetterOptionPlayerItem : BetterOptionItem
public void Increase()
{
- if (CurrentIndex < Main.AllPlayerControls.Length)
+ if (CurrentIndex < Main.AllPlayerControls.Count)
{
CurrentIndex++;
AdjustButtonsActiveState();
@@ -135,7 +135,7 @@ public class BetterOptionPlayerItem : BetterOptionItem
var saveindex = TempPlayerOptionData[Id];
if (saveindex != -1 && Utils.PlayerFromPlayerId(saveindex) == null)
- saveindex = Main.AllPlayerControls.Length - 1;
+ saveindex = Main.AllPlayerControls.Count - 1;
CurrentIndex = saveindex;
}
diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs
index e12ff67..b52a1c9 100644
--- a/Patches/PlayerControlPatch.cs
+++ b/Patches/PlayerControlPatch.cs
@@ -14,6 +14,20 @@ namespace BetterAmongUs.Patches;
[HarmonyPatch(typeof(PlayerControl))]
class PlayerControlPatch
{
+ [HarmonyPatch(nameof(PlayerControl.Awake))]
+ [HarmonyPostfix]
+ public static void Awake_Postfix(PlayerControl __instance)
+ {
+ Main.AllPlayerControls.Add(__instance);
+ }
+
+ [HarmonyPatch(nameof(PlayerControl.OnDestroy))]
+ [HarmonyPostfix]
+ public static void OnDestroy_Postfix(PlayerControl __instance)
+ {
+ Main.AllPlayerControls.Remove(__instance);
+ }
+
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
[HarmonyPrefix]
public static void FixedUpdate_Prefix(PlayerControl __instance)
diff --git a/Patches/RoleManagerPatch.cs b/Patches/RoleManagerPatch.cs
index a71bf45..bc0f957 100644
--- a/Patches/RoleManagerPatch.cs
+++ b/Patches/RoleManagerPatch.cs
@@ -45,7 +45,7 @@ public class RoleManagerPatch
int NumImpostors = GameOptionsManager.Instance.CurrentGameOptions.NumImpostors;
- int NumPlayers = Main.AllPlayerControls.Length;
+ int NumPlayers = Main.AllPlayerControls.Count;
var impostorLimits = new Dictionary
{
@@ -270,8 +270,8 @@ public class RoleManagerPatch
int NumImpostors = BetterGameSettings.HideAndSeekImpNum.GetInt();
- if (NumImpostors > Main.AllPlayerControls.Length)
- NumImpostors = Main.AllPlayerControls.Length;
+ if (NumImpostors > Main.AllPlayerControls.Count)
+ NumImpostors = Main.AllPlayerControls.Count;
List Impostors = [];
List Crewmates = [];
diff --git a/main.cs b/main.cs
index 7fe9331..5e3cd9f 100644
--- a/main.cs
+++ b/main.cs
@@ -9,7 +9,6 @@ using BetterAmongUs.Modules;
using BetterAmongUs.Patches;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
-using Innersloth.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
@@ -110,8 +109,8 @@ public class Main : BasePlugin
"2024.6.18",
];
- public static PlayerControl[] AllPlayerControls => PlayerControl.AllPlayerControls.ToArray().Where(pc => pc != null).ToArray();
- public static PlayerControl[] AllAlivePlayerControls => AllPlayerControls.ToArray().Where(pc => pc.IsAlive()).ToArray();
+ public static List AllPlayerControls = [];
+ public static List AllAlivePlayerControls => AllPlayerControls.Where(pc => pc.IsAlive()).ToList();
public static DeadBody[] AllDeadBodys => UnityEngine.Object.FindObjectsOfType().ToArray();
public static Vent[] AllVents => UnityEngine.Object.FindObjectsOfType();
@@ -261,6 +260,6 @@ public class Main : BasePlugin
CommandPrefix = Config.Bind("Client Options", "CommandPrefix", "/");
}
- public static string GetDataPathToAmongUs() => FileIO.GetRootDataPath();
- public static string GetGamePathToAmongUs() => Environment.CurrentDirectory;
+ public static string GetDataPathToAmongUs() => Application.persistentDataPath;
+ public static string GetGamePathToAmongUs() => Path.GetDirectoryName(Application.dataPath) ?? Application.dataPath;
}