Replaced meta pointer values with ulongs

This commit is contained in:
dexy 2019-12-06 23:53:03 +11:00
parent 52f4563680
commit 43d6bf1068
8 changed files with 129 additions and 129 deletions

View File

@ -600,15 +600,15 @@ namespace CodeWalker.GameFiles
[TC(typeof(EXP))] public struct Array_StructurePointer //16 bytes - pointer for a structure pointer array
{
public uint Pointer { get; set; }
public uint Unk0 { get; set; }
public ulong Pointer { get; set; }
public ushort Count1 { get; set; }
public ushort Count2 { get; set; }
public uint Unk1 { get; set; }
public uint PointerDataId { get { return (Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return ((Pointer >> 12) & 0xFFFFF); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } }
public void SwapEnd()
{
@ -624,22 +624,21 @@ namespace CodeWalker.GameFiles
}
[TC(typeof(EXP))] public struct Array_Structure //16 bytes - pointer for a structure array
{
public uint Pointer { get; set; }
public uint Unk0 { get; set; }
public ulong Pointer { get; set; }
public ushort Count1 { get; set; }
public ushort Count2 { get; set; }
public uint Unk1 { get; set; }
public uint PointerDataId { get { return (Pointer & 0xFFF); } set { Pointer = (Pointer & 0xFFFFF000) + (value & 0xFFF); } }
public uint PointerDataIndex { get { return (Pointer & 0xFFF) - 1; } set { PointerDataId = value + 1; } }
public uint PointerDataOffset { get { return ((Pointer >> 12) & 0xFFFFF); } set { Pointer = (Pointer & 0xFFF) + ((value << 12) & 0xFFFFF000); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } set { Pointer = (Pointer & 0xFFFFFFFFFFFFF000) + (value & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } set { PointerDataId = value + 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } set { Pointer = (Pointer & 0xFFFFFFFF00000FFF) + ((value << 12) & 0xFFFFF000); } }
public Array_Structure(uint ptr, int cnt)
public Array_Structure(ulong ptr, int cnt)
{
Pointer = ptr;
Unk0 = 0;
Count1 = (ushort)cnt;
Count2 = Count1;
Unk1 = 0;
@ -647,7 +646,6 @@ namespace CodeWalker.GameFiles
public Array_Structure(MetaBuilderPointer ptr)
{
Pointer = ptr.Pointer;
Unk0 = 0;
Count1 = (ushort)ptr.Length;
Count2 = Count1;
Unk1 = 0;
@ -656,7 +654,6 @@ namespace CodeWalker.GameFiles
public Array_Structure SwapEnd()
{
Pointer = MetaTypes.SwapBytes(Pointer);
Unk0 = MetaTypes.SwapBytes(Unk0);
Count1 = MetaTypes.SwapBytes(Count1);
Count2 = MetaTypes.SwapBytes(Count2);
Unk1 = MetaTypes.SwapBytes(Unk1);
@ -669,21 +666,20 @@ namespace CodeWalker.GameFiles
}
[TC(typeof(EXP))] public struct Array_uint //16 bytes - pointer for a uint array
{
public uint Pointer { get; set; }
public uint Unk0 { get; set; }
public ulong Pointer { get; set; }
public ushort Count1 { get; set; }
public ushort Count2 { get; set; }
public uint Unk1 { get; set; }
public uint PointerDataId { get { return (Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return ((Pointer >> 12) & 0xFFFFF); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } }
public Array_uint(uint ptr, int cnt)
public Array_uint(ulong ptr, int cnt)
{
Pointer = ptr;
Unk0 = 0;
Count1 = (ushort)cnt;
Count2 = Count1;
Unk1 = 0;
@ -691,7 +687,6 @@ namespace CodeWalker.GameFiles
public Array_uint(MetaBuilderPointer ptr)
{
Pointer = ptr.Pointer;
Unk0 = 0;
Count1 = (ushort)ptr.Length;
Count2 = Count1;
Unk1 = 0;
@ -700,7 +695,6 @@ namespace CodeWalker.GameFiles
public void SwapEnd()
{
Pointer = MetaTypes.SwapBytes(Pointer);
Unk0 = MetaTypes.SwapBytes(Unk0);
Count1 = MetaTypes.SwapBytes(Count1);
Count2 = MetaTypes.SwapBytes(Count2);
Unk1 = MetaTypes.SwapBytes(Unk1);
@ -712,21 +706,20 @@ namespace CodeWalker.GameFiles
}
[TC(typeof(EXP))] public struct Array_ushort //16 bytes - pointer for a ushort array
{
public uint Pointer { get; set; }
public uint Unk0 { get; set; }
public ulong Pointer { get; set; }
public ushort Count1 { get; set; }
public ushort Count2 { get; set; }
public uint Unk1 { get; set; }
public uint PointerDataId { get { return (Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return ((Pointer >> 12) & 0xFFFFF); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } }
public Array_ushort(uint ptr, int cnt)
public Array_ushort(ulong ptr, int cnt)
{
Pointer = ptr;
Unk0 = 0;
Count1 = (ushort)cnt;
Count2 = Count1;
Unk1 = 0;
@ -734,7 +727,6 @@ namespace CodeWalker.GameFiles
public Array_ushort(MetaBuilderPointer ptr)
{
Pointer = ptr.Pointer;
Unk0 = 0;
Count1 = (ushort)ptr.Length;
Count2 = Count1;
Unk1 = 0;
@ -743,7 +735,6 @@ namespace CodeWalker.GameFiles
public void SwapEnd()
{
Pointer = MetaTypes.SwapBytes(Pointer);
Unk0 = MetaTypes.SwapBytes(Unk0);
Count1 = MetaTypes.SwapBytes(Count1);
Count2 = MetaTypes.SwapBytes(Count2);
Unk1 = MetaTypes.SwapBytes(Unk1);
@ -755,20 +746,19 @@ namespace CodeWalker.GameFiles
}
[TC(typeof(EXP))] public struct Array_byte //16 bytes - pointer for a byte array
{
public uint Pointer { get; set; }
public uint Unk0 { get; set; }
public ulong Pointer { get; set; }
public ushort Count1 { get; set; }
public ushort Count2 { get; set; }
public uint Unk1 { get; set; }
public uint PointerDataId { get { return (Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return ((Pointer >> 12) & 0xFFFFF); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } }
public Array_byte(uint ptr, int cnt)
public Array_byte(ulong ptr, int cnt)
{
Pointer = ptr;
Unk0 = 0;
Count1 = (ushort)cnt;
Count2 = Count1;
Unk1 = 0;
@ -776,7 +766,6 @@ namespace CodeWalker.GameFiles
public Array_byte(MetaBuilderPointer ptr)
{
Pointer = ptr.Pointer;
Unk0 = 0;
Count1 = (ushort)ptr.Length;
Count2 = Count1;
Unk1 = 0;
@ -785,7 +774,6 @@ namespace CodeWalker.GameFiles
public void SwapEnd()
{
Pointer = MetaTypes.SwapBytes(Pointer);
Unk0 = MetaTypes.SwapBytes(Unk0);
Count1 = MetaTypes.SwapBytes(Count1);
Count2 = MetaTypes.SwapBytes(Count2);
Unk1 = MetaTypes.SwapBytes(Unk1);
@ -797,20 +785,19 @@ namespace CodeWalker.GameFiles
}
[TC(typeof(EXP))] public struct Array_float //16 bytes - pointer for a float array
{
public uint Pointer { get; set; }
public uint Unk0 { get; set; }
public ulong Pointer { get; set; }
public ushort Count1 { get; set; }
public ushort Count2 { get; set; }
public uint Unk1 { get; set; }
public uint PointerDataId { get { return (Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return ((Pointer >> 12) & 0xFFFFF); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } }
public Array_float(uint ptr, int cnt)
public Array_float(ulong ptr, int cnt)
{
Pointer = ptr;
Unk0 = 0;
Count1 = (ushort)cnt;
Count2 = Count1;
Unk1 = 0;
@ -818,7 +805,6 @@ namespace CodeWalker.GameFiles
public Array_float(MetaBuilderPointer ptr)
{
Pointer = ptr.Pointer;
Unk0 = 0;
Count1 = (ushort)ptr.Length;
Count2 = Count1;
Unk1 = 0;
@ -827,7 +813,6 @@ namespace CodeWalker.GameFiles
public void SwapEnd()
{
Pointer = MetaTypes.SwapBytes(Pointer);
Unk0 = MetaTypes.SwapBytes(Unk0);
Count1 = MetaTypes.SwapBytes(Count1);
Count2 = MetaTypes.SwapBytes(Count2);
Unk1 = MetaTypes.SwapBytes(Unk1);
@ -839,20 +824,19 @@ namespace CodeWalker.GameFiles
}
[TC(typeof(EXP))] public struct Array_Vector3 //16 bytes - pointer for a Vector3 array
{
public uint Pointer { get; set; }
public uint Unk0 { get; set; }
public ulong Pointer { get; set; }
public ushort Count1 { get; set; }
public ushort Count2 { get; set; }
public uint Unk1 { get; set; }
public uint PointerDataId { get { return (Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return ((Pointer >> 12) & 0xFFFFF); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } }
public Array_Vector3(uint ptr, int cnt)
public Array_Vector3(ulong ptr, int cnt)
{
Pointer = ptr;
Unk0 = 0;
Count1 = (ushort)cnt;
Count2 = Count1;
Unk1 = 0;
@ -860,7 +844,6 @@ namespace CodeWalker.GameFiles
public Array_Vector3(MetaBuilderPointer ptr)
{
Pointer = ptr.Pointer;
Unk0 = 0;
Count1 = (ushort)ptr.Length;
Count2 = Count1;
Unk1 = 0;
@ -869,7 +852,6 @@ namespace CodeWalker.GameFiles
public void SwapEnd()
{
Pointer = MetaTypes.SwapBytes(Pointer);
Unk0 = MetaTypes.SwapBytes(Unk0);
Count1 = MetaTypes.SwapBytes(Count1);
Count2 = MetaTypes.SwapBytes(Count2);
Unk1 = MetaTypes.SwapBytes(Unk1);
@ -881,20 +863,19 @@ namespace CodeWalker.GameFiles
}
[TC(typeof(EXP))] public struct CharPointer //16 bytes - pointer for a char array
{
public uint Pointer { get; set; }
public uint Unk0 { get; set; }
public ulong Pointer { get; set; }
public ushort Count1 { get; set; }
public ushort Count2 { get; set; }
public uint Unk1 { get; set; }
public uint PointerDataId { get { return (Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return ((Pointer >> 12) & 0xFFFFF); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } }
public CharPointer(uint ptr, int len)
public CharPointer(ulong ptr, int len)
{
Pointer = ptr;
Unk0 = 0;
Count1 = (ushort)len;
Count2 = Count1;
Unk1 = 0;
@ -902,7 +883,6 @@ namespace CodeWalker.GameFiles
public CharPointer(MetaBuilderPointer ptr)
{
Pointer = ptr.Pointer;
Unk0 = 0;
Count1 = (ushort)ptr.Length;
Count2 = Count1;
Unk1 = 0;
@ -911,7 +891,6 @@ namespace CodeWalker.GameFiles
public void SwapEnd()
{
Pointer = MetaTypes.SwapBytes(Pointer);
Unk0 = MetaTypes.SwapBytes(Unk0);
Count1 = MetaTypes.SwapBytes(Count1);
Count2 = MetaTypes.SwapBytes(Count2);
Unk1 = MetaTypes.SwapBytes(Unk1);
@ -923,29 +902,27 @@ namespace CodeWalker.GameFiles
}
[TC(typeof(EXP))] public struct DataBlockPointer //8 bytes - pointer to data block
{
public uint Ptr0 { get; set; }
public uint Ptr1 { get; set; }
public ulong Pointer { get; set; }
public uint PointerDataId { get { return (Ptr0 & 0xFFF); } }
public uint PointerDataIndex { get { return (Ptr0 & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return ((Ptr0 >> 12) & 0xFFFFF); } }
public uint Unk0 { get { return (uint)(Pointer >> 32); } }
public uint PointerDataId { get { return (uint)(Pointer & 0xFFF); } }
public uint PointerDataIndex { get { return (uint)(Pointer & 0xFFF) - 1; } }
public uint PointerDataOffset { get { return (uint)((Pointer >> 12) & 0xFFFFF); } }
public DataBlockPointer(int blockId, int offset)
{
Ptr0 = ((uint)blockId & 0xFFF) | (((uint)offset & 0xFFFFF) << 12);
Ptr1 = 0;
Pointer = ((uint)blockId & 0xFFF) | (((uint)offset & 0xFFFFF) << 12);
}
public override string ToString()
{
return "DataBlockPointer: " + Ptr0.ToString() + ", " + Ptr1.ToString();
return "DataBlockPointer: " + Pointer.ToString();
}
public void SwapEnd()
{
Ptr0 = MetaTypes.SwapBytes(Ptr0);
Ptr1 = MetaTypes.SwapBytes(Ptr1);
Pointer = MetaTypes.SwapBytes(Pointer);
}
}
@ -1061,22 +1038,20 @@ namespace CodeWalker.GameFiles
[TC(typeof(EXP))] public struct MetaPOINTER //8 bytes - pointer to data item //was: SectionUNKNOWN10
{
public uint Pointer { get; set; }
public uint ExtraOffset { get; set; }
public ulong Pointer { get; set; }
public int BlockIndex { get { return BlockID - 1; } }
public int BlockID { get { return (int)(Pointer & 0xFFF); } set { Pointer = (Pointer & 0xFFFFF000) + ((uint)value & 0xFFF); } }
public int Offset { get { return (int)((Pointer >> 12) & 0xFFFFF); } set { Pointer = (Pointer & 0xFFF) + (((uint)value << 12) & 0xFFFFF000); } }
public MetaPOINTER(int blockID, int itemOffset, uint extra)
public MetaPOINTER(int blockID, int itemOffset)
{
Pointer = (((uint)itemOffset << 12) & 0xFFFFF000) + ((uint)blockID & 0xFFF);
ExtraOffset = extra;
}
public override string ToString()
{
return BlockID.ToString() + ", " + Offset.ToString() + ", " + ExtraOffset.ToString();
return BlockID.ToString() + ", " + Offset.ToString();
}
}

View File

@ -110,13 +110,13 @@ namespace CodeWalker.GameFiles
public MetaPOINTER AddItemPtr<T>(MetaName type, T item) where T : struct //helper method for AddItem<T>
{
var ptr = AddItem(type, item);
return new MetaPOINTER(ptr.BlockID, ptr.Offset, 0);
return new MetaPOINTER(ptr.BlockID, ptr.Offset);
}
public MetaPOINTER AddItemPtr(MetaName type, byte[] data)//helper method for AddItem<T>
{
var ptr = AddItem(type, data);
return new MetaPOINTER(ptr.BlockID, ptr.Offset, 0);
return new MetaPOINTER(ptr.BlockID, ptr.Offset);
}
public Array_Structure AddItemArrayPtr<T>(MetaName type, T[] items) where T : struct //helper method for AddItemArray<T>

View File

@ -1534,7 +1534,7 @@ namespace CodeWalker.GameFiles
{
return ConvertDataArray<T>(meta, name, array.Pointer, array.Count1);
}
public static T[] ConvertDataArray<T>(Meta meta, MetaName name, uint pointer, uint count) where T : struct
public static T[] ConvertDataArray<T>(Meta meta, MetaName name, ulong pointer, uint count) where T : struct
{
if (count == 0) return null;
@ -1542,8 +1542,8 @@ namespace CodeWalker.GameFiles
int itemsize = Marshal.SizeOf(typeof(T));
int itemsleft = (int)count; //large arrays get split into chunks...
uint ptrindex = (pointer & 0xFFF) - 1;
uint ptroffset = ((pointer >> 12) & 0xFFFFF);
uint ptrindex = (uint)(pointer & 0xFFF) - 1;
uint ptroffset = (uint)((pointer >> 12) & 0xFFFFF);
var ptrblock = (ptrindex < meta.DataBlocks.Count) ? meta.DataBlocks[(int)ptrindex] : null;
if ((ptrblock == null) || (ptrblock.Data == null) || (ptrblock.StructureNameHash != name))
{ return null; } //no block or wrong block? shouldn't happen!
@ -1715,9 +1715,8 @@ namespace CodeWalker.GameFiles
}
public static byte[] GetByteArray(Meta meta, Array_byte array)
{
var pointer = array.Pointer;
uint ptrindex = (pointer & 0xFFF) - 1;
uint ptroffset = ((pointer >> 12) & 0xFFFFF);
uint ptrindex = array.PointerDataIndex;
uint ptroffset = array.PointerDataOffset;
var ptrblock = (ptrindex < meta.DataBlocks.Count) ? meta.DataBlocks[(int)ptrindex] : null;
if ((ptrblock == null) || (ptrblock.Data == null))// || (ptrblock.StructureNameHash != name))
{ return null; } //no block or wrong block? shouldn't happen!
@ -1987,9 +1986,6 @@ namespace CodeWalker.GameFiles
{
if (block == null) return -1;
var offset = ptr.Offset;
if (ptr.ExtraOffset != 0)
{ }
//offset += (int)ptr.ExtraOffset;
if ((offset < 0) || (block.Data == null) || (offset >= block.Data.Length))
{ return -1; }
return offset;
@ -2024,8 +2020,9 @@ namespace CodeWalker.GameFiles
}
public static ulong SwapBytes(ulong x)
{
// swap adjacent 32-bit blocks
x = (x >> 32) | (x << 32);
//////// [not swapping 32bit blocks! careful!]
////// swap adjacent 32-bit blocks
////x = (x >> 32) | (x << 32);
// swap adjacent 16-bit blocks
x = ((x & 0xFFFF0000FFFF0000) >> 16) | ((x & 0x0000FFFF0000FFFF) << 16);
// swap adjacent 8-bit blocks

View File

@ -965,7 +965,12 @@ namespace CodeWalker.GameFiles
arrStruc.Count1 = arrStruc.Count2 = (ushort)aCount;
var aind = indent + 1;
string arrTag = ename;
PsoStructureEntryInfo arrEntry = estruct.GetEntry((int)(entry.ReferenceKey & 0xFFFF));
var arrEntInd = (entry.ReferenceKey & 0xFFFF);
if (arrEntInd >= estruct.EntriesCount)
{
arrEntInd = (entry.ReferenceKey & 0xFFF);
}
PsoStructureEntryInfo arrEntry = estruct.GetEntry((int)arrEntInd);
if (arrEntry == null)
{
ErrorXml(sb, indent, "ARRAYINFO not found for " + ename + "!");
@ -1269,6 +1274,11 @@ namespace CodeWalker.GameFiles
var kEntry = xStruct?.FindEntry(MetaName.Key);
var iEntry = xStruct?.FindEntry(MetaName.Item);
if (xOffset1 >= xBlock.Length)
{
xOffset1 = xOffset1 >> 8; //how to tell when to do this??
}
if ((xStruct == null) && (xBlock.NameHash == 0))
{
SelfClosingTag(sb, cind, ename);
@ -1289,9 +1299,9 @@ namespace CodeWalker.GameFiles
{
ErrorXml(sb, aind, ename + ": Map Key was not a string!");
}
else if (iEntry.Type != PsoDataType.Structure)
else if ((iEntry.Type != PsoDataType.Structure) && (iEntry.Type != PsoDataType.String))
{
ErrorXml(sb, aind, ename + ": Map Item was not a structure!");
ErrorXml(sb, aind, ename + ": Map Item was not a structure or string!");
}
//else if (iEntry.Unk_5h != 3)
//{
@ -1305,13 +1315,25 @@ namespace CodeWalker.GameFiles
for (int n = 0; n < xCount; n++)
{
if (xOffset2 >= xBlock.Length)
{
ErrorXml(sb, aind, "Offset out of range! Count is " + xCount.ToString());
break; //out of range...
}
//WriteNode(sb, aind, cont, xBlockId, xOffset, XmlTagMode.Item, xStruct.IndexInfo.NameHash);
int sOffset = xOffset2 + xBlock.Offset;
var kOffset = sOffset + kEntry.DataOffset;
var iOffset = sOffset + iEntry.DataOffset;
var kStr = GetStringValue(cont.Pso, kEntry, data, kOffset);
if (iEntry.ReferenceKey != 0)//(xBlock.NameHash != (MetaName)MetaTypeName.ARRAYINFO)//257,258,259
if (iEntry.Type == PsoDataType.String)
{
var iStr = GetStringValue(cont.Pso, iEntry, data, iOffset);
OpenTag(sb, aind, "Item type=\"String\" key=\"" + kStr + "\"", false);
sb.Append(XmlEscape(iStr));
CloseTag(sb, 0, "Item");
}
else if (iEntry.ReferenceKey != 0)//(xBlock.NameHash != (MetaName)MetaTypeName.ARRAYINFO)//257,258,259
{
//embedded map values
var vOffset = xOffset2 + iEntry.DataOffset;
@ -1340,18 +1362,18 @@ namespace CodeWalker.GameFiles
}
else
{
var iOff = (int)iPtr.ItemOffset;
if (iOff >= iBlock.Length)
{
iOff = iOff >> 8; //how to tell when to do this??
}
OpenTag(sb, aind, iStr);
WriteNode(sb, aind, cont, iPtr.BlockID, (int)iPtr.ItemOffset, XmlTagMode.None);//, (MetaName)entry.ReferenceKey);
WriteNode(sb, aind, cont, iPtr.BlockID, iOff, XmlTagMode.None);//, (MetaName)entry.ReferenceKey);
CloseTag(sb, aind, "Item");
}
}
}
xOffset2 += xStruct.StructureLength;
if ((n < (xCount - 1)) && (xBlock != null) && (xOffset >= xBlock.Length))
{
ErrorXml(sb, aind, "Offset out of range! Count is " + xCount.ToString());
break; //out of range...
}
}
CloseTag(sb, xind, ename);
}

View File

@ -399,6 +399,15 @@ namespace CodeWalker.GameFiles
RootId = reader.ReadInt32();
EntriesCount = reader.ReadInt16();
Unknown_Eh = reader.ReadInt16();
if (EntriesCount <= 0) //any other way to know which version?
{
EntriesCount = reader.ReadInt16();
var unk1 = reader.ReadInt16();
var unk2 = reader.ReadInt16();
var unk3 = reader.ReadInt16();
}
Entries = new PsoDataMappingEntry[EntriesCount];
for (int i = 0; i < EntriesCount; i++)
{

View File

@ -101,13 +101,13 @@ namespace CodeWalker.GameFiles
public PsoPOINTER AddItemPtr<T>(MetaName type, T item) where T : struct //helper method for AddItem<T>
{
var ptr = AddItem(type, item);
return new PsoPOINTER(ptr.BlockID, ptr.Offset, 0);
return new PsoPOINTER(ptr.BlockID, ptr.Offset);
}
public PsoPOINTER AddItemPtr(MetaName type, byte[] data)//helper method for AddItem<T>
{
var ptr = AddItem(type, data);
return new PsoPOINTER(ptr.BlockID, ptr.Offset, 0);
return new PsoPOINTER(ptr.BlockID, ptr.Offset);
}
public Array_Structure AddItemArrayPtr<T>(MetaName type, T[] items) where T : struct //helper method for AddItemArray<T>

View File

@ -15878,7 +15878,7 @@ namespace CodeWalker.GameFiles
{
if ((arr.Count1 > 0) && (arr.Pointer > 0))
{
var entry = pso.DataMapSection.Entries[(int)arr.PointerDataIndex];
var entry = pso.DataMapSection.Entries[arr.PointerDataIndex];
return ConvertDataArrayRaw<T>(pso.DataSection.Data, entry.Offset, arr.Count1);
}
return null;
@ -15887,7 +15887,7 @@ namespace CodeWalker.GameFiles
{
if ((arr.Count1 > 0) && (arr.Pointer > 0))
{
var entry = pso.DataMapSection.Entries[(int)arr.PointerDataIndex];
var entry = pso.DataMapSection.Entries[arr.PointerDataIndex];
var res = ConvertDataArrayRaw<T>(pso.DataSection.Data, entry.Offset, arr.Count1);
if (res != null)
{
@ -15905,12 +15905,12 @@ namespace CodeWalker.GameFiles
public static uint[] GetUintArrayRaw(PsoFile pso, Array_uint arr)
{
byte[] data = pso.DataSection.Data;
var entryid = arr.Pointer & 0xFFF;
var entryid = arr.PointerDataId;
if ((entryid == 0) || (entryid > pso.DataMapSection.EntriesCount))
{
return null;
}
var entryoffset = (arr.Pointer >> 12) & 0xFFFFF;
var entryoffset = arr.PointerDataOffset;
var arrentry = pso.DataMapSection.Entries[(int)entryid - 1];
int totoffset = arrentry.Offset + (int)entryoffset;
uint[] readdata = ConvertDataArrayRaw<uint>(data, totoffset, arr.Count1);
@ -15945,12 +15945,12 @@ namespace CodeWalker.GameFiles
public static float[] GetFloatArrayRaw(PsoFile pso, Array_float arr)
{
byte[] data = pso.DataSection.Data;
var entryid = arr.Pointer & 0xFFF;
var entryid = arr.PointerDataId;
if ((entryid == 0) || (entryid > pso.DataMapSection.EntriesCount))
{
return null;
}
var entryoffset = (arr.Pointer >> 12) & 0xFFFFF;
var entryoffset = arr.PointerDataOffset;
var arrentry = pso.DataMapSection.Entries[(int)entryid - 1];
int totoffset = arrentry.Offset + (int)entryoffset;
float[] readdata = ConvertDataArrayRaw<float>(data, totoffset, arr.Count1);
@ -15974,12 +15974,12 @@ namespace CodeWalker.GameFiles
public static ushort[] GetUShortArrayRaw(PsoFile pso, Array_Structure arr)
{
byte[] data = pso.DataSection.Data;
var entryid = arr.Pointer & 0xFFF;
var entryid = arr.PointerDataId;
if ((entryid == 0) || (entryid > pso.DataMapSection.EntriesCount))
{
return null;
}
var entryoffset = (arr.Pointer >> 12) & 0xFFFFF;
var entryoffset = arr.PointerDataOffset;
var arrentry = pso.DataMapSection.Entries[(int)entryid - 1];
int totoffset = arrentry.Offset + (int)entryoffset;
ushort[] readdata = ConvertDataArrayRaw<ushort>(data, totoffset, arr.Count1);
@ -16041,15 +16041,14 @@ namespace CodeWalker.GameFiles
int ptrsize = Marshal.SizeOf(typeof(MetaPOINTER));
int itemsleft = (int)count; //large arrays get split into chunks...
uint ptr = array.Pointer;
int ptrindex = (int)(ptr & 0xFFF) - 1;
int ptroffset = (int)((ptr >> 12) & 0xFFFFF);
uint ptrindex = array.PointerDataIndex;
uint ptroffset = array.PointerDataOffset;
var ptrblock = (ptrindex < pso.DataMapSection.EntriesCount) ? pso.DataMapSection.Entries[ptrindex] : null;
if ((ptrblock == null) || (ptrblock.NameHash != (MetaName)MetaTypeName.PsoPOINTER))
{ return null; }
var offset = ptrblock.Offset;
int boffset = offset + ptroffset;
int boffset = (int)(offset + ptroffset);
var ptrs = ConvertDataArrayRaw<PsoPOINTER>(pso.DataSection.Data, boffset, (int)count);
if (ptrs != null)
@ -16236,29 +16235,27 @@ namespace CodeWalker.GameFiles
[TC(typeof(EXP))] public struct PsoPOINTER : IPsoSwapEnd //8 bytes - pointer to data item
{
public uint Pointer { get; set; }
public uint Unk2 { get; set; }
public ulong Pointer { get; set; }
public ushort BlockID { get { return (ushort)(Pointer & 0xFFF); } } //1-based ID
public uint ItemOffset { get { return ((Pointer>>12) & 0xFFFFF); } } //byte offset
public uint ItemOffset { get { return (uint)((Pointer>>12) & 0xFFFFF); } } //byte offset
public uint Unk0 { get { return (uint)((Pointer>>32) & 0xFFFFFFFF); } }
public PsoPOINTER(int blockID, int itemOffset, uint extra)
public PsoPOINTER(int blockID, int itemOffset)
{
Pointer = (((uint)itemOffset << 12) & 0xFFFFF000) + ((uint)blockID & 0xFFF);
Unk2 = extra;
}
public override string ToString()
{
return BlockID.ToString() + ", " + ItemOffset.ToString() + ", " + Unk2.ToString();
return BlockID.ToString() + ", " + ItemOffset.ToString();// + ", " + Unk2.ToString();
}
public void SwapEnd()
{
Pointer = MetaTypes.SwapBytes(Pointer);
Unk2 = MetaTypes.SwapBytes(Unk2);
}
}

View File

@ -109,7 +109,7 @@ namespace CodeWalker.GameFiles
case 4: //also pointer? what's the difference?
var bptr = pb.AddItem(stype, struc);
var ptr = new PsoPOINTER(bptr.BlockID, bptr.Offset, 0);
var ptr = new PsoPOINTER(bptr.BlockID, bptr.Offset);
ptr.SwapEnd();
var ptrb = MetaTypes.ConvertToBytes(ptr);
@ -748,7 +748,7 @@ namespace CodeWalker.GameFiles
if (!string.IsNullOrEmpty(str))
{
var bptr = pb.AddString(str);
var ptr = new PsoPOINTER(bptr.BlockID, bptr.Offset, 0);
var ptr = new PsoPOINTER(bptr.BlockID, bptr.Offset);
ptr.SwapEnd();
var val = MetaTypes.ConvertToBytes(ptr);
Buffer.BlockCopy(val, 0, data, entry.DataOffset, val.Length);