Decompiled source of MapPrinter v1.1.0

MapPrinter.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MapPrinter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MapPrinter")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("620b47d4-ca7a-4da4-a6fb-5de9171d672f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public class Debugger : MonoBehaviour
{
	public static string log = "";

	public static void Awake()
	{
		MonoBehaviour.print((object)"Debugger Awake");
	}

	public static void Start()
	{
		MonoBehaviour.print((object)"Debugger Start");
	}

	public static void Update()
	{
		if (log != "")
		{
			Debug.Log((object)log);
			log = "";
		}
	}
}
public class MapImageGeneration
{
	private static Color32[] m_mapTexture;

	private static Color32[] m_forestTexture;

	private static Color32[] m_heightmap;

	private static Color32[] m_fogmap;

	private static int m_textureSize;

	private static int scale;

	private Color32[] result;

	public Color32[] output;

	public static void Initialize(Color32[] biomes, Color32[] forests, Color32[] height, Color32[] exploration, int texture_size, int imageScale)
	{
		m_mapTexture = biomes;
		m_forestTexture = forests;
		m_heightmap = height;
		m_fogmap = exploration;
		m_textureSize = texture_size;
		scale = imageScale;
	}

	public static void DeInitialize()
	{
		m_mapTexture = null;
		m_forestTexture = null;
		m_heightmap = null;
		m_fogmap = null;
	}

	public IEnumerator GenerateOldMap(int graduationHeight)
	{
		Debug.Log((object)(DateTime.Now.ToString() + ": Starting Old Map Generation"));
		output = null;
		yield return GenerateOceanTexture(m_heightmap, clear: false);
		Color32[] oceanTexture = result;
		yield return ReplaceColour32(m_mapTexture, new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue), new Color32((byte)203, (byte)155, (byte)87, byte.MaxValue));
		Color32[] outtex9 = result;
		yield return OverlayTexture(outtex9, oceanTexture);
		outtex9 = result;
		yield return GetSolidColour(new Color32((byte)203, (byte)155, (byte)87, byte.MaxValue));
		Color32[] offYellow = result;
		yield return LerpTextures(outtex9, offYellow);
		outtex9 = result;
		yield return LerpTextures(outtex9, offYellow);
		outtex9 = result;
		yield return LerpTextures(outtex9, offYellow);
		outtex9 = result;
		yield return AddPerlinNoise(outtex9, 128, 16);
		outtex9 = result;
		yield return GenerateContourMap(m_heightmap, graduationHeight, 128);
		Color32[] contours = result;
		yield return OverlayTexture(outtex9, contours);
		outtex9 = result;
		yield return StylizeFog(m_fogmap);
		Color32[] fog = result;
		yield return OverlayTexture(outtex9, fog);
		outtex9 = result;
		yield return SmoothImage(outtex9);
		outtex9 = result;
		output = outtex9;
	}

	public IEnumerator GenerateChartMap(int graduationHeight)
	{
		Debug.Log((object)(DateTime.Now.ToString() + ": Starting Chart Generation"));
		output = null;
		yield return GenerateOceanTexture(m_heightmap, clear: false);
		Color32[] oceanTexture = result;
		yield return ReplaceColour32(m_mapTexture, new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue), new Color32((byte)203, (byte)155, (byte)87, byte.MaxValue));
		Color32[] outtex6 = result;
		yield return OverlayTexture(outtex6, oceanTexture);
		outtex6 = result;
		yield return GetSolidColour(new Color32((byte)203, (byte)155, (byte)87, byte.MaxValue));
		Color32[] offYellow = result;
		yield return LerpTextures(outtex6, offYellow);
		outtex6 = result;
		yield return AddPerlinNoise(outtex6, 128, 16);
		outtex6 = result;
		yield return GenerateContourMap(m_heightmap, graduationHeight, 128);
		Color32[] contours = result;
		yield return OverlayTexture(outtex6, contours);
		outtex6 = result;
		yield return StylizeFog(m_fogmap);
		Color32[] fog = result;
		yield return OverlayTexture(outtex6, fog);
		outtex6 = result;
		output = outtex6;
	}

	public IEnumerator GenerateSatelliteImage()
	{
		Debug.Log((object)(DateTime.Now.ToString() + ": Starting Satellite Generation"));
		output = null;
		yield return GenerateOceanTexture(m_heightmap, clear: true);
		Color32[] oceanTexture2 = result;
		yield return AddPerlinNoise(oceanTexture2, 4, 64);
		oceanTexture2 = result;
		yield return CreateSand();
		yield return ReplaceColour32(result, Color32.op_Implicit(new Color(0.2f, 0.2f, 0.2f)), new Color32((byte)65, (byte)75, (byte)70, byte.MaxValue));
		yield return OverlayTexture(result, oceanTexture2);
		Color32[] outtex5 = result;
		yield return CreateShadowMap(m_heightmap, 23);
		Color32[] shadowmap = result;
		yield return DarkenTextureLinear(outtex5, 20);
		outtex5 = result;
		yield return OverlayTexture(outtex5, shadowmap);
		outtex5 = result;
		yield return StylizeFog(m_fogmap);
		Color32[] fog = result;
		yield return OverlayTexture(outtex5, fog);
		outtex5 = result;
		yield return SmoothImage(outtex5);
		outtex5 = result;
		output = outtex5;
	}

	public IEnumerator GenerateTopographicalMap(int graduationHeight)
	{
		output = null;
		Debug.Log((object)(DateTime.Now.ToString() + ": Starting Topographical Generation"));
		yield return GenerateOceanTexture(m_heightmap, clear: true);
		Color32[] oceanTexture2 = result;
		yield return AddPerlinNoise(oceanTexture2, 4, 64);
		oceanTexture2 = result;
		yield return CreateSand();
		yield return ReplaceColour32(result, Color32.op_Implicit(new Color(0.2f, 0.2f, 0.2f)), new Color32((byte)65, (byte)75, (byte)70, byte.MaxValue));
		yield return OverlayTexture(result, oceanTexture2);
		Color32[] outtex6 = result;
		yield return CreateShadowMap(m_heightmap, 23);
		Color32[] shadowmap = result;
		yield return DarkenTextureLinear(outtex6, 20);
		outtex6 = result;
		yield return GenerateContourMap(m_heightmap, graduationHeight, 128);
		Color32[] contours = result;
		yield return OverlayTexture(outtex6, shadowmap);
		outtex6 = result;
		yield return OverlayTexture(outtex6, contours);
		outtex6 = result;
		yield return StylizeFog(m_fogmap);
		Color32[] fog = result;
		yield return OverlayTexture(outtex6, fog);
		outtex6 = result;
		yield return SmoothImage(outtex6);
		outtex6 = result;
		output = outtex6;
	}

	public IEnumerator GenerateGreyScaleHeightmap()
	{
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//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)
			for (int i = 0; i < m_textureSize * m_textureSize; i++)
			{
				byte r = m_heightmap[i].r;
				output[i] = new Color32(r, r, r, byte.MaxValue);
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
	}

	private IEnumerator OverlayTexture(Color32[] array1, Color32[] array2)
	{
		Color32[] output = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
		Color workingColor;
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_0010: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_textureSize * m_textureSize; i++)
			{
				float a = Color32.op_Implicit(array2[i]).a;
				float a2 = Color32.op_Implicit(array1[i]).a;
				workingColor = Color.Lerp(Color32.op_Implicit(array1[i]), Color32.op_Implicit(array2[i]), a);
				workingColor.a = a + a2;
				if (workingColor.a > 1f)
				{
					workingColor.a = 1f;
				}
				output[i] = Color32.op_Implicit(workingColor);
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator LerpTextures(Color32[] array1, Color32[] array2)
	{
		Color32[] output = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_textureSize * m_textureSize; i++)
			{
				int num = array2[i].a - array1[i].a;
				int num2 = array1[i].a + array2[i].a;
				if (num2 > 255)
				{
					num2 = 255;
				}
				int num3 = ((array1[i].a <= array2[i].a) ? array2[i].a : array1[i].a);
				num3 *= 2;
				float num4 = (float)num / (float)num3 + 0.5f;
				output[i] = Color32.Lerp(array1[i], array2[i], num4);
				output[i].a = (byte)num2;
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator DarkenTextureLinear(Color32[] array, byte d)
	{
		Color32[] output = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			for (int i = 0; i < m_textureSize * m_textureSize; i++)
			{
				int num = array[i].r - d;
				if (num < 0)
				{
					num = 0;
				}
				output[i].r = (byte)num;
				num = array[i].g - d;
				if (num < 0)
				{
					num = 0;
				}
				output[i].g = (byte)num;
				num = array[i].b - d;
				if (num < 0)
				{
					num = 0;
				}
				output[i].b = (byte)num;
				output[i].a = array[i].a;
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator CreateShadowMap(Color32[] heightmap, byte intensity)
	{
		yield return CreateHardShadowMap(heightmap, intensity);
		Color32[] hardshadows = result;
		yield return CreateSoftShadowMap(heightmap);
		Color32[] softshadows = result;
		yield return LerpTextures(softshadows, hardshadows);
	}

	private IEnumerator CreateSoftShadowMap(Color32[] input)
	{
		Color32[] output = (Color32[])(object)new Color32[input.Length];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_textureSize; i++)
			{
				for (int j = 0; j < m_textureSize; j++)
				{
					int num = ((i < m_textureSize) ? (input[i * m_textureSize + j].r * scale - input[(i + 1) * m_textureSize + j].r * scale) : 0);
					num *= 8;
					byte b = (byte)Math.Abs(num);
					byte b2 = (byte)((num >= 0) ? byte.MaxValue : 0);
					output[i * m_textureSize + j] = new Color32(b2, b2, b2, b);
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator CreateHardShadowMap(Color32[] input, byte intensity)
	{
		Color32[] output = (Color32[])(object)new Color32[input.Length];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			bool[] array = new bool[m_textureSize * m_textureSize];
			for (int i = 0; i < m_textureSize * m_textureSize; i++)
			{
				array[i] = false;
			}
			for (int num = m_textureSize - 1; num > -1; num--)
			{
				for (int j = 0; j < m_textureSize; j++)
				{
					if (!array[num * m_textureSize + j])
					{
						output[num * m_textureSize + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)0);
						for (int k = 1; num - k > 0 && input[num * m_textureSize + j].r * scale > input[(num - k) * m_textureSize + j].r * scale + k * 2; k++)
						{
							array[(num - k) * m_textureSize + j] = true;
						}
					}
					else
					{
						output[num * m_textureSize + j] = new Color32((byte)0, (byte)0, (byte)0, intensity);
					}
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator GenerateOceanTexture(Color32[] input, bool clear)
	{
		Color32 m_oceanColor = new Color32((byte)20, (byte)100, byte.MaxValue, byte.MaxValue);
		new Color32((byte)40, (byte)120, byte.MaxValue, byte.MaxValue);
		Color32[] output = (Color32[])(object)new Color32[input.Length];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_textureSize * m_textureSize; i++)
			{
				if (input[i].b > 0)
				{
					int num = i / m_textureSize;
					num = num / 8 / scale - 128;
					int num2 = i % m_textureSize;
					num2 = num2 / 8 / scale - 128;
					int num3 = num * num / 128 + num2 * num2 / 512;
					if (num < 0)
					{
						m_oceanColor = new Color32((byte)(10 + num3), (byte)(136 - num3 / 4), (byte)193, byte.MaxValue);
					}
					else
					{
						m_oceanColor = new Color32((byte)(10 + num3 / 2), (byte)136, (byte)(193 - num3 / 2), byte.MaxValue);
					}
					if (clear)
					{
						output[i] = m_oceanColor;
						int num4 = input[i].b * 16 + 128;
						if (num4 > 255)
						{
							num4 = 255;
						}
						output[i].a = (byte)num4;
					}
					else
					{
						int num5 = m_oceanColor.r;
						int num6 = m_oceanColor.g;
						int num7 = m_oceanColor.b;
						if (m_heightmap[i].r == 0)
						{
							if (m_heightmap[i].b < 5)
							{
								num5 += 20;
								num6 += 20;
								num7 += 20;
								if (num5 > 255)
								{
									num5 = 255;
								}
								if (num6 > 255)
								{
									num6 = 255;
								}
								if (num7 > 255)
								{
									num7 = 255;
								}
							}
							output[i] = new Color32((byte)num5, (byte)num6, (byte)num7, byte.MaxValue);
						}
						else
						{
							output[i] = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
						}
					}
				}
				else
				{
					output[i] = Color32.op_Implicit(Color.clear);
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator CreateSand()
	{
		Color32[] output = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_textureSize; i++)
			{
				for (int j = 0; j < m_textureSize; j++)
				{
					if (m_heightmap[i + j * m_textureSize].b > 0)
					{
						int r = m_mapTexture[i + j * m_textureSize].r;
						int g = m_mapTexture[i + j * m_textureSize].g;
						int b = m_mapTexture[i + j * m_textureSize].b;
						if (r != 0 && g != 0 && b != 0)
						{
							output[i + j * m_textureSize] = Color32.op_Implicit(Minimap.instance.m_heathColor);
						}
					}
					else
					{
						output[i + j * m_textureSize] = m_mapTexture[i + j * m_textureSize];
					}
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator GetPerlin(float tightness, byte damping)
	{
		Color32[] array = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_textureSize; i++)
			{
				for (int j = 0; j < m_textureSize; j++)
				{
					float num = Mathf.PerlinNoise((float)i / tightness, (float)j / tightness);
					num = (num - 0.5f) / (float)(int)damping + 0.5f;
					array[i * m_textureSize + j] = Color32.op_Implicit(new Color(num, num, num, 0.2f));
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = array;
	}

	private IEnumerator StylizeFog(Color32[] input)
	{
		yield return GetPerlin(128f * (float)scale, 16);
		Color32[] noise = result;
		Color32[] output = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_0085: 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)
			for (int i = 0; i < m_textureSize * m_textureSize; i++)
			{
				if (input[i].a > 0)
				{
					output[i] = new Color32((byte)(203 + (noise[i].r - 128)), (byte)(155 + (noise[i].g - 128)), (byte)(87 + (noise[i].b - 128)), byte.MaxValue);
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator GenerateContourMap(Color32[] start, int graduations, byte alpha)
	{
		Color32[] input = (Color32[])(object)new Color32[start.Length];
		Color32[] output = (Color32[])(object)new Color32[input.Length];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_textureSize * m_textureSize; i++)
			{
				int num = start[i].r + graduations;
				if (num > 255)
				{
					num = 255;
				}
				if (start[i].b > 0)
				{
					num = 0;
				}
				input[i].r = (byte)num;
			}
			for (int j = 1; j < m_textureSize - 1; j++)
			{
				int num2 = j * m_textureSize;
				for (int k = 1; k < m_textureSize - 1; k++)
				{
					int num3 = num2 + k;
					int num4 = input[num2 + k].r / graduations;
					output[num3] = Color32.op_Implicit(Color.clear);
					for (int l = -1; l < 2; l++)
					{
						int num5 = l * m_textureSize;
						for (int m = -1; m < 2; m++)
						{
							if (l != 0 || m != 0)
							{
								int num6 = num3 + num5 + m;
								int num7 = input[num6].r / graduations;
								if (num7 < num4)
								{
									byte b = alpha;
									if ((num4 - 1) / 5 == (num7 - 1) / 5)
									{
										b /= 2;
									}
									if (num7 == 0)
									{
										b = alpha;
									}
									if (l == 0 || m == 0 || output[num3].a == b)
									{
										output[num3] = new Color32((byte)0, (byte)0, (byte)0, b);
										break;
									}
									output[num3] = new Color32((byte)0, (byte)0, (byte)0, (byte)(b / 2));
								}
							}
						}
					}
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	private IEnumerator AddPerlinNoise(Color32[] input, int tightness, byte damping)
	{
		Color32[] array = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_0020: 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_002a: 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_006c: 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_007c: 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)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < m_textureSize; i++)
			{
				for (int j = 0; j < m_textureSize; j++)
				{
					Color val = Color32.op_Implicit(input[i * m_textureSize + j]);
					float num = Mathf.PerlinNoise((float)i / (float)tightness, (float)j / (float)tightness);
					num = (num - 0.5f) / (float)(int)damping;
					array[i * m_textureSize + j] = Color32.op_Implicit(new Color(val.r + num, val.g + num, val.b + num, val.a));
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = array;
	}

	private IEnumerator GetSolidColour(Color32 TexColour)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		Color32[] array = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = TexColour;
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = array;
	}

	private IEnumerator ReplaceColour32(Color32[] input, Color32 from, Color32 to)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: 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)
		Color32[] output = (Color32[])(object)new Color32[input.Length];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < input.Length; i++)
			{
				if (input[i].r == from.r && input[i].g == from.g && input[i].b == from.b)
				{
					output[i] = to;
				}
				else
				{
					output[i] = input[i];
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	public IEnumerator SmoothImage(Color32[] input)
	{
		Color32[] output = (Color32[])(object)new Color32[input.Length];
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//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_003d: 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_0056: 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_006f: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 1; i < m_textureSize - 1; i++)
			{
				for (int j = 1; j < m_textureSize - 1; j++)
				{
					Color32 val = input[(i - 1) * m_textureSize + j];
					Color32 val2 = input[i * m_textureSize + (j + 1)];
					Color32 val3 = input[(i + 1) * m_textureSize + j];
					Color32 val4 = input[i * m_textureSize + (j - 1)];
					Color32 val5 = Color32.Lerp(val2, val4, 0.5f);
					Color32 val6 = Color32.Lerp(val, val3, 0.5f);
					Color32 val7 = Color32.Lerp(val5, val6, 0.5f);
					output[i * m_textureSize + j] = Color32.Lerp(input[i * m_textureSize + j], val7, 0.5f);
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}

	public IEnumerator FuzzImage(Color32[] input)
	{
		Color32[] output = (Color32[])(object)new Color32[input.Length];
		float tightness = 2048f;
		Thread internalThread = new Thread((ThreadStart)delegate
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			for (int i = scale * 2; i < m_textureSize - scale * 2; i++)
			{
				for (int j = scale * 2; j < m_textureSize - scale * 2; j++)
				{
					float num = Mathf.PerlinNoise((float)i / tightness, (float)j / tightness);
					num -= 0.5f;
					num = num * 4f * (float)scale;
					float num2 = Mathf.PerlinNoise(((float)i + 0.1f) / tightness, (float)j / tightness);
					num2 -= 0.5f;
					num2 = num2 * 4f * (float)scale;
					output[i * m_textureSize + j] = input[(i + (int)num) * m_textureSize + (j + (int)num2)];
				}
			}
		});
		internalThread.Start();
		while (internalThread.IsAlive)
		{
			yield return null;
		}
		result = output;
	}
}
public class SaveUtility
{
	private static int m_textureSize;

	private static int scale;

	private static string intermediatePathFolder;

	private static string worldName;

	public static void SetUtilityVariables(int newTextureSize, int newScale, string newPathFolder, string newWorldName)
	{
		m_textureSize = newTextureSize;
		scale = newScale;
		intermediatePathFolder = newPathFolder;
		worldName = newWorldName;
	}

	public static bool SaveRawData(List<Color32[]> data, string path)
	{
		if (!Directory.Exists(path + intermediatePathFolder))
		{
			if (!Directory.Exists(path))
			{
				return false;
			}
			Directory.CreateDirectory(path + intermediatePathFolder);
		}
		if (data.Count < 1)
		{
			return false;
		}
		int num = m_textureSize * m_textureSize;
		byte[] array = new byte[num * 4 * data.Count];
		int num2 = 0;
		foreach (Color32[] datum in data)
		{
			for (int i = 0; i < num; i++)
			{
				int num3 = i * 4 + num2;
				array[num3] = datum[i].r;
				array[num3 + 1] = datum[i].g;
				array[num3 + 2] = datum[i].b;
				array[num3 + 3] = datum[i].a;
			}
			num2 += num;
		}
		File.WriteAllBytes(path + intermediatePathFolder + "/" + scale + worldName + ".raw", array);
		return true;
	}

	public static bool SaveRawData(Color32[] biomeMap, Color32[] forestMap, Color32[] heightMap, Color32[] fogMap, string path)
	{
		if (!Directory.Exists(path + intermediatePathFolder))
		{
			if (!Directory.Exists(path))
			{
				return false;
			}
			Directory.CreateDirectory(path + intermediatePathFolder);
		}
		int num = m_textureSize * m_textureSize;
		byte[] array = new byte[num * 16];
		for (int i = 0; i < m_textureSize; i++)
		{
			for (int j = 0; j < m_textureSize; j++)
			{
				int num2 = i * m_textureSize + j;
				int num3 = num2 * 4;
				array[num3] = biomeMap[num2].r;
				array[num3 + 1] = biomeMap[num2].g;
				array[num3 + 2] = biomeMap[num2].b;
				array[num3 + 3] = biomeMap[num2].a;
				num3 = (num2 + num) * 4;
				array[num3] = forestMap[num2].r;
				array[num3 + 1] = forestMap[num2].g;
				array[num3 + 2] = forestMap[num2].b;
				array[num3 + 3] = forestMap[num2].a;
				num3 = (num2 + num * 2) * 4;
				array[num3] = heightMap[num2].r;
				array[num3 + 1] = heightMap[num2].g;
				array[num3 + 2] = heightMap[num2].b;
				array[num3 + 3] = heightMap[num2].a;
				num3 = (num2 + num * 3) * 4;
				array[num3] = fogMap[num2].r;
				array[num3 + 1] = fogMap[num2].g;
				array[num3 + 2] = fogMap[num2].b;
				array[num3 + 3] = fogMap[num2].a;
			}
		}
		File.WriteAllBytes(path + intermediatePathFolder + "/" + scale + worldName + ".raw", array);
		return true;
	}

	public static bool LoadRawData(string path, Color32[] mask, out Color32[] m_mapTexture, out Color32[] m_forestTexture, out Color32[] m_heightmap)
	{
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		string path2 = path + intermediatePathFolder + "/" + scale + worldName + ".raw";
		int num = m_textureSize * m_textureSize;
		m_mapTexture = (Color32[])(object)new Color32[num];
		m_forestTexture = (Color32[])(object)new Color32[num];
		m_heightmap = (Color32[])(object)new Color32[num];
		if (!File.Exists(path2))
		{
			return false;
		}
		byte[] array = File.ReadAllBytes(path2);
		if (array.Length != num * 16)
		{
			return false;
		}
		for (int i = 0; i < m_textureSize; i++)
		{
			for (int j = 0; j < m_textureSize; j++)
			{
				int num2 = i * m_textureSize + j;
				if ((float)(int)mask[num2].r == 0f || (float)(int)mask[num2].g == 0f)
				{
					int num3 = num2 * 4;
					m_mapTexture[num2] = new Color32(array[num3], array[num3 + 1], array[num3 + 2], array[num3 + 3]);
					num3 = (num2 + num) * 4;
					m_forestTexture[num2] = new Color32(array[num3], array[num3 + 1], array[num3 + 2], array[num3 + 3]);
					num3 = (num2 + num * 2) * 4;
					m_heightmap[num2] = new Color32(array[num3], array[num3 + 1], array[num3 + 2], array[num3 + 3]);
				}
			}
		}
		return true;
	}
}
namespace MapPrinter;

[BepInPlugin("ASpy.MapPrinter", "MapPrinter", "1.0.4")]
[BepInProcess("valheim.exe")]
public class ValheimMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(WorldGenerator), "Initialize")]
	private class WorldGen_Patch
	{
		private static void Prefix(World world)
		{
			game_world = world;
		}
	}

	[HarmonyPatch(typeof(MapTable), "OnRead", new Type[]
	{
		typeof(Switch),
		typeof(Humanoid),
		typeof(ItemData),
		typeof(bool)
	})]
	private class MapTable_Patch
	{
		private static void Postfix()
		{
			instance.ConfigUpdate();
			if (filePath.Value == "")
			{
				path = Utils.GetSaveDataPath((FileSource)1) + "/screenshots/";
			}
			else
			{
				path = filePath.Value;
			}
			if (path[path.Length - 1] != '/' && path[path.Length - 1] != '\\')
			{
				path += "/";
			}
			Debug.Log((object)("Saves going to " + path));
			m_waterLevel = (int)ZoneSystem.instance.m_waterLevel;
			scale = imageScale.Value;
			if (speculation.Value.Equals("Full"))
			{
				partialSpeculation = true;
				fullSpeculation = true;
			}
			else if (speculation.Value.Equals("Partial"))
			{
				partialSpeculation = true;
				fullSpeculation = false;
			}
			else
			{
				partialSpeculation = false;
				fullSpeculation = false;
			}
			m_textureSize = Minimap.instance.m_textureSize * scale;
			if (!instance.maker.working)
			{
				((MonoBehaviour)instance).StartCoroutine(instance.maker.Go());
			}
		}
	}

	private class MapPrinter : MonoBehaviour
	{
		public bool working = false;

		public IEnumerator Go()
		{
			working = true;
			SaveUtility.SetUtilityVariables(m_textureSize, scale, intermediatePathFolder, game_world.m_name);
			MessageHud.instance.ShowMessage((MessageType)2, "Drawing the map...", 1, (Sprite)null);
			Debug.Log((object)(DateTime.Now.ToString() + ": Starting Map Query"));
			yield return GetData();
			if (partialSpeculation || fullSpeculation)
			{
				Debug.Log((object)(DateTime.Now.ToString() + ": Starting Speculation"));
				yield return Speculate();
				Debug.Log((object)status);
			}
			MapImageGeneration.Initialize(m_mapTexture, m_forestTexture, m_heightmap, m_fogmap, m_textureSize, scale);
			MapImageGeneration imageGen = new MapImageGeneration();
			if (birdsEye.Value)
			{
				yield return imageGen.GenerateSatelliteImage();
				SaveTextureToPNG(path, "BirdsEyeMap of " + game_world.m_name, imageGen.output);
			}
			if (topo.Value)
			{
				yield return imageGen.GenerateTopographicalMap(8);
				SaveTextureToPNG(path, "TopoMap of " + game_world.m_name, imageGen.output);
			}
			if (chart.Value)
			{
				yield return imageGen.GenerateChartMap(10 / scale);
				SaveTextureToPNG(path, "Chart of " + game_world.m_name, imageGen.output);
			}
			if (old.Value)
			{
				yield return imageGen.GenerateOldMap(8);
				SaveTextureToPNG(path, "OldChart of " + game_world.m_name, imageGen.output);
			}
			if (heightmap.Value)
			{
				yield return imageGen.GenerateGreyScaleHeightmap();
				SaveTextureToPNG(path, "Heightmap of " + game_world.m_name, imageGen.output);
			}
			Debug.Log((object)"Finished Map Draw");
			MessageHud.instance.ShowMessage((MessageType)2, "Map is ready", 1, (Sprite)null);
			MessageHud.instance.ShowMessage((MessageType)1, "Map saved to " + path, 1, (Sprite)null);
			MapImageGeneration.DeInitialize();
			m_mapTexture = null;
			m_forestTexture = null;
			m_heightmap = null;
			m_fogmap = null;
			working = false;
		}

		private static void GetFog()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			m_fogmap = (Color32[])(object)new Color32[m_textureSize * m_textureSize];
			Texture2D val = (Texture2D)((Graphic)Minimap.instance.m_mapImageLarge).material.GetTexture("_FogTex");
			for (int i = 0; i < m_textureSize; i++)
			{
				for (int j = 0; j < m_textureSize; j++)
				{
					Color32 val2 = Color32.op_Implicit(val.GetPixel(j / scale, i / scale));
					if ((float)(int)val2.r != 0f && (float)(int)val2.g != 0f)
					{
						m_fogmap[i * m_textureSize + j] = Color32.op_Implicit(Color.gray);
					}
					else
					{
						m_fogmap[i * m_textureSize + j] = Color32.op_Implicit(Color.clear);
					}
				}
			}
		}

		private IEnumerator GetData()
		{
			debugLog = "";
			Thread internalThread = new Thread((ThreadStart)delegate
			{
				GetFog();
				bool flag = false;
				DIYMapQuery(out m_mapTexture, out m_forestTexture, out m_heightmap, m_fogmap);
			});
			internalThread.Start();
			while (internalThread.IsAlive)
			{
				if (debugLog != "")
				{
					Debug.Log((object)debugLog);
					debugLog = "";
				}
				yield return null;
			}
			if (debugLog != "")
			{
				Debug.Log((object)debugLog);
				debugLog = "";
			}
		}

		private static void DIYMapQuery(out Color32[] biomeMap, out Color32[] forestMap, out Color32[] heightMap, Color32[] mask)
		{
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			float num = Minimap.instance.m_pixelSize / (float)scale;
			int num2 = m_textureSize / 2;
			float num3 = num / 2f;
			int num4 = m_textureSize * m_textureSize;
			biomeMap = (Color32[])(object)new Color32[num4];
			forestMap = (Color32[])(object)new Color32[num4];
			heightMap = (Color32[])(object)new Color32[num4];
			heightBytes = new int[m_textureSize * m_textureSize];
			Color val = default(Color);
			for (int i = 0; i < m_textureSize; i++)
			{
				for (int j = 0; j < m_textureSize; j++)
				{
					if ((float)(int)mask[i * m_textureSize + j].r != 0f && (float)(int)mask[i * m_textureSize + j].g != 0f)
					{
						continue;
					}
					float num5 = (float)(j - num2) * num + num3;
					float num6 = (float)(i - num2) * num + num3;
					Biome biome = WorldGenerator.instance.GetBiome(num5, num6, 0.02f, false);
					float biomeHeight = WorldGenerator.instance.GetBiomeHeight(biome, num5, num6, ref val, false);
					forestMap[i * m_textureSize + j] = Color32.op_Implicit(GetMaskColor(num5, num6, biomeHeight, biome));
					if (biomeHeight > abyss_depth)
					{
						float num7 = biomeHeight - (float)m_waterLevel;
						heightBytes[i * m_textureSize + j] = (int)num7;
						if (num7 > 0f)
						{
							heightMap[i * m_textureSize + j] = Color32.op_Implicit(new Color(num7 / 512f, 0f, 0f));
						}
						else
						{
							heightMap[i * m_textureSize + j] = Color32.op_Implicit(new Color(0f, 0f, num7 / -256f));
						}
						biomeMap[i * m_textureSize + j] = Color32.op_Implicit(GetPixelColor(biome, biomeHeight));
					}
					else
					{
						biomeMap[i * m_textureSize + j] = Color32.op_Implicit(Color.black);
					}
				}
			}
		}

		private static void CreateIntermediateData(string path)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			int num = m_textureSize * m_textureSize;
			Color32[] array = (Color32[])(object)new Color32[num];
			Color32[] biomeMap = (Color32[])(object)new Color32[num];
			Color32[] forestMap = (Color32[])(object)new Color32[num];
			Color32[] heightMap = (Color32[])(object)new Color32[num];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Color32.op_Implicit(Color.clear);
			}
			DIYMapQuery(out biomeMap, out forestMap, out heightMap, array);
			List<Color32[]> list = new List<Color32[]>();
			list.Add(biomeMap);
			list.Add(forestMap);
			list.Add(heightMap);
			list.Add(m_fogmap);
			if (!SaveUtility.SaveRawData(list, path))
			{
				debugLog += "Intermediate Data failed to save!\n";
			}
		}

		private IEnumerator Speculate()
		{
			status = "\n";
			Thread internalThread = new Thread((ThreadStart)delegate
			{
				//IL_062b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0630: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0218: Unknown result type (might be due to invalid IL or missing references)
				//IL_021d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0222: Unknown result type (might be due to invalid IL or missing references)
				//IL_027a: Unknown result type (might be due to invalid IL or missing references)
				//IL_027f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0284: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0420: Unknown result type (might be due to invalid IL or missing references)
				//IL_0425: Unknown result type (might be due to invalid IL or missing references)
				//IL_042a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0940: Unknown result type (might be due to invalid IL or missing references)
				//IL_0945: Unknown result type (might be due to invalid IL or missing references)
				//IL_0951: Unknown result type (might be due to invalid IL or missing references)
				//IL_0956: Unknown result type (might be due to invalid IL or missing references)
				//IL_095b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0986: Unknown result type (might be due to invalid IL or missing references)
				//IL_0990: Unknown result type (might be due to invalid IL or missing references)
				//IL_0995: Unknown result type (might be due to invalid IL or missing references)
				//IL_0490: Unknown result type (might be due to invalid IL or missing references)
				//IL_0495: Unknown result type (might be due to invalid IL or missing references)
				//IL_049a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0500: Unknown result type (might be due to invalid IL or missing references)
				//IL_0505: Unknown result type (might be due to invalid IL or missing references)
				//IL_050a: Unknown result type (might be due to invalid IL or missing references)
				//IL_09fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a00: Unknown result type (might be due to invalid IL or missing references)
				//IL_09d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_09dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0860: Unknown result type (might be due to invalid IL or missing references)
				//IL_0865: Unknown result type (might be due to invalid IL or missing references)
				int textureSize = m_textureSize;
				int num = textureSize * textureSize;
				bool[] array = new bool[textureSize * textureSize];
				for (int i = 0; i < num; i++)
				{
					array[i] = false;
				}
				List<int[]> list = new List<int[]>();
				List<bool> list2 = new List<bool>();
				int[] array2 = new int[num];
				for (int j = 0; j < textureSize; j++)
				{
					for (int k = 0; k < textureSize; k++)
					{
						if (!array[j * textureSize + k])
						{
							array[j * textureSize + k] = true;
							if (!(Color32.op_Implicit(m_fogmap[j * textureSize + k]) == Color.clear))
							{
								int num2 = j;
								int num3 = k;
								array2[0] = num2 * textureSize + num3;
								int num4 = 0;
								bool flag = false;
								bool flag2 = false;
								bool item = false;
								for (int l = 1; l < num; l++)
								{
									bool flag3 = false;
									for (int m = 0; m < 4; m++)
									{
										if (m == 3)
										{
											flag2 = true;
											break;
										}
										switch (num4)
										{
										case 0:
											if (num3 == textureSize - 1)
											{
												item = true;
											}
											else
											{
												int num5 = num2 * textureSize + num3 + 1;
												if (!array[num5])
												{
													array[num5] = true;
													if (Color32.op_Implicit(m_fogmap[num5]) != Color.clear)
													{
														flag3 = true;
														num3++;
													}
												}
											}
											break;
										case 1:
											if (num2 == textureSize - 1)
											{
												item = true;
											}
											else
											{
												int num5 = (num2 + 1) * textureSize + num3;
												if (!array[num5])
												{
													array[num5] = true;
													if (Color32.op_Implicit(m_fogmap[num5]) != Color.clear)
													{
														flag3 = true;
														num2++;
													}
												}
											}
											break;
										case 2:
											if (num3 == 0)
											{
												item = true;
											}
											else
											{
												int num5 = num2 * textureSize + num3 - 1;
												if (!array[num5])
												{
													array[num5] = true;
													if (Color32.op_Implicit(m_fogmap[num5]) != Color.clear)
													{
														flag3 = true;
														num3--;
													}
												}
											}
											break;
										case 3:
											if (num2 == 0)
											{
												item = true;
											}
											else
											{
												int num5 = (num2 - 1) * textureSize + num3;
												if (!array[num5])
												{
													array[num5] = true;
													if (Color32.op_Implicit(m_fogmap[num5]) != Color.clear)
													{
														flag3 = true;
														num2--;
													}
												}
											}
											break;
										default:
											status = status + " ERROR: Search Algorithm d value got lost at " + num3 + ", " + num2 + ".\n";
											return;
										}
										if (flag3)
										{
											num4--;
											if (num4 == -1)
											{
												num4 = 3;
											}
											array2[l] = num2 * textureSize + num3;
											flag3 = false;
											break;
										}
										num4++;
										if (num4 == 4)
										{
											num4 = 0;
										}
									}
									if (flag2)
									{
										for (int num6 = l - 1; num6 >= 0; num6--)
										{
											num2 = array2[num6] / textureSize;
											num3 = array2[num6] % textureSize;
											if (num3 == textureSize - 1)
											{
												item = true;
											}
											else
											{
												int num7 = array2[num6] + 1;
												if (!array[num7])
												{
													array[num7] = true;
													if (Color32.op_Implicit(m_fogmap[num7]) != Color.clear)
													{
														num4 = 3;
														num3++;
														array2[l] = num2 * textureSize + num3;
														flag2 = false;
														break;
													}
												}
											}
											if (num2 == textureSize - 1)
											{
												item = true;
											}
											else
											{
												int num8 = array2[num6] + textureSize;
												if (!array[num8])
												{
													array[num8] = true;
													if (Color32.op_Implicit(m_fogmap[num8]) != Color.clear)
													{
														num4 = 0;
														num2++;
														array2[l] = num2 * textureSize + num3;
														flag2 = false;
														break;
													}
												}
											}
											if (num3 == 0)
											{
												item = true;
											}
											else
											{
												int num9 = array2[num6] - 1;
												if (!array[num9])
												{
													array[num9] = true;
													if (Color32.op_Implicit(m_fogmap[num9]) != Color.clear)
													{
														num4 = 1;
														num3--;
														array2[l] = num2 * textureSize + num3;
														flag2 = false;
														break;
													}
												}
											}
											if (num2 == 0)
											{
												item = true;
											}
											else
											{
												int num10 = array2[num6] - textureSize;
												if (!array[num10])
												{
													array[num10] = true;
													if (Color32.op_Implicit(m_fogmap[num10]) != Color.clear)
													{
														num4 = 2;
														num2--;
														array2[l] = num2 * textureSize + num3;
														flag2 = false;
														break;
													}
												}
											}
											if (num6 == 0)
											{
												flag = true;
											}
										}
										if (flag)
										{
											int[] array3 = new int[l];
											for (int n = 0; n < l; n++)
											{
												array3[n] = array2[n];
											}
											list.Add(array3);
											list2.Add(item);
											break;
										}
									}
									if (l == num - 1)
									{
										status += " ERROR: Speculation Algorithm got lost and ran too long. \n";
										return;
									}
								}
							}
						}
					}
				}
				int num11 = 10;
				Color32[] array4 = (Color32[])(object)new Color32[num11];
				for (int num12 = 0; num12 < num11; num12++)
				{
					array4[num12] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
				}
				if (fullSpeculation)
				{
				}
				if (partialSpeculation)
				{
					for (int num13 = 0; num13 < list.Count; num13++)
					{
						if (!list2[num13])
						{
							int[] array5 = list[num13];
							foreach (int num15 in array5)
							{
								int num16 = num15 / textureSize;
								int num17 = num15 % textureSize;
								m_fogmap[num15] = Color32.op_Implicit(Color.clear);
								int[] array6 = new int[num11];
								for (int num18 = 0; num18 < num11; num18++)
								{
									array6[num18] = 0;
								}
								int num19 = 0;
								int num20 = 0;
								for (int num21 = -1; num21 <= 1; num21++)
								{
									int num22 = num16 + num21;
									if (num22 <= m_textureSize && num22 >= 0)
									{
										for (int num23 = -1; num23 <= 1; num23++)
										{
											if (num23 != 0 || num21 != 0)
											{
												int num24 = num17 + num23;
												if (num24 <= m_textureSize && num24 >= 0)
												{
													int num25 = num22 * m_textureSize + num24;
													if (m_mapTexture[num25].a != 0)
													{
														bool flag4 = false;
														for (int num26 = 0; num26 < num11; num26++)
														{
															if (m_mapTexture[num25].r == array4[num26].r && m_mapTexture[num25].g == array4[num26].g && m_mapTexture[num25].b == array4[num26].b)
															{
																array6[num26]++;
																flag4 = true;
															}
														}
														if (!flag4)
														{
															for (int num27 = 0; num27 < num11; num27++)
															{
																if (array4[num27].a == 0)
																{
																	array4[num27] = m_mapTexture[num25];
																	array6[num27]++;
																	break;
																}
															}
														}
														num19 = num19 + m_heightmap[num25].r - m_heightmap[num25].b;
														num20++;
													}
												}
											}
										}
									}
								}
								int num28 = 0;
								int num29 = 0;
								for (int num30 = 0; num30 < num11; num30++)
								{
									if (array6[num30] > num28)
									{
										num29 = num30;
										num28 = array6[num30];
									}
								}
								int num31 = num16 * m_textureSize + num17;
								m_mapTexture[num31] = array4[num29];
								if (CompareColours(m_mapTexture[num31], Color32.op_Implicit(Color.blue)) && num19 > -30)
								{
									num19 = -30;
								}
								if (CompareColours(m_mapTexture[num31], Color32.op_Implicit(Minimap.instance.m_swampColor)) && num19 > 1)
								{
									num19 = 1;
								}
								if (num19 >= 0)
								{
									m_heightmap[num31] = new Color32((byte)(num19 / num20), (byte)0, (byte)0, byte.MaxValue);
								}
								else
								{
									m_heightmap[num31] = new Color32((byte)0, (byte)0, (byte)(num19 * -1 / num20), byte.MaxValue);
								}
							}
						}
					}
				}
			});
			internalThread.Start();
			while (internalThread.IsAlive)
			{
				yield return null;
			}
		}

		private static void SaveTextureToPNG(string path, string filename, Texture2D toSave)
		{
			Debug.Log((object)("Writing " + path + filename + ".png"));
			File.WriteAllBytes(path + filename + ".png", ImageConversion.EncodeToPNG(toSave));
		}

		private static void SaveTextureToPNG(string path, string filename, Color32[] toSave)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Texture2D val = new Texture2D(m_textureSize, m_textureSize);
			val.SetPixels32(toSave);
			Debug.Log((object)("Writing " + path + filename + ".png"));
			File.WriteAllBytes(path + filename + ".png", ImageConversion.EncodeToPNG(val));
			Object.Destroy((Object)(object)val);
		}

		private static Color GetPixelColor(Biome biome, float height)
		{
			//IL_0018: 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_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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_000d: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			//IL_0021: 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_0039: Expected I4, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Invalid comparison between Unknown and I4
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if (height < abyss_depth)
			{
				return Color.black;
			}
			if ((int)biome <= 16)
			{
				switch (biome - 1)
				{
				default:
					if ((int)biome != 8)
					{
						if ((int)biome != 16)
						{
							break;
						}
						return Minimap.instance.m_heathColor;
					}
					return Minimap.instance.m_blackforestColor;
				case 0:
					return Minimap.instance.m_meadowsColor;
				case 1:
					return Minimap.instance.m_swampColor;
				case 3:
					return Minimap.instance.m_mountainColor;
				case 2:
					break;
				}
			}
			else if ((int)biome <= 64)
			{
				if ((int)biome == 32)
				{
					return Minimap.instance.m_ashlandsColor;
				}
				if ((int)biome == 64)
				{
					return Minimap.instance.m_deepnorthColor;
				}
			}
			else
			{
				if ((int)biome == 256)
				{
					return Color.blue;
				}
				if ((int)biome == 512)
				{
					return new Color(0.2f, 0.2f, 0.2f);
				}
			}
			return Color.black;
		}

		private static Color GetMaskColor(float wx, float wy, float height, Biome biome)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Invalid comparison between Unknown and I4
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_006a: Invalid comparison between Unknown and I4
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Invalid comparison between Unknown and I4
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Invalid comparison between Unknown and I4
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Invalid comparison between Unknown and I4
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			((Color)(ref result))..ctor(0f, 0f, 0f, 0f);
			Color result2 = default(Color);
			((Color)(ref result2))..ctor(1f, 0f, 0f, 0f);
			if (height < (float)m_waterLevel)
			{
				return result;
			}
			if ((int)biome <= 8)
			{
				if ((int)biome == 1)
				{
					if (!WorldGenerator.InForest(new Vector3(wx, 0f, wy)))
					{
						return result;
					}
					return result2;
				}
				if ((int)biome == 8)
				{
					goto IL_00c6;
				}
			}
			else
			{
				if ((int)biome == 16)
				{
					if (!(WorldGenerator.GetForestFactor(new Vector3(wx, 0f, wy)) < 0.8f))
					{
						return result;
					}
					return result2;
				}
				if ((int)biome == 512)
				{
					goto IL_00c6;
				}
			}
			return result;
			IL_00c6:
			return result2;
		}

		private static bool CompareColours(Color32 color1, Color32 color2)
		{
			//IL_0001: 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_000f: 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_001d: 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)
			if (color1.r == color2.r && color1.g == color2.g && color1.b == color2.b)
			{
				return true;
			}
			return false;
		}
	}

	private readonly Harmony harmony = new Harmony("ASpy.MapPrinter");

	private static ConfigEntry<string> filePath;

	private static ConfigEntry<bool> birdsEye;

	private static ConfigEntry<bool> topo;

	private static ConfigEntry<bool> old;

	private static ConfigEntry<bool> chart;

	private static ConfigEntry<bool> heightmap;

	private static ConfigEntry<int> imageScale;

	private static ConfigEntry<string> speculation;

	public static Minimap game_map;

	public static World game_world;

	public static float abyss_depth = -100f;

	private static int m_textureSize;

	private static int scale;

	private static bool partialSpeculation;

	private static bool fullSpeculation;

	private static int m_waterLevel;

	private static Color32[] m_mapTexture;

	private static Color32[] m_forestTexture;

	private static Color32[] m_heightmap;

	private static Color32[] m_fogmap;

	private static int[] heightBytes;

	private MapPrinter maker;

	private static ValheimMod instance;

	private static string status;

	private static string debugLog = "";

	private static string path;

	private static string intermediatePath;

	private static string intermediatePathFolder = "/MapPrinter";

	private static string debugpath = "C:/Users/Justin/Desktop/Valheim Stuff/Test/";

	private void Awake()
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		ConfigInit();
		harmony.PatchAll();
		instance = this;
		maker = new MapPrinter();
		if (WorldGenerator.instance != null)
		{
			WorldGenerator obj = WorldGenerator.instance;
			Type typeFromHandle = typeof(WorldGenerator);
			FieldInfo field = typeFromHandle.GetField("m_world", BindingFlags.Instance | BindingFlags.NonPublic);
			game_world = (World)field.GetValue(obj);
		}
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	private void ConfigInit()
	{
		filePath = ((BaseUnityPlugin)this).Config.Bind<string>("General", "File path", "", "File path to use");
		birdsEye = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Birds Eye", false, "Get a Birds Eye View PNG");
		topo = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Topographical Map", false, "Get Birds Eye View PNG with Topographical Lines");
		chart = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Chart", true, "Get a flat Topographical PNG");
		old = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Old Map", false, "Get a chart with a couple Centuries on it");
		heightmap = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Heightmap", false, "Greyscale heightmap");
		imageScale = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Map Scale", 1, "Scale of map image. ***USE CAUTION***. Integers only, values 1, 2 or 3 recommmended.");
		speculation = ((BaseUnityPlugin)this).Config.Bind<string>("General", "FogFill", "Partial", "Fill unexplored regions with *FAKE* data. *Partial* fills circumnavigated areas, *Full* does the same currently.");
	}

	private void ConfigUpdate()
	{
		((BaseUnityPlugin)this).Config.Reload();
		filePath = ((BaseUnityPlugin)this).Config.Bind<string>("General", "File path", "", "File path to use");
		birdsEye = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Birds Eye", false, "Get a Birds Eye View PNG");
		topo = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Topographical Map", false, "Get Birds Eye View PNG with Topographical Lines");
		chart = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Chart", true, "Get a flat Topographical PNG");
		old = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Old Map", false, "Get a chart with a couple Centuries on it");
		heightmap = ((BaseUnityPlugin)this).Config.Bind<bool>("Image Selection", "Heightmap", false, "Greyscale heightmap");
		imageScale = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Map Scale", 1, "Scale of map image. ***USE CAUTION***. Integers only, values 1, 2 or 3 recommmended.");
		speculation = ((BaseUnityPlugin)this).Config.Bind<string>("General", "FogFill", "Partial", "Fill unexplored regions with *FAKE* data. *Partial* fills circumnavigated areas, *Full* does the same currently.");
	}
}