mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Split CharEquipment.
This commit is contained in:
parent
a4ae44f310
commit
3c560268fc
6 changed files with 136 additions and 49 deletions
27
Penumbra/Game/ActorEquip.cs
Normal file
27
Penumbra/Game/ActorEquip.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Penumbra.Game
|
||||
{
|
||||
[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
|
||||
{
|
||||
public readonly SetId Set;
|
||||
public readonly WeaponType Type;
|
||||
public readonly ushort Variant;
|
||||
public readonly StainId Stain;
|
||||
|
||||
public override string ToString()
|
||||
=> $"{Set},{Type},{Variant},{Stain}";
|
||||
}
|
||||
}
|
||||
|
|
@ -9,48 +9,25 @@ namespace Penumbra.Game
|
|||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
public class CharEquipment
|
||||
{
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
internal readonly struct Weapon
|
||||
{
|
||||
public readonly ushort Set;
|
||||
public readonly ushort Type;
|
||||
public readonly ushort Variant;
|
||||
public readonly byte Stain;
|
||||
|
||||
public override string ToString()
|
||||
=> $"{Set},{Type},{Variant},{Stain}";
|
||||
}
|
||||
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
internal readonly struct Equip
|
||||
{
|
||||
public readonly ushort Set;
|
||||
public readonly byte Variant;
|
||||
public readonly byte Stain;
|
||||
|
||||
public override string ToString()
|
||||
=> $"{Set},{Variant},{Stain}";
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
internal readonly Weapon Mainhand;
|
||||
internal readonly Weapon Offhand;
|
||||
internal readonly Equip Head;
|
||||
internal readonly Equip Body;
|
||||
internal readonly Equip Hands;
|
||||
internal readonly Equip Legs;
|
||||
internal readonly Equip Feet;
|
||||
internal readonly Equip Ear;
|
||||
internal readonly Equip Neck;
|
||||
internal readonly Equip Wrist;
|
||||
internal readonly Equip RFinger;
|
||||
internal readonly Equip LFinger;
|
||||
internal readonly ushort IsSet; // Also fills struct size to 56, a multiple of 8.
|
||||
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 CharEquipment()
|
||||
=> Clear();
|
||||
|
|
@ -81,23 +58,24 @@ namespace Penumbra.Game
|
|||
{
|
||||
IsSet = 1;
|
||||
var actorPtr = ( byte* )actorAddress.ToPointer();
|
||||
fixed( Weapon* main = &Mainhand, off = &Offhand )
|
||||
fixed( ActorWeapon* main = &Mainhand, off = &Offhand )
|
||||
{
|
||||
Buffer.MemoryCopy( actorPtr + MainWeaponOffset, main, sizeof( Weapon ), sizeof( Weapon ) );
|
||||
Buffer.MemoryCopy( actorPtr + OffWeaponOffset, off, sizeof( Weapon ), sizeof( Weapon ) );
|
||||
Buffer.MemoryCopy( actorPtr + MainWeaponOffset, main, sizeof( ActorWeapon ), sizeof( ActorWeapon ) );
|
||||
Buffer.MemoryCopy( actorPtr + OffWeaponOffset, off, sizeof( ActorWeapon ), sizeof( ActorWeapon ) );
|
||||
}
|
||||
|
||||
fixed( Equip* equipment = &Head )
|
||||
fixed( ActorEquip* equipment = &Head )
|
||||
{
|
||||
Buffer.MemoryCopy( actorPtr + EquipmentOffset, equipment, EquipmentSlots * sizeof( Equip ), EquipmentSlots * sizeof( Equip ) );
|
||||
Buffer.MemoryCopy( actorPtr + EquipmentOffset, equipment, EquipmentSlots * sizeof( ActorEquip ),
|
||||
EquipmentSlots * sizeof( ActorEquip ) );
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void Clear()
|
||||
{
|
||||
fixed( Weapon* main = &Mainhand )
|
||||
fixed( ActorWeapon* main = &Mainhand )
|
||||
{
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( Equip ) + WeaponSlots * sizeof( Weapon ) ) / 8;
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorEquip ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
for( ulong* ptr = ( ulong* )main, end = ptr + structSizeEights; ptr != end; ++ptr )
|
||||
{
|
||||
*ptr = 0;
|
||||
|
|
@ -107,9 +85,9 @@ namespace Penumbra.Game
|
|||
|
||||
private unsafe bool CompareAndOverwrite( CharEquipment rhs )
|
||||
{
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( Equip ) + WeaponSlots * sizeof( Weapon ) ) / 8;
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorEquip ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
var ret = true;
|
||||
fixed( Weapon* data1 = &Mainhand, data2 = &rhs.Mainhand )
|
||||
fixed( ActorWeapon* data1 = &Mainhand, data2 = &rhs.Mainhand )
|
||||
{
|
||||
var ptr1 = ( ulong* )data1;
|
||||
var ptr2 = ( ulong* )data2;
|
||||
|
|
@ -128,8 +106,8 @@ namespace Penumbra.Game
|
|||
|
||||
private unsafe bool CompareData( CharEquipment rhs )
|
||||
{
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( Equip ) + WeaponSlots * sizeof( Weapon ) ) / 8;
|
||||
fixed( Weapon* data1 = &Mainhand, data2 = &rhs.Mainhand )
|
||||
var structSizeEights = ( 2 + EquipmentSlots * sizeof( ActorEquip ) + WeaponSlots * sizeof( ActorWeapon ) ) / 8;
|
||||
fixed( ActorWeapon* data1 = &Mainhand, data2 = &rhs.Mainhand )
|
||||
{
|
||||
var ptr1 = ( ulong* )data1;
|
||||
var ptr2 = ( ulong* )data2;
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ namespace Penumbra.Game
|
|||
}
|
||||
}
|
||||
|
||||
public Item? Identify( ushort setId, ushort weaponType, ushort variant, EquipSlot slot )
|
||||
public Item? Identify( SetId setId, WeaponType weaponType, ushort variant, EquipSlot slot )
|
||||
{
|
||||
switch( slot )
|
||||
{
|
||||
|
|
@ -304,7 +304,8 @@ namespace Penumbra.Game
|
|||
}
|
||||
default:
|
||||
{
|
||||
var (begin, _) = FindIndexRange( _equipment, ( ( ulong )setId << 32 ) | ( ( ulong )slot.ToSlot() << 16 ) | weaponType,
|
||||
var (begin, _) = FindIndexRange( _equipment,
|
||||
( ( ulong )setId << 32 ) | ( ( ulong )slot.ToSlot() << 16 ) | ( ulong )weaponType,
|
||||
0xFFFFFFFFFFFF );
|
||||
return begin >= 0 ? _equipment[ begin ].Item2.FirstOrDefault() : null;
|
||||
}
|
||||
|
|
|
|||
23
Penumbra/Game/SetId.cs
Normal file
23
Penumbra/Game/SetId.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
|
||||
namespace Penumbra.Game
|
||||
{
|
||||
public readonly struct SetId : IComparable<SetId>
|
||||
{
|
||||
public readonly ushort Value;
|
||||
|
||||
public SetId( ushort value )
|
||||
=> Value = value;
|
||||
|
||||
public static implicit operator SetId( ushort id ) => new(id);
|
||||
|
||||
public static explicit operator ushort( SetId id )
|
||||
=> id.Value;
|
||||
|
||||
public override string ToString()
|
||||
=> Value.ToString();
|
||||
|
||||
public int CompareTo( SetId other )
|
||||
=> Value.CompareTo( other.Value );
|
||||
}
|
||||
}
|
||||
29
Penumbra/Game/StainId.cs
Normal file
29
Penumbra/Game/StainId.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
namespace Penumbra.Game
|
||||
{
|
||||
public readonly struct StainId : IEquatable<StainId>
|
||||
{
|
||||
public readonly byte Value;
|
||||
|
||||
public StainId( byte value )
|
||||
=> Value = value;
|
||||
|
||||
public static implicit operator StainId( byte id ) => new( id );
|
||||
|
||||
public static explicit operator byte( StainId id )
|
||||
=> id.Value;
|
||||
|
||||
public override string ToString()
|
||||
=> Value.ToString();
|
||||
|
||||
public bool Equals( StainId other )
|
||||
=> Value == other.Value;
|
||||
|
||||
public override bool Equals( object? obj )
|
||||
=> obj is StainId other && Equals( other );
|
||||
|
||||
public override int GetHashCode()
|
||||
=> Value.GetHashCode();
|
||||
}
|
||||
}
|
||||
29
Penumbra/Game/WeaponType.cs
Normal file
29
Penumbra/Game/WeaponType.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
namespace Penumbra.Game
|
||||
{
|
||||
public readonly struct WeaponType : IEquatable<WeaponType>
|
||||
{
|
||||
public readonly ushort Value;
|
||||
|
||||
public WeaponType( ushort value )
|
||||
=> Value = value;
|
||||
|
||||
public static implicit operator WeaponType( ushort id ) => new( id );
|
||||
|
||||
public static explicit operator ushort( WeaponType id )
|
||||
=> id.Value;
|
||||
|
||||
public override string ToString()
|
||||
=> Value.ToString();
|
||||
|
||||
public bool Equals( WeaponType other )
|
||||
=> Value == other.Value;
|
||||
|
||||
public override bool Equals( object? obj )
|
||||
=> obj is WeaponType other && Equals( other );
|
||||
|
||||
public override int GetHashCode()
|
||||
=> Value.GetHashCode();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue