private static Vector2[] TraverseVector2ArrayRaw(XmlNode node) { var items = new List <Vector2>(); var split = node.InnerText.Split('\n');// Regex.Split(node.InnerText, @"[\s\r\n\t]"); float x = 0f; float y = 0f; for (int i = 0; i < split.Length; i++) { var s = split[i]?.Trim(); if (string.IsNullOrEmpty(s)) { continue; } var split2 = Regex.Split(s, @"[\s\t]"); int c = 0; x = 0f; y = 0f; for (int n = 0; n < split2.Length; n++) { var ts = split2[n]?.Trim(); if (ts.EndsWith(",")) { ts = ts.Substring(0, ts.Length - 1); } if (string.IsNullOrEmpty(ts)) { continue; } var f = FloatUtil.Parse(ts); switch (c) { case 0: x = f; break; case 1: y = f; break; } c++; } if (c >= 3) { var val = new Vector2(x, y); items.Add(MetaTypes.SwapBytes(val)); //big schmig } } return(items.ToArray()); }
public static MetaHash[] GetHashArray(PsoFile pso, Array_uint arr) { uint[] uints = GetUintArrayRaw(pso, arr); if (uints == null) { return(null); } MetaHash[] hashes = new MetaHash[uints.Length]; for (int n = 0; n < uints.Length; n++) { hashes[n].Hash = MetaTypes.SwapBytes(uints[n]); } return(hashes); }
//public uint PadCount { get; set; } //public byte[] PadData { get; set; } //public string[] TestStrings { get; set; } public override void Read(ResourceDataReader reader, params object[] parameters) { Count = MetaTypes.SwapBytes(reader.ReadUInt32()); //okay. so this is big endian EncryptedData = reader.ReadBytes((int)Count); //PadCount = (uint)((8 - (reader.Position % 8)) % 8);//maybe next block just needs to be aligned instead? //PadData = reader.ReadBytes((int)PadCount); ////none of these work :( //var strs = new List<string>(); //foreach (var key in GTA5Keys.PC_NG_KEYS) //{ // var decr = GTACrypto.DecryptNG(EncryptedData, key); // strs.Add(Encoding.ASCII.GetString(decr)); //} //TestStrings = strs.ToArray(); }
private static float[] TraverseFloatArrayRaw(XmlNode node) { var data = new List <float>(); if (node.InnerText != "") { var split = Regex.Split(node.InnerText, @"[\s\r\n\t]"); for (int i = 0; i < split.Length; i++) { if (!string.IsNullOrEmpty(split[i])) { var val = FloatUtil.Parse(split[i]); data.Add(MetaTypes.SwapBytes(val)); } } } return(data.ToArray()); }
private static void TraverseArray(XmlNode node, PsoBuilder pb, PsoStructureEntryInfo entry, PsoStructureEntryInfo arrEntry, PsoArrayResults results, byte[] data, PsoStructureInfo structInfo) { int offset = entry.DataOffset; uint aCount = (entry.ReferenceKey >> 16) & 0x0000FFFF; uint aPtr = (entry.ReferenceKey) & 0x0000FFFF; byte[] adata = null; //how do we know when it's an "embedded" array? bool embedded = true; switch (entry.Unk_5h) { default: //ErrorXml(sb, indent, ename + ": WIP! Unsupported Array subtype: " + entry.Unk_5h.ToString()); break; case 0: //Array_Structure //var arrStruc = MetaTypes.ConvertData<Array_Structure>(data, eoffset); embedded = false; break; case 1: //Raw in-line array break; case 2: //also raw in-line array, but how different from above? break; case 4: //pointer array? default array? if (arrEntry.Unk_5h == 3) //pointers... { //var arrStruc4 = MetaTypes.ConvertData<Array_Structure>(data, eoffset); embedded = false; } else { } break; case 129: //also raw inline array? in junctions.pso (AutoJunctionAdjustments) break; } switch (arrEntry.Type) { case PsoDataType.Structure: { if (embedded) { if (arrEntry.ReferenceKey != 0) { var datas = TraverseArrayStructureRaw(node, pb, (MetaName)arrEntry.ReferenceKey); int aoffset = offset; for (int i = 0; i < datas.Length; i++) { Buffer.BlockCopy(datas[i], 0, data, aoffset, datas[i].Length); aoffset += datas[i].Length; } } else { var ptrs = TraverseArrayStructurePointerRaw(node, pb); adata = MetaTypes.ConvertArrayToBytes(ptrs); } } else { if (arrEntry.ReferenceKey != 0) { results.Structures[offset] = TraverseArrayStructure(node, pb, (MetaName)arrEntry.ReferenceKey); } else { results.StructurePointers[offset] = TraverseArrayStructurePointer(node, pb); } } break; } case PsoDataType.Float2: { var arr = TraverseVector2ArrayRaw(node); if (embedded) { adata = MetaTypes.ConvertArrayToBytes(arr); aCount *= 8; } else { results.Float_XYZs[offset] = pb.AddVector2ArrayPtr(arr); } break; } case PsoDataType.Float3: { var arr = TraverseVector3ArrayRaw(node); if (embedded) { adata = MetaTypes.ConvertArrayToBytes(arr); aCount *= 16; } else { results.Float_XYZs[offset] = pb.AddPaddedVector3ArrayPtr(arr); } break; } case PsoDataType.UByte: { var arr = TraverseUByteArrayRaw(node); if (embedded) { adata = arr; } else { results.UBytes[offset] = pb.AddByteArrayPtr(arr); } break; } case PsoDataType.Bool: { var arr = TraverseUByteArrayRaw(node); if (embedded) { adata = arr; } else { results.UBytes[offset] = pb.AddByteArrayPtr(arr); } break; } case PsoDataType.UInt: { var arr = TraverseUIntArrayRaw(node); if (embedded) { adata = MetaTypes.ConvertArrayToBytes(arr); aCount *= 4; } else { results.UInts[offset] = pb.AddUIntArrayPtr(arr); } break; } case PsoDataType.SInt: { var arr = TraverseSIntArrayRaw(node); if (embedded) { adata = MetaTypes.ConvertArrayToBytes(arr); aCount *= 4; } else { results.UInts[offset] = pb.AddSIntArrayPtr(arr); } break; } case PsoDataType.Float: { var arr = TraverseFloatArrayRaw(node); if (embedded) { adata = MetaTypes.ConvertArrayToBytes(arr); aCount *= 4; } else { results.Floats[offset] = pb.AddFloatArrayPtr(arr); } break; } case PsoDataType.UShort: { var arr = TraverseUShortArrayRaw(node); if (embedded) { adata = MetaTypes.ConvertArrayToBytes(arr); aCount *= 2; } else { results.UShorts[offset] = pb.AddUShortArrayPtr(arr); } break; } case PsoDataType.String: { switch (entry.Unk_5h) { default: //ErrorXml(sb, indent, ename + ": Unexpected String array subtype: " + entry.Unk_5h.ToString()); break; case 0: //hash array... var hashes = TraverseHashArrayRaw(node); if (embedded) { adata = MetaTypes.ConvertArrayToBytes(hashes); aCount *= 4; } else { results.Hashes[offset] = pb.AddHashArrayPtr(hashes); } break; } break; } case PsoDataType.Enum: { var hashes = TraverseHashArrayRaw(node); if (arrEntry.ReferenceKey != 0) { var _infos = PsoTypes.GetEnumInfo((MetaName)arrEntry.ReferenceKey); pb.AddEnumInfo(_infos.IndexInfo.NameHash); var values = new uint[hashes.Length]; for (int i = 0; i < hashes.Length; i++) { var enumname = (MetaName)MetaTypes.SwapBytes(hashes[i]); //yeah swap it back to little endian..! var enuminf = _infos.FindEntryByName(enumname); if (enuminf != null) { values[i] = MetaTypes.SwapBytes((uint)enuminf.EntryKey); } else { } //error? } if (embedded) { } //TODO? else { results.UInts[offset] = pb.AddUIntArrayPtr(values); } } else { } break; } case PsoDataType.Array: { //array array... var rk0 = (entry.ReferenceKey >> 16) & 0x0000FFFF; var rk1 = arrEntry.ReferenceKey & 0x0000FFFF; if (rk0 > 0) //should be count of items { var subarrEntry = structInfo.GetEntry((int)rk1); var subarrType = (MetaName)subarrEntry.ReferenceKey; var origOffset = arrEntry.DataOffset; arrEntry.DataOffset = entry.DataOffset; //slight hack for traversing array array foreach (XmlNode cnode in node.ChildNodes) { TraverseArray(cnode, pb, arrEntry, subarrEntry, results, data, structInfo); arrEntry.DataOffset += 16; //ptr size... todo: what if not pointer array? } arrEntry.DataOffset = origOffset; } break; } default: break; } if (embedded) { if (adata?.Length > 0) { if (adata.Length > aCount) { } //bad! old data won't fit in new slot... Buffer.BlockCopy(adata, 0, data, offset, adata.Length); } else { } } }
private static void Write(ulong val, byte[] data, int offset) { byte[] bytes = BitConverter.GetBytes(MetaTypes.SwapBytes(val)); Buffer.BlockCopy(bytes, 0, data, offset, sizeof(ulong)); }
private static void Write(float val, byte[] data, int offset) { byte[] bytes = BitConverter.GetBytes(MetaTypes.SwapBytes(val));//big fkn end Buffer.BlockCopy(bytes, 0, data, offset, sizeof(float)); }
public void SwapEnd() { Ptr0 = MetaTypes.SwapBytes(Ptr0); Ptr1 = MetaTypes.SwapBytes(Ptr1); }
public void SwapEnd() { Name = new MetaHash(MetaTypes.SwapBytes(Name.Hash)); }
public void SwapEnd() { Name = new MetaHash(MetaTypes.SwapBytes(Name.Hash)); var aabb = AABB; aabb.SwapEnd(); AABB = aabb; }
public void SwapEnd() { Name = new MetaHash(MetaTypes.SwapBytes(Name.Hash)); var b = Bounds; b.SwapEnd(); Bounds = b; }
public void SwapEnd() { itypName = new MetaHash(MetaTypes.SwapBytes(itypName.Hash)); manifestFlags = MetaTypes.SwapBytes(manifestFlags); var d = itypDepArray; d.SwapEnd(); itypDepArray = d; }
public void SwapEnd() { imapName = new MetaHash(MetaTypes.SwapBytes(imapName.Hash)); itypName = new MetaHash(MetaTypes.SwapBytes(itypName.Hash)); packFileName = new MetaHash(MetaTypes.SwapBytes(packFileName.Hash)); }
public void SwapEnd() { Pointer = MetaTypes.SwapBytes(Pointer); Unk2 = MetaTypes.SwapBytes(Unk2); }