コード例 #1
0
        public bool Write(BundleEntry entry)
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            bw.Write(Unknown1);
            long fileSizeOffset = bw.BaseStream.Position;

            bw.Write((int)0);
            bw.Write(Unknown3);
            long section2Offset = bw.BaseStream.Position;

            bw.Write((int)0);
            long streetOffset = bw.BaseStream.Position;

            bw.Write((int)0);
            long roadRuleOffset = bw.BaseStream.Position;

            bw.Write((int)0);
            bw.Write(StreetSection1s.Count);
            bw.Write(StreetSection2s.Count);
            bw.Write(StreetInfos.Count);
            bw.Write(Unknown9);
            bw.Write(Unknown10);
            bw.Write(Unknown11);

            for (int i = 0; i < StreetSection1s.Count; i++)
            {
                StreetSection1 streetSection1 = StreetSection1s[i];

                bw.Write(streetSection1.Unknown1);
                bw.Write(streetSection1.Index);
                bw.Write(streetSection1.Unknown3);
                bw.Write(streetSection1.Unknown4);
                bw.Write(streetSection1.Unknown5);
                bw.Write(streetSection1.Unknown6);
            }

            long newPos = bw.BaseStream.Position;

            bw.BaseStream.Seek(section2Offset, SeekOrigin.Begin);
            bw.Write((int)newPos);

            bw.BaseStream.Seek(newPos, SeekOrigin.Begin);

            for (int i = 0; i < StreetSection2s.Count; i++)
            {
                StreetSection2 section2 = StreetSection2s[i];

                bw.Write(section2.Unknown1);
                bw.Write(section2.ID);
                bw.Write(section2.Unknown3);
                bw.Write(section2.Unknown4);
                bw.Write(section2.Unknown5);
                bw.Write(section2.Unknown6);
                bw.Write(section2.Unknown7);
                bw.Write(section2.Unknown8);
                bw.Write(section2.Unknown9);
                bw.Write(section2.Unknown10);
                bw.Write(section2.Unknown11);
                bw.Write(section2.Unknown12);
            }

            long paddingCount = 16 - (bw.BaseStream.Position % 16);

            bw.BaseStream.Position += paddingCount;

            newPos = bw.BaseStream.Position;
            bw.BaseStream.Seek(streetOffset, SeekOrigin.Begin);
            bw.Write((int)newPos);

            bw.BaseStream.Seek(newPos, SeekOrigin.Begin);

            for (int i = 0; i < StreetInfos.Count; i++)
            {
                StreetInfo section3 = StreetInfos[i];

                bw.Write(section3.Coords);
                bw.Write(section3.Unknown4);

                // TODO: TEMP
                //if (section3.StreetID == 808305)
                //    section3.StreetID = 383595;

                bw.Write(section3.StreetID);
                bw.Write(section3.Unknown6);
                bw.Write(section3.Unknown7);
                bw.Write(Encoding.ASCII.GetBytes(section3.StreetNameID).Pad(20));
                bw.Write(section3.Unknown8);
                bw.Write(section3.Unknown9);  // PC Only
                bw.Write(section3.Unknown10); // PC Only
            }

            newPos = bw.BaseStream.Position;
            bw.BaseStream.Seek(roadRuleOffset, SeekOrigin.Begin);
            bw.Write((int)newPos);

            bw.BaseStream.Seek(newPos, SeekOrigin.Begin);

            for (int i = 0; i < RoadRuleInfos.Count; i++)
            {
                RoadRuleInfo section4 = RoadRuleInfos[i];

                bw.Write(section4.Unknown1);
                bw.Write(section4.Unknown2);
                bw.Write(section4.Time);
                bw.Write(section4.ShowTime);
                bw.Write(section4.Unknown5);
                bw.Write(section4.Unknown6);
            }

            for (int i = 0; i < StreetSection5s.Count; i++)
            {
                StreetSection5 section5 = StreetSection5s[i];

                bw.Write(section5.Section1Index);
                bw.Write(section5.Unknown2);
                bw.Write(section5.Unknown3);
                bw.Write(section5.Unknown4);
            }

            newPos = bw.BaseStream.Position;
            bw.BaseStream.Seek(fileSizeOffset, SeekOrigin.Begin);
            bw.Write((int)newPos);

            bw.Flush();

            byte[] data = ms.ToArray();

            bw.Close();
            ms.Close();

            entry.EntryBlocks[0].Data = data;
            entry.Dirty = true;

            return(true);
        }
