public static CommandContext Create(CommandContext parent, OpenTagCache info, HaloTag tag, Model model)
 {
     var context = new CommandContext(parent, string.Format("{0:X8}.hlmt", tag.Index));
     context.AddCommand(new HlmtListVariantsCommand(info, model));
     context.AddCommand(new HlmtExtractModeCommand(info, model));
     return context;
 }
        private bool ExecuteListDependsOn(HaloTag tag)
        {
            var dependsOn = _cache.Tags.Where(t => t != null && t.Dependencies.Contains(tag.Index));

            TagPrinter.PrintTagsShort(dependsOn);
            return(true);
        }
Esempio n. 3
0
 private static bool CheckWriteOffset(HaloTag tag, uint writeOffset)
 {
     if (writeOffset < tag.Size)
         return true;
     Console.Error.WriteLine("Invalid write offset: cannot write past the end of the tag.");
     return false;
 }
Esempio n. 4
0
 private static bool CheckTargetOffset(HaloTag tag, uint targetOffset)
 {
     if (targetOffset < tag.Size)
         return true;
     Console.Error.WriteLine("Invalid target offset: cannot point to something outside the tag.");
     return false;
 }
Esempio n. 5
0
 private static int CompareTags(HaloTag lhs, HaloTag rhs)
 {
     var classCompare = lhs.Class.CompareTo(rhs.Class);
     if (classCompare != 0)
         return classCompare;
     return lhs.Index.CompareTo(rhs.Index);
 }
 private bool ExecuteAddRemove(HaloTag tag, List<string> args)
 {
     if (args.Count < 3)
         return false;
     var dependencies = args.Skip(2).Select(a => ArgumentParser.ParseTagIndex(_cache, a)).ToList();
     if (dependencies.Count == 0 || dependencies.Any(d => d == null))
         return false;
     if (args[0] == "add")
     {
         foreach (var dependency in dependencies)
         {
             if (tag.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 (tag.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);
         }
     }
     using (var stream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite))
         _cache.UpdateTag(stream, tag);
     return true;
 }
        public override bool Execute(List <string> args)
        {
            if (args.Count != 2)
            {
                return(false);
            }
            var outDir = args[1];
            ITagLayoutWriter writer;

            switch (args[0])
            {
            case "csharp":
                writer = new CSharpClassWriter(_stringIds, outDir);
                break;

            case "cpp":
                writer = new CppStructWriter(_stringIds, outDir);
                break;

            default:
                return(false);
            }
            Directory.CreateDirectory(outDir);
            var count = 0;

            using (var stream = _fileInfo.OpenRead())
            {
                foreach (var tagClass in _cache.TagClasses)
                {
                    TagLayoutGuess layout  = null;
                    HaloTag        lastTag = null;
                    foreach (var tag in _cache.Tags.FindAllByClass(tagClass))
                    {
                        Console.Write("Analyzing ");
                        TagPrinter.PrintTagShort(tag);

                        lastTag = tag;
                        var analyzer  = new TagAnalyzer(_cache, tag);
                        var data      = _cache.ExtractTag(stream, tag);
                        var tagLayout = analyzer.Analyze(data);
                        if (layout != null)
                        {
                            layout.Merge(tagLayout);
                        }
                        else
                        {
                            layout = tagLayout;
                        }
                    }
                    if (layout != null && lastTag != null)
                    {
                        Console.WriteLine("Writing {0} layout", tagClass);
                        LayoutGuessWriter.Write(lastTag, layout, writer);
                        count++;
                    }
                }
            }
            Console.WriteLine("Successfully generated {0} layouts!", count);
            return(true);
        }
 public static CommandContext Create(CommandContext parent, FileInfo fileInfo, TagCache cache, StringIdCache stringIds, HaloTag tag, Model model)
 {
     var context = new CommandContext(parent, string.Format("{0:X8}.hlmt", tag.Index));
     context.AddCommand(new HlmtListVariantsCommand(model, stringIds));
     context.AddCommand(new HlmtExtractModeCommand(cache, fileInfo, model, stringIds));
     return context;
 }
 public TagAnalyzer(TagCache cache, HaloTag tag)
 {
     _cache  = cache;
     _tag    = tag;
     _tagMap = BuildTagMap(tag);
     _dataFixupsByWriteOffset     = _tag.DataFixups.ToDictionary(f => f.WriteOffset);
     _resourceFixupsByWriteOffset = _tag.ResourceFixups.ToDictionary(f => f.WriteOffset);
 }
