Decompiled source of LivingFactions v0.6.5

plugins/LivingFactions.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using LivingFactions.Core;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Splatform;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("LivingFactions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.6.5.0")]
[assembly: AssemblyInformationalVersion("0.6.5+806efa56b0ea6b054763243987473abc8f600177")]
[assembly: AssemblyProduct("LivingFactions")]
[assembly: AssemblyTitle("LivingFactions")]
[assembly: AssemblyVersion("0.6.5.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LivingFactions
{
	internal static class AttachPoints
	{
		private class Joint
		{
			public string Name;

			public string Holds;

			public Func<VisEquipment, Transform> Get;

			public Color Color;
		}

		private struct Part
		{
			public Mesh Mesh;

			public Matrix4x4 ToJoint;
		}

		private class Shape
		{
			public Bounds Box;

			public bool Exact;

			public int Triangles;

			public float Gap;

			public Vector3 Nearest;

			public int Long;

			public bool Slice;

			public Vector2 SliceMin;

			public Vector2 SliceMax;
		}

		private static readonly CultureInfo Inv = CultureInfo.InvariantCulture;

		private static readonly string[] AxisName = new string[3] { "X", "Y", "Z" };

		public const float FloatingGap = 0.05f;

		private static readonly Joint[] Joints = new Joint[9]
		{
			new Joint
			{
				Name = "rightHand",
				Get = (VisEquipment v) => v.m_rightHand,
				Color = Color.red,
				Holds = "one- and two-handed weapons, tools, torch"
			},
			new Joint
			{
				Name = "leftHand",
				Get = (VisEquipment v) => v.m_leftHand,
				Color = Color.blue,
				Holds = "shield, bow, left-hand weapons"
			},
			new Joint
			{
				Name = "helmet",
				Get = (VisEquipment v) => v.m_helmet,
				Color = Color.yellow,
				Holds = "helmet"
			},
			new Joint
			{
				Name = "backMelee",
				Get = (VisEquipment v) => v.m_backMelee,
				Color = Color.green,
				Holds = "sheathed one-handed weapon, torch"
			},
			new Joint
			{
				Name = "backTwohandedMelee",
				Get = (VisEquipment v) => v.m_backTwohandedMelee,
				Color = Color.cyan,
				Holds = "sheathed two-handed weapon"
			},
			new Joint
			{
				Name = "backShield",
				Get = (VisEquipment v) => v.m_backShield,
				Color = Color.magenta,
				Holds = "shield on the back"
			},
			new Joint
			{
				Name = "backBow",
				Get = (VisEquipment v) => v.m_backBow,
				Color = new Color(1f, 0.5f, 0f),
				Holds = "bow on the back"
			},
			new Joint
			{
				Name = "backTool",
				Get = (VisEquipment v) => v.m_backTool,
				Color = Color.white,
				Holds = "tool on the back, left-hand torch"
			},
			new Joint
			{
				Name = "backAtgeir",
				Get = (VisEquipment v) => v.m_backAtgeir,
				Color = Color.black,
				Holds = "atgeir on the back"
			}
		};

		private static readonly HumanBodyBones[] Bones;

		private static readonly Dictionary<int, Mesh> Readable;

		private static readonly List<GameObject> Markers;

		private static Mesh ReadableCopy(Mesh mesh)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mesh == (Object)null || mesh.isReadable)
			{
				return mesh;
			}
			if (Readable.TryGetValue(((Object)mesh).GetInstanceID(), out var value))
			{
				return value;
			}
			try
			{
				value = new Mesh
				{
					indexFormat = mesh.indexFormat
				};
				value.SetVertexBufferParams(mesh.vertexCount, mesh.GetVertexAttributes());
				for (int i = 0; i < mesh.vertexBufferCount; i++)
				{
					GraphicsBuffer vertexBuffer = mesh.GetVertexBuffer(i);
					try
					{
						byte[] array = new byte[vertexBuffer.stride * vertexBuffer.count];
						vertexBuffer.GetData((Array)array);
						value.SetVertexBufferData<byte>(array, 0, 0, array.Length, i, (MeshUpdateFlags)0);
					}
					finally
					{
						((IDisposable)vertexBuffer)?.Dispose();
					}
				}
				GraphicsBuffer indexBuffer = mesh.GetIndexBuffer();
				try
				{
					byte[] array2 = new byte[indexBuffer.stride * indexBuffer.count];
					indexBuffer.GetData((Array)array2);
					value.SetIndexBufferParams(indexBuffer.count, mesh.indexFormat);
					value.SetIndexBufferData<byte>(array2, 0, 0, array2.Length, (MeshUpdateFlags)0);
				}
				finally
				{
					((IDisposable)indexBuffer)?.Dispose();
				}
				value.subMeshCount = mesh.subMeshCount;
				for (int j = 0; j < mesh.subMeshCount; j++)
				{
					value.SetSubMesh(j, mesh.GetSubMesh(j), (MeshUpdateFlags)0);
				}
				if (value.vertices.Length == 0)
				{
					value = null;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[points] could not read mesh " + ((Object)mesh).name + ": " + ex.Message));
				value = null;
			}
			Readable[((Object)mesh).GetInstanceID()] = value;
			return value;
		}

		private static Vector3 ClosestOnTriangle(Vector3 a, Vector3 b, Vector3 c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = b - a;
			Vector3 val2 = c - a;
			Vector3 val3 = -a;
			float num = Vector3.Dot(val, val3);
			float num2 = Vector3.Dot(val2, val3);
			if (num <= 0f && num2 <= 0f)
			{
				return a;
			}
			Vector3 val4 = -b;
			float num3 = Vector3.Dot(val, val4);
			float num4 = Vector3.Dot(val2, val4);
			if (num3 >= 0f && num4 <= num3)
			{
				return b;
			}
			float num5 = num * num4 - num3 * num2;
			if (num5 <= 0f && num >= 0f && num3 <= 0f)
			{
				return a + val * (num / (num - num3));
			}
			Vector3 val5 = -c;
			float num6 = Vector3.Dot(val, val5);
			float num7 = Vector3.Dot(val2, val5);
			if (num7 >= 0f && num6 <= num7)
			{
				return c;
			}
			float num8 = num6 * num2 - num * num7;
			if (num8 <= 0f && num2 >= 0f && num7 <= 0f)
			{
				return a + val2 * (num2 / (num2 - num7));
			}
			float num9 = num3 * num7 - num6 * num4;
			if (num9 <= 0f && num4 - num3 >= 0f && num6 - num7 >= 0f)
			{
				return b + (c - b) * ((num4 - num3) / (num4 - num3 + (num6 - num7)));
			}
			float num10 = 1f / (num9 + num8 + num5);
			return a + val * (num8 * num10) + val2 * (num5 * num10);
		}

		private static Shape Measure(List<Part> parts)
		{
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: 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_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			if (parts.Count == 0)
			{
				return null;
			}
			Shape shape = new Shape
			{
				Exact = true,
				Gap = float.MaxValue
			};
			bool flag = true;
			List<Vector3[]> list = new List<Vector3[]>();
			List<int[]> list2 = new List<int[]>();
			foreach (Part part in parts)
			{
				Mesh val = ReadableCopy(part.Mesh);
				Matrix4x4 toJoint;
				if ((Object)(object)val != (Object)null)
				{
					Vector3[] vertices = val.vertices;
					for (int i = 0; i < vertices.Length; i++)
					{
						int num = i;
						toJoint = part.ToJoint;
						vertices[num] = ((Matrix4x4)(ref toJoint)).MultiplyPoint3x4(vertices[i]);
						if (flag)
						{
							shape.Box = new Bounds(vertices[i], Vector3.zero);
						}
						else
						{
							((Bounds)(ref shape.Box)).Encapsulate(vertices[i]);
						}
						flag = false;
					}
					int[] triangles = val.triangles;
					for (int j = 0; j + 2 < triangles.Length; j += 3)
					{
						Vector3 nearest = ClosestOnTriangle(vertices[triangles[j]], vertices[triangles[j + 1]], vertices[triangles[j + 2]]);
						if (((Vector3)(ref nearest)).magnitude < shape.Gap)
						{
							shape.Gap = ((Vector3)(ref nearest)).magnitude;
							shape.Nearest = nearest;
						}
					}
					shape.Triangles += triangles.Length / 3;
					list.Add(vertices);
					list2.Add(triangles);
					continue;
				}
				shape.Exact = false;
				Bounds bounds = part.Mesh.bounds;
				for (int k = 0; k < 8; k++)
				{
					toJoint = part.ToJoint;
					Vector3 val2 = ((Matrix4x4)(ref toJoint)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((k & 1) != 0) ? 1 : (-1)), (float)(((k & 2) != 0) ? 1 : (-1)), (float)(((k & 4) != 0) ? 1 : (-1)))));
					if (flag)
					{
						shape.Box = new Bounds(val2, Vector3.zero);
					}
					else
					{
						((Bounds)(ref shape.Box)).Encapsulate(val2);
					}
					flag = false;
				}
			}
			if (!shape.Exact)
			{
				Vector3 nearest2 = ((Bounds)(ref shape.Box)).ClosestPoint(Vector3.zero);
				shape.Gap = ((Vector3)(ref nearest2)).magnitude;
				shape.Nearest = nearest2;
			}
			Vector3 size = ((Bounds)(ref shape.Box)).size;
			shape.Long = ((!(size.x >= size.y) || !(size.x >= size.z)) ? ((size.y >= size.z) ? 1 : 2) : 0);
			int num2 = (shape.Long + 1) % 3;
			int num3 = (shape.Long + 2) % 3;
			Vector2 val6 = default(Vector2);
			for (int l = 0; l < list.Count; l++)
			{
				Vector3[] array = list[l];
				int[] array2 = list2[l];
				for (int m = 0; m + 2 < array2.Length; m += 3)
				{
					for (int n = 0; n < 3; n++)
					{
						Vector3 val3 = array[array2[m + n]];
						Vector3 val4 = array[array2[m + (n + 1) % 3]];
						float num4 = ((Vector3)(ref val3))[shape.Long];
						float num5 = ((Vector3)(ref val4))[shape.Long];
						if (num4 > 0f == num5 > 0f)
						{
							continue;
						}
						Vector3 val5 = val3 + (val4 - val3) * (num4 / (num4 - num5));
						((Vector2)(ref val6))..ctor(((Vector3)(ref val5))[num2], ((Vector3)(ref val5))[num3]);
						if (!(((Vector2)(ref val6)).magnitude > 0.3f))
						{
							if (!shape.Slice)
							{
								shape.SliceMin = (shape.SliceMax = val6);
								shape.Slice = true;
							}
							else
							{
								shape.SliceMin = Vector2.Min(shape.SliceMin, val6);
								shape.SliceMax = Vector2.Max(shape.SliceMax, val6);
							}
						}
					}
				}
			}
			return shape;
		}

		private static string F(float v)
		{
			return v.ToString("+0.00;-0.00", Inv);
		}

		private static string V(Vector3 v)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			return "(" + F(v.x) + ", " + F(v.y) + ", " + F(v.z) + ")";
		}

		private static string Describe(Shape s, bool handHeld, string indent)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//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_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: 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)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			if (s == null)
			{
				return indent + "no visible model\n";
			}
			StringBuilder stringBuilder = new StringBuilder();
			Vector3 min = ((Bounds)(ref s.Box)).min;
			Vector3 max = ((Bounds)(ref s.Box)).max;
			stringBuilder.AppendLine(indent + "box   x " + F(min.x) + " .. " + F(max.x) + "   y " + F(min.y) + " .. " + F(max.y) + "   z " + F(min.z) + " .. " + F(max.z) + (s.Exact ? ("   (" + s.Triangles + " triangles)") : "   (boxes only, mesh unreadable)"));
			int num = s.Long;
			int num2 = (num + 1) % 3;
			int num3 = (num + 2) % 3;
			Vector3 val = ((Bounds)(ref s.Box)).size;
			float num4 = ((Vector3)(ref val))[num];
			float num5 = ((num4 > 0f) ? ((0f - ((Vector3)(ref min))[num]) / num4) : 0f);
			string[] obj = new string[17]
			{
				indent,
				"long axis ",
				AxisName[num],
				", ",
				num4.ToString("0.00", Inv),
				" m; the joint is ",
				(num5 * 100f).ToString("0", Inv),
				"% of the way from the -",
				AxisName[num],
				" end; the bulk sits ",
				null,
				null,
				null,
				null,
				null,
				null,
				null
			};
			val = ((Bounds)(ref s.Box)).center;
			obj[10] = F(((Vector3)(ref val))[num2]);
			obj[11] = " along ";
			obj[12] = AxisName[num2];
			obj[13] = " and ";
			val = ((Bounds)(ref s.Box)).center;
			obj[14] = F(((Vector3)(ref val))[num3]);
			obj[15] = " along ";
			obj[16] = AxisName[num3];
			stringBuilder.AppendLine(string.Concat(obj));
			stringBuilder.Append(indent + "nearest surface " + s.Gap.ToString("0.00", Inv) + " m from the joint, at " + V(s.Nearest));
			if (handHeld)
			{
				stringBuilder.Append((s.Gap > 0.05f) ? "   <-- NOT IN THE HAND" : "   ok");
			}
			stringBuilder.AppendLine();
			if (s.Slice)
			{
				Vector2 val2 = (s.SliceMin + s.SliceMax) * 0.5f;
				Vector2 val3 = s.SliceMax - s.SliceMin;
				stringBuilder.Append(indent + "what the hand closes around (cut across " + AxisName[num] + " at the joint): centre " + AxisName[num2] + " " + F(val2.x) + ", " + AxisName[num3] + " " + F(val2.y) + ", " + val3.x.ToString("0.00", Inv) + " x " + val3.y.ToString("0.00", Inv) + " m");
				if (handHeld && ((Vector2)(ref val2)).magnitude > 0.02f)
				{
					stringBuilder.Append("   -> move the model " + AxisName[num2] + " " + F(0f - val2.x) + ", " + AxisName[num3] + " " + F(0f - val2.y));
				}
				stringBuilder.AppendLine();
			}
			else if (s.Exact)
			{
				stringBuilder.AppendLine(indent + "nothing of the model crosses the joint along " + AxisName[num] + ": the joint is off the end of it or beside it");
			}
			return stringBuilder.ToString();
		}

		private static bool IsWearable(ItemType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected I4, but got Unknown
			switch (type - 3)
			{
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
			case 8:
			case 11:
			case 12:
			case 14:
			case 15:
			case 16:
			case 17:
			case 19:
			case 21:
				return true;
			default:
				return false;
			}
		}

		private static bool IsHandHeld(ItemType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			if ((int)type != 3 && (int)type != 14 && (int)type != 22 && (int)type != 4 && (int)type != 15 && (int)type != 19)
			{
				return (int)type == 20;
			}
			return true;
		}

		private static void JointsFor(SharedData shared, out string worn, out string back)
		{
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected I4, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			//IL_005e: 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_008b: Expected I4, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			ItemType itemType = shared.m_itemType;
			ItemType val = (((int)shared.m_attachOverride != 0) ? shared.m_attachOverride : itemType);
			worn = (((int)itemType == 6) ? "helmet" : (((int)itemType == 5 || (int)itemType == 4 || (int)itemType == 22) ? "leftHand" : (IsHandHeld(itemType) ? "rightHand" : null)));
			switch (val - 3)
			{
			default:
				switch (val - 14)
				{
				case 1:
					break;
				case 5:
					back = "backTool";
					return;
				case 6:
					back = "backAtgeir";
					return;
				case 0:
				case 8:
					back = "backTwohandedMelee";
					return;
				default:
					back = null;
					return;
				}
				goto case 0;
			case 0:
				back = "backMelee";
				break;
			case 1:
				back = "backBow";
				break;
			case 2:
				back = "backShield";
				break;
			}
		}

		private static VisEquipment ReferenceBody()
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				return ((Component)Player.m_localPlayer).GetComponent<VisEquipment>();
			}
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("Player") : null);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.GetComponent<VisEquipment>();
		}

		private static float JointScale(string joint)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			VisEquipment val = ReferenceBody();
			Joint joint2 = Joints.FirstOrDefault((Joint x) => x.Name == joint);
			Transform val2 = (((Object)(object)val != (Object)null && joint2 != null) ? joint2.Get(val) : null);
			if (!((Object)(object)val2 != (Object)null))
			{
				return 1f;
			}
			return val2.lossyScale.x;
		}

		private static List<Part> PrefabParts(GameObject prefab, bool onBack, string joint, out string node)
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			List<Part> list = new List<Part>();
			node = null;
			Transform val = null;
			for (int i = 0; i < prefab.transform.childCount; i++)
			{
				Transform child = prefab.transform.GetChild(i);
				if (onBack && ((Object)child).name == "attach_back")
				{
					val = child;
					break;
				}
				if (((Object)child).name == "attach" || (!onBack && ((Object)child).name == "attach_skin"))
				{
					val = child;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return list;
			}
			node = ((Object)val).name;
			if (((Object)val).name == "attach_skin")
			{
				return list;
			}
			Transform val2 = prefab.transform.Find("equipoffset");
			Matrix4x4 val3 = Matrix4x4.TRS(((Object)(object)val2 != (Object)null) ? (val2.position * JointScale(joint)) : Vector3.zero, ((Object)(object)val2 != (Object)null) ? val2.rotation : Quaternion.identity, val.localScale) * val.worldToLocalMatrix;
			if ((Object)(object)val2 != (Object)null)
			{
				node += " + equipoffset";
			}
			MeshFilter[] componentsInChildren = ((Component)val).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val4 in componentsInChildren)
			{
				MeshRenderer component = ((Component)val4).GetComponent<MeshRenderer>();
				if (!((Object)(object)val4.sharedMesh == (Object)null) && !((Object)(object)component == (Object)null) && ((Renderer)component).enabled && Shown(((Component)val4).transform, val))
				{
					list.Add(new Part
					{
						Mesh = val4.sharedMesh,
						ToJoint = val3 * ((Component)val4).transform.localToWorldMatrix
					});
				}
			}
			return list;
		}

		private static bool Shown(Transform t, Transform root)
		{
			while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
			{
				if (!((Component)t).gameObject.activeSelf)
				{
					return false;
				}
				t = t.parent;
			}
			return true;
		}

		public static string Item(string name)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(name) : null);
			ItemDrop val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return name + ": no such item";
			}
			SharedData shared = val.m_itemData.m_shared;
			JointsFor(shared, out var worn, out var back);
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine(name + " (" + ((object)Unsafe.As<ItemType, ItemType>(ref shared.m_itemType)/*cast due to .constrained prefix*/).ToString() + (((int)shared.m_attachOverride != 0) ? (", put away as " + ((object)Unsafe.As<ItemType, ItemType>(ref shared.m_attachOverride)/*cast due to .constrained prefix*/).ToString()) : "") + ")");
			stringBuilder.AppendLine("  children of the prefab: " + string.Join(", ", from i in Enumerable.Range(0, prefab.transform.childCount)
				select ((Object)prefab.transform.GetChild(i)).name));
			List<Part> parts = PrefabParts(prefab, onBack: false, worn, out var node);
			if (node == "attach_skin")
			{
				SkinnedMeshRenderer[] componentsInChildren = ((Component)prefab.transform.Find("attach_skin")).GetComponentsInChildren<SkinnedMeshRenderer>(true);
				stringBuilder.AppendLine("  worn: skinned onto the body's own bones (" + componentsInChildren.Length + " skinned mesh(es), " + componentsInChildren.Sum((SkinnedMeshRenderer r) => r.bones.Length) + " bone slots) - no attach point, it follows the skeleton");
			}
			else if (node == null)
			{
				stringBuilder.AppendLine("  worn: no `attach` child - nothing is shown (the body's material or texture may change instead)");
			}
			else
			{
				stringBuilder.AppendLine("  worn on " + (worn ?? "the body") + " (`" + node + "`):");
				stringBuilder.Append(Describe(Measure(parts), IsHandHeld(shared.m_itemType), "    "));
			}
			if (back != null)
			{
				parts = PrefabParts(prefab, onBack: true, back, out node);
				if (node != null && node != "attach_skin")
				{
					stringBuilder.AppendLine("  put away on " + back + " (`" + node + "`):");
					stringBuilder.Append(Describe(Measure(parts), handHeld: false, "    "));
				}
			}
			return stringBuilder.ToString().TrimEnd(Array.Empty<char>());
		}

		public static string All()
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return "no item database yet";
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("item\ttype\tjoint\tnode\texact\tlong axis\tlength\tjoint at % of length\tgap\tmin x\tmax x\tmin y\tmax y\tmin z\tmax z\tcut centre u\tcut centre w\tcut size u\tcut size w");
			int num = 0;
			int num2 = 0;
			foreach (GameObject item in ObjectDB.instance.m_items.OrderBy((GameObject p) => ((Object)p).name))
			{
				ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val == (Object)null || !IsWearable(val.m_itemData.m_shared.m_itemType))
				{
					continue;
				}
				JointsFor(val.m_itemData.m_shared, out var worn, out var _);
				string node;
				Shape shape = Measure(PrefabParts(item, onBack: false, worn, out node));
				stringBuilder.Append(((Object)item).name + "\t" + ((object)Unsafe.As<ItemType, ItemType>(ref val.m_itemData.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString() + "\t" + (worn ?? "body") + "\t" + (node ?? "-"));
				if (shape != null)
				{
					Vector3 min = ((Bounds)(ref shape.Box)).min;
					Vector3 max = ((Bounds)(ref shape.Box)).max;
					Vector3 size = ((Bounds)(ref shape.Box)).size;
					float num3 = ((Vector3)(ref size))[shape.Long];
					stringBuilder.Append("\t" + (shape.Exact ? "yes" : "no") + "\t" + AxisName[shape.Long] + "\t" + num3.ToString("0.00", Inv) + "\t" + ((num3 > 0f) ? ((0f - ((Vector3)(ref min))[shape.Long]) / num3 * 100f) : 0f).ToString("0", Inv) + "\t" + shape.Gap.ToString("0.000", Inv) + "\t" + F(min.x) + "\t" + F(max.x) + "\t" + F(min.y) + "\t" + F(max.y) + "\t" + F(min.z) + "\t" + F(max.z));
					if (shape.Slice)
					{
						Vector2 val2 = (shape.SliceMin + shape.SliceMax) * 0.5f;
						Vector2 val3 = shape.SliceMax - shape.SliceMin;
						stringBuilder.Append("\t" + F(val2.x) + "\t" + F(val2.y) + "\t" + val3.x.ToString("0.00", Inv) + "\t" + val3.y.ToString("0.00", Inv));
					}
					if (IsHandHeld(val.m_itemData.m_shared.m_itemType) && shape.Gap > 0.05f)
					{
						num2++;
					}
				}
				stringBuilder.AppendLine();
				num++;
			}
			string text = Path.Combine(SimHost.DataDir, "points_items.tsv");
			File.WriteAllText(text, stringBuilder.ToString());
			return num + " wearable items, " + num2 + " hand-held ones further than " + 0.05f.ToString("0.00", Inv) + " m from the palm -> " + text;
		}

		private static Matrix4x4 Metric(Transform joint)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = Matrix4x4.TRS(joint.position, joint.rotation, Vector3.one);
			return ((Matrix4x4)(ref val)).inverse;
		}

		private static List<Part> LiveParts(GameObject model, Transform joint)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			List<Part> list = new List<Part>();
			Matrix4x4 val = Metric(joint);
			MeshFilter[] componentsInChildren = model.GetComponentsInChildren<MeshFilter>();
			foreach (MeshFilter val2 in componentsInChildren)
			{
				MeshRenderer component = ((Component)val2).GetComponent<MeshRenderer>();
				if (!((Object)(object)val2.sharedMesh == (Object)null) && !((Object)(object)component == (Object)null) && ((Renderer)component).enabled)
				{
					list.Add(new Part
					{
						Mesh = val2.sharedMesh,
						ToJoint = val * ((Component)val2).transform.localToWorldMatrix
					});
				}
			}
			return list;
		}

		private static string BonePath(Transform t, Transform root)
		{
			List<string> list = new List<string>();
			int num = 0;
			while (num < 3 && (Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
			{
				list.Insert(0, ((Object)t).name);
				num++;
				t = t.parent;
			}
			return string.Join("/", list);
		}

		public unsafe static string Character()
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			VisEquipment val = (((Object)(object)localPlayer != (Object)null) ? ((Component)localPlayer).GetComponent<VisEquipment>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return "no player";
			}
			StringBuilder stringBuilder = new StringBuilder();
			Transform transform = ((Component)localPlayer).transform;
			stringBuilder.AppendLine("Joints equipment hangs on. Position is in the character's own space in the current pose: x to their right, y up from the feet, z forward. Metres.");
			Joint[] joints = Joints;
			foreach (Joint joint in joints)
			{
				Transform val2 = joint.Get(val);
				if ((Object)(object)val2 == (Object)null)
				{
					stringBuilder.AppendLine("  " + joint.Name.PadRight(20) + "missing");
					continue;
				}
				stringBuilder.AppendLine("  " + joint.Name.PadRight(20) + V(transform.InverseTransformPoint(val2.position)) + "  scale " + val2.lossyScale.x.ToString("0.###", Inv) + "  " + BonePath(val2, transform) + "  - " + joint.Holds);
			}
			Animator componentInChildren = ((Component)localPlayer).GetComponentInChildren<Animator>();
			if ((Object)(object)componentInChildren != (Object)null && componentInChildren.isHuman)
			{
				stringBuilder.AppendLine("Skeleton (skinned armour, capes and belts follow these):");
				HumanBodyBones[] bones = Bones;
				for (int i = 0; i < bones.Length; i++)
				{
					HumanBodyBones val3 = bones[i];
					Transform boneTransform = componentInChildren.GetBoneTransform(val3);
					if ((Object)(object)boneTransform != (Object)null)
					{
						stringBuilder.AppendLine("  " + ((object)(*(HumanBodyBones*)(&val3))/*cast due to .constrained prefix*/).ToString().PadRight(20) + V(transform.InverseTransformPoint(boneTransform.position)) + "  " + ((Object)boneTransform).name);
					}
				}
			}
			stringBuilder.Append(Worn());
			return stringBuilder.ToString().TrimEnd(Array.Empty<char>());
		}

		public static string Worn()
		{
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			VisEquipment vis = (((Object)(object)localPlayer != (Object)null) ? ((Component)localPlayer).GetComponent<VisEquipment>() : null);
			if ((Object)(object)vis == (Object)null)
			{
				return "no player";
			}
			Traverse val = Traverse.Create((object)localPlayer);
			string[,] array = new string[5, 3]
			{
				{ "m_rightItemInstance", "rightHand", "m_rightItem" },
				{ "m_leftItemInstance", "leftHand", "m_leftItem" },
				{ "m_helmetItemInstance", "helmet", "m_helmetItem" },
				{ "m_rightBackItemInstance", "", "m_hiddenRightItem" },
				{ "m_leftBackItemInstance", "", "m_hiddenLeftItem" }
			};
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < array.GetLength(0); i++)
			{
				object? value = AccessTools.Field(typeof(VisEquipment), array[i, 0]).GetValue(vis);
				GameObject val2 = (GameObject)((value is GameObject) ? value : null);
				if (!((Object)(object)val2 == (Object)null))
				{
					Transform joint = val2.transform.parent;
					Joint joint2 = Joints.FirstOrDefault((Joint j) => (Object)(object)j.Get(vis) == (Object)(object)joint);
					ItemData value2 = val.Field(array[i, 2]).GetValue<ItemData>();
					string text = ((value2 != null && (Object)(object)value2.m_dropPrefab != (Object)null) ? ((Object)value2.m_dropPrefab).name : ((Object)val2).name);
					bool handHeld = array[i, 1].EndsWith("Hand") && value2 != null && IsHandHeld(value2.m_shared.m_itemType);
					stringBuilder.AppendLine("worn now: " + text + " on " + ((joint2 != null) ? joint2.Name : (((Object)(object)joint != (Object)null) ? ((Object)joint).name : "?")));
					stringBuilder.Append(Describe(Measure(LiveParts(val2, joint)), handHeld, "    "));
				}
			}
			if (stringBuilder.Length != 0)
			{
				return stringBuilder.ToString();
			}
			return "nothing held or carried\n";
		}

		public static float HandGap(out string item)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			item = null;
			Player localPlayer = Player.m_localPlayer;
			VisEquipment val = (((Object)(object)localPlayer != (Object)null) ? ((Component)localPlayer).GetComponent<VisEquipment>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return -1f;
			}
			float num = -1f;
			Traverse val2 = Traverse.Create((object)localPlayer);
			string[][] array = new string[2][]
			{
				new string[2] { "m_rightItemInstance", "m_rightItem" },
				new string[2] { "m_leftItemInstance", "m_leftItem" }
			};
			foreach (string[] array2 in array)
			{
				object? value = AccessTools.Field(typeof(VisEquipment), array2[0]).GetValue(val);
				GameObject val3 = (GameObject)((value is GameObject) ? value : null);
				ItemData value2 = val2.Field(array2[1]).GetValue<ItemData>();
				if (!((Object)(object)val3 == (Object)null) && value2 != null && IsHandHeld(value2.m_shared.m_itemType))
				{
					Shape shape = Measure(LiveParts(val3, val3.transform.parent));
					if (shape != null && shape.Gap > num)
					{
						num = shape.Gap;
						item = (((Object)(object)value2.m_dropPrefab != (Object)null) ? ((Object)value2.m_dropPrefab).name : value2.m_shared.m_name);
					}
				}
			}
			return num;
		}

		public static string Marks(bool on)
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject marker in Markers)
			{
				if ((Object)(object)marker != (Object)null)
				{
					Object.Destroy((Object)(object)marker);
				}
			}
			Markers.Clear();
			if (!on)
			{
				return "markers off";
			}
			Player localPlayer = Player.m_localPlayer;
			VisEquipment val = (((Object)(object)localPlayer != (Object)null) ? ((Component)localPlayer).GetComponent<VisEquipment>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return "no player";
			}
			Shader val2 = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color") ?? Shader.Find("Standard");
			Joint[] joints = Joints;
			foreach (Joint joint in joints)
			{
				Transform val3 = joint.Get(val);
				if (!((Object)(object)val3 == (Object)null))
				{
					GameObject val4 = GameObject.CreatePrimitive((PrimitiveType)0);
					((Object)val4).name = "lf_mark_" + joint.Name;
					Object.Destroy((Object)(object)val4.GetComponent<Collider>());
					val4.transform.SetParent(val3, false);
					val4.transform.localPosition = Vector3.zero;
					val4.transform.localScale = Vector3.one * (0.04f / Mathf.Max(0.0001f, val3.lossyScale.x));
					val4.layer = ((Component)val3).gameObject.layer;
					if ((Object)(object)val2 != (Object)null)
					{
						Material val5 = new Material(val2);
						val5.color = joint.Color;
						((Renderer)val4.GetComponent<MeshRenderer>()).sharedMaterial = val5;
					}
					Markers.Add(val4);
				}
			}
			return Markers.Count + " markers: " + string.Join(", ", Joints.Select((Joint j) => j.Name + " " + ColorName(j.Color)));
		}

		private static string ColorName(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (c == Color.red)
			{
				return "red";
			}
			if (c == Color.blue)
			{
				return "blue";
			}
			if (c == Color.yellow)
			{
				return "yellow";
			}
			if (c == Color.green)
			{
				return "green";
			}
			if (c == Color.cyan)
			{
				return "cyan";
			}
			if (c == Color.magenta)
			{
				return "magenta";
			}
			if (c == Color.white)
			{
				return "white";
			}
			if (c == Color.black)
			{
				return "black";
			}
			return "orange";
		}

		public static string Command(string[] a)
		{
			if (a.Length < 2)
			{
				string text = Character();
				File.WriteAllText(Path.Combine(SimHost.DataDir, "points_character.txt"), text + "\n");
				return text;
			}
			if (a[1] == "all")
			{
				return All();
			}
			return string.Join("\n", a.Skip(1).Select(Item));
		}

		static AttachPoints()
		{
			//IL_005d: 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)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			HumanBodyBones[] array = new HumanBodyBones[19];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			Bones = (HumanBodyBones[])(object)array;
			Readable = new Dictionary<int, Mesh>();
			Markers = new List<GameObject>();
		}
	}
	internal struct PieceSpec
	{
		public string Prefab;

		public Vector3 Pos;

		public float Yaw;
	}
	internal class BuildStyle
	{
		public string Roof26 = "wood_roof";

		public string Roof45 = "wood_roof_45";

		public string RoofTop26 = "wood_roof_top";

		public string RoofTop45 = "wood_roof_top_45";

		public string Banner = "piece_banner01";

		public string Id = "wood";

		public int WallKind;

		public string Door = "wood_door";

		public string Floor = "wood_floor";

		public float FloorDrop;

		public string Pole = "wood_pole_log";

		public float PoleY = 1f;

		public bool Steep = true;
	}
	internal static class Blueprints
	{
		private class Builder
		{
			public readonly List<PieceSpec> Pieces = new List<PieceSpec>();

			public readonly BuildStyle Style;

			public Builder(BuildStyle style)
			{
				Style = style;
			}

			public void Add(string prefab, float x, float y, float z, float yaw = 0f)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				Pieces.Add(new PieceSpec
				{
					Prefab = prefab,
					Pos = new Vector3(x, y, z),
					Yaw = yaw
				});
			}

			public void Floor(int nx, int nz)
			{
				for (int i = 0; i < nz; i++)
				{
					for (int j = 0; j < nx; j++)
					{
						Add(Style.Floor, -nx + 1 + 2 * j, 0.25f + Style.FloorDrop, -nz + 1 + 2 * i);
					}
				}
			}

			public void CornerPoles(int nx, int nz, bool tall)
			{
				int[] array = new int[2] { -1, 1 };
				foreach (int num in array)
				{
					int[] array2 = new int[2] { -1, 1 };
					foreach (int num2 in array2)
					{
						Add(Style.Pole, num * nx, 0.37f + Style.PoleY, num2 * nz);
						if (tall)
						{
							Add("wood_pole", num * nx, 2.87f, num2 * nz);
						}
					}
				}
			}

			private void Wall(float x, float z, float yaw, bool door)
			{
				if (door)
				{
					if (Style.Door != null)
					{
						Add(Style.Door, x, 1.37f, z, yaw);
					}
					else if (Style.WallKind == 1)
					{
						Add("stone_arch", x, 1.87f, z, yaw);
					}
				}
				else if (Style.WallKind == 1)
				{
					Add("stone_wall_2x1", x, 0.87f, z, yaw);
					Add("stone_wall_2x1", x, 1.87f, z, yaw);
				}
				else if (Style.WallKind == 2)
				{
					Add("goblin_woodwall_2m", x, 0.37f, z, yaw);
				}
				else
				{
					Add("woodwall", x, 1.37f, z, yaw);
				}
			}

			public void Walls(int nx, int nz, bool tall, int doorBay, bool openFront = false)
			{
				for (int i = 0; i < nx; i++)
				{
					float x = -nx + 1 + 2 * i;
					Wall(x, -nz, 180f, door: false);
					if (!openFront)
					{
						Wall(x, nz, 0f, i == doorBay);
					}
				}
				for (int j = 0; j < nz; j++)
				{
					float z = -nz + 1 + 2 * j;
					Wall(-nx, z, 90f, door: false);
					Wall(nx, z, 90f, door: false);
				}
				if (tall)
				{
					float y = 2.87f;
					for (int k = 0; k < nx; k++)
					{
						float x2 = -nx + 1 + 2 * k;
						Add("wood_wall_half", x2, y, -nz, 180f);
						Add("wood_wall_half", x2, y, nz);
					}
					for (int l = 0; l < nz; l++)
					{
						float z2 = -nz + 1 + 2 * l;
						Add("wood_wall_half", -nx, y, z2, 90f);
						Add("wood_wall_half", nx, y, z2, 90f);
					}
				}
			}

			public void GableRoof(int nx, int nz, float wallTop, bool steep)
			{
				string prefab = (steep ? "wood_wall_roof_45" : "wood_wall_roof");
				float num = (steep ? 2f : 1f);
				int[] array = new int[2] { -1, 1 };
				for (int i = 0; i < array.Length; i++)
				{
					float x = array[i] * nx;
					Add(prefab, x, wallTop, nz - 1, 90f);
					Add(prefab, x, wallTop, -nz + 1, -90f);
					if (nz == 3)
					{
						if (steep)
						{
							Add("woodwall", x, wallTop + 1f, 0f, 90f);
						}
						else
						{
							Add("wood_wall_half", x, wallTop + 0.5f, 0f, 90f);
						}
						Add(steep ? "wood_wall_roof_top_45" : "wood_wall_roof_top", x, wallTop + num, 0f, 90f);
					}
				}
				float y = (steep ? (wallTop + 1f) : wallTop);
				for (int j = 0; j < nx; j++)
				{
					float x2 = -nx + 1 + 2 * j;
					Add(steep ? Style.Roof45 : Style.Roof26, x2, y, nz - 1);
					Add(steep ? Style.Roof45 : Style.Roof26, x2, y, -nz + 1, 180f);
					if (nz == 3)
					{
						Add(steep ? Style.RoofTop45 : Style.RoofTop26, x2, wallTop + num, 0f);
					}
				}
			}

			public void LeanTo(int nx, float cx, float cz)
			{
				float y = 1.37f;
				for (int i = 0; i < nx; i++)
				{
					float x = cx - (float)nx + 1f + (float)(2 * i);
					Add("wood_floor", x, 0.25f, cz);
				}
				int[] array = new int[2] { -1, 1 };
				foreach (int num in array)
				{
					Add("wood_pole_log", cx + (float)(num * nx), y, cz + 1f);
					Add("wood_pole", cx + (float)(num * nx), 2.87f, cz + 1f);
				}
				for (int k = 0; k < nx; k++)
				{
					float x2 = cx - (float)nx + 1f + (float)(2 * k);
					Add("woodwall", x2, y, cz - 1f, 180f);
				}
				array = new int[2] { -1, 1 };
				foreach (int num2 in array)
				{
					Add("woodwall", cx + (float)(num2 * nx), y, cz, 90f);
					Add("wood_wall_roof", cx + (float)(num2 * nx), 2.37f, cz, -90f);
				}
				for (int l = 0; l < nx; l++)
				{
					Add(Style.Roof26, cx - (float)nx + 1f + (float)(2 * l), 2.37f, cz, 180f);
				}
			}
		}

		private const float FloorY = 0.25f;

		private const float WallBase = 0.37f;

		private static readonly Dictionary<string, List<PieceSpec>> Cache = new Dictionary<string, List<PieceSpec>>();

		public static BuildStyle StyleFor(Faction faction, Tier tier)
		{
			BuildStyle buildStyle = new BuildStyle();
			buildStyle.Banner = "piece_banner" + (1 + faction.ColorIndex % 11).ToString("00");
			string text = Defs.Culture(faction.CultureId).Group;
			switch (text)
			{
			case "draugr":
				buildStyle.Id = "stone";
				buildStyle.WallKind = 1;
				buildStyle.Door = null;
				buildStyle.Floor = "stone_floor_2x2";
				buildStyle.FloorDrop = -0.4f;
				buildStyle.Pole = "stone_pillar";
				break;
			case "fuling":
				buildStyle.Id = "goblin";
				buildStyle.WallKind = 2;
				buildStyle.Door = null;
				buildStyle.Pole = "goblin_pole";
				buildStyle.PoleY = 0.4f;
				break;
			case "greydwarf":
				buildStyle.Id = "open";
				buildStyle.Door = null;
				break;
			}
			if (text == "dvergr")
			{
				buildStyle.Id = "dark";
				buildStyle.Roof26 = "darkwood_roof";
				buildStyle.Roof45 = "darkwood_roof_45";
				buildStyle.RoofTop26 = "darkwood_roof_top";
				buildStyle.RoofTop45 = "darkwood_roof_top_45";
			}
			return buildStyle;
		}

		public static float Radius(BuildingKind kind)
		{
			return kind switch
			{
				BuildingKind.Campfire => 5.5f, 
				BuildingKind.Hut => 4f, 
				BuildingKind.House => 5f, 
				BuildingKind.Longhouse => 6.5f, 
				BuildingKind.GreatHall => 8f, 
				BuildingKind.Farm => 6.5f, 
				BuildingKind.Watchtower => 4f, 
				BuildingKind.Palisade => 0f, 
				_ => 5f, 
			};
		}

		public static List<PieceSpec> Get(BuildingKind kind, BuildStyle style, Biome biome, int variant)
		{
			string key = kind.ToString() + "|" + style.Id + "|" + style.Banner + "|" + biome.ToString() + "|" + (variant & 3);
			if (Cache.TryGetValue(key, out var value))
			{
				return value;
			}
			Builder builder = new Builder(style);
			switch (kind)
			{
			case BuildingKind.Campfire:
				Campfire(builder);
				break;
			case BuildingKind.Hut:
				Hut(builder, variant);
				break;
			case BuildingKind.House:
				House(builder, variant);
				break;
			case BuildingKind.Longhouse:
				Longhouse(builder);
				break;
			case BuildingKind.Storehouse:
				Storehouse(builder);
				break;
			case BuildingKind.Woodcutter:
				Woodcutter(builder);
				break;
			case BuildingKind.Stonecutter:
				Stonecutter(builder);
				break;
			case BuildingKind.Farm:
				Farm(builder, biome);
				break;
			case BuildingKind.HunterLodge:
				HunterLodge(builder);
				break;
			case BuildingKind.Smithy:
				Smithy(builder);
				break;
			case BuildingKind.Watchtower:
				Watchtower(builder);
				break;
			case BuildingKind.Market:
				Market(builder);
				break;
			case BuildingKind.GreatHall:
				GreatHall(builder);
				break;
			case BuildingKind.Palisade:
				Palisade(builder);
				break;
			}
			Cache[key] = builder.Pieces;
			return builder.Pieces;
		}

		private static void Campfire(Builder b)
		{
			b.Add("fire_pit_haldor", 0f, 0f, 0f);
			for (int i = 0; i < 3; i++)
			{
				float num = ((float)i * 120f + 60f) * ((float)Math.PI / 180f);
				b.Add("piece_logbench01", Mathf.Sin(num) * 2.6f, 0.15f, Mathf.Cos(num) * 2.6f, (float)i * 120f + 60f);
			}
			b.Add("wood_pole_log_4", 3.6f, 2f, -3.6f);
			b.Add(b.Style.Banner, 3.95f, 4.1f, -3.6f);
			b.Add("wood_stack", -3.8f, 0.55f, -3.2f, 30f);
		}

		private static void Hut(Builder b, int variant)
		{
			int num = variant & 1;
			b.Floor(2, 2);
			b.CornerPoles(2, 2, tall: true);
			b.Walls(2, 2, tall: true, num);
			b.GableRoof(2, 2, 3.37f, b.Style.Steep);
			b.Add("bed", (num == 0) ? 0.75f : (-0.75f), 0.37f, -0.05f);
			b.Add("piece_walltorch", (num == 0) ? 1f : (-1f), 1.97f, 1.7f, 180f);
			b.Add("piece_chest_wood", (num == 0) ? (-1.2f) : 1.2f, 0.37f, -0.9f, (num == 0) ? 90f : (-90f));
		}

		private static void House(Builder b, int variant)
		{
			b.Floor(3, 2);
			b.CornerPoles(3, 2, tall: true);
			b.Walls(3, 2, tall: true, 1);
			b.GableRoof(3, 2, 3.37f, b.Style.Steep);
			b.Add("bed", -1.75f, 0.37f, -0.05f);
			b.Add("piece_table", 1.9f, 0.37f, -1.1f);
			b.Add("piece_chair", 1.3f, 0.37f, -0.1f);
			b.Add("piece_chair", 2.3f, 0.37f, -0.1f);
			b.Add("piece_chest_wood", 2.1f, 0.37f, 1.35f, 180f);
			b.Add("piece_walltorch", 0f, 1.97f, -1.75f);
		}

		private static void Longhouse(Builder b)
		{
			b.Floor(4, 3);
			b.CornerPoles(4, 3, tall: true);
			b.Walls(4, 3, tall: true, 2);
			b.GableRoof(4, 3, 3.37f, steep: true);
			b.Add("fire_pit_haldor", 0f, 0.37f, 0f);
			b.Add("bed", -2.85f, 0.37f, -1f);
			b.Add("bed", -2.85f, 0.37f, 0.9f, 180f);
			b.Add("bed", 2.85f, 0.37f, -1f);
			b.Add("piece_table", 0f, 0.37f, -2.1f);
			b.Add("piece_bench01", 0f, 0.37f, -1.3f, 180f);
			b.Add("piece_chest_wood", 2.9f, 0.37f, 2.3f, 180f);
			b.Add("piece_walltorch", -1f, 1.97f, -2.75f);
			b.Add("piece_walltorch", 1f, 1.97f, -2.75f);
			b.Add(b.Style.Banner, 2.3f, 3.77f, 3.25f, 90f);
		}

		private static void Storehouse(Builder b)
		{
			b.Floor(3, 2);
			float y = 1.37f;
			int[] array = new int[3] { -3, 0, 3 };
			foreach (int num in array)
			{
				b.Add("wood_pole_log", num, y, 2f);
				b.Add("wood_pole", num, 2.87f, 2f);
				b.Add("wood_pole_log", num, y, -2f);
			}
			b.Walls(3, 2, tall: true, -1, openFront: true);
			b.GableRoof(3, 2, 3.37f, steep: false);
			b.Add("piece_chest_wood", -1.9f, 0.37f, -1.3f);
			b.Add("piece_chest_wood", 0f, 0.37f, -1.3f);
			b.Add("piece_chest_wood", 1.9f, 0.37f, -1.3f);
			b.Add("wood_stack", -4.5f, 0.6f, 0.4f);
			b.Add("stone_pile", 4.3f, 0.2f, 0.3f);
		}

		private static void Woodcutter(Builder b)
		{
			b.LeanTo(2, 0f, -1.5f);
			b.Add("wood_stack", -1f, 0.97f, -1.6f, 90f);
			b.Add("wood_core_stack", 1f, 0.52f, -1.6f);
			b.Add("wood_stack", -3.4f, 0.6f, 1.6f, 15f);
			b.Add("wood_stack", 3.3f, 0.6f, 1.2f, 100f);
		}

		private static void Stonecutter(Builder b)
		{
			b.LeanTo(2, 0f, -1.5f);
			b.Add("piece_stonecutter", 0f, 0.37f, -1.6f);
			b.Add("stone_pile", -3.3f, 0.2f, 1.2f);
			b.Add("stone_pile", 3.2f, 0.2f, 0.8f, 70f);
			b.Add("stone_pile", 1.2f, 0.2f, 2.4f, 140f);
		}

		private static void Farm(Builder b, Biome biome)
		{
			for (int i = 0; i < 5; i++)
			{
				float num = -4f + 2f * (float)i;
				b.Add("wood_fence", num + 0.1f, 0f, -4f);
				if (i != 2)
				{
					b.Add("wood_fence", num + 0.1f, 0f, 4f);
				}
			}
			for (int j = 0; j < 4; j++)
			{
				float num2 = -3f + 2f * (float)j;
				b.Add("wood_fence", -5f, 0f, num2 - 0.1f, 90f);
				b.Add("wood_fence", 5f, 0f, num2 - 0.1f, 90f);
			}
			string[] array = ((biome != Biome.Plains) ? new string[2] { "Pickable_Carrot", "Pickable_Turnip" } : new string[2] { "Pickable_Barley", "Pickable_Flax" });
			for (int k = 0; k < 4; k++)
			{
				for (int l = 0; l < 6; l++)
				{
					b.Add(array[k % 2], -3.5f + (float)l * 1.4f, 0f, -2.4f + (float)k * 1.5f);
				}
			}
			b.Add("piece_beehive", 3.6f, 0.15f, 3f, 200f);
		}

		private static void HunterLodge(Builder b)
		{
			b.Floor(2, 2);
			b.CornerPoles(2, 2, tall: true);
			b.Walls(2, 2, tall: true, 1);
			b.GableRoof(2, 2, 3.37f, steep: false);
			b.Add("rug_deer", -0.3f, 0.39000002f, -0.3f);
			b.Add("piece_chest_wood", -1.2f, 0.37f, -1.35f);
			b.Add("fire_pit_haldor", -3.6f, 0f, 2.6f);
			b.Add("piece_cookingstation", -3.6f, 0.2f, 2.6f, 45f);
		}

		private static void Smithy(Builder b)
		{
			b.Floor(3, 2);
			float y = 1.37f;
			int[] array = new int[4] { -3, -1, 1, 3 };
			foreach (int num in array)
			{
				b.Add("wood_pole_log", num, y, 2f);
				b.Add("wood_pole", num, 2.87f, 2f);
			}
			b.Walls(3, 2, tall: true, -1, openFront: true);
			b.GableRoof(3, 2, 3.37f, steep: false);
			b.Add("forge", -1f, 0.37f, -1.1f);
			b.Add("piece_chest_wood", 2f, 0.37f, -1.35f);
			b.Add("coal_pile", 1.6f, 0.47f, 0.6f);
			b.Add("bar_copper_stack", -2.3f, 0.37f, 0.8f);
		}

		private static void Watchtower(Builder b)
		{
			int[] array = new int[2] { -1, 1 };
			foreach (int num in array)
			{
				int[] array2 = new int[2] { -1, 1 };
				foreach (int num2 in array2)
				{
					b.Add("wood_pole_log_4", (float)num * 2f, 2f, (float)num2 * 2f);
				}
			}
			float num3 = 4.15f;
			array = new int[2] { -1, 1 };
			foreach (int num4 in array)
			{
				int[] array2 = new int[2] { -1, 1 };
				foreach (int num5 in array2)
				{
					b.Add("wood_floor", num4, num3, num5);
				}
			}
			b.Add("wood_stepladder", 0f, 0.1f, 5f);
			b.Add("wood_stepladder", 0f, 2.1f, 3f);
			array = new int[2] { -1, 1 };
			foreach (int num6 in array)
			{
				int[] array2 = new int[2] { -1, 1 };
				foreach (int num7 in array2)
				{
					b.Add("wood_pole2", (float)num6 * 2f, num3 + 1.1f, (float)num7 * 2f);
				}
			}
			float y = num3 + 0.15f;
			b.Add("wood_fence", -0.9f, y, -2f);
			b.Add("wood_fence", 1.1f, y, -2f);
			b.Add("wood_fence", -2f, y, -1.1f, 90f);
			b.Add("wood_fence", -2f, y, 0.9f, 90f);
			b.Add("wood_fence", 2f, y, -1.1f, 90f);
			b.Add("wood_fence", 2f, y, 0.9f, 90f);
			float y2 = num3 + 2.1f;
			array = new int[2] { -1, 1 };
			foreach (int num8 in array)
			{
				b.Add(b.Style.Roof26, num8, y2, 1f);
				b.Add(b.Style.Roof26, num8, y2, -1f, 180f);
			}
			b.Add(b.Style.Banner, 2.35f, num3 + 3.2f, 2f);
		}

		private static void Market(Builder b)
		{
			b.LeanTo(2, -3f, -1.5f);
			b.LeanTo(1, 3.5f, -1.5f);
			b.Add("piece_table", -3f, 0.37f, -1.3f);
			b.Add("piece_chest_wood", -4.3f, 0.37f, -1.9f);
			b.Add("piece_table", 3.5f, 0.37f, -1.2f, 90f);
			b.Add("wood_pole_log_4", 0.4f, 2f, 1.5f);
			b.Add(b.Style.Banner, 0.75f, 4.1f, 1.5f);
			b.Add("Cart", 1.2f, 0.3f, 3.2f, 120f);
		}

		private static void GreatHall(Builder b)
		{
			BuildStyle style = b.Style;
			string roof = style.Roof45;
			string roofTop = style.RoofTop45;
			style.Roof45 = "darkwood_roof_45";
			style.RoofTop45 = "darkwood_roof_top_45";
			b.Floor(6, 3);
			b.CornerPoles(6, 3, tall: true);
			b.Walls(6, 3, tall: true, 3);
			b.GableRoof(6, 3, 3.37f, steep: true);
			style.Roof45 = roof;
			style.RoofTop45 = roofTop;
			b.Add("fire_pit_haldor", -1f, 0.37f, 0f);
			b.Add("piece_throne01", -4.6f, 0.37f, 0f, 90f);
			b.Add("piece_table", 2.5f, 0.37f, -1.4f);
			b.Add("piece_bench01", 2.5f, 0.37f, -2.3f);
			b.Add("piece_table", -2.9f, 0.37f, -1.4f);
			b.Add("piece_bench01", -2.9f, 0.37f, -2.3f);
			b.Add("bed", 4.6f, 0.37f, -1.2f);
			b.Add("piece_chest_wood", 5.2f, 0.37f, 2.3f, 180f);
			int[] array = new int[4] { -4, -1, 2, 5 };
			foreach (int num in array)
			{
				b.Add("piece_walltorch", num, 2.37f, -2.75f);
			}
			b.Add(style.Banner, -0.5f, 4.67f, 3.25f, 90f);
			b.Add(style.Banner, 2.5f, 4.67f, 3.25f, 90f);
			b.Add("piece_groundtorch_wood", -1f, 0.7f, 4.6f);
			b.Add("piece_groundtorch_wood", 3f, 0.7f, 4.6f);
		}

		private static void Palisade(Builder b)
		{
			float num = 60.5f;
			int num2 = Mathf.RoundToInt((float)Math.PI * 2f * num / 2f);
			for (int i = 0; i < num2; i++)
			{
				float num3 = (float)i * 360f / (float)num2;
				if (!(Mathf.Min(Mathf.Abs(Mathf.DeltaAngle(num3, 0f)), Mathf.Abs(Mathf.DeltaAngle(num3, 180f))) < 2.2f))
				{
					float num4 = num3 * ((float)Math.PI / 180f);
					b.Add("stake_wall", Mathf.Sin(num4) * num, 0f, Mathf.Cos(num4) * num, num3);
				}
			}
		}
	}
	internal static class BossHunt
	{
		private static readonly string[] Bosses = new string[7] { "Eikthyr", "gd_king", "Bonemass", "Dragon", "GoblinKing", "SeekerQueen", "Fader" };

		private static readonly Dictionary<string, string> Kin = new Dictionary<string, string>
		{
			{ "greydwarf_brood", "gd_king" },
			{ "draugr_court", "Bonemass" },
			{ "fuling_horde", "GoblinKing" }
		};

		private const string HuntKey = "lf_hunt";

		private const string DoneKey = "lf_hunt_done";

		private const string PaidKey = "lf_hunt_paid_";

		public static int Bounty(string boss)
		{
			return 150 * (Array.IndexOf(Bosses, boss) + 1);
		}

		public static string BossName(string boss)
		{
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(boss) : null);
			Character val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Character>() : null);
			if (!((Object)(object)val2 != (Object)null) || Localization.instance == null)
			{
				return boss;
			}
			return Localization.instance.Localize(val2.m_name);
		}

		public static bool OffersHunts(Faction f)
		{
			if (f != null)
			{
				return Defs.Culture(f.CultureId).Group != "greydwarf";
			}
			return false;
		}

		public static string Offer(Faction f, Player player)
		{
			Kin.TryGetValue(f.CultureId, out var value);
			string[] bosses = Bosses;
			foreach (string text in bosses)
			{
				if (!(text == value) && !player.m_customData.ContainsKey("lf_hunt_paid_" + text))
				{
					return text;
				}
			}
			return null;
		}

		public static KeyValuePair<string, int>? Current(Player player)
		{
			if ((Object)(object)player == (Object)null || !player.m_customData.TryGetValue("lf_hunt", out var value))
			{
				return null;
			}
			string[] array = value.Split(new char[1] { '|' });
			if (array.Length < 2 || !int.TryParse(array[1], out var result))
			{
				return null;
			}
			return new KeyValuePair<string, int>(array[0], result);
		}

		public static bool Done(Player player)
		{
			KeyValuePair<string, int>? keyValuePair = Current(player);
			if (keyValuePair.HasValue && player.m_customData.TryGetValue("lf_hunt_done", out var value))
			{
				return value == keyValuePair.Value.Key;
			}
			return false;
		}

		public static void Take(Player player, Faction f, string boss)
		{
			player.m_customData["lf_hunt"] = boss + "|" + f.Id;
			player.m_customData.Remove("lf_hunt_done");
		}

		public static bool Claim(Player player, Settlement s, Faction f)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			KeyValuePair<string, int>? keyValuePair = Current(player);
			if (!keyValuePair.HasValue || !Done(player) || keyValuePair.Value.Value != f.Id)
			{
				return false;
			}
			int num = Bounty(keyValuePair.Value.Key);
			if (s.Stock[4] < (float)num)
			{
				return false;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Coins");
			if ((Object)(object)itemPrefab == (Object)null)
			{
				return false;
			}
			Net.AddStock(s, Res.Coins, -num);
			int num2 = num;
			while (num2 > 0)
			{
				int num3 = Mathf.Min(num2, 999);
				if (!((Humanoid)player).GetInventory().AddItem(itemPrefab, num3))
				{
					ItemDrop.DropItem(itemPrefab.GetComponent<ItemDrop>().m_itemData.Clone(), num3, ((Component)player).transform.position + Vector3.up, Quaternion.identity);
				}
				num2 -= num3;
			}
			Net.AddReputation(f, player.GetPlayerID(), 10f);
			player.m_customData["lf_hunt_paid_" + keyValuePair.Value.Key] = "1";
			player.m_customData.Remove("lf_hunt");
			player.m_customData.Remove("lf_hunt_done");
			return true;
		}

		public static void BossKilled(Character boss)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!SimHost.Active || (Object)(object)localPlayer == (Object)null || Utils.DistanceXZ(((Component)localPlayer).transform.position, ((Component)boss).transform.position) > 100f)
			{
				return;
			}
			string prefabName = Utils.GetPrefabName(((Component)boss).gameObject);
			if (Array.IndexOf(Bosses, prefabName) < 0)
			{
				return;
			}
			KeyValuePair<string, int>? keyValuePair = Current(localPlayer);
			if (keyValuePair.HasValue && keyValuePair.Value.Key == prefabName)
			{
				localPlayer.m_customData["lf_hunt_done"] = prefabName;
			}
			long playerID = localPlayer.GetPlayerID();
			foreach (Faction faction in SimHost.Sim.State.Factions)
			{
				if (!faction.Eliminated)
				{
					string text = Defs.Culture(faction.CultureId).Group;
					string value;
					float num = ((!Kin.TryGetValue(faction.CultureId, out value)) ? ((text == "human") ? 10f : 5f) : ((value == prefabName) ? (-25f) : 0f));
					if (num != 0f)
					{
						Net.AddReputation(faction, playerID, num);
					}
				}
			}
			if ((Object)(object)MessageHud.instance != (Object)null)
			{
				MessageHud.instance.ShowMessage((MessageType)2, Texts.Get("msg_boss_slain", BossName(prefabName)), 0, (Sprite)null, false, true);
			}
		}
	}
	internal static class Chests
	{
		private static readonly int HashFilled = StringExtensionMethods.GetStableHashCode("lf_filled");

		private static readonly int[] HashCount = new int[2]
		{
			StringExtensionMethods.GetStableHashCode("lf_n0"),
			StringExtensionMethods.GetStableHashCode("lf_n1")
		};

		private static readonly int HashCountSet = StringExtensionMethods.GetStableHashCode("lf_nset");

		private static readonly List<Container> All = new List<Container>();

		private static float _next;

		private static readonly Res[][] StoreRoles = new Res[3][]
		{
			new Res[2]
			{
				Res.Wood,
				Res.Stone
			},
			new Res[1] { Res.Food },
			new Res[2]
			{
				Res.Metal,
				Res.Coins
			}
		};

		private static readonly int[] StoreCaps = new int[5] { 100, 100, 40, 30, 200 };

		private static float _nextPlayerChests;

		public static void Register(Container container)
		{
			All.Add(container);
		}

		public static void Reset()
		{
			All.Clear();
		}

		public static void Update()
		{
			if (!SimHost.Active || Time.time < _next || !ModConfig.ChestsOn.Value)
			{
				return;
			}
			_next = Time.time + 4f;
			Dictionary<long, List<Container>> dictionary = new Dictionary<long, List<Container>>();
			for (int num = All.Count - 1; num >= 0; num--)
			{
				Container val = All[num];
				if ((Object)(object)val == (Object)null)
				{
					All.RemoveAt(num);
				}
				else
				{
					ZNetView component = ((Component)val).GetComponent<ZNetView>();
					if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner())
					{
						int num2 = component.GetZDO().GetInt(Materializer.HashSettlement, 0);
						if (num2 != 0)
						{
							long key = ((long)num2 << 32) | (uint)component.GetZDO().GetInt(Materializer.HashBuilding, 0);
							if (!dictionary.TryGetValue(key, out var value))
							{
								value = (dictionary[key] = new List<Container>());
							}
							value.Add(val);
						}
					}
				}
			}
			if (ModConfig.TradeOn.Value && Time.time >= _nextPlayerChests)
			{
				_nextPlayerChests = Time.time + 20f;
				TradeWithPlayerChests();
			}
			foreach (KeyValuePair<long, List<Container>> item in dictionary)
			{
				Settlement settlement = SimHost.Sim.State.GetSettlement((int)(item.Key >> 32));
				if (settlement == null)
				{
					continue;
				}
				int num3 = (int)(item.Key & 0xFFFFFFFFu);
				Building building = null;
				foreach (Building building2 in settlement.Buildings)
				{
					if (building2.Id == num3)
					{
						building = building2;
					}
				}
				if (building == null)
				{
					continue;
				}
				if (building.Kind == BuildingKind.Storehouse)
				{
					item.Value.Sort((Container x, Container y) => Order(x).CompareTo(Order(y)));
					for (int num4 = 0; num4 < item.Value.Count && num4 < StoreRoles.Length; num4++)
					{
						SyncStore(settlement, item.Value[num4], StoreRoles[num4]);
					}
					continue;
				}
				foreach (Container item2 in item.Value)
				{
					SyncPersonal(settlement, building, item2);
				}
			}
		}

		private static void TradeWithPlayerChests()
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Coins");
			foreach (Container item in All)
			{
				if ((Object)(object)item == (Object)null || item.IsInUse())
				{
					continue;
				}
				ZNetView component = ((Component)item).GetComponent<ZNetView>();
				Piece component2 = ((Component)item).GetComponent<Piece>();
				if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner() || (Object)(object)component2 == (Object)null || component2.GetCreator() == 0L || component.GetZDO().GetInt(Materializer.HashSettlement, 0) != 0)
				{
					continue;
				}
				foreach (Settlement settlement in SimHost.Sim.State.Settlements)
				{
					if (settlement.Destroyed)
					{
						continue;
					}
					float num = Defs.RingRadius[Defs.RingsByTier[(int)settlement.Tier] - 1] + 8f;
					if (Utils.DistanceXZ(((Component)item).transform.position, new Vector3(settlement.Pos.X, 0f, settlement.Pos.Z)) > num)
					{
						continue;
					}
					Faction faction = SimHost.Sim.State.GetFaction(settlement.FactionId);
					if (faction == null || !SimHost.Sim.WillTrade(faction, localPlayer.GetPlayerID()))
					{
						break;
					}
					Inventory inventory = item.GetInventory();
					int num2 = 0;
					ItemData[] array = inventory.GetAllItems().ToArray();
					foreach (ItemData val in array)
					{
						if (Items.TryValue(val, out var res, out var units) && res != Res.Coins)
						{
							int num3 = Mathf.Min(val.m_stack, 20);
							int num4 = Net.PlayerSell(settlement, res, Mathf.Max(1, Mathf.RoundToInt((float)num3 * units)), localPlayer.GetPlayerID());
							if (num4 > 0)
							{
								inventory.RemoveItem(val, num3);
								num2 += num4;
							}
						}
					}
					if (num2 > 0)
					{
						if ((Object)(object)itemPrefab != (Object)null)
						{
							inventory.AddItem(itemPrefab, num2);
						}
						if ((Object)(object)MessageHud.instance != (Object)null)
						{
							MessageHud.instance.ShowMessage((MessageType)1, Texts.Get("msg_chest_trade", Texts.Name(settlement.Name), num2), 0, (Sprite)null, false, true);
						}
					}
					break;
				}
			}
		}

		private static float Order(Container c)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)c).transform.position;
			return position.x * 1.37f + position.z;
		}

		private static string SharedName(GameObject prefab)
		{
			return prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name;
		}

		private static void SyncStore(Settlement s, Container chest, Res[] goods)
		{
			if (chest.IsInUse())
			{
				return;
			}
			ZDO zDO = ((Component)chest).GetComponent<ZNetView>().GetZDO();
			Inventory inventory = chest.GetInventory();
			bool flag = zDO.GetBool(HashCountSet, false);
			for (int i = 0; i < goods.Length; i++)
			{
				Res res = goods[i];
				float unitsPerItem;
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(Items.SalePrefab(res, s, out unitsPerItem));
				if ((Object)(object)itemPrefab == (Object)null)
				{
					continue;
				}
				string text = SharedName(itemPrefab);
				int num = inventory.CountItems(text, -1, true);
				if (flag)
				{
					int num2 = zDO.GetInt(HashCount[i], 0);
					if (num < num2)
					{
						Taken(s, res, (float)(num2 - num) * unitsPerItem);
					}
					else if (num > num2)
					{
						Given(s, res, (float)(num - num2) * unitsPerItem);
					}
				}
				int num3 = (s.Destroyed ? num : Mathf.Min(StoreCaps[(int)res], Mathf.FloorToInt(s.Stock[(int)res] * 0.25f / unitsPerItem)));
				if (num3 > num)
				{
					inventory.AddItem(itemPrefab, num3 - num);
				}
				else if (num3 < num)
				{
					inventory.RemoveItem(text, num - num3, -1, true);
				}
				zDO.Set(HashCount[i], inventory.CountItems(text, -1, true), false);
			}
			zDO.Set(HashCountSet, true);
		}

		private static void SyncPersonal(Settlement s, Building b, Container chest)
		{
			if (chest.IsInUse())
			{
				return;
			}
			ZDO zDO = ((Component)chest).GetComponent<ZNetView>().GetZDO();
			Inventory inventory = chest.GetInventory();
			if (!zDO.GetBool(HashFilled, false))
			{
				zDO.Set(HashFilled, true);
				FillPersonal(s, b, inventory);
				zDO.Set(HashCount[0], Total(inventory), false);
				return;
			}
			int num = Total(inventory);
			int num2 = zDO.GetInt(HashCount[0], 0);
			if (num < num2)
			{
				Taken(s, Res.Coins, (float)(num2 - num) * 2f);
			}
			zDO.Set(HashCount[0], num, false);
		}

		private static int Total(Inventory inv)
		{
			int num = 0;
			foreach (ItemData allItem in inv.GetAllItems())
			{
				num += allItem.m_stack;
			}
			return num;
		}

		private static void FillPersonal(Settlement s, Building b, Inventory inv)
		{
			Random random = new Random(s.Seed * 31 + b.Id);
			int tier = (int)s.Tier;
			Add(inv, "Coins", random.Next(4, 14) * (1 + tier));
			Add(inv, Pick(random, "CookedMeat", "Raspberry", "Honey", "CookedDeerMeat", "Mushroom"), random.Next(2, 6));
			Add(inv, Pick(random, "LeatherScraps", "DeerHide", "Flint", "Resin", "Feathers"), random.Next(2, 8));
			if (random.Next(100) < 60)
			{
				Add(inv, (tier >= 2) ? "ArrowFlint" : "ArrowWood", random.Next(8, 21));
			}
			if (tier >= 2 && random.Next(100) < 50)
			{
				Add(inv, Pick(random, "Bronze", "Copper", "Tin"), random.Next(1, 4));
			}
			if (tier >= 3 && random.Next(100) < 50)
			{
				Add(inv, Pick(random, "Iron", "Amber", "AmberPearl"), random.Next(1, 3));
			}
			if (b.Kind == BuildingKind.GreatHall)
			{
				Add(inv, Pick(random, "Ruby", "AmberPearl", "SilverNecklace"), random.Next(1, 3));
			}
		}

		private static string Pick(Random rnd, params string[] options)
		{
			return options[rnd.Next(options.Length)];
		}

		private static void Add(Inventory inv, string prefabName, int amount)
		{
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName);
			if ((Object)(object)itemPrefab != (Object)null && amount > 0)
			{
				inv.AddItem(itemPrefab, amount);
			}
		}

		private static void Taken(Settlement s, Res res, float units)
		{
			if (res != Res.Coins || units > 0f)
			{
				Net.AddStock(s, res, 0f - units);
			}
			Player localPlayer = Player.m_localPlayer;
			Faction faction = SimHost.Sim.State.GetFaction(s.FactionId);
			if (!((Object)(object)localPlayer == (Object)null) && faction != null && !s.Destroyed)
			{
				Net.NamePlayer(faction, localPlayer.GetPlayerID(), localPlayer.GetPlayerName());
				if (Net.PlayerStole(faction, localPlayer.GetPlayerID(), units * Balance.CoinValue[(int)res]) && (Object)(object)MessageHud.instance != (Object)null)
				{
					MessageHud.instance.ShowMessage((MessageType)1, Texts.Get("msg_theft", Texts.Name(s.Name)), 0, (Sprite)null, false, true);
				}
			}
		}

		private static void Given(Settlement s, Res res, float units)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				Net.AddStock(s, res, units);
			}
			else
			{
				Net.PlayerGift(s, localPlayer.GetPlayerID(), res, units);
			}
		}

		public static string Describe()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (Container item in All)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				ZNetView component = ((Component)item).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || !component.IsValid() || component.GetZDO().GetInt(Materializer.HashSettlement, 0) == 0)
				{
					continue;
				}
				stringBuilder.Append("s" + component.GetZDO().GetInt(Materializer.HashSettlement, 0) + " b" + component.GetZDO().GetInt(Materializer.HashBuilding, 0) + ":");
				foreach (ItemData allItem in item.GetInventory().GetAllItems())
				{
					stringBuilder.Append(" " + ((Object)allItem.m_dropPrefab).name + "x" + allItem.m_stack);
				}
				stringBuilder.AppendLine();
			}
			if (stringBuilder.Length != 0)
			{
				return stringBuilder.ToString().TrimEnd(Array.Empty<char>());
			}
			return "no settlement chests loaded";
		}
	}
	[HarmonyPatch(typeof(Container), "Awake")]
	internal static class ContainerAwakePatch
	{
		private static void Postfix(Container __instance)
		{
			Chests.Register(__instance);
		}
	}
	internal class LfConsoleCommand : ConsoleCommand
	{
		public override string Name => "lf";

		public override string Help => "Living Factions: lf help";

		public override void Run(string[] args)
		{
			string[] array = Commands.Run(string.Join(" ", args)).Split(new char[1] { '\n' });
			foreach (string text in array)
			{
				Console.instance.Print(text);
			}
		}
	}
	internal static class Commands
	{
		private static readonly CultureInfo Inv = CultureInfo.InvariantCulture;

		public static Vector3? CamPos;

		public static Vector3 CamTarget;

		private static float _lastDryRoad = 150f;

		private static string NoSim => "The faction simulation is not running here (only the host of the world runs it).";

		public unsafe static string Run(string line)
		{
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_14f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_14fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_150a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dcf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd6: Expected O, but got Unknown
			//IL_0df0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0df5: Unknown result type (might be due to invalid IL or missing references)
			//IL_15a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_15ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_15b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_15c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_15ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_15d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_15df: Unknown result type (might be due to invalid IL or missing references)
			//IL_15e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_15ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_15f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_15fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_1602: Unknown result type (might be due to invalid IL or missing references)
			//IL_163f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1644: Unknown result type (might be due to invalid IL or missing references)
			//IL_155d: Unknown result type (might be due to invalid IL or missing references)
			//IL_1566: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ee9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ef0: Expected O, but got Unknown
			//IL_0f0a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f0f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1355: Unknown result type (might be due to invalid IL or missing references)
			//IL_135a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1366: Unknown result type (might be due to invalid IL or missing references)
			//IL_136b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1435: Unknown result type (might be due to invalid IL or missing references)
			//IL_1437: Unknown result type (might be due to invalid IL or missing references)
			//IL_1439: Unknown result type (might be due to invalid IL or missing references)
			//IL_143e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1442: Unknown result type (might be due to invalid IL or missing references)
			//IL_1447: Unknown result type (might be due to invalid IL or missing references)
			//IL_1449: Unknown result type (might be due to invalid IL or missing references)
			//IL_144b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1452: Unknown result type (might be due to invalid IL or missing references)
			//IL_1457: Unknown result type (might be due to invalid IL or missing references)
			//IL_145c: Unknown result type (might be due to invalid IL or missing references)
			//IL_138b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1392: Unknown result type (might be due to invalid IL or missing references)
			//IL_13ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_13b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_13b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_13c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_13cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_13d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_13d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_13f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_13f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_11b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_11b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_11c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_11cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_11d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_11d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_11d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_11d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_11dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_11e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_11eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_11f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_11f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_11ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_1204: Unknown result type (might be due to invalid IL or missing references)
			//IL_1213: Unknown result type (might be due to invalid IL or missing references)
			//IL_1215: Unknown result type (might be due to invalid IL or missing references)
			//IL_121a: Unknown result type (might be due to invalid IL or missing references)
			//IL_121f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1485: Unknown result type (might be due to invalid IL or missing references)
			//IL_148a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1499: Unknown result type (might be due to invalid IL or missing references)
			//IL_149b: Unknown result type (might be due to invalid IL or missing references)
			//IL_14a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_14aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_14af: Unknown result type (might be due to invalid IL or missing references)
			//IL_14b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_14bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_12b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_12b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_12bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_12c6: Unknown result type (might be due to invalid IL or missing references)
			string[] a = line.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			if (a.Length == 0)
			{
				return Help();
			}
			switch (a[0].ToLowerInvariant())
			{
			case "help":
				return Help();
			case "status":
				return Status();
			case "factions":
				return Factions();
			case "chronicle":
				return Chronicle((a.Length > 1) ? int.Parse(a[1]) : 15);
			case "advance":
				return Advance((a.Length > 1) ? double.Parse(a[1], Inv) : 1.0);
			case "rewind":
				return SimHost.Rewind(a);
			case "audit":
			{
				Settlement settlement6 = ((SimHost.Active && a.Length > 1) ? FindSettlement(a[1]) : null);
				if (settlement6 == null)
				{
					return "audit <settlement>";
				}
				string text2 = Materializer.Reconcile(settlement6, new Vector3(settlement6.Pos.X, 0f, settlement6.Pos.Z), a.Length > 2 && a[2] == "fix");
				return settlement6.Name + ": " + ((text2.Length == 0) ? "world and record agree" : text2);
			}
			case "tp":
				return Teleport(a);
			case "rep":
				return Rep(a);
			case "save":
				SimHost.Save();
				return "saved";
			default:
			{
				if (!ModConfig.DevTools.Value)
				{
					return "Unknown command. Try: lf help";
				}
				Vector3 val5;
				switch (a[0].ToLowerInvariant())
				{
				case "here":
					return Here(a);
				case "time":
					return "worldDay " + (SimHost.Active ? SimHost.WorldDay.ToString("0.00", Inv) : "?") + " simDay " + (SimHost.Active ? SimHost.Sim.State.Day.ToString("0.00", Inv) : "?");
				case "pos":
					return Pos();
				case "shot":
					return Shot(a);
				case "cam":
					return Cam(a);
				case "look":
					return GearView.Look(a);
				case "gear":
				{
					string text = Equip(a);
					if (!text.StartsWith("equipped"))
					{
						return text;
					}
					return text + "; " + GearView.Look(new string[2] { "look", "auto" });
				}
				case "unequip":
					return GearView.Unequip(a);
				case "sheathe":
					return GearView.Sheathe(away: true);
				case "draw":
					return GearView.Sheathe(away: false);
				case "face":
					return GearView.Face(a);
				case "gearinfo":
					return GearView.Describe();
				case "points":
					return AttachPoints.Command(a);
				case "mats":
					return DevProbes.Materials(a);
				case "crowd":
					return DevProbes.Crowd();
				case "lang":
					return DevProbes.Language(a);
				case "perf":
					return DevProbes.Perf();
				case "track":
					return DevProbes.Track(a);
				case "seams":
					return DevProbes.Seams((a.Length > 1) ? float.Parse(a[1], Inv) : 150f);
				case "emptybag":
				{
					if ((Object)(object)Player.m_localPlayer == (Object)null)
					{
						return "no player";
					}
					((Humanoid)Player.m_localPlayer).UnequipAllItems();
					int num2 = ((Humanoid)Player.m_localPlayer).GetInventory().NrOfItems();
					((Humanoid)Player.m_localPlayer).GetInventory().RemoveAll();
					return "bag emptied, " + num2 + " stacks gone";
				}
				case "server":
					return Net.DevOnHost(string.Join(" ", a, 1, a.Length - 1));
				case "net":
					return Net.Describe();
				case "forest":
					return Forestry.Describe();
				case "ally":
				{
					Faction faction = ((a.Length > 1 && SimHost.Active) ? SimHost.Sim.State.GetFaction(int.Parse(a[1])) : null);
					if (faction == null || (Object)(object)Player.m_localPlayer == (Object)null)
					{
						return "usage: ally <faction#>";
					}
					return Net.PlayerProposeAlliance(faction, Player.m_localPlayer.GetPlayerID()).Reason;
				}
				case "strike":
				{
					Player me2 = Player.m_localPlayer;
					if ((Object)(object)me2 == (Object)null || a.Length < 2)
					{
						return "usage: strike <prefab>";
					}
					Character val2 = (from c in Character.GetAllCharacters()
						where !c.IsDead() && Utils.GetPrefabName(((Component)c).gameObject) == a[1]
						orderby Vector3.Distance(((Component)c).transform.position, ((Component