示例#1
0
        public Array_StructurePointer AddWrapperArrayPtr(MetaWrapper[] items)
        {
            if ((items == null) || (items.Length == 0))
            {
                return(new Array_StructurePointer());
            }


            MetaPOINTER[] ptrs = new MetaPOINTER[items.Length];
            for (int i = 0; i < items.Length; i++)
            {
                ptrs[i] = items[i].Save(this);
            }
            return(AddPointerArray(ptrs));

            //Array_StructurePointer sp = new Array_StructurePointer();
            //sp.Count1 = (ushort)items.Length;
            //sp.Count2 = sp.Count1;
            //for (int i = 0; i < items.Length; i++)
            //{
            //    var item = items[i];
            //    var meptr = item.Save(this);
            //    var mptr = AddItem(MetaName.POINTER, meptr);
            //    if (i == 0)
            //    {
            //        sp.Pointer = mptr.Pointer; //main pointer points to the first item.
            //    }
            //}
            //return sp;
        }
示例#2
0
        public static MetaPOINTER[] GetPointerArray(MetaFile meta, Array_StructurePointer array)
        {
            uint count = array.Count1;

            if (count == 0)
            {
                return(null);
            }

            MetaPOINTER[] ptrs      = new MetaPOINTER[count];
            int           ptrsize   = Marshal.SizeOf(typeof(MetaPOINTER));
            int           ptroffset = (int)array.PointerDataOffset;
            var           ptrblock  = meta.GetBlock((int)array.PointerDataId);

            if ((ptrblock == null) || (ptrblock.Data == null) || ((MetaName)ptrblock.StructureNameHash != MetaName.POINTER))
            {
                return(null);
            }

            for (int i = 0; i < count; i++)
            {
                int offset = ptroffset + (i * ptrsize);

                if (offset >= ptrblock.Data.Count)
                {
                    break;
                }

                ptrs[i] = ConvertData <MetaPOINTER>(ptrblock.Data, offset);
            }

            return(ptrs);
        }
示例#3
0
        public Array_StructurePointer AddItemPointerArrayPtr <T>(MetaName type, T[] items) where T : struct
        {
            //helper method for creating a pointer array
            if ((items == null) || (items.Length == 0))
            {
                return(new Array_StructurePointer());
            }

            MetaPOINTER[] ptrs = new MetaPOINTER[items.Length];
            for (int i = 0; i < items.Length; i++)
            {
                ptrs[i] = AddItemPtr(type, items[i]);
            }
            return(AddPointerArray(ptrs));

            //Array_StructurePointer sp = new Array_StructurePointer();
            //sp.Count1 = (ushort)items.Length;
            //sp.Count2 = sp.Count1;
            //for (int i = 0; i < items.Length; i++)
            //{
            //    var item = items[i];
            //    var meptr = AddItemPtr(type, item);
            //    var mptr = AddItem(MetaName.POINTER, meptr);
            //    if (i == 0)
            //    {
            //        sp.Pointer = mptr.Pointer; //main pointer points to the first item.
            //    }
            //}
            //return sp;
        }
示例#4
0
        public static T GetData <T>(MetaFile meta, 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));
        }
示例#5
0
        public static int GetDataOffset(DataBlock block, MetaPOINTER ptr)
        {
            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);
        }