Esempio n. 1
0
 internal void PridejZakaznika(string zakaznik, byte velikost, string terp = "")
 {
     if (!ZakazniciS.ContainsKey(zakaznik))
     {
         ZakazniciS.Add(zakaznik, velikost);
         zak.RootTag.Add(new NbtCompound(zakaznik));
         zak.RootTag.Get <NbtCompound>(zakaznik).Add(new NbtString("Jmeno", zakaznik));
         zak.RootTag.Get <NbtCompound>(zakaznik).Add(new NbtByte("Velikost", velikost));
         if (velikost == 127)
         {
             zak.RootTag.Get <NbtCompound>(zakaznik).Add(new NbtString("Terp", terp));
         }
         zak.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\zakaznici", NbtCompression.GZip);
     }
     if (zak.RootTag.Get <NbtCompound>(zakaznik) == null)
     {
         zak.RootTag.Add(new NbtCompound(zakaznik));
         zak.RootTag.Get <NbtCompound>(zakaznik).Add(new NbtString("Jmeno", zakaznik));
         zak.RootTag.Get <NbtCompound>(zakaznik).Add(new NbtByte("Velikost", velikost));
         if (velikost == 127)
         {
             zak.RootTag.Get <NbtCompound>(zakaznik).Add(new NbtString("Terp", terp));
         }
         zak.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\zakaznici", NbtCompression.GZip);
     }
 }
Esempio n. 2
0
        public void SaveWorld()
        {
            NbtFile file = new NbtFile();

            try
            {
                file.RootTag.Clear();
            }
            catch { }

            NbtList cList = new NbtList("DATA");

            foreach (Coordinate c in coords)
            {
                NbtCompound cData = new NbtCompound();
                cData.Add(new NbtString("Name", c.Name));
                cData.Add(new NbtInt("X", c.X));
                cData.Add(new NbtInt("Y", c.Y));
                cData.Add(new NbtInt("Z", c.Z));
                cData.Add(new NbtInt("Dim", (int)c.dim));
                cList.Add(cData);
            }

            file.RootTag.Add(cList);
            file.SaveToFile(Path.Combine(dir, "coords.dat"), NbtCompression.None);
        }
Esempio n. 3
0
        public void Flush()
        {
            if (!IsDirty)
            {
                return;
            }
            var regionPath = Path.Join(RegionFolder, $"{X}.{Z}.rgn");

            if (File.Exists(regionPath))
            {
                File.Copy(regionPath, regionPath + ".bak");
            }

            var regionCompound = GetNbt();
            var regionFile     = new NbtFile();

            regionFile.RootTag = regionCompound;
            regionFile.SaveToFile(regionPath, NbtCompression.GZip);

            File.Delete(regionPath + ".bak");
            regionCompound = null;
            regionFile     = null;
            GC.Collect();
            IsDirty = false;
        }
Esempio n. 4
0
        internal static void Add(UpozorneniCls upozorneni)
        {
            NbtFile file = new NbtFile();

            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\upozorneni"))
            {
                file.LoadFromFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\upozorneni");
            }
            else
            {
                file.RootTag = new NbtCompound("Upozorneni");
                file.RootTag.Add(new NbtList("Upozorneni", NbtTagType.Compound));
            }
            NbtCompound newUpo = new NbtCompound();
            short       typUpo = 0;

            if (upozorneni.TypUpozorneni == Typ.RDP)
            {
                typUpo = 1;
            }
            else if (upozorneni.TypUpozorneni == Typ.Upozorneni)
            {
                typUpo = 0;
            }
            newUpo.Add(new NbtShort("Typ", typUpo));
            newUpo.Add(new NbtLong("Datum", upozorneni.Datum.Ticks));
            newUpo.Add(new NbtString("Popis", upozorneni.Popis));

            file.RootTag.Get <NbtList>("Upozorneni").Add(newUpo);
            file.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\upozorneni", NbtCompression.GZip);
        }
Esempio n. 5
0
 public void ReloadUncompressed()
 {
     NbtFile loadedFile = new NbtFile( "TestFiles/bigtest.nbt", NbtCompression.AutoDetect );
     loadedFile.SaveToFile( "TestTemp/bigtest.nbt", NbtCompression.None );
     loadedFile.LoadFromFile( "TestTemp/bigtest.nbt", NbtCompression.AutoDetect );
     AssertNbtBigFile( loadedFile );
 }
Esempio n. 6
0
        /// <summary>
        /// Saves this level. This will not work with an in-memory world.
        /// </summary>
        public void Save()
        {
            if (DatFile == null)
            {
                throw new InvalidOperationException("This level exists only in memory. Use Save(string).");
            }
            LastPlayed = DateTime.UtcNow.Ticks;
            var serializer = new NbtSerializer(typeof(Level));
            var tag        = serializer.Serialize(this, "Data") as NbtCompound;
            var file       = new NbtFile();

            file.RootTag.Add(tag);
            file.SaveToFile(DatFile, NbtCompression.GZip);
            // Save worlds
            foreach (var world in Worlds)
            {
                if (world.BaseDirectory == null)
                {
                    world.Save(Path.Combine(BaseDirectory, world.Name));
                }
                else
                {
                    world.Save();
                }
            }
        }
Esempio n. 7
0
        public void Save()
        {
            var path = Path.Combine(Directory.GetCurrentDirectory(), "players", Username + ".nbt");

            if (Program.ServerConfiguration.Singleplayer)
            {
                path = Path.Combine(((World)World).BaseDirectory, "player.nbt");
            }
            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            if (Entity == null) // I didn't think this could happen but null reference exceptions have been repoted here
            {
                return;
            }
            var nbt = new NbtFile(new NbtCompound("player", new NbtTag[]
            {
                new NbtString("username", Username),
                new NbtList("position", new[]
                {
                    new NbtDouble(Entity.Position.X),
                    new NbtDouble(Entity.Position.Y),
                    new NbtDouble(Entity.Position.Z)
                }),
                new NbtList("inventory", Inventory.GetSlots().Select(s => s.ToNbt())),
                new NbtShort("health", (Entity as PlayerEntity).Health),
                new NbtFloat("yaw", Entity.Yaw),
                new NbtFloat("pitch", Entity.Pitch),
            }
                                                  ));

            nbt.SaveToFile(path, NbtCompression.ZLib);
        }
Esempio n. 8
0
        /// <summary>
        /// Saves the game state to a file.
        /// </summary>
        public void saveToFile()
        {
            NbtCompound root = new NbtCompound("root");

            NbtCompound unlockedItems = new NbtCompound();

            unlockedItems.setTag("foundYoke", this.foundYoke);
            unlockedItems.setTag("foundPlayingCard", this.foundPlayingCard);
            unlockedItems.setTag("foundHammer", this.foundHammer);
            unlockedItems.setTag("foundGlasses", this.foundReadingGlasses);
            unlockedItems.setTag("foundKey", this.foundKey);

            root.setTag("townObstacleRemoved", this.townObstacleRemoved);
            root.setTag("seenCutscene", this.seenCutscene);

            NbtCompound levelsTag = new NbtCompound("levels");

            foreach (Level level in this.allLevels)
            {
                levelsTag.Add(level.writeToNbt());
            }
            root.Add(levelsTag);

            NbtFile file = new NbtFile(root);

            Directory.CreateDirectory(Main.SAVE_PATH);
            file.SaveToFile(Main.SAVE_PATH + FILE_NAME, NbtCompression.None);
        }
