mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
Revert & Fix SyncCustomSettings RPC (Since there isn't other ways to make it function properly) (#436)
* Revert & Fix crappy RPC * Update RPC.cs * Update NotificationPopperPatch.cs * Update OptionItem.cs * Update OnGameStartedPatch.cs
This commit is contained in:
1 parent
df08d0ab5a
commit
b3b17d30ff
4 files changed
+60
-33
No files matched your search
@@ -328,7 +328,7 @@ public abstract class OptionItem
|
||||
)
|
||||
return;
|
||||
|
||||
RPC.SyncCustomSettingsRPC(targetId, sendOption);
|
||||
RPC.SyncCustomSettingsRPC(targetId);
|
||||
}
|
||||
|
||||
public void CallUpdateValueEvent(int beforeValue, int currentValue)
|
||||
@@ -380,4 +380,4 @@ public enum OptionFormat
|
||||
Pieces,
|
||||
Health,
|
||||
Level
|
||||
}
|
||||
}
|
||||
+55
-28
@@ -458,17 +458,30 @@ internal static class RPCHandlerPatch
|
||||
{
|
||||
if (AmongUsClient.Instance.AmHost) break;
|
||||
|
||||
if (reader.ReadBoolean())
|
||||
{
|
||||
Options.Preset.SetValue(9, false, false);
|
||||
Options.GameMode.SetValue(reader.ReadPackedInt32(), false, false);
|
||||
}
|
||||
List<OptionItem> listOptions = [];
|
||||
int startAmount = reader.ReadInt32();
|
||||
int lastAmount = reader.ReadInt32();
|
||||
int countAllOptions = OptionItem.AllOptions.Count;
|
||||
|
||||
while (reader.BytesRemaining > 0)
|
||||
// Add Options
|
||||
for (int option = startAmount; option < countAllOptions && option <= lastAmount; option++)
|
||||
listOptions.Add(OptionItem.AllOptions[option]);
|
||||
|
||||
int countOptions = listOptions.Count;
|
||||
Logger.Msg($"StartAmount: {startAmount} - LastAmount: {lastAmount} ({startAmount}/{lastAmount}) :--: ListOptionsCount: {countOptions} - AllOptions: {countAllOptions} ({countOptions}/{countAllOptions})", "SyncCustomSettings");
|
||||
|
||||
// Sync Settings
|
||||
foreach (OptionItem option in listOptions)
|
||||
{
|
||||
int id = reader.ReadPackedInt32();
|
||||
int value = reader.ReadPackedInt32();
|
||||
OptionItem.FastOptions[id].SetValue(value, false, false);
|
||||
try { option.SetValue(reader.ReadPackedInt32()); }
|
||||
catch { }
|
||||
|
||||
try
|
||||
{
|
||||
if (startAmount == 0 && option.Name == "Preset" && option.CurrentValue != 9)
|
||||
option.SetValue(9, false, false);
|
||||
}
|
||||
catch (Exception e) { Utils.ThrowException(e); }
|
||||
}
|
||||
|
||||
OptionSaver.Save();
|
||||
@@ -629,7 +642,7 @@ internal static class RPCHandlerPatch
|
||||
int index = reader.ReadPackedInt32();
|
||||
int customRole = reader.ReadPackedInt32();
|
||||
bool playSound = reader.ReadBoolean();
|
||||
OptionItem key = OptionItem.FastOptions[index];
|
||||
OptionItem key = OptionItem.AllOptions[index];
|
||||
|
||||
switch (typeId)
|
||||
{
|
||||
@@ -1429,7 +1442,8 @@ internal static class RPCHandlerPatch
|
||||
|
||||
internal static class RPC
|
||||
{
|
||||
public static void SyncCustomSettingsRPC(int targetId = -1, SendOption sendOption = SendOption.None)
|
||||
// Credit: https://github.com/music-discussion/TownOfHost-TheOtherRoles/blob/main/Modules/RPC.cs
|
||||
public static void SyncCustomSettingsRPC(int targetId = -1)
|
||||
{
|
||||
if (targetId != -1)
|
||||
{
|
||||
@@ -1439,26 +1453,39 @@ internal static class RPC
|
||||
|
||||
if (!AmongUsClient.Instance.AmHost || PlayerControl.AllPlayerControls.Count <= 1) return;
|
||||
|
||||
Logger.Msg(" Starting", "SyncCustomSettings");
|
||||
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncCustomSettings, sendOption, targetId);
|
||||
writer.Write(true);
|
||||
writer.WritePacked(Options.GameMode.GetValue());
|
||||
|
||||
foreach (var option in OptionItem.AllOptions)
|
||||
int amount = OptionItem.AllOptions.Count;
|
||||
int divideBy = amount / 10;
|
||||
for (var i = 0; i <= 10; i++) SyncOptionsBetween(i * divideBy, (i + 1) * divideBy, targetId);
|
||||
}
|
||||
|
||||
private static void SyncOptionsBetween(int startAmount, int lastAmount, int targetId = -1)
|
||||
{
|
||||
if (targetId != -1)
|
||||
{
|
||||
if (option is TextOptionItem || option.Id >= 660000 || option.Name == "Preset") continue;
|
||||
|
||||
if (writer.Length > 500)
|
||||
{
|
||||
AmongUsClient.Instance.FinishRpcImmediately(writer);
|
||||
writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncCustomSettings, sendOption, targetId);
|
||||
writer.Write(false);
|
||||
}
|
||||
|
||||
writer.WritePacked(option.Id);
|
||||
writer.WritePacked(option.GetValue());
|
||||
ClientData client = Utils.GetClientById(targetId);
|
||||
if (client == null || client.Character == null || !Main.PlayerVersion.ContainsKey(client.Character.PlayerId)) return;
|
||||
}
|
||||
|
||||
if (!AmongUsClient.Instance.AmHost || PlayerControl.AllPlayerControls.Count <= 1) return;
|
||||
|
||||
int amountAllOptions = OptionItem.AllOptions.Count;
|
||||
|
||||
Logger.Msg(" Starting", "SyncCustomSettings");
|
||||
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncCustomSettings, SendOption.Reliable, targetId);
|
||||
writer.Write(startAmount);
|
||||
writer.Write(lastAmount);
|
||||
|
||||
List<OptionItem> listOptions = [];
|
||||
|
||||
// Add Options
|
||||
for (int option = startAmount; option < amountAllOptions && option <= lastAmount; option++) listOptions.Add(OptionItem.AllOptions[option]);
|
||||
|
||||
int countListOptions = listOptions.Count;
|
||||
Logger.Msg($"StartAmount: {startAmount} - LastAmount: {lastAmount} ({startAmount}/{lastAmount}) :--: ListOptionsCount: {countListOptions} - AllOptions: {amountAllOptions} ({countListOptions}/{amountAllOptions})", "SyncCustomSettings");
|
||||
|
||||
// Sync Settings
|
||||
foreach (OptionItem option in listOptions) writer.WritePacked(option.GetValue());
|
||||
|
||||
AmongUsClient.Instance.FinishRpcImmediately(writer);
|
||||
Logger.Msg(" Finished", "SyncCustomSettings");
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ internal static class NotificationPopperPatch
|
||||
|
||||
private static void SendRpc(byte typeId, int index, CustomRoles customRole = CustomRoles.NotAssigned, bool playSound = true)
|
||||
{
|
||||
if (!AmongUsClient.Instance.AmHost || Options.HideGameSettings.GetBool()) return;
|
||||
if (Options.HideGameSettings.GetBool()) return;
|
||||
Utils.SendRPC(CustomRPC.NotificationPopper, typeId, index, (int)customRole, playSound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,7 +394,7 @@ internal static class ChangeRoleSettings
|
||||
|
||||
if (__instance.AmHost)
|
||||
{
|
||||
RPC.SyncCustomSettingsRPC(sendOption: SendOption.Reliable);
|
||||
RPC.SyncCustomSettingsRPC();
|
||||
Main.RefixCooldownDelay = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user