コード例 #1
0
ファイル: MetaUtils.cs プロジェクト: indilo53/gta-toolkit
        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);
        }
コード例 #2
0
ファイル: MetaUtils.cs プロジェクト: indilo53/gta-toolkit
        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));
        }
コード例 #3
0
ファイル: MetaUtils.cs プロジェクト: indilo53/gta-toolkit
        public static T[] ConvertDataArray <T>(MetaFile meta, Array_StructurePointer array) where T : struct
        {
            uint count = array.Count1;

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

            MetaPOINTER[] ptrs = GetPointerArray(meta, array);

            if (ptrs == null)
            {
                return(null);
            }

            T[] items     = new T[count];
            int itemsize  = Marshal.SizeOf(typeof(T));
            int itemsleft = (int)count; //large arrays get split into chunks...

            //MetaName blocktype = 0;
            for (int i = 0; i < count; i++)
            {
                var ptr    = ptrs[i];
                var offset = ptr.Offset;
                var block  = meta.GetBlock(ptr.BlockID);

                if (block == null)
                {
                    continue;
                }

                if ((offset < 0) || (block.Data == null) || (offset >= block.Data.Count))
                {
                    continue;
                }

                items[i] = ConvertData <T>(block.Data, offset);
            }

            return(items);
        }