mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-20 14:57:50 +01:00
Use strongly typed ids in most places.
This commit is contained in:
parent
dccd347432
commit
18b6b87e6b
26 changed files with 192 additions and 193 deletions
|
|
@ -40,21 +40,21 @@ public sealed unsafe class ExpandedEqdpFile : MetaBaseFile
|
|||
public int Count
|
||||
=> (Length - DataOffset) / EqdpEntrySize;
|
||||
|
||||
public EqdpEntry this[int idx]
|
||||
public EqdpEntry this[SetId id]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (idx >= Count || idx < 0)
|
||||
if (id.Id >= Count)
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
return (EqdpEntry)(*(ushort*)(Data + DataOffset + EqdpEntrySize * idx));
|
||||
return (EqdpEntry)(*(ushort*)(Data + DataOffset + EqdpEntrySize * id.Id));
|
||||
}
|
||||
set
|
||||
{
|
||||
if (idx >= Count || idx < 0)
|
||||
if (id.Id >= Count)
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
*(ushort*)(Data + DataOffset + EqdpEntrySize * idx) = (ushort)value;
|
||||
*(ushort*)(Data + DataOffset + EqdpEntrySize * id.Id) = (ushort)value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ public sealed unsafe class ExpandedEqdpFile : MetaBaseFile
|
|||
MemoryUtility.MemSet(myDataPtr, 0, Length - (int)((byte*)myDataPtr - Data));
|
||||
}
|
||||
|
||||
public void Reset(IEnumerable<int> entries)
|
||||
public void Reset(IEnumerable<SetId> entries)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
this[entry] = GetDefault(entry);
|
||||
|
|
@ -103,18 +103,18 @@ public sealed unsafe class ExpandedEqdpFile : MetaBaseFile
|
|||
Reset();
|
||||
}
|
||||
|
||||
public EqdpEntry GetDefault(int setIdx)
|
||||
=> GetDefault(Manager, Index, setIdx);
|
||||
public EqdpEntry GetDefault(SetId setId)
|
||||
=> GetDefault(Manager, Index, setId);
|
||||
|
||||
public static EqdpEntry GetDefault(MetaFileManager manager, CharacterUtility.InternalIndex idx, int setIdx)
|
||||
=> GetDefault((byte*)manager.CharacterUtility.DefaultResource(idx).Address, setIdx);
|
||||
public static EqdpEntry GetDefault(MetaFileManager manager, CharacterUtility.InternalIndex idx, SetId setId)
|
||||
=> GetDefault((byte*)manager.CharacterUtility.DefaultResource(idx).Address, setId);
|
||||
|
||||
public static EqdpEntry GetDefault(byte* data, int setIdx)
|
||||
public static EqdpEntry GetDefault(byte* data, SetId setId)
|
||||
{
|
||||
var blockSize = *(ushort*)(data + IdentifierSize);
|
||||
var totalBlockCount = *(ushort*)(data + IdentifierSize + 2);
|
||||
|
||||
var blockIdx = setIdx / blockSize;
|
||||
var blockIdx = setId.Id / blockSize;
|
||||
if (blockIdx >= totalBlockCount)
|
||||
return 0;
|
||||
|
||||
|
|
@ -123,9 +123,9 @@ public sealed unsafe class ExpandedEqdpFile : MetaBaseFile
|
|||
return 0;
|
||||
|
||||
var blockData = (ushort*)(data + IdentifierSize + PreambleSize + totalBlockCount * 2 + block * 2);
|
||||
return (EqdpEntry)(*(blockData + setIdx % blockSize));
|
||||
return (EqdpEntry)(*(blockData + setId.Id % blockSize));
|
||||
}
|
||||
|
||||
public static EqdpEntry GetDefault(MetaFileManager manager, GenderRace raceCode, bool accessory, int setIdx)
|
||||
=> GetDefault(manager, CharacterUtility.ReverseIndices[(int)CharacterUtilityData.EqdpIdx(raceCode, accessory)], setIdx);
|
||||
public static EqdpEntry GetDefault(MetaFileManager manager, GenderRace raceCode, bool accessory, SetId setId)
|
||||
=> GetDefault(manager, CharacterUtility.ReverseIndices[(int)CharacterUtilityData.EqdpIdx(raceCode, accessory)], setId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,26 +28,26 @@ public unsafe class ExpandedEqpGmpBase : MetaBaseFile
|
|||
public ulong ControlBlock
|
||||
=> *(ulong*)Data;
|
||||
|
||||
protected ulong GetInternal(int idx)
|
||||
protected ulong GetInternal(SetId idx)
|
||||
{
|
||||
return idx switch
|
||||
return idx.Id switch
|
||||
{
|
||||
>= Count => throw new IndexOutOfRangeException(),
|
||||
<= 1 => *((ulong*)Data + 1),
|
||||
_ => *((ulong*)Data + idx),
|
||||
_ => *((ulong*)Data + idx.Id),
|
||||
};
|
||||
}
|
||||
|
||||
protected void SetInternal(int idx, ulong value)
|
||||
protected void SetInternal(SetId idx, ulong value)
|
||||
{
|
||||
idx = idx switch
|
||||
idx = idx.Id switch
|
||||
{
|
||||
>= Count => throw new IndexOutOfRangeException(),
|
||||
<= 0 => 1,
|
||||
_ => idx,
|
||||
};
|
||||
|
||||
*((ulong*)Data + idx) = value;
|
||||
*((ulong*)Data + idx.Id) = value;
|
||||
}
|
||||
|
||||
protected virtual void SetEmptyBlock(int idx)
|
||||
|
|
@ -85,13 +85,13 @@ public unsafe class ExpandedEqpGmpBase : MetaBaseFile
|
|||
Reset();
|
||||
}
|
||||
|
||||
protected static ulong GetDefaultInternal(MetaFileManager manager, CharacterUtility.InternalIndex fileIndex, int setIdx, ulong def)
|
||||
protected static ulong GetDefaultInternal(MetaFileManager manager, CharacterUtility.InternalIndex fileIndex, SetId setId, ulong def)
|
||||
{
|
||||
var data = (byte*)manager.CharacterUtility.DefaultResource(fileIndex).Address;
|
||||
if (setIdx == 0)
|
||||
setIdx = 1;
|
||||
if (setId == 0)
|
||||
setId = 1;
|
||||
|
||||
var blockIdx = setIdx / BlockSize;
|
||||
var blockIdx = setId.Id / BlockSize;
|
||||
if (blockIdx >= NumBlocks)
|
||||
return def;
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ public unsafe class ExpandedEqpGmpBase : MetaBaseFile
|
|||
return def;
|
||||
|
||||
var count = BitOperations.PopCount(control & (blockBit - 1));
|
||||
var idx = setIdx % BlockSize;
|
||||
var idx = setId.Id % BlockSize;
|
||||
var ptr = (ulong*)data + BlockSize * count + idx;
|
||||
return *ptr;
|
||||
}
|
||||
|
|
@ -116,14 +116,14 @@ public sealed class ExpandedEqpFile : ExpandedEqpGmpBase, IEnumerable<EqpEntry>
|
|||
: base(manager, false)
|
||||
{ }
|
||||
|
||||
public EqpEntry this[int idx]
|
||||
public EqpEntry this[SetId idx]
|
||||
{
|
||||
get => (EqpEntry)GetInternal(idx);
|
||||
set => SetInternal(idx, (ulong)value);
|
||||
}
|
||||
|
||||
|
||||
public static EqpEntry GetDefault(MetaFileManager manager, int setIdx)
|
||||
public static EqpEntry GetDefault(MetaFileManager manager, SetId setIdx)
|
||||
=> (EqpEntry)GetDefaultInternal(manager, InternalIndex, setIdx, (ulong)Eqp.DefaultEntry);
|
||||
|
||||
protected override unsafe void SetEmptyBlock(int idx)
|
||||
|
|
@ -134,7 +134,7 @@ public sealed class ExpandedEqpFile : ExpandedEqpGmpBase, IEnumerable<EqpEntry>
|
|||
*ptr = (ulong)Eqp.DefaultEntry;
|
||||
}
|
||||
|
||||
public void Reset(IEnumerable<int> entries)
|
||||
public void Reset(IEnumerable<SetId> entries)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
this[entry] = GetDefault(Manager, entry);
|
||||
|
|
@ -142,7 +142,7 @@ public sealed class ExpandedEqpFile : ExpandedEqpGmpBase, IEnumerable<EqpEntry>
|
|||
|
||||
public IEnumerator<EqpEntry> GetEnumerator()
|
||||
{
|
||||
for (var idx = 1; idx < Count; ++idx)
|
||||
for (ushort idx = 1; idx < Count; ++idx)
|
||||
yield return this[idx];
|
||||
}
|
||||
|
||||
|
|
@ -159,16 +159,16 @@ public sealed class ExpandedGmpFile : ExpandedEqpGmpBase, IEnumerable<GmpEntry>
|
|||
: base(manager, true)
|
||||
{ }
|
||||
|
||||
public GmpEntry this[int idx]
|
||||
public GmpEntry this[SetId idx]
|
||||
{
|
||||
get => (GmpEntry)GetInternal(idx);
|
||||
set => SetInternal(idx, (ulong)value);
|
||||
}
|
||||
|
||||
public static GmpEntry GetDefault(MetaFileManager manager, int setIdx)
|
||||
public static GmpEntry GetDefault(MetaFileManager manager, SetId setIdx)
|
||||
=> (GmpEntry)GetDefaultInternal(manager, InternalIndex, setIdx, (ulong)GmpEntry.Default);
|
||||
|
||||
public void Reset(IEnumerable<int> entries)
|
||||
public void Reset(IEnumerable<SetId> entries)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
this[entry] = GetDefault(Manager, entry);
|
||||
|
|
@ -176,7 +176,7 @@ public sealed class ExpandedGmpFile : ExpandedEqpGmpBase, IEnumerable<GmpEntry>
|
|||
|
||||
public IEnumerator<GmpEntry> GetEnumerator()
|
||||
{
|
||||
for (var idx = 1; idx < Count; ++idx)
|
||||
for (ushort idx = 1; idx < Count; ++idx)
|
||||
yield return this[idx];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Penumbra.GameData.Enums;
|
||||
using Penumbra.GameData.Structs;
|
||||
using Penumbra.Interop.Services;
|
||||
using Penumbra.Interop.Structs;
|
||||
using Penumbra.Meta.Manipulations;
|
||||
|
|
@ -168,21 +169,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, ushort setId)
|
||||
public static ushort GetDefault(MetaFileManager manager, CharacterUtility.InternalIndex index, GenderRace genderRace, SetId setId)
|
||||
{
|
||||
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);
|
||||
var (idx, found) = FindEntry(span, genderRace, setId.Id);
|
||||
if (!found)
|
||||
return 0;
|
||||
|
||||
return *(ushort*)(data + 4 + count * EntryDescSize + idx * EntrySize);
|
||||
}
|
||||
|
||||
public static ushort GetDefault(MetaFileManager manager, MetaIndex metaIndex, GenderRace genderRace, ushort setId)
|
||||
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, EstManipulation.EstType estType, GenderRace genderRace, ushort setId)
|
||||
public static ushort GetDefault(MetaFileManager manager, EstManipulation.EstType estType, GenderRace genderRace, SetId setId)
|
||||
=> GetDefault(manager, (MetaIndex)estType, genderRace, setId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using Penumbra.GameData.Enums;
|
|||
using Penumbra.GameData.Structs;
|
||||
using Penumbra.Interop.Structs;
|
||||
using Penumbra.Meta.Manipulations;
|
||||
using Penumbra.Services;
|
||||
using Penumbra.String.Classes;
|
||||
using Penumbra.String.Functions;
|
||||
|
||||
|
|
@ -50,19 +49,19 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
private static ushort PartMask(byte* data)
|
||||
=> *(ushort*)(data + 2);
|
||||
|
||||
private static ImcEntry* VariantPtr(byte* data, int partIdx, int variantIdx)
|
||||
private static ImcEntry* VariantPtr(byte* data, int partIdx, Variant variantIdx)
|
||||
{
|
||||
var flag = 1 << partIdx;
|
||||
if ((PartMask(data) & flag) == 0 || variantIdx > CountInternal(data))
|
||||
if ((PartMask(data) & flag) == 0 || variantIdx.Id > CountInternal(data))
|
||||
return null;
|
||||
|
||||
var numParts = BitOperations.PopCount(PartMask(data));
|
||||
var ptr = (ImcEntry*)(data + PreambleSize);
|
||||
ptr += variantIdx * numParts + partIdx;
|
||||
ptr += variantIdx.Id * numParts + partIdx;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
public ImcEntry GetEntry(int partIdx, int variantIdx)
|
||||
public ImcEntry GetEntry(int partIdx, Variant variantIdx)
|
||||
{
|
||||
var ptr = VariantPtr(Data, partIdx, variantIdx);
|
||||
return ptr == null ? new ImcEntry() : *ptr;
|
||||
|
|
@ -106,12 +105,12 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
return true;
|
||||
}
|
||||
|
||||
public bool SetEntry(int partIdx, int variantIdx, ImcEntry entry)
|
||||
public bool SetEntry(int partIdx, Variant variantIdx, ImcEntry entry)
|
||||
{
|
||||
if (partIdx >= NumParts)
|
||||
return false;
|
||||
|
||||
EnsureVariantCount(variantIdx);
|
||||
EnsureVariantCount(variantIdx.Id);
|
||||
|
||||
var variantPtr = VariantPtr(Data, partIdx, variantIdx);
|
||||
if (variantPtr == null)
|
||||
|
|
@ -154,10 +153,10 @@ public unsafe class ImcFile : MetaBaseFile
|
|||
}
|
||||
}
|
||||
|
||||
public static ImcEntry GetDefault(MetaFileManager manager, Utf8GamePath path, EquipSlot slot, int variantIdx, out bool exists)
|
||||
public static ImcEntry GetDefault(MetaFileManager manager, Utf8GamePath path, EquipSlot slot, Variant variantIdx, out bool exists)
|
||||
=> GetDefault(manager, path.ToString(), slot, variantIdx, out exists);
|
||||
|
||||
public static ImcEntry GetDefault(MetaFileManager manager, string path, EquipSlot slot, int variantIdx, out bool exists)
|
||||
public static ImcEntry GetDefault(MetaFileManager manager, string path, EquipSlot slot, Variant variantIdx, out bool exists)
|
||||
{
|
||||
var file = manager.GameData.GetFile(path);
|
||||
exists = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue