Move Entries to GameData.

This commit is contained in:
Ottermandias 2021-07-25 02:36:21 +02:00
parent 4cfd7f56c0
commit b93c5376de
12 changed files with 71 additions and 60 deletions

View file

@ -0,0 +1,107 @@
using System;
using System.ComponentModel;
using Penumbra.GameData.Enums;
namespace Penumbra.GameData.Structs
{
[Flags]
public enum EqdpEntry : ushort
{
Invalid = 0,
Head1 = 0b0000000001,
Head2 = 0b0000000010,
HeadMask = 0b0000000011,
Body1 = 0b0000000100,
Body2 = 0b0000001000,
BodyMask = 0b0000001100,
Hands1 = 0b0000010000,
Hands2 = 0b0000100000,
HandsMask = 0b0000110000,
Legs1 = 0b0001000000,
Legs2 = 0b0010000000,
LegsMask = 0b0011000000,
Feet1 = 0b0100000000,
Feet2 = 0b1000000000,
FeetMask = 0b1100000000,
Ears1 = 0b0000000001,
Ears2 = 0b0000000010,
EarsMask = 0b0000000011,
Neck1 = 0b0000000100,
Neck2 = 0b0000001000,
NeckMask = 0b0000001100,
Wrists1 = 0b0000010000,
Wrists2 = 0b0000100000,
WristsMask = 0b0000110000,
RingR1 = 0b0001000000,
RingR2 = 0b0010000000,
RingRMask = 0b0011000000,
RingL1 = 0b0100000000,
RingL2 = 0b1000000000,
RingLMask = 0b1100000000,
}
public static class Eqdp
{
public static int Offset( EquipSlot slot )
{
return slot switch
{
EquipSlot.Head => 0,
EquipSlot.Body => 2,
EquipSlot.Hands => 4,
EquipSlot.Legs => 6,
EquipSlot.Feet => 8,
EquipSlot.Ears => 0,
EquipSlot.Neck => 2,
EquipSlot.Wrists => 4,
EquipSlot.RingR => 6,
EquipSlot.RingL => 8,
_ => throw new InvalidEnumArgumentException(),
};
}
public static EqdpEntry FromSlotAndBits( EquipSlot slot, bool bit1, bool bit2 )
{
EqdpEntry ret = 0;
var offset = Offset( slot );
if( bit1 )
{
ret |= ( EqdpEntry )( 1 << offset );
}
if( bit2 )
{
ret |= ( EqdpEntry )( 1 << ( offset + 1 ) );
}
return ret;
}
public static EqdpEntry Mask( EquipSlot slot )
{
return slot switch
{
EquipSlot.Head => EqdpEntry.HeadMask,
EquipSlot.Body => EqdpEntry.BodyMask,
EquipSlot.Hands => EqdpEntry.HandsMask,
EquipSlot.Legs => EqdpEntry.LegsMask,
EquipSlot.Feet => EqdpEntry.FeetMask,
EquipSlot.Ears => EqdpEntry.EarsMask,
EquipSlot.Neck => EqdpEntry.NeckMask,
EquipSlot.Wrists => EqdpEntry.WristsMask,
EquipSlot.RingR => EqdpEntry.RingRMask,
EquipSlot.RingL => EqdpEntry.RingLMask,
_ => 0,
};
}
}
}

View file

