public static PsoDataMappingEntry GetRootEntry(PsoFile pso) { var i = pso.DataMappingSection.RootIndex - 1; var e = pso.DataMappingSection.Entries[i]; return(e); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public abstract void Init(PsoFile pso, ref T v);
public static T GetItem <T>(PsoFile pso, int offset) where T : struct, IPsoSwapEnd { return(ConvertData <T>(pso.DataSection.Data, offset)); }