Decompiled source of Madys MiniMap v1.1.0

BepInEx\plugins\StbImageSharp.dll

Decompiled 15 hours 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.Security;
using System.Security.Permissions;
using System.Threading;
using StbImageSharp.Hebron.Runtime;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("StbImageSharpTeam")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("C# port of the stb_image.h")]
[assembly: AssemblyFileVersion("2.30.16.0")]
[assembly: AssemblyInformationalVersion("2.30.16+125af70cb557033f2c46aec8e82eaaf72ac49817")]
[assembly: AssemblyProduct("StbImageSharp")]
[assembly: AssemblyTitle("StbImageSharp")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.30.16.0")]
[module: UnverifiableCode]
namespace StbImageSharp
{
	public class AnimatedFrameResult : ImageResult
	{
		public int DelayInMs { get; set; }
	}
	internal class AnimatedGifEnumerator : IEnumerator<AnimatedFrameResult>, IEnumerator, IDisposable
	{
		private readonly StbImage.stbi__context _context;

		private StbImage.stbi__gif _gif;

		private readonly ColorComponents _colorComponents;

		public ColorComponents ColorComponents => _colorComponents;

		public AnimatedFrameResult Current { get; private set; }

		object IEnumerator.Current => Current;

		public AnimatedGifEnumerator(Stream input, ColorComponents colorComponents)
		{
			if (input == null)
			{
				throw new ArgumentNullException("input");
			}
			_context = new StbImage.stbi__context(input);
			if (StbImage.stbi__gif_test(_context) == 0)
			{
				throw new Exception("Input stream is not GIF file.");
			}
			_gif = new StbImage.stbi__gif();
			_colorComponents = colorComponents;
		}

		public void Dispose()
		{
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		public unsafe bool MoveNext()
		{
			int num = default(int);
			byte b = default(byte);
			byte* ptr = StbImage.stbi__gif_load_next(_context, _gif, &num, (int)ColorComponents, &b);
			if (ptr == null)
			{
				return false;
			}
			if (Current == null)
			{
				Current = new AnimatedFrameResult
				{
					Width = _gif.w,
					Height = _gif.h,
					SourceComp = (ColorComponents)num,
					Comp = ((ColorComponents == ColorComponents.Default) ? ((ColorComponents)num) : ColorComponents)
				};
				Current.Data = new byte[Current.Width * Current.Height * (int)Current.Comp];
			}
			Current.DelayInMs = _gif.delay;
			Marshal.Copy(new IntPtr(ptr), Current.Data, 0, Current.Data.Length);
			return true;
		}

		public void Reset()
		{
			throw new NotImplementedException();
		}

		~AnimatedGifEnumerator()
		{
			Dispose(disposing: false);
		}

		protected unsafe virtual void Dispose(bool disposing)
		{
			if (_gif != null)
			{
				if (_gif._out_ != null)
				{
					CRuntime.free(_gif._out_);
					_gif._out_ = null;
				}
				if (_gif.history != null)
				{
					CRuntime.free(_gif.history);
					_gif.history = null;
				}
				if (_gif.background != null)
				{
					CRuntime.free(_gif.background);
					_gif.background = null;
				}
				_gif = null;
			}
		}
	}
	internal class AnimatedGifEnumerable : IEnumerable<AnimatedFrameResult>, IEnumerable
	{
		private readonly Stream _input;

		private readonly ColorComponents _colorComponents;

		public ColorComponents ColorComponents => _colorComponents;

		public AnimatedGifEnumerable(Stream input, ColorComponents colorComponents)
		{
			_input = input;
			_colorComponents = colorComponents;
		}

		public IEnumerator<AnimatedFrameResult> GetEnumerator()
		{
			return new AnimatedGifEnumerator(_input, ColorComponents);
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
	public enum ColorComponents
	{
		Default,
		Grey,
		GreyAlpha,
		RedGreenBlue,
		RedGreenBlueAlpha
	}
	public struct ImageInfo
	{
		public int Width;

		public int Height;

		public ColorComponents ColorComponents;

		public int BitsPerChannel;

		public unsafe static ImageInfo? FromStream(Stream stream)
		{
			StbImage.stbi__context s = new StbImage.stbi__context(stream);
			bool flag = StbImage.stbi__is_16_main(s) == 1;
			StbImage.stbi__rewind(s);
			int width = default(int);
			int height = default(int);
			int colorComponents = default(int);
			int num = StbImage.stbi__info_main(s, &width, &height, &colorComponents);
			StbImage.stbi__rewind(s);
			if (num == 0)
			{
				return null;
			}
			return new ImageInfo
			{
				Width = width,
				Height = height,
				ColorComponents = (ColorComponents)colorComponents,
				BitsPerChannel = (flag ? 16 : 8)
			};
		}
	}
	public class ImageResult
	{
		public int Width { get; set; }

		public int Height { get; set; }

		public ColorComponents SourceComp { get; set; }

		public ColorComponents Comp { get; set; }

		public byte[] Data { get; set; }

		internal unsafe static ImageResult FromResult(byte* result, int width, int height, ColorComponents comp, ColorComponents req_comp)
		{
			if (result == null)
			{
				throw new InvalidOperationException(StbImage.stbi__g_failure_reason);
			}
			ImageResult imageResult = new ImageResult
			{
				Width = width,
				Height = height,
				SourceComp = comp,
				Comp = ((req_comp == ColorComponents.Default) ? comp : req_comp)
			};
			imageResult.Data = new byte[width * height * (int)imageResult.Comp];
			Marshal.Copy(new IntPtr(result), imageResult.Data, 0, imageResult.Data.Length);
			return imageResult;
		}

		public unsafe static ImageResult FromStream(Stream stream, ColorComponents requiredComponents = ColorComponents.Default)
		{
			byte* ptr = null;
			try
			{
				int width = default(int);
				int height = default(int);
				int comp = default(int);
				ptr = StbImage.stbi__load_and_postprocess_8bit(new StbImage.stbi__context(stream), &width, &height, &comp, (int)requiredComponents);
				return FromResult(ptr, width, height, (ColorComponents)comp, requiredComponents);
			}
			finally
			{
				if (ptr != null)
				{
					CRuntime.free(ptr);
				}
			}
		}

		public static ImageResult FromMemory(byte[] data, ColorComponents requiredComponents = ColorComponents.Default)
		{
			using MemoryStream stream = new MemoryStream(data);
			return FromStream(stream, requiredComponents);
		}

		public static IEnumerable<AnimatedFrameResult> AnimatedGifFramesFromStream(Stream stream, ColorComponents requiredComponents = ColorComponents.Default)
		{
			return new AnimatedGifEnumerable(stream, requiredComponents);
		}
	}
	public class ImageResultFloat
	{
		public int Width { get; set; }

		public int Height { get; set; }

		public ColorComponents SourceComp { get; set; }

		public ColorComponents Comp { get; set; }

		public float[] Data { get; set; }

		internal unsafe static ImageResultFloat FromResult(float* result, int width, int height, ColorComponents comp, ColorComponents req_comp)
		{
			if (result == null)
			{
				throw new InvalidOperationException(StbImage.stbi__g_failure_reason);
			}
			ImageResultFloat imageResultFloat = new ImageResultFloat
			{
				Width = width,
				Height = height,
				SourceComp = comp,
				Comp = ((req_comp == ColorComponents.Default) ? comp : req_comp)
			};
			imageResultFloat.Data = new float[width * height * (int)imageResultFloat.Comp];
			Marshal.Copy(new IntPtr(result), imageResultFloat.Data, 0, imageResultFloat.Data.Length);
			return imageResultFloat;
		}

		public unsafe static ImageResultFloat FromStream(Stream stream, ColorComponents requiredComponents = ColorComponents.Default)
		{
			float* ptr = null;
			try
			{
				int width = default(int);
				int height = default(int);
				int comp = default(int);
				ptr = StbImage.stbi__loadf_main(new StbImage.stbi__context(stream), &width, &height, &comp, (int)requiredComponents);
				return FromResult(ptr, width, height, (ColorComponents)comp, requiredComponents);
			}
			finally
			{
				if (ptr != null)
				{
					CRuntime.free(ptr);
				}
			}
		}

		public static ImageResultFloat FromMemory(byte[] data, ColorComponents requiredComponents = ColorComponents.Default)
		{
			using MemoryStream stream = new MemoryStream(data);
			return FromStream(stream, requiredComponents);
		}
	}
	public static class StbImage
	{
		public class stbi__context
		{
			private readonly Stream _stream;

			public byte[] _tempBuffer;

			public int img_n;

			public int img_out_n;

			public uint img_x;

			public uint img_y;

			public Stream Stream => _stream;

			public stbi__context(Stream stream)
			{
				if (stream == null)
				{
					throw new ArgumentNullException("stream");
				}
				_stream = stream;
			}
		}

		public struct stbi__bmp_data
		{
			public int bpp;

			public int offset;

			public int hsz;

			public uint mr;

			public uint mg;

			public uint mb;

			public uint ma;

			public uint all_a;

			public int extra_read;
		}

		public struct stbi__result_info
		{
			public int bits_per_channel;

			public int num_channels;

			public int channel_order;
		}

		public class stbi__gif
		{
			public unsafe byte* _out_;

			public unsafe byte* background;

			public int bgindex;

			public stbi__gif_lzw[] codes = new stbi__gif_lzw[8192];

			public byte[][] color_table;

			public int cur_x;

			public int cur_y;

			public int delay;

			public int eflags;

			public int flags;

			public int h;

			public unsafe byte* history;

			public int lflags;

			public int line_size;

			public byte[][] lpal = Utility.CreateArray<byte>(256, 4);

			public int max_x;

			public int max_y;

			public byte[][] pal = Utility.CreateArray<byte>(256, 4);

			public int parse;

			public int ratio;

			public int start_x;

			public int start_y;

			public int step;

			public int transparent;

			public int w;
		}

		public struct stbi__gif_lzw
		{
			public short prefix;

			public byte first;

			public byte suffix;
		}

		public unsafe delegate void delegate0(byte* arg0, int arg1, short* arg2);

		public unsafe delegate void delegate1(byte* arg0, byte* arg1, byte* arg2, byte* arg3, int arg4, int arg5);

		public unsafe delegate byte* delegate2(byte* arg0, byte* arg1, byte* arg2, int arg3, int arg4);

		public struct stbi__huffman
		{
			public unsafe fixed byte fast[512];

			public unsafe fixed ushort code[256];

			public unsafe fixed byte values[256];

			public unsafe fixed byte size[257];

			public unsafe fixed uint maxcode[18];

			public unsafe fixed int delta[17];
		}

		public class stbi__jpeg
		{
			public struct unnamed1
			{
				public int id;

				public int h;

				public int v;

				public int tq;

				public int hd;

				public int ha;

				public int dc_pred;

				public int x;

				public int y;

				public int w2;

				public int h2;

				public unsafe byte* data;

				public unsafe void* raw_data;

				public unsafe void* raw_coeff;

				public unsafe byte* linebuf;

				public unsafe short* coeff;

				public int coeff_w;

				public int coeff_h;
			}

			public int app14_color_transform;

			public int code_bits;

			public uint code_buffer;

			public ushort[][] dequant = Utility.CreateArray<ushort>(4, 64);

			public int eob_run;

			public short[][] fast_ac = Utility.CreateArray<short>(4, 512);

			public stbi__huffman[] huff_ac = new stbi__huffman[4];

			public stbi__huffman[] huff_dc = new stbi__huffman[4];

			public delegate0 idct_block_kernel;

			public unnamed1[] img_comp = new unnamed1[4];

			public int img_h_max;

			public int img_mcu_h;

			public int img_mcu_w;

			public int img_mcu_x;

			public int img_mcu_y;

			public int img_v_max;

			public int jfif;

			public byte marker;

			public int nomore;

			public int[] order = new int[4];

			public int progressive;

			public delegate2 resample_row_hv_2_kernel;

			public int restart_interval;

			public int rgb;

			public stbi__context s;

			public int scan_n;

			public int spec_end;

			public int spec_start;

			public int succ_high;

			public int succ_low;

			public int todo;

			public delegate1 YCbCr_to_RGB_kernel;
		}

		public class stbi__resample
		{
			public int hs;

			public unsafe byte* line0;

			public unsafe byte* line1;

			public delegate2 resample;

			public int vs;

			public int w_lores;

			public int ypos;

			public int ystep;
		}

		public class stbi__png
		{
			public unsafe byte* _out_;

			public int depth;

			public unsafe byte* expanded;

			public unsafe byte* idata;

			public stbi__context s;
		}

		public struct stbi__pngchunk
		{
			public uint length;

			public uint type;
		}

		public struct stbi__zbuf
		{
			public unsafe byte* zbuffer;

			public unsafe byte* zbuffer_end;

			public int num_bits;

			public int hit_zeof_once;

			public uint code_buffer;

			public unsafe sbyte* zout;

			public unsafe sbyte* zout_start;

			public unsafe sbyte* zout_end;

			public int z_expandable;

			public stbi__zhuffman z_length;

			public stbi__zhuffman z_distance;
		}

		public struct stbi__zhuffman
		{
			public unsafe fixed ushort fast[512];

			public unsafe fixed ushort firstcode[16];

			public unsafe fixed int maxcode[17];

			public unsafe fixed ushort firstsymbol[16];

			public unsafe fixed byte size[288];

			public unsafe fixed ushort value[288];
		}

		public static string stbi__g_failure_reason;

		public static readonly char[] stbi__parse_png_file_invalid_chunk = new char[25];

		public const int STBI_default = 0;

		public const int STBI_grey = 1;

		public const int STBI_grey_alpha = 2;

		public const int STBI_rgb = 3;

		public const int STBI_rgb_alpha = 4;

		public const int STBI_ORDER_RGB = 0;

		public const int STBI_ORDER_BGR = 1;

		public const int STBI__SCAN_load = 0;

		public const int STBI__SCAN_type = 1;

		public const int STBI__SCAN_header = 2;

		public static int stbi__vertically_flip_on_load_global;

		public static int stbi__vertically_flip_on_load_local;

		public static int stbi__vertically_flip_on_load_set;

		public static float stbi__l2h_gamma = 2.2f;

		public static float stbi__l2h_scale = 1f;

		public static float stbi__h2l_gamma_i = 0.45454544f;

		public static float stbi__h2l_scale_i = 1f;

		public static int stbi__unpremultiply_on_load_global;

		public static int stbi__de_iphone_flag_global;

		public static int stbi__unpremultiply_on_load_local;

		public static int stbi__unpremultiply_on_load_set;

		public static int stbi__de_iphone_flag_local;

		public static int stbi__de_iphone_flag_set;

		public static byte[] stbi__process_marker_tag = new byte[6] { 65, 100, 111, 98, 101, 0 };

		public static byte[] stbi__process_frame_header_rgb = new byte[3] { 82, 71, 66 };

		public static byte[] stbi__compute_huffman_codes_length_dezigzag = new byte[19]
		{
			16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
			11, 4, 12, 3, 13, 2, 14, 1, 15
		};

		public static int[] stbi__shiftsigned_mul_table = new int[9] { 0, 255, 85, 73, 17, 33, 65, 129, 1 };

		public static int[] stbi__shiftsigned_shift_table = new int[9] { 0, 0, 0, 1, 0, 2, 4, 6, 0 };

		public static uint[] stbi__bmask = new uint[17]
		{
			0u, 1u, 3u, 7u, 15u, 31u, 63u, 127u, 255u, 511u,
			1023u, 2047u, 4095u, 8191u, 16383u, 32767u, 65535u
		};

		public static int[] stbi__jbias = new int[16]
		{
			0, -1, -3, -7, -15, -31, -63, -127, -255, -511,
			-1023, -2047, -4095, -8191, -16383, -32767
		};

		public static byte[] stbi__jpeg_dezigzag = new byte[79]
		{
			0, 1, 8, 16, 9, 2, 3, 10, 17, 24,
			32, 25, 18, 11, 4, 5, 12, 19, 26, 33,
			40, 48, 41, 34, 27, 20, 13, 6, 7, 14,
			21, 28, 35, 42, 49, 56, 57, 50, 43, 36,
			29, 22, 15, 23, 30, 37, 44, 51, 58, 59,
			52, 45, 38, 31, 39, 46, 53, 60, 61, 54,
			47, 55, 62, 63, 63, 63, 63, 63, 63, 63,
			63, 63, 63, 63, 63, 63, 63, 63, 63
		};

		public const int STBI__F_none = 0;

		public const int STBI__F_sub = 1;

		public const int STBI__F_up = 2;

		public const int STBI__F_avg = 3;

		public const int STBI__F_paeth = 4;

		public const int STBI__F_avg_first = 5;

		public static byte[] first_row_filter = new byte[5] { 0, 1, 0, 5, 1 };

		public static byte[] stbi__check_png_header_png_sig = new byte[8] { 137, 80, 78, 71, 13, 10, 26, 10 };

		public static byte[] stbi__depth_scale_table = new byte[9] { 0, 255, 85, 0, 17, 0, 0, 0, 1 };

		public static byte[] stbi__zdefault_distance = new byte[32]
		{
			5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
			5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
			5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
			5, 5
		};

		public static byte[] stbi__zdefault_length = new byte[288]
		{
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
			8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
			9, 9, 9, 9, 9, 9, 7, 7, 7, 7,
			7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
			7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
			8, 8, 8, 8, 8, 8, 8, 8
		};

		public static int[] stbi__zdist_base = new int[32]
		{
			1, 2, 3, 4, 5, 7, 9, 13, 17, 25,
			33, 49, 65, 97, 129, 193, 257, 385, 513, 769,
			1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577,
			0, 0
		};

		public static int[] stbi__zdist_extra = new int[32]
		{
			0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
			4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
			9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
			0, 0
		};

		public static int[] stbi__zlength_base = new int[31]
		{
			3, 4, 5, 6, 7, 8, 9, 10, 11, 13,
			15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
			67, 83, 99, 115, 131, 163, 195, 227, 258, 0,
			0
		};

		public static int[] stbi__zlength_extra = new int[31]
		{
			0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
			1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
			4, 4, 4, 4, 5, 5, 5, 5, 0, 0,
			0
		};

		public static int NativeAllocations => MemoryStats.Allocations;

		private static int stbi__err(string str)
		{
			stbi__g_failure_reason = str;
			return 0;
		}

		public static byte stbi__get8(stbi__context s)
		{
			int num = s.Stream.ReadByte();
			if (num == -1)
			{
				return 0;
			}
			return (byte)num;
		}

		public static void stbi__skip(stbi__context s, int skip)
		{
			s.Stream.Seek(skip, SeekOrigin.Current);
		}

		public static void stbi__rewind(stbi__context s)
		{
			s.Stream.Seek(0L, SeekOrigin.Begin);
		}

		public static int stbi__at_eof(stbi__context s)
		{
			return (s.Stream.Position == s.Stream.Length) ? 1 : 0;
		}

		public unsafe static int stbi__getn(stbi__context s, byte* buf, int size)
		{
			if (s._tempBuffer == null || s._tempBuffer.Length < size)
			{
				s._tempBuffer = new byte[size * 2];
			}
			int num = s.Stream.Read(s._tempBuffer, 0, size);
			Marshal.Copy(s._tempBuffer, 0, new IntPtr(buf), num);
			return num;
		}

		public static int stbi__bmp_test(stbi__context s)
		{
			int result = stbi__bmp_test_raw(s);
			stbi__rewind(s);
			return result;
		}

		public unsafe static void* stbi__bmp_load(stbi__context s, int* x, int* y, int* comp, int req_comp, stbi__result_info* ri)
		{
			uint num = 0u;
			uint num2 = 0u;
			uint num3 = 0u;
			uint num4 = 0u;
			uint num5 = 0u;
			byte[][] array = Utility.CreateArray<byte>(256, 4);
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			int num9 = 0;
			int num10 = 0;
			int num11 = 0;
			int num12 = 0;
			stbi__bmp_data stbi__bmp_data = new stbi__bmp_data
			{
				all_a = 255u
			};
			if (stbi__bmp_parse_header(s, &stbi__bmp_data) == null)
			{
				return null;
			}
			num10 = (((int)s.img_y > 0) ? 1 : 0);
			s.img_y = (uint)CRuntime.abs((int)s.img_y);
			if (s.img_y > 16777216)
			{
				return (void*)(int)((stbi__err("too large") != 0) ? 0u : 0u);
			}
			if (s.img_x > 16777216)
			{
				return (void*)(int)((stbi__err("too large") != 0) ? 0u : 0u);
			}
			num = stbi__bmp_data.mr;
			num2 = stbi__bmp_data.mg;
			num3 = stbi__bmp_data.mb;
			num4 = stbi__bmp_data.ma;
			num5 = stbi__bmp_data.all_a;
			if (stbi__bmp_data.hsz == 12)
			{
				if (stbi__bmp_data.bpp < 24)
				{
					num6 = (stbi__bmp_data.offset - stbi__bmp_data.extra_read - 24) / 3;
				}
			}
			else if (stbi__bmp_data.bpp < 16)
			{
				num6 = stbi__bmp_data.offset - stbi__bmp_data.extra_read - stbi__bmp_data.hsz >> 2;
			}
			if (num6 == 0)
			{
				int num13 = (int)s.Stream.Position;
				int num14 = 1024;
				int num15 = 1024;
				if (num13 <= 0 || num13 > num14)
				{
					return (void*)(int)((stbi__err("bad header") != 0) ? 0u : 0u);
				}
				if (stbi__bmp_data.offset < num13 || stbi__bmp_data.offset - num13 > num15)
				{
					return (void*)(int)((stbi__err("bad offset") != 0) ? 0u : 0u);
				}
				stbi__skip(s, stbi__bmp_data.offset - num13);
			}
			if (stbi__bmp_data.bpp == 24 && num4 == 4278190080u)
			{
				s.img_n = 3;
			}
			else
			{
				s.img_n = ((num4 != 0) ? 4 : 3);
			}
			num12 = ((req_comp == 0 || req_comp < 3) ? s.img_n : req_comp);
			if (stbi__mad3sizes_valid(num12, (int)s.img_x, (int)s.img_y, 0) == 0)
			{
				return (void*)(int)((stbi__err("too large") != 0) ? 0u : 0u);
			}
			byte* ptr = (byte*)stbi__malloc_mad3(num12, (int)s.img_x, (int)s.img_y, 0);
			if (ptr == null)
			{
				return (void*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			if (stbi__bmp_data.bpp < 16)
			{
				int num16 = 0;
				if (num6 == 0 || num6 > 256)
				{
					CRuntime.free(ptr);
					return (void*)(int)((stbi__err("invalid") != 0) ? 0u : 0u);
				}
				for (num7 = 0; num7 < num6; num7++)
				{
					array[num7][2] = stbi__get8(s);
					array[num7][1] = stbi__get8(s);
					array[num7][0] = stbi__get8(s);
					if (stbi__bmp_data.hsz != 12)
					{
						stbi__get8(s);
					}
					array[num7][3] = byte.MaxValue;
				}
				stbi__skip(s, stbi__bmp_data.offset - stbi__bmp_data.extra_read - stbi__bmp_data.hsz - num6 * ((stbi__bmp_data.hsz == 12) ? 3 : 4));
				if (stbi__bmp_data.bpp == 1)
				{
					num9 = (int)(s.img_x + 7 >> 3);
				}
				else if (stbi__bmp_data.bpp == 4)
				{
					num9 = (int)(s.img_x + 1 >> 1);
				}
				else
				{
					if (stbi__bmp_data.bpp != 8)
					{
						CRuntime.free(ptr);
						return (void*)(int)((stbi__err("bad bpp") != 0) ? 0u : 0u);
					}
					num9 = (int)s.img_x;
				}
				num11 = -num9 & 3;
				if (stbi__bmp_data.bpp == 1)
				{
					for (num8 = 0; num8 < (int)s.img_y; num8++)
					{
						int num17 = 7;
						int num18 = stbi__get8(s);
						for (num7 = 0; num7 < (int)s.img_x; num7++)
						{
							int num19 = (num18 >> num17) & 1;
							ptr[num16++] = array[num19][0];
							ptr[num16++] = array[num19][1];
							ptr[num16++] = array[num19][2];
							if (num12 == 4)
							{
								ptr[num16++] = byte.MaxValue;
							}
							if (num7 + 1 == (int)s.img_x)
							{
								break;
							}
							if (--num17 < 0)
							{
								num17 = 7;
								num18 = stbi__get8(s);
							}
						}
						stbi__skip(s, num11);
					}
				}
				else
				{
					for (num8 = 0; num8 < (int)s.img_y; num8++)
					{
						for (num7 = 0; num7 < (int)s.img_x; num7 += 2)
						{
							int num20 = stbi__get8(s);
							int num21 = 0;
							if (stbi__bmp_data.bpp == 4)
							{
								num21 = num20 & 0xF;
								num20 >>= 4;
							}
							ptr[num16++] = array[num20][0];
							ptr[num16++] = array[num20][1];
							ptr[num16++] = array[num20][2];
							if (num12 == 4)
							{
								ptr[num16++] = byte.MaxValue;
							}
							if (num7 + 1 == (int)s.img_x)
							{
								break;
							}
							num20 = ((stbi__bmp_data.bpp == 8) ? stbi__get8(s) : num21);
							ptr[num16++] = array[num20][0];
							ptr[num16++] = array[num20][1];
							ptr[num16++] = array[num20][2];
							if (num12 == 4)
							{
								ptr[num16++] = byte.MaxValue;
							}
						}
						stbi__skip(s, num11);
					}
				}
			}
			else
			{
				int shift = 0;
				int shift2 = 0;
				int shift3 = 0;
				int shift4 = 0;
				int num22 = 0;
				int num23 = 0;
				int num24 = 0;
				int num25 = 0;
				int num26 = 0;
				int num27 = 0;
				stbi__skip(s, stbi__bmp_data.offset - stbi__bmp_data.extra_read - stbi__bmp_data.hsz);
				num9 = (int)((stbi__bmp_data.bpp == 24) ? (3 * s.img_x) : ((stbi__bmp_data.bpp == 16) ? (2 * s.img_x) : 0));
				num11 = -num9 & 3;
				if (stbi__bmp_data.bpp == 24)
				{
					num27 = 1;
				}
				else if (stbi__bmp_data.bpp == 32 && num3 == 255 && num2 == 65280 && num == 16711680 && num4 == 4278190080u)
				{
					num27 = 2;
				}
				if (num27 == 0)
				{
					if (num == 0 || num2 == 0 || num3 == 0)
					{
						CRuntime.free(ptr);
						return (void*)(int)((stbi__err("bad masks") != 0) ? 0u : 0u);
					}
					shift = stbi__high_bit(num) - 7;
					num22 = stbi__bitcount(num);
					shift2 = stbi__high_bit(num2) - 7;
					num23 = stbi__bitcount(num2);
					shift3 = stbi__high_bit(num3) - 7;
					num24 = stbi__bitcount(num3);
					shift4 = stbi__high_bit(num4) - 7;
					num25 = stbi__bitcount(num4);
					if (num22 > 8 || num23 > 8 || num24 > 8 || num25 > 8)
					{
						CRuntime.free(ptr);
						return (void*)(int)((stbi__err("bad masks") != 0) ? 0u : 0u);
					}
				}
				for (num8 = 0; num8 < (int)s.img_y; num8++)
				{
					if (num27 != 0)
					{
						for (num7 = 0; num7 < (int)s.img_x; num7++)
						{
							byte b = 0;
							ptr[num26 + 2] = stbi__get8(s);
							ptr[num26 + 1] = stbi__get8(s);
							ptr[num26] = stbi__get8(s);
							num26 += 3;
							b = ((num27 == 2) ? stbi__get8(s) : byte.MaxValue);
							num5 |= b;
							if (num12 == 4)
							{
								ptr[num26++] = b;
							}
						}
					}
					else
					{
						int bpp = stbi__bmp_data.bpp;
						for (num7 = 0; num7 < (int)s.img_x; num7++)
						{
							uint num28 = ((bpp == 16) ? ((uint)stbi__get16le(s)) : stbi__get32le(s));
							uint num29 = 0u;
							ptr[num26++] = (byte)(stbi__shiftsigned(num28 & num, shift, num22) & 0xFF);
							ptr[num26++] = (byte)(stbi__shiftsigned(num28 & num2, shift2, num23) & 0xFF);
							ptr[num26++] = (byte)(stbi__shiftsigned(num28 & num3, shift3, num24) & 0xFF);
							num29 = ((num4 != 0) ? ((uint)stbi__shiftsigned(num28 & num4, shift4, num25)) : 255u);
							num5 |= num29;
							if (num12 == 4)
							{
								ptr[num26++] = (byte)(num29 & 0xFF);
							}
						}
					}
					stbi__skip(s, num11);
				}
			}
			if (num12 == 4 && num5 == 0)
			{
				for (num7 = (int)(4 * s.img_x * s.img_y - 1); num7 >= 0; num7 -= 4)
				{
					ptr[num7] = byte.MaxValue;
				}
			}
			if (num10 != 0)
			{
				byte b2 = 0;
				for (num8 = 0; num8 < (int)s.img_y >> 1; num8++)
				{
					byte* ptr2 = ptr + num8 * s.img_x * num12;
					byte* ptr3 = ptr + (s.img_y - 1 - num8) * s.img_x * num12;
					for (num7 = 0; num7 < (int)s.img_x * num12; num7++)
					{
						b2 = ptr2[num7];
						ptr2[num7] = ptr3[num7];
						ptr3[num7] = b2;
					}
				}
			}
			if (req_comp != 0 && req_comp != num12)
			{
				ptr = stbi__convert_format(ptr, num12, req_comp, s.img_x, s.img_y);
				if (ptr == null)
				{
					return ptr;
				}
			}
			*x = (int)s.img_x;
			*y = (int)s.img_y;
			if (comp != null)
			{
				*comp = s.img_n;
			}
			return ptr;
		}

		public unsafe static int stbi__bmp_info(stbi__context s, int* x, int* y, int* comp)
		{
			stbi__bmp_data stbi__bmp_data = new stbi__bmp_data
			{
				all_a = 255u
			};
			if (stbi__bmp_parse_header(s, &stbi__bmp_data) == null)
			{
				stbi__rewind(s);
				return 0;
			}
			if (x != null)
			{
				*x = (int)s.img_x;
			}
			if (y != null)
			{
				*y = (int)s.img_y;
			}
			if (comp != null)
			{
				if (stbi__bmp_data.bpp == 24 && stbi__bmp_data.ma == 4278190080u)
				{
					*comp = 3;
				}
				else
				{
					*comp = ((stbi__bmp_data.ma != 0) ? 4 : 3);
				}
			}
			return 1;
		}

		public static int stbi__bmp_test_raw(stbi__context s)
		{
			int num = 0;
			if (stbi__get8(s) != 66)
			{
				return 0;
			}
			if (stbi__get8(s) != 77)
			{
				return 0;
			}
			stbi__get32le(s);
			stbi__get16le(s);
			stbi__get16le(s);
			stbi__get32le(s);
			num = (int)stbi__get32le(s);
			if (num != 12 && num != 40 && num != 56 && num != 108 && num != 124)
			{
				return 0;
			}
			return 1;
		}

		public unsafe static int stbi__bmp_set_mask_defaults(stbi__bmp_data* info, int compress)
		{
			switch (compress)
			{
			case 3:
				return 1;
			case 0:
				if (info->bpp == 16)
				{
					info->mr = 31744u;
					info->mg = 992u;
					info->mb = 31u;
				}
				else if (info->bpp == 32)
				{
					info->mr = 16711680u;
					info->mg = 65280u;
					info->mb = 255u;
					info->ma = 4278190080u;
					info->all_a = 0u;
				}
				else
				{
					info->mr = (info->mg = (info->mb = (info->ma = 0u)));
				}
				return 1;
			default:
				return 0;
			}
		}

		public unsafe static void* stbi__bmp_parse_header(stbi__context s, stbi__bmp_data* info)
		{
			int num = 0;
			if (stbi__get8(s) != 66 || stbi__get8(s) != 77)
			{
				return (void*)(int)((stbi__err("not BMP") != 0) ? 0u : 0u);
			}
			stbi__get32le(s);
			stbi__get16le(s);
			stbi__get16le(s);
			info->offset = (int)stbi__get32le(s);
			num = (info->hsz = (int)stbi__get32le(s));
			info->mr = (info->mg = (info->mb = (info->ma = 0u)));
			info->extra_read = 14;
			if (info->offset < 0)
			{
				return (void*)(int)((stbi__err("bad BMP") != 0) ? 0u : 0u);
			}
			if (num != 12 && num != 40 && num != 56 && num != 108 && num != 124)
			{
				return (void*)(int)((stbi__err("unknown BMP") != 0) ? 0u : 0u);
			}
			if (num == 12)
			{
				s.img_x = (uint)stbi__get16le(s);
				s.img_y = (uint)stbi__get16le(s);
			}
			else
			{
				s.img_x = stbi__get32le(s);
				s.img_y = stbi__get32le(s);
			}
			if (stbi__get16le(s) != 1)
			{
				return (void*)(int)((stbi__err("bad BMP") != 0) ? 0u : 0u);
			}
			info->bpp = stbi__get16le(s);
			if (num != 12)
			{
				int num2 = (int)stbi__get32le(s);
				if (num2 == 1 || num2 == 2)
				{
					return (void*)(int)((stbi__err("BMP RLE") != 0) ? 0u : 0u);
				}
				if (num2 >= 4)
				{
					return (void*)(int)((stbi__err("BMP JPEG/PNG") != 0) ? 0u : 0u);
				}
				if (num2 == 3 && info->bpp != 16 && info->bpp != 32)
				{
					return (void*)(int)((stbi__err("bad BMP") != 0) ? 0u : 0u);
				}
				stbi__get32le(s);
				stbi__get32le(s);
				stbi__get32le(s);
				stbi__get32le(s);
				stbi__get32le(s);
				if (num == 40 || num == 56)
				{
					if (num == 56)
					{
						stbi__get32le(s);
						stbi__get32le(s);
						stbi__get32le(s);
						stbi__get32le(s);
					}
					if (info->bpp == 16 || info->bpp == 32)
					{
						switch (num2)
						{
						case 0:
							stbi__bmp_set_mask_defaults(info, num2);
							break;
						case 3:
							info->mr = stbi__get32le(s);
							info->mg = stbi__get32le(s);
							info->mb = stbi__get32le(s);
							info->extra_read += 12;
							if (info->mr == info->mg && info->mg == info->mb)
							{
								return (void*)(int)((stbi__err("bad BMP") != 0) ? 0u : 0u);
							}
							break;
						default:
							return (void*)(int)((stbi__err("bad BMP") != 0) ? 0u : 0u);
						}
					}
				}
				else
				{
					int num3 = 0;
					if (num != 108 && num != 124)
					{
						return (void*)(int)((stbi__err("bad BMP") != 0) ? 0u : 0u);
					}
					info->mr = stbi__get32le(s);
					info->mg = stbi__get32le(s);
					info->mb = stbi__get32le(s);
					info->ma = stbi__get32le(s);
					if (num2 != 3)
					{
						stbi__bmp_set_mask_defaults(info, num2);
					}
					stbi__get32le(s);
					for (num3 = 0; num3 < 12; num3++)
					{
						stbi__get32le(s);
					}
					if (num == 124)
					{
						stbi__get32le(s);
						stbi__get32le(s);
						stbi__get32le(s);
						stbi__get32le(s);
					}
				}
			}
			return (void*)1;
		}

		public static void stbi_hdr_to_ldr_gamma(float gamma)
		{
			stbi__h2l_gamma_i = 1f / gamma;
		}

		public static void stbi_hdr_to_ldr_scale(float scale)
		{
			stbi__h2l_scale_i = 1f / scale;
		}

		public static void stbi_ldr_to_hdr_gamma(float gamma)
		{
			stbi__l2h_gamma = gamma;
		}

		public static void stbi_ldr_to_hdr_scale(float scale)
		{
			stbi__l2h_scale = scale;
		}

		public static void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply)
		{
			stbi__unpremultiply_on_load_global = flag_true_if_should_unpremultiply;
		}

		public static void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert)
		{
			stbi__de_iphone_flag_global = flag_true_if_should_convert;
		}

		public static void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip)
		{
			stbi__vertically_flip_on_load_global = flag_true_if_should_flip;
		}

		public static void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply)
		{
			stbi__unpremultiply_on_load_local = flag_true_if_should_unpremultiply;
			stbi__unpremultiply_on_load_set = 1;
		}

		public static void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert)
		{
			stbi__de_iphone_flag_local = flag_true_if_should_convert;
			stbi__de_iphone_flag_set = 1;
		}

		public static void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip)
		{
			stbi__vertically_flip_on_load_local = flag_true_if_should_flip;
			stbi__vertically_flip_on_load_set = 1;
		}

		public unsafe static void* stbi__malloc(ulong size)
		{
			return CRuntime.malloc(size);
		}

		public static int stbi__addsizes_valid(int a, int b)
		{
			if (b < 0)
			{
				return 0;
			}
			return (a <= int.MaxValue - b) ? 1 : 0;
		}

		public static int stbi__mul2sizes_valid(int a, int b)
		{
			if (a < 0 || b < 0)
			{
				return 0;
			}
			if (b == 0)
			{
				return 1;
			}
			return (a <= int.MaxValue / b) ? 1 : 0;
		}

		public static int stbi__mad2sizes_valid(int a, int b, int add)
		{
			if (stbi__mul2sizes_valid(a, b) == 0 || stbi__addsizes_valid(a * b, add) == 0)
			{
				return 0;
			}
			return 1;
		}

		public static int stbi__mad3sizes_valid(int a, int b, int c, int add)
		{
			if (stbi__mul2sizes_valid(a, b) == 0 || stbi__mul2sizes_valid(a * b, c) == 0 || stbi__addsizes_valid(a * b * c, add) == 0)
			{
				return 0;
			}
			return 1;
		}

		public static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
		{
			if (stbi__mul2sizes_valid(a, b) == 0 || stbi__mul2sizes_valid(a * b, c) == 0 || stbi__mul2sizes_valid(a * b * c, d) == 0 || stbi__addsizes_valid(a * b * c * d, add) == 0)
			{
				return 0;
			}
			return 1;
		}

		public unsafe static void* stbi__malloc_mad2(int a, int b, int add)
		{
			if (stbi__mad2sizes_valid(a, b, add) == 0)
			{
				return null;
			}
			return stbi__malloc((ulong)(a * b + add));
		}

		public unsafe static void* stbi__malloc_mad3(int a, int b, int c, int add)
		{
			if (stbi__mad3sizes_valid(a, b, c, add) == 0)
			{
				return null;
			}
			return stbi__malloc((ulong)(a * b * c + add));
		}

		public unsafe static void* stbi__malloc_mad4(int a, int b, int c, int d, int add)
		{
			if (stbi__mad4sizes_valid(a, b, c, d, add) == 0)
			{
				return null;
			}
			return stbi__malloc((ulong)(a * b * c * d + add));
		}

		public static int stbi__addints_valid(int a, int b)
		{
			if (a >= 0 != b >= 0)
			{
				return 1;
			}
			if (a < 0 && b < 0)
			{
				return (a >= int.MinValue - b) ? 1 : 0;
			}
			return (a <= int.MaxValue - b) ? 1 : 0;
		}

		public static int stbi__mul2shorts_valid(int a, int b)
		{
			if (b == 0 || b == -1)
			{
				return 1;
			}
			if (a >= 0 == b >= 0)
			{
				return (a <= 32767 / b) ? 1 : 0;
			}
			if (b < 0)
			{
				return (a <= -32768 / b) ? 1 : 0;
			}
			return (a >= -32768 / b) ? 1 : 0;
		}

		public unsafe static float* stbi__ldr_to_hdr(byte* data, int x, int y, int comp)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			if (data == null)
			{
				return null;
			}
			float* ptr = (float*)stbi__malloc_mad4(x, y, comp, 4, 0);
			if (ptr == null)
			{
				CRuntime.free(data);
				return (float*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			num3 = (((comp & 1) == 0) ? (comp - 1) : comp);
			for (num = 0; num < x * y; num++)
			{
				for (num2 = 0; num2 < num3; num2++)
				{
					ptr[num * comp + num2] = (float)(CRuntime.pow((float)(int)data[num * comp + num2] / 255f, stbi__l2h_gamma) * (double)stbi__l2h_scale);
				}
			}
			if (num3 < comp)
			{
				for (num = 0; num < x * y; num++)
				{
					ptr[num * comp + num3] = (float)(int)data[num * comp + num3] / 255f;
				}
			}
			CRuntime.free(data);
			return ptr;
		}

		public unsafe static void* stbi__load_main(stbi__context s, int* x, int* y, int* comp, int req_comp, stbi__result_info* ri, int bpc)
		{
			CRuntime.memset(ri, 0, (ulong)sizeof(stbi__result_info));
			ri->bits_per_channel = 8;
			ri->channel_order = 0;
			ri->num_channels = 0;
			if (stbi__png_test(s) != 0)
			{
				return stbi__png_load(s, x, y, comp, req_comp, ri);
			}
			if (stbi__bmp_test(s) != 0)
			{
				return stbi__bmp_load(s, x, y, comp, req_comp, ri);
			}
			if (stbi__gif_test(s) != 0)
			{
				return stbi__gif_load(s, x, y, comp, req_comp, ri);
			}
			if (stbi__psd_test(s) != 0)
			{
				return stbi__psd_load(s, x, y, comp, req_comp, ri, bpc);
			}
			if (stbi__jpeg_test(s) != 0)
			{
				return stbi__jpeg_load(s, x, y, comp, req_comp, ri);
			}
			if (stbi__hdr_test(s) != 0)
			{
				return stbi__hdr_to_ldr(stbi__hdr_load(s, x, y, comp, req_comp, ri), *x, *y, (req_comp != 0) ? req_comp : (*comp));
			}
			if (stbi__tga_test(s) != 0)
			{
				return stbi__tga_load(s, x, y, comp, req_comp, ri);
			}
			return (void*)(int)((stbi__err("unknown image type") != 0) ? 0u : 0u);
		}

		public unsafe static byte* stbi__convert_16_to_8(ushort* orig, int w, int h, int channels)
		{
			int num = 0;
			int num2 = w * h * channels;
			byte* ptr = (byte*)stbi__malloc((ulong)num2);
			if (ptr == null)
			{
				return (byte*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			for (num = 0; num < num2; num++)
			{
				ptr[num] = (byte)((orig[num] >> 8) & 0xFF);
			}
			CRuntime.free(orig);
			return ptr;
		}

		public unsafe static ushort* stbi__convert_8_to_16(byte* orig, int w, int h, int channels)
		{
			int num = 0;
			int num2 = w * h * channels;
			ushort* ptr = (ushort*)stbi__malloc((ulong)(num2 * 2));
			if (ptr == null)
			{
				return (ushort*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			for (num = 0; num < num2; num++)
			{
				ptr[num] = (ushort)((orig[num] << 8) + orig[num]);
			}
			CRuntime.free(orig);
			return ptr;
		}

		public unsafe static void stbi__vertical_flip(void* image, int w, int h, int bytes_per_pixel)
		{
			int num = 0;
			int num2 = w * bytes_per_pixel;
			byte* ptr = stackalloc byte[2048];
			for (num = 0; num < h >> 1; num++)
			{
				byte* ptr2 = (byte*)image + num * num2;
				byte* ptr3 = (byte*)image + (h - num - 1) * num2;
				ulong num3 = (ulong)num2;
				while (num3 != 0L)
				{
					ulong num4 = ((num3 < 2048) ? num3 : 2048);
					CRuntime.memcpy(ptr, ptr2, num4);
					CRuntime.memcpy(ptr2, ptr3, num4);
					CRuntime.memcpy(ptr3, ptr, num4);
					ptr2 += num4;
					ptr3 += num4;
					num3 -= num4;
				}
			}
		}

		public unsafe static void stbi__vertical_flip_slices(void* image, int w, int h, int z, int bytes_per_pixel)
		{
			int num = 0;
			int num2 = w * h * bytes_per_pixel;
			byte* ptr = (byte*)image;
			for (num = 0; num < z; num++)
			{
				stbi__vertical_flip(ptr, w, h, bytes_per_pixel);
				ptr += num2;
			}
		}

		public unsafe static byte* stbi__load_and_postprocess_8bit(stbi__context s, int* x, int* y, int* comp, int req_comp)
		{
			stbi__result_info stbi__result_info = default(stbi__result_info);
			void* ptr = stbi__load_main(s, x, y, comp, req_comp, &stbi__result_info, 8);
			if (ptr == null)
			{
				return null;
			}
			if (stbi__result_info.bits_per_channel != 8)
			{
				ptr = stbi__convert_16_to_8((ushort*)ptr, *x, *y, (req_comp == 0) ? (*comp) : req_comp);
				stbi__result_info.bits_per_channel = 8;
			}
			if (((stbi__vertically_flip_on_load_set != 0) ? stbi__vertically_flip_on_load_local : stbi__vertically_flip_on_load_global) != 0)
			{
				int bytes_per_pixel = ((req_comp != 0) ? req_comp : (*comp));
				stbi__vertical_flip(ptr, *x, *y, bytes_per_pixel);
			}
			return (byte*)ptr;
		}

		public unsafe static ushort* stbi__load_and_postprocess_16bit(stbi__context s, int* x, int* y, int* comp, int req_comp)
		{
			stbi__result_info stbi__result_info = default(stbi__result_info);
			void* ptr = stbi__load_main(s, x, y, comp, req_comp, &stbi__result_info, 16);
			if (ptr == null)
			{
				return null;
			}
			if (stbi__result_info.bits_per_channel != 16)
			{
				ptr = stbi__convert_8_to_16((byte*)ptr, *x, *y, (req_comp == 0) ? (*comp) : req_comp);
				stbi__result_info.bits_per_channel = 16;
			}
			if (((stbi__vertically_flip_on_load_set != 0) ? stbi__vertically_flip_on_load_local : stbi__vertically_flip_on_load_global) != 0)
			{
				int num = ((req_comp != 0) ? req_comp : (*comp));
				stbi__vertical_flip(ptr, *x, *y, num * 2);
			}
			return (ushort*)ptr;
		}

		public unsafe static void stbi__float_postprocess(float* result, int* x, int* y, int* comp, int req_comp)
		{
			if (((stbi__vertically_flip_on_load_set != 0) ? stbi__vertically_flip_on_load_local : stbi__vertically_flip_on_load_global) != 0 && result != null)
			{
				int num = ((req_comp != 0) ? req_comp : (*comp));
				stbi__vertical_flip(result, *x, *y, num * 4);
			}
		}

		public unsafe static float* stbi__loadf_main(stbi__context s, int* x, int* y, int* comp, int req_comp)
		{
			if (stbi__hdr_test(s) != 0)
			{
				stbi__result_info stbi__result_info = default(stbi__result_info);
				float* ptr = stbi__hdr_load(s, x, y, comp, req_comp, &stbi__result_info);
				if (ptr != null)
				{
					stbi__float_postprocess(ptr, x, y, comp, req_comp);
				}
				return ptr;
			}
			byte* ptr2 = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp);
			if (ptr2 != null)
			{
				return stbi__ldr_to_hdr(ptr2, *x, *y, (req_comp != 0) ? req_comp : (*comp));
			}
			return (float*)(int)((stbi__err("unknown image type") != 0) ? 0u : 0u);
		}

		public static int stbi__get16be(stbi__context s)
		{
			return (stbi__get8(s) << 8) + stbi__get8(s);
		}

		public static uint stbi__get32be(stbi__context s)
		{
			return (uint)((uint)(stbi__get16be(s) << 16) + stbi__get16be(s));
		}

		public static int stbi__get16le(stbi__context s)
		{
			return stbi__get8(s) + (stbi__get8(s) << 8);
		}

		public static uint stbi__get32le(stbi__context s)
		{
			return (uint)(stbi__get16le(s) + (stbi__get16le(s) << 16));
		}

		public static byte stbi__compute_y(int r, int g, int b)
		{
			return (byte)(r * 77 + g * 150 + 29 * b >> 8);
		}

		public unsafe static byte* stbi__convert_format(byte* data, int img_n, int req_comp, uint x, uint y)
		{
			int num = 0;
			int num2 = 0;
			if (req_comp == img_n)
			{
				return data;
			}
			byte* ptr = (byte*)stbi__malloc_mad3(req_comp, (int)x, (int)y, 0);
			if (ptr == null)
			{
				CRuntime.free(data);
				return (byte*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			for (num2 = 0; num2 < (int)y; num2++)
			{
				byte* ptr2 = data + num2 * x * img_n;
				byte* ptr3 = ptr + num2 * x * req_comp;
				switch (img_n * 8 + req_comp)
				{
				case 10:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = *ptr2;
						ptr3[1] = byte.MaxValue;
						num--;
						ptr2++;
						ptr3 += 2;
					}
					break;
				case 11:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = (ptr3[1] = (ptr3[2] = *ptr2));
						num--;
						ptr2++;
						ptr3 += 3;
					}
					break;
				case 12:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = (ptr3[1] = (ptr3[2] = *ptr2));
						ptr3[3] = byte.MaxValue;
						num--;
						ptr2++;
						ptr3 += 4;
					}
					break;
				case 17:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = *ptr2;
						num--;
						ptr2 += 2;
						ptr3++;
					}
					break;
				case 19:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = (ptr3[1] = (ptr3[2] = *ptr2));
						num--;
						ptr2 += 2;
						ptr3 += 3;
					}
					break;
				case 20:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = (ptr3[1] = (ptr3[2] = *ptr2));
						ptr3[3] = ptr2[1];
						num--;
						ptr2 += 2;
						ptr3 += 4;
					}
					break;
				case 28:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = *ptr2;
						ptr3[1] = ptr2[1];
						ptr3[2] = ptr2[2];
						ptr3[3] = byte.MaxValue;
						num--;
						ptr2 += 3;
						ptr3 += 4;
					}
					break;
				case 25:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = stbi__compute_y(*ptr2, ptr2[1], ptr2[2]);
						num--;
						ptr2 += 3;
						ptr3++;
					}
					break;
				case 26:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = stbi__compute_y(*ptr2, ptr2[1], ptr2[2]);
						ptr3[1] = byte.MaxValue;
						num--;
						ptr2 += 3;
						ptr3 += 2;
					}
					break;
				case 33:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = stbi__compute_y(*ptr2, ptr2[1], ptr2[2]);
						num--;
						ptr2 += 4;
						ptr3++;
					}
					break;
				case 34:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = stbi__compute_y(*ptr2, ptr2[1], ptr2[2]);
						ptr3[1] = ptr2[3];
						num--;
						ptr2 += 4;
						ptr3 += 2;
					}
					break;
				case 35:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = *ptr2;
						ptr3[1] = ptr2[1];
						ptr3[2] = ptr2[2];
						num--;
						ptr2 += 4;
						ptr3 += 3;
					}
					break;
				default:
					CRuntime.free(data);
					CRuntime.free(ptr);
					return (byte*)(int)((stbi__err("unsupported") != 0) ? 0u : 0u);
				}
			}
			CRuntime.free(data);
			return ptr;
		}

		public static ushort stbi__compute_y_16(int r, int g, int b)
		{
			return (ushort)(r * 77 + g * 150 + 29 * b >> 8);
		}

		public unsafe static ushort* stbi__convert_format16(ushort* data, int img_n, int req_comp, uint x, uint y)
		{
			int num = 0;
			int num2 = 0;
			if (req_comp == img_n)
			{
				return data;
			}
			ushort* ptr = (ushort*)stbi__malloc((ulong)(req_comp * x * y * 2));
			if (ptr == null)
			{
				CRuntime.free(data);
				return (ushort*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			for (num2 = 0; num2 < (int)y; num2++)
			{
				ushort* ptr2 = data + num2 * x * img_n;
				ushort* ptr3 = ptr + num2 * x * req_comp;
				switch (img_n * 8 + req_comp)
				{
				case 10:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = *ptr2;
						ptr3[1] = ushort.MaxValue;
						num--;
						ptr2++;
						ptr3 += 2;
					}
					break;
				case 11:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = (ptr3[1] = (ptr3[2] = *ptr2));
						num--;
						ptr2++;
						ptr3 += 3;
					}
					break;
				case 12:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = (ptr3[1] = (ptr3[2] = *ptr2));
						ptr3[3] = ushort.MaxValue;
						num--;
						ptr2++;
						ptr3 += 4;
					}
					break;
				case 17:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = *ptr2;
						num--;
						ptr2 += 2;
						ptr3++;
					}
					break;
				case 19:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = (ptr3[1] = (ptr3[2] = *ptr2));
						num--;
						ptr2 += 2;
						ptr3 += 3;
					}
					break;
				case 20:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = (ptr3[1] = (ptr3[2] = *ptr2));
						ptr3[3] = ptr2[1];
						num--;
						ptr2 += 2;
						ptr3 += 4;
					}
					break;
				case 28:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = *ptr2;
						ptr3[1] = ptr2[1];
						ptr3[2] = ptr2[2];
						ptr3[3] = ushort.MaxValue;
						num--;
						ptr2 += 3;
						ptr3 += 4;
					}
					break;
				case 25:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = stbi__compute_y_16(*ptr2, ptr2[1], ptr2[2]);
						num--;
						ptr2 += 3;
						ptr3++;
					}
					break;
				case 26:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = stbi__compute_y_16(*ptr2, ptr2[1], ptr2[2]);
						ptr3[1] = ushort.MaxValue;
						num--;
						ptr2 += 3;
						ptr3 += 2;
					}
					break;
				case 33:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = stbi__compute_y_16(*ptr2, ptr2[1], ptr2[2]);
						num--;
						ptr2 += 4;
						ptr3++;
					}
					break;
				case 34:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = stbi__compute_y_16(*ptr2, ptr2[1], ptr2[2]);
						ptr3[1] = ptr2[3];
						num--;
						ptr2 += 4;
						ptr3 += 2;
					}
					break;
				case 35:
					num = (int)(x - 1);
					while (num >= 0)
					{
						*ptr3 = *ptr2;
						ptr3[1] = ptr2[1];
						ptr3[2] = ptr2[2];
						num--;
						ptr2 += 4;
						ptr3 += 3;
					}
					break;
				default:
					CRuntime.free(data);
					CRuntime.free(ptr);
					return (ushort*)(int)((stbi__err("unsupported") != 0) ? 0u : 0u);
				}
			}
			CRuntime.free(data);
			return ptr;
		}

		public static byte stbi__clamp(int x)
		{
			if ((uint)x > 255u)
			{
				if (x < 0)
				{
					return 0;
				}
				if (x > 255)
				{
					return byte.MaxValue;
				}
			}
			return (byte)x;
		}

		public static byte stbi__blinn_8x8(byte x, byte y)
		{
			int num = x * y + 128;
			return (byte)((uint)(num + (num >>> 8)) >> 8);
		}

		public static int stbi__bitreverse16(int n)
		{
			n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1);
			n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2);
			n = ((n & 0xF0F0) >> 4) | ((n & 0xF0F) << 4);
			n = ((n & 0xFF00) >> 8) | ((n & 0xFF) << 8);
			return n;
		}

		public static int stbi__bit_reverse(int v, int bits)
		{
			return stbi__bitreverse16(v) >> 16 - bits;
		}

		public static int stbi__high_bit(uint z)
		{
			int num = 0;
			if (z == 0)
			{
				return -1;
			}
			if (z >= 65536)
			{
				num += 16;
				z >>= 16;
			}
			if (z >= 256)
			{
				num += 8;
				z >>= 8;
			}
			if (z >= 16)
			{
				num += 4;
				z >>= 4;
			}
			if (z >= 4)
			{
				num += 2;
				z >>= 2;
			}
			if (z >= 2)
			{
				num++;
			}
			return num;
		}

		public static int stbi__bitcount(uint a)
		{
			a = (a & 0x55555555) + ((a >> 1) & 0x55555555);
			a = (a & 0x33333333) + ((a >> 2) & 0x33333333);
			a = (a + (a >> 4)) & 0xF0F0F0F;
			a += a >> 8;
			a += a >> 16;
			return (int)(a & 0xFF);
		}

		public static int stbi__shiftsigned(uint v, int shift, int bits)
		{
			v = ((shift >= 0) ? (v >> shift) : (v << -shift));
			v >>= 8 - bits;
			return (int)(v * stbi__shiftsigned_mul_table[bits]) >> stbi__shiftsigned_shift_table[bits];
		}

		public unsafe static int stbi__info_main(stbi__context s, int* x, int* y, int* comp)
		{
			if (stbi__jpeg_info(s, x, y, comp) != 0)
			{
				return 1;
			}
			if (stbi__png_info(s, x, y, comp) != 0)
			{
				return 1;
			}
			if (stbi__gif_info(s, x, y, comp) != 0)
			{
				return 1;
			}
			if (stbi__bmp_info(s, x, y, comp) != 0)
			{
				return 1;
			}
			if (stbi__psd_info(s, x, y, comp) != 0)
			{
				return 1;
			}
			if (stbi__hdr_info(s, x, y, comp) != 0)
			{
				return 1;
			}
			if (stbi__tga_info(s, x, y, comp) != 0)
			{
				return 1;
			}
			return stbi__err("unknown image type");
		}

		public static int stbi__is_16_main(stbi__context s)
		{
			if (stbi__png_is16(s) != 0)
			{
				return 1;
			}
			if (stbi__psd_is16(s) != 0)
			{
				return 1;
			}
			return 0;
		}

		public static int stbi__gif_test(stbi__context s)
		{
			int result = stbi__gif_test_raw(s);
			stbi__rewind(s);
			return result;
		}

		public unsafe static void* stbi__gif_load(stbi__context s, int* x, int* y, int* comp, int req_comp, stbi__result_info* ri)
		{
			byte* ptr = null;
			stbi__gif stbi__gif = new stbi__gif();
			ptr = stbi__gif_load_next(s, stbi__gif, comp, req_comp, null);
			if (ptr != null)
			{
				*x = stbi__gif.w;
				*y = stbi__gif.h;
				if (req_comp != 0 && req_comp != 4)
				{
					ptr = stbi__convert_format(ptr, 4, req_comp, (uint)stbi__gif.w, (uint)stbi__gif.h);
				}
			}
			else if (stbi__gif._out_ != null)
			{
				CRuntime.free(stbi__gif._out_);
			}
			CRuntime.free(stbi__gif.history);
			CRuntime.free(stbi__gif.background);
			return ptr;
		}

		public unsafe static void* stbi__load_gif_main(stbi__context s, int** delays, int* x, int* y, int* z, int* comp, int req_comp)
		{
			if (stbi__gif_test(s) != 0)
			{
				int num = 0;
				byte* ptr = null;
				byte* ptr2 = null;
				byte* two_back = null;
				stbi__gif stbi__gif = new stbi__gif();
				int num2 = 0;
				if (delays != null)
				{
					*delays = null;
				}
				do
				{
					ptr = stbi__gif_load_next(s, stbi__gif, comp, req_comp, two_back);
					if (ptr == null)
					{
						continue;
					}
					*x = stbi__gif.w;
					*y = stbi__gif.h;
					num++;
					num2 = stbi__gif.w * stbi__gif.h * 4;
					if (ptr2 != null)
					{
						void* ptr3 = CRuntime.realloc(ptr2, (ulong)(num * num2));
						if (ptr3 == null)
						{
							return stbi__load_gif_main_outofmem(stbi__gif, ptr2, delays);
						}
						ptr2 = (byte*)ptr3;
						if (delays != null)
						{
							int* ptr4 = (int*)CRuntime.realloc(*delays, (ulong)(4 * num));
							if (ptr4 == null)
							{
								return stbi__load_gif_main_outofmem(stbi__gif, ptr2, delays);
							}
							*delays = ptr4;
						}
					}
					else
					{
						ptr2 = (byte*)stbi__malloc((ulong)(num * num2));
						if (ptr2 == null)
						{
							return stbi__load_gif_main_outofmem(stbi__gif, ptr2, delays);
						}
						if (delays != null)
						{
							*delays = (int*)stbi__malloc((ulong)(num * 4));
							if (*delays == null)
							{
								return stbi__load_gif_main_outofmem(stbi__gif, ptr2, delays);
							}
						}
					}
					CRuntime.memcpy(ptr2 + (num - 1) * num2, ptr, (ulong)num2);
					if (num >= 2)
					{
						two_back = ptr2 - 2 * num2;
					}
					if (delays != null)
					{
						(*delays)[(long)num - 1L] = stbi__gif.delay;
					}
				}
				while (ptr != null);
				CRuntime.free(stbi__gif._out_);
				CRuntime.free(stbi__gif.history);
				CRuntime.free(stbi__gif.background);
				if (req_comp != 0 && req_comp != 4)
				{
					ptr2 = stbi__convert_format(ptr2, 4, req_comp, (uint)(num * stbi__gif.w), (uint)stbi__gif.h);
				}
				*z = num;
				return ptr2;
			}
			return (void*)(int)((stbi__err("not GIF") != 0) ? 0u : 0u);
		}

		public unsafe static int stbi__gif_info(stbi__context s, int* x, int* y, int* comp)
		{
			return stbi__gif_info_raw(s, x, y, comp);
		}

		public static int stbi__gif_test_raw(stbi__context s)
		{
			int num = 0;
			if (stbi__get8(s) != 71 || stbi__get8(s) != 73 || stbi__get8(s) != 70 || stbi__get8(s) != 56)
			{
				return 0;
			}
			num = stbi__get8(s);
			if (num != 57 && num != 55)
			{
				return 0;
			}
			if (stbi__get8(s) != 97)
			{
				return 0;
			}
			return 1;
		}

		public static void stbi__gif_parse_colortable(stbi__context s, byte[][] pal, int num_entries, int transp)
		{
			int num = 0;
			for (num = 0; num < num_entries; num++)
			{
				pal[num][2] = stbi__get8(s);
				pal[num][1] = stbi__get8(s);
				pal[num][0] = stbi__get8(s);
				pal[num][3] = (byte)((transp != num) ? 255u : 0u);
			}
		}

		public unsafe static int stbi__gif_header(stbi__context s, stbi__gif g, int* comp, int is_info)
		{
			byte b = 0;
			if (stbi__get8(s) != 71 || stbi__get8(s) != 73 || stbi__get8(s) != 70 || stbi__get8(s) != 56)
			{
				return stbi__err("not GIF");
			}
			b = stbi__get8(s);
			if (b != 55 && b != 57)
			{
				return stbi__err("not GIF");
			}
			if (stbi__get8(s) != 97)
			{
				return stbi__err("not GIF");
			}
			stbi__g_failure_reason = "";
			g.w = stbi__get16le(s);
			g.h = stbi__get16le(s);
			g.flags = stbi__get8(s);
			g.bgindex = stbi__get8(s);
			g.ratio = stbi__get8(s);
			g.transparent = -1;
			if (g.w > 16777216)
			{
				return stbi__err("too large");
			}
			if (g.h > 16777216)
			{
				return stbi__err("too large");
			}
			if (comp != null)
			{
				*comp = 4;
			}
			if (is_info != 0)
			{
				return 1;
			}
			if ((g.flags & 0x80) != 0)
			{
				stbi__gif_parse_colortable(s, g.pal, 2 << (g.flags & 7), -1);
			}
			return 1;
		}

		public unsafe static int stbi__gif_info_raw(stbi__context s, int* x, int* y, int* comp)
		{
			stbi__gif stbi__gif = new stbi__gif();
			if (stbi__gif == null)
			{
				return stbi__err("outofmem");
			}
			if (stbi__gif_header(s, stbi__gif, comp, 1) == 0)
			{
				stbi__rewind(s);
				return 0;
			}
			if (x != null)
			{
				*x = stbi__gif.w;
			}
			if (y != null)
			{
				*y = stbi__gif.h;
			}
			return 1;
		}

		public unsafe static void stbi__out_gif_code(stbi__gif g, ushort code)
		{
			int num = 0;
			if (g.codes[code].prefix >= 0)
			{
				stbi__out_gif_code(g, (ushort)g.codes[code].prefix);
			}
			if (g.cur_y >= g.max_y)
			{
				return;
			}
			num = g.cur_x + g.cur_y;
			byte* ptr = g._out_ + num;
			g.history[num / 4] = 1;
			byte[] array = g.color_table[g.codes[code].suffix];
			if (array[3] > 128)
			{
				*ptr = array[2];
				ptr[1] = array[1];
				ptr[2] = array[0];
				ptr[3] = array[3];
			}
			g.cur_x += 4;
			if (g.cur_x >= g.max_x)
			{
				g.cur_x = g.start_x;
				g.cur_y += g.step;
				while (g.cur_y >= g.max_y && g.parse > 0)
				{
					g.step = (1 << g.parse) * g.line_size;
					g.cur_y = g.start_y + (g.step >> 1);
					g.parse--;
				}
			}
		}

		public unsafe static byte* stbi__process_gif_raster(stbi__context s, stbi__gif g)
		{
			byte b = 0;
			int num = 0;
			int num2 = 0;
			uint num3 = 0u;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			int num9 = 0;
			int num10 = 0;
			b = stbi__get8(s);
			if (b > 12)
			{
				return null;
			}
			num10 = 1 << (int)b;
			num3 = 1u;
			num4 = b + 1;
			num5 = (1 << num4) - 1;
			num8 = 0;
			num9 = 0;
			for (num2 = 0; num2 < num10; num2++)
			{
				g.codes[num2].prefix = -1;
				g.codes[num2].first = (byte)num2;
				g.codes[num2].suffix = (byte)num2;
			}
			num6 = num10 + 2;
			num7 = -1;
			num = 0;
			while (true)
			{
				if (num9 < num4)
				{
					if (num == 0)
					{
						num = stbi__get8(s);
						if (num == 0)
						{
							return g._out_;
						}
					}
					num--;
					num8 |= stbi__get8(s) << num9;
					num9 += 8;
					continue;
				}
				int num11 = num8 & num5;
				num8 >>= num4;
				num9 -= num4;
				if (num11 == num10)
				{
					num4 = b + 1;
					num5 = (1 << num4) - 1;
					num6 = num10 + 2;
					num7 = -1;
					num3 = 0u;
					continue;
				}
				if (num11 == num10 + 1)
				{
					stbi__skip(s, num);
					while ((num = stbi__get8(s)) > 0)
					{
						stbi__skip(s, num);
					}
					return g._out_;
				}
				if (num11 > num6)
				{
					break;
				}
				if (num3 != 0)
				{
					return (byte*)(int)((stbi__err("no clear code") != 0) ? 0u : 0u);
				}
				if (num7 >= 0)
				{
					fixed (stbi__gif_lzw* ptr = &g.codes[num6++])
					{
						if (num6 > 8192)
						{
							return (byte*)(int)((stbi__err("too many codes") != 0) ? 0u : 0u);
						}
						ptr->prefix = (short)num7;
						ptr->first = g.codes[num7].first;
						ptr->suffix = ((num11 == num6) ? ptr->first : g.codes[num11].first);
					}
				}
				else if (num11 == num6)
				{
					return (byte*)(int)((stbi__err("illegal code in raster") != 0) ? 0u : 0u);
				}
				stbi__out_gif_code(g, (ushort)num11);
				if ((num6 & num5) == 0 && num6 <= 4095)
				{
					num4++;
					num5 = (1 << num4) - 1;
				}
				num7 = num11;
			}
			return (byte*)(int)((stbi__err("illegal code in raster") != 0) ? 0u : 0u);
		}

		public unsafe static byte* stbi__gif_load_next(stbi__context s, stbi__gif g, int* comp, int req_comp, byte* two_back)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			num2 = 0;
			if (g._out_ == null)
			{
				if (stbi__gif_header(s, g, comp, 0) == 0)
				{
					return null;
				}
				if (stbi__mad3sizes_valid(4, g.w, g.h, 0) == 0)
				{
					return (byte*)(int)((stbi__err("too large") != 0) ? 0u : 0u);
				}
				num4 = g.w * g.h;
				g._out_ = (byte*)stbi__malloc((ulong)(4 * num4));
				g.background = (byte*)stbi__malloc((ulong)(4 * num4));
				g.history = (byte*)stbi__malloc((ulong)num4);
				if (g._out_ == null || g.background == null || g.history == null)
				{
					return (byte*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
				}
				CRuntime.memset(g._out_, 0, (ulong)(4 * num4));
				CRuntime.memset(g.background, 0, (ulong)(4 * num4));
				CRuntime.memset(g.history, 0, (ulong)num4);
				num2 = 1;
			}
			else
			{
				num = (g.eflags & 0x1C) >> 2;
				num4 = g.w * g.h;
				if (num == 3 && two_back == null)
				{
					num = 2;
				}
				switch (num)
				{
				case 3:
					for (num3 = 0; num3 < num4; num3++)
					{
						if (g.history[num3] != 0)
						{
							CRuntime.memcpy(g._out_ + num3 * 4, two_back + num3 * 4, 4uL);
						}
					}
					break;
				case 2:
					for (num3 = 0; num3 < num4; num3++)
					{
						if (g.history[num3] != 0)
						{
							CRuntime.memcpy(g._out_ + num3 * 4, g.background + num3 * 4, 4uL);
						}
					}
					break;
				}
				CRuntime.memcpy(g.background, g._out_, (ulong)(4 * g.w * g.h));
			}
			CRuntime.memset(g.history, 0, (ulong)(g.w * g.h));
			while (true)
			{
				switch (stbi__get8(s))
				{
				case 44:
				{
					int num6 = 0;
					int num7 = 0;
					int num8 = 0;
					int num9 = 0;
					num6 = stbi__get16le(s);
					num7 = stbi__get16le(s);
					num8 = stbi__get16le(s);
					num9 = stbi__get16le(s);
					if (num6 + num8 > g.w || num7 + num9 > g.h)
					{
						return (byte*)(int)((stbi__err("bad Image Descriptor") != 0) ? 0u : 0u);
					}
					g.line_size = g.w * 4;
					g.start_x = num6 * 4;
					g.start_y = num7 * g.line_size;
					g.max_x = g.start_x + num8 * 4;
					g.max_y = g.start_y + num9 * g.line_size;
					g.cur_x = g.start_x;
					g.cur_y = g.start_y;
					if (num8 == 0)
					{
						g.cur_y = g.max_y;
					}
					g.lflags = stbi__get8(s);
					if ((g.lflags & 0x40) != 0)
					{
						g.step = 8 * g.line_size;
						g.parse = 3;
					}
					else
					{
						g.step = g.line_size;
						g.parse = 0;
					}
					if ((g.lflags & 0x80) != 0)
					{
						stbi__gif_parse_colortable(s, g.lpal, 2 << (g.lflags & 7), ((g.eflags & 1) != 0) ? g.transparent : (-1));
						g.color_table = g.lpal;
					}
					else
					{
						if ((g.flags & 0x80) == 0)
						{
							return (byte*)(int)((stbi__err("missing color table") != 0) ? 0u : 0u);
						}
						g.color_table = g.pal;
					}
					byte* ptr = stbi__process_gif_raster(s, g);
					if (ptr == null)
					{
						return null;
					}
					num4 = g.w * g.h;
					if (num2 != 0 && g.bgindex > 0)
					{
						for (num3 = 0; num3 < num4; num3++)
						{
							if (g.history[num3] == 0)
							{
								g.pal[g.bgindex][3] = byte.MaxValue;
								fixed (byte* b = &g.pal[g.bgindex][0])
								{
									CRuntime.memcpy(g._out_ + num3 * 4, b, 4uL);
								}
							}
						}
					}
					return ptr;
				}
				case 33:
				{
					int num5 = 0;
					if (stbi__get8(s) == 249)
					{
						num5 = stbi__get8(s);
						if (num5 != 4)
						{
							stbi__skip(s, num5);
							break;
						}
						g.eflags = stbi__get8(s);
						g.delay = 10 * stbi__get16le(s);
						if (g.transparent >= 0)
						{
							g.pal[g.transparent][3] = byte.MaxValue;
						}
						if ((g.eflags & 1) != 0)
						{
							g.transparent = stbi__get8(s);
							if (g.transparent >= 0)
							{
								g.pal[g.transparent][3] = 0;
							}
						}
						else
						{
							stbi__skip(s, 1);
							g.transparent = -1;
						}
					}
					while ((num5 = stbi__get8(s)) != 0)
					{
						stbi__skip(s, num5);
					}
					break;
				}
				case 59:
					return null;
				default:
					return (byte*)(int)((stbi__err("unknown code") != 0) ? 0u : 0u);
				}
			}
		}

		public unsafe static void* stbi__load_gif_main_outofmem(stbi__gif g, byte* _out_, int** delays)
		{
			CRuntime.free(g._out_);
			CRuntime.free(g.history);
			CRuntime.free(g.background);
			if (_out_ != null)
			{
				CRuntime.free(_out_);
			}
			if (delays != null && *delays != null)
			{
				CRuntime.free(*delays);
			}
			return (void*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
		}

		public static int stbi__hdr_test(stbi__context s)
		{
			int num = stbi__hdr_test_core(s, "#?RADIANCE\n");
			stbi__rewind(s);
			if (num == 0)
			{
				num = stbi__hdr_test_core(s, "#?RGBE\n");
				stbi__rewind(s);
			}
			return num;
		}

		public unsafe static float* stbi__hdr_load(stbi__context s, int* x, int* y, int* comp, int req_comp, stbi__result_info* ri)
		{
			byte* ptr = stackalloc byte[4];
			sbyte* buffer = stackalloc sbyte[1024];
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			byte b = 0;
			byte b2 = 0;
			int i = 0;
			int j = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			sbyte* src = stbi__hdr_gettoken(s, buffer);
			if (CRuntime.strcmp(src, "#?RADIANCE") != 0 && CRuntime.strcmp(src, "#?RGBE") != 0)
			{
				return (float*)(int)((stbi__err("not HDR") != 0) ? 0u : 0u);
			}
			sbyte* ptr2;
			while (true)
			{
				ptr2 = stbi__hdr_gettoken(s, buffer);
				if (*ptr2 == 0)
				{
					break;
				}
				if (CRuntime.strcmp(ptr2, "FORMAT=32-bit_rle_rgbe") == 0)
				{
					num = 1;
				}
			}
			if (num == 0)
			{
				return (float*)(int)((stbi__err("unsupported format") != 0) ? 0u : 0u);
			}
			ptr2 = stbi__hdr_gettoken(s, buffer);
			if (CRuntime.strncmp(ptr2, "-Y ", 3uL) != 0)
			{
				return (float*)(int)((stbi__err("unsupported data layout") != 0) ? 0u : 0u);
			}
			ptr2 += 3;
			num3 = (int)CRuntime.strtol(ptr2, &ptr2, 10);
			for (; *ptr2 == 32; ptr2++)
			{
			}
			if (CRuntime.strncmp(ptr2, "+X ", 3uL) != 0)
			{
				return (float*)(int)((stbi__err("unsupported data layout") != 0) ? 0u : 0u);
			}
			ptr2 += 3;
			num2 = (int)CRuntime.strtol(ptr2, null, 10);
			if (num3 > 16777216)
			{
				return (float*)(int)((stbi__err("too large") != 0) ? 0u : 0u);
			}
			if (num2 > 16777216)
			{
				return (float*)(int)((stbi__err("too large") != 0) ? 0u : 0u);
			}
			*x = num2;
			*y = num3;
			if (comp != null)
			{
				*comp = 3;
			}
			if (req_comp == 0)
			{
				req_comp = 3;
			}
			if (stbi__mad4sizes_valid(num2, num3, req_comp, 4, 0) == 0)
			{
				return (float*)(int)((stbi__err("too large") != 0) ? 0u : 0u);
			}
			float* ptr3 = (float*)stbi__malloc_mad4(num2, num3, req_comp, 4, 0);
			if (ptr3 == null)
			{
				return (float*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			if (num2 < 8 || num2 >= 32768)
			{
				for (; j < num3; j++)
				{
					for (; i < num2; i++)
					{
						stbi__getn(s, ptr, 4);
						stbi__hdr_convert(ptr3 + j * num2 * req_comp + i * req_comp, ptr, req_comp);
					}
				}
			}
			else
			{
				byte* ptr4 = null;
				j = 0;
				while (true)
				{
					if (j < num3)
					{
						num6 = stbi__get8(s);
						num7 = stbi__get8(s);
						num4 = stbi__get8(s);
						if (num6 != 2 || num7 != 2 || (num4 & 0x80) != 0)
						{
							*ptr = (byte)num6;
							ptr[1] = (byte)num7;
							ptr[2] = (byte)num4;
							ptr[3] = stbi__get8(s);
							stbi__hdr_convert(ptr3, ptr, req_comp);
							CRuntime.free(ptr4);
							j = 0;
							for (i = 1; i < num2; i++)
							{
								stbi__getn(s, ptr, 4);
								stbi__hdr_convert(ptr3 + j * num2 * req_comp + i * req_comp, ptr, req_comp);
							}
							for (j = 1; j < num3; j++)
							{
								for (i = 0; i < num2; i++)
								{
									stbi__getn(s, ptr, 4);
									stbi__hdr_convert(ptr3 + j * num2 * req_comp + i * req_comp, ptr, req_comp);
								}
							}
							break;
						}
						num4 <<= 8;
						num4 |= stbi__get8(s);
						if (num4 != num2)
						{
							CRuntime.free(ptr3);
							CRuntime.free(ptr4);
							return (float*)(int)((stbi__err("invalid decoded scanline length") != 0) ? 0u : 0u);
						}
						if (ptr4 == null)
						{
							ptr4 = (byte*)stbi__malloc_mad2(num2, 4, 0);
							if (ptr4 == null)
							{
								CRuntime.free(ptr3);
								return (float*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
							}
						}
						for (num5 = 0; num5 < 4; num5++)
						{
							int num9 = 0;
							i = 0;
							while ((num9 = num2 - i) > 0)
							{
								b = stbi__get8(s);
								if (b > 128)
								{
									b2 = stbi__get8(s);
									b -= 128;
									if (b == 0 || b > num9)
									{
										CRuntime.free(ptr3);
										CRuntime.free(ptr4);
										return (float*)(int)((stbi__err("corrupt") != 0) ? 0u : 0u);
									}
									for (num8 = 0; num8 < b; num8++)
									{
										ptr4[i++ * 4 + num5] = b2;
									}
								}
								else
								{
									if (b == 0 || b > num9)
									{
										CRuntime.free(ptr3);
										CRuntime.free(ptr4);
										return (float*)(int)((stbi__err("corrupt") != 0) ? 0u : 0u);
									}
									for (num8 = 0; num8 < b; num8++)
									{
										ptr4[i++ * 4 + num5] = stbi__get8(s);
									}
								}
							}
						}
						for (i = 0; i < num2; i++)
						{
							stbi__hdr_convert(ptr3 + (j * num2 + i) * req_comp, ptr4 + i * 4, req_comp);
						}
						j++;
						continue;
					}
					if (ptr4 != null)
					{
						CRuntime.free(ptr4);
					}
					break;
				}
			}
			return ptr3;
		}

		public unsafe static int stbi__hdr_info(stbi__context s, int* x, int* y, int* comp)
		{
			sbyte* buffer = stackalloc sbyte[1024];
			int num = 0;
			int num2 = 0;
			if (x == null)
			{
				x = &num2;
			}
			if (y == null)
			{
				y = &num2;
			}
			if (comp == null)
			{
				comp = &num2;
			}
			if (stbi__hdr_test(s) == 0)
			{
				stbi__rewind(s);
				return 0;
			}
			sbyte* ptr;
			while (true)
			{
				ptr = stbi__hdr_gettoken(s, buffer);
				if (*ptr == 0)
				{
					break;
				}
				if (CRuntime.strcmp(ptr, "FORMAT=32-bit_rle_rgbe") == 0)
				{
					num = 1;
				}
			}
			if (num == 0)
			{
				stbi__rewind(s);
				return 0;
			}
			ptr = stbi__hdr_gettoken(s, buffer);
			if (CRuntime.strncmp(ptr, "-Y ", 3uL) != 0)
			{
				stbi__rewind(s);
				return 0;
			}
			ptr += 3;
			*y = (int)CRuntime.strtol(ptr, &ptr, 10);
			for (; *ptr == 32; ptr++)
			{
			}
			if (CRuntime.strncmp(ptr, "+X ", 3uL) != 0)
			{
				stbi__rewind(s);
				return 0;
			}
			ptr += 3;
			*x = (int)CRuntime.strtol(ptr, null, 10);
			*comp = 3;
			return 1;
		}

		public unsafe static byte* stbi__hdr_to_ldr(float* data, int x, int y, int comp)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			if (data == null)
			{
				return null;
			}
			byte* ptr = (byte*)stbi__malloc_mad3(x, y, comp, 0);
			if (ptr == null)
			{
				CRuntime.free(data);
				return (byte*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			num3 = (((comp & 1) == 0) ? (comp - 1) : comp);
			for (num = 0; num < x * y; num++)
			{
				for (num2 = 0; num2 < num3; num2++)
				{
					float num4 = (float)CRuntime.pow(data[num * comp + num2] * stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255f + 0.5f;
					if (num4 < 0f)
					{
						num4 = 0f;
					}
					if (num4 > 255f)
					{
						num4 = 255f;
					}
					ptr[num * comp + num2] = (byte)(int)num4;
				}
				if (num2 < comp)
				{
					float num5 = data[num * comp + num2] * 255f + 0.5f;
					if (num5 < 0f)
					{
						num5 = 0f;
					}
					if (num5 > 255f)
					{
						num5 = 255f;
					}
					ptr[num * comp + num2] = (byte)(int)num5;
				}
			}
			CRuntime.free(data);
			return ptr;
		}

		public static int stbi__hdr_test_core(stbi__context s, string signature)
		{
			int num = 0;
			for (num = 0; num < signature.Length; num++)
			{
				if (stbi__get8(s) != signature[num])
				{
					return 0;
				}
			}
			stbi__rewind(s);
			return 1;
		}

		public unsafe static sbyte* stbi__hdr_gettoken(stbi__context z, sbyte* buffer)
		{
			int num = 0;
			sbyte b = 0;
			b = (sbyte)stbi__get8(z);
			while (stbi__at_eof(z) == 0 && b != 10)
			{
				buffer[num++] = b;
				if (num == 1023)
				{
					while (stbi__at_eof(z) == 0 && stbi__get8(z) != 10)
					{
					}
					break;
				}
				b = (sbyte)stbi__get8(z);
			}
			buffer[num] = 0;
			return buffer;
		}

		public unsafe static void stbi__hdr_convert(float* output, byte* input, int req_comp)
		{
			if (input[3] != 0)
			{
				float num = 0f;
				num = (float)CRuntime.ldexp(1.0, input[3] - 136);
				if (req_comp <= 2)
				{
					*output = (float)(*input + input[1] + input[2]) * num / 3f;
				}
				else
				{
					*output = (float)(int)(*input) * num;
					output[1] = (float)(int)input[1] * num;
					output[2] = (float)(int)input[2] * num;
				}
				if (req_comp == 2)
				{
					output[1] = 1f;
				}
				if (req_comp == 4)
				{
					output[3] = 1f;
				}
			}
			else if ((uint)(req_comp - 1) > 1u)
			{
				switch (req_comp)
				{
				case 4:
					output[3] = 1f;
					break;
				case 3:
					break;
				default:
					return;
				}
				*output = (output[1] = (output[2] = 0f));
			}
			else
			{
				if (req_comp == 2)
				{
					output[1] = 1f;
				}
				*output = 0f;
			}
		}

		public static int stbi__jpeg_test(stbi__context s)
		{
			stbi__jpeg stbi__jpeg = new stbi__jpeg();
			if (stbi__jpeg == null)
			{
				return stbi__err("outofmem");
			}
			stbi__jpeg.s = s;
			stbi__setup_jpeg(stbi__jpeg);
			int result = stbi__decode_jpeg_header(stbi__jpeg, 1);
			stbi__rewind(s);
			return result;
		}

		public unsafe static void* stbi__jpeg_load(stbi__context s, int* x, int* y, int* comp, int req_comp, stbi__result_info* ri)
		{
			stbi__jpeg stbi__jpeg = new stbi__jpeg();
			if (stbi__jpeg == null)
			{
				return (void*)(int)((stbi__err("outofmem") != 0) ? 0u : 0u);
			}
			stbi__jpeg.s = s;
			stbi__setup_jpeg(stbi__jpeg);
			return load_jpeg_image(stbi__jpeg, x, y, comp, req_comp);
		}

		public unsafe static int stbi__jpeg_info(stbi__context s, int* x, int* y, int* comp)
		{
			stbi__jpeg stbi__jpeg = new stbi__jpeg();
			if (stbi__jpeg == null)
			{
				return stbi__err("outofmem");
			}
			stbi__jpeg.s = s;
			return stbi__jpeg_info_raw(stbi__jpeg, x, y, comp);
		}

		public unsafe static int stbi__build_huffman(stbi__huffman* h, int* count)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			uint num4 = 0u;
			for (num = 0; num < 16; num++)
			{
				for (num2 = 0; num2 < count[num]; num2++)
				{
					h->size[num3++] = (byte)(num + 1);
					if (num3 >= 257)
					{
						return stbi__err("bad size list");
					}
				}
			}
			h->size[num3] = 0;
			num4 = 0u;
			num3 = 0;
			for (num2 = 1; num2 <= 16; num2++)
			{
				h->delta[num2] = (int)(num3 - num4);
				if (h->size[num3] == num2)
				{
					while (h->size[num3] == num2)
					{
						h->code[num3++] = (ushort)num4++;
					}
					if (num4 - 1 >= (uint)(1 << num2))
					{
						return stbi__err("bad code lengths");
					}
				}
				h->maxcode[num2] = num4 << 16 - num2;
				num4 <<= 1;
			}
			h->maxcode[num2] = uint.MaxValue;
			CRuntime.memset(h->fast, 255, 512uL);
			for (num = 0; num < num3; num++)
			{
				int num5 = h->size[num];
				if (num5 <= 9)
				{
					int num6 = h->code[num] << 9 - num5;
					int num7 = 1 << 9 - num5;
					for (num2 = 0; num2 < num7; num2++)
					{
						h->fast[num6 + num2] = (byte)num;
					}
				}
			}
			return 1;
		}

		public unsafe static void stbi__build_fast_ac(short[] fast_ac, stbi__huffman* h)
		{
			int num = 0;
			for (num = 0; num < 512; num++)
			{
				byte b = h->fast[num];
				fast_ac[num] = 0;
				if (b >= byte.MaxValue)
				{
					continue;
				}
				byte num2 = h->values[(int)b];
				int num3 = (num2 >> 4) & 0xF;
				int num4 = num2 & 0xF;
				int num5 = h->size[(int)b];
				if (num4 != 0 && num5 + num4 <= 9)
				{
					int num6 = ((num << num5) & 0x1FF) >> 9 - num4;
					int num7 = 1 << num4 - 1;
					if (num6 < num7)
					{
						num6 += (-1 << num4) + 1;
					}
					if (num6 >= -128 && num6 <= 127)
					{
						fast_ac[num] = (short)(num6 * 256 + num3 * 16 + num5 + num4);
					}
				}
			}
		}

		public static void stbi__grow_buffer_unsafe(stbi__jpeg j)
		{
			do
			{
				uint num = (uint)((j.nomore == 0) ? stbi__get8(j.s) : 0);
				if (num == 255)
				{
					int num2 = stbi__get8(j.s);
					while (true)
					{
						switch (num2)
						{
						case 255:
							goto IL_002d;
						default:
							j.marker = (byte)num2;
							j.nomore = 1;
							return;
						case 0:
							break;
						}
						break;
						IL_002d:
						num2 = stbi__get8(j.s);
					}
				}
				j.code_buffer |= num << 24 - j.code_bits;
				j.code_bits += 8;
			}
			while (j.code_bits <= 24);
		}

		public unsafe static int stbi__jpeg_huff_decode(stbi__jpeg j, stbi__huffman* h)
		{
			uint num = 0u;
			int num2 = 0;
			int num3 = 0;
			if (j.code_bits < 16)
			{
				stbi__grow_buffer_unsafe(j);
			}
			num2 = (int)((j.code_buffer >> 23) & 0x1FF);
			num3 = h->fast[num2];
			if (num3 < 255)
			{
				int num4 = h->size[num3];
				if (num4 > j.code_bits)
				{
					return -1;
				}
				j.code_buffer <<= num4;
				j.code_bits -= num4;
				return h->values[num3];
			}
			num = j.code_buffer >> 16;
			for (num3 = 10; num >= h->maxcode[num3]; num3++)
			{
			}
			if (num3 == 17)
			{
				j.code_bits -= 16;
				return -1;
			}
			if (num3 > j.code_bits)
			{
				return -1;
			}
			num2 = (int)(((j.code_buffer >> 32 - num3) & stbi__bmask[num3]) + h->delta[num3]);
			if (num2 < 0 || num2 >= 256)
			{
				return -1;
			}
			j.code_bits -= num3;
			j.code_buffer <<= num3;
			return h->values[num2];
		}

		public static int stbi__extend_receive(stbi__jpeg j, int n)
		{
			uint num = 0u;
			int num2 = 0;
			if (j.code_bits < n)
			{
				stbi__grow_buffer_unsafe(j);
			}
			if (j.code_bits < n)
			{
				return 0;
			}
			num2 = (int)(j.code_buffer >> 31);
			num = CRuntime._lrotl(j.code_buffer, n);
			j.code_buffer = num & ~stbi__bmask[n];
			num &= stbi__bmask[n];
			j.code_bits -= n;
			return (int)(num + (stbi__jbias[n] & (num2 - 1)));
		}

		public static int stbi__jpeg_get_bits(stbi__jpeg j, int n)
		{
			uint num = 0u;
			if (j.code_bits < n)
			{
				stbi__grow_buffer_unsafe(j);
			}
			if (j.code_bits < n)
			{
				return 0;
			}
			num = CRuntime._lrotl(j.code_buffer, n);
			j.code_buffer = num & ~stbi__bmask[n];
			num &= stbi__bmask[n];
			j.code_bits -= n;
			return (int)num;
		}

		public static int stbi__jpeg_get_bit(stbi__jpeg j)
		{
			if (j.code_bits < 1)
			{
				stbi__grow_buffer_unsafe(j);
			}
			if (j.code_bits < 1)
			{
				return 0;
			}
			uint code_buffer = j.code_buffer;
			j.code_buffer <<= 1;
			j.code_bits--;
			return (int)code_buffer & int.MinValue;
		}

		public unsafe static int stbi__jpeg_decode_block(stbi__jpeg j, short* data, stbi__huffman* hdc, stbi__huffman* hac, short[] fac, int b, ushort[] dequant)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			if (j.code_bits < 16)
			{
				stbi__grow_buffer_unsafe(j);
			}
			num4 = stbi__jpeg_huff_decode(j, hdc);
			if (num4 < 0 || num4 > 15)
			{
				return stbi__err("bad huffman code");
			}
			CRuntime.memset(data, 0, 128uL);
			num = ((num4 != 0) ? stbi__extend_receive(j, num4) : 0);
			if (stbi__addints_valid(j.img_comp[b].dc_pred, num) == 0)
			{
				return stbi__err("bad delta");
			}
			num2 = j.img_comp[b].dc_pred + num;
			j.img_comp[b].dc_pred = num2;
			if (stbi__mul2shorts_valid(num2, dequant[0]) == 0)
			{
				return stbi__err("can't merge dc and ac");
			}
			*data = (short)(num2 * dequant[0]);
			num3 = 1;
			do
			{
				uint num5 = 0u;
				int num6 = 0;
				int num7 = 0;
				int num8 = 0;
				if (j.code_bits < 16)
				{
					stbi__grow_buffer_unsafe(j);
				}
				num6 = (int)((j.code_buffer >> 23) & 0x1FF);
				num7 = fac[num6];
				if (num7 != 0)
				{
					num3 += (num7 >> 4) & 0xF;
					num8 = num7 & 0xF;
					if (num8 > j.code_bits)
					{
						return stbi__err("bad huffman code");
					}
					j.code_buffer <<= num8;
					j.code_bits -= num8;
					num5 = stbi__jpeg_dezigzag[num3++];
					data[num5] = (short)((num7 >> 8) * dequant[num5]);
					continue;
				}
				int num9 = stbi__jpeg_huff_decode(j, hac);
				if (num9 < 0)
				{
					return stbi__err("bad huffman code");
				}
				num8 = num9 & 0xF;
				num7 = num9 >> 4;
				if (num8 == 0)
				{
					if (num9 != 240)
					{
						break;
					}
					num3 += 16;
				}
				else
				{
					num3 += num7;
					num5 = stbi__jpeg_dezigzag[num3++];
					data[num5] = (short)(stbi__extend_receive(j, num8) * dequant[num5]);
				}
			}
			while (num3 < 64);
			return 1;
		}

		public unsafe static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg j, short* data, stbi__huffman* hdc, int b)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			if (j.spec_end != 0)
			{
				return stbi__err("can't merge dc and ac");
			}
			if (j.code_bits < 16)
			{
				stbi__grow_buffer_unsafe(j);
			}
			if (j.succ_high == 0)
			{
				CRuntime.memset(data, 0, 128uL);
				num3 = stbi__jpeg_huff_decode(j, hdc);
				int num4;
				switch (num3)
				{
				default:
					return stbi__err("can't merge dc and ac");
				case 0:
					num4 = 0;
					break;
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 9:
				case 10:
				case 11:
				case 12:
				case 13:
				case 14:
				case 15:
					num4 = stbi__extend_receive(j, num3);
					break;
				}
				num = num4;
				if (stbi__addints_valid(j.img_comp[b].dc_pred, num) == 0)
				{
					return stbi__err("bad delta");
				}
				num2 = j.img_comp[b].dc_pred + num;
				j.img_comp[b].dc_pred = num2;
				if (stbi__mul2shorts_valid(num2, 1 << j.succ_low) == 0)
				{
					return stbi__err("can't merge dc and ac");
				}
				*data = (short)(num2 * (1 << j.succ_low));
			}
			else if (stbi__jpeg_get_bit(j) != 0)
			{
				*data += (short)(1 << j.succ_low);
			}
			return 1;
		}

		public unsafe static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg j, short* data, stbi__huffman* hac, short[] fac)
		{
			int num = 0;
			if (j.spec_start == 0)
			{
				return stbi__err("can't merge dc and ac");
			}
			if (j.succ_high == 0)
			{
				int succ_low = j.succ_low;
				if (j.eob_run != 0)
				{
					j.eob_run--;
					return 1;
				}
				num = j.spec_start;
				do
				{
					uint num2 = 0u;
					int num3 = 0;
					int num4 = 0;
					int num5 = 0;
					if (j.code_bits < 16)
					{
						stbi__grow_buffer_unsafe(j);
					}
					num3 = (int)((j.code_buffer >> 23) & 0x1FF);
					num4 = fac[num3];
					if (num4 != 0)
					{
						num += (num4 >> 4) & 0xF;
						num5 = num4 & 0xF;
						if (num5 > j.code_bits)
						{
							return stbi__err("bad huffman code");
						}
						j.code_buffer <<= num5;
						j.code_bits -= num5;
						num2 = stbi__jpeg_dezigzag[num++];
						data[num2] = (short)((num4 >> 8) * (1 << succ_low));
						continue;
					}
					int num6 = stbi__jpeg_huff_decode(j, hac);
					if (num6 < 0)
					{
						return stbi__err("bad huffman code");
					}
					num5 = num6 & 0xF;
					num4 = num6 >> 4;
					if (num5 == 0)
					{
						if (num4 < 15)
						{
							j.eob_run = 1 << num4;
							if (num4 != 0)
							{
								j.eob_run += stbi__jpeg_get_bits(j, num4);
							}
							j.eob_run--;
							break;
						}
						num += 16;
					}
					else
					{
						num += num4;
						num2 = stbi__jpeg_dezigzag[num++];
						data[num2] = (short)(stbi__extend_receive(j, num5) * (1 << succ_low));
					}
				}
				while (num <= j.spec_end);
			}
			else
			{
				short num7 = (short)(1 << j.succ_low);
				if (j.eob_run != 0)
				{
					j.eob_run--;
					for (num = j.spec_start; num <= j.spec_end; num++)
					{
						short* ptr = data + (int)stbi__jpeg_dezigzag[num];
						if (*ptr != 0 && stbi__jpeg_get_bit(j) != 0 && (*ptr & num7) == 0)
						{
							if (*ptr > 0)
							{
								*ptr += num7;
							}
							else
							{
								*ptr -= num7;
							}
						}
					}
				}
				else
				{
					num = j.spec_start;
					do
					{
						int num8 = 0;
						int num9 = 0;
						int num10 = stbi__jpeg_huff_decode(j, hac);
						if (num10 < 0)
						{
							return stbi__err("bad huffman code");
						}
						num9 = num10 & 0xF;
						num8 = num10 >> 4;
						switch (num9)
						{
						case 0:
							if (num8 < 15)
							{
								j.eob_run = (1 << num8) - 1;
								if (num8 != 0)
								{
									j.eob_run += stbi__jpeg_get_bits(j, num8);
								}
								num8 = 64;
							}
							break;
						default:
							return stbi__err("bad huffman code");
						case 1:
							num9 = ((stbi__jpeg_get_bit(j) == 0) ? (-num7) : num7);
							break;
						}
						while (num <= j.spec_end)
						{
							short* ptr2 = data + (int)stbi__jpeg_dezigzag[num++];
							if (*ptr2 != 0)
							{
								if (stbi__jpeg_get_bit(j) != 0 && (*ptr2 & num7) == 0)
								{
									if (*ptr2 > 0)
									{
										*ptr2 += num7;
									}
									else
									{
										*ptr2 -= num7;
									}
								}
							}
							else
							{
								if (num8 == 0)
								{
									*ptr2 = (short)num9;
									break;
								}
								num8--;
							}
						}
					}
					while (num <= j.spec_end);
				}
			}
			return 1;
		}

		public unsafe static void stbi__idct_block(byte* _out_, int out_stride, short* data)
		{
			int num = 0;
			int* ptr = stackalloc int[64];
			int* ptr2 = ptr;
			short* ptr3 = data;
			num = 0;
			while (num < 8)
			{
				if (ptr3[8] == 0 && ptr3[16] == 0 && ptr3[24] == 0 && ptr3[32] == 0 && ptr3[40] == 0 && ptr3[48] == 0 && ptr3[56] == 0)
				{
					int num2 = *ptr3 * 4;
					*ptr2 = (ptr2[8] = (ptr2[16] = (ptr2[24] = (ptr2[32] = (ptr2[40] = (ptr2[48] = (ptr2[56] = num2)))))));
				}
				else
				{
					int num3 = 0;
					int num4 = 0;
					int num5 = 0;
					int num6 = 0;
					int num7 = 0;
					int num8 = 0;
					int num9 = 0;
					int num10 = 0;
					int num11 = 0;
					int num12 = 0;
					int num13 = 0;
					int num14 = 0;
					num8 = ptr3[16];
					num9 = ptr3[48];
					num7 = (num8 + num9) * 2217;
					num5 = num7 + num9 * -7567;
					num6 = num7 + num8 * 3135;
					num8 = *ptr3;
					num9 = ptr3[32];
					num3 = (num8 + num9) * 4096;
					num4 = (num8 - num9) * 4096;
					num11 = num3 + num6;
					num14 = num3 - num6;
					num12 = num4 + num5;
					num13 = num4 - num5;
					num3 = ptr3[56];
					num4 = ptr3[40];
					num5 = ptr3[24];
					num6 = ptr3[8];
					num9 = num3 + num5;
					num10 = num4 + num6;
					num7 = num3 + num6;
					num8 = num4 + num5;
					int num15 = (num9 + num10) * 4816;
					num3 *= 1223;
					num4 *= 8410;
					num5 *= 12586;
					num6 *= 6149;
					num7 = num15 + num7 * -3685;
					num8 = num15 + num8 * -10497;
					num9 *= -8034;
					num10 *= -1597;
					num6 += num7 + num10;
					num5 += num8 + num9;
					num4 += num8 + num10;
					num3 += num7 + num9;
					num11 += 512;
					num12 += 512;
					num13 += 512;
					num14 += 512;
					*ptr2 = num11 + num6 >> 10;
					ptr2[56] = num11 - num6 >> 10;
					ptr2[8] = num12 + num5 >> 10;
					ptr2[48] = num12 - num5 >> 10;
					ptr2[16] = num13 + num4 >> 10;
					ptr2[40] = num13 - num4 >> 10;
					ptr2[24] = num14 + num3 >> 10;
					ptr2[32] = num14 - num3 >> 10;
				}
				num++;
				ptr3++;
				ptr2++;
			}
			num = 0;
			ptr2 = ptr;
			byte* ptr4 = _out_;
			while (num < 8)
			{
				int num16 = 0;
				int num17 = 0;
				int num18 = 0;
				int num19 = 0;
				int num20 = 0;
				int num21 = 0;
				int num22 = 0;
				int num23 = 0;
				int num24 = 0;
				int num25 = 0;
				int num26 = 0;
				int num27 = 0;
				num21 = ptr2[2];
				num22 = ptr2[6];
				num20 = (num21 + num22) * 2217;
				num18 = num20 + num22 * -7567;
				num19 = num20 + num21 * 3135;
				num21 = *ptr2;
				num22 = ptr2[4];
				num16 = (num21 + num22) * 4096;
				num17 = (num21 - num22) * 4096;
				num24 = num16 + num19;
				num27 = num16 - num19;
				num25 = num17 + num18;
				num26 = num17 - num18;
				num16 = ptr2[7];
				num17 = ptr2[5];
				num18 = ptr2[3];
				num19 = ptr2[1];
				num22 = num16 + num18;
				num23 = num17 + num19;
				num20 = num16 + num19;
				num21 = num17 + num18;
				int num28 = (num22 + num23) * 4816;
				num16 *= 1223;
				num17 *= 8410;
				num18 *= 12586;
				num19 *= 6149;
				num20 = num28 + num20 * -3685;
				num21 = num28 + num21 * -10497;
				num22 *= -8034;
				num23 *= -1597;
				num19 += num20 + num23;
				num18 += num21 + num22;
				num17 += num21 + num23;
				num16 += num20 + num22;
				num24 += 16842752;
				num25 += 16842752;
				num26 += 16842752;
				num27 += 16842752;
				*ptr4 = stbi__clamp(num24 + num19 >> 17);
				ptr4[7] = stbi__clamp(num24 - num19 >> 17);
				ptr4[1] = stbi__clamp(num25 + num18 >> 17);
				ptr4[6] = stbi__clamp(num25 - num18 >> 17);
				ptr4[2] = stbi__clamp(num26 + num17 >> 17);
				ptr4[5] = stbi__clamp(num26 - num17 >> 17);
				ptr4[3] = stbi__clamp(num27 + num16 >> 17);
				ptr4[4] = stbi__clamp(num27 - num16 >> 17);
				num++;
				ptr2 += 8;
				ptr4 += out_stride;
			}
		}

		public static byte stbi__get_marker(stbi__jpeg j)
		{
			byte b = 0;
			if (j.marker != byte.MaxValue)
			{
				b = j.marker;
				j.marker = byte.MaxValue;
				return b;
			}
			b = stbi__get8(j.s);
			if (b != byte.MaxValue)
			{
				return byte.MaxValue;
			}
			while (b == byte.MaxValue)
			{
				b = stbi__get8(j.s);
			}
			return b;
		}

		public static void stbi__jpeg_reset(stbi__jpeg j)
		{
			j.code_bits = 0;
			j.code_buffer = 0u;
			j.nomore = 0;
			j.img_comp[0].dc_pred = (j.img_comp[1].dc_pred = (j.img_comp[2].dc_pred = (j.img_comp[3].dc_pred = 0)));
			j.marker = byte.MaxValue;
			j.todo = ((j.restart_interval != 0) ? j.restart_interval : int.MaxValue);
			j.eob_run = 0;
		}

		public unsafe static int stbi__parse_entropy_coded_data(stbi__jpeg z)
		{
			stbi__jpeg_reset(z);
			if (z.progressive == 0)
			{
				if (z.scan_n == 1)
				{
					int num = 0;
					int num2 = 0;
					short* ptr = stackalloc short[64];
					int num3 = z.order[0];
					int num4 = z.img_comp[num3].x + 7 >> 3;
					int num5 = z.img_comp[num3].y + 7 >> 3;
					for (num2 = 0; num2 < num5; num2++)
					{
						for (num = 0; num < num4; num++)
						{
							int ha = z.img_comp[num3].ha;
							fixed (stbi__huffman* hdc = &z.huff_dc[z.img_comp[num3].hd])
							{
								fixed (stbi__huffman* hac = &z.huff_ac[ha])
								{
									if (stbi__jpeg_decode_block(z, ptr, hdc, hac, z.fast_ac[ha], num3, z.dequant[z.img_comp[num3].tq]) == 0)
									{
										return 0;
									}
								}
							}
							z.idct_block_kernel(z.img_comp[num3].data + z.img_comp[num3].w2 * num2 * 8 + num * 8, z.img_comp[num3].w2, ptr);
							if (--z.todo <= 0)
							{
								if (z.code_bits < 24)
								{
									stbi__grow_buffer_unsafe(z);
								}
								if (z.marker < 208 || z.marker > 215)
								{
									return 1;
								}
								stbi__jpeg_reset(z);
							}
						}
					}
					return 1;
				}
				int num6 = 0;
				int num7 = 0;
				int num8 = 0;
				int num9 = 0;
				int num10 = 0;
				short* ptr2 = stackalloc short[64];
				for (num7 = 0; num7 < z.img_mcu_y; num7++)
				{
					for (num6 = 0; num6 < z.img_mcu_x; num6++)
					{
						for (num8 = 0; num8 < z.scan_n; num8++)
						{
							int num11 = z.order[num8];
							for (num10 = 0; num10 < z.img_comp[num11].v; num10++)
							{
								for (num9 = 0; num9 < z.img_comp[num11].h; num9++)
								{
									int num12 = (num6 * z.img_comp[num11].h + num9) * 8;
									int num13 = (num7 * z.img_comp[num11].v + num10) * 8;
									int ha2 = z.img_comp[num11].ha;
									fixed (stbi__huffman* hdc2 = &z.huff_dc[z.img_comp[num11].hd])
									{
										fixed (stbi__huffman* hac2 = &z.huff_ac[ha2])
										{
											if (stbi__jpeg_decode_block(z, ptr2, hdc2, hac2, z.fast_ac[ha2], num11, z.dequant[z.img_comp[num11].tq]) == 0)
											{
												return 0;
											}
										}
									}
									z.idct_block_kernel(z.img_comp[num11].data + z.img_comp[num11].w2 * num13 + num12, z.img_comp[num11].w2, ptr2);
								}
							}
						}
						if (--z.todo <= 0)
						{
							if (z.code_bits < 24)
							{
								stbi__grow_buffer_unsafe(z);
							}
							if (z.marker < 208 || z.marker > 215)
							{
								return 1;
							}
							stbi__jpeg_reset(z);
						}
					}
				}
				return 1;
			}
			if (z.scan_n == 1)
			{
				int num14 = 0;
				int num15 = 0;
				int num16 = z.order[0];
				int num17 = z.img_comp[num16].x + 7 >> 3;
				int num18 = z.img_comp[num16].y + 7 >> 3;
				for (num15 = 0; num15 < num18; num15++)
				{
					for (num14 = 0; num14 < num17; num14++)
					{
						short* data = z.img_comp[num16].coeff + 64 * (num14 + num15 * z.img_comp[num16].coeff_w);
						if (z.spec_start == 0)
						{
							fixed (stbi__huffman* hdc3 = &z.huff_dc[z.img_comp[num16].hd])
							{
								if (stbi__jpeg_decode_block_prog_dc(z, data, hdc3, num16) == 0)
								{
									return 0;
								}
							}
						}
						else
						{
							int ha3 = z.img_comp[num16].ha;
							fixed (stbi__huffman* hac3 = &z.huff_ac[ha3])
							{
								if (stbi__jpeg_decode_block_prog_ac(z, data, hac3, z.fast_ac[ha3]) == 0)
								{
									return 0;
								}
							}
						}
						if (--z.todo <= 0)
						{
							if (z.code_bits < 24)
							{
								stbi__grow_buffer_unsafe(z);
							}
							if (z.marker < 208 || z.marker > 215)
							{
								return 1;
							}
							stbi__jpeg_reset(z);
						}
					}
				}
				return 1;
			}
			int num19 = 0;
			int num20 = 0;
			int num21 = 0;
			int num22 = 0;
			int num23 = 0;
			for (num20 = 0; num20 < z.img_mcu_y; num20++)
			{
				for (num19 = 0; num19 < z.img_mcu_x; num19++)
				{
					for (num21 = 0; num21 < z.scan_n; num21++)
					{
						int num24 = z.order[num21];
						for (num23 = 0; num23 < z.img_comp[num24].v; num23++)
						{
							for (num22 = 0; num22 < z.img_comp[num24].h; num22++)
							{
								int num25 = num19 * z.img_comp[num24].h + num22;
								int num26 = num20 * z.img_comp[num24].v + num23;
								short* data2 = z.img_comp[num24].coeff + 64 * (num25 + num26 * z.img_comp[num24].coeff_w);
								fixed (stbi__huffman* hdc4 = &z.huff_dc[z.img_comp[num24].hd])
								{
									if (stbi__jpeg_decode_block_prog_dc(z, data2, hdc4, num24) == 0)
									{
										return 0;
									}
								}
							}
						}
					}
					if (--z.todo <= 0)
					{
						if (z.code_bits < 24)
						{
							stbi__grow_buffer_unsafe(z);
						}
						if (z.marker < 208 || z.marker > 215)
						{
							return 1;
						}
						stbi__jpeg_reset(z);
					}
				}
			}
			return 1;
		}

		public unsafe static void stbi__jpeg_dequantize(short* data, ushort[] dequant)
		{
			int num = 0;
			for (num = 0; num < 64; num++)
			{
				data[num] *= (short)dequant[num];
			}
		}

		public unsafe static void stbi__jpeg_finish(stbi__jpeg z)
		{
			if (z.progressive == 0)
			{
				return;
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			for (num3 = 0; num3 < z.s.img_n; num3++)
			{
				int num4 = z.img_comp[num3].x + 7 >> 3;
				int num5 = z.img_comp[num3].y + 7 >> 3;
				for (num2 = 0; num2 < num5; num2++)
				{
					for (num = 0; num < num4; num++)
					{
						short* ptr = z.img_comp[num3].coeff + 64 * (num + num2 * z.img_comp[num3].coeff_w);
						stbi__jpeg_dequantize(ptr, z.dequant[z.img_comp[num3].tq]);
						z.idct_block_kernel(z.img_comp[num3].data + z.img_comp[num3].w2 * num2 * 8 + num * 8, z.img_comp[num3].w2, ptr);
					}
				}
			}
		}

		public unsafe static int stbi__process_marker(stbi__jpeg z, int m)
		{
			int num = 0;
			switch (m)
			{
			case 255:
				return stbi__err("expected marker");
			case 221:
				if (stbi__get16be(z.s) != 4)
				{
					return stbi__err("bad DRI len");
				}
				z.restart_interval = stbi__get16be(z.s);
				return 1;
			case 219:
				num = stbi__get16be(z.s) - 2;
				while (num > 0)
				{
					byte num11 = stbi__get8(z.s);
					int num12 = num11 >> 4;
					int num13 = ((num12 != 0) ? 1 : 0);
					int num14 = num11 & 0xF;
					int num15 = 0;
					if (num12 != 0 && num12 != 1)
					{
						return stbi__err("bad DQT type");
					}
					if (num14 > 3)
					{
						return stbi__err("bad DQT table");
					}
					for (num15 = 0; num15 < 64; num15++)
					{
						z.dequant[num14][stbi__jpeg_dezigzag[num15]] = (ushort)((num13 != 0) ? stbi__get16be(z.s) : stbi__get8(z.s));
					}
					num -= ((num13 != 0) ? 129 : 65);
				}
				return (num == 0) ? 1 : 0;
			case 196:
			{
				num = stbi__get16be(z.s) - 2;
				int* ptr = stackalloc int[16];
				while (num > 0)
				{
					int num6 = 0;
					int num7 = 0;
					byte num8 = stbi__get8(z.s);
					int num9 = num8 >> 4;
					int num10 = num8 & 0xF;
					if (num9 > 1 || num10 > 3)
					{
						return stbi__err("bad DHT header");
					}
					for (num6 = 0; num6 < 16; num6++)
					{
						ptr[num6] = stbi__get8(z.s);
						num7 += ptr[num6];
					}
					if (num7 > 256)
					{
						return stbi__err("bad DHT header");
					}
					num -= 17;
					if (num9 == 0)
					{
						fixed (stbi__huffman* ptr2 = &z.huff_dc[num10])
						{
							if (stbi__build_huffman(ptr2, ptr) == 0)
							{
								return 0;
							}
							byte* ptr3 = ptr2->values;
							for (num6 = 0; num6 < num7; num6++)
							{
								ptr3[num6] = stbi__get8(z.s);
							}
						}
					}
					else
					{
						fixed (stbi__huffman* ptr4 = &z.huff_ac[num10])
						{
							if (stbi__build_huffman(ptr4, ptr) == 0)
							{
								return 0;
							}
							byte* ptr5 = ptr4->values;
							for (num6 = 0; num6 < num7; num6++)
							{
								ptr5[num6] = stbi__get8(z.s);
							}
						}
					}
					if (num9 != 0)
					{
						fixed (stbi__huffman* h = &z.huff_ac[num10])
						{
							stbi__build_fast_ac(z.fast_ac[num10], h);
						}
					}
					num -= num7;
				}
				return (num == 0) ? 1 : 0;
			}
			default:
				if ((m >= 224 && m <= 239) || m == 254)
				{
					num = stbi__get16be(z.s);
					if (num < 2)
					{
						if (m == 254)
						{
							return stbi__err("bad COM len");
						}
						return stbi__err("bad APP len");
					}
					num -= 2;
					if (m == 224 && num >= 5)
					{
						int num2 = 1;
						int num3 = 0;
						for (num3 = 0; num3 < 5; num3++)
						{
							if (stbi__get8(z.s) != stbi__process_marker_tag[num3])
							{
								num2 = 0;
							}
						}
						num -= 5;
						if (num2 != 0)
						{
							z.jfif = 1;
						}
					}
					else if (m == 238 && num >= 12)
					{
						int num4 = 1;
						int num5 = 0;
						for (num5 = 0; num5 < 6; num5++)
						{
							if (stbi__get8(z.s) != stbi__process_marker_tag[num5])
							{
								num4 = 0;
							}
						}
						num -= 6;
						if (num4 != 0)
						{
							stbi__get8(z.s);
							stbi__get16be(z.s);
							stbi__get16be(z.s);
							z.app14_color_transform = stbi__get8(z.s);
							num -= 6;
						}
					}
					stbi__skip(z.s, num);
					return 1;
				}
				return stbi__err("unknown marker");
			}
		}

		public static int stbi__process_scan_header(stbi__jpeg z)
		{
			int num = 0;
			int num2 = stbi__get16be(z.s);
			z.scan_n = stbi__get8(z.s);
			if (z.scan_n < 1 || z.scan_n > 4 || z.scan_n > z.s.img_n)
			{
				return stbi__err("bad SOS component count");
			}
			if (num2 != 6 + 2 * z.scan_n)
			{
				return stbi__err("bad SOS len");
			}
			for (num = 0; num < z.scan_n; num++)
			{
				int num3 = stbi__get8(z.s);
				int num4 = 0;
				int num5 = stbi__get8(z.s);
				for (num4 = 0; num4 < z.s.img_n && z.img_comp[num4].id != num3; num4++)
				{
				}
				if (num4 == z.s.img_n)
				{
					return 0;
				}
				z.img_comp[num4].hd = num5 >> 4;
				if (z.img_comp[num4].hd > 3)
				{
					return stbi__err("bad DC huff");
				}
				z.img_comp[num4].ha = num5 & 0xF;
				if (z.img_comp[num4].ha > 3)
				{
					return stbi__err("bad AC huff");
				}
				z.order[num] = num4;
			}
			int num6 = 0;
			z.spec_start = stbi__get8(z.s);
			z.spec_end = stbi__get8(z.s);
			num6 = stbi__get8(z.s);
			z.succ_high = num6 >> 4;
			z.succ_low = num6 & 0xF;
			if (z.progressive != 0)
			{
				if (z.spec_start > 63 || z.spec_end > 63 || z.spec_start > z.spec_end || z.succ_high > 13 || z.succ_low > 13)
				{
					return stbi__err("bad SOS");
				}
			}
			else
			{
				if (z.spec_start != 0)
				{
					return stbi__err("bad SOS");
				}
				if (z.succ_high != 0 || z.succ_low != 0)
				{
					return stbi__err("bad SOS");
				}
				z.spec_end = 63;
			}
			return 1;
		}

		public unsafe static int stbi__free_jpeg_components(stbi__jpeg z, int ncomp, int why)
		{
			int num = 0;
			for (num = 0; num < ncomp; num++)
			{
				if (z.img_comp[num].raw_data != null)
				{
					CRuntime.free(z.img_comp[num].raw_data);
					z.img_comp[num].raw_data = null;
					z.img_comp[num].data = null;
				}
				if (z.img_comp[num].raw_coeff != null)
				{
					CRuntime.free(z.img_comp[num].raw_coeff);
					z.img_comp[num].raw_coeff = null;
					z.img_comp[num].coeff = null;
				}
				if (z.img_comp[num].linebuf != null)
				{
					CRuntime.free(z.img_comp[num].linebuf);
					z.img_comp[num].linebuf = null;
				}
			}
			return why;
		}

		public unsafe static int stbi__process_frame_header(stbi__jpeg z, int scan)
		{
			stbi__context s = z.s;
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 1;
			int num5 = 1;
			int num6 = 0;
			num = stbi__get16be(s);
			if (num < 11)
			{
				return stbi__err("bad SOF len");
			}
			if (stbi__get8(s) != 8)
			{
				return stbi__err("only 8-bit");
			}
			s.img_y = (uint)stbi__get16be(s);
			if (s.img_y == 0)
			{
				return stbi__err("no header height");
			}
			s.img_x = (uint)stbi__get16be(s);
			if (s.img_x == 0)
			{
				return stbi__err("0 width");
			}
			if (s.img_y > 16777216)
			{
				return stbi__err("too large");
			}
			if (s.img_x > 16777216)
			{
				return stbi__err("too large");
			}
			num6 = stbi__get8(s);
			if (num6 != 3 && num6 != 1 && num6 != 4)
			{
				return stbi__err("bad component count");
			}
			s.img_n = num6;
			for (num2 = 0; num2 < num6; num2++)
			{
				z.img_comp[num2].data = null;
				z.img_comp[num2].linebuf = null;
			}
			if (num != 8 + 3 * s.img_n)
			{
				return stbi__err("bad SOF len");
			}
			z.rgb = 0;
			for (num2 = 0; num2 < s.img_n; num2++)
			{
				z.img_comp[num2].id = stbi__get8(s);
				if (s.img_n == 3 && z.img_comp[num2].id == stbi__process_frame_header_rgb[num2])
				{
					z.rgb++;
				}
				num3 = stbi__get8(s);
				z.img_comp[num2].h = num3 >> 4;
				if (z.img_comp[num2].h == 0 || z.img_comp[num2].h > 4)
				{
					return stbi__err("bad H");
				}
				z.img_comp[num2].v = num3 & 0xF;
				if (z.img_comp[num2].v == 0 || z.img_comp[num2].v > 4)
				{
					return stbi__err("bad V");
				}
				z.img_comp[num2].tq = stbi__get8(s);
				if (z.img_comp[num2].tq > 3)
	

BepInEx\plugins\AdamMady_Minimap.dll

Decompiled 15 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Mirror;
using ModSettingsMenu.Api;
using StbImageSharp;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SupportedOSPlatform("windows")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AdamMady_Minimap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("Mady's MiniMap")]
[assembly: AssemblyTitle("AdamMady_Minimap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AdamMady.Minimap
{
	public sealed class MapController : MonoBehaviour
	{
		private MapData data;

		private bool open;

		private bool cursorOwned;

		private bool oldCursorVisible;

		private bool oldMenuMode;

		private bool dragging;

		private bool searchFocused;

		private CursorLockMode oldCursorLock;

		private float zoom = 11f;

		private float zoomTarget = 11f;

		private float nextMiniUpdate;

		private Vector2 zoomAnchorMap;

		private Vector2 zoomAnchorScreen;

		private bool zooming;

		private Vector2 center = new Vector2(4096f, 4096f);

		private RenderTexture miniTexture;

		private Material miniMapMaterial;

		private Material miniMaskMaterial;

		private Texture2D miniBorderOverlay;

		private int miniBorderSize;

		private MinimapShape miniBorderShape;

		private MinimapBorderColor miniBorderColor;

		private GUIStyle compassStyle;

		private int miniTextureSize;

		private string title = "";

		private string status = "";

		private string renderFailure;

		private float nextRenderFailureLog;

		private bool loaded;

		private Vector2 miniCenterMap;

		private Vector2 miniCenterSmooth;

		private Vector2 miniForward = new Vector2(0f, -1f);

		private Vector2 miniRight = Vector2.right;

		private float miniAngleSmooth;

		private bool miniPoseReady;

		private bool miniOutsideMap;

		private PlayerCharacter currentLocal;

		private bool miniRotated;

		private bool miniHasFrame;

		private bool miniRenderedBlips;

		private Vector2 miniRenderedCenter;

		private float miniRenderedAngle;

		private float miniRenderedZoom;

		private int miniRenderedSize;

		private MinimapShape miniRenderedShape;

		private MinimapBorderColor miniRenderedBorder;

		private string miniRenderedSearch = "";

		private PropertyInfo hideNSeekSuppressBlips;

		private PropertyInfo hideNSeekSuppressMinimap;

		private float nextHideNSeekLookup;

		private float nextHideNSeekMinimapLookup;

		private string search = "";

		private static readonly Color[] WaypointColors = (Color[])(object)new Color[6]
		{
			Color.white,
			new Color(1f, 0.5f, 0.5f),
			new Color(0.5f, 1f, 0.5f),
			new Color(0.55f, 0.85f, 1f),
			new Color(1f, 0.6f, 1f),
			new Color(1f, 0.9f, 0.5f)
		};

		private readonly HashSet<string> usedTiles = new HashSet<string>();

		private readonly List<PlayerCharacter> playerSnapshot = new List<PlayerCharacter>();

		private Rect SearchRect => new Rect((float)Mathf.Max(610, Screen.width - 550), 14f, 410f, 30f);

		public static bool IsOpen { get; private set; }

		private float Scale => Mathf.Pow(2f, zoom - 13f);

		private float MarkerScale => Mathf.Lerp(0.5f, 1.45f, (zoom - 8f) / 6f);

		public MapController(IntPtr pointer)
			: base(pointer)
		{
		}//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_004c: 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_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)


		private void Update()
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: 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_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			if (!loaded)
			{
				try
				{
					data = new MapData();
					data.Load();
					loaded = true;
				}
				catch (Exception ex)
				{
					status = "Map assets failed: " + ex.Message;
					Debug.LogError(Object.op_Implicit("[Minimap] " + status));
					((Behaviour)this).enabled = false;
					return;
				}
			}
			PlayerCharacter val = LocalPlayer();
			if (!Plugin.Enabled.Value || (Object)(object)val == (Object)null)
			{
				if (open)
				{
					SetOpen(value: false);
				}
				miniPoseReady = false;
				return;
			}
			if ((Object)(object)val != (Object)(object)currentLocal)
			{
				currentLocal = val;
				miniPoseReady = false;
				miniHasFrame = false;
				nextMiniUpdate = 0f;
				renderFailure = null;
			}
			if (open && IsModerationOpen())
			{
				SetOpen(value: false);
				return;
			}
			if ((!ControlsManager.menuModeActive || open) && Input.GetKeyDown(Plugin.MapKey.Value) && (!open || !searchFocused))
			{
				SetOpen(!open);
			}
			if (open && Input.GetKeyDown((KeyCode)27))
			{
				SetOpen(value: false);
			}
			if (open)
			{
				if (Input.GetKeyDown(Plugin.ZoomInKey.Value))
				{
					ZoomAround(new Vector2((float)Screen.width / 2f, (float)Screen.height / 2f), 0.5f);
				}
				if (Input.GetKeyDown(Plugin.ZoomOutKey.Value))
				{
					ZoomAround(new Vector2((float)Screen.width / 2f, (float)Screen.height / 2f), -0.5f);
				}
				UpdateSmoothZoom();
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			if (open || !Plugin.ShowMinimap.Value || !data.Calibration.Ready)
			{
				return;
			}
			Vector2 val2 = data.Calibration.ToMap(((Component)val).transform.position);
			miniOutsideMap = data.Outside(val2);
			if (miniOutsideMap)
			{
				miniHasFrame = false;
				return;
			}
			Vector3 forward = (((Object)(object)val.cameraTransform != (Object)null) ? val.cameraTransform.forward : ((Component)val).transform.forward);
			Vector2 val3 = data.Calibration.Facing(forward);
			float num = Mathf.Atan2(val3.x, 0f - val3.y) * 57.29578f;
			Vector2 val4;
			if (miniPoseReady)
			{
				val4 = val2 - miniCenterSmooth;
				if (!(((Vector2)(ref val4)).sqrMagnitude > 202500f))
				{
					float num2 = 1f - Mathf.Exp(-18f * Time.unscaledDeltaTime);
					miniCenterSmooth = Vector2.Lerp(miniCenterSmooth, val2, num2);
					miniAngleSmooth = Mathf.LerpAngle(miniAngleSmooth, num, num2);
					goto IL_0313;
				}
			}
			miniCenterSmooth = val2;
			miniAngleSmooth = num;
			miniPoseReady = true;
			nextMiniUpdate = 0f;
			goto IL_0313;
			IL_0313:
			if (!(Time.unscaledTime >= nextMiniUpdate))
			{
				return;
			}
			nextMiniUpdate = Time.unscaledTime + 1f / 30f;
			if (miniHasFrame)
			{
				val4 = miniCenterSmooth - miniRenderedCenter;
				if (!(((Vector2)(ref val4)).sqrMagnitude > 0.25f) && (!Plugin.RotateMinimap.Value || !(Mathf.Abs(Mathf.DeltaAngle(miniAngleSmooth, miniRenderedAngle)) > 0.25f)) && Plugin.RotateMinimap.Value == miniRotated && Plugin.MiniSize.Value == miniRenderedSize && Mathf.Approximately(Plugin.MiniZoom.Value, miniRenderedZoom) && Plugin.Shape.Value == miniRenderedShape && Plugin.BorderColor.Value == miniRenderedBorder && Plugin.ShowBlips.Value == miniRenderedBlips && !(search != miniRenderedSearch))
				{
					return;
				}
			}
			miniCenterMap = miniCenterSmooth;
			UpdateMini();
			miniRenderedCenter = miniCenterMap;
			miniRenderedAngle = miniAngleSmooth;
			miniRenderedSize = Plugin.MiniSize.Value;
			miniRenderedZoom = Plugin.MiniZoom.Value;
			miniRenderedShape = Plugin.Shape.Value;
			miniRenderedBorder = Plugin.BorderColor.Value;
			miniRenderedBlips = Plugin.ShowBlips.Value;
			miniRenderedSearch = search;
			miniHasFrame = true;
		}

		private void SetOpen(bool value)
		{
			//IL_0036: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (open == value)
			{
				return;
			}
			open = value;
			IsOpen = value;
			dragging = false;
			searchFocused = false;
			if (open)
			{
				CloseModerationMenu();
				oldCursorLock = Cursor.lockState;
				oldCursorVisible = Cursor.visible;
				oldMenuMode = ControlsManager.menuModeActive;
				cursorOwned = true;
				ControlsManager.SetMenuMode(true);
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
				PlayerCharacter val = LocalPlayer();
				if ((Object)(object)val != (Object)null && data.Calibration.Ready)
				{
					center = data.Calibration.ToMap(((Component)val).transform.position);
				}
			}
			else if (cursorOwned)
			{
				ControlsManager.SetMenuMode(oldMenuMode);
				Cursor.lockState = oldCursorLock;
				Cursor.visible = oldCursorVisible;
				cursorOwned = false;
			}
		}

		public static void CloseMenu()
		{
			Il2CppArrayBase<MapController> val = Object.FindObjectsOfType<MapController>(true);
			for (int i = 0; i < val.Length; i++)
			{
				val[i]?.SetOpen(value: false);
			}
		}

		private static Type ModerationMenuType()
		{
			return Type.GetType("BigOrb.OrbMenu, ModerationImprovements", throwOnError: false);
		}

		private static bool IsModerationOpen()
		{
			try
			{
				return (bool?)ModerationMenuType()?.GetProperty("IsOpen", BindingFlags.Static | BindingFlags.Public)?.GetValue(null) == true;
			}
			catch
			{
				return false;
			}
		}

		private static void CloseModerationMenu()
		{
			try
			{
				ModerationMenuType()?.GetMethod("CloseMenu", BindingFlags.Static | BindingFlags.Public)?.Invoke(null, null);
			}
			catch
			{
			}
		}

		private void OnDestroy()
		{
			if (open)
			{
				SetOpen(value: false);
			}
			if (data != null)
			{
				foreach (Texture2D value in data.Icons.Values)
				{
					Object.Destroy((Object)(object)value);
				}
				foreach (Texture2D value2 in data.TileCache.Values)
				{
					Object.Destroy((Object)(object)value2);
				}
				if ((Object)(object)data.PreviewTexture != (Object)null)
				{
					Object.Destroy((Object)(object)data.PreviewTexture);
				}
			}
			if ((Object)(object)miniTexture != (Object)null)
			{
				miniTexture.Release();
				Object.Destroy((Object)(object)miniTexture);
			}
			if ((Object)(object)miniMapMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)miniMapMaterial);
			}
			if ((Object)(object)miniMaskMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)miniMaskMaterial);
			}
			if ((Object)(object)miniBorderOverlay != (Object)null)
			{
				Object.Destroy((Object)(object)miniBorderOverlay);
			}
		}

		private static PlayerCharacter LocalPlayer()
		{
			List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
			if (allPlayerCharacters == null)
			{
				return null;
			}
			for (int num = allPlayerCharacters.Count - 1; num >= 0; num--)
			{
				PlayerCharacter val = allPlayerCharacters[num];
				if (val != null)
				{
					PlayerNetworking playerNetworking = val.playerNetworking;
					if (((playerNetworking != null) ? new bool?(((NetworkBehaviour)playerNetworking).isLocalPlayer) : ((bool?)null)) == true && (Object)(object)((Component)val).gameObject != (Object)null && ((Component)val).gameObject.activeInHierarchy && (Object)(object)((NetworkBehaviour)val.playerNetworking).netIdentity != (Object)null && ((NetworkBehaviour)val.playerNetworking).netIdentity.isClient)
					{
						return val;
					}
				}
			}
			return null;
		}

		private void OnGUI()
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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: Invalid comparison between Unknown and I4
			if (!loaded || !Plugin.Enabled.Value)
			{
				return;
			}
			if (!open)
			{
				Event current = Event.current;
				if (current == null || (int)current.type != 7)
				{
					return;
				}
			}
			PlayerCharacter val = LocalPlayer();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			try
			{
				if (open)
				{
					DrawFull(val);
				}
				else if (Plugin.ShowMinimap.Value && !IsModerationOpen() && !HideNSeekSuppressesMinimap())
				{
					DrawMini(val);
				}
				renderFailure = null;
			}
			catch (Exception ex)
			{
				renderFailure = "Map render failed: " + ex.Message + ". Press " + ((object)Plugin.MapKey.Value/*cast due to .constrained prefix*/).ToString() + " to close.";
				miniHasFrame = false;
				if ((Object)(object)miniTexture == (Object)null)
				{
					miniTextureSize = 0;
				}
				if (Time.unscaledTime >= nextRenderFailureLog)
				{
					nextRenderFailureLog = Time.unscaledTime + 2f;
					Debug.LogError(Object.op_Implicit("[Minimap] " + ex));
				}
				if (open)
				{
					GUI.Box(new Rect(25f, 68f, (float)(Screen.width - 50), 70f), renderFailure);
				}
			}
		}

		private Rect ViewRect()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(25f, 68f, (float)Mathf.Max(100, Screen.width - 50), (float)Mathf.Max(100, Screen.height - 120));
		}

		private Vector2 MapToScreen(Vector2 pixel, Rect view)
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			return ((Rect)(ref view)).center + (pixel - center) * Scale;
		}

		private Vector2 ScreenToMap(Vector2 screen, Rect view)
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			return center + (screen - ((Rect)(ref view)).center) / Scale;
		}

		private void DrawFull(PlayerCharacter local)
		{
			//IL_0000: 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_0039: 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_0053: 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_005f: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: 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_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			Color color = GUI.color;
			GUI.color = new Color(0.04f, 0.07f, 0.1f, 0.96f);
			GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color;
			Rect val = ViewRect();
			GUI.Box(val, GUIContent.none);
			GUI.BeginGroup(val);
			DrawTiles(new Rect(0f, 0f, ((Rect)(ref val)).width, ((Rect)(ref val)).height));
			if (Plugin.ShowBlips.Value || HasSelectedLocations())
			{
				DrawLocations(val);
			}
			DrawWaypoints(val);
			if (data.Calibration.Ready)
			{
				DrawPlayerOnMap(local, val);
			}
			if (Plugin.TrackPlayers.Value && data.Calibration.Ready && !HideNSeekSuppressesPlayerBlips())
			{
				DrawOtherPlayers(val, mini: false, 0);
			}
			GUI.EndGroup();
			GUI.Label(new Rect(30f, 14f, 210f, 30f), "Mady's MiniMap  |  Zoom " + zoom.ToString("0.0") + " / 14");
			if (GUI.Button(new Rect(245f, 12f, 70f, 34f), "−"))
			{
				ZoomAround(((Rect)(ref val)).center, -0.5f);
			}
			if (GUI.Button(new Rect(318f, 12f, 70f, 34f), "+"))
			{
				ZoomAround(((Rect)(ref val)).center, 0.5f);
			}
			if (GUI.Button(new Rect(392f, 12f, 95f, 34f), "My position") && data.Calibration.Ready)
			{
				center = data.Calibration.ToMap(((Component)local).transform.position);
			}
			if (GUI.Button(new Rect((float)(Screen.width - 110), 12f, 85f, 34f), "Close"))
			{
				SetOpen(value: false);
			}
			DrawSearch();
			string text = ((!string.IsNullOrEmpty(title)) ? title : status);
			GUI.Label(new Rect(30f, (float)(Screen.height - 43), (float)(Screen.width - 60), 24f), text);
			HandleMapEvent(val);
		}

		private void DrawSearch()
		{
			//IL_0001: 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_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Invalid comparison between Unknown and I4
			GUI.Box(SearchRect, (search.Length == 0 && !searchFocused) ? "Type to filter" : (search + (searchFocused ? "|" : "")), GUI.skin.textField);
			Event current = Event.current;
			if (current == null)
			{
				return;
			}
			if ((int)current.type == 0)
			{
				Rect searchRect = SearchRect;
				searchFocused = ((Rect)(ref searchRect)).Contains(current.mousePosition);
				if (searchFocused)
				{
					current.Use();
				}
			}
			else if (searchFocused && (int)current.type == 4)
			{
				if ((int)current.keyCode == 8 && search.Length > 0)
				{
					search = search.Substring(0, search.Length - 1);
				}
				else if ((int)current.keyCode == 127)
				{
					search = "";
				}
				else if (current.character >= ' ' && !char.IsControl(current.character))
				{
					search += current.character;
				}
				current.Use();
			}
		}

		private void DrawTiles(Rect clip)
		{
			//IL_004e: 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_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_0069: 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_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_0077: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: 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)
			int num = Mathf.Clamp(Mathf.FloorToInt(zoom), 8, 13);
			float num2 = 256f * Mathf.Pow(2f, zoom - (float)num);
			int num3 = 1 << 13 - num;
			usedTiles.Clear();
			Vector2 val = ScreenToMap(new Vector2(0f, 0f), clip);
			Vector2 val2 = ScreenToMap(new Vector2(((Rect)(ref clip)).width, ((Rect)(ref clip)).height), clip);
			int num4 = Mathf.Max(0, Mathf.FloorToInt((val.x + (float)(data.MinTileX * 256)) / (256f * (float)num3)));
			int num5 = Mathf.Max(0, Mathf.FloorToInt((val.y + (float)(data.MinTileY * 256)) / (256f * (float)num3)));
			int num6 = Mathf.CeilToInt((val2.x + (float)(data.MinTileX * 256)) / (256f * (float)num3));
			int num7 = Mathf.CeilToInt((val2.y + (float)(data.MinTileY * 256)) / (256f * (float)num3));
			for (int i = num5; i <= num7; i++)
			{
				for (int j = num4; j <= num6; j++)
				{
					Texture2D val3 = data.Tile(num, j, i);
					if (!((Object)(object)val3 == (Object)null))
					{
						float num8 = (float)j * 256f * (float)num3 - (float)data.MinTileX * 256f;
						float num9 = (float)i * 256f * (float)num3 - (float)data.MinTileY * 256f;
						Vector2 val4 = MapToScreen(new Vector2(num8, num9), clip);
						GUI.DrawTexture(new Rect(val4.x, val4.y, num2 + 0.5f, num2 + 0.5f), (Texture)(object)val3);
						usedTiles.Add(num + "/" + i + "/" + j);
					}
				}
			}
			data.TrimTiles(usedTiles);
		}

		private void DrawLocations(Rect view)
		{
			//IL_0071: 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_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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			foreach (MapLocation location in data.Locations)
			{
				if (data.Waypoints.Find((Waypoint w) => w.LocationId == location.Id) != null || (Plugin.ShowBlips.Value && MatchesSearch(location)))
				{
					Vector2 val = MapToScreen(location.Pixel, new Rect(0f, 0f, ((Rect)(ref view)).width, ((Rect)(ref view)).height));
					if (!(val.x < -40f) && !(val.y < -50f) && !(val.x > ((Rect)(ref view)).width + 40f) && !(val.y > ((Rect)(ref view)).height + 50f))
					{
						Texture2D val2 = data.Icon(location.Icon);
						float num = (float)((Texture)val2).width * MarkerScale;
						float num2 = (float)((Texture)val2).height * MarkerScale;
						GUI.DrawTexture(new Rect(val.x - num / 2f, val.y - num2, num, num2), (Texture)(object)val2);
					}
				}
			}
		}

		private void DrawWaypoints(Rect view)
		{
			//IL_0034: 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_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_005c: 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_007c: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			foreach (Waypoint waypoint in data.Waypoints)
			{
				if (waypoint.LocationId == 0 && !MatchesWaypointSearch(waypoint))
				{
					continue;
				}
				Vector2 val = MapToScreen(waypoint.Pixel, new Rect(0f, 0f, ((Rect)(ref view)).width, ((Rect)(ref view)).height));
				if (!(val.x < -40f) && !(val.y < -50f) && !(val.x > ((Rect)(ref view)).width + 40f) && !(val.y > ((Rect)(ref view)).height + 50f))
				{
					Texture2D val2 = data.Icon("Waypoint");
					GUI.color = WaypointTint(waypoint);
					if (waypoint.Hidden)
					{
						GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.35f);
					}
					GUI.DrawTexture(new Rect(val.x - 17f, val.y - 44f, 33f, 44f), (Texture)(object)val2);
					GUI.color = Color.white;
				}
			}
		}

		private void DrawPlayerOnMap(PlayerCharacter local, Rect view)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_003e: 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_004c: 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_0068: 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)
			Vector2 val = MapToScreen(data.Calibration.ToMap(((Component)local).transform.position), new Rect(0f, 0f, ((Rect)(ref view)).width, ((Rect)(ref view)).height));
			if (!(val.x < 0f) && !(val.y < 0f) && !(val.x > ((Rect)(ref view)).width) && !(val.y > ((Rect)(ref view)).height))
			{
				DrawSelfBlip(val, local, 22);
			}
		}

		private void DrawOtherPlayers(Rect view, bool mini, int size)
		{
			//IL_0089: 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_00c0: 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_0099: 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)
			//IL_00b8: 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_010f: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
			if (allPlayerCharacters == null)
			{
				return;
			}
			playerSnapshot.Clear();
			for (int i = 0; i < allPlayerCharacters.Count; i++)
			{
				playerSnapshot.Add(allPlayerCharacters[i]);
			}
			foreach (PlayerCharacter item in playerSnapshot)
			{
				if ((Object)(object)((item != null) ? item.playerNetworking : null) == (Object)null || ((NetworkBehaviour)item.playerNetworking).isLocalPlayer)
				{
					continue;
				}
				Vector2 pixel = data.Calibration.ToMap(((Component)item).transform.position);
				Vector2 val = (mini ? MiniPoint(pixel, size) : MapToScreen(pixel, new Rect(0f, 0f, ((Rect)(ref view)).width, ((Rect)(ref view)).height)));
				bool num;
				if (!mini)
				{
					if (val.x < 0f || val.y < 0f || val.x > ((Rect)(ref view)).width)
					{
						continue;
					}
					num = val.y > ((Rect)(ref view)).height;
				}
				else
				{
					num = !MiniRectIntersects(val.x - 9f, val.y - 9f, val.x + 9f, val.y + 9f, size);
				}
				if (num)
				{
					continue;
				}
				PlayerLooks looks = item.looks;
				Color color = ((looks != null) ? looks.headColor.color : Color.gray);
				color.a = 1f;
				GUI.color = color;
				Texture2D val2 = data.Icon("PlayerBlip");
				float num2 = (mini ? 18f : 22f);
				GUI.DrawTexture(new Rect(val.x - num2 / 2f, val.y - num2 / 2f, num2, num2), (Texture)(object)val2);
				GUI.color = Color.white;
				if (!mini)
				{
					string text = item.playerNetworking.moderationNameSanitized;
					if (string.IsNullOrWhiteSpace(text))
					{
						text = item.playerNetworking.moderationName;
					}
					if (string.IsNullOrWhiteSpace(text))
					{
						text = item.playerNetworking.username;
					}
					GUI.Label(new Rect(val.x - 110f, val.y - 34f, 220f, 24f), text ?? "Player", CenteredStyle());
				}
			}
		}

		private void HandleMapEvent(Rect view)
		{
			//IL_0011: 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_0018: 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_0021: 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_0031: Invalid comparison between Unknown and I4
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Invalid comparison between Unknown and I4
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Invalid comparison between Unknown and I4
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0081: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00bd: 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_00c3: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			if (current == null)
			{
				return;
			}
			Vector2 mousePosition = current.mousePosition;
			Rect searchRect = SearchRect;
			if (((Rect)(ref searchRect)).Contains(mousePosition))
			{
				return;
			}
			if ((int)current.type == 6 && ((Rect)(ref view)).Contains(mousePosition))
			{
				ZoomAround(mousePosition, (0f - current.delta.y) * 0.15f);
				current.Use();
			}
			else if ((int)current.type == 3 && dragging)
			{
				center -= current.delta / Scale;
				current.Use();
			}
			else if ((int)current.type == 1)
			{
				dragging = false;
			}
			else
			{
				if ((int)current.type != 0 || !((Rect)(ref view)).Contains(mousePosition))
				{
					return;
				}
				Vector2 pixel = ScreenToMap(mousePosition, view);
				Waypoint waypoint = HitWaypoint(mousePosition, view);
				if (waypoint != null)
				{
					if (current.button == (int)Plugin.HideButton.Value)
					{
						waypoint.Hidden = !waypoint.Hidden;
						SaveWaypoints();
						title = waypoint.Title + (waypoint.Hidden ? " (tracking hidden)" : " (tracking visible)");
						if (current.button == (int)Plugin.InspectButton.Value)
						{
							dragging = true;
						}
					}
					else if (current.button == (int)Plugin.AddButton.Value)
					{
						data.Waypoints.Remove(waypoint);
						SaveWaypoints();
						title = "Waypoint removed";
					}
					current.Use();
					return;
				}
				MapLocation location = (Plugin.ShowBlips.Value ? HitLocation(mousePosition, view) : null);
				if (location != null)
				{
					if (current.button == (int)Plugin.InspectButton.Value)
					{
						title = location.Title;
						dragging = true;
					}
					else if (current.button == (int)Plugin.AddButton.Value)
					{
						Waypoint waypoint2 = data.Waypoints.Find((Waypoint w) => w.LocationId == location.Id);
						if (waypoint2 != null)
						{
							data.Waypoints.Remove(waypoint2);
							title = location.Title + " deselected";
						}
						else
						{
							data.Waypoints.Add(NewWaypoint(location.Pixel, location.Icon, location.Title, location.Id));
							title = location.Title + " selected";
						}
						SaveWaypoints();
					}
					current.Use();
				}
				else if (current.button == (int)Plugin.AddButton.Value)
				{
					data.Waypoints.Add(NewWaypoint(pixel, "point_of_interest", "Waypoint " + (data.Waypoints.Count + 1), 0));
					SaveWaypoints();
					title = "Waypoint added";
					current.Use();
				}
				else if (current.button == (int)Plugin.InspectButton.Value)
				{
					dragging = true;
				}
			}
		}

		[HideFromIl2Cpp]
		private MapLocation HitLocation(Vector2 mouse, Rect view)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			for (int num = data.Locations.Count - 1; num >= 0; num--)
			{
				MapLocation mapLocation = data.Locations[num];
				if (MatchesSearch(mapLocation))
				{
					Vector2 val = MapToScreen(mapLocation.Pixel, view);
					Texture2D obj = data.Icon(mapLocation.Icon);
					float num2 = (float)((Texture)obj).width * MarkerScale;
					float num3 = (float)((Texture)obj).height * MarkerScale;
					Rect val2 = new Rect(val.x - num2 / 2f, val.y - num3, num2, num3);
					if (((Rect)(ref val2)).Contains(mouse))
					{
						return mapLocation;
					}
				}
			}
			return null;
		}

		[HideFromIl2Cpp]
		private Waypoint HitWaypoint(Vector2 mouse, Rect view)
		{
			//IL_003a: 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_0040: 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_0048: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			Rect val2 = default(Rect);
			for (int num = data.Waypoints.Count - 1; num >= 0; num--)
			{
				Waypoint waypoint = data.Waypoints[num];
				if (waypoint.LocationId != 0 || MatchesWaypointSearch(waypoint))
				{
					Vector2 val = MapToScreen(waypoint.Pixel, view);
					((Rect)(ref val2))..ctor(val.x - 17f, val.y - 44f, 33f, 44f);
					if (((Rect)(ref val2)).Contains(mouse))
					{
						return waypoint;
					}
				}
			}
			return null;
		}

		private static Waypoint NewWaypoint(Vector2 pixel, string icon, string title, int locationId)
		{
			//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)
			return new Waypoint
			{
				Id = Guid.NewGuid().ToString("N"),
				X = pixel.x,
				Y = pixel.y,
				Icon = icon,
				Title = title,
				LocationId = locationId,
				ColorIndex = Random.Range(0, WaypointColors.Length)
			};
		}

		[HideFromIl2Cpp]
		private bool MatchesSearch(MapLocation location)
		{
			if (search.Length != 0)
			{
				return location.Title.Contains(search, StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		[HideFromIl2Cpp]
		private bool MatchesWaypointSearch(Waypoint waypoint)
		{
			if (search.Length != 0 && !"waypoint".Contains(search, StringComparison.OrdinalIgnoreCase))
			{
				if (!string.IsNullOrEmpty(waypoint.Title))
				{
					return waypoint.Title.Contains(search, StringComparison.OrdinalIgnoreCase);
				}
				return false;
			}
			return true;
		}

		private bool HasSelectedLocations()
		{
			foreach (Waypoint waypoint in data.Waypoints)
			{
				if (waypoint.LocationId != 0)
				{
					return true;
				}
			}
			return false;
		}

		private static Color WaypointTint(Waypoint waypoint)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			int num = waypoint.ColorIndex.GetValueOrDefault();
			if (!waypoint.ColorIndex.HasValue && !string.IsNullOrEmpty(waypoint.Id))
			{
				string id = waypoint.Id;
				foreach (char c in id)
				{
					num += c;
				}
			}
			return WaypointColors[Math.Abs(num) % WaypointColors.Length];
		}

		private void SaveWaypoints()
		{
			miniHasFrame = false;
			try
			{
				data.SaveWaypoints();
			}
			catch (Exception ex)
			{
				status = "Waypoints could not save: " + ex.Message;
			}
		}

		private void ZoomAround(Vector2 mouse, float delta)
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0010: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			Rect view = ViewRect();
			zoomAnchorMap = ScreenToMap(mouse, view);
			zoomAnchorScreen = mouse;
			zoomTarget = Mathf.Clamp(zoomTarget + delta, 8f, 14f);
			zooming = true;
		}

		private void UpdateSmoothZoom()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			if (zooming)
			{
				float num = 1f - Mathf.Exp(-14f * Time.unscaledDeltaTime);
				zoom = Mathf.Lerp(zoom, zoomTarget, num);
				if (Mathf.Abs(zoom - zoomTarget) < 0.002f)
				{
					zoom = zoomTarget;
					zooming = false;
				}
				Rect val = ViewRect();
				center = zoomAnchorMap - (zoomAnchorScreen - ((Rect)(ref val)).center) / Scale;
			}
		}

		private void UpdateMini()
		{
			//IL_004f: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_01a1: 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)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			data.LoadPreviewTexture();
			miniRotated = Plugin.RotateMinimap.Value;
			float num = miniAngleSmooth * ((float)Math.PI / 180f);
			miniForward = (miniRotated ? new Vector2(Mathf.Sin(num), 0f - Mathf.Cos(num)) : new Vector2(0f, -1f));
			miniRight = new Vector2(0f - miniForward.y, miniForward.x);
			int value = Plugin.MiniSize.Value;
			if (value != miniTextureSize || (Object)(object)miniTexture == (Object)null)
			{
				if ((Object)(object)miniTexture != (Object)null)
				{
					miniTexture.Release();
					Object.Destroy((Object)(object)miniTexture);
				}
				miniTexture = new RenderTexture(value, value, 24, (RenderTextureFormat)0);
				((Object)miniTexture).hideFlags = (HideFlags)32;
				((Texture)miniTexture).filterMode = (FilterMode)1;
				((Texture)miniTexture).wrapMode = (TextureWrapMode)1;
				miniTexture.Create();
				miniTextureSize = value;
			}
			if ((Object)(object)miniMapMaterial == (Object)null)
			{
				Shader val = Shader.Find("UI/Default") ?? Shader.Find("Sprites/Default") ?? Shader.Find("Legacy Shaders/Transparent/Diffuse");
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("No retained textured shader available.");
				}
				miniMapMaterial = new Material(val)
				{
					hideFlags = (HideFlags)61
				};
				miniMaskMaterial = new Material(val)
				{
					hideFlags = (HideFlags)61
				};
				miniMaskMaterial.mainTexture = (Texture)(object)Texture2D.whiteTexture;
				SetStencil(miniMaskMaterial, 1, 8, 2, 0);
			}
			Vector2 center = miniCenterMap / 4f;
			float sourcePerPixel = 1f / MathF.Pow(2f, Plugin.MiniZoom.Value - 11f);
			bool num2 = Plugin.Shape.Value == MinimapShape.Circle;
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = miniTexture;
			GL.Clear(true, true, Color.clear);
			GL.PushMatrix();
			GL.LoadOrtho();
			if (num2)
			{
				miniMaskMaterial.SetPass(0);
				DrawCircleFan(textured: false, value, center, sourcePerPixel);
				SetStencil(miniMapMaterial, 1, 3, 0, 15);
			}
			else
			{
				SetStencil(miniMapMaterial, 0, 8, 0, 15);
			}
			miniMapMaterial.mainTexture = (Texture)(object)data.PreviewTexture;
			miniMapMaterial.SetPass(0);
			if (num2)
			{
				DrawCircleFan(textured: true, value, center, sourcePerPixel);
			}
			else
			{
				GL.Begin(7);
				MiniMapVertex(0f, 0f, value, center, sourcePerPixel);
				MiniMapVertex(1f, 0f, value, center, sourcePerPixel);
				MiniMapVertex(1f, 1f, value, center, sourcePerPixel);
				MiniMapVertex(0f, 1f, value, center, sourcePerPixel);
				GL.End();
			}
			if (num2 && (Plugin.ShowBlips.Value || HasSelectedLocations()))
			{
				DrawMiniLocationsGpu(value);
			}
			GL.PopMatrix();
			RenderTexture.active = active;
		}

		private static void SetStencil(Material material, int reference, int comparison, int operation, int colorMask)
		{
			if (material.HasProperty("_Stencil"))
			{
				material.SetInt("_Stencil", reference);
			}
			if (material.HasProperty("_StencilComp"))
			{
				material.SetInt("_StencilComp", comparison);
			}
			if (material.HasProperty("_StencilOp"))
			{
				material.SetInt("_StencilOp", operation);
			}
			if (material.HasProperty("_StencilReadMask"))
			{
				material.SetInt("_StencilReadMask", 255);
			}
			if (material.HasProperty("_StencilWriteMask"))
			{
				material.SetInt("_StencilWriteMask", 255);
			}
			if (material.HasProperty("_ColorMask"))
			{
				material.SetInt("_ColorMask", colorMask);
			}
		}

		private void DrawCircleFan(bool textured, int size, Vector2 center11, float sourcePerPixel)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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)
			GL.Begin(4);
			for (int i = 0; i < 96; i++)
			{
				if (textured)
				{
					MiniMapVertex(0.5f, 0.5f, size, center11, sourcePerPixel);
				}
				else
				{
					GL.Vertex3(0.5f, 0.5f, 0f);
				}
				float num = (float)i * (float)Math.PI * 2f / 96f;
				float num2 = (float)(i + 1) * (float)Math.PI * 2f / 96f;
				float num3 = 0.5f + 0.5f * Mathf.Cos(num);
				float num4 = 0.5f + 0.5f * Mathf.Sin(num);
				float num5 = 0.5f + 0.5f * Mathf.Cos(num2);
				float num6 = 0.5f + 0.5f * Mathf.Sin(num2);
				if (textured)
				{
					MiniMapVertex(num3, num4, size, center11, sourcePerPixel);
					MiniMapVertex(num5, num6, size, center11, sourcePerPixel);
				}
				else
				{
					GL.Vertex3(num3, num4, 0f);
					GL.Vertex3(num5, num6, 0f);
				}
			}
			GL.End();
		}

		private void DrawMiniLocationsGpu(int size)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.4f + 0.4f * (Plugin.MiniZoom.Value - 9f) / 5f;
			foreach (MapLocation location in data.Locations)
			{
				if (data.Waypoints.Find((Waypoint w) => w.LocationId == location.Id) != null || (Plugin.ShowBlips.Value && MatchesSearch(location)))
				{
					Vector2 val = MiniPoint(location.Pixel, size);
					Texture2D val2 = data.Icon(location.Icon);
					float num2 = (float)((Texture)val2).width * num;
					float num3 = (float)((Texture)val2).height * num;
					float num4 = (val.x - num2 * 0.5f) / (float)size;
					float num5 = (val.x + num2 * 0.5f) / (float)size;
					float num6 = 1f - (val.y - num3) / (float)size;
					float num7 = 1f - val.y / (float)size;
					if (!(num5 < 0f) && !(num4 > 1f) && !(num6 < 0f) && !(num7 > 1f))
					{
						miniMapMaterial.mainTexture = (Texture)(object)val2;
						miniMapMaterial.SetPass(0);
						GL.Color(Color.white);
						GL.Begin(7);
						GL.TexCoord2(0f, 0f);
						GL.Vertex3(num4, num7, 0f);
						GL.TexCoord2(1f, 0f);
						GL.Vertex3(num5, num7, 0f);
						GL.TexCoord2(1f, 1f);
						GL.Vertex3(num5, num6, 0f);
						GL.TexCoord2(0f, 1f);
						GL.Vertex3(num4, num6, 0f);
						GL.End();
					}
				}
			}
		}

		private void MiniMapVertex(float x, float y, int size, Vector2 center11, float sourcePerPixel)
		{
			//IL_0016: 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_0022: 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_002d: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			float num = (x - 0.5f) * (float)size;
			float num2 = (0.5f - y) * (float)size;
			Vector2 val = center11 + miniRight * (num * sourcePerPixel) - miniForward * (num2 * sourcePerPixel);
			GL.TexCoord2(val.x / 2048f, 1f - val.y / 2048f);
			GL.Vertex3(x, y, 0f);
		}

		private Rect MiniRect(int size)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Plugin.Horizontal.Value == HorizontalSide.Left) ? 16 : (Screen.width - size - 16));
			float num2 = ((Plugin.Vertical.Value == VerticalSide.Top) ? 16 : (Screen.height - size - 16));
			return new Rect(num, num2, (float)size, (float)size);
		}

		private void DrawMini(PlayerCharacter local)
		{
			//IL_001f: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0061: 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_0093: 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)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			if (miniOutsideMap || data.Outside(data.Calibration.ToMap(((Component)local).transform.position)))
			{
				return;
			}
			int value = Plugin.MiniSize.Value;
			Rect val = MiniRect(value);
			if (!data.Calibration.Ready)
			{
				GUI.Box(val, "Minimap needs calibration. Press " + ((object)Plugin.MapKey.Value/*cast due to .constrained prefix*/).ToString() + ".");
			}
			else if (!((Object)(object)miniTexture == (Object)null))
			{
				GUI.BeginGroup(val);
				GUI.DrawTexture(new Rect(0f, 0f, (float)value, (float)value), (Texture)(object)miniTexture);
				if (Plugin.Shape.Value == MinimapShape.Square && (Plugin.ShowBlips.Value || HasSelectedLocations()))
				{
					DrawMiniLocations(value);
				}
				DrawMiniWaypoints(value);
				if (Plugin.TrackPlayers.Value && !HideNSeekSuppressesPlayerBlips())
				{
					DrawOtherPlayers(new Rect(0f, 0f, (float)value, (float)value), mini: true, value);
				}
				DrawMiniBorderOverlay(value);
				DrawSelfBlip(new Vector2((float)value / 2f, (float)value / 2f), local, 24, !miniRotated);
				DrawCompass(value);
				GUI.EndGroup();
			}
		}

		private Vector2 MiniPoint(Vector2 pixel, int size)
		{
			//IL_001b: 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_0022: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0049: 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)
			float num = Mathf.Pow(2f, Plugin.MiniZoom.Value - 13f);
			Vector2 val = pixel - miniCenterMap;
			return new Vector2((float)size / 2f + Vector2.Dot(val, miniRight) * num, (float)size / 2f - Vector2.Dot(val, miniForward) * num);
		}

		private bool InMini(Vector2 point, int size, float margin)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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)
			Vector2 val = point - new Vector2((float)size / 2f, (float)size / 2f);
			if (Plugin.Shape.Value != MinimapShape.Circle)
			{
				if (Mathf.Abs(val.x) <= (float)size / 2f - margin)
				{
					return Mathf.Abs(val.y) <= (float)size / 2f - margin;
				}
				return false;
			}
			return ((Vector2)(ref val)).sqrMagnitude <= Mathf.Pow((float)size / 2f - margin, 2f);
		}

		private bool MiniRectIntersects(float left, float top, float right, float bottom, int size)
		{
			//IL_0049: 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_006b: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Shape.Value == MinimapShape.Square)
			{
				if (right >= 0f && left <= (float)size && bottom >= 0f)
				{
					return top <= (float)size;
				}
				return false;
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((float)size * 0.5f, (float)size * 0.5f);
			float num = Mathf.Clamp(val.x, left, right);
			float num2 = Mathf.Clamp(val.y, top, bottom);
			Vector2 val2 = new Vector2(num, num2) - val;
			float num3 = (float)size * 0.5f;
			return ((Vector2)(ref val2)).sqrMagnitude <= num3 * num3;
		}

		private void DrawMiniWaypoints(int size)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_00ea: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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)
			//IL_005f: 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_00c2: 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_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)
			//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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((float)size / 2f, (float)size / 2f);
			foreach (Waypoint waypoint in data.Waypoints)
			{
				if (waypoint.Hidden)
				{
					continue;
				}
				Vector2 val2 = MiniPoint(waypoint.Pixel, size);
				if (!InMini(val2, size, 15f))
				{
					Vector2 val3 = val2 - val;
					if (((Vector2)(ref val3)).sqrMagnitude < 0.01f)
					{
						continue;
					}
					float num = (float)size / 2f - 21f;
					val2 = ((Plugin.Shape.Value == MinimapShape.Circle) ? (val + ((Vector2)(ref val3)).normalized * num) : (val + val3 * (num / Mathf.Max(Mathf.Abs(val3.x), Mathf.Abs(val3.y)))));
				}
				Texture2D val4 = data.Icon("Waypoint");
				GUI.color = WaypointTint(waypoint);
				GUI.DrawTexture(new Rect(val2.x - 11f, val2.y - 14.5f, 22f, 29f), (Texture)(object)val4);
				GUI.color = Color.white;
			}
		}

		private void DrawMiniLocations(int size)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.4f + 0.4f * (Plugin.MiniZoom.Value - 9f) / 5f;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((float)size * 0.5f, (float)size * 0.5f);
			foreach (MapLocation location in data.Locations)
			{
				if (data.Waypoints.Find((Waypoint w) => w.LocationId == location.Id) == null && (!Plugin.ShowBlips.Value || !MatchesSearch(location)))
				{
					continue;
				}
				Vector2 val2 = MiniPoint(location.Pixel, size);
				Texture2D val3 = data.Icon(location.Icon);
				float num2 = (float)((Texture)val3).width * num;
				float num3 = (float)((Texture)val3).height * num;
				float num4 = val2.x - num2 * 0.5f;
				float num5 = val2.x + num2 * 0.5f;
				float num6 = val2.y - num3;
				float y = val2.y;
				if (Plugin.Shape.Value == MinimapShape.Circle)
				{
					float num7 = Mathf.Clamp(val.x, num4, num5);
					float num8 = Mathf.Clamp(val.y, num6, y);
					Vector2 val4 = new Vector2(num7, num8) - val;
					float num9 = (float)size * 0.5f;
					if (((Vector2)(ref val4)).sqrMagnitude > num9 * num9)
					{
						continue;
					}
				}
				else if (num5 < 0f || num4 > (float)size || y < 0f || num6 > (float)size)
				{
					continue;
				}
				GUI.DrawTexture(new Rect(val2.x - num2 * 0.5f, val2.y - num3, num2, num3), (Texture)(object)val3);
			}
		}

		private void DrawMiniBorderOverlay(int size)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)miniBorderOverlay == (Object)null || miniBorderSize != size || miniBorderShape != Plugin.Shape.Value || miniBorderColor != Plugin.BorderColor.Value)
			{
				if ((Object)(object)miniBorderOverlay != (Object)null)
				{
					Object.Destroy((Object)(object)miniBorderOverlay);
				}
				miniBorderOverlay = new Texture2D(size, size, (TextureFormat)4, false);
				((Object)miniBorderOverlay).hideFlags = (HideFlags)32;
				((Texture)miniBorderOverlay).filterMode = (FilterMode)0;
				Color32[] array = (Color32[])(object)new Color32[size * size];
				Color32 val = ((Plugin.BorderColor.Value == MinimapBorderColor.White) ? new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue) : new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
				bool flag = Plugin.Shape.Value == MinimapShape.Circle;
				float num = (float)(size - 1) * 0.5f;
				float num2 = (float)size * 0.5f;
				float num3 = num2 - 3f;
				float num4 = num2 * num2;
				float num5 = num3 * num3;
				for (int i = 0; i < size; i++)
				{
					for (int j = 0; j < size; j++)
					{
						bool flag2;
						if (flag)
						{
							float num6 = (float)j - num;
							float num7 = (float)i - num;
							float num8 = num6 * num6 + num7 * num7;
							flag2 = num8 <= num4 && num8 >= num5;
						}
						else
						{
							flag2 = j < 3 || i < 3 || j >= size - 3 || i >= size - 3;
						}
						if (flag2)
						{
							array[i * size + j] = val;
						}
					}
				}
				miniBorderOverlay.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
				miniBorderOverlay.Apply(false, true);
				miniBorderSize = size;
				miniBorderShape = Plugin.Shape.Value;
				miniBorderColor = Plugin.BorderColor.Value;
			}
			GUI.DrawTexture(new Rect(0f, 0f, (float)size, (float)size), (Texture)(object)miniBorderOverlay);
		}

		private void DrawCompass(int size)
		{
			//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_0038: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.ShowDirections.Value)
			{
				return;
			}
			Calibration calibration = data.Calibration;
			if (calibration.HasCompassNorth || calibration.HasCompassSouth)
			{
				Vector2 val = Vector2.zero;
				if (calibration.HasCompassNorth)
				{
					val += new Vector2(calibration.CompassNorthX, calibration.CompassNorthZ);
				}
				if (calibration.HasCompassSouth)
				{
					val -= new Vector2(calibration.CompassSouthX, calibration.CompassSouthZ);
				}
				if (!(((Vector2)(ref val)).sqrMagnitude < 0.01f))
				{
					((Vector2)(ref val)).Normalize();
					Vector2 val2 = calibration.Facing(new Vector3(val.x, 0f, val.y));
					Vector2 normalized = ((Vector2)(ref val2)).normalized;
					val2 = new Vector2(Vector2.Dot(normalized, miniRight), 0f - Vector2.Dot(normalized, miniForward));
					Vector2 normalized2 = ((Vector2)(ref val2)).normalized;
					Vector2 val3 = default(Vector2);
					((Vector2)(ref val3))..ctor(0f - normalized2.y, normalized2.x);
					DrawCompassLabel("N", normalized2, size);
					DrawCompassLabel("E", val3, size);
					DrawCompassLabel("S", -normalized2, size);
					DrawCompassLabel("W", -val3, size);
				}
			}
		}

		private void DrawCompassLabel(string label, Vector2 direction, int size)
		{
			//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)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0040: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_00ac: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_0083: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((float)size * 0.5f, (float)size * 0.5f);
			float num = (float)size * 0.5f - 14f;
			Vector2 val2 = ((Plugin.Shape.Value == MinimapShape.Circle) ? (val + direction * num) : (val + direction * (num / Mathf.Max(Mathf.Abs(direction.x), Mathf.Abs(direction.y)))));
			if (compassStyle == null)
			{
				compassStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					fontStyle = (FontStyle)1,
					fontSize = 16
				};
			}
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(val2.x - 12f, val2.y - 12f, 24f, 24f);
			Color color = GUI.color;
			GUI.color = new Color(0f, 0f, 0f, 0.95f);
			for (int i = -1; i <= 1; i++)
			{
				for (int j = -1; j <= 1; j++)
				{
					if (i != 0 || j != 0)
					{
						GUI.Label(new Rect(((Rect)(ref val3)).x + (float)i * 1.5f, ((Rect)(ref val3)).y + (float)j * 1.5f, ((Rect)(ref val3)).width, ((Rect)(ref val3)).height), label, compassStyle);
					}
				}
			}
			GUI.color = Color.white;
			GUI.Label(val3, label, compassStyle);
			GUI.color = color;
		}

		private bool HideNSeekSuppressesPlayerBlips()
		{
			if (hideNSeekSuppressBlips == null && Time.unscaledTime >= nextHideNSeekLookup)
			{
				nextHideNSeekLookup = Time.unscaledTime + 1f;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				for (int i = 0; i < assemblies.Length; i++)
				{
					PropertyInfo propertyInfo = assemblies[i].GetType("MadysHideNSeek.HideAndSeekTester", throwOnError: false)?.GetProperty("SuppressMinimapPlayerBlips", BindingFlags.Static | BindingFlags.Public);
					if (!(propertyInfo == null) && !(propertyInfo.PropertyType != typeof(bool)))
					{
						hideNSeekSuppressBlips = propertyInfo;
						break;
					}
				}
			}
			try
			{
				return hideNSeekSuppressBlips != null && (bool)hideNSeekSuppressBlips.GetValue(null);
			}
			catch
			{
				return false;
			}
		}

		private bool HideNSeekSuppressesMinimap()
		{
			if (hideNSeekSuppressMinimap == null && Time.unscaledTime >= nextHideNSeekMinimapLookup)
			{
				nextHideNSeekMinimapLookup = Time.unscaledTime + 1f;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				for (int i = 0; i < assemblies.Length; i++)
				{
					PropertyInfo propertyInfo = assemblies[i].GetType("MadysHideNSeek.HideAndSeekTester", throwOnError: false)?.GetProperty("SuppressMinimap", BindingFlags.Static | BindingFlags.Public);
					if (!(propertyInfo == null) && !(propertyInfo.PropertyType != typeof(bool)))
					{
						hideNSeekSuppressMinimap = propertyInfo;
						break;
					}
				}
			}
			try
			{
				return hideNSeekSuppressMinimap != null && (bool)hideNSeekSuppressMinimap.GetValue(null);
			}
			catch
			{
				return false;
			}
		}

		private void DrawSelfBlip(Vector2 point, PlayerCharacter player, int size, bool faceDirection = true)
		{
			//IL_00e6: 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_005f: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_002b: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0044: 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_00ac: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			if (faceDirection)
			{
				Vector3 forward = (((Object)(object)player.cameraTransform != (Object)null) ? player.cameraTransform.forward : ((Component)player).transform.forward);
				Vector2 val = data.Calibration.Facing(forward);
				num = Mathf.Atan2(val.x, 0f - val.y) * 57.29578f;
			}
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			try
			{
				GUIUtility.RotateAroundPivot(num, point);
				Texture2D val2 = data.Icon(Plugin.InverseSelfBlip.Value ? "InverseSelfBlip" : "SelfBlip");
				float num2 = (float)(size * ((Texture)val2).width) / (float)((Texture)val2).height;
				GUI.color = Color.white;
				GUI.DrawTexture(new Rect(point.x - num2 / 2f, point.y - (float)size / 2f, num2, (float)size), (Texture)(object)val2);
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
			}
		}

		private static GUIStyle CenteredStyle()
		{
			//IL_000a: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			return new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				richText = false
			};
		}
	}
	internal sealed class MapLocation
	{
		internal int Id;

		internal string Title;

		internal string Icon;

		internal Vector2 Pixel;
	}
	internal sealed class Waypoint
	{
		public string Id { get; set; }

		public int LocationId { get; set; }

		public string Title { get; set; }

		public string Icon { get; set; }

		public float X { get; set; }

		public float Y { get; set; }

		public bool Hidden { get; set; }

		public int? ColorIndex { get; set; }

		internal Vector2 Pixel => new Vector2(X, Y);
	}
	internal sealed class CalibrationAnchor
	{
		public string Name { get; set; }

		public float WorldX { get; set; }

		public float WorldZ { get; set; }

		public float PixelX { get; set; }

		public float PixelY { get; set; }

		public float FacingX { get; set; }

		public float FacingZ { get; set; }

		public float MapFacingX { get; set; }

		public float MapFacingY { get; set; }
	}
	internal sealed class Calibration
	{
		public bool Ready { get; set; }

		public float A { get; set; }

		public float B { get; set; }

		public float Cx { get; set; }

		public float Cy { get; set; }

		public float World1X { get; set; }

		public float World1Z { get; set; }

		public float Pixel1X { get; set; }

		public float Pixel1Y { get; set; }

		public float Facing1 { get; set; }

		public float DirectionX { get; set; }

		public float DirectionY { get; set; }

		public float PixelsPerMeter { get; set; }

		public float HeadingCorrection { get; set; }

		public bool FlipLeftRight { get; set; }

		public bool HasA { get; set; }

		public bool HasB { get; set; }

		public float World2X { get; set; }

		public float World2Z { get; set; }

		public float Pixel2X { get; set; }

		public float Pixel2Y { get; set; }

		public List<CalibrationAnchor> Anchors { get; set; } = new List<CalibrationAnchor>();

		public float FitErrorPixels { get; set; }

		public bool HasCompassNorth { get; set; }

		public bool HasCompassSouth { get; set; }

		public float CompassNorthX { get; set; }

		public float CompassNorthZ { get; set; }

		public float CompassSouthX { get; set; }

		public float CompassSouthZ { get; set; }

		internal Vector2 ToMap(Vector3 world)
		{
			//IL_0006: 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)
			//IL_0042: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			float num = A * world.x - B * world.z + Cx;
			return new Vector2(FlipLeftRight ? (2f * Pixel1X - num) : num, B * world.x + A * world.z + Cy);
		}

		internal Vector2 Facing(Vector3 forward)
		{
			//IL_0006: 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)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			float num = A * forward.x - B * forward.z;
			return new Vector2(FlipLeftRight ? (0f - num) : num, B * forward.x + A * forward.z);
		}

		internal bool Solve(float scale, float headingCorrection)
		{
			float num = Mathf.Sqrt(DirectionX * DirectionX + DirectionY * DirectionY);
			if (num < 0.001f || scale <= 0f)
			{
				return Ready = false;
			}
			float num2 = headingCorrection * ((float)Math.PI / 180f);
			float num3 = DirectionX / num;
			float num4 = DirectionY / num;
			float num5 = num3 * Mathf.Cos(num2) - num4 * Mathf.Sin(num2);
			float num6 = num3 * Mathf.Sin(num2) + num4 * Mathf.Cos(num2);
			if (FlipLeftRight)
			{
				num5 = 0f - num5;
			}
			float num7 = Facing1 * ((float)Math.PI / 180f);
			float num8 = Mathf.Sin(num7);
			float num9 = Mathf.Cos(num7);
			A = scale * (num5 * num8 + num6 * num9);
			B = scale * (num6 * num8 - num5 * num9);
			Cx = Pixel1X - A * World1X + B * World1Z;
			Cy = Pixel1Y - B * World1X - A * World1Z;
			PixelsPerMeter = scale;
			HeadingCorrection = headingCorrection;
			return Ready = true;
		}

		internal void Upsert(CalibrationAnchor anchor)
		{
			int num = Anchors.FindIndex((CalibrationAnchor a) => a.Name == anchor.Name);
			if (num >= 0)
			{
				Anchors[num] = anchor;
			}
			else
			{
				Anchors.Add(anchor);
			}
		}

		internal bool Fit(bool flip, float correctionDegrees, out float score)
		{
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			score = float.PositiveInfinity;
			if (Anchors == null || Anchors.Count < 2)
			{
				return false;
			}
			double num = 0.0;
			double num2 = 0.0;
			double num3 = 0.0;
			double num4 = 0.0;
			foreach (CalibrationAnchor anchor in Anchors)
			{
				num += (double)anchor.WorldX;
				num2 += (double)anchor.WorldZ;
				num3 += (flip ? (2.0 * (double)Pixel1X - (double)anchor.PixelX) : ((double)anchor.PixelX));
				num4 += (double)anchor.PixelY;
			}
			int count = Anchors.Count;
			num /= (double)count;
			num2 /= (double)count;
			num3 /= (double)count;
			num4 /= (double)count;
			double num5 = 0.0;
			double num6 = 0.0;
			double num7 = 0.0;
			foreach (CalibrationAnchor anchor2 in Anchors)
			{
				double num8 = (double)anchor2.WorldX - num;
				double num9 = (double)anchor2.WorldZ - num2;
				double num10 = (flip ? (2.0 * (double)Pixel1X - (double)anchor2.PixelX) : ((double)anchor2.PixelX)) - num3;
				double num11 = (double)anchor2.PixelY - num4;
				num5 += num8 * num8 + num9 * num9;
				num6 += num8 * num10 + num9 * num11;
				num7 += num8 * num11 - num9 * num10;
			}
			if (num5 < 100.0)
			{
				return false;
			}
			double num12 = num6 / num5;
			double num13 = num7 / num5;
			double num14 = Math.Sqrt(num12 * num12 + num13 * num13);
			if (num14 < 0.5 || num14 > 10.0)
			{
				return false;
			}
			double num15 = (double)correctionDegrees * Math.PI / 180.0;
			double num16 = num12 * Math.Cos(num15) - num13 * Math.Sin(num15);
			double num17 = num12 * Math.Sin(num15) + num13 * Math.Cos(num15);
			A = (float)num16;
			B = (float)num17;
			Cx = (float)(num3 - num16 * num + num17 * num2);
			Cy = (float)(num4 - num17 * num - num16 * num2);
			FlipLeftRight = flip;
			PixelsPerMeter = (float)num14;
			HeadingCorrection = correctionDegrees;
			double num18 = 0.0;
			double num19 = 0.0;
			foreach (CalibrationAnchor anchor3 in Anchors)
			{
				Vector2 val = ToMap(new Vector3(anchor3.WorldX, 0f, anchor3.WorldZ));
				double num20 = val.x - anchor3.PixelX;
				double num21 = val.y - anchor3.PixelY;
				num18 += num20 * num20 + num21 * num21;
				if (anchor3.MapFacingX * anchor3.MapFacingX + anchor3.MapFacingY * anchor3.MapFacingY > 0.1f)
				{
					Vector2 val2 = Facing(new Vector3(anchor3.FacingX, 0f, anchor3.FacingZ));
					Vector2 normalized = ((Vector2)(ref val2)).normalized;
					val2 = new Vector2(anchor3.MapFacingX, anchor3.MapFacingY);
					Vector2 normalized2 = ((Vector2)(ref val2)).normalized;
					num19 += 2500.0 * (1.0 - (double)Vector2.Dot(normalized, normalized2));
				}
			}
			FitErrorPixels = (float)Math.Sqrt(num18 / (double)count);
			score = (float)(num18 + num19);
			return Ready = true;
		}
	}
	internal sealed class MapData
	{
		internal readonly string Assets = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MapAssets");

		internal readonly string WaypointPath = Path.Combine(Paths.ConfigPath, "AdamMady.Minimap.waypoints.json");

		internal readonly string CalibrationPath = Path.Combine(Paths.ConfigPath, "AdamMady.Minimap.calibration.json");

		internal readonly List<MapLocation> Locations = new List<MapLocation>();

		internal readonly List<Waypoint> Waypoints = new List<Waypoint>();

		internal readonly Dictionary<int, HashSet<long>> Tiles = new Dictionary<int, HashSet<long>>();

		internal readonly Dictionary<string, Texture2D> Icons = new Dictionary<string, Texture2D>();

		internal readonly Dictionary<string, Texture2D> TileCache = new Dictionary<string, Texture2D>();

		internal Calibration Calibration = new Calibration();

		internal Texture2D PreviewTexture;

		internal byte[] WhiteMask;

		internal int MinTileX;

		internal int MinTileY;

		internal void Load()
		{
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			using (JsonDocument jsonDocument = JsonDocument.Parse(File.ReadAllText(Path.Combine(Assets, "layout.json"))))
			{
				foreach (JsonElement item in jsonDocument.RootElement.GetProperty("mosaics").EnumerateArray())
				{
					if (item.GetProperty("zoom").GetInt32() == 13)
					{
						MinTileX = item.GetProperty("min_x").GetInt32();
						MinTileY = item.GetProperty("min_y").GetInt32();
					}
				}
				foreach (JsonProperty item2 in jsonDocument.RootElement.GetProperty("tiles").EnumerateObject())
				{
					HashSet<long> hashSet = new HashSet<long>();
					foreach (JsonElement item3 in item2.Value.EnumerateArray())
					{
						int @int = item3.GetProperty("x").GetInt32();
						int int2 = item3.GetProperty("y").GetInt32();
						hashSet.Add(((long)@int << 32) | (uint)int2);
					}
					Tiles[int.Parse(item2.Name)] = hashSet;
				}
			}
			using (JsonDocument jsonDocument2 = JsonDocument.Parse(File.ReadAllText(Path.Combine(Assets, "blips", "locations.json"))))
			{
				foreach (JsonElement item4 in jsonDocument2.RootElement.GetProperty("locations").EnumerateArray())
				{
					JsonElement property = item4.GetProperty("pixels").GetProperty("13");
					Locations.Add(new MapLocation
					{
						Id = item4.GetProperty("id").GetInt32(),
						Title = item4.GetProperty("title").GetString(),
						Icon = item4.GetProperty("icon").GetString(),
						Pixel = new Vector2(property.GetProperty("x").GetSingle(), property.GetProperty("y").GetSingle())
					});
				}
			}
			if (File.Exists(WaypointPath))
			{
				Waypoints.AddRange(JsonSerializer.Deserialize<List<Waypoint>>(File.ReadAllText(WaypointPath)) ?? new List<Waypoint>());
			}
			Calibration = BuiltInCalibration();
			if (File.Exists(CalibrationPath))
			{
				Calibration calibration = JsonSerializer.Deserialize<Calibration>(File.ReadAllText(CalibrationPath));
				if (calibration != null)
				{
					Calibration.HasCompassNorth = calibration.HasCompassNorth;
					Calibration.HasCompassSouth = calibration.HasCompassSouth;
					Calibration.CompassNorthX = calibration.CompassNorthX;
					Calibration.CompassNorthZ = calibration.CompassNorthZ;
					Calibration.CompassSouthX = calibration.CompassSouthX;
					Calibration.CompassSouthZ = calibration.CompassSouthZ;
				}
			}
			WhiteMask = File.ReadAllBytes(Path.Combine(Assets, "island-z13-whitemask-z11.bin"));
			if (WhiteMask.Length != 4194304)
			{
				throw new InvalidDataException("White island mask must be 2048x2048 bytes.");
			}
		}

		private static Calibration BuiltInCalibration()
		{
			Calibration calibration = new Calibration();
			calibration.World1X = -227.33624f;
			calibration.World1Z = -525.4304f;
			calibration.Pixel1X = 3272.7007f;
			calibration.Pixel1Y = 3231.7896f;
			calibration.Facing1 = 42.939457f;
			calibration.DirectionX = 47f;
			calibration.DirectionY = 0.5f;
			calibration.HasA = true;
			calibration.HasB = true;
			calibration.World2X = -28.252905f;
			calibration.World2Z = -400.03738f;
			calibration.Pixel2X = 3887.1587f;
			calibration.Pixel2Y = 3373.5803f;
			calibration.HasCompassNorth = true;
			calibration.HasCompassSouth = true;
			calibration.CompassNorthX = -0.7108855f;
			calibration.CompassNorthZ = 0.7033077f;
			calibration.CompassSouthX = 0.71088225f;
			calibration.CompassSouthZ = -0.703311f;
			calibration.Anchors.Add(new CalibrationAnchor
			{
				Name = "A",
				WorldX = -227.33624f,
				WorldZ = -525.4304f,
				PixelX = 3272.7007f,
				PixelY = 3231.7896f,
				FacingX = 0.5614155f,
				FacingZ = 0.6033213f,
				MapFacingX = 47f,
				MapFacingY = 0.5f
			});
			calibration.Anchors.Add(new CalibrationAnchor
			{
				Name = "B",
				WorldX = -28.252905f,
				WorldZ = -400.03738f,
				PixelX = 3887.1587f,
				PixelY = 3373.5803f,
				FacingX = 0.89442974f,
				FacingZ = 0.4471234f,
				MapFacingX = 96.5f,
				MapFacingY = 31f
			});
			calibration.Anchors.Add(new CalibrationAnchor
			{
				Name = "C",
				WorldX = 61.327553f,
				WorldZ = -0.044047296f,
				PixelX = 4838.533f,
				PixelY = 2778.5105f,
				FacingX = 0.545182f,
				FacingZ = -0.8375913f,
				MapFacingX = -25f,
				MapFacingY = 110.5f
			});
			calibration.Anchors.Add(new CalibrationAnchor
			{
				Name = "D",
				WorldX = 499.41962f,
				WorldZ = -525.5809f,
				PixelX = 4665.968f,
				PixelY = 4630.4336f,
				FacingX = -0.24901801f,
				FacingZ = -0.93327546f,
				MapFacingX = -59f,
				MapFacingY = 33.5f
			});
			calibration.Fit(flip: true, 0f, out var _);
			return calibration;
		}

		internal bool Outside(Vector2 pixel)
		{
			//IL_0000: 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)
			int num = Mathf.RoundToInt(pixel.x / 4f);
			int num2 = Mathf.RoundToInt(pixel.y / 4f);
			if (num >= 0 && num < 2048 && num2 >= 0 && num2 < 2048)
			{
				return WhiteMask[num2 * 2048 + num] != 0;
			}
			return true;
		}

		internal void LoadPreviewTexture()
		{
			if (!((Object)(object)PreviewTexture != (Object)null))
			{
				PreviewTexture = ReadTexture(Path.Combine(Assets, "island-z11.png"));
				if (((Texture)PreviewTexture).width != 2048 || ((Texture)PreviewTexture).height != 2048)
				{
					Object.Destroy((Object)(object)PreviewTexture);
					PreviewTexture = null;
					throw new InvalidDataException("Island z11 image must be 2048x2048.");
				}
			}
		}

		internal static Texture2D ReadTexture(string path)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//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)
			ImageResult val;
			using (FileStream fileStream = File.OpenRead(path))
			{
				val = ImageResult.FromStream((Stream)fileStream, (ColorComponents)4);
			}
			Texture2D val2 = new Texture2D(val.Width, val.Height, (TextureFormat)4, false);
			((Object)val2).hideFlags = (HideFlags)32;
			Color32[] array = (Color32[])(object)new Color32[val.Width * val.Height];
			for (int i = 0; i < val.Height; i++)
			{
				int num = i * val.Width * 4;
				int num2 = (val.Height - 1 - i) * val.Width;
				int num3 = 0;
				while (num3 < val.Width)
				{
					array[num2 + num3] = new Color32(val.Data[num], val.Data[num + 1], val.Data[num + 2], val.Data[num + 3]);
					num3++;
					num += 4;
				}
			}
			val2.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val2.Apply(false, true);
			((Texture)val2).filterMode = (FilterMode)1;
			return val2;
		}

		internal Texture2D Icon(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				name = "point_of_interest";
			}
			if (!Icons.TryGetValue(name, out var value) || (Object)(object)value == (Object)null)
			{
				value = (Icons[name] = ReadTexture(Path.Combine(Assets, "blips", "icons", name + ".png")));
			}
			return value;
		}

		internal Texture2D Tile(int z, int x, int y)
		{
			if (!Tiles[z].Contains(((long)x << 32) | (uint)y))
			{
				return null;
			}
			string key = z + "/" + y + "/" + x;
			if (!TileCache.TryGetValue(key, out var value) || (Object)(object)value == (Object)null)
			{
				value = (TileCache[key] = ReadTexture(Path.Combine(Assets, "tiles", "z" + z, y.ToString(), x + ".jpg")));
			}
			return value;
		}

		internal void TrimTiles(HashSet<string> used)
		{
			if (TileCache.Count > 64)
			{
				string[] array = TileCache.Keys.Where((string item) => !used.Contains(item)).Take(TileCache.Count - 64).ToArray();
				foreach (string key in array)
				{
					Object.Destroy((Object)(object)TileCache[key]);
					TileCache.Remove(key);
				}
			}
		}

		internal void SaveWaypoints()
		{
			File.WriteAllText(WaypointPath, JsonSerializer.Serialize(Waypoints));
		}

		internal void SaveCalibration()
		{
			File.WriteAllText(CalibrationPath, JsonSerializer.Serialize(Calibration));
		}
	}
	public enum HorizontalSide
	{
		Left,
		Right
	}
	public enum VerticalSide
	{
		Top,
		Bottom
	}
	public enum MinimapShape
	{
		Circle,
		Square
	}
	public enum MinimapBorderColor
	{
		White,
		Black
	}
	public enum MapMouseButton
	{
		Left,
		Right,
		Middle
	}
	[BepInPlugin("AdamMady.Minimap", "Mady's MiniMap", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BasePlugin
	{
		public const string Guid = "AdamMady.Minimap";

		public const string Name = "Mady's MiniMap";

		public const string Version = "1.1.0";

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> ShowMinimap;

		internal static ConfigEntry<bool> ShowBlips;

		internal static ConfigEntry<bool> TrackPlayers;

		internal static ConfigEntry<bool> RotateMinimap;

		internal static ConfigEntry<bool> InverseSelfBlip;

		internal static ConfigEntry<bool> ShowDirections;

		internal static ConfigEntry<KeyCode> MapKey;

		internal static ConfigEntry<KeyCode> ZoomInKey;

		internal static ConfigEntry<KeyCode> ZoomOutKey;

		internal static Co