Esempio n. 9
0
        public void Save(string p)
        {
            var myFile = new NbtFile();

            var root = myFile.RootTag;

            root.Name = "Schematic";

            root.Add(new NbtShort("Height", Height));
            root.Add(new NbtShort("Length", Length));
            root.Add(new NbtShort("Width", Width));


            var nbttile = new NbtList("TileEntities", NbtTagType.Compound);
            var size    = Width * Height * Length;

            _data   = new byte[size];
            _blocks = new byte[size];

            for (int y = 0; y < Height; y++)
            {
                for (int z = 0; z < Length; z++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        var d = GetBlock(x, y, z);
                        _blocks[(y * Length + z) * Width + x] = (byte)d.ID;
                        _data[(y * Length + z) * Width + x]   = (byte)(d.Metta & 0x0F);

                        if (d.Command != null)
                        {
                            var nbtc = new NbtCompound();
                            nbtc.Add(new NbtString("CustomName", "LuaBlock"));
                            nbtc.Add(new NbtString("Command", d.Command));
                            nbtc.Add(new NbtString("id", "Control"));
                            nbtc.Add(new NbtInt("x", x));
                            nbtc.Add(new NbtInt("y", y));
                            nbtc.Add(new NbtInt("z", z));

                            nbttile.Add(nbtc);
                        }
                    }
                }
            }
            root.Add(new NbtList("Entities", NbtTagType.Byte));
            root.Add(nbttile);
            root.Add(new NbtList("TileTicks", NbtTagType.Byte));

            root.Add(new NbtString("Materials", "Alpha"));



            root.Add(new NbtByteArray("Data", _data));
            //   root.Add(new NbtByteArray("Biomes", new byte[Width * Length]));
            root.Add(new NbtByteArray("Blocks", _blocks));


            myFile.SaveToFile(p, NbtCompression.None);
        }
Esempio n. 10
0
        public void ReloadZLib()
        {
            NbtFile loadedFile = new NbtFile("TestFiles/bigtest.nbt", NbtCompression.AutoDetect);

            loadedFile.SaveToFile("TestTemp/bigtest.nbt.z", NbtCompression.ZLib);
            loadedFile.LoadFromFile("TestTemp/bigtest.nbt.z", NbtCompression.AutoDetect);
            AssertNbtBigFile(loadedFile);
        }
Esempio n. 11
0
        public void TestNbtSmallFileSavingUncompressed()
        {
            NbtFile file         = TestFiles.MakeSmallFile();
            string  testFileName = Path.Combine(TestDirName, "test.nbt");

            file.SaveToFile(testFileName, NbtCompression.None);
            FileAssert.AreEqual(TestFiles.Small, testFileName);
        }
Esempio n. 12
0
        internal static void Upravit(UpozorneniCls puvodni, UpozorneniCls nove)
        {
            NbtFile file;

            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\upozorneni"))
            {
                file = new NbtFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\upozorneni");
                List <UpozorneniCls> list = new List <UpozorneniCls>();
                int index = 0;
                foreach (NbtCompound c in file.RootTag.Get <NbtList>("Upozorneni"))
                {
                    Typ t;
                    switch (c["Typ"].ShortValue)
                    {
                    case 1:
                        t = Typ.RDP;
                        break;

                    case 0:
                        t = Typ.Upozorneni;
                        break;

                    default:
                        t = Typ.Upozorneni;
                        break;
                    }

                    if (puvodni.TypUpozorneni == t && puvodni.Popis == c["Popis"].StringValue && puvodni.Datum == new DateTime(c["Datum"].LongValue))
                    {
                        break;
                    }
                    index++;
                }
                if (index < file.RootTag.Get <NbtList>("Upozorneni").Count)
                {
                    ((NbtCompound)file.RootTag.Get <NbtList>("Upozorneni")[index]).Get <NbtString>("Popis").Value = nove.Popis;
                    ((NbtCompound)file.RootTag.Get <NbtList>("Upozorneni")[index]).Get <NbtLong>("Datum").Value   = nove.Datum.Ticks;

                    switch (nove.TypUpozorneni)
                    {
                    case Typ.RDP:
                        ((NbtCompound)file.RootTag.Get <NbtList>("Upozorneni")[index]).Get <NbtShort>("Typ").Value = 1;
                        break;

                    case Typ.Upozorneni:
                        ((NbtCompound)file.RootTag.Get <NbtList>("Upozorneni")[index]).Get <NbtShort>("Typ").Value = 0;
                        break;

                    default:
                        ((NbtCompound)file.RootTag.Get <NbtList>("Upozorneni")[index]).Get <NbtShort>("Typ").Value = 0;
                        break;
                    }

                    file.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\upozorneni", NbtCompression.GZip);
                }
            }
        }
