mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
Fixed crash issues by adding null checks
This commit is contained in:
1 parent
6e8b34745a
commit
ae8d53372d
4 files changed
+55
-18
No files matched your search
@@ -146,7 +146,14 @@ internal class PlayerInfoDisplay : MonoBehaviour
|
||||
/// </summary>
|
||||
private void UpdatePlayerInfo()
|
||||
{
|
||||
if (_player?.Data == null) return;
|
||||
if (_player == null) return;
|
||||
if (_player.Data == null) return;
|
||||
|
||||
if (_nameText == null) return;
|
||||
if (_cachedTranslations == null) return;
|
||||
|
||||
if (_sbTag == null || _sbTagTop == null || _sbTagBottom == null) return;
|
||||
if (_topText == null || _bottomText == null || _infoText == null) return;
|
||||
|
||||
var betterData = _player.BetterData();
|
||||
|
||||
@@ -169,19 +176,19 @@ internal class PlayerInfoDisplay : MonoBehaviour
|
||||
|
||||
string friendCode = ValidateFriendCode(out string friendCodeColor);
|
||||
|
||||
if (DataManager.Settings == null || DataManager.Settings.Gameplay == null)
|
||||
return;
|
||||
|
||||
if (DataManager.Settings.Gameplay.StreamerMode)
|
||||
{
|
||||
platform = _cachedTranslations.PlatformHidden;
|
||||
}
|
||||
|
||||
if (!_player.IsInShapeshift())
|
||||
{
|
||||
SetPlayerOutline(_sbTag);
|
||||
}
|
||||
|
||||
if (GameState.IsInGame && GameState.IsLobby && !GameState.IsFreePlay)
|
||||
{
|
||||
SetLobbyInfo(ref newName, betterData, _sbTag);
|
||||
|
||||
_sbTagTop.Append($"<color=#9e9e9e>{platform}</color>+++")
|
||||
.Append($"<color=#ffd829>Lv: {_player.Data.PlayerLevel + 1}</color>+++");
|
||||
|
||||
@@ -196,15 +203,21 @@ internal class PlayerInfoDisplay : MonoBehaviour
|
||||
{
|
||||
if (_player.IsImpostorTeammate())
|
||||
newName = newName.ToColor(Colors.ImpostorRed);
|
||||
|
||||
_player.RawSetName(newName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var targetData = Utils.PlayerDataFromPlayerId(_player.shapeshiftTargetPlayerId);
|
||||
var name = targetData.BetterData()?.RealName ?? targetData.PlayerName;
|
||||
if (targetData == null) return;
|
||||
|
||||
var betterTargetData = targetData.BetterData();
|
||||
string name = betterTargetData != null ? betterTargetData.RealName : targetData.PlayerName;
|
||||
|
||||
if (_player.IsImpostorTeammate())
|
||||
name = name.ToColor(Colors.ImpostorRed);
|
||||
if (targetData != null) _player.RawSetName(name);
|
||||
|
||||
_player.RawSetName(name);
|
||||
}
|
||||
|
||||
UpdateTextIfChanged(_topText, _sbTagTop, ref _lastTopText);
|
||||
|
||||
@@ -54,7 +54,9 @@ internal static class PlayerControlPatch
|
||||
[HarmonyPostfix]
|
||||
private static void PlayerControl_MurderPlayer_Postfix(PlayerControl __instance, PlayerControl target)
|
||||
{
|
||||
if (target == null) return;
|
||||
// Check for null references
|
||||
if (__instance == null || target == null || target.Data == null || __instance.Data == null)
|
||||
return;
|
||||
|
||||
// Log kill event with player names and roles
|
||||
Logger_.LogPrivate($"{__instance.Data.PlayerName} Has killed {target.Data.PlayerName} as {__instance.Data.RoleType.GetRoleName()}", "EventLog");
|
||||
|
||||
@@ -16,6 +16,10 @@ internal static class GameSummaryPatch
|
||||
[HarmonyPostfix]
|
||||
private static void EndGameManager_SetEverythingUp_Postfix(EndGameManager __instance)
|
||||
{
|
||||
// Check for null references
|
||||
if (__instance == null)
|
||||
return;
|
||||
|
||||
LogGameEnd();
|
||||
|
||||
if (!BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_EndGameSummary))
|
||||
|
||||
@@ -15,23 +15,32 @@ internal static class MeetingHudPatch
|
||||
[HarmonyPostfix]
|
||||
private static void MeetingHud_Start_Postfix(MeetingHud __instance)
|
||||
{
|
||||
if (__instance == null || __instance.playerStates == null) return;
|
||||
|
||||
foreach (var pva in __instance.playerStates)
|
||||
{
|
||||
if (pva == null) continue;
|
||||
|
||||
var target = Utils.PlayerFromPlayerId(pva.TargetPlayerId);
|
||||
if (target == null) continue;
|
||||
|
||||
pva.gameObject.AddComponent<MeetingInfoDisplay>().Init(target, pva);
|
||||
}
|
||||
|
||||
if (!GameState.IsOnlineGame) return;
|
||||
|
||||
// Add host icon to meeting hud
|
||||
__instance.ProceedButton.gameObject.transform.localPosition = new(-2.5f, 2.2f, 0);
|
||||
__instance.ProceedButton.gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||||
__instance.ProceedButton.GetComponent<PassiveButton>().enabled = false;
|
||||
__instance.HostIcon.enabled = true;
|
||||
__instance.HostIcon.gameObject.SetActive(true);
|
||||
__instance.ProceedButton.gameObject.SetActive(true);
|
||||
MeetingHud.Instance.ProceedButton.DestroyTextTranslators();
|
||||
UpdateHostIcon();
|
||||
if (__instance.ProceedButton != null && __instance.HostIcon != null)
|
||||
{
|
||||
__instance.ProceedButton.gameObject.transform.localPosition = new(-2.5f, 2.2f, 0);
|
||||
__instance.ProceedButton.gameObject.GetComponent<SpriteRenderer>().enabled = false;
|
||||
__instance.ProceedButton.GetComponent<PassiveButton>().enabled = false;
|
||||
__instance.HostIcon.enabled = true;
|
||||
__instance.HostIcon.gameObject.SetActive(true);
|
||||
__instance.ProceedButton.gameObject.SetActive(true);
|
||||
UpdateHostIcon();
|
||||
MeetingHud.Instance.ProceedButton.DestroyTextTranslators();
|
||||
}
|
||||
|
||||
Logger_.LogHeader("Meeting Has Started");
|
||||
}
|
||||
@@ -39,9 +48,18 @@ internal static class MeetingHudPatch
|
||||
internal static void UpdateHostIcon()
|
||||
{
|
||||
if (MeetingHud.Instance == null) return;
|
||||
if (GameData.Instance == null) return;
|
||||
|
||||
PlayerMaterial.SetColors(GameData.Instance.GetHost().Color, MeetingHud.Instance.HostIcon);
|
||||
MeetingHud.Instance.ProceedButton.gameObject.GetComponentInChildren<TextMeshPro>().text = string.Format(Translator.GetString("HostInMeeting"), GameData.Instance.GetHost().BetterData().RealName);
|
||||
var host = GameData.Instance.GetHost();
|
||||
if (host == null || host.BetterData() == null) return;
|
||||
|
||||
var hostColor = host.Color;
|
||||
var hostRealName = host.BetterData().RealName;
|
||||
|
||||
if (MeetingHud.Instance.HostIcon == null || MeetingHud.Instance.ProceedButton == null) return;
|
||||
|
||||
PlayerMaterial.SetColors(hostColor, MeetingHud.Instance.HostIcon);
|
||||
MeetingHud.Instance.ProceedButton.gameObject.GetComponentInChildren<TextMeshPro>().text = string.Format(Translator.GetString("HostInMeeting"), hostRealName);
|
||||
}
|
||||
|
||||
internal static float timeOpen = 0f;
|
||||
|
||||
Reference in new issue
Block a user