From 4eb46a9fff8a21513d12c9257c7928b4a4043fa4 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 2 Jun 2023 18:48:22 +0200 Subject: [PATCH] make shit compile. --- Glamourer/Designs/Design.cs | 21 ++++++++++--------- Glamourer/Designs/DesignData.cs | 14 ++++++------- Glamourer/Designs/ModelData.cs | 7 +++++++ Glamourer/DrawObjectManager.cs | 7 +++---- .../Gui/Customization/CustomizationDrawer.cs | 16 ++------------ Glamourer/Gui/Interface.Actors.cs | 8 +++---- Glamourer/Gui/Interface.DesignTab.cs | 2 +- Glamourer/Interop/Actor.cs | 4 ++-- Glamourer/Interop/DrawObject.cs | 2 +- Glamourer/Interop/RedrawManager.cs | 11 +++++----- Glamourer/Services/SaveService.cs | 2 +- Glamourer/State/ActiveDesign.Manager.cs | 14 ++++++------- Glamourer/State/ActiveDesign.cs | 9 ++++---- Glamourer/State/FixedDesignManager.cs | 2 +- 14 files changed, 56 insertions(+), 63 deletions(-) diff --git a/Glamourer/Designs/Design.cs b/Glamourer/Designs/Design.cs index efccd20..09283c0 100644 --- a/Glamourer/Designs/Design.cs +++ b/Glamourer/Designs/Design.cs @@ -15,6 +15,7 @@ public partial class Design : DesignData, ISavable { public const int FileVersion = 1; + public Guid Identifier { get; internal init; } public DateTimeOffset CreationDate { get; internal init; } public LowerString Name { get; internal set; } = LowerString.Empty; @@ -85,7 +86,7 @@ public partial class Design : DesignData, ISavable [nameof(Description)] = Description, [nameof(Tags)] = JArray.FromObject(Tags), [nameof(WriteProtected)] = WriteProtected, - [nameof(ModelData.Equipment)] = SerializeEquipment(), + ["Equipment"] = SerializeEquipment(), [nameof(ModelData.Customize)] = SerializeCustomize(), }; return ret; @@ -269,15 +270,15 @@ public partial class Design : DesignData, ISavable UpdateMainhand(items, data.MainHand); UpdateOffhand(items, data.OffHand); foreach (var slot in EquipSlotExtensions.EqdpSlots) - UpdateArmor(items, slot, data.Equipment[slot], true); - ModelData.CustomizeData = data.CustomizeData; - ApplyEquip = applyEquip; - ApplyCustomize = applyCustomize; - WriteProtected = writeProtected; - Wetness = wet; - Hat = hat; - Visor = visor; - Weapon = weapon; + UpdateArmor(items, slot, data.Armor(slot), true); + ModelData.Customize = data.Customize; + ApplyEquip = applyEquip; + ApplyCustomize = applyCustomize; + WriteProtected = writeProtected; + Wetness = wet; + Hat = hat; + Visor = visor; + Weapon = weapon; } public static Design CreateTemporaryFromBase64(ItemManager items, string base64, bool customize, bool equip) diff --git a/Glamourer/Designs/DesignData.cs b/Glamourer/Designs/DesignData.cs index a2ca078..7c2c52c 100644 --- a/Glamourer/Designs/DesignData.cs +++ b/Glamourer/Designs/DesignData.cs @@ -1,14 +1,10 @@ using System; -using System.Runtime.InteropServices; using Glamourer.Customization; -using Glamourer.Interop; using Glamourer.Services; using OtterGui.Classes; using OtterGui; -using Penumbra.GameData.Data; using Penumbra.GameData.Enums; using Penumbra.GameData.Structs; -using CustomizeData = FFXIVClientStructs.FFXIV.Client.Game.Character.CustomizeData; namespace Glamourer.Designs; @@ -218,7 +214,6 @@ public class DesignData return true; } - private bool SetArmor(EquipSlot slot, SetId set, byte variant, string name, uint id) { var changes = false; @@ -373,13 +368,16 @@ public static class DesignBase64Migration { fixed (byte* ptr = bytes) { - data.CustomizeData.Read(ptr + 4); + data.Customize.Load(*(Customize*) (ptr + 4)); var cur = (CharacterWeapon*)(ptr + 30); data.MainHand = cur[0]; data.OffHand = cur[1]; var eq = (CharacterArmor*)(cur + 2); 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.RFinger) ? 0x04 : 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))[1] = save.OffHand; ((CharacterArmor*)(data + 44))[0] = save.Head; diff --git a/Glamourer/Designs/ModelData.cs b/Glamourer/Designs/ModelData.cs index e9852dd..5f2b914 100644 --- a/Glamourer/Designs/ModelData.cs +++ b/Glamourer/Designs/ModelData.cs @@ -6,6 +6,13 @@ using Penumbra.String.Functions; namespace Glamourer.Designs; +public struct ItemPiece +{ + public string Name; + public uint ItemId; + public SetId ModelId; +} + [Flags] public enum ModelFlags : ushort { diff --git a/Glamourer/DrawObjectManager.cs b/Glamourer/DrawObjectManager.cs index 3c25ad8..430d1c0 100644 --- a/Glamourer/DrawObjectManager.cs +++ b/Glamourer/DrawObjectManager.cs @@ -58,9 +58,9 @@ public class DrawObjectManager : IDisposable // Compare game object customize data against draw object customize data for transformations. // Apply customization if they correspond and there is customization to apply. var gameObjectCustomize = gameObject.Customize; - var customize = new Customize((CustomizeData*)customizePtr); + var customize = new Customize(*(CustomizeData*)customizePtr); 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. // 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); if (gameObjectEquip.Equals(equip)) { - var saveEquip = design.Equipment; foreach (var slot in EquipSlotExtensions.EquipmentSlots) { (_, equip[slot]) = - _items.ResolveRestrictedGear(saveEquip[slot], slot, customize.Race, customize.Gender); + _items.ResolveRestrictedGear(design.ModelData.Armor(slot), slot, customize.Race, customize.Gender); } } } diff --git a/Glamourer/Gui/Customization/CustomizationDrawer.cs b/Glamourer/Gui/Customization/CustomizationDrawer.cs index fa90d55..51b0399 100644 --- a/Glamourer/Gui/Customization/CustomizationDrawer.cs +++ b/Glamourer/Gui/Customization/CustomizationDrawer.cs @@ -20,13 +20,10 @@ public partial class CustomizationDrawer : IDisposable private bool _withFlags = false; private Exception? _terminate = null; - private readonly unsafe CustomizeData* _data; - private Customize _customize; private CustomizationSet _set = null!; - public unsafe CustomizeData CustomizeData - => *_data; + public Customize Customize; public CustomizeFlag CurrentFlag { get; private set; } public CustomizeFlag Changed { get; private set; } @@ -49,21 +46,12 @@ public partial class CustomizationDrawer : IDisposable _service = service; _items = items; _legacyTattoo = GetLegacyTattooIcon(pi); - unsafe - { - _data = (CustomizeData*)Marshal.AllocHGlobal(sizeof(CustomizeData)); - *_data = Customize.Default; - _customize = new Customize(_data); - } + Customize = Customize.Default; } public void Dispose() { _legacyTattoo?.Dispose(); - unsafe - { - Marshal.FreeHGlobal((nint)_data); - } } public bool Draw(Customize current, bool locked) diff --git a/Glamourer/Gui/Interface.Actors.cs b/Glamourer/Gui/Interface.Actors.cs index fbd6c43..413a498 100644 --- a/Glamourer/Gui/Interface.Actors.cs +++ b/Glamourer/Gui/Interface.Actors.cs @@ -72,8 +72,8 @@ public partial class Interface _currentSave.Initialize(_items, _currentData.Objects[0]); RevertButton(); - if (_main._customizationDrawer.Draw(_currentSave.Customize, _identifier.Type == IdentifierType.Special)) - _activeDesigns.ChangeCustomize(_currentSave, _main._customizationDrawer.Changed, _main._customizationDrawer.CustomizeData, + if (_main._customizationDrawer.Draw(_currentSave.ModelData.Customize, _identifier.Type == IdentifierType.Special)) + _activeDesigns.ChangeCustomize(_currentSave, _main._customizationDrawer.Changed, _main._customizationDrawer.Customize.Data, false); foreach (var slot in EquipSlotExtensions.EqdpSlots) @@ -82,8 +82,8 @@ public partial class Interface if (_main._equipmentDrawer.DrawStain(current.Stain, slot, out var stain)) _activeDesigns.ChangeStain(_currentSave, slot, stain.RowIndex, false); ImGui.SameLine(); - if (_main._equipmentDrawer.DrawArmor(current, slot, out var armor, _currentSave.Customize.Gender, - _currentSave.Customize.Race)) + if (_main._equipmentDrawer.DrawArmor(current, slot, out var armor, _currentSave.ModelData.Customize.Gender, + _currentSave.ModelData.Customize.Race)) _activeDesigns.ChangeEquipment(_currentSave, slot, armor, false); } diff --git a/Glamourer/Gui/Interface.DesignTab.cs b/Glamourer/Gui/Interface.DesignTab.cs index 82927eb..40a92dc 100644 --- a/Glamourer/Gui/Interface.DesignTab.cs +++ b/Glamourer/Gui/Interface.DesignTab.cs @@ -79,7 +79,7 @@ public partial class Interface if (!child) 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) { var current = Selector.Selected.Armor(slot); diff --git a/Glamourer/Interop/Actor.cs b/Glamourer/Interop/Actor.cs index b3a875d..5192637 100644 --- a/Glamourer/Interop/Actor.cs +++ b/Glamourer/Interop/Actor.cs @@ -82,10 +82,10 @@ public unsafe partial struct Actor : IEquatable, IDesignable => ObjectKind == ObjectKind.Companion ? *(ushort*)((byte*)Pointer + 0x1AAC) : (ushort)0; public Customize Customize - => new((CustomizeData*)Pointer->CustomizeData); + => new(*(CustomizeData*)&Pointer->DrawData.CustomizeData); public CharacterEquip Equip - => new((CharacterArmor*)Pointer->EquipSlotData); + => new((CharacterArmor*)&Pointer->DrawData.Head); public CharacterWeapon MainHand { diff --git a/Glamourer/Interop/DrawObject.cs b/Glamourer/Interop/DrawObject.cs index fe67a7f..6775120 100644 --- a/Glamourer/Interop/DrawObject.cs +++ b/Glamourer/Interop/DrawObject.cs @@ -32,7 +32,7 @@ public unsafe partial struct DrawObject : IEquatable, IDesignable => (*(delegate* unmanaged**)Pointer)[50](Pointer); public Customize Customize - => new((CustomizeData*)Pointer->CustomizeData); + => *(Customize*)Pointer->CustomizeData; public CharacterEquip Equip => new((CharacterArmor*)Pointer->EquipSlotData); diff --git a/Glamourer/Interop/RedrawManager.cs b/Glamourer/Interop/RedrawManager.cs index c6ba3e7..2340c23 100644 --- a/Glamourer/Interop/RedrawManager.cs +++ b/Glamourer/Interop/RedrawManager.cs @@ -56,20 +56,19 @@ public unsafe partial class RedrawManager : IDisposable // Compare game object customize data against draw object customize data for transformations. // 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)) - customize.Load(save!.Customize); + customize.Load(save.ModelData.Customize); // Compare game object equip data against draw object equip data for transformations. // 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)) { - var saveEquip = save!.Equipment; foreach (var slot in EquipSlotExtensions.EqdpSlots) { (_, 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 { - OnCharacterRedraw(gameObject, (uint*)modelId, new Customize((CustomizeData*)customize), + OnCharacterRedraw(gameObject, (uint*)modelId, new Customize(*(CustomizeData*)customize), new CharacterEquip((CharacterArmor*)equipData)); } catch (Exception e) diff --git a/Glamourer/Services/SaveService.cs b/Glamourer/Services/SaveService.cs index 06fb498..6638888 100644 --- a/Glamourer/Services/SaveService.cs +++ b/Glamourer/Services/SaveService.cs @@ -43,7 +43,7 @@ public class SaveService public void QueueSave(ISavable value) { var file = value.ToFilename(FileNames); - _framework.RegisterDelayed(value.GetType().Name + file, () => + _framework.RegisterOnTick(value.GetType().Name + file, () => { ImmediateSave(value); }); diff --git a/Glamourer/State/ActiveDesign.Manager.cs b/Glamourer/State/ActiveDesign.Manager.cs index 4946e30..b7c65ab 100644 --- a/Glamourer/State/ActiveDesign.Manager.cs +++ b/Glamourer/State/ActiveDesign.Manager.cs @@ -133,7 +133,7 @@ public sealed partial class ActiveDesign 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) SetWetness(to, from.Wetness.ForcedValue, fromFixed); @@ -168,11 +168,11 @@ public sealed partial class ActiveDesign { } 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) { - var customize = new Customize(ref newValue); + var customize = new Customize(newValue); var anyChanges = false; foreach (var option in Enum.GetValues()) { @@ -203,13 +203,13 @@ public sealed partial class ActiveDesign if (redraw) _penumbra.RedrawObject(obj, RedrawType.Redraw); 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) { - var item = design._initialData.Equipment[slot]; + var item = design._initialData.Armor(slot); if (equip) { var flag = slot.ToFlag(); @@ -239,7 +239,7 @@ public sealed partial class ActiveDesign var flag = slot.ToFlag(); design.SetArmor(slot, item); 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) design.ChangedEquip |= flag; else @@ -265,7 +265,7 @@ public sealed partial class ActiveDesign { EquipSlot.MainHand => (design.WeaponMain.Stain, design._initialData.MainHand.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) design.ChangedEquip |= flag; diff --git a/Glamourer/State/ActiveDesign.cs b/Glamourer/State/ActiveDesign.cs index f488738..9118c90 100644 --- a/Glamourer/State/ActiveDesign.cs +++ b/Glamourer/State/ActiveDesign.cs @@ -7,6 +7,8 @@ using Penumbra.GameData.Enums; namespace Glamourer.State; + + public sealed partial class ActiveDesign : DesignData { public readonly ActorIdentifier Identifier; @@ -74,17 +76,16 @@ public sealed partial class ActiveDesign : DesignData if (!_initialData.Customize.Equals(actor.Customize)) { _initialData.Customize.Load(actor.Customize); - Customize.Load(actor.Customize); + ModelData.Customize.Load(actor.Customize); } - var initialEquip = _initialData.Equipment; var currentEquip = actor.Equip; foreach (var slot in EquipSlotExtensions.EqdpSlots) { 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); SetStain(slot, current.Stain); } diff --git a/Glamourer/State/FixedDesignManager.cs b/Glamourer/State/FixedDesignManager.cs index d7706e4..1215060 100644 --- a/Glamourer/State/FixedDesignManager.cs +++ b/Glamourer/State/FixedDesignManager.cs @@ -13,7 +13,7 @@ public class FixedDesignManager { public class FixedDesign { - public Design Design; + public Design Design = null!; public byte? JobCondition; public ushort? TerritoryCondition;