make shit compile.

This commit is contained in:
Ottermandias 2023-06-02 18:48:22 +02:00
parent 10631341cb
commit 4eb46a9fff
14 changed files with 56 additions and 63 deletions

View file

@ -15,6 +15,7 @@ public partial class Design : DesignData, ISavable
{ {
public const int FileVersion = 1; public const int FileVersion = 1;
public Guid Identifier { get; internal init; } public Guid Identifier { get; internal init; }
public DateTimeOffset CreationDate { get; internal init; } public DateTimeOffset CreationDate { get; internal init; }
public LowerString Name { get; internal set; } = LowerString.Empty; public LowerString Name { get; internal set; } = LowerString.Empty;
@ -85,7 +86,7 @@ public partial class Design : DesignData, ISavable
[nameof(Description)] = Description, [nameof(Description)] = Description,
[nameof(Tags)] = JArray.FromObject(Tags), [nameof(Tags)] = JArray.FromObject(Tags),
[nameof(WriteProtected)] = WriteProtected, [nameof(WriteProtected)] = WriteProtected,
[nameof(ModelData.Equipment)] = SerializeEquipment(), ["Equipment"] = SerializeEquipment(),
[nameof(ModelData.Customize)] = SerializeCustomize(), [nameof(ModelData.Customize)] = SerializeCustomize(),
}; };
return ret; return ret;
@ -269,15 +270,15 @@ public partial class Design : DesignData, ISavable
UpdateMainhand(items, data.MainHand); UpdateMainhand(items, data.MainHand);
UpdateOffhand(items, data.OffHand); UpdateOffhand(items, data.OffHand);
foreach (var slot in EquipSlotExtensions.EqdpSlots) foreach (var slot in EquipSlotExtensions.EqdpSlots)
UpdateArmor(items, slot, data.Equipment[slot], true); UpdateArmor(items, slot, data.Armor(slot), true);
ModelData.CustomizeData = data.CustomizeData; ModelData.Customize = data.Customize;
ApplyEquip = applyEquip; ApplyEquip = applyEquip;
ApplyCustomize = applyCustomize; ApplyCustomize = applyCustomize;
WriteProtected = writeProtected; WriteProtected = writeProtected;
Wetness = wet; Wetness = wet;
Hat = hat; Hat = hat;
Visor = visor; Visor = visor;
Weapon = weapon; Weapon = weapon;
} }
public static Design CreateTemporaryFromBase64(ItemManager items, string base64, bool customize, bool equip) public static Design CreateTemporaryFromBase64(ItemManager items, string base64, bool customize, bool equip)

View file

@ -1,14 +1,10 @@
using System; using System;
using System.Runtime.InteropServices;
using Glamourer.Customization; using Glamourer.Customization;
using Glamourer.Interop;
using Glamourer.Services; using Glamourer.Services;
using OtterGui.Classes; using OtterGui.Classes;
using OtterGui; using OtterGui;
using Penumbra.GameData.Data;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs; using Penumbra.GameData.Structs;
using CustomizeData = FFXIVClientStructs.FFXIV.Client.Game.Character.CustomizeData;
namespace Glamourer.Designs; namespace Glamourer.Designs;
@ -218,7 +214,6 @@ public class DesignData
return true; return true;
} }
private bool SetArmor(EquipSlot slot, SetId set, byte variant, string name, uint id) private bool SetArmor(EquipSlot slot, SetId set, byte variant, string name, uint id)
{ {
var changes = false; var changes = false;
@ -373,13 +368,16 @@ public static class DesignBase64Migration
{ {
fixed (byte* ptr = bytes) fixed (byte* ptr = bytes)
{ {
data.CustomizeData.Read(ptr + 4); data.Customize.Load(*(Customize*) (ptr + 4));
var cur = (CharacterWeapon*)(ptr + 30); var cur = (CharacterWeapon*)(ptr + 30);
data.MainHand = cur[0]; data.MainHand = cur[0];
data.OffHand = cur[1]; data.OffHand = cur[1];
var eq = (CharacterArmor*)(cur + 2); var eq = (CharacterArmor*)(cur + 2);
foreach (var (slot, idx) in EquipSlotExtensions.EqdpSlots.WithIndex()) foreach (var (slot, idx) in EquipSlotExtensions.EqdpSlots.WithIndex())
data.Equipment[slot] = eq[idx]; {
var mdl = eq[idx];
data.SetPiece(slot, mdl.Set, mdl.Variant, mdl.Stain, out _);
}
} }
} }
@ -409,7 +407,7 @@ public static class DesignBase64Migration
| (equipFlags.HasFlag(EquipFlag.Wrist) ? 0x02 : 0) | (equipFlags.HasFlag(EquipFlag.Wrist) ? 0x02 : 0)
| (equipFlags.HasFlag(EquipFlag.RFinger) ? 0x04 : 0) | (equipFlags.HasFlag(EquipFlag.RFinger) ? 0x04 : 0)
| (equipFlags.HasFlag(EquipFlag.LFinger) ? 0x08 : 0)); | (equipFlags.HasFlag(EquipFlag.LFinger) ? 0x08 : 0));
save.CustomizeData.Write(data + 4); save.Customize.Load(*(Customize*) (data + 4));
((CharacterWeapon*)(data + 30))[0] = save.MainHand; ((CharacterWeapon*)(data + 30))[0] = save.MainHand;
((CharacterWeapon*)(data + 30))[1] = save.OffHand; ((CharacterWeapon*)(data + 30))[1] = save.OffHand;
((CharacterArmor*)(data + 44))[0] = save.Head; ((CharacterArmor*)(data + 44))[0] = save.Head;

