Describes a tag in a tag cache.
Exemple #1
0
 private static int CompareTags(TagInstance lhs, TagInstance rhs)
 {
     var classCompare = lhs.Group.Tag.CompareTo(rhs.Group.Tag);
     if (classCompare != 0)
         return classCompare;
     return lhs.Index.CompareTo(rhs.Index);
 }
        private bool ImportAnimationResource(TagInstance tagIndex, string cachePath, string dataPath)
        {
            ModelAnimationGraph animation;
            ResourceCache resourceCache;
            uint compressedSize = 0;
            var data = File.ReadAllBytes(dataPath);

            using (var cacheStream = _info.OpenCacheReadWrite())
            {
                var tagContext = new TagSerializationContext(cacheStream, _info.Cache, _info.StringIDs, tagIndex);
                animation = _info.Deserializer.Deserialize<ModelAnimationGraph>(tagContext);
            }
            using (var stream = File.Open(_info.CacheFile.DirectoryName + "\\" + cachePath, FileMode.Open, FileAccess.ReadWrite))
            {
                resourceCache = new ResourceCache(stream);
                animation.ResourceGroups[0].Resource.Index = resourceCache.Add(stream, data, out compressedSize);
                animation.ResourceGroups[0].Resource.CompressedSize = compressedSize;
                animation.ResourceGroups[0].Resource.OldLocationFlags = (OldResourceLocationFlags)2;
            }
            using (var cacheStream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite))
            {
                var context = new TagSerializationContext(cacheStream, _cache, _stringIds, tagIndex);
                _info.Serializer.Serialize(context, animation);
            }
            Console.WriteLine("{1}: Imported 0x{0}.", compressedSize, tagIndex);
            return true;
        }
 /// <summary>
 /// Creates a tag serialization context which serializes data into a tag.
 /// </summary>
 /// <param name="stream">The stream to write to.</param>
 /// <param name="cache">The cache file to write to.</param>
 /// <param name="stringIds">The stringID source to use.</param>
 /// <param name="tag">The tag to overwrite.</param>
 public TagSerializationContext(Stream stream, TagCache cache, StringIDCache stringIds, TagInstance tag)
 {
     _stream = stream;
     _cache = cache;
     _stringIds = stringIds;
     Tag = tag;
 }
