From 021f4c8724bda5bbd88c11fb7ef5cf936a8c4b61 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:44:47 +0300 Subject: [PATCH] Update CutsceneService and ObjectManager from upstream --- .../Services/CutsceneService.cs | 37 ++++++++++--------- .../Services/ObjectManager.cs | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CustomizePlus.GameData/Services/CutsceneService.cs b/CustomizePlus.GameData/Services/CutsceneService.cs index eb97e46..4ab0ecd 100644 --- a/CustomizePlus.GameData/Services/CutsceneService.cs +++ b/CustomizePlus.GameData/Services/CutsceneService.cs @@ -1,4 +1,5 @@ using CustomizePlus.GameData.Hooks.Objects; +using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.FFXIV.Client.Game.Object; @@ -9,23 +10,23 @@ using System.Diagnostics; namespace CustomizePlus.GameData.Services; -public class CutsceneService : IService, IDisposable +public sealed class CutsceneService : IRequiredService, IDisposable { public const int CutsceneStartIdx = (int)ScreenActor.CutsceneStart; public const int CutsceneEndIdx = (int)ScreenActor.CutsceneEnd; public const int CutsceneSlots = CutsceneEndIdx - CutsceneStartIdx; - private readonly IObjectTable _objects; + private readonly ObjectManager _objects; private readonly CopyCharacter _copyCharacter; private readonly CharacterDestructor _characterDestructor; private readonly short[] _copiedCharacters = Enumerable.Repeat((short)-1, CutsceneSlots).ToArray(); - public IEnumerable> Actors + public IEnumerable> Actors => Enumerable.Range(CutsceneStartIdx, CutsceneSlots) - .Where(i => _objects[i] != null) - .Select(i => KeyValuePair.Create(i, this[i] ?? _objects[i]!)); + .Where(i => _objects[i].Valid) + .Select(i => KeyValuePair.Create(i, this[i] ?? _objects.GetDalamudObject(i)!)); - public unsafe CutsceneService(IObjectTable objects, CopyCharacter copyCharacter, CharacterDestructor characterDestructor, + public unsafe CutsceneService(ObjectManager objects, CopyCharacter copyCharacter, CharacterDestructor characterDestructor, IClientState clientState) { _objects = objects; @@ -43,13 +44,13 @@ public class CutsceneService : IService, IDisposable /// Does not check for valid input index. /// Returns null if no connected actor is set or the actor does not exist anymore. /// - public Dalamud.Game.ClientState.Objects.Types.IGameObject? this[int idx] + private IGameObject? this[int idx] { get { Debug.Assert(idx is >= CutsceneStartIdx and < CutsceneEndIdx); idx = _copiedCharacters[idx - CutsceneStartIdx]; - return idx < 0 ? null : _objects[idx]; + return idx < 0 ? null : _objects.GetDalamudObject(idx); } } @@ -65,10 +66,10 @@ public class CutsceneService : IService, IDisposable if (parentIdx is < -1 or >= CutsceneEndIdx) return false; - if (_objects.GetObjectAddress(copyIdx) == nint.Zero) + if (!_objects[copyIdx].Valid) return false; - if (parentIdx != -1 && _objects.GetObjectAddress(parentIdx) == nint.Zero) + if (parentIdx != -1 && !_objects[parentIdx].Valid) return false; _copiedCharacters[copyIdx - CutsceneStartIdx] = (short)parentIdx; @@ -100,9 +101,9 @@ public class CutsceneService : IService, IDisposable { // A hack to deal with GPose actors leaving and thus losing the link, we just set the home world instead. // I do not think this breaks anything? - var address = (GameObject*)_objects.GetObjectAddress(i + CutsceneStartIdx); - if (address != null && address->GetObjectKind() is ObjectKind.Pc) - ((Character*)address)->HomeWorld = character->HomeWorld; + var address = _objects[i + CutsceneStartIdx]; + if (address.IsPlayer) + address.AsCharacter->HomeWorld = character->HomeWorld; _copiedCharacters[i] = -1; } @@ -126,7 +127,7 @@ public class CutsceneService : IService, IDisposable /// Try to recover GPose actors on reloads into a running game. /// This is not 100% accurate due to world IDs, minions etc., but will be mostly sane. - private unsafe void RecoverGPoseActors() + private void RecoverGPoseActors() { Dictionary? actors = null; @@ -144,11 +145,11 @@ public class CutsceneService : IService, IDisposable bool TryGetName(int idx, out ByteString name) { name = ByteString.Empty; - var address = (GameObject*)_objects.GetObjectAddress(idx); - if (address == null) + var address = _objects[idx]; + if (!address.Valid) return false; - name = new ByteString(address->Name); + name = address.Utf8Name; return !name.IsEmpty; } @@ -164,4 +165,4 @@ public class CutsceneService : IService, IDisposable return ret; } } -} +} \ No newline at end of file diff --git a/CustomizePlus.GameData/Services/ObjectManager.cs b/CustomizePlus.GameData/Services/ObjectManager.cs index 38bce0f..9c9d440 100644 --- a/CustomizePlus.GameData/Services/ObjectManager.cs +++ b/CustomizePlus.GameData/Services/ObjectManager.cs @@ -44,7 +44,7 @@ public class ObjectManager( return false; _identifierUpdate = LastUpdate; - World = (ushort)(this[0].Valid ? this[0].HomeWorld : 0); + World = (ushort)(Player.Valid ? Player.HomeWorld : 0); _identifiers.Clear(); _allWorldIdentifiers.Clear(); _nonOwnedIdentifiers.Clear();