This commit is contained in:
Ottermandias 2022-08-23 18:06:28 +02:00
parent cb2e2f0128
commit 941bba1518
39 changed files with 2569 additions and 1579 deletions

View file

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using Dalamud.Data;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using Lumina.Excel.GeneratedSheets;
using OtterGui.Raii;
using Companion = Lumina.Excel.GeneratedSheets.Companion;
namespace Glamourer;
@ -26,16 +26,37 @@ public class ModelData
FirstName = $"{name} #{model.RowId:D4}";
AllNames = $"#{model.RowId:D4}\n{name}";
}
public uint Id
=> Model.RowId;
}
private readonly SortedList<uint, Data> _models;
private readonly SortedList<uint, Data> _models;
private readonly Dictionary<ulong, Data> _modelByData;
public IReadOnlyDictionary<uint, Data> Models
=> _models;
public unsafe ulong KeyFromCharacterBase(CharacterBase* drawObject)
{
var type = (*(delegate* unmanaged<CharacterBase*, uint>**)drawObject)[50](drawObject);
var unk = (ulong)*((byte*)drawObject + 0x8E8) << 8;
return type switch
{
1 => type | unk,
2 => type | unk | ((ulong)*(ushort*)((byte*)drawObject + 0x908) << 16),
3 => type | unk | ((ulong)*(ushort*)((byte*)drawObject + 0x8F0) << 16) | ((ulong)**(ushort**)((byte*)drawObject + 0x910) << 32) | ((ulong)**(ushort**)((byte*)drawObject + 0x910) << 40),
_ => 0u,
};
}
public unsafe bool FromCharacterBase(CharacterBase* drawObject, out Data data)
=> _modelByData.TryGetValue(KeyFromCharacterBase(drawObject), out data);
public ModelData(DataManager dataManager)
{
var modelSheet = dataManager.GetExcelSheet<ModelChara>();
var modelSheet = dataManager.GetExcelSheet<ModelChara>()!;
_models = new SortedList<uint, Data>(NpcNames.ModelCharas.Count);
@ -71,5 +92,20 @@ public class ModelData
UpdateData(model, name);
}
}
_modelByData = new Dictionary<ulong, Data>((int)modelSheet.RowCount);
foreach (var mdl in modelSheet)
{
var unk5 = (ulong)mdl.Unknown5 << 8;
var key = mdl.Type switch
{
1 => mdl.Type | unk5,
2 => mdl.Type | unk5 | ((ulong)mdl.Model << 16),
3 => mdl.Type | unk5 | ((ulong)mdl.Model << 16) | ((ulong)mdl.Base << 32) | ((ulong)mdl.Base << 40),
_ => 0u,
};
if (key != 0)
_modelByData.TryAdd(key, _models.TryGetValue(mdl.RowId, out var d) ? d : new Data(mdl, string.Empty));
}
}
}