Skip to content

Commit

Permalink
Merge pull request #1308 from tukasa0001/develop-5.1.5
Browse files Browse the repository at this point in the history
Develop 5.1.5
  • Loading branch information
Hyz-sui authored Mar 6, 2024
2 parents 54f6e43 + 8883be1 commit 24fd73d
Show file tree
Hide file tree
Showing 36 changed files with 399 additions and 230 deletions.
42 changes: 40 additions & 2 deletions Modules/ExtendedPlayerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,35 @@ public static void RpcResetAbilityCooldown(this PlayerControl target)
ホストのクールダウンは直接リセットします。
*/
}
public static void RpcSpecificShapeshift(this PlayerControl player, PlayerControl target, bool shouldAnimate)
{
if (!AmongUsClient.Instance.AmHost) return;
if (player.PlayerId == 0)
{
player.Shapeshift(target, shouldAnimate);
return;
}
MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.Shapeshift, SendOption.Reliable, player.GetClientId());
messageWriter.WriteNetObject(target);
messageWriter.Write(shouldAnimate);
AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
}
public static void RpcSpecificRejectShapeshift(this PlayerControl player, PlayerControl target, bool shouldAnimate)
{
if (!AmongUsClient.Instance.AmHost) return;
foreach (var seer in Main.AllPlayerControls)
{
if (seer != player)
{
MessageWriter msg = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.RejectShapeshift, SendOption.Reliable, seer.GetClientId());
AmongUsClient.Instance.FinishRpcImmediately(msg);
}
else
{
player.RpcSpecificShapeshift(target, shouldAnimate);
}
}
}
public static void RpcDesyncUpdateSystem(this PlayerControl target, SystemTypes systemType, int amount)
{
MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(ShipStatus.Instance.NetId, (byte)RpcCalls.UpdateSystem, SendOption.Reliable, target.GetClientId());
Expand Down Expand Up @@ -570,9 +599,18 @@ public static PlainShipRoom GetPlainShipRoom(this PlayerControl pc)
}
return null;
}
public static void RpcSnapTo(this PlayerControl pc, Vector2 position)
public static void RpcSnapToForced(this PlayerControl pc, Vector2 position)
{
pc.NetTransform.RpcSnapTo(position);
var netTransform = pc.NetTransform;
if (AmongUsClient.Instance.AmClient)
{
netTransform.SnapTo(position, (ushort)(netTransform.lastSequenceId + 128));
}
ushort newSid = (ushort)(netTransform.lastSequenceId + 2);
MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(netTransform.NetId, (byte)RpcCalls.SnapTo, SendOption.Reliable);
NetHelpers.WriteVector2(position, messageWriter);
messageWriter.Write(newSid);
AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
}
public static void RpcSnapToDesync(this PlayerControl pc, PlayerControl target, Vector2 position)
{
Expand Down
2 changes: 2 additions & 0 deletions Modules/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public bool CanUseMovingPlatform
}
public (DateTime, byte) RealKiller;
public PlainShipRoom LastRoom;
/// <summary>会議等の後に湧いた後かどうか</summary>
public bool HasSpawned { get; set; } = false;
public Dictionary<byte, string> TargetColorData;
public PlayerState(byte playerId)
{
Expand Down
3 changes: 2 additions & 1 deletion Modules/OptionSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public static string GenerateModOptionsString()
/// <returns>生成された文字列</returns>
public static string GenerateVanillaOptionsString()
{
byte[] bytes = GameOptionsManager.Instance.gameOptionsFactory.ToBytes(GameOptionsManager.Instance.CurrentGameOptions);
// 保存時はエイプリルフール無効
byte[] bytes = GameOptionsManager.Instance.gameOptionsFactory.ToBytes(GameOptionsManager.Instance.CurrentGameOptions, false);
return Convert.ToBase64String(bytes);
}
/// <summary>
Expand Down
20 changes: 3 additions & 17 deletions Modules/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,10 @@ public enum CustomRPC
EndGame,
PlaySound,
SetCustomRole,
SetBountyTarget,
WitchSync,
SetSheriffShotLimit,
SetDousedPlayer,
SetNameColorData,
SniperSync,
SetLoversPlayers,
SetExecutionerTarget,
SetCurrentDousingTarget,
SetEvilTrackerTarget,
SetRealKiller,
SyncPuppet,
SetSchrodingerCatTeam,
StealthDarken,
EvilHackerCreateMurderNotify,
PenguinSync,
MareSync,
SyncPlagueDoctor,
CustomRoleSync,
}
public enum Sounds
{
Expand Down Expand Up @@ -153,8 +139,8 @@ public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] byte c
byte killerId = reader.ReadByte();
RPC.SetRealKiller(targetId, killerId);
break;
default:
CustomRoleManager.DispatchRpc(reader, rpcType);
case CustomRPC.CustomRoleSync:
CustomRoleManager.DispatchRpc(reader);
break;
}
}
Expand Down
12 changes: 12 additions & 0 deletions Modules/SystemEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace TownOfHost.Modules;

