Decompiled source of ValheimTooler v1.9.2

BepInEx/plugins/ValheimTooler/SharpConfig.dll

Decompiled 6 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName = ".NET Framework 4.6.1")]
[assembly: AssemblyCompany("SharpConfig")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright 2013-2020 Cemalettin Dervis")]
[assembly: AssemblyDescription("An easy to use CFG/INI configuration library for .NET.")]
[assembly: AssemblyFileVersion("3.2.9.1")]
[assembly: AssemblyInformationalVersion("3.2.9.1")]
[assembly: AssemblyProduct("SharpConfig")]
[assembly: AssemblyTitle("SharpConfig")]
[assembly: AssemblyVersion("3.2.9.1")]
namespace SharpConfig;

public class Configuration : IEnumerable<Section>, IEnumerable
{
	private static CultureInfo mCultureInfo;

	private static char mPreferredCommentChar;

	private static char mArrayElementSeparator;

	private static Dictionary<Type, ITypeStringConverter> mTypeStringConverters;

	internal readonly List<Section> mSections;

	public string StringRepresentation
	{
		get
		{
			StringBuilder sb = new StringBuilder();
			bool isFirstSection = true;
			Section defaultSection = DefaultSection;
			if (defaultSection.SettingCount > 0)
			{
				WriteSection(DefaultSection);
			}
			foreach (Section mSection in mSections)
			{
				if (mSection != defaultSection)
				{
					WriteSection(mSection);
				}
			}
			return sb.ToString();
			void WriteSection(Section section)
			{
				if (!isFirstSection)
				{
					sb.AppendLine();
				}
				if (!isFirstSection && section.PreComment != null)
				{
					sb.AppendLine();
				}
				if (section.Name != "$SharpConfigDefaultSection")
				{
					sb.AppendLine(section.ToString());
				}
				foreach (Setting item in section)
				{
					sb.AppendLine(item.ToString());
				}
				if (section.Name != "$SharpConfigDefaultSection" || section.SettingCount > 0)
				{
					isFirstSection = false;
				}
			}
		}
	}

	internal static ITypeStringConverter FallbackConverter { get; private set; }

	public static CultureInfo CultureInfo
	{
		get
		{
			return mCultureInfo;
		}
		set
		{
			mCultureInfo = value ?? throw new ArgumentNullException("value");
		}
	}

	public static char[] ValidCommentChars { get; private set; }

	public static char PreferredCommentChar
	{
		get
		{
			return mPreferredCommentChar;
		}
		set
		{
			if (!Array.Exists(ValidCommentChars, (char c) => c == value))
			{
				throw new ArgumentException("The specified char '" + value + "' is not allowed as a comment char.");
			}
			mPreferredCommentChar = value;
		}
	}

	public static char ArrayElementSeparator
	{
		get
		{
			return mArrayElementSeparator;
		}
		set
		{
			if (value == '\0')
			{
				throw new ArgumentException("Zero-character is not allowed.");
			}
			mArrayElementSeparator = value;
		}
	}

	public static bool OutputRawStringValues { get; set; }

	public static bool IgnoreInlineComments { get; set; }

	public static bool IgnorePreComments { get; set; }

	public static bool SpaceBetweenEquals { get; set; }

	public int SectionCount => mSections.Count;

	public Section this[int index]
	{
		get
		{
			if (index < 0 || index >= mSections.Count)
			{
				throw new ArgumentOutOfRangeException("index");
			}
			return mSections[index];
		}
	}

	public Section this[string name]
	{
		get
		{
			Section section = FindSection(name);
			if (section == null)
			{
				section = new Section(name);
				Add(section);
			}
			return section;
		}
	}

	public Section DefaultSection => this["$SharpConfigDefaultSection"];

	static Configuration()
	{
		mCultureInfo = (CultureInfo)CultureInfo.InvariantCulture.Clone();
		ValidCommentChars = new char[2] { '#', ';' };
		mPreferredCommentChar = '#';
		mArrayElementSeparator = ',';
		FallbackConverter = new FallbackStringConverter();
		mTypeStringConverters = new Dictionary<Type, ITypeStringConverter>
		{
			{
				typeof(bool),
				new BoolStringConverter()
			},
			{
				typeof(byte),
				new ByteStringConverter()
			},
			{
				typeof(char),
				new CharStringConverter()
			},
			{
				typeof(DateTime),
				new DateTimeStringConverter()
			},
			{
				typeof(decimal),
				new DecimalStringConverter()
			},
			{
				typeof(double),
				new DoubleStringConverter()
			},
			{
				typeof(Enum),
				new EnumStringConverter()
			},
			{
				typeof(short),
				new Int16StringConverter()
			},
			{
				typeof(int),
				new Int32StringConverter()
			},
			{
				typeof(long),
				new Int64StringConverter()
			},
			{
				typeof(sbyte),
				new SByteStringConverter()
			},
			{
				typeof(float),
				new SingleStringConverter()
			},
			{
				typeof(string),
				new StringStringConverter()
			},
			{
				typeof(ushort),
				new UInt16StringConverter()
			},
			{
				typeof(uint),
				new UInt32StringConverter()
			},
			{
				typeof(ulong),
				new UInt64StringConverter()
			}
		};
		IgnoreInlineComments = false;
		IgnorePreComments = false;
		SpaceBetweenEquals = false;
		OutputRawStringValues = false;
	}

	public Configuration()
	{
		mSections = new List<Section>();
	}

	public IEnumerator<Section> GetEnumerator()
	{
		return mSections.GetEnumerator();
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return GetEnumerator();
	}

	public void Add(Section section)
	{
		if (section == null)
		{
			throw new ArgumentNullException("section");
		}
		if (Contains(section))
		{
			throw new ArgumentException("The specified section already exists in the configuration.");
		}
		mSections.Add(section);
	}

	public Section Add(string sectionName)
	{
		Section section = new Section(sectionName);
		Add(section);
		return section;
	}

	public bool Remove(string sectionName)
	{
		if (string.IsNullOrEmpty(sectionName))
		{
			throw new ArgumentNullException("sectionName");
		}
		return Remove(FindSection(sectionName));
	}

	public bool Remove(Section section)
	{
		return mSections.Remove(section);
	}

	public void RemoveAllNamed(string sectionName)
	{
		if (string.IsNullOrEmpty(sectionName))
		{
			throw new ArgumentNullException("sectionName");
		}
		while (Remove(sectionName))
		{
		}
	}

	public void Clear()
	{
		mSections.Clear();
	}

	public bool Contains(Section section)
	{
		return mSections.Contains(section);
	}

	public bool Contains(string sectionName)
	{
		if (string.IsNullOrEmpty(sectionName))
		{
			throw new ArgumentNullException("sectionName");
		}
		return FindSection(sectionName) != null;
	}

	public bool Contains(string sectionName, string settingName)
	{
		if (string.IsNullOrEmpty(sectionName))
		{
			throw new ArgumentNullException("sectionName");
		}
		if (string.IsNullOrEmpty(settingName))
		{
			throw new ArgumentNullException("settingName");
		}
		return FindSection(sectionName)?.Contains(settingName) ?? false;
	}

	public static void RegisterTypeStringConverter(ITypeStringConverter converter)
	{
		if (converter == null)
		{
			throw new ArgumentNullException("converter");
		}
		Type convertibleType = converter.ConvertibleType;
		if (mTypeStringConverters.ContainsKey(convertibleType))
		{
			throw new InvalidOperationException("A converter for type '" + convertibleType.FullName + "' is already registered.");
		}
		mTypeStringConverters.Add(convertibleType, converter);
	}

	public static void DeregisterTypeStringConverter(Type type)
	{
		if (type == null)
		{
			throw new ArgumentNullException("type");
		}
		if (!mTypeStringConverters.ContainsKey(type))
		{
			throw new InvalidOperationException("No converter is registered for type '" + type.FullName + "'.");
		}
		mTypeStringConverters.Remove(type);
	}

	internal static ITypeStringConverter FindTypeStringConverter(Type type)
	{
		if (type.IsEnum)
		{
			type = typeof(Enum);
		}
		if (!mTypeStringConverters.TryGetValue(type, out var value))
		{
			return FallbackConverter;
		}
		return value;
	}

	public static Configuration LoadFromFile(string filename)
	{
		return LoadFromFile(filename, null);
	}

	public static Configuration LoadFromFile(string filename, Encoding encoding)
	{
		if (string.IsNullOrEmpty(filename))
		{
			throw new ArgumentNullException("filename");
		}
		if (!File.Exists(filename))
		{
			throw new FileNotFoundException("Configuration file not found.", filename);
		}
		if (encoding != null)
		{
			return LoadFromString(File.ReadAllText(filename, encoding));
		}
		return LoadFromString(File.ReadAllText(filename));
	}

	public static Configuration LoadFromStream(Stream stream)
	{
		return LoadFromStream(stream, null);
	}

	public static Configuration LoadFromStream(Stream stream, Encoding encoding)
	{
		if (stream == null)
		{
			throw new ArgumentNullException("stream");
		}
		string source = null;
		StreamReader streamReader = ((encoding == null) ? new StreamReader(stream) : new StreamReader(stream, encoding));
		using (streamReader)
		{
			source = streamReader.ReadToEnd();
		}
		return LoadFromString(source);
	}

	public static Configuration LoadFromString(string source)
	{
		if (source == null)
		{
			throw new ArgumentNullException("source");
		}
		return ConfigurationReader.ReadFromString(source);
	}

	public static Configuration LoadFromBinaryFile(string filename)
	{
		return LoadFromBinaryFile(filename, null);
	}

	public static Configuration LoadFromBinaryFile(string filename, BinaryReader reader)
	{
		if (string.IsNullOrEmpty(filename))
		{
			throw new ArgumentNullException("filename");
		}
		using FileStream stream = File.OpenRead(filename);
		return LoadFromBinaryStream(stream, reader);
	}

	public static Configuration LoadFromBinaryStream(Stream stream)
	{
		return LoadFromBinaryStream(stream, null);
	}

	public static Configuration LoadFromBinaryStream(Stream stream, BinaryReader reader)
	{
		if (stream == null)
		{
			throw new ArgumentNullException("stream");
		}
		return ConfigurationReader.ReadFromBinaryStream(stream, reader);
	}

	public void SaveToFile(string filename)
	{
		SaveToFile(filename, null);
	}

	public void SaveToFile(string filename, Encoding encoding)
	{
		if (string.IsNullOrEmpty(filename))
		{
			throw new ArgumentNullException("filename");
		}
		using FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write);
		SaveToStream(stream, encoding);
	}

	public void SaveToStream(Stream stream)
	{
		SaveToStream(stream, null);
	}

	public void SaveToStream(Stream stream, Encoding encoding)
	{
		if (stream == null)
		{
			throw new ArgumentNullException("stream");
		}
		ConfigurationWriter.WriteToStreamTextual(this, stream, encoding);
	}

	public void SaveToBinaryFile(string filename)
	{
		SaveToBinaryFile(filename, null);
	}

	public void SaveToBinaryFile(string filename, BinaryWriter writer)
	{
		if (string.IsNullOrEmpty(filename))
		{
			throw new ArgumentNullException("filename");
		}
		using FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write);
		SaveToBinaryStream(stream, writer);
	}

	public void SaveToBinaryStream(Stream stream)
	{
		SaveToBinaryStream(stream, null);
	}

	public void SaveToBinaryStream(Stream stream, BinaryWriter writer)
	{
		if (stream == null)
		{
			throw new ArgumentNullException("stream");
		}
		ConfigurationWriter.WriteToStreamBinary(this, stream, writer);
	}

	public IEnumerable<Section> GetSectionsNamed(string name)
	{
		List<Section> list = new List<Section>();
		foreach (Section mSection in mSections)
		{
			if (string.Equals(mSection.Name, name, StringComparison.OrdinalIgnoreCase))
			{
				list.Add(mSection);
			}
		}
		return list;
	}

	private Section FindSection(string name)
	{
		foreach (Section mSection in mSections)
		{
			if (string.Equals(mSection.Name, name, StringComparison.OrdinalIgnoreCase))
			{
				return mSection;
			}
		}
		return null;
	}
}
public abstract class ConfigurationElement
{
	public string Name { get; }

	public string Comment { get; set; }

	public string PreComment { get; set; }

	internal ConfigurationElement(string name)
	{
		if (string.IsNullOrEmpty(name))
		{
			throw new ArgumentNullException("name");
		}
		Name = name;
	}

	public override string ToString()
	{
		string stringExpression = GetStringExpression();
		if (Comment != null && PreComment != null && !Configuration.IgnoreInlineComments && !Configuration.IgnorePreComments)
		{
			return GetFormattedPreComment() + Environment.NewLine + stringExpression + " " + GetFormattedComment();
		}
		if (Comment != null && !Configuration.IgnoreInlineComments)
		{
			return stringExpression + " " + GetFormattedComment();
		}
		if (PreComment != null && !Configuration.IgnorePreComments)
		{
			return GetFormattedPreComment() + Environment.NewLine + stringExpression;
		}
		return stringExpression;
	}

	private string GetFormattedComment()
	{
		string text = Comment;
		int num = Comment.IndexOfAny(Environment.NewLine.ToCharArray());
		if (num >= 0)
		{
			text = text.Substring(0, num);
		}
		return Configuration.PreferredCommentChar + " " + text;
	}

	private string GetFormattedPreComment()
	{
		string[] array = PreComment.Split(new string[2] { "\r\n", "\n" }, StringSplitOptions.None);
		return string.Join(Environment.NewLine, Array.ConvertAll(array, (string s) => Configuration.PreferredCommentChar + " " + s));
	}

	protected abstract string GetStringExpression();
}
internal static class ConfigurationReader
{
	internal static Configuration ReadFromString(string source)
	{
		Configuration configuration = new Configuration();
		using StringReader reader = new StringReader(source);
		Parse(reader, configuration);
		return configuration;
	}

	private static void Parse(StringReader reader, Configuration config)
	{
		Section section = new Section("$SharpConfigDefaultSection");
		StringBuilder stringBuilder = new StringBuilder();
		int length = Environment.NewLine.Length;
		int num = 0;
		string text;
		while ((text = reader.ReadLine()) != null)
		{
			num++;
			text = text.Trim();
			if (string.IsNullOrEmpty(text))
			{
				continue;
			}
			int commentIndex;
			string text2 = ParseComment(text, out commentIndex);
			if (commentIndex == 0)
			{
				if (!Configuration.IgnorePreComments)
				{
					stringBuilder.AppendLine(text2);
				}
				continue;
			}
			string text3 = text;
			if (commentIndex > 0)
			{
				text3 = text.Remove(commentIndex).Trim();
			}
			if (text3.StartsWith("["))
			{
				if (section != null && section.Name == "$SharpConfigDefaultSection")
				{
					config.mSections.Add(section);
				}
				section = ParseSection(text3, num);
				if (!Configuration.IgnoreInlineComments)
				{
					section.Comment = text2;
				}
				if (!Configuration.IgnorePreComments && stringBuilder.Length > 0)
				{
					stringBuilder.Remove(stringBuilder.Length - length, length);
					section.PreComment = stringBuilder.ToString();
					stringBuilder.Length = 0;
				}
				config.mSections.Add(section);
			}
			else
			{
				Setting setting = ParseSetting(Configuration.IgnoreInlineComments ? text : text3, num);
				if (!Configuration.IgnoreInlineComments)
				{
					setting.Comment = text2;
				}
				if (section == null)
				{
					throw new ParserException($"The setting '{setting.Name}' has to be in a section.", num);
				}
				if (!Configuration.IgnorePreComments && stringBuilder.Length > 0)
				{
					stringBuilder.Remove(stringBuilder.Length - length, length);
					setting.PreComment = stringBuilder.ToString();
					stringBuilder.Length = 0;
				}
				section.Add(setting);
			}
		}
	}

	private static bool IsInQuoteMarks(string line, int startIndex)
	{
		int num = startIndex;
		bool flag = false;
		while (--num >= 0)
		{
			if (line[num] == '"')
			{
				flag = true;
				break;
			}
		}
		bool flag2 = line.IndexOf('"', startIndex) > 0;
		return flag && flag2;
	}

