Beispiel #1
0
        private void WriteTagNamesSection(EndianWriter writer, DataSerializationContext context, TagSerializer serializer)
        {
            uint sectionOffset = (uint)writer.BaseStream.Position;
            GenericSectionEntry tagNameFileEntry = new GenericSectionEntry(TagCacheNames.Count, 0x8);

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

            writer.Write(new byte[0x8 * TagCacheNames.Count]);

            for (int i = 0; i < TagCacheNames.Count; i++)
            {
                //prepare tag names
                var names = new Dictionary <int, string>();

                foreach (var entry in TagCaches[i].TagTable)
                {
                    if (entry != null && entry.Name != null)
                    {
                        names.Add(entry.Index, entry.Name);
                    }
                }

                uint offset = (uint)writer.BaseStream.Position;

                GenericSectionEntry tagNameTable = new GenericSectionEntry(names.Count, offset - sectionOffset + 0x8);
                tagNameTable.Write(writer);

                foreach (var entry in names)
                {
                    var tagNameEntry = new ModPackageTagNamesEntry(entry.Key, entry.Value);
                    serializer.Serialize(context, tagNameEntry);
                }

                uint size = (uint)(writer.BaseStream.Position - offset);

                writer.BaseStream.Seek(tagNameFileEntry.TableOffset + 0x8 * i + sectionOffset, SeekOrigin.Begin);
                var tableEntry = new GenericTableEntry(size, offset - sectionOffset);
                tableEntry.Write(writer);
                writer.BaseStream.Seek(0, SeekOrigin.End);
            }
        }
Beispiel #2
0
        private void WriteTagNamesSection(EndianWriter writer, DataSerializationContext context, TagSerializer serializer)
        {
            //prepare tag names
            var names = new Dictionary <int, string>();

            foreach (var entry in Tags.Index)
            {
                if (entry != null && entry.Name != null)
                {
                    names.Add(entry.Index, entry.Name);
                }
            }

            // create entry and immediatly write the tag names table
            GenericSectionEntry mapEntry = new GenericSectionEntry(names.Count, (int)writer.BaseStream.Position + 0x8);

            mapEntry.Write(writer);

            foreach (var entry in names)
            {
                var tagNameEntry = new ModPackageTagNamesEntry(entry.Key, entry.Value);
                serializer.Serialize(context, tagNameEntry);
            }
        }