Skip to content

Commit

Permalink
Remove CachedPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyx0412 committed Feb 2, 2025
1 parent fcc7f3c commit b42d696
Show file tree
Hide file tree
Showing 54 changed files with 971 additions and 1,110 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v1.1.2.0更新日志
v1.1.2.1更新日志

* 修复部分bug。
* 修复掷弹兵使用技能时可能会导致所有玩家游戏卡死的问题
* 怨灵: 新增选项 "拾取尸体后本轮会议结束才可复活"
* 还有其它一些小优化
806 changes: 403 additions & 403 deletions TheOtherRoles/Buttons/Buttons.cs

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions TheOtherRoles/Buttons/CustomButton.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using TheOtherRoles.Utilities;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
Expand Down Expand Up @@ -90,8 +89,8 @@ public void onClickEvent()
OnClick();

// Deputy skip onClickEvent if handcuffed
if (Sheriff.handcuffedKnows.ContainsKey(CachedPlayer.LocalPlayer.PlayerId) &&
Sheriff.handcuffedKnows[CachedPlayer.LocalPlayer.PlayerId] > 0f) return;
if (Sheriff.handcuffedKnows.ContainsKey(PlayerControl.LocalPlayer.PlayerId) &&
Sheriff.handcuffedKnows[PlayerControl.LocalPlayer.PlayerId] > 0f) return;

