Esempio n. 1
0
        public void PrettyPrint()
        {
            var loadedFile = new NbtFile(TestFiles.Big);

            Assert.AreEqual(loadedFile.RootTag.ToString(), loadedFile.ToString());
            Assert.AreEqual(loadedFile.RootTag.ToString("   "), loadedFile.ToString("   "));
            Assert.Throws <ArgumentNullException>(() => loadedFile.ToString(null));
            Assert.Throws <ArgumentNullException>(() => NbtTag.DefaultIndentString = null);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var file = new NbtFile(@"C:\Users\ZACH-GAMING\Downloads\madiaval-lamp.schematic");

            Console.WriteLine(file.ToString("\t"));
            Console.ReadLine();
        }
Esempio n. 3
0
        private static string SkullUrl(NbtFile file)
        {
            string base64 = null;

            try
            {
                base64 = file.RootTag.Get <NbtList>("i")
                         .Get <NbtCompound>(0)
                         .Get <NbtCompound>("tag")
                         .Get <NbtCompound>("SkullOwner")
                         .Get <NbtCompound>("Properties")
                         .Get <NbtList>("textures")
                         .Get <NbtCompound>(0)
                         .Get <NbtString>("Value").StringValue;
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error in parsing {file.ToString()} {e.Message}");
            }

            //Console.WriteLine(base64);
            base64 = base64.Replace('-', '+');
            base64 = base64.Replace('_', '/');

            string json = null;

            try
            {
                json = Encoding.UTF8.GetString(Convert.FromBase64String(base64.Trim()));
            }
            catch (Exception)
            {
                // somethimes the "==" is missing idk why
                try
                {
                    json = Encoding.UTF8.GetString(Convert.FromBase64String(base64.Trim() + "="));
                }
                catch (Exception)
                {
                    json = Encoding.UTF8.GetString(Convert.FromBase64String(base64 + "=="));
                }
                Console.WriteLine(json);

                //return null;
            }

            dynamic result = JsonConvert.DeserializeObject(json);

            return(result.textures.SKIN.url);
        }
Esempio n. 4
0
        public void BlockEntityTest()
        {
            NbtFile file = new NbtFile();

            file.BigEndian = false;
            var compound = file.RootTag = new NbtCompound(string.Empty);

            compound.Add(new NbtString("Text1", "first line"));
            compound.Add(new NbtString("Text2", "second line"));
            compound.Add(new NbtString("Text3", "third line"));
            compound.Add(new NbtString("Text4", "forth line"));
            compound.Add(new NbtString("id", "Sign"));
            compound.Add(new NbtInt("x", 6));
            compound.Add(new NbtInt("y", 6));
            compound.Add(new NbtInt("z", 6));

            Console.WriteLine(file.ToString());

            Nbt nbt = new Nbt();

            nbt.NbtFile = file;
            McpeTileEntityData message = new McpeTileEntityData()
            {
                x        = 6,
                y        = 6,
                z        = 6,
                namedtag = nbt
            };

            Assert.NotNull(message.Encode());
            Console.WriteLine(ByteArrayToString(message.Encode()));

            var b = new byte[]
            {
                0xb8, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x06, 0x0a, 0x00, 0x00, 0x08, 0x02,
                0x00, 0x49, 0x64, 0x04, 0x00, 0x53, 0x69, 0x67, 0x6e, 0x03, 0x01, 0x00, 0x78, 0x06, 0x00,
                0x00, 0x00, 0x03, 0x01, 0x00, 0x79, 0x06, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x7a, 0x06,
                0x00, 0x00, 0x00, 0x08, 0x05, 0x00, 0x54, 0x65, 0x78, 0x74, 0x31, 0x0a, 0x00, 0x66, 0x69,
                0x72, 0x73, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x08, 0x05, 0x00, 0x54, 0x65, 0x78, 0x74,
                0x32, 0x0b, 0x00, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x08,
                0x05, 0x00, 0x54, 0x65, 0x78, 0x74, 0x33, 0x0a, 0x00, 0x74, 0x68, 0x69, 0x72, 0x64, 0x20,
                0x6c, 0x69, 0x6e, 0x65, 0x08, 0x05, 0x00, 0x54, 0x65, 0x78, 0x74, 0x34, 0x0a, 0x00, 0x66,
                0x6f, 0x72, 0x74, 0x68, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x00,
            };
        }
Esempio n. 5
0
        private void speichernToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (object o in tabControlNBT.SelectedTab.Controls)
            {
                if (o is TreeView)
                {
                    NbtFile file = null;
                    //NbtFile file = new NbtFile();
                    foreach (KeyValuePair <string, KeyValuePair <NBTTab, TabPage> > val in nbtPages)
                    {
                        (new AlertForm($"string key: {val.Key}")).ShowDialog();
                        if (val.Key == Path.GetFileName(tabControlNBT.SelectedTab.Name))
                        {
                            file = ((NBTTab)(val.Value.Key))._NBTFile;
                        }
                    }
                    if (file == null)
                    {
                        return;
                    }

                    /*NbtTag tree = MainClass.TreeToNBT(((TreeView)o).Nodes);
                     * if (tree is NbtCompound)
                     *  file.RootTag = (NbtCompound)tree;
                     * else
                     * {
                     *  file.RootTag = new NbtCompound("");
                     *  file.RootTag.Add(tree);
                     * }
                     * NbtFile original = new NbtFile(tabControlNBT.SelectedTab.Name);
                     * (new AlertForm(file.RootTag.ToString())
                     * {
                     *  Text = "original file direct root tag"
                     * }).ShowDialog();*/
                    (new AlertForm(file.ToString())).ShowDialog();
                    file.SaveToFile(Path.GetFullPath(file.FileName).Replace(Path.GetFileName(file.FileName), "") + Path.GetFileNameWithoutExtension(file.FileName) + "_DEBUG" + Path.GetExtension(file.FileName), file.FileCompression);//TODO remove _DEBUG
                    break;
                }
            }
        }
