Exemple #1
0
        private static string ReadElement(BinaryReader reader, GOPGREC.ElementInfo elementInfo, GENESTRT stringTable)
        {
            switch (elementInfo.Type)
            {
            case GOPGREC.ElementType.ENUM:
                return(reader.ReadUInt32().ToString());

            case GOPGREC.ElementType.INT8:
                return(reader.ReadSByte().ToString());

            case GOPGREC.ElementType.INT16:
                return(reader.ReadInt16().ToString());

            case GOPGREC.ElementType.INT32:
                return(reader.ReadInt32().ToString());

            case GOPGREC.ElementType.UINT8:
                return(reader.ReadByte().ToString());

            case GOPGREC.ElementType.UINT16:
                return(reader.ReadUInt16().ToString());

            case GOPGREC.ElementType.UINT32:
                return(reader.ReadUInt32().ToString());

            case GOPGREC.ElementType.FLOAT32:
                return(reader.ReadSingle().ToString());

            case GOPGREC.ElementType.BOOL:
                return(reader.ReadBoolean().ToString());

            case GOPGREC.ElementType.RECID:
            case GOPGREC.ElementType.STRING:
                return(stringTable.Strings[reader.ReadInt32()]);

            case GOPGREC.ElementType.RGBA:
                return("(" + reader.ReadByte() + "," + reader.ReadByte() + "," + reader.ReadByte() + "," + reader.ReadByte() + ")");

            case GOPGREC.ElementType.FRGB:
            case GOPGREC.ElementType.VECTOR3:
                return("(" + reader.ReadSingle() + "," + reader.ReadSingle() + "," + reader.ReadSingle() + ")");

            case GOPGREC.ElementType.FRGBA:
                return("(" + reader.ReadSingle() + "," + reader.ReadSingle() + "," + reader.ReadSingle() + "," + reader.ReadSingle() + ")");

            case GOPGREC.ElementType.IVECTOR4:
                return("(" + reader.ReadInt32() + "," + reader.ReadInt32() + "," + reader.ReadInt32() + "," + reader.ReadInt32() + ")");

            default:
                throw new Exception("Element \"" + stringTable.Strings[(int)elementInfo.NameIndex] + "\" has unknown type " + (int)elementInfo.Type + ".");
            }
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
0
        private static void WriteElement(BinaryWriter writer, GOPGREC.ElementInfo elementInfo, GENESTRT stringTable, string value)
        {
            switch (elementInfo.Type)
            {
            case GOPGREC.ElementType.ENUM:
                writer.Write(uint.Parse(value));
                break;

            case GOPGREC.ElementType.INT8:
                writer.Write(sbyte.Parse(value));
                break;

            case GOPGREC.ElementType.INT16:
                writer.Write(short.Parse(value));
                break;

            case GOPGREC.ElementType.INT32:
                writer.Write(int.Parse(value));
                break;

            case GOPGREC.ElementType.UINT8:
                writer.Write(byte.Parse(value));
                break;

            case GOPGREC.ElementType.UINT16:
                writer.Write(ushort.Parse(value));
                break;

            case GOPGREC.ElementType.UINT32:
                writer.Write(uint.Parse(value));
                break;

            case GOPGREC.ElementType.FLOAT32:
                writer.Write(float.Parse(value));
                break;

            case GOPGREC.ElementType.BOOL:
                writer.Write(bool.Parse(value));
                break;

            case GOPGREC.ElementType.RECID:
            case GOPGREC.ElementType.STRING:
                writer.Write(stringTable.AddString(value));
                break;

            case GOPGREC.ElementType.RGBA:
                foreach (string component in StringVectorToComponents(value, 4))
                {
                    writer.Write(byte.Parse(component));
                }

                break;

            case GOPGREC.ElementType.FRGB:
            case GOPGREC.ElementType.VECTOR3:
                foreach (string component in StringVectorToComponents(value, 3))
                {
                    writer.Write(float.Parse(component));
                }

                break;

            case GOPGREC.ElementType.FRGBA:
                foreach (string component in StringVectorToComponents(value, 4))
                {
                    writer.Write(float.Parse(component));
                }

                break;

            case GOPGREC.ElementType.IVECTOR4:
                foreach (string component in StringVectorToComponents(value, 4))
                {
                    writer.Write(int.Parse(component));
                }

                break;

            default:
                throw new Exception("Element \"" + stringTable.Strings[(int)elementInfo.NameIndex] + "\" has unknown type " + (int)elementInfo.Type + ".");
            }
        }