Exemplo n.º 1
0
        private static void LoadLegacy(byte[] buffer)
        {
            const int numByteFlags = 1;

            using (MemoryStream stream = new MemoryStream(buffer))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    byte limit = reader.ReadByte();
                    if (limit == 0)
                    {
                        return;
                    }
                    byte[] flags = reader.ReadBytes(limit);
                    if (flags.Length < numByteFlags)
                    {
                        Array.Resize(ref flags, numByteFlags);
                    }
                    try
                    {
                        LoadLegacyModWorld(flags, reader);
                    }
                    catch (CustomModDataException e)
                    {
                        customDataFail = e;
                        throw;
                    }
                }
            }
        }
Exemplo n.º 2
0
 //add near end of Terraria.IO.WorldFile.loadWorld before setting failure and success
 internal static void ReadModFile(string path, bool isCloudSave)
 {
     customDataFail = null;
     path           = Path.ChangeExtension(path, ".twld");
     if (!FileUtilities.Exists(path, isCloudSave))
     {
         return;
     }
     byte[] buffer = FileUtilities.ReadAllBytes(path, isCloudSave);
     using (MemoryStream stream = new MemoryStream(buffer))
     {
         using (BinaryReader reader = new BinaryReader(stream))
         {
             byte limit = reader.ReadByte();
             if (limit == 0)
             {
                 return;
             }
             byte[] flags = reader.ReadBytes(limit);
             if (flags.Length < numByteFlags)
             {
                 Array.Resize(ref flags, numByteFlags);
             }
             try
             {
                 ReadModWorld(flags, reader);
             }
             catch (CustomModDataException e)
             {
                 customDataFail = e;
                 throw;
             }
         }
     }
 }
Exemplo n.º 3
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;
            }
        }