private ResourceSimpleArray <byte_r> StreamToResourceBytes(Stream stream) { var resourceBytes = new ResourceSimpleArray <byte_r>(); var buffer = new byte[stream.Length]; stream.Position = 0; stream.Read(buffer, 0, (int)stream.Length); foreach (var b in buffer) { var rb = new byte_r(); rb.Value = b; resourceBytes.Add(rb); } return(resourceBytes); }
private void MetaBuildStructureInfos(MetaInformationXml xmlInfo) { strList = new ResourceSimpleArray <StructureInfo_GTA5_pc>(); foreach (var xmlStructureInfo in xmlInfo.Structures) { var structureInfo = new StructureInfo_GTA5_pc(); structureInfo.StructureNameHash = xmlStructureInfo.NameHash; structureInfo.StructureKey = xmlStructureInfo.Key; structureInfo.Unknown_8h = xmlStructureInfo.Unknown; structureInfo.StructureLength = xmlStructureInfo.Length; structureInfo.Entries = new ResourceSimpleArray <StructureEntryInfo_GTA5_pc>(); foreach (var xmlStructureEntryInfo in xmlStructureInfo.Entries) { var xmlArrayTypeStack = new Stack <MetaStructureArrayTypeXml>(); var xmlArrayType = xmlStructureEntryInfo.ArrayType; while (xmlArrayType != null) { xmlArrayTypeStack.Push(xmlArrayType); xmlArrayType = xmlArrayType.ArrayType; } while (xmlArrayTypeStack.Count > 0) { xmlArrayType = xmlArrayTypeStack.Pop(); var arrayStructureEntryInfo = new StructureEntryInfo_GTA5_pc(); arrayStructureEntryInfo.EntryNameHash = 0x100; arrayStructureEntryInfo.DataOffset = 0; arrayStructureEntryInfo.DataType = (StructureEntryDataType)xmlArrayType.Type; arrayStructureEntryInfo.Unknown_9h = 0; if (arrayStructureEntryInfo.DataType == StructureEntryDataType.Array) { arrayStructureEntryInfo.ReferenceTypeIndex = (short)(structureInfo.Entries.Count - 1); } else { arrayStructureEntryInfo.ReferenceTypeIndex = 0; } arrayStructureEntryInfo.ReferenceKey = xmlArrayType.TypeHash; structureInfo.Entries.Add(arrayStructureEntryInfo); } var structureEntryInfo = new StructureEntryInfo_GTA5_pc(); structureEntryInfo.EntryNameHash = xmlStructureEntryInfo.NameHash; structureEntryInfo.DataOffset = xmlStructureEntryInfo.Offset; structureEntryInfo.DataType = (StructureEntryDataType)xmlStructureEntryInfo.Type; structureEntryInfo.Unknown_9h = (byte)xmlStructureEntryInfo.Unknown; if (structureEntryInfo.DataType == StructureEntryDataType.Array) { structureEntryInfo.ReferenceTypeIndex = (short)(structureInfo.Entries.Count - 1); } else { structureEntryInfo.ReferenceTypeIndex = 0; } structureEntryInfo.ReferenceKey = xmlStructureEntryInfo.TypeHash; structureInfo.Entries.Add(structureEntryInfo); } strList.Add(structureInfo); } }
// Hashes alignment pad // Extra 32 bytes // Extra 4 * ParametersTotalSize bytes public override void Read(ResourceDataReader reader, params object[] parameters) { int cnt = Convert.ToInt32(parameters[0]); Parameters = reader.ReadBlock <ResourceSimpleArray <ShaderParameter> >(cnt); Data = new ResourceSimpleArray <SimpleArray <Vector4> >(); int dataBlockSize = 0; for (int i = 0; i < cnt; i++) { var p = Parameters[i]; // read reference data switch (p.DataType) { case 0: dataBlockSize += 0; p.Data = reader.ReadBlockAt <Texture>(p.DataPointer); break; //case 1: // dataBlockSize += 16; // p.Data = reader.ReadBlockAt<RAGE_Vector4>(p.DataPointer); // break; //case 2: // offset += 32; // p.Data = reader.ReadBlockAt<ResourceSimpleArray<RAGE_Vector4>>( // p.DataPointer, // offset // 2 // ); // break; //case 4: // offset += 64; // p.Data = reader.ReadBlockAt<ResourceSimpleArray<RAGE_Vector4>>( // p.DataPointer, // offset // 4 // ); // break; default: dataBlockSize += 16 * p.DataType; var data = reader.ReadBlockAt <SimpleArray <Vector4> >(p.DataPointer, p.DataType); p.Data = data; Data.Add(data); break; } } // Skip Data among Parameters and Hashes which we have already read reader.Position += dataBlockSize; Hashes = reader.ReadBlock <SimpleArray <uint> >(cnt); // Read hashes alignment pad //reader.Position += (16 - (reader.Position % 16)) % 16; // Read extra 32 bytes //reader.Position += 32; // Read extra 4 * ParametersTotalSize bytes //reader.Position += 4 * BaseSize; }