	private static string ParseComment(string line, out int commentIndex)
	{
		string result = null;
		commentIndex = -1;
		do
		{
			commentIndex = line.IndexOfAny(Configuration.ValidCommentChars, commentIndex + 1);
			if (commentIndex < 0)
			{
				break;
			}
			if (commentIndex > 0 && line[commentIndex - 1] == '\\')
			{
				commentIndex = -1;
				return null;
			}
			if (!IsInQuoteMarks(line, commentIndex))
			{
				result = line.Substring(commentIndex + 1).Trim();
				break;
			}
		}
		while (commentIndex >= 0);
		return result;
	}

	private static Section ParseSection(string line, int lineNumber)
	{
		int num = line.LastIndexOf(']');
		if (num < 0)
		{
			throw new ParserException("closing bracket missing.", lineNumber);
		}
		if (line.Length - 1 > num && line.Substring(num + 1).Trim().IndexOfAny(Configuration.ValidCommentChars) != 0)
		{
			string arg = line.Substring(num + 1);
			throw new ParserException($"unexpected token '{arg}'", lineNumber);
		}
		return new Section(line.Substring(1, line.Length - 2).Trim());
	}

	private static Setting ParseSetting(string line, int lineNumber)
	{
		string text = null;
		bool flag = line.StartsWith("\"");
		int num2;
		if (flag)
		{
			int num = 0;
			do
			{
				num = line.IndexOf('"', num + 1);
			}
			while (num > 0 && line[num - 1] == '\\');
			if (num < 0)
			{
				throw new ParserException("closing quote mark expected.", lineNumber);
			}
			text = line.Substring(1, num - 1);
			num2 = line.IndexOf('=', num + 1);
		}
		else
		{
			num2 = line.IndexOf('=');
		}
		if (num2 < 0)
		{
			throw new ParserException("setting assignment expected.", lineNumber);
		}
		if (!flag)
		{
			text = line.Substring(0, num2).Trim();
		}
		string text2 = line.Substring(num2 + 1);
		text2 = text2.Trim();
		if (string.IsNullOrEmpty(text))
		{
			throw new ParserException("setting name expected.", lineNumber);
		}
		return new Setting(text, text2);
	}

	internal static Configuration ReadFromBinaryStream(Stream stream, BinaryReader reader)
	{
		if (stream == null)
		{
			throw new ArgumentNullException("stream");
		}
		if (reader == null)
		{
			reader = new BinaryReader(stream);
		}
		Configuration configuration = new Configuration();
		int num = reader.ReadInt32();
		for (int i = 0; i < num; i++)
		{
			string name = reader.ReadString();
			int num2 = reader.ReadInt32();
			Section section = new Section(name);
			ReadCommentsBinary(reader, section);
			for (int j = 0; j < num2; j++)
			{
				Setting setting = new Setting(reader.ReadString())
				{
					RawValue = reader.ReadString()
				};
				ReadCommentsBinary(reader, setting);
				section.Add(setting);
			}
			configuration.Add(section);
		}
		return configuration;
	}

	private static void ReadCommentsBinary(BinaryReader reader, ConfigurationElement element)
	{
		if (reader.ReadBoolean())
		{
			reader.ReadChar();
			element.Comment = reader.ReadString();
		}
		if (reader.ReadBoolean())
		{
			reader.ReadChar();
			element.PreComment = reader.ReadString();
		}
	}
}
internal static class ConfigurationWriter
{
	private class NonClosingBinaryWriter : BinaryWriter
	{
		public NonClosingBinaryWriter(Stream stream)
			: base(stream)
		{
		}

		protected override void Dispose(bool disposing)
		{
		}
	}

	internal static void WriteToStreamTextual(Configuration cfg, Stream stream, Encoding encoding)
	{
		if (stream == null)
		{
			throw new ArgumentNullException("stream");
		}
		if (encoding == null)
		{
			encoding = Encoding.UTF8;
		}
		string stringRepresentation = cfg.StringRepresentation;
		byte[] array = new byte[encoding.GetByteCount(stringRepresentation)];
		int bytes = encoding.GetBytes(stringRepresentation, 0, stringRepresentation.Length, array, 0);
		stream.Write(array, 0, bytes);
		stream.Flush();
	}

	internal static void WriteToStreamBinary(Configuration cfg, Stream stream, BinaryWriter writer)
	{
		if (stream == null)
		{
			throw new ArgumentNullException("stream");
		}
		if (writer == null)
		{
			writer = new NonClosingBinaryWriter(stream);
		}
		writer.Write(cfg.SectionCount);
		foreach (Section item in cfg)
		{
			writer.Write(item.Name);
			writer.Write(item.SettingCount);
			WriteCommentsBinary(writer, item);
			foreach (Setting item2 in item)
			{
				writer.Write(item2.Name);
				writer.Write(item2.RawValue);
				WriteCommentsBinary(writer, item2);
			}
		}
		writer.Close();
	}

	private static void WriteCommentsBinary(BinaryWriter writer, ConfigurationElement element)
	{
		writer.Write(element.Comment != null);
		if (element.Comment != null)
		{
			writer.Write(' ');
			writer.Write(element.Comment);
		}
		writer.Write(element.PreComment != null);
		if (element.PreComment != null)
		{
			writer.Write(' ');
			writer.Write(element.PreComment);
		}
	}
}
public sealed class IgnoreAttribute : Attribute
{
}
public interface ITypeStringConverter
{
	Type ConvertibleType { get; }

	string ConvertToString(object value);

	object TryConvertFromString(string value, Type hint);
}
public abstract class TypeStringConverter<T> : ITypeStringConverter
{
	public Type ConvertibleType => typeof(T);

	public abstract string ConvertToString(object value);

	public abstract object TryConvertFromString(string value, Type hint);
}
[Serializable]
public sealed class ParserException : Exception
{
	public int Line { get; private set; }

	internal ParserException(string message, int line)
		: base($"Line {line}: {message}")
	{
		Line = line;
	}
}
public sealed class Section : ConfigurationElement, IEnumerable<Setting>, IEnumerable
{
	public const string DefaultSectionName = "$SharpConfigDefaultSection";

	private readonly List<Setting> mSettings;

	public int SettingCount => mSettings.Count;

	public Setting this[int index]
	{
		get
		{
			if (index < 0 || index >= mSettings.Count)
			{
				throw new ArgumentOutOfRangeException("index");
			}
			return mSettings[index];
		}
	}

	public Setting this[string name]
	{
		get
		{
			Setting setting = FindSetting(name);
			if (setting == null)
			{
				setting = new Setting(name);
				mSettings.Add(setting);
			}
			return setting;
		}
	}

	public Section(string name)
		: base(name)
	{
		mSettings = new List<Setting>();
	}

	public static Section FromObject(string name, object obj)
	{
		if (string.IsNullOrEmpty(name))
		{
			throw new ArgumentException("The section name must not be null or empty.", "name");
		}
		if (obj == null)
		{
			throw new ArgumentNullException("obj");
		}
		Section section = new Section(name);
		Type type = obj.GetType();
		PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
		foreach (PropertyInfo propertyInfo in properties)
		{
			if (propertyInfo.CanRead && !ShouldIgnoreMappingFor(propertyInfo))
			{
				Setting item = new Setting(propertyInfo.Name, propertyInfo.GetValue(obj, null));
				section.mSettings.Add(item);
			}
		}
		FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
		foreach (FieldInfo fieldInfo in fields)
		{
			if (!ShouldIgnoreMappingFor(fieldInfo))
			{
				Setting item2 = new Setting(fieldInfo.Name, fieldInfo.GetValue(obj));
				section.mSettings.Add(item2);
			}
		}
		return section;
	}

	public T ToObject<T>() where T : new()
	{
		T val = new T();
		SetValuesTo(val);
		return val;
	}

	public object ToObject(Type type)
	{
		if (type == null)
		{
			throw new ArgumentNullException(type.Name);
		}
		object obj = Activator.CreateInstance(type);
		SetValuesTo(obj);
		return obj;
	}

	public void GetValuesFrom(object obj)
	{
		if (obj == null)
		{
			throw new ArgumentNullException("obj");
		}
		Type type = obj.GetType();
		PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
		foreach (PropertyInfo propertyInfo in properties)
		{
			if (propertyInfo.CanRead)
			{
				SetSettingValueFromMemberInfo(propertyInfo, obj);
			}
		}
		FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
		foreach (FieldInfo info in fields)
		{
			SetSettingValueFromMemberInfo(info, obj);
		}
	}

	private void SetSettingValueFromMemberInfo(MemberInfo info, object instance)
	{
		if (ShouldIgnoreMappingFor(info))
		{
			return;
		}
		Setting setting = FindSetting(info.Name);
		if (setting != null)
		{
			object value = null;
			if (info is FieldInfo)
			{
				value = ((FieldInfo)info).GetValue(instance);
			}
			else if (info is PropertyInfo)
			{
				value = ((PropertyInfo)info).GetValue(instance, null);
			}
			setting.SetValue(value);
		}
	}

	public void SetValuesTo(object obj)
	{
		if (obj == null)
		{
			throw new ArgumentNullException("obj");
		}
		Type type = obj.GetType();
		PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
		foreach (PropertyInfo propertyInfo in properties)
		{
			if (!propertyInfo.CanWrite || ShouldIgnoreMappingFor(propertyInfo))
			{
				continue;
			}
			Setting setting = FindSetting(propertyInfo.Name);
			if (setting == null)
			{
				continue;
			}
			object obj2 = (propertyInfo.PropertyType.IsArray ? setting.GetValueArray(propertyInfo.PropertyType.GetElementType()) : setting.GetValue(propertyInfo.PropertyType));
			if (propertyInfo.PropertyType.IsArray)
			{
				Array array = obj2 as Array;
				Array array2 = propertyInfo.GetValue(obj, null) as Array;
				if (array != null && (array2 == null || array2.Length != array.Length))
				{
					array2 = Array.CreateInstance(propertyInfo.PropertyType.GetElementType(), array.Length);
				}
				for (int j = 0; j < array.Length; j++)
				{
					array2?.SetValue(array.GetValue(j), j);
				}
				propertyInfo.SetValue(obj, array2, null);
			}
			else
			{
				propertyInfo.SetValue(obj, obj2, null);
			}
		}
		FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
		foreach (FieldInfo fieldInfo in fields)
		{
			if (fieldInfo.IsInitOnly || ShouldIgnoreMappingFor(fieldInfo))
			{
				continue;
			}
			Setting setting2 = FindSetting(fieldInfo.Name);
			if (setting2 == null)
			{
				continue;
			}
			object obj3 = (fieldInfo.FieldType.IsArray ? setting2.GetValueArray(fieldInfo.FieldType.GetElementType()) : setting2.GetValue(fieldInfo.FieldType));
			if (fieldInfo.FieldType.IsArray)
			{
				Array array3 = obj3 as Array;
				Array array4 = fieldInfo.GetValue(obj) as Array;
				if (array3 != null && (array4 == null || array4.Length != array3.Length))
				{
					array4 = Array.CreateInstance(fieldInfo.FieldType.GetElementType(), array3.Length);
				}
				for (int k = 0; k < array3.Length; k++)
				{
					array4.SetValue(array3.GetValue(k), k);
				}
				fieldInfo.SetValue(obj, array4);
			}
			else
			{
				fieldInfo.SetValue(obj, obj3);
			}
		}
	}

	private static bool ShouldIgnoreMappingFor(MemberInfo member)
	{
		if (member.GetCustomAttributes(typeof(IgnoreAttribute), inherit: false).Length != 0)
		{
			return true;
		}
		if (member as PropertyInfo != null)
		{
			return (member as PropertyInfo).PropertyType.GetCustomAttributes(typeof(IgnoreAttribute), inherit: false).Length != 0;
		}
		if (member as FieldInfo != null)
		{
			return (member as FieldInfo).FieldType.GetCustomAttributes(typeof(IgnoreAttribute), inherit: false).Length != 0;
		}
		return false;
	}

	public IEnumerator<Setting> GetEnumerator()
	{
		return mSettings.GetEnumerator();
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return GetEnumerator();
	}

	public void Add(Setting setting)
	{
		if (setting == null)
		{
			throw new ArgumentNullException("setting");
		}
		if (Contains(setting))
		{
			throw new ArgumentException("The specified setting already exists in the section.");
		}
		mSettings.Add(setting);
	}

	public Setting Add(string settingName)
	{
		return Add(settingName, string.Empty);
	}

	public Setting Add(string settingName, object settingValue)
	{
		Setting setting = new Setting(settingName, settingValue);
		Add(setting);
		return setting;
	}

	public bool Remove(string settingName)
	{
		if (string.IsNullOrEmpty(settingName))
		{
			throw new ArgumentNullException("settingName");
		}
		return Remove(FindSetting(settingName));
	}

	public bool Remove(Setting setting)
	{
		return mSettings.Remove(setting);
	}

	public void RemoveAllNamed(string settingName)
	{
		if (string.IsNullOrEmpty(settingName))
		{
			throw new ArgumentNullException("settingName");
		}
		while (Remove(settingName))
		{
		}
	}

	public void Clear()
	{
		mSettings.Clear();
	}

	public bool Contains(Setting setting)
	{
		return mSettings.Contains(setting);
	}

	public bool Contains(string settingName)
	{
		if (string.IsNullOrEmpty(settingName))
		{
			throw new ArgumentNullException("settingName");
		}
		return FindSetting(settingName) != null;
	}

	public IEnumerable<Setting> GetSettingsNamed(string name)
	{
		List<Setting> list = new List<Setting>();
		foreach (Setting mSetting in mSettings)
		{
			if (string.Equals(mSetting.Name, name, StringComparison.OrdinalIgnoreCase))
			{
				list.Add(mSetting);
			}
		}
		return list;
	}

	private Setting FindSetting(string name)
	{
		foreach (Setting mSetting in mSettings)
		{
			if (string.Equals(mSetting.Name, name, StringComparison.OrdinalIgnoreCase))
			{
				return mSetting;
			}
		}
		return null;
	}

	protected override string GetStringExpression()
	{
		return "[" + base.Name + "]";
	}
}
public sealed class Setting : ConfigurationElement
{
	private int mCachedArraySize;

	private bool mShouldCalculateArraySize;

	private char mCachedArrayElementSeparator;

	public bool IsEmpty => string.IsNullOrEmpty(RawValue);

	[Obsolete("Use StringValue instead")]
	public string StringValueTrimmed
	{
		get
		{
			string text = StringValue;
			if (text[0] == '"')
			{
				text = text.Trim(new char[1] { '"' });
			}
			return text;
		}
	}

	public string RawValue { get; set; } = string.Empty;


	public string StringValue
	{
		get
		{
			return GetValue<string>().Trim(new char[1] { '"' });
		}
		set
		{
			SetValue(value.Trim(new char[1] { '"' }));
		}
	}

	public string[] StringValueArray
	{
		get
		{
			return GetValueArray<string>();
		}
		set
		{
			SetValue(value);
		}
	}

	public int IntValue
	{
		get
		{
			return GetValue<int>();
		}
		set
		{
			SetValue(value);
		}
	}

	public int[] IntValueArray
	{
		get
		{
			return GetValueArray<int>();
		}
		set
		{
			SetValue(value);
		}
	}

	public float FloatValue
	{
		get
		{
			return GetValue<float>();
		}
		set
		{
			SetValue(value);
		}
	}

	public float[] FloatValueArray
	{
		get
		{
			return GetValueArray<float>();
		}
		set
		{
			SetValue(value);
		}
	}

	public double DoubleValue
	{
		get
		{
			return GetValue<double>();
		}
		set
		{
			SetValue(value);
		}
	}

	public double[] DoubleValueArray
	{
		get
		{
			return GetValueArray<double>();
		}
		set
		{
			SetValue(value);
		}
	}

	public decimal DecimalValue
	{
		get
		{
			return GetValue<decimal>();
		}
		set
		{
			SetValue(value);
		}
	}

	public decimal[] DecimalValueArray
	{
		get
		{
			return GetValueArray<decimal>();
		}
		set
		{
			SetValue(value);
		}
	}

