public MetaBuilderPointer AddItem(MetaName type, byte[] data) { MetaBuilderBlock block = EnsureBlock(type); int brem = data.Length % 16; if (brem > 0) { int newlen = data.Length - brem + 16; byte[] newdata = new byte[newlen]; Buffer.BlockCopy(data, 0, newdata, 0, data.Length); data = newdata; //make sure item size is multiple of 16... so pointers don't need sub offsets! } int idx = block.AddItem(data); MetaBuilderPointer r = new MetaBuilderPointer(); r.BlockID = block.Index + 1; r.Offset = (idx * data.Length); r.Length = data.Length; return(r); }
int MaxBlockLength = 0x4000; //TODO: figure what this should be! public MetaBuilderBlock EnsureBlock(MetaName type) { foreach (var block in Blocks) { if (block.StructureNameHash == type) { if (block.TotalSize < MaxBlockLength) { return(block); } } } MetaBuilderBlock b = new MetaBuilderBlock(); b.StructureNameHash = type; b.Index = Blocks.Count; Blocks.Add(b); return(b); }
public MetaBuilderPointer AddItemArray(MetaName type, byte[] data, int length) { MetaBuilderBlock block = EnsureBlock(type); int datalen = data.Length; int newlen = datalen; int lenrem = newlen % 16; if (lenrem != 0) { newlen += (16 - lenrem); } byte[] newdata = new byte[newlen]; Buffer.BlockCopy(data, 0, newdata, 0, datalen); int offs = block.TotalSize; int idx = block.AddItem(newdata); MetaBuilderPointer r = new MetaBuilderPointer(); r.BlockID = block.Index + 1; r.Offset = offs; //(idx * data.Length);; r.Length = length; return(r); }