Exemple #4
0
 /// <summary>
 /// Allocates a new tag at the end of the tag list without updating the file.
 /// You can give the tag data by using one of the overwrite functions.
 /// </summary>
 /// <param name="type">The tag's type information.</param>
 /// <returns>The allocated tag.</returns>
 public TagInstance AllocateTag(TagGroup type)
 {
     var tagIndex = _tags.Count;
     var tag = new TagInstance(tagIndex, type);
     _tags.Add(tag);
     return tag;
 }
 public static void Populate(CommandContext context, OpenTagCache info, TagInstance tag, VFilesList vfsl)
 {
     context.AddCommand(new ListCommand(vfsl));
     context.AddCommand(new ExtractCommand(vfsl));
     context.AddCommand(new ExtractAllCommand(vfsl));
     context.AddCommand(new ImportCommand(info, tag, vfsl));
     context.AddCommand(new ImportAllCommand(info, tag, vfsl));
 }
        public static void Populate(CommandContext context, OpenTagCache info, TagInstance tag, MultilingualUnicodeStringList unic)
        {
            if (info.StringIDs == null)
                return;

            context.AddCommand(new ListCommand(info, unic));
            context.AddCommand(new GetCommand(info, tag, unic));
            context.AddCommand(new SetCommand(info, tag, unic));
        }
        public static CommandContext Create(CommandContext parent, OpenTagCache info, TagInstance tag, VFilesList vfsl)
        {
            var groupName = info.StringIDs.GetString(tag.Group.Name);

            var context = new CommandContext(parent,
                string.Format("{0:X8}.{1}", tag.Index, groupName));

            return context;
        }
        public static CommandContext Create(CommandContext parent, OpenTagCache info, TagInstance tag, RenderMethod renderMethod)
        {
            var groupName = info.StringIDs.GetString(tag.Group.Name);

            var context = new CommandContext(parent,
                string.Format("{0:X8}.{1}", tag.Index, groupName));

            Populate(context, info, tag, renderMethod);

            return context;
        }
 public SpecifyBitmapsCommand(OpenTagCache info, TagInstance tag, RenderMethod definition)
     : base(CommandFlags.Inherit,
          "specifybitmaps",
          "Allows the bitmaps of the render_method to be respecified.",
          "specifybitmaps",
          "Allows the bitmaps of the render_method to be respecified.")
 {
     Info = info;
     Tag = tag;
     Definition = definition;
 }
 public GetResourceCommand(OpenTagCache info, TagInstance tag, RenderModel definition)
     : base(CommandFlags.None,
           "getresource",
           "",
           "getresource",
           "")
 {
     Info = info;
     Tag = tag;
     Definition = definition;
 }
 public GetResourcesCommand(OpenTagCache info, TagInstance tag, ModelAnimationGraph definition)
     : base(CommandFlags.None,
           "getresources",
           "",
           "getresources",
           "")
 {
     Info = info;
     Tag = tag;
     Definition = definition;
 }
        public static CommandContext Create(CommandContext parent, OpenTagCache info, TagInstance tag, MultilingualUnicodeStringList unic)
        {
            var groupName = info.StringIDs.GetString(tag.Group.Name);

            var context = new CommandContext(parent,
                string.Format("{0:X8}.{1}", tag.Index, groupName));

            Populate(context, info, tag, unic);

            return context;
        }
 public LoadResourcesCommand(OpenTagCache info, TagInstance tag, ScenarioStructureBsp bsp)
     : base(CommandFlags.Inherit,
           "loadresources",
           "",
           "loadresources",
           "")
 {
     Info = info;
     Tag = tag;
     BSP = bsp;
 }
 public ListBitmapsCommand(OpenTagCache info, TagInstance tag, RenderMethod definition)
     : base(CommandFlags.Inherit,
          "listbitmaps",
          "Lists the bitmaps used by the render_method.",
          "listbitmaps",
          "Lists the bitmaps used by the render_method.")
 {
     Info = info;
     Tag = tag;
     Definition = definition;
 }
 public SpecifyShadersCommand(OpenTagCache info, TagInstance tag, RenderModel definition)
     : base(CommandFlags.Inherit,
           "specifyshaders",
           "Allows the shaders of a render_model to be respecified.",
           "specifyshaders",
           "Allows the shaders of a render_model to be respecified.")
 {
     Info = info;
     Tag = tag;
     Definition = definition;
 }
Exemple #16
0
 public GetCommand(OpenTagCache info, TagInstance tag, MultilingualUnicodeStringList unic)
     : base(CommandFlags.Inherit,
           "get",
           "",
           "get <language> <string_id>",
           "")
 {
     Info = info;
     Tag = tag;
     Definition = unic;
 }
 public ImportAllCommand(OpenTagCache info, TagInstance tag, VFilesList definition)
     : base(CommandFlags.None,
           "importall",
           "Replace all files stored in the tag",
           "importall [directory]",
           "Replaces all file stored in the tag. The tag will be resized as necessary.\n" +
           "If no directory is specified, files will be loaded from the current directory.")
 {
     Info = info;
     Tag = tag;
     Definition = definition;
 }