Esempio n. 10
0
 private void EditBitmTag(HaloTag tag)
 {
     Bitmap bitmap;
     using (var stream = _fileInfo.OpenRead())
         bitmap = TagDeserializer.Deserialize<Bitmap>(new TagSerializationContext(stream, _cache, tag));
     var context = BitmContextFactory.Create(_stack.Context, _fileInfo, _cache, tag, bitmap);
     _stack.Push(context);
 }
Esempio n. 11
0
 public TagAnalyzer(TagCache cache, HaloTag tag)
 {
     _cache = cache;
     _tag = tag;
     _tagMap = BuildTagMap(tag);
     _dataFixupsByWriteOffset = _tag.DataFixups.ToDictionary(f => f.WriteOffset);
     _resourceFixupsByWriteOffset = _tag.ResourceFixups.ToDictionary(f => f.WriteOffset);
 }
Esempio n. 12
0
 /// <summary>
 /// Serializes a tag reference.
 /// </summary>
 /// <param name="writer">The writer to write to.</param>
 /// <param name="referencedTag">The referenced tag.</param>
 private static void SerializeTagReference(BinaryWriter writer, HaloTag referencedTag)
 {
     // Write the reference out
     writer.Write((referencedTag != null) ? referencedTag.Class.Value : -1);
     writer.Write(0);
     writer.Write(0);
     writer.Write((referencedTag != null) ? referencedTag.Index : -1);
 }
 private static bool CheckTargetOffset(HaloTag tag, uint targetOffset)
 {
     if (targetOffset < tag.Size)
     {
         return(true);
     }
     Console.Error.WriteLine("Invalid target offset: cannot point to something outside the tag.");
     return(false);
 }
 private static bool CheckWriteOffset(HaloTag tag, uint writeOffset)
 {
     if (writeOffset < tag.Size)
     {
         return(true);
     }
     Console.Error.WriteLine("Invalid write offset: cannot write past the end of the tag.");
     return(false);
 }
Esempio n. 15
0
 /// <summary>
 /// Builds a memory map for a tag.
 /// </summary>
 /// <param name="tag">The tag to build a memory map for.</param>
 /// <returns>The built map.</returns>
 private static MemoryMap BuildTagMap(HaloTag tag)
 {
     // Create a memory map with a boundary at each fixup target
     // and at the main structure
     var result = new MemoryMap(0, tag.Size);
     result.AddBoundary(tag.MainStructOffset);
     result.AddBoundaries(tag.DataFixups.Select(f => f.TargetOffset));
     return result;
 }
Esempio n. 16
0
        private static int CompareTags(HaloTag lhs, HaloTag rhs)
        {
            var classCompare = lhs.Class.CompareTo(rhs.Class);

            if (classCompare != 0)
            {
                return(classCompare);
            }
            return(lhs.Index.CompareTo(rhs.Index));
        }
 public static CommandContext Create(CommandContext parent, OpenTagCache info, HaloTag tag, MultilingualUnicodeStringList unic)
 {
     var context = new CommandContext(parent, string.Format("{0:X8}.unic", tag.Index));
     if (info.StringIds != null)
     {
         context.AddCommand(new UnicListCommand(info, unic));
         context.AddCommand(new UnicSetCommand(info, tag, unic));
     }
     return context;
 }
        /// <summary>
        /// Builds a memory map for a tag.
        /// </summary>
        /// <param name="tag">The tag to build a memory map for.</param>
        /// <returns>The built map.</returns>
        private static MemoryMap BuildTagMap(HaloTag tag)
        {
            // Create a memory map with a boundary at each fixup target
            // and at the main structure
            var result = new MemoryMap(0, tag.Size);

            result.AddBoundary(tag.MainStructOffset);
            result.AddBoundaries(tag.DataFixups.Select(f => f.TargetOffset));
            return(result);
        }
        private void EditHlmtTag(HaloTag tag)
        {
            Model model;

            using (var stream = _fileInfo.OpenRead())
                model = TagDeserializer.Deserialize <Model>(new TagSerializationContext(stream, _cache, tag));
            var context = HlmtContextFactory.Create(_stack.Context, _fileInfo, _cache, _stringIds, tag, model);

            _stack.Push(context);
        }
        private void EditUnicTag(HaloTag tag)
        {
            MultilingualUnicodeStringList unic;

            using (var stream = _fileInfo.OpenRead())
                unic = TagDeserializer.Deserialize <MultilingualUnicodeStringList>(new TagSerializationContext(stream, _cache, tag));
            var context = UnicContextFactory.Create(_stack.Context, _fileInfo, _cache, tag, unic, _stringIds);

            _stack.Push(context);
        }