	public bool BoolValue
	{
		get
		{
			return GetValue<bool>();
		}
		set
		{
			SetValue(value);
		}
	}

	public bool[] BoolValueArray
	{
		get
		{
			return GetValueArray<bool>();
		}
		set
		{
			SetValue(value);
		}
	}

	public DateTime DateTimeValue
	{
		get
		{
			return GetValue<DateTime>();
		}
		set
		{
			SetValue(value);
		}
	}

	public DateTime[] DateTimeValueArray
	{
		get
		{
			return GetValueArray<DateTime>();
		}
		set
		{
			SetValue(value);
		}
	}

	public byte ByteValue
	{
		get
		{
			return GetValue<byte>();
		}
		set
		{
			SetValue(value);
		}
	}

	public byte[] ByteValueArray
	{
		get
		{
			return GetValueArray<byte>();
		}
		set
		{
			SetValue(value);
		}
	}

	public sbyte SByteValue
	{
		get
		{
			return GetValue<sbyte>();
		}
		set
		{
			SetValue(value);
		}
	}

	public sbyte[] SByteValueArray
	{
		get
		{
			return GetValueArray<sbyte>();
		}
		set
		{
			SetValue(value);
		}
	}

	public char CharValue
	{
		get
		{
			return GetValue<char>();
		}
		set
		{
			SetValue(value);
		}
	}

	public char[] CharValueArray
	{
		get
		{
			if (ByteValueArray != null)
			{
				return Encoding.UTF8.GetChars(ByteValueArray);
			}
			return null;
		}
		set
		{
			if (value != null)
			{
				ByteValueArray = Encoding.UTF8.GetBytes(value);
			}
			else
			{
				SetEmptyValue();
			}
		}
	}

	public bool IsArray => ArraySize >= 0;

	public int ArraySize
	{
		get
		{
			if (mCachedArrayElementSeparator != Configuration.ArrayElementSeparator)
			{
				mCachedArrayElementSeparator = Configuration.ArrayElementSeparator;
				mShouldCalculateArraySize = true;
			}
			if (mShouldCalculateArraySize)
			{
				mCachedArraySize = CalculateArraySize();
				mShouldCalculateArraySize = false;
			}
			return mCachedArraySize;
		}
	}

	public Setting(string name)
		: this(name, string.Empty)
	{
	}

	public Setting(string name, object value)
		: base(name)
	{
		SetValue(value);
		mCachedArrayElementSeparator = Configuration.ArrayElementSeparator;
	}

	private int CalculateArraySize()
	{
		int num = 0;
		SettingArrayEnumerator settingArrayEnumerator = new SettingArrayEnumerator(RawValue, shouldCalcElemString: false);
		while (settingArrayEnumerator.Next())
		{
			num++;
		}
		if (!settingArrayEnumerator.IsValid)
		{
			return -1;
		}
		return num;
	}

	public object GetValue(Type type)
	{
		if (type == null)
		{
			throw new ArgumentNullException("type");
		}
		if (type.IsArray)
		{
			throw new InvalidOperationException("To obtain an array value, use GetValueArray() instead of GetValue().");
		}
		if (IsArray)
		{
			throw new InvalidOperationException("The setting represents an array. Use GetValueArray() to obtain its value.");
		}
		return CreateObjectFromString(RawValue, type);
	}

	public object[] GetValueArray(Type elementType)
	{
		if (elementType.IsArray)
		{
			throw CreateJaggedArraysNotSupportedEx(elementType);
		}
		int arraySize = ArraySize;
		if (ArraySize < 0)
		{
			return null;
		}
		object[] array = new object[arraySize];
		if (arraySize > 0)
		{
			SettingArrayEnumerator settingArrayEnumerator = new SettingArrayEnumerator(RawValue, shouldCalcElemString: true);
			int num = 0;
			while (settingArrayEnumerator.Next())
			{
				array[num] = CreateObjectFromString(settingArrayEnumerator.Current, elementType);
				num++;
			}
		}
		return array;
	}

	public T GetValue<T>()
	{
		Type typeFromHandle = typeof(T);
		if (typeFromHandle.IsArray)
		{
			throw new InvalidOperationException("To obtain an array value, use GetValueArray() instead of GetValue().");
		}
		if (IsArray)
		{
			throw new InvalidOperationException("The setting represents an array. Use GetValueArray() to obtain its value.");
		}
		return (T)CreateObjectFromString(RawValue, typeFromHandle);
	}

	public T[] GetValueArray<T>()
	{
		Type typeFromHandle = typeof(T);
		if (typeFromHandle.IsArray)
		{
			throw CreateJaggedArraysNotSupportedEx(typeFromHandle);
		}
		int arraySize = ArraySize;
		if (arraySize < 0)
		{
			return null;
		}
		T[] array = new T[arraySize];
		if (arraySize > 0)
		{
			SettingArrayEnumerator settingArrayEnumerator = new SettingArrayEnumerator(RawValue, shouldCalcElemString: true);
			int num = 0;
			while (settingArrayEnumerator.Next())
			{
				array[num] = (T)CreateObjectFromString(settingArrayEnumerator.Current, typeFromHandle);
				num++;
			}
		}
		return array;
	}

	public T GetValueOrDefault<T>(T defaultValue, bool setDefault = false)
	{
		Type typeFromHandle = typeof(T);
		if (typeFromHandle.IsArray)
		{
			throw new InvalidOperationException("GetValueOrDefault<T> cannot be used with arrays.");
		}
		if (IsArray)
		{
			throw new InvalidOperationException("The setting represents an array. Use GetValueArray() to obtain its value.");
		}
		object obj = CreateObjectFromString(RawValue, typeFromHandle, tryConvert: true);
		if (obj != null)
		{
			return (T)obj;
		}
		if (setDefault)
		{
			SetValue(defaultValue);
		}
		return defaultValue;
	}

	private static object CreateObjectFromString(string value, Type dstType, bool tryConvert = false)
	{
		Type underlyingType = Nullable.GetUnderlyingType(dstType);
		if (underlyingType != null)
		{
			if (string.IsNullOrEmpty(value))
			{
				return null;
			}
			dstType = underlyingType;
		}
		object obj = Configuration.FindTypeStringConverter(dstType).TryConvertFromString(value, dstType);
		if (obj == null && !tryConvert)
		{
			throw SettingValueCastException.Create(value, dstType, null);
		}
		return obj;
	}

	public void SetValue(object value)
	{
		if (value == null)
		{
			SetEmptyValue();
			return;
		}
		Type type = value.GetType();
		if (type.IsArray)
		{
			Type elementType = type.GetElementType();
			if (elementType != null && elementType.IsArray)
			{
				throw CreateJaggedArraysNotSupportedEx(type.GetElementType());
			}
			Array array = value as Array;
			if (array != null)
			{
				string[] array2 = new string[array.Length];
				for (int i = 0; i < array.Length; i++)
				{
					object value2 = array.GetValue(i);
					ITypeStringConverter typeStringConverter = Configuration.FindTypeStringConverter(value2.GetType());
					array2[i] = GetValueForOutput(typeStringConverter.ConvertToString(value2));
				}
				RawValue = "{" + string.Join(Configuration.ArrayElementSeparator.ToString(), array2) + "}";
			}
			if (array != null)
			{
				mCachedArraySize = array.Length;
			}
			mShouldCalculateArraySize = false;
		}
		else
		{
			ITypeStringConverter typeStringConverter2 = Configuration.FindTypeStringConverter(type);
			RawValue = typeStringConverter2.ConvertToString(value);
			mShouldCalculateArraySize = true;
		}
	}

	private void SetEmptyValue()
	{
		RawValue = string.Empty;
		mCachedArraySize = -1;
		mShouldCalculateArraySize = false;
	}

	private static string GetValueForOutput(string rawValue)
	{
		if (Configuration.OutputRawStringValues)
		{
			return rawValue;
		}
		if (rawValue.StartsWith("{") && rawValue.EndsWith("}"))
		{
			return rawValue;
		}
		if (rawValue.StartsWith("\"") && rawValue.EndsWith("\""))
		{
			return rawValue;
		}
		if (rawValue.IndexOf(" ", StringComparison.Ordinal) >= 0 || (rawValue.IndexOfAny(Configuration.ValidCommentChars) >= 0 && !Configuration.IgnoreInlineComments))
		{
			rawValue = "\"" + rawValue + "\"";
		}
		return rawValue;
	}

	protected override string GetStringExpression()
	{
		if (Configuration.SpaceBetweenEquals)
		{
			return base.Name + " = " + GetValueForOutput(RawValue);
		}
		return base.Name + "=" + GetValueForOutput(RawValue);
	}

	private static ArgumentException CreateJaggedArraysNotSupportedEx(Type type)
	{
		Type elementType = type.GetElementType();
		while (elementType != null && elementType.IsArray)
		{
			elementType = elementType.GetElementType();
		}
		throw new ArgumentException("Jagged arrays are not supported. The type you have specified is '" + type.Name + "', but '" + elementType?.Name + "' was expected.");
	}
}
internal sealed class SettingArrayEnumerator
{
	private readonly string mStringValue;

	private readonly bool mShouldCalcElemString;

	private int mIdxInString;

	private readonly int mLastRBraceIdx;

	private int mPrevElemIdxInString;

	private int mBraceBalance;

	private bool mIsInQuotes;

	private bool mIsDone;

	public string Current { get; private set; }

	public bool IsValid { get; private set; }

	public SettingArrayEnumerator(string value, bool shouldCalcElemString)
	{
		mStringValue = value;
		mIdxInString = -1;
		mLastRBraceIdx = -1;
		mShouldCalcElemString = shouldCalcElemString;
		IsValid = true;
		mIsDone = false;
		for (int i = 0; i < value.Length; i++)
		{
			char c = value[i];
			if (c != ' ' && c != '{')
			{
				break;
			}
			if (c == '{')
			{
				mIdxInString = i + 1;
				mBraceBalance = 1;
				mPrevElemIdxInString = i + 1;
				break;
			}
		}
		if (mIdxInString < 0)
		{
			IsValid = false;
			mIsDone = true;
			return;
		}
		for (int num = value.Length - 1; num >= 0; num--)
		{
			char c2 = value[num];
			if (c2 != ' ' && c2 != '}')
			{
				break;
			}
			if (c2 == '}')
			{
				mLastRBraceIdx = num;
				break;
			}
		}
		if (mLastRBraceIdx < 0)
		{
			IsValid = false;
			mIsDone = true;
		}
		else if (mIdxInString == mLastRBraceIdx || !IsNonEmptyValue(mStringValue, mIdxInString, mLastRBraceIdx))
		{
			IsValid = true;
			mIsDone = true;
		}
	}

	private void UpdateElementString(int idx)
	{
		Current = mStringValue.Substring(mPrevElemIdxInString, idx - mPrevElemIdxInString);
		Current = Current.Trim(new char[1] { ' ' });
		if (Current[Current.Length - 1] == '"')
		{
			Current = Current.Remove(Current.Length - 1, 1);
		}
		if (Current[0] == '"')
		{
			Current = Current.Remove(0, 1);
		}
	}

	public bool Next()
	{
		if (mIsDone)
		{
			return false;
		}
		int i;
		for (i = mIdxInString; i <= mLastRBraceIdx; i++)
		{
			char c = mStringValue[i];
			if (c == '{' && !mIsInQuotes)
			{
				mBraceBalance++;
			}
			else if (c == '}' && !mIsInQuotes)
			{
				mBraceBalance--;
				if (i == mLastRBraceIdx)
				{
					if (!IsNonEmptyValue(mStringValue, mPrevElemIdxInString, i))
					{
						IsValid = false;
					}
					else if (mShouldCalcElemString)
					{
						UpdateElementString(i);
					}
					mIsDone = true;
					break;
				}
			}
			else if (c == '"')
			{
				int num = mStringValue.IndexOf('"', i + 1);
				if (num > 0 && mStringValue[num - 1] != '\\')
				{
					i = num;
					mIsInQuotes = false;
				}
				else
				{
					mIsInQuotes = true;
				}
			}
			else if (c == Configuration.ArrayElementSeparator && mBraceBalance == 1 && !mIsInQuotes)
			{
				if (!IsNonEmptyValue(mStringValue, mPrevElemIdxInString, i))
				{
					IsValid = false;
				}
				else if (mShouldCalcElemString)
				{
					UpdateElementString(i);
				}
				mPrevElemIdxInString = i + 1;
				i++;
				break;
			}
		}
		mIdxInString = i;
		if (mIsInQuotes)
		{
			IsValid = false;
		}
		return IsValid;
	}

	private static bool IsNonEmptyValue(string s, int begin, int end)
	{
		while (begin < end)
		{
			if (s[begin] != ' ')
			{
				return true;
			}
			begin++;
		}
		return false;
	}
}
[Serializable]
public sealed class SettingValueCastException : Exception
{
	private SettingValueCastException(string message, Exception innerException)
		: base(message, innerException)
	{
	}

	internal static SettingValueCastException Create(string stringValue, Type dstType, Exception innerException)
	{
		return new SettingValueCastException("Failed to convert value '" + stringValue + "' to type " + dstType.FullName + ".", innerException);
	}
}
internal sealed class FallbackStringConverter : ITypeStringConverter
{
	public Type ConvertibleType => null;

	public string ConvertToString(object value)
	{
		try
		{
			return TypeDescriptor.GetConverter(value).ConvertToString(null, Configuration.CultureInfo, value);
		}
		catch (Exception innerException)
		{
			throw SettingValueCastException.Create(value.ToString(), value.GetType(), innerException);
		}
	}

	public object ConvertFromString(string value, Type hint)
	{
		try
		{
			return TypeDescriptor.GetConverter(hint).ConvertFrom(null, Configuration.CultureInfo, value);
		}
		catch (Exception innerException)
		{
			throw SettingValueCastException.Create(value, hint, innerException);
		}
	}

