예제 #1
0
        private void ProcessTagBlockDefinition(TagBlockDefinition tagBlock, XmlWriter writer, int address,
                                               ref int fieldOffset, string group_tag = "", string className = "", bool root = false, bool inline = false,
                                               IList <tag_field> fieldOverride       = null)
        {
            IList <tag_field> fields = tagBlock.LatestFieldSet.Fields;

            if (fieldOverride != null)
            {
                fields = fieldOverride;
            }

            var size = CalculateSizeOfFieldSet(fields);

            if (size == 0)
            {
                if (!inline)
                {
                    WritePaddingField(writer, 8, fieldOffset);
                }
                return;
            }

            if (root)
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("plugin");
                writer.WriteAttributeString("class", group_tag);
                writer.WriteAttributeString("author", "Moonfxsh");
                writer.WriteAttributeString("headersize", size.ToString());
                writer.WriteAttributeString("date", DateTime.Now.ToShortDateString());
            }
            else if (!inline)
            {
                writer.WriteStartElement("struct");
                WriteNameAndDescriptionAttributes(writer, className == string.Empty ? tagBlock.DisplayName : className);
                writer.WriteAttributeString("type", tagBlock.Name);
                writer.WriteAttributeString("offset", fieldOffset.ToString());
                writer.WriteAttributeString("size", size.ToString());
                writer.WriteAttributeString("maxelements", tagBlock.maximum_element_count.ToString());
                writer.WriteAttributeString("padalign", tagBlock.LatestFieldSet.Alignment.ToString());
                writer.WriteAttributeString("visible", "false");
            }

            var i      = 0;
            var offset = !inline ? 0 : fieldOffset;

            ProcessFields(tagBlock, writer, fields, ref i, ref offset);


            // Finish the tag_field_set struct.
            if (!inline)
            {
                writer.WriteEndElement();
            }
        }
예제 #2
0
        private void ProcessArrayFields(TagBlockDefinition definition, XmlWriter writer, IList <tag_field> fields, ref tag_field field, ref int i, ref int offset)
        {
            var name = field.Name;

            ++i;    //move past field_type._field_array_start
            for (int index = 0; index < field.definition; ++index)
            {
                int startindex = i;
                ProcessFields(definition, writer, fields, ref startindex, ref offset);
            }
            ++i;    // move past field_type._field_array_end
        }
예제 #3
0
        public MoonfishTagDefinition(TagBlockDefinition definition)
            : this()
        {
            Name                = definition.Name;
            DisplayName         = definition.DisplayName;
            MaximumElementCount = definition.maximum_element_count;
            Alignment           = definition.LatestFieldSet.Alignment;

            var definitionFields = definition.LatestFieldSet.Fields;

            Fields = new List <MoonfishTagField>(definitionFields.Count);
            foreach (var field in definitionFields)
            {
                var moonfishField = new MoonfishTagField((MoonfishFieldType)field.type, field.Name);

                moonfishField.AssignCount(field.definition);

                if (field.Definition is TagBlockDefinition)
                {
                    var fieldDefinition = (TagBlockDefinition)field.Definition;
                    moonfishField.AssignDefinition(new MoonfishTagDefinition(fieldDefinition));
                }
                if (field.Definition is enum_definition)
                {
                    var fieldDefinition = (enum_definition)field.Definition;
                    moonfishField.AssignDefinition(new MoonfishTagEnumDefinition(fieldDefinition));
                }
                if (field.Definition is tag_struct_definition)
                {
                    var fieldDefinition = (tag_struct_definition)field.Definition;
                    moonfishField.AssignDefinition(new MoonfishTagStruct(fieldDefinition));
                }
                if (field.Definition is tag_data_definition)
                {
                    var fieldDefinition = (tag_data_definition)field.Definition;
                    moonfishField.AssignDefinition(new MoonfishTagDataDefinition(fieldDefinition));
                }
                if (field.Definition is tag_reference_definition)
                {
                    var fieldDefinition = (tag_reference_definition)field.Definition;
                    moonfishField.AssignDefinition(new MoonfishTagReferenceDefinition(fieldDefinition));
                }
                if (field.Definition is string)
                {
                    moonfishField.AssignDefinition((string)field.Definition);
                }

                Fields.Add(moonfishField);
            }
            Fields = new List <MoonfishTagField>(Guerilla.PostProcess(Name, Fields));
        }
예제 #4
0
        public ClassInfo BeginProcessTagBlockDefinition(TagBlockDefinition block, int address, string group_tag = "", string className = "")
        {
            var size = CalculateSizeOfFieldSet(block.LatestFieldSet.Fields);

            ClassInfo @class = new ClassInfo()
            {
                AccessModifiers = AccessModifiers.Public,
                Value           = className == string.Empty ? GuerillaCs.ToTypeName(block.Name) : GuerillaCs.ToTypeName(className),
                Attributes      = { new AttributeInfo(typeof(LayoutAttribute), "Size", size) }
            };

            ProcessFields(block.LatestFieldSet.Fields, @class);
            @class.Format();
            return(@class);
        }
예제 #5
0
        public static int CalculateSizeOfField(tag_field field)
        {
            switch (field.type)
            {
            case field_type._field_struct:
            {
                tag_struct_definition struct_definition = (tag_struct_definition)field.Definition;
                TagBlockDefinition    blockDefinition   = struct_definition.Definition;

                return(CalculateSizeOfFieldSet(blockDefinition.LatestFieldSet.Fields));
            }

            case field_type._field_skip:
            case field_type._field_pad:
                return(field.definition);

            default:
                return(GetFieldSize(field.type));
            }
        }
예제 #6
0
        private ElementArray ProcessTagBlockDefinition(ElementArray parent, TagBlockDefinition tagBlock, ref int offset, bool inline = false, string group_tag = "")
        {
            var size = Guerilla.CalculateSizeOfFieldSet(tagBlock.LatestFieldSet.Fields);

            var blockElementArray = new ElementArray()
            {
                Name            = tagBlock.Name,
                ElementSize     = size,
                Address         = offset,
                Parent          = parent,
                MaxElementCount = tagBlock.maximum_element_count,
                Alignment       = tagBlock.LatestFieldSet.Alignment,
            };

            var i           = 0;
            int blockOffset = inline ? offset : 0;

            ProcessFields(tagBlock.LatestFieldSet.Fields, blockElementArray, ref i, ref blockOffset);
            if (inline)
            {
                offset = blockOffset;
            }
            return(blockElementArray);
        }
예제 #7
0
        private IEnumerable <ElementArray> ProcessTagStructDefinition(ElementArray parent, TagBlockDefinition definition, ref int offset)
        {
            var size = Guerilla.CalculateSizeOfFieldSet(definition.LatestFieldSet.Fields);

            var blockElementArray = new ElementArray()
            {
                Name            = definition.Name,
                ElementSize     = size,
                Address         = offset,
                Parent          = parent,
                MaxElementCount = definition.maximum_element_count,
                Alignment       = definition.LatestFieldSet.Alignment,
            };

            var i = 0;

            ProcessFields(definition.LatestFieldSet.Fields, blockElementArray, ref i, ref offset);
            return(blockElementArray.Children);
        }
예제 #8
0
 private ElementArray ProcessTagBlockDefinition(TagBlockDefinition tagBlock, ref int offset, bool inline = false)
 {
     return(ProcessTagBlockDefinition(null, tagBlock, ref offset, inline, ""));
 }
예제 #9
0
 public void Read(BinaryReader reader)
 {
     this = new TagBlockDefinition(reader);
 }
예제 #10
0
        public static List <tag_field> ReadFieldSet(this BinaryReader reader, ref TagBlockDefinition definition, out tag_field_set field_set)
        {
            field_set = new tag_field_set();
            if (definition.Name == "sound_block")
            {
                definition.field_sets_address = 0x957870;
                //definition.field_set_latest_address = 0x906178;
                field_set.version.fields_address = 0x906178;
                field_set.version.index          = 0;
                field_set.version.upgrade_proc   = 0;
                field_set.version.size_of        = -1;
                field_set.size                 = 172;
                field_set.alignment_bit        = 0;
                field_set.parent_version_index = -1;
                field_set.fields_address       = 0x906178;
                field_set.size_string_address  = 0x00795330;
                field_set.size_string          = "sizeof(sound_definition)";
            }
            else
            {
                // We are going to use the latest tag_field_set for right now.
                if (definition.Name == "animation_pool_block")
                {
                    reader.BaseStream.Position = definition.field_sets_address + ((definition.field_set_count - 2) * 76) - Guerilla.BaseAddress;
                }
                else if (definition.Name == "decorator_cache_block_data_block")
                {
                    reader.BaseStream.Position = definition.field_sets_address + ((definition.field_set_count - 1) * 76) - Guerilla.BaseAddress;
                }
                else
                {
                    reader.BaseStream.Position = definition.field_set_latest_address - Guerilla.BaseAddress;
                }
                field_set = reader.ReadFieldDefinition <tag_field_set>();
            }
            // Seek to the field set address.
            reader.BaseStream.Position = field_set.fields_address - Guerilla.BaseAddress;

            var fields = new List <tag_field>();
            var field  = new tag_field();

            do
            {
                long currentAddress = reader.BaseStream.Position;
                field = reader.ReadFieldDefinition <tag_field>();
                fields.Add(field);
                // Seek to the next tag_field.
                reader.BaseStream.Position = currentAddress + 16;// sizeof(tag_field);
            }while (field.type != field_type._field_terminator);
            var blockName = definition.Name;
            var methods   = (from method in Assembly.GetExecutingAssembly().GetTypes().SelectMany(x => x.GetMethods(BindingFlags.NonPublic | BindingFlags.Static))
                             where method.IsDefined(typeof(GuerillaPreProcessMethodAttribute), false)
                             from attribute in method.GetCustomAttributes(typeof(GuerillaPreProcessMethodAttribute), false)
                             where (attribute as GuerillaPreProcessMethodAttribute).BlockName == blockName
                             select method).ToArray();

            if (methods.Count() > 0)
            {
                methods[0].Invoke(null, new object[] { reader, fields });
            }
            return(fields);
        }
예제 #11
0
 public void Read(IntPtr h2LangLib, BinaryReader reader)
 {
     this = new TagBlockDefinition(reader);
 }
예제 #12
0
        private void ProcessFields(TagBlockDefinition tagBlock, XmlWriter writer, IList <tag_field> fields, ref int i, ref int fieldOffset)
        {
            writer.Flush();
            for (; i < fields.Count; ++i)
            {
                var field = fields[i];
                // Check the field type.
                switch (field.type)
                {
                case field_type._field_tag_reference:
                {
                    WriteField(writer, "tag", field.Name, fieldOffset + 0);
                    WriteField(writer, "id", field.Name, fieldOffset + 4);
                    break;
                }

                case field_type._field_block:
                {
                    ProcessTagBlockDefinition(field.Definition, writer, field.definition, ref fieldOffset, "", field.Name);
                    break;
                }

                case field_type._field_struct:
                {
                    tag_struct_definition struct_definition = (tag_struct_definition)field.Definition;
                    var fieldType = ToTypeName(struct_definition.name);

                    ProcessTagBlockDefinition(struct_definition.Definition, writer, struct_definition.block_definition_address, ref fieldOffset, "", field.Name, false, true);

                    break;
                }

                case field_type._field_data:
                {
                    {
                        writer.WriteStartElement("struct");
                        writer.WriteAttributeString("name", field.Name);
                        writer.WriteAttributeString("offset", fieldOffset.ToString());
                        writer.WriteAttributeString("size", 1.ToString());
                        writer.WriteAttributeString("maxelements", ((tag_data_definition)field.Definition).maximumSize.ToString());
                        writer.WriteAttributeString("padalign", ((tag_data_definition)field.Definition).Alignment.ToString());
                        writer.WriteStartElement("byte");
                        writer.WriteAttributeString("name", "data");
                        writer.WriteAttributeString("offset", 1.ToString());
                        writer.WriteAttributeString("visible", "false");
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                    break;
                }

                case field_type._field_explanation:
                {
                    //// Check if there is sub-text for this explaination.
                    //string subtext = "";
                    //if (field.definition != 0)
                    //    subtext = Guerilla.ReadString(reader, field.definition);

                    // Write the field info to the output file.
                    //writer.WriteComment(string.Format("FIELD_EXPLAINATION(\"{0}\", \"{1}\"),", field.Name, subtext.Replace("\n", "<lb>")));
                    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:
                {
                    WriteEnumElement(writer, field.Definition, ref field, fieldOffset);
                    break;
                }

                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_block_index1:
                case field_type._field_short_block_index1:
                case field_type._field_long_block_index1:
                {
                    WriteField(writer, field, fieldOffset);
                    break;
                }

                case field_type._field_char_block_index2:
                case field_type._field_short_block_index2:
                case field_type._field_long_block_index2:
                {
                    WriteField(writer, field, fieldOffset);
                    break;
                }

                case field_type._field_array_start:
                {
                    ProcessArrayFields(tagBlock, writer, fields, ref field, ref i, ref fieldOffset);
                    break;
                }

                case field_type._field_array_end:
                {
                    return;
                }

                case field_type._field_string:
                {
                    WriteField(writer, "string32", field.Name, fieldOffset + 0);
                } break;

                case field_type._field_long_string:
                {
                    WriteField(writer, "string256", field.Name, fieldOffset + 0);
                } break;

                case field_type._field_pad:
                {
                    WritePaddingField(writer, field.definition, fieldOffset, tagBlock.DisplayName);
                    break;
                }

                case field_type._field_skip:
                {
                    WritePaddingField(writer, field.definition, fieldOffset);
                    break;
                }

                case field_type._field_useless_pad:
                case field_type._field_terminator:
                case field_type._field_custom:
                {
                    break;
                }

                default:
                {
                    //attributeString.Append("TagField");
                    WriteField(writer, field, fieldOffset);
                    break;
                }
                }
                fieldOffset += CalculateSizeOfField(field);
            }
        }