Esempio n. 21
0
 public static CommandContext Create(CommandContext parent, FileInfo fileInfo, TagCache cache, HaloTag tag, VFilesList vfsl)
 {
     var context = new CommandContext(parent, string.Format("{0:X8}.vfsl", tag.Index));
     context.AddCommand(new VfslListCommand(vfsl));
     context.AddCommand(new VfslExtractCommand(vfsl));
     context.AddCommand(new VfslExtractAllCommand(vfsl));
     context.AddCommand(new VfslImportCommand(fileInfo, cache, tag, vfsl));
     context.AddCommand(new VfslImportAllCommand(fileInfo, cache, tag, vfsl));
     return context;
 }
        private void EditVfslTag(HaloTag tag)
        {
            VFilesList vfsl;

            using (var stream = _fileInfo.OpenRead())
                vfsl = TagDeserializer.Deserialize <VFilesList>(new TagSerializationContext(stream, _cache, tag));
            var context = VfslContextFactory.Create(_stack.Context, _fileInfo, _cache, tag, vfsl);

            _stack.Push(context);
        }
        private void EditBitmTag(HaloTag tag)
        {
            Bitmap bitmap;

            using (var stream = _fileInfo.OpenRead())
                bitmap = TagDeserializer.Deserialize <Bitmap>(new TagSerializationContext(stream, _cache, tag));
            var context = BitmContextFactory.Create(_stack.Context, _fileInfo, _cache, tag, bitmap);

            _stack.Push(context);
        }
Esempio n. 24
0
        public static CommandContext Create(CommandContext parent, FileInfo fileInfo, TagCache cache, HaloTag tag,
			MultilingualUnicodeStringList unic, StringIdCache stringIds)
        {
            var context = new CommandContext(parent, string.Format("{0:X8}.unic", tag.Index));
            if (stringIds != null)
            {
                context.AddCommand(new UnicListCommand(unic, stringIds));
                context.AddCommand(new UnicSetCommand(fileInfo, cache, tag, unic, stringIds));
            }
            return context;
        }
        private static bool ExecuteList(HaloTag tag, List <string> args)
        {
            if (args.Count != 2)
            {
                return(false);
            }
            var fixups = tag.DataFixups.OrderBy(f => f.WriteOffset);

            foreach (var fixup in fixups)
            {
                Console.WriteLine("0x{0:X} -> 0x{1:X}", fixup.WriteOffset, fixup.TargetOffset);
            }
            return(true);
        }
        public VfslImportCommand(OpenTagCache info, HaloTag tag, VFilesList list)
            : base(CommandFlags.None,
			
			"import",
			"Replace a file stored in the tag",

			"import <virtual path> [filename]",
			
			"Replaces a file stored in the tag. The tag will be resized as necessary.")
        {
            _info = info;
            _tag = tag;
            _list = list;
        }
        public VfslImportAllCommand(OpenTagCache info, HaloTag tag, VFilesList list)
            : 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;
            _list = list;
        }
Esempio n. 28
0
        public VfslImportCommand(FileInfo fileInfo, TagCache cache, HaloTag tag, VFilesList list) : base(
                CommandFlags.None,

                "import",
                "Replace a file stored in the tag",

                "import <virtual path> [filename]",

                "Replaces a file stored in the tag. The tag will be resized as necessary.")
        {
            _fileInfo = fileInfo;
            _cache    = cache;
            _tag      = tag;
            _list     = list;
        }
Esempio n. 29
0
        private void FindAllReferences(HaloTag tag, Dictionary <HaloTag, Group> tags)
        {
            if (!tags.ContainsKey(tag))
            {
                var tagGroup = Abide.Tag.Cache.Generated.TagLookup.CreateTagGroup(tag.Tag);
                using (var data = Map.ReadTagData(tag))
                {
                    _ = data.Stream.Seek(tag.MemoryAddress, SeekOrigin.Begin);
                    tagGroup.Read(data.Stream.CreateReader());
                    tags.Add(tag, tagGroup);

                    FindAllReferences(tagGroup, tags);
                }
            }
        }
        public BitmImportCommand(OpenTagCache info, HaloTag tag, Bitmap bitmap)
            : base(CommandFlags.None,

			"import",
			"Import 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;
        }
