Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop 5.1.8 #1323

Merged
merged 14 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Modules/AURoleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@ public static bool ShapeshifterLeaveSkin
get => Opt.GetBool(BoolOptionNames.ShapeshifterLeaveSkin);
set => Opt.SetBool(BoolOptionNames.ShapeshifterLeaveSkin, value);
}
public static bool NoisemakerImpostorAlert
{
get => Opt.GetBool(BoolOptionNames.NoisemakerImpostorAlert);
set => Opt.SetBool(BoolOptionNames.NoisemakerImpostorAlert, value);
}
}
}
4 changes: 4 additions & 0 deletions Modules/GameOptionsSender/PlayerGameOptionsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public override IGameOptions BuildGameOptions()
opt.SetBool(BoolOptionNames.AnonymousVotes, false);
break;
}
if (!role.IsImpostor())
{
AURoleOptions.NoisemakerImpostorAlert = true;
}

var roleClass = player.GetRoleClass();
roleClass?.ApplyGameOptions(opt);
Expand Down
8 changes: 4 additions & 4 deletions Patches/ExilePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public static void Postfix(ExileController __instance)
{
try
{
WrapUpPostfix(__instance.exiled);
WrapUpPostfix(__instance.initData.networkedPlayer);
}
finally
{
WrapUpFinalizer(__instance.exiled);
WrapUpFinalizer(__instance.initData.networkedPlayer);
}
}
}
Expand All @@ -32,11 +32,11 @@ public static void Postfix(AirshipExileController __instance)
{
try
{
WrapUpPostfix(__instance.exiled);
WrapUpPostfix(__instance.initData.networkedPlayer);
}
finally
{
WrapUpFinalizer(__instance.exiled);
WrapUpFinalizer(__instance.initData.networkedPlayer);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Patches/GameOptionsMenuPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public static void Postfix()
OptionItem.SyncAllOptions();
}
}
[HarmonyPatch(typeof(RolesSettingsMenu), nameof(RolesSettingsMenu.Start))]
[HarmonyPatch(typeof(RolesSettingsMenu), nameof(RolesSettingsMenu.InitialSetup))]
public static class RolesSettingsMenuPatch
{
public static void Postfix(RolesSettingsMenu __instance)
Expand Down
83 changes: 28 additions & 55 deletions Patches/onGameStartedPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,13 @@ public static void Prefix()
PlayerControl.LocalPlayer.RpcSetRole(RoleTypes.Crewmate);
PlayerControl.LocalPlayer.Data.IsDead = true;
}
Dictionary<(byte, byte), RoleTypes> rolesMap = new();
foreach (var (role, info) in CustomRoleManager.AllRolesInfo)
{
if (info.IsDesyncImpostor)
{
AssignDesyncRole(role, AllPlayers, senders, rolesMap, BaseRole: info.BaseRoleType.Invoke());
AssignDesyncRole(role, AllPlayers, senders, BaseRole: info.BaseRoleType.Invoke());
}
}
MakeDesyncSender(senders, rolesMap);
}
//以下、バニラ側の役職割り当てが入る
}
Expand All @@ -165,7 +163,7 @@ public static void Postfix()

// 不要なオブジェクトの削除
RpcSetRoleReplacer.senders = null;
RpcSetRoleReplacer.OverriddenSenderList = null;
RpcSetRoleReplacer.DesyncImpostorList = null;
RpcSetRoleReplacer.StoragedData = null;

//Utils.ApplySuffix();
Expand Down Expand Up @@ -337,7 +335,7 @@ public static void Postfix()
Utils.SyncAllSettings();
SetColorPatch.IsAntiGlitchDisabled = false;
}
private static void AssignDesyncRole(CustomRoles role, List<PlayerControl> AllPlayers, Dictionary<byte, CustomRpcSender> senders, Dictionary<(byte, byte), RoleTypes> rolesMap, RoleTypes BaseRole, RoleTypes hostBaseRole = RoleTypes.Crewmate)
private static void AssignDesyncRole(CustomRoles role, List<PlayerControl> AllPlayers, Dictionary<byte, CustomRpcSender> senders, RoleTypes BaseRole, RoleTypes hostBaseRole = RoleTypes.Crewmate)
{
if (!role.IsPresent()) return;

Expand All @@ -350,53 +348,26 @@ private static void AssignDesyncRole(CustomRoles role, List<PlayerControl> AllPl
var player = AllPlayers[rand.Next(0, AllPlayers.Count)];
AllPlayers.Remove(player);
PlayerState.GetByPlayerId(player.PlayerId).SetMainRole(role);
RpcSetRoleReplacer.DesyncImpostorList.Add(player.PlayerId);

var selfRole = player.PlayerId == hostId ? hostBaseRole : BaseRole;
var othersRole = player.PlayerId == hostId ? RoleTypes.Crewmate : RoleTypes.Scientist;

//Desync役職視点
foreach (var target in Main.AllPlayerControls)
var hostRole = player.PlayerId == hostId ? hostBaseRole : RoleTypes.Crewmate;
foreach (var seer in Main.AllPlayerControls)
{
if (player.PlayerId != target.PlayerId)
if (seer.PlayerId == hostId)
{
rolesMap[(player.PlayerId, target.PlayerId)] = othersRole;
//ホスト視点は即確定
player.StartCoroutine(player.CoSetRole(hostRole, false));
}
else
{
rolesMap[(player.PlayerId, target.PlayerId)] = selfRole;
}
}

//他者視点
foreach (var seer in Main.AllPlayerControls)
{
if (player.PlayerId != seer.PlayerId)
{
rolesMap[(seer.PlayerId, player.PlayerId)] = othersRole;
var assignRole = seer.PlayerId == player.PlayerId ? BaseRole : RoleTypes.Scientist;
senders[player.PlayerId].RpcSetRole(player, assignRole, seer.GetClientId());
}
}
RpcSetRoleReplacer.OverriddenSenderList.Add(senders[player.PlayerId]);
//ホスト視点はロール決定
player.StartCoroutine(player.CoSetRole(othersRole, false));
//vailla配役の回避
player.Data.IsDead = true;
}
}
public static void MakeDesyncSender(Dictionary<byte, CustomRpcSender> senders, Dictionary<(byte, byte), RoleTypes> rolesMap)
{
var hostId = PlayerControl.LocalPlayer.PlayerId;
foreach (var seer in Main.AllPlayerControls)
{
var sender = senders[seer.PlayerId];
foreach (var target in Main.AllPlayerControls)
{
if (rolesMap.TryGetValue((seer.PlayerId, target.PlayerId), out var role))
{
sender.RpcSetRole(seer, role, target.GetClientId());
}
}
}
}

