Decompiled source of Expand World Prefabs v1.60.0

ExpandWorldPrefabs.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Data;
using ExpandWorld.Prefab;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Service;
using Splatform;
using UnityEngine;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

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

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Data
{
	public class Calculator
	{
		private sealed class DoubleParser(string expression)
		{
			private readonly string expression = expression;

			private int index;

			public double Parse()
			{
				double result = ParseExpression();
				SkipWhiteSpace();
				if (index != expression.Length)
				{
					throw new InvalidOperationException("Failed to parse expression: " + expression);
				}
				return result;
			}

			private double ParseExpression()
			{
				double num = ParseTerm();
				while (true)
				{
					SkipWhiteSpace();
					if (TryRead('+'))
					{
						num += ParseTerm();
						continue;
					}
					if (!TryRead('-'))
					{
						break;
					}
					num -= ParseTerm();
				}
				return num;
			}

			private double ParseTerm()
			{
				double num = ParseUnary();
				while (true)
				{
					SkipWhiteSpace();
					if (TryRead('*'))
					{
						num *= ParseUnary();
						continue;
					}
					if (!TryRead('/'))
					{
						break;
					}
					num /= ParseUnary();
				}
				return num;
			}

			private double ParseUnary()
			{
				SkipWhiteSpace();
				if (TryRead('+'))
				{
					return ParseUnary();
				}
				if (TryRead('-'))
				{
					return 0.0 - ParseUnary();
				}
				return ParsePower();
			}

			private double ParsePower()
			{
				double num = ParsePrimary();
				SkipWhiteSpace();
				if (TryRead('^'))
				{
					num = Math.Pow(num, ParseUnary());
				}
				return num;
			}

			private double ParsePrimary()
			{
				SkipWhiteSpace();
				if (TryRead('('))
				{
					double result = ParseExpression();
					SkipWhiteSpace();
					if (!TryRead(')'))
					{
						throw new InvalidOperationException("Failed to parse expression: " + expression);
					}
					return result;
				}
				return ParseNumber();
			}

			private double ParseNumber()
			{
				SkipWhiteSpace();
				int num = index;
				bool flag = false;
				while (index < expression.Length && char.IsDigit(expression[index]))
				{
					flag = true;
					index++;
				}
				if (index < expression.Length && expression[index] == '.')
				{
					index++;
					while (index < expression.Length && char.IsDigit(expression[index]))
					{
						flag = true;
						index++;
					}
				}
				if (index < expression.Length && (expression[index] == 'e' || expression[index] == 'E'))
				{
					int num2 = index;
					index++;
					if (index < expression.Length && (expression[index] == '+' || expression[index] == '-'))
					{
						index++;
					}
					int num3 = index;
					while (index < expression.Length && char.IsDigit(expression[index]))
					{
						index++;
					}
					if (num3 == index)
					{
						index = num2;
					}
				}
				if (!flag)
				{
					throw new InvalidOperationException("Failed to parse expression: " + expression);
				}
				return double.Parse(expression.Substring(num, index - num), NumberFormatInfo.InvariantInfo);
			}

			private bool TryRead(char c)
			{
				if (index >= expression.Length || expression[index] != c)
				{
					return false;
				}
				index++;
				return true;
			}

			private void SkipWhiteSpace()
			{
				while (index < expression.Length && char.IsWhiteSpace(expression[index]))
				{
					index++;
				}
			}
		}

		private sealed class LongParser(string expression)
		{
			private readonly string expression = expression;

			private int index;

			public long Parse()
			{
				long result = ParseExpression();
				SkipWhiteSpace();
				if (index != expression.Length)
				{
					throw new InvalidOperationException("Failed to parse expression: " + expression);
				}
				return result;
			}

			private long ParseExpression()
			{
				long num = ParseTerm();
				while (true)
				{
					SkipWhiteSpace();
					if (TryRead('+'))
					{
						num += ParseTerm();
						continue;
					}
					if (!TryRead('-'))
					{
						break;
					}
					num -= ParseTerm();
				}
				return num;
			}

			private long ParseTerm()
			{
				long num = ParseUnary();
				while (true)
				{
					SkipWhiteSpace();
					if (TryRead('*'))
					{
						num *= ParseUnary();
						continue;
					}
					if (!TryRead('/'))
					{
						break;
					}
					num /= ParseUnary();
				}
				return num;
			}

			private long ParseUnary()
			{
				SkipWhiteSpace();
				if (TryRead('+'))
				{
					return ParseUnary();
				}
				if (TryRead('-'))
				{
					return -ParseUnary();
				}
				return ParsePower();
			}

			private long ParsePower()
			{
				long num = ParsePrimary();
				SkipWhiteSpace();
				if (TryRead('^'))
				{
					long num2 = ParseUnary();
					if (num2 < 0)
					{
						throw new InvalidOperationException("Failed to parse expression: " + expression);
					}
					num = Pow(num, num2);
				}
				return num;
			}

			private long ParsePrimary()
			{
				SkipWhiteSpace();
				if (TryRead('('))
				{
					long result = ParseExpression();
					SkipWhiteSpace();
					if (!TryRead(')'))
					{
						throw new InvalidOperationException("Failed to parse expression: " + expression);
					}
					return result;
				}
				return ParseNumber();
			}

			private long ParseNumber()
			{
				SkipWhiteSpace();
				int num = index;
				while (index < expression.Length && char.IsDigit(expression[index]))
				{
					index++;
				}
				if (num == index)
				{
					throw new InvalidOperationException("Failed to parse expression: " + expression);
				}
				return long.Parse(expression.Substring(num, index - num), NumberFormatInfo.InvariantInfo);
			}

			private static long Pow(long value, long exponent)
			{
				long num = 1L;
				checked
				{
					while (exponent > 0)
					{
						if ((exponent & 1) == 1)
						{
							num *= value;
						}
						exponent >>= 1;
						if (exponent > 0)
						{
							value *= value;
						}
					}
					return num;
				}
			}

			private bool TryRead(char c)
			{
				if (index >= expression.Length || expression[index] != c)
				{
					return false;
				}
				index++;
				return true;
			}

			private void SkipWhiteSpace()
			{
				while (index < expression.Length && char.IsWhiteSpace(expression[index]))
				{
					index++;
				}
			}
		}

		public static Vector3 EvaluateVector3(string expression)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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)
			string[] array = Parse.Split(expression);
			if (Parse.TryDistanceAngle(array, out var vector))
			{
				return vector;
			}
			Vector3 zero = Vector3.zero;
			zero.x = EvaluateFloat(array[0]).GetValueOrDefault();
			if (array.Length > 1)
			{
				zero.z = EvaluateFloat(array[1]).GetValueOrDefault();
			}
			if (array.Length > 2)
			{
				zero.y = EvaluateFloat(array[2]).GetValueOrDefault();
			}
			return zero;
		}

		public static Quaternion EvaluateQuaternion(string expression)
		{
			//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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			Vector3 zero = Vector3.zero;
			string[] array = Parse.Split(expression);
			zero.y = EvaluateFloat(array[0]).GetValueOrDefault();
			if (array.Length > 1)
			{
				zero.x = EvaluateFloat(array[1]).GetValueOrDefault();
			}
			if (array.Length > 2)
			{
				zero.z = EvaluateFloat(array[2]).GetValueOrDefault();
			}
			return Quaternion.Euler(zero);
		}

		public static int? EvaluateInt(string expression)
		{
			try
			{
				return (int?)EvaluateLong(expression);
			}
			catch
			{
				return null;
			}
		}

		public static float? EvaluateFloat(string expression)
		{
			try
			{
				return (float)EvaluateDouble(expression);
			}
			catch
			{
				return null;
			}
		}

		private static double EvaluateDouble(string expression)
		{
			return new DoubleParser(expression.Replace("**", "^")).Parse();
		}

		public static long? EvaluateLong(string expression)
		{
			try
			{
				return EvalLong(expression);
			}
			catch
			{
				return null;
			}
		}

		private static long EvalLong(string expression)
		{
			return new LongParser(expression.Replace("**", "^")).Parse();
		}
	}
	public sealed class ConditionClause
	{
		private readonly Func<Func<string, string>, bool> evaluator;

		public readonly string Source;

		internal ConditionClause(string source, Func<Func<string, string>, bool> evaluator)
		{
			Source = source;
			this.evaluator = evaluator;
		}

		public bool Evaluate(Functions f)
		{
			return Evaluate((string r) => f.Replace(r, preventInjections: false, allValues: true));
		}

		public bool Evaluate(Func<string, string> resolveValue)
		{
			try
			{
				return evaluator(resolveValue);
			}
			catch
			{
				return false;
			}
		}
	}
	public static class Conditions
	{
		private enum TokenType
		{
			Value,
			And,
			Or,
			Not,
			Xor,
			In,
			NotIn,
			Equal,
			NotEqual,
			Greater,
			Less,
			GreaterOrEqual,
			LessOrEqual,
			LeftParen,
			RightParen,
			End
		}

		private readonly struct Token
		{
			public readonly TokenType Type;

			public readonly string Text;

			public readonly int Position;

			public Token(TokenType type, string text, int position)
			{
				Type = type;
				Text = text;
				Position = position;
			}
		}

		private static class Tokenizer
		{
			public static bool TryTokenize(string condition, out List<Token> tokens, out string error)
			{
				tokens = new List<Token>();
				error = "";
				int i = 0;
				while (i < condition.Length)
				{
					char c = condition[i];
					if (char.IsWhiteSpace(c))
					{
						i++;
						continue;
					}
					switch (c)
					{
					case '(':
						tokens.Add(new Token(TokenType.LeftParen, "(", i));
						i++;
						continue;
					case ')':
						tokens.Add(new Token(TokenType.RightParen, ")", i));
						i++;
						continue;
					case '<':
					{
						if (TryReadFunctionValue(condition, i, out string functionValue, out int nextIndex))
						{
							tokens.Add(new Token(TokenType.Value, functionValue, i));
							i = nextIndex;
						}
						else if (TryRead(condition, "<=", i))
						{
							tokens.Add(new Token(TokenType.LessOrEqual, "<=", i));
							i += 2;
						}
						else
						{
							tokens.Add(new Token(TokenType.Less, "<", i));
							i++;
						}
						continue;
					}
					case '>':
						if (TryRead(condition, ">=", i))
						{
							tokens.Add(new Token(TokenType.GreaterOrEqual, ">=", i));
							i += 2;
						}
						else
						{
							tokens.Add(new Token(TokenType.Greater, ">", i));
							i++;
						}
						continue;
					case '=':
						tokens.Add(new Token(TokenType.Equal, "=", i));
						i++;
						continue;
					case '!':
						if (TryRead(condition, "!=", i))
						{
							tokens.Add(new Token(TokenType.NotEqual, "!=", i));
							i += 2;
						}
						else
						{
							tokens.Add(new Token(TokenType.Not, "!", i));
							i++;
						}
						continue;
					case '"':
					case '\'':
					{
						int nextIndex2 = i;
						if (!TryReadQuotedValue(condition, i, out string value, out nextIndex2))
						{
							error = $"Unterminated quoted string at position {i + 1}.";
							return false;
						}
						tokens.Add(new Token(TokenType.Value, value, i));
						i = nextIndex2;
						continue;
					}
					}
					int num = i;
					for (; i < condition.Length && !char.IsWhiteSpace(condition[i]) && !IsDelimiter(condition, i); i++)
					{
					}
					string text = condition.Substring(num, i - num);
					if (text.Length == 0)
					{
						error = $"Unexpected token at position {num + 1}.";
						return false;
					}
					TokenType? tokenType = ToKeyword(text);
					tokens.Add(new Token(tokenType.GetValueOrDefault(), text, num));
				}
				tokens.Add(new Token(TokenType.End, "", condition.Length));
				return true;
			}

			private static bool TryReadFunctionValue(string condition, int index, out string functionValue, out int nextIndex)
			{
				functionValue = "";
				nextIndex = index;
				if (index + 1 >= condition.Length)
				{
					return false;
				}
				char c = condition[index + 1];
				if (char.IsWhiteSpace(c) || c == '>' || c == '=')
				{
					return false;
				}
				int num = 0;
				for (int i = index; i < condition.Length; i++)
				{
					switch (condition[i])
					{
					case '<':
						num++;
						break;
					case '>':
						num--;
						if (num == 0)
						{
							functionValue = condition.Substring(index, i - index + 1);
							nextIndex = i + 1;
							return true;
						}
						break;
					}
				}
				return false;
			}

			private static bool TryReadQuotedValue(string condition, int index, out string value, out int nextIndex)
			{
				value = "";
				nextIndex = index;
				char c = condition[index];
				List<char> list = new List<char>();
				bool flag = false;
				for (int i = index + 1; i < condition.Length; i++)
				{
					char c2 = condition[i];
					if (flag)
					{
						list.Add(c2);
						flag = false;
						continue;
					}
					if (c2 == '\\')
					{
						flag = true;
						continue;
					}
					if (c2 == c)
					{
						value = new string(list.ToArray());
						nextIndex = i + 1;
						return true;
					}
					list.Add(c2);
				}
				return false;
			}

			private static bool IsDelimiter(string condition, int index)
			{
				char c = condition[index];
				if (c != '(' && c != ')' && c != '<' && c != '>' && c != '=')
				{
					return c == '!';
				}
				return true;
			}

			private static TokenType? ToKeyword(string value)
			{
				return value.ToUpperInvariant() switch
				{
					"AND" => TokenType.And, 
					"OR" => TokenType.Or, 
					"NOT" => TokenType.Not, 
					"XOR" => TokenType.Xor, 
					"IN" => TokenType.In, 
					_ => null, 
				};
			}

			private static bool TryRead(string condition, string match, int index)
			{
				if (index + match.Length > condition.Length)
				{
					return false;
				}
				return string.CompareOrdinal(condition, index, match, 0, match.Length) == 0;
			}
		}

		private sealed class Parser(List<Token> tokens)
		{
			private readonly List<Token> tokens = tokens;

			private int index;

			private Token Current => tokens[index];

			private Token Next
			{
				get
				{
					if (index + 1 >= tokens.Count)
					{
						return tokens[tokens.Count - 1];
					}
					return tokens[index + 1];
				}
			}

			public ConditionNode ParseCondition()
			{
				ConditionNode result = ParseOr();
				if (Current.Type != TokenType.End)
				{
					throw new InvalidOperationException($"Unexpected token '{Current.Text}' at position {Current.Position + 1}.");
				}
				return result;
			}

			private ConditionNode ParseOr()
			{
				ConditionNode conditionNode = ParseXor();
				while (Current.Type == TokenType.Or)
				{
					index++;
					conditionNode = new LogicalNode(LogicalType.Or, conditionNode, ParseXor());
				}
				return conditionNode;
			}

			private ConditionNode ParseXor()
			{
				ConditionNode conditionNode = ParseAnd();
				while (Current.Type == TokenType.Xor)
				{
					index++;
					conditionNode = new LogicalNode(LogicalType.Xor, conditionNode, ParseAnd());
				}
				return conditionNode;
			}

			private ConditionNode ParseAnd()
			{
				ConditionNode conditionNode = ParseUnary();
				while (Current.Type == TokenType.And)
				{
					index++;
					conditionNode = new LogicalNode(LogicalType.And, conditionNode, ParseUnary());
				}
				return conditionNode;
			}

			private ConditionNode ParseUnary()
			{
				if (Current.Type != TokenType.Not)
				{
					return ParsePrimary();
				}
				index++;
				return new NotNode(ParseUnary());
			}

			private ConditionNode ParsePrimary()
			{
				if (Current.Type == TokenType.LeftParen)
				{
					index++;
					ConditionNode result = ParseOr();
					if (Current.Type != TokenType.RightParen)
					{
						throw new InvalidOperationException($"Missing closing parenthesis at position {Current.Position + 1}.");
					}
					index++;
					return result;
				}
				return ParseComparisonOrValue();
			}

			private ConditionNode ParseComparisonOrValue()
			{
				string text = ParseValue();
				if (!IsComparisonToken(Current.Type) && (Current.Type != TokenType.Not || Next.Type != TokenType.In))
				{
					return new ValueNode(text);
				}
				TokenType operatorType;
				if (Current.Type == TokenType.Not)
				{
					operatorType = TokenType.NotIn;
					index += 2;
				}
				else
				{
					operatorType = Current.Type;
					index++;
				}
				string rightToken = ParseValue();
				return new ComparisonNode(operatorType, text, rightToken);
			}

			private string ParseValue()
			{
				if (Current.Type != TokenType.Value)
				{
					throw new InvalidOperationException($"Expected value at position {Current.Position + 1}.");
				}
				string text = Current.Text;
				index++;
				return text;
			}

			private static bool IsComparisonToken(TokenType token)
			{
				switch (token)
				{
				case TokenType.In:
					return true;
				default:
					return token == TokenType.LessOrEqual;
				case TokenType.Equal:
				case TokenType.NotEqual:
				case TokenType.Greater:
				case TokenType.Less:
				case TokenType.GreaterOrEqual:
					return true;
				}
			}
		}

		private enum LogicalType
		{
			And,
			Or,
			Xor
		}

		private abstract class ConditionNode
		{
			public abstract bool Evaluate(Func<string, string> resolve);
		}

		private sealed class ValueNode(string token) : ConditionNode()
		{
			private readonly string token = token;

			public override bool Evaluate(Func<string, string> resolve)
			{
				return ToTruthy(ResolveToken(token, resolve));
			}
		}

		private sealed class NotNode(ConditionNode node) : ConditionNode()
		{
			private readonly ConditionNode node = node;

			public override bool Evaluate(Func<string, string> resolve)
			{
				return !node.Evaluate(resolve);
			}
		}

		private sealed class LogicalNode(LogicalType type, ConditionNode left, ConditionNode right) : ConditionNode()
		{
			private readonly LogicalType type = type;

			private readonly ConditionNode left = left;

			private readonly ConditionNode right = right;

			public override bool Evaluate(Func<string, string> resolve)
			{
				bool flag = left.Evaluate(resolve);
				if (type == LogicalType.And)
				{
					if (flag)
					{
						return right.Evaluate(resolve);
					}
					return false;
				}
				if (type == LogicalType.Or)
				{
					if (!flag)
					{
						return right.Evaluate(resolve);
					}
					return true;
				}
				return flag ^ right.Evaluate(resolve);
			}
		}

		private sealed class ComparisonNode(TokenType operatorType, string leftToken, string rightToken) : ConditionNode()
		{
			private readonly TokenType operatorType = operatorType;

			private readonly string leftToken = leftToken;

			private readonly string rightToken = rightToken;

			public override bool Evaluate(Func<string, string> resolve)
			{
				string left = ResolveToken(leftToken, resolve);
				string right = ResolveToken(rightToken, resolve);
				return Compare(operatorType, left, right);
			}
		}

		private const double NumericTolerance = 1E-07;

		public static ConditionClause False(string source = "")
		{
			return new ConditionClause(source, (Func<string, string> _) => false);
		}

		public static bool TryParse(string condition, out ConditionClause? clause, out string error)
		{
			clause = null;
			error = "";
			if (string.IsNullOrWhiteSpace(condition))
			{
				error = "Condition is empty.";
				return false;
			}
			if (!Tokenizer.TryTokenize(condition, out List<Token> tokens, out error))
			{
				return false;
			}
			try
			{
				Parser parser = new Parser(tokens);
				ConditionNode root = parser.ParseCondition();
				clause = new ConditionClause(condition, (Func<string, string> resolver) => root.Evaluate(resolver));
				return true;
			}
			catch (Exception ex)
			{
				error = ex.Message;
				return false;
			}
		}

		private static string ResolveToken(string token, Func<string, string> resolve)
		{
			return resolve(token) ?? "";
		}

		private static bool ToTruthy(string value)
		{
			string text = value.Trim();
			if (text == "")
			{
				return false;
			}
			if (string.Equals(text, "false", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			if (!double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				return true;
			}
			return Math.Abs(result) > 1E-07;
		}

		private static bool Compare(TokenType operatorType, string left, string right)
		{
			string text = left.Trim();
			string text2 = right.Trim();
			if (operatorType == TokenType.In || operatorType == TokenType.NotIn)
			{
				bool flag = ContainsValue(text2, text);
				if (operatorType != TokenType.In)
				{
					return !flag;
				}
				return flag;
			}
			double result;
			bool flag2 = double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out result);
			double result2;
			bool flag3 = double.TryParse(text2, NumberStyles.Float, CultureInfo.InvariantCulture, out result2);
			if (operatorType == TokenType.Equal || operatorType == TokenType.NotEqual)
			{
				bool flag4 = ((flag2 && flag3) ? (Math.Abs(result - result2) <= 1E-07) : string.Equals(text, text2, StringComparison.OrdinalIgnoreCase));
				if (operatorType != TokenType.Equal)
				{
					return !flag4;
				}
				return flag4;
			}
			if (!flag2 || !flag3)
			{
				return false;
			}
			return operatorType switch
			{
				TokenType.Greater => result > result2, 
				TokenType.Less => result < result2, 
				TokenType.GreaterOrEqual => result > result2 || Math.Abs(result - result2) <= 1E-07, 
				TokenType.LessOrEqual => result < result2 || Math.Abs(result - result2) <= 1E-07, 
				_ => false, 
			};
		}

		private static bool ContainsValue(string commaSeparatedValues, string value)
		{
			if (value == "")
			{
				return false;
			}
			return commaSeparatedValues.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0;
		}
	}
	public class DataData
	{
		[DefaultValue(null)]
		public string? name;

		[DefaultValue(null)]
		public string? position;

		[DefaultValue(null)]
		public string? rotation;

		[DefaultValue(null)]
		public string? connection;

		[DefaultValue(null)]
		public string[]? bools;

		[DefaultValue(null)]
		public string[]? ints;

		[DefaultValue(null)]
		public string[]? hashes;

		[DefaultValue(null)]
		public string[]? floats;

		[DefaultValue(null)]
		public string[]? strings;

		[DefaultValue(null)]
		public string[]? longs;

		[DefaultValue(null)]
		public string[]? vecs;

		[DefaultValue(null)]
		public string[]? quats;

		[DefaultValue(null)]
		public string[]? bytes;

		[DefaultValue(null)]
		public ItemData[]? items;

		[DefaultValue(null)]
		public string? containerSize;

		[DefaultValue(null)]
		public string? itemAmount;

		[DefaultValue(null)]
		public string? valueGroup;

		[DefaultValue(null)]
		public string? value;

		[DefaultValue(null)]
		public string[]? values;

		[DefaultValue(null)]
		public string? persistent;

		[DefaultValue(null)]
		public string? distant;

		[DefaultValue(null)]
		public string? priority;
	}
	public class ItemData
	{
		public string pos = "";

		[DefaultValue(1f)]
		public float chance = 1f;

		[DefaultValue("")]
		public string prefab = "";

		public string? stack;

		public string? quality;

		public string? variant;

		public string? durability;

		public string? crafterID;

		public string? crafterName;

		public string? worldLevel;

		public string? equipped;

		public string? pickedUp;

		public Dictionary<string, string>? customData;
	}
	public class DataEntry
	{
		private static readonly int HasFieldsHash = ZdoHelper.Hash("HasFields");

		public bool CanBeInjected = true;

		public Dictionary<int, IStringValue>? Strings;

		public Dictionary<int, IFloatValue>? Floats;

		public Dictionary<int, IIntValue>? Ints;

		public Dictionary<int, IIntValue>? Components;

		public Dictionary<int, IBoolValue>? Bools;

		public Dictionary<int, IHashValue>? Hashes;

		public Dictionary<int, ILongValue>? Longs;

		public Dictionary<int, IVector3Value>? Vecs;

		public Dictionary<int, IQuaternionValue>? Quats;

		public Dictionary<int, IBytesValue>? ByteArrays;

		public List<ItemValue>? Items;

		public Vector2i? ContainerSize;

		public IIntValue? ItemAmount;

		public ConnectionType? ConnectionType;

		public int ConnectionHash;

		public IZdoIdValue? OriginalId;

		public IZdoIdValue? TargetConnectionId;

		public IBoolValue? Persistent;

		public IBoolValue? Distant;

		public ObjectType? Priority;

		public IVector3Value? Position;

		public IQuaternionValue? Rotation;

		public static HashSet<string> SupportedTypes = new HashSet<string> { "float", "int", "bool", "hash", "long", "string", "vec", "vec3", "quat", "bytes" };

		public DataEntry()
		{
		}

		public DataEntry(string[] tkv)
		{
			Load(tkv);
		}

		public DataEntry(DataData data)
		{
			Load(data);
		}

		public DataEntry(ZDO zdo)
		{
			Load(zdo);
		}

		public DataEntry(ZPackage pkg)
		{
			Load(pkg);
		}

		public void Load(ZDO zdo)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: 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_059d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			ZDOID uid = zdo.m_uid;
			Floats = (ZDOExtraData.s_floats.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, float>>)ZDOExtraData.s_floats[uid]).ToDictionary((KeyValuePair<int, float> kvp) => kvp.Key, (KeyValuePair<int, float> kvp) => DataValue.Simple(kvp.Value)) : null);
			Ints = (ZDOExtraData.s_ints.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, int>>)ZDOExtraData.s_ints[uid]).ToDictionary((KeyValuePair<int, int> kvp) => kvp.Key, (KeyValuePair<int, int> kvp) => DataValue.Simple(kvp.Value)) : null);
			Longs = (ZDOExtraData.s_longs.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, long>>)ZDOExtraData.s_longs[uid]).ToDictionary((KeyValuePair<int, long> kvp) => kvp.Key, (KeyValuePair<int, long> kvp) => DataValue.Simple(kvp.Value)) : null);
			Strings = (ZDOExtraData.s_strings.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, string>>)ZDOExtraData.s_strings[uid]).ToDictionary((KeyValuePair<int, string> kvp) => kvp.Key, (KeyValuePair<int, string> kvp) => DataValue.Simple(kvp.Value)) : null);
			Vecs = (ZDOExtraData.s_vec3.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, Vector3>>)ZDOExtraData.s_vec3[uid]).ToDictionary((KeyValuePair<int, Vector3> kvp) => kvp.Key, (KeyValuePair<int, Vector3> kvp) => DataValue.Simple(kvp.Value)) : null);
			Quats = (ZDOExtraData.s_quats.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, Quaternion>>)ZDOExtraData.s_quats[uid]).ToDictionary((KeyValuePair<int, Quaternion> kvp) => kvp.Key, (KeyValuePair<int, Quaternion> kvp) => DataValue.Simple(kvp.Value)) : null);
			ByteArrays = (ZDOExtraData.s_byteArrays.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, byte[]>>)ZDOExtraData.s_byteArrays[uid]).ToDictionary((KeyValuePair<int, byte[]> kvp) => kvp.Key, (KeyValuePair<int, byte[]> kvp) => DataValue.Simple(kvp.Value)) : null);
			if (ServerSideData.TryGetFloats(uid, out Dictionary<int, float> values))
			{
				if (Floats == null)
				{
					Floats = new Dictionary<int, IFloatValue>();
				}
				foreach (KeyValuePair<int, float> item in values)
				{
					Floats[item.Key] = DataValue.Simple(item.Value);
				}
			}
			if (ServerSideData.TryGetInts(uid, out Dictionary<int, int> values2))
			{
				if (Ints == null)
				{
					Ints = new Dictionary<int, IIntValue>();
				}
				foreach (KeyValuePair<int, int> item2 in values2)
				{
					Ints[item2.Key] = DataValue.Simple(item2.Value);
				}
			}
			if (ServerSideData.TryGetLongs(uid, out Dictionary<int, long> values3))
			{
				if (Longs == null)
				{
					Longs = new Dictionary<int, ILongValue>();
				}
				foreach (KeyValuePair<int, long> item3 in values3)
				{
					Longs[item3.Key] = DataValue.Simple(item3.Value);
				}
			}
			if (ServerSideData.TryGetStrings(uid, out Dictionary<int, string> values4))
			{
				if (Strings == null)
				{
					Strings = new Dictionary<int, IStringValue>();
				}
				foreach (KeyValuePair<int, string> item4 in values4)
				{
					Strings[item4.Key] = DataValue.Simple(item4.Value);
				}
			}
			if (ServerSideData.TryGetVecs(uid, out Dictionary<int, Vector3> values5))
			{
				if (Vecs == null)
				{
					Vecs = new Dictionary<int, IVector3Value>();
				}
				foreach (KeyValuePair<int, Vector3> item5 in values5)
				{
					Vecs[item5.Key] = DataValue.Simple(item5.Value);
				}
			}
			if (ServerSideData.TryGetQuaternions(uid, out Dictionary<int, Quaternion> values6))
			{
				if (Quats == null)
				{
					Quats = new Dictionary<int, IQuaternionValue>();
				}
				foreach (KeyValuePair<int, Quaternion> item6 in values6)
				{
					Quats[item6.Key] = DataValue.Simple(item6.Value);
				}
			}
			if (ServerSideData.TryGetBytes(uid, out Dictionary<int, byte[]> values7))
			{
				if (ByteArrays == null)
				{
					ByteArrays = new Dictionary<int, IBytesValue>();
				}
				foreach (KeyValuePair<int, byte[]> item7 in values7)
				{
					ByteArrays[item7.Key] = DataValue.Simple(item7.Value);
				}
			}
			if (ZDOExtraData.s_connectionsHashData.TryGetValue(uid, out var value))
			{
				ConnectionType = value.m_type;
				ConnectionHash = value.m_hash;
			}
			OriginalId = new SimpleZdoIdValue(uid);
			if (ZDOExtraData.s_connections.TryGetValue(uid, out var value2) && value2.m_target != ZDOID.None)
			{
				TargetConnectionId = new SimpleZdoIdValue(value2.m_target);
				ConnectionType = value2.m_type;
			}
			Persistent = null;
			Distant = null;
			Priority = null;
			CanBeInjected = CheckCanBeInjected();
		}

		public void Load(DataEntry data)
		{
			if (data.Floats != null)
			{
				if (Floats == null)
				{
					Floats = new Dictionary<int, IFloatValue>();
				}
				foreach (KeyValuePair<int, IFloatValue> @float in data.Floats)
				{
					Floats[@float.Key] = @float.Value;
				}
			}
			if (data.Vecs != null)
			{
				if (Vecs == null)
				{
					Vecs = new Dictionary<int, IVector3Value>();
				}
				foreach (KeyValuePair<int, IVector3Value> vec in data.Vecs)
				{
					Vecs[vec.Key] = vec.Value;
				}
			}
			if (data.Quats != null)
			{
				if (Quats == null)
				{
					Quats = new Dictionary<int, IQuaternionValue>();
				}
				foreach (KeyValuePair<int, IQuaternionValue> quat in data.Quats)
				{
					Quats[quat.Key] = quat.Value;
				}
			}
			if (data.Ints != null)
			{
				if (Ints == null)
				{
					Ints = new Dictionary<int, IIntValue>();
				}
				foreach (KeyValuePair<int, IIntValue> @int in data.Ints)
				{
					Ints[@int.Key] = @int.Value;
				}
			}
			if (data.Strings != null)
			{
				if (Strings == null)
				{
					Strings = new Dictionary<int, IStringValue>();
				}
				foreach (KeyValuePair<int, IStringValue> @string in data.Strings)
				{
					Strings[@string.Key] = @string.Value;
				}
			}
			if (data.ByteArrays != null)
			{
				if (ByteArrays == null)
				{
					ByteArrays = new Dictionary<int, IBytesValue>();
				}
				foreach (KeyValuePair<int, IBytesValue> byteArray in data.ByteArrays)
				{
					ByteArrays[byteArray.Key] = byteArray.Value;
				}
			}
			if (data.Longs != null)
			{
				if (Longs == null)
				{
					Longs = new Dictionary<int, ILongValue>();
				}
				foreach (KeyValuePair<int, ILongValue> @long in data.Longs)
				{
					Longs[@long.Key] = @long.Value;
				}
			}
			if (data.Bools != null)
			{
				if (Bools == null)
				{
					Bools = new Dictionary<int, IBoolValue>();
				}
				foreach (KeyValuePair<int, IBoolValue> @bool in data.Bools)
				{
					Bools[@bool.Key] = @bool.Value;
				}
			}
			if (data.Hashes != null)
			{
				if (Hashes == null)
				{
					Hashes = new Dictionary<int, IHashValue>();
				}
				foreach (KeyValuePair<int, IHashValue> hash in data.Hashes)
				{
					Hashes[hash.Key] = hash.Value;
				}
			}
			if (data.Components != null)
			{
				if (Components == null)
				{
					Components = new Dictionary<int, IIntValue>();
				}
				foreach (KeyValuePair<int, IIntValue> component in data.Components)
				{
					Components[component.Key] = component.Value;
				}
			}
			if (data.Items != null)
			{
				if (Items == null)
				{
					Items = new List<ItemValue>();
				}
				foreach (ItemValue item in data.Items)
				{
					Items.Add(item);
				}
			}
			if (data.ContainerSize.HasValue)
			{
				ContainerSize = data.ContainerSize;
			}
			if (data.ItemAmount != null)
			{
				ItemAmount = data.ItemAmount;
			}
			ConnectionType = data.ConnectionType;
			ConnectionHash = data.ConnectionHash;
			OriginalId = data.OriginalId;
			TargetConnectionId = data.TargetConnectionId;
			if (data.Persistent != null)
			{
				Persistent = data.Persistent;
			}
			if (data.Distant != null)
			{
				Distant = data.Distant;
			}
			if (data.Priority.HasValue)
			{
				Priority = data.Priority;
			}
			if (data.Position != null)
			{
				Position = data.Position;
			}
			if (data.Rotation != null)
			{
				Rotation = data.Rotation;
			}
			CanBeInjected = data.CanBeInjected;
		}

		public DataEntry Reset(DataData data)
		{
			CanBeInjected = true;
			Floats = null;
			Vecs = null;
			Quats = null;
			Ints = null;
			Strings = null;
			ByteArrays = null;
			Longs = null;
			Bools = null;
			Hashes = null;
			Items = null;
			Components = null;
			ContainerSize = null;
			ItemAmount = null;
			ConnectionType = null;
			ConnectionHash = 0;
			OriginalId = null;
			TargetConnectionId = null;
			Position = null;
			Rotation = null;
			Distant = null;
			Persistent = null;
			Priority = null;
			Load(data);
			return this;
		}

		public void Load(DataData data)
		{
			//IL_0aaa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bfe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c75: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c43: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> hashSet = new HashSet<string>();
			if (data.floats != null)
			{
				if (Floats == null)
				{
					Floats = new Dictionary<int, IFloatValue>();
				}
				string[] floats = data.floats;
				foreach (string text in floats)
				{
					KeyValuePair<string, string> keyValuePair = Parse.Kvp(text);
					if (keyValuePair.Key == "")
					{
						throw new InvalidOperationException("Failed to parse float " + text + ".");
					}
					if (keyValuePair.Key.Contains("."))
					{
						hashSet.Add(keyValuePair.Key.Split(new char[1] { '.' })[0]);
					}
					int key = ZdoHelper.Hash(keyValuePair.Key);
					if (Floats.ContainsKey(key))
					{
						Log.Warning("Data " + data.name + ": Duplicate float key " + keyValuePair.Key + ".");
					}
					Floats[key] = DataValue.Float(keyValuePair.Value);
				}
			}
			if (data.ints != null)
			{
				if (Ints == null)
				{
					Ints = new Dictionary<int, IIntValue>();
				}
				string[] floats = data.ints;
				foreach (string text2 in floats)
				{
					KeyValuePair<string, string> keyValuePair2 = Parse.Kvp(text2);
					if (keyValuePair2.Key == "")
					{
						throw new InvalidOperationException("Failed to parse int " + text2 + ".");
					}
					if (keyValuePair2.Key.Contains("."))
					{
						hashSet.Add(keyValuePair2.Key.Split(new char[1] { '.' })[0]);
					}
					int key2 = ZdoHelper.Hash(keyValuePair2.Key);
					if (Ints.ContainsKey(key2))
					{
						Log.Warning("Data " + data.name + ": Duplicate int key " + keyValuePair2.Key + ".");
					}
					Ints[key2] = DataValue.Int(keyValuePair2.Value);
				}
			}
			if (data.bools != null)
			{
				if (Bools == null)
				{
					Bools = new Dictionary<int, IBoolValue>();
				}
				string[] floats = data.bools;
				foreach (string text3 in floats)
				{
					KeyValuePair<string, string> keyValuePair3 = Parse.Kvp(text3);
					if (keyValuePair3.Key == "")
					{
						throw new InvalidOperationException("Failed to parse bool " + text3 + ".");
					}
					if (keyValuePair3.Key.Contains("."))
					{
						hashSet.Add(keyValuePair3.Key.Split(new char[1] { '.' })[0]);
					}
					int key3 = ZdoHelper.Hash(keyValuePair3.Key);
					if (Bools.ContainsKey(key3))
					{
						Log.Warning("Data " + data.name + ": Duplicate bool key " + keyValuePair3.Key + ".");
					}
					Bools[key3] = DataValue.Bool(keyValuePair3.Value);
				}
			}
			if (data.hashes != null)
			{
				if (Hashes == null)
				{
					Hashes = new Dictionary<int, IHashValue>();
				}
				string[] floats = data.hashes;
				foreach (string text4 in floats)
				{
					KeyValuePair<string, string> keyValuePair4 = Parse.Kvp(text4);
					if (keyValuePair4.Key == "")
					{
						throw new InvalidOperationException("Failed to parse hash " + text4 + ".");
					}
					if (keyValuePair4.Key.Contains("."))
					{
						hashSet.Add(keyValuePair4.Key.Split(new char[1] { '.' })[0]);
					}
					int key4 = ZdoHelper.Hash(keyValuePair4.Key);
					if (Hashes.ContainsKey(key4))
					{
						Log.Warning("Data " + data.name + ": Duplicate hash key " + keyValuePair4.Key + ".");
					}
					Hashes[key4] = DataValue.Hash(keyValuePair4.Value);
				}
			}
			if (data.longs != null)
			{
				if (Longs == null)
				{
					Longs = new Dictionary<int, ILongValue>();
				}
				string[] floats = data.longs;
				foreach (string text5 in floats)
				{
					KeyValuePair<string, string> keyValuePair5 = Parse.Kvp(text5);
					if (keyValuePair5.Key == "")
					{
						throw new InvalidOperationException("Failed to parse long " + text5 + ".");
					}
					if (keyValuePair5.Key.Contains("."))
					{
						hashSet.Add(keyValuePair5.Key.Split(new char[1] { '.' })[0]);
					}
					int key5 = ZdoHelper.Hash(keyValuePair5.Key);
					if (Longs.ContainsKey(key5))
					{
						Log.Warning("Data " + data.name + ": Duplicate long key " + keyValuePair5.Key + ".");
					}
					Longs[key5] = DataValue.Long(keyValuePair5.Value);
				}
			}
			if (data.strings != null)
			{
				if (Strings == null)
				{
					Strings = new Dictionary<int, IStringValue>();
				}
				string[] floats = data.strings;
				foreach (string text6 in floats)
				{
					KeyValuePair<string, string> keyValuePair6 = Parse.Kvp(text6);
					if (keyValuePair6.Key == "")
					{
						throw new InvalidOperationException("Failed to parse string " + text6 + ".");
					}
					if (keyValuePair6.Key.Contains("."))
					{
						hashSet.Add(keyValuePair6.Key.Split(new char[1] { '.' })[0]);
					}
					int num = ZdoHelper.Hash(keyValuePair6.Key);
					if (num == ZDOVars.s_items)
					{
						if (ByteArrays == null)
						{
							ByteArrays = new Dictionary<int, IBytesValue>();
						}
						if (ByteArrays.ContainsKey(num))
						{
							Log.Warning("Data " + data.name + ": Duplicate string key " + keyValuePair6.Key + ".");
						}
						ByteArrays[num] = DataValue.Bytes(keyValuePair6.Value);
					}
					else
					{
						if (Strings.ContainsKey(num))
						{
							Log.Warning("Data " + data.name + ": Duplicate string key " + keyValuePair6.Key + ".");
						}
						Strings[num] = DataValue.String(keyValuePair6.Value);
					}
				}
			}
			if (data.vecs != null)
			{
				if (Vecs == null)
				{
					Vecs = new Dictionary<int, IVector3Value>();
				}
				string[] floats = data.vecs;
				foreach (string text7 in floats)
				{
					KeyValuePair<string, string> keyValuePair7 = Parse.Kvp(text7);
					if (keyValuePair7.Key == "")
					{
						throw new InvalidOperationException("Failed to parse vector " + text7 + ".");
					}
					if (keyValuePair7.Key.Contains("."))
					{
						hashSet.Add(keyValuePair7.Key.Split(new char[1] { '.' })[0]);
					}
					int key6 = ZdoHelper.Hash(keyValuePair7.Key);
					if (Vecs.ContainsKey(key6))
					{
						Log.Warning("Data " + data.name + ": Duplicate vector key " + keyValuePair7.Key + ".");
					}
					Vecs[key6] = DataValue.Vector3(keyValuePair7.Value);
				}
			}
			if (data.quats != null)
			{
				if (Quats == null)
				{
					Quats = new Dictionary<int, IQuaternionValue>();
				}
				string[] floats = data.quats;
				foreach (string text8 in floats)
				{
					KeyValuePair<string, string> keyValuePair8 = Parse.Kvp(text8);
					if (keyValuePair8.Key == "")
					{
						throw new InvalidOperationException("Failed to parse quaternion " + text8 + ".");
					}
					if (keyValuePair8.Key.Contains("."))
					{
						hashSet.Add(keyValuePair8.Key.Split(new char[1] { '.' })[0]);
					}
					int key7 = ZdoHelper.Hash(keyValuePair8.Key);
					if (Quats.ContainsKey(key7))
					{
						Log.Warning("Data " + data.name + ": Duplicate quaternion key " + keyValuePair8.Key + ".");
					}
					Quats[key7] = DataValue.Quaternion(keyValuePair8.Value);
				}
			}
			if (data.bytes != null)
			{
				if (ByteArrays == null)
				{
					ByteArrays = new Dictionary<int, IBytesValue>();
				}
				string[] floats = data.bytes;
				foreach (string text9 in floats)
				{
					KeyValuePair<string, string> keyValuePair9 = Parse.Kvp(text9);
					if (keyValuePair9.Key == "")
					{
						throw new InvalidOperationException("Failed to parse byte array " + text9 + ".");
					}
					if (keyValuePair9.Key.Contains("."))
					{
						hashSet.Add(keyValuePair9.Key.Split(new char[1] { '.' })[0]);
					}
					int key8 = ZdoHelper.Hash(keyValuePair9.Key);
					if (ByteArrays.ContainsKey(key8))
					{
						Log.Warning("Data " + data.name + ": Duplicate byte array key " + keyValuePair9.Key + ".");
					}
					ByteArrays[key8] = DataValue.Bytes(keyValuePair9.Value);
				}
			}
			if (data.items != null)
			{
				List<ItemValue> list = new List<ItemValue>();
				list.AddRange(data.items.Select((ItemData item) => new ItemValue(item)));
				Items = list;
			}
			if (!string.IsNullOrWhiteSpace(data.containerSize))
			{
				ContainerSize = Parse.Vector2Int(data.containerSize);
			}
			if (!string.IsNullOrWhiteSpace(data.itemAmount))
			{
				ItemAmount = DataValue.Int(data.itemAmount);
			}
			CanBeInjected = hashSet.Count == 0;
			if (hashSet.Count > 0)
			{
				if (Components == null)
				{
					Components = new Dictionary<int, IIntValue>();
				}
				Components[ZdoHelper.Hash("HasFields")] = DataValue.Simple(1);
				foreach (string item in hashSet)
				{
					Components[ZdoHelper.Hash("HasFields" + item)] = DataValue.Simple(1);
				}
			}
			if (!string.IsNullOrWhiteSpace(data.position))
			{
				Position = DataValue.Vector3(data.position);
			}
			if (!string.IsNullOrWhiteSpace(data.rotation))
			{
				Rotation = DataValue.Quaternion(data.rotation);
			}
			if (data.persistent != null)
			{
				Persistent = DataValue.Bool(data.persistent);
			}
			if (data.distant != null)
			{
				Distant = DataValue.Bool(data.distant);
			}
			if (data.priority != null)
			{
				Priority = (Enum.TryParse<ObjectType>(data.priority, ignoreCase: true, out ObjectType result) ? new ObjectType?(result) : ((ObjectType?)null));
			}
			if (string.IsNullOrWhiteSpace(data.connection))
			{
				return;
			}
			string[] array = Parse.SplitWithEmpty(data.connection);
			if (array.Length == 1)
			{
				string[] floats = array;
				List<string> list2 = new List<string>(floats.Length);
				list2.AddRange(floats);
				ConnectionType = ToByteEnum<ConnectionType>(list2);
				return;
			}
			List<string> list3 = array.Take(array.Length - 1).ToList();
			string text10 = array[^1];
			ConnectionType = ToByteEnum<ConnectionType>(list3);
			if (text10.Contains(":") || text10.Contains("<"))
			{
				TargetConnectionId = DataValue.ZdoId(text10);
				OriginalId = TargetConnectionId;
				return;
			}
			ConnectionHash = Parse.Int(text10);
			if (ConnectionHash == 0)
			{
				ConnectionHash = StringExtensionMethods.GetStableHashCode(text10);
			}
		}

		public void Load(string[] tkv)
		{
			if (tkv.Length != 3)
			{
				throw new InvalidOperationException("Failed to parse type, field, value.");
			}
			string text = tkv[0].ToLowerInvariant();
			string text2 = tkv[1];
			string values = tkv[2];
			if (text2.Contains("."))
			{
				CanBeInjected = false;
				string text3 = text2.Split(new char[1] { '.' })[0];
				if (Ints == null)
				{
					Ints = new Dictionary<int, IIntValue>();
				}
				Ints[ZdoHelper.Hash("HasFields")] = DataValue.Simple(1);
				Ints[ZdoHelper.Hash("HasFields" + text3)] = DataValue.Simple(1);
			}
			switch (text)
			{
			case "float":
				if (Floats == null)
				{
					Floats = new Dictionary<int, IFloatValue>();
				}
				Floats[ZdoHelper.Hash(text2)] = DataValue.Float(values);
				break;
			case "int":
				if (Ints == null)
				{
					Ints = new Dictionary<int, IIntValue>();
				}
				Ints[ZdoHelper.Hash(text2)] = DataValue.Int(values);
				break;
			case "bool":
				if (Bools == null)
				{
					Bools = new Dictionary<int, IBoolValue>();
				}
				Bools[ZdoHelper.Hash(text2)] = DataValue.Bool(values);
				break;
			case "hash":
				if (Hashes == null)
				{
					Hashes = new Dictionary<int, IHashValue>();
				}
				Hashes[ZdoHelper.Hash(text2)] = DataValue.Hash(values);
				break;
			case "long":
				if (Longs == null)
				{
					Longs = new Dictionary<int, ILongValue>();
				}
				Longs[ZdoHelper.Hash(text2)] = DataValue.Long(values);
				break;
			case "string":
				if (Strings == null)
				{
					Strings = new Dictionary<int, IStringValue>();
				}
				Strings[ZdoHelper.Hash(text2)] = DataValue.String(values);
				break;
			case "vec":
			case "vec3":
				if (Vecs == null)
				{
					Vecs = new Dictionary<int, IVector3Value>();
				}
				Vecs[ZdoHelper.Hash(text2)] = DataValue.Vector3(values);
				break;
			case "quat":
				if (Quats == null)
				{
					Quats = new Dictionary<int, IQuaternionValue>();
				}
				Quats[ZdoHelper.Hash(text2)] = DataValue.Quaternion(values);
				break;
			case "bytes":
				if (ByteArrays == null)
				{
					ByteArrays = new Dictionary<int, IBytesValue>();
				}
				ByteArrays[ZdoHelper.Hash(text2)] = DataValue.Bytes(values);
				break;
			default:
				throw new InvalidOperationException("Unknown type " + text + ".");
			}
		}

		public void Load(ZPackage pkg)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			pkg.SetPos(0);
			int num = pkg.ReadInt();
			if ((num & 1) != 0)
			{
				if (Floats == null)
				{
					Floats = new Dictionary<int, IFloatValue>();
				}
				byte b = pkg.ReadByte();
				for (int i = 0; i < b; i++)
				{
					Floats[pkg.ReadInt()] = new SimpleFloatValue(pkg.ReadSingle());
				}
			}
			if ((num & 2) != 0)
			{
				if (Vecs == null)
				{
					Vecs = new Dictionary<int, IVector3Value>();
				}
				byte b2 = pkg.ReadByte();
				for (int j = 0; j < b2; j++)
				{
					Vecs[pkg.ReadInt()] = new SimpleVector3Value(pkg.ReadVector3());
				}
			}
			if ((num & 4) != 0)
			{
				if (Quats == null)
				{
					Quats = new Dictionary<int, IQuaternionValue>();
				}
				byte b3 = pkg.ReadByte();
				for (int k = 0; k < b3; k++)
				{
					Quats[pkg.ReadInt()] = new SimpleQuaternionValue(pkg.ReadQuaternion());
				}
			}
			if ((num & 8) != 0)
			{
				if (Ints == null)
				{
					Ints = new Dictionary<int, IIntValue>();
				}
				byte b4 = pkg.ReadByte();
				for (int l = 0; l < b4; l++)
				{
					Ints[pkg.ReadInt()] = new SimpleIntValue(pkg.ReadInt());
				}
			}
			if ((num & 0x40) != 0)
			{
				if (Longs == null)
				{
					Longs = new Dictionary<int, ILongValue>();
				}
				byte b5 = pkg.ReadByte();
				for (int m = 0; m < b5; m++)
				{
					Longs[pkg.ReadInt()] = new SimpleLongValue(pkg.ReadLong());
				}
			}
			if ((num & 0x10) != 0)
			{
				if (Strings == null)
				{
					Strings = new Dictionary<int, IStringValue>();
				}
				byte b6 = pkg.ReadByte();
				for (int n = 0; n < b6; n++)
				{
					Strings[pkg.ReadInt()] = new SimpleStringValue(pkg.ReadString());
				}
			}
			if ((num & 0x80) != 0)
			{
				if (ByteArrays == null)
				{
					ByteArrays = new Dictionary<int, IBytesValue>();
				}
				byte b7 = pkg.ReadByte();
				for (int num2 = 0; num2 < b7; num2++)
				{
					ByteArrays[pkg.ReadInt()] = new SimpleBytesValue(pkg.ReadByteArray());
				}
			}
			if ((num & 0x100) != 0)
			{
				ConnectionType = (ConnectionType)pkg.ReadByte();
				ConnectionHash = pkg.ReadInt();
			}
			if ((num & 0x200) != 0)
			{
				Persistent = new SimpleBoolValue(pkg.ReadBool());
			}
			if ((num & 0x400) != 0)
			{
				Distant = new SimpleBoolValue(pkg.ReadBool());
			}
			if ((num & 0x800) != 0)
			{
				Priority = (ObjectType)pkg.ReadByte();
			}
			CanBeInjected = CheckCanBeInjected();
		}

		public bool Match(Functions f, ZDO zdo)
		{
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: 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_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: 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_02e4: Unknown result type (might be due to invalid IL or missing references)
			if (Strings != null && Strings.Any<KeyValuePair<int, IStringValue>>((KeyValuePair<int, IStringValue> pair) => pair.Value.Match(f, GetString(zdo, pair.Key)) == false))
			{
				return false;
			}
			if (Floats != null && Floats.Any<KeyValuePair<int, IFloatValue>>((KeyValuePair<int, IFloatValue> pair) => pair.Value.Match(f, GetFloat(zdo, pair.Key)) == false))
			{
				return false;
			}
			if (Ints != null && Ints.Any<KeyValuePair<int, IIntValue>>((KeyValuePair<int, IIntValue> pair) => pair.Value.Match(f, GetInt(zdo, pair.Key)) == false))
			{
				return false;
			}
			if (Longs != null && Longs.Any<KeyValuePair<int, ILongValue>>((KeyValuePair<int, ILongValue> pair) => pair.Value.Match(f, GetLong(zdo, pair.Key)) == false))
			{
				return false;
			}
			if (Bools != null && Bools.Any<KeyValuePair<int, IBoolValue>>((KeyValuePair<int, IBoolValue> pair) => pair.Value.Match(f, GetBool(zdo, pair.Key)) == false))
			{
				return false;
			}
			if (Hashes != null && Hashes.Any<KeyValuePair<int, IHashValue>>((KeyValuePair<int, IHashValue> pair) => pair.Value.Match(f, GetInt(zdo, pair.Key)) == false))
			{
				return false;
			}
			if (Vecs != null && Vecs.Any<KeyValuePair<int, IVector3Value>>((KeyValuePair<int, IVector3Value> pair) => pair.Value.Match(f, GetVec(zdo, pair.Key)) == false))
			{
				return false;
			}
			if (Quats != null && Quats.Any<KeyValuePair<int, IQuaternionValue>>((KeyValuePair<int, IQuaternionValue> pair) => pair.Value.Match(f, GetQuaternion(zdo, pair.Key)) == false))
			{
				return false;
			}
			if (ByteArrays != null && ByteArrays.Any<KeyValuePair<int, IBytesValue>>((KeyValuePair<int, IBytesValue> pair) => pair.Value.Match(f, zdo.GetByteArray(pair.Key, (byte[])null)) == false))
			{
				return false;
			}
			if (Persistent != null && Persistent.Match(f, zdo.Persistent) == false)
			{
				return false;
			}
			if (Distant != null && Distant.Match(f, zdo.Distant) == false)
			{
				return false;
			}
			if (Priority.HasValue && Priority.Value != zdo.Type)
			{
				return false;
			}
			if (Items != null)
			{
				return ItemValue.Match(f, Items, zdo, ItemAmount);
			}
			if (ItemAmount != null)
			{
				return ItemValue.Match(f, zdo, ItemAmount);
			}
			if (ConnectionType.HasValue)
			{
				if ((int)ConnectionType.Value == 0)
				{
					ZDOConnection connection = zdo.GetConnection();
					if (connection != null && connection.m_target != ZDOID.None)
					{
						return false;
					}
				}
				else
				{
					ZDOID connectionZDOID = zdo.GetConnectionZDOID(ConnectionType.Value);
					if (TargetConnectionId == null)
					{
						if (connectionZDOID == ZDOID.None)
						{
							return false;
						}
					}
					else
					{
						ZDOID? val = TargetConnectionId.Get(f);
						if (val.HasValue)
						{
							ZDOID val2 = connectionZDOID;
							ZDOID? val3 = val;
							if (!val3.HasValue || val2 != val3.GetValueOrDefault())
							{
								return false;
							}
						}
					}
				}
			}
			return true;
		}

		public bool Unmatch(Functions f, ZDO zdo)
		{
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: 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_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: 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_02ca: Unknown result type (might be due to invalid IL or missing references)
			if (Strings != null && Strings.Any<KeyValuePair<int, IStringValue>>((KeyValuePair<int, IStringValue> pair) => pair.Value.Match(f, GetString(zdo, pair.Key)) == true))
			{
				return false;
			}
			if (Floats != null && Floats.Any<KeyValuePair<int, IFloatValue>>((KeyValuePair<int, IFloatValue> pair) => pair.Value.Match(f, GetFloat(zdo, pair.Key)) == true))
			{
				return false;
			}
			if (Ints != null && Ints.Any<KeyValuePair<int, IIntValue>>((KeyValuePair<int, IIntValue> pair) => pair.Value.Match(f, GetInt(zdo, pair.Key)) == true))
			{
				return false;
			}
			if (Longs != null && Longs.Any<KeyValuePair<int, ILongValue>>((KeyValuePair<int, ILongValue> pair) => pair.Value.Match(f, GetLong(zdo, pair.Key)) == true))
			{
				return false;
			}
			if (Bools != null && Bools.Any<KeyValuePair<int, IBoolValue>>((KeyValuePair<int, IBoolValue> pair) => pair.Value.Match(f, GetBool(zdo, pair.Key)) == true))
			{
				return false;
			}
			if (Hashes != null && Hashes.Any<KeyValuePair<int, IHashValue>>((KeyValuePair<int, IHashValue> pair) => pair.Value.Match(f, GetInt(zdo, pair.Key)) == true))
			{
				return false;
			}
			if (Vecs != null && Vecs.Any<KeyValuePair<int, IVector3Value>>((KeyValuePair<int, IVector3Value> pair) => pair.Value.Match(f, GetVec(zdo, pair.Key)) == true))
			{
				return false;
			}
			if (Quats != null && Quats.Any<KeyValuePair<int, IQuaternionValue>>((KeyValuePair<int, IQuaternionValue> pair) => pair.Value.Match(f, GetQuaternion(zdo, pair.Key)) == true))
			{
				return false;
			}
			if (ByteArrays != null && ByteArrays.Any<KeyValuePair<int, IBytesValue>>((KeyValuePair<int, IBytesValue> pair) => pair.Value.Match(f, zdo.GetByteArray(pair.Key, (byte[])null)) == true))
			{
				return false;
			}
			if (Persistent != null && Persistent.Match(f, zdo.Persistent) == true)
			{
				return false;
			}
			if (Distant != null && Distant.Match(f, zdo.Distant) == true)
			{
				return false;
			}
			if (Priority.HasValue && Priority.Value == zdo.Type)
			{
				return false;
			}
			if (Items != null)
			{
				return !ItemValue.Match(f, Items, zdo, ItemAmount);
			}
			if (ItemAmount != null)
			{
				return !ItemValue.Match(f, zdo, ItemAmount);
			}
			if (ConnectionType.HasValue)
			{
				if ((int)ConnectionType.Value == 0)
				{
					ZDOConnection connection = zdo.GetConnection();
					if (connection == null || connection.m_target == ZDOID.None)
					{
						return false;
					}
				}
				else
				{
					ZDOID connectionZDOID = zdo.GetConnectionZDOID(ConnectionType.Value);
					if (TargetConnectionId == null)
					{
						if (connectionZDOID != ZDOID.None)
						{
							return false;
						}
					}
					else
					{
						ZDOID? val = TargetConnectionId.Get(f);
						if (val.HasValue)
						{
							ZDOID val2 = connectionZDOID;
							ZDOID? val3 = val;
							if (val3.HasValue && val2 == val3.GetValueOrDefault())
							{
								return false;
							}
						}
					}
				}
			}
			return true;
		}

		private string GetString(ZDO zdo, int key)
		{
			return ZdoHelper.TryGetString(zdo, key) ?? "";
		}

		private float GetFloat(ZDO zdo, int key)
		{
			return ZdoHelper.TryGetFloat(zdo, key).GetValueOrDefault();
		}

		private int GetInt(ZDO zdo, int key)
		{
			return ZdoHelper.TryGetInt(zdo, key).GetValueOrDefault();
		}

		private long GetLong(ZDO zdo, int key)
		{
			return ZdoHelper.TryGetLong(zdo, key).GetValueOrDefault();
		}

		private bool GetBool(ZDO zdo, int key)
		{
			return ZdoHelper.TryGetBool(zdo, key) == true;
		}

		private Vector3 GetVec(ZDO zdo, int key)
		{
			//IL_0019: 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)
			return (Vector3)(((??)ZdoHelper.TryGetVec(zdo, key)) ?? Vector3.zero);
		}

		private Quaternion GetQuaternion(ZDO zdo, int key)
		{
			//IL_0019: 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)
			return (Quaternion)(((??)ZdoHelper.TryGetQuaternion(zdo, key)) ?? Quaternion.identity);
		}

		private static T ToByteEnum<T>(List<string> list) where T : struct, Enum
		{
			byte b = 0;
			foreach (string item in list)
			{
				string text = item.Trim();
				if (Enum.TryParse<T>(text, ignoreCase: true, out var result))
				{
					b += (byte)(object)result;
				}
				else
				{
					Log.Warning("Failed to parse value " + text + " as T.");
				}
			}
			return (T)(object)b;
		}

		private bool CheckCanBeInjected()
		{
			if ((Ints == null || (!Ints.ContainsKey(HasFieldsHash) && !Ints.ContainsKey(ZDOVars.s_level))) && Components == null && Position == null)
			{
				return Rotation == null;
			}
			return false;
		}

		public void RollItems(Functions f, ZDO zdo)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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)
			List<ItemValue>? items = Items;
			if (items != null && items.Count > 0)
			{
				Vector2i size = (Vector2i)(((??)ContainerSize) ?? ZdoHelper.GetInventorySize(this, f, zdo));
				byte[] value = ItemValue.LoadItemBytes(f, Items, size, (ItemAmount?.Get(f)).GetValueOrDefault());
				if (ByteArrays == null)
				{
					ByteArrays = new Dictionary<int, IBytesValue>();
				}
				ByteArrays[ZDOVars.s_items] = DataValue.Simple(value);
			}
		}

		public void AddItems(Functions f, ZDO zdo)
		{
			//IL_0032: 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_0037: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (Items == null || Items.Count == 0)
			{
				return;
			}
			Vector2i val = (Vector2i)(((??)ContainerSize) ?? ZdoHelper.GetInventorySize(this, f, zdo));
			Inventory val2 = ItemValue.CreateInventory(zdo, val.x, val.y);
			foreach (ItemValue item in GenerateItems(f, val))
			{
				item.AddTo(f, val2);
			}
			InventoryStorage.Save(zdo, val2);
		}

		public void RemoveItems(Functions f, ZDO zdo)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (Items == null || Items.Count == 0)
			{
				return;
			}
			Inventory val = ItemValue.CreateInventory(zdo);
			if (val.m_inventory.Count == 0)
			{
				return;
			}
			foreach (ItemValue item in GenerateItems(f, new Vector2i(10000, 10000)))
			{
				item.RemoveFrom(f, val);
			}
			InventoryStorage.Save(zdo, val);
		}

		public List<ItemValue> GenerateItems(Functions f, Vector2i size)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (Items == null)
			{
				throw new ArgumentNullException("Items");
			}
			return ItemValue.Generate(f, Items, size, (ItemAmount?.Get(f)).GetValueOrDefault());
		}
	}
	public class DataHelper
	{
		public static DataEntry? Merge(params DataEntry?[] datas)
		{
			DataEntry[] array = datas.Where((DataEntry d) => d != null).ToArray();
			if (array.Length == 0)
			{
				return null;
			}
			if (array.Length == 1)
			{
				return array[0];
			}
			DataEntry dataEntry = new DataEntry();
			DataEntry[] array2 = array;
			foreach (DataEntry data in array2)
			{
				dataEntry.Load(data);
			}
			return dataEntry;
		}

		public static bool Exists(int hash)
		{
			return DataLoading.Data.ContainsKey(hash);
		}

		public static bool Match(int hash, ZDO zdo, Functions f)
		{
			if (DataLoading.Data.TryGetValue(hash, out DataEntry value))
			{
				return value.Match(f, zdo);
			}
			return false;
		}

		public static DataEntry? Get(string name)
		{
			if (!(name == ""))
			{
				return DataLoading.Get(name);
			}
			return null;
		}

		public static DataEntry? Get(IStringValue? name, Functions f)
		{
			if (name == null)
			{
				return null;
			}
			string whole = name.GetWhole(f);
			if (whole == null)
			{
				return null;
			}
			int stableHashCode = StringExtensionMethods.GetStableHashCode(whole);
			if (DataLoading.TryGet(stableHashCode, out DataEntry entry))
			{
				return entry;
			}
			if (!Enumerable.Contains(whole, ','))
			{
				return Get(whole);
			}
			string[] array = (from s in whole.Split(new char[1] { ',' }, 3)
				select s.Trim()).ToArray();
			if (array.Length > 2 && DataEntry.SupportedTypes.Contains(array[0]))
			{
				DataEntry dataEntry = new DataEntry(array);
				DataLoading.Add(stableHashCode, dataEntry);
				return dataEntry;
			}
			return Get(name.Get(f) ?? "");
		}

		public static int GetHash(string name)
		{
			int stableHashCode = StringExtensionMethods.GetStableHashCode(name);
			if (Enumerable.Contains(name, ','))
			{
				string[] array = (from s in name.Split(new char[1] { ',' }, 3)
					select s.Trim()).ToArray();
				if (array.Length > 2 && DataEntry.SupportedTypes.Contains(array[0]))
				{
					DataEntry entry = new DataEntry(array);
					DataLoading.Add(stableHashCode, entry);
					return stableHashCode;
				}
			}
			Get(name);
			return stableHashCode;
		}

		public static List<string>? GetValuesFromGroup(string group)
		{
			int stableHashCode = StringExtensionMethods.GetStableHashCode(group.ToLowerInvariant());
			if (DataLoading.ValueGroups.TryGetValue(stableHashCode, out List<string> value))
			{
				return value;
			}
			return null;
		}

		public static string GetGlobalKey(string key)
		{
			string lower = key.ToLowerInvariant();
			return ZoneSystem.instance.m_globalKeysValues.FirstOrDefault((KeyValuePair<string, string> kvp) => kvp.Key.ToLowerInvariant() == lower).Value ?? "0";
		}
	}
	public class DataLoading
	{
		public static Dictionary<int, DataEntry> Data = new Dictionary<int, DataEntry>();

		public static readonly Dictionary<int, List<string>> ValueGroups = new Dictionary<int, List<string>>();

		private static readonly Dictionary<string, List<DataData>> FileEntries = new Dictionary<string, List<DataData>>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<int, List<string>> DefaultValueGroups = new Dictionary<int, List<string>>();

		private static readonly int WearNTearHash = StringExtensionMethods.GetStableHashCode("wearntear");

		private static readonly int HumanoidHash = StringExtensionMethods.GetStableHashCode("humanoid");

		private static readonly int CreatureHash = StringExtensionMethods.GetStableHashCode("creature");

		private static readonly int StructureHash = StringExtensionMethods.GetStableHashCode("structure");

		public static void Add(int hash, DataEntry entry)
		{
			Data[hash] = entry;
		}

		public static DataEntry? Get(string name)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			DataEntry dataEntry = Get(StringExtensionMethods.GetStableHashCode(name));
			if (dataEntry != null)
			{
				return dataEntry;
			}
			if (name.Length >= 12 && name.Length % 4 == 0)
			{
				try
				{
					DataEntry dataEntry2 = new DataEntry(new ZPackage(name));
					Data[StringExtensionMethods.GetStableHashCode(name)] = dataEntry2;
					return dataEntry2;
				}
				catch
				{
					Log.Error("Failed to decode base64 data: " + name);
				}
			}
			Log.Warning("Data entry not found: " + name);
			return null;
		}

		public static DataEntry? Get(int hash)
		{
			if (!Data.ContainsKey(hash))
			{
				return null;
			}
			return Data[hash];
		}

		public static bool TryGet(int hash, out DataEntry? entry)
		{
			entry = (Data.ContainsKey(hash) ? Data[hash] : null);
			return entry != null;
		}

		public static void LoadFromFiles(List<string> files, Dictionary<string, List<DataData>> fileEntries)
		{
			Dictionary<int, DataEntry> data = Data;
			FileEntries.Clear();
			foreach (string file in files)
			{
				FileEntries[file] = (fileEntries.TryGetValue(file, out List<DataData> value) ? value : new List<DataData>());
			}
			RebuildFromCache(data, files);
		}

		private static void RebuildFromCache(Dictionary<int, DataEntry> prev, List<string> files)
		{
			Data = new Dictionary<int, DataEntry>();
			ValueGroups.Clear();
			foreach (string file in files)
			{
				if (!FileEntries.TryGetValue(file, out List<DataData> value))
				{
					continue;
				}
				foreach (DataData item in value)
				{
					LoadValues(item);
				}
			}
			if (ValueGroups.Count > 0)
			{
				Log.Info($"Loaded {ValueGroups.Count} value groups.");
			}
			LoadDefaultValueGroups();
			foreach (KeyValuePair<int, List<string>> valueGroup in ValueGroups)
			{
				ResolveValues(valueGroup.Value);
			}
			foreach (KeyValuePair<int, List<string>> defaultValueGroup in DefaultValueGroups)
			{
				if (!ValueGroups.ContainsKey(defaultValueGroup.Key))
				{
					ValueGroups[defaultValueGroup.Key] = defaultValueGroup.Value;
				}
			}
			foreach (string file2 in files)
			{
				if (!FileEntries.TryGetValue(file2, out List<DataData> value2))
				{
					continue;
				}
				foreach (DataData item2 in value2)
				{
					LoadEntry(item2, prev);
				}
			}
			PrefabHelper.ClearCache();
			Log.Info($"Loaded {Data.Count} data entries.");
		}

		private static void LoadValues(DataData data)
		{
			if (data.value != null)
			{
				KeyValuePair<string, string> keyValuePair = Parse.Kvp(data.value);
				int stableHashCode = StringExtensionMethods.GetStableHashCode(keyValuePair.Key.ToLowerInvariant());
				if (ValueGroups.ContainsKey(stableHashCode))
				{
					Log.Warning("Duplicate value group entry: " + keyValuePair.Key);
				}
				if (!ValueGroups.ContainsKey(stableHashCode))
				{
					ValueGroups[stableHashCode] = new List<string>();
				}
				ValueGroups[stableHashCode].Add(keyValuePair.Value);
			}
			if (data.valueGroup != null && data.values != null)
			{
				int stableHashCode2 = StringExtensionMethods.GetStableHashCode(data.valueGroup.ToLowerInvariant());
				if (ValueGroups.ContainsKey(stableHashCode2))
				{
					Log.Warning("Duplicate value group entry: " + data.valueGroup);
				}
				if (!ValueGroups.ContainsKey(stableHashCode2))
				{
					ValueGroups[stableHashCode2] = new List<string>();
				}
				string[] values = data.values;
				foreach (string item in values)
				{
					ValueGroups[stableHashCode2].Add(item);
				}
			}
		}

		private static void LoadEntry(DataData data, Dictionary<int, DataEntry> oldData)
		{
			if (data.name != null)
			{
				int stableHashCode = StringExtensionMethods.GetStableHashCode(data.name);
				if (Data.ContainsKey(stableHashCode))
				{
					Log.Warning("Duplicate data entry: " + data.name);
				}
				Data[stableHashCode] = (oldData.TryGetValue(stableHashCode, out DataEntry value) ? value.Reset(data) : new DataEntry(data));
			}
		}

		private static void LoadDefaultValueGroups()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if (DefaultValueGroups.Count == 0)
			{
				foreach (GameObject value in ZNetScene.instance.m_namedPrefabs.Values)
				{
					if (!Object.op_Implicit((Object)(object)value))
					{
						continue;
					}
					value.GetComponentsInChildren<MonoBehaviour>(ZNetView.m_tempComponents);
					foreach (MonoBehaviour tempComponent in ZNetView.m_tempComponents)
					{
						AddDefaultValue(((object)tempComponent).GetType().Name, ((Object)value).name);
						WearNTear val = (WearNTear)(object)((tempComponent is WearNTear) ? tempComponent : null);
						if (val != null)
						{
							AddDefaultValue($"material_{val.m_materialType}", ((Object)value).name);
						}
						ItemDrop val2 = (ItemDrop)(object)((tempComponent is ItemDrop) ? tempComponent : null);
						if (val2 != null)
						{
							AddDefaultValue($"itemtype_{val2.m_itemData.m_shared.m_itemType}", ((Object)value).name);
						}
					}
				}
			}
			DefaultValueGroups[CreatureHash] = DefaultValueGroups[HumanoidHash];
			DefaultValueGroups[StructureHash] = DefaultValueGroups[WearNTearHash];
		}

		private static void AddDefaultValue(string name, string prefab)
		{
			int stableHashCode = StringExtensionMethods.GetStableHashCode(name.ToLowerInvariant().Replace(" ", "_"));
			if (!DefaultValueGroups.ContainsKey(stableHashCode))
			{
				DefaultValueGroups[stableHashCode] = new List<string>();
			}
			DefaultValueGroups[stableHashCode].Add(prefab);
		}

		private static void ResolveValues(List<string> values)
		{
			for (int i = 0; i < values.Count; i++)
			{
				string text = values[i];
				if (text.StartsWith("<", StringComparison.OrdinalIgnoreCase) && text.EndsWith(">", StringComparison.OrdinalIgnoreCase))
				{
					string text2 = text.Substring(1, text.Length - 2);
					List<string> value2;
					if (ValueGroups.TryGetValue(StringExtensionMethods.GetStableHashCode(text2.ToLowerInvariant()), out List<string> value))
					{
						values.RemoveAt(i);
						values.InsertRange(i, value);
						i--;
					}
					else if (DefaultValueGroups.TryGetValue(StringExtensionMethods.GetStableHashCode(text2.ToLowerInvariant()), out value2))
					{
						values.RemoveAt(i);
						values.InsertRange(i, value2);
						i += value2.Count - 1;
					}
				}
			}
		}
	}
	public class DataValue
	{
		public static IZdoIdValue ZdoId(string values)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			string[] array = SplitWithValues(values);
			ZDOID val = Parse.ZdoId(array[0]);
			if (array.Length == 1 && val != ZDOID.None)
			{
				return new SimpleZdoIdValue(val);
			}
			return new ZdoIdValue(array);
		}

		public static IIntValue Simple(int value)
		{
			return new SimpleIntValue(value);
		}

		public static IStringValue Simple(string value)
		{
			return new SimpleStringValue(value);
		}

		public static IFloatValue Simple(float value)
		{
			return new SimpleFloatValue(value);
		}

		public static ILongValue Simple(long value)
		{
			return new SimpleLongValue(value);
		}

		public static IVector3Value Simple(Vector3 value)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return new SimpleVector3Value(value);
		}

		public static IQuaternionValue Simple(Quaternion value)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return new SimpleQuaternionValue(value);
		}

		public static IBytesValue Simple(byte[]? value)
		{
			return new SimpleBytesValue(value);
		}

		public static IIntValue Int(string values)
		{
			string[] array = SplitWithValues(values);
			if (array.Length == 1 && int.TryParse(array[0], out var result))
			{
				return new SimpleIntValue(result);
			}
			return new IntValue(array);
		}

		public static IRangeIntValue RangeInt(string values)
		{
			string[] array = SplitWithValues(values);
			if (array.Length == 1 && !HasFunctions(array[0]))
			{
				if (int.TryParse(array[0], out var result))
				{
					return new SimpleRangeIntValue(new Range<int>(result, 0));
				}
				return new SimpleRangeIntValue(Parse.IntRange(array[0]));
			}
			return new RangeIntValue(array);
		}

		public static IFloatValue Float(string values)
		{
			string[] array = SplitWithValues(values);
			if (array.Length == 1 && Parse.TryFloat(array[0], out var result))
			{
				return new SimpleFloatValue(result);
			}
			return new FloatValue(array);
		}

		public static ILongValue Long(string values)
		{
			string[] array = SplitWithValues(values);
			if (array.Length == 1 && Parse.TryLong(array[0], out var result))
			{
				return new SimpleLongValue(result);
			}
			return new LongValue(array);
		}

		public static IStringValue String(string values)
		{
			if (values.Length > 2 && values[0] == '"' && values[values.Length - 1] == '"')
			{
				return new SimpleStringValue(values.Substring(1, values.Length - 2));
			}
			string[] array = SplitWithValues(values);
			if (array.Length == 1 && !HasFunctions(array[0]))
			{
				return new SimpleStringValue(array[0]);
			}
			return new StringValue(array);
		}

		public static IBoolValue Bool(string values)
		{
			string[] array = SplitWithValues(values);
			if (array.Length == 1 && bool.TryParse(array[0], out var result))
			{
				return new SimpleBoolValue(result);
			}
			return new BoolValue(array);
		}

		public static IBytesValue Bytes(string values)
		{
			string[] array = SplitWithValues(values);
			if (array.Length == 1 && !HasFunctions(array[0]))
			{
				if (string.IsNullOrEmpty(array[0]))
				{
					return new SimpleBytesValue(null);
				}
				try
				{
					return new SimpleBytesValue(Convert.FromBase64String(array[0]));
				}
				catch (FormatException)
				{
				}
			}
			return new BytesValue(array);
		}

		public static IHashValue Hash(string values)
		{
			string[] array = SplitWithValues(values);
			if (array.Length == 1 && !HasFunctions(array[0]))
			{
				return new SimpleHashValue(array[0]);
			}
			return new HashValue(array);
		}

		public static IPrefabValue Prefab(string values)
		{
			if (HasFunctions(values))
			{
				return new PrefabValue(SplitWithValues(values));
			}
			List<int> prefabs = PrefabHelper.GetPrefabs(values, "");
			if (prefabs.Count == 0)
			{
				return new SimplePrefabValue(null);
			}
			if (prefabs.Count == 1)
			{
				return new SimplePrefabValue(prefabs[0]);
			}
			return new SimplePrefabsValue(prefabs);
		}

		public static IVector3Value Vector3(string values)
		{
			//IL_008d: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			string[] array = SplitWithValues(values);
			if (HasFunctions(values) || array.Length > 3)
			{
				List<string> list = new List<string>();
				for (int i = 0; i < array.Length; i += 3)
				{
					string[] array2;
					if (i + 3 >= array.Length)
					{
						List<string> list2 = new List<string>();
						list2.AddRange(array.Skip(i));
						array2 = list2.ToArray();
					}
					else
					{
						array2 = array.Skip(i).Take(3).ToArray();
					}
					string[] value = array2;
					list.Add(string.Join(",", value));
				}
				return new Vector3Value(list.ToArray());
			}
			if (Parse.TryDistanceAngle(array, out var vector))
			{
				return new SimpleVector3Value(vector);
			}
			Vector3? val = Parse.VectorXZYNull(array);
			return new SimpleVector3Value(val.HasValue ? val.Value : Vector3.zero);
		}

		public static IQuaternionValue Quaternion(string values)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			string[] array = SplitWithValues(values);
			if (HasFunctions(values) || array.Length > 3)
			{
				List<string> list = new List<string>();
				for (int i = 0; i < array.Length; i += 3)
				{
					string[] array2;
					if (i + 3 >= array.Length)
					{
						List<string> list2 = new List<string>();
						list2.AddRange(array.Skip(i));
						array2 = list2.ToArray();
					}
					else
					{
						array2 = array.Skip(i).Take(3).ToArray();
					}
					string[] value = array2;
					list.Add(string.Join(",", value));
				}
				return new QuaternionValue(list.ToArray());
			}
			Quaternion? val = Parse.AngleYXZNull(array);
			return new SimpleQuaternionValue(val.HasValue ? val.Value : Quaternion.identity);
		}

		private static bool HasFunctions(string value)
		{
			if (value.Contains("<"))
			{
				return value.Contains(">");
			}
			return false;
		}

		private static string[] SplitWithValues(string str)
		{
			List<string> list = new List<string>();
			string[] array = Parse.SplitWithEmpty(str);
			foreach (string text in array)
			{
				if (!text.Contains("<") || !text.Contains(">"))
				{
					list.Add(text);
					continue;
				}
				string[] array2 = text.Split('<', '>');
				List<string> list2 = new List<string>();
				List<int> list3 = new List<int>();
				for (int j = 1; j < array2.Length; j += 2)
				{
					int stableHashCode = StringExtensionMethods.GetStableHashCode(array2[j].ToLowerInvariant());
					if (DataLoading.ValueGroups.ContainsKey(stableHashCode))
					{
						list2.Add("<" + array2[j] + ">");
						list3.Add(stableHashCode);
					}
				}
				if (list2.Count == 0)
				{
					list.Add(text);
					if (list.Count > 1000)
					{
						break;
					}
				}
				else
				{
					SubstitueValues(list, text, list2, list3, 0);
				}
			}
			if (list.Count > 1000)
			{
				Log.Warning("Too many values loaded for " + str);
			}
			if (list.Count <= 1000)
			{
				return list.ToArray();
			}
			return new string[1] { str };
		}

		private static void SubstitueValues(List<string> result, string format, List<string> parameters, List<int> hashes, int index)
		{
			foreach (string item in DataLoading.ValueGroups[hashes[index]])
			{
				string text = format.Replace(parameters[index], item);
				if (index == parameters.Count - 1)
				{
					result.Add(text);
					if (result.Count > 1000)
					{
						break;
					}
				}
				else
				{
					SubstitueValues(result, text, parameters, hashes, index + 1);
				}
			}
		}
	}
	public class AnyValue(string[] values)
	{
		protected readonly string[] Values = values;

		private string? RollValue()
		{
			if (values.Length == 1)
			{
				return values[0];
			}
			return values[Random.Range(0, values.Length)];
		}

		protected string? GetValue(Functions f)
		{
			string text = RollValue();
			if (text == null || text == "<none>")
			{
				return null;
			}
			return f.Replace(text);
		}

		protected string? GetValue()
		{
			string text = RollValue();
			if (text != null && !(text == "<none>"))
			{
				return text;
			}
			return null;
		}

		protected List<string> GetAllValues(Functions f)
		{
			List<string> list = new List<string>();
			list.AddRange(from v in values.Select(f.Replace)
				where v != null && v != "" && v != "<none>"
				select v);
			return list;
		}

		protected string GetWholeValue(Functions f)
		{
			return string.Join(",", values.Select(f.Replace));
		}
	}
	public class ItemValue
	{
		public IPrefabValue Prefab = DataValue.Prefab(data.prefab);

		public float Chance = data.chance;

		public IIntValue? Stack = ((data.stack == null) ? null : DataValue.Int(data.stack));

		public IFloatValue? Durability = ((data.durability == null) ? null : DataValue.Float(data.durability));

		public string Position = data.pos;

		private Vector2i RolledPosition = Parse.Vector2Int(data.pos);

		public IBoolValue? Equipped = ((data.equipped == null) ? null : DataValue.Bool(data.equipped));

		public IIntValue? Quality = ((data.quality == null) ? null : DataValue.Int(data.quality));

		public IIntValue? Variant = ((data.variant == null) ? null : DataValue.Int(data.variant));

		public ILongValue? CrafterID = ((data.crafterID == null) ? null : DataValue.Long(data.crafterID));

		public IStringValue? CrafterName = ((data.crafterName == null) ? null : DataValue.String(data.crafterName));

		public Dictionary<string, IStringValue>? CustomData = data.customData?.ToDictionary((KeyValuePair<string, string> kvp) => kvp.Key, (KeyValuePair<string, string> kvp) => DataValue.String(kvp.Value));

		public IIntValue? WorldLevel = ((data.worldLevel == null) ? null : DataValue.Int(data.worldLevel));

		public IBoolValue? PickedUp = ((data.pickedUp == null) ? null : DataValue.Bool(data.pickedUp));

		private int RolledPrefab;

		private int RolledStack;

		public ItemValue(ItemData data)
		{
		}//IL_0068: 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)


		public static bool Match(Functions f, List<ItemValue> data, ZDO zdo, IIntValue? amount)
		{
			Inventory inv = CreateInventory(zdo);
			int num = data.Count((ItemValue item) => item.Match(f, inv));
			if (amount == null)
			{
				if (num == data.Count)
				{
					return inv.m_inventory.Count == 0;
				}
				return false;
			}
			return amount.Match(f, num) == true;
		}

		public static bool Match(Functions f, ZDO zdo, IIntValue amount)
		{
			Inventory val = CreateInventory(zdo);
			return amount.Match(f, val.m_inventory.Count) == true;
		}

		public static Inventory CreateInventory(ZDO zdo, int width = 100000, int height = 10000)
		{
			return InventoryStorage.Create(zdo, width, height);
		}

		public static string LoadItems(Functions f, List<ItemValue> items, Vector2i size, int amount)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return Convert.ToBase64String(LoadItemBytes(f, items, size, amount));
		}

		internal static byte[] LoadItemBytes(Functions f, List<ItemValue> items, Vector2i size, int amount)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(109);
			items = Generate(f, items, size, amount);
			List<ItemValue> list = new List<ItemValue>();
			list.AddRange(items.Where((ItemValue item) => item.CanWrite()));
			items = list;
			val.Write((ushort)items.Count);
			foreach (ItemValue item in items)
			{
				item.Write(f, val);
			}
			return val.GetArray();
		}

		public static List<ItemValue> Generate(Functions f, List<ItemValue> data, Vector2i size, int amount)
		{
			//IL_0076: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			List<ItemValue> list = data.Where((ItemValue item) => item.Position != "").ToList();
			List<ItemValue> items = data.Where((ItemValue item) => item.Position == "").ToList();
			Dictionary<Vector2i, ItemValue> dictionary = new Dictionary<Vector2i, ItemValue>();
			foreach (ItemValue item in list)
			{
				if (item.Roll(f))
				{
					dictionary[item.RolledPosition] = item;
				}
			}
			if (amount == 0)
			{
				GenerateEach(f, dictionary, size, items);
			}
			else
			{
				GenerateAmount(f, dictionary, size, items, amount);
			}
			Dictionary<Vector2i, ItemValue>.ValueCollection values = dictionary.Values;
			List<ItemValue> list2 = new List<ItemValue>(values.Count);
			list2.AddRange(values);
			return list2;
		}

		private static void GenerateEach(Functions f, Dictionary<Vector2i, ItemValue> inventory, Vector2i size, List<ItemValue> items)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			foreach (ItemValue item in items)
			{
				if (item.Roll(f))
				{
					Vector2i? val = FindNextFreeSlot(inventory, size);
					if (!val.HasValue)
					{
						break;
					}
					item.RolledPosition = val.Value;
					inventory[val.Value] = item;
				}
			}
		}

		private static void GenerateAmount(Functions f, Dictionary<Vector2i, ItemValue> inventory, Vector2i size, List<ItemValue> items, int amount)
		{
			//IL_002b: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			float num = items.Sum((ItemValue item) => item.Chance);
			for (int num2 = 0; num2 < amount; num2++)
			{
				if (items.Count <= 0)
				{
					break;
				}
				Vector2i? val = FindNextFreeSlot(inventory, size);
				if (val.HasValue)
				{
					ItemValue itemValue = RollItem(items, num);
					itemValue.RolledPosition = val.Value;
					if (itemValue.RollPrefab(f))
					{
						inventory[val.Value] = itemValue;
					}
					num -= itemValue.Chance;
					items.Remove(itemValue);
					continue;
				}
				break;
			}
		}

		private static ItemValue RollItem(List<ItemValue> items, float maxWeight)
		{
			float num = Random.Range(0f, maxWeight);
			foreach (ItemValue item in items)
			{
				if (num < item.Chance)
				{
					return item;
				}
				num -= item.Chance;
			}
			return items.Last();
		}

		private static Vector2i? FindNextFreeSlot(Dictionary<Vector2i, ItemValue> inventory, Vector2i size)
		{
			//IL_0000: 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_0020: 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)
			int x = size.x;
			int y = size.y;
			Vector2i val = default(Vector2i);
			for (int i = 0; i < y; i++)
			{
				for (int j = 0; j < x; j++)
				{
					((Vector2i)(ref val))..ctor(j, i);
					if (!inventory.ContainsKey(val))
					{
						return val;
					}
				}
			}
			return null;
		}

		public bool RollPrefab(Functions f)
		{
			RolledPrefab = Prefab.Get(f).GetValueOrDefault();
			RolledStack = Stack?.Get(f) ?? 1;
			if (RolledPrefab != 0)
			{
				return RolledStack != 0;
			}
			return false;
		}

		public bool RollChance()
		{
			if (!(Chance >= 1f))
			{
				return Random.value <= Chance;
			}
			return true;
		}

		public bool Roll(Functions f)
		{
			if (RollChance())
			{
				return RollPrefab(f);
			}
			return false;
		}

		private bool CanWrite()
		{
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(RolledPrefab);
			ItemDrop val = default(ItemDrop);
			if ((Object)(object)itemPrefab != (Object)null)
			{
				return itemPrefab.TryGetComponent<ItemDrop>(ref val);
			}
			return false;
		}

		public void Write(Functions f, ZPackage pkg)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(RolledPrefab);
			ItemDrop val = default(ItemDrop);
			if (!((Object)(object)itemPrefab == (Object)null) && itemPrefab.TryGetComponent<ItemDrop>(ref val))
			{
				ItemData obj = CreateItemData(f, itemPrefab);
				obj.m_gridPos = RolledPosition;
				obj.Save(pkg);
			}
		}

		public void Spawn(ZDO source, Functions f)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = ZNetScene.instance.GetPrefab(RolledPrefab);
			if ((Object)(object)prefab == (Object)null)
			{
				Log.Error($"Can't spawn missing drop: {RolledPrefab}");
				return;
			}
			Vector3 position = source.m_position;
			if (Object.op_Implicit((Object)(object)prefab.GetComponent<ItemDrop>()))
			{
				ZDO val = ZdoEntry.Spawn(RolledPrefab, position, Vector3.zero, source.GetOwner());
				if (val != null)
				{
					ItemDrop.SaveToZDO(CreateItemData(f, prefab), val, -1);
				}
				return;
			}
			for (int i = 0; i < RolledStack; i++)
			{
				ZDO val2 = ZdoEntry.Spawn(RolledPrefab, position, Vector3.zero, source.GetOwner());
				if (val2 == null)
				{
					break;
				}
				if (Object.op_Implicit((Object)(object)prefab.GetComponent<Character>()))
				{
					val2.Set(ZDOVars.s_level, Quality?.Get(f) ?? 1, false);
				}
				if (CustomData == null)
				{
					continue;
				}
				foreach (KeyValuePair<string, IStringValue> customDatum in CustomData)
				{
					LoadCustomData(val2, f, customDatum);
				}
			}
		}

		private ItemData CreateItemData(Functions f, GameObject prefab)
		{
			Dictionary<string, string> customData = CustomData?.ToDictionary((KeyValuePair<string, IStringValue> x) => x.Key, (KeyValuePair<string, IStringValue> x) => x.Value.Get(f) ?? "");
			return ItemDataHelper.Create(prefab, RolledStack, Durability?.Get(f), Quality?.Get(f) ?? 1, (Variant?.Get(f)).GetValueOrDefault(), (CrafterID?.Get(f)).GetValueOrDefault(), CrafterName?.Get(f) ?? "", (WorldLevel?.Get(f)).GetValueOrDefault(), PickedUp?.GetBool(f) == true, Equipped?.GetBool(f) == true, customData);
		}

		private void LoadCustomData(ZDO zdo, Functions f, KeyValuePair<string, IStringValue> kvp)
		{
			if (kvp.Key == "data")
			{
				DataEntry dataEntry = DataHelper.Get(kvp.Value.Get(f) ?? "");
				if (dataEntry != null)
				{
					ZdoEntry zdoEntry = new ZdoEntry(zdo);
					zdoEntry.Load(dataEntry, f);
					zdoEntry.Write(zdo);
				}
			}
		}

		public void AddTo(Functions f, Inventory inv)
		{
			int stack = Stack?.Get(f) ?? 1;
			stack = StackTo(f, stack, inv);
			InsertTo(f, stack, inv);
		}

		private int StackTo(Functions f, int stack, Inventory inv)
		{
			foreach (ItemData item in inv.m_inventory)
			{
				if (MatchItem(f, item))
				{
					int num = Mathf.Min(item.m_shared.m_maxStackSize - item.m_stack, stack);
					item.m_stack += num;
					stack -= num;
					if (stack <= 0)
					{
						break;
					}
				}
			}
			return stack;
		}

		private int InsertTo(Functions f, int stack, Inventory inv)
		{
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: 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_0299: 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_02ab: Unknown result type (might be due to invalid IL or missing references)
			ItemDrop val = default(ItemDrop);
			while (stack > 0)
			{
				int valueOrDefault = Prefab.Get(f).GetValueOrDefault();
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(valueOrDefault);
				if ((Object)(object)itemPrefab == (Object)null || !itemPrefab.TryGetComponent<ItemDrop>(ref val))
				{
					return stack;
				}
				ItemData val2 = val.m_itemData.Clone();
				val2.m_dropPrefab = itemPrefab;
				val2.m_quality = Quality?.Get(f) ?? 1;
				val2.m_variant = (Variant?.Get(f)).GetValueOrDefault();
				val2.m_crafterID = (CrafterID?.Get(f)).GetValueOrDefault();
				val2.m_crafterName = CrafterName?.Get(f) ?? "";
				val2.m_worldLevel = (WorldLevel?.Get(f)).GetValueOrDefault();
				val2.m_durability = Durability?.Get(f) ?? val2.GetMaxDurability(val2.m_quality);
				val2.m_equipped = Equipped?.GetBool(f) == true;
				val2.m_pickedUp = PickedUp?.GetBool(f) == true;
				if (CustomData != null)
				{
					val2.m_customData = CustomData.ToDictionary<KeyValuePair<string, IStringValue>, string, string>((KeyValuePair<string, IStringValue> x) => x.Key, (KeyValuePair<string, IStringValue> x) => x.Value.Get(f) ?? "");
				}
				int num = Mathf.Min(val2.m_shared.m_maxStackSize, stack);
				stack -= num;
				val2.m_stack = num;
				if (Position == "")
				{
					Vector2i val3 = inv.FindEmptySlot(true);
					if (val3.x < 0)
					{
						return stack;
					}
					val2.m_gridPos = val3;
					inv.m_inventory.Add(val2);
				}
				else
				{
					val2.m_gridPos = RolledPosition;
					inv.m_inventory.RemoveAll((ItemData x) => x.m_gridPos == RolledPosition);
					inv.m_inventory.Add(val2);
				}
			}
			return stack;
		}

		public void RemoveFrom(Functions f, Inventory inv)
		{
			int num = Stack?.Get(f) ?? 1;
			for (int num2 = inv.m_inventory.Count - 1; num2 >= 0; num2--)
			{
				ItemData val = inv.m_inventory[num2];
				if (MatchItem(f, val))
				{
					int num3 = Mathf.Min(val.m_stack, num);
					val.m_stack -= num3;
					num -= num3;
					if (num <= 0)
					{
						break;
					}
				}
			}
			inv.m_inventory.RemoveAll((ItemData x) => x.m_stack <= 0);
		}

		public bool Match(Functions f, Inventory inv)
		{
			ItemData val = FindMatch(f, inv);
			if (val == null)
			{
				return false;
			}
			inv.RemoveItem(val);
			return true;
		}

		private ItemData? FindMatch(Functions f, Inventory inv)
		{
			if (Position != "")
			{
				ItemData itemAt = inv.GetItemAt(RolledPosition.x, RolledPosition.y);
				if (itemAt == null)
				{
					return null;
				}
				IIntValue? stack = Stack;
				if (stack != null && stack.Match(f, itemAt.m_stack) == false)
				{
					return null;
				}
				if (MatchItem(f, itemAt))
				{
					return itemAt;
				}
			}
			foreach (ItemData item in inv.m_inventory)
			{
				IIntValue? stack2 = Stack;
				if ((stack2 == null || stack2.Match(f, item.m_stack) != false) && MatchItem(f, item))
				{
					return item;
				}
			}
			return null;
		}

		private bool MatchItem(Functions f, ItemData item)
		{
			GameObject dropPrefab = item.m_dropPrefab;
			string text = ((dropPrefab != null) ? ((Object)dropPrefab).name : null) ?? item.m_shared.m_name;
			bool? flag = Prefab.Match(f, StringExtensionMethods.GetStableHashCode(text));
			bool flag2 = false;
			if (flag == flag2)
			{
				return false;
			}
			IFloatValue? durability = Durability;
			if (durability != null)
			{
				flag = durability.Match(f, item.m_durability);
				flag2 = false;
				if (flag == flag2)
				{
					return false;
				}
			}
			IBoolValue? equipped = Equipped;
			if (equipped != null)
			{
				flag = equipped.Match(f, item.m_equipped);
				flag2 = false;
				if (flag == flag2)
				{
					return false;
				}
			}
			IIntValue? quality = Quality;
			if (quality != null)
			{
				flag = quality.Match(f, item.m_quality);
				flag2 = false;
				if (flag == flag2)
				{
					return false;
				}
			}
			IIntValue? variant = Variant;
			if (variant != null)
			{
				flag = variant.Match(f, item.m_variant);
				flag2 = false;
				if (flag == flag2)
				{