Esempio n. 13
0
        public void ReloadZLib()
        {
            var loadedFile   = new NbtFile("TestFiles/bigtest.nbt");
            var bytesWritten = loadedFile.SaveToFile("TestTemp/bigtest.nbt.z", NbtCompression.ZLib);
            var bytesRead    = loadedFile.LoadFromFile("TestTemp/bigtest.nbt.z", NbtCompression.AutoDetect, null);

            Assert.AreEqual(bytesWritten, bytesRead);
            AssertNbtBigFile(loadedFile);
        }
Esempio n. 14
0
        public void ReloadGZip()
        {
            NbtFile loadedFile   = new NbtFile("TestFiles/bigtest.nbt");
            int     bytesWritten = loadedFile.SaveToFile("TestTemp/bigtest.nbt.gz", NbtCompression.GZip);
            int     bytesRead    = loadedFile.LoadFromFile("TestTemp/bigtest.nbt.gz", NbtCompression.AutoDetect, null);

            Assert.AreEqual(bytesWritten, bytesRead);
            AssertNbtBigFile(loadedFile);
        }
Esempio n. 15
0
    public void saveToFile()
    {
        NbtCompound rootTag = new NbtCompound("map");

        this.writeToNbt(rootTag);

        NbtFile file = new NbtFile(rootTag);

        file.SaveToFile(this.func(), NbtCompression.None);
    }
Esempio n. 16
0
        public void writeWorldDataToDisk(WorldData worldData)
        {
            if (this.dontWriteToDisk)
            {
                return;
            }

            NbtFile file = new NbtFile(worldData.writeToNbt());

            file.SaveToFile(this.worldDataFileName, NbtCompression.None);
        }
Esempio n. 17
0
        public static void Process(string playerDataPath, string oldLevelDatPath, string newLevelDatPath, string outputPath, ILogger?logger = null)
        {
            var main        = new NbtFile(playerDataPath);
            var oldMappings = GetMappings(oldLevelDatPath, logger);
            var newMappings = GetMappings(newLevelDatPath, logger);

            Process(main.RootTag, oldMappings, newMappings, logger);

            main.SaveToFile(outputPath, main.FileCompression);
            logger?.Log(LogLevel.Information, $"File saved to {outputPath}");
        }
Esempio n. 18
0
        // Reading of world data in done in GuiScreenWorldSelect.Awake()

        public void writeChunkToDisk(Chunk chunk, NbtCompound tag)
        {
            if (this.dontWriteToDisk)
            {
                return;
            }

            NbtFile file = new NbtFile(tag);

            file.SaveToFile(this.getChunkFileName(chunk.chunkPos), NbtCompression.None);
        }
Esempio n. 19
0
        public void writePlayerToDisk(EntityPlayer player)
        {
            if (this.dontWriteToDisk)
            {
                return;
            }

            NbtFile file = new NbtFile(player.writeToNbt(new NbtCompound("player")));

            file.SaveToFile(this.playerFileName, NbtCompression.None);
        }
