예제 #1
0
        public static PsoDataMappingEntry GetRootEntry(PsoFile pso)
        {
            var i = pso.DataMappingSection.RootIndex - 1;
            var e = pso.DataMappingSection.Entries[i];

            return(e);
        }
예제 #2
0
        public static T GetRootItem <T>(PsoFile pso) where T : struct, IPsoSwapEnd
        {
            var i = pso.DataMappingSection.RootIndex - 1;
            var e = pso.DataMappingSection.Entries[i];

            return(GetItem <T>(pso, e.Offset));
        }
예제 #3
0
 public static T[] GetItemArrayRaw <T>(PsoFile pso, Array_Structure arr) where T : struct
 {
     if ((arr.Count1 > 0) && (arr.Pointer > 0))
     {
         var entry = pso.DataMappingSection.Entries[(int)arr.PointerDataIndex];
         return(ConvertDataArrayRaw <T>(pso.DataSection.Data, entry.Offset, arr.Count1));
     }
     return(null);
 }
예제 #4
0
 public static ushort[] GetUShortArray(PsoFile pso, Array_Structure arr)
 {
     ushort[] ushorts = GetUShortArrayRaw(pso, arr);
     if (ushorts == null)
     {
         return(null);
     }
     for (int i = 0; i < ushorts.Length; i++)
     {
         ushorts[i] = MetaUtils.SwapBytes(ushorts[i]);
     }
     return(ushorts);
 }
예제 #5
0
 public static float[] GetFloatArray(PsoFile pso, Array_float arr)
 {
     float[] floats = GetFloatArrayRaw(pso, arr);
     if (floats == null)
     {
         return(null);
     }
     for (int i = 0; i < floats.Length; i++)
     {
         floats[i] = MetaUtils.SwapBytes(floats[i]);
     }
     return(floats);
 }
예제 #6
0
 public static uint[] GetUintArray(PsoFile pso, Array_uint arr)
 {
     uint[] uints = GetUintArrayRaw(pso, arr);
     if (uints == null)
     {
         return(null);
     }
     for (int i = 0; i < uints.Length; i++)
     {
         uints[i] = MetaUtils.SwapBytes(uints[i]);
     }
     return(uints);
 }
예제 #7
0
 public static MetaName[] GetHashArray(PsoFile pso, Array_uint arr)
 {
     uint[] uints = GetUintArrayRaw(pso, arr);
     if (uints == null)
     {
         return(null);
     }
     MetaName[] hashes = new MetaName[uints.Length];
     for (int n = 0; n < uints.Length; n++)
     {
         hashes[n] = (MetaName)MetaUtils.SwapBytes(uints[n]);
     }
     return(hashes);
 }
예제 #8
0
        public static byte[] GetByteArray(PsoFile pso, PsoStructureEntryInfo entry, int offset)
        {
            var aCount   = (entry.ReferenceKey >> 16) & 0x0000FFFF;
            var aBlockId = (int)entry.ReferenceKey & 0x0000FFFF;
            var block    = pso.GetBlock(aBlockId);

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

            //block.Offset

            return(null);
        }
예제 #9
0
        public static ushort[] GetUShortArrayRaw(PsoFile pso, Array_Structure arr)
        {
            byte[] data    = pso.DataSection.Data;
            var    entryid = arr.Pointer & 0xFFF;

            if ((entryid == 0) || (entryid > pso.DataMappingSection.EntriesCount))
            {
                return(null);
            }
            var entryoffset = (arr.Pointer & 0xFFFFFF) >> 12;
            var arrentry    = pso.DataMappingSection.Entries[(int)entryid - 1];
            int totoffset   = arrentry.Offset + (int)entryoffset;

            ushort[] readdata = ConvertDataArrayRaw <ushort>(data, totoffset, arr.Count1);
            return(readdata);
        }
예제 #10
0
 public static T[] GetItemArray <T>(PsoFile pso, Array_Structure arr) where T : struct, IPsoSwapEnd
 {
     if ((arr.Count1 > 0) && (arr.Pointer > 0))
     {
         var entry = pso.DataMappingSection.Entries[(int)arr.PointerDataIndex];
         var res   = ConvertDataArrayRaw <T>(pso.DataSection.Data, entry.Offset, arr.Count1);
         if (res != null)
         {
             for (int i = 0; i < res.Length; i++)
             {
                 res[i].SwapEnd();
             }
         }
         return(res);
     }
     return(null);
 }
예제 #11
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.DataMappingSection.EntriesCount)
                {
                    continue;
                }
                var block = pso.DataMappingSection.Entries[blocki];

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

                int boffset = block.Offset + offset;

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

            return(items);
        }
예제 #12
0
        public static string GetString(PsoFile pso, CharPointer ptr)
        {
            if (ptr.Count1 == 0)
            {
                return(null);
            }

            var blocki = (int)ptr.PointerDataId;     // (ptr.Pointer & 0xFFF) - 1;
            var offset = (int)ptr.PointerDataOffset; // (ptr.Pointer >> 12) & 0xFFFFF;

            var block = pso.GetBlock(blocki);

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

            var length   = ptr.Count1;
            var lastbyte = offset + length;

            if (lastbyte >= block.Length)
            {
                return(null);
            }

            var data = pso.DataSection?.Data;

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

            var doffset = block.Offset + offset;

            string s = Encoding.ASCII.GetString(data, doffset, length);

            //if (meta.Strings == null) return null;
            //if (offset < 0) return null;
            //if (offset >= meta.Strings.Length) return null;
            //string s = meta.Strings[offset];

            return(s);
        }
예제 #13
0
        public static string GetString(PsoFile pso, DataBlockPointer ptr)
        {
            var blocki = (int)ptr.PointerDataId;     // (ptr.Pointer & 0xFFF) - 1;
            var offset = (int)ptr.PointerDataOffset; // (ptr.Pointer >> 12) & 0xFFFFF;

            var block = pso.GetBlock(blocki);

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

            //var length = ptr.Count1;
            //var lastbyte = offset + length;
            //if (lastbyte >= block.Length)
            //{ return null; }

            var data = pso.DataSection?.Data;

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

            //var doffset = block.Offset + offset;

            //string s = Encoding.ASCII.GetString(data, doffset, length);

            StringBuilder sb = new StringBuilder();
            var           o  = block.Offset + offset;
            char          c  = (char)data[o];

            while (c != 0)
            {
                sb.Append(c);
                o++;
                c = (char)data[o];
            }
            var s = sb.ToString();

            return(s);
        }
예제 #14
0
 public static T[] GetObjectArray <T, U>(PsoFile pso, Array_Structure arr) where U : struct, IPsoSwapEnd where T : PsoClass <U>, new()
 {
     U[] items = GetItemArray <U>(pso, arr);
     if (items == null)
     {
         return(null);
     }
     if (items.Length == 0)
     {
         return(null);
     }
     T[] result = new T[items.Length];
     for (int i = 0; i < items.Length; i++)
     {
         T newitem = new T();
         newitem.Init(pso, ref items[i]);
         result[i] = newitem;
     }
     return(result);
 }
예제 #15
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.DataMappingSection.EntriesCount) ? pso.DataMappingSection.Entries[ptrindex] : null;

            if ((ptrblock == null) || ((MetaName)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);
        }
예제 #16
0
 public abstract void Init(PsoFile pso, ref T v);
예제 #17
0
 public static T GetItem <T>(PsoFile pso, int offset) where T : struct, IPsoSwapEnd
 {
     return(ConvertData <T>(pso.DataSection.Data, offset));
 }