Esempio n. 1
0
 private void MenuSceneLoadedFresh()
 {
     ModelSaberAPI.HashAllAvatars();
     PluginUI.OnLoad();
     InGameOnlineController.OnLoad();
     SpectatingController.OnLoad();
     GetUserInfo.UpdateUserInfo();
 }
Esempio n. 2
0
        private void MenuSceneLoadedFresh()
        {
            ModelSaberAPI.HashAllAvatars();
            PluginUI.OnLoad();
            InGameOnlineController.OnLoad();
            SpectatingController.OnLoad();
            GetUserInfo.UpdateUserInfo();

            if (joinAfterRestart)
            {
                joinAfterRestart = false;
                SharedCoroutineStarter.instance.StartCoroutine(PluginUI.instance.JoinGameWithSecret(joinSecret));
                joinSecret = string.Empty;
            }
        }
        public void SetPlayerPacket(PlayerPacket _playerInfo, Vector3 offsetVector, bool isLocal)
        {
            if (_playerInfo == null)
            {
                playerNameText.gameObject.SetActive(false);
                if (rendererEnabled)
                {
                    SetRendererInChilds(avatar.GameObject.transform, false);
                    rendererEnabled = false;
                }
                return;
            }

            try
            {
                playerInfo = _playerInfo;

                if (!playerNameText)
                {
                    return;
                }
                if (avatar == null || ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key != playerInfo.avatarHash)
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerInfo.avatarHash))
                    {
                        if (ModelSaberAPI.cachedAvatars[playerInfo.avatarHash].IsLoaded)
                        {
                            if (avatar != null)
                            {
                                Destroy(avatar.GameObject);
                            }

                            avatar = AvatarSpawner.SpawnAvatar(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash], this);
                        }
                        else if (!pendingAvatars.Contains(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]))
                        {
                            pendingAvatars.Add(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                            ModelSaberAPI.cachedAvatars[playerInfo.avatarHash].Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                            {
                                if (result == AvatarLoadResult.Completed)
                                {
                                    pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                                    AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key, loadedAvatar);
                                }
                            });
                            AvatarLoaded += AvatarController_AvatarLoaded;
                        }
                        else
                        {
                            AvatarLoaded -= AvatarController_AvatarLoaded;
                            AvatarLoaded += AvatarController_AvatarLoaded;
                        }
                    }
                    else
                    {
                        if (ModelSaberAPI.queuedAvatars.Contains(playerInfo.avatarHash))
                        {
                            ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                        }
                        else
                        {
                            SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerInfo.avatarHash, (CustomAvatar.CustomAvatar avatar) => { AvatarDownloaded(playerInfo.avatarHash, avatar); }));
                        }
                    }
                }

                if (isLocal)
                {
                    playerNameText.gameObject.SetActive(false);
#if !DEBUG
                    if (rendererEnabled)
                    {
                        SetRendererInChilds(avatar.GameObject.transform, false);
                        rendererEnabled = false;
                    }
#endif
                }
                else
                {
                    playerNameText.gameObject.SetActive(true);
                    if (!rendererEnabled)
                    {
                        SetRendererInChilds(avatar.GameObject.transform, true);
                        rendererEnabled = true;
                    }
                }
                interpolationProgress = 0f;


                lastHeadPos   = targetHeadPos;
                targetHeadPos = _playerInfo.headPos + offsetVector;

                lastRightHandPos   = targetRightHandPos;
                targetRightHandPos = _playerInfo.rightHandPos + offsetVector;

                lastLeftHandPos   = targetLeftHandPos;
                targetLeftHandPos = _playerInfo.leftHandPos + offsetVector;

                lastHeadRot   = targetHeadRot;
                targetHeadRot = _playerInfo.headRot;

                lastRightHandRot   = targetRightHandRot;
                targetRightHandRot = _playerInfo.rightHandRot;

                lastLeftHandRot   = targetLeftHandRot;
                targetLeftHandRot = _playerInfo.leftHandRot;

                playerNameText.text = playerInfo.playerName;

                if (forcePlayerPacket)
                {
                    interpHeadPos      = targetHeadPos;
                    interpLeftHandPos  = targetLeftHandPos;
                    interpRightHandPos = targetRightHandPos;

                    interpHeadRot      = targetHeadRot;
                    interpLeftHandRot  = targetLeftHandRot;
                    interpRightHandRot = targetRightHandRot;

                    transform.position = interpHeadPos;
                }
            }
            catch (Exception e)
            {
                Logger.Error($"Avatar controller exception: {_playerInfo.playerName}: {e}");
            }
        }
        public void SetPlayerInfo(PlayerInfo _playerInfo, float offset, bool isLocal)
        {
            if (_playerInfo == default)
            {
                if (playerNameText != null)
                {
                    playerNameText.gameObject.SetActive(false);
                }
                if (playerSpeakerIcon != null)
                {
                    playerSpeakerIcon.gameObject.SetActive(false);
                }
                if (avatar != null && avatar.GameObject != null)
                {
                    Destroy(avatar.GameObject);
                }
                return;
            }

            try
            {
                playerInfo       = _playerInfo.updateInfo;
                playerId         = _playerInfo.playerId;
                playerAvatarHash = _playerInfo.avatarHash;
                playerName       = _playerInfo.playerName;

                if (playerNameText != null && playerSpeakerIcon != null)
                {
                    if (isLocal)
                    {
                        playerNameText.gameObject.SetActive(false);
                        playerSpeakerIcon.gameObject.SetActive(false);
#if !DEBUG
                        if (avatar != null)
                        {
                            Destroy(avatar.GameObject);
                        }
#endif
                    }
                    else
                    {
                        playerNameText.gameObject.SetActive(true);
                        playerNameText.alignment = TextAlignmentOptions.Center;
                        playerSpeakerIcon.gameObject.SetActive(InGameOnlineController.Instance.VoiceChatIsTalking(playerId));
                    }
                }
                else
                {
                    return;
                }
#if !DEBUG
                if ((avatar == null || currentAvatarHash != playerAvatarHash) && !isLocal)
#else
                if ((avatar == null || currentAvatarHash != playerAvatarHash))
#endif
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerAvatarHash))
                    {
                        CustomAvatar.CustomAvatar cachedAvatar = ModelSaberAPI.cachedAvatars[playerAvatarHash];

                        if (cachedAvatar != null)
                        {
                            if (pendingAvatars.Contains(cachedAvatar))
                            {
                                AvatarLoaded -= AvatarController_AvatarLoaded;
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                            else if (!pendingAvatars.Contains(cachedAvatar) && !cachedAvatar.IsLoaded)
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                pendingAvatars.Add(cachedAvatar);
                                AvatarLoaded -= AvatarController_AvatarLoaded;
                                AvatarLoaded += AvatarController_AvatarLoaded;
                                cachedAvatar.Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                                {
                                    if (result == AvatarLoadResult.Completed)
                                    {
                                        pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerAvatarHash]);
                                        AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == loadedAvatar).Key);
                                    }
                                });
                            }
                            else
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(cachedAvatar, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                currentAvatarHash = playerAvatarHash;
                            }
                        }
                    }
                    else
                    {
                        if (Config.Instance.DownloadAvatars)
                        {
                            if (ModelSaberAPI.queuedAvatars.Contains(playerAvatarHash))
                            {
                                ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;
                                ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                            }
                            else
                            {
                                ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;
                                ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                                SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerAvatarHash));

                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }
                            }
                        }
                    }
                }

                Vector3 offsetVector = new Vector3(offset, 0f, 0f);

                HeadPos      = playerInfo.headPos + offsetVector;
                RightHandPos = playerInfo.rightHandPos + offsetVector;
                LeftHandPos  = playerInfo.leftHandPos + offsetVector;

                HeadRot      = playerInfo.headRot;
                RightHandRot = playerInfo.rightHandRot;
                LeftHandRot  = playerInfo.leftHandRot;

                if (playerInfo.fullBodyTracking)
                {
                    RightLegPos = playerInfo.rightLegPos + offsetVector;
                    LeftLegPos  = playerInfo.leftLegPos + offsetVector;
                    PelvisPos   = playerInfo.pelvisPos + offsetVector;
                    RightLegRot = playerInfo.rightLegRot;
                    LeftLegRot  = playerInfo.leftLegRot;
                    PelvisRot   = playerInfo.pelvisRot;
                }
                else
                {
                    RightLegPos = new Vector3();
                    LeftLegPos  = new Vector3();
                    PelvisPos   = new Vector3();
                    RightLegRot = new Quaternion();
                    LeftLegRot  = new Quaternion();
                    PelvisRot   = new Quaternion();
                }

                transform.position = HeadPos;

                playerNameText.text = playerName;

                if (playerInfo.playerFlags.rainbowName && !rainbowName)
                {
                    playerNameText.color = playerInfo.playerNameColor;
                    nameColor            = HSBColor.FromColor(playerInfo.playerNameColor);
                }
                else if (!playerInfo.playerFlags.rainbowName && playerNameText.color != playerInfo.playerNameColor)
                {
                    playerNameText.color = playerInfo.playerNameColor;
                }

                rainbowName = playerInfo.playerFlags.rainbowName;
            }
            catch (Exception e)
            {
                Plugin.log.Critical(e);
            }
        }
