Ejemplo n.º 1
0
        //add near end of Terraria.IO.WorldFile.saveWorld before releasing locks
        internal static void Save(string path, bool isCloudSave)
        {
            path = Path.ChangeExtension(path, ".twld");
            if (FileUtilities.Exists(path, isCloudSave))
            {
                FileUtilities.Copy(path, path + ".bak", isCloudSave);
            }

            var tag = new TagCompound {
                ["chests"]       = SaveChests(),
                ["tiles"]        = TileIO.SaveTiles(),
                ["containers"]   = TileIO.SaveContainers(),
                ["npcs"]         = SaveNPCs(),
                ["tileEntities"] = TileIO.SaveTileEntities(),
                ["killCounts"]   = SaveNPCKillCounts(),
                ["anglerQuest"]  = SaveAnglerQuest(),
                ["townManager"]  = SaveTownManager(),
                ["modData"]      = SaveModData()
            };

            var stream = new MemoryStream();

            TagIO.ToStream(tag, stream);
            var data = stream.ToArray();

            FileUtilities.Write(path, data, data.Length, isCloudSave);
        }
Ejemplo n.º 2
0
 private static void LoadLegacyModWorld(byte[] flags, BinaryReader reader)
 {
     if (flags.Length == 0)
     {
         return;
     }
     if ((flags[0] & 1) == 1)
     {
         LoadLegacyChests(reader);
     }
     if ((flags[0] & 2) == 2)
     {
         TileIO.LoadLegacyTiles(reader);
     }
     if ((flags[0] & 4) == 4)
     {
         LoadLegacyNPCKillCounts(reader);
     }
     if ((flags[0] & 8) == 8)
     {
         TileIO.ReadContainers(reader);
     }
     if ((flags[0] & 16) == 16)
     {
         LoadLegacyAnglerQuest(reader);
     }
     if ((flags[0] & 32) == 32)
     {
         LoadLegacyModData(reader);
     }
 }
Ejemplo n.º 3
0
 internal static byte[] WriteModWorld(BinaryWriter writer)
 {
     byte[] flags = new byte[numByteFlags];
     if (WriteChests(writer))
     {
         flags[0] |= 1;
     }
     if (TileIO.WriteTiles(writer))
     {
         flags[0] |= 2;
     }
     if (WriteNPCKillCounts(writer))
     {
         flags[0] |= 4;
     }
     if (TileIO.WriteContainers(writer))
     {
         flags[0] |= 8;
     }
     if (WriteAnglerQuest(writer))
     {
         flags[0] |= 16;
     }
     return(flags);
 }
Ejemplo n.º 4
0
 internal static void ReadModWorld(byte[] flags, BinaryReader reader)
 {
     if (flags.Length == 0)
     {
         return;
     }
     if ((flags[0] & 1) == 1)
     {
         ReadChests(reader);
     }
     if ((flags[0] & 2) == 2)
     {
         TileIO.ReadTiles(reader);
     }
     if ((flags[0] & 4) == 4)
     {
         ReadNPCKillCounts(reader);
     }
     if ((flags[0] & 8) == 8)
     {
         TileIO.ReadContainers(reader);
     }
     if ((flags[0] & 16) == 16)
     {
         ReadAnglerQuest(reader);
     }
 }
Ejemplo n.º 5
0
 internal static void ReadModWorld(byte[] flags, BinaryReader reader)
 {
     if ((flags[0] & 1) == 1)
     {
         ReadChests(reader);
     }
     if ((flags[0] & 2) == 2)
     {
         TileIO.ReadTiles(reader);
     }
     if ((flags[0] & 4) == 4)
     {
         ReadNPCKillCounts(reader);
     }
 }
Ejemplo n.º 6
0
        //add near end of Terraria.IO.WorldFile.loadWorld before setting failure and success
        internal static void Load(string path, bool isCloudSave)
        {
            customDataFail = null;
            path           = Path.ChangeExtension(path, ".twld");
            if (!FileUtilities.Exists(path, isCloudSave))
            {
                return;
            }

            var buf = FileUtilities.ReadAllBytes(path, isCloudSave);

            if (buf[0] != 0x1F || buf[1] != 0x8B)
            {
                LoadLegacy(buf);
                return;
            }

            var tag = TagIO.FromStream(new MemoryStream(buf));

            LoadChests(tag.GetList <TagCompound>("chests"));
            TileIO.LoadTiles(tag.GetCompound("tiles"));
            TileIO.LoadContainers(tag.GetCompound("containers"));
            LoadNPCs(tag.GetList <TagCompound>("npcs"));
            try
            {
                TileIO.LoadTileEntities(tag.GetList <TagCompound>("tileEntities"));
            }
            catch (CustomModDataException e)
            {
                customDataFail = e;
                throw;
            }
            LoadNPCKillCounts(tag.GetList <TagCompound>("killCounts"));
            LoadAnglerQuest(tag.GetCompound("anglerQuest"));
            LoadTownManager(tag.GetList <TagCompound>("townManager"));
            try
            {
                LoadModData(tag.GetList <TagCompound>("modData"));
            }
            catch (CustomModDataException e)
            {
                customDataFail = e;
                throw;
            }
        }