Esempio n. 20
0
        public static void SaveSchematic(Colony colony, Schematic schematic)
        {
            var colonySaves = GameLoader.Schematic_SAVE_LOC + $"\\{colony.ColonyID}\\";

            if (!Directory.Exists(colonySaves))
            {
                Directory.CreateDirectory(colonySaves);
            }

            List <NbtTag> tags = new List <NbtTag>();

            tags.Add(new NbtInt("Width", schematic.XMax));
            tags.Add(new NbtInt("Height", schematic.YMax));
            tags.Add(new NbtInt("Length", schematic.ZMax));

            List <NbtTag> blocks = new List <NbtTag>();

            for (int Y = 0; Y <= schematic.YMax; Y++)
            {
                for (int Z = 0; Z <= schematic.ZMax; Z++)
                {
                    for (int X = 0; X <= schematic.XMax; X++)
                    {
                        NbtCompound compTag = new NbtCompound();
                        compTag.Add(new NbtInt("x", X));
                        compTag.Add(new NbtInt("y", Y));
                        compTag.Add(new NbtInt("z", Z));
                        compTag.Add(new NbtString("id", schematic.Blocks[X, Y, Z].BlockID));
                        blocks.Add(compTag);
                    }
                }
            }

            NbtList nbtList = new NbtList("CSBlocks", blocks);

            tags.Add(nbtList);

            NbtFile nbtFile      = new NbtFile(new NbtCompound("CompoundTag", tags));
            var     fileSave     = Path.Combine(colonySaves, schematic.Name + ".schematic");
            var     metaDataSave = Path.Combine(GameLoader.Schematic_SAVE_LOC, schematic.Name + ".schematic.metadata.json");

            if (File.Exists(fileSave))
            {
                File.Delete(fileSave);
            }

            if (File.Exists(metaDataSave))
            {
                File.Delete(metaDataSave);
            }

            GenerateMetaData(metaDataSave, schematic.Name, schematic);
            nbtFile.SaveToFile(fileSave, NbtCompression.GZip);
        }
Esempio n. 21
0
        public void SaveNbt()
        {
            var p    = Path + "/level.dat";
            var file = new NbtFile(LevelData);

            if (File.Exists(p))
            {
                File.Delete(p);
            }
            file.SaveToFile(p, NbtCompression.None);
        }
Esempio n. 22
0
        public void writeGenerationData(WorldGeneratorBase generator)
        {
            if (this.dontWriteToDisk)
            {
                return;
            }

            NbtFile file = new NbtFile(generator.writeToNbt(new NbtCompound("generationData")));

            file.SaveToFile(this.generationDataFileName, NbtCompression.None);
        }
Esempio n. 23
0
    /// <summary>
    /// Saves the World.  If the world has no save name, nothing happens.
    /// </summary>
    public void saveGame()
    {
        if (!string.IsNullOrEmpty(this.saveName))
        {
            NbtCompound rootTag = new NbtCompound("root");
            rootTag.Add(this.writeToNbt());
            NbtFile nbtFile = new NbtFile(rootTag);

            Directory.CreateDirectory("saves/");
            nbtFile.SaveToFile("saves/" + this.saveName + ".nbt", NbtCompression.None);
        }
    }
Esempio n. 24
0
    public void saveMapDataToFile(MapData mapData)
    {
        #if UNITY_EDITOR
        if (this.dontWriteToDisk)
        {
            return;
        }
        #endif

        NbtFile file = new NbtFile(mapData.writeToNbt());
        file.SaveToFile(this.getMapDataFileName(), NbtCompression.None);
    }
Esempio n. 25
0
        public void TestNbtSmallFileSavingUncompressed()
        {
            var file = new NbtFile(
                new NbtCompound("hello world", new NbtTag[] {
                new NbtString("name", "Bananrama")
            })
                );

            file.SaveToFile("TestTemp/test.nbt", NbtCompression.None);

            FileAssert.AreEqual("TestFiles/test.nbt", "TestTemp/test.nbt");
        }
Esempio n. 26
0
        public static void SaveLevel(LevelInfo level)
        {
            if (!Directory.Exists(_basePath))
            {
                Directory.CreateDirectory(_basePath);
            }

            NbtFile file    = new NbtFile();
            NbtTag  dataTag = file.RootTag["Data"] = new NbtCompound("Data");

            level.SaveToNbt(dataTag);
            file.SaveToFile(Path.Combine(_basePath, "level.dat"), NbtCompression.ZLib);
        }
Esempio n. 27
0
        public void SaveAnvilLevelTest()
        {
            var leveldat = @"D:\Temp\unit-test-level.dat";

            var level = new LevelInfo();

            NbtFile file    = new NbtFile();
            NbtTag  dataTag = new NbtCompound("Data");

            file.RootTag.Add(dataTag);
            level.SaveToNbt(dataTag);
            file.SaveToFile(leveldat, NbtCompression.GZip);
        }
Esempio n. 28
0
 public static void SavePlayer(this Level level, RemoteClient client)
 {
     if (string.IsNullOrEmpty(level.BaseDirectory))
     {
         return;
     }
     try
     {
         Directory.CreateDirectory(Path.Combine(level.BaseDirectory, "players"));
         var file = new NbtFile();
         file.RootTag.Add(new NbtInt("playerGameType", (int)client.GameMode));
         file.RootTag.Add(new NbtShort("SelectedItemSlot", client.Entity.SelectedSlot));
         file.RootTag.Add(new NbtInt("SpawnX", (int)client.Entity.SpawnPoint.X));
         file.RootTag.Add(new NbtInt("SpawnY", (int)client.Entity.SpawnPoint.Y));
         file.RootTag.Add(new NbtInt("SpawnZ", (int)client.Entity.SpawnPoint.Z));
         file.RootTag.Add(new NbtInt("foodLevel", client.Entity.Food));
         file.RootTag.Add(new NbtFloat("foodExhaustionLevel", client.Entity.FoodExhaustion));
         file.RootTag.Add(new NbtFloat("foodSaturationLevel", client.Entity.FoodSaturation));
         file.RootTag.Add(new NbtShort("Health", client.Entity.Health));
         var inventory = new NbtList("Inventory", NbtTagType.Compound);
         var slots     = client.Entity.Inventory.GetSlots();
         for (int i = 0; i < slots.Length; i++)
         {
             var slot = (ItemStack)slots[i].Clone();
             slot.Index = Level.NetworkSlotToDataSlot(i);
             if (!slot.Empty)
             {
                 inventory.Add(slot.ToNbt());
             }
         }
         file.RootTag.Add(inventory);
         var position = new NbtList("Pos", NbtTagType.Double);
         position.Add(new NbtDouble(client.Entity.Position.X));
         position.Add(new NbtDouble(client.Entity.Position.Y));
         position.Add(new NbtDouble(client.Entity.Position.Z));
         file.RootTag.Add(position);
         var rotation = new NbtList("Rotation", NbtTagType.Float);
         rotation.Add(new NbtFloat(client.Entity.Yaw));
         rotation.Add(new NbtFloat(client.Entity.Pitch));
         file.RootTag.Add(rotation);
         var velocity = new NbtList("Motion", NbtTagType.Double);
         velocity.Add(new NbtDouble(client.Entity.Velocity.X));
         velocity.Add(new NbtDouble(client.Entity.Velocity.Y));
         velocity.Add(new NbtDouble(client.Entity.Velocity.Z));
         file.RootTag.Add(velocity);
         file.SaveToFile(Path.Combine(level.BaseDirectory, "players", client.Username + ".dat"), NbtCompression.None);
     }
     catch { } // If exceptions happen here, the entire server dies
 }
Esempio n. 29
0
    public void savePlayerToFile(Player player)
    {
        #if UNITY_EDITOR
        if (this.dontWriteToDisk)
        {
            return;
        }
        #endif

        NbtCompound rootTag = new NbtCompound("player");
        player.writeToNbt(rootTag);

        NbtFile file = new NbtFile(rootTag);
        file.SaveToFile(this.getPlayerFileName(player), NbtCompression.None);
    }
