From b2d110980e45b6db40562299ee57bc043f7c593d Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:32:48 +0300 Subject: [PATCH] Improve lobby handling so it doesn't spam errors anymore --- .../Services/ObjectManager.cs | 36 +++++++++++-------- CustomizePlus/Profiles/ProfileManager.cs | 5 +-- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CustomizePlus.GameData/Services/ObjectManager.cs b/CustomizePlus.GameData/Services/ObjectManager.cs index 9c9d440..6bbef08 100644 --- a/CustomizePlus.GameData/Services/ObjectManager.cs +++ b/CustomizePlus.GameData/Services/ObjectManager.cs @@ -3,11 +3,13 @@ using Dalamud.Game.ClientState.Objects; using Dalamud.Plugin; using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.Game.Control; +using FFXIVClientStructs.FFXIV.Client.Game.Object; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using OtterGui.Log; using Penumbra.GameData.Actors; using Penumbra.GameData.Enums; using Penumbra.GameData.Interop; +using Penumbra.GameData.Structs; using Penumbra.String; namespace CustomizePlus.GameData.Services; @@ -84,7 +86,7 @@ public class ObjectManager( IsInGPose = gPose.Utf8Name.Length > 0; //C+ custom - IsInLobby = AddLobbyCharacter(); + IsInLobby = AddLobbyCharacters(); return true; } @@ -136,10 +138,6 @@ public class ObjectManager( } } - //c+ custom - public Actor LobbyActor - => IsInLobby ? this[200] : nint.Zero; - public Actor GPosePlayer => this[(int)ScreenActor.GPosePlayer]; @@ -218,22 +216,32 @@ public class ObjectManager( } //c+ custom - private unsafe bool AddLobbyCharacter() + private unsafe bool AddLobbyCharacters() { var agent = AgentLobby.Instance(); - if (agent == null || agent->LobbyData.CharaSelectEntries.LongCount() == 0) + if (agent == null) return false; - var chara = agent->LobbyData.CharaSelectEntries[(long)agent->SelectedCharacterContentId].Value; - if (chara == null) - return false; + var span = agent->LobbyData.CharaSelectEntries.AsSpan(); - var actor = CutsceneCharacters.FirstOrDefault(); + // The lobby uses the first 8 cutscene actors. + int cnt = 0; + foreach (var actor in CutsceneCharacters.Take(8)) + { + if (!actor.Valid) //shouldn't happen so should be safe to break? + break; - if (!actor.Valid) - return false; + if (cnt >= span.Length) + break; - HandleIdentifier(actors.CreatePlayer(new ByteString(chara->Name), chara->HomeWorldId), actor); + if (span[cnt].Value == null) //should mean the end of valid actors so should be safe to break? + break; + + var chara = span[cnt].Value; + HandleIdentifier(actors.CreatePlayer(new ByteString(chara->Name), chara->HomeWorldId), actor); + + cnt++; + } return true; } diff --git a/CustomizePlus/Profiles/ProfileManager.cs b/CustomizePlus/Profiles/ProfileManager.cs index 8acd8b7..4b6575f 100644 --- a/CustomizePlus/Profiles/ProfileManager.cs +++ b/CustomizePlus/Profiles/ProfileManager.cs @@ -487,10 +487,7 @@ public class ProfileManager : IDisposable //performance: using textual override for ProfileAppliesTo here to not call //GetGameObjectName every time we are trying to check object against profiles - if (_objectManager.LobbyActor.Valid && - _objectManager.TryGetValue(actorIdentifier, out var actorData) && - actorData.Objects.Count == 1 && - _objectManager.LobbyActor == actorData.Objects[0] && !_configuration.ProfileApplicationSettings.ApplyInLobby) + if (_objectManager.IsInLobby && !_configuration.ProfileApplicationSettings.ApplyInLobby) yield break; (actorIdentifier, _) = _gameObjectService.GetTrueActorForSpecialTypeActor(actorIdentifier);