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