public List <Amf0Object> ReadAmf0(bool rootobject = false)
        {
            List <Amf0Object> retlist = new List <Amf0Object>();

            while (true)
            {
                Amf0Object ret = new Amf0Object();
                if (br.Remaining < 2 && rootobject)
                {
                    return(retlist);
                }
                ret.name = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt16())); //object name
                ret.type = (Amf0Object.Amf0Type)br.ReadByte();                     //type
                switch (ret.type)
                {
                case Amf0Object.Amf0Type.AMF0_NUMBER:                        //NUMBER
                    ret.data = br.ReadDouble();
                    break;

                case Amf0Object.Amf0Type.AMF0_BOOLEAN:                        //BOOLEAN
                    ret.data = br.ReadBoolean();
                    break;

                case Amf0Object.Amf0Type.AMF0_STRING:
                    ret.data = Encoding.UTF8.GetString(br.ReadBytes(br.ReadInt16()));
                    break;

                case Amf0Object.Amf0Type.AMF0_OBJECT:                        //OBJECT
                {
                    ret.data = ReadAmf0();
                }
                break;

                case Amf0Object.Amf0Type.AMF0_NULL:
                case Amf0Object.Amf0Type.AMF0_UNDEFINED:
                    ret.data = null;
                    break;

                case Amf0Object.Amf0Type.AMF0_ECMA_ARRAY:                        //ecma array
                {
                    br.ReadInt32();
                    var ecma = ReadAmf0();
                    ret.data = ecma;
                    //							if (ecma.Count != l)
                    //								throw new Exception("Corrupt ECMA array in SOL file");
                }
                break;

                case Amf0Object.Amf0Type.AMF0_OBJECT_END:
                    return(retlist);

                default:
                    throw new Exception("Error reading SOL file (40)");
                }
                retlist.Add(ret);
            }
        }
 public void WriteAmf0Object(Amf0Object obj)
 {
     bw.WriteMapleString(obj.name);
     if (obj.data == null)
     {
         bw.WriteByte(5);
     }
     else if (obj.data is List <Amf0Object> )
     {
         if (obj.type == Amf0Object.Amf0Type.AMF0_ECMA_ARRAY)
         {
             bw.WriteByte((byte)obj.type);
             var list = obj.data as List <Amf0Object>;
             bw.WriteInt(list.Count);
             int counter = 0;
             foreach (var lobj in list)
             {
                 if (lobj.name == null)
                 {
                     lobj.name = counter++.ToString(Program.Culture);
                 }
                 WriteAmf0Object(lobj);
             }
             bw.WriteShort(0);
             bw.WriteByte(9);
         }
         else                //OBJECT
         {
             obj.type = Amf0Object.Amf0Type.AMF0_OBJECT;
             bw.WriteByte((byte)obj.type);
             var list    = obj.data as List <Amf0Object>;
             int counter = 0;
             foreach (var lobj in list)
             {
                 if (lobj.name == null)
                 {
                     lobj.name = counter++.ToString(Program.Culture);
                 }
                 WriteAmf0Object(lobj);
             }
             bw.WriteShort(0);
             bw.WriteByte(9);
         }
     }
     else if (obj.data is int || obj.data is double || obj.data is float)
     {
         if (!(obj.data is double))
         {
             var data = Convert.ToDouble(obj.data);
             obj.data = data;
         }
         obj.type = Amf0Object.Amf0Type.AMF0_NUMBER;
         bw.WriteByte((byte)obj.type);
         bw.WriteDouble((double)obj.data);
     }
     else if (obj.data is string)
     {
         obj.type = Amf0Object.Amf0Type.AMF0_STRING;
         bw.WriteByte((byte)obj.type);
         bw.WriteMapleString((string)obj.data);
     }
     else if (obj.data is bool)
     {
         bw.WriteByte((byte)Amf0Object.Amf0Type.AMF0_BOOLEAN);
         bw.WriteByte(Convert.ToByte(obj.data));
     }
     else
     {
         throw new Exception("Unable to write type to sol file");
     }
 }