示例#1
0
 public void WriteObject(IHSDNode o)
 {
     if (o == null)
     {
         return;
     }
     Align(4);
     if (!ObjectOffsets.ContainsKey(o))
     {
         o.Save(this);
     }
 }
示例#2
0
        public override void Close()
        {
            // Grab Vertex Buffers Here

            // Gather all data offsets including the vertex buffer ones and texture buffers
            List <uint> Offsets = NodeCache.Keys.ToList();

            for (int i = 0; i < NodeCache.Keys.Count; i++)
            {
                IHSDNode ob = NodeCache[Offsets[i]];
                if (ob is HSD_AttributeGroup)
                {
                    foreach (GX.GXVertexBuffer a in ((HSD_AttributeGroup)ob).Attributes)
                    {
                        if (!Offsets.Contains(a.Offset))
                        {
                            Offsets.Add(a.Offset);
                        }
                    }
                }
            }
            Offsets.AddRange(BufferCache.Keys.ToList());

            // sort them from lowest to highest
            Offsets.Sort();

            // get the minimum next offset for each buffer
            foreach (uint off in NodeCache.Keys)
            {
                IHSDNode ob = NodeCache[off];
                if (ob is HSD_AttributeGroup)
                {
                    foreach (HSDLib.GX.GXVertexBuffer a in ((HSD_AttributeGroup)ob).Attributes)
                    {
                        if (a.AttributeType != GX.GXAttribType.GX_DIRECT)
                        {
                            a.DataBuffer = ReadBuffer(a.Offset, (int)(Offsets[BinarySearch(Offsets, a.Offset)] - a.Offset));
                        }
                    }
                }
            }

            // Close the stream
            base.Close();
        }
示例#3
0
        /// <summary>
        /// Reads properties from the HSDReader stream
        /// </summary>
        /// <param name="Reader"></param>
        public virtual void Open(HSDReader Reader)
        {
            foreach (var prop in GetType().GetProperties())
            {
                var attrs = (FieldData[])prop.GetCustomAttributes(typeof(FieldData), false);

                var  type   = prop.PropertyType;
                bool inLine = false;
                bool ignore = false;
                foreach (var attr in prop.GetCustomAttributes(false))
                {
                    if (attr is FieldData field)
                    {
                        type = field.Type;
                    }
                    if (attr is HSDInLineAttribute inline)
                    {
                        inLine = true;
                    }
                    if (attr is HSDParseIgnoreAttribute)
                    {
                        ignore = true;
                    }
                }
                if (ignore)
                {
                    continue;
                }
                if (type.IsSubclassOf(typeof(IHSDNode)))
                {
                    uint     temp       = Reader.Position() + 4;
                    IHSDNode field      = (IHSDNode)Activator.CreateInstance(type);
                    dynamic  changedObj = field;
                    uint     Offset     = Reader.Position();
                    if (!inLine)
                    {
                        Offset = Reader.ReadUInt32();
                    }
                    prop.SetValue(this, Reader.ReadObject(Offset, changedObj));
                    if (!inLine)
                    {
                        Reader.Seek(temp);
                    }
                }
                else
                if (type == typeof(uint))
                {
                    prop.SetValue(this, Reader.ReadUInt32());
                }
                else
                if (type == typeof(int))
                {
                    prop.SetValue(this, Reader.ReadInt32());
                }
                else
                if (type == typeof(float))
                {
                    prop.SetValue(this, Reader.ReadSingle());
                }
                else
                if (type == typeof(ushort))
                {
                    prop.SetValue(this, Reader.ReadUInt16());
                }
                else
                if (type == typeof(short))
                {
                    prop.SetValue(this, Reader.ReadInt16());
                }
                else
                if (type == typeof(bool))
                {
                    prop.SetValue(this, Reader.ReadBoolean());
                }
                else
                if (type == typeof(string))
                {
                    prop.SetValue(this, Reader.ReadString(Reader.ReadInt32()));
                }
                else
                if (type == typeof(byte))
                {
                    if (type.IsEnum)
                    {
                        prop.SetValue(this, (Enum)Enum.ToObject(prop.PropertyType, Reader.ReadByte()));
                    }
                    else
                    {
                        prop.SetValue(this, Reader.ReadByte());
                    }
                }
                else if (type.IsEnum)
                {
                    prop.SetValue(this, (Enum)Enum.ToObject(type, Reader.ReadUInt32()));
                }
                else
                {
                    throw new InvalidOperationException("Failed to read " + type);
                }
            }
        }
示例#4
0
 public override void Open(HSDReader Reader)
 {
     // Assuming Node Type from the root name
     if (Name.EndsWith("matanim_joint"))
     {
         Node = Reader.ReadObject <HSD_MatAnimJoint>(Offset);
     }
     else if (Name.EndsWith("_joint"))
     {
         Node = Reader.ReadObject <HSD_JOBJ>(Offset);
     }
     else if (Name.EndsWith("_figatree"))
     {
         Node = Reader.ReadObject <HSD_FigaTree>(Offset);
     }
     else if (Name.StartsWith("vcDataStar") || Name.StartsWith("vcDataWing"))
     {
         Node = Reader.ReadObject <KAR_VcStarVehicle>(Offset);
     }
     else if (Name.StartsWith("vcDataWheel"))
     {
         Node = Reader.ReadObject <KAR_WheelVehicle>(Offset);
     }
     else if (Name.StartsWith("grModelMotion"))
     {
         Node = Reader.ReadObject <KAR_GrModelMotion>(Offset);
     }
     else if (Name.StartsWith("grModel"))
     {
         Node = Reader.ReadObject <KAR_GrModel>(Offset);
     }
     else if (Name.StartsWith("grData"))
     {
         Node = Reader.ReadObject <KAR_GrData>(Offset);
     }
     else if (Name.StartsWith("ftData"))
     {
         Node = Reader.ReadObject <SBM_FighterData>(Offset);
     }
     else if (Name.StartsWith("grGroundParam"))
     {
         Node = Reader.ReadObject <SBM_GrGroundParam>(Offset);
     }
     else if (Name.StartsWith("coll_data"))
     {
         Node = Reader.ReadObject <SBM_GrCollData>(Offset);
     }
     else if (Name.StartsWith("map_plit"))
     {
         Node = Reader.ReadObject <SBM_GrMapPLIT>(Offset);
     }
     else if (Name.StartsWith("ALDYakuAll"))
     {
         Node = Reader.ReadObject <SBM_GrYakuAll>(Offset);
     }
     else if (Name.StartsWith("map_head"))
     {
         Node = Reader.ReadObject <SBM_GrMapHead>(Offset);
     }
     else if (Name.StartsWith("map_texg"))
     {
         Node = Reader.ReadObject <SBM_GrMapTexG>(Offset);
     }
     else if (Name.StartsWith("Sc"))
     {
         Node = Reader.ReadObject <HSD_SOBJ>(Offset);
     }
 }