2024-11-01 16:41:05 -04:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2025-01-03 16:11:32 -05:00
|
|
|
using System.Runtime.CompilerServices;
|
2024-11-01 18:58:38 -04:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using Dalamud.Utility;
|
|
|
|
using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel;
|
|
|
|
using FFXIVClientStructs.FFXIV.Client.System.String;
|
2024-11-01 16:41:05 -04:00
|
|
|
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
2024-11-01 18:58:38 -04:00
|
|
|
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
|
|
|
|
using Lumina.Data.Files;
|
2024-11-17 15:04:15 -05:00
|
|
|
using Lumina.Excel.Sheets;
|
2024-11-01 16:41:05 -04:00
|
|
|
using SharpDX;
|
|
|
|
using SharpDX.Direct3D11;
|
|
|
|
using SharpDX.DXGI;
|
|
|
|
using SixLabors.ImageSharp;
|
|
|
|
using SixLabors.ImageSharp.Formats.Png;
|
|
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
|
|
|
|
|
|
namespace Auracite;
|
|
|
|
|
|
|
|
public class AdventurerPlateStep : IStep
|
|
|
|
{
|
|
|
|
public AdventurerPlateStep()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public event IStep.CompletedDelegate? Completed;
|
|
|
|
|
|
|
|
public void Run()
|
|
|
|
{
|
|
|
|
if (IsInPlateWindow())
|
|
|
|
{
|
|
|
|
unsafe
|
|
|
|
{
|
2025-03-10 20:35:19 -04:00
|
|
|
var storage = AgentCharaCard.Instance()->Data;
|
2024-11-01 16:41:05 -04:00
|
|
|
var image = GetCurrentCharaViewImage();
|
|
|
|
Plugin.package.portrait = image.ToBase64String(PngFormat.Instance);
|
2025-03-10 20:35:19 -04:00
|
|
|
|
|
|
|
var plateDesign = storage->PlateDesign;
|
2024-11-01 18:58:38 -04:00
|
|
|
|
2025-03-10 20:35:19 -04:00
|
|
|
if (plateDesign.BasePlate != 0)
|
2024-11-01 18:58:38 -04:00
|
|
|
{
|
2025-03-10 20:35:19 -04:00
|
|
|
Plugin.package.base_plate = GetImage(ResolveCardBase(plateDesign.BasePlate))
|
2024-11-01 18:58:38 -04:00
|
|
|
.ToBase64String(PngFormat.Instance);
|
|
|
|
}
|
|
|
|
|
2025-03-10 20:35:19 -04:00
|
|
|
for (int i = 0; i < plateDesign.NumDecorations; i++)
|
2024-11-01 18:58:38 -04:00
|
|
|
{
|
2025-03-10 20:35:19 -04:00
|
|
|
var decoration = storage->Decorations[i];
|
|
|
|
var rowIndex = plateDesign.Decorations[i];
|
2025-01-03 16:11:32 -05:00
|
|
|
if (rowIndex == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2025-03-29 17:02:07 -04:00
|
|
|
switch (decoration.Type)
|
2025-01-03 16:11:32 -05:00
|
|
|
{
|
2025-03-29 17:02:07 -04:00
|
|
|
case AgentCharaCard.DecorationType.PatternOverlay:
|
2025-01-03 16:11:32 -05:00
|
|
|
{
|
|
|
|
Plugin.package.pattern_overlay = GetImage(ResolveCardDecoration(rowIndex))
|
|
|
|
.ToBase64String(PngFormat.Instance);
|
|
|
|
}
|
|
|
|
break;
|
2025-03-29 17:02:07 -04:00
|
|
|
case AgentCharaCard.DecorationType.Backing:
|
2025-01-03 16:11:32 -05:00
|
|
|
{
|
|
|
|
Plugin.package.backing = GetImage(ResolveCardDecoration(rowIndex))
|
|
|
|
.ToBase64String(PngFormat.Instance);
|
|
|
|
}
|
|
|
|
break;
|
2025-03-29 17:02:07 -04:00
|
|
|
case AgentCharaCard.DecorationType.PortraitFrame:
|
2025-01-03 16:11:32 -05:00
|
|
|
{
|
|
|
|
Plugin.package.portrait_frame = GetImage(ResolveCardDecoration(rowIndex))
|
|
|
|
.ToBase64String(PngFormat.Instance);
|
|
|
|
}
|
|
|
|
break;
|
2025-03-29 17:02:07 -04:00
|
|
|
case AgentCharaCard.DecorationType.PlateFrame:
|
2025-01-03 16:11:32 -05:00
|
|
|
{
|
|
|
|
Plugin.package.plate_frame = GetImage(ResolveCardDecoration(rowIndex))
|
|
|
|
.ToBase64String(PngFormat.Instance);
|
|
|
|
}
|
|
|
|
break;
|
2025-03-29 17:02:07 -04:00
|
|
|
case AgentCharaCard.DecorationType.Accent:
|
2025-01-03 16:11:32 -05:00
|
|
|
{
|
|
|
|
Plugin.package.accent = GetImage(ResolveCardDecoration(rowIndex))
|
|
|
|
.ToBase64String(PngFormat.Instance);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-11-01 18:58:38 -04:00
|
|
|
}
|
|
|
|
|
2025-03-10 20:35:19 -04:00
|
|
|
if (plateDesign.TopBorder != 0)
|
2024-11-01 18:58:38 -04:00
|
|
|
{
|
2025-03-10 20:35:19 -04:00
|
|
|
Plugin.package.top_border = GetImage(ResolveCardHeaderTop(plateDesign.TopBorder))
|
2024-11-01 18:58:38 -04:00
|
|
|
.ToBase64String(PngFormat.Instance);
|
|
|
|
}
|
|
|
|
|
2025-03-10 20:35:19 -04:00
|
|
|
if (plateDesign.BottomBorder != 0)
|
2024-11-01 18:58:38 -04:00
|
|
|
{
|
2025-03-10 20:35:19 -04:00
|
|
|
Plugin.package.bottom_border = GetImage(ResolveCardHeaderBottom(plateDesign.BottomBorder))
|
2024-11-01 18:58:38 -04:00
|
|
|
.ToBase64String(PngFormat.Instance);
|
|
|
|
}
|
|
|
|
|
2024-11-17 15:04:15 -05:00
|
|
|
Plugin.package.plate_title = Title?.Feminine.ToString(); // TODO: Support mascs
|
2024-11-01 16:41:05 -04:00
|
|
|
Plugin.package.plate_title_is_prefix = Title?.IsPrefix;
|
2024-11-17 15:04:15 -05:00
|
|
|
Plugin.package.plate_class_job = ClassJob?.Name.ToString();
|
2024-11-01 16:41:05 -04:00
|
|
|
Plugin.package.plate_class_job_level = AgentCharaCard.Instance()->Data->Level;
|
|
|
|
Plugin.package.search_comment = AgentCharaCard.Instance()->Data->SearchComment.ToString();
|
|
|
|
Completed?.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public unsafe Image GetCurrentCharaViewImage()
|
|
|
|
{
|
|
|
|
var texture = CppObject.FromPointer<Texture2D>((nint)AgentCharaCard.Instance()->Data->PortraitTexture->D3D11Texture2D);
|
|
|
|
var device = (Device5)(IntPtr)FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Device.Instance()->D3D11Forwarder;
|
|
|
|
|
|
|
|
// Copy to a CPU-mapped staging texture
|
|
|
|
var desc = texture.Description;
|
|
|
|
|
|
|
|
using var stagingTexture = new Texture2D(device, new Texture2DDescription()
|
|
|
|
{
|
|
|
|
ArraySize = 1,
|
|
|
|
BindFlags = BindFlags.None,
|
|
|
|
CpuAccessFlags = CpuAccessFlags.Read,
|
|
|
|
Format = desc.Format,
|
|
|
|
Height = desc.Height,
|
|
|
|
Width = desc.Width,
|
|
|
|
MipLevels = 1,
|
|
|
|
OptionFlags = desc.OptionFlags,
|
|
|
|
SampleDescription = new SampleDescription(1, 0),
|
|
|
|
Usage = ResourceUsage.Staging
|
|
|
|
});
|
|
|
|
|
|
|
|
device.ImmediateContext.CopyResource(texture, stagingTexture);
|
|
|
|
|
|
|
|
device.ImmediateContext.MapSubresource(stagingTexture, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None, out var dataStream);
|
|
|
|
|
|
|
|
using var pixelDataStream = new MemoryStream();
|
|
|
|
dataStream.CopyTo(pixelDataStream);
|
|
|
|
|
|
|
|
device.ImmediateContext.UnmapSubresource(stagingTexture, 0);
|
|
|
|
|
|
|
|
return Image.LoadPixelData<Bgra32>(pixelDataStream.ToArray(), desc.Width, desc.Height);
|
|
|
|
}
|
2024-11-01 18:58:38 -04:00
|
|
|
|
|
|
|
public Image GetImage(string path)
|
|
|
|
{
|
|
|
|
var tex = Plugin.DataManager.GetFile<TexFile>(path);
|
|
|
|
tex.LoadFile();
|
|
|
|
var imageData = tex.GetRgbaImageData();
|
|
|
|
return Image.LoadPixelData<Rgba32>(imageData, tex.Header.Width, tex.Header.Height);
|
|
|
|
}
|
2024-11-01 16:41:05 -04:00
|
|
|
|
|
|
|
private unsafe Title? Title {
|
|
|
|
get {
|
|
|
|
ushort titleId = AgentCharaCard.Instance()->Data->TitleId;
|
|
|
|
return titleId == 0
|
|
|
|
? null
|
|
|
|
: Plugin.DataManager.GetExcelSheet<Title>()?.GetRow(titleId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private unsafe ClassJob? ClassJob {
|
|
|
|
get {
|
|
|
|
ushort classJobId = AgentCharaCard.Instance()->Data->ClassJobId;
|
|
|
|
return classJobId == 0
|
|
|
|
? null
|
|
|
|
: Plugin.DataManager.GetExcelSheet<ClassJob>()?.GetRow(classJobId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string StepName()
|
|
|
|
{
|
|
|
|
return "Adventurer Plate";
|
|
|
|
}
|
|
|
|
|
|
|
|
public string StepDescription()
|
|
|
|
{
|
|
|
|
return "Type /adventurerplate into the chat window or open your Adventurer Plate.";
|
|
|
|
}
|
|
|
|
|
|
|
|
private static unsafe bool IsInPlateWindow()
|
|
|
|
{
|
|
|
|
return AgentCharaCard.Instance()->AgentInterface.IsAgentActive();
|
|
|
|
}
|
2024-11-01 18:58:38 -04:00
|
|
|
|
|
|
|
public string ResolveCardBase(uint rowIndex)
|
|
|
|
{
|
|
|
|
var row = Plugin.DataManager.GetExcelSheet<CharaCardBase>()?.GetRow(rowIndex);
|
2024-11-17 15:04:15 -05:00
|
|
|
return $"ui/icon/{row?.Image.ToString().Substring(0, 3)}000/{row?.Image}_hr1.tex";
|
2024-11-01 18:58:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public string? ResolveCardDecoration(uint rowIndex)
|
|
|
|
{
|
|
|
|
var row = Plugin.DataManager.GetExcelSheet<CharaCardDecoration>()?.GetRow(rowIndex);
|
2024-11-17 15:04:15 -05:00
|
|
|
return $"ui/icon/{row?.Image.ToString().Substring(0, 3)}000/{row?.Image}_hr1.tex";
|
2024-11-01 18:58:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public string? ResolveCardHeaderTop(uint rowIndex)
|
|
|
|
{
|
|
|
|
var row = Plugin.DataManager.GetExcelSheet<CharaCardHeader>()?.GetRow(rowIndex);
|
2024-11-17 15:04:15 -05:00
|
|
|
return $"ui/icon/{row?.TopImage.ToString().Substring(0, 3)}000/{row?.TopImage}_hr1.tex";
|
2024-11-01 18:58:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public string? ResolveCardHeaderBottom(uint rowIndex)
|
|
|
|
{
|
|
|
|
var row = Plugin.DataManager.GetExcelSheet<CharaCardHeader>()?.GetRow(rowIndex);
|
2024-11-17 15:04:15 -05:00
|
|
|
return $"ui/icon/{row?.BottomImage.ToString().Substring(0, 3)}000/{row?.BottomImage}_hr1.tex";
|
2024-11-01 18:58:38 -04:00
|
|
|
}
|
2025-03-10 20:42:37 -04:00
|
|
|
}
|