mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Remove PopulateResultsRpc and simplify.
This commit is contained in:
1 parent
1462061df9
commit
db327604c5
3 files changed
+18
-73
No files matched your search
@@ -40,11 +40,6 @@ public enum MiraRpc : uint
|
||||
/// </summary>
|
||||
CustomGameOver,
|
||||
|
||||
/// <summary>
|
||||
/// Custom RPC to handle populating vote results.
|
||||
/// </summary>
|
||||
PopulateResults,
|
||||
|
||||
/// <summary>
|
||||
/// Custom RPC to undo a player's vote.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Meeting;
|
||||
using MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Voting;
|
||||
using Reactor.Networking.Rpc;
|
||||
|
||||
namespace MiraAPI.Patches.Voting;
|
||||
|
||||
@@ -201,21 +201,33 @@ internal static class MeetingHudPatches
|
||||
exiled = @event.ExiledPlayer;
|
||||
}
|
||||
|
||||
__instance.RpcVotingComplete(new MeetingHud.VoterState[__instance.playerStates.Length], exiled, isTie);
|
||||
var voterStates = new Il2CppStructArray<MeetingHud.VoterState>([
|
||||
.. votes.Select(
|
||||
v=> new MeetingHud.VoterState
|
||||
{
|
||||
VoterId = v.Voter,
|
||||
VotedForId = v.Suspect,
|
||||
})
|
||||
]);
|
||||
|
||||
__instance.RpcVotingComplete(voterStates, exiled, isTie);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(MeetingHud.PopulateResults))]
|
||||
public static bool PopulateResultsPatch(MeetingHud __instance)
|
||||
public static bool PopulateResultsPatch(MeetingHud __instance, ref Il2CppStructArray<MeetingHud.VoterState> states)
|
||||
{
|
||||
if (!AmongUsClient.Instance.AmHost)
|
||||
var votes = states.Select(x=> new CustomVote(x.VoterId, x.VotedForId)).ToList();
|
||||
var @event = new PopulateResultsEvent(votes);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (@event.IsCancelled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var votes = VotingUtils.CalculateVotes();
|
||||
|
||||
Rpc<PopulateResultsRpc>.Instance.Send([.. votes]);
|
||||
VotingUtils.HandlePopulateResults(votes);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
using Hazel;
|
||||
using MiraAPI.Networking;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Networking.Rpc;
|
||||
|
||||
namespace MiraAPI.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the networking for populating results of a meeting. Custom implementation to work with Mira voting API.
|
||||
/// </summary>
|
||||
[RegisterCustomRpc((uint)MiraRpc.PopulateResults)]
|
||||
public class PopulateResultsRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<MiraApiPlugin, CustomVote[]>(plugin, id)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override RpcLocalHandling LocalHandling => RpcLocalHandling.Before;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(MessageWriter writer, CustomVote[]? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
writer.WritePacked(0);
|
||||
return;
|
||||
}
|
||||
|
||||
writer.WritePacked(data.Length);
|
||||
foreach (var t in data)
|
||||
{
|
||||
writer.Write(t.Voter);
|
||||
writer.Write(t.Suspect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override CustomVote[] Read(MessageReader reader)
|
||||
{
|
||||
var votes = new CustomVote[reader.ReadPackedInt32()];
|
||||
|
||||
for (var i = 0; i < votes.Length; i++)
|
||||
{
|
||||
votes[i] = new CustomVote(reader.ReadByte(), reader.ReadByte());
|
||||
}
|
||||
|
||||
return votes;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Handle(PlayerControl innerNetObject, CustomVote[]? data)
|
||||
{
|
||||
if (AmongUsClient.Instance.HostId != innerNetObject.OwnerId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VotingUtils.HandlePopulateResults([.. data]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user