mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
Fixed Unity logs getting logged in console
This commit is contained in:
1 parent
e21e3fea2f
commit
105cfc1f0b
13 files changed
+118
-17
No files matched your search
@@ -58,6 +58,8 @@ public class ExtendedAntiCheatInfo
|
||||
public bool IsFixingPanelSabotage => OpenSabotageNum != 0;
|
||||
public float TimeSinceLastTask { get; set; } = 5f;
|
||||
public uint LastTaskId { get; set; } = 999;
|
||||
public bool HasSetName { get; set; }
|
||||
public bool HasSetLevel { get; set; }
|
||||
}
|
||||
|
||||
public class ExtendedRoleInfo
|
||||
|
||||
@@ -95,16 +95,14 @@ static class PlayerControlHelper
|
||||
{
|
||||
if (player == null) return false;
|
||||
|
||||
if (player.isDummy || GameState.IsLocalGame || !GameState.IsVanillaServer)
|
||||
if (player.isDummy || GameState.IsLocalGame/* || !GameState.IsVanillaServer*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.gameObject.transform.Find("Names/NameText_TMP").GetComponent<TextMeshPro>().text
|
||||
is "???" or "Player" or "<color=#b5b5b5>Loading</color>" or null
|
||||
is "???" or "Player" or "<color=#b5b5b5>Loading</color>" or "" or null
|
||||
|| player.Data == null
|
||||
|| string.IsNullOrEmpty(player.Data.Puid)
|
||||
|| player.Data.PlayerLevel == uint.MaxValue
|
||||
|| player.CurrentOutfit == null
|
||||
|| player.CurrentOutfit.ColorId == -1)
|
||||
{
|
||||
|
||||
@@ -43,6 +43,8 @@ class BetterNotificationManager
|
||||
|
||||
public static void NotifyCheat(PlayerControl player, string reason, string newText = "", bool kickPlayer = true)
|
||||
{
|
||||
if (player?.Data == null) return;
|
||||
|
||||
var Reason = reason;
|
||||
if (BetterGameSettings.CensorDetectionReason.GetBool())
|
||||
{
|
||||
@@ -67,7 +69,7 @@ class BetterNotificationManager
|
||||
if (!BAUAntiCheat.PlayerData.ContainsKey(Utils.GetHashPuid(player)))
|
||||
{
|
||||
BAUAntiCheat.PlayerData[Utils.GetHashPuid(player)] = player.Data.FriendCode;
|
||||
BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player?.BetterData().RealName, "cheatData", Reason);
|
||||
BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player?.BetterData().RealName ?? player.Data.PlayerName, "cheatData", Reason);
|
||||
Notify(text, Time: 8f);
|
||||
}
|
||||
|
||||
|
||||
@@ -144,9 +144,9 @@ class BAUAntiCheat
|
||||
}
|
||||
|
||||
// Handle RPC before anti cheat detection
|
||||
public static void HandleCheatRPCBeforeCheck(PlayerControl player, byte callId, MessageReader Oldreader)
|
||||
public static void HandleCheatRPCBeforeCheck(PlayerControl player, byte callId, MessageReader oldReader)
|
||||
{
|
||||
MessageReader reader = MessageReader.Get(Oldreader);
|
||||
MessageReader reader = MessageReader.Get(oldReader);
|
||||
|
||||
if (player.IsLocalPlayer() || player == null || !IsEnabled) return;
|
||||
|
||||
@@ -154,9 +154,9 @@ class BAUAntiCheat
|
||||
}
|
||||
|
||||
// Check and notify for invalid rpcs
|
||||
public static void CheckRPC(PlayerControl player, byte callId, MessageReader Oldreader)
|
||||
public static void CheckRPC(PlayerControl player, byte callId, MessageReader oldReader)
|
||||
{
|
||||
MessageReader reader = MessageReader.Get(Oldreader);
|
||||
MessageReader reader = MessageReader.Get(oldReader);
|
||||
|
||||
if (player == null || player.IsLocalPlayer() || player.BetterData().IsBetterHost || reader == null || !IsEnabled || !Main.AntiCheat.Value
|
||||
|| GameState.IsBetterHostLobby && !GameState.IsHost || !BetterGameSettings.DetectInvalidRPCs.GetBool()) return;
|
||||
@@ -165,11 +165,11 @@ class BAUAntiCheat
|
||||
}
|
||||
|
||||
// Check notify and cancel out request for invalid rpcs
|
||||
public static bool CheckCancelRPC(PlayerControl player, byte callId, MessageReader Oldreader)
|
||||
public static bool CheckCancelRPC(PlayerControl player, byte callId, MessageReader oldReader)
|
||||
{
|
||||
try
|
||||
{
|
||||
MessageReader reader = MessageReader.Get(Oldreader);
|
||||
MessageReader reader = MessageReader.Get(oldReader);
|
||||
|
||||
if (PlayerControl.LocalPlayer == null || player == null || player.IsLocalPlayer() || player.BetterData().IsBetterHost || reader == null) return true;
|
||||
|
||||
@@ -259,8 +259,10 @@ class BAUAntiCheat
|
||||
}
|
||||
|
||||
// Check game states when sabotaging
|
||||
public static bool RpcUpdateSystemCheck(PlayerControl player, SystemTypes systemType, MessageReader reader)
|
||||
public static bool RpcUpdateSystemCheck(PlayerControl player, SystemTypes systemType, MessageReader oldReader)
|
||||
{
|
||||
MessageReader reader = MessageReader.Get(oldReader);
|
||||
|
||||
RPCHandler.GetHandlerInstance<UpdateSystemHandler>().CatchedSystemType = systemType;
|
||||
return RPCHandler.HandleRPC((byte)RpcCalls.UpdateSystem, player, reader, HandlerFlag.AntiCheatCancel);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using BetterAmongUs.Helpers;
|
||||
using Hazel;
|
||||
using InnerNet;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -12,6 +13,7 @@ public enum HandlerFlag
|
||||
AntiCheatCancel,
|
||||
AntiCheat,
|
||||
BetterHost,
|
||||
HandleGameDataTag
|
||||
}
|
||||
|
||||
public abstract class RPCHandler
|
||||
@@ -25,12 +27,15 @@ public abstract class RPCHandler
|
||||
.Select(t => (RPCHandler?)Activator.CreateInstance(t))
|
||||
.ToArray();
|
||||
|
||||
public abstract byte CallId { get; }
|
||||
public InnerNetClient innerNetClient => DestroyableSingleton<InnerNetClient>.Instance;
|
||||
public virtual byte CallId => byte.MaxValue;
|
||||
public virtual byte GameDataTag => byte.MaxValue;
|
||||
public virtual bool LocalHandling { get; set; }
|
||||
protected static bool CancelAsHost => !(GameState.IsHost);
|
||||
|
||||
public static bool CheckRange(Vector2 pos1, Vector2 pos2, float range) => Vector2.Distance(pos1, pos2) <= range;
|
||||
public virtual void Handle(PlayerControl? sender, MessageReader reader) { }
|
||||
public virtual void HandleGameData(MessageReader reader) { }
|
||||
public virtual void HandleAntiCheatCheck(PlayerControl? sender, MessageReader reader) { }
|
||||
public virtual bool HandleAntiCheatCancel(PlayerControl? sender, MessageReader reader) => true;
|
||||
public virtual void HandleAntiCheat(PlayerControl? sender, MessageReader reader) { }
|
||||
@@ -46,7 +51,7 @@ public abstract class RPCHandler
|
||||
|
||||
foreach (var handler in allHandlers)
|
||||
{
|
||||
if (calledId == handler.CallId)
|
||||
if (calledId == handler.CallId && handlerFlag != HandlerFlag.HandleGameDataTag)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -62,6 +67,17 @@ public abstract class RPCHandler
|
||||
Logger.Error(ex);
|
||||
}
|
||||
}
|
||||
else if (calledId == handler.GameDataTag && handlerFlag == HandlerFlag.HandleGameDataTag)
|
||||
{
|
||||
try
|
||||
{
|
||||
handler.HandleGameData(MessageReader.Get(reader));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !(cancel);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using BetterAmongUs.Helpers;
|
||||
using BetterAmongUs.Managers;
|
||||
using Hazel;
|
||||
|
||||
namespace BetterAmongUs.Modules.AntiCheat;
|
||||
@@ -6,5 +8,24 @@ public class CheckNameHandler : RPCHandler
|
||||
{
|
||||
public override byte CallId => (byte)RpcCalls.CheckName;
|
||||
|
||||
public override bool HandleAntiCheatCancel(PlayerControl? sender, MessageReader reader) => GetHandlerInstance<SetNameHandler>().HandleAntiCheatCancel(sender, reader);
|
||||
public override bool HandleAntiCheatCancel(PlayerControl? sender, MessageReader reader)
|
||||
{
|
||||
if (!GameState.IsHost) return false;
|
||||
|
||||
var name = reader.ReadString();
|
||||
|
||||
if (sender.DataIsCollected() == true && sender.BetterData().AntiCheatInfo.HasSetName && !GameState.IsLocalGame && GameState.IsVanillaServer)
|
||||
{
|
||||
BetterNotificationManager.NotifyCheat(sender, GetFormatSetText());
|
||||
Utils.AddChatPrivate($"{sender.GetPlayerNameAndColor()} Has tried to change their name to '{name}' but has been undone!");
|
||||
Logger.LogCheat($"{sender.BetterData().RealName} Has tried to change their name to '{name}' but has been undone!");
|
||||
LogRpcInfo($"{sender.DataIsCollected() == true} && {!GameState.IsLocalGame} && {GameState.IsVanillaServer}");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.BetterData().AntiCheatInfo.HasSetName = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using BetterAmongUs.Helpers;
|
||||
using BetterAmongUs.Managers;
|
||||
using Hazel;
|
||||
using InnerNet;
|
||||
|
||||
namespace BetterAmongUs.Modules.AntiCheat;
|
||||
|
||||
public class DespawnNetObjectHandler : RPCHandler
|
||||
{
|
||||
public override byte GameDataTag => (byte)HandleGameDataTags.NetObjectDespawn;
|
||||
|
||||
public override void HandleGameData(MessageReader reader)
|
||||
{
|
||||
if (!GameState.IsHost) return;
|
||||
|
||||
uint netId = reader.ReadPackedUInt32();
|
||||
var innerNetObject = innerNetClient.FindObjectByNetId<InnerNetObject>(netId);
|
||||
if (innerNetObject is PlayerControl player)
|
||||
{
|
||||
BetterNotificationManager.NotifyCheat(player, "Attempting to despawn player", kickPlayer: false);
|
||||
player.Kick(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class SetLevelHandler : RPCHandler
|
||||
|
||||
public override bool HandleAntiCheatCancel(PlayerControl? sender, MessageReader reader)
|
||||
{
|
||||
if (sender.DataIsCollected() == true && !GameState.IsLocalGame && GameState.IsVanillaServer)
|
||||
if (sender.DataIsCollected() == true && sender.BetterData().AntiCheatInfo.HasSetLevel && !GameState.IsLocalGame && GameState.IsVanillaServer)
|
||||
{
|
||||
BetterNotificationManager.NotifyCheat(sender, GetFormatSetText());
|
||||
LogRpcInfo($"{sender.DataIsCollected() == true} && {!GameState.IsLocalGame} && {GameState.IsVanillaServer}");
|
||||
@@ -19,6 +19,8 @@ public class SetLevelHandler : RPCHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.BetterData().AntiCheatInfo.HasSetLevel = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,12 @@ public class SetNameHandler : RPCHandler
|
||||
|
||||
public override bool HandleAntiCheatCancel(PlayerControl? sender, MessageReader reader)
|
||||
{
|
||||
if (GameState.IsHost) return false;
|
||||
|
||||
_ = reader.ReadUInt32();
|
||||
var name = reader.ReadString();
|
||||
|
||||
if (sender.DataIsCollected() == true && !GameState.IsLocalGame && GameState.IsVanillaServer)
|
||||
if (sender.DataIsCollected() == true && sender.BetterData().AntiCheatInfo.HasSetName && !GameState.IsLocalGame && GameState.IsVanillaServer)
|
||||
{
|
||||
BetterNotificationManager.NotifyCheat(sender, GetFormatSetText());
|
||||
Utils.AddChatPrivate($"{sender.GetPlayerNameAndColor()} Has tried to change their name to '{name}' but has been undone!");
|
||||
@@ -27,6 +30,8 @@ public class SetNameHandler : RPCHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.BetterData().AntiCheatInfo.HasSetName = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,15 @@ enum CustomRPC : int
|
||||
|
||||
//Better Among Us
|
||||
BetterCheck = 150,
|
||||
}
|
||||
|
||||
enum HandleGameDataTags : byte
|
||||
{
|
||||
NetObjectDeserialize = 1,
|
||||
NetObjectHandleRPC = 2,
|
||||
NetObjectSpawn = 4,
|
||||
NetObjectDespawn = 5,
|
||||
ClientDataReady = 7,
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.HandleRpc))]
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using BetterAmongUs.Items;
|
||||
using BetterAmongUs.Managers;
|
||||
using BetterAmongUs.Modules;
|
||||
using BetterAmongUs.Modules.AntiCheat;
|
||||
using HarmonyLib;
|
||||
using Hazel;
|
||||
using InnerNet;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -129,6 +131,18 @@ public class ClientPatch
|
||||
[HarmonyPatch(typeof(InnerNetClient))]
|
||||
public class InnerNetClientPatch
|
||||
{
|
||||
[HarmonyPatch(nameof(InnerNetClient.HandleGameData))]
|
||||
[HarmonyPrefix]
|
||||
public static void HandleGameDataInner_Prefix(/*InnerNetClient __instance,*/ [HarmonyArgument(0)] MessageReader oldReader)
|
||||
{
|
||||
var parentReader = MessageReader.Get(oldReader);
|
||||
while (parentReader.Position < parentReader.Length)
|
||||
{
|
||||
MessageReader messageReader = parentReader.ReadMessageAsNewBuffer();
|
||||
MessageReader reader = messageReader;
|
||||
RPCHandler.HandleRPC(reader.Tag, null, MessageReader.Get(reader), HandlerFlag.HandleGameDataTag);
|
||||
}
|
||||
}
|
||||
[HarmonyPatch(nameof(InnerNetClient.CanBan))]
|
||||
[HarmonyPrefix]
|
||||
public static bool CanBan_Prefix(ref bool __result)
|
||||
|
||||
@@ -103,6 +103,9 @@ class PlayerControlPatch
|
||||
|
||||
private static string ValidateFriendCode(PlayerControl player, out string color)
|
||||
{
|
||||
color = "#FFFFFF";
|
||||
if (player?.Data == null) return "";
|
||||
|
||||
void TryKick()
|
||||
{
|
||||
if (GameState.IsHost)
|
||||
|
||||
@@ -156,11 +156,14 @@ public class Main : BasePlugin
|
||||
{
|
||||
try
|
||||
{
|
||||
ConsoleManager.DetachConsole();
|
||||
ConsoleManager.CreateConsole();
|
||||
ConsoleManager.ConfigConsoleEnabled.BoxedValue = false;
|
||||
ConsoleManager.SetConsoleTitle("Among Us - BAU Console");
|
||||
ConsoleManager.ConfigPreventClose.Value = true;
|
||||
Logger = BepInEx.Logging.Logger.CreateLogSource(PluginGuid);
|
||||
var customLogListener = new CustomLogListener();
|
||||
BepInEx.Logging.Logger.Listeners.Clear();
|
||||
BepInEx.Logging.Logger.Listeners.Add(customLogListener);
|
||||
ConsoleManager.SetConsoleColor(ConsoleColor.Green);
|
||||
ConsoleManager.ConsoleStream.WriteLine($".--------------------------------------------------------------------------------.\r\n| ____ _ _ _ _ _ |\r\n| | __ ) ___| |_| |_ ___ _ __ / \\ _ __ ___ ___ _ __ __ _ | | | |___ |\r\n| | _ \\ / _ \\ __| __/ _ \\ '__| / _ \\ | '_ ` _ \\ / _ \\| '_ \\ / _` | | | | / __||\r\n| | |_) | __/ |_| || __/ | / ___ \\| | | | | | (_) | | | | (_| | | |_| \\__ \\|\r\n| |____/ \\___|\\__|\\__\\___|_| /_/ \\_\\_| |_| |_|\\___/|_| |_|\\__, | \\___/|___/|\r\n| |___/ |\r\n'--------------------------------------------------------------------------------'");
|
||||
|
||||
Reference in new issue
Block a user