Update for GameData changes.

This commit is contained in:
Ottermandias 2023-12-20 16:39:26 +01:00
parent 6dc5916f2b
commit 5d28904bdf
24 changed files with 160 additions and 123 deletions

View file

@ -38,7 +38,7 @@ public sealed unsafe class ExpandedEqdpFile : MetaBaseFile
public int Count
=> (Length - DataOffset) / EqdpEntrySize;
public EqdpEntry this[SetId id]
public EqdpEntry this[PrimaryId id]
{
get
{
@ -79,7 +79,7 @@ public sealed unsafe class ExpandedEqdpFile : MetaBaseFile
MemoryUtility.MemSet(myDataPtr, 0, Length - (int)((byte*)myDataPtr - Data));
}
public void Reset(IEnumerable<SetId> entries)
public void Reset(IEnumerable<PrimaryId> entries)
{
foreach (var entry in entries)
this[entry] = GetDefault(entry);
@ -101,18 +101,18 @@ public sealed unsafe class ExpandedEqdpFile : MetaBaseFile
Reset();
}
public EqdpEntry GetDefault(SetId setId)
=> GetDefault(Manager, Index, setId);
public EqdpEntry GetDefault(PrimaryId primaryId)
=> GetDefault(Manager, Index, primaryId);
public static EqdpEntry GetDefault(MetaFileManager manager, CharacterUtility.InternalIndex idx, SetId setId)
=> GetDefault((byte*)manager.CharacterUtility.DefaultResource(idx).Address, setId);
public static EqdpEntry GetDefault(MetaFileManager manager, CharacterUtility.InternalIndex idx, PrimaryId primaryId)
=> GetDefault((byte*)manager.CharacterUtility.DefaultResource(idx).Address, primaryId);
public static EqdpEntry GetDefault(byte* data, SetId setId)
public static EqdpEntry GetDefault(byte* data, PrimaryId primaryId)
{
var blockSize = *(ushort*)(data + IdentifierSize);
var totalBlockCount = *(ushort*)(data + IdentifierSize + 2);
var blockIdx = setId.Id / blockSize;
var blockIdx = primaryId.Id / blockSize;
if (blockIdx >= totalBlockCount)
return 0;
@ -121,9 +121,9 @@ public sealed unsafe class ExpandedEqdpFile : MetaBaseFile
return 0;
var blockData = (ushort*)(data + IdentifierSize + PreambleSize + totalBlockCount * 2 + block * 2);
return (EqdpEntry)(*(blockData + setId.Id % blockSize));
return (EqdpEntry)(*(blockData + primaryId.Id % blockSize));
}
public static EqdpEntry GetDefault(MetaFileManager manager, GenderRace raceCode, bool accessory, SetId setId)
=> GetDefault(manager, CharacterUtility.ReverseIndices[(int)CharacterUtilityData.EqdpIdx(raceCode, accessory)], setId);
public static EqdpEntry GetDefault(MetaFileManager manager, GenderRace raceCode, bool accessory, PrimaryId primaryId)
=> GetDefault(manager, CharacterUtility.ReverseIndices[(int)CharacterUtilityData.EqdpIdx(raceCode, accessory)], primaryId);
}

View file

