Пример #1
0
        private void ReadMapFilesSection(EndianReader reader)
        {
            var section = GetSectionHeader(reader, ModPackageSection.MapFiles);

            if (!GoToSectionHeaderOffset(reader, section))
            {
                return;
            }

            var entry    = new GenericSectionEntry(reader);
            var mapCount = entry.Count;

            MapFileStreams    = new List <Stream>();
            MapToCacheMapping = new Dictionary <int, int>();

            for (int i = 0; i < mapCount; i++)
            {
                reader.BaseStream.Position = entry.TableOffset + 0x10 * i + section.Offset;
                var tableEntry = new CacheMapTableEntry(reader);

                reader.BaseStream.Position = tableEntry.Offset + section.Offset;

                MapToCacheMapping.Add(i, tableEntry.CacheIndex);
                int    size   = (int)section.Size;
                var    stream = new MemoryStream();
                byte[] data   = new byte[size];
                reader.Read(data, 0, size);
                stream.Write(data, 0, size);
                MapFileStreams.Add(stream);
            }
        }
Пример #2
0
        private void WriteMapsSection(EndianWriter writer)
        {
            uint sectionOffset           = (uint)writer.BaseStream.Position;
            GenericSectionEntry mapEntry = new GenericSectionEntry(MapFileStreams.Count, 0x8);

            mapEntry.Write(writer);
            // make room for table

            writer.Write(new byte[0x10 * mapEntry.Count]);

            for (int i = 0; i < MapFileStreams.Count; i++)
            {
                var  mapFileStream = MapFileStreams[i];
                uint offset        = (uint)writer.BaseStream.Position;
                int  size          = (int)mapFileStream.Length;

                mapFileStream.Position = 0;
                StreamUtil.Copy(mapFileStream, writer.BaseStream, (int)mapFileStream.Length);
                StreamUtil.Align(writer.BaseStream, 4);

                // seek to the table and update size and offset
                writer.BaseStream.Seek(mapEntry.TableOffset + 0x10 * i + sectionOffset, SeekOrigin.Begin);
                var tableEntry = new CacheMapTableEntry(size, offset - sectionOffset, MapToCacheMapping[i], MapIds[i]);
                tableEntry.Write(writer);
                writer.BaseStream.Seek(0, SeekOrigin.End);
            }

            writer.BaseStream.Seek(0, SeekOrigin.End);
        }