Exemple #18
0
 public ImportCommand(OpenTagCache info, TagInstance tag, Bitmap bitmap)
     : base(CommandFlags.None,
           "import",
           "Imports an image from a DDS file.",
           "import <image index> <path>",
           "The image index must be in hexadecimal.\n" +
           "No conversion will be done on the data in the DDS file.\n" +
           "The pixel format must be supported by the game.")
 {
     Info = info;
     Tag = tag;
     Bitmap = bitmap;
 }
 public EditBlockCommand(CommandContextStack stack, OpenTagCache info, TagInstance tag, object value)
     : base(CommandFlags.Inherit,
           "edit",
           "Edit the fields of a particular block element.",
           "edit <block name> [block index (if block)]",
           "Edit the fields of a particular block element.")
 {
     Info = info;
     Stack = stack;
     Tag = tag;
     Structure = new TagStructureInfo(value.GetType(), Info.Version);
     Owner = value;
 }
 public PasteElementsCommand(CommandContextStack stack, OpenTagCache info, TagInstance tag, TagStructureInfo structure, object owner)
     : base(CommandFlags.Inherit,
           "pasteelements",
           $"Pastes block element(s) to a specific tag block in the current {structure.Types[0].Name} definition.",
           "pasteelements <tag block name> [index = *]",
           $"Pastes block element(s) to a specific tag block in the current {structure.Types[0].Name} definition.")
 {
     Stack = stack;
     Info = info;
     Tag = tag;
     Structure = structure;
     Owner = owner;
 }
 public SetFieldCommand(CommandContextStack stack, OpenTagCache info, TagInstance tag, TagStructureInfo structure, object owner)
     : base(CommandFlags.Inherit,
           "setfield",
           $"Sets the value of a specific field in the current {structure.Types[0].Name} definition.",
           "setfield <field name> <field value>",
           $"Sets the value of a specific field in the current {structure.Types[0].Name} definition.")
 {
     Stack = stack;
     Info = info;
     Tag = tag;
     Structure = structure;
     Owner = owner;
 }
Exemple #22
0
 public SetCommand(OpenTagCache info, TagInstance tag, MultilingualUnicodeStringList unic)
     : base(CommandFlags.None,
           "set",
           "Set the value of a string",
           "set <language> <stringid> <value>",
           "Sets the string associated with a stringID in a language.\n" +
           "Remember to put the string value in quotes if it contains spaces.\n" +
           "If the string does not exist, it will be added.")
 {
     Info = info;
     Tag = tag;
     Definition = unic;
 }
 public RemoveFromCommand(CommandContextStack stack, OpenTagCache info, TagInstance tag, TagStructureInfo structure, object owner)
     : base(CommandFlags.Inherit,
           "removefrom",
           $"Removes block element(s) from a specified index of a specific tag block in the current {structure.Types[0].Name} definition.",
           "removefrom <tag block name> [* | <tag block index> [* | amount = 1]]",
           $"Removes block element(s) from a specified index of a specific tag block in the current {structure.Types[0].Name} definition.")
 {
     Stack = stack;
     Info = info;
     Tag = tag;
     Structure = structure;
     Owner = owner;
 }
Exemple #24
0
        private void ImportTagInstance(TagInstance instance, string path)
        {
            byte[] data;

            using (var inStream = File.OpenRead(path))
            {
                data = new byte[inStream.Length];
                inStream.Read(data, 0, data.Length);
            }

            using (var stream = Info.OpenCacheReadWrite())
                Info.Cache.SetTagDataRaw(stream, instance, data);

            Console.WriteLine($"Imported 0x{data.Length:X} bytes.");
        }
        private void ExtractTagInstance(TagInstance tag, string path)
        {
            var info = new FileInfo(path);

            if (!info.Directory.Exists)
                info.Directory.Create();

            byte[] data;

            using (var stream = Info.OpenCacheRead())
                data = Info.Cache.ExtractTagRaw(stream, tag);

            using (var outStream = File.Open(path, FileMode.Create, FileAccess.Write))
            {
                outStream.Write(data, 0, data.Length);
                Console.WriteLine("Wrote 0x{0:X} bytes to {1}.", outStream.Position, path);
                Console.WriteLine("The tag's main struct will be at offset 0x{0:X}.", tag.MainStructOffset);
            }
        }
        private bool ExecuteAddRemove(TagInstance tag, List<string> args)
        {
            if (args.Count < 3)
                return false;

            var dependencies = args.Skip(2).Select(a => ArgumentParser.ParseTagIndex(Info, a)).ToList();

            if (dependencies.Count == 0 || dependencies.Any(d => d == null))
                return false;

            using (var stream = Info.OpenCacheReadWrite())
            {
                var data = Info.Cache.ExtractTag(stream, tag);

                if (args[0] == "add")
                {
                    foreach (var dependency in dependencies)
                    {
                        if (data.Dependencies.Add(dependency.Index))
                            Console.WriteLine("Added dependency on tag {0:X8}.", dependency.Index);
                        else
                            Console.Error.WriteLine("Tag {0:X8} already depends on tag {1:X8}.", tag.Index, dependency.Index);
                    }
                }
                else
                {
                    foreach (var dependency in dependencies)
                    {
                        if (data.Dependencies.Remove(dependency.Index))
                            Console.WriteLine("Removed dependency on tag {0:X8}.", dependency.Index);
                        else
                            Console.Error.WriteLine("Tag {0:X8} does not depend on tag {1:X8}.", tag.Index, dependency.Index);
                    }
                }

                Info.Cache.SetTagData(stream, tag, data);
            }

            return true;
        }
