Decompiled source of HalfBeam v1.0.0

HalfBeam.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HalfBeam.Core;
using HalfBeam.Pieces;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("HalfBeam")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Half-sized beams so you can build with more precision.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a4afc68dbbb0faf96cef5e10340f7ecbeff848a3")]
[assembly: AssemblyProduct("HalfBeam")]
[assembly: AssemblyTitle("HalfBeam")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[DebuggerDisplay("Count = {System.Collections.ICollection.Count}")]
[CompilerGenerated]
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Length;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Length;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Length;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyArray(T[] items)
	{
		_items = items;
	}

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

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return ((ICollection<T>)_items).Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		((ICollection<T>)_items).CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return ((IList<T>)_items).IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
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 HalfBeam
{
	[BepInPlugin("javidahmed64592.halfbeam", "HalfBeam", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class HalfBeamPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "javidahmed64592.halfbeam";

		public const string PluginName = "HalfBeam";

		public const string PluginVersion = "1.0.0";

		private bool _knownRecipesRefreshed;

		private void Awake()
		{
			Translations.Load();
			PrefabManager.OnVanillaPrefabsAvailable += RegisterPieces;
		}

		private void Update()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				_knownRecipesRefreshed = false;
			}
			else if (!_knownRecipesRefreshed)
			{
				_knownRecipesRefreshed = true;
				Player.m_localPlayer.UpdateKnownRecipesList();
			}
		}

		private void RegisterPieces()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterPieces;
			foreach (PieceVariantDefinition item in PieceVariantRegistry.All)
			{
				try
				{
					PieceVariantFactory.Build(item, ((BaseUnityPlugin)this).Logger);
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Failed to build " + item.NewPrefabName + ": " + ex));
				}
			}
		}
	}
}
namespace HalfBeam.Pieces
{
	internal static class IconLoader
	{
		private static readonly MethodInfo LoadImageMethod = typeof(ImageConversion).GetMethod("LoadImage", new Type[2]
		{
			typeof(Texture2D),
			typeof(byte[])
		});

		public static Sprite Load(string prefabName, ManualLogSource log)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			string text = "Icons." + prefabName + ".png";
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text);
			if (stream == null)
			{
				return null;
			}
			byte[] array;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				stream.CopyTo(memoryStream);
				array = memoryStream.ToArray();
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
			{
				name = prefabName + "_icon"
			};
			if (!(LoadImageMethod != null) || !(bool)LoadImageMethod.Invoke(null, new object[2] { val, array }))
			{
				log.LogWarning((object)("Could not decode icon " + text));
				return null;
			}
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
	internal sealed class KeepSpan(float start, float end)
	{
		public float Start { get; } = start;

		public float End { get; } = end;

		public float Length => End - Start;
	}
	internal sealed class MeshCut(float start, float end, float scale = 1f)
	{
		public float Start { get; } = start;

		public float End { get; } = end;

		public float Scale { get; } = scale;

		public float Length => End - Start;
	}
	internal sealed class MeshCutter
	{
		private readonly struct Corner
		{
			public readonly int From;

			public readonly int To;

			public readonly float Share;

			public readonly float Along;

			public Corner(int from, float along, int to = -1, float share = 0f)
			{
				From = from;
				To = to;
				Share = share;
				Along = along;
			}
		}

		private sealed class VertexData
		{
			public VertexData Source { get; private set; }

			public List<Vector3> Positions { get; } = new List<Vector3>();

			public List<Vector3> Normals { get; } = new List<Vector3>();

			public List<Vector4> Tangents { get; } = new List<Vector4>();

			public List<Color> Colors { get; } = new List<Color>();

			public List<Vector4>[] Uvs { get; } = new List<Vector4>[8];

			public int[] UvDimensions { get; } = new int[8];

			public static VertexData Read(Mesh mesh)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				VertexData vertexData = new VertexData();
				mesh.GetVertices(vertexData.Positions);
				mesh.GetNormals(vertexData.Normals);
				mesh.GetTangents(vertexData.Tangents);
				mesh.GetColors(vertexData.Colors);
				for (int i = 0; i < 8; i++)
				{
					VertexAttribute val = (VertexAttribute)(4 + i);
					if (mesh.HasVertexAttribute(val))
					{
						vertexData.UvDimensions[i] = mesh.GetVertexAttributeDimension(val);
						vertexData.Uvs[i] = new List<Vector4>();
						mesh.GetUVs(i, vertexData.Uvs[i]);
					}
				}
				return vertexData;
			}

			public VertexData EmptyCopy()
			{
				VertexData vertexData = new VertexData
				{
					Source = this
				};
				for (int i = 0; i < 8; i++)
				{
					if (Uvs[i] != null)
					{
						vertexData.Uvs[i] = new List<Vector4>();
						vertexData.UvDimensions[i] = UvDimensions[i];
					}
				}
				return vertexData;
			}

			public int AddFrom(VertexData from, int index)
			{
				return AddBetween(from, index, index, 0f);
			}

			public int AddBetween(VertexData from, int a, int b, float share)
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: 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_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: 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_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: 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_013d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				Positions.Add(Vector3.Lerp(from.Positions[a], from.Positions[b], share));
				Vector3 val;
				if (from.Normals.Count > 0)
				{
					List<Vector3> normals = Normals;
					val = Vector3.Lerp(from.Normals[a], from.Normals[b], share);
					normals.Add(((Vector3)(ref val)).normalized);
				}
				if (from.Tangents.Count > 0)
				{
					val = Vector4.op_Implicit(Vector4.Lerp(from.Tangents[a], from.Tangents[b], share));
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					Tangents.Add(new Vector4(normalized.x, normalized.y, normalized.z, from.Tangents[a].w));
				}
				if (from.Colors.Count > 0)
				{
					Colors.Add(Color.Lerp(from.Colors[a], from.Colors[b], share));
				}
				for (int i = 0; i < 8; i++)
				{
					if (from.Uvs[i] != null)
					{
						Uvs[i].Add(Vector4.Lerp(from.Uvs[i][a], from.Uvs[i][b], share));
					}
				}
				return Positions.Count - 1;
			}

