public static void DumpTagLayouts(string exePath, string folder) { // Open the guerilla executable. BinaryReader reader = new BinaryReader(new FileStream(exePath, FileMode.Open, FileAccess.Read, FileShare.Read)); // Load the h2 language library. IntPtr h2LangLib = LoadLibrary(H2LanguageLibrary); // Loop through all the tag layouts and extract each one. for (int i = 0; i < NumberOfTagLayouts; i++) { // Go to the tag layout table. reader.BaseStream.Position = TagLayoutTableAddress - BaseAddress + (i * 4); // Read the tag layout pointer. int layoutAddress = reader.ReadInt32(); // Go to the tag layout and read it. reader.BaseStream.Position = layoutAddress - BaseAddress; tag_group tag = new tag_group(); tag.Read(h2LangLib, reader); // Print the name of the layout. Console.WriteLine("found tag_group: {0}", tag.Name); // Create the tag layout file. StreamWriter writer = new StreamWriter(string.Format("{0}\\{1}.h", folder, tag.Name)); // Write a header for the layout. writer.WriteLine("/*********************************************************************"); writer.WriteLine("* name: {0}", tag.Name); writer.WriteLine("* flags: {0}", tag.flags); writer.WriteLine("* group_tag: {0}", tag.GroupTag); writer.WriteLine("* parent group_tag: {0}", tag.ParentGroupTag); writer.WriteLine("* version: {0}", tag.version); writer.WriteLine("*"); writer.WriteLine("* postprocess_proc:\t\t0x{0}", tag.postprocess_proc.ToString("x08")); writer.WriteLine("* save_postprocess_proc:\t0x{0}", tag.save_postprocess_proc.ToString("x08")); writer.WriteLine("* postprocess_for_sync_proc:\t0x{0}", tag.postprocess_for_sync_proc.ToString("x08")); writer.WriteLine("**********************************************************************/"); // Process the tag_group definition. //ProcessTagBlockDefinition(h2LangLib, reader, writer, tag.definition_address, tag.GroupTag, new tag_field(), ""); // Close the tag layout writer. writer.Close(); } // Close the reader stream. reader.Close(); }
/// <summary> /// Creates a TagGroupDefinitionAttribute CodeDOM declaration. /// </summary> /// <param name="tagGroup">Guerill tag group definition.</param> /// <param name="definitionSize">Alternative calculated size of the definition, overrides fieldSet.size</param> /// <returns>A CodeDOM attribute declaration.</returns> public static CodeAttributeDeclaration CreateAttributeDeclaration(tag_group tagGroup, int definitionSize = 0) { // Get the latest field set from the guerilla definition. tag_field_set fieldSet = tagGroup.Definition.TagFieldSets[tagGroup.Definition.GetFieldSetIndexClosestToH2Xbox()]; // Setup a TagGroupDefinitionAttribute attribute using the definition info. CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(TagGroupDefinitionAttribute).Name, new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeSnippetExpression(string.Format("sizeOf: {0}", (definitionSize != 0 ? definitionSize : fieldSet.size)))), new CodeAttributeArgument(new CodeSnippetExpression(string.Format("version: {0}", tagGroup.version))), new CodeAttributeArgument(new CodeSnippetExpression(string.Format("groupTag: \"{0}\"", tagGroup.GroupTag))) }); // Return the new attribute declaration. return(attribute); }
public void CreateTagLayout(GuerillaReader reader, MutationCodeScope parentScope) { // Our child code creator for the tag group/block. MutationCodeCreator childCodeCreator = null; // Check if this tag block is a tag group. if (this.TagBlockDefinition.IsTagGroup == true) { // Get the tag group that points to this tag block definition. tag_group tagGroup = reader.TagGroups.First(tag => tag.definition_address == this.TagBlockDefinition.s_tag_block_definition.address); // Compute the size of the definition. int definitionSize = TagLayoutValidator.ComputeMutationDefinitionSize(reader, tagGroup.Definition.TagFields[tagGroup.Definition.GetFieldSetIndexClosestToH2Xbox()]); // Check if the tag group has a parent tag group it inherits from. if (tagGroup.ParentGroupTag != string.Empty) { // Get the parent tag group object. tag_group parentTagGroup = reader.TagGroups.First(tag => tag.GroupTag.Equals(tagGroup.ParentGroupTag) == true); // Now find the code scope for the parent tag layout. MutationCodeScope parentTagScope = parentScope.Types.Values.First(scope => scope.DefinitionAddress == parentTagGroup.definition_address); // Create a new tag group class. childCodeCreator = this.CodeCreator.CreateTagGroupClass(this.TypeName, TagGroupDefinitionAttribute.CreateAttributeDeclaration(tagGroup, definitionSize), parentTagScope.Namespace); } else { // Create a new tag group class. childCodeCreator = this.CodeCreator.CreateTagGroupClass(this.TypeName, TagGroupDefinitionAttribute.CreateAttributeDeclaration(tagGroup, definitionSize)); } } else { // Compute the size of the definition. int definitionSize = TagLayoutValidator.ComputeMutationDefinitionSize(reader, this.TagBlockDefinition.TagFields[this.TagBlockDefinition.GetFieldSetIndexClosestToH2Xbox()]); // Create a new tag block class. childCodeCreator = this.CodeCreator.CreateTagBlockClass(this.TypeName, TagBlockDefinitionAttribute.CreateAttributeDeclaration(this.TagBlockDefinition, definitionSize)); } // Process the tag block definition. ProcessTagBlockDefinition(reader, this.TagBlockDefinition, childCodeCreator, this.CodeScope, parentScope); }