Add code to make sure to not exceed new rate limits

This commit is contained in:
Gurge44 committed 2026-04-17 09:21:00 +02:00
1 parent ce05a2cd2c
commit 2c854192a9
6 files changed
+64 -32

No files matched your search

+8 -5
View File
@@ -319,13 +319,16 @@ public static class CaptureTheFlag
void ResetSkins()
{
foreach ((byte key, NetworkedPlayerInfo.PlayerOutfit outfit) in DefaultOutfits)
Utils.CombineSendTimeLowering(() =>
{
PlayerControl pc = key.GetPlayer();
foreach ((byte key, NetworkedPlayerInfo.PlayerOutfit outfit) in DefaultOutfits)
{
PlayerControl pc = key.GetPlayer();
if (pc && outfit != null)
Utils.RpcChangeSkin(pc, outfit);
}
if (pc && outfit != null)
Utils.RpcChangeSkin(pc, outfit);
}
});
}
}
+2 -2
View File
@@ -645,7 +645,7 @@ public static class KingOfTheZones
}
}
void ResetSkins() => DefaultOutfits.Select(x => (pc: x.Key.GetPlayer(), outfit: x.Value)).DoIf(x => x.pc && x.outfit != null, x => Utils.RpcChangeSkin(x.pc, x.outfit));
void ResetSkins() => Utils.CombineSendTimeLowering(() => DefaultOutfits.Select(x => (pc: x.Key.GetPlayer(), outfit: x.Value)).DoIf(x => x.pc && x.outfit != null, x => Utils.RpcChangeSkin(x.pc, x.outfit)));
}
public static bool IsNotInLocalPlayersTeam(PlayerControl pc)
@@ -949,7 +949,7 @@ public static class KingOfTheZones
{
if (tie) return;
GameGoing = false;
DefaultOutfits.Select(x => (pc: x.Key.GetPlayer(), outfit: x.Value)).DoIf(x => x.pc && x.outfit != null, x => Utils.RpcChangeSkin(x.pc, x.outfit));
Utils.CombineSendTimeLowering(() => DefaultOutfits.Select(x => (pc: x.Key.GetPlayer(), outfit: x.Value)).DoIf(x => x.pc && x.outfit != null, x => Utils.RpcChangeSkin(x.pc, x.outfit)));
KOTZTeam winner = Points.GetKeyByValue(highestPoints);
CustomWinnerHolder.WinnerIds = PlayerTeams.Where(x => x.Value == winner).Select(x => x.Key).ToHashSet();
Color color = winner.GetColor();
+7
View File
@@ -24,6 +24,7 @@ internal static class ExtendedPlayerControl
public static readonly HashSet<byte> CancelBlackScreenFix = [];
private static readonly List<Vent> ResultBuffer = [];
public static readonly HashSet<byte> TempExiled = [];
public static bool DontLowerSendTimer;
extension(PlayerControl player)
{
@@ -250,6 +251,9 @@ internal static class ExtendedPlayerControl
writer.EndMessage();
AmongUsClient.Instance.SendOrDisconnect(writer);
writer.Recycle();
if (DontLowerSendTimer) return;
AmongUsClient.Instance.timer -= AmongUsClient.Instance.MinSendInterval;
}
public ClientData GetClient()
@@ -2443,6 +2447,9 @@ internal static class ExtendedPlayerControl
writer.EndMessage();
AmongUsClient.Instance.SendOrDisconnect(writer);
writer.Recycle();
if (DontLowerSendTimer) return;
AmongUsClient.Instance.timer -= AmongUsClient.Instance.MinSendInterval;
}
}
+18 -4
View File
@@ -3486,8 +3486,7 @@ public static class Utils
return true;
}
/*
public static void SendGameData()
{
int messages = 0;
@@ -3520,8 +3519,9 @@ public static class Utils
writer.EndMessage();
AmongUsClient.Instance.SendOrDisconnect(writer);
writer.Recycle();
AmongUsClient.Instance.timer -= AmongUsClient.Instance.MinSendInterval;
}
*/
public static void SendGameDataTo(int targetClientId)
{
@@ -4508,7 +4508,21 @@ public static class Utils
}
}
aapc.Do(x => x.SetChatVisible(true));
CombineSendTimeLowering(() => aapc.Do(x => x.SetChatVisible(true)));
}
/// <summary>
/// Wraps code to run while <see cref="ExtendedPlayerControl.DontLowerSendTimer"/> is set to true, then lowers the sending timer once.
/// </summary>
public static void CombineSendTimeLowering([Annotations.InstantHandle] Action action)
{
ExtendedPlayerControl.DontLowerSendTimer = true;
try { action(); }
catch (Exception e) { ThrowException(e); }
ExtendedPlayerControl.DontLowerSendTimer = false;
AmongUsClient.Instance.timer -= AmongUsClient.Instance.MinSendInterval;
}
public static bool TryCast<T>(this Il2CppObjectBase obj, out T casted) where T : Il2CppObjectBase
+5 -3
View File
@@ -1142,8 +1142,9 @@ internal static class StartGameHostPatch
yield return null;
pc.Data.Disconnected = true;
pc.Data.SendGameData();
}
Utils.SendGameData();
Logger.Info("Successfully set everyone's data as Disconnected", "StartGameHost");
@@ -1159,12 +1160,13 @@ internal static class StartGameHostPatch
foreach (PlayerControl pc in PlayerControl.AllPlayerControls)
{
if (pc == null || pc.Data == null) continue;
if (!pc || !pc.Data) continue;
bool disconnected = Main.PlayerStates.TryGetValue(pc.PlayerId, out var state) && state.IsDead && state.deathReason == PlayerState.DeathReason.Disconnected;
pc.Data.Disconnected = disconnected;
if (!disconnected) pc.Data.SendGameData();
}
Utils.SendGameData();
}
private static bool IsBasisChangingPlayer(byte id, CustomRoles role)
+24 -18
View File
@@ -1472,33 +1472,39 @@ internal static class ReportDeadBodyPatch
{
Main.ProcessShapeshifts = false;
foreach (PlayerControl pc in Main.EnumeratePlayerControls())
void Action()
{
try
foreach (PlayerControl pc in Main.EnumeratePlayerControls())
{
if (pc.IsAlive())
try
{
if (Camouflage.IsCamouflage && !Magistrate.CallCourtNextMeeting && !Doppelganger.DoppelVictim.ContainsKey(pc.PlayerId))
Camouflage.RpcSetSkin(pc, revertToDefault: true, forceRevert: true);
if (Magistrate.CallCourtNextMeeting)
if (pc.IsAlive())
{
string name = pc.GetRealName();
RpcChangeSkin(pc, new NetworkedPlayerInfo.PlayerOutfit().Set(name, 15, "", "", "", "", ""));
}
if (Camouflage.IsCamouflage && !Magistrate.CallCourtNextMeeting && !Doppelganger.DoppelVictim.ContainsKey(pc.PlayerId))
Camouflage.RpcSetSkin(pc, revertToDefault: true, forceRevert: true);
if (Main.CheckShapeshift.ContainsKey(pc.PlayerId))
pc.RpcShapeshift(pc, false);
if (pc.Is(CustomRoles.Truant))
Main.AllPlayerSpeed[pc.PlayerId] = Main.MinSpeed;
if (Magistrate.CallCourtNextMeeting)
{
string name = pc.GetRealName();
RpcChangeSkin(pc, new NetworkedPlayerInfo.PlayerOutfit().Set(name, 15, "", "", "", "", ""));
}
if (Main.CheckShapeshift.ContainsKey(pc.PlayerId))
pc.RpcShapeshift(pc, false);
if (pc.Is(CustomRoles.Truant))
Main.AllPlayerSpeed[pc.PlayerId] = Main.MinSpeed;
}
else if (!pc.Data.IsDead && (!pc.AmOwner || !TempReviveHostRunning))
pc.RpcExileV2();
}
else if (!pc.Data.IsDead && (!pc.AmOwner || !TempReviveHostRunning))
pc.RpcExileV2();
catch (Exception e) { ThrowException(e); }
}
catch (Exception e) { ThrowException(e); }
}
if (!Camouflage.IsCamouflage && !Magistrate.CallCourtNextMeeting) Action();
else CombineSendTimeLowering(Action);
RPCHandlerPatch.RemoveExpiredWhiteList();
Camouflage.CamoTimesThisRound = 0;