Skip to content

Commit

Permalink
Merge pull request #1318 from tukasa0001/develop-5.1.7
Browse files Browse the repository at this point in the history
Develop 5.1.7
  • Loading branch information
yurinakira authored Jul 10, 2024
2 parents 94cb37f + 056e237 commit fce8043
Show file tree
Hide file tree
Showing 70 changed files with 717 additions and 369 deletions.
11 changes: 10 additions & 1 deletion Helpers/CustomRolesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ public static bool IsVanilla(this CustomRoles role)
role is CustomRoles.Crewmate or
CustomRoles.Engineer or
CustomRoles.Scientist or
CustomRoles.Tracker or
CustomRoles.Noisemaker or
CustomRoles.GuardianAngel or
CustomRoles.Impostor or
CustomRoles.Shapeshifter;
CustomRoles.Shapeshifter or
CustomRoles.Phantom;
}

public static CustomRoleTypes GetCustomRoleTypes(this CustomRoles role)
Expand All @@ -74,7 +77,10 @@ public static int GetCount(this CustomRoles role)
{
CustomRoles.Engineer => roleOpt.GetNumPerGame(RoleTypes.Engineer),
CustomRoles.Scientist => roleOpt.GetNumPerGame(RoleTypes.Scientist),
CustomRoles.Tracker => roleOpt.GetNumPerGame(RoleTypes.Tracker),
CustomRoles.Noisemaker => roleOpt.GetNumPerGame(RoleTypes.Noisemaker),
CustomRoles.Shapeshifter => roleOpt.GetNumPerGame(RoleTypes.Shapeshifter),
CustomRoles.Phantom => roleOpt.GetNumPerGame(RoleTypes.Phantom),
CustomRoles.GuardianAngel => roleOpt.GetNumPerGame(RoleTypes.GuardianAngel),
CustomRoles.Crewmate => roleOpt.GetNumPerGame(RoleTypes.Crewmate),
_ => 0
Expand All @@ -94,7 +100,10 @@ public static int GetChance(this CustomRoles role)
{
CustomRoles.Engineer => roleOpt.GetChancePerGame(RoleTypes.Engineer),
CustomRoles.Scientist => roleOpt.GetChancePerGame(RoleTypes.Scientist),
CustomRoles.Noisemaker => roleOpt.GetChancePerGame(RoleTypes.Noisemaker),
CustomRoles.Tracker => roleOpt.GetChancePerGame(RoleTypes.Tracker),
CustomRoles.Shapeshifter => roleOpt.GetChancePerGame(RoleTypes.Shapeshifter),
CustomRoles.Phantom => roleOpt.GetChancePerGame(RoleTypes.Phantom),
CustomRoles.GuardianAngel => roleOpt.GetChancePerGame(RoleTypes.GuardianAngel),
CustomRoles.Crewmate => roleOpt.GetChancePerGame(RoleTypes.Crewmate),
_ => 0
Expand Down
27 changes: 15 additions & 12 deletions Modules/AntiBlackout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,28 @@ public static void RestoreIsDead(bool doSend = true, [CallerMemberName] string c
public static void SendGameData([CallerMemberName] string callerMethodName = "")
{
logger.Info($"SendGameData is called from {callerMethodName}");
MessageWriter writer = MessageWriter.Get(SendOption.Reliable);
// 書き込み {}は読みやすさのためです。
writer.StartMessage(5); //0x05 GameData
foreach (var playerinfo in GameData.Instance.AllPlayers)
{
writer.Write(AmongUsClient.Instance.GameId);
writer.StartMessage(1); //0x01 Data
MessageWriter writer = MessageWriter.Get(SendOption.Reliable);
// 書き込み {}は読みやすさのためです。
writer.StartMessage(5); //0x05 GameData
{
writer.WritePacked(GameData.Instance.NetId);
GameData.Instance.Serialize(writer, true);
writer.Write(AmongUsClient.Instance.GameId);
writer.StartMessage(1); //0x01 Data
{
writer.WritePacked(playerinfo.NetId);
playerinfo.Serialize(writer, true);

}
writer.EndMessage();
}
writer.EndMessage();
}
writer.EndMessage();

AmongUsClient.Instance.SendOrDisconnect(writer);
writer.Recycle();
AmongUsClient.Instance.SendOrDisconnect(writer);
writer.Recycle();
}
}
public static void OnDisconnect(GameData.PlayerInfo player)
public static void OnDisconnect(NetworkedPlayerInfo player)
{
// 実行条件: クライアントがホストである, IsDeadが上書きされている, playerが切断済み
if (!AmongUsClient.Instance.AmHost || !IsCached || !player.Disconnected) return;
Expand Down
15 changes: 10 additions & 5 deletions Modules/Camouflague.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TownOfHost
{
static class PlayerOutfitExtension
{
public static GameData.PlayerOutfit Set(this GameData.PlayerOutfit instance, string playerName, int colorId, string hatId, string skinId, string visorId, string petId)
public static NetworkedPlayerInfo.PlayerOutfit Set(this NetworkedPlayerInfo.PlayerOutfit instance, string playerName, int colorId, string hatId, string skinId, string visorId, string petId)
{
instance.PlayerName = playerName;
instance.ColorId = colorId;
Expand All @@ -15,7 +15,7 @@ public static GameData.PlayerOutfit Set(this GameData.PlayerOutfit instance, str
instance.PetId = petId;
return instance;
}
public static bool Compare(this GameData.PlayerOutfit instance, GameData.PlayerOutfit targetOutfit)
public static bool Compare(this NetworkedPlayerInfo.PlayerOutfit instance, NetworkedPlayerInfo.PlayerOutfit targetOutfit)
{
return instance.ColorId == targetOutfit.ColorId &&
instance.HatId == targetOutfit.HatId &&
Expand All @@ -24,17 +24,17 @@ public static bool Compare(this GameData.PlayerOutfit instance, GameData.PlayerO
instance.PetId == targetOutfit.PetId;

}
public static string GetString(this GameData.PlayerOutfit instance)
public static string GetString(this NetworkedPlayerInfo.PlayerOutfit instance)
{
return $"{instance.PlayerName} Color:{instance.ColorId} {instance.HatId} {instance.SkinId} {instance.VisorId} {instance.PetId}";
}
}
public static class Camouflage
{
static GameData.PlayerOutfit CamouflageOutfit = new GameData.PlayerOutfit().Set("", 15, "", "", "", "");
static NetworkedPlayerInfo.PlayerOutfit CamouflageOutfit = new NetworkedPlayerInfo.PlayerOutfit().Set("", 15, "", "", "", "");

public static bool IsCamouflage;
public static Dictionary<byte, GameData.PlayerOutfit> PlayerSkins = new();
public static Dictionary<byte, NetworkedPlayerInfo.PlayerOutfit> PlayerSkins = new();

[GameModuleInitializer]
public static void Init()
Expand Down Expand Up @@ -104,27 +104,32 @@ public static void RpcSetSkin(PlayerControl target, bool ForceRevert = false, bo

target.SetColor(newOutfit.ColorId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetColor)
.Write(target.Data.NetId)
.Write(newOutfit.ColorId)
.EndRpc();

target.SetHat(newOutfit.HatId, newOutfit.ColorId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetHatStr)
.Write(newOutfit.HatId)
.Write(target.GetNextRpcSequenceId(RpcCalls.SetHatStr))
.EndRpc();

target.SetSkin(newOutfit.SkinId, newOutfit.ColorId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetSkinStr)
.Write(newOutfit.SkinId)
.Write(target.GetNextRpcSequenceId(RpcCalls.SetSkinStr))
.EndRpc();

target.SetVisor(newOutfit.VisorId, newOutfit.ColorId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetVisorStr)
.Write(newOutfit.VisorId)
.Write(target.GetNextRpcSequenceId(RpcCalls.SetVisorStr))
.EndRpc();

target.SetPet(newOutfit.PetId);
sender.AutoStartRpc(target.NetId, (byte)RpcCalls.SetPetStr)
.Write(newOutfit.PetId)
.Write(target.GetNextRpcSequenceId(RpcCalls.SetPetStr))
.EndRpc();

sender.SendMessage();
Expand Down
1 change: 1 addition & 0 deletions Modules/CustomRpcSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public static void RpcSetRole(this CustomRpcSender sender, PlayerControl player,
{
sender.AutoStartRpc(player.NetId, (byte)RpcCalls.SetRole, targetClientId)
.Write((ushort)role)
.Write(false)
.EndRpc();
}
public static void RpcMurderPlayer(this CustomRpcSender sender, PlayerControl player, PlayerControl target, int targetClientId = -1)
Expand Down
2 changes: 1 addition & 1 deletion Modules/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void Enable(string tag, bool toGame = false)
public static void SendInGame(string text, bool isAlways = false)
{
if (!isEnable) return;
if (DestroyableSingleton<HudManager>._instance) DestroyableSingleton<HudManager>.Instance.Notifier.AddItem(text);
if (DestroyableSingleton<HudManager>._instance) DestroyableSingleton<HudManager>.Instance.Notifier.AddDisconnectMessage(text);
}
private static void SendToFile(string text, LogLevel level = LogLevel.Info, string tag = "", bool escapeCRLF = true, int lineNumber = 0, string fileName = "")
{
Expand Down
43 changes: 40 additions & 3 deletions Modules/ErrorText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,32 @@ public static void Create(TMPro.TextMeshPro baseText)
Text.color = Color.red;
Text.outlineColor = Color.black;
Text.alignment = TMPro.TextAlignmentOptions.Top;

// 背景
var bgObject = new GameObject("Background") { layer = LayerMask.NameToLayer("UI") };
var bgRenderer = instance.background = bgObject.AddComponent<SpriteRenderer>();
var bgTexture = new Texture2D(Screen.width, 150, TextureFormat.ARGB32, false);
for (var x = 0; x < bgTexture.width; x++)
{
for (var y = 0; y < bgTexture.height; y++)
{
bgTexture.SetPixel(x, y, new(0f, 0f, 0f, 0.6f));
}
}
bgTexture.Apply();
var bgSprite = Sprite.Create(bgTexture, new(0, 0, bgTexture.width, bgTexture.height), new(0.5f, 1f /* 上端の真ん中を中心とする */ ));
bgRenderer.sprite = bgSprite;
var bgTransform = bgObject.transform;
bgTransform.parent = instance.transform;
bgTransform.localPosition = new(0f, TextOffsetY, 1f);
bgObject.SetActive(false);
}

public TMPro.TextMeshPro Text;
private SpriteRenderer background;
public Camera Camera;
public List<ErrorData> AllErrors = new();
public Vector3 TextOffset = new(0, 0.3f, -1000f);
public Vector3 TextOffset = new(0, TextOffsetY, -1000f);
public void Update()
{
AllErrors.ForEach(err => err.IncreaseTimer());
Expand Down Expand Up @@ -95,13 +115,13 @@ public void UpdateText()
}
if (maxLevel == 0)
{
Text.enabled = false;
Hide();
}
else
{
if (!HnSFlag)
text += $"{GetString($"ErrorLevel{maxLevel}")}";
Text.enabled = true;
Show();
}
if (GameStates.IsInGame && maxLevel != 3)
text += $"\n{GetString("TerminateCommand")}: Shift+L+Enter";
Expand All @@ -112,6 +132,16 @@ public void Clear()
AllErrors.RemoveAll(err => err.ErrorLevel != 3);
UpdateText();
}
private void Show()
{
Text.enabled = true;
background.gameObject.SetActive(true);
}
private void Hide()
{
Text.enabled = false;
background.gameObject.SetActive(false);
}

public class ErrorData
{
Expand All @@ -138,6 +168,8 @@ public override string ToString()
}

public bool HnSFlag;

const float TextOffsetY = 0.3f;
}
public enum ErrorCode
{
Expand All @@ -155,6 +187,11 @@ public enum ErrorCode
OptionIDDuplicate = 001_010_3, // 001-010-3 オプションIDが重複している(DEBUGビルド時のみ)
// 002 サポート関連
UnsupportedVersion = 002_000_1, // 002-000-1 AmongUsのバージョンが古い

// 010 参加/退出関連
OnPlayerLeftPostfixFailedInGame = 010_000_2, // 010-000-2 OnPlayerLeftPatch.Postfixがゲーム中に失敗
OnPlayerLeftPostfixFailedInLobby = 010_001_2, // 010-001-2 OnPlayerLeftPatch.Postfixがロビーで失敗

// ==========
// 000 Test
NoError = 0000000, // 000-000-0 No Error
Expand Down
10 changes: 6 additions & 4 deletions Modules/ExtendedPlayerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static int GetClientId(this PlayerControl player)
var client = player.GetClient();
return client == null ? -1 : client.Id;
}
public static CustomRoles GetCustomRole(this GameData.PlayerInfo player)
public static CustomRoles GetCustomRole(this NetworkedPlayerInfo player)
{
return player == null || player.Object == null ? CustomRoles.Crewmate : player.Object.GetCustomRole();
}
Expand Down Expand Up @@ -148,6 +148,7 @@ public static void RpcSetNamePrivate(this PlayerControl player, string name, boo

var clientId = seer.GetClientId();
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.SetName, Hazel.SendOption.Reliable, clientId);
writer.Write(player.Data.NetId);
writer.Write(name);
writer.Write(DontShowOnModdedClient);
AmongUsClient.Instance.FinishRpcImmediately(writer);
Expand All @@ -159,11 +160,12 @@ public static void RpcSetRoleDesync(this PlayerControl player, RoleTypes role, i
if (player == null) return;
if (AmongUsClient.Instance.ClientId == clientId)
{
player.SetRole(role);
player.StartCoroutine(player.CoSetRole(role, false));
return;
}
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.SetRole, Hazel.SendOption.Reliable, clientId);
writer.Write((ushort)role);
writer.Write(false);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}

Expand Down Expand Up @@ -477,13 +479,13 @@ public static void RpcProtectedMurderPlayer(this PlayerControl killer, PlayerCon
// Other Clients
if (killer.PlayerId != 0)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(killer.NetId, (byte)RpcCalls.MurderPlayer, SendOption.Reliable);
var writer = AmongUsClient.Instance.StartRpcImmediately(killer.NetId, (byte)RpcCalls.MurderPlayer, SendOption.Reliable, killer.GetClientId());
writer.WriteNetObject(target);
writer.Write((int)MurderResultFlags.FailedProtected);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
}
public static void NoCheckStartMeeting(this PlayerControl reporter, GameData.PlayerInfo target)
public static void NoCheckStartMeeting(this PlayerControl reporter, NetworkedPlayerInfo target)
{ /*サボタージュ中でも関係なしに会議を起こせるメソッド
targetがnullの場合はボタンとなる*/
MeetingRoomManager.Instance.AssignSelf(reporter, target);
Expand Down
20 changes: 10 additions & 10 deletions Modules/Extensions/IGameManagerEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ namespace TownOfHost.Modules.Extensions
public static class IGameManagerEx
{
public static void Set(this BoolOptionNames name, bool value, IGameOptions opt) => opt.SetBool(name, value);
public static void Set(this BoolOptionNames name, bool value, NormalGameOptionsV07 opt) => opt.SetBool(name, value);
public static void Set(this BoolOptionNames name, bool value, HideNSeekGameOptionsV07 opt) => opt.SetBool(name, value);
public static void Set(this BoolOptionNames name, bool value, NormalGameOptionsV08 opt) => opt.SetBool(name, value);
public static void Set(this BoolOptionNames name, bool value, HideNSeekGameOptionsV08 opt) => opt.SetBool(name, value);

public static void Set(this Int32OptionNames name, int value, IGameOptions opt) => opt.SetInt(name, value);
public static void Set(this Int32OptionNames name, int value, NormalGameOptionsV07 opt) => opt.SetInt(name, value);
public static void Set(this Int32OptionNames name, int value, HideNSeekGameOptionsV07 opt) => opt.SetInt(name, value);
public static void Set(this Int32OptionNames name, int value, NormalGameOptionsV08 opt) => opt.SetInt(name, value);
public static void Set(this Int32OptionNames name, int value, HideNSeekGameOptionsV08 opt) => opt.SetInt(name, value);

public static void Set(this FloatOptionNames name, float value, IGameOptions opt) => opt.SetFloat(name, value);
public static void Set(this FloatOptionNames name, float value, NormalGameOptionsV07 opt) => opt.SetFloat(name, value);
public static void Set(this FloatOptionNames name, float value, HideNSeekGameOptionsV07 opt) => opt.SetFloat(name, value);
public static void Set(this FloatOptionNames name, float value, NormalGameOptionsV08 opt) => opt.SetFloat(name, value);
public static void Set(this FloatOptionNames name, float value, HideNSeekGameOptionsV08 opt) => opt.SetFloat(name, value);

public static void Set(this ByteOptionNames name, byte value, IGameOptions opt) => opt.SetByte(name, value);
public static void Set(this ByteOptionNames name, byte value, NormalGameOptionsV07 opt) => opt.SetByte(name, value);
public static void Set(this ByteOptionNames name, byte value, HideNSeekGameOptionsV07 opt) => opt.SetByte(name, value);
public static void Set(this ByteOptionNames name, byte value, NormalGameOptionsV08 opt) => opt.SetByte(name, value);
public static void Set(this ByteOptionNames name, byte value, HideNSeekGameOptionsV08 opt) => opt.SetByte(name, value);

public static void Set(this UInt32OptionNames name, uint value, IGameOptions opt) => opt.SetUInt(name, value);
public static void Set(this UInt32OptionNames name, uint value, NormalGameOptionsV07 opt) => opt.SetUInt(name, value);
public static void Set(this UInt32OptionNames name, uint value, HideNSeekGameOptionsV07 opt) => opt.SetUInt(name, value);
public static void Set(this UInt32OptionNames name, uint value, NormalGameOptionsV08 opt) => opt.SetUInt(name, value);
public static void Set(this UInt32OptionNames name, uint value, HideNSeekGameOptionsV08 opt) => opt.SetUInt(name, value);
}
}
14 changes: 8 additions & 6 deletions Modules/GameOptionsSender/GameOptionsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ public static void SendAllGameOptions()
public virtual void SendGameOptions()
{
var opt = BuildGameOptions();
var currentGameMode = AprilFoolsMode.IsAprilFoolsModeToggledOn //April fools mode toggled on by host
? opt.AprilFoolsOnMode : opt.GameMode; //Change game mode, same as well as in "RpcSyncSettings()"

// option => byte[]
MessageWriter writer = MessageWriter.Get(SendOption.None);
writer.Write(opt.Version);
writer.StartMessage(0);
writer.Write((byte)opt.GameMode);
if (opt.TryCast<NormalGameOptionsV07>(out var normalOpt))
NormalGameOptionsV07.Serialize(writer, normalOpt);
else if (opt.TryCast<HideNSeekGameOptionsV07>(out var hnsOpt))
HideNSeekGameOptionsV07.Serialize(writer, hnsOpt);
writer.Write((byte)currentGameMode);
if (opt.TryCast<NormalGameOptionsV08>(out var normalOpt))
NormalGameOptionsV08.Serialize(writer, normalOpt);
else if (opt.TryCast<HideNSeekGameOptionsV08>(out var hnsOpt))
HideNSeekGameOptionsV08.Serialize(writer, hnsOpt);
else
{
writer.Recycle();
Expand Down Expand Up @@ -93,4 +95,4 @@ protected virtual void SendOptionsArray(Il2CppStructArray<byte> optionArray, byt

public virtual bool AmValid() => true;
}
}
}
Loading

0 comments on commit fce8043

Please sign in to comment.