Skip to content

Commit

Permalink
Fix broken rpc & fix speed mod
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoCat233 committed Mar 1, 2025
1 parent bb4fad6 commit 512e899
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions GameModes/SpeedRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using static TOHE.Utils;
using static TOHE.Translator;
using Il2CppSystem.Text;
using InnerNet;

namespace TOHE;

Expand Down Expand Up @@ -115,7 +116,7 @@ public static void RpcSyncSpeedRunStates(byte specificPlayerId = 255) // Not 255
{
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncSpeedRunStates, ExtendedPlayerControl.RpcSendOption);
writer.Write(StartedAt.ToString());
writer.Write(1);
writer.Write((byte)1);
writer.Write(specificPlayerId);
writer.Write((byte)PlayerTaskCounts[specificPlayerId].Item1);
writer.Write((byte)PlayerTaskCounts[specificPlayerId].Item2);
Expand Down Expand Up @@ -163,7 +164,12 @@ public static void RpcSyncSpeedRunStates(byte specificPlayerId = 255) // Not 255

public static void HandleSyncSpeedRunStates(MessageReader reader)
{
StartedAt = long.Parse(reader.ReadString());
var start = reader.ReadString();
if (!long.TryParse(start, out StartedAt))
{
Logger.Error("Failed to parse StartedAt timestamp from " + start, "HandleSyncSpeedRunStates");
}

var amount = reader.ReadByte();
for (int i = 0; i < amount; i++)
{
Expand All @@ -174,7 +180,15 @@ public static void HandleSyncSpeedRunStates(MessageReader reader)
var hasFinishedAt = reader.ReadBoolean();
if (hasFinishedAt)
{
PlayerTaskFinishedAt[id] = long.Parse(reader.ReadString());
var finish = reader.ReadString();
if (!long.TryParse(finish, out var finishedAt))
{
Logger.Error($"Failed to parse finishedAt timestamp for player {id} {finish}.", "HandleSyncSpeedRunStates");
}
else
{
PlayerTaskFinishedAt[id] = finishedAt;
}
}
PlayerTaskCounts[id] = (taskCount, totalTaskCount);
PlayerNumKills[id] = numKills;
Expand Down Expand Up @@ -369,12 +383,14 @@ public override void ApplyGameOptions(IGameOptions opt, byte playerId)
}
}

Main.AllPlayerSpeed[playerId] = speed;
AURoleOptions.PlayerSpeedMod = speed;
}

public void SendRPC()
{
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncRoleSkill, ExtendedPlayerControl.RpcSendOption);
writer.WriteNetObject(_Player);
writer.Write(BasisChanged);
writer.Write(ProtectState.Item1);
writer.Write(ProtectState.Item2);
Expand Down
2 changes: 1 addition & 1 deletion Modules/GameOptionsSender/PlayerGameOptionsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public override IGameOptions BuildGameOptions()

if (Main.AllPlayerSpeed.TryGetValue(player.PlayerId, out var speed))
{
AURoleOptions.PlayerSpeedMod = Mathf.Clamp(speed, Main.MinSpeed, 3f);
AURoleOptions.PlayerSpeedMod = Mathf.Clamp(speed, Main.MinSpeed, 10f);
}

state.taskState.hasTasks = Utils.HasTasks(player.Data, false);
Expand Down

0 comments on commit 512e899

Please sign in to comment.