Some more general cleanup.

This commit is contained in:
Ottermandias 2021-07-27 00:13:36 +02:00
parent 44fc83784d
commit 3679b780cf
13 changed files with 116 additions and 111 deletions

View file

@ -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 },
};
}

View file

@ -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 );

View 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}";
}
}

View file

@ -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;

View file

@ -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
{

View file

@ -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,
};
}

View file

@ -23,6 +23,6 @@ namespace Penumbra.PlayerWatch
public void AddPlayerToWatch( string name );
public void RemovePlayerFromWatch( string playerName );
public CharEquipment UpdateActorWithoutEvent( Actor actor );
public ActorEquipment UpdateActorWithoutEvent( Actor actor );
}
}

View file

@ -15,7 +15,7 @@ namespace Penumbra.PlayerWatch
private readonly DalamudPluginInterface _pi;
internal readonly HashSet< PlayerWatcher > RegisteredWatchers = new();
private readonly Dictionary< string, (CharEquipment, HashSet< PlayerWatcher >) > _equip = new();
private readonly Dictionary< string, (ActorEquipment, HashSet< PlayerWatcher >) > _equip = new();
private int _frameTicker;
private IntPtr _lastGPoseAddress = IntPtr.Zero;
@ -41,9 +41,9 @@ namespace Penumbra.PlayerWatch
}
}
internal CharEquipment UpdateActorWithoutEvent( Actor actor )
internal ActorEquipment UpdateActorWithoutEvent( Actor actor )
{
var equipment = new CharEquipment( actor );
var equipment = new ActorEquipment( actor );
if( _equip.ContainsKey( actor.Name ) )
{
_equip[ actor.Name ] = ( equipment, _equip[ actor.Name ].Item2 );
@ -60,7 +60,7 @@ namespace Penumbra.PlayerWatch
}
else
{
_equip[ playerName ] = ( new CharEquipment(), new HashSet< PlayerWatcher > { watcher } );
_equip[ playerName ] = ( new ActorEquipment(), new HashSet< PlayerWatcher > { watcher } );
}
}

View file

@ -73,7 +73,7 @@ namespace Penumbra.PlayerWatch
_playerWatch!.RemovePlayerFromWatch( playerName, this );
}
public CharEquipment UpdateActorWithoutEvent( Actor actor )
public ActorEquipment UpdateActorWithoutEvent( Actor actor )
{
CheckValidity();
return _playerWatch!.UpdateActorWithoutEvent( actor );

View file

@ -111,9 +111,9 @@ namespace Penumbra.Meta.Files
EquipSlot.Hands => 2,
EquipSlot.Wrists => 2,
EquipSlot.Legs => 3,
EquipSlot.RingR => 3,
EquipSlot.RFinger => 3,
EquipSlot.Feet => 4,
EquipSlot.RingL => 4,
EquipSlot.LFinger => 4,
_ => throw new InvalidEnumArgumentException(),
};
}

View file

@ -71,8 +71,8 @@ namespace Penumbra.Meta.Files
EquipSlot.Neck => Eqdp( ObjectType.Accessory, gr ),
EquipSlot.Ears => Eqdp( ObjectType.Accessory, gr ),
EquipSlot.Wrists => Eqdp( ObjectType.Accessory, gr ),
EquipSlot.RingL => Eqdp( ObjectType.Accessory, gr ),
EquipSlot.RingR => Eqdp( ObjectType.Accessory, gr ),
EquipSlot.LFinger => Eqdp( ObjectType.Accessory, gr ),
EquipSlot.RFinger => Eqdp( ObjectType.Accessory, gr ),
_ => throw new NotImplementedException(),
};
}

View file

