private void FinishCreatingWorld() { ProcessSeed(out var processedSeed); switch (_optionSize) { case WorldSizeId.Small: Main.maxTilesX = 4200; Main.maxTilesY = 1200; break; case WorldSizeId.Medium: Main.maxTilesX = 6400; Main.maxTilesY = 1800; break; case WorldSizeId.Large: Main.maxTilesX = 8400; Main.maxTilesY = 2400; break; } WorldGen.setWorldSize(); switch (_optionDifficulty) { case WorldDifficultyId.Creative: Main.GameMode = 3; break; case WorldDifficultyId.Normal: Main.GameMode = 0; break; case WorldDifficultyId.Expert: Main.GameMode = 1; break; case WorldDifficultyId.Master: Main.GameMode = 2; break; } switch (_optionEvil) { case WorldEvilId.Random: WorldGen.WorldGenParam_Evil = -1; break; case WorldEvilId.Corruption: WorldGen.WorldGenParam_Evil = 0; break; case WorldEvilId.Crimson: WorldGen.WorldGenParam_Evil = 1; break; } Main.ActiveWorldFileData = WorldFile.CreateMetadata(Main.worldName = _optionwWorldName.Trim(), SocialAPI.Cloud != null && SocialAPI.Cloud.EnabledByDefault, Main.GameMode); if (processedSeed.Length == 0) { Main.ActiveWorldFileData.SetSeedToRandom(); } else { Main.ActiveWorldFileData.SetSeed(processedSeed); } Main.menuMode = 10; WorldGen.CreateNewWorld(); }
private static void LoadWorldDirect(bool loadFromCloud) { WorldFile.IsWorldOnCloud = loadFromCloud; Main.checkXMas(); Main.checkHalloween(); bool flag = loadFromCloud && SocialAPI.Cloud != null; if (!FileUtilities.Exists(Main.worldPathName, flag) && Main.autoGen) { if (!flag) { for (int i = Main.worldPathName.Length - 1; i >= 0; i--) { if (Main.worldPathName.Substring(i, 1) == (Path.DirectorySeparatorChar.ToString() ?? "")) { Directory.CreateDirectory(Main.worldPathName.Substring(0, i)); break; } } } WorldGen.clearWorld(); Main.ActiveWorldFileData = WorldFile.CreateMetadata((Main.worldName == "") ? "World" : Main.worldName, flag, Main.expertMode); string text = (Main.AutogenSeedName ?? "").Trim(); if (text.Length == 0) { Main.ActiveWorldFileData.SetSeedToRandom(); } else { Main.ActiveWorldFileData.SetSeed(text); } WorldGen.generateWorld(Main.ActiveWorldFileData.Seed, Main.AutogenProgress); WorldFile.saveWorld(); } using (MemoryStream memoryStream = new MemoryStream(FileUtilities.ReadAllBytes(Main.worldPathName, flag))) { using (BinaryReader binaryReader = new BinaryReader(memoryStream)) { try { WorldGen.loadFailed = false; WorldGen.loadSuccess = false; int num = WorldFile.versionNumber = binaryReader.ReadInt32(); int num2; if (num <= 87) { // Not supported num2 = WorldFile.LoadWorld_Version1(binaryReader); } else { num2 = LoadWorld_Version2(binaryReader); } if (num < 141) { if (!loadFromCloud) { Main.ActiveWorldFileData.CreationTime = File.GetCreationTime(Main.worldPathName); } else { Main.ActiveWorldFileData.CreationTime = DateTime.Now; } } binaryReader.Close(); memoryStream.Close(); if (num2 != 0) { WorldGen.loadFailed = true; } else { WorldGen.loadSuccess = true; } if (WorldGen.loadFailed || !WorldGen.loadSuccess) { return; } WorldGen.gen = true; WorldGen.waterLine = Main.maxTilesY; Liquid.QuickWater(2, -1, -1); WorldGen.WaterCheck(); int num3 = 0; Liquid.quickSettle = true; int num4 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer; float num5 = 0f; while (Liquid.numLiquid > 0 && num3 < 100000) { num3++; float num6 = (float)(num4 - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num4; if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > num4) { num4 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer; } if (num6 > num5) { num5 = num6; } else { num6 = num5; } SetStatusText(string.Concat(new object[] { Lang.gen[27].Value, " ", (int)(num6 * 100f / 2f + 50f), "%" })); Liquid.UpdateLiquid(); } Liquid.quickSettle = false; Main.weatherCounter = WorldGen.genRand.Next(3600, 18000); Cloud.resetClouds(); WorldGen.WaterCheck(); WorldGen.gen = false; NPC.setFireFlyChance(); Main.InitLifeBytes(); if (Main.slimeRainTime > 0.0) { Main.StartSlimeRain(false); } NPC.setWorldMonsters(); } catch (Exception value) { WorldGen.loadFailed = true; WorldGen.loadSuccess = false; System.Console.WriteLine(value); try { binaryReader.Close(); memoryStream.Close(); } catch { } return; } } } EventInfo eventOnWorldLoad = typeof(WorldFile).GetEvent("OnWorldLoad", BindingFlags.Public | BindingFlags.Static); eventOnWorldLoad.GetRaiseMethod()?.Invoke(null, new object[] { }); //if (WorldFile.OnWorldLoad != null) //WorldFile.OnWorldLoad(); }