Decompiled source of SlimBeams v0.1.0

plugins/SlimBeams/SlimBeams.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SlimBeams")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("SlimBeams")]
[assembly: AssemblyTitle("SlimBeams")]
[assembly: AssemblyVersion("0.1.0.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 SlimBeams
{
	public sealed class SlimPiece : MonoBehaviour
	{
		public string Source;

		public Vector3 A;

		public Vector3 B;

		public Vector3 U;

		public Vector3 V;

		public Vector3 Center;

		public float HalfV;

		public float HalfZ;

		public Vector3 CollisionCenter;

		public Vector3 CollisionSize;

		public Vector3 Compress(Vector3 p)
		{
			//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_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_000e: 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_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_0028: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = p - Center;
			return Center + 0.25f * val + 0.75f * Vector3.Dot(val, U) * U;
		}
	}
	[BepInPlugin("SmeagsMods.SlimBeams", "Slim Beams", "0.1.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(WearNTear), "GetMaterialProperties")]
		private static class SupportPatch
		{
			private static void Postfix(WearNTear __instance, ref float maxSupport)
			{
				if ((Object)(object)((Component)__instance).GetComponent<SlimPiece>() != (Object)null)
				{
					maxSupport = 25f;
				}
			}
		}

		[HarmonyPatch(typeof(WearNTear), "SetupColliders")]
		private static class BoundsPatch
		{
			private static readonly Type BoundType = typeof(WearNTear).GetNestedType("BoundData", BindingFlags.NonPublic);

			private static void Postfix(WearNTear __instance)
			{
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//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_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_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				SlimPiece component = ((Component)__instance).GetComponent<SlimPiece>();
				if (Object.op_Implicit((Object)(object)component))
				{
					IList obj = (IList)AccessTools.Field(typeof(WearNTear), "m_bounds").GetValue(__instance);
					obj.Clear();
					object obj2 = Activator.CreateInstance(BoundType);
					AccessTools.Field(BoundType, "m_pos").SetValue(obj2, ((Component)__instance).transform.TransformPoint(component.CollisionCenter));
					AccessTools.Field(BoundType, "m_rot").SetValue(obj2, ((Component)__instance).transform.rotation * Quaternion.FromToRotation(Vector3.right, component.U));
					AccessTools.Field(BoundType, "m_size").SetValue(obj2, (component.CollisionSize + Vector3.one * 0.3f) * 0.5f);
					obj.Add(obj2);
				}
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class ScenePatch
		{
			private static void Postfix(ZNetScene __instance)
			{
				Register(__instance);
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class DbPatch
		{
			private static void Postfix(ObjectDB __instance)
			{
				AddToHammer(__instance);
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static class DbCopyPatch
		{
			private static void Postfix(ObjectDB __instance)
			{
				AddToHammer(__instance);
			}
		}

		public const string Guid = "SmeagsMods.SlimBeams";

		public static readonly string[] Sources = new string[7] { "wood_beam_1", "wood_beam", "wood_pole", "wood_pole2", "wood_beam_26", "wood_beam_45", "wood_beam_67" };

		private static readonly string[] Labels = new string[7] { "Slim wood beam 1 m", "Slim wood beam 2 m", "Slim wood post 1 m", "Slim wood post 2 m", "Slim wood beam 26 degrees", "Slim wood beam 45 degrees", "Slim wood beam 67 degrees" };

		public static readonly Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>();

		private static Plugin instance;

		private static GameObject storage;

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			storage = new GameObject("Slim Beams inactive prefab storage");
			storage.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)storage);
			new Harmony("SmeagsMods.SlimBeams").PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Slim Beams 0.1.0 private beta: quarter thickness, 25 support capacity, original health.");
		}

		public static string PrefabName(string source)
		{
			return "SlimBeams_" + source;
		}

		private static void Register(ZNetScene scene)
		{
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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)
			Dictionary<int, GameObject> dictionary = AccessTools.FieldRefAccess<ZNetScene, Dictionary<int, GameObject>>("m_namedPrefabs").Invoke(scene);
			for (int i = 0; i < Sources.Length; i++)
			{
				string text = PrefabName(Sources[i]);
				GameObject value = null;
				try
				{
					int stableHashCode = StringExtensionMethods.GetStableHashCode(text);
					if (dictionary.TryGetValue(stableHashCode, out var value2))
					{
						if (!Prefabs.TryGetValue(text, out var value3) || (Object)(object)value3 != (Object)(object)value2)
						{
							throw new InvalidOperationException("Prefab identity collision: " + text);
						}
						continue;
					}
					if (!Prefabs.TryGetValue(text, out value))
					{
						GameObject prefab = scene.GetPrefab(Sources[i]);
						if (!Object.op_Implicit((Object)(object)prefab) || !Object.op_Implicit((Object)(object)prefab.GetComponent<Piece>()) || !Object.op_Implicit((Object)(object)prefab.GetComponent<WearNTear>()) || !Object.op_Implicit((Object)(object)prefab.GetComponent<ZNetView>()))
						{
							throw new InvalidOperationException("Missing source components: " + Sources[i]);
						}
						value = Object.Instantiate<GameObject>(prefab, storage.transform, false);
						((Object)value).name = text;
						value.transform.localPosition = Vector3.zero;
						value.transform.localRotation = Quaternion.identity;
						value.transform.localScale = Vector3.one;
						Slim(value, Sources[i]);
						Piece component = value.GetComponent<Piece>();
						component.m_name = Labels[i];
						component.m_description = "Quarter thickness; original length and health. Structural capacity 25 (normal wood: 100). Custom end, centre, face and vanilla-post adapter snaps.";
						value.SetActive(true);
						Prefabs.Add(text, value);
					}
					scene.m_prefabs.Add(value);
					dictionary.Add(stableHashCode, value);
					((BaseUnityPlugin)instance).Logger.LogInfo((object)("Registered " + text));
				}
				catch (Exception ex)
				{
					if (Object.op_Implicit((Object)(object)value) && !Prefabs.ContainsKey(text))
					{
						Object.Destroy((Object)(object)value);
					}
					((BaseUnityPlugin)instance).Logger.LogError((object)("Slim piece unavailable: " + text + ": " + ex));
				}
			}
			AddToHammer(ObjectDB.instance);
		}

		private static void AddToHammer(ObjectDB db)
		{
			if (!Object.op_Implicit((Object)(object)db))
			{
				return;
			}
			GameObject itemPrefab = db.GetItemPrefab("Hammer");
			if (!Object.op_Implicit((Object)(object)itemPrefab))
			{
				return;
			}
			PieceTable val = itemPrefab.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_buildPieces;
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			foreach (GameObject value in Prefabs.Values)
			{
				if (!val.m_pieces.Contains(value))
				{
					val.m_pieces.Add(value);
				}
			}
		}

		public static void Slim(GameObject clone, string sourceName)
		{
			//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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_005b: 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_0093: 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_009b: 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_00a3: 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_00ae: 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_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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: 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_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Expected O, but got Unknown
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Expected O, but got Unknown
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: 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_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_0629: Unknown result type (might be due to invalid IL or missing references)
			//IL_0634: Unknown result type (might be due to invalid IL or missing references)
			//IL_0640: Unknown result type (might be due to invalid IL or missing references)
			//IL_064e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0668: Unknown result type (might be due to invalid IL or missing references)
			//IL_0669: Unknown result type (might be due to invalid IL or missing references)
			//IL_0672: Unknown result type (might be due to invalid IL or missing references)
			//IL_0677: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_071c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0721: Unknown result type (might be due to invalid IL or missing references)
			//IL_0728: Unknown result type (might be due to invalid IL or missing references)
			//IL_072d: Unknown result type (might be due to invalid IL or missing references)
			//IL_074b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0750: Unknown result type (might be due to invalid IL or missing references)
			//IL_0757: Unknown result type (might be due to invalid IL or missing references)
			//IL_075c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0522: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_0793: Unknown result type (might be due to invalid IL or missing references)
			//IL_0796: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0818: Unknown result type (might be due to invalid IL or missing references)
			//IL_081d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0843: Unknown result type (might be due to invalid IL or missing references)
			//IL_0846: Unknown result type (might be due to invalid IL or missing references)
			//IL_0855: Unknown result type (might be due to invalid IL or missing references)
			//IL_085d: Unknown result type (might be due to invalid IL or missing references)
			//IL_087b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0880: Unknown result type (might be due to invalid IL or missing references)
			//IL_0890: Unknown result type (might be due to invalid IL or missing references)
			//IL_0893: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cd: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = clone.transform;
			List<Transform> list = new List<Transform>();
			clone.GetComponent<Piece>().GetSnapPoints(list);
			if (list.Count != 2)
			{
				throw new InvalidOperationException("Expected two native endpoint snaps");
			}
			Vector3 val = list[0].localPosition;
			Vector3 val2 = list[1].localPosition;
			if (val2.x < val.x || (Mathf.Abs(val2.x - val.x) < 0.001f && val2.y < val.y))
			{
				Vector3 val3 = val;
				val = val2;
				val2 = val3;
			}
			SlimPiece slimPiece = clone.AddComponent<SlimPiece>();
			slimPiece.Source = sourceName;
			slimPiece.A = val;
			slimPiece.B = val2;
			slimPiece.Center = (val + val2) * 0.5f;
			Vector3 val4 = val2 - val;
			slimPiece.U = ((Vector3)(ref val4)).normalized;
			slimPiece.V = new Vector3(0f - slimPiece.U.y, slimPiece.U.x, 0f);
			if (Mathf.Abs(slimPiece.U.z) > 0.0001f || Vector3.Distance(val, val2) < 0.9f)
			{
				throw new InvalidOperationException("Uninspected longitudinal frame");
			}
			Collider[] componentsInChildren = clone.GetComponentsInChildren<Collider>(true);
			if (componentsInChildren.Length != 1 || !(componentsInChildren[0] is BoxCollider))
			{
				throw new InvalidOperationException("Uninspected collision schema");
			}
			Transform[] array = Enumerable.Range(0, transform.childCount).Select((Func<int, Transform>)transform.GetChild).ToArray();
			Quaternion val5 = Quaternion.FromToRotation(Vector3.right, slimPiece.U);
			Transform transform2 = new GameObject("SlimBeams transverse scale").transform;
			transform2.SetParent(transform, false);
			transform2.localPosition = slimPiece.Center - (0.25f * slimPiece.Center + 0.75f * Vector3.Dot(slimPiece.Center, slimPiece.U) * slimPiece.U);
			transform2.localRotation = val5;
			transform2.localScale = new Vector3(1f, 0.25f, 0.25f);
			Transform transform3 = new GameObject("SlimBeams original frame").transform;
			transform3.SetParent(transform2, false);
			transform3.localRotation = Quaternion.Inverse(val5);
			BoxCollider val6 = (BoxCollider)componentsInChildren[0];
			Matrix4x4 val7 = transform.worldToLocalMatrix * ((Component)val6).transform.localToWorldMatrix;
			Vector3[] array2 = (Vector3[])(object)new Vector3[8];
			int num = 0;
			for (int i = -1; i <= 1; i += 2)
			{
				for (int j = -1; j <= 1; j += 2)
				{
					for (int k = -1; k <= 1; k += 2)
					{
						array2[num++] = slimPiece.Compress(((Matrix4x4)(ref val7)).MultiplyPoint3x4(val6.center + Vector3.Scale(val6.size * 0.5f, new Vector3((float)k, (float)j, (float)i))));
					}
				}
			}
			GameObject val8 = new GameObject("SlimBeams collision");
			val8.transform.SetParent(transform, false);
			val8.layer = ((Component)val6).gameObject.layer;
			val8.tag = ((Component)val6).gameObject.tag;
			Mesh val9 = new Mesh
			{
				name = "SlimBeams private collision hull"
			};
			val9.vertices = array2;
			val9.triangles = new int[36]
			{
				0, 2, 1, 1, 2, 3, 4, 5, 6, 5,
				7, 6, 0, 1, 4, 1, 5, 4, 2, 6,
				3, 3, 6, 7, 0, 4, 2, 2, 4, 6,
				1, 3, 5, 3, 7, 5
			};
			val9.RecalculateBounds();
			val9.RecalculateNormals();
			MeshCollider obj = val8.AddComponent<MeshCollider>();
			obj.sharedMesh = val9;
			obj.convex = true;
			((Collider)obj).sharedMaterial = ((Collider)val6).sharedMaterial;
			((Collider)obj).isTrigger = ((Collider)val6).isTrigger;
			((Collider)obj).enabled = ((Collider)val6).enabled;
			val8.SetActive(((Component)val6).gameObject.activeSelf);
			Object.DestroyImmediate((Object)(object)val6);
			Bounds val10 = default(Bounds);
			((Bounds)(ref val10))..ctor(Quaternion.Inverse(val5) * array2[0], Vector3.zero);
			Vector3[] array3 = array2;
			foreach (Vector3 val11 in array3)
			{
				((Bounds)(ref val10)).Encapsulate(Quaternion.Inverse(val5) * val11);
			}
			slimPiece.CollisionCenter = val5 * ((Bounds)(ref val10)).center;
			slimPiece.CollisionSize = ((Bounds)(ref val10)).size;
			WearNTear component = clone.GetComponent<WearNTear>();
			GameObject obj2 = component.m_new;
			if (!Object.op_Implicit((Object)(object)obj2))
			{
				throw new InvalidOperationException("No intact visual root");
			}
			float num2 = float.PositiveInfinity;
			float num3 = float.NegativeInfinity;
			float num4 = float.PositiveInfinity;
			float num5 = float.NegativeInfinity;
			Bounds val12 = default(Bounds);
			bool flag = true;
			MeshFilter[] componentsInChildren2 = obj2.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val13 in componentsInChildren2)
			{
				if (!Object.op_Implicit((Object)(object)val13.sharedMesh) || !val13.sharedMesh.isReadable)
				{
					continue;
				}
				array3 = val13.sharedMesh.vertices;
				foreach (Vector3 val14 in array3)
				{
					Vector3 val15 = slimPiece.Compress(transform.InverseTransformPoint(((Component)val13).transform.TransformPoint(val14)));
					if (flag)
					{
						((Bounds)(ref val12))..ctor(val15, Vector3.zero);
						flag = false;
					}
					else
					{
						((Bounds)(ref val12)).Encapsulate(val15);
					}
					Vector3 val16 = val15 - slimPiece.Center;
					float num6 = Vector3.Dot(val16, slimPiece.V);
					num2 = Mathf.Min(num2, num6);
					num3 = Mathf.Max(num3, num6);
					num4 = Mathf.Min(num4, val16.z);
					num5 = Mathf.Max(num5, val16.z);
				}
			}
			if (float.IsInfinity(num2))
			{
				throw new InvalidOperationException("No readable intact body for snap placement");
			}
			slimPiece.HalfV = Mathf.Max(Mathf.Abs(num2), Mathf.Abs(num3));
			slimPiece.HalfZ = Mathf.Max(Mathf.Abs(num4), Mathf.Abs(num5));
			Transform[] array4 = array;
			foreach (Transform val17 in array4)
			{
				if (list.Contains(val17))
				{
					Object.DestroyImmediate((Object)(object)((Component)val17).gameObject);
				}
				else
				{
					val17.SetParent(transform3, false);
				}
			}
			component.m_comOffset = slimPiece.Compress(component.m_comOffset);
			AddSnap(transform, "End A", val);
			AddSnap(transform, "End B", val2);
			AddSnap(transform, "Centre", slimPiece.Center);
			Vector3[] array5 = (Vector3[])(object)new Vector3[3] { val, val2, slimPiece.Center };
			string[] array6 = new string[3] { "A", "B", "Centre" };
			for (int n = 0; n < array5.Length; n++)
			{
				AddSnap(transform, array6[n] + " upper face", array5[n] + slimPiece.V * num3);
				AddSnap(transform, array6[n] + " lower face", array5[n] + slimPiece.V * num2);
				AddSnap(transform, array6[n] + " front face", array5[n] + Vector3.forward * num5);
				AddSnap(transform, array6[n] + " back face", array5[n] + Vector3.forward * num4);
			}
			if (slimPiece.U.x > 0.001f)
			{
				AddSnap(transform, "A vanilla post side", val - slimPiece.U * ((0.2f + Mathf.Max(0f, val.x - ((Bounds)(ref val12)).min.x)) / slimPiece.U.x));
				AddSnap(transform, "B vanilla post side", val2 + slimPiece.U * ((0.2f + Mathf.Max(0f, ((Bounds)(ref val12)).max.x - val2.x)) / slimPiece.U.x));
			}
			if (slimPiece.U.y > 0.001f)
			{
				AddSnap(transform, "A vanilla beam face", val - slimPiece.U * ((0.2f + Mathf.Max(0f, val.y - ((Bounds)(ref val12)).min.y)) / slimPiece.U.y));
				AddSnap(transform, "B vanilla beam face", val2 + slimPiece.U * ((0.2f + Mathf.Max(0f, ((Bounds)(ref val12)).max.y - val2.y)) / slimPiece.U.y));
			}
		}

		private static void AddSnap(Transform root, string label, Vector3 p)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < root.childCount; i++)
			{
				Transform child = root.GetChild(i);
				if (((Component)child).CompareTag("snappoint") && Vector3.Distance(child.localPosition, p) < 0.0001f)
				{
					if (label.Contains("vanilla"))
					{
						((Object)child).name = ((Object)child).name.Replace("vanilla post side", "vanilla post / beam side");
					}
					return;
				}
			}
			GameObject val = new GameObject("Slim: " + label)
			{
				tag = "snappoint"
			};
			val.transform.SetParent(root, false);
			val.transform.localPosition = p;
			val.SetActive(false);
		}
	}
}