public TagGroupDocumentation(ResourceKeyStack messagePath, ITagGroup tagGroup, IList<Func<ITag, TagDocumentation, bool>> specials) { _messagePath = messagePath.BranchFor(tagGroup); _name = tagGroup.Name; _specials = specials; _tags = new List<TagDocumentation>(); var tagGroupType=tagGroup.GetType(); _description=DescriptionAttribute.Harvest(tagGroupType)?? _messagePath.Description; _title = TitleAttribute.HarvestTagLibrary(tagGroupType); foreach (ITag _tag in tagGroup) { _tags.Add(new TagDocumentation(_messagePath, _tag, _specials)); } if (ExampleAttribute.Harvest(tagGroupType)) { _examples.AddRange(ExampleAttribute.HarvestTags(tagGroupType)); } if (HasExample.Has(tagGroupType)) { _examples.Add(new ExampleAttribute(_messagePath.Example)); } if (NoteAttribute.Harvest(tagGroupType)) { _notes.AddRange(NoteAttribute.HarvestTags(tagGroupType)); } if (HasNote.Has(tagGroupType)) { _notes.Add(new NoteAttribute(_messagePath.Note)); } }
public ITagLib Register(ITagGroup group) { if (_tags.ContainsKey(group.Name)) throw new ArgumentException($"Group '{group.Name}' is already registered. Currently registered groups are: {string.Join(", ", _tags.Keys)}."); _tags.Add(group.Name, group); return this; }
private void GuardPresenceOfCategoriesOnTagGroup(ITagGroup taggroup) { foreach (var tag in taggroup) { Console.Write("\t"+tag.TagName+":"); GuardPresenceOfCategoriesOnTag(tag); } }
private void DecoratorSetTagGroup_CreateResources(ITagGroup guerillaTagGroup, IndexEntry entry, BinaryWriter writer, ref TagGroupHeader header) { List <long> addresses = new List <long>(); List <byte[]> buffers = new List <byte[]>(); ITagBlock geometry = (ITagBlock)guerillaTagGroup[0][8].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } if (header.TagResourceCount > 0) { header.RawOffsetsOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write((int)addresses[i]); } header.RawLengthsOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write(buffers[i].Length); } header.RawDataOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write(buffers[i]); } } }
/// <summary> /// Finds the first tag in a group which has a given name. /// </summary> /// <param name="name">The case-sensitive tag name to search for.</param> /// <param name="tagGroup">The tag group to search in.</param> /// <param name="names">The <see cref="FileNameSource" /> containing tag names.</param> /// <returns>The first tag in the group which has the given name, or null if nothing was found.</returns> public ITag FindTagByName(string name, ITagGroup tagGroup, FileNameSource names) { return(FindTagByName(name, tagGroup.Magic, names)); }
/// <summary> /// Retrieves a collection of tags which are members of a given group. /// Tags which inherit from the group will be included as well. /// </summary> /// <param name="tagGroup">The tag group to search for.</param> /// <returns>A collection of tags which are members of the group.</returns> public IEnumerable <ITag> FindTagsByGroup(ITagGroup tagGroup) { return(FindTagsByGroup(tagGroup.Magic)); }
/// <summary> /// Finds the first tag which belongs to a given group. /// Tags which inherit from the group will be included as well. /// </summary> /// <param name="tagGroup">The tag group to search for.</param> /// <returns>The first tag which is a member of the group, or null if not found.</returns> public ITag FindTagByGroup(ITagGroup tagGroup) { return(FindTagByGroup(tagGroup.Magic)); }
private void TagExportButton_Click(object sender, EventArgs e) { //Prepare TagManifest manifest = null; m_SoundCacheFileGestaltEntry = Map.GetSoundCacheFileGestaltEntry(); m_SoundCacheFileGestalt = null; //Check if (SelectedEntry != null) { //Create new FolderBrowserDialog instance using (FolderBrowserDialog folderDlg = new FolderBrowserDialog()) { //Setup folderDlg.Description = "Select the folder you wish to extract the tags to."; manifest = new TagManifest(); //Show if (folderDlg.ShowDialog() == DialogResult.OK) { //Read sound cache file gestalt using (BinaryReader reader = m_SoundCacheFileGestaltEntry.TagData.CreateReader()) { m_SoundCacheFileGestalt = new SoundCacheFileGestalt(); reader.BaseStream.Seek(m_SoundCacheFileGestaltEntry.Offset, SeekOrigin.Begin); m_SoundCacheFileGestalt.Read(reader); } //Export entry IndexEntry_Export(manifest, SelectedEntry, m_SoundCacheFileGestalt, folderDlg.SelectedPath); //Create manifest file XmlWriterSettings settings = new XmlWriterSettings() { Indent = true }; using (FileStream fs = new FileStream(Path.Combine(folderDlg.SelectedPath, $"{SelectedEntry.Filename.Split('\\').Last()}.{SelectedEntry.Root}.xml"), FileMode.Create, FileAccess.Write)) using (XmlWriter writer = XmlWriter.Create(fs, settings)) { //Write document writer.WriteStartDocument(); //Write manifest writer.WriteStartElement("Manifest"); //Write tags writer.WriteStartElement("Tags"); //Loop foreach (string localTag in manifest.TagFileNames) { //Write tag writer.WriteStartElement("Tag"); //Write path writer.WriteStartAttribute("Path"); writer.WriteValue(localTag); writer.WriteEndAttribute(); //End tag writer.WriteEndElement(); } //End tags writer.WriteEndElement(); //Write strings writer.WriteStartElement("Strings"); //Loop foreach (string stringId in manifest.StringIds) { //Write tag writer.WriteStartElement("String"); //Write path writer.WriteStartAttribute("value"); writer.WriteValue(stringId); writer.WriteEndAttribute(); //End tag writer.WriteEndElement(); } //End strings writer.WriteEndElement(); //End manifest writer.WriteEndElement(); //End document writer.WriteEndDocument(); } } } } }
private void IndexEntry_Export(TagManifest manifest, IndexEntry entry, ITagGroup soundCacheFileGestalt, string outputDirectory) { //Check if (entry == null || manifest == null || outputDirectory == null) { return; } if (manifest.TagIdReferences.Contains(entry.Id.Dword)) { return; } //Prepare AbideTagGroupFile tagGroupFile = new AbideTagGroupFile() { Id = entry.Id }; Group tagGroup = TagLookup.CreateTagGroup(entry.Root); string localPath = $"{entry.Filename}.{tagGroup.GroupName}"; string absolutePath = Path.Combine(outputDirectory, localPath); //Check using (BinaryReader reader = entry.TagData.CreateReader()) { //Add reference manifest.TagIdReferences.Add(entry.Id.Dword); //Read entry.TagData.Seek((uint)entry.PostProcessedOffset, SeekOrigin.Begin); tagGroup.Read(reader); //Get references foreach (ITagBlock tagBlock in tagGroup) { TagBock_BuildReferences(manifest, tagBlock, outputDirectory); } //Add file manifest.TagFileNames.Add(localPath); //Add raws foreach (RawSection section in Enum.GetValues(typeof(RawSection))) { foreach (RawStream raw in entry.Raws[section]) { tagGroupFile.SetRaw(raw.RawOffset, raw.ToArray()); } } //Convert cache to guerilla tagGroup = Guerilla.Library.Convert.ToGuerilla(tagGroup, soundCacheFileGestalt, entry, Map); //Copy raws if (tagGroup.GroupTag == HaloTags.snd_) { int rawOffset = 0; IndexEntry soundCacheFileGestaltEntry = Map.GetSoundCacheFileGestaltEntry(); Block soundBlock = tagGroup.TagBlocks[0]; foreach (Block pitchRangeBlock in ((BlockField)soundBlock.Fields[13]).BlockList) { foreach (Block permutationBlock in ((BlockField)pitchRangeBlock.Fields[7]).BlockList) { foreach (Block permutationChunkBlock in ((BlockField)permutationBlock.Fields[6]).BlockList) { rawOffset = (int)permutationChunkBlock.Fields[0].Value; if (soundCacheFileGestaltEntry.Raws[RawSection.Sound].ContainsRawOffset(rawOffset)) { tagGroupFile.SetRaw(rawOffset, soundCacheFileGestaltEntry.Raws[RawSection.Sound][rawOffset].ToArray()); } } } } foreach (Block extraInfoBlock in ((BlockField)soundBlock.Fields[15]).BlockList) { ITagBlock globalGeometryBlockInfoStruct = (ITagBlock)extraInfoBlock.Fields[2].Value; if (soundCacheFileGestaltEntry.Raws[RawSection.LipSync].ContainsRawOffset(rawOffset)) { tagGroupFile.SetRaw(rawOffset, soundCacheFileGestaltEntry.Raws[RawSection.LipSync][rawOffset].ToArray()); } } } //Create Directory.CreateDirectory(Path.GetDirectoryName(absolutePath)); //Set tag group tagGroupFile.TagGroup = tagGroup; //Create file using (FileStream fs = new FileStream(absolutePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) tagGroupFile.Save(fs); } }
public ResourceKeyStack BranchFor(ITagGroup group) { var branch = (ResourceKeyStack) MemberwiseClone(); branch._group = group; return branch; }
private void SoundTagGroup_CreateResources(ITagGroup tagGroup, IndexEntry entry, BinaryWriter writer, ref TagGroupHeader header) { List <long> addresses = new List <long>(); List <byte[]> buffers = new List <byte[]>(); foreach (ITagBlock pitchRange in ((BlockField)tagGroup[0][13]).BlockList) { foreach (ITagBlock permutation in ((BlockField)pitchRange[7]).BlockList) { foreach (ITagBlock chunk in ((BlockField)permutation[6]).BlockList) { int address = (int)chunk[0].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } else if ((address & 0xC0000000) == 0) { System.Diagnostics.Debugger.Break(); } } } } foreach (ITagBlock extraInfo in ((BlockField)tagGroup[0][15]).BlockList) { ITagBlock geometry = (ITagBlock)extraInfo[2].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } } if (header.TagResourceCount > 0) { header.RawOffsetsOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write((int)addresses[i]); } header.RawLengthsOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write(buffers[i].Length); } header.RawDataOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write(buffers[i]); } } }
private void analyzeMapsToolStripMenuItem_Click(object sender, EventArgs e) { //Prepare ITagGroup tagGroup = null; sharedResources = new SharedTagResources(); List <string> header = new List <string>(); DateTime start = DateTime.Now; //Add header.Add("Abide Guerilla Analyzer"); header.Add(string.Empty); //Loop foreach (string file in Directory.GetFiles(@"F:\XBox\Original\Games\Halo 2\Clean Maps", "*.map")) { using (MapFile map = new MapFile()) { //Load start = DateTime.Now; map.Load(file); //Check type using (var reader = map.Scenario.TagData.CreateReader()) { reader.BaseStream.Seek(map.Scenario.Offset + 16, SeekOrigin.Begin); short mapType = reader.ReadInt16(); switch (mapType) { case 0: sharedResources.CollideSingleplayer(map.IndexEntries.Select( i => { tagGroup = TagLookup.CreateTagGroup(i.Root); return($"{i.Filename}.{tagGroup.GroupName}"); }).ToArray()); break; case 1: sharedResources.CollideMultiplayer(map.IndexEntries.Select( i => { tagGroup = TagLookup.CreateTagGroup(i.Root); return($"{i.Filename}.{tagGroup.GroupName}"); }).ToArray()); break; } } //Add header.Add($"{file} loaded in {(DateTime.Now - start).TotalSeconds} seconds"); } } //Create file using (StreamWriter writer = File.CreateText(Path.Combine(Application.StartupPath, "resource analysis.log"))) { //Write header foreach (string line in header) { writer.WriteLine(line); } //Write line writer.WriteLine(); writer.WriteLine(); //Write ui resources writer.WriteLine($"ui shared resources (count {sharedResources.UiSharedResourceCount}):"); foreach (string resource in sharedResources.GetUiResources()) { writer.WriteLine($"@\"{resource}\","); } //Write line writer.WriteLine(); writer.WriteLine(); //Write multiplayer resources writer.WriteLine($"multiplayer shared resources (count {sharedResources.MultiplayerSharedResourceCount}):"); foreach (string resource in sharedResources.GetMultiplayerSharedResources()) { writer.WriteLine($"@\"{resource}\","); } //Write line writer.WriteLine(); writer.WriteLine(); //Write singleplayer resources writer.WriteLine($"singleplayer shared resources (count {sharedResources.SingleplayerSharedResourceCount}):"); foreach (string resource in sharedResources.GetSingleplayerSharedResources()) { writer.WriteLine($"@\"{resource}\","); } } }
public ITagLib Register(ITagGroup group) { return(_top.Register(group)); }
private void FixSystemLinkButton_Click(object sender, EventArgs e) { /* * Heh I guess Entity is good for something :P */ //Prepare ITagGroup tagGroup = null; ITagGroup scenario = new Scenario(); ITagBlock scenarioBlock = null, simulationDefinitionTableElementBlock = null; BlockField simulationDefinitionTableField = null; List <IndexEntry> simulationDefinitionEntries = new List <IndexEntry>(); bool success = false; //Build table foreach (IndexEntry entry in Map.IndexEntries) { switch (entry.Root) { case "bipd": case "bloc": case "ctrl": case "jpt!": case "mach": case "scen": case "ssce": case "vehi": simulationDefinitionEntries.Add(entry); break; case "eqip": case "garb": case "proj": simulationDefinitionEntries.Add(entry); simulationDefinitionEntries.Add(entry); break; case "weap": simulationDefinitionEntries.Add(entry); simulationDefinitionEntries.Add(entry); simulationDefinitionEntries.Add(entry); break; } } //Read scenario using (BinaryReader reader = Map.Scenario.TagData.CreateReader()) { reader.BaseStream.Seek((uint)Map.Scenario.PostProcessedOffset, SeekOrigin.Begin); scenario.Read(reader); } //Re-create simulation definition table scenarioBlock = scenario[0]; simulationDefinitionTableField = (BlockField)scenarioBlock[143]; simulationDefinitionTableField.BlockList.Clear(); foreach (IndexEntry entry in simulationDefinitionEntries) { //Attempt to add tag block simulationDefinitionTableElementBlock = simulationDefinitionTableField.Add(out success); if (success) { simulationDefinitionTableElementBlock[0].Value = entry.Id; } } //Rebuild map using (VirtualStream tagDataStream = new VirtualStream(Map.TagDataStream.MemoryAddress)) using (BinaryWriter writer = tagDataStream.CreateWriter()) using (BinaryReader reader = Map.TagDataStream.CreateReader()) { //Loop foreach (IndexEntry entry in Map.IndexEntries.Where(ie => ie.Offset > 0 && ie.Size > 0)) { //Read (unless it's our modified scenario) if (entry != Map.Scenario) { tagGroup = TagLookup.CreateTagGroup(entry.Root); reader.BaseStream.Seek(entry.Offset, SeekOrigin.Begin); tagGroup.Read(reader); } else { tagGroup = scenario; } //Create buffer using (VirtualStream stream = new VirtualStream(tagDataStream.Position)) using (BinaryWriter tagWriter = stream.CreateWriter()) using (BinaryReader tagReader = stream.CreateReader()) { //Write tagGroup.Write(tagWriter); //Recalculate raw addresses Helper.RecalculateRawAddresses(entry.Raws, entry.Root, stream, tagReader, tagWriter); //Setup tag entry.Offset = (uint)stream.MemoryAddress; entry.Size = (int)stream.Length; //Write to tag data stream writer.Write(stream.ToArray()); } } //Align tagDataStream.Align(4096); //Swap Map.SwapTagBuffer(tagDataStream.ToArray(), tagDataStream.MemoryAddress); } }
private void ScenarioStructureLightmapTagGroup_CreateResources(ITagGroup guerillaTagGroup, IndexEntry entry, BinaryWriter writer, ref TagGroupHeader header) { List <long> addresses = new List <long>(); List <byte[]> buffers = new List <byte[]>(); foreach (ITagBlock structureLightmapGroup in ((BlockField)guerillaTagGroup[0][16]).BlockList) { foreach (ITagBlock cluster in ((BlockField)structureLightmapGroup[6]).BlockList) { ITagBlock geometry = (ITagBlock)cluster[1].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } } foreach (ITagBlock lightmapGeometrySectionBlock in ((BlockField)structureLightmapGroup[8]).BlockList) { ITagBlock geometry = (ITagBlock)lightmapGeometrySectionBlock[1].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } } foreach (ITagBlock lightmapVertexBufferBucket in ((BlockField)structureLightmapGroup[10]).BlockList) { ITagBlock geometry = (ITagBlock)lightmapVertexBufferBucket[3].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } } } if (header.TagResourceCount > 0) { header.RawOffsetsOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write((int)addresses[i]); } header.RawLengthsOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write(buffers[i].Length); } header.RawDataOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write(buffers[i]); } } }
private void ScenarioStructureBspTagGroup_CreateResources(ITagGroup guerillaTagGroup, IndexEntry entry, BinaryWriter writer, ref TagGroupHeader header) { List <long> addresses = new List <long>(); List <byte[]> buffers = new List <byte[]>(); foreach (ITagBlock structureBspCluster in ((BlockField)guerillaTagGroup[0][19]).BlockList) { ITagBlock geometry = (ITagBlock)structureBspCluster[1].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } } foreach (ITagBlock structureBspInstancedGeometryDefinition in ((BlockField)guerillaTagGroup[0][39]).BlockList) { ITagBlock renderInfo = (ITagBlock)structureBspInstancedGeometryDefinition[0].Value; ITagBlock geometry = (ITagBlock)renderInfo[1].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } } foreach (ITagBlock structureBspWaterDefinition in ((BlockField)guerillaTagGroup[0][50]).BlockList) { ITagBlock geometry = (ITagBlock)structureBspWaterDefinition[2].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } } foreach (ITagBlock decoratorPlacementDefinition in ((BlockField)guerillaTagGroup[0][54]).BlockList) { foreach (ITagBlock decoratorCacheBlock in ((BlockField)decoratorPlacementDefinition[2]).BlockList) { ITagBlock geometry = (ITagBlock)decoratorCacheBlock[0].Value; int address = (int)geometry[1].Value; if (entry.Resources.TryGetResource(address, out var resource)) { header.TagResourceCount++; addresses.Add(address); buffers.Add(resource.GetBuffer()); } } } if (header.TagResourceCount > 0) { header.RawOffsetsOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write((int)addresses[i]); } header.RawLengthsOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write(buffers[i].Length); } header.RawDataOffset = (uint)writer.BaseStream.Position; for (int i = 0; i < header.TagResourceCount; i++) { writer.Write(buffers[i]); } } }
/// <summary> /// Adds a tag to the table and allocates space for its base data. /// </summary> /// <param name="tagGroup">The tag's group.</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 added.</returns> public ITag AddTag(ITagGroup tagGroup, int baseSize, IStream stream) { return(AddTag(tagGroup.Magic, baseSize, stream)); }
public ITagLib Register(ITagGroup group) { return _top.Register(group); }
public void Register(ITagGroup group) { _lib.Register(group); }
public ThirdGenTag(DatumIndex index, ITagGroup tagGroup, SegmentPointer metaLocation) { Index = index; Group = tagGroup; MetaLocation = metaLocation; }
public void Prepare(ITagGroup group) { }
public TagGroupReqHdlr(ILoggerFactory loggerFactory, ITagGroup tagGroupRepository) { _loggerFactory = loggerFactory; _logger = _loggerFactory.CreateLogger <TagGroupReqHdlr>(); _tagGroupRepository = tagGroupRepository; }
public TagGroupReqHdlr(ILoggerFactory loggerFactory, IDatabaseUnitOfWork unitOfWork, ITagGroup tagGroupRepository, IMapper mapper) { _loggerFactory = loggerFactory; _logger = _loggerFactory.CreateLogger <TagGroupReqHdlr>(); _unitOfWork = unitOfWork; _tagGroupRepository = tagGroupRepository; _mapper = mapper; }