public override void Execute() { string clipboardPath = Tools.GetClipboardPath(plr.User.Name); using (var reader = new BinaryReader(new GZipStream(new FileStream(clipboardPath, FileMode.Open), CompressionMode.Decompress))) { reader.ReadInt32(); reader.ReadInt32(); int width = reader.ReadInt32() - 1; int height = reader.ReadInt32() - 1; int ignore = 0; if (alignment == 9) { ignore = alignment; alignment = 0; } if ((alignment & 1) == 0) x2 = x + width; else { x2 = x; x -= width; } if ((alignment & 2) == 0) y2 = y + height; else { y2 = y; y -= height; } Tools.PrepareUndo(x, y, x2, y2, plr); 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 && (expression == null || expression.Evaluate(Main.tile[i, j]))) { if (TShock.Regions.InAreaRegion(i, j).Any(r => r != null && r.Z > 99) && ignore != 9) { continue; } else { Main.tile[i, j] = tile; // Paste Tiles } } } } } ResetSection(); plr.SendSuccessMessage("Pasted clipboard to selection."); }
public override void Execute() { string clipboardPath = Tools.GetClipboardPath(plr.UserAccountName); using (var reader = new BinaryReader(new GZipStream(new FileStream(clipboardPath, FileMode.Open), CompressionMode.Decompress))) { reader.ReadInt32(); reader.ReadInt32(); int width = reader.ReadInt32() - 1; int height = reader.ReadInt32() - 1; if ((alignment & 1) == 0) x2 = x + width; else { x2 = x; x -= width; } if ((alignment & 2) == 0) y2 = y + height; else { y2 = y; y -= height; } Tools.PrepareUndo(x, y, x2, y2, plr); 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 && conditions.TrueForAll(c => c(i, j))) Main.tile[i, j] = tile; } } } ResetSection(); plr.SendSuccessMessage("Pasted clipboard to selection."); }
public static void RegenerateWorld(string path) { Task.Factory.StartNew(() => { using (var reader = new BinaryReader(new GZipStream(new FileStream(path, FileMode.Open), CompressionMode.Decompress))) { #region Reset Specific WorldGen Data WorldGen.oreTier1 = -1; WorldGen.oreTier2 = -1; WorldGen.oreTier3 = -1; #endregion Main.worldSurface = reader.ReadDouble(); Main.rockLayer = reader.ReadDouble(); Main.dungeonX = reader.ReadInt32(); Main.dungeonY = reader.ReadInt32(); WorldGen.crimson = reader.ReadBoolean(); 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 > 99)) { continue; } else { Main.tile[i, j] = tile; } } } } ResetSection(x, y, x2, y2); #region Chest Data int totalChests = reader.ReadInt32(); int chests = 0; int index = 0; if (!WorldRegeneration.Config.IgnoreChests) { for (int a = 0; a < totalChests; a++) { 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 > 99)) { break; } else if (Main.chest[c] != null && TShock.Regions.InAreaRegion(Main.chest[c].x, Main.chest[c].y).Any(r => r != null && r.Z > 99)) { 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 > 99)) { break; } else if (Main.sign[s] != null && TShock.Regions.InAreaRegion(Main.sign[s].x, Main.sign[s].y).Any(r => r != null && r.Z > 99)) { 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 if (WorldRegeneration.Config.UseInfiniteChests) { TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/convchests"); System.Threading.Thread.Sleep(10000); TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/prunechests"); } } }); }
public static void LoadWorldSection(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(); 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 > 99)) { continue; } else { Main.tile[i, j] = tile; // Paste Tiles } } } } ResetSection(x, y, x2, y2); TSPlayer.All.SendInfoMessage("Tile Data Loaded..."); #region Chest Data int totalChests = reader.ReadInt32(); int chests = 0; int index = 0; if (!WorldRegeneration.Config.IgnoreChests) { for (int a = 0; a < totalChests; a++) { 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 > 99)) { break; } else if (Main.chest[c] != null && TShock.Regions.InAreaRegion(Main.chest[c].x, Main.chest[c].y).Any(r => r != null && r.Z > 99)) { 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 > 99)) { break; } else if (Main.sign[s] != null && TShock.Regions.InAreaRegion(Main.sign[s].x, Main.sign[s].y).Any(r => r != null && r.Z > 99)) { 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); if (WorldRegeneration.Config.UseInfiniteChests) { TSPlayer.All.SendInfoMessage("Using InfiniteChests Commands..."); TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/convchests"); System.Threading.Thread.Sleep(10000); TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/prunechests,"); } TSPlayer.All.SendInfoMessage("Successfully regenerated the world."); #endregion } }); }
public static void LoadWorldSection(string path) { // GZipStream is already buffered, but it's much faster to have a 1 MB buffer. using (var reader = new BinaryReader( new BufferedStream( new GZipStream(File.Open(path, FileMode.Open), CompressionMode.Decompress), BUFFER_SIZE))) { int x = reader.ReadInt32(); int y = reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); for (int i = x; i < x + width; i++) { for (int j = y; j < y + height; j++) { Main.tile[i, j] = reader.ReadTile(); Main.tile[i, j].skipLiquid(true); } ResetSection(x, y, x + width, y + height); } } }