mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
115 lines
4.5 KiB
C#
115 lines
4.5 KiB
C#
using InnerNet;
|
|
using HarmonyLib;
|
|
using Hazel;
|
|
using BetterAmongUs.Patches;
|
|
|
|
namespace BetterAmongUs;
|
|
|
|
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameJoined))]
|
|
class OnGameJoinedPatch
|
|
{
|
|
public static void Postfix(/*AmongUsClient __instance*/)
|
|
{
|
|
try
|
|
{
|
|
PlayerControlPatch.infotime = 0f;
|
|
|
|
AntiCheat.PauseAntiCheat();
|
|
|
|
// Fix host icon in lobby on modded servers
|
|
if (!GameStates.IsVanillaServer)
|
|
{
|
|
var host = AmongUsClient.Instance.GetHost().Character;
|
|
host.SetColor(-2);
|
|
host.SetColor(host.CurrentOutfit.ColorId);
|
|
}
|
|
|
|
_ = new LateTask(() =>
|
|
{
|
|
// Send Better Among Us Check RPC
|
|
if (GameStates.IsInGame)
|
|
{
|
|
MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.BetterCheck, SendOption.None, -1);
|
|
messageWriter.Write((byte)PlayerControl.LocalPlayer.NetId);
|
|
AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
|
|
}
|
|
}, 1.5f, "OnGameJoinedPatch");
|
|
|
|
Logger.Log($"Successfully joined {GameCode.IntToGameName(AmongUsClient.Instance.GameId)}", "OnGameJoinedPatch");
|
|
}
|
|
catch { };
|
|
}
|
|
}
|
|
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerJoined))]
|
|
public static class OnPlayerJoinedPatch
|
|
{
|
|
public static void Postfix(/*AmongUsClient __instance,*/ [HarmonyArgument(0)] ClientData client)
|
|
{
|
|
PlayerControlPatch.infotime = 0f;
|
|
|
|
_ = new LateTask(() =>
|
|
{
|
|
if (GameStates.IsInGame)
|
|
{
|
|
// Send Better Among Us Check RPC
|
|
MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, unchecked((byte)CustomRPC.BetterCheck), SendOption.None, -1);
|
|
messageWriter.Write((byte)PlayerControl.LocalPlayer.NetId);
|
|
AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
|
|
|
|
RPC.SyncAllNames(force: true);
|
|
|
|
if (Main.BetterHost.Value)
|
|
client.Character.RpcSendHostChat(HudManagerPatch.WelcomeMessage, sendToBetterUser: false);
|
|
}
|
|
}, 1.5f, "OnPlayerJoinedPatch", false);
|
|
}
|
|
}
|
|
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerLeft))]
|
|
class OnPlayerLeftPatch
|
|
{
|
|
public static void Postfix(/*AmongUsClient __instance,*/ [HarmonyArgument(0)] ClientData data, [HarmonyArgument(1)] DisconnectReasons reason)
|
|
{
|
|
if ((GameStates.IsInGame || GameStates.IsFreePlay) && !GameStates.IsLobby && !GameStates.IsHideNSeek && HudManager.Instance.CrewmatesKilled.isActiveAndEnabled)
|
|
HudManager.Instance?.NotifyOfDisconnect(data.Character);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(GameData), nameof(GameData.ShowNotification))]
|
|
class GameDataPatch
|
|
{
|
|
public static bool Prefix(AmongUsClient __instance, ref string playerName, ref DisconnectReasons reason)
|
|
{
|
|
string ReasonText;
|
|
switch (reason)
|
|
{
|
|
case DisconnectReasons.ExitGame:
|
|
ReasonText = $"{playerName} Left the game!";
|
|
break;
|
|
case DisconnectReasons.ClientTimeout:
|
|
ReasonText = $"{playerName} Disconnected!";
|
|
break;
|
|
case DisconnectReasons.Kicked:
|
|
ReasonText = $"{playerName} Was kicked by {AmongUsClient.Instance.GetHost().Character.Data.PlayerName}!";
|
|
break;
|
|
case DisconnectReasons.Banned:
|
|
ReasonText = $"{playerName} Was banned by {AmongUsClient.Instance.GetHost().Character.Data.PlayerName}!";
|
|
break;
|
|
case DisconnectReasons.Hacking:
|
|
ReasonText = $"{playerName} Was banned by Innersloth Anti-Cheat!";
|
|
break;
|
|
case DisconnectReasons.Error:
|
|
ReasonText = $"{playerName} Was kicked due to an error!";
|
|
break;
|
|
case DisconnectReasons.Unknown:
|
|
ReasonText = $"{playerName} Left the game due to unknown reason?";
|
|
break;
|
|
default:
|
|
ReasonText = $"{playerName} Left the game!";
|
|
break;
|
|
}
|
|
|
|
DestroyableSingleton<HudManager>.Instance.Notifier.AddDisconnectMessage(ReasonText);
|
|
return false;
|
|
}
|
|
}
|