@ -0,0 +1,130 @@
using System;
using System.ComponentModel;
using Penumbra.GameData.Enums;
namespace Penumbra.GameData.Structs
{
[Flags]
public enum EqpEntry : ulong
{
BodyEnabled = 0x00_01ul,
BodyHideWaist = 0x00_02ul,
_2 = 0x00_04ul,
BodyHideGlovesS = 0x00_08ul,
_4 = 0x00_10ul,
BodyHideGlovesM = 0x00_20ul,
BodyHideGlovesL = 0x00_40ul,
BodyHideGorget = 0x00_80ul,
BodyShowLeg = 0x01_00ul,
BodyShowHand = 0x02_00ul,
BodyShowHead = 0x04_00ul,
BodyShowNecklace = 0x08_00ul,
BodyShowBracelet = 0x10_00ul,
BodyShowTail = 0x20_00ul,
_14 = 0x40_00ul,
_15 = 0x80_00ul,
BodyMask = 0xFF_FFul,
LegsEnabled = 0x01ul << 16,
LegsHideKneePads = 0x02ul << 16,
LegsHideBootsS = 0x04ul << 16,
LegsHideBootsM = 0x08ul << 16,
_20 = 0x10ul << 16,
LegsShowFoot = 0x20ul << 16,
LegsShowTail = 0x40ul << 16,
_23 = 0x80ul << 16,
LegsMask = 0xFFul << 16,
HandsEnabled = 0x01ul << 24,
HandsHideElbow = 0x02ul << 24,
HandsHideForearm = 0x04ul << 24,
_27 = 0x08ul << 24,
HandShowBracelet = 0x10ul << 24,
HandShowRingL = 0x20ul << 24,
HandShowRingR = 0x40ul << 24,
_31 = 0x80ul << 24,
HandsMask = 0xFFul << 24,
FeetEnabled = 0x01ul << 32,
FeetHideKnee = 0x02ul << 32,
FeetHideCalf = 0x04ul << 32,
FeetHideAnkle = 0x08ul << 32,
_36 = 0x10ul << 32,
_37 = 0x20ul << 32,
_38 = 0x40ul << 32,
_39 = 0x80ul << 32,
FeetMask = 0xFFul << 32,
HeadEnabled = 0x00_00_01ul << 40,
HeadHideScalp = 0x00_00_02ul << 40,
HeadHideHair = 0x00_00_04ul << 40,
HeadShowHairOverride = 0x00_00_08ul << 40,
HeadHideNeck = 0x00_00_10ul << 40,
HeadShowNecklace = 0x00_00_20ul << 40,
_46 = 0x00_00_40ul << 40,
HeadShowEarrings = 0x00_00_80ul << 40,
HeadShowEarringsHuman = 0x00_01_00ul << 40,
HeadShowEarringsAura = 0x00_02_00ul << 40,
HeadShowEarHuman = 0x00_04_00ul << 40,
HeadShowEarMiqote = 0x00_08_00ul << 40,
HeadShowEarAuRa = 0x00_10_00ul << 40,
HeadShowEarViera = 0x00_20_00ul << 40,
_54 = 0x00_40_00ul << 40,
_55 = 0x00_80_00ul << 40,
HeadShowHrothgarHat = 0x01_00_00ul << 40,
HeadShowVieraHat = 0x02_00_00ul << 40,
_58 = 0x04_00_00ul << 40,
_59 = 0x08_00_00ul << 40,
_60 = 0x10_00_00ul << 40,
_61 = 0x20_00_00ul << 40,
_62 = 0x40_00_00ul << 40,
_63 = 0x80_00_00ul << 40,
HeadMask = 0xFF_FF_FFul << 40,
}
public static class Eqp
{
public static (int, int) BytesAndOffset( EquipSlot slot )
{
return slot switch
{
EquipSlot.Body => ( 2, 0 ),
EquipSlot.Legs => ( 1, 2 ),
EquipSlot.Hands => ( 1, 3 ),
EquipSlot.Feet => ( 1, 4 ),
EquipSlot.Head => ( 3, 5 ),
_ => throw new InvalidEnumArgumentException(),
};
}
public static EqpEntry FromSlotAndBytes( EquipSlot slot, byte[] value )
{
EqpEntry ret = 0;
var (bytes, offset) = BytesAndOffset( slot );
if( bytes != value.Length )
{
throw new ArgumentException();
}
for( var i = 0; i < bytes; ++i )
{
ret |= ( EqpEntry )( ( ulong )value[ i ] << ( ( offset + i ) * 8 ) );
}
return ret;
}
public static EqpEntry Mask( EquipSlot slot )
{
return slot switch
{
EquipSlot.Body => EqpEntry.BodyMask,
EquipSlot.Head => EqpEntry.HeadMask,
EquipSlot.Legs => EqpEntry.LegsMask,
EquipSlot.Feet => EqpEntry.FeetMask,
EquipSlot.Hands => EqpEntry.HandsMask,
_ => 0,
};
}
}
}

