diff --git a/Patches/InnerNetClientPatch.cs b/Patches/InnerNetClientPatch.cs index c4744fd7cd..b752150a79 100644 --- a/Patches/InnerNetClientPatch.cs +++ b/Patches/InnerNetClientPatch.cs @@ -1,3 +1,4 @@ +using System; using Hazel; using InnerNet; using TOHE.Modules; @@ -19,6 +20,52 @@ public enum GameDataTag : byte XboxDeclareXuid = 207, } +[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.HandleMessage))] +class ClientHandleMessagePatch +{ + public static void Prefix(InnerNetClient __instance, MessageReader reader, SendOption sendOption) + { + try + { + if (reader.Tag == 3) // Tags.RemoveGame = 3 + { + DisconnectReasons disconnectReasons = DisconnectReasons.ServerRequest; + if (reader.Position < reader.Length) + { + disconnectReasons = (DisconnectReasons)reader.ReadByte(); + } + + var extraBytes = ""; + while (reader.Position < reader.Length) + { + extraBytes += reader.ReadByte().ToString(); + extraBytes += " "; + if (extraBytes.Length > 32) break; + } + if (extraBytes == "") extraBytes = "None"; + + Logger.Info($"{__instance.ClientId} was disconnected on client-side / Reason: {disconnectReasons} / Junk Bytes: {extraBytes}", "ClientHandleMessagePatch Tag3"); + + __instance.EnqueueDisconnect(disconnectReasons, null); + + return; + } + else if (reader.Tag == 4) + { + Logger.Info($"{__instance.ClientId} was disconnected by server.", "ClientHandleMessagePatch Tag4"); + } + else + { + Logger.Info($"Received message with code {reader.Tag} from {__instance.ClientId}.", "ServerHandleMessagePatch"); + } + } + catch (Exception e) + { + Logger.Error($"Couldn't get disconnect info / Error: {e.Message}", "ClientHandleMessagePatch"); + } + } +} + [HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.HandleGameDataInner))] internal class GameDataHandlerPatch { diff --git a/Patches/InnerNetServerPatch.cs b/Patches/InnerNetServerPatch.cs new file mode 100644 index 0000000000..fec3d2659a --- /dev/null +++ b/Patches/InnerNetServerPatch.cs @@ -0,0 +1,56 @@ +using System; +using Hazel; +using InnerNet; +using static TOHE.Translator; + +namespace TOHE; + +[HarmonyPatch(typeof(InnerNetServer), nameof(InnerNetServer.HandleMessage))] +class ServerHandleMessagePatch +{ + public static void Prefix(InnerNetServer __instance, InnerNetServer.Player client, MessageReader reader, SendOption sendOption) + { + try + { + if (reader.Tag == 3) // Tags.RemoveGame = 3 + { + if (reader.ReadInt32() == 32) + { + var extraBytes = ""; + while (reader.Position < reader.Length) + { + extraBytes += reader.ReadByte().ToString(); + extraBytes += " "; + if (extraBytes.Length > 32) break; + } + if (extraBytes == "") extraBytes = "None"; + Logger.Info($"{client?.PlayerName} was disconnected on server-side. Junk Bytes: {extraBytes}", "ServerHandleMessagePatch"); + + __instance.ClientDisconnect(client); + return; + } + else + { + var extraBytes = ""; + while (reader.Position < reader.Length) + { + extraBytes += reader.ReadByte().ToString(); + extraBytes += " "; + if (extraBytes.Length > 32) break; + } + if (extraBytes == "") extraBytes = "None"; + Logger.Info($"{client?.PlayerName} was disconnected on server-side. Junk Bytes: {extraBytes}", "ServerHandleMessagePatch"); + return; + } + } + else + { + Logger.Info($"Received message with code {reader.Tag} from {client?.PlayerName}.", "ServerHandleMessagePatch"); + } + } + catch (Exception e) + { + Logger.Error($"Couldn't get disconnect info / Error: {e.Message}", "ServerHandleMessagePatch"); + } + } +} diff --git a/Patches/PlayerJoinAndLeftPatch.cs b/Patches/PlayerJoinAndLeftPatch.cs index 1e4f528555..88dbc1aa76 100644 --- a/Patches/PlayerJoinAndLeftPatch.cs +++ b/Patches/PlayerJoinAndLeftPatch.cs @@ -501,7 +501,7 @@ public static void Postfix(AmongUsClient __instance, [HarmonyArgument(0)] Client break; } - Logger.Info($"{data?.PlayerName} - (ClientID:{data?.Id} / FriendCode:{data?.FriendCode} / HashPuid:{data?.GetHashedPuid()} / Platform:{data?.PlatformData.Platform}) Disconnect (Reason:{reason}´╝îPing:{AmongUsClient.Instance.Ping})", "Session OnPlayerLeftPatch"); + Logger.Info($"{data?.PlayerName} - (ClientID:{data?.Id} / FriendCode:{data?.FriendCode} / HashPuid:{data?.GetHashedPuid()} / Platform:{data?.PlatformData.Platform}) Disconnect (Reason:{reason} / Ping:{AmongUsClient.Instance.Ping})", "Session OnPlayerLeftPatch"); // End the game when a player exits game during assigning roles (AntiBlackOut Protect) if (Main.AssignRolesIsStarted) diff --git a/Patches/onGameStartedPatch.cs b/Patches/onGameStartedPatch.cs index 443a372a71..aba0dbf6b9 100644 --- a/Patches/onGameStartedPatch.cs +++ b/Patches/onGameStartedPatch.cs @@ -349,6 +349,7 @@ public static System.Collections.IEnumerator StartGameHost() else { thiz.SendLateRejection(clientData.Id, DisconnectReasons.ClientTimeout); + Logger.Info($"{clientData.Id} timed out.", "StartGameHost"); clientData.IsReady = true; thiz.OnPlayerLeft(clientData, DisconnectReasons.ClientTimeout); } diff --git a/Roles/Coven/MoonDancer.cs b/Roles/Coven/MoonDancer.cs index fbbeaa7bd4..35a89771e1 100644 --- a/Roles/Coven/MoonDancer.cs +++ b/Roles/Coven/MoonDancer.cs @@ -154,42 +154,52 @@ private void BlastPlayer(PlayerControl pc, PlayerControl target) public override bool OnCheckMurderAsKiller(PlayerControl killer, PlayerControl target) { if (killer == null || target == null) return false; - if (HasNecronomicon(killer)) + if (killer.CheckDoubleTrigger(target, () => { SetBatonPass(killer, target); })) { - var rd = IRandom.Instance; - if (target.GetCustomRole().IsCovenTeam()) + if (HasNecronomicon(killer)) { - killer.Notify(GetString("MoonDancerCantBlastOff")); - return false; - } - if (rd.Next(0, 101) < BlastOffChance.GetInt()) - { - if (CanBlast(killer, target.PlayerId)) + var rd = IRandom.Instance; + if (target.GetCustomRole().IsCovenTeam()) { - BlastPlayer(killer, target); - if (!DisableShieldAnimations.GetBool()) killer.RpcGuardAndKill(killer); - killer.ResetKillCooldown(); - killer.SetKillCooldown(); - killer.RPCPlayCustomSound("BlastOff"); - target.RPCPlayCustomSound("BlastOff"); + killer.Notify(GetString("MoonDancerCantBlastOff")); + return false; } - else + if (rd.Next(0, 101) < BlastOffChance.GetInt()) { - killer.ResetKillCooldown(); - killer.SetKillCooldown(); - killer.Notify(GetString("MoonDancerCantBlastOff")); + if (CanBlast(killer, target.PlayerId)) + { + BlastPlayer(killer, target); + if (!DisableShieldAnimations.GetBool()) killer.RpcGuardAndKill(killer); + killer.ResetKillCooldown(); + killer.SetKillCooldown(); + killer.RPCPlayCustomSound("BlastOff"); + target.RPCPlayCustomSound("BlastOff"); + } + else + { + killer.ResetKillCooldown(); + killer.SetKillCooldown(); + killer.Notify(GetString("MoonDancerCantBlastOff")); + } + return false; } - return false; - } - else - { - _ = new LateTask(() => + else { - killer.Notify(GetString("MoonDancerNormalKill")); - }, target.Is(CustomRoles.Burst) ? Burst.BurstKillDelay.GetFloat() : 0f, "BurstKillCheck"); - return true; + _ = new LateTask(() => + { + killer.Notify(GetString("MoonDancerNormalKill")); + }, target.Is(CustomRoles.Burst) ? Burst.BurstKillDelay.GetFloat() : 0f, "BurstKillCheck"); + return true; + } } } + + return false; + } + + private static void SetBatonPass(PlayerControl killer, PlayerControl target) + { + if (killer == null || target == null) return; if (target.GetCustomRole().IsCovenTeam()) { BatonPassList[killer.PlayerId].Add(target.PlayerId); @@ -200,9 +210,9 @@ public override bool OnCheckMurderAsKiller(PlayerControl killer, PlayerControl t BatonPassList[killer.PlayerId].Add(target.PlayerId); killer.Notify(GetString("MoonDancerGiveHarmfulAddon")); } + killer.ResetKillCooldown(); killer.SetKillCooldown(); - return false; } public override void OnReportDeadBody(PlayerControl reporter, NetworkedPlayerInfo target)