View file

@ -6,6 +6,13 @@ using Penumbra.String.Functions;
namespace Glamourer.Designs; namespace Glamourer.Designs;
public struct ItemPiece
{
public string Name;
public uint ItemId;
public SetId ModelId;
}
[Flags] [Flags]
public enum ModelFlags : ushort public enum ModelFlags : ushort
{ {

View file

@ -58,9 +58,9 @@ public class DrawObjectManager : IDisposable
// Compare game object customize data against draw object customize data for transformations. // Compare game object customize data against draw object customize data for transformations.
// Apply customization if they correspond and there is customization to apply. // Apply customization if they correspond and there is customization to apply.
var gameObjectCustomize = gameObject.Customize; var gameObjectCustomize = gameObject.Customize;
var customize = new Customize((CustomizeData*)customizePtr); var customize = new Customize(*(CustomizeData*)customizePtr);
if (gameObjectCustomize.Equals(customize)) if (gameObjectCustomize.Equals(customize))
customize.Load(design.Customize); customize.Load(design.ModelData.Customize);
// Compare game object equip data against draw object equip data for transformations. // Compare game object equip data against draw object equip data for transformations.
// Apply each piece of equip that should be applied if they correspond. // Apply each piece of equip that should be applied if they correspond.
@ -68,11 +68,10 @@ public class DrawObjectManager : IDisposable
var equip = new CharacterEquip((CharacterArmor*)equipDataPtr); var equip = new CharacterEquip((CharacterArmor*)equipDataPtr);
if (gameObjectEquip.Equals(equip)) if (gameObjectEquip.Equals(equip))
{ {
var saveEquip = design.Equipment;
foreach (var slot in EquipSlotExtensions.EquipmentSlots) foreach (var slot in EquipSlotExtensions.EquipmentSlots)
{ {
(_, equip[slot]) = (_, equip[slot]) =
_items.ResolveRestrictedGear(saveEquip[slot], slot, customize.Race, customize.Gender); _items.ResolveRestrictedGear(design.ModelData.Armor(slot), slot, customize.Race, customize.Gender);
} }
} }
} }

View file

@ -20,13 +20,10 @@ public partial class CustomizationDrawer : IDisposable
private bool _withFlags = false; private bool _withFlags = false;
private Exception? _terminate = null; private Exception? _terminate = null;
private readonly unsafe CustomizeData* _data;
private Customize _customize; private Customize _customize;
private CustomizationSet _set = null!; private CustomizationSet _set = null!;
public unsafe CustomizeData CustomizeData public Customize Customize;
=> *_data;
public CustomizeFlag CurrentFlag { get; private set; } public CustomizeFlag CurrentFlag { get; private set; }
public CustomizeFlag Changed { get; private set; } public CustomizeFlag Changed { get; private set; }
@ -49,21 +46,12 @@ public partial class CustomizationDrawer : IDisposable
_service = service; _service = service;
_items = items; _items = items;
_legacyTattoo = GetLegacyTattooIcon(pi); _legacyTattoo = GetLegacyTattooIcon(pi);
unsafe Customize = Customize.Default;
{
_data = (CustomizeData*)Marshal.AllocHGlobal(sizeof(CustomizeData));
*_data = Customize.Default;
_customize = new Customize(_data);
}
} }
public void Dispose() public void Dispose()
{ {
_legacyTattoo?.Dispose(); _legacyTattoo?.Dispose();
unsafe
{
Marshal.FreeHGlobal((nint)_data);
}
} }
public bool Draw(Customize current, bool locked) public bool Draw(Customize current, bool locked)

