예제 #1
0
        private void WriteSsbh(SsbhFile file, bool isLastWrite)
        {
            foreach (var prop in file.GetType().GetProperties())
            {
                // Some more matl hacks.
                if (ParseTag.ShouldSkipProperty(prop))
                {
                    continue;
                }

                // Check for types that use offsets.
                if (prop.PropertyType == typeof(string))
                {
                    // TODO: Is this check necessary?
                    if (prop.GetValue(file) == null)
                    {
                        // Write placeholder relative offset.
                        Write(0L);
                        continue;
                    }
                    objectWriteQueue.Enqueue(new ObjectWriteInfo(prop.GetValue(file), (uint)Position));
                    // Write placeholder relative offset.
                    Write(0L);
                }
                else if (prop.PropertyType.IsArray)
                {
                    var array = (prop.GetValue(file) as Array);
                    if (array.Length > 0)
                    {
                        objectWriteQueue.Enqueue(new ObjectWriteInfo(array, (uint)Position));
                    }
                    else
                    {
                        objectWriteQueue.Enqueue(new ObjectWriteInfo(array));
                    }

                    // Write placeholder relative offset.
                    Write(0L);
                    Write((long)array.Length);
                }
                else if (prop.PropertyType == typeof(SsbhOffset))
                {
                    // HACK: for materials
                    var dataObject = file.GetType().GetProperty("DataObject").GetValue(file);
                    var matEntry   = new MaterialEntry(dataObject);
                    objectWriteQueue.Enqueue(new ObjectWriteInfo(matEntry, (uint)Position));
                    // Write placeholder relative offset.
                    Write(0L);
                }
                else
                {
                    WriteProperty(prop.GetValue(file), isLastWrite);
                }
            }
        }
예제 #2
0
        private void WriteSsbhFile(SsbhFile 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);
        }