Esempio n. 5
0
        public void SetPlayerInfo(PlayerInfo _playerInfo, float offset, bool isLocal)
        {
            if (_playerInfo == default)
            {
                if (playerNameText != null)
                {
                    playerNameText.gameObject.SetActive(false);
                }
                if (playerSpeakerIcon != null)
                {
                    playerSpeakerIcon.gameObject.SetActive(false);
                }
                if (avatar != null && avatar.eventsPlayer != null)
                {
                    avatar.Destroy();
                    avatar = null;
                }
                return;
            }

            try
            {
                playerInfo       = _playerInfo.updateInfo;
                playerId         = _playerInfo.playerId;
                playerAvatarHash = _playerInfo.avatarHash;
                playerName       = _playerInfo.playerName;

                if (playerNameText != null && playerSpeakerIcon != null)
                {
                    if (isLocal)
                    {
                        playerNameText.gameObject.SetActive(false);
                        playerSpeakerIcon.gameObject.SetActive(false);
#if !DEBUG
                        if (avatar != null && avatar.eventsPlayer != null)
                        {
                            avatar.Destroy();
                        }
#endif
                    }
                    else
                    {
                        playerNameText.gameObject.SetActive(true);
                        playerNameText.alignment = TextAlignmentOptions.Center;
                        playerSpeakerIcon.gameObject.SetActive(InGameOnlineController.Instance.VoiceChatIsTalking(playerId));
                    }
                }
                else
                {
                    return;
                }
#if !DEBUG
                if ((avatar == null || currentAvatarHash != playerAvatarHash) && !isLocal)
#else
                if ((avatar == null || currentAvatarHash != playerAvatarHash))
#endif
                {
                    if (unableToSpawnAvatar)
                    {
                        if (retryTimeCounter + 5f > Time.realtimeSinceStartup)
                        {
                            retryTimeCounter    = -1f;
                            unableToSpawnAvatar = false;
                        }
                    }
                    else
                    {
                        if (ModelSaberAPI.cachedAvatars.ContainsKey(playerAvatarHash))
                        {
                            LoadedAvatar cachedAvatar = ModelSaberAPI.cachedAvatars[playerAvatarHash];

                            if (cachedAvatar != null)
                            {
                                if (avatar != null && avatar.eventsPlayer != null)
                                {
                                    avatar.Destroy();
                                    avatar = null;
                                }

                                avatar = AvatarManager.SpawnAvatar(cachedAvatar, avatarInput);
                                avatar.SetChildrenToLayer(10);

                                currentAvatarHash = playerAvatarHash;
                            }
                            else
                            {
                                unableToSpawnAvatar = true;
                                retryTimeCounter    = Time.realtimeSinceStartup;
                            }
                        }
                        else
                        {
                            if (Config.Instance.DownloadAvatars)
                            {
                                if (!Config.Instance.DownloadNSFWAvatars && ModelSaberAPI.nsfwAvatars.Contains(playerAvatarHash))
                                {
                                    unableToSpawnAvatar = true;
                                    retryTimeCounter    = Time.realtimeSinceStartup;
                                }
                                else
                                {
                                    ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;
                                    ModelSaberAPI.avatarDownloaded += AvatarDownloaded;

                                    if (!ModelSaberAPI.queuedAvatars.Contains(playerAvatarHash))
                                    {
                                        SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerAvatarHash));

                                        if (avatar != null && avatar.eventsPlayer != null)
                                        {
                                            avatar.Destroy();
                                        }

                                        avatar = AvatarManager.SpawnAvatar(defaultAvatarInstance, avatarInput);
                                        avatar.SetChildrenToLayer(10);
                                    }
                                }
                            }
                        }
                    }
                }

                Vector3 offsetVector = new Vector3(offset, 0f, 0f);

                avatarInput.headPos      = playerInfo.headPos + offsetVector;
                avatarInput.rightHandPos = playerInfo.rightHandPos + offsetVector;
                avatarInput.leftHandPos  = playerInfo.leftHandPos + offsetVector;

                avatarInput.headRot      = playerInfo.headRot;
                avatarInput.rightHandRot = playerInfo.rightHandRot;
                avatarInput.leftHandRot  = playerInfo.leftHandRot;

                avatarInput.poseValid = true;

                avatarInput.fullBodyTracking = playerInfo.fullBodyTracking;
                if (playerInfo.fullBodyTracking)
                {
                    avatarInput.rightLegPos = playerInfo.rightLegPos + offsetVector;
                    avatarInput.leftLegPos  = playerInfo.leftLegPos + offsetVector;
                    avatarInput.pelvisPos   = playerInfo.pelvisPos + offsetVector;
                    avatarInput.rightLegRot = playerInfo.rightLegRot;
                    avatarInput.leftLegRot  = playerInfo.leftLegRot;
                    avatarInput.pelvisRot   = playerInfo.pelvisRot;
                }

                transform.position = avatarInput.headPos;

                playerNameText.text = playerName;

                if (playerInfo.playerFlags.rainbowName && !rainbowName)
                {
                    playerNameText.color = playerInfo.playerNameColor;
                    nameColor            = HSBColor.FromColor(playerInfo.playerNameColor);
                }
                else if (!playerInfo.playerFlags.rainbowName && playerNameText.color != playerInfo.playerNameColor)
                {
                    playerNameText.color = playerInfo.playerNameColor;
                }

                rainbowName = playerInfo.playerFlags.rainbowName;
            }
            catch (Exception e)
            {
                Plugin.log.Critical(e);
            }
        }