@ -24,7 +24,7 @@ public unsafe class ExpandedEqpGmpBase : MetaBaseFile
public ulong ControlBlock
=> *(ulong*)Data;
protected ulong GetInternal(SetId idx)
protected ulong GetInternal(PrimaryId idx)
{
return idx.Id switch
{
@ -34,7 +34,7 @@ public unsafe class ExpandedEqpGmpBase : MetaBaseFile
};
}
protected void SetInternal(SetId idx, ulong value)
protected void SetInternal(PrimaryId idx, ulong value)
{
idx = idx.Id switch
{
@ -81,13 +81,13 @@ public unsafe class ExpandedEqpGmpBase : MetaBaseFile
Reset();
}
protected static ulong GetDefaultInternal(MetaFileManager manager, CharacterUtility.InternalIndex fileIndex, SetId setId, ulong def)
protected static ulong GetDefaultInternal(MetaFileManager manager, CharacterUtility.InternalIndex fileIndex, PrimaryId primaryId, ulong def)
{
var data = (byte*)manager.CharacterUtility.DefaultResource(fileIndex).Address;
if (setId == 0)
setId = 1;
if (primaryId == 0)
primaryId = 1;
var blockIdx = setId.Id / BlockSize;
var blockIdx = primaryId.Id / BlockSize;
if (blockIdx >= NumBlocks)
return def;
@ -97,7 +97,7 @@ public unsafe class ExpandedEqpGmpBase : MetaBaseFile
return def;
var count = BitOperations.PopCount(control & (blockBit - 1));
var idx = setId.Id % BlockSize;
var idx = primaryId.Id % BlockSize;
var ptr = (ulong*)data + BlockSize * count + idx;
return *ptr;
}
@ -112,15 +112,15 @@ public sealed class ExpandedEqpFile : ExpandedEqpGmpBase, IEnumerable<EqpEntry>
: base(manager, false)
{ }
public EqpEntry this[SetId idx]
public EqpEntry this[PrimaryId idx]
{
get => (EqpEntry)GetInternal(idx);
set => SetInternal(idx, (ulong)value);
}
public static EqpEntry GetDefault(MetaFileManager manager, SetId setIdx)
=> (EqpEntry)GetDefaultInternal(manager, InternalIndex, setIdx, (ulong)Eqp.DefaultEntry);
public static EqpEntry GetDefault(MetaFileManager manager, PrimaryId primaryIdx)
=> (EqpEntry)GetDefaultInternal(manager, InternalIndex, primaryIdx, (ulong)Eqp.DefaultEntry);
protected override unsafe void SetEmptyBlock(int idx)
{
@ -130,7 +130,7 @@ public sealed class ExpandedEqpFile : ExpandedEqpGmpBase, IEnumerable<EqpEntry>
*ptr = (ulong)Eqp.DefaultEntry;
}
public void Reset(IEnumerable<SetId> entries)
public void Reset(IEnumerable<PrimaryId> entries)
{
foreach (var entry in entries)
this[entry] = GetDefault(Manager, entry);
@ -155,16 +155,16 @@ public sealed class ExpandedGmpFile : ExpandedEqpGmpBase, IEnumerable<GmpEntry>
: base(manager, true)
{ }
public GmpEntry this[SetId idx]
public GmpEntry this[PrimaryId idx]
{
get => (GmpEntry)GetInternal(idx);
set => SetInternal(idx, (ulong)value);
}
public static GmpEntry GetDefault(MetaFileManager manager, SetId setIdx)
=> (GmpEntry)GetDefaultInternal(manager, InternalIndex, setIdx, (ulong)GmpEntry.Default);
public static GmpEntry GetDefault(MetaFileManager manager, PrimaryId primaryIdx)
=> (GmpEntry)GetDefaultInternal(manager, InternalIndex, primaryIdx, (ulong)GmpEntry.Default);
public void Reset(IEnumerable<SetId> entries)
public void Reset(IEnumerable<PrimaryId> entries)
{
foreach (var entry in entries)
this[entry] = GetDefault(Manager, entry);

View file

@ -167,21 +167,21 @@ public sealed unsafe class EstFile : MetaBaseFile
public ushort GetDefault(GenderRace genderRace, ushort setId)
=> GetDefault(Manager, Index, genderRace, setId);
public static ushort GetDefault(MetaFileManager manager, CharacterUtility.InternalIndex index, GenderRace genderRace, SetId setId)
public static ushort GetDefault(MetaFileManager manager, CharacterUtility.InternalIndex index, GenderRace genderRace, PrimaryId primaryId)
{
var data = (byte*)manager.CharacterUtility.DefaultResource(index).Address;
var count = *(int*)data;
var span = new ReadOnlySpan<Info>(data + 4, count);
var (idx, found) = FindEntry(span, genderRace, setId.Id);
var (idx, found) = FindEntry(span, genderRace, primaryId.Id);
if (!found)
return 0;
return *(ushort*)(data + 4 + count * EntryDescSize + idx * EntrySize);
}
public static ushort GetDefault(MetaFileManager manager, MetaIndex metaIndex, GenderRace genderRace, SetId setId)
=> GetDefault(manager, CharacterUtility.ReverseIndices[(int)metaIndex], genderRace, setId);
public static ushort GetDefault(MetaFileManager manager, MetaIndex metaIndex, GenderRace genderRace, PrimaryId primaryId)
=> GetDefault(manager, CharacterUtility.ReverseIndices[(int)metaIndex], genderRace, primaryId);
public static ushort GetDefault(MetaFileManager manager, EstManipulation.EstType estType, GenderRace genderRace, SetId setId)
=> GetDefault(manager, (MetaIndex)estType, genderRace, setId);
public static ushort GetDefault(MetaFileManager manager, EstManipulation.EstType estType, GenderRace genderRace, PrimaryId primaryId)
=> GetDefault(manager, (MetaIndex)estType, genderRace, primaryId);
}

View file

@ -18,13 +18,13 @@ public readonly struct EqdpManipulation : IMetaManipulation<EqdpManipulation>
[JsonConverter(typeof(StringEnumConverter))]
public ModelRace Race { get; private init; }
public SetId SetId { get; private init; }
public PrimaryId SetId { get; private init; }
[JsonConverter(typeof(StringEnumConverter))]
public EquipSlot Slot { get; private init; }
[JsonConstructor]
public EqdpManipulation(EqdpEntry entry, EquipSlot slot, Gender gender, ModelRace race, SetId setId)
public EqdpManipulation(EqdpEntry entry, EquipSlot slot, Gender gender, ModelRace race, PrimaryId setId)
{
Gender = gender;
Race = race;

View file

@ -15,13 +15,13 @@ public readonly struct EqpManipulation : IMetaManipulation<EqpManipulation>
[JsonConverter(typeof(ForceNumericFlagEnumConverter))]
public EqpEntry Entry { get; private init; }
public SetId SetId { get; private init; }
public PrimaryId SetId { get; private init; }
[JsonConverter(typeof(StringEnumConverter))]
public EquipSlot Slot { get; private init; }
[JsonConstructor]
public EqpManipulation(EqpEntry entry, EquipSlot slot, SetId setId)
public EqpManipulation(EqpEntry entry, EquipSlot slot, PrimaryId setId)
{
Slot = slot;
SetId = setId;

View file

@ -36,13 +36,14 @@ public readonly struct EstManipulation : IMetaManipulation<EstManipulation>
[JsonConverter(typeof(StringEnumConverter))]
public ModelRace Race { get; private init; }
public SetId SetId { get; private init; }
public PrimaryId SetId { get; private init; }
[JsonConverter(typeof(StringEnumConverter))]
public EstType Slot { get; private init; }
[JsonConstructor]
public EstManipulation(Gender gender, ModelRace race, EstType slot, SetId setId, ushort entry)
public EstManipulation(Gender gender, ModelRace race, EstType slot, PrimaryId setId, ushort entry)
{
Entry = entry;
Gender = gender;

View file

@ -8,11 +8,11 @@ namespace Penumbra.Meta.Manipulations;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public readonly struct GmpManipulation : IMetaManipulation<GmpManipulation>
{
public GmpEntry Entry { get; private init; }
public SetId SetId { get; private init; }
public GmpEntry Entry { get; private init; }
public PrimaryId SetId { get; private init; }
[JsonConstructor]
public GmpManipulation(GmpEntry entry, SetId setId)
public GmpManipulation(GmpEntry entry, PrimaryId setId)
{
Entry = entry;
SetId = setId;

View file

@ -12,10 +12,10 @@ namespace Penumbra.Meta.Manipulations;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public readonly struct ImcManipulation : IMetaManipulation<ImcManipulation>
{
public ImcEntry Entry { get; private init; }
public SetId PrimaryId { get; private init; }
public SetId SecondaryId { get; private init; }
public Variant Variant { get; private init; }
public ImcEntry Entry { get; private init; }
public PrimaryId PrimaryId { get; private init; }
public PrimaryId SecondaryId { get; private init; }
public Variant Variant { get; private init; }
[JsonConverter(typeof(StringEnumConverter))]
public ObjectType ObjectType { get; private init; }
@ -26,7 +26,7 @@ public readonly struct ImcManipulation : IMetaManipulation<ImcManipulation>
[JsonConverter(typeof(StringEnumConverter))]
public BodySlot BodySlot { get; private init; }
public ImcManipulation(EquipSlot equipSlot, ushort variant, SetId primaryId, ImcEntry entry)
public ImcManipulation(EquipSlot equipSlot, ushort variant, PrimaryId primaryId, ImcEntry entry)
{
Entry = entry;
PrimaryId = primaryId;
@ -42,7 +42,7 @@ public readonly struct ImcManipulation : IMetaManipulation<ImcManipulation>
// so we change the unused value to something nonsensical in that case, just so they do not compare equal,
// and clamp the variant to 255.
[JsonConstructor]
internal ImcManipulation(ObjectType objectType, BodySlot bodySlot, SetId primaryId, SetId secondaryId, ushort variant,
internal ImcManipulation(ObjectType objectType, BodySlot bodySlot, PrimaryId primaryId, PrimaryId secondaryId, ushort variant,
EquipSlot equipSlot, ImcEntry entry)
{
Entry = entry;

View file

@ -269,5 +269,23 @@ public readonly struct MetaManipulation : IEquatable<MetaManipulation>, ICompara
Type.Gmp => $"{Gmp.Entry.Value}",
Type.Rsp => $"{Rsp.Entry}",
_ => string.Empty,
};
};
public static bool operator ==(MetaManipulation left, MetaManipulation right)
=> left.Equals(right);
public static bool operator !=(MetaManipulation left, MetaManipulation right)
=> !(left == right);
public static bool operator <(MetaManipulation left, MetaManipulation right)
=> left.CompareTo(right) < 0;
public static bool operator <=(MetaManipulation left, MetaManipulation right)
=> left.CompareTo(right) <= 0;
public static bool operator >(MetaManipulation left, MetaManipulation right)
=> left.CompareTo(right) > 0;
public static bool operator >=(MetaManipulation left, MetaManipulation right)
=> left.CompareTo(right) >= 0;
}