@ -27,10 +27,10 @@ namespace Penumbra.UI
return;
}
var actors = ( Dictionary< string, CharEquipment >? )_plugin.PlayerWatcher.GetType()
var actors = ( Dictionary< string, ActorEquipment >? )_plugin.PlayerWatcher.GetType()
.GetField( "_equip", BindingFlags.Instance | BindingFlags.NonPublic )
?.GetValue( _plugin.PlayerWatcher )
?? new Dictionary< string, CharEquipment >();
?? new Dictionary< string, ActorEquipment >();
if( !actors.Any() )
{
return;
@ -48,7 +48,7 @@ namespace Penumbra.UI
ImGui.TableNextColumn();
ImGui.Text( actor.Key );
ImGui.TableNextColumn();
ImGui.Text( $"{actor.Value.Mainhand}" );
ImGui.Text( $"{actor.Value.MainHand}" );
ImGui.TableNextColumn();
ImGui.Text( $"{actor.Value.Head}" );
ImGui.TableNextColumn();
@ -67,7 +67,7 @@ namespace Penumbra.UI
ImGui.Text( "(not set)" );
}
ImGui.TableNextColumn();
ImGui.Text( identifier.Identify( actor.Value.Mainhand.Set, actor.Value.Mainhand.Type, actor.Value.Mainhand.Variant, EquipSlot.MainHand )?.Name.ToString() ?? "Unknown" );
ImGui.Text( identifier.Identify( actor.Value.MainHand.Set, actor.Value.MainHand.Type, actor.Value.MainHand.Variant, EquipSlot.MainHand )?.Name.ToString() ?? "Unknown" );
ImGui.TableNextColumn();
ImGui.Text( identifier.Identify( actor.Value.Head.Set, actor.Value.Head.Variant, 0, EquipSlot.Head )?.Name.ToString() ?? "Unknown" );
ImGui.TableNextColumn();
@ -82,13 +82,13 @@ namespace Penumbra.UI
ImGui.TableNextRow();
ImGui.TableNextColumn();
ImGui.TableNextColumn();
ImGui.Text( $"{actor.Value.Offhand}" );
ImGui.Text( $"{actor.Value.OffHand}" );
ImGui.TableNextColumn();
ImGui.Text( $"{actor.Value.Ear}" );
ImGui.Text( $"{actor.Value.Ears}" );
ImGui.TableNextColumn();
ImGui.Text( $"{actor.Value.Neck}" );
ImGui.TableNextColumn();
ImGui.Text( $"{actor.Value.Wrist}" );
ImGui.Text( $"{actor.Value.Wrists}" );
ImGui.TableNextColumn();
ImGui.Text( $"{actor.Value.LFinger}" );
ImGui.TableNextColumn();
@ -97,17 +97,17 @@ namespace Penumbra.UI
ImGui.TableNextRow();
ImGui.TableNextColumn();
ImGui.TableNextColumn();
ImGui.Text( identifier.Identify( actor.Value.Offhand.Set, actor.Value.Offhand.Type, actor.Value.Offhand.Variant, EquipSlot.Offhand )?.Name.ToString() ?? "Unknown" );
ImGui.Text( identifier.Identify( actor.Value.OffHand.Set, actor.Value.OffHand.Type, actor.Value.OffHand.Variant, EquipSlot.OffHand )?.Name.ToString() ?? "Unknown" );
ImGui.TableNextColumn();
ImGui.Text( identifier.Identify( actor.Value.Ear.Set, actor.Value.Ear.Variant, 0, EquipSlot.Ears )?.Name.ToString() ?? "Unknown" );
ImGui.Text( identifier.Identify( actor.Value.Ears.Set, actor.Value.Ears.Variant, 0, EquipSlot.Ears )?.Name.ToString() ?? "Unknown" );
ImGui.TableNextColumn();
ImGui.Text( identifier.Identify( actor.Value.Neck.Set, actor.Value.Neck.Variant, 0, EquipSlot.Neck )?.Name.ToString() ?? "Unknown" );
ImGui.TableNextColumn();
ImGui.Text( identifier.Identify( actor.Value.Wrist.Set, actor.Value.Wrist.Variant, 0, EquipSlot.Wrists )?.Name.ToString() ?? "Unknown" );
ImGui.Text( identifier.Identify( actor.Value.Wrists.Set, actor.Value.Wrists.Variant, 0, EquipSlot.Wrists )?.Name.ToString() ?? "Unknown" );
ImGui.TableNextColumn();
ImGui.Text( identifier.Identify( actor.Value.LFinger.Set, actor.Value.LFinger.Variant, 0, EquipSlot.RingL )?.Name.ToString() ?? "Unknown" );
ImGui.Text( identifier.Identify( actor.Value.LFinger.Set, actor.Value.LFinger.Variant, 0, EquipSlot.LFinger )?.Name.ToString() ?? "Unknown" );
ImGui.TableNextColumn();
ImGui.Text( identifier.Identify( actor.Value.RFinger.Set, actor.Value.RFinger.Variant, 0, EquipSlot.RingL )?.Name.ToString() ?? "Unknown" );
ImGui.Text( identifier.Identify( actor.Value.RFinger.Set, actor.Value.RFinger.Variant, 0, EquipSlot.LFinger )?.Name.ToString() ?? "Unknown" );
// @formatter:on
}

