Пример #1
0
        int MaxBlockLength            = 0x100000; //TODO: figure what this should be!

        public PsoBuilderBlock EnsureBlock(MetaName type)
        {
            foreach (var block in Blocks)
            {
                if (block.StructureNameHash == type)
                {
                    if (block.TotalSize < MaxBlockLength)
                    {
                        return(block);
                    }
                }
            }
            PsoBuilderBlock b = new PsoBuilderBlock();

            b.StructureNameHash = type;
            b.Index             = Blocks.Count;
            Blocks.Add(b);
            return(b);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }