Decompiled source of Expand World Size v1.45.0

ExpandWorldSize.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Common;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using ServerSync;
using Service;
using TMPro;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ExpandWorldSize")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+eae35267d46d08775cfd822d6e21fee5f68fbb7d")]
[assembly: AssemblyProduct("ExpandWorldSize")]
[assembly: AssemblyTitle("ExpandWorldSize")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Service
{
	public class ConfigWrapper(ConfigFile configFile, ConfigSync configSync)
	{
		private readonly ConfigFile ConfigFile = configFile;

		private readonly ConfigSync ConfigSync = configSync;

		public static Dictionary<ConfigEntry<string>, float> Floats = new Dictionary<ConfigEntry<string>, float>();

		public static Dictionary<ConfigEntry<string>, float?> NullFloats = new Dictionary<ConfigEntry<string>, float?>();

		public static Dictionary<ConfigEntry<string>, int> Ints = new Dictionary<ConfigEntry<string>, int>();

		public static readonly List<ConfigEntryBase> Entries = new List<ConfigEntryBase>();

		public ConfigEntry<string> BindFloat(string group, string name, float value, Regen regenerate, string description = "", bool synchronizedSetting = true)
		{
			ConfigEntry<string> entry = Bind(group, name, value.ToString(CultureInfo.InvariantCulture), Regen.None, description, synchronizedSetting);
			entry.SettingChanged += delegate
			{
				Floats[entry] = TryParseFloat(entry).GetValueOrDefault(value);
			};
			Floats[entry] = TryParseFloat(entry).GetValueOrDefault(value);
			AddRegenerate<string>(entry, regenerate);
			return entry;
		}

		public ConfigEntry<string> BindFloat(string group, string name, float? value, Regen regenerate, string description = "", bool synchronizedSetting = true)
		{
			ConfigEntry<string> entry = Bind(group, name, value.HasValue ? value.Value.ToString(CultureInfo.InvariantCulture) : "", Regen.None, description, synchronizedSetting);
			entry.SettingChanged += delegate
			{
				NullFloats[entry] = TryParseFloat(entry);
			};
			NullFloats[entry] = TryParseFloat(entry);
			AddRegenerate<string>(entry, regenerate);
			return entry;
		}

		public ConfigEntry<T> Bind<T>(string group, string name, T value, Regen regenerate, ConfigDescription description, bool synchronizedSetting = true)
		{
			ConfigEntry<T> val = configFile.Bind<T>(group, name, value, description);
			Entries.Add((ConfigEntryBase)(object)val);
			AddRegenerate<T>(val, regenerate);
			configSync.AddConfigEntry<T>(val).SynchronizedConfig = synchronizedSetting;
			return val;
		}

		public ConfigEntry<T> Bind<T>(string group, string name, T value, Regen regenerate, string description = "", bool synchronizedSetting = true)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			return Bind(group, name, value, regenerate, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		private static void AddRegenerate<T>(ConfigEntry<T> entry, Regen regenerate)
		{
			if (regenerate != Regen.None)
			{
				entry.SettingChanged += delegate
				{
					Refresh.Request(regenerate);
				};
			}
		}

		private static float? TryParseFloat(string value)
		{
			if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				return result;
			}
			return null;
		}

		private static float? TryParseFloat(ConfigEntry<string> setting)
		{
			if (float.TryParse(setting.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				return result;
			}
			return TryParseFloat((string)((ConfigEntryBase)setting).DefaultValue);
		}
	}
	public class Log
	{
		private static ManualLogSource Logger;

		public static void Init(ManualLogSource logger)
		{
			Logger = logger;
		}

		public static void Error(string message)
		{
			Logger.LogError((object)message);
		}

		public static void Warning(string message)
		{
			Logger.LogWarning((object)message);
		}

		public static void Info(string message)
		{
			Logger.LogInfo((object)message);
		}

		public static void Debug(string message)
		{
			Logger.LogDebug((object)message);
		}
	}
}
namespace ExpandWorldSize
{
	public class BetterContinents
	{
		public const string GUID = "BetterContinents";

		private static Assembly? Assembly;

		private static FieldInfo? SettingsField;

		private static FieldInfo? IsEnabledField;

		private static MethodInfo? SetSizeMethod;

		private static FieldInfo? WorldSizeField;

		private static FieldInfo? EdgeSizeField;

		private static MethodInfo? SetStretchMethod;

		public static void Run()
		{
			if (!Chainloader.PluginInfos.TryGetValue("BetterContinents", out var value))
			{
				return;
			}
			Assembly = ((object)value.Instance).GetType().Assembly;
			Type type = Assembly.GetType("BetterContinents.BetterContinents");
			if (type == null)
			{
				return;
			}
			SettingsField = AccessTools.Field(type, "Settings");
			if (SettingsField == null)
			{
				return;
			}
			type = Assembly.GetType("BetterContinents.BetterContinents+BetterContinentsSettings");
			IsEnabledField = AccessTools.Field(type, "EnabledForThisWorld");
			if (IsEnabledField == null)
			{
				return;
			}
			type = Assembly.GetType("BetterContinents.BetterContinents");
			if (type == null)
			{
				return;
			}
			SetSizeMethod = AccessTools.Method(type, "SetSize", (Type[])null, (Type[])null);
			Type type2 = Assembly.GetType("BetterContinents.WorldSizeHelper");
			if (type2 != null)
			{
				SetStretchMethod = AccessTools.Method(type2, "SetStretch", (Type[])null, (Type[])null);
			}
			if (SetSizeMethod != null)
			{
				Log.Info("\"Better Continents\" detected. Applying compatibility.");
				return;
			}
			WorldSizeField = AccessTools.Field(type, "WorldSize");
			EdgeSizeField = AccessTools.Field(type, "EdgeSize");
			if (EdgeSizeField != null && SetSizeMethod != null)
			{
				Log.Info("Older \"Better Continents\" detected. Applying compatibility.");
			}
		}

		public static bool IsEnabled()
		{
			if (SettingsField == null)
			{
				return false;
			}
			if (IsEnabledField == null)
			{
				return false;
			}
			object value = SettingsField.GetValue(null);
			if (value == null)
			{
				return false;
			}
			return (bool)IsEnabledField.GetValue(value);
		}

		public static void RefreshSize()
		{
			SetSizeMethod?.Invoke(null, new object[2]
			{
				Configuration.WorldRadius,
				Configuration.WorldEdgeSize
			});
			WorldSizeField?.SetValue(null, Configuration.WorldTotalRadius);
			EdgeSizeField?.SetValue(null, Configuration.WorldEdgeSize);
			SetStretchMethod?.Invoke(null, new object[2]
			{
				Configuration.WorldStretch,
				Configuration.BiomeStretch
			});
		}
	}
	public class EWD
	{
		public const string GUID = "expand_world_data";

		public static bool IsPresent;

		private static Assembly? Assembly;

		private static MethodInfo? SetSize;

		private static MethodInfo? MethodGetMinimapHeight;

		public static void Run()
		{
			if (Chainloader.PluginInfos.TryGetValue("expand_world_data", out var value))
			{
				Assembly = ((object)value.Instance).GetType().Assembly;
				AccessSetSize(Assembly);
				AccessGetMinimapHeight(Assembly);
				Refresh.Forward(Assembly);
				Log.Info("\"Expand World Data\" detected. Applying compatibility.");
				IsPresent = true;
			}
		}

		private static void AccessSetSize(Assembly assembly)
		{
			Type type = assembly.GetType("ExpandWorldData.WorldInfo");
			if (!(type == null))
			{
				SetSize = AccessTools.Method(type, "Set", (Type[])null, (Type[])null);
			}
		}

		private static void AccessGetMinimapHeight(Assembly assembly)
		{
			Type type = assembly.GetType("ExpandWorldData.Api");
			if (!(type == null))
			{
				MethodGetMinimapHeight = AccessTools.Method(type, "GetMinimapHeight", (Type[])null, (Type[])null);
			}
		}

		public static void RefreshSize()
		{
			if (!(SetSize == null))
			{
				SetSize.Invoke(null, new object[4]
				{
					Configuration.WorldRadius,
					Configuration.WorldTotalRadius,
					Configuration.WorldStretch,
					Configuration.BiomeStretch
				});
			}
		}

		public static float GetMinimapHeight(float height, Biome biome)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (MethodGetMinimapHeight == null)
			{
				return height;
			}
			return (float)MethodGetMinimapHeight.Invoke(null, new object[2] { height, biome });
		}
	}
	public class LPACompatibility
	{
		public const string GUID = "nickpappas.locationplacementaccelerator";

		private static bool _checked;

		private static bool _present;

		public static bool IsEnabled()
		{
			if (!_checked)
			{
				_checked = true;
				_present = Chainloader.PluginInfos.ContainsKey("nickpappas.locationplacementaccelerator");
			}
			return _present;
		}
	}
	public class Marketplace
	{
		public const string GUID = "MarketplaceAndServerNPCs";

		private static Assembly? MarketplaceAssembly;

		private static FieldInfo? IsLoadingField;

		public static void Run()
		{
			if (!Chainloader.PluginInfos.TryGetValue("MarketplaceAndServerNPCs", out var value))
			{
				return;
			}
			MarketplaceAssembly = ((object)value.Instance).GetType().Assembly;
			Type type = MarketplaceAssembly.GetType("API.ClientSide");
			if (!(type == null))
			{
				IsLoadingField = AccessTools.Field(type, "FillingTerritoryData");
				if (!(IsLoadingField == null))
				{
					Log.Info("\"Marketplace\" detected. Applying compatibility.");
				}
			}
		}

		public static bool IsLoading()
		{
			if (IsLoadingField == null)
			{
				return false;
			}
			return (bool)IsLoadingField.GetValue(null);
		}
	}
	public class VPO
	{
		public const string GUID = "dev.ontrigger.vpo";

		public static void Run()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("dev.ontrigger.vpo", out var value))
			{
				return;
			}
			Type type = ((object)value.Instance).GetType().Assembly.GetType("ValheimPerformanceOptimizations.Patches.Water.VPOWaterVolumeManager");
			MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "TryScheduleFloaterUpdates", (Type[])null, (Type[])null));
			if (methodInfo == null)
			{
				Log.Warning("\"Valheim Performance Optimizations\" detected but floater update method not found. Water edge may not scale.");
				return;
			}
			Log.Info("\"Valheim Performance Optimizations\" detected. Applying compatibility.");
			try
			{
				Patcher.Harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(VPO), "Transpiler", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				Log.Warning("Failed to apply VPO compatibility: " + ex.Message);
			}
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)10500f, (string)null)
			}).ThrowIfInvalid("Failed to find 10500f in VPO floater update.").SetInstruction(new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(Configuration), "WorldTotalRadius")))
				.InstructionEnumeration();
		}
	}
	public class WorldInfo
	{
		private sealed record OriginalSeed(string Name, int Seed);

		public static float WaterLevel = 30f;

		public static float BaseWaterLevel = Helper.HeightToBaseHeight(WaterLevel);

		public static float WorldStretch = 1f;

		public static float BiomeStretch = 1f;

		public static float WaterDepth = 1f;

		public static float AltitudeMultiplier = 1f;

		public static float BaseAltitudeDelta = 0f;

		public static float ForestMultiplier = 1f;

		private static readonly ConditionalWeakTable<World, OriginalSeed> OriginalSeeds = new ConditionalWeakTable<World, OriginalSeed>();

		public static void SetWaterLevel(float waterLevel)
		{
			if (WaterLevel != waterLevel)
			{
				WaterLevel = waterLevel;
				BaseWaterLevel = Helper.HeightToBaseHeight(WaterLevel);
			}
		}

		public static void StoreSeed(World world)
		{
			if (!world.m_menu)
			{
				OriginalSeeds.AddOrUpdate(world, new OriginalSeed(world.m_seedName, world.m_seed));
				if (Configuration.Seed != "")
				{
					ApplySeed(world, Configuration.Seed, StringExtensionMethods.GetStableHashCode(Configuration.Seed));
				}
			}
		}

		private static void ApplySeed(World world, string name, int seed)
		{
			world.m_seedName = name;
			world.m_seed = seed;
		}

		public static void RefreshSeed()
		{
			WorldGenerator instance = WorldGenerator.instance;
			if (instance == null)
			{
				return;
			}
			World world = instance.m_world;
			if (world.m_menu)
			{
				return;
			}
			if (Configuration.Seed != "")
			{
				ApplySeed(world, Configuration.Seed, StringExtensionMethods.GetStableHashCode(Configuration.Seed));
			}
			else
			{
				if (!OriginalSeeds.TryGetValue(world, out OriginalSeed value))
				{
					return;
				}
				ApplySeed(world, value.Name, value.Seed);
			}
			world.m_menu = true;
			try
			{
				WorldGenerator.Initialize(world);
			}
			finally
			{
				world.m_menu = false;
			}
		}

		public static void Patch()
		{
			WorldStretch = Configuration.WorldStretch;
			BiomeStretch = Configuration.BiomeStretch;
			WaterDepth = Configuration.WaterDepthMultiplier;
			AltitudeMultiplier = Configuration.AltitudeMultiplier;
			ForestMultiplier = ((Configuration.ForestMultiplier == 0f) ? 1f : Configuration.ForestMultiplier);
			BaseAltitudeDelta = Helper.HeightToBaseHeight(Configuration.AltitudeDelta);
			if (Patcher.WG != null)
			{
				Patcher.WG.maxMarshDistance = VersionSetup.MaxMarshDistance * Configuration.WorldRadius / 10000f / Configuration.WorldStretch;
			}
			EWD.RefreshSize();
			BetterContinents.RefreshSize();
			WorldSizeHelper.GrowBiomeData();
			Patcher.Patch();
		}
	}
	[HarmonyPatch(typeof(WorldGenerator), "VersionSetup")]
	public class VersionSetup
	{
		public static float MaxMarshDistance = 6000f;

		private static void Prefix(WorldGenerator __instance)
		{
			__instance.maxMarshDistance = 6000f;
		}

		private static void Postfix(WorldGenerator __instance)
		{
			MaxMarshDistance = __instance.maxMarshDistance;
		}
	}
	[HarmonyPatch(typeof(World), "LoadWorld")]
	public class LoadWorld
	{
		private static World Postfix(World result)
		{
			WorldInfo.StoreSeed(result);
			return result;
		}
	}
	public class Configuration
	{
		public static ConfigEntry<string> configWorldRadius;

		public static ConfigEntry<string> configWorldEdgeSize;

		public static ConfigEntry<int> configSaveGridSize;

		public static ConfigEntry<string> configMapSize;

		public static ConfigEntry<string> configMapPixelSize;

		public static ConfigEntry<string> configAltitudeMultiplier;

		public static ConfigEntry<string> configAltitudeDelta;

		public static ConfigEntry<string> configLocationsMultiplier;

		public static ConfigEntry<string> configForestMultiplier;

		public static ConfigEntry<string> configWorldStretch;

		public static ConfigEntry<string> configBiomeStretch;

		public static ConfigEntry<string> configSeed;

		public static ConfigEntry<string> configOffsetX;

		public static ConfigEntry<string> configOffsetY;

		public static ConfigEntry<string> configHeightSeed;

		public static ConfigEntry<string> configWaterDepthMultiplier;

		public static ConfigEntry<string> configAshlandsWidthRestriction;

		public static ConfigEntry<string> configAshlandsLengthRestriction;

		public static ConfigEntry<bool> configRestrictAshlands;

		public static ConfigEntry<bool> configAshlandsGap;

		public static ConfigEntry<bool> configDeepNorthGap;

		public static ConfigEntry<bool> configFixWaterColor;

		public static ConfigEntry<bool> configRemoveAshlandsWater;

		public static float WorldRadius => ConfigWrapper.Floats[configWorldRadius];

		public static float StrechedWorldRadius => WorldRadius / WorldStretch;

		public static float WorldEdgeSize => ConfigWrapper.Floats[configWorldEdgeSize];

		public static float WorldTotalRadius => WorldRadius + WorldEdgeSize;

		public static float StrechedWorldTotalRadius => WorldTotalRadius / WorldStretch;

		public static int SaveGridSize => configSaveGridSize.Value;

		public static float MapSize => ConfigWrapper.Floats[configMapSize];

		public static float MapPixelSize => ConfigWrapper.Floats[configMapPixelSize];

		public static float AltitudeMultiplier => ConfigWrapper.Floats[configAltitudeMultiplier];

		public static float AltitudeDelta => ConfigWrapper.Floats[configAltitudeDelta];

		public static float LocationsMultiplier => ConfigWrapper.Floats[configLocationsMultiplier];

		public static float ForestMultiplier => ConfigWrapper.Floats[configForestMultiplier];

		public static float WorldStretch => ConfigWrapper.Floats[configWorldStretch];

		public static float BiomeStretch => ConfigWrapper.Floats[configBiomeStretch];

		public static string Seed => configSeed.Value;

		public static float? OffsetX => ConfigWrapper.NullFloats[configOffsetX];

		public static float? OffsetY => ConfigWrapper.NullFloats[configOffsetY];

		public static float? HeightSeed => ConfigWrapper.NullFloats[configHeightSeed];

		public static float WaterDepthMultiplier => ConfigWrapper.Floats[configWaterDepthMultiplier];

		public static double AshlandsWidthRestriction
		{
			get
			{
				if (!RestrictAshlands)
				{
					return double.PositiveInfinity;
				}
				return ConfigWrapper.Floats[configAshlandsWidthRestriction];
			}
		}

		public static double AshlandsLengthRestriction
		{
			get
			{
				if (!RestrictAshlands)
				{
					return double.PositiveInfinity;
				}
				return ConfigWrapper.Floats[configAshlandsLengthRestriction];
			}
		}

		public static bool RestrictAshlands => configRestrictAshlands.Value;

		public static bool AshlandsGap => configAshlandsGap.Value;

		public static bool DeepNorthGap => configDeepNorthGap.Value;

		public static bool FixWaterColor => configFixWaterColor.Value;

		public static bool RemoveAshlandsWater => configRemoveAshlandsWater.Value;

		public static void Init(ConfigWrapper wrapper)
		{
			string text = "1. General";
			configWorldRadius = wrapper.BindFloat(text, "World radius", 10000f, Regen.World | Regen.ZoneGrid, "Radius of the world in meters (excluding the edge).");
			configWorldEdgeSize = wrapper.BindFloat(text, "World edge size", 500f, Regen.World | Regen.ZoneGrid, "Size of the edge area in meters (added to the radius for the total size).");
			configSaveGridSize = wrapper.Bind(text, "Save system size", 0, Regen.World | Regen.ZoneGrid, "Size of the save system grid. When zero, automatically calculated from the world size.");
			configMapSize = wrapper.BindFloat(text, "Minimap size", 1f, Regen.Minimap, "Increases the minimap size, but also significantly increases the generation time.");
			configMapPixelSize = wrapper.BindFloat(text, "Minimap pixel size", 0f, Regen.Minimap, "Decreases the minimap detail, but doesn't affect the generation time. Automatically calculated when zero.");
			configWorldStretch = wrapper.BindFloat(text, "Stretch world", 1f, Regen.World, "Stretches the world to a bigger area.");
			configBiomeStretch = wrapper.BindFloat(text, "Stretch biomes", 1f, Regen.World, "Stretches the biomes to a bigger area.");
			configForestMultiplier = wrapper.BindFloat(text, "Forest multiplier", 1f, Regen.World, "Multiplies the amount of forest.");
			configAltitudeMultiplier = wrapper.BindFloat(text, "Altitude multiplier", 1f, Regen.World, "Multiplies the altitude.");
			configAltitudeDelta = wrapper.BindFloat(text, "Altitude delta", 0f, Regen.World, "Adds to the altitude.");
			configWaterDepthMultiplier = wrapper.BindFloat(text, "Water depth multiplier", 1f, Regen.World, "Multplies the water depth.");
			configLocationsMultiplier = wrapper.BindFloat(text, "Locations", 1f, Regen.World, "Multiplies the max amount of locations.");
			configOffsetX = wrapper.BindFloat(text, "Offset X", null, Regen.World);
			configOffsetY = wrapper.BindFloat(text, "Offset Y", null, Regen.World);
			configSeed = wrapper.Bind(text, "Seed", "", Regen.World | Regen.Seed);
			configHeightSeed = wrapper.BindFloat(text, "Height variation seed", null, Regen.World);
			text = "2. Poles";
			configRestrictAshlands = wrapper.Bind(text, "Restrict Ashlands position", value: true, Regen.World, "If true, restricts Ashlands biome position.");
			configAshlandsWidthRestriction = wrapper.BindFloat(text, "Ashlands width restriction", 7500f, Regen.World, "How wide is the Ashlands biome (meters).");
			configAshlandsLengthRestriction = wrapper.BindFloat(text, "Ashlands length restriction", 1000f, Regen.World, "How long/deep is the Ashlands biome (meters).");
			configAshlandsGap = wrapper.Bind(text, "Ashlands gap", value: true, Regen.World, "If true, Ashlands biome has an Ocean gap above it.");
			configDeepNorthGap = wrapper.Bind(text, "Deep North gap", value: true, Regen.World, "If true, Deep North biome has an Ocean gap below it.");
			configRemoveAshlandsWater = wrapper.Bind(text, "Remove Ashlands water", value: false, Regen.Water, "If true, the red water color is completely removed.");
			configFixWaterColor = wrapper.Bind(text, "Fix water color", value: true, Regen.Water, "If true, fixes the water color to match the current biome.");
			WaterColor.Refresh();
		}
	}
	[HarmonyPatch]
	public static class Patcher
	{
		public static WorldGenerator? WG;

		public static Harmony Harmony;

		private const HarmonyPatchType Prefix = (HarmonyPatchType)1;

		private const HarmonyPatchType Postfix = (HarmonyPatchType)2;

		private const HarmonyPatchType Transpiler = (HarmonyPatchType)3;

		private const HarmonyPatchType Finalizer = (HarmonyPatchType)4;

		private static readonly Type[] GetBiomeArgs = new Type[4]
		{
			typeof(float),
			typeof(float),
			typeof(float),
			typeof(bool)
		};

		private static readonly Type[] GetBiomeSectorArgs = new Type[3]
		{
			typeof(int),
			typeof(int),
			typeof(bool)
		};

		private static readonly Type[] GenerateLocationsArgs = new Type[3]
		{
			typeof(ZoneLocation),
			typeof(Stopwatch),
			typeof(ZPackage)
		};

		public static bool IsMenu
		{
			get
			{
				if (WG != null)
				{
					return WG.m_world.m_menu;
				}
				return true;
			}
		}

		public static void Init(Harmony harmony)
		{
			Harmony = harmony;
			Harmony.PatchAll();
			Patch();
		}

		private static void Apply(bool shouldPatch, Type type, string name, Type patchType, string patchName, HarmonyPatchType kind, object? state = null, Type[]? args = null, bool enumerator = false)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Patches.Apply(Harmony, shouldPatch, type, name, patchType, patchName, kind, null, args, enumerator, state);
		}

		public static void Patch()
		{
			bool isMenu = IsMenu;
			bool bc = BetterContinents.IsEnabled();
			float worldRadius = Configuration.WorldRadius;
			float worldTotalRadius = Configuration.WorldTotalRadius;
			float worldStretch = Configuration.WorldStretch;
			float biomeStretch = Configuration.BiomeStretch;
			float strechedWorldRadius = Configuration.StrechedWorldRadius;
			float strechedWorldTotalRadius = Configuration.StrechedWorldTotalRadius;
			int biomeMapSize = WorldSizeHelper.BiomeMapSize;
			bool radiusChanged = worldRadius != 10000f;
			bool flag = worldTotalRadius != 10500f;
			bool biomeMapChanged = biomeMapSize != 2048 || worldStretch != 1f || flag;
			Stretch.UpdateAshlandsLimits(isMenu);
			PatchWorldStretch(isMenu, worldStretch, biomeStretch, strechedWorldRadius);
			PatchHeights(isMenu, bc, worldRadius, worldTotalRadius, worldStretch, strechedWorldRadius, strechedWorldTotalRadius);
			PatchPoles(isMenu, strechedWorldRadius);
			PatchWorldSize(bc, worldRadius, worldTotalRadius, worldStretch, biomeMapSize, biomeMapChanged, flag);
			PatchRivers(isMenu, worldRadius, worldStretch, radiusChanged);
			PatchLocations(worldRadius, radiusChanged);
		}

		public static void PatchZoneGrid(int width)
		{
			ZoneGrid.Patch(Harmony, width);
		}

		[HarmonyPatch(typeof(WorldGenerator), "VersionSetup")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void PatchOnLoad(WorldGenerator __instance)
		{
			WG = __instance;
			WorldInfo.Patch();
		}

		private static void PatchWorldStretch(bool menu, float stretch, float biomeStretch, float stretchedRadius)
		{
			bool shouldPatch = !menu && stretch != 1f;
			bool shouldPatch2 = !menu && (biomeStretch != 1f || stretchedRadius != 10000f);
			Apply(shouldPatch, typeof(WorldGenerator), "GetBiomeHeight", typeof(Stretch), "GetBiomeHeight", (HarmonyPatchType)1);
			Apply(shouldPatch, typeof(WorldGenerator), "GetAshlandsOceanGradient", typeof(Stretch), "StretchVector3", (HarmonyPatchType)1, null, new Type[1] { typeof(Vector3) });
			Apply(shouldPatch, typeof(Minimap), "GetMaskColor", typeof(Stretch), "GetMaskColor", (HarmonyPatchType)1);
			Apply(shouldPatch, typeof(WorldGenerator), "GetBiome", typeof(Stretch), "GetBiome", (HarmonyPatchType)1, null, GetBiomeArgs);
			Apply(shouldPatch2, typeof(WorldGenerator), "GetBiome", typeof(Stretch), "Transpiler", (HarmonyPatchType)3, (biomeStretch, stretchedRadius), GetBiomeArgs);
			Apply(shouldPatch, typeof(WorldGenerator), "AddRivers", typeof(AddRivers), "Prefix", (HarmonyPatchType)1);
			Apply(shouldPatch, typeof(AltBiomeWorldData), "GenerateAltBiomes", typeof(Stretch), "PrefixGenerateAltBiomes", (HarmonyPatchType)1);
			Apply(shouldPatch, typeof(AltBiomeWorldData), "GenerateAltBiomes", typeof(Stretch), "FinalizerGenerateAltBiomes", (HarmonyPatchType)4);
			Apply(shouldPatch, typeof(Character), "UpdateLava", typeof(Stretch), "StretchIsAshlandsTranspiler", (HarmonyPatchType)3, stretch);
			Apply(shouldPatch, typeof(EnvMan), "GetBiome", typeof(Stretch), "StretchIsAshlandsDeepNorthTranspiler", (HarmonyPatchType)3, stretch);
			Apply(shouldPatch, typeof(EnvMan), "UpdateEnvironment", typeof(Stretch), "StretchIsAshlandsDeepNorthTranspiler", (HarmonyPatchType)3, stretch);
		}

		private static void PatchHeights(bool menu, bool bc, float radius, float total, float stretch, float stretchedRadius, float stretchedTotal)
		{
			float? heightSeed = Configuration.HeightSeed;
			bool shouldPatch = !menu && heightSeed.HasValue;
			float? offsetX = Configuration.OffsetX;
			float? offsetY = Configuration.OffsetY;
			bool flag = offsetX.HasValue || offsetY.HasValue || stretchedRadius != 10000f || stretchedTotal != 10500f || (total - 10f) / stretch != 10490f;
			float num = (menu ? 1f : WorldInfo.WaterDepth);
			float num2 = (menu ? 0f : WorldInfo.BaseAltitudeDelta);
			float num3 = (menu ? 1f : WorldInfo.AltitudeMultiplier);
			float num4 = (menu ? 1f : WorldInfo.ForestMultiplier);
			Apply(!menu && !bc && stretchedTotal != 10500f, typeof(WorldGenerator), "GetBiomeHeight", typeof(Stretch), "TranspilerGetBiomeHeight", (HarmonyPatchType)3, (total, stretch));
			Apply(num != 1f, typeof(WorldGenerator), "GetBiomeHeight", typeof(BiomeHeight), "Postfix", (HarmonyPatchType)2);
			Apply(!menu && !bc && flag, typeof(WorldGenerator), "GetBaseHeight", typeof(GetBaseHeight), "Transpiler", (HarmonyPatchType)3, (offsetX, offsetY, radius, total, stretch));
			Apply(num2 != 0f || num3 != 1f, typeof(WorldGenerator), "GetBaseHeight", typeof(BaseHeight), "Postfix", (HarmonyPatchType)2);
			Apply(num4 != 1f, typeof(WorldGenerator), "GetForestFactor", typeof(Forest), "Postfix", (HarmonyPatchType)2);
			Apply(shouldPatch, typeof(WorldGenerator), "GetAshlandsHeight", typeof(HeightSeed), "Ashlands", (HarmonyPatchType)3, heightSeed);
			Apply(shouldPatch, typeof(WorldGenerator), "GetForestHeight", typeof(HeightSeed), "Forest", (HarmonyPatchType)3, heightSeed);
			Apply(shouldPatch, typeof(WorldGenerator), "GetMeadowsHeight", typeof(HeightSeed), "Meadows", (HarmonyPatchType)3, heightSeed);
			Apply(shouldPatch, typeof(WorldGenerator), "GetDeepNorthHeight", typeof(HeightSeed), "DeepNorth", (HarmonyPatchType)3, heightSeed);
			Apply(shouldPatch, typeof(WorldGenerator), "GetPlainsHeight", typeof(HeightSeed), "Plains", (HarmonyPatchType)3, heightSeed);
			Apply(shouldPatch, typeof(WorldGenerator), "GetSnowMountainHeight", typeof(HeightSeed), "Mountain", (HarmonyPatchType)3, heightSeed);
			Apply(shouldPatch, typeof(WorldGenerator), "GetMistlandsHeight", typeof(HeightSeed), "Mistlands", (HarmonyPatchType)3, heightSeed);
			Apply(!menu && !bc && (total + 150f) / stretch != 10150f, typeof(WorldGenerator), "GetAshlandsHeight", typeof(GetAshlandsHeightSize), "Transpiler", (HarmonyPatchType)3, (total, stretch));
		}

		private static void PatchPoles(bool menu, float stretchedRadius)
		{
			double ashlandsWidthRestriction = Configuration.AshlandsWidthRestriction;
			double ashlandsLengthRestriction = Configuration.AshlandsLengthRestriction;
			bool shouldPatch = !menu && stretchedRadius != 10000f;
			Apply(ashlandsWidthRestriction != GetAshlandsHeight.DefaultWidthRestriction || ashlandsLengthRestriction != GetAshlandsHeight.DefaultLengthRestriction, typeof(WorldGenerator), "GetAshlandsHeight", typeof(GetAshlandsHeight), "Transpiler", (HarmonyPatchType)3, (ashlandsWidthRestriction, ashlandsLengthRestriction));
			Apply(shouldPatch, typeof(WorldGenerator), "IsDeepnorth", typeof(Stretch), "TranspilerIsDeepnorth", (HarmonyPatchType)3, stretchedRadius);
			Apply(shouldPatch, typeof(WorldGenerator), "CreateAshlandsGap", typeof(Stretch), "TranspilerCreateAshlandsGap", (HarmonyPatchType)3, stretchedRadius);
			Apply(shouldPatch, typeof(WorldGenerator), "CreateDeepNorthGap", typeof(Stretch), "TranspilerCreateDeepNorthGap", (HarmonyPatchType)3, stretchedRadius);
			Apply(!Configuration.AshlandsGap, typeof(WorldGenerator), "CreateAshlandsGap", typeof(Poles), "DisableGap", (HarmonyPatchType)1);
			Apply(!Configuration.DeepNorthGap, typeof(WorldGenerator), "CreateDeepNorthGap", typeof(Poles), "DisableGap", (HarmonyPatchType)1);
		}

		private static void PatchWorldSize(bool bc, float radius, float total, float stretch, int biomeMapSize, bool biomeMapChanged, bool totalChanged)
		{
			(int, float) tuple = (biomeMapSize, stretch);
			Apply(biomeMapChanged, typeof(AltBiomeWorldData), "MapSpaceToWorldSpace", typeof(MapSpaceToWorldSpaceSize), "Transpiler", (HarmonyPatchType)3, tuple, new Type[1] { typeof(float) });
			Apply(biomeMapChanged, typeof(AltBiomeWorldData), "WorldSpaceToMapSpace", typeof(WorldSpaceToMapSpaceSize), "Transpiler", (HarmonyPatchType)3, tuple, new Type[1] { typeof(float) });
			Apply(biomeMapChanged, typeof(AltBiomeWorldData), "GenerateBiomePoints", typeof(GenerateBiomePointsSize), "Transpiler", (HarmonyPatchType)3, (biomeMapSize, total));
			Apply(!bc && biomeMapSize != 2048, typeof(WorldGenerator), "GetBiomeSector", typeof(GetBiomeSectorSize), "Transpiler", (HarmonyPatchType)3, biomeMapSize, GetBiomeSectorArgs);
			bool shouldPatch = !bc && totalChanged;
			Apply(shouldPatch, typeof(Ship), "ApplyEdgeForce", typeof(WorldSizeHelper), "EdgeCheck", (HarmonyPatchType)3, total);
			Apply(shouldPatch, typeof(Player), "EdgeOfWorldKill", typeof(WorldSizeHelper), "EdgeCheck", (HarmonyPatchType)3, total);
			Apply(shouldPatch, typeof(WaterVolume), "GetWaterSurface", typeof(GetWaterSurface), "Transpiler", (HarmonyPatchType)3, total);
			Apply(!bc, typeof(EnvMan), "UpdateWind", typeof(UpdateWind), "Transpiler", (HarmonyPatchType)3, (radius, total));
		}

		private static void PatchRivers(bool menu, float radius, float stretch, bool radiusChanged)
		{
			Apply(!menu && (radiusChanged || stretch != 1f), typeof(WorldGenerator), "FindLakes", typeof(FindLakes), "Transpiler", (HarmonyPatchType)3, (radius, stretch));
			Apply(!menu && stretch != 1f, typeof(WorldGenerator), "IsRiverAllowed", typeof(IsRiverAllowed), "Transpiler", (HarmonyPatchType)3, stretch);
			Apply(!menu && radiusChanged, typeof(WorldGenerator), "FindStreamStartPoint", typeof(FindStreamStartPoint), "Transpiler", (HarmonyPatchType)3, radius);
		}

		private static void PatchLocations(float radius, bool radiusChanged)
		{
			Apply(radiusChanged, typeof(ZoneSystem), "GetRandomZone", typeof(GetRandomZone), "Transpiler", (HarmonyPatchType)3, radius);
			Apply(radiusChanged, typeof(ZoneSystem), "GenerateLocationsTimeSliced", typeof(GenerateLocations), "TranspileMoveNext", (HarmonyPatchType)3, radius, GenerateLocationsArgs, enumerator: true);
		}
	}
	public static class Patches
	{
		private static readonly Dictionary<(MethodBase Original, MethodInfo Patch), object?> Registered = new Dictionary<(MethodBase, MethodInfo), object>();

		public static void Apply(Harmony harmony, bool shouldPatch, Type originalType, string originalName, Type patchType, string patchName, HarmonyPatchType patchKind, int? priority = null, Type[]? argumentTypes = null, bool enumerator = false, object? state = null)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				MethodBase methodBase = ResolveOriginal(originalType, originalName, argumentTypes, enumerator);
				MethodInfo methodInfo = AccessTools.Method(patchType, patchName, (Type[])null, (Type[])null) ?? throw new MissingMethodException(patchType.FullName, patchName);
				(MethodBase, MethodInfo) key = (methodBase, methodInfo);
				object value;
				bool flag = Registered.TryGetValue(key, out value);
				if (!(flag && shouldPatch) || !object.Equals(value, state))
				{
					if (flag)
					{
						harmony.Unpatch(methodBase, methodInfo);
						Registered.Remove(key);
					}
					if (shouldPatch)
					{
						Patch(harmony, methodBase, methodInfo, patchKind, priority);
						Registered[key] = state;
					}
				}
			}
			catch (Exception ex)
			{
				Log.Error("Failed to " + (shouldPatch ? "patch" : "unpatch") + " " + originalType.Name + "." + originalName + " with " + patchType.Name + "." + patchName + ": " + ex.Message);
			}
		}

		private static MethodBase ResolveOriginal(Type originalType, string originalName, Type[]? argumentTypes, bool enumerator)
		{
			MethodInfo methodInfo = AccessTools.Method(originalType, originalName, argumentTypes, (Type[])null) ?? throw new MissingMethodException(originalType.FullName, originalName);
			if (!enumerator)
			{
				return methodInfo;
			}
			return AccessTools.EnumeratorMoveNext((MethodBase)methodInfo) ?? throw new MissingMethodException(originalType.FullName, originalName + ".MoveNext");
		}

		private static void Patch(Harmony harmony, MethodBase original, MethodInfo patch, HarmonyPatchType patchKind, int? priority)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected I4, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			HarmonyMethod val = new HarmonyMethod(patch);
			if (priority.HasValue)
			{
				val.priority = priority.Value;
			}
			switch (patchKind - 1)
			{
			case 0:
				harmony.Patch(original, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				break;
			case 1:
				harmony.Patch(original, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				break;
			case 2:
				harmony.Patch(original, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
				break;
			case 3:
				harmony.Patch(original, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null);
				break;
			default:
				throw new ArgumentOutOfRangeException("patchKind", patchKind, "Unsupported Harmony patch kind.");
			}
		}
	}
	public static class WorldSettings
	{
		private const string Prefix = "ews_";

		private const string GridWidthKey = "ews_gridwidth";

		private static readonly ConditionalWeakTable<World, Dictionary<string, string>> Stored = new ConditionalWeakTable<World, Dictionary<string, string>>();

		[ThreadStatic]
		private static List<string>? SaveKeys;

		private static string KeyOf(ConfigEntryBase entry)
		{
			return "ews_" + entry.Definition.Key.ToLowerInvariant().Replace(' ', '_');
		}

		private static string DefaultOf(ConfigEntryBase entry)
		{
			return TomlTypeConverter.ConvertToString(entry.DefaultValue, entry.SettingType);
		}

		private static Dictionary<string, string> Snapshot()
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (ConfigEntryBase entry in ConfigWrapper.Entries)
			{
				string serializedValue = entry.GetSerializedValue();
				if (serializedValue != DefaultOf(entry))
				{
					dictionary[KeyOf(entry)] = serializedValue;
				}
			}
			return dictionary;
		}

		public static void Extract(World world)
		{
			List<string> startingGlobalKeys = world.m_startingGlobalKeys;
			Dictionary<string, string> dictionary = null;
			for (int num = startingGlobalKeys.Count - 1; num >= 0; num--)
			{
				string text = startingGlobalKeys[num];
				if (text.StartsWith("ews_", StringComparison.OrdinalIgnoreCase))
				{
					if (dictionary == null)
					{
						dictionary = new Dictionary<string, string>();
					}
					int num2 = text.IndexOf(' ');
					if (num2 < 0)
					{
						dictionary[text.ToLowerInvariant()] = "";
					}
					else
					{
						Dictionary<string, string> dictionary2 = dictionary;
						string key = text.Substring(0, num2).ToLowerInvariant();
						string text2 = text;
						int num3 = num2 + 1;
						dictionary2[key] = text2.Substring(num3, text2.Length - num3);
					}
					startingGlobalKeys.RemoveAt(num);
				}
			}
			if (dictionary != null)
			{
				Stored.AddOrUpdate(world, dictionary);
			}
		}

		public static void Apply(World world)
		{
			if (!Stored.TryGetValue(world, out Dictionary<string, string> value))
			{
				return;
			}
			foreach (ConfigEntryBase entry in ConfigWrapper.Entries)
			{
				string value2;
				string text = (value.TryGetValue(KeyOf(entry), out value2) ? value2 : DefaultOf(entry));
				if (entry.GetSerializedValue() != text)
				{
					entry.SetSerializedValue(text);
				}
			}
			Refresh.Clear();
		}

		public static int SavedGridWidth(World world)
		{
			if (Stored.TryGetValue(world, out Dictionary<string, string> value) && value.TryGetValue("ews_gridwidth", out var value2) && int.TryParse(value2, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return result;
			}
			return 512;
		}

		public static void PrepareSave(World world)
		{
			bool flag = ZNet.GetWorldIfIsHost() == world;
			if (flag || !Stored.TryGetValue(world, out Dictionary<string, string> value))
			{
				value = Snapshot();
				if (flag)
				{
					value["ews_gridwidth"] = ZoneGrid.Width.ToString(CultureInfo.InvariantCulture);
				}
				Stored.AddOrUpdate(world, value);
			}
			List<string> startingGlobalKeys = world.m_startingGlobalKeys;
			List<string> list = new List<string>(startingGlobalKeys.Count);
			list.AddRange(startingGlobalKeys);
			SaveKeys = list;
			foreach (KeyValuePair<string, string> item in value)
			{
				SaveKeys.Add(item.Key + " " + item.Value);
			}
		}

		public static void EndSave()
		{
			SaveKeys = null;
		}

		public static List<string> GetSaveKeys(World world)
		{
			return SaveKeys ?? world.m_startingGlobalKeys;
		}
	}
	[HarmonyPatch(typeof(World), "LoadWorld")]
	public class LoadWorldSettings
	{
		private static void Postfix(World? __result)
		{
			if (__result != null)
			{
				WorldSettings.Extract(__result);
			}
		}
	}
	[HarmonyPatch]
	public class SaveWorldSettings
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(World), "SaveWorldFWLData", new Type[2]
			{
				typeof(DateTime),
				typeof(FileWriter).MakeByRefType()
			}, (Type[])null);
		}

		private static void Prefix(World __instance)
		{
			WorldSettings.PrepareSave(__instance);
		}

		private static void Finalizer()
		{
			WorldSettings.EndSave();
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			FieldInfo fieldInfo = AccessTools.Field(typeof(World), "m_startingGlobalKeys");
			MethodInfo method = AccessTools.Method(typeof(WorldSettings), "GetSaveKeys", (Type[])null, (Type[])null);
			return new CodeMatcher(instructions, (ILGenerator)null).MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo, (string)null)
			}).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher)
			{
				matcher.Set(OpCodes.Call, (object)method);
			}, (Action<string>)null).InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(Terminal), "InitTerminal")]
	public class DebugCommands
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__0_0;

			public static ConsoleEvent <>9__0_1;

			internal void <Postfix>b__0_0(ConsoleEventArgs args)
			{
				Refresh.Request(Regen.Minimap);
			}

			internal void <Postfix>b__0_1(ConsoleEventArgs args)
			{
				WorldGenerator instance = WorldGenerator.m_instance;
				if (instance != null)
				{
					List<string> values = new List<string>
					{
						"Main: " + instance.m_world.m_seedName,
						"Generator: " + instance.m_world.m_worldGenVersion,
						"World: " + instance.m_world.m_seed,
						"Offset X: " + instance.m_offset0,
						"Offset Y: " + instance.m_offset1,
						"Height: " + instance.m_offset3,
						"Meadows: " + instance.m_offset3,
						"Black forest: " + instance.m_offset2,
						"Swamp: " + instance.m_offset0,
						"Plains: " + instance.m_offset1,
						"Mistlands: " + instance.m_offset4
					};
					ZLog.Log((object)string.Join("\n", values));
					args.Context.AddString(string.Join("\n", values));
				}
			}
		}

		private static void Postfix()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate
				{
					Refresh.Request(Regen.Minimap);
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("ew_map", "Refreshes the world map.", (ConsoleEvent)obj, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj2 = <>c.<>9__0_1;
			if (obj2 == null)
			{
				ConsoleEvent val2 = delegate(ConsoleEventArgs args)
				{
					WorldGenerator instance = WorldGenerator.m_instance;
					if (instance != null)
					{
						List<string> values = new List<string>
						{
							"Main: " + instance.m_world.m_seedName,
							"Generator: " + instance.m_world.m_worldGenVersion,
							"World: " + instance.m_world.m_seed,
							"Offset X: " + instance.m_offset0,
							"Offset Y: " + instance.m_offset1,
							"Height: " + instance.m_offset3,
							"Meadows: " + instance.m_offset3,
							"Black forest: " + instance.m_offset2,
							"Swamp: " + instance.m_offset0,
							"Plains: " + instance.m_offset1,
							"Mistlands: " + instance.m_offset4
						};
						ZLog.Log((object)string.Join("\n", values));
						args.Context.AddString(string.Join("\n", values));
					}
				};
				<>c.<>9__0_1 = val2;
				obj2 = (object)val2;
			}
			new ConsoleCommand("ew_seeds", "- Prints different seeds.", (ConsoleEvent)obj2, true, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}
	}
	[BepInPlugin("expand_world_size", "Expand World Size", "1.45")]
	public class EWS : BaseUnityPlugin
	{
		public const string GUID = "expand_world_size";

		public const string NAME = "Expand World Size";

		public const string VERSION = "1.45";

		public static EWS Instance;

		public static ConfigSync ConfigSync = new ConfigSync("expand_world_size")
		{
			DisplayName = "Expand World Size",
			CurrentVersion = "1.45",
			ModRequired = true,
			IsLocked = true
		};

		public static string ConfigName = "expand_world_size.cfg";

		public static bool NeedsMigration = File.Exists(Path.Combine(Paths.ConfigPath, "expand_world.cfg")) && !File.Exists(Path.Combine(Paths.ConfigPath, ConfigName));

		public void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			Instance = this;
			RegisterRefresh();
			Configuration.Init(new ConfigWrapper(((BaseUnityPlugin)this).Config, ConfigSync));
			Patcher.Init(new Harmony("expand_world_size"));
			try
			{
				SetupWatcher();
			}
			catch (Exception ex)
			{
				Log.Error(ex.Message);
			}
		}

		public void Start()
		{
			Marketplace.Run();
			BetterContinents.Run();
			EWD.Run();
			VPO.Run();
		}

		public void LateUpdate()
		{
			Refresh.Tick(Time.deltaTime);
			if (!Patcher.IsMenu)
			{
				WaterColor.Transition(Time.deltaTime);
			}
		}

		private static void RegisterRefresh()
		{
			Refresh.Register(Regen.Seed, WorldInfo.RefreshSeed);
			Refresh.Register(Regen.Patches, WorldInfo.Patch);
			Refresh.Register(Regen.ZoneGrid, ZoneGrid.Refresh);
			Refresh.Register(Regen.Water, WaterColor.Refresh);
			Refresh.Register(Regen.Water, SetupMaterial.Refresh);
			Refresh.Register(Regen.Water, delegate
			{
				if (Object.op_Implicit((Object)(object)EnvMan.instance))
				{
					ScaleGlobalWaterSurface.Refresh(EnvMan.instance);
				}
			});
			Refresh.Register(Regen.Minimap, MapGeneration.Cancel);
			Refresh.Register(Regen.Minimap, delegate
			{
				if (Object.op_Implicit((Object)(object)Minimap.instance))
				{
					MinimapAwake.Refresh(Minimap.instance);
				}
			});
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
			{
				return;
			}
			try
			{
				Log.Debug("ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				Log.Error("There was an issue loading your " + ((BaseUnityPlugin)this).Config.ConfigFilePath);
				Log.Error("Please check your config entries for spelling and format!");
			}
		}
	}
	[HarmonyPatch(typeof(ZRpc), "SetLongTimeout")]
	public class IncreaseTimeout
	{
		private static bool Prefix()
		{
			ZRpc.m_timeout = 300f;
			ZLog.Log((object)$"ZRpc timeout set to {ZRpc.m_timeout}s ");
			return false;
		}
	}
	public class BaseHeight
	{
		public static float Postfix(float result)
		{
			return WorldInfo.BaseWaterLevel + (result - WorldInfo.BaseWaterLevel) * WorldInfo.AltitudeMultiplier + WorldInfo.BaseAltitudeDelta;
		}
	}
	public class BiomeHeight
	{
		public static float Postfix(float result)
		{
			if (!(result > WorldInfo.WaterLevel))
			{
				return (result - WorldInfo.WaterLevel) * WorldInfo.WaterDepth + WorldInfo.WaterLevel;
			}
			return result;
		}
	}
	public class Forest
	{
		public static float Postfix(float result)
		{
			return result / WorldInfo.ForestMultiplier;
		}
	}
	public class HeightSeed
	{
		private static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			return Helper.ReplaceSeed(new CodeMatcher(instructions, (ILGenerator)null), "m_offset3", Configuration.HeightSeed.Value).InstructionEnumeration();
		}

		public static IEnumerable<CodeInstruction> Ashlands(IEnumerable<CodeInstruction> instructions)
		{
			return Transpile(instructions);
		}

		public static IEnumerable<CodeInstruction> Forest(IEnumerable<CodeInstruction> instructions)
		{
			return Transpile(instructions);
		}

		public static IEnumerable<CodeInstruction> Meadows(IEnumerable<CodeInstruction> instructions)
		{
			return Transpile(instructions);
		}

		public static IEnumerable<CodeInstruction> DeepNorth(IEnumerable<CodeInstruction> instructions)
		{
			return Transpile(instructions);
		}

		public static IEnumerable<CodeInstruction> Plains(IEnumerable<CodeInstruction> instructions)
		{
			return Transpile(instructions);
		}

		public static IEnumerable<CodeInstruction> Mountain(IEnumerable<CodeInstruction> instructions)
		{
			return Transpile(instructions);
		}

		public static IEnumerable<CodeInstruction> Mistlands(IEnumerable<CodeInstruction> instructions)
		{
			return Transpile(instructions);
		}
	}
	[HarmonyPatch(typeof(LoadingIndicator), "SetShowProgress")]
	public class ModifyLocations
	{
		private static readonly Dictionary<ZoneLocation, int> OriginalQuantities = new Dictionary<ZoneLocation, int>();

		private static readonly Dictionary<ZoneLocation, float> OriginalMin = new Dictionary<ZoneLocation, float>();

		private static readonly Dictionary<ZoneLocation, float> OriginalMax = new Dictionary<ZoneLocation, float>();

		private static void Prefix(bool show)
		{
			if (!show)
			{
				return;
			}
			Restore();
			GetRandomPointByBiome.Warned.Clear();
			if (Configuration.LocationsMultiplier != 1f)
			{
				foreach (ZoneLocation location in ZoneSystem.instance.m_locations)
				{
					if (location.m_quantity != 0 && location.m_enable && !(location.m_prefabName == Game.instance.m_StartLocation))
					{
						OriginalQuantities[location] = location.m_quantity;
						if (Configuration.LocationsMultiplier == 0f)
						{
							location.m_quantity = 0;
						}
						else
						{
							location.m_quantity = Math.Max(1, Mathf.RoundToInt((float)location.m_quantity * Configuration.LocationsMultiplier));
						}
					}
				}
			}
			if (EWD.IsPresent || Configuration.WorldRadius == 10000f)
			{
				return;
			}
			foreach (ZoneLocation location2 in ZoneSystem.instance.m_locations)
			{
				OriginalMin[location2] = location2.m_minDistance;
				OriginalMax[location2] = location2.m_maxDistance;
				location2.m_minDistance *= Configuration.WorldRadius / 10000f;
				location2.m_maxDistance *= Configuration.WorldRadius / 10000f;
			}
		}

		private static void Postfix(bool show)
		{
			if (!show)
			{
				Restore();
			}
		}

		private static void Restore()
		{
			foreach (ZoneLocation location in ZoneSystem.instance.m_locations)
			{
				if (OriginalQuantities.TryGetValue(location, out var value))
				{
					location.m_quantity = value;
				}
				if (OriginalMin.TryGetValue(location, out var value2))
				{
					location.m_minDistance = value2;
				}
				if (OriginalMax.TryGetValue(location, out var value3))
				{
					location.m_maxDistance = value3;
				}
			}
			OriginalQuantities.Clear();
			OriginalMin.Clear();
			OriginalMax.Clear();
		}
	}
	[HarmonyPatch(typeof(AltBiomeWorldData), "GetRandomPointByBiome")]
	public class GetRandomPointByBiome
	{
		public static HashSet<Biome> Warned = new HashSet<Biome>();

		private static bool Prefix(AltBiomeWorldData __instance, Biome biome, ref BiomePointCoordinate __result)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.Biomes[biome].AllPoints.Count == 0)
			{
				if (!Warned.Contains(biome))
				{
					Log.Warning($"Biome {biome} doesn't exist in the map!");
					Warned.Add(biome);
				}
				__result = default(BiomePointCoordinate);
				return false;
			}
			return true;
		}
	}
	public class GetRandomZone
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 10000f, Configuration.WorldRadius).InstructionEnumeration();
		}
	}
	public class GenerateLocations
	{
		public static IEnumerable<CodeInstruction> TranspileMoveNext(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 10000f, Configuration.WorldRadius).InstructionEnumeration();
		}
	}
	public class GetAshlandsHeight
	{
		public static readonly double DefaultWidthRestriction = 7500.0;

		public static readonly double DefaultLengthRestriction = 1000.0;

		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_R8, (object)1000.0, (string)null)
			}).SetOperandAndAdvance((object)Configuration.AshlandsLengthRestriction).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_R8, (object)7500.0, (string)null)
			})
				.SetOperandAndAdvance((object)Configuration.AshlandsWidthRestriction)
				.InstructionEnumeration();
		}
	}
	public class Poles
	{
		public static bool DisableGap(ref double __result)
		{
			__result = 1.0;
			return false;
		}
	}
	public class FindLakes
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Stretch.Replace(Stretch.Replace(Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), -10000f, 0f - Configuration.WorldRadius), -10000f, 0f - Configuration.WorldRadius), 10000f, Configuration.WorldRadius), OpCodes.Ldloc_3), OpCodes.Ldloc_2), 10000f, Configuration.WorldRadius), 10000f, Configuration.WorldRadius).InstructionEnumeration();
		}
	}
	public class IsRiverAllowed
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return Stretch.Replace(Stretch.Replace(new CodeMatcher(instructions, (ILGenerator)null), OpCodes.Ldfld), OpCodes.Ldfld).InstructionEnumeration();
		}
	}
	public class FindStreamStartPoint
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), -10000f, 0f - Configuration.WorldRadius), 10000f, Configuration.WorldRadius), -10000f, 0f - Configuration.WorldRadius), 10000f, Configuration.WorldRadius).InstructionEnumeration();
		}
	}
	public class AddRivers
	{
		public static void Prefix(ref float wx, ref float wy)
		{
			wx *= Configuration.WorldStretch;
			wy *= Configuration.WorldStretch;
		}
	}
	public class Stretch
	{
		private static readonly FieldInfo AshlandsMinDistance = AccessTools.Field(typeof(WorldGenerator), "ashlandsMinDistance");

		private static readonly FieldInfo AshlandsYOffset = AccessTools.Field(typeof(WorldGenerator), "ashlandsYOffset");

		private static object? DefaultMinDistance;

		private static object? DefaultYOffset;

		public static void UpdateAshlandsLimits(bool menu)
		{
			if (DefaultMinDistance == null)
			{
				DefaultMinDistance = AshlandsMinDistance.GetValue(null);
			}
			if (DefaultYOffset == null)
			{
				DefaultYOffset = AshlandsYOffset.GetValue(null);
			}
			AshlandsMinDistance.SetValue(null, menu ? DefaultMinDistance : ((object)(1.2f * Configuration.StrechedWorldRadius)));
			AshlandsYOffset.SetValue(null, menu ? DefaultYOffset : ((object)(-0.4f * Configuration.StrechedWorldRadius)));
		}

		public static IEnumerable<CodeInstruction> StretchIsAshlandsTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(WorldGenerator), "IsAshlands", (Type[])null, (Type[])null), (string)null)
			}).MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Vector3), "z"), (string)null)
			}).Advance(1)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.WorldStretch)
				})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				})
				.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Vector3), "x"), (string)null)
				})
				.Advance(1)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.WorldStretch)
				})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				})
				.InstructionEnumeration();
		}

		public static IEnumerable<CodeInstruction> StretchIsAshlandsDeepNorthTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(WorldGenerator), "IsAshlands", (Type[])null, (Type[])null), (string)null)
			}).MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Vector3), "z"), (string)null)
			}).Advance(1)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.WorldStretch)
				})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				})
				.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Vector3), "x"), (string)null)
				})
				.Advance(1)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.WorldStretch)
				})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				})
				.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(WorldGenerator), "IsDeepnorth", (Type[])null, (Type[])null), (string)null)
				})
				.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Vector3), "z"), (string)null)
				})
				.Advance(1)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.WorldStretch)
				})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				})
				.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Vector3), "x"), (string)null)
				})
				.Advance(1)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.WorldStretch)
				})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				})
				.InstructionEnumeration();
		}

		[HarmonyPriority(500)]
		public static void StretchVector3(ref Vector3 pos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = pos;
			val.x = pos.x / Configuration.WorldStretch;
			val.z = pos.z / Configuration.WorldStretch;
			pos = val;
		}

		[HarmonyPriority(500)]
		public static void GetMaskColor(ref float wx, ref float wy)
		{
			wx /= Configuration.WorldStretch;
			wy /= Configuration.WorldStretch;
		}

		[HarmonyPriority(500)]
		public static void GetBiomeHeight(ref float wx, ref float wy)
		{
			wx /= Configuration.WorldStretch;
			wy /= Configuration.WorldStretch;
		}

		[HarmonyPriority(500)]
		public static void GetBiome(ref float wx, ref float wy)
		{
			wx /= Configuration.WorldStretch;
			wy /= Configuration.WorldStretch;
		}

		public static CodeMatcher Replace(CodeMatcher matcher, OpCode code)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			if (Configuration.WorldStretch == 1f)
			{
				return matcher;
			}
			return matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)code, (object)null, (string)null)
			}).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.WorldStretch)
			})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				});
		}

		public static CodeMatcher ReplaceBiome(CodeMatcher matcher)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			if (Configuration.BiomeStretch == 1f)
			{
				return matcher;
			}
			return matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Conv_R8, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null)
			}).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.BiomeStretch)
			})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				})
				.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_2, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Conv_R8, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null)
				})
				.Advance(1)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)Configuration.BiomeStretch)
				})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Div, (object)null)
				});
		}

		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Helper.Replace(Helper.Replace(Helper.Replace(Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(ReplaceBiome(ReplaceBiome(ReplaceBiome(ReplaceBiome(new CodeMatcher(instructions, (ILGenerator)null))))).InstructionEnumeration(), (ILGenerator)null), 2000f, 0.2f * Configuration.StrechedWorldRadius), 6000.0, 0.6 * (double)Configuration.StrechedWorldRadius), 10000f, Configuration.StrechedWorldRadius), 3000.0, 0.3 * (double)Configuration.StrechedWorldRadius), 8000f, 0.8f * Configuration.StrechedWorldRadius), 600.0, 0.06 * (double)Configuration.StrechedWorldRadius), 6000f, 0.6f * Configuration.StrechedWorldRadius), 5000.0, 0.5 * (double)Configuration.StrechedWorldRadius).InstructionEnumeration();
		}

		public static IEnumerable<CodeInstruction> TranspilerIsDeepnorth(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 4000.0, 0.4 * (double)Configuration.StrechedWorldRadius), 12000.0, 1.2 * (double)Configuration.StrechedWorldRadius).InstructionEnumeration();
		}

		public static IEnumerable<CodeInstruction> TranspilerCreateAshlandsGap(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			return Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 400.0, 0.04 * (double)Configuration.StrechedWorldRadius).InstructionEnumeration();
		}

		public static IEnumerable<CodeInstruction> TranspilerCreateDeepNorthGap(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 4000f, 0.4f * Configuration.StrechedWorldRadius), 12000.0, 1.2f * Configuration.StrechedWorldRadius), 400.0, 0.04 * (double)Configuration.StrechedWorldRadius).InstructionEnumeration();
		}

		public static IEnumerable<CodeInstruction> TranspilerGetBiomeHeight(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 10500f, Configuration.StrechedWorldTotalRadius).InstructionEnumeration();
		}

		public static void PrefixGenerateAltBiomes()
		{
			foreach (AltBiome altBiome in AltBiomeList.m_altBiomes)
			{
				altBiome.m_minDistanceFromCenter *= Configuration.WorldStretch;
				altBiome.m_aboveWorldX *= Configuration.WorldStretch;
				altBiome.m_belowWorldX *= Configuration.WorldStretch;
				altBiome.m_aboveWorldY *= Configuration.WorldStretch;
				altBiome.m_belowWorldY *= Configuration.WorldStretch;
			}
		}

		public static void FinalizerGenerateAltBiomes()
		{
			foreach (AltBiome altBiome in AltBiomeList.m_altBiomes)
			{
				altBiome.m_minDistanceFromCenter /= Configuration.WorldStretch;
				altBiome.m_aboveWorldX /= Configuration.WorldStretch;
				altBiome.m_belowWorldX /= Configuration.WorldStretch;
				altBiome.m_aboveWorldY /= Configuration.WorldStretch;
				altBiome.m_belowWorldY /= Configuration.WorldStretch;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "AddKnownBiome")]
	public class StartColorTransition
	{
		public static void Postfix(BiomeSector biome)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			WaterColor.StartTransition((int)biome.Biome == 32);
		}
	}
	[HarmonyPatch(typeof(Player), "OnSpawned")]
	public class ResetColorTransition
	{
		public static void Postfix()
		{
			WaterColor.StopTransition();
		}
	}
	public class WaterColor
	{
		private static float TransitionProgress;

		private static bool Transitioning;

		public static bool? TargetAshlands;

		private static bool InitDone;

		private static Color WaterSurface;

		private static Color AshlandsSurface;

		private static Color WaterTop;

		private static Color AshlandsTop;

		private static Color WaterBottom;

		private static Color AshlandsBottom;

		private static Color WaterShallow;

		private static Color AshlandsShallow;

		public static void Transition(float time)
		{
			if (!Transitioning)
			{
				return;
			}
			if (TargetAshlands == true)
			{
				TransitionProgress += 0.1f * time;
				if (TransitionProgress >= 1f)
				{
					StopTransition();
				}
			}
			else if (TargetAshlands == false)
			{
				TransitionProgress -= 0.1f * time;
				if (TransitionProgress <= 0f)
				{
					StopTransition();
				}
			}
			UpdateTransitions();
		}

		public static void StartTransition(bool toAshlands)
		{
			if (Configuration.FixWaterColor && TargetAshlands != toAshlands)
			{
				TargetAshlands = toAshlands;
				Transitioning = true;
			}
		}

		public static void StopTransition()
		{
			if (Transitioning)
			{
				Transitioning = false;
				TransitionProgress = ((TargetAshlands == true) ? 1f : 0f);
			}
		}

		private static void UpdateTransitions()
		{
			foreach (WaterVolume instance2 in WaterVolume.Instances)
			{
				UpdateTransition(((Renderer)instance2.m_waterSurface).sharedMaterial);
			}
			EnvMan instance = EnvMan.instance;
			Transform val = ((instance != null) ? ((Component)instance).transform.Find("WaterPlane").Find("watersurface") : null);
			if ((Object)(object)val != (Object)null)
			{
				UpdateTransition(((Renderer)((Component)val).GetComponent<MeshRenderer>()).sharedMaterial);
			}
		}

		private static void UpdateTransition(Material mat)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			InitColors(mat);
			Color surface = Color.Lerp(WaterSurface, AshlandsSurface, TransitionProgress);
			Color top = Color.Lerp(WaterTop, AshlandsTop, TransitionProgress);
			Color bottom = Color.Lerp(WaterBottom, AshlandsBottom, TransitionProgress);
			Color shallow = Color.Lerp(WaterShallow, AshlandsShallow, TransitionProgress);
			UpdateColors(mat, surface, top, bottom, shallow);
		}

		public static void Refresh()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				StartTransition((int)Player.m_localPlayer.GetCurrentBiome() == 32);
			}
			foreach (WaterVolume instance2 in WaterVolume.Instances)
			{
				FixColors(((Renderer)instance2.m_waterSurface).sharedMaterial);
			}
			EnvMan instance = EnvMan.instance;
			Transform val = ((instance != null) ? ((Component)instance).transform.Find("WaterPlane").Find("watersurface") : null);
			if ((Object)(object)val != (Object)null)
			{
				FixColors(((Renderer)((Component)val).GetComponent<MeshRenderer>()).sharedMaterial);
			}
		}

		public static void FixColors(Material mat)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			InitColors(mat);
			if (Configuration.FixWaterColor)
			{
				UpdateTransition(mat);
				return;
			}
			if (Configuration.RemoveAshlandsWater)
			{
				StopTransition();
				UpdateColors(mat, WaterSurface, WaterTop, WaterBottom, WaterShallow);
				return;
			}
			StopTransition();
			mat.SetColor("_SurfaceColor", WaterSurface);
			mat.SetColor("_AshlandsSurfaceColor", AshlandsSurface);
			mat.SetColor("_ColorTop", WaterTop);
			mat.SetColor("_AshlandsColorTop", AshlandsTop);
			mat.SetColor("_ColorBottom", WaterBottom);
			mat.SetColor("_AshlandsColorBottom", AshlandsBottom);
			mat.SetColor("_ColorBottomShallow", WaterShallow);
			mat.SetColor("_AshlandsColorBottomShallow", AshlandsShallow);
		}

		private static void UpdateColors(Material mat, Color surface, Color top, Color bottom, Color shallow)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			mat.SetColor("_SurfaceColor", surface);
			mat.SetColor("_AshlandsSurfaceColor", surface);
			mat.SetColor("_ColorTop", top);
			mat.SetColor("_AshlandsColorTop", top);
			mat.SetColor("_ColorBottom", bottom);
			mat.SetColor("_AshlandsColorBottom", bottom);
			mat.SetColor("_ColorBottomShallow", shallow);
			mat.SetColor("_AshlandsColorBottomShallow", shallow);
		}

		private static void InitColors(Material mat)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (!InitDone)
			{
				InitDone = true;
				WaterSurface = mat.GetColor("_SurfaceColor");
				AshlandsSurface = mat.GetColor("_AshlandsSurfaceColor");
				WaterTop = mat.GetColor("_ColorTop");
				AshlandsTop = mat.GetColor("_AshlandsColorTop");
				WaterBottom = mat.GetColor("_ColorBottom");
				AshlandsBottom = mat.GetColor("_AshlandsColorBottom");
				WaterShallow = mat.GetColor("_ColorBottomShallow");
				AshlandsShallow = mat.GetColor("_AshlandsColorBottomShallow");
			}
		}
	}
	public class WorldSizeHelper
	{
		public static int BiomeMapSize => Mathf.CeilToInt(2048f * Configuration.WorldTotalRadius / 10500f / Configuration.WorldStretch);

		public static float BiomeMapCenter => (float)BiomeMapSize / 2f;

		public static float BiomeMapPixelSize => 12f * Configuration.WorldStretch;

		public static float BiomeMapHalfPixel => 6f * Configuration.WorldStretch;

		public static void GrowBiomeData()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			AltBiomeWorldData val = Patcher.WG?.m_world?.m_biomeData;
			if (val == null)
			{
				return;
			}
			int biomeMapSize = BiomeMapSize;
			if (biomeMapSize <= val.Size)
			{
				return;
			}
			float[,] array = new float[biomeMapSize, biomeMapSize];
			BiomeIndex[,] array2 = new BiomeIndex[biomeMapSize, biomeMapSize];
			BiomeSector[,] array3 = new BiomeSector[biomeMapSize, biomeMapSize];
			for (int i = 0; i < val.Size; i++)
			{
				for (int j = 0; j < val.Size; j++)
				{
					array[i, j] = val.PointHeights[i, j];
					array2[i, j] = val.PointBiomes[i, j];
					array3[i, j] = val.PointSectors[i, j];
				}
			}
			val.PointHeights = array;
			val.PointBiomes = array2;
			val.PointSectors = array3;
			val.Size = biomeMapSize;
		}

		public static IEnumerable<CodeInstruction> EdgeCheck(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 10420f, Configuration.WorldTotalRadius - 80f), 10500f, Configuration.WorldTotalRadius).InstructionEnumeration();
		}
	}
	public class MapSpaceToWorldSpaceSize
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 1024f, WorldSizeHelper.BiomeMapCenter), 12f, WorldSizeHelper.BiomeMapPixelSize), 6f, WorldSizeHelper.BiomeMapHalfPixel).InstructionEnumeration();
		}
	}
	public class WorldSpaceToMapSpaceSize
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 6f, WorldSizeHelper.BiomeMapHalfPixel), 12f, WorldSizeHelper.BiomeMapPixelSize), 1024f, WorldSizeHelper.BiomeMapCenter).InstructionEnumeration();
		}
	}
	public class GenerateBiomePointsSize
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 2048, WorldSizeHelper.BiomeMapSize), 110250000f, Configuration.WorldTotalRadius * Configuration.WorldTotalRadius), 2048, WorldSizeHelper.BiomeMapSize), 2048, WorldSizeHelper.BiomeMapSize).InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(AltBiomeWorldData), "Load")]
	public class LoadBiomePointsSize
	{
		private static bool Prefix(BinaryReader reader, World version, ref AltBiomeWorldData __result)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			int num = reader.ReadInt32();
			if (num == WorldSizeHelper.BiomeMapSize)
			{
				reader.BaseStream.Position -= 4L;
				return true;
			}
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					BiomePoint.Load(reader, version);
				}
			}
			__result = new AltBiomeWorldData(WorldSizeHelper.BiomeMapSize);
			return false;
		}
	}
	[HarmonyPatch(typeof(Player), "EdgeOfWorldKill")]
	public class EdgeOfWorldKillDungeons
	{
		private static bool Prefix(Player __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return ((Component)__instance).transform.position.y < 4000f;
		}
	}
	public class GetAshlandsHeightSize
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			return Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 10150.0, (Configuration.WorldTotalRadius + 150f) / Configuration.WorldStretch).InstructionEnumeration();
		}
	}
	public class GetBaseHeight
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val = val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(WorldGenerator), "m_offset1"), (string)null)
			});
			if (Configuration.OffsetX.HasValue)
			{
				val = Helper.ReplaceSeed(val, "m_offset0", Configuration.OffsetX.Value);
			}
			if (Configuration.OffsetY.HasValue)
			{
				val = Helper.ReplaceSeed(val, "m_offset1", Configuration.OffsetY.Value);
			}
			val = Helper.Replace(val, 10000f, Configuration.StrechedWorldRadius);
			val = Helper.Replace(val, 10000f, Configuration.StrechedWorldRadius);
			val = Helper.Replace(val, 10500f, Configuration.StrechedWorldTotalRadius);
			val = Helper.Replace(val, 10490f, (Configuration.WorldTotalRadius - 10f) / Configuration.WorldStretch);
			val = Helper.Replace(val, 10500f, Configuration.StrechedWorldTotalRadius);
			return val.InstructionEnumeration();
		}
	}
	public class GetBiomeSectorSize
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 2048, WorldSizeHelper.BiomeMapSize), 2047, WorldSizeHelper.BiomeMapSize - 1), 2048, WorldSizeHelper.BiomeMapSize), 2047, WorldSizeHelper.BiomeMapSize - 1).InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(WaterVolume), "SetupMaterial")]
	public class SetupMaterial
	{
		public static void Refresh()
		{
			foreach (WaterVolume instance in WaterVolume.Instances)
			{
				((Renderer)instance.m_waterSurface).sharedMaterial.SetFloat("_WaterEdge", Configuration.WorldTotalRadius);
			}
		}

		public static void Prefix(WaterVolume __instance)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			((Renderer)__instance.m_waterSurface).sharedMaterial.SetFloat("_WaterEdge", Configuration.WorldTotalRadius);
			if (((Component)__instance).transform.position.y < 30.001f && ((Component)__instance).transform.position.y > 29.999f)
			{
				Collider collider = __instance.m_collider;
				BoxCollider val = (BoxCollider)(object)((collider is BoxCollider) ? collider : null);
				if (val != null)
				{
					val.center = new Vector3(0f, -100f, 0f);
					val.size = new Vector3(64f, 220f, 64f);
				}
			}
			WaterColor.FixColors(((Renderer)__instance.m_waterSurface).sharedMaterial);
		}
	}
	[HarmonyPatch(typeof(EnvMan), "Awake")]
	public class ScaleGlobalWaterSurface
	{
		public static void Refresh(EnvMan obj)
		{
			Transform val = ((Component)obj).transform.Find("WaterPlane").Find("watersurface");
			if (Object.op_Implicit((Object)(object)val))
			{
				((Renderer)((Component)val).GetComponent<MeshRenderer>()).sharedMaterial.SetFloat("_WaterEdge", Configuration.WorldTotalRadius);
			}
		}

		public static void Postfix(EnvMan __instance)
		{
			Refresh(__instance);
		}
	}
	public class UpdateWind
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(Helper.Replace(Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 10500f, Configuration.WorldRadius).SetOpcodeAndAdvance(OpCodes.Nop).SetOpcodeAndAdvance(OpCodes.Nop)
				.SetOpcodeAndAdvance(OpCodes.Nop), 10500f, Configuration.WorldRadius).SetOpcodeAndAdvance(OpCodes.Nop).SetOpcodeAndAdvance(OpCodes.Nop)
				.SetOpcodeAndAdvance(OpCodes.Nop), 10500f, Configuration.WorldTotalRadius).InstructionEnumeration();
		}
	}
	public class GetWaterSurface
	{
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return Helper.Replace(new CodeMatcher(instructions, (ILGenerator)null), 10500f, Configuration.WorldTotalRadius).InstructionEnumeration();
		}
	}
	public static class ZoneGrid
	{
		public const int VanillaWidth = 512;

		public const int ExtendedWidth = 2048;

		public const float VanillaRadius = 16384f;

		public const float ExtendedRadius = 65536f;

		public static int Width = 512;

		public static uint MinChunkVersion = 0u;

		private static readonly FieldInfo WidthField = AccessTools.Field(typeof(ZDOMan), "m_width");

		public static int GetWidth()
		{
			int val = ((Configuration.SaveGridSize > 0) ? (Configuration.SaveGridSize * 64) : ((int)Math.Ceiling(Configuration.WorldTotalRadius / 32f / 64f) * 64));
			return Math.Max(512, Math.Min(2048, val));
		}

		public static IEnumerable<CodeInstruction> Patch(IEnumerable<CodeInstruction> instructions, int widths, int halves)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			if (widths > 0)
			{
				Helper.ReplaceAllInts(val, 512, Width, widths);
			}
			if (halves > 0)
			{
				Helper.ReplaceAllInts(val, 256, Width / 2, halves);
			}
			return val.InstructionEnumeration();
		}

		public static void Patch(Harmony harmony, int width)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			if (Width == width)
			{
				return;
			}
			Width = width;
			foreach (var item2 in Targets())
			{
				MethodBase item = item2.Item1;
				MethodInfo methodInfo = AccessTools.Method(item2.Item2, "Transpiler", (Type[])null, (Type[])null);
				harmony.Unpatch(item, methodInfo);
				if (width != 512)
				{
					harmony.Patch(item, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
		}

		private static IEnumerable<(MethodBase, Type)> Targets()
		{
			yield return (AccessTools.Method(typeof(ZoneSystem), "SectorToIndex", new Type[2]
			{
				typeof(int),
				typeof(int)
			}, (Type[])null), typeof(SectorToIndexGrid));
			yield return (AccessTools.Method(typeof(ZoneSystem), "IndicesToIndex", (Type[])null, (Type[])null), typeof(IndicesToIndexGrid));
			yield return (AccessTools.Method(typeof(ZoneSystem), "IndexToSector", (Type[])null, (Type[])null), typeof(IndexToSectorGrid));
			yield return (AccessTools.Method(typeof(ZoneSystem), "GetZonesChunk", (Type[])null, (Type[])null), typeof(GetZonesChunkGrid));
			yield return (AccessTools.Method(typeof(ZoneSystem), "GetZoneFromChunk", (Type[])null, (Type[])null), typeof(GetZoneFromChunkGrid));
			yield return (AccessTools.Method(typeof(ZDOMan), "GetSaveClonePerChunk", (Type[])null, (Type[])null), typeof(GetSaveClonePerChunkGrid));
			yield return (AccessTools.Method(typeof(ZDOMan), "DecideChunkSize", (Type[])null, (Type[])null), typeof(DecideChunkSizeGrid));
			yield return (AccessTools.Method(typeof(ZDOMan), "AddObjectsPerChunk", (Type[])null, (Type[])null), typeof(AddObjectsPerChunkGrid));
		}

		public static void CheckSize()
		{
			if (!Patcher.IsMenu)
			{
				float worldTotalRadius = Configuration.WorldTotalRadius;
				if (worldTotalRadius > 65536f)
				{
					Log.Warning($"World size {worldTotalRadius} m is past {65536f} m which is the limit of the save system. Everything beyond is saved to a single chunk which causes massive lag.");
				}
			}
		}

		public static void Refresh()
		{
			CheckSize();
			int width = GetWidth();
			ZDOMan val = (Object.op_Implicit((Object)(object)ZNet.instance) ? ZDOMan.instance : null);
			if (val != null && width != Width)
			{
				bool num = Helper.IsServer();
				if (num)
				{
					WaitForSave();
				}
				Patcher.PatchZoneGrid(width);
				Rebuild(val);
				if (num)
				{
					Log.Warning($"Grid changed to {Width} zones. Converting the save, old files are removed on the next load.");
					Convert(val);
				}
			}
		}

		private static void WaitForSave()
		{
			Thread saveThread = ZNet.instance.m_saveThread;
			if (saveThread != null && saveThread.IsAlive)
			{
				Log.Info("Waiting for the world save to finish before changing the grid.");
				saveThread.Join();
			}
		}

		public static void Convert(ZDOMan zdoMan)
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			foreach (ChunkInfo value in zdoMan.m_chunkSaveMapping.Chunks.Values)
			{
				MinChunkVersion = Math.Max(MinChunkVersion, value.m_version + 1);
			}
			Dictionary<ZDOID, ZDO>.ValueCollection values = zdoMan.m_objectsByID.Values;
			List<ZDO> list = values.Where((ZDO zdo) => ZoneSystem.GetSectorIndex(zdo.GetPosition()).Sector == 0 && zdo.m_position.x < 900000f).ToList();
			if (list.Count > 0)
			{
				int num = Width * 32;
				float num2 = list.Max(delegate(ZDO zdo)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_0012: Unknown result type (might be due to invalid IL or missing references)
					Vector3 position = zdo.GetPosition();
					return Math.Max(Math.Abs(position.x), Math.Abs(position.z));
				});
				int num3 = Math.Min(32, (int)Math.Ceiling(num2 / 2048f));
				Log.Warning($"{list.Count} objects are past {num} m and are saved to a single chunk. The furthest is at {num2:F0} m. Consider increasing the \"Save system size\" setting to {num3}.");
			}
			zdoMan.m_chunkSaveMapping = new ChunkSaveMapping();
			foreach (ZDO item in values)
			{
				zdoMan.SetDirtySector(item);
			}
			zdoMan.SetDirtyPortals();
		}

		private static void Rebuild(ZDOMan zdoMan)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			WidthField.SetValue(zdoMan, Width);
			zdoMan.ResetSectorArray();
			Dictionary<ZDOID, ZDO> objectsByID = zdoMan.m_objectsByID;
			Dictionary<SectorIndex, List<ZDO>> portalObjects = zdoMan.m_portalObjects;
			HashSet<ZDO> hashSet = portalObjects.Values.SelectMany((List<ZDO> result) => result).ToHashSet();
			portalObjects.Clear();