	public object TryConvertFromString(string value, Type hint)
	{
		return ConvertFromString(value, hint);
	}
}
internal sealed class BoolStringConverter : TypeStringConverter<bool>
{
	public override string ConvertToString(object value)
	{
		return value.ToString();
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		switch (value.ToLowerInvariant())
		{
		case "":
		case "false":
		case "off":
		case "no":
		case "n":
		case "0":
			return false;
		case "true":
		case "on":
		case "yes":
		case "y":
		case "1":
			return true;
		default:
			return null;
		}
	}
}
internal sealed class ByteStringConverter : TypeStringConverter<byte>
{
	public override string ConvertToString(object value)
	{
		return value.ToString();
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return (byte)0;
		}
		if (!byte.TryParse(value, NumberStyles.Integer, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class CharStringConverter : TypeStringConverter<char>
{
	public override string ConvertToString(object value)
	{
		return value.ToString();
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return '\0';
		}
		if (!char.TryParse(value, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class DateTimeStringConverter : TypeStringConverter<DateTime>
{
	public override string ConvertToString(object value)
	{
		return ((DateTime)value).ToString(Configuration.CultureInfo.DateTimeFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return default(DateTime);
		}
		if (!DateTime.TryParse(value, Configuration.CultureInfo.DateTimeFormat, DateTimeStyles.None, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class DecimalStringConverter : TypeStringConverter<decimal>
{
	public override string ConvertToString(object value)
	{
		return ((decimal)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return 0m;
		}
		if (!decimal.TryParse(value, NumberStyles.Number, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class DoubleStringConverter : TypeStringConverter<double>
{
	public override string ConvertToString(object value)
	{
		return ((double)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return 0.0;
		}
		if (!double.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class EnumStringConverter : TypeStringConverter<Enum>
{
	public override string ConvertToString(object value)
	{
		return value.ToString();
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return 0.0;
		}
		value = RemoveTypeNames(value);
		if (!Enum.IsDefined(hint, value))
		{
			return null;
		}
		return Enum.Parse(hint, value);
	}

	private static string RemoveTypeNames(string value)
	{
		int num = value.LastIndexOf('.');
		if (num >= 0)
		{
			value = value.Substring(num + 1, value.Length - num - 1).Trim();
		}
		return value;
	}
}
internal sealed class Int16StringConverter : TypeStringConverter<short>
{
	public override string ConvertToString(object value)
	{
		return ((short)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return (short)0;
		}
		if (!short.TryParse(value, NumberStyles.Integer, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class Int32StringConverter : TypeStringConverter<int>
{
	public override string ConvertToString(object value)
	{
		return ((int)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return 0;
		}
		if (!int.TryParse(value, NumberStyles.Integer, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class Int64StringConverter : TypeStringConverter<long>
{
	public override string ConvertToString(object value)
	{
		return ((long)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return 0L;
		}
		if (!long.TryParse(value, NumberStyles.Integer, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class SByteStringConverter : TypeStringConverter<sbyte>
{
	public override string ConvertToString(object value)
	{
		return ((sbyte)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return (sbyte)0;
		}
		if (!sbyte.TryParse(value, NumberStyles.Integer, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class SingleStringConverter : TypeStringConverter<float>
{
	public override string ConvertToString(object value)
	{
		return ((float)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return 0f;
		}
		if (!float.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class StringStringConverter : TypeStringConverter<string>
{
	public override string ConvertToString(object value)
	{
		return value.ToString().Trim(new char[1] { '"' });
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		return value.Trim(new char[1] { '"' });
	}
}
internal sealed class UInt16StringConverter : TypeStringConverter<ushort>
{
	public override string ConvertToString(object value)
	{
		return ((ushort)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return (ushort)0;
		}
		if (!ushort.TryParse(value, NumberStyles.Integer, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class UInt32StringConverter : TypeStringConverter<uint>
{
	public override string ConvertToString(object value)
	{
		return ((uint)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return 0u;
		}
		if (!uint.TryParse(value, NumberStyles.Integer, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}
internal sealed class UInt64StringConverter : TypeStringConverter<ulong>
{
	public override string ConvertToString(object value)
	{
		return ((ulong)value).ToString(Configuration.CultureInfo.NumberFormat);
	}

	public override object TryConvertFromString(string value, Type hint)
	{
		if (value == string.Empty)
		{
			return 0uL;
		}
		if (!ulong.TryParse(value, NumberStyles.Integer, Configuration.CultureInfo.NumberFormat, out var result))
		{
			return null;
		}
		return result;
	}
}

BepInEx/plugins/ValheimTooler/ValheimTooler.dll

Decompiled 6 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using HarmonyLib;
using RapidGUI;
using SharpConfig;
using UnityEngine;
using ValheimTooler.Configuration;
using ValheimTooler.Core;
using ValheimTooler.Core.Extensions;
using ValheimTooler.Models;
using ValheimTooler.Models.Mono;
using ValheimTooler.UI;
using ValheimTooler.Utils;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ValheimTooler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Astropilot")]
[assembly: AssemblyProduct("ValheimTooler")]
[assembly: AssemblyCopyright("Copyright © Astropilot 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("66a8de82-ae2d-4a68-bc1b-84452afe01bd")]
[assembly: AssemblyFileVersion("1.9.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.9.2.0")]
namespace RapidGUI
{
	public interface IDoGUI
	{
		void DoGUI();
	}
	public interface IDoGUIWindow
	{
		void DoGUIWindow();

		void CloseWindow();
	}
	public class RapidGUIBehaviour : MonoBehaviour
	{
		private static RapidGUIBehaviour s_instance;

		public KeyCode closeFocusedWindowKey = (KeyCode)113;

		public int prefixLabelSlideButton = 1;

		public Action onGUI;

		public static RapidGUIBehaviour Instance
		{
			get
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)s_instance == (Object)null)
				{
					s_instance = Object.FindObjectOfType<RapidGUIBehaviour>();
					if ((Object)(object)s_instance == (Object)null)
					{
						s_instance = new GameObject("RapidGUI").AddComponent<RapidGUIBehaviour>();
					}
					if (Application.isPlaying)
					{
						Object.DontDestroyOnLoad((Object)(object)s_instance);
					}
				}
				return s_instance;
			}
		}

		public void OnGUI()
		{
			onGUI?.Invoke();
		}
	}
	public static class RGUIUtility
	{
		private static readonly GUIContent s_tempContent = new GUIContent();

		public static GUIContent TempContent(string text)
		{
			s_tempContent.text = text;
			s_tempContent.tooltip = null;
			s_tempContent.image = null;
			return s_tempContent;
		}

		public static Vector2 GetMouseScreenPos(Vector2? screenInsideOffset = null)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0035: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0049: 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)
			Vector3 mousePosition = Input.mousePosition;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(mousePosition.x, (float)Screen.height - mousePosition.y);
			if (screenInsideOffset.HasValue)
			{
				Vector2 val2 = new Vector2((float)Screen.width, (float)Screen.height) - screenInsideOffset.Value;
				val = Vector2.Min(val, val2);
				return val;
			}
			return val;
		}
	}
	public static class WindowInvoker
	{
		private static readonly HashSet<IDoGUIWindow> s_windows;

		private static IDoGUIWindow s_focusedWindow;

		static WindowInvoker()
		{
			s_windows = new HashSet<IDoGUIWindow>();
			RapidGUIBehaviour instance = RapidGUIBehaviour.Instance;
			instance.onGUI = (Action)Delegate.Combine(instance.onGUI, new Action(DoGUI));
		}

		public static void Add(IDoGUIWindow window)
		{
			s_windows.Add(window);
		}

		public static void Remove(IDoGUIWindow window)
		{
			s_windows.Remove(window);
		}

		public static void SetFocusedWindow(IDoGUIWindow window)
		{
			s_focusedWindow = window;
		}

		private static void DoGUI()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Invalid comparison between Unknown and I4
			//IL_0048: 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)
			foreach (IDoGUIWindow s_window in s_windows)
			{
				s_window?.DoGUIWindow();
			}
			Event current = Event.current;
			if ((int)current.type == 5 && current.keyCode == RapidGUIBehaviour.Instance.closeFocusedWindowKey && GUIUtility.keyboardControl == 0 && s_windows.Contains(s_focusedWindow))
			{
				s_focusedWindow.CloseWindow();
				s_focusedWindow = null;
			}
			if ((int)Event.current.type == 7)
			{
				s_windows.Clear();
			}
		}
	}
	public static class RGUI
	{
		private class PopupWindow : IDoGUIWindow
		{
			public string label;

			public Vector2 pos;

			public Vector2 size;

			public int? result;

			public string[] displayOptions;

			public Vector2 scrollPosition;

			protected static readonly int s_popupWindowId = "Popup".GetHashCode();

			public Rect GetWindowRect()
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				return new Rect(pos, size);
			}

			public virtual void DoGUIWindow()
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Expected O, but got Unknown
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				GUI.skin = InterfaceMaker.CustomSkin;
				GUI.ModalWindow(s_popupWindowId, GetWindowRect(), (WindowFunction)delegate
				{
					//IL_0001: 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_0011: Expected O, but got Unknown
					//IL_0013: 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_006d: 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_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_0084: Unknown result type (might be due to invalid IL or missing references)
					//IL_0088: Unknown result type (might be due to invalid IL or missing references)
					ScrollViewScope val = new ScrollViewScope(scrollPosition, Array.Empty<GUILayoutOption>());
					try
					{
						scrollPosition = val.scrollPosition;
						for (int i = 0; i < displayOptions.Length; i++)
						{
							if (GUILayout.Button(displayOptions[i], InterfaceMaker.CustomSkin.button, Array.Empty<GUILayoutOption>()))
							{
								result = i;
							}
						}
					}
					finally
					{
						((IDisposable)val)?.Dispose();
					}
					Event current = Event.current;
					if ((int)current.rawType == 0)
					{
						Rect val2 = new Rect(Vector2.zero, size);
						if (!((Rect)(ref val2)).Contains(current.mousePosition))
						{
							result = -1;
						}
					}
				}, label, InterfaceMaker.CustomSkin.GetStyle("popup"));
			}

			public void CloseWindow()
			{
				result = -1;
			}
		}

		private class SearchablePopupWindow : PopupWindow
		{
			public string _searchTerms;

			public string[] _displayOptionsCopy;

			public void SetSearchTerms(string searchTerms)
			{
				_searchTerms = searchTerms;
			}

			public override void DoGUIWindow()
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Invalid comparison between Unknown and I4
				//IL_0033: 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_005e: Expected O, but got Unknown
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				GUI.skin = InterfaceMaker.CustomSkin;
				if ((int)Event.current.type == 8)
				{
					_displayOptionsCopy = (string[])displayOptions.Clone();
				}
				GUI.ModalWindow(PopupWindow.s_popupWindowId, GetWindowRect(), (WindowFunction)delegate
				{
					//IL_0040: 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_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_00aa: Unknown result type (might be due to invalid IL or missing references)
					//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_00b8: Unknown result type (might be due to invalid IL or missing references)
					_searchTerms = GUILayout.TextField(_searchTerms, Array.Empty<GUILayoutOption>());
					if (_displayOptionsCopy.Length == 0)
					{
						GUILayout.Label("No results has been found!", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) });
					}
					else
					{
						scrollPosition = GUILayout.BeginScrollView(scrollPosition, Array.Empty<GUILayoutOption>());
						for (int i = 0; i < _displayOptionsCopy.Length; i++)
						{
							if (GUILayout.Button(_displayOptionsCopy[i], InterfaceMaker.CustomSkin.button, Array.Empty<GUILayoutOption>()))
							{
								result = i;
							}
						}
						GUILayout.EndScrollView();
					}
					Event current = Event.current;
					if ((int)current.rawType == 0)
					{
						Rect val = new Rect(Vector2.zero, size);
						if (!((Rect)(ref val)).Contains(current.mousePosition))
						{
							result = -1;
						}
					}
				}, label, InterfaceMaker.CustomSkin.GetStyle("popup"));
			}
		}

		private static int s_popupControlId;

		private static readonly PopupWindow s_popupWindow = new PopupWindow();

		private static readonly SearchablePopupWindow s_searchablePopupWindow = new SearchablePopupWindow();

		public static string SelectionPopup(string current, string[] displayOptions)
		{
			int num = Array.IndexOf(displayOptions, current);
			GUILayout.Box(current, InterfaceMaker.CustomSkin.textField, Array.Empty<GUILayoutOption>());
			int num2 = PopupOnLastRect(num, displayOptions);
			if (num2 != num)
			{
				current = displayOptions[num2];
			}
			return current;
		}

		public static int SelectionPopup(int selectionIndex, string[] displayOptions)
		{
			GUILayout.Box((selectionIndex < 0 || displayOptions.Length <= selectionIndex) ? "" : displayOptions[selectionIndex], InterfaceMaker.CustomSkin.textField, Array.Empty<GUILayoutOption>());
			return PopupOnLastRect(selectionIndex, displayOptions);
		}

		public static string SearchableSelectionPopup(string current, string[] displayOptions, ref string searchTerms)
		{
			int num = Array.IndexOf(displayOptions, current);
			GUILayout.Box(current, InterfaceMaker.CustomSkin.textField, Array.Empty<GUILayoutOption>());
			int num2 = SearchablePopupOnLastRect(num, displayOptions, ref searchTerms);
			if (num2 != num)
			{
				current = displayOptions[num2];
			}
			return current;
		}

		public static int SearchableSelectionPopup(int selectionIndex, string[] displayOptions, ref string searchTerms)
		{
			GUILayout.Box((selectionIndex < 0 || displayOptions.Length <= selectionIndex) ? "" : displayOptions[selectionIndex], InterfaceMaker.CustomSkin.textField, Array.Empty<GUILayoutOption>());
			return SearchablePopupOnLastRect(selectionIndex, displayOptions, ref searchTerms);
		}

		public static int PopupOnLastRect(string[] displayOptions, string label = "")
		{
			return PopupOnLastRect(-1, displayOptions, -1, label);
		}

		public static int PopupOnLastRect(string[] displayOptions, int button, string label = "")
		{
			return PopupOnLastRect(-1, displayOptions, button, label);
		}

		public static int PopupOnLastRect(int selectionIndex, string[] displayOptions, int mouseButton = -1, string label = "")
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return Popup(GUILayoutUtility.GetLastRect(), mouseButton, selectionIndex, displayOptions, label);
		}

		public static int SearchablePopupOnLastRect(string[] displayOptions, ref string searchTerms, string label = "")
		{
			return SearchablePopupOnLastRect(-1, displayOptions, ref searchTerms, -1, label);
		}

		public static int SearchablePopupOnLastRect(string[] displayOptions, int button, ref string searchTerms, string label = "")
		{
			return SearchablePopupOnLastRect(-1, displayOptions, ref searchTerms, button, label);
		}

		public static int SearchablePopupOnLastRect(int selectionIndex, string[] displayOptions, ref string searchTerms, int mouseButton = -1, string label = "")
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return SearchablePopup(GUILayoutUtility.GetLastRect(), mouseButton, selectionIndex, displayOptions, ref searchTerms, label);
		}

		public static int Popup(Rect launchRect, int mouseButton, int selectionIndex, string[] displayOptions, string label = "")
		{
			//IL_008d: 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_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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Invalid comparison between Unknown and I4
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_010a: Expected O, but got Unknown
			//IL_010a: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Invalid comparison between Unknown and I4
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: 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_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: 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_025b: 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_0063: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			int result = selectionIndex;
			int controlID = GUIUtility.GetControlID((FocusType)2);
			if (s_popupControlId != controlID)
			{
				Event current = Event.current;
				Vector2 mousePosition = current.mousePosition;
				if ((int)current.type == 1 && (mouseButton < 0 || current.button == mouseButton) && ((Rect)(ref launchRect)).Contains(mousePosition) && displayOptions != null && displayOptions.Length != 0)
				{
					s_popupWindow.pos = RGUIUtility.GetMouseScreenPos(Vector2.one * 150f);
					s_popupControlId = controlID;
					current.Use();
				}
			}
			else
			{
				EventType type = Event.current.type;
				int? result2 = s_popupWindow.result;
				if (result2.HasValue && (int)type == 8)
				{
					if (result2.Value >= 0)
					{
						result = result2.Value;
					}
					s_popupWindow.result = null;
					s_popupControlId = 0;
				}
				else
				{
					if ((int)type == 8 || (int)type == 7)
					{
						GUIStyle val = new GUIStyle(InterfaceMaker.CustomSkin.button)
						{
							padding = new RectOffset(24, 48, 2, 2)
						};
						Vector2 zero = Vector2.zero;
						for (int i = 0; i < displayOptions.Length; i++)
						{
							Vector2 val2 = val.CalcSize(RGUIUtility.TempContent(displayOptions[i]));
							zero.x = Mathf.Max(zero.x, val2.x);
							zero.y += val2.y;
						}
						RectOffset margin = val.margin;
						zero.y += Mathf.Max(0, displayOptions.Length - 1) * Mathf.Max(margin.top, margin.bottom);
						GUIStyle verticalScrollbar = InterfaceMaker.OldSkin.verticalScrollbar;
						Vector2 val3 = verticalScrollbar.CalcScreenSize(Vector2.zero);
						RectOffset margin2 = verticalScrollbar.margin;
						GUIStyle horizontalScrollbar = InterfaceMaker.OldSkin.horizontalScrollbar;
						Vector2 val4 = horizontalScrollbar.CalcScreenSize(Vector2.zero);
						RectOffset margin3 = horizontalScrollbar.margin;
						zero += new Vector2(val3.x + (float)margin2.horizontal, val4.y + (float)margin3.vertical) + Vector2.one * 5f;
						Vector2 val5 = InterfaceMaker.CustomSkin.GetStyle("popup").CalcScreenSize(zero);
						Vector2 val6 = new Vector2((float)Screen.width, (float)Screen.height) - s_popupWindow.pos;
						s_popupWindow.size = Vector2.Min(val5, val6);
					}
					s_popupWindow.label = label;
					s_popupWindow.displayOptions = displayOptions;
					WindowInvoker.Add(s_popupWindow);
				}
			}
			return result;
		}

		public static int SearchablePopup(Rect launchRect, int mouseButton, int selectionIndex, string[] displayOptions, ref string searchTerms, string label = "")
		{
			//IL_008d: 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_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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Invalid comparison between Unknown and I4
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Invalid comparison between Unknown and I4
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_0137: Expected O, but got Unknown
			//IL_0139: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_0112: Invalid comparison between Unknown and I4
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_0186: 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_0063: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: 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_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: 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_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			int result = selectionIndex;
			int controlID = GUIUtility.GetControlID((FocusType)2);
			if (s_popupControlId != controlID)
			{
				Event current = Event.current;
				Vector2 mousePosition = current.mousePosition;
				if ((int)current.type == 1 && (mouseButton < 0 || current.button == mouseButton) && ((Rect)(ref launchRect)).Contains(mousePosition) && displayOptions != null && displayOptions.Length != 0)
				{
					s_searchablePopupWindow.pos = RGUIUtility.GetMouseScreenPos(Vector2.one * 150f);
					s_popupControlId = controlID;
					current.Use();
				}
			}
			else
			{
				EventType type = Event.current.type;
				int? result2 = s_searchablePopupWindow.result;
				if (s_searchablePopupWindow._searchTerms != null)
				{
					if (!searchTerms.Equals(s_searchablePopupWindow._searchTerms))
					{
						result = -1;
					}
					searchTerms = s_searchablePopupWindow._searchTerms;
				}
				if (result2.HasValue && (int)type == 8)
				{
					if (result2.Value >= 0)
					{
						result = result2.Value;
					}
					s_searchablePopupWindow.result = null;
					s_popupControlId = 0;
				}
				else
				{
					if ((int)type == 8 || (int)type == 7)
					{
						GUIStyle val = new GUIStyle(InterfaceMaker.CustomSkin.button)
						{
							padding = new RectOffset(24, 48, 2, 2)
						};
						GUIStyle textField = InterfaceMaker.CustomSkin.textField;
						Vector2 zero = Vector2.zero;
						for (int i = 0; i < displayOptions.Length; i++)
						{
							Vector2 val2 = val.CalcSize(RGUIUtility.TempContent(displayOptions[i]));
							zero.x = Mathf.Max(zero.x, val2.x);
							zero.y += val2.y;
						}
						if (displayOptions.Length == 0)
						{
							zero.x += 150f;
						}
						RectOffset margin = val.margin;
						zero.y += Mathf.Max(0, displayOptions.Length - 1) * Mathf.Max(margin.top, margin.bottom);
						GUIStyle verticalScrollbar = InterfaceMaker.CustomSkin.verticalScrollbar;
						Vector2 val3 = verticalScrollbar.CalcScreenSize(Vector2.zero);
						RectOffset margin2 = verticalScrollbar.margin;
						GUIStyle horizontalScrollbar = InterfaceMaker.CustomSkin.horizontalScrollbar;
						Vector2 val4 = horizontalScrollbar.CalcScreenSize(Vector2.zero);
						RectOffset margin3 = horizontalScrollbar.margin;
						zero += new Vector2(val3.x + (float)margin2.horizontal, val4.y + (float)margin3.vertical) + Vector2.one * 5f;
						zero.y += textField.CalcHeight(RGUIUtility.TempContent("t"), zero.x);
						Vector2 val5 = InterfaceMaker.CustomSkin.GetStyle("popup").CalcScreenSize(zero);
						Vector2 val6 = new Vector2((float)Screen.width, (float)Screen.height) - s_searchablePopupWindow.pos;
						s_searchablePopupWindow.size = Vector2.Min(val5, val6);
					}
					s_searchablePopupWindow.SetSearchTerms(searchTerms);
					s_searchablePopupWindow.label = label;
					s_searchablePopupWindow.displayOptions = displayOptions;
					WindowInvoker.Add(s_searchablePopupWindow);
				}
			}
			return result;
		}
	}
}
namespace ValheimTooler
{
	public class EntryPoint : MonoBehaviour
	{
		public static readonly int s_boxSpacing = 30;

		private Rect _valheimToolerRect;

		private bool _showMainWindow = true;

		private bool _wasMainWindowShowed;

		public static bool s_showItemGiver = false;

		private WindowToolbar _windowToolbar;

		private readonly string[] _toolbarChoices = new string[4] { "$vt_toolbar_player", "$vt_toolbar_entities", "$vt_toolbar_terrain_shaper", "$vt_toolbar_misc" };

		private string _version;

		public void Start()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			_valheimToolerRect = new Rect(ConfigManager.s_mainWindowPosition.Value.x, ConfigManager.s_mainWindowPosition.Value.y, 800f, 300f);
			_showMainWindow = ConfigManager.s_showAtStartup.Value;
			PlayerHacks.Start();
			EntitiesItemsHacks.Start();
			ItemGiver.Start();
			MiscHacks.Start();
			ESP.Start();
			TerrainShaper.Start();
			_version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
		}

		public void Update()
		{
			if (ConfigManager.s_toggleInterfaceKey.Value.IsDown())
			{
				_showMainWindow = !_showMainWindow;
			}
			PlayerHacks.Update();
			EntitiesItemsHacks.Update();
			ItemGiver.Update();
			MiscHacks.Update();
			ESP.Update();
			TerrainShaper.Update();
		}

		public void OnGUI()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			GUI.skin = InterfaceMaker.CustomSkin;
			if (_showMainWindow)
			{
				if ((Object)(object)GameCamera.instance != (Object)null)
				{
					GameCamera.instance.SetFieldValue("m_mouseCapture", value: false);
					GameCamera.instance.CallMethod("UpdateMouseCapture");
				}
				_valheimToolerRect = GUILayout.Window(1001, _valheimToolerRect, new WindowFunction(ValheimToolerWindow), VTLocalization.instance.Localize("$vt_main_title (v" + _version + ")"), (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Height(10f),
					GUILayout.Width(10f)
				});
				if (s_showItemGiver)
				{
					ItemGiver.DisplayGUI();
				}
				_wasMainWindowShowed = true;
				ConfigManager.s_mainWindowPosition.Value = ((Rect)(ref _valheimToolerRect)).position;
			}
			else if (_wasMainWindowShowed)
			{
				if ((Object)(object)GameCamera.instance != (Object)null)
				{
					GameCamera.instance.SetFieldValue("m_mouseCapture", value: true);
					GameCamera.instance.CallMethod("UpdateMouseCapture");
				}
				_wasMainWindowShowed = false;
			}
			ESP.DisplayGUI();
		}

		private void ValheimToolerWindow(int windowID)
		{
			GUILayout.Space(10f);
			_windowToolbar = (WindowToolbar)GUILayout.Toolbar((int)_windowToolbar, _toolbarChoices.Select((string choice) => VTLocalization.instance.Localize(choice)).ToArray(), Array.Empty<GUILayoutOption>());
			switch (_windowToolbar)
			{
			case WindowToolbar.PLAYER:
				PlayerHacks.DisplayGUI();
				break;
			case WindowToolbar.ENTITIES_ITEMS:
				EntitiesItemsHacks.DisplayGUI();
				break;
			case WindowToolbar.TERRAIN_SHAPER:
				TerrainShaper.DisplayGUI();
				break;
			case WindowToolbar.MISC:
				MiscHacks.DisplayGUI();
				break;
			}
			GUI.DragWindow();
		}
	}
	internal class Loader
	{
		private static GameObject s_entryPoint = null;

		private static readonly Harmony s_harmony = new Harmony("ValheimTooler");

		public static void Init()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)s_entryPoint == (Object)null)
			{
				RunPatches();
				s_entryPoint = new GameObject();
				s_entryPoint.AddComponent<EntryPoint>();
				s_entryPoint.AddComponent<RapidGUIBehaviour>();
				Object.DontDestroyOnLoad((Object)(object)s_entryPoint);
			}
		}

		private static void RunPatches()
		{
			s_harmony.PatchAll();
		}

		public static void Unload()
		{
			_Unload();
		}

		private static void _Unload()
		{
			Object.Destroy((Object)(object)s_entryPoint);
			s_harmony.UnpatchSelf();
		}
	}
}
namespace ValheimTooler.Utils
{
	public static class ConfigManager
	{
		private static readonly ConfigFile s_settingsFile;

		private static readonly ConfigFile s_internalFile;

		private static readonly string s_configurationPath;

		private const string SettingsFileName = "valheimtooler_settings.cfg";

		private const string InternalFileName = "valheimtooler_internal.cfg";

		public static ConfigEntry<KeyboardShortcut> s_toggleInterfaceKey;

		public static ConfigEntry<bool> s_showAtStartup;

		public static ConfigEntry<string> s_language;

		public static ConfigEntry<KeyboardShortcut> s_godModeShortCut;

		public static ConfigEntry<KeyboardShortcut> s_unlimitedStaminaShortcut;

		public static ConfigEntry<KeyboardShortcut> s_flyModeShortcut;

		public static ConfigEntry<KeyboardShortcut> s_ghostModeShortcut;

		public static ConfigEntry<KeyboardShortcut> s_noPlacementCostShortcut;

		public static ConfigEntry<KeyboardShortcut> s_inventoryInfiniteWeightShortcut;

		public static ConfigEntry<KeyboardShortcut> s_instantCraftShortcut;

		public static ConfigEntry<KeyboardShortcut> s_removeAllDropShortcut;

		public static ConfigEntry<KeyboardShortcut> s_terrainShapeShortcut;

		public static ConfigEntry<KeyboardShortcut> s_terrainLevelShortcut;

		public static ConfigEntry<KeyboardShortcut> s_terrainLowerShortcut;

		public static ConfigEntry<KeyboardShortcut> s_terrainRaiseShortcut;

		public static ConfigEntry<KeyboardShortcut> s_terrainResetShortcut;

		public static ConfigEntry<KeyboardShortcut> s_terrainSmoothShortcut;

		public static ConfigEntry<KeyboardShortcut> s_terrainPaintShortcut;

		public static ConfigEntry<KeyboardShortcut> s_espPlayersShortcut;

		public static ConfigEntry<KeyboardShortcut> s_espMonstersShortcut;

		public static ConfigEntry<KeyboardShortcut> s_espDroppedItemsShortcut;

		public static ConfigEntry<KeyboardShortcut> s_espDepositsShortcut;

		public static ConfigEntry<KeyboardShortcut> s_espPickablesShortcut;

		public static ConfigEntry<Vector2> s_mainWindowPosition;

		public static ConfigEntry<Vector2> s_itemGiverWindowPosition;

		public static ConfigEntry<bool> s_permanentPins;

		public static ConfigEntry<bool> s_espRadiusEnabled;

		public static ConfigEntry<float> s_espRadius;

		static ConfigManager()
		{
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "config_vt.path");
			string path2 = "";
			if (File.Exists(path))
			{
				path2 = Path.GetFullPath(File.ReadAllText(path));
				if (!Directory.Exists(path2))
				{
					ZLog.Log((object)"[ValheimTooler - ConfigManager] Path given in config_vt.path file is incorrect.");
					path2 = "";
				}
			}
			else
			{
				ZLog.Log((object)"[ValheimTooler - ConfigManager] Failed to find config_vt.path file.");
			}
			s_configurationPath = path2;
			string configPath = Path.Combine(s_configurationPath, "valheimtooler_settings.cfg");
			string configPath2 = Path.Combine(s_configurationPath, "valheimtooler_internal.cfg");
			s_settingsFile = new ConfigFile(configPath, saveOnInit: true);
			s_internalFile = new ConfigFile(configPath2, saveOnInit: true);
			s_toggleInterfaceKey = s_settingsFile.Bind("General", "ToggleInterfaceKey", new KeyboardShortcut((KeyCode)127), "Which key will show/hide the tool.");
			s_showAtStartup = s_settingsFile.Bind("General", "ShowAtStartup", defaultValue: true, "Choose whether or not to display the tool at startup.");
			s_language = s_settingsFile.Bind("General", "Language", "Auto", new ConfigDescription("Tool language, in auto the language is chosen according to the game language.", new AcceptableValueList<string>("Auto", "French", "English")));
			s_godModeShortCut = s_settingsFile.Bind("Shortcuts", "GodMode", default(KeyboardShortcut), "The shortcut to use the god mode feature");
			s_unlimitedStaminaShortcut = s_settingsFile.Bind("Shortcuts", "UnlimitedStamina", default(KeyboardShortcut), "The shortcut to use the unlimited stamina feature");
			s_flyModeShortcut = s_settingsFile.Bind("Shortcuts", "FlyMode", default(KeyboardShortcut), "The shortcut to use the fly mode feature");
			s_ghostModeShortcut = s_settingsFile.Bind("Shortcuts", "GhostMode", default(KeyboardShortcut), "The shortcut to use the ghost mode feature");
			s_noPlacementCostShortcut = s_settingsFile.Bind("Shortcuts", "NoPlacementCost", default(KeyboardShortcut), "The shortcut to use the no placement cost feature");
			s_inventoryInfiniteWeightShortcut = s_settingsFile.Bind("Shortcuts", "InventoryInfiniteWeight", default(KeyboardShortcut), "The shortcut to use the inventory with infinite weight feature");
			s_instantCraftShortcut = s_settingsFile.Bind("Shortcuts", "InstantCraft", default(KeyboardShortcut), "The shortcut to use the instant craft feature");
			s_removeAllDropShortcut = s_settingsFile.Bind("Shortcuts", "RemoveAllDrops", default(KeyboardShortcut), "The shortcut to use the remove all drops feature");
			s_terrainShapeShortcut = s_settingsFile.Bind("Shortcuts", "TerrainChangeShape", default(KeyboardShortcut), "");
			s_terrainLevelShortcut = s_settingsFile.Bind("Shortcuts", "TerrainLevel", default(KeyboardShortcut), "");
			s_terrainLowerShortcut = s_settingsFile.Bind("Shortcuts", "TerrainLower", default(KeyboardShortcut), "");
			s_terrainRaiseShortcut = s_settingsFile.Bind("Shortcuts", "TerrainRaise", default(KeyboardShortcut), "");
			s_terrainResetShortcut = s_settingsFile.Bind("Shortcuts", "TerrainReset", default(KeyboardShortcut), "");
			s_terrainSmoothShortcut = s_settingsFile.Bind("Shortcuts", "TerrainSmooth", default(KeyboardShortcut), "");
			s_terrainPaintShortcut = s_settingsFile.Bind("Shortcuts", "TerrainPaint", default(KeyboardShortcut), "");
			s_espPlayersShortcut = s_settingsFile.Bind("Shortcuts", "ESPPlayers", default(KeyboardShortcut), "The shortcut to show/hide the ESP for players");
			s_espMonstersShortcut = s_settingsFile.Bind("Shortcuts", "ESPMonsters", default(KeyboardShortcut), "The shortcut to show/hide the ESP for monsters");
			s_espDroppedItemsShortcut = s_settingsFile.Bind("Shortcuts", "ESPDroppedItems", default(KeyboardShortcut), "The shortcut to show/hide the ESP for dropped items");
			s_espDepositsShortcut = s_settingsFile.Bind("Shortcuts", "ESPDeposits", default(KeyboardShortcut), "The shortcut to show/hide the ESP for deposits");
			s_espPickablesShortcut = s_settingsFile.Bind("Shortcuts", "ESPPickables", default(KeyboardShortcut), "The shortcut to show/hide the ESP for pickables");
			s_mainWindowPosition = s_internalFile.Bind<Vector2>("Internal", "MainWindowPosition", new Vector2(5f, 5f));
			s_itemGiverWindowPosition = s_internalFile.Bind<Vector2>("Internal", "ItemGiverPosition", new Vector2((float)(Screen.width - 400), 5f));
			s_permanentPins = s_internalFile.Bind("Internal", "PermanentPins", defaultValue: false);
			s_espRadiusEnabled = s_internalFile.Bind("Internal", "RadiusEnabled", defaultValue: false);
			s_espRadius = s_internalFile.Bind("Internal", "RadiusValue", 5f);
			s_settingsFile.OrphanedEntries.Clear();
			s_internalFile.OrphanedEntries.Clear();
			s_settingsFile.Save();
			s_internalFile.Save();
		}
	}
	public class VTLocalization
	{
		public static readonly string s_cheatOn = "$vt_cheat_on";

		public static readonly string s_cheatOff = "$vt_cheat_off";

		private static VTLocalization s_instance;

		private static readonly char[] s_endChars = " (){}[]+-!?/\\\\&%,.:-=<>\n".ToCharArray();

		private Dictionary<string, string> m_translations = new Dictionary<string, string>();

		public static VTLocalization instance
		{
			get
			{
				if (s_instance == null)
				{
					Initialize();
				}
				return s_instance;
			}
		}

		private static void Initialize()
		{
			if (s_instance == null)
			{
				s_instance = new VTLocalization();
			}
		}

		private VTLocalization()
		{
			SetupLanguage("English");
			string value = ConfigManager.s_language.Value;
			if (value == "Auto")
			{
				string @string = PlayerPrefs.GetString("language", "");
				if (@string.Length > 0)
				{
					SetupLanguage(@string);
				}
			}
			else if (value != "English")
			{
				SetupLanguage(value);
			}
		}

		public string Localize(string text)
		{
			StringBuilder stringBuilder = new StringBuilder();
			int num = 0;
			string word;
			int wordStart;
			int wordEnd;
			while (FindNextWord(text, num, out word, out wordStart, out wordEnd))
			{
				stringBuilder.Append(text.Substring(num, wordStart - num));
				stringBuilder.Append(Translate(word));
				num = wordEnd;
			}
			stringBuilder.Append(text.Substring(num));
			return stringBuilder.ToString();
		}

		private bool FindNextWord(string text, int startIndex, out string word, out int wordStart, out int wordEnd)
		{
			if (startIndex >= text.Length - 1)
			{
				word = null;
				wordStart = -1;
				wordEnd = -1;
				return false;
			}
			wordStart = text.IndexOf('$', startIndex);
			if (wordStart != -1)
			{
				int num = text.IndexOfAny(s_endChars, wordStart);
				if (num != -1)
				{
					word = text.Substring(wordStart + 1, num - wordStart - 1);
					wordEnd = num;
				}
				else
				{
					word = text.Substring(wordStart + 1);
					wordEnd = text.Length;
				}
				return true;
			}
			word = null;
			wordEnd = -1;
			return false;
		}

		private string Translate(string word)
		{
			if (word.StartsWith("KEY_"))
			{
				string bindingName = word.Substring(4);
				return GetBoundKeyString(bindingName);
			}
			if (m_translations.TryGetValue(word, out var value))
			{
				return value;
			}
			return "[" + word + "]";
		}

		public string GetBoundKeyString(string bindingName)
		{
			string boundKeyString = ZInput.instance.GetBoundKeyString(bindingName, false);
			if (boundKeyString.Length > 0 && boundKeyString[0] == '$' && m_translations.TryGetValue(boundKeyString.Substring(1), out var value))
			{
				return value;
			}
			return boundKeyString;
		}

		private void AddWord(string key, string text)
		{
			m_translations.Remove(key);
			m_translations.Add(key, text);
		}

		private void Clear()
		{
			m_translations.Clear();
		}

		public bool SetupLanguage(string language)
		{
			if (!LoadCFG(language))
			{
				return false;
			}
			return true;
		}

		public bool LoadCFG(string language)
		{
			byte[] embeddedResource = ResourceUtils.GetEmbeddedResource("Resources.Localization.translations.cfg");
			if (embeddedResource == null)
			{
				ZLog.Log((object)"Failed to load the translation file!");
				return false;
			}
			Configuration val = Configuration.LoadFromString(Encoding.UTF8.GetString(embeddedResource, 0, embeddedResource.Length));
			if (!val.Contains(language))
			{
				ZLog.Log((object)("Failed to find language: " + language));
				return false;
			}
			foreach (Setting item in val[language])
			{
				AddWord(((ConfigurationElement)item).Name, item.StringValue);
			}
			return true;
		}
	}
	public static class ReflectionExtensions
	{
		public static T GetFieldValue<T>(this object obj, string name)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
			return (T)(obj.GetType().GetField(name, bindingAttr)?.GetValue(obj));
		}

		public static void SetFieldValue<T>(this object obj, string name, T value)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
			obj.GetType().GetField(name, bindingAttr)?.SetValue(obj, value);
		}

		public static object CallMethod(this object obj, string methodName, params object[] args)
		{
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
			MethodInfo method = obj.GetType().GetMethod(methodName, bindingAttr);
			if (method != null)
			{
				return method.Invoke(obj, args);
			}
			return null;
		}

		public static object CallStaticMethod<T>(string methodName, params object[] args) where T : new()
		{
			BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
			MethodInfo method = typeof(T).GetMethod(methodName, bindingAttr);
			if (method != null)
			{
				return method.Invoke(null, args);
			}
			return null;
		}
	}
	public static class ResourceUtils
	{
		private static Dictionary<string, GameObject> s_cachedPrefabs = new Dictionary<string, GameObject>();

		public static byte[] ReadAllBytes(this Stream input)
		{
			byte[] array = new byte[16384];
			using MemoryStream memoryStream = new MemoryStream();
			int count;
			while ((count = input.Read(array, 0, array.Length)) > 0)
			{
				memoryStream.Write(array, 0, count);
			}
			return memoryStream.ToArray();
		}

		public static byte[] GetEmbeddedResource(string resourceFileName, Assembly containingAssembly = null)
		{
			if (containingAssembly == null)
			{
				containingAssembly = Assembly.GetCallingAssembly();
			}
			string name = containingAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(resourceFileName));
			using Stream input = containingAssembly.GetManifestResourceStream(name);
			byte[] array = input.ReadAllBytes();
			if (array.Length == 0)
			{
				Debug.LogWarning((object)string.Format("The resource %1 was not found", resourceFileName));
			}
			return array;
		}

		public static Texture2D LoadTexture(byte[] texData)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)5, false);
			MethodInfo method = typeof(Texture2D).GetMethod("LoadImage", new Type[1] { typeof(byte[]) });
			if (method != null)
			{
				method.Invoke(val, new object[1] { texData });
			}
			else
			{
				Type? type = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule");
				if (type == null)
				{
					throw new ArgumentNullException("converter");
				}
				MethodInfo? method2 = type.GetMethod("LoadImage", new Type[2]
				{
					typeof(Texture2D),
					typeof(byte[])
				});
				if (method2 == null)
				{
					throw new ArgumentNullException("converterMethod");
				}
				method2.Invoke(null, new object[2] { val, texData });
			}
			return val;
		}

		public static GameObject GetHiddenPrefab(string name)
		{
			if (s_cachedPrefabs.TryGetValue(name.ToLower(), out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			foreach (GameObject item in from t in Resources.FindObjectsOfTypeAll<Transform>()
				where (Object)(object)t.parent == (Object)null
				select t into x
				select ((Component)x).gameObject)
			{
				if (((Object)item).name.Equals(name, StringComparison.OrdinalIgnoreCase))
				{
					if (s_cachedPrefabs.ContainsKey(name.ToLower()))
					{
						s_cachedPrefabs.Remove(name.ToLower());
					}
					s_cachedPrefabs.Add(name.ToLower(), item);
					return item;
				}
			}
			return null;
		}
	}
}
namespace ValheimTooler.UI
{
	internal class InterfaceMaker
	{
		private static GUISkin s_customSkin;

		private static Texture2D s_winBackground;

		private static Texture2D s_winTitleBackground;

		private static Texture2D s_boxBackground;

		private static Texture2D s_toggleOffBackground;

		private static Texture2D s_toggleOnBackground;

		private static Texture2D s_buttonNormalBackground;

		private static Texture2D s_buttonHoverBackground;

		private static Texture2D s_buttonActiveBackground;

		private static Texture2D s_buttonActiveNormalBackground;

		private static Texture2D s_buttonActiveHoverBackground;

		private static Texture2D s_buttonActiveActiveBackground;

		private static Texture2D s_fieldBackground;

		private static Texture2D s_scrollBackground;

		private static Texture2D s_scrollThumbBackground;

		private static Texture2D s_flatButtonNormalBackground;

		private static Texture2D s_flatButtonHoverBackground;

		private static Texture2D s_flatButtonActiveBackground;

		private static Font s_font;

		private static GUISkin s_oldSkin;

		public static GUISkin CustomSkin
		{
			get
			{
				if ((Object)(object)s_customSkin == (Object)null)
				{
					try
					{
						s_customSkin = CreateSkin();
					}
					catch (Exception ex)
					{
						ZLog.Log((object)("Could not load custom GUISkin - " + ex.Message));
						s_customSkin = GUI.skin;
					}
				}
				return s_customSkin;
			}
		}

		public static GUISkin OldSkin => s_oldSkin;

		private static GUISkin CreateSkin()
		{
			//IL_0036: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: 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_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Expected O, but got Unknown
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Expected O, but got Unknown
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Expected O, but got Unknown
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_0530: Unknown result type (might be due to invalid IL or missing references)
			//IL_055a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0584: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0602: Unknown result type (might be due to invalid IL or missing references)
			//IL_062c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0640: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Expected O, but got Unknown
			//IL_0650: Unknown result type (might be due to invalid IL or missing references)
			//IL_068a: Unknown result type (might be due to invalid IL or missing references)
			//IL_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0690: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Expected O, but got Unknown
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a6: Expected O, but got Unknown
			//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d9: Expected O, but got Unknown
			//IL_06e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0702: Expected O, but got Unknown
			s_oldSkin = GUI.skin;
			GUISkin val = Object.Instantiate<GUISkin>(GUI.skin);
			Object.DontDestroyOnLoad((Object)(object)val);
			LoadTextures();
			val.font = s_font;
			val.label.normal.textColor = Color.gray;
			val.box.onNormal.background = null;
			val.box.normal.background = s_boxBackground;
			val.box.normal.textColor = Color.gray;
			RectOffset padding = val.box.padding;
			padding.top += 7;
			RectOffset padding2 = val.box.padding;
			padding2.bottom += 7;
			RectOffset padding3 = val.box.padding;
			padding3.left += 7;
			RectOffset padding4 = val.box.padding;
			padding4.right += 7;
			val.window.border = new RectOffset(80, 80, 80, 20);
			RectOffset padding5 = val.window.padding;
			padding5.top += 5;
			val.window.onNormal.background = null;
			val.window.normal.background = s_winTitleBackground;
			val.window.normal.textColor = Color.white;
			val.button.normal.textColor = Color.white;
			val.button.normal.background = s_buttonNormalBackground;
			val.button.hover.textColor = Color.white;
			val.button.hover.background = s_buttonHoverBackground;
			val.button.active.textColor = Color.white;
			val.button.active.background = s_buttonActiveBackground;
			val.button.onNormal.textColor = Color.white;
			val.button.onNormal.background = s_buttonActiveNormalBackground;
			val.button.onHover.textColor = Color.white;
			val.button.onHover.background = s_buttonActiveHoverBackground;
			val.button.onActive.textColor = Color.white;
			val.button.onActive.background = s_buttonActiveActiveBackground;
			val.button.font = s_font;
			val.button.wordWrap = false;
			val.horizontalSliderThumb.normal.background = s_buttonNormalBackground;
			val.horizontalSliderThumb.hover.background = s_buttonHoverBackground;
			val.horizontalSliderThumb.active.background = s_buttonActiveBackground;
			val.horizontalSliderThumb.onNormal.background = s_buttonActiveNormalBackground;
			val.horizontalSliderThumb.onHover.background = s_buttonActiveHoverBackground;
			val.horizontalSliderThumb.onActive.background = s_buttonActiveActiveBackground;
			val.horizontalSlider.normal.background = s_scrollBackground;
			val.toggle.normal.textColor = Color.gray;
			val.toggle.normal.background = s_toggleOffBackground;
			val.toggle.onNormal.textColor = Color.gray;
			val.toggle.onNormal.background = s_toggleOnBackground;
			val.toggle.hover.textColor = Color.gray;
			val.toggle.hover.background = s_toggleOffBackground;
			val.toggle.onHover.textColor = Color.gray;
			val.toggle.onHover.background = s_toggleOnBackground;
			val.toggle.active.textColor = Color.gray;
			val.toggle.active.background = s_toggleOnBackground;
			val.toggle.onActive.textColor = Color.gray;
			val.toggle.onActive.background = s_toggleOffBackground;
			val.toggle.border = new RectOffset(0, 0, 0, 0);
			val.toggle.overflow = new RectOffset(0, 0, 0, 0);
			val.toggle.imagePosition = (ImagePosition)2;
			val.toggle.padding = new RectOffset(0, 0, 0, 0);
			val.toggle.fixedWidth = 30f;
			val.toggle.fixedHeight = 30f;
			RectOffset padding6 = val.button.padding;
			int top = (val.button.padding.bottom = 6);
			padding6.top = top;
			RectOffset padding7 = val.button.padding;
			top = (val.button.padding.left = 5);
			padding7.left = top;
			RectOffset border = val.button.border;
			top = (val.button.border.top = 0);
			border.bottom = top;
			RectOffset border2 = val.button.border;
			top = (val.button.border.right = 10);
			border2.left = top;
			val.textField.normal.background = s_fieldBackground;
			val.textField.normal.textColor = Color.white;
			val.textField.onNormal.background = s_fieldBackground;
			val.textField.onNormal.textColor = Color.white;
			val.textField.hover.background = s_fieldBackground;
			val.textField.hover.textColor = Color.white;
			val.textField.onHover.background = s_fieldBackground;
			val.textField.onHover.textColor = Color.white;
			val.textField.active.background = s_fieldBackground;
			val.textField.active.textColor = Color.white;
			val.textField.onActive.background = s_fieldBackground;
			val.textField.onActive.textColor = Color.white;
			val.textField.focused.background = s_fieldBackground;
			val.textField.focused.textColor = Color.white;
			val.textField.onFocused.background = s_fieldBackground;
			val.textField.onFocused.textColor = Color.white;
			val.textField.padding = new RectOffset(8, 8, 5, 5);
			val.settings.cursorColor = Color.white;
			val.verticalScrollbar.normal.background = s_scrollBackground;
			val.verticalScrollbarThumb.normal.background = s_scrollThumbBackground;
			GUIStyle val2 = new GUIStyle(val.box)
			{
				border = new RectOffset(),
				name = "popup"
			};
			GUIStyleState normal = val2.normal;
			Texture2D background = (val2.hover.background = s_winBackground);
			normal.background = background;
			val2.border = new RectOffset(30, 30, 30, 30);
			GUIStyle val4 = new GUIStyle(OldSkin.label)
			{
				wordWrap = false,
				alignment = (TextAnchor)4,
				name = "flatButton"
			};
			val4.normal.background = s_flatButtonNormalBackground;
			val4.hover.background = s_flatButtonHoverBackground;
			val4.onNormal.background = s_flatButtonActiveBackground;
			val.customStyles = (GUIStyle[])(object)new GUIStyle[2] { val2, val4 };
			return val;
		}

		private static void LoadTextures()
		{
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Expected O, but got Unknown
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Expected O, but got Unknown
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Expected O, but got Unknown
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			s_winBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.window.png"));
			Object.DontDestroyOnLoad((Object)(object)s_winBackground);
			s_winTitleBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.window_title.png"));
			Object.DontDestroyOnLoad((Object)(object)s_winTitleBackground);
			s_boxBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.box.png"));
			Object.DontDestroyOnLoad((Object)(object)s_boxBackground);
			s_toggleOffBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.toggle_off.png"));
			Object.DontDestroyOnLoad((Object)(object)s_toggleOffBackground);
			s_toggleOnBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.toggle_on.png"));
			Object.DontDestroyOnLoad((Object)(object)s_toggleOnBackground);
			s_buttonNormalBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.button_normal.png"));
			Object.DontDestroyOnLoad((Object)(object)s_buttonNormalBackground);
			s_buttonHoverBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.button_hover.png"));
			Object.DontDestroyOnLoad((Object)(object)s_buttonHoverBackground);
			s_buttonActiveBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.button_active.png"));
			Object.DontDestroyOnLoad((Object)(object)s_buttonActiveBackground);
			s_buttonActiveNormalBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.button_active_normal.png"));
			Object.DontDestroyOnLoad((Object)(object)s_buttonActiveNormalBackground);
			s_buttonActiveHoverBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.button_active_hover.png"));
			Object.DontDestroyOnLoad((Object)(object)s_buttonActiveHoverBackground);
			s_buttonActiveActiveBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.button_active_active.png"));
			Object.DontDestroyOnLoad((Object)(object)s_buttonActiveActiveBackground);
			s_fieldBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.field.png"));
			Object.DontDestroyOnLoad((Object)(object)s_fieldBackground);
			s_scrollBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.scroll_background.png"));
			Object.DontDestroyOnLoad((Object)(object)s_scrollBackground);
			s_scrollThumbBackground = ResourceUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("Resources.scroll_thumb.png"));
			Object.DontDestroyOnLoad((Object)(object)s_scrollThumbBackground);
			s_flatButtonNormalBackground = new Texture2D(1, 1);
			s_flatButtonNormalBackground.SetPixels((Color[])(object)new Color[1]
			{
				new Color(0.5f, 0.5f, 0.5f, 0.5f)
			});
			s_flatButtonNormalBackground.Apply();
			Object.DontDestroyOnLoad((Object)(object)s_flatButtonNormalBackground);
			s_flatButtonHoverBackground = new Texture2D(1, 1);
			s_flatButtonHoverBackground.SetPixels((Color[])(object)new Color[1]
			{
				new Color(0.5f, 0.5f, 0.5f, 0.2f)
			});
			s_flatButtonHoverBackground.Apply();
			Object.DontDestroyOnLoad((Object)(object)s_flatButtonHoverBackground);
			s_flatButtonActiveBackground = new Texture2D(1, 1);
			s_flatButtonActiveBackground.SetPixels((Color[])(object)new Color[1]
			{
				new Color(0.9f, 0.5f, 0.1f, 0.5f)
			});
			s_flatButtonActiveBackground.Apply();
			Object.DontDestroyOnLoad((Object)(object)s_flatButtonActiveBackground);
			s_font = ((IEnumerable<Font>)(Resources.FindObjectsOfTypeAll(typeof(Font)) as Font[])).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.Equals("AveriaSerifLibre-Bold")));
			if ((Object)(object)s_font == (Object)null)
			{
				ZLog.Log((object)"Error while loading font!");
			}
		}
	}
	public static class Utils
	{
		public static string ToggleButtonLabel(string labelCode, bool condition, KeyboardShortcut? shortcut)
		{
			return ToggleButtonLabelCustom(labelCode, condition, VTLocalization.s_cheatOn, VTLocalization.s_cheatOff, shortcut);
		}

		public static string ToggleButtonLabel(string labelCode, bool condition)
		{
			return ToggleButtonLabel(labelCode, condition, null);
		}

		public static string ToggleButtonLabelCustom(string labelCode, bool condition, string activeLabelCode, string normalLabelCode)
		{
			return ToggleButtonLabelCustom(labelCode, condition, activeLabelCode, normalLabelCode, null);
		}

		public static string ToggleButtonLabelCustom(string labelCode, bool condition, string activeLabelCode, string normalLabelCode, KeyboardShortcut? shortcut)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			string text = VTLocalization.instance.Localize(labelCode + " : " + (condition ? activeLabelCode : normalLabelCode));
			if (shortcut.HasValue && (int)shortcut.Value.MainKey != 0)
			{
				text = text + " [" + shortcut.Value.ToString() + "]";
			}
			return text;
		}

		public static string LabelWithShortcut(string labelCode, KeyboardShortcut? shortcut)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			string text = VTLocalization.instance.Localize(labelCode);
			if (shortcut.HasValue && (int)shortcut.Value.MainKey != 0)
			{
				text = text + " [" + shortcut.Value.ToString() + "]";
			}
			return text;
		}
	}
	public static class SpriteManager
	{
		private static readonly Dictionary<string, Texture2D> s_atlasCache;

		static SpriteManager()
		{
			s_atlasCache = new Dictionary<string, Texture2D>();
		}

		public static Texture2D TextureFromSprite(Sprite sprite, bool resize = true)
		{
			//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_0075: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//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_00ad: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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)
			Rect val = sprite.rect;
			if (((Rect)(ref val)).width == (float)((Texture)sprite.texture).width)
			{
				return sprite.texture;
			}
			Texture2D val2;
			if (s_atlasCache.ContainsKey(((Object)sprite.texture).name))
			{
				val2 = s_atlasCache[((Object)sprite.texture).name];
			}
			else
			{
				val2 = DuplicateTexture(sprite.texture);
				s_atlasCache.Add(((Object)sprite.texture).name, val2);
			}
			val = sprite.rect;
			int num = (int)((Rect)(ref val)).width;
			val = sprite.rect;
			Texture2D val3 = new Texture2D(num, (int)((Rect)(ref val)).height);
			Texture2D obj = val2;
			val = sprite.textureRect;
			int num2 = Mathf.CeilToInt(((Rect)(ref val)).x);
			val = sprite.textureRect;
			int num3 = Mathf.CeilToInt(((Rect)(ref val)).y);
			val = sprite.textureRect;
			int num4 = Mathf.CeilToInt(((Rect)(ref val)).width);
			val = sprite.textureRect;
			Color[] pixels = obj.GetPixels(num2, num3, num4, Mathf.CeilToInt(((Rect)(ref val)).height));
			val3.SetPixels(pixels);
			val3.Apply();
			if (resize && (((Texture)val3).width > 200 || ((Texture)val3).height > 200))
			{
				val3.Reinitialize(60, 60);
			}
			return val3;
		}

		public static Texture2D DuplicateTexture(Texture2D source)
		{
			//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_0052: 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_0071: Expected O, but got Unknown
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)1);
			Graphics.Blit((Texture)(object)source, temporary);
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(((Texture)source).width, ((Texture)source).height);
			val.ReadPixels(new Rect(0f, 0f, (float)((Texture)temporary).width, (float)((Texture)temporary).height), 0, 0);
			val.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return val;
		}
	}
}
namespace ValheimTooler.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	public class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		public static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("ValheimTooler.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		public static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace ValheimTooler.Patches
{
	[HarmonyPatch(typeof(Inventory), "IsTeleportable")]
	internal class AlwaysTeleportAllow
	{
		private static bool Prefix(ref bool __result)
		{
			if (PlayerHacks.s_bypassRestrictedTeleportable)
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Destructible), "Start")]
	internal class AutoPinResources
	{
		private static Random s_random = new Random();

		private const string Chars = "0123456789";

		private static void Postfix(ref Destructible __instance)
		{
			if (!MiscHacks.s_enableAutopinMap)
			{
				return;
			}
			HoverText component = ((Component)__instance).GetComponent<HoverText>();
			if (Object.op_Implicit((Object)(object)component) && !((Object)(object)((Component)__instance).gameObject.GetComponent<PinnedObject>() != (Object)null) && component.m_text.ToLower().Contains("deposit"))
			{
				string text = new string((from s in Enumerable.Repeat("0123456789", 5)
					select s[s_random.Next(s.Length)]).ToArray());
				string text2 = component.GetHoverName() + " [VT" + text + "]";
				((Component)__instance).gameObject.AddComponent<PinnedObject>().Init(text2);
				ZLog.Log((object)("Pin candidate: " + text2));
			}
		}
	}
	[HarmonyPatch(typeof(Player), "EdgeOfWorldKill", new Type[] { typeof(float) })]
	internal class EdgeMapKill
	{
		private static bool Prefix()
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null && Player.m_localPlayer.VTInGodMode())
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "UseStamina", new Type[]
	{
		typeof(float),
		typeof(bool)
	})]
	internal class InfiniteStamina
	{
		private static void Prefix(ref float v)
		{
			if (PlayerHacks.s_isInfiniteStaminaMe)
			{
				v = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateRecipe", new Type[]
	{
		typeof(Player),
		typeof(float)
	})]
	internal class InstantCraft
	{
		private static void Prefix(ref Player player, ref float dt)
		{
			if (PlayerHacks.s_instantCraft)
			{
				dt = 2f;
			}
		}
	}
	[HarmonyPatch(typeof(Inventory), "GetTotalWeight")]
	internal class InventoryNoWeightLimit
	{
		private static bool Prefix(ref float __result)
		{
			if (PlayerHacks.s_inventoryNoWeightLimit)
			{
				__result = 0f;
				return false;
			}
			return true;
		}
	}
	internal class NoPlacementCostRepair
	{
		[HarmonyPatch(typeof(InventoryGui), "CanRepair", new Type[] { typeof(ItemData) })]
		public class CanRepairPatch
		{
			private static bool Prefix(ref InventoryGui __instance, ref bool __result, ItemData item)
			{
				if ((Object)(object)Player.m_localPlayer == (Object)null)
				{
					return true;
				}
				bool fieldValue = Player.m_localPlayer.GetFieldValue<bool>("m_noPlacementCost");
				if (fieldValue)
				{
					__result = fieldValue;
					return false;
				}
				return true;
			}
		}
	}
}
namespace ValheimTooler.Models
{
	public class TPTarget
	{
		public enum TargetType
		{
			PlayerNet,
			Player,
			Peer,
			MapPin
		}

		public readonly TargetType targetType;

		public readonly PlayerInfo playerNet;

		public readonly Player player;

		public readonly ZNetPeer peer;

		public readonly PinData minimapPin;

		public string Name => targetType switch
		{
			TargetType.PlayerNet => playerNet.m_name, 
			TargetType.Player => player.GetPlayerName(), 
			TargetType.Peer => peer.m_playerName, 
			TargetType.MapPin => $"{minimapPin.m_name} ({minimapPin.m_type})", 
			_ => "", 
		};

		public Vector3? Position
		{
			get
			{
				//IL_0055: 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_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: 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)
				switch (targetType)
				{
				case TargetType.PlayerNet:
					if (playerNet.m_publicPosition)
					{
						return playerNet.m_position;
					}
					return null;
				case TargetType.Player:
					return ((Component)player).transform.position;
				case TargetType.Peer:
					return null;
				case TargetType.MapPin:
				{
					Vector3 pos = minimapPin.m_pos;
					pos.y = Mathf.Clamp(pos.y, ZoneSystem.instance.m_waterLevel, ZoneSystem.instance.m_waterLevel);
					return pos;
				}
				default:
					return null;
				}
			}
		}

		public TPTarget(TargetType targetType, object target)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			this.targetType = targetType;
			switch (targetType)
			{
			case TargetType.PlayerNet:
				playerNet = (PlayerInfo)target;
				break;
			case TargetType.Player:
				player = (Player)target;
				break;
			case TargetType.Peer:
				peer = (ZNetPeer)target;
				break;
			case TargetType.MapPin:
				minimapPin = (PinData)target;
				break;
			}
		}

		public override string ToString()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			return targetType switch
			{
				TargetType.PlayerNet => "Player " + playerNet.m_name, 
				TargetType.Player => "Player " + player.GetPlayerName(), 
				TargetType.Peer => "Player " + peer.m_playerName, 
				TargetType.MapPin => $"Map pin: {minimapPin.m_name} ({minimapPin.m_type})", 
				_ => "Unknow", 
			};
		}
	}
}
namespace ValheimTooler.Models.Mono
{
	internal class PinnedObject : MonoBehaviour
	{
		public PinData pin;

		public void Init(string aName)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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)
			pin = Minimap.instance.AddPin(((Component)this).transform.position, (PinType)3, aName, ConfigManager.s_permanentPins.Value, false, 0L, "");
			ZLog.Log((object)$"Tracking: {aName} at {((Component)this).transform.position.x} {((Component)this).transform.position.y} {((Component)this).transform.position.z}");
		}

		private void OnDestroy()
		{
			//IL_0058: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			if (pin != null && (Object)(object)Minimap.instance != (Object)null && !ConfigManager.s_permanentPins.Value)
			{
				Minimap.instance.RemovePin(pin);
				ZLog.Log((object)$"Removing: {pin.m_name} at {((Component)this).transform.position.x} {((Component)this).transform.position.y} {((Component)this).transform.position.z}");
			}
		}
	}
}
namespace ValheimTooler.Core
{
	public static class EntitiesItemsHacks
	{
		private static string s_entityQuantityText = "1";

		private static int s_entityLevelIdx = 0;

		private static int s_entityPrefabIdx = 0;

		private static string s_entitySearchTerms = "";

		private static string s_previousSearchTerms = "";

		private static float s_updateTimer = 0f;

		private static readonly float s_updateTimerInterval = 1.5f;

		private static readonly List<string> s_entityLevels = new List<string>();

		private static readonly List<string> s_entityPrefabs = new List<string>();

		private static List<string> s_entityPrefabsFiltered = new List<string>();

		private static int NameComparator(string a, string b)
		{
			return string.Compare(a, b, StringComparison.InvariantCultureIgnoreCase);
		}

		public static void Start()
		{
			for (int i = 1; i <= 5; i++)
			{
				s_entityLevels.Add(i.ToString());
			}
		}

		public static void Update()
		{
			if (Time.time >= s_updateTimer && s_entityPrefabs.Count == 0)
			{
				if (Object.op_Implicit((Object)(object)ZNetScene.instance))
				{
					foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
					{
						s_entityPrefabs.Add(((Object)prefab).name);
					}
					s_entityPrefabs.Sort(NameComparator);
					s_entityPrefabsFiltered = s_entityPrefabs;
				}
				s_updateTimer = Time.time + s_updateTimerInterval;
			}
			if (ConfigManager.s_removeAllDropShortcut.Value.IsDown())
			{
				RemoveAllDrops();
			}
		}

		public static void DisplayGUI()
		{
			GUILayout.BeginVertical(VTLocalization.instance.Localize("$vt_entities_spawn_title"), GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_entities_spawn_entity_name :"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_entityPrefabIdx = RGUI.SearchableSelectionPopup(s_entityPrefabIdx, s_entityPrefabsFiltered.ToArray(), ref s_entitySearchTerms);
			SearchItem(s_entitySearchTerms);
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_entities_spawn_quantity :"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_entityQuantityText = GUILayout.TextField(s_entityQuantityText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_entities_spawn_level :"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_entityLevelIdx = RGUI.SelectionPopup(s_entityLevelIdx, s_entityLevels.ToArray());
			GUILayout.EndHorizontal();
			if (GUILayout.Button(VTLocalization.instance.Localize("$vt_entities_spawn_button"), Array.Empty<GUILayoutOption>()) && int.TryParse(s_entityQuantityText, out var result) && int.TryParse(s_entityLevels[s_entityLevelIdx], out var result2) && result <= 100 && s_entityPrefabIdx < s_entityPrefabsFiltered.Count && s_entityPrefabIdx >= 0)
			{
				SpawnEntities(s_entityPrefabsFiltered[s_entityPrefabIdx], result2, result);
			}
			GUILayout.EndVertical();
			GUILayout.BeginVertical(VTLocalization.instance.Localize("$vt_entities_drops_title"), GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			if (GUILayout.Button(ValheimTooler.UI.Utils.LabelWithShortcut("$vt_entities_drops_button", ConfigManager.s_removeAllDropShortcut.Value), Array.Empty<GUILayoutOption>()))
			{
				RemoveAllDrops();
			}
			GUILayout.EndVertical();
			GUILayout.BeginVertical(VTLocalization.instance.Localize("$vt_entities_item_giver_title"), GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			if (GUILayout.Button(EntryPoint.s_showItemGiver ? VTLocalization.instance.Localize("$vt_entities_item_giver_button_hide") : VTLocalization.instance.Localize("$vt_entities_item_giver_button_show"), Array.Empty<GUILayoutOption>()))
			{
				EntryPoint.s_showItemGiver = !EntryPoint.s_showItemGiver;
			}
			GUILayout.EndVertical();
		}

		private static void SearchItem(string search)
		{
			if (s_previousSearchTerms.Equals(search))
			{
				return;
			}
			if (search.Length == 0)
			{
				s_entityPrefabsFiltered = s_entityPrefabs;
			}
			else
			{
				string searchLower = search.ToLower();
				s_entityPrefabsFiltered = s_entityPrefabs.Where((string i) => i.ToLower().Contains(searchLower)).ToList();
			}
			s_previousSearchTerms = search;
		}

		private static void SpawnEntity(GameObject entityPrefab, int level)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)entityPrefab != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				Vector3 val = Random.insideUnitSphere * 0.5f;
				Character component = Object.Instantiate<GameObject>(entityPrefab, ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 2f + Vector3.up + val, Quaternion.identity).GetComponent<Character>();
				if ((Object)(object)component != (Object)null)
				{
					component.SetLevel(level);
				}
			}
		}

		private static void SpawnEntities(string entityPrefab, int level, int quantity)
		{
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				return;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab(entityPrefab);
			if (!((Object)(object)prefab == (Object)null))
			{
				for (int i = 0; i < quantity; i++)
				{
					SpawnEntity(prefab, level);
				}
			}
		}

		private static void RemoveAllDrops()
		{
			ItemDrop[] array = Object.FindObjectsOfType<ItemDrop>();
			foreach (ItemDrop val in array)
			{
				Fish component = ((Component)val).gameObject.GetComponent<Fish>();
				if (!Object.op_Implicit((Object)(object)component) || component.IsOutOfWater())
				{
					ZNetView component2 = ((Component)val).GetComponent<ZNetView>();
					if (Object.op_Implicit((Object)(object)component2) && component2.IsValid())
					{
						component2.Destroy();
					}
				}
			}
		}
	}
	public static class ItemGiver
	{
		private class InventoryItem
		{
			public GameObject itemPrefab;

			public ItemDrop itemDrop;

			public GUIContent guiContent;

			public int variant;

			public InventoryItem(GameObject itemPrefab, ItemDrop itemDrop, GUIContent guiContent, int variant)
			{
				this.itemPrefab = itemPrefab;
				this.itemDrop = itemDrop;
				this.guiContent = guiContent;
				this.variant = variant;
			}
		}

		private static Rect s_itemGiverRect;

		private static Vector2 s_itemGiverScrollPosition;

		private static readonly List<InventoryItem> s_items = new List<InventoryItem>();

		private static List<InventoryItem> s_itemsFiltered = new List<InventoryItem>();

		private static List<GUIContent> s_itemsGUIFiltered = new List<GUIContent>();

		private static int s_selectedItem = 0;

		private static string s_quantityItem = "1";

		private static string s_qualityItem = "1";

		private static string s_searchTerms = "";

		private static string s_previousSearchTerms = "";

		public static void Start()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_002d: 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_0126: Expected O, but got Unknown
			s_itemGiverRect = new Rect(ConfigManager.s_itemGiverWindowPosition.Value.x, ConfigManager.s_itemGiverWindowPosition.Value.y, 400f, 400f);
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return;
			}
			foreach (GameObject item2 in ObjectDB.instance.m_items)
			{
				ItemDrop component = item2.GetComponent<ItemDrop>();
				ItemData itemData = component.m_itemData;
				if (itemData != null && itemData.m_shared?.m_icons?.Length <= 0)
				{
					continue;
				}
				for (int i = 0; i < component.m_itemData.m_shared.m_icons.Length; i++)
				{
					try
					{
						GUIContent val = new GUIContent((Texture)(object)SpriteManager.TextureFromSprite(component.m_itemData.m_shared.m_icons[i]), Localization.instance.Localize(component.m_itemData.m_shared.m_name + ((i > 0) ? (" Variant " + i) : "")));
						InventoryItem item = new InventoryItem(item2, component, val, i);
						s_itemsGUIFiltered.Add(val);
						s_items.Add(item);
						s_itemsFiltered.Add(item);
					}
					catch
					{
						ZLog.Log((object)$"[ValheimTooler - ItemGiver] Failed to load item {component.m_itemData.m_shared.m_name} with variant {i}. This item will be ignored.");
					}
				}
			}
		}

		public static void Update()
		{
		}

		public static void DisplayGUI()
		{
			//IL_0005: 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_002f: Expected O, but got Unknown
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			s_itemGiverRect = GUILayout.Window(1002, s_itemGiverRect, new WindowFunction(ItemGiverWindow), VTLocalization.instance.Localize("$vt_item_giver_title"), Array.Empty<GUILayoutOption>());
			ConfigManager.s_itemGiverWindowPosition.Value = ((Rect)(ref s_itemGiverRect)).position;
		}

		public static void ItemGiverWindow(int windowID)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0035: 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_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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Expected O, but got Unknown
			//IL_0202: 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_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items.Count == 0)
			{
				return;
			}
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.normal.textColor = Color.white;
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			s_searchTerms = GUILayout.TextField(s_searchTerms, Array.Empty<GUILayoutOption>());
			SearchItem(s_searchTerms);
			s_itemGiverScrollPosition = GUILayout.BeginScrollView(s_itemGiverScrollPosition, GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(350f) });
			s_selectedItem = GUILayout.SelectionGrid(s_selectedItem, s_itemsGUIFiltered.ToArray(), 4, InterfaceMaker.CustomSkin.GetStyle("flatButton"), Array.Empty<GUILayoutOption>());
			GUILayout.EndScrollView();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_item_giver_quantity :"), val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_quantityItem = GUILayout.TextField(s_quantityItem, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_item_giver_quality :"), val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_qualityItem = GUILayout.TextField(s_qualityItem, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			if (GUILayout.Button(VTLocalization.instance.Localize("$vt_item_giver_button"), Array.Empty<GUILayoutOption>()) && int.TryParse(s_quantityItem, out var result) && int.TryParse(s_qualityItem, out var result2))
			{
				Player.m_localPlayer.VTAddItemToInventory(((Object)s_itemsFiltered[s_selectedItem].itemPrefab).name, result, result2, s_itemsFiltered[s_selectedItem].variant);
			}
			if (GUI.tooltip != "")
			{
				GUIContent val2 = new GUIContent(GUI.tooltip);
				Vector2 val3 = new GUIStyle(GUI.skin.textField).CalcSize(val2);
				Vector2 val4 = default(Vector2);
				if (Event.current.mousePosition.x + val3.x > ((Rect)(ref s_itemGiverRect)).width)
				{
					val4.x = Event.current.mousePosition.x - (Event.current.mousePosition.x + val3.x - ((Rect)(ref s_itemGiverRect)).width);
				}
				else
				{
					val4.x = Event.current.mousePosition.x;
				}
				if (Event.current.mousePosition.y + 30f + val3.y > ((Rect)(ref s_itemGiverRect)).height)
				{
					val4.y = Event.current.mousePosition.y + 30f - (Event.current.mousePosition.y + 30f + val3.y - ((Rect)(ref s_itemGiverRect)).height);
				}
				else
				{
					val4.y = Event.current.mousePosition.y + 30f;
				}
				GUI.Box(new Rect(val4.x, val4.y, val3.x, val3.y), val2, GUI.skin.textField);
			}
			GUI.DragWindow();
		}

		private static void SearchItem(string search)
		{
			search = search.ToLower();
			if (s_previousSearchTerms.Equals(search))
			{
				return;
			}
			if (search.Length == 0)
			{
				s_itemsFiltered = s_items;
				s_itemsGUIFiltered = s_itemsFiltered.Select((InventoryItem i) => i.guiContent).ToList();
			}
			else
			{
				s_itemsFiltered = s_items.Where((InventoryItem i) => Localization.instance.Localize(i.itemDrop.m_itemData.m_shared.m_name + ((i.variant > 0) ? (" Variant " + i.variant) : "")).ToLower().Contains(search)).ToList();
				s_itemsGUIFiltered = s_itemsFiltered.Select((InventoryItem i) => i.guiContent).ToList();
			}
			s_previousSearchTerms = search;
		}
	}
	public static class MiscHacks
	{
		public static bool s_enableAutopinMap = false;

		private static int s_playerDamageIdx = 0;

		private static string s_damageToDeal = "1";

		private static string s_worldMessageText = "";

		private static string s_chatUsernameText = "";

		private static string s_chatMessageText = "";

		private static bool s_isShoutMessage = false;

		private static List<Player> s_players = null;

		private static float s_updateTimer = 0f;

		private static readonly float s_updateTimerInterval = 1.5f;

		public static void Start()
		{
		}

		public static void Update()
		{
			if (Time.time >= s_updateTimer)
			{
				s_players = Player.GetAllPlayers();
				s_updateTimer = Time.time + s_updateTimerInterval;
			}
			if (ConfigManager.s_espPlayersShortcut.Value.IsDown())
			{
				ActionToggleESPPlayers(sendNotification: true);
			}
			if (ConfigManager.s_espMonstersShortcut.Value.IsDown())
			{
				ActionToggleESPMonsters(sendNotification: true);
			}
			if (ConfigManager.s_espDroppedItemsShortcut.Value.IsDown())
			{
				ActionToggleESPDroppedItems(sendNotification: true);
			}
			if (ConfigManager.s_espDepositsShortcut.Value.IsDown())
			{
				ActionToggleESPDeposits(sendNotification: true);
			}
			if (ConfigManager.s_espPickablesShortcut.Value.IsDown())
			{
				ActionToggleESPPickables(sendNotification: true);
			}
		}

		public static void DisplayGUI()
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical(VTLocalization.instance.Localize("$vt_misc_damage_title"), GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_misc_damage_player :"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_playerDamageIdx = RGUI.SelectionPopup(s_playerDamageIdx, s_players?.Select((Player p) => p.GetPlayerName()).ToArray());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_misc_damage_value :"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_damageToDeal = GUILayout.TextField(s_damageToDeal, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			if (GUILayout.Button(VTLocalization.instance.Localize("$vt_misc_damage_button_player"), Array.Empty<GUILayoutOption>()) && int.TryParse(s_damageToDeal, out var result))
			{
				((Character)(object)s_players[s_playerDamageIdx]).VTDamage(result);
			}
			if (GUILayout.Button(VTLocalization.instance.Localize("$vt_misc_damage_button_entities"), Array.Empty<GUILayoutOption>()))
			{
				DamageAllCharacters();
			}
			if (GUILayout.Button(VTLocalization.instance.Localize("$vt_misc_damage_button_players"), Array.Empty<GUILayoutOption>()))
			{
				DamageAllOtherPlayers();
			}
			GUILayout.EndVertical();
			GUILayout.BeginVertical(VTLocalization.instance.Localize("$vt_misc_map_title"), GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			if (GUILayout.Button(ValheimTooler.UI.Utils.ToggleButtonLabel("$vt_misc_autopin", s_enableAutopinMap), Array.Empty<GUILayoutOption>()))
			{
				s_enableAutopinMap = !s_enableAutopinMap;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			ConfigManager.s_permanentPins.Value = GUILayout.Toggle(ConfigManager.s_permanentPins.Value, "", Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_misc_autopin_permanent"), Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			if (GUILayout.Button(VTLocalization.instance.Localize("$vt_misc_autopin_clear"), Array.Empty<GUILayoutOption>()) && (Object)(object)Minimap.instance != (Object)null)
			{
				foreach (PinData item in new List<PinData>(Minimap.instance.GetFieldValue<List<PinData>>("m_pins")))
				{
					if (Regex.IsMatch(item.m_name, "^.+\\[VT[0-9]{5}]$"))
					{
						Minimap.instance.RemovePin(item);
					}
				}
			}
			GUILayout.EndVertical();
			GUILayout.BeginVertical(VTLocalization.instance.Localize("$vt_misc_event_title"), GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_misc_event_message :"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_worldMessageText = GUILayout.TextField(s_worldMessageText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			if (GUILayout.Button(VTLocalization.instance.Localize("$vt_misc_event_button"), Array.Empty<GUILayoutOption>()))
			{
				MessageAllInRange((MessageType)2, s_worldMessageText);
			}
			GUILayout.EndVertical();
			GUILayout.EndVertical();
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical(VTLocalization.instance.Localize("$vt_misc_chat_title"), GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_misc_chat_username :"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_chatUsernameText = GUILayout.TextField(s_chatUsernameText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_misc_chat_message :"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			s_chatMessageText = GUILayout.TextField(s_chatMessageText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			s_isShoutMessage = GUILayout.Toggle(s_isShoutMessage, "", Array.Empty<GUILayoutOption>());
			GUILayout.Label(VTLocalization.instance.Localize("$vt_misc_chat_shout"), Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			if (GUILayout.Button(VTLocalization.instance.Localize("$vt_misc_chat_button"), Array.Empty<GUILayoutOption>()))
			{
				ChatMessage((Type)((!s_isShoutMessage) ? 1 : 2), s_chatUsernameText, s_chatMessageText);
			}
			GUILayout.EndVertical();
			GUILayout.BeginVertical(VTLocalization.instance.Localize("$vt_misc_esp_title"), GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Space((float)EntryPoint.s_boxSpacing);
			if (GUILayout.Button(ValheimTooler.UI.Utils.ToggleButtonLabel("$vt_misc_player_esp_button", ESP.s_showPlayerESP, ConfigManager.s_espPlayersShortcut.Value), Array.Empty<GUILayoutOption>()))
			{
				ActionToggleESPPlayers();
			}
			if (GUILayout.Button(ValheimTooler.UI.Utils.ToggleButtonLabel("$vt_misc_monster_esp_button", ESP.s_showMonsterESP, ConfigManager.s_espMonstersShortcut.Value), Array.Empty<GUILayoutOption>()))
			{
				ActionToggleESPMonsters();
			}
			if (GUILayout.Button(ValheimTooler.UI.Utils.ToggleButtonLabel("$vt_misc_dropped_esp_button", ESP.s_showDroppedESP, ConfigManager.s_espDroppedItemsShortcut.Value), Array.Empty<GUILayoutOption>()))
			{
				ActionToggleESPDroppedItems()

BepInEx/plugins/ValheimTooler/ValheimToolerMod.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using ValheimTooler;
using ValheimToolerMod.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ValheimToolerMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimToolerMod")]
[assembly: AssemblyCopyright("Copyright © Astropilot 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3d5f17bb-bb22-440e-848e-5f5f45a530f9")]
[assembly: AssemblyFileVersion("1.9.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.9.2.0")]
namespace ValheimToolerMod
{
	[BepInPlugin("com.github.Astropilot.ValheimTooler", "ValheimTooler", "1.9.2")]
	[BepInProcess("valheim.exe")]
	public class ValheimToolerMod : BaseUnityPlugin
	{
		private const string PluginGUID = "com.github.Astropilot.ValheimTooler";

		private const string PluginName = "ValheimTooler";

		private const string PluginVersion = "1.9.2";

		private Harmony _harmony;

		private void Awake()
		{
			FejdStartupPatch.OnGameInitialized += LoadPlugin;
			_harmony = Harmony.CreateAndPatchAll(typeof(FejdStartupPatch), "com.github.Astropilot.ValheimTooler");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			CallLoaderUnload();
		}

		private void LoadPlugin()
		{
			FejdStartupPatch.OnGameInitialized -= LoadPlugin;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			_harmony = null;
			string directoryName = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
			string path = Path.Combine(directoryName, "config_vt.path");
			File.WriteAllText(path, Paths.ConfigPath);
			CallLoaderInit();
		}

		private static Type GetLoaderType()
		{
			Type typeFromHandle = typeof(EntryPoint);
			Type type = typeFromHandle.Assembly.GetType("ValheimTooler.Loader");
			if ((object)type == null)
			{
				throw new Exception("Can't find Type ValheimTooler.Loader");
			}
			return type;
		}

		private void CallLoader(string methodName)
		{
			Type loaderType = GetLoaderType();
			MethodInfo method = loaderType.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public);
			if ((object)method == null)
			{
				throw new Exception("Can't find method " + methodName);
			}
			method.Invoke(null, new object[0]);
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Called ValheimTooler.Loader." + methodName));
		}

		private void CallLoaderInit()
		{
			CallLoader("Init");
		}

		private void CallLoaderUnload()
		{
			CallLoader("Unload");
		}
	}
}
namespace ValheimToolerMod.Patches
{
	internal class FejdStartupPatch
	{
		public static event Action OnGameInitialized;

		[HarmonyPatch(typeof(FejdStartup), "Start")]
		[HarmonyPostfix]
		private static void OnFejdStartup(FejdStartup __instance)
		{
			Delegate[] invocationList = FejdStartupPatch.OnGameInitialized.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action action = (Action)invocationList[i];
				action();
			}
		}
	}
}