mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
* Well lets try check this * Some changes * Change * Well * Change ControllerManager.Update * Nothing * Optimaze more? * Fix error build * Fix win check * Change * Fix * Optimaze some roles in OnCheckPlayerPosition * More optimaze * Full optimaze roles in OnGlobalFixedUpdate * Optimaze some add-ons * ProgressText * Change * Optimaze NameNotifyManager * Optimaze NotifyRoles and some roles * Move the displayed version * Some changes * Optimaze OnFixedUpdate in some roles * Fix bugs * Optimaze IsActive & V4 version * Optimaze MapRoom.DoorsUpdate * Cache TryCatch in IsActive * Change * Fix * More optimze TaskPanelBehaviour * Cache GetRoleColor & ColorString & AllStringNames & Change RemoveHtmlTags * Cache TryCast VentilationSystem & ICriticalSabotage & IUsable and more optimaze * Fix CountAlivePlayers * Fix exceptios * Replace some CachedAllPlayerControls to EnumeratePlayerControls * Replace some CachedAlivePlayerControls to EnumerateAlivePlayerControls * Fixes * Fix modded clients * Fix errors * Fix again * Optimaze & add null check * Fix crash in Starlight * Use only Main.PluginVersion in LobbySharingAPI * Optimaze code in FixedUpdate * Fix * Optimize GetProgressText for Roles * Some changes in Translations * Cache Enum.GetValues and StringBuilder * Changes * CustomRole.ColoredTextByRole() * Optimaze Lobby & Meeting * ColorStringPrefix => ColorPrefix * Add null check * Remove * Fixes & optimaze * Fixes * Changes * Fix * Fix * Fix * Remove * Fix * Change * Revert
223 lines
8.3 KiB
C#
223 lines
8.3 KiB
C#
using AmongUs.Data;
|
|
using EHR.Modules;
|
|
using HarmonyLib;
|
|
using Il2CppInterop.Runtime.InteropTypes;
|
|
using InnerNet;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using static EHR.Translator;
|
|
|
|
namespace EHR;
|
|
|
|
/*[HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.MakePublic))]
|
|
internal static class MakePublicPatch
|
|
{
|
|
public static bool Prefix()
|
|
{
|
|
if (ModUpdater.IsBroken || (ModUpdater.HasUpdate && ModUpdater.ForceUpdate) || !VersionChecker.IsSupported)
|
|
{
|
|
var message = string.Empty;
|
|
if (!VersionChecker.IsSupported) message = GetString("UnsupportedVersion");
|
|
if (ModUpdater.IsBroken) message = GetString("ModBrokenMessage");
|
|
if (ModUpdater.HasUpdate) message = GetString("CanNotJoinPublicRoomNoLatest");
|
|
Logger.Info(message, "MakePublicPatch");
|
|
Logger.SendInGame(message, Color.red);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}*/
|
|
|
|
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.StartRpcImmediately))]
|
|
static class StartRpcImmediatelyPatch
|
|
{
|
|
public static void Postfix(uint targetNetId, byte callId, Hazel.SendOption option, int targetClientId = -1)
|
|
{
|
|
if (callId is 21 or 44 or 45 or 104) return;
|
|
Logger.Info($"Starting RPC: {callId} ({RPC.GetRpcName(callId)}) as {Main.CachedAllPlayerControls().FirstOrDefault(x => x.NetId == targetNetId)?.GetRealName() ?? targetNetId.ToString()} with SendOption {option} to {Utils.GetClientById(targetClientId)?.Character?.GetRealName() ?? targetClientId.ToString()}", "StartRpcImmediately");
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(MMOnlineManager), nameof(MMOnlineManager.Start))]
|
|
// ReSharper disable once InconsistentNaming
|
|
internal static class MMOnlineManagerStartPatch
|
|
{
|
|
public static void Postfix()
|
|
{
|
|
if (!((ModUpdater.HasUpdate && ModUpdater.ForceUpdate) || ModUpdater.IsBroken)) return;
|
|
|
|
GameObject obj = GameObject.Find("FindGameButton");
|
|
|
|
if (obj)
|
|
{
|
|
obj.SetActive(false);
|
|
TextMeshPro textObj = Object.Instantiate(obj.transform.FindChild("Text_TMP").GetComponent<TextMeshPro>());
|
|
textObj.transform.position = new(1f, -0.3f, 0);
|
|
textObj.name = "CanNotJoinPublic";
|
|
|
|
string message = ModUpdater.IsBroken
|
|
? $"<size=2>{Utils.ColorString(Color.red, GetString("ModBrokenMessage"))}</size>"
|
|
: $"<size=2>{Utils.ColorString(Color.red, GetString("CanNotJoinPublicRoomNoLatest"))}</size>";
|
|
|
|
LateTask.New(() => { textObj.text = message; }, 0.01f, "CanNotJoinPublic");
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(SplashManager), nameof(SplashManager.Update))]
|
|
internal static class SplashLogoAnimatorPatch
|
|
{
|
|
public static SceneChanger SceneChanger;
|
|
|
|
public static void Prefix(SplashManager __instance)
|
|
{
|
|
SceneChanger = __instance.sceneChanger;
|
|
__instance.sceneChanger.AllowFinishLoadingScene();
|
|
__instance.startedSceneLoad = true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EOSManager), nameof(EOSManager.IsAllowedOnline))]
|
|
internal static class RunLoginPatch
|
|
{
|
|
public const int ClickCount = 0;
|
|
|
|
public static void Prefix(ref bool canOnline)
|
|
{
|
|
if (DebugModeManager.AmDebugger) canOnline = true;
|
|
|
|
if (!Main.AckdPrivacyPolicy.Value)
|
|
{
|
|
ModUpdater.ShowPopupWithTwoButtons(GetString("PrivacyPolicy"), GetString("Yes"), GetString("MainMenu.ExitGameButton"), () => Main.AckdPrivacyPolicy.Value = true, SplashLogoAnimatorPatch.SceneChanger.ExitGame);
|
|
return;
|
|
}
|
|
|
|
try { ModUpdater.ShowAvailableUpdate(); }
|
|
catch (Exception error) { Logger.Error(error.ToString(), "ModUpdater.ShowAvailableUpdate"); }
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BanMenu), nameof(BanMenu.SetVisible))]
|
|
internal static class BanMenuSetVisiblePatch
|
|
{
|
|
public static bool Prefix(BanMenu __instance, bool show)
|
|
{
|
|
if (!AmongUsClient.Instance.AmHost) return true;
|
|
|
|
show &= PlayerControl.LocalPlayer && PlayerControl.LocalPlayer.Data != null;
|
|
__instance.BanButton.gameObject.SetActive(AmongUsClient.Instance.CanBan());
|
|
__instance.KickButton.gameObject.SetActive(AmongUsClient.Instance.CanKick());
|
|
__instance.MenuButton.gameObject.SetActive(show);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.CanBan))]
|
|
internal static class InnerNetClientCanBanPatch
|
|
{
|
|
public static bool Prefix(InnerNetClient __instance, ref bool __result)
|
|
{
|
|
__result = __instance.AmHost;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.KickPlayer))]
|
|
internal static class KickPlayerPatch
|
|
{
|
|
public static bool Prefix( /*InnerNetClient __instance,*/ int clientId, bool ban)
|
|
{
|
|
if (!AmongUsClient.Instance.AmHost && !OnGameJoinedPatch.JoiningGame) return true;
|
|
|
|
if (AmongUsClient.Instance.ClientId == clientId)
|
|
{
|
|
Logger.SendInGame($"Game Attempting to {(ban ? "Ban" : "Kick")} Host, Blocked the attempt.", Color.red);
|
|
return false;
|
|
}
|
|
|
|
if (ban) BanManager.AddBanPlayer(AmongUsClient.Instance.GetRecentClient(clientId));
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(ResolutionManager), nameof(ResolutionManager.SetResolution))]
|
|
internal static class SetResolutionManager
|
|
{
|
|
public static void Postfix()
|
|
{
|
|
if (MainMenuManagerPatch.UpdateButton)
|
|
MainMenuManagerPatch.UpdateButton.transform.localPosition = MainMenuManagerPatch.Template.transform.localPosition + new Vector3(0.25f, 0.75f);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.SendAllStreamedObjects))]
|
|
internal static class InnerNetObjectSerializePatch
|
|
{
|
|
public static void Prefix()
|
|
{
|
|
if (!AmongUsClient.Instance.AmHost || GameOptionsSender.ActiveCoroutine != null) return;
|
|
GameOptionsSender.ActiveCoroutine = Main.Instance.StartCoroutine(GameOptionsSender.SendDirtyGameOptionsContinuously());
|
|
}
|
|
}
|
|
|
|
// https://github.com/Rabek009/MoreGamemodes/blob/master/Patches/ClientPatch.cs
|
|
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CheckOnlinePermissions))]
|
|
static class CheckOnlinePermissionsPatch
|
|
{
|
|
public static void Prefix()
|
|
{
|
|
DataManager.Player.Ban.banPoints = 0f;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch]
|
|
internal static class AuthTimeoutPatch
|
|
{
|
|
// From Reactor.gg
|
|
// https://github.com/NuclearPowered/Reactor/blob/master/Reactor/Patches/Miscellaneous/CustomServersPatch.cs
|
|
[HarmonyPatch(typeof(AuthManager), nameof(AuthManager.CoConnect))]
|
|
[HarmonyPatch(typeof(AuthManager), nameof(AuthManager.CoWaitForNonce))]
|
|
[HarmonyPrefix]
|
|
public static bool CoWaitforNonce_Prefix()
|
|
{
|
|
return GameStates.CurrentServerTypeInCreateMenu is GameStates.ServerType.Vanilla or GameStates.ServerType.Local;
|
|
}
|
|
|
|
// If you don't patch this, you still need to wait for 5 s.
|
|
// I have no idea why this is happening
|
|
[HarmonyPatch]
|
|
public static class EnableUdpPatch
|
|
{
|
|
public static MethodBase TargetMethod()
|
|
{
|
|
return Utils.GetStateMachineMoveNext<AmongUsClient>(nameof(AmongUsClient.CoJoinOnlinePublicGame))!;
|
|
}
|
|
|
|
public static void Prefix(Il2CppObjectBase __instance)
|
|
{
|
|
var stateMachine = new StateMachineWrapper<AmongUsClient>(__instance);
|
|
|
|
// Skip to state 1 which just calls CoJoinOnlineGameDirect
|
|
if (stateMachine.State == 0 && !ServerManager.Instance.IsHttp)
|
|
{
|
|
stateMachine.State = 1;
|
|
var lambdaType = stateMachine.GetParameter<Il2CppObjectBase>("__8__1").GetType();
|
|
var newDisplayClass = Activator.CreateInstance(lambdaType);
|
|
if (newDisplayClass == null)
|
|
{
|
|
throw new InvalidOperationException($"Could not create display class of type '{lambdaType}'.");
|
|
}
|
|
|
|
var displayClass = new CompilerGeneratedObjectWrapper(newDisplayClass);
|
|
displayClass.SetField("matchmakerToken", string.Empty);
|
|
|
|
stateMachine.SetParameter("__8__1", newDisplayClass);
|
|
}
|
|
}
|
|
}
|
|
} |