Skip to content
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

Set spamms CustomRPC to SendOption.None & Remove Unused #1505

Merged
merged 6 commits into from
Mar 1, 2025
Merged
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
6 changes: 3 additions & 3 deletions Modules/ExtendedPlayerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static void RpcExileDesync(this PlayerControl player, PlayerControl seer)
player.Exiled();
return;
}
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.Exiled, SendOption.None, clientId);
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.Exiled, SendOption.Reliable, clientId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
public static void RpcExileV2(this PlayerControl player)
Expand All @@ -348,7 +348,7 @@ public static void RpcExileV2(this PlayerControl player)
}
player.Exiled();

MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.Exiled, SendOption.None, -1);
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.Exiled, SendOption.Reliable, -1);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
public static void RpcCastVote(this PlayerControl player, byte suspectIdx)
Expand Down Expand Up @@ -830,7 +830,7 @@ public static void RpcResetAbilityCooldown(this PlayerControl target)
}
else
{
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(target.NetId, (byte)RpcCalls.ProtectPlayer, SendOption.None, target.GetClientId());
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(target.NetId, (byte)RpcCalls.ProtectPlayer, RpcSendOption, target.GetClientId());
writer.WriteNetObject(target);
writer.Write(0);
AmongUsClient.Instance.FinishRpcImmediately(writer);
Expand Down
53 changes: 11 additions & 42 deletions Modules/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
namespace TOHE;

[Obfuscation(Exclude = true)]
public enum CustomRPC : byte // 184/255 USED
public enum CustomRPC : byte // 174/255 USED
{
// RpcCalls can increase with each AU version
// On version 2024.6.18 the last id in RpcCalls: 65

// Adding Role rpcs that overrides TOHE section and changing BetterCheck will be rejected
// Sync Role Skill can be used under most cases so you should not make a new rpc unless it's necessary
// NOTE: Set RPC's that are spammed to "ExtendedPlayerControl.RpcSendOption" to prevent kick due innersloth anti-cheat

VersionCheck = 80,
RequestRetryVersionCheck = 81,
SyncCustomSettings = 100, // AUM use 101 rpc
Expand All @@ -41,12 +43,11 @@ public enum CustomRPC : byte // 184/255 USED
ShowPopUp,
KillFlash,
DumpLog,
SyncRoleSkill,
SetNameColorData,
GuessKill,
Judge,
KNChat = 119, // Kill network chat, may conflicts with judge and guess calls
Guess,
KNChat = 119, // Kill network chat, may conflicts with judge and guess calls
CouncillorJudge,
NemesisRevenge,
RetributionistRevenge,
Expand All @@ -65,55 +66,47 @@ public enum CustomRPC : byte // 184/255 USED
SyncAbilityUseLimit,

//Roles
SyncRoleSkill,
SetBountyTarget,
SyncPuppet,
SyncKami,
SetKillOrSpell,
SetKillOrHex,
SetKillOrCurse,
SetDousedPlayer,
DoSpell,
DoHex,
DoCurse,
SniperSync,
SetLoversPlayers,
SendFireworkerState,
SetCurrentDousingTarget,
SetEvilTrackerTarget,
SetDrawPlayer,

// BetterAmongUs (BAU) RPC, This is sent to allow other BAU users know who's using BAU!
BetterCheck = 150,

SetCurrentDousingTarget,
SetEvilTrackerTarget,
SetDrawPlayer,
SetCrewpostorTasksDone,
SetCurrentDrawTarget,
RpcPassBomb,
SyncRomanticTarget,
SyncVengefulRomanticTarget,
SyncJailerData,
SetInspectorLimit,
KeeperRPC,
SetAlchemistTimer,
UndertakerLocationSync,
LightningSetGhostPlayer,
SetDarkHiderKillCount,
SetConsigliere,
SetGreedy,
BenefactorRPC,
SetSwapperVotes,
SetMarkedPlayer,
SetConcealerTimer,
PresidentEnd,
PresidentReveal,
SetBKTimer,
SetInvestgatorLimit,
SetOverseerRevealedPlayer,
SetOverseerTimer,
SetChameleonTimer,
SyncAdmiredList,
SetImitateLimit,
DictatorRPC,
Necronomicon,

//FFA
SyncFFAPlayer,
SyncFFANameNotify,
Expand Down Expand Up @@ -1048,32 +1041,8 @@ public static void Prefix(/*InnerNet.InnerNetClient __instance,*/ [HarmonyArgume
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.StartRpcImmediately))]
public class StartRpcImmediatelyPatch
{
public static bool Prefix(InnerNetClient __instance, [HarmonyArgument(0)] uint targetNetId, [HarmonyArgument(1)] byte callId, [HarmonyArgument(2)] SendOption option, [HarmonyArgument(3)] int targetClientId, ref MessageWriter __result)
public static void Prefix(InnerNetClient __instance, [HarmonyArgument(0)] uint targetNetId, [HarmonyArgument(1)] byte callId, [HarmonyArgument(2)] SendOption option, [HarmonyArgument(3)] int targetClientId)
{
if (callId < (byte)CustomRPC.VersionCheck || !AmongUsClient.Instance.AmHost || !GameStates.IsVanillaServer || GameStates.IsLocalGame || option is SendOption.None)
{
RPC.SendRpcLogger(targetNetId, callId, option, targetClientId);
return true;
}

MessageWriter messageWriter = MessageWriter.Get(SendOption.None);
if (targetClientId < 0)
{
messageWriter.StartMessage(5);
messageWriter.Write(AmongUsClient.Instance.GameId);
}
else
{
messageWriter.StartMessage(6);
messageWriter.Write(AmongUsClient.Instance.GameId);
messageWriter.WritePacked(targetClientId);
}
messageWriter.StartMessage(2);
messageWriter.WritePacked(targetNetId);
messageWriter.Write(callId);

__result = messageWriter;
RPC.SendRpcLogger(targetNetId, callId, SendOption.None, targetClientId);
return false;
RPC.SendRpcLogger(targetNetId, callId, option, targetClientId);
}
}
2 changes: 1 addition & 1 deletion Roles/Coven/PotionMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public override bool OnCheckMurderAsKiller(PlayerControl killer, PlayerControl t
}

public static bool IsReveal(byte seer, byte target) => RevealList[seer].Contains(target);
private void SetRitual(PlayerControl killer, PlayerControl target)
private static void SetRitual(PlayerControl killer, PlayerControl target)
{
switch (PotionMode)
{
Expand Down
2 changes: 1 addition & 1 deletion Roles/Coven/Sacrifist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public override void Add(byte playerId)
maxDebuffTimer = DebuffCooldown.GetFloat();
VisionChange[playerId] = [];
}
public void SendRPC(PlayerControl pc)
private static void SendRPC(PlayerControl pc)
{
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncRoleSkill, SendOption.Reliable, pc.GetClientId());
writer.Write(DebuffID);
Expand Down
4 changes: 2 additions & 2 deletions Roles/Crewmate/Alchemist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public override bool OnTaskComplete(PlayerControl player, int completedTaskCount

private static void SendRPC(PlayerControl pc)
{
if (pc.IsHost()) return;
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetAlchemistTimer, SendOption.Reliable, pc.GetClientId());
if (!pc.IsNonHostModdedClient()) return;
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetAlchemistTimer, ExtendedPlayerControl.RpcSendOption, pc.GetClientId());
writer.Write(FixNextSabo);
writer.Write(PotionID);
writer.Write((InvisTime.TryGetValue(pc.PlayerId, out var x) ? x : -1).ToString());
Expand Down
3 changes: 2 additions & 1 deletion Roles/Crewmate/Chameleon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public override void Add(byte playerId)
}
public static void SendRPC(PlayerControl pc)
{
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetChameleonTimer, SendOption.Reliable, pc.GetClientId());
if (!pc.IsNonHostModdedClient()) return;
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetChameleonTimer, ExtendedPlayerControl.RpcSendOption, pc.GetClientId());
writer.Write(pc.PlayerId);
writer.Write((InvisCooldown.TryGetValue(pc.PlayerId, out var y) ? y : -1).ToString());
writer.Write((InvisDuration.TryGetValue(pc.PlayerId, out var x) ? x : -1).ToString());
Expand Down
2 changes: 1 addition & 1 deletion Roles/Crewmate/Overseer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public override void Remove(byte playerId)

