public IPsoValue Parse(PsoFile meta) { var blockKeys = new List <int>(); var blocks = new List <List <IPsoValue> >(); var t1 = (PsoStructureInfo)null; var t2 = (PsoElementIndexInfo)null; var rootHash = meta.DataMappingSection.Entries[meta.DataMappingSection.RootIndex - 1].NameHash; for (int i = 0; i < meta.DefinitionSection.Count; i++) { if (meta.DefinitionSection.EntriesIdx[i].NameHash == rootHash) { t1 = (PsoStructureInfo)meta.DefinitionSection.Entries[i]; t2 = meta.DefinitionSection.EntriesIdx[i]; } } var resultStructure = new PsoStructure(meta, t1, t2, null); var reader = new PsoDataReader(meta); reader.SetSectionIndex(meta.DataMappingSection.RootIndex - 1); reader.Position = 0; resultStructure.Read(reader); return(resultStructure); }
public IPsoValue Parse(PsoFile meta) { var blockKeys = new List <int>(); var blocks = new List <List <IPsoValue> >(); var resultStructure = new PsoStructure(); resultStructure.pso = meta; var rootHash = meta.DataMappingSection.Entries[meta.DataMappingSection.RootIndex - 1].NameHash; for (int i = 0; i < meta.DefinitionSection.Count; i++) { if (meta.DefinitionSection.EntriesIdx[i].NameHash == rootHash) { resultStructure.psoSection = (PsoStructureInfo)meta.DefinitionSection.Entries[i]; resultStructure.psoEntryInfo = meta.DefinitionSection.EntriesIdx[i]; } } var reader = new DataReader(new MemoryStream(meta.DataSection.Data), Endianess.BigEndian); reader.Position = meta.DataMappingSection.Entries[meta.DataMappingSection.RootIndex - 1].Offset; resultStructure.Read(reader); var stack = new Stack <PsoStructure>(); stack.Push(resultStructure); while (stack.Count > 0) { var x = stack.Pop(); foreach (var ee in x.psoSection.Entries) { if (ee.EntryNameHash == 0x100) { continue; } var value = x.Values[ee.EntryNameHash]; if (value is PsoStructure) { stack.Push((PsoStructure)value); } if (value is PsoArray) { var arrayValue = (PsoArray)value; switch (arrayValue.psoSection.Type) { case DataType.Structure: { if (arrayValue.NumberOfEntries > 0) { arrayValue.Entries = new List <IPsoValue>(); reader.Position = meta.DataMappingSection.Entries[arrayValue.BlockIndex - 1].Offset + arrayValue.Offset; for (int i = 0; i < arrayValue.NumberOfEntries; i++) { PsoStructure item = new PsoStructure(); item.pso = meta; item.psoSection = null; for (int y = 0; y < meta.DefinitionSection.Count; y++) { if (meta.DefinitionSection.EntriesIdx[y].NameHash == arrayValue.psoSection.ReferenceKey) { item.psoSection = (PsoStructureInfo)meta.DefinitionSection.Entries[y]; item.psoEntryInfo = meta.DefinitionSection.EntriesIdx[y]; } } item.Read(reader); arrayValue.Entries.Add(item); stack.Push(item); } } break; } case DataType.INT_0Bh: { if (arrayValue.NumberOfEntries > 0) { arrayValue.Entries = new List <IPsoValue>(); reader.Position = meta.DataMappingSection.Entries[arrayValue.BlockIndex - 1].Offset + arrayValue.Offset; for (int i = 0; i < arrayValue.NumberOfEntries; i++) { PsoType11 item = new PsoType11(0); item.Read(reader); arrayValue.Entries.Add(item); } } break; } default: throw new System.Exception("Unknown array type."); } } } } return(resultStructure); }