private static List<PlayerControl> AssignCustomRolesFromList(CustomRoles role, List<PlayerControl> players, int RawCount = -1)
{
if (players == null || players.Count <= 0) return null;
Expand Down Expand Up @@ -472,8 +443,7 @@ class RpcSetRoleReplacer
public static bool doReplace = false;
public static Dictionary<byte, CustomRpcSender> senders;
public static List<(PlayerControl, RoleTypes)> StoragedData = new();
// 役職Desyncなど別の処理でSetRoleRpcを書き込み済みなため、追加の書き込みが不要なSenderのリスト
public static List<CustomRpcSender> OverriddenSenderList;
public static List<byte> DesyncImpostorList;
public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] RoleTypes roleType)
{
if (doReplace && senders != null)
Expand All @@ -485,29 +455,32 @@ public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] RoleTyp
}
public static void Release()
{
foreach (var sender in senders)
foreach (var (player, role) in StoragedData)
{
if (OverriddenSenderList.Contains(sender.Value)) continue;
if (sender.Value.CurrentState != CustomRpcSender.State.InRootMessage)
throw new InvalidOperationException("A CustomRpcSender had Invalid State.");
//ホスト視点は即確定
player.StartCoroutine(player.CoSetRole(role, false));

foreach (var pair in StoragedData)
var impostorRole = role is RoleTypes.Impostor or RoleTypes.Shapeshifter or RoleTypes.Phantom;
if (impostorRole && DesyncImpostorList.Count != 0)
{
foreach (var seer in Main.AllPlayerControls)
{
var assignRole = DesyncImpostorList.Contains(seer.PlayerId) ? RoleTypes.Scientist : role;
senders[player.PlayerId].RpcSetRole(player, assignRole, seer.GetClientId());
}
}
else
{
pair.Item1.StartCoroutine(pair.Item1.CoSetRole(pair.Item2, false));
sender.Value.AutoStartRpc(pair.Item1.NetId, (byte)RpcCalls.SetRole, Utils.GetPlayerById(sender.Key).GetClientId())
.Write((ushort)pair.Item2)
.Write(false)
.EndRpc();
senders[player.PlayerId].RpcSetRole(player, role);
}
sender.Value.EndMessage();
}
doReplace = false;
}
public static void StartReplace(Dictionary<byte, CustomRpcSender> senders)
{
RpcSetRoleReplacer.senders = senders;
StoragedData = new();
OverriddenSenderList = new();
DesyncImpostorList = new();
doReplace = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This mod is not affiliated with Among Us or Innersloth LLC, and the content cont

## Releases

AmongUs Version: **2024.6.18**
AmongUs Version: **2024.8.13**

**Latest Version: [Here](https://github.com/tukasa0001/TownOfHost/releases/latest)**

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## リリース

AmongUsバージョン : **2024.6.18**
AmongUsバージョン : **2024.8.13**

**最新版は[こちら](https://github.com/tukasa0001/TownOfHost/releases/latest)**

Expand Down
6 changes: 3 additions & 3 deletions main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public class Main : BasePlugin
// ==========
//Sorry for many Japanese comments.
public const string PluginGuid = "com.emptybottle.townofhost";
public const string PluginVersion = "5.1.7";
public const string PluginVersion = "5.1.8";
// サポートされている最低のAmongUsバージョン
public static readonly string LowestSupportedVersion = "2024.6.18";
public static readonly string LowestSupportedVersion = "2024.8.13";
// このバージョンのみで公開ルームを無効にする場合
public static readonly bool IsPublicAvailableOnThisVersion = false;
// プレリリースかどうか
public static bool IsPrerelease { get; } = true;
public static bool IsPrerelease { get; } = false;
public Harmony Harmony { get; } = new Harmony(PluginGuid);
public static Version version = Version.Parse(PluginVersion);
public static Color UnityModColor
Expand Down