View file

@ -51,8 +51,8 @@ namespace Penumbra.UI
( "Ears", EquipSlot.Ears ),
( "Neck", EquipSlot.Neck ),
( "Wrist", EquipSlot.Wrists ),
( "Left Finger", EquipSlot.RingL ),
( "Right Finger", EquipSlot.RingR ),
( "Left Finger", EquipSlot.LFinger ),
( "Right Finger", EquipSlot.RFinger ),
};
private static readonly (string, Race)[] Races =
@ -308,8 +308,8 @@ namespace Penumbra.UI
EquipSlot.Neck => ( entry.HasFlag( EqdpEntry.Neck1 ), entry.HasFlag( EqdpEntry.Neck2 ) ),
EquipSlot.Ears => ( entry.HasFlag( EqdpEntry.Ears1 ), entry.HasFlag( EqdpEntry.Ears2 ) ),
EquipSlot.Wrists => ( entry.HasFlag( EqdpEntry.Wrists1 ), entry.HasFlag( EqdpEntry.Wrists2 ) ),
EquipSlot.RingR => ( entry.HasFlag( EqdpEntry.RingR1 ), entry.HasFlag( EqdpEntry.RingR2 ) ),
EquipSlot.RingL => ( entry.HasFlag( EqdpEntry.RingL1 ), entry.HasFlag( EqdpEntry.RingL2 ) ),
EquipSlot.RFinger => ( entry.HasFlag( EqdpEntry.RingR1 ), entry.HasFlag( EqdpEntry.RingR2 ) ),
EquipSlot.LFinger => ( entry.HasFlag( EqdpEntry.RingL1 ), entry.HasFlag( EqdpEntry.RingL2 ) ),
_ => ( false, false ),
};
}
@ -350,11 +350,11 @@ namespace Penumbra.UI
value = bit1 ? value | EqdpEntry.Wrists1 : value & ~EqdpEntry.Wrists1;
value = bit2 ? value | EqdpEntry.Wrists2 : value & ~EqdpEntry.Wrists2;
return value;
case EquipSlot.RingR:
case EquipSlot.RFinger:
value = bit1 ? value | EqdpEntry.RingR1 : value & ~EqdpEntry.RingR1;
value = bit2 ? value | EqdpEntry.RingR2 : value & ~EqdpEntry.RingR2;
return value;
case EquipSlot.RingL:
case EquipSlot.LFinger:
value = bit1 ? value | EqdpEntry.RingL1 : value & ~EqdpEntry.RingL1;
value = bit2 ? value | EqdpEntry.RingL2 : value & ~EqdpEntry.RingL2;
return value;