Add SetCutsceneParentIndex.

This commit is contained in:
Ottermandias 2024-01-27 18:51:16 +01:00
parent b543d9fc1d
commit 5a80e65d3b
5 changed files with 46 additions and 3 deletions

@ -1 +1 @@
Subproject commit cfc51714f74cae93608bc507775a9580cd1801de
Subproject commit b28288ee9668425f49f41cba88e8dc417ad62aff

View file

@ -484,7 +484,9 @@ public class IpcTester : IDisposable
private DateTimeOffset _lastResolvedGamePathTime = DateTimeOffset.MaxValue;
private string _currentDrawObjectString = string.Empty;
private IntPtr _currentDrawObject = IntPtr.Zero;
private int _currentCutsceneActor = 0;
private int _currentCutsceneActor;
private int _currentCutsceneParent;
private PenumbraApiEc _cutsceneError = PenumbraApiEc.Success;
public GameState(DalamudPluginInterface pi)
{
@ -507,7 +509,14 @@ public class IpcTester : IDisposable
? tmp
: IntPtr.Zero;
ImGui.InputInt("Cutscene Actor", ref _currentCutsceneActor, 0);
ImGui.InputInt("Cutscene Actor", ref _currentCutsceneActor, 0);
ImGui.InputInt("Cutscene Parent", ref _currentCutsceneParent, 0);
if (_cutsceneError is not PenumbraApiEc.Success)
{
ImGui.SameLine();
ImGui.TextUnformatted("Invalid Argument on last Call");
}
using var table = ImRaii.Table(string.Empty, 3, ImGuiTableFlags.SizingFixedFit);
if (!table)
return;
@ -526,6 +535,10 @@ public class IpcTester : IDisposable
DrawIntro(Ipc.GetCutsceneParentIndex.Label, "Cutscene Parent");
ImGui.TextUnformatted(Ipc.GetCutsceneParentIndex.Subscriber(_pi).Invoke(_currentCutsceneActor).ToString());
DrawIntro(Ipc.SetCutsceneParentIndex.Label, "Cutscene Parent");
if (ImGui.Button("Set Parent"))
_cutsceneError = Ipc.SetCutsceneParentIndex.Subscriber(_pi).Invoke(_currentCutsceneActor, _currentCutsceneParent);
DrawIntro(Ipc.CreatingCharacterBase.Label, "Last Drawobject created");
if (_lastCreatedGameObjectTime < DateTimeOffset.Now)
ImGui.TextUnformatted(_lastCreatedDrawObject != IntPtr.Zero

View file

@ -600,6 +600,15 @@ public class PenumbraApi : IDisposable, IPenumbraApi
return _cutsceneService.GetParentIndex(actorIdx);
}
public PenumbraApiEc SetCutsceneParentIndex(int copyIdx, int newParentIdx)
{
CheckInitialized();
if (_cutsceneService.SetParentIndex(copyIdx, newParentIdx))
return PenumbraApiEc.Success;
return PenumbraApiEc.InvalidArgument;
}
public IList<(string, string)> GetModList()
{
CheckInitialized();

View file

@ -47,6 +47,7 @@ public class PenumbraIpcProviders : IDisposable
// Game State
internal readonly FuncProvider<nint, (nint, string)> GetDrawObjectInfo;
internal readonly FuncProvider<int, int> GetCutsceneParentIndex;
internal readonly FuncProvider<int, int, PenumbraApiEc> SetCutsceneParentIndex;
internal readonly EventProvider<nint, string, nint, nint, nint> CreatingCharacterBase;
internal readonly EventProvider<nint, string, nint> CreatedCharacterBase;
internal readonly EventProvider<nint, string, string> GameObjectResourcePathResolved;
@ -171,6 +172,7 @@ public class PenumbraIpcProviders : IDisposable
// Game State
GetDrawObjectInfo = Ipc.GetDrawObjectInfo.Provider(pi, Api.GetDrawObjectInfo);
GetCutsceneParentIndex = Ipc.GetCutsceneParentIndex.Provider(pi, Api.GetCutsceneParentIndex);
SetCutsceneParentIndex = Ipc.SetCutsceneParentIndex.Provider(pi, Api.SetCutsceneParentIndex);
CreatingCharacterBase = Ipc.CreatingCharacterBase.Provider(pi,
() => Api.CreatingCharacterBase += CreatingCharacterBaseEvent,
() => Api.CreatingCharacterBase -= CreatingCharacterBaseEvent);
@ -293,6 +295,7 @@ public class PenumbraIpcProviders : IDisposable
// Game State
GetDrawObjectInfo.Dispose();
GetCutsceneParentIndex.Dispose();
SetCutsceneParentIndex.Dispose();
CreatingCharacterBase.Dispose();
CreatedCharacterBase.Dispose();
GameObjectResourcePathResolved.Dispose();

View file

@ -56,6 +56,24 @@ public sealed class CutsceneService : IService, IDisposable
public int GetParentIndex(int idx)
=> GetParentIndex((ushort)idx);
public bool SetParentIndex(int copyIdx, int parentIdx)
{
if (copyIdx is < CutsceneStartIdx or >= CutsceneEndIdx)
return false;
if (parentIdx is < -1 or >= CutsceneEndIdx)
return false;
if (_objects.GetObjectAddress(copyIdx) == nint.Zero)
return false;
if (parentIdx != -1 && _objects.GetObjectAddress(parentIdx) == nint.Zero)
return false;
_copiedCharacters[copyIdx - CutsceneStartIdx] = (short)parentIdx;
return true;
}
public short GetParentIndex(ushort idx)
{
if (idx is >= CutsceneStartIdx and < CutsceneEndIdx)