예제 #1
0
 static void WriteInfChests(this BinaryWriter writer, InfiniteChests.Chest chest)
 {
     writer.Write(chest.Location.X);
     writer.Write(chest.Location.Y);
     writer.Write(chest.Account);
     writer.Write(chest.Items);
     writer.Write((int)chest.Flags);
     writer.Write(chest.BankID);
     writer.Write(chest.RefillTime);
 }
예제 #2
0
        public static void RegenerateWorld(string path)
        {
            Task.Factory.StartNew(() =>
            {
                using (var reader = new BinaryReader(new GZipStream(new FileStream(path, FileMode.Open), CompressionMode.Decompress)))
                {
                    Main.worldSurface = reader.ReadDouble();
                    Main.rockLayer    = reader.ReadDouble();
                    Main.dungeonX     = reader.ReadInt32();
                    Main.dungeonY     = reader.ReadInt32();
                    WorldGen.crimson  = reader.ReadBoolean();

                    WorldGen.SavedOreTiers.Copper = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Silver = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Iron   = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Gold   = reader.ReadInt32();

                    WorldGen.SavedOreTiers.Cobalt     = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Mythril    = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Adamantite = reader.ReadInt32();

                    reader.ReadInt32();
                    reader.ReadInt32();

                    int x = 0;
                    int y = 0;

                    int x2 = reader.ReadInt32();
                    int y2 = reader.ReadInt32();

                    for (int i = x; i <= x2; i++)
                    {
                        for (int j = y; j <= y2; j++)
                        {
                            Tile tile = reader.ReadTile();
                            if (i >= 0 && j >= 0 && i < Main.maxTilesX && j < Main.maxTilesY)
                            {
                                if (TShock.Regions.InAreaRegion(i, j).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                                {
                                    continue;
                                }
                                else
                                {
                                    Main.tile[i, j] = tile;
                                }
                            }
                        }
                    }
                    ResetSection(x, y, x2, y2);

                    #region Chest Data
                    int iccount = 0;
                    InfiniteChests.Chest[] ic = new InfiniteChests.Chest[0];
                    if (WorldRegeneration.Config.UseInfiniteChests)
                    {
                        iccount = reader.ReadInt32();
                        ic      = new InfiniteChests.Chest[iccount];
                        for (int i = 0; i < iccount; i++)
                        {
                            ic[i] = reader.ReadInfChests();
                        }
                    }
                    int totalChests = reader.ReadInt32();
                    int chests      = 0;
                    int index       = 0;
                    if (!WorldRegeneration.Config.IgnoreChests)
                    {
                        for (int a = 0; a < (WorldRegeneration.Config.UseInfiniteChests ? iccount : totalChests); a++)
                        {
                            if (WorldRegeneration.Config.UseInfiniteChests)
                            {
                                Point location = ic[a].Location;
                                if (!TShock.Regions.InAreaRegion(location.X, location.Y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                                {
                                    if (InfiniteChests.InfiniteChests.IsNull(location.X, location.Y))
                                    {
                                        InfiniteChests.InfiniteChests.InsertInfChest(ic[a]);
                                    }
                                    else
                                    {
                                        InfiniteChests.InfiniteChests.UpdateInfChest(ic[a]);
                                    }
                                }
                            }
                            else
                            {
                                Chest chest = reader.ReadChest();
                                for (int c = index; c < 1000; c++)
                                {
                                    if (TShock.Regions.InAreaRegion(chest.x, chest.y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                                    {
                                        break;
                                    }
                                    else if (Main.chest[c] != null && TShock.Regions.InAreaRegion(Main.chest[c].x, Main.chest[c].y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                                    {
                                        index++;
                                        continue;
                                    }
                                    else
                                    {
                                        Main.chest[c] = chest;
                                        index++;
                                        chests++;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int a = 0; a < totalChests; a++)
                        {
                            reader.ReadChest();
                        }
                    }
                    #endregion

                    #region Sign Data
                    int totalSigns = reader.ReadInt32();
                    int signs      = 0;
                    index          = 0;
                    for (int a = 0; a < totalSigns; a++)
                    {
                        Sign sign = reader.ReadSign();
                        for (int s = index; s < 1000; s++)
                        {
                            if (TShock.Regions.InAreaRegion(sign.x, sign.y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                            {
                                break;
                            }
                            else if (Main.sign[s] != null && TShock.Regions.InAreaRegion(Main.sign[s].x, Main.sign[s].y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                            {
                                index++;
                                continue;
                            }
                            else
                            {
                                Main.sign[s] = sign;
                                index++;
                                signs++;
                                break;
                            }
                        }
                    }
                    #endregion

                    #region Tile Entitity Data
                    int totalTileEntities = reader.ReadInt32();

                    for (int i = 0; i < totalTileEntities; i++)
                    {
                        TileEntity tileEntity = TileEntity.Read(reader);
                        for (int j = 0; j < 1000; j++)
                        {
                            TileEntity entityUsed;
                            if (TileEntity.ByID.TryGetValue(j, out entityUsed))
                            {
                                if (entityUsed.Position == tileEntity.Position)
                                {
                                    break;
                                }
                                continue;
                            }
                            else
                            {
                                tileEntity.ID = j;
                                TileEntity.ByID[tileEntity.ID]             = tileEntity;
                                TileEntity.ByPosition[tileEntity.Position] = tileEntity;
                                break;
                            }
                        }
                    }
                    #endregion

                    TSPlayer.All.SendMessage(string.Format("The world has regenerated..."), 50, 255, 130);

                    #region WorldGen Reset Data
                    if (WorldRegeneration.Config.ResetWorldGenStatus)
                    {
                        Main.hardMode               = false;
                        NPC.downedBoss1             = false;
                        NPC.downedBoss2             = false;
                        NPC.downedBoss3             = false;
                        NPC.downedQueenBee          = false;
                        NPC.downedSlimeKing         = false;
                        NPC.downedMechBossAny       = false;
                        NPC.downedMechBoss1         = false;
                        NPC.downedMechBoss2         = false;
                        NPC.downedMechBoss3         = false;
                        NPC.downedFishron           = false;
                        NPC.downedMartians          = false;
                        NPC.downedAncientCultist    = false;
                        NPC.downedMoonlord          = false;
                        NPC.downedHalloweenKing     = false;
                        NPC.downedHalloweenTree     = false;
                        NPC.downedChristmasIceQueen = false;
                        NPC.downedChristmasSantank  = false;
                        NPC.downedChristmasTree     = false;
                        NPC.downedPlantBoss         = false;
                        NPC.savedStylist            = false;
                        NPC.savedGoblin             = false;
                        NPC.savedWizard             = false;
                        NPC.savedMech               = false;
                        NPC.downedGoblins           = false;
                        NPC.downedClown             = false;
                        NPC.downedFrost             = false;
                        NPC.downedPirates           = false;
                        NPC.savedAngler             = false;
                        NPC.downedMartians          = false;
                        NPC.downedGolemBoss         = false;
                        NPC.savedTaxCollector       = false;
                        WorldGen.shadowOrbSmashed   = false;
                        WorldGen.altarCount         = 0;
                        WorldGen.shadowOrbCount     = 0;
                    }
                    #endregion
                }
            });
        }
예제 #3
0
        public static void LoadWorldSection(string path, Rectangle rect, bool useRect = false)
        {
            Task.Factory.StartNew(() =>
            {
                using (var reader = new BinaryReader(new GZipStream(new FileStream(path, FileMode.Open), CompressionMode.Decompress)))
                {
                    Main.worldSurface = reader.ReadDouble();
                    Main.rockLayer    = reader.ReadDouble();
                    Main.dungeonX     = reader.ReadInt32();
                    Main.dungeonY     = reader.ReadInt32();
                    WorldGen.crimson  = reader.ReadBoolean();

                    WorldGen.SavedOreTiers.Copper = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Silver = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Iron   = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Gold   = reader.ReadInt32();

                    WorldGen.SavedOreTiers.Cobalt     = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Mythril    = reader.ReadInt32();
                    WorldGen.SavedOreTiers.Adamantite = reader.ReadInt32();

                    reader.ReadInt32();
                    reader.ReadInt32();

                    int x = 0;
                    int y = 0;

                    int x2 = reader.ReadInt32();
                    int y2 = reader.ReadInt32();

                    for (int i = x; i <= x2; i++)
                    {
                        for (int j = y; j <= y2; j++)
                        {
                            Tile tile = reader.ReadTile();
                            if (i >= 0 && j >= 0 && i < Main.maxTilesX && j < Main.maxTilesY)
                            {
                                if (TShock.Regions.InAreaRegion(i, j).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                                {
                                    continue;
                                }
                                else if (useRect)
                                {
                                    if (rect.Contains(i, j))
                                    {
                                        Main.tile[i, j] = tile;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    Main.tile[i, j] = tile; // Paste Tiles
                                }
                            }
                        }
                    }
                    ResetSection(x, y, x2, y2);
                    TSPlayer.All.SendInfoMessage("Tile Data Loaded...");

                    if (useRect)
                    {
                        return;
                    }

                    #region Chest Data
                    int iccount = 0;
                    InfiniteChests.Chest[] ic = new InfiniteChests.Chest[0];
                    if (WorldRegeneration.Config.UseInfiniteChests)
                    {
                        iccount = reader.ReadInt32();
                        ic      = new InfiniteChests.Chest[iccount];
                        for (int i = 0; i < iccount; i++)
                        {
                            ic[i] = reader.ReadInfChests();
                        }
                    }
                    int totalChests = reader.ReadInt32();
                    int chests      = 0;
                    int index       = 0;
                    if (!WorldRegeneration.Config.IgnoreChests)
                    {
                        for (int a = 0; a < (WorldRegeneration.Config.UseInfiniteChests ? iccount : totalChests); a++)
                        {
                            if (WorldRegeneration.Config.UseInfiniteChests)
                            {
                                Point location = ic[a].Location;
                                if (!TShock.Regions.InAreaRegion(location.X, location.Y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                                {
                                    if (InfiniteChests.InfiniteChests.IsNull(location.X, location.Y))
                                    {
                                        InfiniteChests.InfiniteChests.InsertInfChest(ic[a]);
                                    }
                                    else
                                    {
                                        InfiniteChests.InfiniteChests.UpdateInfChest(ic[a]);
                                    }
                                }
                            }
                            else
                            {
                                Chest chest = reader.ReadChest();
                                for (int c = index; c < 1000; c++)
                                {
                                    if (TShock.Regions.InAreaRegion(chest.x, chest.y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                                    {
                                        break;
                                    }
                                    else if (Main.chest[c] != null && TShock.Regions.InAreaRegion(Main.chest[c].x, Main.chest[c].y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                                    {
                                        index++;
                                        continue;
                                    }
                                    else
                                    {
                                        Main.chest[c] = chest;
                                        index++;
                                        chests++;
                                        break;
                                    }
                                }
                            }
                        }
                        TSPlayer.All.SendInfoMessage("{0} of {1} Chest Data Loaded...", chests, totalChests);
                    }
                    else
                    {
                        for (int a = 0; a < totalChests; a++)
                        {
                            reader.ReadChest();
                        }
                        TSPlayer.All.SendInfoMessage("{0} Chest Data Ignored...", totalChests);
                    }
                    #endregion

                    #region Sign Data
                    int totalSigns = reader.ReadInt32();
                    int signs      = 0;
                    index          = 0;
                    for (int a = 0; a < totalSigns; a++)
                    {
                        Sign sign = reader.ReadSign();
                        for (int s = index; s < 1000; s++)
                        {
                            if (TShock.Regions.InAreaRegion(sign.x, sign.y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                            {
                                break;
                            }
                            else if (Main.sign[s] != null && TShock.Regions.InAreaRegion(Main.sign[s].x, Main.sign[s].y).Any(r => r != null && r.Z >= WorldRegeneration.Config.MaxZRegion))
                            {
                                index++;
                                continue;
                            }
                            else
                            {
                                Main.sign[s] = sign;
                                index++;
                                signs++;
                                break;
                            }
                        }
                    }
                    TSPlayer.All.SendInfoMessage("{0} of {1} Signs Data Loaded...", signs, totalSigns);
                    #endregion

                    #region Tile Entitity Data
                    int totalTileEntities = reader.ReadInt32();
                    int num1 = 0;
                    for (int i = 0; i < totalTileEntities; i++)
                    {
                        TileEntity tileEntity = TileEntity.Read(reader);
                        for (int j = 0; j < 1000; j++)
                        {
                            TileEntity entityUsed;
                            if (TileEntity.ByID.TryGetValue(j, out entityUsed))
                            {
                                if (entityUsed.Position == tileEntity.Position)
                                {
                                    break;
                                }
                                continue;
                            }
                            else
                            {
                                tileEntity.ID = j;
                                TileEntity.ByID[tileEntity.ID]             = tileEntity;
                                TileEntity.ByPosition[tileEntity.Position] = tileEntity;
                                TileEntity.TileEntitiesNextID = j++;
                                num1++;
                                break;
                            }
                        }
                    }
                    TSPlayer.All.SendInfoMessage("{0} of {1} Tile Entity Data Loaded...", num1, totalTileEntities);
                    TSPlayer.All.SendInfoMessage("Successfully regenerated the world.");

                    #endregion
                }
            });
        }