Inheritance: GalaSoft.MvvmLight.ObservableObject
コード例 #1
0
        private static void WriteTally(StreamWriter sb, World world)
        {
            int index = 0;
            int killcount = 0;
            int bannercount = 0;
            int uniquecount = 0;

            foreach (int count in world.KilledMobs)
            {
                if (count > 0)
                {
                    int banners = (int)Math.Floor((double)count / 50f);
                    // sb.WriteProperty(index.ToString(), count.ToString());
                    sb.WriteLine("{0} {1}: {2} ({3} earned)", index, World.TallyNames[index], count, banners);
                    killcount = killcount + count;
                    if (banners > 0)
                        uniquecount = uniquecount + 1;
                    bannercount = bannercount + banners;
                }
                index++;
            }
            sb.Write(Environment.NewLine);
            sb.WriteLine("Total kills counted: {0}", killcount);
            sb.WriteLine("Total banners awarded: {0}", bannercount);
            sb.WriteLine("Total unique banners: {0}", uniquecount);
        }
コード例 #2
0
 public static World LoadWorld(string filename)
 {
     var w = new World();
     try
     {
         lock (_fileLock)
         {
             using (var b = new BinaryReader(File.OpenRead(filename)))
             {
                 w.Version = b.ReadUInt32();
                 if (w.Version > 87)
                     LoadV2(b, filename, w);
                 else
                     LoadV1(b, filename, w);
             }
             w.LastSave = File.GetLastWriteTimeUtc(filename);
         }
     }
     catch (Exception err)
     {
         string msg =
             "There was an error reading the world file, do you wish to force it to load anyway?\r\n\r\n" +
             "WARNING: This may have unexpected results including corrupt world files and program crashes.\r\n\r\n" +
             "The error is :\r\n";
         if (MessageBox.Show(msg + err, "World File Error", MessageBoxButton.YesNo, MessageBoxImage.Error) !=
             MessageBoxResult.Yes)
             return null;
     }
     return w;
 }
コード例 #3
0
        public static void Save(World world, string filename, bool resetTime = false)
        {
            try
            {
                OnProgressChanged(world, new ProgressChangedEventArgs(0, "Validating World..."));
                world.Validate();
            }
            catch (ArgumentOutOfRangeException err)
            {
                string msg = string.Format("There is a problem in your world.\r\n" + 
                                           "{0}\r\nThis world will not open in Terraria\r\n" + 
                                           "Would you like to save anyways??\r\n"
                                           , err.ParamName);
                if (MessageBox.Show(msg, "World Error", MessageBoxButton.YesNo, MessageBoxImage.Error) !=
                    MessageBoxResult.Yes)
                    return;
            }
            lock (_fileLock)
            {
                

                if (resetTime)
                {
                    OnProgressChanged(world, new ProgressChangedEventArgs(0, "Resetting Time..."));
                    world.ResetTime();
                }

                if (filename == null)
                    return;

                string temp = filename + ".tmp";
                using (var fs = new FileStream(temp, FileMode.Create))
                {
                    using (var bw = new BinaryWriter(fs))
                    {
                        if (world.Version > 87)
                            SaveV2(world, bw);
                        else
                            SaveV1(world, bw);

                        bw.Close();
                        fs.Close();

                        // make a backup of current file if it exists
                        if (File.Exists(filename))
                        {
                            string backup = filename + ".TEdit";
                            File.Copy(filename, backup, true);
                        }
                        // replace actual file with temp save file
                        File.Copy(temp, filename, true);
                        // delete temp save file
                        File.Delete(temp);
                        OnProgressChanged(null, new ProgressChangedEventArgs(0, "World Save Complete."));
                    }
                }

                world._lastSave = File.GetLastWriteTimeUtc(filename);
            }
        }
コード例 #4
0
        public static WriteableBitmap Render(World w)
        {
            WriteableBitmap bmp = new WriteableBitmap(w.TilesWide / Resolution, w.TilesHigh / Resolution, 96, 96, PixelFormats.Bgra32, null);

            UpdateMinimap(w, ref bmp);

            return bmp;
        }
コード例 #5
0
        public static void SaveTally(World world, string file)
        {
            if (world == null) return;

            using (var writer = new StreamWriter(file, false))
            {
                WriteTallyCount(writer, world, true);
            }
        }
コード例 #6
0
        public static void AnalyzeWorld(World world, string file)
        {
            if (world == null) return;

            using (var writer = new StreamWriter(file, false))
            {
                WriteAnalyzeWorld(writer, world, true);
            }
        }
コード例 #7
0
 public NewWorldView()
 {
     InitializeComponent();
     _newWorld = new World(1200, 4300, "TEdit World");
     _newWorld.Version = World.CompatibleVersion;
     _newWorld.GroundLevel = 350;
     _newWorld.RockLevel = 480;
     _newWorld.ResetTime();
     AddCharNames();
     this.DataContext = NewWorld;
 }
コード例 #8
0
        public static string AnalyzeWorld(World world)
        {
            if (world == null) return string.Empty;

            using (var ms = new MemoryStream())
            using (var writer = new StreamWriter(ms))
            using (var reader = new StreamReader(ms))
            {
                WriteAnalyzeWorld(writer, world, true);
                writer.Flush();
                ms.Position = 0;

                var text = reader.ReadToEnd();
                return text;
            }
        }
