Created MloArchetype and TimeArchetype subclasses, Meta pointer improvement

This commit is contained in:
dexyfex
2017-09-28 14:28:09 +10:00
Unverified
parent 7ddd88e561
commit f974c9eb49
9 changed files with 167 additions and 179 deletions
+10 -8
View File
@@ -882,7 +882,7 @@ namespace CodeWalker.GameFiles
}
}
[TC(typeof(EXP))] public struct ArrayOfUshorts3 //array of 3 bytes
[TC(typeof(EXP))] public struct ArrayOfUshorts3 //array of 3 ushorts
{
public ushort u0, u1, u2;
public override string ToString()
@@ -961,22 +961,24 @@ namespace CodeWalker.GameFiles
}
}
[TC(typeof(EXP))] public struct MetaPOINTER //8 bytes - pointer to data item //SectionUNKNOWN10
[TC(typeof(EXP))] public struct MetaPOINTER //8 bytes - pointer to data item //was: SectionUNKNOWN10
{
public ushort BlockID { get; set; } //1-based ID
public ushort ItemOffset { get; set; } //byte offset / 16
public uint Pointer { get; set; }
public uint ExtraOffset { get; set; }
public MetaPOINTER(ushort blockID, ushort itemOffset, uint extra)
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)
{
BlockID = blockID;
ItemOffset = itemOffset;
Pointer = (((uint)itemOffset << 12) & 0xFFFFF000) + ((uint)blockID & 0xFFF);
ExtraOffset = extra;
}
public override string ToString()
{
return BlockID.ToString() + ", " + ItemOffset.ToString() + ", " + ExtraOffset.ToString();
return BlockID.ToString() + ", " + Offset.ToString() + ", " + ExtraOffset.ToString();
}
}
+15 -15
View File
@@ -47,8 +47,8 @@ namespace CodeWalker.GameFiles
}
int idx = block.AddItem(data);
MetaBuilderPointer r = new MetaBuilderPointer();
r.Block = block.Index + 1;
r.Offset = (idx * data.Length) / 16;
r.BlockID = block.Index + 1;
r.Offset = (idx * data.Length);
r.Length = data.Length;
return r;
}
@@ -65,11 +65,11 @@ namespace CodeWalker.GameFiles
}
byte[] newdata = new byte[newlen];
Buffer.BlockCopy(data, 0, newdata, 0, datalen);
int offs = block.TotalSize / 16;
int offs = block.TotalSize;
int idx = block.AddItem(newdata);
MetaBuilderPointer r = new MetaBuilderPointer();
r.Block = block.Index + 1;
r.Offset = offs; //(idx * data.Length) / 16;
r.BlockID = block.Index + 1;
r.Offset = offs; //(idx * data.Length);;
r.Length = items.Length;
return r;
}
@@ -86,11 +86,11 @@ namespace CodeWalker.GameFiles
}
byte[] newdata = new byte[newlen];
Buffer.BlockCopy(data, 0, newdata, 0, datalen);
int offs = block.TotalSize / 16;
int offs = block.TotalSize;
int idx = block.AddItem(newdata);
MetaBuilderPointer r = new MetaBuilderPointer();
r.Block = block.Index + 1;
r.Offset = offs;// (idx * data.Length) / 16;//not sure if this is correct! should also use sub-offset!
r.BlockID = block.Index + 1;
r.Offset = offs;// (idx * data.Length);
r.Length = datalen; //actual length of string.
return r;
}
@@ -98,7 +98,7 @@ 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((ushort)ptr.Block, (ushort)ptr.Offset, 0);
return new MetaPOINTER(ptr.BlockID, ptr.Offset, 0);
}
public Array_Structure AddItemArrayPtr<T>(MetaName type, T[] items) where T : struct //helper method for AddItemArray<T>
{
@@ -207,8 +207,8 @@ namespace CodeWalker.GameFiles
if (i == 0)
{
MetaBuilderPointer mbp = new MetaBuilderPointer();
mbp.Block = meptr.BlockID;
mbp.Offset = meptr.ItemOffset;
mbp.BlockID = meptr.BlockID;
mbp.Offset = meptr.Offset;
sa.Pointer = mbp.Pointer;
}
}
@@ -359,15 +359,15 @@ namespace CodeWalker.GameFiles
public struct MetaBuilderPointer
{
public int Block { get; set; } //0-based index
public int Offset { get; set; } //(byteoffset/16)
public int BlockID { get; set; } //1-based id
public int Offset { get; set; } //byte offset
public int Length { get; set; } //for temp use...
public uint Pointer
{
get
{
uint bidx = (((uint)Block) & 0xFFF);
uint offs = (((uint)Offset) & 0xFFFF) << 16;
uint bidx = (((uint)BlockID) & 0xFFF);
uint offs = (((uint)Offset) & 0xFFFFF) << 12;
return bidx + offs;
}
}
+9 -28
View File
@@ -819,12 +819,10 @@ namespace CodeWalker.GameFiles
//MetaName blocktype = 0;
for (int i = 0; i < count; i++)
{
var sptr = ptrs[i];
int blocki = sptr.BlockID - 1;
int offset = sptr.ItemOffset * 16;//block data size...
if (blocki >= meta.DataBlocks.Count)
{ continue; }
var block = meta.DataBlocks[blocki];
var ptr = ptrs[i];
var offset = ptr.Offset;
var block = meta.GetBlock(ptr.BlockID);
if (block == null) continue;
//if (blocktype == 0)
//{ blocktype = block.StructureNameHash; }
@@ -983,11 +981,8 @@ namespace CodeWalker.GameFiles
MetaPOINTER[] ptrs = new MetaPOINTER[count];
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);
var ptrblock = (ptrindex < meta.DataBlocks.Count) ? meta.DataBlocks[ptrindex] : null;
int ptroffset = (int)array.PointerDataOffset;
var ptrblock = meta.GetBlock((int)array.PointerDataId);
if ((ptrblock == null) || (ptrblock.Data == null) || (ptrblock.StructureNameHash != MetaName.POINTER))
{ return null; }
@@ -1204,7 +1199,7 @@ namespace CodeWalker.GameFiles
{
var extptr = extptrs[i];
MetaWrapper ext = null;
var block = GetDataBlock(meta, extptr);
var block = meta.GetBlock(extptr.BlockID);
var h = block.StructureNameHash;
switch (h)
{
@@ -1277,18 +1272,10 @@ namespace CodeWalker.GameFiles
}
public static MetaDataBlock GetDataBlock(Meta meta, MetaPOINTER ptr)
{
int blocki = ptr.BlockID - 1;
if ((blocki < 0) || (blocki >= meta.DataBlocks.Count))
{ return null; }
var block = meta.DataBlocks[blocki];
return block;
}
public static int GetDataOffset(MetaDataBlock block, MetaPOINTER ptr)
{
if (block == null) return -1;
int offset = ptr.ItemOffset * 16;//block data size...
var offset = ptr.Offset;
if (ptr.ExtraOffset != 0)
{ }
//offset += (int)ptr.ExtraOffset;
@@ -1298,13 +1285,7 @@ namespace CodeWalker.GameFiles
}
public static T GetData<T>(Meta meta, MetaPOINTER ptr) where T : struct
{
var block = GetDataBlock(meta, ptr);
var offset = GetDataOffset(block, ptr);
if (offset < 0) return new T();
return ConvertData<T>(block.Data, offset);
}
public static T GetData<T>(MetaDataBlock block, MetaPOINTER ptr) where T : struct
{
var block = meta.GetBlock(ptr.BlockID);
var offset = GetDataOffset(block, ptr);
if (offset < 0) return new T();
return ConvertData<T>(block.Data, offset);
+2 -2
View File
@@ -285,8 +285,8 @@ namespace CodeWalker.GameFiles
for (int n = 0; n < aCount; n++)
{
var ptr = ptrArr[n];
var eboffset = ptr.ItemOffset * 16;
WriteNode(sb, aind, cont, ptr.BlockID, eboffset, XmlTagMode.ItemAndType);
var offset = ptr.Offset;
WriteNode(sb, aind, cont, ptr.BlockID, offset, XmlTagMode.ItemAndType);
}
CloseTag(sb, indent, ename);
}