Skip to content

Fixed Moon Dancer losing baton pass after gaining Necronomicon #1603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: dev_2.3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Patches/InnerNetClientPatch.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Hazel;
using InnerNet;
using TOHE.Modules;
Expand All @@ -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
{
Expand Down
56 changes: 56 additions & 0 deletions Patches/InnerNetServerPatch.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
2 changes: 1 addition & 1 deletion Patches/PlayerJoinAndLeftPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Patches/onGameStartedPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
66 changes: 38 additions & 28 deletions Roles/Coven/MoonDancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Loading