Ejemplo n.º 1
0
        public DatumIndex InjectTag(ExtractedTag tag, IStream stream)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag is null");
            }

            // Don't inject the tag if it's already been injected
            DatumIndex newIndex;

            if (_tagIndices.TryGetValue(tag, out newIndex))
            {
                return(newIndex);
            }

            // Make sure there isn't already a tag with the given name
            ITag existingTag = _cacheFile.Tags.FindTagByName(tag.Name, tag.Class, _cacheFile.FileNames);

            if (existingTag != null)
            {
                return(existingTag.Index);
            }

            // Look up the tag's datablock to get its size and allocate a tag for it
            DataBlock tagData = _container.FindDataBlock(tag.OriginalAddress);

            if (_resources == null && BlockNeedsResources(tagData))
            {
                // If the tag relies on resources and that info isn't available, throw it out
                LoadResourceTable(stream);
                if (_resources == null)
                {
                    return(DatumIndex.Null);
                }
            }

            ITag newTag = _cacheFile.Tags.AddTag(tag.Class, tagData.Data.Length, stream);

            _tagIndices[tag] = newTag.Index;
            _cacheFile.FileNames.SetTagName(newTag, tag.Name);

            // Write the data
            WriteDataBlock(tagData, newTag.MetaLocation, stream);

            // Make the tag load
            LoadZoneSets(stream);
            if (_zoneSets != null && _zoneSets.GlobalZoneSet != null)
            {
                _zoneSets.GlobalZoneSet.ActivateTag(newTag, true);
            }

            return(newTag.Index);
        }
Ejemplo n.º 2
0
        public DatumIndex InjectTag(ExtractedTag tag, IStream stream)
        {
            string tagnameuniqifier = "";

            if (tag == null)
            {
                throw new ArgumentNullException("tag is null");
            }

            // Don't inject the tag if it's already been injected
            DatumIndex newIndex;

            if (_tagIndices.TryGetValue(tag, out newIndex))
            {
                return(newIndex);
            }

            // Make sure there isn't already a tag with the given name
            ITag existingTag = _cacheFile.Tags.FindTagByName(tag.Name, tag.Group, _cacheFile.FileNames);

            if (existingTag != null)
            {
                //check if we are doing shader tweaks
                if (_renameShaders && _shaderGroups.Contains(CharConstant.ToString(tag.Group)))
                {
                    //append old tagid to make it unique
                    tagnameuniqifier = "_" + tag.OriginalIndex.ToString();

                    //make sure the tag didnt come from this exact map
                    if (existingTag.Index == tag.OriginalIndex)
                    {
                        return(existingTag.Index);
                    }

                    //make sure the appended name isn't already present
                    existingTag = _cacheFile.Tags.FindTagByName(tag.Name + tagnameuniqifier, tag.Group, _cacheFile.FileNames);

                    if (existingTag != null)
                    {
                        return(existingTag.Index);
                    }
                }
                else
                {
                    return(existingTag.Index);
                }
            }

            if (!_keepSound && tag.Group == SoundGroup)
            {
                return(DatumIndex.Null);
            }

            //PCA resource type is not always present, so get rid of 'em for now
            if (tag.Group == PCAGroup)
            {
                return(DatumIndex.Null);
            }

            // Look up the tag's datablock to get its size and allocate a tag for it
            DataBlock tagData = _container.FindDataBlock(tag.OriginalAddress);

            if (_resources == null && BlockNeedsResources(tagData))
            {
                // If the tag relies on resources and that info isn't available, throw it out
                LoadResourceTable(stream);
                if (_resources == null)
                {
                    return(DatumIndex.Null);
                }
            }
            if (_soundResources == null && BlockNeedsSounds(tagData))
            {
                // If the tag relies on sound resources and that info isn't available, throw it out
                LoadSoundResourceTable(stream);
                if (_soundResources == null)
                {
                    return(DatumIndex.Null);
                }
            }

            ITag newTag = _cacheFile.Tags.AddTag(tag.Group, tagData.Data.Length, stream);

            _tagIndices[tag] = newTag.Index;
            _cacheFile.FileNames.SetTagName(newTag, tag.Name + tagnameuniqifier);

            // Write the data
            WriteDataBlock(tagData, newTag.MetaLocation, stream, newTag);

            // Make the tag load
            LoadZoneSets(stream);
            if (_zoneSets != null)
            {
                _zoneSets.ExpandAllTags(newTag.Index.Index);
                if (_zoneSets.GlobalZoneSet != null)
                {
                    _zoneSets.GlobalZoneSet.ActivateTag(newTag, true);
                }
            }

            // If its group matches one of the valid simulation group names, add it to the simulation definition table
            if (_cacheFile.SimulationDefinitions != null && _simulationGroups.Contains(CharConstant.ToString(newTag.Group.Magic)))
            {
                _cacheFile.SimulationDefinitions.Add(newTag);
            }

            return(newTag.Index);
        }
Ejemplo n.º 3
0
        public DatumIndex InjectTag(ExtractedTag tag, IStream stream)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag is null");
            }

            // Don't inject the tag if it's already been injected
            DatumIndex newIndex;

            if (_tagIndices.TryGetValue(tag, out newIndex))
            {
                return(newIndex);
            }

            // Make sure there isn't already a tag with the given name
            ITag existingTag = _cacheFile.Tags.FindTagByName(tag.Name, tag.Class, _cacheFile.FileNames);

            if (existingTag != null)
            {
                return(existingTag.Index);
            }

            // If the tag has made it this far but is a sound, make everyone (especially gerit) shut up.
            if (tag.Class == SoundClass)
            {
                return(DatumIndex.Null);
            }

            // Look up the tag's datablock to get its size and allocate a tag for it
            DataBlock tagData = _container.FindDataBlock(tag.OriginalAddress);

            if (_resources == null && BlockNeedsResources(tagData))
            {
                // If the tag relies on resources and that info isn't available, throw it out
                LoadResourceTable(stream);
                if (_resources == null)
                {
                    return(DatumIndex.Null);
                }
            }

            ITag newTag = _cacheFile.Tags.AddTag(tag.Class, tagData.Data.Length, stream);

            _tagIndices[tag] = newTag.Index;
            _cacheFile.FileNames.SetTagName(newTag, tag.Name);

            // Write the data
            WriteDataBlock(tagData, newTag.MetaLocation, stream, newTag);

            // Make the tag load
            LoadZoneSets(stream);
            if (_zoneSets != null && _zoneSets.GlobalZoneSet != null)
            {
                _zoneSets.GlobalZoneSet.ActivateTag(newTag, true);
            }

            // If its class matches one of the valid simulation class names, add it to the simulation definition table
            if (_cacheFile.SimulationDefinitions != null && _simulationClasses.Contains(CharConstant.ToString(newTag.Class.Magic)))
            {
                _cacheFile.SimulationDefinitions.Add(newTag);
            }

            return(newTag.Index);
        }