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
|
|
@ -7,7 +7,7 @@ namespace Penumbra.GameData.Enums
|
|||
{
|
||||
Unknown = 0,
|
||||
MainHand = 1,
|
||||
Offhand = 2,
|
||||
OffHand = 2,
|
||||
Head = 3,
|
||||
Body = 4,
|
||||
Hands = 5,
|
||||
|
|
@ -17,9 +17,9 @@ namespace Penumbra.GameData.Enums
|
|||
Ears = 9,
|
||||
Neck = 10,
|
||||
Wrists = 11,
|
||||
RingR = 12,
|
||||
RFinger = 12,
|
||||
BothHand = 13,
|
||||
RingL = 14, // Not officially existing, means "weapon could be equipped in either hand" for the game.
|
||||
LFinger = 14, // Not officially existing, means "weapon could be equipped in either hand" for the game.
|
||||
HeadBody = 15,
|
||||
BodyHandsLegsFeet = 16,
|
||||
SoulCrystal = 17,
|
||||
|
|
@ -36,17 +36,17 @@ namespace Penumbra.GameData.Enums
|
|||
{
|
||||
return value switch
|
||||
{
|
||||
EquipSlot.Head => "met",
|
||||
EquipSlot.Hands => "glv",
|
||||
EquipSlot.Legs => "dwn",
|
||||
EquipSlot.Feet => "sho",
|
||||
EquipSlot.Body => "top",
|
||||
EquipSlot.Ears => "ear",
|
||||
EquipSlot.Neck => "nek",
|
||||
EquipSlot.RingR => "rir",
|
||||
EquipSlot.RingL => "ril",
|
||||
EquipSlot.Wrists => "wrs",
|
||||
_ => throw new InvalidEnumArgumentException(),
|
||||
EquipSlot.Head => "met",
|
||||
EquipSlot.Hands => "glv",
|
||||
EquipSlot.Legs => "dwn",
|
||||
EquipSlot.Feet => "sho",
|
||||
EquipSlot.Body => "top",
|
||||
EquipSlot.Ears => "ear",
|
||||
EquipSlot.Neck => "nek",
|
||||
EquipSlot.RFinger => "rir",
|
||||
EquipSlot.LFinger => "ril",
|
||||
EquipSlot.Wrists => "wrs",
|
||||
_ => throw new InvalidEnumArgumentException(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ namespace Penumbra.GameData.Enums
|
|||
return value switch
|
||||
{
|
||||
EquipSlot.MainHand => EquipSlot.MainHand,
|
||||
EquipSlot.Offhand => EquipSlot.Offhand,
|
||||
EquipSlot.OffHand => EquipSlot.OffHand,
|
||||
EquipSlot.Head => EquipSlot.Head,
|
||||
EquipSlot.Body => EquipSlot.Body,
|
||||
EquipSlot.Hands => EquipSlot.Hands,
|
||||
|
|
@ -65,9 +65,9 @@ namespace Penumbra.GameData.Enums
|
|||
EquipSlot.Ears => EquipSlot.Ears,
|
||||
EquipSlot.Neck => EquipSlot.Neck,
|
||||
EquipSlot.Wrists => EquipSlot.Wrists,
|
||||
EquipSlot.RingR => EquipSlot.RingR,
|
||||
EquipSlot.RFinger => EquipSlot.RFinger,
|
||||
EquipSlot.BothHand => EquipSlot.MainHand,
|
||||
EquipSlot.RingL => EquipSlot.RingR,
|
||||
EquipSlot.LFinger => EquipSlot.RFinger,
|
||||
EquipSlot.HeadBody => EquipSlot.Body,
|
||||
EquipSlot.BodyHandsLegsFeet => EquipSlot.Body,
|
||||
EquipSlot.SoulCrystal => EquipSlot.SoulCrystal,
|
||||
|
|
@ -96,12 +96,12 @@ namespace Penumbra.GameData.Enums
|
|||
{
|
||||
return value switch
|
||||
{
|
||||
EquipSlot.Ears => true,
|
||||
EquipSlot.Neck => true,
|
||||
EquipSlot.RingR => true,
|
||||
EquipSlot.RingL => true,
|
||||
EquipSlot.Wrists => true,
|
||||
_ => false,
|
||||
EquipSlot.Ears => true,
|
||||
EquipSlot.Neck => true,
|
||||
EquipSlot.RFinger => true,
|
||||
EquipSlot.LFinger => true,
|
||||
EquipSlot.Wrists => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -117,8 +117,8 @@ namespace Penumbra.GameData.Enums
|
|||
{ EquipSlot.Body.ToSuffix(), EquipSlot.Body },
|
||||
{ EquipSlot.Ears.ToSuffix(), EquipSlot.Ears },
|
||||
{ EquipSlot.Neck.ToSuffix(), EquipSlot.Neck },
|
||||
{ EquipSlot.RingR.ToSuffix(), EquipSlot.RingR },
|
||||
{ EquipSlot.RingL.ToSuffix(), EquipSlot.RingL },
|
||||
{ EquipSlot.RFinger.ToSuffix(), EquipSlot.RFinger },
|
||||
{ EquipSlot.LFinger.ToSuffix(), EquipSlot.LFinger },
|
||||
{ EquipSlot.Wrists.ToSuffix(), EquipSlot.Wrists },
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ namespace Penumbra.GameData
|
|||
switch( ( EquipSlot )item.EquipSlotCategory.Row )
|
||||
{
|
||||
case EquipSlot.MainHand:
|
||||
case EquipSlot.Offhand:
|
||||
case EquipSlot.OffHand:
|
||||
case EquipSlot.BothHand:
|
||||
if( item.ModelMain != 0 )
|
||||
{
|
||||
|
|
@ -88,7 +88,7 @@ namespace Penumbra.GameData
|
|||
|
||||
break;
|
||||
// Accessories
|
||||
case EquipSlot.RingR:
|
||||
case EquipSlot.RFinger:
|
||||
case EquipSlot.Wrists:
|
||||
case EquipSlot.Ears:
|
||||
case EquipSlot.Neck:
|
||||
|
|
@ -304,7 +304,7 @@ namespace Penumbra.GameData
|
|||
switch( slot )
|
||||
{
|
||||
case EquipSlot.MainHand:
|
||||
case EquipSlot.Offhand:
|
||||
case EquipSlot.OffHand:
|
||||
{
|
||||
var (begin, _) = FindIndexRange( _weapons, ( ( ulong )setId << 32 ) | ( ( ulong )weaponType << 16 ) | variant,
|
||||
0xFFFFFFFFFFFF );
|
||||
|
|
|
|||
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