			public Mesh ToMesh(Mesh source, List<List<int>> submeshes)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				Mesh val = new Mesh
				{
					name = ((Object)source).name + "_halfbeam",
					indexFormat = (IndexFormat)(Positions.Count > 65535)
				};
				val.SetVertices(Positions);
				if (Normals.Count > 0)
				{
					val.SetNormals(Normals);
				}
				if (Tangents.Count > 0)
				{
					val.SetTangents(Tangents);
				}
				if (Colors.Count > 0)
				{
					val.SetColors(Colors);
				}
				for (int i = 0; i < 8; i++)
				{
					if (Uvs[i] != null)
					{
						SetUvs(val, i, Uvs[i], UvDimensions[i]);
					}
				}
				val.subMeshCount = submeshes.Count;
				for (int j = 0; j < submeshes.Count; j++)
				{
					val.SetTriangles(submeshes[j], j);
				}
				val.RecalculateBounds();
				return val;
			}

			private static void SetUvs(Mesh mesh, int channel, List<Vector4> uvs, int dimension)
			{
				switch (dimension)
				{
				case 2:
					mesh.SetUVs(channel, uvs.ConvertAll((Converter<Vector4, Vector2>)((Vector4 uv) => new Vector2(uv.x, uv.y))));
					break;
				case 3:
					mesh.SetUVs(channel, uvs.ConvertAll((Converter<Vector4, Vector3>)((Vector4 uv) => new Vector3(uv.x, uv.y, uv.z))));
					break;
				default:
					mesh.SetUVs(channel, uvs);
					break;
				}
			}
		}

		private const float SideEpsilon = 1E-06f;

		private const int MaxUvChannels = 8;

		private readonly Vector3 _center;

		private readonly Vector3 _axis;

		private readonly MeshCut _cut;

		private readonly Vector3 _firstEnd;

		private readonly Vector3 _offset;

		private readonly Dictionary<(Mesh, Matrix4x4), Mesh> _cache;

		public MeshCutter(Vector3 center, Vector3 axis, float length, float factor, MeshCut cut)
		{
			//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_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_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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			_center = center;
			_axis = axis;
			_cut = cut;
			_firstEnd = center - axis * (length / 2f);
			_offset = (factor - 1f) * center + axis * (length * (1f - factor) / 2f);
			_cache = new Dictionary<(Mesh, Matrix4x4), Mesh>();
			base..ctor();
		}

		public Mesh Cut(Mesh source, Matrix4x4 nodeToRoot)
		{
			//IL_0007: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			if (_cache.TryGetValue((source, nodeToRoot), out var value))
			{
				return value;
			}
			Mesh val = Build(source, nodeToRoot);
			_cache[(source, nodeToRoot)] = val;
			return val;
		}

		private Mesh Build(Mesh source, Matrix4x4 nodeToRoot)
		{
			//IL_000f: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			VertexData data = VertexData.Read(source);
			Matrix4x4 inverse = ((Matrix4x4)(ref nodeToRoot)).inverse;
			int count = data.Positions.Count;
			List<float> list = new List<float>();
			for (int i = 0; i < count; i++)
			{
				list.Add(Vector3.Dot(((Matrix4x4)(ref nodeToRoot)).MultiplyPoint3x4(data.Positions[i]) - _center, _axis));
			}
			VertexData output = data.EmptyCopy();
			List<bool> shifted = new List<bool>();
			Dictionary<int, int> reused = new Dictionary<int, int>();
			List<List<int>> list2 = new List<List<int>>();
			for (int j = 0; j < source.subMeshCount; j++)
			{
				int[] triangles = source.GetTriangles(j);
				List<int> list3 = new List<int>();
				for (int k = 0; k + 2 < triangles.Length; k += 3)
				{
					int num = triangles[k];
					int num2 = triangles[k + 1];
					int num3 = triangles[k + 2];
					float num4 = list[num];
					float num5 = list[num2];
					float num6 = list[num3];
					bool num7 = num4 <= _cut.Start + 1E-06f && num5 <= _cut.Start + 1E-06f && num6 <= _cut.Start + 1E-06f;
					bool flag = num4 >= _cut.End - 1E-06f && num5 >= _cut.End - 1E-06f && num6 >= _cut.End - 1E-06f;
					if (num7 || flag)
					{
						list3.Add(AddOriginal(num, flag));
						list3.Add(AddOriginal(num2, flag));
						list3.Add(AddOriginal(num3, flag));
						continue;
					}
					List<Corner> polygon = new List<Corner>(3)
					{
						new Corner(num, num4),
						new Corner(num2, num5),
						new Corner(num3, num6)
					};
					AddPolygon(Clip(polygon, _cut.Start, keepBelow: true), output, shifted, list3, right: false);
					AddPolygon(Clip(polygon, _cut.End, keepBelow: false), output, shifted, list3, right: true);
				}
				list2.Add(list3);
			}
			Place(output, shifted, nodeToRoot, inverse);
			return output.ToMesh(source, list2);
			int AddOriginal(int index, bool right)
			{
				if (!reused.TryGetValue(index, out var value))
				{
					value = output.AddFrom(data, index);
					shifted.Add(right);
					reused[index] = value;
				}
				return value;
			}
		}

		private static List<Corner> Clip(List<Corner> polygon, float limit, bool keepBelow)
		{
			List<Corner> list = new List<Corner>();
			for (int i = 0; i < polygon.Count; i++)
			{
				Corner corner = polygon[i];
				Corner corner2 = polygon[(i + polygon.Count - 1) % polygon.Count];
				if (Inside(corner) != Inside(corner2))
				{
					float share = (limit - corner2.Along) / (corner.Along - corner2.Along);
					list.Add(new Corner(corner2.From, limit, corner.From, share));
				}
				if (Inside(corner))
				{
					list.Add(corner);
				}
			}
			if (!list.TrueForAll((Corner corner3) => Mathf.Abs(corner3.Along - limit) <= 1E-06f))
			{
				return list;
			}
			return new List<Corner>();
			bool Inside(Corner corner3)
			{
				if (!keepBelow)
				{
					return corner3.Along >= limit - 1E-06f;
				}
				return corner3.Along <= limit + 1E-06f;
			}
		}

		private static void AddPolygon(List<Corner> polygon, VertexData output, List<bool> shifted, List<int> kept, bool right)
		{
			if (polygon.Count < 3)
			{
				return;
			}
			List<int> list = new List<int>();
			foreach (Corner item in polygon)
			{
				list.Add((item.To < 0) ? output.AddFrom(output.Source, item.From) : output.AddBetween(output.Source, item.From, item.To, item.Share));
				shifted.Add(right);
			}
			for (int i = 1; i + 1 < list.Count; i++)
			{
				kept.Add(list[0]);
				kept.Add(list[i]);
				kept.Add(list[i + 1]);
			}
		}

		private void Place(VertexData output, List<bool> shifted, Matrix4x4 nodeToRoot, Matrix4x4 rootToNode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 identity = Matrix4x4.identity;
			Vector3 val;
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					int num = i;
					int num2 = j;
					float num3 = ((Matrix4x4)(ref identity))[num, num2];
					float num4 = 1f - _cut.Scale;
					val = _axis;
					float num5 = num4 * ((Vector3)(ref val))[i];
					val = _axis;
					((Matrix4x4)(ref identity))[num, num2] = num3 - num5 * ((Vector3)(ref val))[j];
				}
			}
			Matrix4x4 val2 = rootToNode * identity * nodeToRoot;
			Matrix4x4 inverse = ((Matrix4x4)(ref val2)).inverse;
			Matrix4x4 transpose = ((Matrix4x4)(ref inverse)).transpose;
			for (int k = 0; k < output.Positions.Count; k++)
			{
				Vector3 val3 = ((Matrix4x4)(ref nodeToRoot)).MultiplyPoint3x4(output.Positions[k]);
				if (shifted[k])
				{
					val3 -= _axis * _cut.Length;
				}
				float num6 = Vector3.Dot(val3 - _firstEnd, _axis);
				val3 -= _axis * (num6 * (1f - _cut.Scale));
				output.Positions[k] = ((Matrix4x4)(ref rootToNode)).MultiplyPoint3x4(val3 + _offset);
			}
			if (!Mathf.Approximately(_cut.Scale, 1f))
			{
				for (int l = 0; l < output.Normals.Count; l++)
				{
					List<Vector3> normals = output.Normals;
					int index = l;
					val = ((Matrix4x4)(ref transpose)).MultiplyVector(output.Normals[l]);
					normals[index] = ((Vector3)(ref val)).normalized;
				}
				for (int m = 0; m < output.Tangents.Count; m++)
				{
					Vector4 val4 = output.Tangents[m];
					val = ((Matrix4x4)(ref val2)).MultiplyVector(Vector4.op_Implicit(val4));
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					output.Tangents[m] = new Vector4(normalized.x, normalized.y, normalized.z, val4.w);
				}
			}
		}
	}
	internal enum SnowMode
	{
		ScaleLength,
		Remove
	}
	internal sealed class PieceVariantDefinition
	{
		public string SourcePrefabName { get; }

		public string NewPrefabName { get; }

		public string DisplayName { get; }

		public string Description { get; }

		public float LengthScale { get; }

		public float CostRatio { get; }

		public SnowMode Snow { get; }

		public MeshCut Cut { get; }

		public KeepSpan Keep { get; }

		public SnapAxis? Axis { get; }

		public PieceVariantDefinition(string sourcePrefabName, string newPrefabName, string displayName, string description, float lengthScale, SnowMode snow, float? costRatio = null, MeshCut cut = null, KeepSpan keep = null, SnapAxis? axis = null)
		{
			SourcePrefabName = sourcePrefabName;
			NewPrefabName = newPrefabName;
			DisplayName = displayName;
			Description = description;
			LengthScale = lengthScale;
			CostRatio = costRatio ?? lengthScale;
			Snow = snow;
			Cut = cut;
			Keep = keep;
			Axis = axis;
			base..ctor();
		}
	}
	internal static class PieceVariantFactory
	{
		private readonly struct BeamFrame
		{
			public readonly Vector3 Center;

			public readonly Vector3 Axis;

			public readonly float Scale;

			public BeamFrame(Vector3 center, Vector3 axis, float scale)
			{
				//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_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)
				Center = center;
				Axis = axis;
				Scale = scale;
			}

			public Vector3 Directional(Vector3 v)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				return v - (1f - Scale) * Vector3.Dot(v, Axis) * Axis;
			}

			public Vector3 MapPoint(Vector3 p)
			{
				//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_0012: 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_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				return Scale * Center + Directional(p - Center);
			}
		}

		private const float AxisAlignmentThreshold = 0.998f;

		public static void Build(PieceVariantDefinition def, ManualLogSource log)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Expected O, but got Unknown
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab(def.SourcePrefabName);
			if ((Object)(object)prefab == (Object)null)
			{
				log.LogError((object)("Source prefab not found: " + def.SourcePrefabName));
				return;
			}
			Piece component = prefab.GetComponent<Piece>();
			List<Transform> list = new List<Transform>();
			component.GetSnapPoints(list);
			if (list.Count < 2)
			{
				log.LogError((object)(def.SourcePrefabName + ": expected at least 2 snap points (beam or pole), found " + list.Count + ". Skipped."));
				return;
			}
			GameObject val = PrefabManager.Instance.CreateClonedPrefab(def.NewPrefabName, prefab);
			Resize(val, def, log);
			Piece component2 = val.GetComponent<Piece>();
			component2.m_usage = (UsageTagFlags)(component2.m_usage | 0x44);
			Sprite val2 = IconLoader.Load(def.NewPrefabName, log);
			if ((Object)(object)val2 != (Object)null)
			{
				component2.m_icon = val2;
			}
			PieceConfig val3 = new PieceConfig
			{
				Name = def.DisplayName,
				Description = def.Description,
				Icon = val2,
				PieceTable = "Hammer",
				Category = ((object)Unsafe.As<PieceCategory, PieceCategory>(ref component.m_category)/*cast due to .constrained prefix*/).ToString(),
				CraftingStation = (((Object)(object)component.m_craftingStation != (Object)null) ? ((Object)component.m_craftingStation).name : ""),
				Requirements = ((IEnumerable<Requirement>)component.m_resources).Select((Func<Requirement, RequirementConfig>)((Requirement r) => new RequirementConfig
				{
					Item = ((Object)r.m_resItem).name,
					Amount = Math.Max(1, (int)Math.Ceiling((float)r.m_amount * def.CostRatio)),
					Recover = r.m_recover
				})).ToArray()
			};
			PieceManager.Instance.AddPiece(new CustomPiece(val, false, val3));
			log.LogInfo((object)("Registered " + def.NewPrefabName + " (from " + def.SourcePrefabName + ")"));
		}

		private static void Resize(GameObject clone, PieceVariantDefinition def, ManualLogSource log)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01dc: Unknown result type (might be due to invalid IL or missing references)
			float lengthScale = def.LengthScale;
			Transform transform = clone.transform;
			Piece component = clone.GetComponent<Piece>();
			List<Transform> list = new List<Transform>();
			component.GetSnapPoints(list);
			(Vector3 Center, Vector3 Axis, float Length) tuple = SnapFrame(list, def.Axis);
			Vector3 item = tuple.Center;
			Vector3 item2 = tuple.Axis;
			float item3 = tuple.Length;
			BeamFrame frame = new BeamFrame(item, item2, lengthScale);
			foreach (Transform item4 in list)
			{
				item4.localPosition = frame.MapPoint(item4.localPosition);
			}
			Transform val = null;
			int num = 0;
			int num2;
			List<Transform> list2;
			if (def.Cut == null)
			{
				num2 = ((def.Keep != null) ? 1 : 0);
				if (num2 == 0)
				{
					list2 = new List<Transform>();
					goto IL_00b8;
				}
			}
			else
			{
				num2 = 1;
			}
			list2 = VisualRoots(clone);
			goto IL_00b8;
			IL_00b8:
			List<Transform> list3 = list2;
			if (num2 != 0 && list3.Count == 0)
			{
				log.LogWarning((object)(def.NewPrefabName + ": no WearNTear visuals to reshape; scaling instead."));
			}
			foreach (Transform child in ((IEnumerable)transform).Cast<Transform>().ToList())
			{
				if (list.Contains(child) || list3.Exists((Transform visual) => (Object)(object)visual == (Object)(object)child || visual.IsChildOf(child)))
				{
					continue;
				}
				if (((Object)child).name.IndexOf("snow", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					HandleSnow(child, def);
					continue;
				}
				bool flag = (Object)(object)((Component)child).GetComponent<Collider>() != (Object)null;
				bool flag2 = (Object)(object)((Component)child).GetComponent<MeshFilter>() != (Object)null;
				if (flag || flag2)
				{
					if (TryFindAlignedAxis(child, frame.Axis, out var axisIndex))
					{
						child.localPosition = frame.MapPoint(child.localPosition);
						child.localScale = ScaleAxis(child.localScale, axisIndex, lengthScale);
						continue;
					}
					if (flag)
					{
						log.LogWarning((object)(def.NewPrefabName + ": collider '" + ((Object)child).name + "' has no axis along the beam; left unchanged."));
						continue;
					}
				}
				if (!((Object)(object)((Component)child).GetComponentInChildren<Renderer>(true) == (Object)null) || !((Object)(object)((Component)child).GetComponentInChildren<Collider>(true) == (Object)null))
				{
					if ((Object)(object)val == (Object)null)
					{
						val = CreatePivot(transform, frame);
					}
					Wrap(child, val, frame);
					num++;
				}
			}
			if (list3.Count > 0)
			{
				ReshapeMeshes(transform, list3, MeshShortener(frame, item3, def, log), def, log);
			}
			LODGroup[] componentsInChildren = clone.GetComponentsInChildren<LODGroup>(true);
			for (int num3 = 0; num3 < componentsInChildren.Length; num3++)
			{
				componentsInChildren[num3].RecalculateBounds();
			}
		}

		private static List<Transform> VisualRoots(GameObject clone)
		{
			WearNTear component = clone.GetComponent<WearNTear>();
			if (!((Object)(object)component == (Object)null))
			{
				return (from visual in (IEnumerable<GameObject>)(object)new GameObject[3] { component.m_new, component.m_worn, component.m_broken }
					where (Object)(object)visual != (Object)null
					select visual.transform).Distinct().ToList();
			}
			return new List<Transform>();
		}

		private static (Vector3 Center, Vector3 Axis, float Length) SnapFrame(List<Transform> snaps, SnapAxis? along)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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)
			if (snaps.Count == 2 && !along.HasValue)
			{
				Vector3 localPosition = snaps[0].localPosition;
				Vector3 localPosition2 = snaps[1].localPosition;
				Vector3 item = (localPosition + localPosition2) * 0.5f;
				Vector3 val = localPosition2 - localPosition;
				return (Center: item, Axis: ((Vector3)(ref val)).normalized, Length: Vector3.Distance(localPosition, localPosition2));
			}
			Vector3 val2 = snaps[0].localPosition;
			Vector3 val3 = val2;
			foreach (Transform snap in snaps)
			{
				val2 = Vector3.Min(val2, snap.localPosition);
				val3 = Vector3.Max(val3, snap.localPosition);
			}
			Vector3 val4 = val3 - val2;
			int num = 0;
			for (int i = 1; i < 3; i++)
			{
				if (((Vector3)(ref val4))[i] > ((Vector3)(ref val4))[num])
				{
					num = i;
				}
			}
			if (along.HasValue)
			{
				num = (int)along.Value;
			}
			Vector3 zero = Vector3.zero;
			((Vector3)(ref zero))[num] = 1f;
			return (Center: (val2 + val3) * 0.5f, Axis: zero, Length: ((Vector3)(ref val4))[num]);
		}

		private static Func<Mesh, Matrix4x4, Mesh> MeshShortener(BeamFrame frame, float length, PieceVariantDefinition def, ManualLogSource log)
		{
			//IL_0033: 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_0009: 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)
			if (def.Cut != null)
			{
				return new MeshCutter(frame.Center, frame.Axis, length, def.LengthScale, def.Cut).Cut;
			}
			SpanStretcher spanStretcher = new SpanStretcher(frame.Center, frame.Axis, length, def.LengthScale, def.Keep);
			if (!spanStretcher.Fits)
			{
				log.LogError((object)(def.NewPrefabName + ": the kept span is longer than the new piece; meshes left as they are."));
				return (Mesh mesh, Matrix4x4 _) => mesh;
			}
			return spanStretcher.Stretch;
		}

		private static void ReshapeMeshes(Transform root, List<Transform> visuals, Func<Mesh, Matrix4x4, Mesh> shorten, PieceVariantDefinition def, ManualLogSource log)
		{
			//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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix;
			MeshCollider val2 = default(MeshCollider);
			foreach (MeshFilter item in visuals.SelectMany((Transform visual) => ((Component)visual).GetComponentsInChildren<MeshFilter>(true)))
			{
				Mesh sharedMesh = item.sharedMesh;
				if ((Object)(object)sharedMesh == (Object)null)
				{
					continue;
				}
				if (!sharedMesh.isReadable)
				{
					log.LogError((object)(def.NewPrefabName + ": mesh '" + ((Object)sharedMesh).name + "' isn't readable, so it can't be reshaped."));
					continue;
				}
				Mesh sharedMesh2 = (item.sharedMesh = shorten(sharedMesh, worldToLocalMatrix * ((Component)item).transform.localToWorldMatrix));
				if (((Component)item).TryGetComponent<MeshCollider>(ref val2) && (Object)(object)val2.sharedMesh == (Object)(object)sharedMesh)
				{
					val2.sharedMesh = sharedMesh2;
				}
			}
		}

		private static bool TryFindAlignedAxis(Transform node, Vector3 beamAxis, out int axisIndex)
		{
			//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_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_0015: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			Quaternion localRotation = node.localRotation;
			Vector3[] array = (Vector3[])(object)new Vector3[3]
			{
				localRotation * Vector3.right,
				localRotation * Vector3.up,
				localRotation * Vector3.forward
			};
			axisIndex = 0;
			float num = 0f;
			for (int i = 0; i < array.Length; i++)
			{
				float num2 = Mathf.Abs(Vector3.Dot(array[i], beamAxis));
				if (num2 > num)
				{
					num = num2;
					axisIndex = i;
				}
			}
			return num >= 0.998f;
		}

		private static Vector3 ScaleAxis(Vector3 scale, int axis, float f)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			((Vector3)(ref scale))[axis] = ((Vector3)(ref scale))[axis] * f;
			return scale;
		}

		private static Transform CreatePivot(Transform root, BeamFrame frame)
		{
			//IL_0005: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("HalfBeams_pivot");
			val.transform.SetParent(root, false);
			val.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, frame.Axis);
			val.transform.localPosition = frame.Scale * frame.Center;
			val.transform.localScale = new Vector3(1f, 1f, frame.Scale);
			return val.transform;
		}

		private static void Wrap(Transform node, Transform pivot, BeamFrame frame)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.Inverse(pivot.localRotation);
			Quaternion localRotation = node.localRotation;
			Vector3 localPosition = node.localPosition;
			node.SetParent(pivot, false);
			node.localRotation = val * localRotation;
			node.localPosition = val * (localPosition - frame.Center);
		}

		private static void HandleSnow(Transform node, PieceVariantDefinition def)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (def.Snow == SnowMode.ScaleLength)
			{
				Vector3 localPosition = node.localPosition;
				localPosition.x *= def.LengthScale;
				node.localPosition = localPosition;
				Vector3 localScale = node.localScale;
				localScale.x *= def.LengthScale;
				node.localScale = localScale;
			}
			else
			{
				Object.DestroyImmediate((Object)(object)((Component)node).gameObject);
			}
		}
	}
	internal static class PieceVariantRegistry
	{
		private const float Half = 0.5f;

		private const float Quarter = 0.25f;

		private const float Eighth = 0.125f;

		private const float Full = 1f;

		public static readonly IReadOnlyList<PieceVariantDefinition> All;

		static PieceVariantRegistry()
		{
			PieceVariantDefinition[] obj = new PieceVariantDefinition[59]
			{
				new PieceVariantDefinition("wood_pole", "half_wood_pole", "$piece_half_wood_pole", "$piece_halfbeam_wood_description", 0.5f, SnowMode.Remove),
				new PieceVariantDefinition("wood_beam_1", "half_wood_beam", "$piece_half_wood_beam", "$piece_halfbeam_wood_description", 0.5f, SnowMode.ScaleLength),
				new PieceVariantDefinition("wood_beam_26", "half_wood_beam_26", "$piece_half_wood_beam_26", "$piece_halfbeam_wood_description", 0.5f, SnowMode.Remove),
				new PieceVariantDefinition("wood_beam_45", "half_wood_beam_45", "$piece_half_wood_beam_45", "$piece_halfbeam_wood_description", 0.5f, SnowMode.Remove),
				new PieceVariantDefinition("wood_beam_67", "half_wood_beam_67", "$piece_half_wood_beam_67", "$piece_halfbeam_wood_description", 0.5f, SnowMode.Remove),
				new PieceVariantDefinition("wood_pole_log", "half_log_pole", "$piece_half_log_pole", "$piece_halfbeam_log_description", 0.5f, SnowMode.Remove),
				new PieceVariantDefinition("wood_pole_log", "quarter_log_pole", "$piece_quarter_log_pole", "$piece_halfbeam_log_description", 0.25f, SnowMode.Remove),
				new PieceVariantDefinition("wood_pole_log_4_worn", "half_worn_log_pole", "$piece_half_worn_log_pole", "$piece_halfbeam_log_description", 0.5f, SnowMode.Remove),
				new PieceVariantDefinition("wood_pole_log_4_worn", "quarter_worn_log_pole", "$piece_quarter_worn_log_pole", "$piece_halfbeam_log_description", 0.25f, SnowMode.Remove),
				new PieceVariantDefinition("wood_pole_log_4_worn", "eighth_worn_log_pole", "$piece_eighth_worn_log_pole", "$piece_halfbeam_log_description", 0.125f, SnowMode.Remove),
				new PieceVariantDefinition("wood_wall_log", "half_log_beam", "$piece_half_log_beam", "$piece_halfbeam_log_description", 0.5f, SnowMode.ScaleLength),
				new PieceVariantDefinition("wood_wall_log", "quarter_log_beam", "$piece_quarter_log_beam", "$piece_halfbeam_log_description", 0.25f, SnowMode.ScaleLength),
				new PieceVariantDefinition("wood_log_26", "half_log_beam_26", "$piece_half_log_beam_26", "$piece_halfbeam_log_description", 0.5f, SnowMode.Remove),
				new PieceVariantDefinition("wood_log_45", "half_log_beam_45", "$piece_half_log_beam_45", "$piece_halfbeam_log_description", 0.5f, SnowMode.Remove),
				new PieceVariantDefinition("wood_log_67", "half_log_beam_67", "$piece_half_log_beam_67", "$piece_halfbeam_log_description", 0.5f, SnowMode.Remove),
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null
			};
			MeshCut cut = new MeshCut(-0.508f, 0.492f);
			obj[15] = new PieceVariantDefinition("woodiron_pole", "half_woodiron_pole", "$piece_half_woodiron_pole", "$piece_halfbeam_woodiron_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.748f, 0.752f);
			obj[16] = new PieceVariantDefinition("woodiron_pole", "quarter_woodiron_pole", "$piece_quarter_woodiron_pole", "$piece_halfbeam_woodiron_description", 0.25f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.4951f, 0.5049f);
			obj[17] = new PieceVariantDefinition("woodiron_beam", "half_woodiron_beam", "$piece_half_woodiron_beam", "$piece_halfbeam_woodiron_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.7501f, 0.7499f);
			obj[18] = new PieceVariantDefinition("woodiron_beam", "quarter_woodiron_beam", "$piece_quarter_woodiron_beam", "$piece_halfbeam_woodiron_description", 0.25f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.5579f, 0.5601f);
			obj[19] = new PieceVariantDefinition("woodiron_beam_26", "half_woodiron_beam_26", "$piece_half_woodiron_beam_26", "$piece_halfbeam_woodiron_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.7069f, 0.7073f);
			obj[20] = new PieceVariantDefinition("woodiron_beam_45", "half_woodiron_beam_45", "$piece_half_woodiron_beam_45", "$piece_halfbeam_woodiron_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-1.1167f, 1.1194f);
			obj[21] = new PieceVariantDefinition("woodiron_beam_67", "half_woodiron_beam_67", "$piece_half_woodiron_beam_67", "$piece_halfbeam_woodiron_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.5005f, 0.4995f);
			obj[22] = new PieceVariantDefinition("darkwood_pole", "half_darkwood_pole", "$piece_half_darkwood_pole", "$piece_halfbeam_darkwood_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.7505f, 0.7495f);
			obj[23] = new PieceVariantDefinition("darkwood_pole", "quarter_darkwood_pole", "$piece_quarter_darkwood_pole", "$piece_halfbeam_darkwood_description", 0.25f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.5005f, 0.4995f);
			obj[24] = new PieceVariantDefinition("darkwood_beam", "half_darkwood_beam", "$piece_half_darkwood_beam", "$piece_halfbeam_darkwood_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.7505f, 0.7495f);
			obj[25] = new PieceVariantDefinition("darkwood_beam", "quarter_darkwood_beam", "$piece_quarter_darkwood_beam", "$piece_halfbeam_darkwood_description", 0.25f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.5575f, 0.5605f);
			obj[26] = new PieceVariantDefinition("darkwood_beam_26", "half_darkwood_beam_26", "$piece_half_darkwood_beam_26", "$piece_halfbeam_darkwood_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.7052f, 0.709f);
			obj[27] = new PieceVariantDefinition("darkwood_beam_45", "half_darkwood_beam_45", "$piece_half_darkwood_beam_45", "$piece_halfbeam_darkwood_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-1.1176f, 1.1185f);
			obj[28] = new PieceVariantDefinition("darkwood_beam_67", "half_darkwood_beam_67", "$piece_half_darkwood_beam_67", "$piece_halfbeam_darkwood_description", 0.5f, SnowMode.Remove, null, cut);
			obj[29] = new PieceVariantDefinition("piece_dvergr_pole", "full_dvergr_pole", "$piece_full_dvergr_pole", "$piece_halfbeam_dvergr_description", 1f, SnowMode.Remove);
			KeepSpan keep = new KeepSpan(-0.467f, -0.09f);
			obj[30] = new PieceVariantDefinition("piece_dvergr_pole", "half_dvergr_pole", "$piece_half_dvergr_pole", "$piece_halfbeam_dvergr_description", 0.5f, SnowMode.Remove, null, null, keep);
			keep = new KeepSpan(-0.467f, -0.09f);
			obj[31] = new PieceVariantDefinition("piece_dvergr_pole", "quarter_dvergr_pole", "$piece_quarter_dvergr_pole", "$piece_halfbeam_dvergr_description", 0.25f, SnowMode.Remove, null, null, keep);
			obj[32] = new PieceVariantDefinition("ashwood_pole_1m", "half_ashwood_pole", "$piece_half_ashwood_pole", "$piece_halfbeam_ashwood_description", 0.5f, SnowMode.Remove);
			obj[33] = new PieceVariantDefinition("ashwood_beam_1m", "half_ashwood_beam", "$piece_half_ashwood_beam", "$piece_halfbeam_ashwood_description", 0.5f, SnowMode.ScaleLength);
			obj[34] = new PieceVariantDefinition("ashwood_wall_beam_26", "half_ashwood_beam_26", "$piece_half_ashwood_beam_26", "$piece_halfbeam_ashwood_description", 0.5f, SnowMode.Remove);
			obj[35] = new PieceVariantDefinition("ashwood_wall_beam_45", "half_ashwood_beam_45", "$piece_half_ashwood_beam_45", "$piece_halfbeam_ashwood_description", 0.5f, SnowMode.Remove);
			obj[36] = new PieceVariantDefinition("ashwood_wall_beam_67", "half_ashwood_beam_67", "$piece_half_ashwood_beam_67", "$piece_halfbeam_ashwood_description", 0.5f, SnowMode.Remove);
			obj[37] = new PieceVariantDefinition("Piece_grausten_pillarbase_small", "half_grausten_pillar_small", "$piece_half_grausten_pillar_small", "$piece_halfbeam_grausten_description", 0.5f, SnowMode.Remove);
			SnapAxis? axis = SnapAxis.Y;
			obj[38] = new PieceVariantDefinition("Piece_grausten_pillarbase_medium", "half_grausten_pillar_medium", "$piece_half_grausten_pillar_medium", "$piece_halfbeam_grausten_description", 0.5f, SnowMode.Remove, null, null, null, axis);
			obj[39] = new PieceVariantDefinition("Piece_grausten_pillarbeam_small", "half_grausten_beam_small", "$piece_half_grausten_beam_small", "$piece_halfbeam_grausten_description", 0.5f, SnowMode.Remove);
			axis = SnapAxis.X;
			obj[40] = new PieceVariantDefinition("Piece_grausten_pillarbeam_medium", "half_grausten_beam_medium", "$piece_half_grausten_beam_medium", "$piece_halfbeam_grausten_description", 0.5f, SnowMode.Remove, null, null, null, axis);
			obj[41] = new PieceVariantDefinition("Piece_flametal_pillar", "half_flametal_pillar", "$piece_half_flametal_pillar", "$piece_halfbeam_flametal_description", 0.5f, SnowMode.Remove);
			obj[42] = new PieceVariantDefinition("Piece_flametal_pillar", "quarter_flametal_pillar", "$piece_quarter_flametal_pillar", "$piece_halfbeam_flametal_description", 0.25f, SnowMode.Remove);
			obj[43] = new PieceVariantDefinition("Piece_flametal_beam", "half_flametal_beam", "$piece_half_flametal_beam", "$piece_halfbeam_flametal_description", 0.5f, SnowMode.Remove);
			obj[44] = new PieceVariantDefinition("Piece_flametal_beam", "quarter_flametal_beam", "$piece_quarter_flametal_beam", "$piece_halfbeam_flametal_description", 0.25f, SnowMode.Remove);
			obj[45] = new PieceVariantDefinition("stave_pole_2m", "half_stave_pole", "$piece_half_stave_pole", "$piece_halfbeam_stave_description", 0.5f, SnowMode.Remove);
			obj[46] = new PieceVariantDefinition("stave_pole_2m", "quarter_stave_pole", "$piece_quarter_stave_pole", "$piece_halfbeam_stave_description", 0.25f, SnowMode.Remove);
			obj[47] = new PieceVariantDefinition("stave_beam_2m", "half_stave_beam", "$piece_half_stave_beam", "$piece_halfbeam_stave_description", 0.5f, SnowMode.Remove);
			obj[48] = new PieceVariantDefinition("stave_beam_2m", "quarter_stave_beam", "$piece_quarter_stave_beam", "$piece_halfbeam_stave_description", 0.25f, SnowMode.Remove);
			obj[49] = new PieceVariantDefinition("stave_beam_26", "half_stave_beam_26", "$piece_half_stave_beam_26", "$piece_halfbeam_stave_description", 0.5f, SnowMode.Remove);
			obj[50] = new PieceVariantDefinition("stave_beam_45", "half_stave_beam_45", "$piece_half_stave_beam_45", "$piece_halfbeam_stave_description", 0.5f, SnowMode.Remove);
			obj[51] = new PieceVariantDefinition("stave_beam_67", "half_stave_beam_67", "$piece_half_stave_beam_67", "$piece_halfbeam_stave_description", 0.5f, SnowMode.Remove);
			cut = new MeshCut(-0.5024f, 0.4976f);
			obj[52] = new PieceVariantDefinition("stave_deco_pole_2m", "half_stave_deco_pole", "$piece_half_stave_deco_pole", "$piece_halfbeam_stave_deco_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.6674f, 0.6659f, 0.75f);
			obj[53] = new PieceVariantDefinition("stave_deco_pole_2m", "quarter_stave_deco_pole", "$piece_quarter_stave_deco_pole", "$piece_halfbeam_stave_deco_description", 0.25f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.5014f, 0.4986f);
			obj[54] = new PieceVariantDefinition("stave_deco_beam_2m", "half_stave_deco_beam", "$piece_half_stave_deco_beam", "$piece_halfbeam_stave_deco_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.6664f, 0.6669f, 0.75f);
			obj[55] = new PieceVariantDefinition("stave_deco_beam_2m", "quarter_stave_deco_beam", "$piece_quarter_stave_deco_beam", "$piece_halfbeam_stave_deco_description", 0.25f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.4928f, 0.4897f, 0.8919f);
			obj[56] = new PieceVariantDefinition("stave_deco_beam_26", "half_stave_deco_beam_26", "$piece_half_stave_deco_beam_26", "$piece_halfbeam_stave_deco_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-0.8453f, 0.5689f);
			obj[57] = new PieceVariantDefinition("stave_deco_beam_45", "half_stave_deco_beam_45", "$piece_half_stave_deco_beam_45", "$piece_halfbeam_stave_deco_description", 0.5f, SnowMode.Remove, null, cut);
			cut = new MeshCut(-1.1176f, 1.1184f);
			obj[58] = new PieceVariantDefinition("stave_deco_beam_67", "half_stave_deco_beam_67", "$piece_half_stave_deco_beam_67", "$piece_halfbeam_stave_deco_description", 0.5f, SnowMode.Remove, null, cut);
			All = new <>z__ReadOnlyArray<PieceVariantDefinition>(obj);
		}
	}
	internal enum SnapAxis
	{
		X,
		Y,
		Z
	}
	internal sealed class SpanStretcher(Vector3 center, Vector3 axis, float length, float factor, KeepSpan keep)
	{
		private const float SideEpsilon = 0.0001f;

		private readonly Vector3 _center = center;

		private readonly Vector3 _axis = axis;

		private readonly float _length = length;

		private readonly float _factor = factor;

		private readonly KeepSpan _keep = keep;

		private readonly float _scale = (length * factor - keep.Length) / (length - keep.Length);

		private readonly Dictionary<(Mesh, Matrix4x4), Mesh> _cache = new Dictionary<(Mesh, Matrix4x4), Mesh>();

		public bool Fits => _scale > 0f;

		public Mesh Stretch(Mesh source, Matrix4x4 nodeToRoot)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			if (_cache.TryGetValue((source, nodeToRoot), out var value))
			{
				return value;
			}
			Mesh val = Object.Instantiate<Mesh>(source);
			((Object)val).name = ((Object)source).name + "_halfbeam";
			Matrix4x4 inverse = ((Matrix4x4)(ref nodeToRoot)).inverse;
			Matrix4x4 identity = Matrix4x4.identity;
			Vector3 val2;
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					int num = i;
					int num2 = j;
					float num3 = ((Matrix4x4)(ref identity))[num, num2];
					float num4 = 1f - _scale;
					val2 = axis;
					float num5 = num4 * ((Vector3)(ref val2))[i];
					val2 = axis;
					((Matrix4x4)(ref identity))[num, num2] = num3 - num5 * ((Vector3)(ref val2))[j];
				}
			}
			Matrix4x4 val3 = inverse * identity * nodeToRoot;
			Matrix4x4 inverse2 = ((Matrix4x4)(ref val3)).inverse;
			Matrix4x4 transpose = ((Matrix4x4)(ref inverse2)).transpose;
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector4> list3 = new List<Vector4>();
			val.GetVertices(list);
			val.GetNormals(list2);
			val.GetTangents(list3);
			for (int k = 0; k < list.Count; k++)
			{
				Vector3 val4 = ((Matrix4x4)(ref nodeToRoot)).MultiplyPoint3x4(list[k]);
				float num6 = Vector3.Dot(val4 - center, axis);
				val4 = factor * center + (val4 - center) + axis * (Map(num6) - num6);
				list[k] = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(val4);
				if (!(num6 > keep.Start + 0.0001f) || !(num6 < keep.End - 0.0001f))
				{
					if (k < list2.Count)
					{
						int index = k;
						val2 = ((Matrix4x4)(ref transpose)).MultiplyVector(list2[k]);
						list2[index] = ((Vector3)(ref val2)).normalized;
					}
					if (k < list3.Count)
					{
						Vector4 val5 = list3[k];
						val2 = ((Matrix4x4)(ref val3)).MultiplyVector(Vector4.op_Implicit(val5));
						Vector3 normalized = ((Vector3)(ref val2)).normalized;
						list3[k] = new Vector4(normalized.x, normalized.y, normalized.z, val5.w);
					}
				}
			}
			val.SetVertices(list);
			if (list2.Count > 0)
			{
				val.SetNormals(list2);
			}
			if (list3.Count > 0)
			{
				val.SetTangents(list3);
			}
			val.RecalculateBounds();
			_cache[(source, nodeToRoot)] = val;
			return val;
		}

		private float Map(float along)
		{
			float num = (0f - length) * factor / 2f + _scale * (Mathf.Min(along, keep.Start) + length / 2f);
			float num2 = Mathf.Clamp(along, keep.Start, keep.End) - keep.Start;
			float num3 = _scale * (Mathf.Max(along, keep.End) - keep.End);
			return num + num2 + num3;
		}
	}
}
namespace HalfBeam.Core
{
	internal static class Translations
	{
		private const string ResourcePrefix = "HalfBeam.Translations.";

		private const string ResourceSuffix = ".json";

		public static void Load()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				if (text.StartsWith("HalfBeam.Translations.", StringComparison.Ordinal) && text.EndsWith(".json", StringComparison.Ordinal))
				{
					string text2 = text.Substring("HalfBeam.Translations.".Length, text.Length - "HalfBeam.Translations.".Length - ".json".Length);
					using StreamReader streamReader = new StreamReader(executingAssembly.GetManifestResourceStream(text));
					localization.AddJsonFile(text2, streamReader.ReadToEnd());
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}