/// <summary> /// Creates a new code safe field name that is unique in the current scope and adds it to the fields list for this scope. /// </summary> /// <param name="fieldType">Type of field.</param> /// <param name="fieldName">Name of the field</param> /// <param name="displayName">The UI mark up display name for the field.</param> /// <param name="units">String to receive the units specifier is one is present</param> /// <param name="tooltip">String to receive the tooltip text if it is present</param> /// <param name="markupFlags">The UI markup flags for this field.</param> /// <returns>The new code safe field name for the field</returns> public string CreateCodeSafeFieldName(field_type fieldType, string fieldName, out string displayName, out string units, out string tooltip, out EditorMarkUpFlags markupFlags) { string newFieldName = ""; // Satisfy the compiler. displayName = string.Empty; units = string.Empty; tooltip = string.Empty; markupFlags = EditorMarkUpFlags.None; // Check if the field is a padding field. if (fieldType == field_type._field_pad || fieldType == field_type._field_skip || fieldType == field_type._field_useless_pad) { // Create a new padding field name. return(AddPaddingField()); } else if (fieldType == field_type._field_explanation) { // Create a new explanation field name. return(AddExplanationField()); } // Check if the name is invalid. if (MutationCodeFormatter.IsValidFieldName(fieldName) == false) { // Create a new no-name field name. return(AddNoNameField()); } // Convert the field name to a code safe representation. MutationCodeFormatter.ProcessFieldName(fieldName, out newFieldName, out displayName, out units, out tooltip, out markupFlags); if (newFieldName == "") { // Create a new no-name field name. return(AddNoNameField()); } // Make sure the new field name is unique in the code scope. if (this.Fields.Contains(newFieldName) == true) { string tempFieldName = ""; // Loop and append an integer until the field name becomes unique. int uniqueInt = 1; do { // Append an integer to the field name to try and make it unique. tempFieldName = String.Format("{0}{1}", newFieldName, uniqueInt++); }while (this.Fields.Contains(tempFieldName) == true); // Save the new field name. newFieldName = tempFieldName; } // Add the new field name to the fields list. this.Fields.Add(newFieldName); // Return the new field name. return(newFieldName); }
public virtual void Read(IntPtr h2LangLib, BinaryReader reader) { // Read all the fields from the stream. this.type = (field_type)reader.ReadInt16(); reader.BaseStream.Position += 2; this.name_address = reader.ReadInt32(); this.definition_address = reader.ReadInt32(); this.group_tag = reader.ReadInt32(); // Read the name string. this.name = Guerilla.Guerilla.ReadString(h2LangLib, reader, this.name_address); }
public void Read(IntPtr h2LangLib, BinaryReader reader) { // Read all the fields from the stream. this.type = (field_type)reader.ReadInt16(); this.padding = reader.ReadInt16(); this.name_address = reader.ReadInt32(); this.definition = reader.ReadInt32(); this.group_tag = reader.ReadInt32(); // Read Properties this.Name = Guerilla.ReadString(reader, this.name_address); this.Definition = ReadDefinition(reader); }
/// <summary> /// Takes a Guerilla field_type and returns the corresponding PaddingType value. /// </summary> /// <param name="fieldType">Guerilla field type to convert.</param> /// <returns>Corresponding PaddingType value.</returns> public static PaddingType PaddingTypeFromFieldType(field_type fieldType) { // Return the corresponding PaddingType value for the field type. if (fieldType == field_type._field_pad) { return(PaddingType.Padding); } else if (fieldType == field_type._field_skip) { return(PaddingType.Skip); } else { return(PaddingType.Useless); } }
/// <summary> /// Creates a PaddingAttribute CodeDOM declaration. /// </summary> /// <param name="fieldType">Guerilla field type.</param> /// <param name="length">Length of the padding field.</param> /// <returns>A CodeCOM attribute delcaration.</returns> public static CodeAttributeDeclaration CreateAttributeDeclaration(field_type fieldType, int length) { // Create an expression for the padding type parameter. CodeFieldReferenceExpression attPadType = new CodeFieldReferenceExpression( new CodeTypeReferenceExpression(typeof(PaddingType).Name), PaddingAttribute.PaddingTypeFromFieldType(fieldType).ToString()); // Create the PaddingAttribute attribute using the parameters. CodeAttributeDeclaration attribute = new CodeAttributeDeclaration( typeof(PaddingAttribute).Name, new CodeAttributeArgument(attPadType), new CodeAttributeArgument(new CodePrimitiveExpression(length))); // Return the attribute instance. return(attribute); }
public void Read(BinaryReader reader) { // Read all the fields from the stream. type = (field_type)reader.ReadInt16(); if (type == field_type._field_rgb_color) { } padding = reader.ReadInt16(); name_address = reader.ReadInt32(); definition = reader.ReadInt32(); group_tag = reader.ReadInt32(); // Read Properties Name = Guerilla.ReadString(reader, name_address); Definition = ReadDefinition(reader); }
/// <summary> /// Creates a new field for the specified type and adds it to the current code object. /// </summary> /// <param name="fieldType">Guerilla field type of the field.</param> /// <param name="fieldName">Name of the field.</param> /// <param name="attributeCollection">Collection of attributes to be put on the field.</param> public void AddField(field_type fieldType, string fieldName, CodeAttributeDeclarationCollection attributeCollection = null) { // Get the underlying type for this field. Type standardFieldType = ValueTypeDictionary[fieldType]; // Create a new code member field for the tag field. CodeMemberField field = new CodeMemberField(MutationCodeFormatter.CreateShortCodeTypeReference(standardFieldType, MutationNamespaces), fieldName); field.Attributes = MemberAttributes.Public; // Add any attributes for this field. field.CustomAttributes = attributeCollection; // Add the field to the class definition. this.CodeClass.Members.Add(field); }
/// <summary> /// Creates a new field for a custom type and adds it to the current code object. /// </summary> /// <param name="fieldType">Guerilla field type of the field.</param> /// <param name="fieldName">Name of the field.</param> /// <param name="fieldTypeName">Name of the custom type.</param> /// <param name="attributeCollection">Collection of attributes to be put on the field.</param> public void AddCustomTypedField(field_type fieldType, string fieldName, string fieldTypeName, CodeAttributeDeclarationCollection attributeCollection = null) { // Get the underlying type for this field. Type standardFieldType = ValueTypeDictionary[fieldType]; // If the field name is the same as the type name then we have to append an '@' character. if (fieldName.Equals(fieldTypeName) == true) { fieldName.Insert(0, "@"); } // Create a new code member field for the tag field. CodeMemberField field = new CodeMemberField(fieldTypeName, fieldName); field.Attributes = MemberAttributes.Public; // Add any attributes for this field. field.CustomAttributes = attributeCollection; // Add the field to the class definition. this.CodeClass.Members.Add(field); }
private void ReadTagBlockDefinition(int address, bool isSound, TagBlockDefinition parent) { // Check if this tag_block_definition has already been read. if (this.TagBlockDefinitions.ContainsKey(address) == true) { //// Check if this definition has a parent and if so add a reference to it. //if (parent != null) //{ // // Add the parent defintion as a reference. // this.TagBlockDefinitions[address].AddReference(parent); //} // Don't process the tag block. return; } // Seek to the definition address. this.reader.BaseStream.Position = address - Guerilla.BaseAddress; // Initialize and read the tag_block_definition struct. TagBlockDefinition tagBlockDef = new TagBlockDefinition(); tagBlockDef.s_tag_block_definition.address = address; tagBlockDef.s_tag_block_definition.Read(h2LangLib, reader); // Special case tags may need the field set addresses adjusted. if (isSound == true) { tagBlockDef.s_tag_block_definition.field_sets_address = 0;// 0x906178; tagBlockDef.s_tag_block_definition.field_set_count = 6; tagBlockDef.s_tag_block_definition.field_set_latest_address = 0x906178; } // Initialize the tag field set arrays. tagBlockDef.TagFieldSets = new tag_field_set[tagBlockDef.s_tag_block_definition.field_set_count]; tagBlockDef.TagFields = new List <tag_field> [tagBlockDef.s_tag_block_definition.field_set_count]; //// Check if this definition has a parent and if so add a reference to it. //if (parent != null) //{ // // Add the parent defintion as a reference. // tagBlockDef.AddReference(parent); //} // Add the tag block definition to the dictionary. this.TagBlockDefinitions.Add(address, tagBlockDef); // Loop through all the tag_field_set's and read each one. for (int i = 0; i < tagBlockDef.s_tag_block_definition.field_set_count; i++) { // Special case tags may need the field set addresses adjusted. if (isSound == true) { // Initialize the field set. tagBlockDef.TagFieldSets[i] = new tag_field_set(); // Manuall fill in the information. if (i == 0) { // Seek to the tag_field_set definition address. reader.BaseStream.Position = 0x957A60 - Guerilla.BaseAddress; tagBlockDef.TagFieldSets[i].Read(h2LangLib, reader); } else if (i == 1 || i == 2 || i == 3) // 2 & 3 { // Seek to the tag_field_set definition address. reader.BaseStream.Position = 0x957448 - Guerilla.BaseAddress; tagBlockDef.TagFieldSets[i].Read(h2LangLib, reader); } else if (i == 4) // 4 { tagBlockDef.TagFieldSets[i].version.fields_address = 0x906078; tagBlockDef.TagFieldSets[i].version.index = 0; tagBlockDef.TagFieldSets[i].version.upgrade_proc = 0x49F700; tagBlockDef.TagFieldSets[i].version.size_of = -1; tagBlockDef.TagFieldSets[i].size = 176; tagBlockDef.TagFieldSets[i].alignment_bit = 0; tagBlockDef.TagFieldSets[i].parent_version_index = -1; tagBlockDef.TagFieldSets[i].fields_address = 0x906078; tagBlockDef.TagFieldSets[i].size_string = "sizeof(struct sound_definition_v1)"; } else if (i == 5) // 5 { tagBlockDef.TagFieldSets[i].version.fields_address = 0x906178; tagBlockDef.TagFieldSets[i].version.index = 0; tagBlockDef.TagFieldSets[i].version.upgrade_proc = 0; tagBlockDef.TagFieldSets[i].version.size_of = -1; tagBlockDef.TagFieldSets[i].size = 172; tagBlockDef.TagFieldSets[i].alignment_bit = 0; tagBlockDef.TagFieldSets[i].parent_version_index = -1; tagBlockDef.TagFieldSets[i].fields_address = 0x906178; tagBlockDef.TagFieldSets[i].size_string = "sizeof(sound_definition)"; } } else { // Seek to the tag_field_set definition address. reader.BaseStream.Position = tagBlockDef.s_tag_block_definition.field_sets_address + (i * 76) - Guerilla.BaseAddress; // Initialize and read the tag_field_set struct. tagBlockDef.TagFieldSets[i] = new tag_field_set(); tagBlockDef.TagFieldSets[i].Read(h2LangLib, reader); } // Check if this is the latest tag field set. if (tagBlockDef.s_tag_block_definition.field_set_latest_address == tagBlockDef.TagFieldSets[i].address) { tagBlockDef.TagFieldSetLatestIndex = i; } // Initialize the tag field list. tagBlockDef.TagFields[i] = new List <tag_field>(); // Seek to the tag field set address. this.reader.BaseStream.Position = tagBlockDef.TagFieldSets[i].fields_address - Guerilla.BaseAddress; // Loop through all the tag fields and read each one. tag_field field = new tag_field(); do { // Save the current address. long currentAddress = this.reader.BaseStream.Position; // Read the field type from the stream. field_type fieldType = (field_type)this.reader.ReadInt16(); // Create the field type accordingly. switch (fieldType) { case field_type._field_tag_reference: field = new tag_reference_definition(); break; case field_type._field_struct: field = new tag_struct_definition(); break; case field_type._field_data: field = new tag_data_definition(); break; case field_type._field_byte_flags: case field_type._field_long_flags: case field_type._field_word_flags: case field_type._field_char_enum: case field_type._field_enum: case field_type._field_long_enum: field = new enum_definition(); break; case field_type._field_char_block_index2: case field_type._field_short_block_index2: case field_type._field_long_block_index2: field = new block_index_custom_search_definition(); break; case field_type._field_explanation: field = new explaination_definition(); break; default: field = new tag_field(); break; } // Read the tag field from the stream. this.reader.BaseStream.Position = currentAddress; field.Read(h2LangLib, reader); // Add the field to the list. tagBlockDef.TagFields[i].Add(field); // Read any tag_block definitions. switch (field.type) { case field_type._field_byte_block_flags: case field_type._field_word_block_flags: case field_type._field_long_block_flags: case field_type._field_char_integer: case field_type._field_short_integer: case field_type._field_long_integer: case field_type._field_block: { // Check if the definition address is valid. if (field.definition_address != 0) { ReadTagBlockDefinition(field.definition_address, false, tagBlockDef); } break; } case field_type._field_struct: { ReadTagBlockDefinition(((tag_struct_definition)field).block_definition_address, false, tagBlockDef); break; } } // Seek to the next tag_field. this.reader.BaseStream.Position = currentAddress + 16; //sizeof(tag_field) }while (field.type != field_type._field_terminator); } }
public void Read(IntPtr h2LangLib, BinaryReader reader) { // Read all the fields from the stream. this.type = (field_type)reader.ReadInt16(); this.padding = reader.ReadInt16(); this.name_address = reader.ReadInt32(); this.definition = reader.ReadInt32(); this.group_tag = reader.ReadInt32(); // Read Properties this.Name = Guerilla.ReadString(reader, this.name_address); this.Definition = ReadDefinition(reader); }
public static int GetFieldSize(field_type type) { switch (type) { #region Standard Types case field_type._field_char_integer: case field_type._field_char_enum: case field_type._field_byte_flags: case field_type._field_byte_block_flags: case field_type._field_char_block_index1: case field_type._field_char_block_index2: return(1); case field_type._field_short_integer: case field_type._field_enum: case field_type._field_word_flags: case field_type._field_word_block_flags: case field_type._field_short_block_index1: case field_type._field_short_block_index2: return(2); case field_type._field_long_integer: case field_type._field_long_enum: case field_type._field_long_flags: case field_type._field_long_block_flags: case field_type._field_long_block_index1: case field_type._field_long_block_index2: return(4); #endregion case field_type._field_string: return(32); case field_type._field_long_string: return(256); case field_type._field_string_id: case field_type._field_old_string_id: //? return(4); case field_type._field_point_2d: { return(4); } case field_type._field_rectangle_2d: return(8); #region Real, Vector, Point, Angle Types case field_type._field_real: case field_type._field_angle: case field_type._field_real_fraction: return(4); case field_type._field_real_point_2d: case field_type._field_real_vector_2d: case field_type._field_real_euler_angles_2d: return(8); case field_type._field_real_point_3d: case field_type._field_real_vector_3d: case field_type._field_real_euler_angles_3d: return(12); case field_type._field_real_quaternion: return(16); case field_type._field_real_plane_2d: return(12); case field_type._field_real_plane_3d: return(16); #endregion #region Colour Types case field_type._field_rgb_color: return(3); case field_type._field_argb_color: return(4); case field_type._field_real_rgb_color: case field_type._field_real_hsv_color: return(12); case field_type._field_real_argb_color: case field_type._field_real_ahsv_color: return(16); #endregion #region Bounds case field_type._field_short_bounds: return(4); case field_type._field_angle_bounds: case field_type._field_real_bounds: case field_type._field_real_fraction_bounds: return(8); #endregion case field_type._field_tag: return(4); case field_type._field_tag_reference: case field_type._field_block: case field_type._field_data: return(8); case field_type._field_vertex_buffer: return(32); case field_type._field_moonfish_ident: return(Marshal.SizeOf(typeof(Moonfish.Tags.TagIdent))); //case field_type._field_pad: //case field_type._field_skip: //case field_type._field_struct: case field_type._field_useless_pad: case field_type._field_array_start: case field_type._field_array_end: case field_type._field_explanation: case field_type._field_terminator: case field_type._field_custom: return(0); } throw new Exception(); }
public static int GetFieldSize(field_type type) { switch (type) { #region Standard Types case field_type._field_char_integer: case field_type._field_char_enum: case field_type._field_byte_flags: case field_type._field_byte_block_flags: case field_type._field_char_block_index1: case field_type._field_char_block_index2: return 1; case field_type._field_short_integer: case field_type._field_enum: case field_type._field_word_flags: case field_type._field_word_block_flags: case field_type._field_short_block_index1: case field_type._field_short_block_index2: return 2; case field_type._field_long_integer: case field_type._field_long_enum: case field_type._field_long_flags: case field_type._field_long_block_flags: case field_type._field_long_block_index1: case field_type._field_long_block_index2: return 4; #endregion case field_type._field_string: return 32; case field_type._field_long_string: return 256; case field_type._field_string_id: case field_type._field_old_string_id: //? return 4; case field_type._field_point_2d: { return 4; } case field_type._field_rectangle_2d: return 8; #region Real, Vector, Point, Angle Types case field_type._field_real: case field_type._field_angle: case field_type._field_real_fraction: return 4; case field_type._field_real_point_2d: case field_type._field_real_vector_2d: case field_type._field_real_euler_angles_2d: return 8; case field_type._field_real_point_3d: case field_type._field_real_vector_3d: case field_type._field_real_euler_angles_3d: return 12; case field_type._field_real_quaternion: return 16; case field_type._field_real_plane_2d: return 12; case field_type._field_real_plane_3d: return 16; #endregion #region Colour Types case field_type._field_rgb_color: return 3; case field_type._field_argb_color: return 4; case field_type._field_real_rgb_color: case field_type._field_real_hsv_color: return 12; case field_type._field_real_argb_color: case field_type._field_real_ahsv_color: return 16; #endregion #region Bounds case field_type._field_short_bounds: return 4; case field_type._field_angle_bounds: case field_type._field_real_bounds: case field_type._field_real_fraction_bounds: return 8; #endregion case field_type._field_tag: return 4; case field_type._field_tag_reference: case field_type._field_block: case field_type._field_data: return 8; case field_type._field_vertex_buffer: return 32; //case field_type._field_pad: //case field_type._field_skip: //case field_type._field_struct: case field_type._field_useless_pad: case field_type._field_array_start: case field_type._field_array_end: case field_type._field_explanation: case field_type._field_terminator: case field_type._field_custom: return 0; } throw new Exception(); }
public field(string name, field_type tp = field_type.text) { this.name = name; this.tp = tp; this.value = null; }
public GuerillaTypeAttribute(field_type fieldType) { this.fieldType = fieldType; }
/// <summary> /// Builds a dictionary of Guerilla field types and their corresponding size in terms of Guerilla field types. /// </summary> private static void CacheGuerillaFieldSizes() { // Initialize the field size dictionary. guerillaFieldSizes = new Dictionary <field_type, int>((int)field_type._field_type_max); // Loop through all of the guerilla field types and add each one to the size list. for (int i = 0; i < (int)field_type._field_type_max; i++) { // Get the current field type. field_type fieldType = (field_type)i; // Get the size accordingle. switch (fieldType) { case field_type._field_byte_block_flags: case field_type._field_byte_flags: case field_type._field_char_block_index1: case field_type._field_char_block_index2: case field_type._field_char_enum: case field_type._field_char_integer: { // 1-byte fields. guerillaFieldSizes.Add(fieldType, 1); break; } case field_type._field_enum: case field_type._field_short_block_index1: case field_type._field_short_block_index2: case field_type._field_short_integer: case field_type._field_word_block_flags: case field_type._field_word_flags: { // 2-byte fields. guerillaFieldSizes.Add(fieldType, 2); break; } case field_type._field_angle: case field_type._field_datum_index: case field_type._field_long_block_flags: case field_type._field_long_block_index1: case field_type._field_long_block_index2: case field_type._field_long_enum: case field_type._field_long_flags: case field_type._field_long_integer: case field_type._field_real: case field_type._field_real_fraction: case field_type._field_tag: case field_type._field_argb_color: case field_type._field_rgb_color: case field_type._field_short_bounds: case field_type._field_string_id: case field_type._field_old_string_id: case field_type._field_point_2d: { // 4-byte fields. guerillaFieldSizes.Add(fieldType, 4); break; } case field_type._field_angle_bounds: case field_type._field_real_bounds: case field_type._field_real_fraction_bounds: case field_type._field_real_euler_angles_2d: case field_type._field_real_point_2d: case field_type._field_rectangle_2d: case field_type._field_real_vector_2d: { // 8-byte fields. guerillaFieldSizes.Add(fieldType, 8); break; } case field_type._field_block: //case field_type._field_string_id: case field_type._field_real_euler_angles_3d: case field_type._field_real_hsv_color: case field_type._field_real_plane_2d: case field_type._field_real_point_3d: case field_type._field_real_rgb_color: case field_type._field_real_vector_3d: { // 12-byte fields. guerillaFieldSizes.Add(fieldType, 12); break; } case field_type._field_tag_reference: case field_type._field_real_argb_color: case field_type._field_real_ahsv_color: case field_type._field_real_plane_3d: case field_type._field_real_quaternion: { // 16-byte fields. guerillaFieldSizes.Add(fieldType, 16); break; } case field_type._field_data: { // 20 byte field. guerillaFieldSizes.Add(fieldType, 20); break; } case field_type._field_string: case field_type._field_vertex_buffer: //case field_type._field_old_string_id: { // 32-byte field. guerillaFieldSizes.Add(fieldType, 32); break; } case field_type._field_long_string: { // 256-byte field. guerillaFieldSizes.Add(fieldType, 256); break; } case field_type._field_array_start: case field_type._field_array_end: case field_type._field_custom: case field_type._field_explanation: case field_type._field_useless_pad: default: { // It's either some type of markup field or idfk. guerillaFieldSizes.Add(fieldType, 0); break; } } } }
public GuerillaTypeAttribute(field_type fieldType) { // Initialize fields. this.FieldType = fieldType; }