コード例 #9
0
        private static void SaveV2(World world, BinaryWriter bw)
        {
            world.Validate();

            // initialize tileframeimportance array if empty
            if (TileFrameImportant == null || TileFrameImportant.Length < TileCount)
            {
                TileFrameImportant = new bool[TileCount];
                for (int i = 0; i < TileCount; i++)
                {
                    if (World.TileProperties.Count > i)
                    {
                        TileFrameImportant[i] = World.TileProperties[i].IsFramed;
                    }
                }
            }

            int[] sectionPointers = new int[SectionCount];

            OnProgressChanged(null, new ProgressChangedEventArgs(0, "Save headers..."));
            sectionPointers[0] = SaveSectionHeader(world, bw);
            sectionPointers[1] = SaveHeaderFlags(world, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(0, "Save UndoTiles..."));
            sectionPointers[2] = SaveTiles(world.Tiles, world.TilesWide, world.TilesHigh, bw);

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Chests..."));
            sectionPointers[3] = SaveChests(world.Chests, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Signs..."));
            sectionPointers[4] = SaveSigns(world.Signs, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save NPCs..."));
            sectionPointers[5] = SaveNPCs(world.NPCs, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Mobs..."));
            sectionPointers[5] = SaveMobs(world.Mobs, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Tile Entities Section..."));
            sectionPointers[6] = SaveTileEntities(world, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Footers..."));
            SaveFooter(world, bw);
            UpdateSectionPointers(sectionPointers, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Save Complete."));
        }
コード例 #10
0
ファイル: World.cs プロジェクト: TEdit/Terraria-Map-Editor
        public static World LoadWorld(string filename)
        {
            var w = new World();
            uint curVersion = 0;
            try
            {
                lock (_fileLock)
                {
                    using (var b = new BinaryReader(File.OpenRead(filename)))
                    {
                        w.Version = b.ReadUInt32();
                        curVersion = w.Version;
                        if (w.Version > 87)
                            LoadV2(b, filename, w);
                        else
                            LoadV1(b, filename, w);
                    }
                    w.LastSave = File.GetLastWriteTimeUtc(filename);
                }
            }
            catch (Exception err)
            {

                string msg =
                    string.Format("There was an error reading the world file. This is usually caused by a corrupt save file or a world version newer than supported.\r\n\r\n" +
                                  "TEdit v{0}\r\n" +
                                  "TEdit Max World: {1}    Current World: {2}\r\n\r\n" +
                                  "Do you wish to force it to load anyway?\r\n\r\n" +
                                  "WARNING: This may have unexpected results including corrupt world files and program crashes.\r\n\r\n" +
                                   "The error is :\r\n{3}\r\n\r\n{4}\r\n"
                    , TEditXna.App.Version.FileVersion, World.CompatibleVersion, curVersion, err.Message, err);
                if (MessageBox.Show(msg, "World File Error", MessageBoxButton.YesNo, MessageBoxImage.Error) !=
                    MessageBoxResult.Yes)
                    return null;
            }
            return w;
        }
コード例 #11
0
        public static void UpdateMinimap(World w, ref WriteableBitmap bmp)
        {
            bmp.Lock();
            unsafe
            {
                int pixelCount = bmp.PixelHeight * bmp.PixelWidth;
                var pixels = (int*)bmp.BackBuffer;

                for (int i = 0; i < pixelCount; i++)
                {
                    int x = i % bmp.PixelWidth;
                    int y = i / bmp.PixelWidth;

                    int worldX = x * Resolution;
                    int worldY = y * Resolution;



                    pixels[i] = XnaColorToWindowsInt(PixelMap.GetTileColor(w.Tiles[worldX, worldY], Microsoft.Xna.Framework.Color.Transparent));
                }
            }
            bmp.AddDirtyRect(new Int32Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight));
            bmp.Unlock();
        }
コード例 #12
0
        private static void LoadV1(BinaryReader reader, string filename, World w)
        {
            uint version = w.Version;
            w.Title = reader.ReadString();
            w.WorldId = reader.ReadInt32();

            w.Rand = new Random(w.WorldId);

            w.LeftWorld = reader.ReadInt32();
            w.RightWorld = reader.ReadInt32();
            w.TopWorld = reader.ReadInt32();
            w.BottomWorld = reader.ReadInt32();
            w.TilesHigh = reader.ReadInt32();
            w.TilesWide = reader.ReadInt32();

            //if (w.TilesHigh > 10000 || w.TilesWide > 10000 || w.TilesHigh <= 0 || w.TilesWide <= 0)
            //    throw new FileLoadException(string.Format("Invalid File: {0}", filename));


            if (version >= 63)
                w.MoonType = reader.ReadByte();
            else
                w.MoonType = (byte)w.Rand.Next(MaxMoons);


            if (version >= 44)
            {
                w.TreeX0 = reader.ReadInt32();
                w.TreeX1 = reader.ReadInt32();
                w.TreeX2 = reader.ReadInt32();
                w.TreeStyle0 = reader.ReadInt32();
                w.TreeStyle1 = reader.ReadInt32();
                w.TreeStyle2 = reader.ReadInt32();
                w.TreeStyle3 = reader.ReadInt32();
            }
            if (version >= 60)
            {
                w.CaveBackX0 = reader.ReadInt32();
                w.CaveBackX1 = reader.ReadInt32();
                w.CaveBackX2 = reader.ReadInt32();
                w.CaveBackStyle0 = reader.ReadInt32();
                w.CaveBackStyle1 = reader.ReadInt32();
                w.CaveBackStyle2 = reader.ReadInt32();
                w.CaveBackStyle3 = reader.ReadInt32();
                w.IceBackStyle = reader.ReadInt32();
                if (version >= 61)
                {
                    w.JungleBackStyle = reader.ReadInt32();
                    w.HellBackStyle = reader.ReadInt32();
                }
            }
            else
            {
                w.CaveBackX[0] = w.TilesWide/2;
                w.CaveBackX[1] = w.TilesWide;
                w.CaveBackX[2] = w.TilesWide;
                w.CaveBackStyle0 = 0;
                w.CaveBackStyle1 = 1;
                w.CaveBackStyle2 = 2;
                w.CaveBackStyle3 = 3;
                w.IceBackStyle = 0;
                w.JungleBackStyle = 0;
                w.HellBackStyle = 0;
            }

            w.SpawnX = reader.ReadInt32();
            w.SpawnY = reader.ReadInt32();
            w.GroundLevel = (int) reader.ReadDouble();
            w.RockLevel = (int) reader.ReadDouble();

            // read world flags
            w.Time = reader.ReadDouble();
            w.DayTime = reader.ReadBoolean();
            w.MoonPhase = reader.ReadInt32();
            w.BloodMoon = reader.ReadBoolean();

            if (version >= 70)
            {
                w.IsEclipse = reader.ReadBoolean();
            }

            w.DungeonX = reader.ReadInt32();
            w.DungeonY = reader.ReadInt32();

            if (version >= 56)
            {
                w.IsCrimson = reader.ReadBoolean();
            }
            else
            {
                w.IsCrimson = false;
            }

            w.DownedBoss1 = reader.ReadBoolean();
            w.DownedBoss2 = reader.ReadBoolean();
            w.DownedBoss3 = reader.ReadBoolean();

            if (version >= 66)
            {
                w.DownedQueenBee = reader.ReadBoolean();
            }
            if (version >= 44)
            {
                w.DownedMechBoss1 = reader.ReadBoolean();
                w.DownedMechBoss2 = reader.ReadBoolean();
                w.DownedMechBoss3 = reader.ReadBoolean();
                w.DownedMechBossAny = reader.ReadBoolean();
            }
            if (version >= 64)
            {
                w.DownedPlantBoss = reader.ReadBoolean();
                w.DownedGolemBoss = reader.ReadBoolean();
            }
            if (version >= 29)
            {
                w.SavedGoblin = reader.ReadBoolean();
                w.SavedWizard = reader.ReadBoolean();
                if (version >= 34)
                {
                    w.SavedMech = reader.ReadBoolean();
                }
                w.DownedGoblins = reader.ReadBoolean();
            }
            if (version >= 32)
                w.DownedClown = reader.ReadBoolean();
            if (version >= 37)
                w.DownedFrost = reader.ReadBoolean();
            if (version >= 56)
                w.DownedPirates = reader.ReadBoolean();


            w.ShadowOrbSmashed = reader.ReadBoolean();
            w.SpawnMeteor = reader.ReadBoolean();
            w.ShadowOrbCount = reader.ReadByte();

            if (version >= 23)
            {
                w.AltarCount = reader.ReadInt32();
                w.HardMode = reader.ReadBoolean();
            }

            w.InvasionDelay = reader.ReadInt32();
            w.InvasionSize = reader.ReadInt32();
            w.InvasionType = reader.ReadInt32();
            w.InvasionX = reader.ReadDouble();

            if (version >= 53)
            {
                w.TempRaining = reader.ReadBoolean();
                w.TempRainTime = reader.ReadInt32();
                w.TempMaxRain = reader.ReadSingle();
            }
            if (version >= 54)
            {
                w.OreTier1 = reader.ReadInt32();
                w.OreTier2 = reader.ReadInt32();
                w.OreTier3 = reader.ReadInt32();
            }
            else if (version < 23 || w.AltarCount != 0)
            {
                w.OreTier1 = 107;
                w.OreTier2 = 108;
                w.OreTier3 = 111;
            }
            else
            {
                w.OreTier1 = -1;
                w.OreTier2 = -1;
                w.OreTier3 = -1;
            }

            if (version >= 55)
            {
                w.BgTree = reader.ReadByte();
                w.BgCorruption = reader.ReadByte();
                w.BgJungle = reader.ReadByte();
            }
            if (version >= 60)
            {
                w.BgSnow = reader.ReadByte();
                w.BgHallow = reader.ReadByte();
                w.BgCorruption = reader.ReadByte();
                w.BgDesert = reader.ReadByte();
                w.BgOcean = reader.ReadByte();
            }

            if (version >= 60)
            {
                w.CloudBgActive = reader.ReadInt32();
            }
            else
            {
                w.CloudBgActive = -w.Rand.Next(8640, 86400);
            }

            if (version >= 62)
            {
                w.NumClouds = reader.ReadInt16();
                w.WindSpeedSet = reader.ReadSingle();
            }

            w.Tiles = new Tile[w.TilesWide, w.TilesHigh];
            for (int i = 0; i < w.TilesWide; i++)
            {
                for (int j = 0; j < w.TilesHigh; j++)
                {
                    w.Tiles[i, j] = new Tile();
                }
            }


            for (int x = 0; x < w.TilesWide; ++x)
            {
                OnProgressChanged(null,
                    new ProgressChangedEventArgs(x.ProgressPercentage(w.TilesWide), "Loading UndoTiles..."));

                for (int y = 0; y < w.TilesHigh; y++)
                {
                    Tile tile = ReadTileDataFromStreamV1(reader, version);

                    // read complete, start compression
                    w.Tiles[x, y] = tile;

                    if (version >= 25)
                    {
                        int rle = reader.ReadInt16();

                        if (rle < 0)
                            throw new ApplicationException("Invalid Tile Data!");

                        if (rle > 0)
                        {
                            for (int k = y + 1; k < y + rle + 1; k++)
                            {
                                var tcopy = (Tile) tile.Clone();
                                w.Tiles[x, k] = tcopy;
                            }
                            y = y + rle;
                        }
                    }
                }
            }

            if (version < 67)
                w.FixSunflowers();
            if (version < 72)
                w.FixChand();

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Chests..."));
            w.Chests.Clear();
            ((ObservableCollection<Chest>)w.Chests).AddRange(ReadChestDataFromStreamV1(reader, version));

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Signs..."));
            w.Signs.Clear();

            foreach (Sign sign in ReadSignDataFromStreamV1(reader))
            {
                if (w.Tiles[sign.X, sign.Y].IsActive && Tile.IsSign(w.Tiles[sign.X, sign.Y].Type))
                {
                    w.Signs.Add(sign);
                }
            }

            w.NPCs.Clear();
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading NPC Data..."));
            while (reader.ReadBoolean())
            {
                var npc = new NPC();
                npc.Name = reader.ReadString();
                npc.Position = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                npc.IsHomeless = reader.ReadBoolean();
                npc.Home = new Vector2Int32(reader.ReadInt32(), reader.ReadInt32());
                npc.SpriteId = 0;
                if (NpcIds.ContainsKey(npc.Name))
                    npc.SpriteId = NpcIds[npc.Name];

                w.NPCs.Add(npc);
            }
            // if (version>=0x1f) read the names of the following npcs:
            // merchant, nurse, arms dealer, dryad, guide, clothier, demolitionist,
            // tinkerer and wizard
            // if (version>=0x23) read the name of the mechanic


            if (version >= 31)
            {
                OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading NPC Names..."));
                w.CharacterNames.Add(new NpcName(17, reader.ReadString()));
                w.CharacterNames.Add(new NpcName(18, reader.ReadString()));
                w.CharacterNames.Add(new NpcName(19, reader.ReadString()));
                w.CharacterNames.Add(new NpcName(20, reader.ReadString()));
                w.CharacterNames.Add(new NpcName(22, reader.ReadString()));
                w.CharacterNames.Add(new NpcName(54, reader.ReadString()));
                w.CharacterNames.Add(new NpcName(38, reader.ReadString()));
                w.CharacterNames.Add(new NpcName(107, reader.ReadString()));
                w.CharacterNames.Add(new NpcName(108, reader.ReadString()));
                if (version >= 35)
                    w.CharacterNames.Add(new NpcName(124, reader.ReadString()));
                else
                    w.CharacterNames.Add(new NpcName(124, "Nancy"));

                if (version >= 65)
                {
                    w.CharacterNames.Add(new NpcName(160, reader.ReadString()));
                    w.CharacterNames.Add(new NpcName(178, reader.ReadString()));
                    w.CharacterNames.Add(new NpcName(207, reader.ReadString()));
                    w.CharacterNames.Add(new NpcName(208, reader.ReadString()));
                    w.CharacterNames.Add(new NpcName(209, reader.ReadString()));
                    w.CharacterNames.Add(new NpcName(227, reader.ReadString()));
                    w.CharacterNames.Add(new NpcName(228, reader.ReadString()));
                    w.CharacterNames.Add(new NpcName(229, reader.ReadString()));
                }
                else
                {
                    w.CharacterNames.Add(GetNewNpc(160));
                    w.CharacterNames.Add(GetNewNpc(178));
                    w.CharacterNames.Add(GetNewNpc(207));
                    w.CharacterNames.Add(GetNewNpc(208));
                    w.CharacterNames.Add(GetNewNpc(209));
                    w.CharacterNames.Add(GetNewNpc(227));
                    w.CharacterNames.Add(GetNewNpc(228));
                    w.CharacterNames.Add(GetNewNpc(229));
                }
            }
            else
            {
                w.CharacterNames.Add(GetNewNpc(17));
                w.CharacterNames.Add(GetNewNpc(18));
                w.CharacterNames.Add(GetNewNpc(19));
                w.CharacterNames.Add(GetNewNpc(20));
                w.CharacterNames.Add(GetNewNpc(22));
                w.CharacterNames.Add(GetNewNpc(54));
                w.CharacterNames.Add(GetNewNpc(38));
                w.CharacterNames.Add(GetNewNpc(107));
                w.CharacterNames.Add(GetNewNpc(108));
                w.CharacterNames.Add(GetNewNpc(124));
                w.CharacterNames.Add(GetNewNpc(160));
                w.CharacterNames.Add(GetNewNpc(178));
                w.CharacterNames.Add(GetNewNpc(207));
                w.CharacterNames.Add(GetNewNpc(208));
                w.CharacterNames.Add(GetNewNpc(209));
                w.CharacterNames.Add(GetNewNpc(227));
                w.CharacterNames.Add(GetNewNpc(228));
                w.CharacterNames.Add(GetNewNpc(229));
            }
            if (version >= 7)
            {
                OnProgressChanged(null, new ProgressChangedEventArgs(100, "Validating File..."));
                bool validation = reader.ReadBoolean();
                string checkTitle = reader.ReadString();
                int checkVersion = reader.ReadInt32();
                if (validation && checkTitle == w.Title && checkVersion == w.WorldId)
                {
                    //w.loadSuccess = true;
                }
                else
                {
                    reader.Close();
                    throw new FileLoadException(
                        string.Format("Error reading world file validation parameters! {0}", filename));
                }
            }
            OnProgressChanged(null, new ProgressChangedEventArgs(0, "World Load Complete."));
        }
コード例 #13
0
        private static void SaveV1(World world, BinaryWriter bw)
        {
            bw.Write(CompatibleVersion);
            bw.Write(world.Title);
            bw.Write(world.WorldId);
            bw.Write((int) world.LeftWorld);
            bw.Write((int) world.RightWorld);
            bw.Write((int) world.TopWorld);
            bw.Write((int) world.BottomWorld);
            bw.Write(world.TilesHigh);
            bw.Write(world.TilesWide);

            bw.Write((byte) world.MoonType);
            bw.Write(world.TreeX0);
            bw.Write(world.TreeX1);
            bw.Write(world.TreeX2);
            bw.Write(world.TreeStyle0);
            bw.Write(world.TreeStyle1);
            bw.Write(world.TreeStyle2);
            bw.Write(world.TreeStyle3);
            bw.Write(world.CaveBackX0);
            bw.Write(world.CaveBackX1);
            bw.Write(world.CaveBackX2);
            bw.Write(world.CaveBackStyle0);
            bw.Write(world.CaveBackStyle1);
            bw.Write(world.CaveBackStyle2);
            bw.Write(world.CaveBackStyle3);
            bw.Write(world.IceBackStyle);
            bw.Write(world.JungleBackStyle);
            bw.Write(world.HellBackStyle);

            bw.Write(world.SpawnX);
            bw.Write(world.SpawnY);
            bw.Write(world.GroundLevel);
            bw.Write(world.RockLevel);
            bw.Write(world.Time);
            bw.Write(world.DayTime);
            bw.Write(world.MoonPhase);
            bw.Write(world.BloodMoon);
            bw.Write(world.IsEclipse);
            bw.Write(world.DungeonX);
            bw.Write(world.DungeonY);

            bw.Write(world.IsCrimson);

            bw.Write(world.DownedBoss1);
            bw.Write(world.DownedBoss2);
            bw.Write(world.DownedBoss3);
            bw.Write(world.DownedQueenBee);
            bw.Write(world.DownedMechBoss1);
            bw.Write(world.DownedMechBoss2);
            bw.Write(world.DownedMechBoss3);
            bw.Write(world.DownedMechBossAny);
            bw.Write(world.DownedPlantBoss);
            bw.Write(world.DownedGolemBoss);
            bw.Write(world.SavedGoblin);
            bw.Write(world.SavedWizard);
            bw.Write(world.SavedMech);
            bw.Write(world.DownedGoblins);
            bw.Write(world.DownedClown);
            bw.Write(world.DownedFrost);
            bw.Write(world.DownedPirates);

            bw.Write(world.ShadowOrbSmashed);
            bw.Write(world.SpawnMeteor);
            bw.Write((byte) world.ShadowOrbCount);
            bw.Write(world.AltarCount);
            bw.Write(world.HardMode);
            bw.Write(world.InvasionDelay);
            bw.Write(world.InvasionSize);
            bw.Write(world.InvasionType);
            bw.Write(world.InvasionX);

            bw.Write(world.TempRaining);
            bw.Write(world.TempRainTime);
            bw.Write(world.TempMaxRain);
            bw.Write(world.OreTier1);
            bw.Write(world.OreTier2);
            bw.Write(world.OreTier3);
            bw.Write(world.BgTree);
            bw.Write(world.BgCorruption);
            bw.Write(world.BgJungle);
            bw.Write(world.BgSnow);
            bw.Write(world.BgHallow);
            bw.Write(world.BgCrimson);
            bw.Write(world.BgDesert);
            bw.Write(world.BgOcean);
            bw.Write((int) world.CloudBgActive);
            bw.Write(world.NumClouds);
            bw.Write(world.WindSpeedSet);


            for (int x = 0; x < world.TilesWide; ++x)
            {
                OnProgressChanged(world,
                    new ProgressChangedEventArgs(x.ProgressPercentage(world.TilesWide), "Saving UndoTiles..."));

                int rle = 0;
                for (int y = 0; y < world.TilesHigh; y = y + rle + 1)
                {
                    Tile curTile = world.Tiles[x, y];
                    WriteTileDataToStreamV1(curTile, bw);

                    int rleTemp = 1;
                    while (y + rleTemp < world.TilesHigh && curTile.Equals(world.Tiles[x, (y + rleTemp)]))
                        ++rleTemp;
                    rle = rleTemp - 1;
                    bw.Write((short) rle);
                }
            }
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving Chests..."));
            WriteChestDataToStreamV1(world.Chests, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving Signs..."));
            WriteSignDataToStreamV1(world.Signs, bw);
            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving NPC Data..."));
            foreach (NPC curNpc in world.NPCs)
            {
                bw.Write(true);
                bw.Write(curNpc.Name);
                bw.Write(curNpc.Position.X);
                bw.Write(curNpc.Position.Y);
                bw.Write(curNpc.IsHomeless);
                bw.Write(curNpc.Home.X);
                bw.Write(curNpc.Home.Y);
            }
            bw.Write(false);


            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving NPC Names..."));

            world.FixNpcs();

            bw.Write(world.GetNpc(17).Name);
            bw.Write(world.GetNpc(18).Name);
            bw.Write(world.GetNpc(19).Name);
            bw.Write(world.GetNpc(20).Name);
            bw.Write(world.GetNpc(22).Name);
            bw.Write(world.GetNpc(54).Name);
            bw.Write(world.GetNpc(38).Name);
            bw.Write(world.GetNpc(107).Name);
            bw.Write(world.GetNpc(108).Name);
            bw.Write(world.GetNpc(124).Name);
            bw.Write(world.GetNpc(160).Name);
            bw.Write(world.GetNpc(178).Name);
            bw.Write(world.GetNpc(207).Name);
            bw.Write(world.GetNpc(208).Name);
            bw.Write(world.GetNpc(209).Name);
            bw.Write(world.GetNpc(227).Name);
            bw.Write(world.GetNpc(228).Name);
            bw.Write(world.GetNpc(229).Name);

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Saving Validation Data..."));
            bw.Write(true);
            bw.Write(world.Title);
            bw.Write(world.WorldId);
        }
コード例 #14
0
        public static void LoadHeaderFlags(BinaryReader r, World w, int expectedPosition)
        {
            w.Title = r.ReadString();
            w.WorldId = r.ReadInt32();
            w.LeftWorld = (float)r.ReadInt32();
            w.RightWorld = (float)r.ReadInt32();
            w.TopWorld = (float)r.ReadInt32();
            w.BottomWorld = (float)r.ReadInt32();
            w.TilesHigh = r.ReadInt32();
            w.TilesWide = r.ReadInt32();

            if (w.Version >= 147)
            {
                w.ExpertMode = r.ReadBoolean();
                w.CreationTime = r.ReadInt64();
            }
            else
            {
                w.CreationTime = DateTime.Now.ToBinary();
            }

            w.MoonType = r.ReadByte();
            w.TreeX[0] = r.ReadInt32();
            w.TreeX[1] = r.ReadInt32();
            w.TreeX[2] = r.ReadInt32();
            w.TreeX2 = w.TreeX[2];
            w.TreeX1 = w.TreeX[1];
            w.TreeX0 = w.TreeX[0];
            w.TreeStyle0 = r.ReadInt32();
            w.TreeStyle1 = r.ReadInt32();
            w.TreeStyle2 = r.ReadInt32();
            w.TreeStyle3 = r.ReadInt32();
            w.CaveBackX[0] = r.ReadInt32();
            w.CaveBackX[1] = r.ReadInt32();
            w.CaveBackX[2] = r.ReadInt32();
            w.CaveBackX2 = w.CaveBackX[2];
            w.CaveBackX1 = w.CaveBackX[1];
            w.CaveBackX0 = w.CaveBackX[0];
            w.CaveBackStyle0 = r.ReadInt32();
            w.CaveBackStyle1 = r.ReadInt32();
            w.CaveBackStyle2 = r.ReadInt32();
            w.CaveBackStyle3 = r.ReadInt32();
            w.IceBackStyle = r.ReadInt32();
            w.JungleBackStyle = r.ReadInt32();
            w.HellBackStyle = r.ReadInt32();

            w.SpawnX = r.ReadInt32();
            w.SpawnY = r.ReadInt32();
            w.GroundLevel = r.ReadDouble();
            w.RockLevel = r.ReadDouble();
            w.Time = r.ReadDouble();
            w.DayTime = r.ReadBoolean();
            w.MoonPhase = r.ReadInt32();
            w.BloodMoon = r.ReadBoolean();
            w.IsEclipse = r.ReadBoolean();
            w.DungeonX = r.ReadInt32();
            w.DungeonY = r.ReadInt32();

            w.IsCrimson = r.ReadBoolean();

            w.DownedBoss1 = r.ReadBoolean();
            w.DownedBoss2 = r.ReadBoolean();
            w.DownedBoss3 = r.ReadBoolean();
            w.DownedQueenBee = r.ReadBoolean();
            w.DownedMechBoss1 = r.ReadBoolean();
            w.DownedMechBoss2 = r.ReadBoolean();
            w.DownedMechBoss3 = r.ReadBoolean();
            w.DownedMechBossAny = r.ReadBoolean();
            w.DownedPlantBoss = r.ReadBoolean();
            w.DownedGolemBoss = r.ReadBoolean();
            if (w.Version >= 147) w.DownedSlimeKingBoss = r.ReadBoolean();
            w.SavedGoblin = r.ReadBoolean();
            w.SavedWizard = r.ReadBoolean();
            w.SavedMech = r.ReadBoolean();
            w.DownedGoblins = r.ReadBoolean();
            w.DownedClown = r.ReadBoolean();
            w.DownedFrost = r.ReadBoolean();
            w.DownedPirates = r.ReadBoolean();

            w.ShadowOrbSmashed = r.ReadBoolean();
            w.SpawnMeteor = r.ReadBoolean();
            w.ShadowOrbCount = r.ReadByte();
            w.AltarCount = r.ReadInt32();
            w.HardMode = r.ReadBoolean();
            w.InvasionDelay = r.ReadInt32();
            w.InvasionSize = r.ReadInt32();
            w.InvasionType = r.ReadInt32();
            w.InvasionX = r.ReadDouble();

            if (w.Version >= 147)
            {                 
                 w.SlimeRainTime = r.ReadDouble();
                 w.SundialCooldown = r.ReadByte();
            }

            w.TempRaining = r.ReadBoolean();
            w.TempRainTime = r.ReadInt32();
            w.TempMaxRain = r.ReadSingle();
            w.OreTier1 = r.ReadInt32();
            w.OreTier2 = r.ReadInt32();
            w.OreTier3 = r.ReadInt32();
            w.BgTree = r.ReadByte();
            w.BgCorruption = r.ReadByte();
            w.BgJungle = r.ReadByte();
            w.BgSnow = r.ReadByte();
            w.BgHallow = r.ReadByte();
            w.BgCrimson = r.ReadByte();
            w.BgDesert = r.ReadByte();
            w.BgOcean = r.ReadByte();
            w.CloudBgActive = (float)r.ReadInt32();
            w.NumClouds = r.ReadInt16();
            w.WindSpeedSet = r.ReadSingle();

            if (w.Version >= 95)
            {
                for (int i = r.ReadInt32(); i > 0; i--)
                {
                    w.Anglers.Add(r.ReadString());
                }
            }

            if (w.Version >= 99)
            {
                w.SavedAngler = r.ReadBoolean();
            }

            if (w.Version >= 101)
            {
                w.AnglerQuest = r.ReadInt32();
            }

            if (w.Version >= 104)
            {
                w.SavedStylist = r.ReadBoolean();
            }

            if (w.Version >= 140)
            {
                w.SavedTaxCollector = r.ReadBoolean();
            }

            if (w.Version >= 140)
            {
                w.InvasionSizeStart = r.ReadInt32();
            }

            if (w.Version >= 140)
            {
                w.CultistDelay = r.ReadInt32();
            }

            if (w.Version >= 140)
            {
                int numberOfMobs = r.ReadInt16();
                w.NumberOfMobs = numberOfMobs;
                for (int counter = 0; counter < numberOfMobs; counter++)
                {
                    w.KilledMobs.Add(r.ReadInt32());
                }
            }

            if (w.Version >= 140)
            {
                w.FastForwardTime = r.ReadBoolean();
            }

            if (w.Version >= 140)
            {
                w.DownedFishron = r.ReadBoolean();
                w.DownedMartians = r.ReadBoolean();
                w.DownedLunaticCultist = r.ReadBoolean();
                w.DownedMoonlord = r.ReadBoolean();
                w.DownedHalloweeenKing = r.ReadBoolean();
                w.DownedHalloweenTree = r.ReadBoolean();
                w.DownedChristmasQueen = r.ReadBoolean();
                w.DownedSanta = r.ReadBoolean();
                w.DownedChristmasTree = r.ReadBoolean();
                w.DownedCelestialSolar = r.ReadBoolean();
                w.DownedCelestialVortex = r.ReadBoolean();
                w.DownedCelestialNebula = r.ReadBoolean();
                w.DownedCelestialStardust = r.ReadBoolean();
                w.CelestialSolarActive = r.ReadBoolean();
                w.CelestialVortexActive = r.ReadBoolean();
                w.CelestialNebulaActive = r.ReadBoolean();
                w.CelestialStardustActive = r.ReadBoolean();
                w.Apocalypse = r.ReadBoolean();
            }

            // a little future proofing, read any "unknown" flags from the end of the list and save them. We will write these back after we write our "known" flags.
            if (r.BaseStream.Position < expectedPosition)
            {
                w.UnknownData = r.ReadBytes(expectedPosition - (int)r.BaseStream.Position);
            }
        }
コード例 #15
0
        public static void LoadTileEntities(BinaryReader r, World w)
        {
            w.TileEntitiesNumber = r.ReadInt32();

            for (int counter = 0; counter < w.TileEntitiesNumber; counter++ )
            {
                TileEntity entity = new TileEntity();
                entity.Type = r.ReadByte();
                entity.Id = r.ReadInt32();
                entity.PosX = r.ReadInt16();
                entity.PosY = r.ReadInt16();
                switch (entity.Type)
                {
                    case 0: //it is a dummy
                        entity.Npc = r.ReadInt16();
                        break;
                    case 1: //it is a item frame
                        entity.ItemNetId = r.ReadInt16();
                        entity.Prefix = r.ReadByte();
                        entity.Stack = r.ReadInt16();
                        break;
                }
                w.TileEntities.Add(entity);
            }
        }
コード例 #16
0
        public static void LoadFooter(BinaryReader r, World w)
        {
            if (!r.ReadBoolean())
                throw new FileFormatException("Invalid Footer");

            if (r.ReadString() != w.Title)
                throw new FileFormatException("Invalid Footer");

            if (r.ReadInt32() != w.WorldId)
                throw new FileFormatException("Invalid Footer");
        }
コード例 #17
0
        public static void LoadMobsData(BinaryReader r, World w)
        {
            int totalMobs = 0;
            bool flag = r.ReadBoolean();
            while (flag)            
            {
                NPC npc = new NPC();
                npc.Name = r.ReadString();                    
                npc.Position = new Vector2(r.ReadSingle(), r.ReadSingle());

                if (NpcIds.ContainsKey(npc.Name))
                    npc.SpriteId = NpcIds[npc.Name];

                w.Mobs.Add(npc);
                totalMobs++;
                flag = r.ReadBoolean();
            }
        }
コード例 #18
0
        public static void LoadNPCsData(BinaryReader r, World w)
        {
            int totalNpcs = 0;
            for (bool i = r.ReadBoolean(); i; i = r.ReadBoolean())
            {
                NPC npc = new NPC();
                npc.Name = r.ReadString();
                npc.DisplayName = r.ReadString();
                npc.Position = new Vector2(r.ReadSingle(), r.ReadSingle());
                npc.IsHomeless = r.ReadBoolean();
                npc.Home = new Vector2Int32(r.ReadInt32(), r.ReadInt32());

                if (NpcIds.ContainsKey(npc.Name))
                    npc.SpriteId = NpcIds[npc.Name];

                w.NPCs.Add(npc);
                totalNpcs++;
            }
        }
コード例 #19
0
        public static void LoadV2(BinaryReader b, string filename, World w)
        {
            //throw new NotImplementedException("World Version > 87");

            bool[] tileFrameImportant;
            int[] sectionPointers;

            // reset the stream
            b.BaseStream.Position = (long)0;

            OnProgressChanged(null, new ProgressChangedEventArgs(0, "Loading File Header..."));
            // read section pointers and tile frame data
            if (!LoadSectionHeader(b, out tileFrameImportant, out sectionPointers, w))
                throw new FileFormatException("Invalid File Format Section");

            TileFrameImportant = tileFrameImportant;

            // we should be at the end of the first section
            if (b.BaseStream.Position != sectionPointers[0])
                throw new FileFormatException("Unexpected Position: Invalid File Format Section");

            // Load the flags
            LoadHeaderFlags(b, w, sectionPointers[1]);
            if (b.BaseStream.Position != sectionPointers[1])
                throw new FileFormatException("Unexpected Position: Invalid Header Flags");

            OnProgressChanged(null, new ProgressChangedEventArgs(0, "Loading UndoTiles..."));
            w.Tiles = LoadTileData(b, w.TilesWide, w.TilesHigh);
            if (b.BaseStream.Position != sectionPointers[2])
                throw new FileFormatException("Unexpected Position: Invalid Tile Data");

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Chests..."));

            foreach (Chest chest in LoadChestData(b))
            {
                //Tile tile = w.Tiles[chest.X, chest.Y];
                //if (tile.IsActive && (tile.Type == 55 || tile.Type == 85))
                {
                    w.Chests.Add(chest);
                }
            }

            if (b.BaseStream.Position != sectionPointers[3])
                throw new FileFormatException("Unexpected Position: Invalid Chest Data");

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Signs..."));

            foreach (Sign sign in LoadSignData(b))
            {
                Tile tile = w.Tiles[sign.X, sign.Y];
                if (tile.IsActive && Tile.IsSign(tile.Type))
                {
                    w.Signs.Add(sign);
                }
            }

            if (b.BaseStream.Position != sectionPointers[4])
                throw new FileFormatException("Unexpected Position: Invalid Sign Data");

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading NPCs..."));
            LoadNPCsData(b, w);
            if(w.Version >= 140)
            {
                OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Mobs..."));
                LoadMobsData(b, w);
                if (b.BaseStream.Position != sectionPointers[5])
                    throw new FileFormatException("Unexpected Position: Invalid Mob and NPC Data");

                OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Tile Entities Section..."));
                LoadTileEntities(b, w);
                if (b.BaseStream.Position != sectionPointers[6])
                    throw new FileFormatException("Unexpected Position: Invalid Tile Entities Section");
            }
            else
            {
                if (b.BaseStream.Position != sectionPointers[5])
                    throw new FileFormatException("Unexpected Position: Invalid NPC Data");
            }

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Verifying File..."));
            LoadFooter(b, w);

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Load Complete."));
        }
コード例 #20
0
        public static void LoadHeaderFlags(BinaryReader r, World w, int expectedPosition)
        {
            w.Title = r.ReadString();
            if (w.Version >= 179)
            {
                if (w.Version == 179)
                {
                    w.Seed = r.ReadInt32().ToString();
                }
                else
                {
                    w.Seed = r.ReadString();
                }
                w.WorldGenVersion = r.ReadUInt64();
            }
            else
            {
                w.Seed = "";
            }
            if (w.Version >= 181)
            {
                w.Guid = new Guid(r.ReadBytes(16));
            }
            else
            {
                w.Guid = Guid.NewGuid();
            }
            w.WorldId     = r.ReadInt32();
            w.LeftWorld   = (float)r.ReadInt32();
            w.RightWorld  = (float)r.ReadInt32();
            w.TopWorld    = (float)r.ReadInt32();
            w.BottomWorld = (float)r.ReadInt32();
            w.TilesHigh   = r.ReadInt32();
            w.TilesWide   = r.ReadInt32();

            if (w.Version >= 147)
            {
                w.ExpertMode   = r.ReadBoolean();
                w.CreationTime = r.ReadInt64();
            }
            else
            {
                w.CreationTime = DateTime.Now.ToBinary();
            }

            w.MoonType        = r.ReadByte();
            w.TreeX[0]        = r.ReadInt32();
            w.TreeX[1]        = r.ReadInt32();
            w.TreeX[2]        = r.ReadInt32();
            w.TreeX2          = w.TreeX[2];
            w.TreeX1          = w.TreeX[1];
            w.TreeX0          = w.TreeX[0];
            w.TreeStyle0      = r.ReadInt32();
            w.TreeStyle1      = r.ReadInt32();
            w.TreeStyle2      = r.ReadInt32();
            w.TreeStyle3      = r.ReadInt32();
            w.CaveBackX[0]    = r.ReadInt32();
            w.CaveBackX[1]    = r.ReadInt32();
            w.CaveBackX[2]    = r.ReadInt32();
            w.CaveBackX2      = w.CaveBackX[2];
            w.CaveBackX1      = w.CaveBackX[1];
            w.CaveBackX0      = w.CaveBackX[0];
            w.CaveBackStyle0  = r.ReadInt32();
            w.CaveBackStyle1  = r.ReadInt32();
            w.CaveBackStyle2  = r.ReadInt32();
            w.CaveBackStyle3  = r.ReadInt32();
            w.IceBackStyle    = r.ReadInt32();
            w.JungleBackStyle = r.ReadInt32();
            w.HellBackStyle   = r.ReadInt32();

            w.SpawnX      = r.ReadInt32();
            w.SpawnY      = r.ReadInt32();
            w.GroundLevel = r.ReadDouble();
            w.RockLevel   = r.ReadDouble();
            w.Time        = r.ReadDouble();
            w.DayTime     = r.ReadBoolean();
            w.MoonPhase   = r.ReadInt32();
            w.BloodMoon   = r.ReadBoolean();
            w.IsEclipse   = r.ReadBoolean();
            w.DungeonX    = r.ReadInt32();
            w.DungeonY    = r.ReadInt32();

            w.IsCrimson = r.ReadBoolean();

            w.DownedBoss1       = r.ReadBoolean();
            w.DownedBoss2       = r.ReadBoolean();
            w.DownedBoss3       = r.ReadBoolean();
            w.DownedQueenBee    = r.ReadBoolean();
            w.DownedMechBoss1   = r.ReadBoolean();
            w.DownedMechBoss2   = r.ReadBoolean();
            w.DownedMechBoss3   = r.ReadBoolean();
            w.DownedMechBossAny = r.ReadBoolean();
            w.DownedPlantBoss   = r.ReadBoolean();
            w.DownedGolemBoss   = r.ReadBoolean();
            if (w.Version >= 147)
            {
                w.DownedSlimeKingBoss = r.ReadBoolean();
            }
            w.SavedGoblin   = r.ReadBoolean();
            w.SavedWizard   = r.ReadBoolean();
            w.SavedMech     = r.ReadBoolean();
            w.DownedGoblins = r.ReadBoolean();
            w.DownedClown   = r.ReadBoolean();
            w.DownedFrost   = r.ReadBoolean();
            w.DownedPirates = r.ReadBoolean();

            w.ShadowOrbSmashed = r.ReadBoolean();
            w.SpawnMeteor      = r.ReadBoolean();
            w.ShadowOrbCount   = (int)r.ReadByte();
            w.AltarCount       = r.ReadInt32();
            w.HardMode         = r.ReadBoolean();
            w.InvasionDelay    = r.ReadInt32();
            w.InvasionSize     = r.ReadInt32();
            w.InvasionType     = r.ReadInt32();
            w.InvasionX        = r.ReadDouble();

            if (w.Version >= 147)
            {
                w.SlimeRainTime   = r.ReadDouble();
                w.SundialCooldown = r.ReadByte();
            }

            w.TempRaining   = r.ReadBoolean();
            w.TempRainTime  = r.ReadInt32();
            w.TempMaxRain   = r.ReadSingle();
            w.OreTier1      = r.ReadInt32();
            w.OreTier2      = r.ReadInt32();
            w.OreTier3      = r.ReadInt32();
            w.BgTree        = r.ReadByte();
            w.BgCorruption  = r.ReadByte();
            w.BgJungle      = r.ReadByte();
            w.BgSnow        = r.ReadByte();
            w.BgHallow      = r.ReadByte();
            w.BgCrimson     = r.ReadByte();
            w.BgDesert      = r.ReadByte();
            w.BgOcean       = r.ReadByte();
            w.CloudBgActive = (float)r.ReadInt32();
            w.NumClouds     = r.ReadInt16();
            w.WindSpeedSet  = r.ReadSingle();

            if (w.Version >= 95)
            {
                for (int i = r.ReadInt32(); i > 0; i--)
                {
                    w.Anglers.Add(r.ReadString());
                }
            }

            if (w.Version >= 99)
            {
                w.SavedAngler = r.ReadBoolean();
            }

            if (w.Version >= 101)
            {
                w.AnglerQuest = r.ReadInt32();
            }

            if (w.Version >= 104)
            {
                w.SavedStylist = r.ReadBoolean();
            }

            if (w.Version >= 140)
            {
                w.SavedTaxCollector = r.ReadBoolean();
                w.InvasionSizeStart = r.ReadInt32();
                w.CultistDelay      = r.ReadInt32();
                int numberOfMobs = r.ReadInt16();
                w.NumberOfMobs = numberOfMobs;
                for (int counter = 0; counter < numberOfMobs; counter++)
                {
                    w.KilledMobs.Add(r.ReadInt32());
                }
                w.FastForwardTime         = r.ReadBoolean();
                w.DownedFishron           = r.ReadBoolean();
                w.DownedMartians          = r.ReadBoolean();
                w.DownedLunaticCultist    = r.ReadBoolean();
                w.DownedMoonlord          = r.ReadBoolean();
                w.DownedHalloweenKing     = r.ReadBoolean();
                w.DownedHalloweenTree     = r.ReadBoolean();
                w.DownedChristmasQueen    = r.ReadBoolean();
                w.DownedSanta             = r.ReadBoolean();
                w.DownedChristmasTree     = r.ReadBoolean();
                w.DownedCelestialSolar    = r.ReadBoolean();
                w.DownedCelestialVortex   = r.ReadBoolean();
                w.DownedCelestialNebula   = r.ReadBoolean();
                w.DownedCelestialStardust = r.ReadBoolean();
                w.CelestialSolarActive    = r.ReadBoolean();
                w.CelestialVortexActive   = r.ReadBoolean();
                w.CelestialNebulaActive   = r.ReadBoolean();
                w.CelestialStardustActive = r.ReadBoolean();
                w.Apocalypse = r.ReadBoolean();
            }
            if (w.Version >= 170)
            {
                w.PartyManual   = r.ReadBoolean();
                w.PartyGenuine  = r.ReadBoolean();
                w.PartyCooldown = r.ReadInt32();
                int numparty = r.ReadInt32();
                for (int counter = 0; counter < numparty; counter++)
                {
                    w.PartyingNPCs.Add(r.ReadInt32());
                }
            }
            if (w.Version >= 174)
            {
                w.SandStormHappening        = r.ReadBoolean();
                w.SandStormTimeLeft         = r.ReadInt32();
                w.SandStormSeverity         = r.ReadSingle();
                w.SandStormIntendedSeverity = r.ReadSingle();
            }
            if (w.Version >= 178)
            {
                w.SavedBartender      = r.ReadBoolean();
                w.DownedDD2InvasionT1 = r.ReadBoolean();
                w.DownedDD2InvasionT2 = r.ReadBoolean();
                w.DownedDD2InvasionT3 = r.ReadBoolean();
            }

            // a little future proofing, read any "unknown" flags from the end of the list and save them. We will write these back after we write our "known" flags.
            if (r.BaseStream.Position < expectedPosition)
            {
                w.UnknownData = r.ReadBytes(expectedPosition - (int)r.BaseStream.Position);
            }
        }
コード例 #21
0
        public static bool LoadSectionHeader(BinaryReader r, out bool[] tileFrameImportant, out int[] sectionPointers, World w)
        {
            tileFrameImportant = null;
            sectionPointers    = null;
            int versionNumber = r.ReadInt32();

            if (versionNumber > 140)
            {
                UInt64 versionTypecheck = r.ReadUInt64();
                if (versionTypecheck != 0x026369676f6c6572ul)
                {
                    throw new FileFormatException("Invalid Header");
                }

                w.FileRevision = r.ReadUInt32();
                UInt64 temp = r.ReadUInt64();//I have no idea what this is for...
                w.IsFavorite = ((temp & 1uL) == 1uL);
            }

            // read file section stream positions
            short fileSectionCount = r.ReadInt16();

            sectionPointers = new int[fileSectionCount];
            for (int i = 0; i < fileSectionCount; i++)
            {
                sectionPointers[i] = r.ReadInt32();
            }

            // Read tile frame importance from bit-packed data
            tileFrameImportant = ReadBitArray(r);

            return(true);
        }
コード例 #22
0
        public static int SaveHeaderFlags(World world, BinaryWriter bw)
        {
            bw.Write(world.Title);
            bw.Write(world.Seed);
            bw.Write(world.WorldGenVersion);
            bw.Write(world.Guid.ToByteArray());
            bw.Write(world.WorldId);
            bw.Write((int)world.LeftWorld);
            bw.Write((int)world.RightWorld);
            bw.Write((int)world.TopWorld);
            bw.Write((int)world.BottomWorld);
            bw.Write(world.TilesHigh);
            bw.Write(world.TilesWide);
            bw.Write(world.ExpertMode);
            bw.Write(world.CreationTime);
            bw.Write((byte)world.MoonType);
            bw.Write(world.TreeX0);
            bw.Write(world.TreeX1);
            bw.Write(world.TreeX2);
            bw.Write(world.TreeStyle0);
            bw.Write(world.TreeStyle1);
            bw.Write(world.TreeStyle2);
            bw.Write(world.TreeStyle3);
            bw.Write(world.CaveBackX0);
            bw.Write(world.CaveBackX1);
            bw.Write(world.CaveBackX2);
            bw.Write(world.CaveBackStyle0);
            bw.Write(world.CaveBackStyle1);
            bw.Write(world.CaveBackStyle2);
            bw.Write(world.CaveBackStyle3);
            bw.Write(world.IceBackStyle);
            bw.Write(world.JungleBackStyle);
            bw.Write(world.HellBackStyle);
            bw.Write(world.SpawnX);
            bw.Write(world.SpawnY);
            bw.Write(world.GroundLevel);
            bw.Write(world.RockLevel);
            bw.Write(world.Time);
            bw.Write(world.DayTime);
            bw.Write(world.MoonPhase);
            bw.Write(world.BloodMoon);
            bw.Write(world.IsEclipse);
            bw.Write(world.DungeonX);
            bw.Write(world.DungeonY);
            bw.Write(world.IsCrimson);
            bw.Write(world.DownedBoss1);
            bw.Write(world.DownedBoss2);
            bw.Write(world.DownedBoss3);
            bw.Write(world.DownedQueenBee);
            bw.Write(world.DownedMechBoss1);
            bw.Write(world.DownedMechBoss2);
            bw.Write(world.DownedMechBoss3);
            bw.Write(world.DownedMechBossAny);
            bw.Write(world.DownedPlantBoss);
            bw.Write(world.DownedGolemBoss);
            bw.Write(world.DownedSlimeKingBoss);
            bw.Write(world.SavedGoblin);
            bw.Write(world.SavedWizard);
            bw.Write(world.SavedMech);
            bw.Write(world.DownedGoblins);
            bw.Write(world.DownedClown);
            bw.Write(world.DownedFrost);
            bw.Write(world.DownedPirates);
            bw.Write(world.ShadowOrbSmashed);
            bw.Write(world.SpawnMeteor);
            bw.Write((byte)world.ShadowOrbCount);
            bw.Write(world.AltarCount);
            bw.Write(world.HardMode);
            bw.Write(world.InvasionDelay);
            bw.Write(world.InvasionSize);
            bw.Write(world.InvasionType);
            bw.Write(world.InvasionX);
            bw.Write(world.SlimeRainTime);
            bw.Write((byte)world.SundialCooldown);
            bw.Write(world.TempRaining);
            bw.Write(world.TempRainTime);
            bw.Write(world.TempMaxRain);
            bw.Write(world.OreTier1);
            bw.Write(world.OreTier2);
            bw.Write(world.OreTier3);
            bw.Write(world.BgTree);
            bw.Write(world.BgCorruption);
            bw.Write(world.BgJungle);
            bw.Write(world.BgSnow);
            bw.Write(world.BgHallow);
            bw.Write(world.BgCrimson);
            bw.Write(world.BgDesert);
            bw.Write(world.BgOcean);
            bw.Write((int)world.CloudBgActive);
            bw.Write(world.NumClouds);
            bw.Write(world.WindSpeedSet);
            bw.Write(world.Anglers.Count);
            foreach (string angler in world.Anglers)
            {
                bw.Write(angler);
            }
            bw.Write(world.SavedAngler);
            bw.Write(world.AnglerQuest);
            bw.Write(world.SavedStylist);
            bw.Write(world.SavedTaxCollector);
            bw.Write(world.InvasionSizeStart);
            bw.Write(world.CultistDelay);
            bw.Write((Int16)world.NumberOfMobs);
            foreach (int count in world.KilledMobs)
            {
                bw.Write(count);
            }
            bw.Write(world.FastForwardTime);
            bw.Write(world.DownedFishron);
            bw.Write(world.DownedMartians);
            bw.Write(world.DownedLunaticCultist);
            bw.Write(world.DownedMoonlord);
            bw.Write(world.DownedHalloweenKing);
            bw.Write(world.DownedHalloweenTree);
            bw.Write(world.DownedChristmasQueen);
            bw.Write(world.DownedSanta);
            bw.Write(world.DownedChristmasTree);
            bw.Write(world.DownedCelestialSolar);
            bw.Write(world.DownedCelestialVortex);
            bw.Write(world.DownedCelestialNebula);
            bw.Write(world.DownedCelestialStardust);
            bw.Write(world.CelestialSolarActive);
            bw.Write(world.CelestialVortexActive);
            bw.Write(world.CelestialNebulaActive);
            bw.Write(world.CelestialStardustActive);
            bw.Write(world.Apocalypse);
            bw.Write(world.PartyManual);
            bw.Write(world.PartyGenuine);
            bw.Write(world.PartyCooldown);
            bw.Write(world.PartyingNPCs.Count);
            foreach (int partier in world.PartyingNPCs)
            {
                bw.Write(partier);
            }

            bw.Write(world.SandStormHappening);
            bw.Write(world.SandStormTimeLeft);
            bw.Write(world.SandStormSeverity);
            bw.Write(world.SandStormIntendedSeverity);
            bw.Write(world.SavedBartender);
            bw.Write(world.DownedDD2InvasionT1);
            bw.Write(world.DownedDD2InvasionT2);
            bw.Write(world.DownedDD2InvasionT3);

            if (world.UnknownData != null && world.UnknownData.Length > 0)
            {
                bw.Write(world.UnknownData);
            }

            return((int)bw.BaseStream.Position);
        }
コード例 #23
0
        public static void LoadV2(BinaryReader b, string filename, World w)
        {
            //throw new NotImplementedException("World Version > 87");

            bool[] tileFrameImportant;
            int[]  sectionPointers;

            // reset the stream
            b.BaseStream.Position = (long)0;

            OnProgressChanged(null, new ProgressChangedEventArgs(0, "Loading File Header..."));
            // read section pointers and tile frame data
            if (!LoadSectionHeader(b, out tileFrameImportant, out sectionPointers, w))
            {
                throw new FileFormatException("Invalid File Format Section");
            }

            TileFrameImportant = tileFrameImportant;

            // we should be at the end of the first section
            if (b.BaseStream.Position != sectionPointers[0])
            {
                throw new FileFormatException("Unexpected Position: Invalid File Format Section");
            }

            // Load the flags
            LoadHeaderFlags(b, w, sectionPointers[1]);
            if (b.BaseStream.Position != sectionPointers[1])
            {
                throw new FileFormatException("Unexpected Position: Invalid Header Flags");
            }

            OnProgressChanged(null, new ProgressChangedEventArgs(0, "Loading UndoTiles..."));
            w.Tiles = LoadTileData(b, w.TilesWide, w.TilesHigh);
            if (b.BaseStream.Position != sectionPointers[2])
            {
                throw new FileFormatException("Unexpected Position: Invalid Tile Data");
            }

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Chests..."));

            foreach (Chest chest in LoadChestData(b))
            {
                //Tile tile = w.Tiles[chest.X, chest.Y];
                //if (tile.IsActive && (tile.Type == 55 || tile.Type == 85))
                {
                    w.Chests.Add(chest);
                }
            }

            if (b.BaseStream.Position != sectionPointers[3])
            {
                throw new FileFormatException("Unexpected Position: Invalid Chest Data");
            }

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Signs..."));

            foreach (Sign sign in LoadSignData(b))
            {
                Tile tile = w.Tiles[sign.X, sign.Y];
                if (tile.IsActive && Tile.IsSign(tile.Type))
                {
                    w.Signs.Add(sign);
                }
            }

            if (b.BaseStream.Position != sectionPointers[4])
            {
                throw new FileFormatException("Unexpected Position: Invalid Sign Data");
            }

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading NPCs..."));
            LoadNPCsData(b, w);
            if (w.Version >= 140)
            {
                OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Mobs..."));
                LoadMobsData(b, w);
                if (b.BaseStream.Position != sectionPointers[5])
                {
                    throw new FileFormatException("Unexpected Position: Invalid Mob and NPC Data");
                }

                OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Tile Entities Section..."));
                LoadTileEntities(b, w);
                if (b.BaseStream.Position != sectionPointers[6])
                {
                    throw new FileFormatException("Unexpected Position: Invalid Tile Entities Section");
                }
            }
            else
            {
                if (b.BaseStream.Position != sectionPointers[5])
                {
                    throw new FileFormatException("Unexpected Position: Invalid NPC Data");
                }
            }
            if (w.Version >= 170)
            {
                LoadPressurePlate(b, w);
                if (b.BaseStream.Position != sectionPointers[7])
                {
                    throw new FileFormatException("Unexpected Position: Invalid Weighted Pressure Plate Section");
                }
            }

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Verifying File..."));
            LoadFooter(b, w);

            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Load Complete."));
        }
コード例 #24
0
ファイル: World.cs プロジェクト: Kapow751/Terraria-Map-Editor
        public static World LoadWorld(string filename)
        {
            var w = new World();
            try
            {
                lock (_fileLock)
                {
                    using (var b = new BinaryReader(File.OpenRead(filename)))
                    {
                        w.Version = b.ReadUInt32(); //now we care about the version
                        uint version = w.Version;
                        w.Title = b.ReadString();
                        w.WorldId = b.ReadInt32();

                        w.Rand = new Random(w.WorldId);

                        w.LeftWorld = (float)b.ReadInt32();
                        w.RightWorld = (float)b.ReadInt32();
                        w.TopWorld = (float)b.ReadInt32();
                        w.BottomWorld = (float)b.ReadInt32();
                        w.TilesHigh = b.ReadInt32();
                        w.TilesWide = b.ReadInt32();

                        //if (w.TilesHigh > 10000 || w.TilesWide > 10000 || w.TilesHigh <= 0 || w.TilesWide <= 0)
                        //    throw new FileLoadException(string.Format("Invalid File: {0}", filename));

                        if (version >= 63)
                            w.MoonType = (int)b.ReadByte();
                        else
                            w.MoonType = w.Rand.Next(MaxMoons);

                        if (version >= 44)
                        {
                            w.TreeX[0] = b.ReadInt32();
                            w.TreeX[1] = b.ReadInt32();
                            w.TreeX[2] = b.ReadInt32();
                            w.TreeStyle[0] = b.ReadInt32();
                            w.TreeStyle[1] = b.ReadInt32();
                            w.TreeStyle[2] = b.ReadInt32();
                            w.TreeStyle[3] = b.ReadInt32();
                        }
                        if (version >= 60)
                        {
                            w.CaveBackX[0] = b.ReadInt32();
                            w.CaveBackX[1] = b.ReadInt32();
                            w.CaveBackX[2] = b.ReadInt32();
                            w.CaveBackStyle[0] = b.ReadInt32();
                            w.CaveBackStyle[1] = b.ReadInt32();
                            w.CaveBackStyle[2] = b.ReadInt32();
                            w.CaveBackStyle[3] = b.ReadInt32();
                            w.IceBackStyle = b.ReadInt32();
                            if (version >= 61)
                            {
                                w.JungleBackStyle = b.ReadInt32();
                                w.HellBackStyle = b.ReadInt32();
                            }
                        }
                        else
                        {
                            w.CaveBackX[0] = w.TilesWide / 2;
                            w.CaveBackX[1] = w.TilesWide;
                            w.CaveBackX[2] = w.TilesWide;
                            w.CaveBackStyle[0] = 0;
                            w.CaveBackStyle[1] = 1;
                            w.CaveBackStyle[2] = 2;
                            w.CaveBackStyle[3] = 3;
                            w.IceBackStyle = 0;
                            w.JungleBackStyle = 0;
                            w.HellBackStyle = 0;
                        }

                        w.SpawnX = b.ReadInt32();
                        w.SpawnY = b.ReadInt32();
                        w.GroundLevel = (int)b.ReadDouble();
                        w.RockLevel = (int)b.ReadDouble();

                        // read world flags
                        w.Time = b.ReadDouble();
                        w.DayTime = b.ReadBoolean();
                        w.MoonPhase = b.ReadInt32();
                        w.BloodMoon = b.ReadBoolean();

                        if (version >= 70)
                        {
                            w.IsEclipse = b.ReadBoolean();
                        }

                        w.DungeonX = b.ReadInt32();
                        w.DungeonY = b.ReadInt32();

                        if (version >= 56)
                        {
                            w.IsCrimson = b.ReadBoolean();
                        }
                        else
                        {
                            w.IsCrimson = false;
                        }

                        w.DownedBoss1 = b.ReadBoolean();
                        w.DownedBoss2 = b.ReadBoolean();
                        w.DownedBoss3 = b.ReadBoolean();

                        if (version >= 66)
                        {
                            w.DownedQueenBee = b.ReadBoolean();
                        }
                        if (version >= 44)
                        {
                            w.DownedMechBoss1 = b.ReadBoolean();
                            w.DownedMechBoss2 = b.ReadBoolean();
                            w.DownedMechBoss3 = b.ReadBoolean();
                            w.DownedMechBossAny = b.ReadBoolean();
                        }
                        if (version >= 64)
                        {
                            w.DownedPlantBoss = b.ReadBoolean();
                            w.DownedGolemBoss = b.ReadBoolean();
                        }
                        if (version >= 29)
                        {
                            w.SavedGoblin = b.ReadBoolean();
                            w.SavedWizard = b.ReadBoolean();
                            if (version >= 34)
                            {
                                w.SavedMech = b.ReadBoolean();
                            }
                            w.DownedGoblins = b.ReadBoolean();
                        }
                        if (version >= 32)
                            w.DownedClown = b.ReadBoolean();
                        if (version >= 37)
                            w.DownedFrost = b.ReadBoolean();
                        if (version >= 56)
                            w.DownedPirates = b.ReadBoolean();

                        w.ShadowOrbSmashed = b.ReadBoolean();
                        w.SpawnMeteor = b.ReadBoolean();
                        w.ShadowOrbCount = (int)b.ReadByte();

                        if (version >= 23)
                        {
                            w.AltarCount = b.ReadInt32();
                            w.HardMode = b.ReadBoolean();
                        }

                        w.InvasionDelay = b.ReadInt32();
                        w.InvasionSize = b.ReadInt32();
                        w.InvasionType = b.ReadInt32();
                        w.InvasionX = b.ReadDouble();

                        if (version >= 53)
                        {
                            w.TempRaining = b.ReadBoolean();
                            w.TempRainTime = b.ReadInt32();
                            w.TempMaxRain = b.ReadSingle();
                        }
                        if (version >= 54)
                        {
                            w.OreTier1 = b.ReadInt32();
                            w.OreTier2 = b.ReadInt32();
                            w.OreTier3 = b.ReadInt32();
                        }
                        else if (version < 23 || w.AltarCount != 0)
                        {
                            w.OreTier1 = 107;
                            w.OreTier2 = 108;
                            w.OreTier3 = 111;
                        }
                        else
                        {
                            w.OreTier1 = -1;
                            w.OreTier2 = -1;
                            w.OreTier3 = -1;
                        }

                        if (version >= 55)
                        {
                            w.BgTree = b.ReadByte();
                            w.BgCorruption = b.ReadByte();
                            w.BgJungle = b.ReadByte();
                        }
                        if (version >= 60)
                        {
                            w.BgSnow = b.ReadByte();
                            w.BgHallow = b.ReadByte();
                            w.BgCorruption = b.ReadByte();
                            w.BgDesert = b.ReadByte();
                            w.BgOcean = b.ReadByte();
                        }

                        if (version >= 60)
                        {
                            w.CloudBgActive = (float)b.ReadInt32();
                        }
                        else
                        {
                            w.CloudBgActive = -w.Rand.Next(8640, 86400);
                        }

                        if (version >= 62)
                        {
                            w.NumClouds = b.ReadInt16();
                            w.WindSpeedSet = b.ReadSingle();
                        }

                        w.Tiles = new Tile[w.TilesWide, w.TilesHigh];
                        for (int i = 0; i < w.TilesWide; i++)
                        {
                            for (int j = 0; j < w.TilesHigh; j++)
                            {
                                w.Tiles[i, j] = new Tile();
                            }
                        }

                        for (int x = 0; x < w.TilesWide; ++x)
                        {
                            OnProgressChanged(null, new ProgressChangedEventArgs(x.ProgressPercentage(w.TilesWide), "Loading Tiles..."));

                            for (int y = 0; y < w.TilesHigh; y++)
                            {
                                var tile = ReadTileDataFromStream(b, version);

                                // read complete, start compression
                                w.Tiles[x, y] = tile;

                                if (version >= 25)
                                {
                                    int rle = b.ReadInt16();

                                    if (rle < 0)
                                        throw new ApplicationException("Invalid Tile Data!");

                                    if (rle > 0)
                                    {
                                        for (int k = y + 1; k < y + rle + 1; k++)
                                        {
                                            var tcopy = (Tile)tile.Clone();
                                            w.Tiles[x, k] = tcopy;
                                        }
                                        y = y + rle;
                                    }
                                }
                            }
                        }

                        if (version < 67)
                            w.FixSunflowers();
                        if (version < 72)
                            w.FixChand();

                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Chests..."));
                        w.Chests.Clear();
                        w.Chests.AddRange(ReadChestDataFromStream(b, version));

                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Signs..."));
                        w.Signs.Clear();

                        foreach (var sign in ReadSignDataFromStream(b))
                        {
                            if (w.Tiles[sign.X, sign.Y].IsActive && ((int)w.Tiles[sign.X, sign.Y].Type == 55 || (int)w.Tiles[sign.X, sign.Y].Type == 85))
                                w.Signs.Add(sign);
                        }

                        w.NPCs.Clear();
                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading NPC Data..."));
                        while (b.ReadBoolean())
                        {
                            var npc = new NPC();
                            npc.Name = b.ReadString();
                            npc.Position = new Vector2(b.ReadSingle(), b.ReadSingle());
                            npc.IsHomeless = b.ReadBoolean();
                            npc.Home = new Vector2Int32(b.ReadInt32(), b.ReadInt32());
                            npc.SpriteId = 0;
                            if (NpcIds.ContainsKey(npc.Name))
                                npc.SpriteId = NpcIds[npc.Name];

                            w.NPCs.Add(npc);
                        }
                        // if (version>=0x1f) read the names of the following npcs:
                        // merchant, nurse, arms dealer, dryad, guide, clothier, demolitionist,
                        // tinkerer and wizard
                        // if (version>=0x23) read the name of the mechanic

                        if (version >= 31)
                        {
                            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading NPC Names..."));
                            w.CharacterNames.Add(new NpcName(17, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(18, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(19, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(20, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(22, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(54, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(38, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(107, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(108, b.ReadString()));
                            if (version >= 35)
                                w.CharacterNames.Add(new NpcName(124, b.ReadString()));
                            else
                                w.CharacterNames.Add(new NpcName(124, "Nancy"));

                            if (version >= 65)
                            {
                                w.CharacterNames.Add(new NpcName(160, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(178, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(207, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(208, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(209, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(227, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(228, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(229, b.ReadString()));
                            }
                            else
                            {
                                w.CharacterNames.Add(GetNewNpc(160));
                                w.CharacterNames.Add(GetNewNpc(178));
                                w.CharacterNames.Add(GetNewNpc(207));
                                w.CharacterNames.Add(GetNewNpc(208));
                                w.CharacterNames.Add(GetNewNpc(209));
                                w.CharacterNames.Add(GetNewNpc(227));
                                w.CharacterNames.Add(GetNewNpc(228));
                                w.CharacterNames.Add(GetNewNpc(229));
                            }
                        }
                        else
                        {
                            w.CharacterNames.Add(GetNewNpc(17));
                            w.CharacterNames.Add(GetNewNpc(18));
                            w.CharacterNames.Add(GetNewNpc(19));
                            w.CharacterNames.Add(GetNewNpc(20));
                            w.CharacterNames.Add(GetNewNpc(22));
                            w.CharacterNames.Add(GetNewNpc(54));
                            w.CharacterNames.Add(GetNewNpc(38));
                            w.CharacterNames.Add(GetNewNpc(107));
                            w.CharacterNames.Add(GetNewNpc(108));
                            w.CharacterNames.Add(GetNewNpc(124));
                            w.CharacterNames.Add(GetNewNpc(160));
                            w.CharacterNames.Add(GetNewNpc(178));
                            w.CharacterNames.Add(GetNewNpc(207));
                            w.CharacterNames.Add(GetNewNpc(208));
                            w.CharacterNames.Add(GetNewNpc(209));
                            w.CharacterNames.Add(GetNewNpc(227));
                            w.CharacterNames.Add(GetNewNpc(228));
                            w.CharacterNames.Add(GetNewNpc(229));

                        }
                        if (version >= 7)
                        {
                            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Validating File..."));
                            bool validation = b.ReadBoolean();
                            string checkTitle = b.ReadString();
                            int checkVersion = b.ReadInt32();
                            if (validation && checkTitle == w.Title && checkVersion == w.WorldId)
                            {
                                //w.loadSuccess = true;
                            }
                            else
                            {
                                b.Close();
                                throw new FileLoadException(string.Format("Error reading world file validation parameters! {0}", filename));
                            }
                        }
                        OnProgressChanged(null, new ProgressChangedEventArgs(0, "World Load Complete."));

                    }
                    w.LastSave = File.GetLastWriteTimeUtc(filename);
                }
            }
            catch (Exception err)
            {
                string msg = "There was an error reading the world file, do you wish to force it to load anyway?\r\n\r\n" +
                             "WARNING: This may have unexpected results including corrupt world files and program crashes.\r\n\r\n" +
                             "The error is :\r\n";
                if (MessageBox.Show(msg + err, "World File Error", MessageBoxButton.YesNo, MessageBoxImage.Error) != MessageBoxResult.Yes)
                    return null;
            }
            return w;
        }
コード例 #25
0
        public static bool LoadSectionHeader(BinaryReader r, out bool[] tileFrameImportant, out int[] sectionPointers, World w)
        {
            tileFrameImportant = null;
            sectionPointers = null;
            int versionNumber = r.ReadInt32();
            if(versionNumber > 140)
            {
                UInt64 versionTypecheck = r.ReadUInt64();
                if (versionTypecheck != 0x026369676f6c6572ul )
                    throw new FileFormatException("Invalid Header");

                w.FileRevision = r.ReadUInt32();
                UInt64 temp = r.ReadUInt64();//I have no idea what this is for...
                w.IsFavorite = ((temp & 1uL) == 1uL);
            }

            // read file section stream positions
            short fileSectionCount = r.ReadInt16();
            sectionPointers = new int[fileSectionCount];
            for (int i = 0; i < fileSectionCount; i++)
            {
                sectionPointers[i] = r.ReadInt32();
            }

            // Read tile frame importance from bit-packed data
            tileFrameImportant = ReadBitArray(r);

            return true;
        }
コード例 #26
0
        public static World LoadWorld(string filename)
        {
            var w = new World();
            try
            {
                lock (_fileLock)
                {
                    using (var b = new BinaryReader(File.OpenRead(filename)))
                    {
                        w.Version = b.ReadUInt32(); //now we care about the version
                        w.Title = b.ReadString();
                        w.WorldId = b.ReadInt32();

                        w.Rand = new Random(w.WorldId);

                        w.LeftWorld = (float)b.ReadInt32();
                        w.RightWorld = (float)b.ReadInt32();
                        w.TopWorld = (float)b.ReadInt32();
                        w.BottomWorld = (float)b.ReadInt32();
                        w.TilesHigh = b.ReadInt32();
                        w.TilesWide = b.ReadInt32();

                        //if (w.TilesHigh > 10000 || w.TilesWide > 10000 || w.TilesHigh <= 0 || w.TilesWide <= 0)
                        //    throw new FileLoadException(string.Format("Invalid File: {0}", filename));

                        if (w.Version >= 63)
                            w.MoonType = (int)b.ReadByte();
                        else
                            w.MoonType = w.Rand.Next(MaxMoons);

                        if (w.Version >= 44)
                        {
                            w.TreeX[0] = b.ReadInt32();
                            w.TreeX[1] = b.ReadInt32();
                            w.TreeX[2] = b.ReadInt32();
                            w.TreeStyle[0] = b.ReadInt32();
                            w.TreeStyle[1] = b.ReadInt32();
                            w.TreeStyle[2] = b.ReadInt32();
                            w.TreeStyle[3] = b.ReadInt32();
                        }
                        if (w.Version >= 60)
                        {
                            w.CaveBackX[0] = b.ReadInt32();
                            w.CaveBackX[1] = b.ReadInt32();
                            w.CaveBackX[2] = b.ReadInt32();
                            w.CaveBackStyle[0] = b.ReadInt32();
                            w.CaveBackStyle[1] = b.ReadInt32();
                            w.CaveBackStyle[2] = b.ReadInt32();
                            w.CaveBackStyle[3] = b.ReadInt32();
                            w.IceBackStyle = b.ReadInt32();
                            if (w.Version >= 61)
                            {
                                w.JungleBackStyle = b.ReadInt32();
                                w.HellBackStyle = b.ReadInt32();
                            }
                        }
                        else
                        {
                            w.CaveBackX[0] = w.TilesWide / 2;
                            w.CaveBackX[1] = w.TilesWide;
                            w.CaveBackX[2] = w.TilesWide;
                            w.CaveBackStyle[0] = 0;
                            w.CaveBackStyle[1] = 1;
                            w.CaveBackStyle[2] = 2;
                            w.CaveBackStyle[3] = 3;
                            w.IceBackStyle = 0;
                            w.JungleBackStyle = 0;
                            w.HellBackStyle = 0;
                        }

                        w.SpawnX = b.ReadInt32();
                        w.SpawnY = b.ReadInt32();
                        w.GroundLevel = (int)b.ReadDouble();
                        w.RockLevel = (int)b.ReadDouble();

                        // read world flags
                        w.Time = b.ReadDouble();
                        w.DayTime = b.ReadBoolean();
                        w.MoonPhase = b.ReadInt32();
                        w.BloodMoon = b.ReadBoolean();

                        if (w.Version >= 70)
                        {
                            w.IsEclipse = b.ReadBoolean();
                        }

                        w.DungeonX = b.ReadInt32();
                        w.DungeonY = b.ReadInt32();

                        if (w.Version >= 56)
                        {
                            w.IsCrimson = b.ReadBoolean();
                        }
                        else
                        {
                            w.IsCrimson = false;
                        }

                        w.DownedBoss1 = b.ReadBoolean();
                        w.DownedBoss2 = b.ReadBoolean();
                        w.DownedBoss3 = b.ReadBoolean();

                        if (w.Version >= 66)
                        {
                            w.DownedQueenBee = b.ReadBoolean();
                        }
                        if (w.Version >= 44)
                        {
                            w.DownedMechBoss1 = b.ReadBoolean();
                            w.DownedMechBoss2 = b.ReadBoolean();
                            w.DownedMechBoss3 = b.ReadBoolean();
                            w.DownedMechBossAny = b.ReadBoolean();
                        }
                        if (w.Version >= 64)
                        {
                            w.DownedPlantBoss = b.ReadBoolean();
                            w.DownedGolemBoss = b.ReadBoolean();
                        }
                        if (w.Version >= 29)
                        {
                            w.SavedGoblin = b.ReadBoolean();
                            w.SavedWizard = b.ReadBoolean();
                            if (w.Version >= 34)
                            {
                                w.SavedMech = b.ReadBoolean();
                            }
                            w.DownedGoblins = b.ReadBoolean();
                        }
                        if (w.Version >= 32)
                            w.DownedClown = b.ReadBoolean();
                        if (w.Version >= 37)
                            w.DownedFrost = b.ReadBoolean();
                        if (w.Version >= 56)
                            w.DownedPirates = b.ReadBoolean();

                        w.ShadowOrbSmashed = b.ReadBoolean();
                        w.SpawnMeteor = b.ReadBoolean();
                        w.ShadowOrbCount = (int)b.ReadByte();

                        if (w.Version >= 23)
                        {
                            w.AltarCount = b.ReadInt32();
                            w.HardMode = b.ReadBoolean();
                        }

                        w.InvasionDelay = b.ReadInt32();
                        w.InvasionSize = b.ReadInt32();
                        w.InvasionType = b.ReadInt32();
                        w.InvasionX = b.ReadDouble();

                        if (w.Version >= 53)
                        {
                            w.TempRaining = b.ReadBoolean();
                            w.TempRainTime = b.ReadInt32();
                            w.TempMaxRain = b.ReadSingle();
                        }
                        if (w.Version >= 54)
                        {
                            w.OreTier1 = b.ReadInt32();
                            w.OreTier2 = b.ReadInt32();
                            w.OreTier3 = b.ReadInt32();
                        }
                        else if (w.Version < 23 || w.AltarCount != 0)
                        {
                            w.OreTier1 = 107;
                            w.OreTier2 = 108;
                            w.OreTier3 = 111;
                        }
                        else
                        {
                            w.OreTier1 = -1;
                            w.OreTier2 = -1;
                            w.OreTier3 = -1;
                        }

                        if (w.Version >= 55)
                        {
                            w.BgTree = b.ReadByte();
                            w.BgCorruption = b.ReadByte();
                            w.BgJungle = b.ReadByte();
                        }
                        if (w.Version >= 60)
                        {
                            w.BgSnow = b.ReadByte();
                            w.BgHallow = b.ReadByte();
                            w.BgCorruption = b.ReadByte();
                            w.BgDesert = b.ReadByte();
                            w.BgOcean = b.ReadByte();
                        }

                        if (w.Version >= 60)
                        {
                            w.CloudBgActive = (float)b.ReadInt32();
                        }
                        else
                        {
                            w.CloudBgActive = -w.Rand.Next(8640, 86400);
                        }

                        if (w.Version >= 62)
                        {
                            w.NumClouds = b.ReadInt16();
                            w.WindSpeedSet = b.ReadSingle();
                        }

                        w.Tiles = new Tile[w.TilesWide, w.TilesHigh];
                        for (int i = 0; i < w.TilesWide; i++)
                        {
                            for (int j = 0; j < w.TilesHigh; j++)
                            {
                                w.Tiles[i, j] = new Tile();
                            }
                        }

                        for (int x = 0; x < w.TilesWide; ++x)
                        {
                            OnProgressChanged(null, new ProgressChangedEventArgs(x.ProgressPercentage(w.TilesWide), "Loading Tiles..."));

                            for (int y = 0; y < w.TilesHigh; y++)
                            {
                                var tile = new Tile();

                                tile.IsActive = b.ReadBoolean();

                                if (!tile.IsActive)
                                    DebugLog(string.Format("Reading Empty Tile [{0},{1}]", x, y));

                                TileProperty tileProperty = null;
                                if (tile.IsActive)
                                {
                                    tile.Type = b.ReadByte();
                                    tileProperty = TileProperties[tile.Type];

                                    DebugLog(string.Format("Reading Tile {2} [{0},{1}] {3}", x, y, tile.Type, tileProperty.IsFramed ? "Framed" : ""));

                                    if (tile.Type == 127)
                                        tile.IsActive = false;

                                    if (tileProperty.IsFramed)
                                    {
                                        if (w.Version < 28 && tile.Type == 4)
                                        {
                                            // torches didn't have extra in older versions.
                                            tile.U = 0;
                                            tile.V = 0;
                                        }
                                        else if (w.Version < 40 && tile.Type == 19)
                                        {
                                            tile.U = 0;
                                            tile.V = 0;
                                        }
                                        else
                                        {
                                            tile.U = b.ReadInt16();
                                            tile.V = b.ReadInt16();

                                            if (tile.Type == 144) //timer
                                                tile.V = 0;
                                        }
                                    }
                                    else
                                    {
                                        tile.U = -1;
                                        tile.V = -1;
                                    }

                                    if (w.Version >= 48 && b.ReadBoolean())
                                    {
                                        tile.Color = b.ReadByte();
                                    }
                                }

                                //skip obsolete hasLight
                                if (w.Version <= 25)
                                    b.ReadBoolean();

                                if (b.ReadBoolean())
                                {
                                    tile.Wall = b.ReadByte();
                                    if (w.Version >= 48 && b.ReadBoolean())
                                        tile.WallColor = b.ReadByte();
                                }

                                if (b.ReadBoolean())
                                {
                                    tile.Liquid = b.ReadByte();
                                    tile.IsLava = b.ReadBoolean();
                                    if (w.Version >= 51)
                                    {
                                        tile.IsHoney = b.ReadBoolean();
                                    }
                                }

                                if (w.Version >= 33)
                                {
                                    tile.HasWire = b.ReadBoolean();
                                }
                                if (w.Version >= 43)
                                {
                                    tile.HasWire2 = b.ReadBoolean();
                                    tile.HasWire3 = b.ReadBoolean();
                                }

                                if (w.Version >= 41)
                                {
                                    tile.HalfBrick = b.ReadBoolean();

                                    if (tileProperty == null || !tileProperty.IsSolid)
                                        tile.HalfBrick = false;

                                    if (w.Version >= 49)
                                    {
                                        tile.Slope = b.ReadByte();

                                        if (tileProperty == null || !tileProperty.IsSolid)
                                            tile.Slope = 0;
                                    }
                                }
                                if (w.Version >= 42)
                                {
                                    tile.Actuator = b.ReadBoolean();
                                    tile.InActive = b.ReadBoolean();
                                }

                                // read complete, start compression
                                w.Tiles[x, y] = tile;

                                if (w.Version >= 25)
                                {
                                    int rle = b.ReadInt16();

                                    if (rle < 0)
                                        throw new ApplicationException("Invalid Tile Data!");

                                    DebugLog(string.Format("RLE {0}", rle));
                                    if (rle > 0)
                                    {
                                        for (int k = y + 1; k < y + rle + 1; k++)
                                        {
                                            var tcopy = (Tile)tile.Clone();
                                            w.Tiles[x, k] = tcopy;
                                        }
                                        y = y + rle;
                                    }
                                }
                            }
                        }

                        if (w.Version < 67)
                            w.FixSunflowers();
                        int chestSize = Chest.MaxItems;
                        if (w.Version < 58)
                            chestSize = 20;
                        w.Chests.Clear();
                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Chests..."));
                        for (int i = 0; i < 1000; i++)
                        {
                            if (b.ReadBoolean())
                            {
                                var chest = new Chest(b.ReadInt32(), b.ReadInt32());
                                for (int slot = 0; slot < Chest.MaxItems; slot++)
                                {
                                    if (slot < chestSize)
                                    {

                                        int stackSize = w.Version < 59 ? b.ReadByte() : (int)b.ReadInt16();
                                        chest.Items[slot].StackSize = stackSize;

                                        if (chest.Items[slot].StackSize > 0)
                                        {
                                            if (w.Version >= 38)
                                                chest.Items[slot].NetId = b.ReadInt32();
                                            else
                                                chest.Items[slot].SetFromName(b.ReadString());

                                            chest.Items[slot].StackSize = stackSize;
                                            // Read prefix
                                            if (w.Version >= 36)
                                                chest.Items[slot].Prefix = b.ReadByte();
                                        }
                                    }
                                }
                                w.Chests.Add(chest);
                            }
                        }
                        w.Signs.Clear();
                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading Signs..."));
                        for (int i = 0; i < 1000; i++)
                        {
                            if (b.ReadBoolean())
                            {
                                Sign sign = new Sign();
                                sign.Text = b.ReadString();
                                sign.X = b.ReadInt32();
                                sign.Y = b.ReadInt32();

                                if (w.Tiles[sign.X, sign.Y].IsActive && (int)w.Tiles[sign.X, sign.Y].Type == 55 && (int)w.Tiles[sign.X, sign.Y].Type == 85)
                                    w.Signs.Add(sign);
                            }
                        }
                        w.NPCs.Clear();
                        OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading NPC Data..."));
                        while (b.ReadBoolean())
                        {
                            var npc = new NPC();
                            npc.Name = b.ReadString();
                            npc.Position = new Vector2(b.ReadSingle(), b.ReadSingle());
                            npc.IsHomeless = b.ReadBoolean();
                            npc.Home = new Vector2Int32(b.ReadInt32(), b.ReadInt32());
                            npc.SpriteId = 0;
                            if (NpcIds.ContainsKey(npc.Name))
                                npc.SpriteId = NpcIds[npc.Name];

                            w.NPCs.Add(npc);
                        }
                        // if (version>=0x1f) read the names of the following npcs:
                        // merchant, nurse, arms dealer, dryad, guide, clothier, demolitionist,
                        // tinkerer and wizard
                        // if (version>=0x23) read the name of the mechanic

                        if (w.Version >= 31)
                        {
                            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Loading NPC Names..."));
                            w.CharacterNames.Add(new NpcName(17, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(18, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(19, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(20, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(22, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(54, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(38, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(107, b.ReadString()));
                            w.CharacterNames.Add(new NpcName(108, b.ReadString()));
                            if (w.Version >= 35)
                                w.CharacterNames.Add(new NpcName(124, b.ReadString()));
                            else
                                w.CharacterNames.Add(new NpcName(124, "Nancy"));

                            if (w.Version >= 65)
                            {
                                w.CharacterNames.Add(new NpcName(160, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(178, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(207, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(208, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(209, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(227, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(228, b.ReadString()));
                                w.CharacterNames.Add(new NpcName(229, b.ReadString()));
                            }
                            else
                            {
                                w.CharacterNames.Add(new NpcName(160, "Truffle"));
                                w.CharacterNames.Add(new NpcName(178, "Steampunker"));
                                w.CharacterNames.Add(new NpcName(207, "Dye Trader"));
                                w.CharacterNames.Add(new NpcName(208, "Party Girl"));
                                w.CharacterNames.Add(new NpcName(209, "Cyborg"));
                                w.CharacterNames.Add(new NpcName(227, "Painter"));
                                w.CharacterNames.Add(new NpcName(228, "Witch Doctor"));
                                w.CharacterNames.Add(new NpcName(229, "Pirate"));
                            }
                        }
                        else
                        {
                            w.CharacterNames.Add(new NpcName(17, "Harold"));
                            w.CharacterNames.Add(new NpcName(18, "Molly"));
                            w.CharacterNames.Add(new NpcName(19, "Dominique"));
                            w.CharacterNames.Add(new NpcName(20, "Felicitae"));
                            w.CharacterNames.Add(new NpcName(22, "Steve"));
                            w.CharacterNames.Add(new NpcName(54, "Fitz"));
                            w.CharacterNames.Add(new NpcName(38, "Gimut"));
                            w.CharacterNames.Add(new NpcName(107, "Knogs"));
                            w.CharacterNames.Add(new NpcName(108, "Fizban"));
                            w.CharacterNames.Add(new NpcName(124, "Nancy"));
                            w.CharacterNames.Add(new NpcName(160, "Truffle"));
                            w.CharacterNames.Add(new NpcName(178, "Steampunker"));
                            w.CharacterNames.Add(new NpcName(207, "Dye Trader"));
                            w.CharacterNames.Add(new NpcName(208, "Party Girl"));
                            w.CharacterNames.Add(new NpcName(209, "Cyborg"));
                            w.CharacterNames.Add(new NpcName(227, "Painter"));
                            w.CharacterNames.Add(new NpcName(228, "Witch Doctor"));
                            w.CharacterNames.Add(new NpcName(229, "Pirate"));

                        }
                        if (w.Version >= 7)
                        {
                            OnProgressChanged(null, new ProgressChangedEventArgs(100, "Validating File..."));
                            bool validation = b.ReadBoolean();
                            string checkTitle = b.ReadString();
                            int checkVersion = b.ReadInt32();
                            if (validation && checkTitle == w.Title && checkVersion == w.WorldId)
                            {
                                //w.loadSuccess = true;
                            }
                            else
                            {
                                b.Close();
                                throw new FileLoadException(string.Format("Error reading world file validation parameters! {0}", filename));
                            }
                        }
                        OnProgressChanged(null, new ProgressChangedEventArgs(0, "World Load Complete."));

                    }
                    w.LastSave = File.GetLastWriteTimeUtc(filename);
                }
            }
            catch (Exception err)
            {
                string msg = "There was an error reading the world file, do you wish to force it to load anyway?\r\n\r\n" +
                             "WARNING: This may have unexpected results including corrupt world files and program crashes.\r\n\r\n" +
                             "The error is :\r\n";
                if (MessageBox.Show(msg + err, "World File Error", MessageBoxButton.YesNo, MessageBoxImage.Error) != MessageBoxResult.Yes)
                    return null;
            }
            return w;
        }
コード例 #27
0
        private static void WriteFlags(StreamWriter sb, World world)
        {
            sb.WriteProperty("world.FileRevision", world.FileRevision);
            sb.WriteProperty("world.IsFavorite", world.IsFavorite);

            sb.WriteLine("===SECTION: Flags===");

            sb.WriteProperty("world.Title", world.Title);
            sb.WriteProperty("world.WorldId", world.WorldId);
            sb.WriteProperty("world.LeftWorld", world.LeftWorld);
            sb.WriteProperty("world.RightWorld", world.RightWorld);
            sb.WriteProperty("world.TopWorld", world.TopWorld);
            sb.WriteProperty("world.BottomWorld", world.BottomWorld);
            sb.WriteProperty("world.TilesHigh", world.TilesHigh);
            sb.WriteProperty("world.TilesWide", world.TilesWide);

            sb.WriteProperty("world.ExpertMode", world.ExpertMode);
            sb.WriteProperty("world.CreationTime", world.CreationTime);

            sb.WriteProperty("world.MoonType", world.MoonType);
            sb.WriteProperty("world.TreeX[0]", world.TreeX0);
            sb.WriteProperty("world.TreeX[1]", world.TreeX1);
            sb.WriteProperty("world.TreeX[2]", world.TreeX2);
            sb.WriteProperty("world.TreeStyle[0]", world.TreeStyle0);
            sb.WriteProperty("world.TreeStyle[1]", world.TreeStyle1);
            sb.WriteProperty("world.TreeStyle[2]", world.TreeStyle2);
            sb.WriteProperty("world.TreeStyle[3]", world.TreeStyle3);
            sb.WriteProperty("world.CaveBackX[0]", world.CaveBackX0);
            sb.WriteProperty("world.CaveBackX[1]", world.CaveBackX1);
            sb.WriteProperty("world.CaveBackX[2]", world.CaveBackX2);
            sb.WriteProperty("world.CaveBackStyle[0]", world.CaveBackStyle0);
            sb.WriteProperty("world.CaveBackStyle[1]", world.CaveBackStyle1);
            sb.WriteProperty("world.CaveBackStyle[2]", world.CaveBackStyle2);
            sb.WriteProperty("world.CaveBackStyle[3]", world.CaveBackStyle3);
            sb.WriteProperty("world.IceBackStyle", world.IceBackStyle);
            sb.WriteProperty("world.JungleBackStyle", world.JungleBackStyle);
            sb.WriteProperty("world.HellBackStyle", world.HellBackStyle);

            sb.WriteProperty("world.SpawnX", world.SpawnX);
            sb.WriteProperty("world.SpawnY", world.SpawnY);
            sb.WriteProperty("world.GroundLevel", world.GroundLevel);
            sb.WriteProperty("world.RockLevel", world.RockLevel);
            sb.WriteProperty("world.Time", world.Time);
            sb.WriteProperty("world.DayTime", world.DayTime);
            sb.WriteProperty("world.MoonPhase", world.MoonPhase);
            sb.WriteProperty("world.BloodMoon", world.BloodMoon);
            sb.WriteProperty("world.IsEclipse", world.IsEclipse);
            sb.WriteProperty("world.DungeonX", world.DungeonX);
            sb.WriteProperty("world.DungeonY", world.DungeonY);

            sb.WriteProperty("world.IsCrimson", world.IsCrimson);

            sb.WriteProperty("world.DownedBoss1", world.DownedBoss1);
            sb.WriteProperty("world.DownedBoss2", world.DownedBoss2);
            sb.WriteProperty("world.DownedBoss3", world.DownedBoss3);
            sb.WriteProperty("world.DownedQueenBee", world.DownedQueenBee);
            sb.WriteProperty("world.DownedMechBoss1", world.DownedMechBoss1);
            sb.WriteProperty("world.DownedMechBoss2", world.DownedMechBoss2);
            sb.WriteProperty("world.DownedMechBoss3", world.DownedMechBoss3);
            sb.WriteProperty("world.DownedMechBossAny", world.DownedMechBossAny);
            sb.WriteProperty("world.DownedPlantBoss", world.DownedPlantBoss);
            sb.WriteProperty("world.DownedGolemBoss", world.DownedGolemBoss);
            sb.WriteProperty("world.DownedSlimeKingBoss", world.DownedSlimeKingBoss);
            sb.WriteProperty("world.SavedGoblin", world.SavedGoblin);
            sb.WriteProperty("world.SavedWizard", world.SavedWizard);
            sb.WriteProperty("world.SavedMech", world.SavedMech);
            sb.WriteProperty("world.DownedGoblins", world.DownedGoblins);
            sb.WriteProperty("world.DownedClown", world.DownedClown);
            sb.WriteProperty("world.DownedFrost", world.DownedFrost);
            sb.WriteProperty("world.DownedPirates", world.DownedPirates);

            sb.WriteProperty("world.ShadowOrbSmashed", world.ShadowOrbSmashed);
            sb.WriteProperty("world.SpawnMeteor", world.SpawnMeteor);
            sb.WriteProperty("world.ShadowOrbCount", world.ShadowOrbCount);
            sb.WriteProperty("world.AltarCount", world.AltarCount);
            sb.WriteProperty("world.HardMode", world.HardMode);
            sb.WriteProperty("world.InvasionDelay", world.InvasionDelay);
            sb.WriteProperty("world.InvasionSize", world.InvasionSize);
            sb.WriteProperty("world.InvasionType", world.InvasionType);
            sb.WriteProperty("world.InvasionX", world.InvasionX);

            sb.WriteProperty("world.TempRaining", world.TempRaining);
            sb.WriteProperty("world.TempRainTime", world.TempRainTime);
            sb.WriteProperty("world.TempMaxRain", world.TempMaxRain);
            sb.WriteProperty("world.OreTier1", world.OreTier1);
            sb.WriteProperty("world.OreTier2", world.OreTier2);
            sb.WriteProperty("world.OreTier3", world.OreTier3);
            sb.WriteProperty("world.BgTree", world.BgTree);
            sb.WriteProperty("world.BgCorruption", world.BgCorruption);
            sb.WriteProperty("world.BgJungle", world.BgJungle);
            sb.WriteProperty("world.BgSnow", world.BgSnow);
            sb.WriteProperty("world.BgHallow", world.BgHallow);
            sb.WriteProperty("world.BgCrimson", world.BgCrimson);
            sb.WriteProperty("world.BgDesert", world.BgDesert);
            sb.WriteProperty("world.BgOcean", world.BgOcean);
            sb.WriteProperty("world.CloudBgActive", world.CloudBgActive);
            sb.WriteProperty("world.NumClouds", world.NumClouds);
            sb.WriteProperty("world.WindSpeedSet", world.WindSpeedSet);
            sb.WriteProperty("world.Anglers.Count", world.Anglers.Count);

            for (int i = 0; i < world.Anglers.Count; i++)
            {
                sb.WriteProperty("Angler " + i, world.Anglers[i]);
            }

            sb.WriteProperty("world.SavedAngler", world.SavedAngler);
            sb.WriteProperty("world.AnglerQuest", world.AnglerQuest);

            if (world.UnknownData != null && world.UnknownData.Length > 0)
                sb.WriteProperty("world.UnknownData", BitConverter.ToString(world.UnknownData));
        }
コード例 #28
0
        public static int SaveFooter(World world, BinaryWriter bw)
        {
            bw.Write(true);
            bw.Write(world.Title);
            bw.Write(world.WorldId);

            return (int)bw.BaseStream.Position;
        }
コード例 #29
0
 private static void WriteHeader(StreamWriter sb, World world)
 {
     sb.WriteLine("===SECTION: Header===");
     sb.WriteProperty("Compatible Version", world.Version);
     sb.WriteProperty("Section Count", World.SectionCount);
     sb.Write("Frames: ");
     foreach (bool t in World.TileFrameImportant)
     {
         sb.Write(t ? 1 : 0);
     }
     sb.Write(Environment.NewLine);
 }
コード例 #30
0
        public static int SaveSectionHeader(World world, BinaryWriter bw)
        {
            bw.Write(Math.Max(CompatibleVersion, world.Version));
            bw.Write((UInt64)0x026369676f6c6572ul);
            bw.Write((int)world.FileRevision+1);
            bw.Write(Convert.ToUInt64(world.IsFavorite));                
            bw.Write(SectionCount);

            // write section pointer placeholders
            for (int i = 0; i < SectionCount; i++)
            {
                bw.Write(0);
            }

            // write bitpacked tile frame importance
            WriteBitArray(bw, TileFrameImportant);

            return (int)bw.BaseStream.Position;
        }
コード例 #31
0
        private static void WriteAnalyzeWorld(StreamWriter sb, World world, bool fullAnalysis = false)
        {
            world.Validate();
            WriteHeader(sb, world);
            WriteFlags(sb, world);

            if (!fullAnalysis) return;

            sb.WriteLine("===SECTION: Tiles===");

            var tileCounts = new Dictionary<int, int>();

            int activeTiles = 0;
            for (int x = 0; x < world.TilesWide; x++)
            {
                for (int y = 0; y < world.TilesHigh; y++)
                {

                    var tile = world.Tiles[x, y];

                    if (tile.IsActive)
                    {
                        if (tileCounts.ContainsKey(tile.Type))
                        {
                            tileCounts[tile.Type] += 1;
                        }
                        else
                        {
                            tileCounts.Add(tile.Type, 1);
                        }
                        activeTiles++;
                    }

                }
            }

            float totalTiles = world.TilesWide * world.TilesHigh;
            int airTiles = (int)(totalTiles - activeTiles);
            sb.WriteLine("Air: {0} ({1:P2})", airTiles, airTiles / totalTiles);

            var tiles = tileCounts.OrderByDescending(kvp => kvp.Value);
            foreach (var tilePair in tiles)
            {
                string name = tilePair.Key.ToString();
                if (World.TileProperties.Count >= tilePair.Key)
                {
                    var prop = World.TileProperties[tilePair.Key];
                    if (prop != null)
                    {
                        name = prop.Name;
                    }
                }

                sb.WriteLine("{0}: {1} ({2:P2})", name, tilePair.Value, tilePair.Value / totalTiles);
            }

            sb.WriteLine("===SECTION: Chests===");
            sb.WriteProperty("Chest Count", world.Chests.Count);
            sb.WriteProperty("Chest Max Items", Chest.MaxItems);

            foreach (var chest in world.Chests)
            {
                sb.Write("[{0}, {1}] {2} - Contents: ", chest.X, chest.Y, chest.Name);

                for (int i = 0; i < Chest.MaxItems; i++)
                {
                    Item item = chest.Items[i];
                    if (item == null)
                        sb.Write("[{0}]: Empty,", i.ToString());
                    else
                    {
                        sb.Write("[{0}]: {1} - {2}{3},", i.ToString(), item.StackSize, item.PrefixName, item.Name);
                    }
                }

                sb.WriteLine();
            }

            sb.WriteLine("===SECTION: Signs===");
            sb.WriteProperty("Sign Count", world.Signs.Count);

            foreach (var sign in world.Signs)
            {
                sb.Write("[{0}, {1}] {2}\r\n", sign.X, sign.Y, sign.Text);
            }

            sb.WriteLine("===SECTION: NPCs===");
            sb.WriteProperty("NPC Count", world.NPCs.Count);
            foreach (var npc in world.NPCs)
            {
                sb.Write("ID: {0}, Name: {1}, Position: [{2:0.00}, {3:0.00}], {4}: [{5}, {6}]\r\n", npc.Name, npc.DisplayName, npc.Position.X, npc.Position.Y, npc.IsHomeless ? "Homeless" : "Home", npc.Home.X, npc.Home.Y);
            }

            sb.WriteLine("===SECTION: Tile Entities===");
            sb.WriteProperty("Tile Entities Count", world.TileEntities.Count);
            foreach (var entity in world.TileEntities)
            {
                switch (entity.Type)
                {
                    case 0:
                        sb.Write("Dummy - ID: {0}, Position: [{1}, {2}], NPC: {3}\r\n", entity.Id, entity.PosX, entity.PosY, entity.Npc);
                        break;
                    case 1:
                        sb.Write("ItemFrame - ID: {0}, Position: [{1}, {2}], ItemID: {3}, Prefix: {4}, Stack: {5}\r\n", entity.Id, entity.PosX, entity.PosY, entity.NetId, entity.Prefix, entity.StackSize);
                        break;
                    case 2:
                        sb.Write("Logic Sensor - ID: {0}, Position: [{1}, {2}], LogicCheck: {3}, On: {4}\r\n", entity.Id, entity.PosX, entity.PosY, entity.LogicCheck, entity.On);
                        break;
                }
            }
        }
コード例 #32
0
        public static int SaveHeaderFlags(World world, BinaryWriter bw)
        {
            bw.Write(world.Title);
            bw.Write(world.WorldId);
            bw.Write((int)world.LeftWorld);
            bw.Write((int)world.RightWorld);
            bw.Write((int)world.TopWorld);
            bw.Write((int)world.BottomWorld);
            bw.Write(world.TilesHigh);
            bw.Write(world.TilesWide);
            bw.Write(world.ExpertMode);
            bw.Write(world.CreationTime);
            bw.Write((byte)world.MoonType);
            bw.Write(world.TreeX0);
            bw.Write(world.TreeX1);
            bw.Write(world.TreeX2);
            bw.Write(world.TreeStyle0);
            bw.Write(world.TreeStyle1);
            bw.Write(world.TreeStyle2);
            bw.Write(world.TreeStyle3);
            bw.Write(world.CaveBackX0);
            bw.Write(world.CaveBackX1);
            bw.Write(world.CaveBackX2);
            bw.Write(world.CaveBackStyle0);
            bw.Write(world.CaveBackStyle1);
            bw.Write(world.CaveBackStyle2);
            bw.Write(world.CaveBackStyle3);
            bw.Write(world.IceBackStyle);
            bw.Write(world.JungleBackStyle);
            bw.Write(world.HellBackStyle);
            bw.Write(world.SpawnX);
            bw.Write(world.SpawnY);
            bw.Write(world.GroundLevel);
            bw.Write(world.RockLevel);
            bw.Write(world.Time);
            bw.Write(world.DayTime);
            bw.Write(world.MoonPhase);
            bw.Write(world.BloodMoon);
            bw.Write(world.IsEclipse);
            bw.Write(world.DungeonX);
            bw.Write(world.DungeonY);
            bw.Write(world.IsCrimson);
            bw.Write(world.DownedBoss1);
            bw.Write(world.DownedBoss2);
            bw.Write(world.DownedBoss3);
            bw.Write(world.DownedQueenBee);
            bw.Write(world.DownedMechBoss1);
            bw.Write(world.DownedMechBoss2);
            bw.Write(world.DownedMechBoss3);
            bw.Write(world.DownedMechBossAny);
            bw.Write(world.DownedPlantBoss);
            bw.Write(world.DownedGolemBoss);
            bw.Write(world.DownedSlimeKingBoss);
            bw.Write(world.SavedGoblin);
            bw.Write(world.SavedWizard);
            bw.Write(world.SavedMech);
            bw.Write(world.DownedGoblins);
            bw.Write(world.DownedClown);
            bw.Write(world.DownedFrost);
            bw.Write(world.DownedPirates);
            bw.Write(world.ShadowOrbSmashed);
            bw.Write(world.SpawnMeteor);
            bw.Write((byte)world.ShadowOrbCount);
            bw.Write(world.AltarCount);
            bw.Write(world.HardMode);
            bw.Write(world.InvasionDelay);
            bw.Write(world.InvasionSize);
            bw.Write(world.InvasionType);
            bw.Write(world.InvasionX);
            bw.Write(world.SlimeRainTime);
            bw.Write((byte)world.SundialCooldown);
            bw.Write(world.TempRaining);
            bw.Write(world.TempRainTime);
            bw.Write(world.TempMaxRain);
            bw.Write(world.OreTier1);
            bw.Write(world.OreTier2);
            bw.Write(world.OreTier3);
            bw.Write(world.BgTree);
            bw.Write(world.BgCorruption);
            bw.Write(world.BgJungle);
            bw.Write(world.BgSnow);
            bw.Write(world.BgHallow);
            bw.Write(world.BgCrimson);
            bw.Write(world.BgDesert);
            bw.Write(world.BgOcean);
            bw.Write((int)world.CloudBgActive);
            bw.Write(world.NumClouds);
            bw.Write(world.WindSpeedSet);
            bw.Write(world.Anglers.Count);
            foreach (string angler in world.Anglers)
            {
                bw.Write(angler);
            }
            bw.Write(world.SavedAngler);
            bw.Write(world.AnglerQuest);
            bw.Write(world.SavedStylist);
            bw.Write(world.SavedTaxCollector);
            bw.Write(world.InvasionSizeStart);
            bw.Write(world.CultistDelay);
            bw.Write((Int16)world.NumberOfMobs);
            foreach (int count in world.KilledMobs)
            {
                bw.Write(count);
            }
            bw.Write(world.FastForwardTime);
            bw.Write(world.DownedFishron);
            bw.Write(world.DownedMartians);
            bw.Write(world.DownedLunaticCultist);
            bw.Write(world.DownedMoonlord);
            bw.Write(world.DownedHalloweeenKing);
            bw.Write(world.DownedHalloweenTree);
            bw.Write(world.DownedChristmasQueen);
            bw.Write(world.DownedSanta);
            bw.Write(world.DownedChristmasTree);
            bw.Write(world.DownedCelestialSolar);
            bw.Write(world.DownedCelestialVortex);
            bw.Write(world.DownedCelestialNebula);
            bw.Write(world.DownedCelestialStardust);
            bw.Write(world.CelestialSolarActive);
            bw.Write(world.CelestialVortexActive);
            bw.Write(world.CelestialNebulaActive);
            bw.Write(world.CelestialStardustActive);
            bw.Write(world.Apocalypse);

            if (world.UnknownData != null && world.UnknownData.Length > 0)
                bw.Write(world.UnknownData);

            return (int)bw.BaseStream.Position;
        }
コード例 #33
0
        public static void Save(World world, string filename, bool resetTime = false)
        {
            lock (_fileLock)
            {
                OnProgressChanged(world, new ProgressChangedEventArgs(0, "Validating World..."));
                world.Validate();

                if (resetTime)
                {
                    OnProgressChanged(world, new ProgressChangedEventArgs(0, "Resetting Time..."));
                    world.ResetTime();
                }

                if (filename == null)
                    return;

                string temp = filename + ".tmp";
                using (var fs = new FileStream(temp, FileMode.Create))
                {
                    using (var bw = new BinaryWriter(fs))
                    {
                        if (CompatibleVersion > 87)
                            SaveV2(world, bw);
                        else
                            SaveV1(world, bw);

                        bw.Close();
                        fs.Close();

                        // make a backup of current file if it exists
                        if (File.Exists(filename))
                        {
                            string backup = filename + ".TEdit";
                            File.Copy(filename, backup, true);
                        }
                        // replace actual file with temp save file
                        File.Copy(temp, filename, true);
                        // delete temp save file
                        File.Delete(temp);
                        OnProgressChanged(null, new ProgressChangedEventArgs(0, "World Save Complete."));
                    }
                }

                world._lastSave = File.GetLastWriteTimeUtc(filename);
            }
        }
コード例 #34
0
        public static int SaveTileEntities(World w, BinaryWriter bw)
        {
            bw.Write(w.TileEntitiesNumber);

            foreach(TileEntity tentity in w.TileEntities)
            {
                bw.Write(tentity.Type);
                bw.Write(tentity.Id);
                bw.Write(tentity.PosX);
                bw.Write(tentity.PosY);
                switch (tentity.Type)
                {
                    case 0: //it is a dummy                        
                        bw.Write(tentity.Npc);
                        break;
                    case 1: //it is a item frame                        
                        bw.Write(tentity.ItemNetId);
                        bw.Write(tentity.Prefix);
                        bw.Write(tentity.Stack);
                        break;
                }
            }

            return (int)bw.BaseStream.Position;
        }