private static void SendTimerRPC(byte RpcType, byte overseertId, PlayerControl target = null, float timer = 0)
{
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetOverseerTimer, SendOption.Reliable, -1);
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetOverseerTimer, ExtendedPlayerControl.RpcSendOption);
writer.Write(RpcType);
writer.Write(overseertId);
if (target != null && RpcType == 1)
Expand Down
2 changes: 1 addition & 1 deletion Roles/Impostor/Swooper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Add(byte playerId)
private void SendRPC(PlayerControl pc)
{
if (!pc.IsNonHostModdedClient()) return;
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncRoleSkill, SendOption.Reliable, pc.GetClientId());
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncRoleSkill, ExtendedPlayerControl.RpcSendOption, pc.GetClientId());
writer.WriteNetObject(_Player);
writer.Write(InvisCooldown.GetValueOrDefault(pc.PlayerId, -1).ToString());
writer.Write(InvisDuration.GetValueOrDefault(pc.PlayerId, -1).ToString());
Expand Down
2 changes: 1 addition & 1 deletion Roles/Neutral/Wraith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override void Init()
private void SendRPC(PlayerControl pc)
{
if (!pc.IsNonHostModdedClient()) return;
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncRoleSkill, SendOption.Reliable, pc.GetClientId());
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncRoleSkill, ExtendedPlayerControl.RpcSendOption, pc.GetClientId());
writer.WriteNetObject(_Player);//SetWraithTimer
writer.Write((InvisTime.TryGetValue(pc.PlayerId, out var x) ? x : -1).ToString());
writer.Write((lastTime.TryGetValue(pc.PlayerId, out var y) ? y : -1).ToString());
Expand Down