Esempio n. 30
0
    public void saveMapToFile(MapMP map)
    {
        #if UNITY_EDITOR
        if (this.dontWriteToDisk)
        {
            return;
        }
        #endif

        NbtCompound rootTag = new NbtCompound("map");
        map.writeToNbt(rootTag);

        NbtFile file = new NbtFile(rootTag);
        file.SaveToFile(this.getSaveFileName(), NbtCompression.None);
    }
Esempio n. 31
0
        /// <summary>
        /// Writes the passed chunk to disk.
        /// </summary>
        public void writeChunkToDisk(Chunk chunk, bool deleteEntities)
        {
            if (this.dontWriteToDisk)
            {
                return;
            }

            NbtCompound tag = new NbtCompound("chunk");

            chunk.writeToNbt(tag, deleteEntities);

            NbtFile file = new NbtFile(tag);

            file.SaveToFile(this.getChunkFileName(chunk.chunkPos), NbtCompression.None);
        }
Esempio n. 32
0
        public void TestNbtSmallFileSavingUncompressed()
        {
            var file = new NbtFile(
                new NbtCompound( "hello world", new NbtTag[] {
                    new NbtString( "name", "Bananrama" )
                } )
            );

            file.SaveToFile( "TestTemp/test.nbt", NbtCompression.None );

            FileAssert.AreEqual( "TestFiles/test.nbt", "TestTemp/test.nbt" );
        }
Esempio n. 33
0
 public void ReloadZLib()
 {
     NbtFile loadedFile = new NbtFile( "TestFiles/bigtest.nbt" );
     int bytesWritten = loadedFile.SaveToFile( "TestTemp/bigtest.nbt.z", NbtCompression.ZLib );
     int bytesRead = loadedFile.LoadFromFile( "TestTemp/bigtest.nbt.z", NbtCompression.AutoDetect, null );
     Assert.AreEqual( bytesWritten, bytesRead );
     AssertNbtBigFile( loadedFile );
 }
Esempio n. 34
0
        public void Serializing()
        {
            string fileName = Path.Combine( TempDir, "NbtListType.nbt" );
            const NbtTagType expectedListType = NbtTagType.Int;
            const int elements = 10;

            // construct nbt file
            NbtFile writtenFile = new NbtFile( new NbtCompound( "ListTypeTest" ) );
            NbtList writtenList = new NbtList( "Entities", null, expectedListType );
            for( int i = 0; i < elements; i++ ) {
                writtenList.Add( new NbtInt( i ) );
            }
            writtenFile.RootTag.Add( writtenList );

            // test saving
            writtenFile.SaveToFile( fileName, NbtCompression.GZip );

            // test loading
            NbtFile readFile = new NbtFile( fileName );

            // check contents of loaded file
            Assert.NotNull( readFile.RootTag );
            Assert.IsInstanceOf<NbtList>( readFile.RootTag["Entities"] );
            NbtList readList = (NbtList)readFile.RootTag["Entities"];
            Assert.AreEqual( readList.ListType, writtenList.ListType );
            Assert.AreEqual( readList.Count, writtenList.Count );

            // check .ToArray
            CollectionAssert.AreEquivalent( readList, readList.ToArray() );
            CollectionAssert.AreEquivalent( readList, readList.ToArray<NbtInt>() );

            // check contents of loaded list
            for( int i = 0; i < elements; i++ ) {
                Assert.AreEqual( readList.Get<NbtInt>( i ).Value, writtenList.Get<NbtInt>( i ).Value );
            }
        }
