public RemoveBlockElementsCommand(CommandContextStack contextStack, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, TagStructureInfo structure, object owner) : base(true, "RemoveBlockElements", $"Removes block element(s) from a specified index of a specific tag block in the current {structure.Types[0].Name} definition.", "RemoveBlockElements <block name> [* | <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.") { ContextStack = contextStack; CacheContext = cacheContext; Tag = tag; Structure = structure; Owner = owner; }
public SetFieldCommand(CommandContextStack contextStack, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, TagStructureInfo structure, object owner) : base(true, "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.") { ContextStack = contextStack; CacheContext = cacheContext; Tag = tag; Structure = structure; Owner = owner; }
private void CopyTagNames(Stream cacheStream, object edDef, TagStructureInfo edInfo, object blamDef, TagStructureInfo blamInfo) { foreach (var blamField in TagStructure.GetTagFieldEnumerable(blamInfo.Types[0], blamInfo.Version)) { foreach (var edField in TagStructure.GetTagFieldEnumerable(edInfo.Types[0], edInfo.Version)) { if (blamField.FieldType != edField.FieldType || edField.FieldInfo.Name != blamField.FieldInfo.Name) { continue; } var blamValue = blamField.FieldInfo.GetValue(blamDef); var edValue = edField.FieldInfo.GetValue(edDef); if (blamValue is CachedTagInstance blamRef && edValue is CachedTagInstance edRef) { if (blamRef != null && edRef != null && blamRef.IsInGroup(edRef.Group)) { CopyTagNames(cacheStream, edRef, BlamCache.GetIndexItemFromID(blamRef.Index)); } }
public ForEachCommand(CommandContextStack contextStack, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, TagStructureInfo structure, object owner) : base(true, "ForEach", "Executes a command for each element in the specified tag block.", "ForEach <Tag Block> <Command>", "Executes a command for each element in the specified tag block.") { ContextStack = contextStack; CacheContext = cacheContext; Tag = tag; Structure = structure; Owner = owner; }
public CopyElementsCommand(CommandContextStack stack, OpenTagCache info, TagInstance tag, TagStructureInfo structure, object owner) : base(CommandFlags.None, "copyelements", "Copies block elements from one tag to another.", "copyelements <block name> [count = *] [index = 0]", "Copies block elements from one tag to another.") { Stack = stack; Info = info; Tag = tag; Structure = structure; Owner = owner; }
public override bool Execute(List <string> args) { if (args.Count < 1 || args.Count > 2) { return(false); } var blockName = args[0]; var ownerType = Owner.GetType(); var enumerator = new TagFieldEnumerator(Structure); var deferredNames = new List <string>(); var deferredArgs = new List <string>(); if (blockName.Contains(".")) { deferredNames.AddRange(blockName.Split('.')); blockName = deferredNames[0]; deferredNames = deferredNames.Skip(1).ToList(); deferredArgs.AddRange(args.Skip(1)); args = new List <string> { blockName }; } if (blockName.Contains("]")) { var openBracketIndex = blockName.IndexOf('['); var closeBracketIndex = blockName.IndexOf(']'); var name = blockName.Substring(0, openBracketIndex); var index = blockName.Substring(openBracketIndex + 1, (closeBracketIndex - openBracketIndex) - 1); blockName = name; args = new List <string> { name, index }; } var blockNameLow = blockName.ToLower(); var field = enumerator.Find(f => f.Name == blockName || f.Name.ToLower() == blockNameLow); if (field == null) { Console.WriteLine("{0} does not contain a block named \"{1}\"", ownerType.Name, blockName); return(false); } var contextName = ""; object blockValue = null; var structureAttribute = field.FieldType.CustomAttributes.ToList().Find(a => a.AttributeType == typeof(TagStructureAttribute)); if (structureAttribute != null) { if (args.Count != 1) { return(false); } blockValue = field.GetValue(Owner); contextName = $"{blockName}"; } else { if (args.Count != 2) { return(false); } IList fieldValue = null; if (field.FieldType.GetInterface("IList") == null || (fieldValue = (IList)field.GetValue(Owner)) == null) { Console.WriteLine("{0} does not contain a block named \"{1}\"", ownerType.Name, blockName); return(false); } int blockIndex = 0; if (args[1] == "*") { blockIndex = fieldValue.Count - 1; } else if (!int.TryParse(args[1], out blockIndex)) { Console.WriteLine("Invalid index requested from block {0}: {1}", blockName, blockIndex); return(false); } if (blockIndex >= fieldValue.Count || blockIndex < 0) { Console.WriteLine("Invalid index requested from block {0}: {1}", blockName, blockIndex); return(false); } blockValue = fieldValue[blockIndex]; contextName = $"{blockName}[{blockIndex}]"; } var blockStructure = new TagStructureInfo(blockValue.GetType()); var blockContext = new CommandContext(Stack.Context, contextName); blockContext.AddCommand(new ListFieldsCommand(Info, blockStructure, blockValue)); blockContext.AddCommand(new SetFieldCommand(Stack, Info, Tag, blockStructure, blockValue)); blockContext.AddCommand(new EditBlockCommand(Stack, Info, Tag, blockValue)); blockContext.AddCommand(new AddToBlockCommand(Stack, Info, Tag, blockStructure, blockValue)); blockContext.AddCommand(new RemoveFromBlockCommand(Stack, Info, Tag, blockStructure, blockValue)); blockContext.AddCommand(new ExitToCommand(Stack)); Stack.Push(blockContext); if (deferredNames.Count != 0) { var name = deferredNames[0]; deferredNames = deferredNames.Skip(1).ToList(); foreach (var deferredName in deferredNames) { name += '.' + deferredName; } args = new List <string> { name }; args.AddRange(deferredArgs); var command = new EditBlockCommand(Stack, Info, Tag, blockValue); return(command.Execute(args)); } return(true); }
public CopyBlockElementsCommand(CommandContextStack contextStack, CacheFile blamCache, CacheFile.IndexItem tag, TagStructureInfo structure, object owner) : base(false, "CopyBlockElements", "Copies block elements from one tag to another.", "CopyBlockElements <block name> [index = 0] [count = *]", "Copies block elements from one tag to another.") { ContextStack = contextStack; BlamCache = blamCache; Tag = tag; Structure = structure; Owner = owner; }
public CopyBlockElementsCommand(CommandContextStack contextStack, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, TagStructureInfo structure, object owner) : base(false, "CopyBlockElements", "Copies block elements from one tag to another.", "CopyBlockElements <block name> [index = 0] [count = *]", "Copies block elements from one tag to another.") { ContextStack = contextStack; CacheContext = cacheContext; Tag = tag; Structure = structure; Owner = owner; }
public void EndSerialize(TagStructureInfo info, byte[] data, uint mainStructOffset) { ProcessStream.Write(data, 0, data.Length); }
public ExtractResourceCommand(CommandContextStack contextStack, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, TagStructureInfo structure, object owner) : base(true, "ExtractResource", $"Extracts the data of a specific resource field in the current {structure.Types[0].Name} definition.", "ExtractResource <field name> <path>", $"Extracts the data of a specific resource field in the current {structure.Types[0].Name} definition.") { ContextStack = contextStack; CacheContext = cacheContext; Tag = tag; Structure = structure; Owner = owner; }
public void EndDeserialize(TagStructureInfo info, object obj) { }
public void BeginSerialize(TagStructureInfo info) { }
public EndianReader BeginDeserialize(TagStructureInfo info) { return(new EndianReader(ProcessStream)); }
public static CommandContext Create(CommandContextStack stack, OpenTagCache info, TagInstance tag) { var groupName = info.StringIds.GetString(tag.Group.Name); var context = new CommandContext(stack.Context, string.Format("0x{0:X4}.{1}", tag.Index, groupName)); switch (tag.Group.Tag.ToString()) { case "vfsl": // vfiles_list EditVFilesList(context, info, tag); break; case "unic": // multilingual_unicode_string_list EditMultilingualUnicodeStringList(context, info, tag); break; case "bitm": // bitmap EditBitmap(context, info, tag); break; case "hlmt": // model EditModel(context, info, tag); break; case "mode": // render_model EditRenderModel(context, info, tag); break; case "rm ": // render_method case "rmsh": // shader case "rmd ": // shader_decal case "rmfl": // shader_foliage case "rmhg": // shader_halogram case "rmss": // shader_screen case "rmtr": // shader_terrain case "rmw ": // shader_water case "rmzo": // shader_zonly case "rmcs": // shader_custom EditRenderMethod(context, info, tag); break; case "scnr": EditScenario(context, info, tag); break; } object value = null; using (var stream = info.OpenCacheRead()) value = info.Deserializer.Deserialize( new TagSerializationContext(stream, info.Cache, info.StringIds, tag), TagStructureTypes.FindByGroupTag(tag.Group.Tag)); var structure = new TagStructureInfo( TagStructureTypes.FindByGroupTag(tag.Group.Tag)); context.AddCommand(new ListFieldsCommand(info, structure, value)); context.AddCommand(new SetFieldCommand(stack, info, tag, structure, value)); context.AddCommand(new EditBlockCommand(stack, info, tag, value)); context.AddCommand(new AddToBlockCommand(stack, info, tag, structure, value)); context.AddCommand(new RemoveFromBlockCommand(stack, info, tag, structure, value)); context.AddCommand(new SaveChangesCommand(info, tag, value)); context.AddCommand(new ExitToCommand(stack)); return(context); }
public RemoveFromBlockCommand(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; }
public AddToCommand(CommandContextStack stack, OpenTagCache info, TagInstance tag, TagStructureInfo structure, object owner) : base(CommandFlags.Inherit, "addto", $"Adds/inserts block element(s) to a specific tag block in the current {structure.Types[0].Name} definition.", "addto <tag block name> [amount = 1] [index = *]", $"Adds/inserts 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 PasteBlockElementsCommand(CommandContextStack contextStack, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, TagStructureInfo structure, object owner) : base(true, "PasteBlockElements", $"Pastes block element(s) to a specific tag block in the current {structure.Types[0].Name} definition.", "PasteBlockElements <tag block name> [index = *]", $"Pastes block element(s) to a specific tag block in the current {structure.Types[0].Name} definition.") { ContextStack = contextStack; CacheContext = cacheContext; 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; }
public AddBlockElementsCommand(CommandContextStack contextStack, GameCache cache, CachedTag tag, TagStructureInfo structure, object owner) : base(true, "AddBlockElements", $"Adds/inserts block element(s) to a specific tag block in the current {structure.Types[0].Name} definition.", "AddBlockElements <block name> [amount = 1] [index = *]", $"Adds/inserts block element(s) to a specific tag block in the current {structure.Types[0].Name} definition.") { ContextStack = contextStack; Cache = cache; Tag = tag; Structure = structure; Owner = owner; }