Esempio n. 31
0
        public VfslImportAllCommand(FileInfo fileInfo, TagCache cache, HaloTag tag, VFilesList list) : 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.")
        {
            _fileInfo = fileInfo;
            _cache    = cache;
            _tag      = tag;
            _list     = list;
        }
Esempio n. 32
0
        public UnicSetCommand(OpenTagCache info, HaloTag 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;
            _unic = unic;
        }
        public BitmImportCommand(FileInfo fileInfo, TagCache cache, HaloTag tag, Bitmap bitmap) : base(
                CommandFlags.None,

                "import",
                "Import 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.")
        {
            _fileInfo = fileInfo;
            _cache    = cache;
            _tag      = tag;
            _bitmap   = bitmap;
        }
Esempio n. 34
0
        public static void Write(HaloTag tag, TagLayoutGuess layout, ITagLayoutWriter writer)
        {
            if (tag != null)
            {
                writer.Begin(tag.Class, tag.ClassId, layout);
            }
            else
            {
                writer.Begin(new MagicNumber(0), 0, layout);
            }

            for (uint offset = 0; offset < layout.Size; offset += 4)
            {
                var guess = layout.TryGet(offset);
                if (guess != null)
                {
                    writer.AddGuess(offset, guess);
                    offset += guess.Size - 4;
                }
                else
                {
                    var remaining = layout.Size - offset;
                    switch (remaining)
                    {
                    case 3:
                        writer.AddUnknownInt16(offset);
                        writer.AddUnknownByte(offset + 2);
                        break;

                    case 2:
                        writer.AddUnknownInt16(offset);
                        break;

                    case 1:
                        writer.AddUnknownByte(offset);
                        break;

                    default:                             // >= 4
                        writer.AddUnknownInt32(offset);
                        break;
                    }
                }
            }
            writer.End();
        }
Esempio n. 35
0
        public UnicSetCommand(FileInfo fileInfo, TagCache cache, HaloTag tag, MultilingualUnicodeStringList unic, StringIdCache stringIds) : 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.")
        {
            _fileInfo  = fileInfo;
            _cache     = cache;
            _tag       = tag;
            _unic      = unic;
            _stringIds = stringIds;
        }
        private bool ExecuteAddRemove(HaloTag tag, List <string> args)
        {
            if (args.Count < 3)
            {
                return(false);
            }
            var dependencies = args.Skip(2).Select(a => ArgumentParser.ParseTagIndex(_cache, a)).ToList();

            if (dependencies.Count == 0 || dependencies.Any(d => d == null))
            {
                return(false);
            }
            if (args[0] == "add")
            {
                foreach (var dependency in dependencies)
                {
                    if (tag.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 (tag.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);
                    }
                }
            }
            using (var stream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite))
                _cache.UpdateTag(stream, tag);
            return(true);
        }
        private bool ExecuteAdd(HaloTag tag, List <string> args)
        {
            if (args.Count != 4)
            {
                return(false);
            }
            uint writeOffset, targetOffset;

            if (!uint.TryParse(args[2], NumberStyles.HexNumber, null, out writeOffset))
            {
                return(false);
            }
            if (!uint.TryParse(args[3], NumberStyles.HexNumber, null, out targetOffset))
            {
                return(false);
            }
            if (!CheckWriteOffset(tag, writeOffset))
            {
                return(true);
            }
            if (!CheckTargetOffset(tag, targetOffset))
            {
                return(true);
            }

            // Create a new fixup if there isn't one, otherwise overwrite it
            var fixup = tag.DataFixups.FirstOrDefault(f => f.WriteOffset == writeOffset);

            if (fixup == null)
            {
                fixup = new TagFixup();
                tag.DataFixups.Add(fixup);
            }
            fixup.WriteOffset  = writeOffset;
            fixup.TargetOffset = targetOffset;

            // Update the tag
            using (var stream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite))
                _cache.UpdateTag(stream, tag);

            Console.WriteLine("Added fixup at offset 0x{0:X} to 0x{1:X}.", writeOffset, targetOffset);
            return(true);
        }
        private bool ExecuteList(HaloTag tag, bool all)
        {
            if (tag.Dependencies.Count == 0)
            {
                Console.Error.WriteLine("Tag {0:X8} has no dependencies.", tag.Index);
                return(true);
            }
            IEnumerable <HaloTag> dependencies;

            if (all)
            {
                dependencies = _cache.Tags.FindDependencies(tag);
            }
            else
            {
                dependencies = tag.Dependencies.Where(i => _cache.Tags.Contains(i)).Select(i => _cache.Tags[i]);
            }
            TagPrinter.PrintTagsShort(dependencies);
            return(true);
        }
Esempio n. 39
0
 private void tagTreeView_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (e.Node.Level == 1)
     {
         string       tagType          = e.Node.Parent.Text;
         string       offset           = e.Node.Text;
         HaloTag      selectedTag      = tagsCol.getTag(offset, tagType);
         List <patch> availablePatches = patchCol.getPatchByType(selectedTag.getType());
         Label        offsetLabel      = new Label();
         offsetLabel.Text = "Offset: 0x" + selectedTag.getOffset();
         Label sizeLabel = new Label();
         sizeLabel.Text = "Size: 0x" + selectedTag.getSize();
         Label displayNameLabel = new Label();
         displayNameLabel.Text = "Display Name: " + selectedTag.getDisplayName();
         flowLayoutPanel1.Controls.Clear();
         flowLayoutPanel1.Controls.Add(offsetLabel);
         flowLayoutPanel1.Controls.Add(sizeLabel);
         flowLayoutPanel1.Controls.Add(displayNameLabel);
         if (availablePatches.Count == 0)
         {
             TextBox tagContents = new TextBox();
             tagContents.Width     = flowLayoutPanel1.Width;
             tagContents.Height    = flowLayoutPanel1.Height - 46;
             tagContents.Multiline = true;
             tagContents.Text      = BitConverter.ToString(selectedTag.getContents());
             flowLayoutPanel1.Controls.Add(tagContents);
         }
         else
         {
             foreach (patch patch in availablePatches)
             {
                 Label patchLabel = new Label();
                 patchLabel.Text  = "Offset: 0x" + patch.getOffset() + "Size: 0x" + patch.getSize();
                 patchLabel.Width = flowLayoutPanel1.Width;
                 flowLayoutPanel1.Controls.Add(patchLabel);
             }
         }
     }
 }
        private bool ExecuteRemove(HaloTag tag, List <string> args)
        {
            if (args.Count != 3)
            {
                return(false);
            }
            uint writeOffset;

            if (!uint.TryParse(args[2], NumberStyles.HexNumber, null, out writeOffset))
            {
                return(false);
            }
            if (!CheckWriteOffset(tag, writeOffset))
            {
                return(true);
            }

            for (var i = 0; i < tag.DataFixups.Count; i++)
            {
                if (tag.DataFixups[i].WriteOffset != writeOffset)
                {
                    continue;
                }

                // Remove the fixup and then open a stream and write a null pointer at the offset
                tag.DataFixups.RemoveAt(i);
                using (var writer = new BinaryWriter(_fileInfo.Open(FileMode.Open, FileAccess.ReadWrite)))
                {
                    writer.BaseStream.Position = tag.Offset + writeOffset;
                    writer.Write(0);
                    _cache.UpdateTag(writer.BaseStream, tag);
                }

                Console.WriteLine("Removed fixup at offset 0x{0:X}.", writeOffset);
                return(true);
            }
            Console.Error.WriteLine("No fixup found at offset 0x{0:X}.", writeOffset);
            return(true);
        }
        public static void Write(HaloTag tag, TagLayoutGuess layout, ITagLayoutWriter writer)
        {
            if (tag != null)
                writer.Begin(tag.Class, tag.ClassId, layout);
            else
                writer.Begin(new MagicNumber(0), StringId.Null, layout);

            for (uint offset = 0; offset < layout.Size; offset += 4)
            {
                var guess = layout.TryGet(offset);
                if (guess != null)
                {
                    writer.AddGuess(offset, guess);
                    offset += guess.Size - 4;
                }
                else
                {
                    var remaining = layout.Size - offset;
                    switch (remaining)
                    {
                        case 3:
                            writer.AddUnknownInt16(offset);
                            writer.AddUnknownByte(offset + 2);
                            break;
                        case 2:
                            writer.AddUnknownInt16(offset);
                            break;
                        case 1:
                            writer.AddUnknownByte(offset);
                            break;
                        default: // >= 4
                            writer.AddUnknownInt32(offset);
                            break;
                    }
                }
            }
            writer.End();
        }
Esempio n. 42
0
            public TagPathNode Add(string name, bool isExpanded, HaloTag tag)
            {
                if (name == null)
                {
                    throw new ArgumentNullException(nameof(name));
                }

                if (nodeNameMap.ContainsKey(name))
                {
                    throw new InvalidOperationException("A node with the specified name already exists.");
                }

                TagPathNode node = new TagPathNode()
                {
                    Name       = name,
                    IsExpanded = isExpanded,
                    Tag        = tag
                };

                Add(node);

                return(node);
            }
Esempio n. 43
0
 private bool RemoveSubcommand(Stream stream, HaloTag tag, int offset, int elementSize, ref int count, List<string> args)
 {
     if (args.Count != 4)
         return false;
     int amount;
     if (!int.TryParse(args[3], NumberStyles.HexNumber, null, out amount))
         return false;
     Console.WriteLine("Removing {0} elements...", amount);
     DoRemove(stream, tag, offset, elementSize, count - amount, amount, ref count);
     return true;
 }
Esempio n. 44
0
 private void DoRemove(Stream stream, HaloTag tag, int offset, int elementSize, int index, int amount, ref int count)
 {
     index = Math.Max(0, Math.Min(index, count - 1));
     amount = Math.Max(0, Math.Min(amount, count - index));
     if (amount == 0)
         return;
     _cache.InsertTagData(stream, tag, (uint)(offset + (index + amount) * elementSize), -elementSize * amount, InsertOrigin.Before);
     count = Math.Max(0, count - amount);
 }
Esempio n. 45
0
 private bool RemoveAtSubcommand(Stream stream, HaloTag tag, int offset, int elementSize, ref int count, List<string> args)
 {
     if (args.Count != 5)
         return false;
     int index;
     if (!int.TryParse(args[3], NumberStyles.HexNumber, null, out index) || index < 0)
         return false;
     int amount;
     if (!int.TryParse(args[4], NumberStyles.HexNumber, null, out amount) || amount < 0)
         return false;
     Console.WriteLine("Removing {0} elements at index {1}...", amount, index);
     DoRemove(stream, tag, offset, elementSize, index, amount, ref count);
     return true;
 }
Esempio n. 46
0
 private bool AddSubcommand(Stream stream, HaloTag tag, int offset, int elementSize, ref int count, List<string> args)
 {
     if (args.Count != 4)
         return false;
     int amount;
     if (!int.TryParse(args[3], NumberStyles.HexNumber, null, out amount) || amount < 0)
         return false;
     Console.WriteLine("Inserting {0} elements at index {1}...", amount, count);
     DoAdd(stream, tag, offset, elementSize, count, amount, ref count);
     return true;
 }
Esempio n. 47
0
 private void DoAdd(Stream stream, HaloTag tag, int offset, int elementSize, int index, int amount, ref int count)
 {
     if (amount == 0)
         return;
     index = Math.Max(0, Math.Min(index, count));
     _cache.InsertTagData(stream, tag, (uint)(offset + index * elementSize), elementSize * amount, InsertOrigin.Before);
     count += amount;
 }
Esempio n. 48
0
 private void EditVfslTag(HaloTag tag)
 {
     VFilesList vfsl;
     using (var stream = _fileInfo.OpenRead())
         vfsl = TagDeserializer.Deserialize<VFilesList>(new TagSerializationContext(stream, _cache, tag));
     var context = VfslContextFactory.Create(_stack.Context, _fileInfo, _cache, tag, vfsl);
     _stack.Push(context);
 }
        public static CommandContext Create(CommandContext parent, FileInfo fileInfo, TagCache cache, StringIdCache stringIds, HaloTag tag, Model model)
        {
            var context = new CommandContext(parent, string.Format("{0:X8}.hlmt", tag.Index));

            context.AddCommand(new HlmtListVariantsCommand(model, stringIds));
            context.AddCommand(new HlmtExtractModeCommand(cache, fileInfo, model, stringIds));
            return(context);
        }
 public TagSerializationContext(Stream stream, TagCache cache, HaloTag tag)
 {
     _stream = stream;
     _cache = cache;
     _tag = tag;
 }
Esempio n. 51
0
        private bool ExecuteAdd(HaloTag tag, List<string> args)
        {
            if (args.Count != 4)
                return false;
            uint writeOffset, targetOffset;
            if (!uint.TryParse(args[2], NumberStyles.HexNumber, null, out writeOffset))
                return false;
            if (!uint.TryParse(args[3], NumberStyles.HexNumber, null, out targetOffset))
                return false;
            if (!CheckWriteOffset(tag, writeOffset))
                return true;
            if (!CheckTargetOffset(tag, targetOffset))
                return true;

            // Create a new fixup if there isn't one, otherwise overwrite it
            var fixup = tag.DataFixups.FirstOrDefault(f => f.WriteOffset == writeOffset);
            if (fixup == null)
            {
                fixup = new TagFixup();
                tag.DataFixups.Add(fixup);
            }
            fixup.WriteOffset = writeOffset;
            fixup.TargetOffset = targetOffset;

            // Update the tag
            using (var stream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite))
                _cache.UpdateTag(stream, tag);

            Console.WriteLine("Added fixup at offset 0x{0:X} to 0x{1:X}.", writeOffset, targetOffset);
            return true;
        }
        public static CommandContext Create(CommandContext parent, FileInfo fileInfo, TagCache cache, HaloTag tag, Bitmap bitmap)
        {
            var context = new CommandContext(parent, string.Format("{0:X8}.bitm", tag.Index));

            context.AddCommand(new BitmImportCommand(fileInfo, cache, tag, bitmap));
            return(context);
        }
 private bool ExecuteList(HaloTag tag, bool all)
 {
     if (tag.Dependencies.Count == 0)
     {
         Console.Error.WriteLine("Tag {0:X8} has no dependencies.", tag.Index);
         return true;
     }
     IEnumerable<HaloTag> dependencies;
     if (all)
         dependencies = _cache.Tags.FindDependencies(tag);
     else
         dependencies = tag.Dependencies.Where(i => _cache.Tags.Contains(i)).Select(i => _cache.Tags[i]);
     TagPrinter.PrintTagsShort(dependencies);
     return true;
 }
Esempio n. 54
0
 public static void PrintTagShort(HaloTag tag)
 {
     Console.WriteLine("{0} {1:X8} [Offset = 0x{2:X}, Size = 0x{3:X}]", tag.Class, tag.Index, tag.Offset, tag.Size);
 }
Esempio n. 55
0
 private void EditUnicTag(HaloTag tag)
 {
     MultilingualUnicodeStringList unic;
     using (var stream = _fileInfo.OpenRead())
         unic = TagDeserializer.Deserialize<MultilingualUnicodeStringList>(new TagSerializationContext(stream, _cache, tag));
     var context = UnicContextFactory.Create(_stack.Context, _fileInfo, _cache, tag, unic, _stringIds);
     _stack.Push(context);
 }
Esempio n. 56
0
 public static void PrintTagShort(HaloTag tag)
 {
     Console.WriteLine("{0} {1:X8} [Offset = 0x{2:X}, Size = 0x{3:X}]", tag.Class, tag.Index, tag.Offset, tag.Size);
 }
        public static CommandContext Create(CommandContext parent, FileInfo fileInfo, TagCache cache, HaloTag tag,
                                            MultilingualUnicodeStringList unic, StringIdCache stringIds)
        {
            var context = new CommandContext(parent, string.Format("{0:X8}.unic", tag.Index));

            if (stringIds != null)
            {
                context.AddCommand(new UnicListCommand(unic, stringIds));
                context.AddCommand(new UnicSetCommand(fileInfo, cache, tag, unic, stringIds));
            }
            return(context);
        }
Esempio n. 58
0
 private void EditHlmtTag(HaloTag tag)
 {
     Model model;
     using (var stream = _fileInfo.OpenRead())
         model = TagDeserializer.Deserialize<Model>(new TagSerializationContext(stream, _cache, tag));
     var context = HlmtContextFactory.Create(_stack.Context, _fileInfo, _cache, _stringIds, tag, model);
     _stack.Push(context);
 }
 private bool ExecuteListDependsOn(HaloTag tag)
 {
     var dependsOn = _cache.Tags.Where(t => t != null && t.Dependencies.Contains(tag.Index));
     TagPrinter.PrintTagsShort(dependsOn);
     return true;
 }
 public TagSerializationContext(Stream stream, TagCache cache, HaloTag tag)
 {
     _stream = stream;
     _cache  = cache;
     _tag    = tag;
 }