コード例 #2
0
        public bool Read(BundleEntry entry, ILoader loader = null)
        {
            Clear();

            MemoryStream  ms = entry.MakeStream();
            BinaryReader2 br = new BinaryReader2(ms);

            br.BigEndian = entry.Console;

            Unknown1       = br.ReadInt32();
            FileSize       = br.ReadInt32();
            Unknown3       = br.ReadInt32();
            Section2Offset = br.ReadInt32();
            StreetOffset   = br.ReadInt32();
            RoadRuleOffset = br.ReadInt32();
            Section1Count  = br.ReadInt32();
            RoadRuleCount  = br.ReadInt32();
            StreetCount    = br.ReadInt32();
            Unknown9       = br.ReadInt32();
            Unknown10      = br.ReadInt32();
            Unknown11      = br.ReadInt32();

            for (int i = 0; i < Section1Count; i++)
            {
                StreetSection1 streetSection1 = new StreetSection1();

                streetSection1.Unknown1 = br.ReadInt32();
                streetSection1.Index    = br.ReadInt16();
                streetSection1.Unknown3 = br.ReadInt32();
                streetSection1.Unknown4 = br.ReadInt16();
                streetSection1.Unknown5 = br.ReadInt16();
                streetSection1.Unknown6 = br.ReadInt16();

                StreetSection1s.Add(streetSection1);
            }

            br.BaseStream.Seek(Section2Offset, SeekOrigin.Begin);

            for (int i = 0; i < RoadRuleCount; i++)
            {
                StreetSection2 section2 = new StreetSection2();

                section2.Unknown1  = br.ReadInt32();
                section2.ID        = br.ReadInt16();
                section2.Unknown3  = br.ReadInt16();
                section2.Unknown4  = br.ReadByte();
                section2.Unknown5  = br.ReadByte();
                section2.Unknown6  = br.ReadInt16();
                section2.Unknown7  = br.ReadInt32();
                section2.Unknown8  = br.ReadInt32();
                section2.Unknown9  = br.ReadInt32();
                section2.Unknown10 = br.ReadInt32();
                section2.Unknown11 = br.ReadInt32();
                section2.Unknown12 = br.ReadInt32();

                StreetSection2s.Add(section2);
            }

            br.BaseStream.Seek(StreetOffset, SeekOrigin.Begin);

            for (int i = 0; i < StreetCount; i++)
            {
                StreetInfo section3 = new StreetInfo();

                section3.Coords       = br.ReadVector3F();
                section3.Unknown4     = br.ReadInt32();
                section3.StreetID     = br.ReadInt64();
                section3.Unknown6     = br.ReadInt64();
                section3.Unknown7     = br.ReadInt64();
                section3.StreetNameID = Encoding.ASCII.GetString(br.ReadBytes(20));
                section3.Unknown8     = br.ReadInt32();

                //if (entry.Console)
                //    section3.Unknown9 = 1;
                //else
                section3.Unknown9  = br.ReadInt32();
                section3.Unknown10 = br.ReadInt32();

                StreetInfos.Add(section3);
            }

            br.BaseStream.Seek(RoadRuleOffset, SeekOrigin.Begin);

            for (int i = 0; i < RoadRuleCount; i++)
            {
                RoadRuleInfo section4 = new RoadRuleInfo();

                section4.Unknown1 = br.ReadInt64();
                section4.Unknown2 = br.ReadInt64();
                section4.Time     = br.ReadInt32();
                section4.ShowTime = br.ReadInt32();
                section4.Unknown5 = br.ReadInt64();
                section4.Unknown6 = br.ReadInt64();

                RoadRuleInfos.Add(section4);
            }

            while (br.BaseStream.Position < FileSize)
            {
                StreetSection5 section5 = new StreetSection5();

                section5.Section1Index = br.ReadInt16();
                section5.Unknown2      = br.ReadInt16();
                section5.Unknown3      = br.ReadInt16();
                section5.Unknown4      = br.ReadInt16();

                StreetSection5s.Add(section5);
            }

            // TODO: TEMP
            //StreetInfo info1 = result.StreetInfos[1];
            //StreetInfo info70 = result.StreetInfos[70];
            //result.StreetInfos[1] = info70;
            //result.StreetInfos[70] = info1;
            //result.Write(entry);

            return(true);
        }