-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
188 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,10 @@ | |
using Dalamud.Interface; | ||
using FFXIVClientStructs.FFXIV.Component.GUI; | ||
using FFXIVClientStructs.FFXIV.Client.System.Memory; | ||
using TickTracker.Windows; | ||
using Dalamud.Plugin.Services; | ||
using Lumina.Data.Files; | ||
using System.Linq; | ||
|
||
namespace TickTracker.Helpers; | ||
|
||
|
@@ -12,7 +16,18 @@ public static unsafe class NativeUi | |
{ | ||
private static readonly Dictionary<string, uint> NodeIds = new(StringComparer.Ordinal); | ||
private static readonly Dictionary<uint, string> NodeNames = new(); | ||
private static Dictionary<uint, string> TextureDictionary = new(); | ||
private static uint NodeIdBase = 0x5469636B; | ||
private static int CurrentNodePartsListAmount = 0; | ||
|
||
private static IDataManager? DataManager; | ||
private static IPluginLog Log = null!; | ||
|
||
public static void InitServices(IDataManager _dataManager, IPluginLog _log) | ||
{ | ||
DataManager = _dataManager; | ||
Log = _log; | ||
} | ||
|
||
public static uint Get(string name, int index = 0) | ||
{ | ||
|
@@ -82,12 +97,162 @@ public static void FreeImageComponents(ref AtkImageNode* imageNode) | |
{ | ||
IMemorySpace.Free(imageNode->PartsList->Parts->UldAsset, (ulong)(sizeof(AtkUldAsset) * imageNode->PartsList->PartCount)); | ||
IMemorySpace.Free(imageNode->PartsList->Parts, (ulong)(sizeof(AtkUldPart) * imageNode->PartsList->PartCount)); | ||
IMemorySpace.Free(imageNode->PartsList, (ulong)sizeof(AtkUldPartsList)); | ||
IMemorySpace.Free(imageNode->PartsList, (ulong)(sizeof(AtkUldPartsList)* CurrentNodePartsListAmount)); | ||
imageNode->AtkResNode.Destroy(false); | ||
IMemorySpace.Free(imageNode, (ulong)sizeof(AtkImageNode)); | ||
} | ||
|
||
private static AtkUldPartsList* CreateAtkUldPartsList(UldWrapper uld, int partListIndex, string texturePath) | ||
private static void PopulateTextureDictionary(UldFile uldFile) | ||
{ | ||
if (DataManager is null) | ||
{ | ||
return; | ||
} | ||
TextureDictionary.Clear(); | ||
for (var i = 0; i < uldFile.AssetData.Length; i++) | ||
{ | ||
var rawTexturePath = uldFile.AssetData[i].Path; | ||
if (rawTexturePath is null) | ||
{ | ||
DevWindow.Print($"{rawTexturePath} was skipped"); | ||
continue; | ||
} | ||
|
||
var textureId = uldFile.AssetData[i].Id; | ||
var texturePath = new string(rawTexturePath, 0, rawTexturePath.Length).Trim('\0').Trim(); | ||
var hqTexturePath = texturePath.Replace(".tex", "_hr1.tex"); | ||
|
||
if (DataManager.FileExists(hqTexturePath)) | ||
{ | ||
TextureDictionary.Add(textureId, hqTexturePath); | ||
} | ||
else if (DataManager.FileExists(texturePath)) | ||
{ | ||
TextureDictionary.Add(textureId, texturePath); | ||
} | ||
} | ||
} | ||
|
||
private static void ParseUldFile(UldFile uld, out int uldPartsListAmount, out uint uldPartAmount) | ||
{ | ||
uldPartsListAmount = uld.Parts.Length; | ||
uldPartAmount = 0; | ||
for (var i = 0; i < uldPartsListAmount; i++) | ||
{ | ||
var currentPartList = uld.Parts[i]; | ||
uldPartAmount += currentPartList.PartCount; | ||
} | ||
} | ||
|
||
private static AtkUldPartsList* CreateCompleteAtkUldPartsList(UldWrapper uld) | ||
Check warning on line 147 in TickTracker/Helpers/NativeUi.cs GitHub Actions / build
Check warning on line 147 in TickTracker/Helpers/NativeUi.cs GitHub Actions / build
|
||
{ | ||
if (!uld.Valid || uld.Uld is null) | ||
{ | ||
return null; | ||
} | ||
var uldFile = uld.Uld; | ||
ParseUldFile(uldFile, out var uldPartsListAmount, out var uldPartAmount); | ||
CurrentNodePartsListAmount = uldPartsListAmount; | ||
PopulateTextureDictionary(uldFile); | ||
if (TextureDictionary.Count is 0) | ||
{ | ||
return null; | ||
} | ||
|
||
var atkPartsList = (AtkUldPartsList*)IMemorySpace.GetUISpace()->Malloc((ulong)(sizeof(AtkUldPartsList) * uldPartsListAmount), 8); | ||
if (atkPartsList is null) | ||
{ | ||
return null; | ||
} | ||
for (var i = 0; i < uldPartsListAmount; i++) | ||
{ | ||
atkPartsList[i].Id = uldFile.Parts[i].Id; | ||
atkPartsList[i].PartCount = uldFile.Parts[i].PartCount; | ||
} | ||
|
||
var atkUldPart = (AtkUldPart*)IMemorySpace.GetUISpace()->Malloc((ulong)(sizeof(AtkUldPart) * uldPartAmount), 8); | ||
if (atkUldPart is null) | ||
{ | ||
IMemorySpace.Free(atkPartsList, (ulong)(sizeof(AtkUldPartsList) * uldPartsListAmount)); | ||
return null; | ||
} | ||
for (var i = 0; i < uldPartsListAmount; i++) | ||
{ | ||
for (var j = 0; j < atkPartsList[i].PartCount; j++) | ||
{ | ||
// j + i uld part? | ||
var currentUldPart = uldFile.Parts[i].Parts[j]; | ||
atkUldPart[j].U = currentUldPart.U; | ||
atkUldPart[j].V = currentUldPart.V; | ||
atkUldPart[j].Width = currentUldPart.W; | ||
atkUldPart[j].Height = currentUldPart.H; | ||
} | ||
atkPartsList[i].Parts = atkUldPart; | ||
} | ||
|
||
var atkUldAsset = (AtkUldAsset*)IMemorySpace.GetUISpace()->Malloc((ulong)(sizeof(AtkUldAsset) * uldPartAmount), 8); | ||
if (atkUldAsset is null) | ||
{ | ||
IMemorySpace.Free(atkUldPart, (ulong)(sizeof(AtkUldPart) * uldPartAmount)); | ||
IMemorySpace.Free(atkPartsList, (ulong)(sizeof(AtkUldPartsList) * uldPartsListAmount)); | ||
return null; | ||
} | ||
for (var i = 0; i < uldPartsListAmount; i++) | ||
{ | ||
var currentPartsList = &atkPartsList[i]; | ||
var currentUldPartsList = uldFile.Parts[i]; | ||
for (var j = 0; j < currentPartsList->PartCount; j++) | ||
{ | ||
var currentPart = ¤tPartsList->Parts[j]; | ||
var currentUldPart = currentUldPartsList.Parts[j]; | ||
atkUldAsset[j].Id = currentUldPart.TextureId; | ||
atkUldAsset[j].AtkTexture.Ctor(); | ||
if (TextureDictionary.ContainsKey(atkUldAsset[j].Id)) | ||
{ | ||
var texturePath = TextureDictionary[atkUldAsset[j].Id]; | ||
Log.Debug("Loading texture {path}", texturePath); | ||
atkUldAsset[j].AtkTexture.LoadTexture(texturePath); | ||
} | ||
currentPart->UldAsset = &atkUldAsset[j]; | ||
} | ||
} | ||
|
||
if (atkPartsList is null) | ||
{ | ||
IMemorySpace.Free(atkUldAsset, (ulong)(sizeof(AtkUldAsset) * uldPartAmount)); | ||
IMemorySpace.Free(atkUldPart, (ulong)(sizeof(AtkUldPart) * uldPartAmount)); | ||
IMemorySpace.Free(atkPartsList, (ulong)(sizeof(AtkUldPartsList) * uldPartsListAmount)); | ||
return null; | ||
} | ||
|
||
return atkPartsList; | ||
} | ||
|
||
public static AtkImageNode* CreateCompleteImageNode(UldWrapper uld, uint ImageNodeID, AtkComponentNode* parent, AtkResNode* targetNode, bool visibility) | ||
{ | ||
var imageNode = IMemorySpace.GetUISpace()->Create<AtkImageNode>(); | ||
if (imageNode is null) | ||
{ | ||
return null; | ||
} | ||
var atkPartList = CreateCompleteAtkUldPartsList(uld); | ||
imageNode->AtkResNode.Type = NodeType.Image; | ||
imageNode->AtkResNode.NodeID = ImageNodeID; | ||
imageNode->PartsList = atkPartList; | ||
imageNode->PartId = 0; | ||
imageNode->AtkResNode.NodeFlags = NodeFlags.AnchorTop | NodeFlags.AnchorLeft | NodeFlags.Enabled | NodeFlags.Visible | NodeFlags.EmitsEvents; | ||
imageNode->AtkResNode.DrawFlags |= 1; | ||
imageNode->WrapMode = 1; | ||
imageNode->Flags = 0; | ||
imageNode->AtkResNode.SetWidth(160); | ||
imageNode->AtkResNode.SetHeight(20); | ||
imageNode->AtkResNode.SetScale(1, 1); | ||
imageNode->AtkResNode.ToggleVisibility(visibility); | ||
LinkNodeAfterTargetNode(&imageNode->AtkResNode, parent, targetNode); | ||
return imageNode; | ||
} | ||
|
||
private static AtkUldPartsList* CreateAtkUldPartsList(UldWrapper uld, int partListIndex) | ||
{ | ||
if (!uld.Valid || uld.Uld is null) | ||
{ | ||
|
@@ -134,7 +299,7 @@ public static void FreeImageComponents(ref AtkImageNode* imageNode) | |
atkUldAsset[i].AtkTexture.Ctor(); | ||
// Technically not a proper call, because the texturePath is blindly passed here | ||
// Different parts can belong to different textures | ||
atkUldAsset[i].AtkTexture.LoadTexture(texturePath); | ||
//atkUldAsset[i].AtkTexture.LoadTexture(texturePath); | ||
atkPartsList->Parts[i].UldAsset = &atkUldAsset[i]; | ||
} | ||
|
||
|
@@ -148,7 +313,7 @@ public static void FreeImageComponents(ref AtkImageNode* imageNode) | |
{ | ||
return null; | ||
} | ||
var atkPartList = CreateAtkUldPartsList(uld, partListIndex, texturePath); | ||
var atkPartList = CreateAtkUldPartsList(uld, partListIndex); | ||
if (atkPartList is null) | ||
{ | ||
IMemorySpace.Free(imageNode, (ulong)sizeof(AtkImageNode)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters