Ejemplo n.º 1
0
        private bool Skip(ISSBH_File File, PropertyInfo prop)
        {
            object[] attrs = prop.GetCustomAttributes(true);
            bool     skip  = false;

            foreach (object attr in attrs)
            {
                if (attr is ParseTag tag)
                {
                    if (!tag.IF.Equals(""))
                    {
                        string[]     args      = tag.IF.Split('>');
                        PropertyInfo checkprop = null;
                        foreach (PropertyInfo pi in File.GetType().GetProperties())
                        {
                            if (pi.Name.Equals(args[0]))
                            {
                                checkprop = pi;
                                break;
                            }
                        }
                        skip = true;
                        if (checkprop != null)
                        {
                            if ((ushort)checkprop.GetValue(File) > int.Parse(args[1]))
                            {
                                skip = false;
                                break;
                            }
                        }
                    }
                }
            }
            return(skip);
        }
Ejemplo n.º 2
0
        private void WriteSSBHFile(ISSBH_File File)
        {
            foreach (var prop in File.GetType().GetProperties())
            {
                if (Skip(File, prop))
                {
                    continue;
                }

                if (prop.PropertyType == typeof(string))
                {
                    objectQueue.AddLast(prop.GetValue(File));
                    objectOffset.Add((uint)Position, prop.GetValue(File));
                    Write((long)0);
                }
                else if (prop.PropertyType.IsArray)
                {
                    var  Array  = (prop.GetValue(File) as Array);
                    bool Inline = false;
                    if (prop.GetCustomAttribute(typeof(ParseTag)) != null)
                    {
                        Inline = ((ParseTag)prop.GetCustomAttribute(typeof(ParseTag))).InLine;
                    }

                    if (!Inline)
                    {
                        if (Array.Length > 0)
                        {
                            objectOffset.Add((uint)Position, Array);
                        }
                        objectQueue.AddLast(Array);
                        Write((long)0);
                        Write((long)Array.Length);
                    }
                    else
                    {
                        // inline array
                        foreach (object o in Array)
                        {
                            WriteProperty(o);
                        }
                    }
                }
                else
                {
                    WriteProperty(prop.GetValue(File));
                }
            }

            // Post Write
            // TODO: mostly for materials....
        }
Ejemplo n.º 3
0
        private void WriteSSBHFile(ISSBH_File file)
        {
            foreach (var prop in file.GetType().GetProperties())
            {
                if (Skip(file, prop))
                {
                    continue;
                }

                if (prop.PropertyType == typeof(string))
                {
                    if (prop.GetValue(file) == null)
                    {
                        Write((long)0);
                        continue;
                    }
                    objectQueue.AddLast(prop.GetValue(file));
                    objectOffset.Add((uint)Position, prop.GetValue(file));
                    Write((long)0);
                }
                else if (prop.PropertyType.IsArray)
                {
                    var  array  = (prop.GetValue(file) as Array);
                    bool inline = false;
                    if (prop.GetCustomAttribute(typeof(ParseTag)) != null)
                    {
                        inline = ((ParseTag)prop.GetCustomAttribute(typeof(ParseTag))).InLine;
                    }

                    if (!inline)
                    {
                        if (array.Length > 0)
                        {
                            objectOffset.Add((uint)Position, array);
                        }
                        objectQueue.AddLast(array);
                        Write((long)0);
                        Write((long)array.Length);
                    }
                    else
                    {
                        // inline array
                        foreach (object o in array)
                        {
                            WriteProperty(o);
                        }
                    }
                }
                else if (prop.PropertyType == typeof(SSBHOffset))
                {
                    // HACK: for materials
                    var dataObject = file.GetType().GetProperty("DataObject").GetValue(file);
                    var matentry   = new MaterialEntry(dataObject);
                    objectOffset.Add((uint)Position, matentry);
                    objectQueue.AddLast(matentry);
                    Write((long)0);
                }
                else
                {
                    WriteProperty(prop.GetValue(file));
                }
            }


            // TODO: Post Write is only used for materials.
            file.PostWrite(this);
        }