if (!HasEffect || isEffectActive) return;
DeputyTimer = EffectDuration;
Expand Down Expand Up @@ -135,7 +134,7 @@ public static void MeetingEndedUpdate()
public static void ResetAllCooldowns(float Time = -1)
{
var time = Time == -1 ? ModOption.KillCooddown : Time;
CachedPlayer.LocalPlayer.PlayerControl.killTimer = time - 0.6f;
PlayerControl.LocalPlayer.killTimer = time - 0.6f;
foreach (var t in buttons)
{
var maxTime = Time == -1 ? t.MaxTimer : Time;
Expand Down Expand Up @@ -196,7 +195,7 @@ public CustomButton SetTimer(float timer)

public void Update()
{
var localPlayer = CachedPlayer.LocalPlayer;
var localPlayer = PlayerControl.LocalPlayer;

if (localPlayer.Data == null || MeetingHud.Instance || ExileController.Instance || !HasButton())
{
Expand All @@ -211,7 +210,7 @@ public void Update()
// This had to be reordered, so that the handcuffs do not stop the underlying timers from running
if (HasEffect && isEffectActive)
DeputyTimer -= Time.deltaTime;
else if (!localPlayer.PlayerControl.inVent)
else if (!localPlayer.inVent)
DeputyTimer -= Time.deltaTime;
}

Expand Down Expand Up @@ -260,7 +259,7 @@ public void Update()
{
if (HasEffect && isEffectActive)
Timer -= Time.deltaTime;
else if (!localPlayer.PlayerControl.inVent)
else if (!localPlayer.inVent)
Timer -= Time.deltaTime;
}

Expand Down
3 changes: 1 addition & 2 deletions TheOtherRoles/GameHistory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TheOtherRoles.Utilities;
using UnityEngine;

namespace TheOtherRoles;
Expand Down Expand Up @@ -84,7 +83,7 @@ public static void OverrideDeathReasonAndKiller(PlayerControl player, CustomDeat
public static void RpcOverrideDeathReasonAndKiller(PlayerControl player, CustomDeathReason deathReason, PlayerControl killer)
{
if (player.IsAlive()) return;
var writer = StartRPC(CachedPlayer.LocalPlayer.PlayerControl.NetId, CustomRPC.ShareGhostInfo);
var writer = StartRPC(PlayerControl.LocalPlayer.NetId, CustomRPC.ShareGhostInfo);
writer.Write(player.PlayerId);
writer.Write((byte)RPCProcedure.GhostInfoTypes.DeathReasonAndKiller);
writer.Write(player.PlayerId);
Expand Down
4 changes: 1 addition & 3 deletions TheOtherRoles/Helper/FastRPCExtension.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Linq;
using Hazel;
using InnerNet;
using TheOtherRoles.Utilities;
using UnityEngine;

namespace TheOtherRoles.Helper;
Expand All @@ -29,7 +27,7 @@ public static Rect ReadRect(this MessageReader reader)
public static PlayerControl ReadPlayer(this MessageReader reader)
{
var id = reader.ReadByte();
return CachedPlayer.AllPlayers.FirstOrDefault(n => n.PlayerId == id);
return PlayerControl.AllPlayerControls.FirstOrDefault(n => n.PlayerId == id);
}

public static Il2CppStructArray<byte> ReadBytesFormLength(this MessageReader reader)
Expand Down
57 changes: 33 additions & 24 deletions TheOtherRoles/Helper/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static bool hasImpVision(GameData.PlayerInfo player)

public static void handleTrapperTrapOnBodyReport()
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.TrapperMeetingFlag, SendOption.Reliable, -1);
AmongUsClient.Instance.FinishRpcImmediately(writer);
RPCProcedure.trapperMeetingFlag();
Expand Down Expand Up @@ -231,11 +231,11 @@ public static bool checkAndDoVetKill(PlayerControl target)
var shouldVetKill = Veteran.veteran == target && Veteran.alertActive;
if (shouldVetKill)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.VeteranKill, SendOption.Reliable);
writer.Write(CachedPlayer.LocalPlayer.PlayerControl.PlayerId);
writer.Write(PlayerControl.LocalPlayer.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
RPCProcedure.veteranKill(CachedPlayer.LocalPlayer.PlayerControl.PlayerId);
RPCProcedure.veteranKill(PlayerControl.LocalPlayer.PlayerId);
}

return shouldVetKill;
Expand Down Expand Up @@ -349,7 +349,7 @@ public static bool roleCanSabotage(this PlayerControl player)

public static SabatageTypes GetActiveSabo()
{
foreach (var task in CachedPlayer.LocalPlayer.PlayerControl.myTasks.GetFastEnumerator())
foreach (var task in PlayerControl.LocalPlayer.myTasks.GetFastEnumerator())
if (task.TaskType == TaskTypes.FixLights)
return SabatageTypes.Lights;
else if (task.TaskType == TaskTypes.RestoreOxy)
Expand Down Expand Up @@ -435,7 +435,7 @@ public static int getAvailableId()

public static void turnToImpostorRPC(PlayerControl player)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.TurnToImpostor, SendOption.Reliable);
writer.Write(player.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
Expand All @@ -451,7 +451,7 @@ public static void turnToImpostor(PlayerControl player)
Message("PROOF I AM IMP VANILLA ROLE: " + player.Data.Role.IsImpostor);

foreach (var player2 in PlayerControl.AllPlayerControls)
if (player2.Data.Role.IsImpostor && CachedPlayer.LocalPlayer.PlayerControl.Data.Role.IsImpostor)
if (player2.Data.Role.IsImpostor && PlayerControl.LocalPlayer.Data.Role.IsImpostor)
player.cosmetics.nameText.color = Palette.ImpostorRed;
}

Expand Down Expand Up @@ -660,22 +660,23 @@ public static List<RoleInfo> allRoleInfos()
public static List<RoleInfo> onlineRoleInfos()
{
var role = new List<RoleInfo>();
role.AddRange(CachedPlayer.AllPlayers.Select(n => RoleInfo.getRoleInfoForPlayer(n, false, false)).SelectMany(x => x));
role.AddRange(PlayerControl.AllPlayerControls.ToList()
.Select(n => RoleInfo.getRoleInfoForPlayer(n, false, false)).SelectMany(x => x));
return role;
}

public static PlayerControl playerById(byte? id)
{
if (id == null) return null;
foreach (PlayerControl player in CachedPlayer.AllPlayers)
foreach (PlayerControl player in PlayerControl.AllPlayerControls.ToList())
if (player.PlayerId == id)
return player;
return null;
}

public static bool isSabotageActive()
{
foreach (var task in CachedPlayer.LocalPlayer.PlayerControl.myTasks.GetFastEnumerator())
foreach (var task in PlayerControl.LocalPlayer.myTasks.GetFastEnumerator())
if (task.TaskType == TaskTypes.FixLights || task.TaskType == TaskTypes.RestoreOxy ||
task.TaskType == TaskTypes.ResetReactor || task.TaskType == TaskTypes.ResetSeismic ||
task.TaskType == TaskTypes.FixComms || task.TaskType == TaskTypes.StopCharles
Expand All @@ -688,7 +689,7 @@ public static void handleVampireBiteOnBodyReport()
{
// Murder the bitten player and reset bitten (regardless whether the kill was successful or not)
checkMurderAttemptAndKill(Vampire.vampire, Vampire.bitten, true, false);
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.VampireSetBitten, SendOption.Reliable);
writer.Write(byte.MaxValue);
writer.Write(byte.MaxValue);
Expand All @@ -700,7 +701,7 @@ public static void handleBomberExplodeOnBodyReport()
{
// Murder the bitten player and reset bitten (regardless whether the kill was successful or not)
checkMurderAttemptAndKill(Bomber.bomber, Bomber.hasBombPlayer, true, false);
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.GiveBomb, SendOption.Reliable);
writer.Write(byte.MaxValue);
writer.Write(false);
Expand Down Expand Up @@ -797,7 +798,7 @@ public static bool IsDead(this PlayerControl player)

public static void setInvisable(PlayerControl player)
{
var invisibleWriter = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var invisibleWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.SetInvisibleGen, SendOption.Reliable);
invisibleWriter.Write(player.PlayerId);
invisibleWriter.Write(byte.MinValue);
Expand Down Expand Up @@ -829,10 +830,18 @@ public static GameObject[] GetChildren(this GameObject ParentObject)

public static bool shouldShowGhostInfo()
{
return (PlayerControl.LocalPlayer.IsDead() && CanSeeRoleInfo) ||
return (PlayerControl.LocalPlayer.Data.IsDead && CanSeeRoleInfo) ||
AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Ended;
}

public static bool ZoomButtonActive()
{
if (!shouldShowGhostInfo() || InMeeting) return false;
var (playerCompleted, playerTotal) = TasksHandler.taskInfo(PlayerControl.LocalPlayer.Data);
var numberOfLeftTasks = playerTotal - playerCompleted;
return numberOfLeftTasks <= 0 || !CustomOptionHolder.finishTasksBeforeHauntingOrZoomingOut.GetBool();
}

public static void clearAllTasks(this PlayerControl player)
{
if (player == null) return;
Expand Down Expand Up @@ -988,7 +997,7 @@ public static void setLook(this PlayerControl target, string playerName, int col
target.RawSetColor(colorId);
target.RawSetVisor(visorId, colorId);
target.RawSetHat(hatId, colorId);
target.RawSetName(hidePlayerName(CachedPlayer.LocalPlayer.PlayerControl, target) ? "" : playerName);
target.RawSetName(hidePlayerName(PlayerControl.LocalPlayer, target) ? "" : playerName);


SkinViewData nextSkin = null;
Expand Down Expand Up @@ -1130,7 +1139,7 @@ public static MurderAttemptResult checkMuderAttempt(PlayerControl killer, Player
// Handle blank shot
if (!ignoreBlank && Pursuer.blankedList.Any(x => x.PlayerId == killer.PlayerId))
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.PursuerSetBlanked, SendOption.Reliable);
writer.Write(killer.PlayerId);
writer.Write((byte)0);
Expand Down Expand Up @@ -1175,7 +1184,7 @@ public static MurderAttemptResult checkMuderAttempt(PlayerControl killer, Player
// Block impostor shielded kill
if (!Medic.unbreakableShield && Medic.shielded != null && Medic.shielded == target)
{
var write = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var write = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.PursuerSetBlanked, SendOption.Reliable);
write.Write(killer.PlayerId);
write.Write((byte)0);
Expand Down Expand Up @@ -1222,7 +1231,7 @@ public static MurderAttemptResult checkMuderAttempt(PlayerControl killer, Player

if (Cursed.cursed != null && Cursed.cursed == target && killer.Data.Role.IsImpostor)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.PursuerSetBlanked, SendOption.Reliable);
writer.Write(killer.PlayerId);
writer.Write((byte)0);
Expand Down Expand Up @@ -1251,7 +1260,7 @@ public static MurderAttemptResult checkMuderAttempt(PlayerControl killer, Player

public static void MurderPlayer(PlayerControl killer, PlayerControl target, bool showAnimation)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.UncheckedMurderPlayer, SendOption.Reliable);
writer.Write(killer.PlayerId);
writer.Write(target.PlayerId);
Expand All @@ -1274,7 +1283,7 @@ public static MurderAttemptResult checkMurderAttemptAndKill(PlayerControl killer
if (Mimic.mimic != null && killer == Mimic.mimic && !Mimic.hasMimic)
{
var writerMimic = AmongUsClient.Instance.StartRpcImmediately(
CachedPlayer.LocalPlayer.PlayerControl.NetId, (byte)CustomRPC.MimicMimicRole, SendOption.Reliable);
PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.MimicMimicRole, SendOption.Reliable);
writerMimic.Write(target.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writerMimic);
Mimic.MimicRole(target.PlayerId);
Expand All @@ -1288,7 +1297,7 @@ public static MurderAttemptResult checkMurderAttemptAndKill(PlayerControl killer
{
if (!target.isUsingTransportation() && Vampire.bitten != null)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.VampireSetBitten, SendOption.Reliable);
writer.Write(byte.MaxValue);
writer.Write(byte.MaxValue);
Expand All @@ -1302,7 +1311,7 @@ public static MurderAttemptResult checkMurderAttemptAndKill(PlayerControl killer
if (murder == MurderAttemptResult.BodyGuardKill)
{
// Kill the Killer
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.UncheckedMurderPlayer, SendOption.Reliable);
writer.Write(BodyGuard.bodyguard.PlayerId);
writer.Write(killer.PlayerId);
Expand All @@ -1311,15 +1320,15 @@ public static MurderAttemptResult checkMurderAttemptAndKill(PlayerControl killer
RPCProcedure.uncheckedMurderPlayer(BodyGuard.bodyguard.PlayerId, killer.PlayerId, 0);

// Kill the BodyGuard
var writer2 = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer2 = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.UncheckedMurderPlayer, SendOption.Reliable);
writer2.Write(killer.PlayerId);
writer2.Write(BodyGuard.bodyguard.PlayerId);
writer2.Write(showAnimation ? byte.MaxValue : 0);
AmongUsClient.Instance.FinishRpcImmediately(writer2);
RPCProcedure.uncheckedMurderPlayer(BodyGuard.bodyguard.PlayerId, BodyGuard.bodyguard.PlayerId, 0);

var writer3 = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
var writer3 = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte)CustomRPC.ShowBodyGuardFlash, SendOption.Reliable);
AmongUsClient.Instance.FinishRpcImmediately(writer3);
RPCProcedure.showBodyGuardFlash();
Expand Down
Loading

0 comments on commit b42d696

Please sign in to comment.