Esempio n. 6
0
        public override string ToString()
        {
            if (Empty)
            {
                return("(Empty)");
            }
            string result = "ID: " + Id;

            if (Count != 1)
            {
                result += "; Count: " + Count;
            }
            if (Metadata != 0)
            {
                result += "; Metadata: " + Metadata;
            }
            if (Nbt != null)
            {
                result += Environment.NewLine + Nbt.ToString();
            }
            return("(" + result + ")");
        }
Esempio n. 7
0
        public void CompoundListTest()
        {
            // test writing various combinations of compound tags and list tags
            const string testString = "Come on and slam, and welcome to the jam.";
            using (var ms = new MemoryStream()) {
                var writer = new NbtWriter(ms, "Test");
                {
                    writer.BeginCompound("EmptyCompy"); {}
                    writer.EndCompound();

                    writer.BeginCompound("OuterNestedCompy");
                    {
                        writer.BeginCompound("InnerNestedCompy");
                        {
                            writer.WriteInt("IntTest", 123);
                            writer.WriteString("StringTest", testString);
                        }
                        writer.EndCompound();
                    }
                    writer.EndCompound();

                    writer.BeginList("ListOfInts", NbtTagType.Int, 3);
                    {
                        writer.WriteInt(1);
                        writer.WriteInt(2);
                        writer.WriteInt(3);
                    }
                    writer.EndList();

                    writer.BeginCompound("CompoundOfListsOfCompounds");
                    {
                        writer.BeginList("ListOfCompounds", NbtTagType.Compound, 1);
                        {
                            writer.BeginCompound();
                            {
                                writer.WriteInt("TestInt", 123);
                            }
                            writer.EndCompound();
                        }
                        writer.EndList();
                    }
                    writer.EndCompound();

                    writer.BeginList("ListOfEmptyLists", NbtTagType.List, 3);
                    {
                        writer.BeginList(NbtTagType.List, 0); {}
                        writer.EndList();
                        writer.BeginList(NbtTagType.List, 0); {}
                        writer.EndList();
                        writer.BeginList(NbtTagType.List, 0); {}
                        writer.EndList();
                    }
                    writer.EndList();
                }
                writer.EndCompound();
                writer.Finish();

                ms.Seek(0, SeekOrigin.Begin);
                var file = new NbtFile();
                file.LoadFromStream(ms, NbtCompression.None);
                Console.WriteLine(file.ToString());
            }
        }
Esempio n. 8
0
        public void CompoundListTest()
        {
            // test writing various combinations of compound tags and list tags
            const string testString = "Come on and slam, and welcome to the jam.";

            using (var ms = new MemoryStream()) {
                var writer = new NbtWriter(ms, "Test");
                {
                    writer.BeginCompound("EmptyCompy"); {}
                    writer.EndCompound();

                    writer.BeginCompound("OuterNestedCompy");
                    {
                        writer.BeginCompound("InnerNestedCompy");
                        {
                            writer.WriteInt("IntTest", 123);
                            writer.WriteString("StringTest", testString);
                        }
                        writer.EndCompound();
                    }
                    writer.EndCompound();

                    writer.BeginList("ListOfInts", NbtTagType.Int, 3);
                    {
                        writer.WriteInt(1);
                        writer.WriteInt(2);
                        writer.WriteInt(3);
                    }
                    writer.EndList();

                    writer.BeginCompound("CompoundOfListsOfCompounds");
                    {
                        writer.BeginList("ListOfCompounds", NbtTagType.Compound, 1);
                        {
                            writer.BeginCompound();
                            {
                                writer.WriteInt("TestInt", 123);
                            }
                            writer.EndCompound();
                        }
                        writer.EndList();
                    }
                    writer.EndCompound();


                    writer.BeginList("ListOfEmptyLists", NbtTagType.List, 3);
                    {
                        writer.BeginList(NbtTagType.List, 0); {}
                        writer.EndList();
                        writer.BeginList(NbtTagType.List, 0); {}
                        writer.EndList();
                        writer.BeginList(NbtTagType.List, 0); {}
                        writer.EndList();
                    }
                    writer.EndList();
                }
                writer.EndCompound();
                writer.Finish();

                ms.Seek(0, SeekOrigin.Begin);
                var file = new NbtFile();
                file.LoadFromStream(ms, NbtCompression.None);
                Console.WriteLine(file.ToString());
            }
        }
Esempio n. 9
0
 public void PrettyPrint()
 {
     var loadedFile = new NbtFile(TestFiles.Big);
     Assert.AreEqual(loadedFile.RootTag.ToString(), loadedFile.ToString());
     Assert.AreEqual(loadedFile.RootTag.ToString("   "), loadedFile.ToString("   "));
     Assert.Throws<ArgumentNullException>(() => loadedFile.ToString(null));
     Assert.Throws<ArgumentNullException>(() => NbtTag.DefaultIndentString = null);
 }