Esempio n. 6
0
        public void SetPlayerInfo(PlayerInfo _playerInfo, float offset, bool isLocal)
        {
            if (_playerInfo == null)
            {
                if (playerNameText != null)
                {
                    playerNameText.gameObject.SetActive(false);
                }
                if (playerSpeakerIcon != null)
                {
                    playerSpeakerIcon.gameObject.SetActive(false);
                }
                if (avatar != null)
                {
                    Destroy(avatar.GameObject);
                }
                return;
            }

            try
            {
                playerInfo = _playerInfo;

                if (playerNameText != null && playerSpeakerIcon != null)
                {
                    if (isLocal)
                    {
                        playerNameText.gameObject.SetActive(false);
                        playerSpeakerIcon.gameObject.SetActive(false);
#if !DEBUG
                        if (avatar != null)
                        {
                            Destroy(avatar.GameObject);
                        }
#endif
                    }
                    else
                    {
                        playerNameText.gameObject.SetActive(true);
                        playerNameText.alignment = TextAlignmentOptions.Center;
                        playerSpeakerIcon.gameObject.SetActive(InGameOnlineController.Instance.VoiceChatIsTalking(playerInfo.playerId));
                    }
                }

                if (playerNameText == null || playerSpeakerIcon == null)
                {
                    return;
                }

                if ((avatar == null || currentAvatarHash != playerInfo.avatarHash) && !isLocal)
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerInfo.avatarHash))
                    {
                        CustomAvatar.CustomAvatar cachedAvatar = ModelSaberAPI.cachedAvatars[playerInfo.avatarHash];

                        if (cachedAvatar != null)
                        {
                            if (pendingAvatars.Contains(cachedAvatar))
                            {
                                AvatarLoaded -= AvatarController_AvatarLoaded;
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                            else if (!pendingAvatars.Contains(cachedAvatar) && !cachedAvatar.IsLoaded)
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                pendingAvatars.Add(cachedAvatar);
                                cachedAvatar.Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                                {
                                    if (result == AvatarLoadResult.Completed)
                                    {
                                        pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                                        AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == loadedAvatar).Key);
                                    }
                                });
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                            else
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(cachedAvatar, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                currentAvatarHash = playerInfo.avatarHash;
                            }
                        }
                    }
                    else
                    {
                        if (Config.Instance.DownloadAvatars)
                        {
                            if (ModelSaberAPI.queuedAvatars.Contains(playerInfo.avatarHash))
                            {
                                ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                            }
                            else
                            {
                                SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerInfo.avatarHash, (string hash) => { AvatarDownloaded(hash); }));

                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }
                            }
                        }
                    }
                }

                Vector3 offsetVector = new Vector3(offset, 0f, 0f);

                HeadPos      = playerInfo.headPos + offsetVector;
                RightHandPos = playerInfo.rightHandPos + offsetVector;
                LeftHandPos  = playerInfo.leftHandPos + offsetVector;

                HeadRot      = playerInfo.headRot;
                RightHandRot = playerInfo.rightHandRot;
                LeftHandRot  = playerInfo.leftHandRot;

                transform.position = HeadPos;

                playerNameText.text  = playerInfo.playerName;
                playerNameText.color = playerInfo.playerNameColor;
            }
            catch (Exception e)
            {
                Misc.Logger.Exception($"Avatar controller exception: {playerInfo.playerName}: {e}");
            }
        }
        public void SetPlayerInfo(PlayerInfo _playerInfo, float offset, bool isLocal)
        {
            if (_playerInfo == null)
            {
                playerNameText.gameObject.SetActive(false);
                if (rendererEnabled)
                {
                    SetRendererInChilds(avatar.GameObject.transform, false);
                    rendererEnabled = false;
                }
                return;
            }

            try
            {
                playerInfo = _playerInfo;

                if (playerNameText == null)
                {
                    return;
                }

                if (avatar == null || currentAvatarHash != playerInfo.avatarHash)
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerInfo.avatarHash))
                    {
                        CustomAvatar.CustomAvatar cachedAvatar = ModelSaberAPI.cachedAvatars[playerInfo.avatarHash];
                        if (cachedAvatar != null)
                        {
                            if (cachedAvatar.IsLoaded)
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(cachedAvatar, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                currentAvatarHash = playerInfo.avatarHash;
                            }
                            else if (!pendingAvatars.Contains(cachedAvatar))
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                pendingAvatars.Add(cachedAvatar);
                                cachedAvatar.Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                                {
                                    if (result == AvatarLoadResult.Completed)
                                    {
                                        pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                                        AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == loadedAvatar).Key);
                                    }
                                });
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                            else
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                AvatarLoaded -= AvatarController_AvatarLoaded;
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                        }
                    }
                    else
                    {
                        if (Config.Instance.DownloadAvatars)
                        {
                            if (avatar != null)
                            {
                                Destroy(avatar.GameObject);
                            }

                            avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                            exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                            if (exclusionScript != null)
                            {
                                exclusionScript.SetVisible();
                            }

                            if (ModelSaberAPI.queuedAvatars.Contains(playerInfo.avatarHash))
                            {
                                ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                            }
                            else
                            {
                                SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerInfo.avatarHash, (string hash) => { AvatarDownloaded(hash); }));
                            }
                        }
                    }
                }

                if (isLocal)
                {
                    playerNameText.gameObject.SetActive(false);
#if !DEBUG
                    if (rendererEnabled)
                    {
                        SetRendererInChilds(avatar.GameObject.transform, false);
                        rendererEnabled = false;
                    }
#endif
                }
                else
                {
                    playerNameText.gameObject.SetActive(true);
                    if (!rendererEnabled)
                    {
                        SetRendererInChilds(avatar.GameObject.transform, true);
                        rendererEnabled = true;
                    }
                }

                interpolationProgress = 0f;

                Vector3 offsetVector = new Vector3(offset, 0f, 0f);

                lastHeadPos   = targetHeadPos;
                targetHeadPos = _playerInfo.headPos + offsetVector;

                lastRightHandPos   = targetRightHandPos;
                targetRightHandPos = _playerInfo.rightHandPos + offsetVector;

                lastLeftHandPos   = targetLeftHandPos;
                targetLeftHandPos = _playerInfo.leftHandPos + offsetVector;

                lastHeadRot   = targetHeadRot;
                targetHeadRot = _playerInfo.headRot;

                lastRightHandRot   = targetRightHandRot;
                targetRightHandRot = _playerInfo.rightHandRot;

                lastLeftHandRot   = targetLeftHandRot;
                targetLeftHandRot = _playerInfo.leftHandRot;

                playerNameText.text = playerInfo.playerName;

                if (forcePlayerInfo)
                {
                    interpHeadPos      = targetHeadPos;
                    interpLeftHandPos  = targetLeftHandPos;
                    interpRightHandPos = targetRightHandPos;

                    interpHeadRot      = targetHeadRot;
                    interpLeftHandRot  = targetLeftHandRot;
                    interpRightHandRot = targetRightHandRot;

                    transform.position = interpHeadPos;
                }
            }
            catch (Exception e)
            {
                Misc.Logger.Exception($"Avatar controller exception: {_playerInfo.playerName}: {e}");
            }
        }