Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
From TOHE,显示炸房时间
Browse files Browse the repository at this point in the history
  • Loading branch information
Night-GUA committed Jul 30, 2024
1 parent 2133d2a commit 0d98b3a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions YuEzTools/Patches/CustomPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ namespace YuEzTools;
public enum CustomRPC
{
SetKickReason,

SyncLobbyTimer,
}
15 changes: 15 additions & 0 deletions YuEzTools/Patches/ExtendedPlayerControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using AmongUs.GameOptions;
using Hazel;
using InnerNet;
using System;
using System.Text;
using UnityEngine;
using static YuEzTools.Translator;

namespace YuEzTools;

static class ExtendedPlayerControl
{
public static bool OwnedByHost(this InnerNetObject innerObject)
=> innerObject.OwnerId == AmongUsClient.Instance.HostId;
}
2 changes: 1 addition & 1 deletion YuEzTools/Patches/GameStartPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace YuEzTools.Patches;

public class GameStartManagerPatch
{
private static float timer = 600f;
public static float timer = 600f;
private static TextMeshPro warningText;
public static TextMeshPro GameCountdown;
private static PassiveButton cancelButton;
Expand Down
34 changes: 34 additions & 0 deletions YuEzTools/Patches/OnPlayerJoinedPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,38 @@ public static void Prefix(InnerNetClient __instance, DisconnectReasons reason, s
if (AmongUsClient.Instance.AmHost && GetPlayer.IsInGame)
GameManager.Instance.RpcEndGame(GameOverReason.ImpostorDisconnect, false);
}
}

[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.Spawn))]
class InnerNetClientSpawnPatch
{
public static void Postfix([HarmonyArgument(1)] int ownerId, [HarmonyArgument(2)] SpawnFlags flags)
{
ClientData client = GetPlayer.GetClientById(ownerId);
Logger.Msg($"Spawn player data: ID {ownerId}: {client.PlayerName}", "InnerNetClientSpawn");
if (GetPlayer.IsOnlineGame)
{
_ = new LateTask(() =>
{
if (GetPlayer.IsLobby && client.Character != null && LobbyBehaviour.Instance != null )//&& GetPlayer.IsVanillaServer)
{
// Only for vanilla
if (!client.Character.OwnedByHost())
{
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(LobbyBehaviour.Instance.NetId, (byte)RpcCalls.LobbyTimeExpiring, SendOption.None, client.Id);
writer.WritePacked((int)GameStartManagerPatch.timer);
writer.Write(false);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
// Non-host modded client
else if (!client.Character.OwnedByHost())
{
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncLobbyTimer, SendOption.Reliable, client.Id);
writer.WritePacked((int)GameStartManagerPatch.timer);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
}
}, 3.1f, "Send RPC or Sync Lobby Timer");
}
}
}
26 changes: 26 additions & 0 deletions YuEzTools/Utils/GetPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ public PlayerState(int clientid)

static class GetPlayer
{
public static bool IsVanillaServer
{
get
{
if (!IsOnlineGame) return false;

const string Domain = "among.us";

// From Reactor.gg
return ServerManager.Instance.CurrentRegion?.TryCast<StaticHttpRegionInfo>() is { } regionInfo &&
regionInfo.PingServer.EndsWith(Domain, StringComparison.Ordinal) &&
regionInfo.Servers.All(serverInfo => serverInfo.Ip.EndsWith(Domain, StringComparison.Ordinal));
}
}
public static ClientData GetClientById(int id)
{
try
{
var client = AmongUsClient.Instance.allClients.ToArray().FirstOrDefault(cd => cd.Id == id);
return client;
}
catch
{
return null;
}
}
public static string GetColorRole(PlayerControl player)
{
if (GetPlayerRoleTeam(player) == RoleTeam.Crewmate)
Expand Down

0 comments on commit 0d98b3a

Please sign in to comment.