even more rpc merging

This commit is contained in:
Gurge44 committed 2025-04-06 13:13:59 +02:00
1 parent f2fe5e0239
commit b13f06e187
12 files changed
+94 -46

No files matched your search

+1 -1
View File
@@ -385,7 +385,7 @@ internal static class FreeForAll
public static void UpdateLastChatMessage(string playerName, string message)
{
LatestChatMessage = string.Format(GetString("FFAChatMessageNotify"), playerName, message);
foreach (PlayerControl pc in Main.AllAlivePlayerControls) pc.Notify(LatestChatMessage);
Main.AllAlivePlayerControls.NotifyPlayers(LatestChatMessage);
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.FixedUpdate))]
+16 -2
View File
@@ -267,8 +267,22 @@ public static class CollectionExtensions
public static void NotifyPlayers(this IEnumerable<PlayerControl> players, string text, float time = 6f, bool overrideAll = false, bool log = true, bool setName = true)
{
var sender = CustomRpcSender.Create("NotifyPlayers", SendOption.Reliable);
players.Do(x => sender.Notify(x, text, time, overrideAll, log, setName));
sender.SendMessage();
var hasValue = false;
foreach (PlayerControl player in players)
{
sender.Notify(player, text, time, overrideAll, log, setName);
hasValue = true;
if (sender.stream.Length > 800)
{
sender.SendMessage();
sender = CustomRpcSender.Create("NotifyPlayers", SendOption.Reliable);
hasValue = false;
}
}
sender.SendMessage(dispose: !hasValue);
}
#region ToValidPlayers
+45 -23
View File
@@ -1132,19 +1132,26 @@ public static class Utils
public static void ShowActiveSettingsHelp(byte PlayerId = byte.MaxValue)
{
SendMessage(GetString("CurrentActiveSettingsHelp") + ":", PlayerId);
var sender = CustomRpcSender.Create("ShowActiveSettingsHelp", SendOption.Reliable);
if (Options.DisableDevices.GetBool()) SendMessage(GetString("DisableDevicesInfo"), PlayerId);
if (Options.SyncButtonMode.GetBool()) SendMessage(GetString("SyncButtonModeInfo"), PlayerId);
if (Options.SabotageTimeControl.GetBool()) SendMessage(GetString("SabotageTimeControlInfo"), PlayerId);
if (Options.RandomMapsMode.GetBool()) SendMessage(GetString("RandomMapsModeInfo"), PlayerId);
SendMessage(GetString("CurrentActiveSettingsHelp") + ":", PlayerId, writer: sender, multiple: true);
if (Main.GM.Value) SendMessage(GetRoleName(CustomRoles.GM) + GetString("GMInfoLong"), PlayerId);
if (Options.DisableDevices.GetBool()) SendMessage(GetString("DisableDevicesInfo"), PlayerId, writer: sender, multiple: true);
if (Options.SyncButtonMode.GetBool()) SendMessage(GetString("SyncButtonModeInfo"), PlayerId, writer: sender, multiple: true);
if (Options.SabotageTimeControl.GetBool()) SendMessage(GetString("SabotageTimeControlInfo"), PlayerId, writer: sender, multiple: true);
if (Options.RandomMapsMode.GetBool()) SendMessage(GetString("RandomMapsModeInfo"), PlayerId, writer: sender, multiple: true);
foreach (CustomRoles role in Enum.GetValues<CustomRoles>().Where(role => role.IsEnable() && !role.IsVanilla()))
SendMessage(GetRoleName(role) + GetRoleMode(role) + GetString($"{role}InfoLong"), PlayerId);
if (Main.GM.Value) SendMessage(GetRoleName(CustomRoles.GM) + GetString("GMInfoLong"), PlayerId, writer: sender, multiple: true);
if (Options.NoGameEnd.GetBool()) SendMessage(GetString("NoGameEndInfo"), PlayerId);
foreach (CustomRoles role in Enum.GetValues<CustomRoles>())
{
if (role.IsEnable() && !role.IsVanilla())
SendMessage(GetRoleName(role) + GetRoleMode(role) + GetString($"{role}InfoLong"), PlayerId, writer: sender, multiple: true);
}
if (Options.NoGameEnd.GetBool()) SendMessage(GetString("NoGameEndInfo"), PlayerId, writer: sender, multiple: true);
sender.SendMessage(dispose: sender.stream.Length == 0);
}
/// <summary>
@@ -1335,13 +1342,15 @@ public static class Utils
}
}
SendMessage($"<size=80%>{sb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("GMRoles"));
SendMessage($"<size=80%>{impsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, ColorString(GetRoleColor(CustomRoles.Impostor), GetString("ImpostorRoles")));
SendMessage($"<size=80%>{crewsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, ColorString(GetRoleColor(CustomRoles.Crewmate), GetString("CrewmateRoles")));
SendMessage($"<size=80%>{neutralsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("NeutralRoles"));
SendMessage($"<size=80%>{covensb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("CovenRoles"));
SendMessage($"<size=80%>{ghostsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("GhostRoles"));
SendMessage($"<size=80%>{addonsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("AddonRoles"));
var sender = CustomRpcSender.Create("ShowActiveRoles", SendOption.Reliable);
SendMessage($"<size=80%>{sb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("GMRoles"), writer: sender, multiple: true);
SendMessage($"<size=80%>{impsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, ColorString(GetRoleColor(CustomRoles.Impostor), GetString("ImpostorRoles")), writer: sender, multiple: true);
SendMessage($"<size=80%>{crewsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, ColorString(GetRoleColor(CustomRoles.Crewmate), GetString("CrewmateRoles")), writer: sender, multiple: true);
SendMessage($"<size=80%>{neutralsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("NeutralRoles"), writer: sender, multiple: true);
SendMessage($"<size=80%>{covensb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("CovenRoles"), writer: sender, multiple: true);
SendMessage($"<size=80%>{ghostsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("GhostRoles"), writer: sender, multiple: true);
SendMessage($"<size=80%>{addonsb.Append("\n.").ToString().RemoveHtmlTags()}</size>", PlayerId, GetString("AddonRoles"), writer: sender, multiple: true);
sender.SendMessage(dispose: sender.stream.Length == 0);
}
public static void ShowChildrenSettings(OptionItem option, ref StringBuilder sb, int deep = 0, bool f1 = false, bool disableColor = true)
@@ -1694,7 +1703,7 @@ public static class Utils
catch (Exception e) { ThrowException(e); }
}
public static void SendMessage(string text, byte sendTo = byte.MaxValue, string title = "", bool noSplit = false, CustomRpcSender writer = null, bool final = false)
public static void SendMessage(string text, byte sendTo = byte.MaxValue, string title = "", bool noSplit = false, CustomRpcSender writer = null, bool final = false, bool multiple = false)
{
PlayerControl receiver = GetPlayerById(sendTo, false);
if (sendTo != byte.MaxValue && receiver == null) return;
@@ -1702,7 +1711,7 @@ public static class Utils
if (!AmongUsClient.Instance.AmHost)
{
if (sendTo == PlayerControl.LocalPlayer.PlayerId)
if (sendTo == PlayerControl.LocalPlayer.PlayerId && !multiple)
{
MessageWriter w = AmongUsClient.Instance.StartRpc(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.RequestSendMessage);
w.Write(text);
@@ -1792,7 +1801,10 @@ public static class Utils
.Write(sender.Data.PlayerName)
.EndRpc();
writer.SendMessage();
if (multiple) writer.EndMessage();
else writer.SendMessage();
if (multiple) RestartMessageIfTooLong();
}
return;
@@ -1822,16 +1834,26 @@ public static class Utils
.Write(sender.Data.PlayerName)
.EndRpc();
writer.SendMessage();
if (multiple) writer.EndMessage();
else writer.SendMessage();
if (multiple) RestartMessageIfTooLong();
}
else if (writer.stream.Length > 800)
else RestartMessageIfTooLong();
ChatUpdatePatch.LastMessages.Add((text, sendTo, title, TimeStamp));
}
return;
void RestartMessageIfTooLong()
{
if (writer.stream.Length > 800)
{
writer.SendMessage();
writer = CustomRpcSender.Create("Utils.SendMessage", SendOption.Reliable);
writer.StartMessage(receiver.GetClientId());
}
ChatUpdatePatch.LastMessages.Add((text, sendTo, title, TimeStamp));
}
}
+16 -9
View File
@@ -314,9 +314,11 @@ internal static class ChatCommands
PlayerControl otherLover = Main.LoversPlayers.First(x => x.PlayerId != PlayerControl.LocalPlayer.PlayerId);
string title = PlayerControl.LocalPlayer.GetRealName();
ChatUpdatePatch.LoversMessage = true;
Utils.SendMessage(text, otherLover.PlayerId, title);
Utils.SendMessage(text, PlayerControl.LocalPlayer.PlayerId, title);
otherLover.Notify($"<size=80%><{Main.RoleColors[CustomRoles.Lovers]}>[\u2665]</color> {text}</size>", 8f);
var sender = CustomRpcSender.Create("LoversMessage", SendOption.Reliable);
Utils.SendMessage(text, otherLover.PlayerId, title, writer: sender, multiple: true);
Utils.SendMessage(text, PlayerControl.LocalPlayer.PlayerId, title, writer: sender, multiple: true);
sender.Notify(otherLover, $"<size=80%><{Main.RoleColors[CustomRoles.Lovers]}>[\u2665]</color> {text}</size>", 8f);
sender.SendMessage();
LateTask.New(() => ChatUpdatePatch.LoversMessage = false, Math.Max(AmongUsClient.Instance.Ping / 1000f * 2f, Main.MessageWait.Value + 0.5f), log: false);
}
@@ -908,9 +910,12 @@ internal static class ChatCommands
int duration = args.Length < 3 || !int.TryParse(args[2], out int dur) ? 60 : dur;
MutedPlayers[id] = (Utils.TimeStamp, duration);
Utils.SendMessage("\n", player.PlayerId, string.Format(GetString("PlayerMuted"), id.ColoredPlayerName(), duration));
Utils.SendMessage("\n", id, string.Format(GetString("YouMuted"), player.PlayerId.ColoredPlayerName(), duration));
if (!host) Utils.SendMessage("\n", 0, string.Format(GetString("ModeratorMuted"), player.PlayerId.ColoredPlayerName(), id.ColoredPlayerName(), duration));
var sender = CustomRpcSender.Create("MuteCommand", SendOption.Reliable);
Utils.SendMessage("\n", player.PlayerId, string.Format(GetString("PlayerMuted"), id.ColoredPlayerName(), duration), writer: sender, multiple: true);
Utils.SendMessage("\n", id, string.Format(GetString("YouMuted"), player.PlayerId.ColoredPlayerName(), duration), writer: sender, multiple: true);
if (!host) Utils.SendMessage("\n", 0, string.Format(GetString("ModeratorMuted"), player.PlayerId.ColoredPlayerName(), id.ColoredPlayerName(), duration), writer: sender, multiple: true);
sender.SendMessage(dispose: sender.stream.Length == 0);
}
private static void UnmuteCommand(PlayerControl player, string text, string[] args)
@@ -3090,9 +3095,11 @@ internal static class ChatCommands
{
string title = player.GetRealName();
ChatUpdatePatch.LoversMessage = true;
Utils.SendMessage(text, otherLover.PlayerId, title);
Utils.SendMessage(text, player.PlayerId, title);
otherLover.Notify($"<size=80%><{Main.RoleColors[CustomRoles.Lovers]}>[\u2665]</color> {text}</size>", 8f);
var sender = CustomRpcSender.Create("LoversChat", SendOption.Reliable);
Utils.SendMessage(text, otherLover.PlayerId, title, writer: sender, multiple: true);
Utils.SendMessage(text, player.PlayerId, title, writer: sender, multiple: true);
sender.Notify(otherLover, $"<size=80%><{Main.RoleColors[CustomRoles.Lovers]}>[\u2665]</color> {text}</size>", 8f);
sender.SendMessage();
LateTask.New(() => ChatUpdatePatch.LoversMessage = false, Math.Max(AmongUsClient.Instance.Ping / 1000f * 2f, Main.MessageWait.Value + 0.5f), log: false);
}, 0.2f, log: false);
}
+1 -1
View File
@@ -63,7 +63,7 @@ internal static class Crowded
}));
Object.Destroy(firstButtonRenderer);
var lastButtonRenderer = __instance.MaxPlayerButtons[^1];
var lastButtonRenderer = __instance.MaxPlayerButtons[^1]; // Must use 'var' here to avoid compiler errors
lastButtonRenderer.GetComponentInChildren<TextMeshPro>().text = "+"; // False error
lastButtonRenderer.enabled = false; // False error
var lastButtonButton = lastButtonRenderer.GetComponent<PassiveButton>(); // False error
+1 -1
View File
@@ -1343,7 +1343,7 @@ public static class FixDarkThemeForSearchBar
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.RpcSyncSettings))]
public class RpcSyncSettingsPatch
public static class RpcSyncSettingsPatch
{
public static void Postfix()
{
+1 -1
View File
@@ -942,7 +942,7 @@ internal static class IntroCutsceneDestroyPatch
var sender = CustomRpcSender.Create("Shapeshift After Pet Assign On Game Start", SendOption.Reliable);
sender.Notify(lp, GetString("GLHF"), 2f);
var hasValue = true;
var hasValue = false;
foreach (PlayerControl pc in aapc)
{
+1 -1
View File
@@ -667,7 +667,7 @@ internal static class MeetingHudStartPatch
List<(string Message, byte TargetID, string Title)> msgToSend = [];
if (Options.SendRoleDescriptionFirstMeeting.GetBool() && MeetingStates.FirstMeeting)
if (Options.SendRoleDescriptionFirstMeeting.GetBool() && MeetingStates.FirstMeeting && Options.CurrentGameMode == CustomGameMode.Standard)
{
foreach (PlayerControl pc in Main.AllAlivePlayerControls)
{
-1
View File
@@ -223,7 +223,6 @@ masturbation
menage a trois
milf
missionary position
mong
motherfucker
mound of venus
mr hands
+1 -1
View File
@@ -1529,7 +1529,7 @@
"JesterCanUseButton": "Can call emergency meetings",
"MarioVentButtonText": "Hop",
"Mario.NumVentsToWinOn.Skeld": "Number of Vents to Win on Skeld",
"Mario.NumVentsToWinOn.Mira": "Number of Vents to Win on Mira",
"Mario.NumVentsToWinOn.MiraHQ": "Number of Vents to Win on Mira",
"Mario.NumVentsToWinOn.Polus": "Number of Vents to Win on Polus",
"Mario.NumVentsToWinOn.Dleks": "Number of Vents to Win on Dleks",
"Mario.NumVentsToWinOn.Airship": "Number of Vents to Win on Airship",
+5 -2
View File
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using Hazel;
namespace EHR.Coven;
@@ -32,9 +33,11 @@ public abstract class Coven : RoleBase
LateTask.New(() =>
{
var sender = CustomRpcSender.Create("CovenGiveNecronomicon", SendOption.Reliable);
string[] holders = Main.PlayerStates.Where(s => s.Value.Role is Coven { HasNecronomicon: true }).Select(s => s.Key.ColoredPlayerName()).ToArray();
Main.AllPlayerControls.Where(x => x.Is(Team.Coven)).Select(x => x.PlayerId).Without(receiver.Key).Do(x => Utils.SendMessage("\n", x, string.Format(Translator.GetString("PlayerReceivedTheNecronomicon"), receiver.Key.ColoredPlayerName(), Main.CovenColor, holders.Length, string.Join(", ", holders))));
Utils.SendMessage("\n", receiver.Key, string.Format(Translator.GetString("YouReceivedTheNecronomicon"), Main.CovenColor));
Main.AllPlayerControls.Where(x => x.Is(Team.Coven)).Select(x => x.PlayerId).Without(receiver.Key).Do(x => Utils.SendMessage("\n", x, string.Format(Translator.GetString("PlayerReceivedTheNecronomicon"), receiver.Key.ColoredPlayerName(), Main.CovenColor, holders.Length, string.Join(", ", holders)), writer: sender, multiple: true));
Utils.SendMessage("\n", receiver.Key, string.Format(Translator.GetString("YouReceivedTheNecronomicon"), Main.CovenColor), writer: sender, multiple: true);
sender.SendMessage(dispose: sender.stream.Length == 0);
}, 12f, log: false);
}
+6 -3
View File
@@ -4,6 +4,7 @@ using System.Linq;
using AmongUs.GameOptions;
using EHR.Modules;
using EHR.Patches;
using Hazel;
using static EHR.Options;
namespace EHR.Neutral;
@@ -307,12 +308,14 @@ internal class QuizMaster : RoleBase
}
else if (index != -1)
{
Utils.SendMessage(string.Format(Translator.GetString("QuizMaster.AnswerIncorrect"), CurrentQuestion.Answers[CurrentQuestion.CorrectAnswerIndex]), Target, Translator.GetString("QuizMaster.Title"));
Utils.SendMessage(string.Format(Translator.GetString("QuizMaster.AnswerIncorrect.Self"), CurrentQuestion.Answers[index], CurrentQuestion.Answers[CurrentQuestion.CorrectAnswerIndex]), QuizMasterId, Translator.GetString("QuizMaster.Title"));
var sender = CustomRpcSender.Create("QuizMaster", SendOption.Reliable);
Utils.SendMessage(string.Format(Translator.GetString("QuizMaster.AnswerIncorrect"), CurrentQuestion.Answers[CurrentQuestion.CorrectAnswerIndex]), Target, Translator.GetString("QuizMaster.Title"), writer: sender, multiple: true);
Utils.SendMessage(string.Format(Translator.GetString("QuizMaster.AnswerIncorrect.Self"), CurrentQuestion.Answers[index], CurrentQuestion.Answers[CurrentQuestion.CorrectAnswerIndex]), QuizMasterId, Translator.GetString("QuizMaster.Title"), writer: sender, multiple: true);
Main.PlayerStates[Target].deathReason = PlayerState.DeathReason.WrongAnswer;
Main.PlayerStates[Target].SetDead();
pc?.RpcExileV2();
if (pc != null) sender.RpcExileV2(pc);
sender.SendMessage(dispose: pc == null && sender.stream.Length == 0);
Utils.AfterPlayerDeathTasks(pc, true);
Logger.Info($"Player {name} was killed for answering incorrectly", "QuizMaster");