Esempio n. 1
0
        public Array_StructurePointer AddPointerArray(PsoPOINTER[] arr)
        {
            if ((arr == null) || (arr.Length == 0))
            {
                return(new Array_StructurePointer());
            }
            var ptr = AddItemArray((MetaName)MetaTypeName.PsoPOINTER, arr);
            Array_StructurePointer sp = new Array_StructurePointer();

            sp.Count1  = (ushort)arr.Length;
            sp.Count2  = sp.Count1;
            sp.Pointer = ptr.Pointer;
            return(sp);
        }
Esempio n. 2
0
        public static T[] ConvertDataArray <T>(PsoFile pso, Array_StructurePointer array) where T : struct, IPsoSwapEnd
        {
            uint count = array.Count1;

            if (count == 0)
            {
                return(null);
            }
            PsoPOINTER[] ptrs = GetPointerArray(pso, array);
            if (ptrs == null)
            {
                return(null);
            }
            if (ptrs.Length < count)
            {
                return(null);
            }

            T[] items    = new T[count];
            int itemsize = Marshal.SizeOf(typeof(T));

            for (int i = 0; i < count; i++)
            {
                var sptr   = ptrs[i];
                int blocki = sptr.BlockID - 1;
                int offset = (int)sptr.ItemOffset;// * 16;//block data size...
                if (blocki >= pso.DataMapSection.EntriesCount)
                {
                    continue;
                }
                var block = pso.DataMapSection.Entries[blocki];

                if ((offset < 0) || (offset >= block.Length))
                {
                    continue;
                }

                int boffset = block.Offset + offset;

                items[i] = ConvertData <T>(pso.DataSection.Data, boffset);
            }

            return(items);
        }
Esempio n. 3
0
        public static PsoPOINTER[] GetPointerArray(PsoFile pso, Array_StructurePointer array)
        {
            uint count = array.Count1;

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

            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 < pso.DataMapSection.EntriesCount) ? pso.DataMapSection.Entries[ptrindex] : null;

            if ((ptrblock == null) || (ptrblock.NameHash != MetaName.PsoPOINTER))
            {
                return(null);
            }

            var offset  = ptrblock.Offset;
            int boffset = offset + ptroffset;

            var ptrs = ConvertDataArrayRaw <PsoPOINTER>(pso.DataSection.Data, boffset, (int)count);

            if (ptrs != null)
            {
                for (int i = 0; i < ptrs.Length; i++)
                {
                    ptrs[i].SwapEnd();
                }
            }

            return(ptrs);
        }