Beispiel #1
0
        public static void Write(Stream stream, Pmp pmp)
        {
            stream.Position = 0;
            BinaryMapping.WriteObject <Header>(stream, pmp.header);

            for (int i = 0; i < pmp.objectInfo.Count; i++)
            {
                BinaryMapping.WriteObject <ObjectInfo>(stream, pmp.objectInfo[i]);
            }

            List <Pmo> nPmoList = pmp.PmoList;

            nPmoList.Sort((l, r) => l.PMO_StartPosition.CompareTo(r.PMO_StartPosition));

            for (int p = 0; p < nPmoList.Count; p++)
            {
                uint off = (uint)stream.Position;
                stream.Seek(0x44 + (p * 0x30), SeekOrigin.Begin);
                stream.Write(off);
                stream.Seek(0, SeekOrigin.End);

                BinaryMapping.WriteObject <Pmo.Header>(stream, nPmoList[p].header);

                for (int g = 0; g < nPmoList[p].textureInfo.Length; g++)
                {
                    BinaryMapping.WriteObject <Pmo.TextureInfo>(stream, nPmoList[p].textureInfo[g]);
                }

                Pmo.WriteMeshData(stream, nPmoList[p]);
            }

            uint pos = (uint)stream.Position;

            stream.Seek(0x1C, SeekOrigin.Begin);
            stream.Write(pos);
            stream.Seek(0, SeekOrigin.End);

            for (int tl = 0; tl < pmp.TextureList.Count; tl++)
            {
                BinaryMapping.WriteObject <PMPTextureInfo>(stream, pmp.TextureList[tl]);
            }

            for (int td = 0; td < pmp.TextureList.Count; td++)
            {
                uint       sPos = (uint)stream.Position;
                List <Tm2> l    = new List <Tm2>();
                l.Add(pmp.TextureDataList[td]);
                Tm2.Write(stream, l);

                stream.Seek(pos + (td * 0x20), SeekOrigin.Begin);
                stream.Write(sPos);
                stream.Seek(0, SeekOrigin.End);
            }
        }
Beispiel #2
0
        public static Pmp Read(Stream stream)
        {
            Pmp pmp = new Pmp();

            pmp.header = BinaryMapping.ReadObject <Header>(stream);

            // Read Object List.
            for (int i = 0; i < pmp.header.ObjectCount; i++)
            {
                pmp.objectInfo.Add(Mapping.ReadObject <ObjectInfo>(stream));
                pmp.hasDifferentMatrix.Add(BitsUtil.Int.GetBit(pmp.objectInfo[i].ObjectFlags, 0));
            }

            // Read PMO list.
            for (int p = 0; p < pmp.header.ObjectCount; p++)
            {
                ObjectInfo currentPmoInfo = pmp.objectInfo[p];
                if (currentPmoInfo.PMO_Offset != 0)
                {
                    stream.Seek(currentPmoInfo.PMO_Offset, SeekOrigin.Begin);
                    pmp.PmoList.Add(Pmo.Read(stream));
                }
                else
                {
                    pmp.PmoList.Add(null);
                }
            }

            stream.Seek(pmp.header.TextureListOffset, SeekOrigin.Begin);

            for (int t = 0; t < pmp.header.TextureCount; t++)
            {
                pmp.TextureList.Add(BinaryMapping.ReadObject <PMPTextureInfo>(stream));
            }

            // Read textures.
            for (int k = 0; k < pmp.TextureList.Count; k++)
            {
                stream.Seek(pmp.TextureList[k].Offset + 0x10, SeekOrigin.Begin);
                uint tm2size = stream.ReadUInt32() + 0x10;
                stream.Seek(pmp.TextureList[k].Offset, SeekOrigin.Begin);

                pmp.TextureDataList.Add(Tm2.Read(stream, true).First());
            }

            return(pmp);
        }
Beispiel #3
0
        public static void Write(Stream stream, Pmp pmp)
        {
            stream.Position = 0;
            BinaryMapping.WriteObject <Header>(stream, pmp.header);

            for (int i = 0; i < pmp.objectInfo.Count; i++)
            {
                BinaryMapping.WriteObject <ObjectInfo>(stream, pmp.objectInfo[i]);
            }

            List <Pmo> nPmoList = pmp.PmoList;

            nPmoList.Sort((l, r) => l.PMO_StartPosition.CompareTo(r.PMO_StartPosition));

            for (int p = 0; p < nPmoList.Count; p++)
            {
                BinaryMapping.WriteObject <Pmo.Header>(stream, nPmoList[p].header);

                for (int g = 0; g < nPmoList[p].textureInfo.Length; g++)
                {
                    BinaryMapping.WriteObject <Pmo.TextureInfo>(stream, nPmoList[p].textureInfo[g]);
                }

                Pmo.WriteMeshData(stream, nPmoList[p]);
            }

            for (int tl = 0; tl < pmp.TextureList.Count; tl++)
            {
                BinaryMapping.WriteObject <PMPTextureInfo>(stream, pmp.TextureList[tl]);
            }

            for (int td = 0; td < pmp.TextureList.Count; td++)
            {
                List <Tm2> l = new List <Tm2>();
                l.Add(pmp.TextureDataList[td]);
                Tm2.Write(stream, l);
            }
        }