Exemple #1
0
        public static string ToBase64(Item item)
        {
            MemoryStream ms = new MemoryStream();

            TagIO.ToStream(ItemIO.Save(item), ms, true);
            return(Convert.ToBase64String(ms.ToArray()));
        }
Exemple #2
0
        //make Terraria.Player.ENCRYPTION_KEY internal
        //add to end of Terraria.Player.SavePlayer
        internal static void Save(Player player, string path, bool isCloudSave)
        {
            path = Path.ChangeExtension(path, ".tplr");
            if (FileUtilities.Exists(path, isCloudSave))
            {
                FileUtilities.Copy(path, path + ".bak", isCloudSave);
            }

            var tag = new TagCompound {
                ["armor"]      = SaveInventory(player.armor),
                ["dye"]        = SaveInventory(player.dye),
                ["inventory"]  = SaveInventory(player.inventory),
                ["miscEquips"] = SaveInventory(player.miscEquips),
                ["miscDyes"]   = SaveInventory(player.miscDyes),
                ["bank"]       = SaveInventory(player.bank.item),
                ["bank2"]      = SaveInventory(player.bank2.item),
                ["bank3"]      = SaveInventory(player.bank3.item),
                ["hairDye"]    = SaveHairDye(player.hairDye),
                ["modData"]    = SaveModData(player),
                ["modBuffs"]   = SaveModBuffs(player),
                ["usedMods"]   = SaveUsedMods(player)
            };

            using (Stream stream = isCloudSave ? (Stream) new MemoryStream() : (Stream) new FileStream(path, FileMode.Create)) {
                TagIO.ToStream(tag, stream);
                if (isCloudSave && SocialAPI.Cloud != null)
                {
                    SocialAPI.Cloud.Write(path, ((MemoryStream)stream).ToArray());
                }
            }
        }
Exemple #3
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);
        }