Esempio n. 1
0
        /// <summary>
        ///     Adds a tag to the table and allocates space for its base data.
        /// </summary>
        /// <param name="classMagic">The magic number (ID) of the tag's class.</param>
        /// <param name="baseSize">The size of the data to initially allocate for the tag.</param>
        /// <param name="stream">The stream to write to.</param>
        /// <returns>
        ///     The tag that was allocated.
        /// </returns>
        public override ITag AddTag(int classMagic, int baseSize, IStream stream)
        {
            if (_indexHeaderLocation == null)
            {
                throw new InvalidOperationException("Tags cannot be added to a shared map");
            }

            ITagClass tagClass = Classes.FirstOrDefault(c => (c.Magic == classMagic));

            if (tagClass == null)
            {
                throw new InvalidOperationException("Invalid tag class");
            }

            uint address = _allocator.Allocate(baseSize, stream);
            var  index   = new DatumIndex(0x4153, (ushort)_tags.Count);           // 0x4153 = 'AS' because the salt doesn't matter
            var  result  = new ThirdGenTag(index, tagClass, SegmentPointer.FromPointer(address, _metaArea));

            _tags.Add(result);

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        ///     Adds a tag to the table and allocates space for its base data.
        /// </summary>
        /// <param name="classMagic">The magic number (ID) of the tag's class.</param>
        /// <param name="baseSize">The size of the data to initially allocate for the tag.</param>
        /// <param name="stream">The stream to write to.</param>
        /// <returns>
        ///     The tag that was allocated.
        /// </returns>
        public override ITag AddTag(int classMagic, int baseSize, IStream stream)
        {
            if (_indexHeaderLocation == null)
                throw new InvalidOperationException("Tags cannot be added to a shared map");

            ITagClass tagClass = Classes.FirstOrDefault(c => (c.Magic == classMagic));
            if (tagClass == null)
                throw new InvalidOperationException("Invalid tag class");

            uint address = _allocator.Allocate(baseSize, stream);
            var index = new DatumIndex(0x4153, (ushort) _tags.Count); // 0x4153 = 'AS' because the salt doesn't matter
            var result = new ThirdGenTag(index, tagClass, SegmentPointer.FromPointer(address, _metaArea));
            _tags.Add(result);

            return result;
        }