mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
skip better user
This commit is contained in:
1 parent
81f40ebad8
commit
7e1b529dc2
3 files changed
+49
-8
No files matched your search
@@ -25,9 +25,9 @@ static class ExtendedInnerNetClient
|
||||
messageWriter.ForEach(mW => mW.Write("RPC TEST"));
|
||||
AmongUsClient.Instance.FinishRpcDesync(messageWriter);
|
||||
*/
|
||||
public static List<MessageWriter> StartRpcDesync(this InnerNetClient client, uint playerNetId, byte callId, SendOption option, int ignoreClientId = -1)
|
||||
public static List<MessageWriter> StartRpcDesync(this InnerNetClient client, uint playerNetId, byte callId, SendOption option, int ignoreClientId = -1, Func<ClientData, bool> clientCheck = null)
|
||||
{
|
||||
List<MessageWriter> messageWriters = [];
|
||||
List<MessageWriter> messageWriters = new List<MessageWriter>();
|
||||
|
||||
if (ignoreClientId < 0)
|
||||
{
|
||||
@@ -37,13 +37,18 @@ static class ExtendedInnerNetClient
|
||||
{
|
||||
foreach (var allClients in AmongUsClient.Instance.allClients.ToArray().Where(c => c.Id != ignoreClientId))
|
||||
{
|
||||
messageWriters.Add(client.StartRpcImmediately(playerNetId, callId, option, allClients.Id));
|
||||
if (clientCheck == null || clientCheck.Invoke(allClients))
|
||||
{
|
||||
messageWriters.Add(client.StartRpcImmediately(playerNetId, callId, option, allClients.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return messageWriters;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void FinishRpcDesync(this InnerNetClient client, List<MessageWriter> messageWriters)
|
||||
{
|
||||
foreach (var msg in messageWriters)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AmongUs.GameOptions;
|
||||
using InnerNet;
|
||||
|
||||
namespace BetterAmongUs;
|
||||
|
||||
@@ -18,6 +19,7 @@ public static class PlayerControlExtensions
|
||||
{
|
||||
private static readonly Dictionary<NetworkedPlayerInfo, ExtendedPlayerInfo> playerInfo = [];
|
||||
|
||||
// Get BetterData from PlayerControl
|
||||
public static ExtendedPlayerInfo BetterData(this PlayerControl player)
|
||||
{
|
||||
if (!playerInfo.ContainsKey(player.Data))
|
||||
@@ -27,4 +29,33 @@ public static class PlayerControlExtensions
|
||||
|
||||
return playerInfo[player.Data];
|
||||
}
|
||||
|
||||
// Get BetterData from NetworkedPlayerInfo
|
||||
public static ExtendedPlayerInfo BetterData(this NetworkedPlayerInfo info)
|
||||
{
|
||||
if (!playerInfo.ContainsKey(info))
|
||||
{
|
||||
playerInfo[info] = new ExtendedPlayerInfo();
|
||||
}
|
||||
|
||||
return playerInfo[info];
|
||||
}
|
||||
|
||||
// Get BetterData from ClientData
|
||||
public static ExtendedPlayerInfo? BetterData(this ClientData data)
|
||||
{
|
||||
var player = Utils.PlayerFromClientId(data.Id);
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
if (!playerInfo.ContainsKey(player.Data))
|
||||
{
|
||||
playerInfo[player.Data] = new ExtendedPlayerInfo();
|
||||
}
|
||||
|
||||
return playerInfo[player.Data];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,11 @@ public class RoleManagerPatch
|
||||
public static Dictionary<string, int> ImpostorMultiplier = []; // HashPuid, Multiplier
|
||||
private static Random random = new Random();
|
||||
|
||||
static readonly Func<InnerNet.ClientData, bool> clientCheck = (clientData) =>
|
||||
{
|
||||
return clientData?.BetterData()?.IsBetterUser != true;
|
||||
};
|
||||
|
||||
// Better role algorithm
|
||||
[HarmonyPatch(nameof(RoleManager.SelectRoles))]
|
||||
[HarmonyPrefix]
|
||||
@@ -123,14 +128,14 @@ public class RoleManagerPatch
|
||||
// Desync role to other clients to prevent revealing the true role
|
||||
if (IsImpostorRole(role) && role is not RoleTypes.Phantom)
|
||||
{
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId());
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck);
|
||||
messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Impostor));
|
||||
messageWriter.ForEach(mW => mW.Write(false));
|
||||
AmongUsClient.Instance.FinishRpcDesync(messageWriter);
|
||||
}
|
||||
else if (role is not RoleTypes.Noisemaker)
|
||||
{
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId());
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck);
|
||||
messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Crewmate));
|
||||
messageWriter.ForEach(mW => mW.Write(false));
|
||||
AmongUsClient.Instance.FinishRpcDesync(messageWriter);
|
||||
@@ -176,7 +181,7 @@ public class RoleManagerPatch
|
||||
// Desync role to other clients to prevent revealing the true role
|
||||
if (kvp.Key is not RoleTypes.Phantom)
|
||||
{
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(pc.NetId, (byte)RpcCalls.SetRole, SendOption.None, pc.GetClientId());
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(pc.NetId, (byte)RpcCalls.SetRole, SendOption.None, pc.GetClientId(), clientCheck);
|
||||
messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Impostor));
|
||||
messageWriter.ForEach(mW => mW.Write(false));
|
||||
AmongUsClient.Instance.FinishRpcDesync(messageWriter);
|
||||
@@ -210,7 +215,7 @@ public class RoleManagerPatch
|
||||
// Desync role to other clients to prevent revealing the true role
|
||||
if (kvp.Key is not RoleTypes.Noisemaker)
|
||||
{
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(pc.NetId, (byte)RpcCalls.SetRole, SendOption.None, pc.GetClientId());
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(pc.NetId, (byte)RpcCalls.SetRole, SendOption.None, pc.GetClientId(), clientCheck);
|
||||
messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Crewmate));
|
||||
messageWriter.ForEach(mW => mW.Write(false));
|
||||
AmongUsClient.Instance.FinishRpcDesync(messageWriter);
|
||||
@@ -283,7 +288,7 @@ public class RoleManagerPatch
|
||||
{
|
||||
player.RpcSetRole(kvp.Key);
|
||||
// Desync role to other clients to prevent revealing the true role
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId());
|
||||
List<MessageWriter> messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck);
|
||||
messageWriter.ForEach(mW => mW.Write((ushort)player.Data.Role.DefaultGhostRole));
|
||||
messageWriter.ForEach(mW => mW.Write(false));
|
||||
AmongUsClient.Instance.FinishRpcDesync(messageWriter);
|
||||
|
||||
Reference in new issue
Block a user