From 5edb83f00b79ff4fb0dd5da28cdf703254f4b15c Mon Sep 17 00:00:00 2001 From: Caraxi Date: Wed, 17 Jul 2024 18:20:14 +0930 Subject: [PATCH] Update for Dawntrail --- ApiProvider.cs | 29 ++++++++++++------------- Changelog.cs | 1 + CharacterConfig.cs | 2 +- ConfigWindow.cs | 28 ++++++++++++------------- EmoteIdentifier.cs | 2 +- ExtraDebug.cs | 20 ++++++++---------- ImGuiExt.cs | 2 +- IpcCharacterConfig.cs | 8 +++---- Plugin.cs | 49 ++++++++++++++++++++++--------------------- PluginService.cs | 2 +- SimpleHeels.csproj | 4 ++-- Util.cs | 4 ++-- packages.lock.json | 6 +++--- 13 files changed, 79 insertions(+), 78 deletions(-) diff --git a/ApiProvider.cs b/ApiProvider.cs index 5d976b8..e6b9cf1 100644 --- a/ApiProvider.cs +++ b/ApiProvider.cs @@ -3,13 +3,12 @@ using System.Numerics; using System.Threading; using Dalamud.Game.ClientState.Objects.SubKinds; -using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Plugin.Ipc; namespace SimpleHeels; public static class ApiProvider { - private const int ApiVersionMajor = 1; + private const int ApiVersionMajor = 2; private const int ApiVersionMinor = 1; public const string ApiVersionIdentifier = "SimpleHeels.ApiVersion"; @@ -23,8 +22,8 @@ public static class ApiProvider { private static ICallGateProvider<(int, int)>? _apiVersion; private static ICallGateProvider? _getLocalPlayer; private static ICallGateProvider? _localChanged; - private static ICallGateProvider? _registerPlayer; - private static ICallGateProvider? _unregisterPlayer; + private static ICallGateProvider? _registerPlayer; + private static ICallGateProvider? _unregisterPlayer; private static IpcCharacterConfig? _lastReported; private static Vector3? _lastReportedOffset; @@ -44,28 +43,30 @@ public static void Init(Plugin plugin) { _apiVersion.RegisterFunc(() => (ApiVersionMajor, ApiVersionMinor)); _getLocalPlayer = pluginInterface.GetIpcProvider(GetLocalPlayerIdentifier); _localChanged = pluginInterface.GetIpcProvider(LocalChangedIdentifier); - _registerPlayer = pluginInterface.GetIpcProvider(RegisterPlayerIdentifier); - _unregisterPlayer = pluginInterface.GetIpcProvider(UnregisterPlayerIdentifier); + _registerPlayer = pluginInterface.GetIpcProvider(RegisterPlayerIdentifier); + _unregisterPlayer = pluginInterface.GetIpcProvider(UnregisterPlayerIdentifier); _apiVersion.RegisterFunc(() => (ApiVersionMajor, ApiVersionMinor)); - _registerPlayer.RegisterAction((gameObject, data) => { - if (gameObject is not PlayerCharacter playerCharacter) return; + _registerPlayer.RegisterAction((gameObjectIndex, data) => { + var gameObject = gameObjectIndex >= 0 && gameObjectIndex < PluginService.Objects.Length ? PluginService.Objects[gameObjectIndex] : null; + if (gameObject is not IPlayerCharacter playerCharacter) return; if (string.IsNullOrWhiteSpace(data)) { - Plugin.IpcAssignedData.Remove(playerCharacter.ObjectId); + Plugin.IpcAssignedData.Remove(playerCharacter.EntityId); return; } var assigned = IpcCharacterConfig.FromString(data); if (assigned == null) return; - Plugin.IpcAssignedData.Remove(playerCharacter.ObjectId); - Plugin.IpcAssignedData.Add(playerCharacter.ObjectId, assigned); + Plugin.IpcAssignedData.Remove(playerCharacter.EntityId); + Plugin.IpcAssignedData.Add(playerCharacter.EntityId, assigned); Plugin.RequestUpdateAll(); }); - _unregisterPlayer.RegisterAction(gameObject => { - if (gameObject is not PlayerCharacter playerCharacter) return; - Plugin.IpcAssignedData.Remove(playerCharacter.ObjectId); + _unregisterPlayer.RegisterAction(gameObjectIndex => { + var gameObject = gameObjectIndex >= 0 && gameObjectIndex < PluginService.Objects.Length ? PluginService.Objects[gameObjectIndex] : null; + if (gameObject is not IPlayerCharacter playerCharacter) return; + Plugin.IpcAssignedData.Remove(playerCharacter.EntityId); Plugin.RequestUpdateAll(); }); diff --git a/Changelog.cs b/Changelog.cs index 089a13d..2cecc84 100644 --- a/Changelog.cs +++ b/Changelog.cs @@ -16,6 +16,7 @@ public static class Changelog { private static bool _isOldExpanded; private static void Changelogs() { + ChangelogFor(10.0f, "0.10.0.0", "Updated for Dawntrail"); ChangelogFor(9.35f, "0.9.3.5", "Fix support for new worlds."); ChangelogFor(9.34f, "0.9.3.4", "Fixed issue causing other players to appear to teleport for a brief moment when using emotes with precise positioning."); ChangelogFor(9.31f, "0.9.3.1", () => { diff --git a/CharacterConfig.cs b/CharacterConfig.cs index 0c74c9f..2ec2509 100644 --- a/CharacterConfig.cs +++ b/CharacterConfig.cs @@ -82,7 +82,7 @@ public unsafe bool TryGetFirstMatch(GameObject* character, [NotNullWhen(true)] o return offsetProvider != null; } - public unsafe IOffsetProvider? GetFirstMatch(PlayerCharacter playerCharacter, bool checkEmote = true) { + public unsafe IOffsetProvider? GetFirstMatch(IPlayerCharacter playerCharacter, bool checkEmote = true) { var character = (Character*)playerCharacter.Address; if (character == null) return null; return GetFirstMatch(character, checkEmote); diff --git a/ConfigWindow.cs b/ConfigWindow.cs index e320533..3ab9673 100644 --- a/ConfigWindow.cs +++ b/ConfigWindow.cs @@ -7,6 +7,7 @@ using System.Numerics; using System.Threading; using Dalamud.Game.ClientState.Objects.SubKinds; +using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface; @@ -16,7 +17,6 @@ using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; -using Dalamud.Memory; using Dalamud.Utility; using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.FFXIV.Client.Game.Object; @@ -183,7 +183,7 @@ public unsafe void DrawCharacterList() { var ipcAssignedCharacter = (Character*)ipcAssignedObject; if (ipcAssignedCharacter->HomeWorld == ushort.MaxValue) continue; - var name = MemoryHelper.ReadSeString((nint)ipcAssignedObject->Name, 64).TextValue; + var name = SeString.Parse(ipcAssignedObject->Name).TextValue; var worldId = ipcAssignedCharacter->HomeWorld; var world = PluginService.Data.GetExcelSheet()?.GetRow(worldId); @@ -264,9 +264,9 @@ public unsafe void DrawCharacterList() { private void ShowDebugInfo() { if (Plugin.IsDebug && ImGui.TreeNode("DEBUG INFO")) { try { - var activePlayer = PluginService.Objects.FirstOrDefault(t => t is PlayerCharacter playerCharacter && playerCharacter.Name.TextValue == selectedName && playerCharacter.HomeWorld.Id == selectedWorld); + var activePlayer = PluginService.Objects.FirstOrDefault(t => t is IPlayerCharacter playerCharacter && playerCharacter.Name.TextValue == selectedName && playerCharacter.HomeWorld.Id == selectedWorld); - if (activePlayer is not PlayerCharacter pc) { + if (activePlayer is not IPlayerCharacter pc) { ImGui.TextDisabled("Character is not currently in world."); return; } @@ -377,7 +377,7 @@ public override void Draw() { ImGui.SameLine(); if (ImGuiComponents.IconButton(FontAwesomeIcon.DotCircle)) { - if (PluginService.Targets.Target is PlayerCharacter pc) { + if (PluginService.Targets.Target is IPlayerCharacter pc) { config.TryAddCharacter(pc.Name.TextValue, pc.HomeWorld.Id); } } @@ -587,7 +587,7 @@ void World(string name, uint worldId, WorldDCGroupType? dc = null) { if (ImGuiComponents.IconButton(FontAwesomeIcon.DotCircle)) { var target = PluginService.Targets.SoftTarget ?? PluginService.Targets.Target; if (target != null) { - var c = new GroupCharacter { Name = target.Name.TextValue, World = target is PlayerCharacter pc ? pc.HomeWorld.Id : ushort.MaxValue }; + var c = new GroupCharacter { Name = target.Name.TextValue, World = target is IPlayerCharacter pc ? pc.HomeWorld.Id : ushort.MaxValue }; if (!selectedGroup.Characters.Any(ec => ec.Name == c.Name && ec.World == c.World)) { selectedGroup.Characters.Add(c); } @@ -853,12 +853,12 @@ private unsafe void DrawCharacterView(CharacterConfig? characterConfig) { IOffsetProvider? activeHeelConfig = null; if (characterConfig is GroupConfig gc) { - var target = new[] { PluginService.Targets.SoftTarget, PluginService.Targets.Target, PluginService.ClientState.LocalPlayer }.FirstOrDefault(t => t is Dalamud.Game.ClientState.Objects.Types.Character character && gc.Matches(((GameObject*)character.Address)->DrawObject, character.Name.TextValue, (character is PlayerCharacter pc) ? pc.HomeWorld.Id : ushort.MaxValue)); - if (target is Dalamud.Game.ClientState.Objects.Types.Character) { + var target = new[] { PluginService.Targets.SoftTarget, PluginService.Targets.Target, PluginService.ClientState.LocalPlayer }.FirstOrDefault(t => t is ICharacter character && gc.Matches(((GameObject*)character.Address)->DrawObject, character.Name.TextValue, (character is IPlayerCharacter pc) ? pc.HomeWorld.Id : ushort.MaxValue)); + if (target is ICharacter) { activeCharacter = (GameObject*)target.Address; activeCharacterAsCharacter = (Character*)activeCharacter; activeHeelConfig = characterConfig.GetFirstMatch(activeCharacterAsCharacter); - if (target is PlayerCharacter pc) { + if (target is IPlayerCharacter pc) { ImGui.TextDisabled($"Preview displays based on {target.Name.TextValue} ({pc.HomeWorld?.GameData?.Name.RawString})"); } else { ImGui.TextDisabled($"Preview displays based on {target.Name.TextValue} (NPC)"); @@ -867,8 +867,8 @@ private unsafe void DrawCharacterView(CharacterConfig? characterConfig) { Plugin.RequestUpdateAll(); } } else { - var player = PluginService.Objects.FirstOrDefault(t => t is PlayerCharacter playerCharacter && playerCharacter.Name.TextValue == selectedName && playerCharacter.HomeWorld.Id == selectedWorld); - if (player is PlayerCharacter) { + var player = PluginService.Objects.FirstOrDefault(t => t is IPlayerCharacter playerCharacter && playerCharacter.Name.TextValue == selectedName && playerCharacter.HomeWorld.Id == selectedWorld); + if (player is IPlayerCharacter) { activeCharacter = (GameObject*)player.Address; activeCharacterAsCharacter = (Character*)activeCharacter; activeHeelConfig = characterConfig.GetFirstMatch(activeCharacterAsCharacter); @@ -876,7 +876,7 @@ private unsafe void DrawCharacterView(CharacterConfig? characterConfig) { } } - if (activeCharacter != null && Plugin.IpcAssignedData.TryGetValue(activeCharacter->ObjectID, out var ipcCharacterConfig)) { + if (activeCharacter != null && Plugin.IpcAssignedData.TryGetValue(activeCharacter->EntityId, out var ipcCharacterConfig)) { characterConfig = ipcCharacterConfig; } @@ -885,7 +885,7 @@ private unsafe void DrawCharacterView(CharacterConfig? characterConfig) { if (Plugin.IsDebug && activeCharacter != null) { ImGui.SameLine(); if (ImGui.SmallButton("Clear IPC")) { - Plugin.IpcAssignedData.Remove(activeCharacter->ObjectID); + Plugin.IpcAssignedData.Remove(activeCharacter->EntityId); selectedCharacter = null; selectedWorld = 0; selectedName = string.Empty; @@ -1688,7 +1688,7 @@ void ShowAddPathButton(string? path, ModelSlot slot) { if (Plugin.IsDebug) { if (characterConfig is IpcCharacterConfig ipcCharacter && ImGui.TreeNode("IPC Data")) { - if (ipcCharacter.EmotePosition != null && activeCharacterAsCharacter->Mode is Character.CharacterModes.EmoteLoop or Character.CharacterModes.InPositionLoop) { + if (ipcCharacter.EmotePosition != null && activeCharacterAsCharacter->Mode is CharacterModes.EmoteLoop or CharacterModes.InPositionLoop) { ImGui.Text("Position Error:"); var pos = (Vector3) activeCharacter->Position; var emotePos = ipcCharacter.EmotePosition.GetOffset(); diff --git a/EmoteIdentifier.cs b/EmoteIdentifier.cs index e8c2922..be688dd 100644 --- a/EmoteIdentifier.cs +++ b/EmoteIdentifier.cs @@ -74,7 +74,7 @@ public uint Icon { public static EmoteIdentifier? Get(Character* character) { if (character == null) return null; - if (character->Mode is not (Character.CharacterModes.InPositionLoop or Character.CharacterModes.EmoteLoop)) return null; + if (character->Mode is not (CharacterModes.InPositionLoop or CharacterModes.EmoteLoop)) return null; return new EmoteIdentifier(character->ModeParam, character->EmoteController.CPoseState); } diff --git a/ExtraDebug.cs b/ExtraDebug.cs index cc4d1bb..287ccab 100644 --- a/ExtraDebug.cs +++ b/ExtraDebug.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Reflection; -using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; @@ -63,17 +61,17 @@ private void TabBaseOffsets() { private Vector4[] minionPositions = new Vector4[Constants.ObjectLimit]; private void TabStaticMinions() { - foreach (var c in PluginService.Objects.Where(o => o is PlayerCharacter).Cast()) { + foreach (var c in PluginService.Objects.Where(o => o is IPlayerCharacter).Cast()) { if (c == null) continue; var chr = (Character*)c.Address; - if (chr->Companion.CompanionObject == null) continue; - var companionId = chr->Companion.CompanionObject->Character.GameObject.DataID; + if (chr->CompanionData.CompanionObject == null) continue; + var companionId = chr->CompanionData.CompanionObject->Character.GameObject.BaseId; var companion = PluginService.Data.GetExcelSheet()?.GetRow(companionId); if (companion == null) continue; if (companion.Behavior.Row != 3) continue; - using (ImRaii.PushId($"chr_{c.ObjectId:X}")) { + using (ImRaii.PushId($"chr_{c.EntityId:X}")) { ImGui.Separator(); - var go = &chr->Companion.CompanionObject->Character.GameObject; + var go = &chr->CompanionData.CompanionObject->Character.GameObject; if (minionPositions[go->ObjectIndex] == default) minionPositions[go->ObjectIndex] = new Vector4(go->Position, go->Rotation); if (ImGui.DragFloat4($"{c.Name.TextValue}'s {companion.Singular.ToDalamudString().TextValue}", ref minionPositions[go->ObjectIndex], 0.01f)) { go->DrawObject->Object.Position.X = minionPositions[go->ObjectIndex].X; @@ -83,14 +81,14 @@ private void TabStaticMinions() { } ImGui.SameLine(); - ImGui.Text($"{go->ObjectID:X}"); + ImGui.Text($"{go->EntityId:X}"); } } } private void TabObjects() { foreach (var actor in PluginService.Objects) { - if (actor is not PlayerCharacter pc) continue; + if (actor is not IPlayerCharacter pc) continue; if (ImGui.TreeNode($"[{actor.ObjectIndex} ({actor.GetType().Name})] {actor.ObjectKind}.{actor.SubKind} - {actor.Name}")) { var obj = (Character*)pc.Address; @@ -104,7 +102,7 @@ private void TabObjects() { ImGui.Text($"Mode: {obj->Mode}"); ImGui.Text($"ModeParam: {obj->ModeParam}"); - ImGui.Text($"Feet Model: {obj->DrawData.Feet.Id}"); + ImGui.Text($"Feet Model: {obj->DrawData.Equipment(DrawDataContainer.EquipmentSlot.Feet).Id}"); ImGui.Text($"Draw Offset: {obj->GameObject.DrawOffset}"); ImGui.Text($"Height: {obj->GameObject.Height}"); diff --git a/ImGuiExt.cs b/ImGuiExt.cs index 94ea894..a1956a1 100644 --- a/ImGuiExt.cs +++ b/ImGuiExt.cs @@ -23,7 +23,7 @@ public static bool IconTextFrame(uint previewIcon, string previewText, bool hove using (ImRaii.PushColor(ImGuiCol.FrameBg, ImGui.GetColorU32(ImGuiCol.FrameBgHovered), hoverColor && ImGui.IsMouseHoveringRect(pos, pos + frameSize))) { if (ImGui.BeginChildFrame(ImGui.GetID($"iconTextFrame_{previewIcon}_{previewText}"), frameSize)) { var dl = ImGui.GetWindowDrawList(); - var icon = PluginService.TextureProvider.GetIcon(previewIcon); + var icon = PluginService.TextureProvider.GetFromGameIcon(previewIcon).GetWrapOrDefault(); if (icon != null) dl.AddImage(icon.ImGuiHandle, pos, pos + new Vector2(size.Y)); var textSize = ImGui.CalcTextSize(previewText); dl.AddText(pos + new Vector2(size.Y + ImGui.GetStyle().FramePadding.X, size.Y / 2f - textSize.Y / 2f), ImGui.GetColorU32(ImGuiCol.Text), previewText); diff --git a/IpcCharacterConfig.cs b/IpcCharacterConfig.cs index a7a7db6..ccff575 100644 --- a/IpcCharacterConfig.cs +++ b/IpcCharacterConfig.cs @@ -20,7 +20,7 @@ public class IpcCharacterConfig : CharacterConfig { public string PluginVersion = string.Empty; - public unsafe IpcCharacterConfig(Plugin plugin, PlayerCharacter player) { + public unsafe IpcCharacterConfig(Plugin plugin, IPlayerCharacter player) { if (player == null) throw new Exception("No Player"); if (plugin.TryGetCharacterConfig(player, out var characterConfig, false) && characterConfig != null) { @@ -34,8 +34,8 @@ public unsafe IpcCharacterConfig(Plugin plugin, PlayerCharacter player) { var chr = (Character*)player.Address; if (Plugin.Config.ApplyStaticMinionPositions) { - if (chr->Companion.CompanionObject != null && Utils.StaticMinions.Value.Contains(chr->Companion.CompanionObject->Character.GameObject.DataID)) { - var drawObj = chr->Companion.CompanionObject->Character.GameObject.DrawObject; + if (chr->CompanionData.CompanionObject != null && Utils.StaticMinions.Value.Contains(chr->CompanionData.CompanionObject->Character.GameObject.BaseId)) { + var drawObj = chr->CompanionData.CompanionObject->Character.GameObject.DrawObject; if (drawObj != null) { var p = drawObj->Object.Position; MinionPosition = new TempOffset(p.X, p.Y, p.Z, drawObj->Object.Rotation.EulerAngles.Y * MathF.PI / 180f); @@ -43,7 +43,7 @@ public unsafe IpcCharacterConfig(Plugin plugin, PlayerCharacter player) { } } - if (chr->Mode is Character.CharacterModes.EmoteLoop or Character.CharacterModes.InPositionLoop) { + if (chr->Mode is CharacterModes.EmoteLoop or CharacterModes.InPositionLoop) { // Precise Positioning var p = chr->GameObject.Position; EmotePosition = new TempOffset(p.X, p.Y, p.Z, chr->GameObject.Rotation); diff --git a/Plugin.cs b/Plugin.cs index 3004853..b7860c6 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -9,6 +9,7 @@ using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.Command; +using Dalamud.Game.Text.SeStringHandling; using Dalamud.Hooking; using Dalamud.Interface.Windowing; using Dalamud.Memory; @@ -51,7 +52,7 @@ public unsafe class Plugin : IDalamudPlugin { [Signature("E8 ?? ?? ?? ?? 48 8B 4B 08 44 8B CF", DetourName = nameof(SetModeDetour))] private Hook? setModeHook; - public Plugin(DalamudPluginInterface pluginInterface) { + public Plugin(IDalamudPluginInterface pluginInterface) { #if DEBUG IsDebug = true; #endif @@ -164,13 +165,13 @@ public void Dispose() { } private void* SetModeDetour(Character* character, ulong mode, byte modeParam) { - var previousMode = character == null ? Character.CharacterModes.None : character->Mode; + var previousMode = character == null ? CharacterModes.None : character->Mode; try { return setModeHook!.Original(character, mode, modeParam); } finally { try { - var m = (Character.CharacterModes)mode; - if (character->GameObject.ObjectIndex == 0 && (m is Character.CharacterModes.EmoteLoop or Character.CharacterModes.InPositionLoop || previousMode is Character.CharacterModes.EmoteLoop or Character.CharacterModes.InPositionLoop)) { + var m = (CharacterModes)mode; + if (character->GameObject.ObjectIndex == 0 && (m is CharacterModes.EmoteLoop or CharacterModes.InPositionLoop || previousMode is CharacterModes.EmoteLoop or CharacterModes.InPositionLoop)) { ApiProvider.ForceUpdateLocal(); } } catch (Exception ex) { @@ -179,7 +180,7 @@ public void Dispose() { } } - public bool TryGetCharacterConfig(PlayerCharacter playerCharacter, out CharacterConfig? characterConfig, bool allowIpc = true) { + public bool TryGetCharacterConfig(IPlayerCharacter playerCharacter, out CharacterConfig? characterConfig, bool allowIpc = true) { var character = (Character*)playerCharacter.Address; if (character == null) { characterConfig = null; @@ -192,7 +193,7 @@ public bool TryGetCharacterConfig(PlayerCharacter playerCharacter, out Character public bool TryGetCharacterConfig(Character* character, [NotNullWhen(true)] out CharacterConfig? characterConfig, bool allowIpc = true) { using var performance = PerformanceMonitors.Run("TryGetCharacterConfig"); - if (allowIpc && character->GameObject.ObjectID != Constants.InvalidObjectId && IpcAssignedData.TryGetValue(character->GameObject.ObjectID, out var ipcCharacterConfig)) { + if (allowIpc && character->GameObject.EntityId != Constants.InvalidObjectId && IpcAssignedData.TryGetValue(character->GameObject.EntityId, out var ipcCharacterConfig)) { characterConfig = ipcCharacterConfig; return true; } @@ -203,7 +204,7 @@ public bool TryGetCharacterConfig(Character* character, [NotNullWhen(true)] out name = mappedActor.name; homeWorld = mappedActor.homeWorld; } else { - name = MemoryHelper.ReadSeString((nint)character->GameObject.Name, 64).TextValue; + name = SeString.Parse(character->GameObject.Name).TextValue; homeWorld = character->HomeWorld; } @@ -224,7 +225,7 @@ public bool TryGetMinionCharacterConfig(GameObject* minion, [NotNullWhen(true)] if (ActorMapping.TryGetValue(minion->ObjectIndex, out var mappedActor)) { name = mappedActor.name; } else { - name = MemoryHelper.ReadSeString((nint)minion->Name, 64).TextValue; + name = SeString.Parse(minion->Name).TextValue; } @@ -269,7 +270,7 @@ private void SetDrawOffsetDetour(GameObject* gameObject, float x, float y, float ActorMapping.Add(destination->GameObject.ObjectIndex, (name.TextValue, source->HomeWorld)); if (destination->GameObject.ObjectIndex < Constants.ObjectLimit && source->GameObject.ObjectIndex < Constants.ObjectLimit) { ManagedIndex[destination->GameObject.ObjectIndex] = ManagedIndex[source->GameObject.ObjectIndex]; - if (IpcAssignedData.TryGetValue(source->GameObject.ObjectID, out var ipcCharacterConfig)) { + if (IpcAssignedData.TryGetValue(source->GameObject.EntityId, out var ipcCharacterConfig)) { TempOffsets[destination->GameObject.ObjectIndex] = ipcCharacterConfig.TempOffset; TempOffsetEmote[destination->GameObject.ObjectIndex] = ipcCharacterConfig.TempOffset == null ? null : EmoteIdentifier.Get(source); } else { @@ -290,7 +291,7 @@ private void SetDrawOffsetDetour(GameObject* gameObject, float x, float y, float return cloneActor!.Original(destinationArray, source, copyFlags); } - private void DoConfigBackup(DalamudPluginInterface pluginInterface) { + private void DoConfigBackup(IDalamudPluginInterface pluginInterface) { try { var configFile = pluginInterface.ConfigFile; if (!configFile.Exists) return; @@ -345,7 +346,7 @@ private bool UpdateCompanion(uint updateIndex, GameObject* obj) { IOffsetProvider? offsetProvider = null; - if (!IpcAssignedData.ContainsKey(obj->ObjectID) && TempOffsets[updateIndex] != null) { + if (!IpcAssignedData.ContainsKey(obj->EntityId) && TempOffsets[updateIndex] != null) { offsetProvider = TempOffsets[updateIndex]; } @@ -380,7 +381,7 @@ private bool UpdateCompanion(uint updateIndex, GameObject* obj) { private bool ObjectIsCompanionTurnedHuman(GameObject* gameObject) { if (gameObject == null) return false; - if (gameObject->ObjectKind != (byte)ObjectKind.Companion) return false; + if (gameObject->ObjectKind != ObjectKind.Companion) return false; if (gameObject->DrawObject == null) return false; if (gameObject->DrawObject->Object.GetObjectType() != ObjectType.CharacterBase) return false; var chrBase = (CharacterBase*)gameObject->DrawObject; @@ -393,7 +394,7 @@ private bool UpdateObjectIndex(uint updateIndex) { if (updateIndex >= Constants.ObjectLimit) return true; NeedsUpdate[updateIndex] = false; - var obj = GameObjectManager.GetGameObjectByIndex((int)updateIndex); + var obj = GameObjectManager.Instance()->Objects.IndexSorted[(int)updateIndex].Value; if (Config is { Enabled: true, ApplyToMinions: true } && ObjectIsCompanionTurnedHuman(obj)) return UpdateCompanion(updateIndex, obj); @@ -417,17 +418,17 @@ bool ReleaseControl(bool r) { using var performance = PerformanceMonitors.Run("UpdateObject"); using var performance2 = PerformanceMonitors.Run($"UpdateObject:{updateIndex}", Config.DetailedPerformanceLogging); - if (Config is { Enabled: true } && character->Companion.CompanionObject != null) { - var companion = (GameObject*) character->Companion.CompanionObject; + if (Config is { Enabled: true } && character->CompanionData.CompanionObject != null) { + var companion = (GameObject*) character->CompanionData.CompanionObject; if (companion->DrawObject != null) { - if (updateIndex != 0 && Utils.StaticMinions.Value.Contains(companion->DataID) && IpcAssignedData.TryGetValue(obj->ObjectID, out var ipc) && ipc.MinionPosition != null) { + if (updateIndex != 0 && Utils.StaticMinions.Value.Contains(companion->BaseId) && IpcAssignedData.TryGetValue(obj->EntityId, out var ipc) && ipc.MinionPosition != null) { companion->DrawObject->Object.Position.X = ipc.MinionPosition.X; companion->DrawObject->Object.Position.Y = ipc.MinionPosition.Y; companion->DrawObject->Object.Position.Z = ipc.MinionPosition.Z; companion->DrawObject->Object.Rotation = Quaternion.CreateFromYawPitchRoll(ipc.MinionPosition.R, 0, 0); } - if (Config.ApplyStaticMinionPositions && updateIndex == 0 && Utils.StaticMinions.Value.Contains(companion->DataID)) { + if (Config.ApplyStaticMinionPositions && updateIndex == 0 && Utils.StaticMinions.Value.Contains(companion->BaseId)) { ApiProvider.UpdateMinion(companion->DrawObject->Object.Position, companion->DrawObject->Object.Rotation.EulerAngles.Y * MathF.PI / 180f); } } @@ -435,7 +436,7 @@ bool ReleaseControl(bool r) { IOffsetProvider? offsetProvider = null; - if (!IpcAssignedData.ContainsKey(obj->ObjectID) && TempOffsets[updateIndex] != null) { + if (!IpcAssignedData.ContainsKey(obj->EntityId) && TempOffsets[updateIndex] != null) { var emote = EmoteIdentifier.Get(character); var tEmote = TempOffsetEmote[updateIndex]; if (TempOffsetEmote[updateIndex] == emote || (emote != null && tEmote != null && emote.EmoteModeId == tEmote.EmoteModeId)) { @@ -460,24 +461,24 @@ bool ReleaseControl(bool r) { var appliedOffset = offsetProvider.GetOffset(); offset += appliedOffset; - if (updateIndex != 0 && Config.UsePrecisePositioning && character->Mode is Character.CharacterModes.EmoteLoop or Character.CharacterModes.InPositionLoop && IpcAssignedData.TryGetValue(obj->ObjectID, out var ipcCharacter) && ipcCharacter.EmotePosition != null) { + if (updateIndex != 0 && Config.UsePrecisePositioning && character->Mode is CharacterModes.EmoteLoop or CharacterModes.InPositionLoop && IpcAssignedData.TryGetValue(obj->EntityId, out var ipcCharacter) && ipcCharacter.EmotePosition != null) { using (PerformanceMonitors.Run($"Calculate Precise Position Offset:{updateIndex}", Config.DetailedPerformanceLogging)) using (PerformanceMonitors.Run("Calculate Precise Position Offset")) { var pos = (Vector3) character->GameObject.Position; - //var rot = character->GameObject.Rotation; + var rot = character->GameObject.Rotation; var emotePos = ipcCharacter.EmotePosition.GetOffset(); - //var emoteRot = ipcCharacter.EmotePosition.GetRotation(); + var emoteRot = ipcCharacter.EmotePosition.GetRotation(); if (Vector3.Distance(pos, emotePos) is > Constants.FloatDelta and < 1f ) { PluginService.Log.Debug($"Apply Precise Position to Object#{updateIndex}"); character->GameObject.SetPosition(emotePos.X, emotePos.Y, emotePos.Z); } -/* + if (MathF.Abs(rot - emoteRot) > Constants.FloatDelta) { PluginService.Log.Debug($"Apply Precise Rotation to Object#{updateIndex}"); - character->GameObject.Rotate(emoteRot); + character->GameObject.SetRotation(emoteRot); } -*/ + } } diff --git a/PluginService.cs b/PluginService.cs index b580118..5f0d647 100644 --- a/PluginService.cs +++ b/PluginService.cs @@ -7,7 +7,7 @@ namespace SimpleHeels; // ReSharper disable AutoPropertyCanBeMadeGetOnly.Local public class PluginService { - [PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; + [PluginService] public static IDalamudPluginInterface PluginInterface { get; private set; } = null!; [PluginService] public static IClientState ClientState { get; private set; } = null!; [PluginService] public static ICommandManager Commands { get; private set; } = null!; [PluginService] public static IDataManager Data { get; private set; } = null!; diff --git a/SimpleHeels.csproj b/SimpleHeels.csproj index 649de22..394ba80 100644 --- a/SimpleHeels.csproj +++ b/SimpleHeels.csproj @@ -9,13 +9,13 @@ false false true - 0.9.3.7 + 0.10.0.0 $(appdata)\XIVLauncher\addon\Hooks\dev\ true - + $(DalamudLibPath)Dalamud.dll false diff --git a/Util.cs b/Util.cs index 79d0e61..1875dd2 100644 --- a/Util.cs +++ b/Util.cs @@ -9,8 +9,8 @@ namespace SimpleHeels; public static unsafe class Utils { public static GameObject* GetGameObjectById(uint objectId) { for (var i = 0; i < Constants.ObjectLimit; i++) { - var o = GameObjectManager.GetGameObjectByIndex(i); - if (o == null || o->ObjectID != objectId) continue; + var o = GameObjectManager.Instance()->Objects.IndexSorted[i].Value; + if (o == null || o->EntityId != objectId) continue; return o; } diff --git a/packages.lock.json b/packages.lock.json index 8ca7ea5..19fcea9 100644 --- a/packages.lock.json +++ b/packages.lock.json @@ -4,9 +4,9 @@ "net8.0-windows7.0": { "DalamudPackager": { "type": "Direct", - "requested": "[2.1.12, )", - "resolved": "2.1.12", - "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" + "requested": "[2.1.13, )", + "resolved": "2.1.13", + "contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ==" } } }