public PsoBuilderPointer AddItem(MetaName type, byte[] data) { PsoBuilderBlock 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); PsoBuilderPointer r = new PsoBuilderPointer(); r.BlockID = block.Index + 1; r.Offset = (idx * data.Length); r.Length = data.Length; return(r); }
public PsoBuilderPointer AddItemArray(MetaName type, byte[] data, int length) { PsoBuilderBlock 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); PsoBuilderPointer r = new PsoBuilderPointer(); r.BlockID = block.Index + 1; r.Offset = offs; //(idx * data.Length);; r.Length = length; return(r); }
public PsoBuilderPointer AddString(string str) { PsoBuilderBlock block = EnsureBlock((MetaName)1); //PsoSTRING seems to be 1 byte[] data = Encoding.ASCII.GetBytes(str + (char)0); int datalen = data.Length; int newlen = datalen; //int lenrem = newlen % 16; //if (lenrem != 0) //pad the data length up to multiple of 16. //{ // newlen += (16 - lenrem); //} byte[] newdata = new byte[newlen]; Buffer.BlockCopy(data, 0, newdata, 0, datalen); int offs = block.TotalSize; int idx = block.AddItem(newdata); PsoBuilderPointer r = new PsoBuilderPointer(); r.BlockID = block.Index + 1; r.Offset = offs; // (idx * data.Length); r.Length = datalen; //actual length of string. return(r); }