Exemple #27
0
 /// <summary>
 /// Serializes a tag reference.
 /// </summary>
 /// <param name="writer">The writer to write to.</param>
 /// <param name="referencedTag">The referenced tag.</param>
 /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param>
 private static void SerializeTagReference(BinaryWriter writer, TagInstance referencedTag, TagFieldAttribute valueInfo)
 {
     // Write the reference out
     if (valueInfo == null || (valueInfo.Flags & TagFieldFlags.Short) == 0)
     {
         writer.Write((referencedTag != null) ? referencedTag.Group.Tag.Value : -1);
         writer.Write(0);
         writer.Write(0);
     }
     writer.Write((referencedTag != null) ? referencedTag.Index : -1);
 }
 public static void Populate(CommandContext context, OpenTagCache info, TagInstance tag, ScenarioStructureBsp bsp)
 {
     context.AddCommand(new LoadResourcesCommand(info, tag, bsp));
 }
        private bool ImportBitmapResource(TagInstance tagIndex, string cachePath, string dataPath)
        {
            Bitmap bitmap;
            ResourceCache resourceCache;
            uint compressedSize = 0;

            using (var cacheStream = _info.OpenCacheRead())
            {
                var tagContext = new TagSerializationContext(cacheStream, _info.Cache, _info.StringIDs, tagIndex);
                bitmap = _info.Deserializer.Deserialize<Bitmap>(tagContext);
            }
            using (var stream = File.Open(_info.CacheFile.DirectoryName + "\\" + cachePath, FileMode.Open, FileAccess.ReadWrite))
            {
                int imageIndex = 0;
                foreach (string file in Directory.EnumerateFiles(dataPath, "*.bitm"))
                {
                    byte[] inBitmapData = File.ReadAllBytes(file);
                    resourceCache = new ResourceCache(stream);
                    bitmap.Resources[imageIndex].Resource.Index = resourceCache.Add(stream, inBitmapData, out compressedSize);
                    bitmap.Resources[imageIndex].Resource.CompressedSize = compressedSize;
                    imageIndex++;
                }
            }
            using (var cacheStream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite))
            {
                var context = new TagSerializationContext(cacheStream, _cache, _stringIds, tagIndex);
                _info.Serializer.Serialize(context, bitmap);
            }
            Console.WriteLine("{1}: Imported 0x{0}.", compressedSize, tagIndex);
            return true;
        }
 public static void Populate(CommandContext context, OpenTagCache info, TagInstance tag, RenderMethod renderMethod)
 {
     context.AddCommand(new ListArgumentsCommand(info, tag, renderMethod));
     context.AddCommand(new ListBitmapsCommand(info, tag, renderMethod));
     context.AddCommand(new SpecifyBitmapsCommand(info, tag, renderMethod));
 }