From 44bbf546f616f304c44227fc33a07c5b49973d24 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 7 Aug 2021 12:02:55 +0200 Subject: [PATCH] Add some Write options to ActorEquipment. --- Penumbra.GameData/Structs/ActorEquipment.cs | 49 +++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/Penumbra.GameData/Structs/ActorEquipment.cs b/Penumbra.GameData/Structs/ActorEquipment.cs index 29852577..ff9f3116 100644 --- a/Penumbra.GameData/Structs/ActorEquipment.cs +++ b/Penumbra.GameData/Structs/ActorEquipment.cs @@ -16,19 +16,19 @@ namespace Penumbra.GameData.Structs public const int EquipmentSlots = 10; public const int WeaponSlots = 2; - public ActorWeapon MainHand; - public ActorWeapon OffHand; - public ActorArmor Head; - public ActorArmor Body; - public ActorArmor Hands; - public ActorArmor Legs; - public ActorArmor Feet; - public ActorArmor Ears; - public ActorArmor Neck; - public ActorArmor Wrists; - public ActorArmor RFinger; - public ActorArmor LFinger; - public ushort IsSet; // Also fills struct size to 56, a multiple of 8. + public ActorWeapon MainHand; + public ActorWeapon OffHand; + public ActorArmor Head; + public ActorArmor Body; + public ActorArmor Hands; + public ActorArmor Legs; + public ActorArmor Feet; + public ActorArmor Ears; + public ActorArmor Neck; + public ActorArmor Wrists; + public ActorArmor RFinger; + public ActorArmor LFinger; + public ushort IsSet; // Also fills struct size to 56, a multiple of 8. public ActorEquipment() => Clear(); @@ -123,5 +123,28 @@ namespace Penumbra.GameData.Structs return true; } + + public unsafe void WriteBytes( byte[] array, int offset = 0 ) + { + fixed( ActorWeapon* data = &MainHand ) + { + Marshal.Copy( new IntPtr( data ), array, offset, 56 ); + } + } + + public byte[] ToBytes() + { + var ret = new byte[56]; + WriteBytes( ret ); + return ret; + } + + public unsafe void FromBytes( byte[] array, int offset = 0 ) + { + fixed( ActorWeapon* data = &MainHand ) + { + Marshal.Copy( array, offset, new IntPtr( data ), 56 ); + } + } } } \ No newline at end of file