mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Some more general cleanup.
This commit is contained in:
parent
44fc83784d
commit
3679b780cf
13 changed files with 116 additions and 111 deletions
15
Penumbra.GameData/Structs/ActorArmor.cs
Normal file
15
Penumbra.GameData/Structs/ActorArmor.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Penumbra.GameData.Structs
|
||||
{
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
public readonly struct ActorArmor
|
||||
{
|
||||
public readonly SetId Set;
|
||||
public readonly byte Variant;
|
||||
public readonly StainId Stain;
|
||||
|
||||
public override string ToString()
|
||||
=> $"{Set},{Variant},{Stain}";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +1,82 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Dalamud.Game.ClientState.Actors.Types;
|
||||
using Penumbra.GameData.Enums;
|
||||
|
||||
// Read the customization data regarding weapons and displayable equipment from an actor struct.
|
||||
// Stores the data in a 56 bytes, i.e. 7 longs for easier comparison.
|
||||
namespace Penumbra.GameData.Structs
|
||||
{
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
public class CharEquipment
|
||||
public class ActorEquipment
|
||||
{
|
||||
private const int MainWeaponOffset = 0x0F08;
|
||||
private const int OffWeaponOffset = 0x0F70;
|
||||
private const int EquipmentOffset = 0x1040;
|
||||
private const int EquipmentSlots = 10;
|
||||
private const int WeaponSlots = 2;
|
||||
public const int MainWeaponOffset = 0x0F08;
|
||||
public const int OffWeaponOffset = 0x0F70;
|
||||
public const int EquipmentOffset = 0x1040;
|
||||
public const int EquipmentSlots = 10;
|
||||
public const int WeaponSlots = 2;
|
||||
|
||||
public readonly ActorWeapon Mainhand;
|
||||
public readonly ActorWeapon Offhand;
|
||||
public readonly ActorEquip Head;
|
||||
public readonly ActorEquip Body;
|
||||
public readonly ActorEquip Hands;
|
||||
public readonly ActorEquip Legs;
|
||||
public readonly ActorEquip Feet;
|
||||
public readonly ActorEquip Ear;
|
||||
public readonly ActorEquip Neck;
|
||||
public readonly ActorEquip Wrist;
|
||||
public readonly ActorEquip RFinger;
|
||||
public readonly ActorEquip LFinger;
|
||||
public readonly 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 CharEquipment()
|
||||
public ActorEquipment()
|
||||
=> Clear();
|
||||
|
||||
public CharEquipment( Actor actor )
|
||||
public ActorEquipment( Actor actor )
|
||||
: this( actor.Address )
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
=> IsSet == 0
|
||||
? "(Not Set)"
|
||||
: $"({Mainhand}) | ({Offhand}) | ({Head}) | ({Body}) | ({Hands}) | ({Legs}) | "
|
||||
+ $"({Feet}) | ({Ear}) | ({Neck}) | ({Wrist}) | ({LFinger}) | ({RFinger})";
|
||||
: $"({MainHand}) | ({OffHand}) | ({Head}) | ({Body}) | ({Hands}) | ({Legs}) | "
|
||||
+ $"({Feet}) | ({Ears}) | ({Neck}) | ({Wrists}) | ({LFinger}) | ({RFinger})";
|
||||
|
||||
public bool Equal( Actor rhs )
|
||||
=> CompareData( new CharEquipment( rhs ) );
|
||||
=> CompareData( new ActorEquipment( rhs ) );
|
||||
|
||||
public bool Equal( CharEquipment rhs )
|
||||
public bool Equal( ActorEquipment rhs )
|
||||
=> CompareData( rhs );
|
||||
|
||||
public bool CompareAndUpdate( Actor rhs )
|
||||
=> CompareAndOverwrite( new CharEquipment( rhs ) );
|
||||
=> CompareAndOverwrite( new ActorEquipment( rhs ) );
|
||||
|
||||
public bool CompareAndUpdate( CharEquipment rhs )
|
||||
public bool CompareAndUpdate( ActorEquipment rhs )
|
||||
=> CompareAndOverwrite( rhs );
|
||||
|
||||
private unsafe CharEquipment( IntPtr actorAddress )
|
||||
private unsafe ActorEquipment( IntPtr actorAddress )
|
||||
{
|
||||
IsSet = 1;
|
||||
var actorPtr = ( byte* )actorAddress.ToPointer();
|
||||
fixed( ActorWeapon* main = &Mainhand, off = &Offhand )
|
||||
fixed( ActorWeapon* main = &MainHand, off = &OffHand )
|
||||
{
|
||||
Buffer.MemoryCopy( actorPtr + MainWeaponOffset, main, sizeof( ActorWeapon ), sizeof( ActorWeapon ) );
|
||||
Buffer.MemoryCopy( actorPtr + OffWeaponOffset, off, sizeof( ActorWeapon ), sizeof( ActorWeapon ) );
|
||||
}
|
||||
|
||||
fixed( ActorEquip* equipment = &Head )
|
||||
fixed( ActorArmor* equipment = &Head )
|
||||
{
|
||||
Buffer.MemoryCopy( actorPtr + EquipmentOffset, equipment, EquipmentSlots * sizeof( ActorEquip ),
|
||||
EquipmentSlots * sizeof( ActorEquip ) );
|
||||
Buffer.MemoryCopy( actorPtr + EquipmentOffset, equipment, EquipmentSlots * sizeof( ActorArmor ),
|
||||
EquipmentSlots * sizeof( ActorArmor ) );
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void Clear()
|
||||
{
|
||||
fixed( ActorWeapon* main = &Mainhand )
|
||||
fixed( ActorWeapon* main = &MainHand )
|
||||
{
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorEquip ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorArmor ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
for( ulong* ptr = ( ulong* )main, end = ptr + structSizeEights; ptr != end; ++ptr )
|
||||
{
|
||||
*ptr = 0;
|
||||
|
|
@ -83,11 +84,11 @@ namespace Penumbra.GameData.Structs
|
|||
}
|
||||
}
|
||||
|
||||
private unsafe bool CompareAndOverwrite( CharEquipment rhs )
|
||||
private unsafe bool CompareAndOverwrite( ActorEquipment rhs )
|
||||
{
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorEquip ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorArmor ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
var ret = true;
|
||||
fixed( ActorWeapon* data1 = &Mainhand, data2 = &rhs.Mainhand )
|
||||
fixed( ActorWeapon* data1 = &MainHand, data2 = &rhs.MainHand )
|
||||
{
|
||||
var ptr1 = ( ulong* )data1;
|
||||
var ptr2 = ( ulong* )data2;
|
||||
|
|
@ -104,10 +105,10 @@ namespace Penumbra.GameData.Structs
|
|||
return ret;
|
||||
}
|
||||
|
||||
private unsafe bool CompareData( CharEquipment rhs )
|
||||
private unsafe bool CompareData( ActorEquipment rhs )
|
||||
{
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorEquip ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
fixed( ActorWeapon* data1 = &Mainhand, data2 = &rhs.Mainhand )
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorArmor ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
fixed( ActorWeapon* data1 = &MainHand, data2 = &rhs.MainHand )
|
||||
{
|
||||
var ptr1 = ( ulong* )data1;
|
||||
var ptr2 = ( ulong* )data2;
|
||||
|
|
@ -2,17 +2,6 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace Penumbra.GameData.Structs
|
||||
{
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
public readonly struct ActorEquip
|
||||
{
|
||||
public readonly SetId Set;
|
||||
public readonly byte Variant;
|
||||
public readonly StainId Stain;
|
||||
|
||||
public override string ToString()
|
||||
=> $"{Set},{Variant},{Stain}";
|
||||
}
|
||||
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
public readonly struct ActorWeapon
|
||||
{
|
||||
|
|
@ -63,8 +63,8 @@ namespace Penumbra.GameData.Structs
|
|||
EquipSlot.Ears => 0,
|
||||
EquipSlot.Neck => 2,
|
||||
EquipSlot.Wrists => 4,
|
||||
EquipSlot.RingR => 6,
|
||||
EquipSlot.RingL => 8,
|
||||
EquipSlot.RFinger => 6,
|
||||
EquipSlot.LFinger => 8,
|
||||
_ => throw new InvalidEnumArgumentException(),
|
||||
};
|
||||
}
|
||||
|
|
@ -98,8 +98,8 @@ namespace Penumbra.GameData.Structs
|
|||
EquipSlot.Ears => EqdpEntry.EarsMask,
|
||||
EquipSlot.Neck => EqdpEntry.NeckMask,
|
||||
EquipSlot.Wrists => EqdpEntry.WristsMask,
|
||||
EquipSlot.RingR => EqdpEntry.RingRMask,
|
||||
EquipSlot.RingL => EqdpEntry.RingLMask,
|
||||
EquipSlot.RFinger => EqdpEntry.RingRMask,
|
||||
EquipSlot.LFinger => EqdpEntry.RingLMask,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue