示例#1
0
        internal override void SkipTag(BinaryReader reader)
        {
            while (true)
            {
                NBTTagType nextTag = (NBTTagType)reader.ReadInt32();
                NBTTag     newTag  = null;
                switch (nextTag)
                {
                case NBTTagType.END:
                    return;

                case NBTTagType.COMPOUND:
                    newTag = new NBTFolder();
                    break;

                case NBTTagType.STRING:
                    newTag = new NBTString();
                    break;

                case NBTTagType.INT:
                    newTag = new NBTInt();
                    break;

                case NBTTagType.DOUBLE:
                    newTag = new NBTDouble();
                    break;

                case NBTTagType.STRINGARRAY:
                    newTag = new NBTStringArray();
                    break;

                case NBTTagType.FLOAT:
                    newTag = new NBTFloat();
                    break;

                case NBTTagType.INTARRAY:
                    newTag = new NBTIntArray();
                    break;

                case NBTTagType.BYTE:
                    newTag = new NBTByte();
                    break;

                case NBTTagType.BYTEARRAY:
                    newTag = new NBTByteArray();
                    break;

                case NBTTagType.FLOATARRAY:
                    newTag = new NBTFloatArray();
                    break;

                case NBTTagType.DOUBLEARRAY:
                    newTag = new NBTDoubleArray();
                    break;
                }
                reader.ReadString();
                newTag.SkipTag(reader);
            }
        }
示例#2
0
        private static void ProcessFields(FieldInfo[] fields, object src, NBTTag parent)
        {
            NBTTag currentParent = parent;

            foreach (FieldInfo fi in fields)
            {
                //Console.WriteLine($"Name: {fi.Name}\nType: {fi.FieldType.Name}\nValue: {fi.GetValue(src)}\n\n");
                NBTTag theTag = null;
                switch (fi.FieldType.Name)
                {
                case "String":
                    theTag = new NBTString(fi.Name, (string)fi.GetValue(src));

                    break;

                case "Int32":
                    theTag = new NBTInt(fi.Name, (int)fi.GetValue(src));
                    break;

                case "Double":
                    theTag = new NBTDouble(fi.Name, (double)fi.GetValue(src));
                    break;

                case "String[]":
                    theTag = new NBTStringArray(fi.Name, (string[])fi.GetValue(src));
                    break;

                case "Int32[]":
                    theTag = new NBTIntArray(fi.Name, (int[])fi.GetValue(src));
                    break;

                case "Single":
                    theTag = new NBTFloat(fi.Name, (float)fi.GetValue(src));
                    break;

                case "Byte":
                    theTag = new NBTByte(fi.Name, (byte)fi.GetValue(src));
                    break;

                case "List`1":
                    if (fi.GetValue(src).ToString().Contains("System.String"))
                    {
                        theTag = new NBTStringArray(fi.Name, (List <string>)fi.GetValue(src));
                    }
                    else if (fi.GetValue(src).ToString().Contains("System.Int32"))
                    {
                        theTag = new NBTIntArray(fi.Name, (List <int>)fi.GetValue(src));
                    }
                    else if (fi.GetValue(src).ToString().Contains("System.Byte"))
                    {
                        theTag = new NBTByteArray(fi.Name, (List <byte>)fi.GetValue(src));
                    }
                    else if (fi.GetValue(src).ToString().Contains("System.Single"))
                    {
                        theTag = new NBTFloatArray(fi.Name, (List <float>)fi.GetValue(src));
                    }
                    else if (fi.GetValue(src).ToString().Contains("System.Double"))
                    {
                        theTag = new NBTDoubleArray(fi.Name, (List <double>)fi.GetValue(src));
                    }
                    else
                    {
                        // Treat as a compound tag
                        NBTFolder tags = new NBTFolder(fi.Name);
                        Type      _typ = Type.GetType(fi.GetValue(src).ToString());
                        tags.Add(new NBTString("_TYPE", _typ.FullName));
                    }


                    if (theTag == null)
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }

                case "Byte[]":
                    theTag = new NBTByteArray(fi.Name, (byte[])fi.GetValue(src));
                    break;

                case "Single[]":
                    theTag = new NBTFloatArray(fi.Name, (float[])fi.GetValue(src));
                    break;

                case "Double[]":
                    theTag = new NBTDoubleArray(fi.Name, (double[])fi.GetValue(src));
                    break;

                default:
                    // Try to run as a folder
                    var       valx      = fi.GetValue(src);
                    NBTFolder thefolder = new NBTFolder(fi.Name);
                    ProcessFields(fi.FieldType.GetFields(), valx, thefolder);
                    theTag = thefolder;
                    break;
                }
                switch (currentParent.TagType)
                {
                case NBTTagType.COMPOUND:
                    NBTFolder parFold = currentParent as NBTFolder;
                    parFold.Add(theTag);
                    break;

                default:
                    continue;
                }
            }
        }
示例#3
0
        internal override bool ReadTag(BinaryReader reader)
        {
            if (Parent != null)
            {
                SkipTag(reader);
                return(false);
            }

            while (true)
            {
                NBTTagType nextTag = (NBTTagType)reader.ReadInt32();
                NBTTag     newTag  = null;
                switch (nextTag)
                {
                case NBTTagType.COMPOUND:
                    newTag = new NBTFolder();
                    break;

                case NBTTagType.STRING:
                    newTag = new NBTString();
                    break;

                case NBTTagType.END:
                    return(true);

                case NBTTagType.INT:
                    newTag = new NBTInt();
                    break;

                case NBTTagType.DOUBLE:
                    newTag = new NBTDouble();
                    break;

                case NBTTagType.STRINGARRAY:
                    newTag = new NBTStringArray();
                    break;

                case NBTTagType.FLOAT:
                    newTag = new NBTFloat();
                    break;

                case NBTTagType.INTARRAY:
                    newTag = new NBTIntArray();
                    break;

                case NBTTagType.BYTE:
                    newTag = new NBTByte();
                    break;

                case NBTTagType.BYTEARRAY:
                    newTag = new NBTByteArray();
                    break;

                case NBTTagType.FLOATARRAY:
                    newTag = new NBTFloatArray();
                    break;

                case NBTTagType.DOUBLEARRAY:
                    newTag = new NBTDoubleArray();
                    break;
                }

                newTag.Name = reader.ReadString();
                if (newTag.ReadTag(reader))
                {
                    tags.Add(newTag.Name, newTag);
                }
                newTag.Parent = this;
            }
        }
示例#4
0
 public NBTFloatArray(NBTFloatArray other) : this(other.Name, other.ToArray())
 {
 }