Esempio n. 35
0
        public void Save(string p)
        {
            var myFile = new NbtFile();

            var root = myFile.RootTag;
            root.Name = "Schematic";

            root.Add(new NbtShort("Height", Height));
            root.Add(new NbtShort("Length", Length));
            root.Add(new NbtShort("Width", Width));

            var nbttile = new NbtList("TileEntities", NbtTagType.Compound);
            var size = Width * Height * Length;
            _data = new byte[size];
            _blocks = new byte[size];

            for (int y = 0; y < Height; y++)
            {
                for (int z = 0; z < Length; z++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        var d = GetBlock(x, y, z);
                        _blocks[(y * Length + z) * Width + x] = (byte)d.ID;
                        _data[(y * Length + z) * Width + x] = (byte)(d.Metta & 0x0F);

                        if (d.Command != null)
                        {
                            var nbtc = new NbtCompound();
                            nbtc.Add(new NbtString("CustomName", "LuaBlock"));
                            nbtc.Add(new NbtString("Command", d.Command));
                            nbtc.Add(new NbtString("id", "Control"));
                            nbtc.Add(new NbtInt("x", x));
                            nbtc.Add(new NbtInt("y", y));
                            nbtc.Add(new NbtInt("z", z));

                            nbttile.Add(nbtc);
                        }
                    }
                }
            }
            root.Add(new NbtList("Entities", NbtTagType.Byte));
            root.Add(nbttile);
            root.Add(new NbtList("TileTicks", NbtTagType.Byte));

            root.Add(new NbtString("Materials", "Alpha"));

            root.Add(new NbtByteArray("Data", _data));
             //   root.Add(new NbtByteArray("Biomes", new byte[Width * Length]));
            root.Add(new NbtByteArray("Blocks", _blocks));

            myFile.SaveToFile(p, NbtCompression.None);
        }
Esempio n. 36
0
 void ReloadFileInternal(String fileName, NbtCompression compression, bool bigEndian, bool buffered)
 {
     var loadedFile = new NbtFile(Path.Combine(TestFiles.DirName, fileName)) {
         BigEndian = bigEndian
     };
     if (!buffered) {
         loadedFile.BufferSize = 0;
     }
     long bytesWritten = loadedFile.SaveToFile(Path.Combine(TestDirName, fileName), compression);
     long bytesRead = loadedFile.LoadFromFile(Path.Combine(TestDirName, fileName), NbtCompression.AutoDetect,
                                              null);
     Assert.AreEqual(bytesWritten, bytesRead);
     TestFiles.AssertNbtBigFile(loadedFile);
 }
Esempio n. 37
0
        public void NullParameterTest()
        {
            Assert.Throws<ArgumentNullException>(() => new NbtFile((NbtCompound)null));
            Assert.Throws<ArgumentNullException>(() => new NbtFile((string)null));

            NbtFile file = new NbtFile();
            Assert.Throws<ArgumentNullException>(() => file.LoadFromBuffer(null, 0, 1, NbtCompression.None));
            Assert.Throws<ArgumentNullException>(() => file.LoadFromBuffer(null, 0, 1, NbtCompression.None, tag => true));
            Assert.Throws<ArgumentNullException>(() => file.LoadFromFile(null));
            Assert.Throws<ArgumentNullException>(() => file.LoadFromFile(null, NbtCompression.None, tag => true));
            Assert.Throws<ArgumentNullException>(() => file.LoadFromStream(null, NbtCompression.AutoDetect));
            Assert.Throws<ArgumentNullException>(() => file.LoadFromStream(null, NbtCompression.AutoDetect, tag => true));

            Assert.Throws<ArgumentNullException>(() => file.SaveToBuffer(null, 0, NbtCompression.None));
            Assert.Throws<ArgumentNullException>(() => file.SaveToFile(null, NbtCompression.None));
            Assert.Throws<ArgumentNullException>(() => file.SaveToStream(null, NbtCompression.None));

            Assert.Throws<ArgumentNullException>(() => NbtFile.ReadRootTagName(null));
            Assert.Throws<ArgumentNullException>(
                () => NbtFile.ReadRootTagName((Stream)null, NbtCompression.None, true, 0));
        }