View file

@ -72,8 +72,8 @@ public partial class Interface
_currentSave.Initialize(_items, _currentData.Objects[0]); _currentSave.Initialize(_items, _currentData.Objects[0]);
RevertButton(); RevertButton();
if (_main._customizationDrawer.Draw(_currentSave.Customize, _identifier.Type == IdentifierType.Special)) if (_main._customizationDrawer.Draw(_currentSave.ModelData.Customize, _identifier.Type == IdentifierType.Special))
_activeDesigns.ChangeCustomize(_currentSave, _main._customizationDrawer.Changed, _main._customizationDrawer.CustomizeData, _activeDesigns.ChangeCustomize(_currentSave, _main._customizationDrawer.Changed, _main._customizationDrawer.Customize.Data,
false); false);
foreach (var slot in EquipSlotExtensions.EqdpSlots) foreach (var slot in EquipSlotExtensions.EqdpSlots)
@ -82,8 +82,8 @@ public partial class Interface
if (_main._equipmentDrawer.DrawStain(current.Stain, slot, out var stain)) if (_main._equipmentDrawer.DrawStain(current.Stain, slot, out var stain))
_activeDesigns.ChangeStain(_currentSave, slot, stain.RowIndex, false); _activeDesigns.ChangeStain(_currentSave, slot, stain.RowIndex, false);
ImGui.SameLine(); ImGui.SameLine();
if (_main._equipmentDrawer.DrawArmor(current, slot, out var armor, _currentSave.Customize.Gender, if (_main._equipmentDrawer.DrawArmor(current, slot, out var armor, _currentSave.ModelData.Customize.Gender,
_currentSave.Customize.Race)) _currentSave.ModelData.Customize.Race))
_activeDesigns.ChangeEquipment(_currentSave, slot, armor, false); _activeDesigns.ChangeEquipment(_currentSave, slot, armor, false);
} }

View file

