示例#1
0
        public GOP(Stream stream)
        {
            SectionSet sections = SectionIO.ReadAll(stream);

            GOPGMET  met  = sections.Get <GOPGMET>();
            GOPGREC  rec  = sections.Get <GOPGREC>();
            GENESTRT strt = sections.Get <GENESTRT>();
            GOPGDAT  dat  = sections.Get <GOPGDAT>();

            foreach (GOPGREC.ElementInfo elementInfo in rec.Elements)
            {
                Element element = new Element();
                element.Name    = strt.Strings[elementInfo.NameIndex];
                element.Type    = elementInfo.Type;
                element.Unknown = elementInfo.Unknown;

                this.Elements.Add(element);
            }

            this.Records = new string[dat.Records.Count, rec.Elements.Count + 1];

            int recordIndex = 0;

            foreach (GOPGDAT.Record record in dat.Records)
            {
                this.Records[recordIndex, 0] = record.Index.ToString();
                using (MemoryStream dataStream = new MemoryStream(record.Data)) {
                    using (BinaryReader dataReader = new BinaryReader(dataStream)) {
                        for (int i = 0; i < rec.Elements.Count; i++)
                        {
                            GOPGREC.ElementInfo elementInfo = rec.Elements[i];
                            dataStream.Seek(elementInfo.Offset, SeekOrigin.Begin);
                            this.Records[recordIndex, i + 1] = ReadElement(dataReader, elementInfo, strt);
                        }
                    }
                }

                recordIndex++;
            }

            this.RootMetric = ConvertToParsedMetric(met.Root, strt);
        }
示例#2
0
        public void Write(Stream stream)
        {
            SectionSet sections = new SectionSet();

            GOPGFIN fin = new GOPGFIN();

            fin.Unknown1 = 0x2;
            fin.Unknown2 = 0x1;
            sections.Add(fin);

            GOPGMET  met  = new GOPGMET();
            GOPGREC  rec  = new GOPGREC();
            GENESTRT strt = new GENESTRT();
            GOPGDAT  dat  = new GOPGDAT();

            strt.AddString("");

            uint currElementPos = 0;

            foreach (Element element in this.Elements)
            {
                uint padTo = ELEMENT_PAD_TO[element.Type];
                currElementPos = (currElementPos + (padTo - 1)) & ~(padTo - 1);

                GOPGREC.ElementInfo info = new GOPGREC.ElementInfo();
                info.Type      = element.Type;
                info.Offset    = currElementPos;
                info.NameIndex = (ushort)strt.AddString(element.Name);
                info.Unknown   = element.Unknown;

                rec.Elements.Add(info);
                currElementPos += ELEMENT_LENGTH[element.Type];
            }

            for (int recordIndex = 0; recordIndex < this.Records.GetLength(0); recordIndex++)
            {
                using (MemoryStream dataStream = new MemoryStream()) {
                    using (BinaryWriter dataWriter = new BinaryWriter(dataStream)) {
                        for (int elementIndex = 0; elementIndex < this.Elements.Count; elementIndex++)
                        {
                            string element = this.Records[recordIndex, elementIndex + 1];
                            GOPGREC.ElementInfo elementInfo = rec.Elements[elementIndex];

                            dataWriter.PadTo((int)ELEMENT_PAD_TO[elementInfo.Type]);
                            WriteElement(dataWriter, elementInfo, strt, element);
                        }

                        dataWriter.PadTo(0x4);
                    }

                    GOPGDAT.Record record = new GOPGDAT.Record();
                    record.Index = uint.Parse(this.Records[recordIndex, 0]);
                    record.Data  = dataStream.ToArray();

                    dat.Records.Add(record);
                }
            }

            met.Root = ConvertToRawMetric(this.RootMetric, strt);

            sections.Add(met);
            sections.Add(rec);
            sections.Add(strt);
            sections.Add(dat);
            sections.Add(new GENEEOF());

            SectionIO.WriteAll(stream, sections);
        }