public static class SystemEnvironment
{
public static void SetEnvironmentVariables()
{
// ユーザ環境変数に最近開かれたTOHアモアスフォルダのパスを設定
Environment.SetEnvironmentVariable("TOWN_OF_HOST_DIR_ROOT", Environment.CurrentDirectory, EnvironmentVariableTarget.User);
}
}
1 change: 0 additions & 1 deletion Patches/AirshipStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public static bool Prefix()
{
if (PlayerControl.LocalPlayer.Is(CustomRoles.GM))
{
RandomSpawn.hostReady = true;
RandomSpawn.AirshipSpawn(PlayerControl.LocalPlayer);
// GMは湧き画面をスキップ
return false;
Expand Down
12 changes: 11 additions & 1 deletion Patches/ExilePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ static void WrapUpPostfix(GameData.PlayerInfo exiled)
exiled = AntiBlackout_LastExiled;
}

var mapId = Main.NormalOptions.MapId;
// エアシップではまだ湧かない
if ((MapNames)mapId != MapNames.Airship)
{
foreach (var state in PlayerState.AllPlayerStates.Values)
{
state.HasSpawned = true;
}
}

bool DecidedWinner = false;
if (!AmongUsClient.Instance.AmHost) return; //ホスト以外はこれ以降の処理を実行しません
AntiBlackout.RestoreIsDead(doSend: false);
Expand Down Expand Up @@ -76,7 +86,7 @@ static void WrapUpPostfix(GameData.PlayerInfo exiled)
if (RandomSpawn.IsRandomSpawn())
{
RandomSpawn.SpawnMap map;
switch (Main.NormalOptions.MapId)
switch (mapId)
{
case 0:
map = new RandomSpawn.SkeldSpawnMap();
Expand Down
4 changes: 2 additions & 2 deletions Patches/GameStartManagerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static bool Prefix(GameStartManager __instance)
Main.LastShapeshifterCooldown.Value = AURoleOptions.ShapeshifterCooldown;
AURoleOptions.ShapeshifterCooldown = 0f;

PlayerControl.LocalPlayer.RpcSyncSettings(GameOptionsManager.Instance.gameOptionsFactory.ToBytes(opt));
PlayerControl.LocalPlayer.RpcSyncSettings(GameOptionsManager.Instance.gameOptionsFactory.ToBytes(opt, AprilFoolsMode.IsAprilFoolsModeToggledOn));

__instance.ReallyBegin(false);
return false;
Expand Down Expand Up @@ -250,7 +250,7 @@ public static void Prefix()
if (GameStates.IsCountDown)
{
Main.NormalOptions.KillCooldown = Options.DefaultKillCooldown;
PlayerControl.LocalPlayer.RpcSyncSettings(GameOptionsManager.Instance.gameOptionsFactory.ToBytes(GameOptionsManager.Instance.CurrentGameOptions));
PlayerControl.LocalPlayer.RpcSyncSettings(GameOptionsManager.Instance.gameOptionsFactory.ToBytes(GameOptionsManager.Instance.CurrentGameOptions, AprilFoolsMode.IsAprilFoolsModeToggledOn));
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions Patches/IntroPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,22 @@ class IntroCutsceneDestroyPatch
public static void Postfix(IntroCutscene __instance)
{
if (!GameStates.IsInGame) return;

Main.introDestroyed = true;

var mapId = Main.NormalOptions.MapId;
// エアシップではまだ湧かない
if ((MapNames)mapId != MapNames.Airship)
{
foreach (var state in PlayerState.AllPlayerStates.Values)
{
state.HasSpawned = true;
}
}

if (AmongUsClient.Instance.AmHost)
{
if (Main.NormalOptions.MapId != 4)
if (mapId != 4)
{
Main.AllPlayerControls.Do(pc => pc.RpcResetAbilityCooldown());
if (Options.FixFirstKillCooldown.GetBool())
Expand All @@ -244,7 +256,7 @@ public static void Postfix(IntroCutscene __instance)
if (RandomSpawn.IsRandomSpawn())
{
RandomSpawn.SpawnMap map;
switch (Main.NormalOptions.MapId)
switch (mapId)
{
case 0:
map = new RandomSpawn.SkeldSpawnMap();
Expand Down
2 changes: 0 additions & 2 deletions Patches/MeetingHudPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ public static void Postfix()
if (AmongUsClient.Instance.AmHost)
{
AntiBlackout.SetIsDead();
Main.AllPlayerControls.Do(pc => RandomSpawn.FirstTP[pc.PlayerId] = true);
RandomSpawn.FastSpawnPosition.Clear();
}
// MeetingVoteManagerを通さずに会議が終了した場合の後処理
MeetingVoteManager.Instance?.Destroy();
Expand Down
74 changes: 74 additions & 0 deletions Patches/PlayerContorolPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,80 @@ public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] Player
CustomRoleManager.OnMurderPlayer(__instance, target);
}
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.CheckShapeshift))]
public static class PlayerControlCheckShapeshiftPatch
{
private static readonly LogHandler logger = Logger.Handler(nameof(PlayerControl.CheckShapeshift));

public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] PlayerControl target, [HarmonyArgument(1)] bool shouldAnimate)
{
if (AmongUsClient.Instance.IsGameOver || !AmongUsClient.Instance.AmHost)
{
return false;
}

// 無効な変身を弾く.これより前に役職等の処理をしてはいけない
if (!CheckInvalidShapeshifting(__instance, target, shouldAnimate))
{
__instance.RpcRejectShapeshift();
return false;
}
// 役職の処理
var role = __instance.GetRoleClass();
if (role?.OnCheckShapeshift(target, ref shouldAnimate) == false)
{
if (role.CanDesyncShapeshift)
{
__instance.RpcSpecificRejectShapeshift(target, shouldAnimate);
}
else
{
__instance.RpcRejectShapeshift();
}
return false;
}

__instance.RpcShapeshift(target, shouldAnimate);
return false;
}
private static bool CheckInvalidShapeshifting(PlayerControl instance, PlayerControl target, bool animate)
{
logger.Info($"Checking shapeshift {instance.GetNameWithRole()} -> {(target == null || target.Data == null ? "(null)" : target.GetNameWithRole())}");

if (!target || target.Data == null)
{
logger.Info("targetがnullのため変身をキャンセルします");
return false;
}
if (!instance.IsAlive())
{
logger.Info("変身者が死亡しているため変身をキャンセルします");
return false;
}
// RoleInfoによるdesyncシェイプシフター用の判定を追加
if (instance.Data.Role.Role != RoleTypes.Shapeshifter && instance.GetCustomRole().GetRoleInfo()?.BaseRoleType?.Invoke() != RoleTypes.Shapeshifter)
{
logger.Info("変身者がシェイプシフターではないため変身をキャンセルします");
return false;
}
if (instance.Data.Disconnected)
{
logger.Info("変身者が切断済のため変身をキャンセルします");
return false;
}
if (target.IsMushroomMixupActive() && animate)
{
logger.Info("キノコカオス中のため変身をキャンセルします");
return false;
}
if (MeetingHud.Instance && animate)
{
logger.Info("会議中のため変身をキャンセルします");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.Shapeshift))]
class ShapeshiftPatch
{
Expand Down
Loading

0 comments on commit 24fd73d

Please sign in to comment.