View file

@ -0,0 +1,92 @@
using System.IO;
namespace Penumbra.GameData.Structs
{
public struct GmpEntry
{
public bool Enabled
{
get => ( Value & 1 ) == 1;
set
{
if( value )
{
Value |= 1ul;
}
else
{
Value &= ~1ul;
}
}
}
public bool Animated
{
get => ( Value & 2 ) == 2;
set
{
if( value )
{
Value |= 2ul;
}
else
{
Value &= ~2ul;
}
}
}
public ushort RotationA
{
get => ( ushort )( ( Value >> 2 ) & 0x3FF );
set => Value = ( Value & ~0xFFCul ) | ( ( value & 0x3FFul ) << 2 );
}
public ushort RotationB
{
get => ( ushort )( ( Value >> 12 ) & 0x3FF );
set => Value = ( Value & ~0x3FF000ul ) | ( ( value & 0x3FFul ) << 12 );
}
public ushort RotationC
{
get => ( ushort )( ( Value >> 22 ) & 0x3FF );
set => Value = ( Value & ~0xFFC00000ul ) | ( ( value & 0x3FFul ) << 22 );
}
public byte UnknownA
{
get => ( byte )( ( Value >> 32 ) & 0x0F );
set => Value = ( Value & ~0x0F00000000ul ) | ( ( value & 0x0Ful ) << 32 );
}
public byte UnknownB
{
get => ( byte )( ( Value >> 36 ) & 0x0F );
set => Value = ( Value & ~0xF000000000ul ) | ( ( value & 0x0Ful ) << 36 );
}
public byte UnknownTotal
{
get => ( byte )( ( Value >> 32 ) & 0xFF );
set => Value = ( Value & ~0xFF00000000ul ) | ( ( value & 0xFFul ) << 32 );
}
public ulong Value { get; set; }
public static GmpEntry FromTexToolsMeta( byte[] data )
{
GmpEntry ret = new();
using var reader = new BinaryReader( new MemoryStream( data ) );
ret.Value = reader.ReadUInt32();
ret.UnknownTotal = data[ 4 ];
return ret;
}
public static implicit operator ulong( GmpEntry entry )
=> entry.Value;
public static explicit operator GmpEntry( ulong entry )
=> new() { Value = entry };
}
}

View file

@ -0,0 +1,58 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using Penumbra.GameData.Enums;
namespace Penumbra.GameData.Structs
{
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
public readonly struct RspEntry
{
public const int ByteSize = ( int )RspAttribute.NumAttributes * 4;
private readonly float[] Attributes;
public RspEntry( RspEntry copy )
=> Attributes = ( float[] )copy.Attributes.Clone();
public RspEntry( byte[] bytes, int offset )
{
if( offset < 0 || offset + ByteSize > bytes.Length )
{
throw new ArgumentOutOfRangeException();
}
Attributes = new float[( int )RspAttribute.NumAttributes];
using MemoryStream s = new( bytes ) { Position = offset };
using BinaryReader br = new( s );
for( var i = 0; i < ( int )RspAttribute.NumAttributes; ++i )
{
Attributes[ i ] = br.ReadSingle();
}
}
private static int ToIndex( RspAttribute attribute )
=> attribute < RspAttribute.NumAttributes && attribute >= 0
? ( int )attribute
: throw new InvalidEnumArgumentException();
public float this[ RspAttribute attribute ]
{
get => Attributes[ ToIndex( attribute ) ];
set => Attributes[ ToIndex( attribute ) ] = value;
}
public byte[] ToBytes()
{
using var s = new MemoryStream( ByteSize );
using var bw = new BinaryWriter( s );
foreach( var attribute in Attributes )
{
bw.Write( attribute );
}
return s.ToArray();
}
}
}