@ -79,7 +79,7 @@ public partial class Interface
if (!child) if (!child)
return; return;
_main._customizationDrawer.Draw(Selector.Selected.Customize, CustomizeFlagExtensions.All, true); _main._customizationDrawer.Draw(Selector.Selected.ModelData.Customize, CustomizeFlagExtensions.All, true);
foreach (var slot in EquipSlotExtensions.EqdpSlots) foreach (var slot in EquipSlotExtensions.EqdpSlots)
{ {
var current = Selector.Selected.Armor(slot); var current = Selector.Selected.Armor(slot);

View file

@ -82,10 +82,10 @@ public unsafe partial struct Actor : IEquatable<Actor>, IDesignable
=> ObjectKind == ObjectKind.Companion ? *(ushort*)((byte*)Pointer + 0x1AAC) : (ushort)0; => ObjectKind == ObjectKind.Companion ? *(ushort*)((byte*)Pointer + 0x1AAC) : (ushort)0;
public Customize Customize public Customize Customize
=> new((CustomizeData*)Pointer->CustomizeData); => new(*(CustomizeData*)&Pointer->DrawData.CustomizeData);
public CharacterEquip Equip public CharacterEquip Equip
=> new((CharacterArmor*)Pointer->EquipSlotData); => new((CharacterArmor*)&Pointer->DrawData.Head);
public CharacterWeapon MainHand public CharacterWeapon MainHand
{ {

View file

@ -32,7 +32,7 @@ public unsafe partial struct DrawObject : IEquatable<DrawObject>, IDesignable
=> (*(delegate* unmanaged<Human*, uint>**)Pointer)[50](Pointer); => (*(delegate* unmanaged<Human*, uint>**)Pointer)[50](Pointer);
public Customize Customize public Customize Customize
=> new((CustomizeData*)Pointer->CustomizeData); => *(Customize*)Pointer->CustomizeData;
public CharacterEquip Equip public CharacterEquip Equip
=> new((CharacterArmor*)Pointer->EquipSlotData); => new((CharacterArmor*)Pointer->EquipSlotData);

View file

@ -56,20 +56,19 @@ public unsafe partial class RedrawManager : IDisposable
// Compare game object customize data against draw object customize data for transformations. // Compare game object customize data against draw object customize data for transformations.
// Apply customization if they correspond and there is customization to apply. // Apply customization if they correspond and there is customization to apply.
var gameObjectCustomize = new Customize((CustomizeData*)actor.Pointer->CustomizeData); var gameObjectCustomize = new Customize(*(CustomizeData*)&actor.Pointer->DrawData.CustomizeData);
if (gameObjectCustomize.Equals(customize)) if (gameObjectCustomize.Equals(customize))
customize.Load(save!.Customize); customize.Load(save.ModelData.Customize);
// Compare game object equip data against draw object equip data for transformations. // Compare game object equip data against draw object equip data for transformations.
// Apply each piece of equip that should be applied if they correspond. // Apply each piece of equip that should be applied if they correspond.
var gameObjectEquip = new CharacterEquip((CharacterArmor*)actor.Pointer->EquipSlotData); var gameObjectEquip = new CharacterEquip((CharacterArmor*)&actor.Pointer->DrawData.Head);
if (gameObjectEquip.Equals(equip)) if (gameObjectEquip.Equals(equip))
{ {
var saveEquip = save!.Equipment;
foreach (var slot in EquipSlotExtensions.EqdpSlots) foreach (var slot in EquipSlotExtensions.EqdpSlots)
{ {
(_, equip[slot]) = (_, equip[slot]) =
_items.ResolveRestrictedGear(saveEquip[slot], slot, customize.Race, customize.Gender); _items.ResolveRestrictedGear(save.ModelData.Armor(slot), slot, customize.Race, customize.Gender);
} }
} }
} }
@ -78,7 +77,7 @@ public unsafe partial class RedrawManager : IDisposable
{ {
try try
{ {
OnCharacterRedraw(gameObject, (uint*)modelId, new Customize((CustomizeData*)customize), OnCharacterRedraw(gameObject, (uint*)modelId, new Customize(*(CustomizeData*)customize),
new CharacterEquip((CharacterArmor*)equipData)); new CharacterEquip((CharacterArmor*)equipData));
} }
catch (Exception e) catch (Exception e)

View file

@ -43,7 +43,7 @@ public class SaveService
public void QueueSave(ISavable value) public void QueueSave(ISavable value)
{ {
var file = value.ToFilename(FileNames); var file = value.ToFilename(FileNames);
_framework.RegisterDelayed(value.GetType().Name + file, () => _framework.RegisterOnTick(value.GetType().Name + file, () =>
{ {
ImmediateSave(value); ImmediateSave(value);
}); });

View file

@ -133,7 +133,7 @@ public sealed partial class ActiveDesign
ChangeStain(to, slot, armor.Stain, fromFixed); ChangeStain(to, slot, armor.Stain, fromFixed);
} }
ChangeCustomize(to, from.ApplyCustomize, *from.Customize.Data, fromFixed); ChangeCustomize(to, from.ApplyCustomize, from.ModelData.Customize.Data, fromFixed);
if (from.Wetness.Enabled) if (from.Wetness.Enabled)
SetWetness(to, from.Wetness.ForcedValue, fromFixed); SetWetness(to, from.Wetness.ForcedValue, fromFixed);
@ -168,11 +168,11 @@ public sealed partial class ActiveDesign
{ } { }
public void RevertCustomize(ActiveDesign design, CustomizeFlag flags) public void RevertCustomize(ActiveDesign design, CustomizeFlag flags)
=> ChangeCustomize(design, flags, design._initialData.CustomizeData, false); => ChangeCustomize(design, flags, design._initialData.Customize.Data, false);
public void ChangeCustomize(ActiveDesign design, CustomizeFlag flags, CustomizeData newValue, bool fromFixed) public void ChangeCustomize(ActiveDesign design, CustomizeFlag flags, CustomizeData newValue, bool fromFixed)
{ {
var customize = new Customize(ref newValue); var customize = new Customize(newValue);
var anyChanges = false; var anyChanges = false;
foreach (var option in Enum.GetValues<CustomizeIndex>()) foreach (var option in Enum.GetValues<CustomizeIndex>())
{ {
@ -203,13 +203,13 @@ public sealed partial class ActiveDesign
if (redraw) if (redraw)
_penumbra.RedrawObject(obj, RedrawType.Redraw); _penumbra.RedrawObject(obj, RedrawType.Redraw);
else else
_customize.UpdateCustomize(obj, design.ModelData.CustomizeData); _customize.UpdateCustomize(obj, design.ModelData.Customize.Data);
} }
} }
public void RevertEquipment(ActiveDesign design, EquipSlot slot, bool equip, bool stain) public void RevertEquipment(ActiveDesign design, EquipSlot slot, bool equip, bool stain)
{ {
var item = design._initialData.Equipment[slot]; var item = design._initialData.Armor(slot);
if (equip) if (equip)
{ {
var flag = slot.ToFlag(); var flag = slot.ToFlag();
@ -239,7 +239,7 @@ public sealed partial class ActiveDesign
var flag = slot.ToFlag(); var flag = slot.ToFlag();
design.SetArmor(slot, item); design.SetArmor(slot, item);
var current = design.Armor(slot); var current = design.Armor(slot);
var initial = design._initialData.Equipment[slot]; var initial = design._initialData.Armor(slot);
if (current.ModelBase.Value != initial.Set.Value || current.Variant != initial.Variant) if (current.ModelBase.Value != initial.Set.Value || current.Variant != initial.Variant)
design.ChangedEquip |= flag; design.ChangedEquip |= flag;
else else
@ -265,7 +265,7 @@ public sealed partial class ActiveDesign
{ {
EquipSlot.MainHand => (design.WeaponMain.Stain, design._initialData.MainHand.Stain, true), EquipSlot.MainHand => (design.WeaponMain.Stain, design._initialData.MainHand.Stain, true),
EquipSlot.OffHand => (design.WeaponOff.Stain, design._initialData.OffHand.Stain, true), EquipSlot.OffHand => (design.WeaponOff.Stain, design._initialData.OffHand.Stain, true),
_ => (design.Armor(slot).Stain, design._initialData.Equipment[slot].Stain, false), _ => (design.Armor(slot).Stain, design._initialData.Armor(slot).Stain, false),
}; };
if (current.Value != initial.Value) if (current.Value != initial.Value)
design.ChangedEquip |= flag; design.ChangedEquip |= flag;

View file

@ -7,6 +7,8 @@ using Penumbra.GameData.Enums;
namespace Glamourer.State; namespace Glamourer.State;
public sealed partial class ActiveDesign : DesignData public sealed partial class ActiveDesign : DesignData
{ {
public readonly ActorIdentifier Identifier; public readonly ActorIdentifier Identifier;
@ -74,17 +76,16 @@ public sealed partial class ActiveDesign : DesignData
if (!_initialData.Customize.Equals(actor.Customize)) if (!_initialData.Customize.Equals(actor.Customize))
{ {
_initialData.Customize.Load(actor.Customize); _initialData.Customize.Load(actor.Customize);
Customize.Load(actor.Customize); ModelData.Customize.Load(actor.Customize);
} }
var initialEquip = _initialData.Equipment;
var currentEquip = actor.Equip; var currentEquip = actor.Equip;
foreach (var slot in EquipSlotExtensions.EqdpSlots) foreach (var slot in EquipSlotExtensions.EqdpSlots)
{ {
var current = currentEquip[slot]; var current = currentEquip[slot];
if (initialEquip[slot] != current) if (_initialData.Armor(slot) != current)
{ {
initialEquip[slot] = current; _initialData.SetPiece(slot, current.Set, current.Variant, current.Stain, out _);
UpdateArmor(items, slot, current, true); UpdateArmor(items, slot, current, true);
SetStain(slot, current.Stain); SetStain(slot, current.Stain);
} }

View file

@ -13,7 +13,7 @@ public class FixedDesignManager
{ {
public class FixedDesign public class FixedDesign
{ {
public Design Design; public Design Design = null!;
public byte? JobCondition; public byte? JobCondition;
public ushort? TerritoryCondition; public ushort? TerritoryCondition;