improved improved android support (but actually keeping all features instead of deleting them from pc also)

This commit is contained in:
Gurge44 committed 2025-10-21 09:35:29 +02:00
1 parent 7a1f3aae57
commit 1c0f8f93d9
31 files changed
+157 -137

No files matched your search

+1 -1
View File
@@ -51,7 +51,7 @@
<Target Name="Roles" AfterTargets="Build">
<Copy SourceFiles="CustomRoles.cs" DestinationFolder="CTA/CustomTeamAssigner/"/>
</Target>
<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != '' And '$(Configuration)' != 'Android'">
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="$(AmongUs)/BepInEx/plugins/"/>
</Target>
</Project>
+2
View File
@@ -861,7 +861,9 @@ public class Main : BasePlugin
{
CustomLogger.ClearLog();
#if !ANDROID
StartCoroutine(ModNewsFetcher.FetchNews());
#endif
try { DevManager.StartFetchingTags(); }
catch (Exception e) { Utils.ThrowException(e); }
+1 -1
View File
@@ -39,7 +39,7 @@ public static class AutoHaunt
{
while (Main.AutoHaunt.Value)
{
if (GameStates.IsInTask && !ExileController.Instance && !AntiBlackout.SkipTasks && !PlayerControl.LocalPlayer.IsAlive() && PlayerControl.LocalPlayer.Data.RoleType is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost && !ExtendedPlayerControl.TempExiled.Contains(PlayerControl.LocalPlayer.PlayerId))
if (HudManager.InstanceExists && GameStates.IsInTask && !ExileController.Instance && !AntiBlackout.SkipTasks && !PlayerControl.LocalPlayer.IsAlive() && PlayerControl.LocalPlayer.Data.RoleType is RoleTypes.CrewmateGhost or RoleTypes.ImpostorGhost && !ExtendedPlayerControl.TempExiled.Contains(PlayerControl.LocalPlayer.PlayerId))
{
if (HauntMenuMinigameStartPatch.Instance != null)
{
+1 -1
View File
@@ -17,7 +17,7 @@ public static class ChatBubbleShower
{
try
{
if (Queue.Count == 0 || ExileController.Instance) return;
if (Queue.Count == 0 || ExileController.Instance || !HudManager.InstanceExists) return;
long now = Utils.TimeStamp;
int wait = GameStates.IsInTask ? 8 : 4;
+8 -1
View File
@@ -147,7 +147,11 @@ internal static class Logger
public class CustomLogger
{
private static readonly string LOGFilePath = $"{Main.DataPath}/BepInEx/log.html";
#if ANDROID
public static readonly string LOGFilePath = $"{Main.DataPath}/EHR/log.html";
#else
public static readonly string LOGFilePath = $"{Main.DataPath}/BepInEx/log.html";
#endif
private const string HtmlHeader =
"""
@@ -188,6 +192,9 @@ public class CustomLogger
private CustomLogger()
{
#if ANDROID
Directory.CreateDirectory(Path.GetDirectoryName(LOGFilePath) ?? throw new InvalidOperationException());
#endif
if (!File.Exists(LOGFilePath)) File.WriteAllText(LOGFilePath, HtmlHeader);
else if (Options.IsLoaded && new FileInfo(LOGFilePath).Length > 4 * 1024 * 1024) // 4 MB
{
+12 -1
View File
@@ -1,8 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using AmongUs.GameOptions;
using AmongUs.QuickChat;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Hazel;
using InnerNet;
@@ -1222,11 +1224,19 @@ internal enum GameDataTag : byte
XboxDeclareXuid = 207
}
#if !ANDROID
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.HandleGameDataInner))]
internal class GameDataHandlerPatch
{
public static bool Prefix(InnerNetClient __instance, MessageReader reader, int msgNum)
private static IEnumerator EmptyCoroutine()
{
yield break;
}
public static bool Prefix(InnerNetClient __instance, MessageReader reader, int msgNum, ref Il2CppSystem.Collections.IEnumerator __result)
{
__result = EmptyCoroutine().WrapToIl2Cpp(); // fix errors if we return false
var tag = (GameDataTag)reader.Tag;
switch (tag)
@@ -1365,6 +1375,7 @@ internal static class StartGameHostPatchEAC
if (ShipStatus.Instance != null) IsStartingAsHost = false;
}
}
#endif
//[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.FixedUpdate))]
internal static class CheckInvalidMovementPatch
+7
View File
@@ -172,6 +172,13 @@ public class ErrorText : MonoBehaviour
try
{
if (!HudManager.InstanceExists)
{
_camera = Camera.main;
Logger.Error("Hudmanager instance not found", "ErrorText");
return;
}
_camera1 = HudManager.Instance.PlayerCam.GetComponent<Camera>();
_camera = Camera.main;
}
+2 -1
View File
@@ -2034,6 +2034,7 @@ internal static class ExtendedPlayerControl
public static void NoCheckStartMeeting(this PlayerControl reporter, NetworkedPlayerInfo target, bool force = false)
{
if (!HudManager.InstanceExists) return;
if (Options.DisableMeeting.GetBool() && !force) return;
ReportDeadBodyPatch.AfterReportTasks(reporter, target);
@@ -2281,7 +2282,7 @@ internal static class ExtendedPlayerControl
if (Main.UserData.TryGetValue(pc.FriendCode, out Options.UserData userData) && !string.IsNullOrWhiteSpace(userData.Tag) && userData.Tag.Length > 0) return true;
ClientData client = pc.GetClient();
return client != null && FastDestroyableSingleton<FriendsListManager>.Instance.IsPlayerFriend(client.ProductUserId);
return client != null && FriendsListManager.InstanceExists && FastDestroyableSingleton<FriendsListManager>.Instance.IsPlayerFriend(client.ProductUserId);
}
public static bool IsBeginner(this PlayerControl pc)
+8
View File
@@ -66,9 +66,13 @@ public static unsafe class FastDestroyableSingleton<T> where T : MonoBehaviour
{
get
{
#if ANDROID
return DestroyableSingleton<T>.Instance;
#else
IntPtr objectPointer;
IL2CPP.il2cpp_field_static_get_value(FieldPtr, &objectPointer);
return objectPointer == IntPtr.Zero ? DestroyableSingleton<T>.Instance : CreateObject(objectPointer);
#endif
}
}
}
@@ -79,7 +83,11 @@ public static class Il2CppCastHelper
public static T CastFast<T>(this Il2CppObjectBase obj) where T : Il2CppObjectBase
{
if (obj is T casted) return casted;
#if ANDROID
return obj.Cast<T>();
#else
return obj.Pointer.CastFast<T>();
#endif
}
private static T CastFast<T>(this IntPtr ptr) where T : Il2CppObjectBase
+11 -8
View File
@@ -61,13 +61,16 @@ public static class FixedUpdateCaller
GameStartManagerPatch.GameStartManagerUpdatePatch.Postfix_ManualCall(gameStartManager);
#endif
HudManager hudManager = FastDestroyableSingleton<HudManager>.Instance;
if (hudManager)
if (HudManager.InstanceExists)
{
HudManagerPatch.Postfix(hudManager);
Zoom.Postfix();
HudSpritePatch.Postfix(hudManager);
HudManager hudManager = FastDestroyableSingleton<HudManager>.Instance;
if (hudManager)
{
HudManagerPatch.Postfix(hudManager);
Zoom.Postfix();
HudSpritePatch.Postfix(hudManager);
}
}
try
@@ -84,7 +87,7 @@ public static class FixedUpdateCaller
try
{
if (GameStates.IsInTask && !ExileController.Instance && !AntiBlackout.SkipTasks && PlayerControl.LocalPlayer.CanUseKillButton())
if (HudManager.InstanceExists && GameStates.IsInTask && !ExileController.Instance && !AntiBlackout.SkipTasks && PlayerControl.LocalPlayer.CanUseKillButton())
{
Predicate<PlayerControl> predicate = AmongUsClient.Instance.AmHost
? Options.CurrentGameMode switch
@@ -99,7 +102,7 @@ public static class FixedUpdateCaller
List<PlayerControl> players = PlayerControl.LocalPlayer.GetPlayersInAbilityRangeSorted(predicate);
PlayerControl closest = players.Count == 0 ? null : players[0];
KillButton killButton = hudManager.KillButton;
KillButton killButton = FastDestroyableSingleton<HudManager>.Instance.KillButton;
if (killButton.currentTarget && killButton.currentTarget != closest)
killButton.currentTarget.ToggleHighlight(false, RoleTeamTypes.Impostor);
+1
View File
@@ -611,6 +611,7 @@ public static class GuessManager
private static void ProcessGuess(PlayerControl pc, MeetingHud meetingHud)
{
if (!HudManager.InstanceExists) return;
HudManager hudManager = FastDestroyableSingleton<HudManager>.Instance;
SoundManager.Instance.PlaySound(pc.KillSfx, false, 0.8f);
if (!Options.DisableKillAnimationOnGuess.GetBool()) hudManager.KillOverlay.ShowKillAnimation(pc.Data, pc.Data);
+14 -50
View File
@@ -1,42 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace EHR;
internal class LateTask
internal static class LateTask
{
private static readonly List<LateTask> Tasks = [];
private readonly Action Action;
private readonly string CallerData;
private readonly bool LOG;
private readonly string Name;
private float Timer;
private LateTask(Action action, float time, string name, bool log, string callerData)
{
Action = action;
Timer = time;
Name = name;
LOG = log;
CallerData = callerData;
Tasks.Add(this);
if (log && name is not "" and not "No Name Task") Logger.Info($"\"{name}\" is created (completes in {time:N2})", "LateTask");
}
private bool Run(float deltaTime)
{
Timer -= deltaTime;
if (Timer <= 0)
{
Action();
return true;
}
return false;
}
/// <summary>
/// Creates a task that will be automatically completed after the specified amount of time
/// </summary>
@@ -46,28 +16,22 @@ internal class LateTask
/// <param name="log">Whether to send log of the creation and completion of the Late Task</param>
public static void New(Action action, float time, string name = "No Name Task", bool log = true, [CallerFilePath] string path = "", [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
{
_ = new LateTask(action, time, name, log, $"created at {path.Split('\\')[^1]}, by member {member}, at line {line}");
}
if (log && name is not "" and not "No Name Task") Logger.Info($"\"{name}\" is created (completes in {time:N2})", "LateTask");
Main.Instance.StartCoroutine(CoLateTask());
return;
public static void Update(float deltaTime)
{
foreach (LateTask task in Tasks.ToArray())
IEnumerator CoLateTask()
{
yield return new WaitForSeconds(time);
try
{
if (task.Run(deltaTime))
{
if (task.Name is not "" and not "No Name Task" && task.LOG)
Logger.Info($"\"{task.Name}\" is finished", "LateTask");
Tasks.Remove(task);
}
}
catch (Exception ex)
{
Logger.Error($"{ex.GetType()}: {ex.Message} in \"{task.Name}\" ({task.CallerData})\n\n{ex.StackTrace}", "LateTask.Error", false, multiLine: true);
Tasks.Remove(task);
action();
if (name is not "" and not "No Name Task" && log)
Logger.Info($"\"{name}\" is finished", "LateTask");
}
catch (Exception ex) { Logger.Error($"{ex.GetType()}: {ex.Message}\n in \"{name}\"\n (created at {path.Split('\\')[^1]}, by member {member}, at line {line})\n {ex.StackTrace}".Replace("\r\n", "\n"), "LateTask.Error", false, multiLine: true); }
}
}
}
+1
View File
@@ -17,6 +17,7 @@ public static class Prompt
{
try
{
if (!HudManager.InstanceExists) return;
HudManager hud = FastDestroyableSingleton<HudManager>.Instance;
if (CurrentQuestion != string.Empty || !hud)
+2 -2
View File
@@ -1520,10 +1520,10 @@ internal static class RPC
case Sounds.KillSound:
SoundManager.Instance.PlaySound(PlayerControl.LocalPlayer.KillSfx, false);
break;
case Sounds.TaskComplete:
case Sounds.TaskComplete when HudManager.InstanceExists:
SoundManager.Instance.PlaySound(FastDestroyableSingleton<HudManager>.Instance.TaskCompleteSound, false);
break;
case Sounds.TaskUpdateSound:
case Sounds.TaskUpdateSound when HudManager.InstanceExists:
SoundManager.Instance.PlaySound(FastDestroyableSingleton<HudManager>.Instance.TaskUpdateSound, false);
break;
case Sounds.ImpTransform:
+13 -12
View File
@@ -12,6 +12,7 @@ using System.Text.RegularExpressions;
using AmongUs.Data;
using AmongUs.GameOptions;
using AmongUs.InnerNet.GameDataMessages;
using BepInEx;
using EHR.AddOns.Common;
using EHR.AddOns.Crewmate;
using EHR.AddOns.GhostRoles;
@@ -1853,10 +1854,13 @@ public static class Utils
if (sendTo != byte.MaxValue && receiver.IsLocalPlayer())
{
string name = sender.Data.PlayerName;
sender.SetName(title);
FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(sender, text);
sender.SetName(name);
if (HudManager.InstanceExists)
{
string name = sender.Data.PlayerName;
sender.SetName(title);
FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(sender, text);
sender.SetName(name);
}
try
{
@@ -2060,7 +2064,7 @@ public static class Utils
.Write(text)
.EndRpc();
if (sendTo == byte.MaxValue)
if (sendTo == byte.MaxValue && HudManager.InstanceExists)
{
string name = sender.Data.PlayerName;
sender.SetName(title);
@@ -3754,17 +3758,13 @@ public static class Utils
if (!Directory.Exists(f)) Directory.CreateDirectory(f);
var filename = $"{f}/EHR-v{Main.PluginVersion}-LOG";
#if ANDROID
var directory = Main.DataPath;
#else
string directory = Environment.CurrentDirectory;
#endif
FileInfo[] files = [new($"{directory}/BepInEx/LogOutput.log"), new($"{directory}/BepInEx/log.html")];
FileInfo[] files = [new(Path.Combine(Paths.BepInExRootPath, "LogOutput.log")), new(CustomLogger.LOGFilePath)];
files.Do(x => x.CopyTo($"{filename}{x.Extension}"));
if (!open) return;
if (PlayerControl.LocalPlayer != null)
if (PlayerControl.LocalPlayer != null && HudManager.InstanceExists)
FastDestroyableSingleton<HudManager>.Instance?.Chat?.AddChat(PlayerControl.LocalPlayer, string.Format(GetString("Message.DumpfileSaved"), "EHR" + filename.Split("EHR")[1]));
#if !ANDROID
@@ -4006,6 +4006,7 @@ public static class Utils
public static void FlashColor(Color color, float duration = 1f)
{
if (!HudManager.InstanceExists) return;
HudManager hud = FastDestroyableSingleton<HudManager>.Instance;
if (hud.FullScreen == null) return;
+2 -2
View File
@@ -52,7 +52,7 @@ public static class Zoom
public static void SetZoomSize(bool times = false, bool reset = false)
{
if (Camera.main == null) return;
if (Camera.main == null || !HudManager.InstanceExists) return;
var size = 1.5f;
if (!times) size = 1 / size;
@@ -81,7 +81,7 @@ public static class Zoom
public static void OnFixedUpdate()
{
if (Camera.main == null) return;
if (Camera.main == null || !HudManager.InstanceExists) return;
FastDestroyableSingleton<HudManager>.Instance?.ShadowQuad?.gameObject.SetActive(Mathf.Approximately(Camera.main.orthographicSize, 3.0f) && PlayerControl.LocalPlayer.IsAlive());
}
+3 -1
View File
@@ -12,6 +12,7 @@ using UnityEngine.Networking;
namespace EHR;
#if !ANDROID
// ReSharper disable once ClassNeverInstantiated.Global
public class ModNews
{
@@ -99,4 +100,5 @@ public static class ModNewsHistory
for (var i = 0; i < finalAllNews.Count; i++)
aRange[i] = finalAllNews[i];
}
}
}
#endif
+4 -3
View File
@@ -2833,6 +2833,7 @@ internal static class ChatCommands
break;
default:
if (!HudManager.InstanceExists) break;
FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(player, "crew | imp");
break;
}
@@ -3358,7 +3359,7 @@ internal static class ChatCommands
private static void VersionCommand(PlayerControl player, string text, string[] args)
{
string versionText = Main.PlayerVersion.OrderBy(pair => pair.Key).Aggregate(string.Empty, (current, kvp) => current + $"{kvp.Key}: ({Main.AllPlayerNames[kvp.Key]}) {kvp.Value.forkId}/{kvp.Value.version}({kvp.Value.tag})\n");
if (versionText != string.Empty) FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(player, (player.FriendCode.GetDevUser().HasTag() ? "\n" : string.Empty) + versionText);
if (versionText != string.Empty && HudManager.InstanceExists) FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(player, (player.FriendCode.GetDevUser().HasTag() ? "\n" : string.Empty) + versionText);
}
private static void LTCommand(PlayerControl player, string text, string[] args)
@@ -3681,7 +3682,7 @@ internal static class ChatUpdatePatch
string name = player.Data.PlayerName;
if (clientId == -1)
if (clientId == -1 && HudManager.InstanceExists)
{
player.SetName(title);
FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(player, msg);
@@ -3753,7 +3754,7 @@ internal static class RpcSendChatPatch
int return_count = PlayerControl.LocalPlayer.name.Count(x => x == '\n');
chatText = new StringBuilder(chatText).Insert(0, "\n", return_count).ToString();
if (AmongUsClient.Instance.AmClient && FastDestroyableSingleton<HudManager>.Instance) FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(__instance, chatText);
if (AmongUsClient.Instance.AmClient && HudManager.InstanceExists) FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(__instance, chatText);
if (chatText.Contains("who", StringComparison.OrdinalIgnoreCase)) FastDestroyableSingleton<UnityTelemetry>.Instance.SendWho();
+2 -2
View File
@@ -219,7 +219,7 @@ public static class ChatManager
public static void SendPreviousMessagesToAll()
{
if (!AmongUsClient.Instance.AmHost) return;
if (!AmongUsClient.Instance.AmHost || !HudManager.InstanceExists) return;
Logger.Info(" Sending Previous Messages To Everyone", "ChatManager");
@@ -284,7 +284,7 @@ public static class ChatManager
{
bool toEveryone = receiver == null;
bool toLocalPlayer = !toEveryone && receiver.IsLocalPlayer();
if (toLocalPlayer || toEveryone) FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(player, "<size=32767>.");
if (HudManager.InstanceExists && (toLocalPlayer || toEveryone)) FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(player, "<size=32767>.");
if (toLocalPlayer) return;
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.SendChat, SendOption.Reliable, toEveryone ? -1 : receiver.OwnerId);
writer.Write("<size=32767>.");
+9 -4
View File
@@ -10,6 +10,7 @@ using static EHR.Translator;
namespace EHR;
#if !ANDROID
[HarmonyPatch(typeof(ControllerManager), nameof(ControllerManager.Update))]
internal static class ControllerManagerUpdatePatch
{
@@ -133,7 +134,7 @@ internal static class ControllerManagerUpdatePatch
Utils.ShowActiveSettings();
}
if (GameStates.IsLobby && KeysDown(KeyCode.Delete, KeyCode.LeftControl, KeyCode.LeftShift) && !IsResetting)
if (GameStates.IsLobby && HudManager.InstanceExists && KeysDown(KeyCode.Delete, KeyCode.LeftControl, KeyCode.LeftShift) && !IsResetting)
{
Prompt.Show(GetString("Promt.ResetAllOptions"), ResetAllOptions, () => { });
@@ -193,6 +194,7 @@ internal static class ControllerManagerUpdatePatch
if (!Options.NoGameEnd.GetBool()) return;
#endif
#if DEBUG
if (KeysDown(KeyCode.Return, KeyCode.F, KeyCode.LeftShift))
{
@@ -200,7 +202,7 @@ internal static class ControllerManagerUpdatePatch
if (Constants.ShouldPlaySfx()) RPC.PlaySound(PlayerControl.LocalPlayer.PlayerId, Sounds.KillSound);
}
if (KeysDown(KeyCode.Return, KeyCode.G, KeyCode.LeftShift) && GameStates.IsInGame)
if (KeysDown(KeyCode.Return, KeyCode.G, KeyCode.LeftShift) && GameStates.IsInGame && HudManager.InstanceExists)
{
HudManager.Instance.StartCoroutine(HudManager.Instance.CoFadeFullScreen(Color.clear, Color.black));
HudManager.Instance.StartCoroutine(FastDestroyableSingleton<HudManager>.Instance.CoShowIntro());
@@ -233,7 +235,7 @@ internal static class ControllerManagerUpdatePatch
Logger.SendInGame(GetString("SyncCustomSettingsRPC"));
}
if (Input.GetKeyDown(KeyCode.Equals) && !GameStates.IsMeeting && !HudManager.Instance.Chat.IsOpenOrOpening)
if (Input.GetKeyDown(KeyCode.Equals) && !GameStates.IsMeeting && HudManager.InstanceExists && !HudManager.Instance.Chat.IsOpenOrOpening)
{
Main.VisibleTasksCount = !Main.VisibleTasksCount;
FastDestroyableSingleton<HudManager>.Instance.Notifier.AddDisconnectMessage($"VisibleTaskCount changed to {Main.VisibleTasksCount}.");
@@ -277,6 +279,7 @@ internal static class ControllerManagerUpdatePatch
VentilationSystem.Update(VentilationSystem.Operation.StartCleaning, 0);
#endif
#if !ANDROID
}
catch { }
}
@@ -321,11 +324,13 @@ internal static class HandleHUDPatch
public static void Postfix(Player player)
{
if (player.GetButtonDown(8) && // 8: Kill button actionId
HudManager.InstanceExists &&
PlayerControl.LocalPlayer.Data?.Role?.IsImpostor == false &&
PlayerControl.LocalPlayer.CanUseKillButton())
FastDestroyableSingleton<HudManager>.Instance.KillButton.DoClick();
if (player.GetButtonDown(50) && // 50: Impostor vent button actionId
HudManager.InstanceExists &&
PlayerControl.LocalPlayer.Data?.Role?.IsImpostor == false &&
PlayerControl.LocalPlayer.CanUseImpostorVentButton())
FastDestroyableSingleton<HudManager>.Instance.ImpostorVentButton.DoClick();
@@ -448,5 +453,5 @@ public static class InGameRoleInfoMenu
Menu?.SetActive(false);
}
}
}
#endif
+4 -5
View File
@@ -199,7 +199,7 @@ internal static class FriendsListUIOpenPatch
__instance.currentSceneName = activeScene.name;
__instance.UpdateFriendCodeUI();
if ((DestroyableSingleton<HudManager>.InstanceExists && FastDestroyableSingleton<HudManager>.Instance != null && FastDestroyableSingleton<HudManager>.Instance.Chat != null && FastDestroyableSingleton<HudManager>.Instance.Chat.IsOpenOrOpening) || ShipStatus.Instance != null)
if ((HudManager.InstanceExists && FastDestroyableSingleton<HudManager>.Instance != null && FastDestroyableSingleton<HudManager>.Instance.Chat != null && FastDestroyableSingleton<HudManager>.Instance.Chat.IsOpenOrOpening) || ShipStatus.Instance != null)
return false;
__instance.friendBars = new();
@@ -406,7 +406,6 @@ internal static class ModManagerLateUpdatePatch
{
__instance.ShowModStamp();
LateTask.Update(Time.deltaTime);
ChatBubbleShower.Update();
if (LobbySharingAPI.LastRoomCode != string.Empty && Utils.TimeStamp - LobbySharingAPI.LastRequestTimeStamp > 60)
@@ -417,7 +416,7 @@ internal static class ModManagerLateUpdatePatch
public static void Postfix(ModManager __instance)
{
__instance.localCamera = !DestroyableSingleton<HudManager>.InstanceExists
__instance.localCamera = !HudManager.InstanceExists
? Camera.main
: FastDestroyableSingleton<HudManager>.Instance.GetComponentInChildren<Camera>();
@@ -439,7 +438,7 @@ internal static class OptionsMenuBehaviourOpenPatch
{
try
{
if (DestroyableSingleton<HudManager>.InstanceExists && !FastDestroyableSingleton<HudManager>.Instance.SettingsButton.activeSelf) return false;
if (HudManager.InstanceExists && !FastDestroyableSingleton<HudManager>.Instance.SettingsButton.activeSelf) return false;
}
catch { }
@@ -459,7 +458,7 @@ internal static class OptionsMenuBehaviourOpenPatch
__instance.UpdateButtons();
__instance.gameObject.SetActive(true);
__instance.MenuButton?.SelectButton(true);
if (DestroyableSingleton<HudManager>.InstanceExists) ConsoleJoystick.SetMode_MenuAdditive();
if (HudManager.InstanceExists) ConsoleJoystick.SetMode_MenuAdditive();
if (!__instance.grabbedControllerButtons)
{
+9 -9
View File
@@ -1,12 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using EHR.AddOns.GhostRoles;
using EHR.Modules;
using EHR.Patches;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
@@ -937,7 +937,7 @@ public static class StringOptionPatch
[HarmonyPatch(typeof(GameSettingMenu))]
public static class GameSettingMenuPatch
{
public static System.Collections.Generic.List<GameObject> GMButtons = [];
public static List<GameObject> GMButtons = [];
private static readonly Vector3 ButtonPositionLeft = new(-3.9f, -0.55f, 0f);
private static readonly Vector3 ButtonPositionRight = new(-2.4f, -0.55f, 0f);
@@ -948,15 +948,15 @@ public static class GameSettingMenuPatch
private static GameOptionsMenu TemplateGameOptionsMenu;
private static PassiveButton TemplateGameSettingsButton;
private static System.Collections.Generic.Dictionary<TabGroup, PassiveButton> ModSettingsButtons = [];
private static System.Collections.Generic.Dictionary<TabGroup, GameOptionsMenu> ModSettingsTabs = [];
private static Dictionary<TabGroup, PassiveButton> ModSettingsButtons = [];
private static Dictionary<TabGroup, GameOptionsMenu> ModSettingsTabs = [];
public static NumberOption PresetBehaviour;
public static long LastPresetChange;
public static FreeChatInputField InputField;
private static System.Collections.Generic.List<OptionItem> HiddenBySearch = [];
private static List<OptionItem> HiddenBySearch = [];
public static Action SearchForOptionsAction;
private static int NumImpsOnOpen = 1;
@@ -1196,7 +1196,7 @@ public static class GameSettingMenuPatch
}
FreeChatInputField freeChatField = DestroyableSingleton<ChatController>.Instance.freeChatField; // FastDestroyableSingleton DOES NOT WORK HERE!!!! IF YOU USE THAT, IT BREAKS THE ENTIRE SETTINGS MENU
FreeChatInputField freeChatField = FastDestroyableSingleton<HudManager>.Instance.Chat.freeChatField; // FastDestroyableSingleton DOES NOT WORK HERE!!!! IF YOU USE THAT, IT BREAKS THE ENTIRE SETTINGS MENU
FreeChatInputField field = Object.Instantiate(freeChatField, parentLeftPanel.parent);
field.transform.localScale = new(0.3f, 0.59f, 1);
field.transform.localPosition = new(-0.7f, -2.5f, -5f);
@@ -1253,9 +1253,9 @@ public static class GameSettingMenuPatch
string text = textField.textArea.text.Trim().ToLower();
var modTab = (TabGroup)(ModGameOptionsMenu.TabIndex - 3);
OptionItem[] optionItems = Options.GroupedOptions[modTab];
System.Collections.Generic.List<OptionItem> result = optionItems.Where(x => x.Parent == null && !x.IsCurrentlyHidden() && !Translator.GetString($"{x.Name}").Contains(text, StringComparison.OrdinalIgnoreCase)).ToList();
List<OptionItem> result = optionItems.Where(x => x.Parent == null && !x.IsCurrentlyHidden() && !Translator.GetString($"{x.Name}").Contains(text, StringComparison.OrdinalIgnoreCase)).ToList();
HiddenBySearch = result;
System.Collections.Generic.List<OptionItem> searchWinners = optionItems.Where(x => x.Parent == null && !x.IsCurrentlyHidden() && !result.Contains(x)).ToList();
List<OptionItem> searchWinners = optionItems.Where(x => x.Parent == null && !x.IsCurrentlyHidden() && !result.Contains(x)).ToList();
if (searchWinners.Count == 0 || !ModSettingsTabs.TryGetValue(modTab, out GameOptionsMenu gameSettings) || gameSettings == null)
{
@@ -1394,7 +1394,7 @@ public static class GameSettingMenuPatch
ModGameOptionsMenu.CategoryHeaderList = new();
ControllerManager.Instance.OpenOverlayMenu(__instance.name, __instance.BackButton, __instance.DefaultButtonSelected, __instance.ControllerSelectable);
FastDestroyableSingleton<HudManager>.Instance.menuNavigationPrompts.SetActive(false);
if (HudManager.InstanceExists) FastDestroyableSingleton<HudManager>.Instance.menuNavigationPrompts.SetActive(false);
if (Controller.currentTouchType != Controller.TouchType.Joystick) __instance.ChangeTab(1, false);
__instance.StartCoroutine(__instance.CoSelectDefault());
+15 -15
View File
@@ -51,7 +51,7 @@ public static class GameStartManagerPatch
GameCountdown = Object.Instantiate(__instance.PlayerCounter, __instance.HostInfoPanel.transform);
GameCountdown.text = string.Empty;
if (GameData.Instance && AmongUsClient.Instance.NetworkMode != NetworkModes.LocalGame && GameStates.CurrentServerType == GameStates.ServerType.Vanilla)
if (GameData.Instance && HudManager.InstanceExists && AmongUsClient.Instance.NetworkMode != NetworkModes.LocalGame && GameStates.CurrentServerType == GameStates.ServerType.Vanilla)
{
HudManager hudManager = FastDestroyableSingleton<HudManager>.Instance;
hudManager.ShowLobbyTimer(597);
@@ -323,8 +323,11 @@ public static class GameStartManagerPatch
instance.GameStartText.text = string.Empty;
}
}
if (!HudManager.InstanceExists) return;
if (instance.LobbyInfoPane.gameObject.activeSelf && FastDestroyableSingleton<HudManager>.Instance.Chat.IsOpenOrOpening) instance.LobbyInfoPane.DeactivatePane();
if (instance.LobbyInfoPane.gameObject.activeSelf && FastDestroyableSingleton<HudManager>.Instance.Chat.IsOpenOrOpening)
instance.LobbyInfoPane.DeactivatePane();
instance.LobbyInfoPane.gameObject.SetActive(!FastDestroyableSingleton<HudManager>.Instance.Chat.IsOpenOrOpening);
}
@@ -454,7 +457,7 @@ public static class GameStartManagerPatch
tmp.gameObject.SetActive(true);
// Lobby timer
if (GameData.Instance && AmongUsClient.Instance.NetworkMode != NetworkModes.LocalGame && GameStates.CurrentServerType == GameStates.ServerType.Vanilla)
if (GameData.Instance && HudManager.InstanceExists && AmongUsClient.Instance.NetworkMode != NetworkModes.LocalGame && GameStates.CurrentServerType == GameStates.ServerType.Vanilla)
{
float timer = Timer;
@@ -462,7 +465,7 @@ public static class GameStartManagerPatch
LobbyTimerBg.sprite = Utils.LoadSprite("EHR.Resources.Images.LobbyTimerBG.png", 100f);
LobbyTimerBg.color = GetTimerColor(timer);
if (timer <= 60 && !Warned)
if (timer <= 60 && !Warned && AmongUsClient.Instance.AmHost)
{
Warned = true;
LobbyTimerExtensionUI lobbyTimerExtensionUI = FastDestroyableSingleton<HudManager>.Instance.LobbyTimerExtensionUI;
@@ -538,6 +541,14 @@ public static class GameStartRandomMap
Utils.SendMessage(msg, sendOption: SendOption.None);
return false;
}
if (Options.RandomMapsMode.GetBool())
{
Main.NormalOptions.MapId = SelectRandomMap();
CreateOptionsPickerPatch.SetDleks = Main.CurrentMap == MapNames.Dleks;
}
else if (CreateOptionsPickerPatch.SetDleks) Main.NormalOptions.MapId = 3;
else if (CreateOptionsPickerPatch.SetSubmerged) Main.NormalOptions.MapId = 6;
if (__instance.startState == GameStartManager.StartingStates.Countdown)
Main.NormalOptions.KillCooldown = Main.LastKillCooldown.Value;
@@ -566,17 +577,6 @@ public static class GameStartRandomMap
return false;
}
public static void Prefix( /*GameStartRandomMap __instance*/)
{
if (Options.RandomMapsMode.GetBool())
{
Main.NormalOptions.MapId = SelectRandomMap();
CreateOptionsPickerPatch.SetDleks = Main.CurrentMap == MapNames.Dleks;
}
else if (CreateOptionsPickerPatch.SetDleks) Main.NormalOptions.MapId = 3;
else if (CreateOptionsPickerPatch.SetSubmerged) Main.NormalOptions.MapId = 6;
}
public static byte SelectRandomMap()
{
System.Collections.Generic.Dictionary<byte, int> chance = Enumerable.Range(0, 6).ToDictionary(x => (byte)x, x => x switch
+10 -8
View File
@@ -2,6 +2,8 @@ using System;
using System.Collections;
using System.Linq;
using AmongUs.GameOptions;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using EHR.AddOns.Common;
using EHR.Modules;
using EHR.Neutral;
using HarmonyLib;
@@ -43,7 +45,7 @@ static class ShowRoleMoveNextPatch
[HarmonyPatch(typeof(HudManager), nameof(HudManager.CoShowIntro))]
static class CoShowIntroPatch
{
public static bool Prefix(HudManager __instance)
public static bool Prefix(HudManager __instance, ref Il2CppSystem.Collections.IEnumerator __result)
{
if (!AmongUsClient.Instance.AmHost || !GameStates.IsModHost) return true;
@@ -67,12 +69,12 @@ static class CoShowIntroPatch
catch { Logger.Warn($"Game ended? {AmongUsClient.Instance.IsGameOver || GameStates.IsLobby || GameEndChecker.Ended}", "ShipStatus.Begin"); }
}, 4f, "Assign Tasks");
Main.Instance.StartCoroutine(CoShowIntro());
__result = CoShowIntro().WrapToIl2Cpp();
return false;
IEnumerator CoShowIntro()
{
while (!ShipStatus.Instance) yield return null;
while (!ShipStatus.Instance || !HudManager.InstanceExists) yield return null;
RPC.RpcVersionCheck();
GameStates.InGame = true;
@@ -80,11 +82,9 @@ static class CoShowIntroPatch
__instance.IsIntroDisplayed = true;
__instance.LobbyTimerExtensionUI.HideAll();
__instance.SetMapButtonEnabled(false);
__instance.FullScreen.transform.localPosition = new Vector3(0.0f, 0.0f, -250f);
HudManager hudManager = FastDestroyableSingleton<HudManager>.Instance;
hudManager.FullScreen.transform.localPosition = new Vector3(0.0f, 0.0f, -250f);
yield return hudManager.ShowEmblem(true);
yield return __instance.ShowEmblem(true);
yield return CoBegin(Object.Instantiate(__instance.IntroPrefab, __instance.transform));
PlayerControl.LocalPlayer.SetKillTimer(10f);
@@ -1326,6 +1326,8 @@ internal static class IntroCutsceneDestroyPatch
pc.TP(new Vector2(3.32f, -26.57f));
}
}
if (!HudManager.InstanceExists) return;
HudManager hud = FastDestroyableSingleton<HudManager>.Instance;
@@ -1344,7 +1346,7 @@ internal static class IntroCutsceneDestroyPatch
if (Options.CurrentGameMode == CustomGameMode.Standard && !Utils.HasTasks(PlayerControl.LocalPlayer.Data, forRecompute: false))
hud.TaskPanel.open = false;
if (!AmongUsClient.Instance.AmHost) return;
if (!AmongUsClient.Instance.AmHost || !Lovers.PrivateChat.GetBool()) return;
Main.LoversPlayers.ForEach(x => x.SetChatVisible(true));
}, 1f, log: false);
+4 -1
View File
@@ -173,7 +173,10 @@ public static class MainMenuManagerPatch
foreach (string buttonName in new[] { "SettingsButton", "Inventory Button", "CreditsButton", "ExitGameButton" })
{
var buttonText = GameObject.Find(buttonName).transform.Find("FontPlacer/Text_TMP").GetComponent<TMP_Text>();
var go = GameObject.Find(buttonName);
if (!go) continue;
var buttonText = go.GetComponentInChildren<TMP_Text>();
if (!buttonText) continue;
buttonText.DestroyTranslator();
buttonText.text = Translator.GetString($"MainMenu.{buttonName.Replace(" ", "")}");
}
+3 -3
View File
@@ -32,11 +32,11 @@ internal static class ChangeRoleSettings
{
public static bool BlockPopulateSkins;
public static bool Prefix(AmongUsClient __instance)
public static bool Prefix(AmongUsClient __instance, ref Il2CppSystem.Collections.IEnumerator __result)
{
if (!GameStates.IsLocalGame) return true;
if (!GameStates.IsLocalGame || !HudManager.InstanceExists) return true;
__instance.StartCoroutine(CoStartGame().WrapToIl2Cpp());
__result = CoStartGame().WrapToIl2Cpp();
return false;
IEnumerator<object> CoStartGame()
+3 -1
View File
@@ -152,6 +152,8 @@ public static class PhantomRolePatch
public static bool CheckTrigger(PlayerControl phantom)
{
if (!HudManager.InstanceExists) return true;
RoleBase roleBase = Main.PlayerStates[phantom.PlayerId].Role;
if ((phantom.Is(CustomRoles.Trainee) && MeetingStates.FirstMeeting) || !Rhapsode.CheckAbilityUse(phantom) || Stasis.IsTimeFrozen || TimeMaster.Rewinding || !roleBase.OnVanish(phantom))
@@ -337,7 +339,7 @@ public static class PhantomRoleUseAbilityPatch
{
public static bool Prefix(PhantomRole __instance)
{
if (!AmongUsClient.Instance.AmHost) return true;
if (!AmongUsClient.Instance.AmHost || !HudManager.InstanceExists) return true;
if (__instance.Player.AmOwner && !__instance.Player.Data.IsDead && __instance.Player.moveable && !Minigame.Instance && !__instance.IsCoolingDown && !__instance.fading)
{
+1 -1
View File
@@ -1189,7 +1189,7 @@ internal static class ReportDeadBodyPatch
CustomNetObject.OnMeeting();
FastDestroyableSingleton<HudManager>.Instance.SetRolePanelOpen(false);
if (HudManager.InstanceExists) FastDestroyableSingleton<HudManager>.Instance.SetRolePanelOpen(false);
Asthmatic.RunChecks = false;
+1 -1
View File
@@ -472,7 +472,7 @@ internal static class OnPlayerJoinedPatch
Logger.Info(msg, "Android Kick");
}
if (FastDestroyableSingleton<FriendsListManager>.Instance.IsPlayerBlockedUsername(client.FriendCode) && AmongUsClient.Instance.AmHost && GameStates.CurrentServerType is not GameStates.ServerType.Modded and not GameStates.ServerType.Niko and not GameStates.ServerType.Local)
if (FriendsListManager.InstanceExists && FastDestroyableSingleton<FriendsListManager>.Instance.IsPlayerBlockedUsername(client.FriendCode) && AmongUsClient.Instance.AmHost && GameStates.CurrentServerType is not GameStates.ServerType.Modded and not GameStates.ServerType.Niko and not GameStates.ServerType.Local)
{
AmongUsClient.Instance.KickPlayer(client.Id, true);
Logger.Info($"Blocked Player {client.PlayerName}({client.FriendCode}) has been banned.", "BAN");
+1 -1
View File
@@ -8,7 +8,7 @@ public static class SabotageButtonDoClickPatch
{
public static bool Prefix()
{
if (!PlayerControl.LocalPlayer.inVent && GameManager.Instance.SabotagesEnabled())
if (!PlayerControl.LocalPlayer.inVent && GameManager.Instance.SabotagesEnabled() && HudManager.InstanceExists)
{
FastDestroyableSingleton<HudManager>.Instance.ToggleMapVisible(new()
{
+2 -2
View File
@@ -109,7 +109,7 @@ public static class TextBoxPatch
{
try
{
if (!__instance.gameObject.HasParentInHierarchy("ChatScreenRoot/ChatScreenContainer")) return;
if (!HudManager.InstanceExists || !__instance.gameObject.HasParentInHierarchy("ChatScreenRoot/ChatScreenContainer")) return;
if (!Main.EnableCommandHelper.Value)
{
@@ -363,7 +363,7 @@ public static class TextBoxPatch
{
try
{
bool open = FastDestroyableSingleton<HudManager>.Instance?.Chat?.IsOpenOrOpening ?? false;
bool open = HudManager.InstanceExists && (FastDestroyableSingleton<HudManager>.Instance?.Chat?.IsOpenOrOpening ?? false);
PlaceHolderText?.gameObject.SetActive(open);
CommandInfoText?.gameObject.SetActive(open);
AdditionalInfoText?.gameObject.SetActive(open);