Decompiled source of Lumberjack v1.1.2

Mods/WoodStudios.Lumberjack.dll

Decompiled 29 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using HarmonyLib;
using HoldTheFort;
using Il2CppFishNet;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.AvatarFramework;
using Il2CppScheduleOne.AvatarFramework.Animation;
using Il2CppScheduleOne.Building;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.Instancing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Relation;
using Il2CppScheduleOne.Networking;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Property;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.Tiles;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.UI.Shop;
using Il2CppScheduleOne.Weather;
using Il2CppSteamworks;
using Il2CppSystem;
using Il2CppSystem.Collections;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Il2CppTMPro;
using LumberjackMod;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using S1API.Entities;
using S1API.Items;
using S1API.Items.Storable;
using S1API.Lifecycle;
using S1API.Rendering;
using S1API.Shops;
using S2_LJ.FybCommon;
using S2_LJ.WoodKit;
using Schedule2;
using Schedule2.Game;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(LumberCore), "Lumberjack", "1.1.2", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonOptionalDependencies(new string[] { "HoldTheFort" })]
[assembly: AssemblyTitle("WoodStudios.Lumberjack")]
[assembly: AssemblyProduct("WoodStudios.Lumberjack")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.0")]
[module: UnverifiableCode]
[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 Schedule2
{
	internal static class Res
	{
		private static readonly Assembly Asm = typeof(Res).Assembly;

		public static Stream Open(string name)
		{
			Stream manifestResourceStream = Asm.GetManifestResourceStream(name);
			if (manifestResourceStream == null)
			{
				return null;
			}
			int num = manifestResourceStream.ReadByte();
			int num2 = manifestResourceStream.ReadByte();
			manifestResourceStream.Position = 0L;
			if (num != 31 || num2 != 139)
			{
				return manifestResourceStream;
			}
			MemoryStream memoryStream = new MemoryStream();
			using (GZipStream gZipStream = new GZipStream(manifestResourceStream, CompressionMode.Decompress))
			{
				gZipStream.CopyTo(memoryStream);
			}
			memoryStream.Position = 0L;
			return memoryStream;
		}
	}
}
namespace Schedule2.Game
{
	internal static class Sfx
	{
		public static AudioClip Create(string name, int lengthSamples, int channels, int frequency, bool stream)
		{
			return AudioClip.Create(name, lengthSamples, channels, frequency, stream);
		}

		public static bool SetData(AudioClip clip, Il2CppStructArray<float> data, int offset)
		{
			if ((Object)(object)clip != (Object)null)
			{
				return clip.SetData(data, offset);
			}
			return false;
		}
	}
}
namespace LumberjackMod
{
	internal static class Chop
	{
		private static int _heldFrame = -10;

		private static bool _saw;

		private static bool _viewSaw;

		private static Camera _cam;

		private static GameObject _view;

		private static float _swingAt = -10f;

		private static float _nextSwing;

		private static bool _swingHit;

		private static Transform _target;

		private static Forest.Cut _stump;

		private static float _progress;

		private static string _say;

		private static float _sayUntil;

		private static float _aimAt;

		private static Transform _aimTrunk;

		private static Forest.Cut _aimStump;

		private static RaycastHit _aimHit;

		private static bool _aimOk;

		private const float Reach = 3.2f;

		private const float SwingTime = 0.5f;

		private static readonly Vector3 HoldPos = new Vector3(0.4f, -0.52f, 0.52f);

		private static int Hits => Mathf.Clamp(LumberCore.AxeHits?.Value ?? 6, 1, 40);

		private static float SawSeconds => Mathf.Clamp(LumberCore.SawSeconds?.Value ?? 3f, 0.3f, 30f);

		public static void Say(string s, float secs = 2.5f)
		{
			_say = s;
			_sayUntil = Time.unscaledTime + secs;
		}

		public static bool Held(ItemSpec s, Camera cam, Player pl, out string hint)
		{
			_heldFrame = Time.frameCount;
			bool num = s.Id == "lj_chainsaw";
			if (num != _saw)
			{
				_progress = 0f;
				_target = null;
				_stump = null;
			}
			_saw = num;
			_cam = cam;
			Look(pl);
			if ((Object)(object)_aimTrunk != (Object)null)
			{
				if (_saw)
				{
					hint = (((Object)(object)_target == (Object)(object)_aimTrunk && _progress > 0f) ? $"Cutting... {(int)(_progress * 100f)}%    (hold the mouse button)" : "[Hold click] Cut this tree down");
				}
				else
				{
					int value = (((Object)(object)_target == (Object)(object)_aimTrunk) ? (Hits - Mathf.RoundToInt(_progress)) : Hits);
					hint = (((Object)(object)_target == (Object)(object)_aimTrunk && _progress > 0f) ? $"[Click] Chop ({value} more)" : "[Click] Chop this tree down");
				}
			}
			else if (_aimStump != null)
			{
				hint = (_saw ? "[Hold click] Cut out the stump" : "[Click] Dig up the stump");
			}
			else
			{
				hint = (_saw ? "Aim at a tree trunk to cut it down" : "Aim at a tree trunk to chop it down");
			}
			return true;
		}

		private static void Look(Player pl)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _aimAt)
			{
				return;
			}
			_aimAt = Time.unscaledTime + 0.08f;
			_aimTrunk = null;
			_aimStump = null;
			_aimOk = false;
			if (!((Object)(object)_cam == (Object)null) && !((Object)(object)pl == (Object)null) && Placement.Aim(_cam, 3.2f, pl, out var best))
			{
				_aimHit = best;
				_aimOk = true;
				_aimTrunk = Forest.TrunkOf(((RaycastHit)(ref best)).collider);
				if ((Object)(object)_aimTrunk == (Object)null)
				{
					_aimStump = Forest.StumpOf(((RaycastHit)(ref best)).collider);
				}
			}
		}

		public static void Update()
		{
			//IL_027b: 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_0290: 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_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: 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)
			if (_heldFrame < Time.frameCount - 1 || !((Object)(object)_cam != (Object)null))
			{
				HideView();
				LumberSound.Saw(null, 0);
				_progress = 0f;
				_target = null;
				_stump = null;
				return;
			}
			Player local = Player.Local;
			if ((Object)(object)local == (Object)null)
			{
				return;
			}
			EnsureView();
			bool buttonDown = GameInput.GetButtonDown((ButtonCode)0);
			bool button = GameInput.GetButton((ButtonCode)0);
			float unscaledTime = Time.unscaledTime;
			if ((Object)(object)_aimTrunk != (Object)null && (Object)(object)_target != (Object)(object)_aimTrunk)
			{
				_target = null;
				_progress = 0f;
			}
			if (_aimStump != null && _stump != _aimStump)
			{
				_stump = null;
				_progress = 0f;
			}
			if (_saw)
			{
				bool flag = button && ((Object)(object)_aimTrunk != (Object)null || _aimStump != null);
				LumberSound.Saw(((Component)_cam).transform, (!flag) ? 1 : 2);
				if (flag)
				{
					if ((Object)(object)_aimTrunk != (Object)null)
					{
						_target = _aimTrunk;
					}
					else
					{
						_stump = _aimStump;
					}
					_progress += Time.deltaTime / ((_aimStump != null) ? (SawSeconds * 0.5f) : SawSeconds);
					if (Random.value < Time.deltaTime * 14f && _aimOk)
					{
						LumberModels.Chips(((RaycastHit)(ref _aimHit)).point, Away(local), 2);
					}
					if (_progress >= 1f)
					{
						Finish(local);
					}
				}
			}
			else
			{
				if (buttonDown && unscaledTime >= _nextSwing)
				{
					_swingAt = unscaledTime;
					_nextSwing = unscaledTime + 0.5f + 0.05f;
					_swingHit = false;
				}
				if (!_swingHit && unscaledTime - _swingAt >= 0.225f && unscaledTime - _swingAt < 0.5f)
				{
					_swingHit = true;
					if ((Object)(object)_aimTrunk != (Object)null || _aimStump != null)
					{
						if ((Object)(object)_aimTrunk != (Object)null)
						{
							_target = _aimTrunk;
						}
						else
						{
							_stump = _aimStump;
						}
						_progress += 1f;
						if (_aimOk)
						{
							if ((Object)(object)_aimTrunk != (Object)null)
							{
								LumberSound.Chop(((RaycastHit)(ref _aimHit)).point);
								LumberModels.Chips(((RaycastHit)(ref _aimHit)).point, Away(local), 5);
							}
							else
							{
								LumberSound.Dig(((RaycastHit)(ref _aimHit)).point);
								LumberModels.Chips(((RaycastHit)(ref _aimHit)).point, Away(local), 3);
							}
						}
						int num = ((_aimStump != null) ? Math.Max(1, Hits / 2) : Hits);
						if (_progress >= (float)num)
						{
							Finish(local);
						}
					}
				}
			}
			Animate(unscaledTime);
		}

		private static Vector3 Away(Player me)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (((Object)(object)_cam != (Object)null) ? (-((Component)_cam).transform.forward) : (-((Component)me).transform.forward));
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude > 0.001f))
			{
				return Vector3.back;
			}
			return ((Vector3)(ref val)).normalized;
		}

		private static void Finish(Player me)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			_progress = 0f;
			if ((Object)(object)_target != (Object)null)
			{
				Forest.Cut cut = Forest.Fell(_target);
				_target = null;
				_aimAt = 0f;
				if (cut == null)
				{
					Say("That one won't come down.");
					return;
				}
				Fall.Begin(cut, ((Component)me).transform.position);
				LumberCore.Felled++;
				Say("Timber!", 2f);
			}
			else if (_stump != null)
			{
				Forest.DigUp(_stump);
				_stump = null;
				_aimAt = 0f;
				Say("Stump's out.", 2f);
			}
		}

		private static void EnsureView()
		{
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_view != (Object)null && _viewSaw == _saw && (Object)(object)_view.transform.parent == (Object)(object)((Component)_cam).transform)
			{
				if (!_view.activeSelf)
				{
					_view.SetActive(true);
				}
				return;
			}
			if ((Object)(object)_view != (Object)null)
			{
				Object.Destroy((Object)(object)_view);
			}
			GameObject val = Catalog.Get(_saw ? "lj_chainsaw" : "lj_axe")?.Template;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			_view = Object.Instantiate<GameObject>(val);
			_view.SetActive(true);
			foreach (Collider componentsInChild in _view.GetComponentsInChildren<Collider>(true))
			{
				Object.Destroy((Object)(object)componentsInChild);
			}
			_viewSaw = _saw;
			((Object)_view).name = "LJ_ToolView";
			_view.transform.SetParent(((Component)_cam).transform, false);
			_view.transform.localPosition = HoldPos;
			_view.transform.localScale = Vector3.one * (_saw ? 0.9f : 0.75f);
			foreach (Renderer componentsInChild2 in _view.GetComponentsInChildren<Renderer>(true))
			{
				componentsInChild2.shadowCastingMode = (ShadowCastingMode)0;
			}
		}

		private static void HideView()
		{
			if ((Object)(object)_view != (Object)null && _view.activeSelf)
			{
				_view.SetActive(false);
			}
		}

		private static void Animate(float now)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ec: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_view == (Object)null)
			{
				return;
			}
			Vector3 val = HoldPos;
			int num;
			float num2;
			if (_saw)
			{
				if (GameInput.GetButton((ButtonCode)0))
				{
					if (!((Object)(object)_aimTrunk != (Object)null))
					{
						num = ((_aimStump != null) ? 1 : 0);
						if (num == 0)
						{
							goto IL_0219;
						}
					}
					else
					{
						num = 1;
					}
					num2 = 0.006f;
					goto IL_0191;
				}
				num = 0;
				goto IL_0219;
			}
			float num3 = now - _swingAt;
			float num4 = -8f;
			if (num3 >= 0f && num3 < 0.5f)
			{
				float num5 = num3 / 0.5f;
				num4 = ((num5 < 0.35f) ? Mathf.Lerp(-8f, -55f, num5 / 0.35f) : ((num5 < 0.5f) ? Mathf.Lerp(-55f, 70f, (num5 - 0.35f) / 0.15f) : Mathf.Lerp(70f, -8f, (num5 - 0.5f) / 0.5f)));
				val += new Vector3(-0.06f * Mathf.Sin(num5 * (float)Math.PI), 0.05f * Mathf.Sin(num5 * (float)Math.PI), 0.08f * Mathf.Sin(num5 * (float)Math.PI));
			}
			else
			{
				num4 += Mathf.Sin(now * 1.4f) * 0.8f;
			}
			Quaternion localRotation = Quaternion.Euler(num4, 0f, -12f) * Quaternion.Euler(0f, -90f, 0f) * Quaternion.Euler(-78f, 0f, 0f);
			goto IL_01f7;
			IL_0191:
			float num6 = num2;
			val = new Vector3(0.22f, -0.38f, 0.42f) + new Vector3(Mathf.Sin(now * 91f), Mathf.Sin(now * 77f), 0f) * num6;
			localRotation = Quaternion.Euler((num != 0) ? 12f : 4f, -6f, 0f);
			goto IL_01f7;
			IL_01f7:
			_view.transform.localPosition = val;
			_view.transform.localRotation = localRotation;
			return;
			IL_0219:
			num2 = 0.002f;
			goto IL_0191;
		}

		public static void Draw()
		{
			//IL_0070: 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_009c: 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)
			if (_say != null && !(Time.unscaledTime > _sayUntil))
			{
				Rect r = default(Rect);
				((Rect)(ref r))..ctor((float)Screen.width / 2f - 380f, (float)Screen.height * 0.62f, 760f, 40f);
				FortifyApi.UiText(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), _say, 26, new Color(0f, 0f, 0f, 0.7f), (TextAnchor)4);
				FortifyApi.UiText(r, _say, 26, new Color(1f, 0.92f, 0.7f), (TextAnchor)4);
			}
		}

		public static void Unload()
		{
			if ((Object)(object)_view != (Object)null)
			{
				Object.Destroy((Object)(object)_view);
			}
			_view = null;
			LumberSound.Saw(null, 0);
			_target = null;
			_stump = null;
			_progress = 0f;
		}
	}
	internal static class Fall
	{
		private sealed class Falling
		{
			public GameObject Root;

			public Transform Model;

			public Vector3 ModelAt;

			public float Under;

			public Vector3 Base;

			public Vector3 Axis;

			public Vector3 Away;

			public float Start;

			public float Height;

			public Forest.Cut Cut;

			public bool Landed;

			public bool Piled;
		}

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

		private static Material[] _treeMats;

		private static Mesh _treeMesh;

		private static Material _bark;

		private static Material _needles;

		private static bool _told;

		private const float DropTime = 2.6f;

		private const float LieTime = 2.2f;

		private const float SinkTime = 2f;

		public static void Begin(Forest.Cut c, Vector3 from)
		{
			//IL_0025: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_0056: 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_00d1: 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)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			if (c == null)
			{
				return;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(c.X, c.Y, c.Z);
			Vector3 forward = default(Vector3);
			((Vector3)(ref forward))..ctor(c.X - from.x, 0f, c.Z - from.z);
			if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			GameObject val2 = new GameObject("lj_Falling");
			val2.transform.position = val;
			float height = 9f * Mathf.Max(0.3f, c.S);
			Transform model = null;
			Vector3 modelAt = Vector3.zero;
			float under = 0f;
			try
			{
				var (val3, src, val4) = Forest.Look(c.Tex);
				if ((Object)(object)val3 != (Object)null)
				{
					GameObject val5 = new GameObject("Tree");
					val5.transform.SetParent(val2.transform, false);
					val5.transform.localPosition = val4 * c.S;
					val5.transform.localScale = Vector3.one * c.S;
					val5.AddComponent<MeshFilter>().sharedMesh = val3;
					((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterials = Il2CppReferenceArray<Material>.op_Implicit(MatsFor(val3, src));
					Bounds bounds = val3.bounds;
					height = Mathf.Max(2f, ((Bounds)(ref bounds)).max.y * c.S);
					model = val5.transform;
					modelAt = val5.transform.localPosition;
					bounds = val3.bounds;
					under = Mathf.Clamp((0f - (((Bounds)(ref bounds)).min.y + val4.y)) * c.S, 0f, 6f);
				}
				else
				{
					Simple(val2.transform, c.S);
				}
			}
			catch (Exception ex)
			{
				if (!_told)
				{
					_told = true;
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Warning("Lumberjack: drawing a plain tree for the fall (" + ex.Message + ").");
					}
				}
				IEnumerator enumerator = val2.transform.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						Object.Destroy((Object)(object)((Component)(Transform)enumerator.Current).gameObject);
					}
				}
				finally
				{
					if (enumerator is IDisposable disposable)
					{
						disposable.Dispose();
					}
				}
				Simple(val2.transform, c.S);
			}
			All.Add(new Falling
			{
				Root = val2,
				Model = model,
				ModelAt = modelAt,
				Under = under,
				Base = val,
				Away = forward,
				Axis = Vector3.Cross(Vector3.up, forward),
				Start = Time.time,
				Height = height,
				Cut = c
			});
			LumberSound.Crack(val + Vector3.up * 1.5f);
		}

		private static Material[] MatsFor(Mesh mesh, Material src)
		{
			//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_0205: Expected O, but got Unknown
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: 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)
			//IL_0252: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			if (_treeMats != null && (Object)(object)_treeMesh == (Object)(object)mesh)
			{
				return _treeMats;
			}
			int num = Math.Max(1, mesh.subMeshCount);
			Texture val = null;
			Color color = default(Color);
			((Color)(ref color))..ctor(0.26f, 0.36f, 0.2f);
			string value = "none";
			if ((Object)(object)src != (Object)null)
			{
				try
				{
					Il2CppStringArray texturePropertyNames = src.GetTexturePropertyNames();
					string text = null;
					for (int i = 0; i < 2; i++)
					{
						if (!((Object)(object)val == (Object)null))
						{
							break;
						}
						for (int j = 0; j < ((Il2CppArrayBase<string>)(object)texturePropertyNames).Length; j++)
						{
							if (!((Object)(object)val == (Object)null))
							{
								break;
							}
							string text2 = ((Il2CppArrayBase<string>)(object)texturePropertyNames)[j] ?? "";
							string text3 = text2.ToLowerInvariant();
							if (!text3.Contains("position") && !text3.Contains("rotation") && !text3.Contains("normal") && !text3.Contains("data") && !text3.Contains("noise") && !text3.Contains("wind") && (i != 0 || text3.Contains("base") || text3.Contains("main") || text3.Contains("albedo") || text3.Contains("diffuse") || text3.Contains("color")))
							{
								Texture texture = src.GetTexture(text2);
								if ((Object)(object)texture != (Object)null)
								{
									val = texture;
									text = text2;
								}
							}
						}
					}
					Shader shader = src.shader;
					value = "shader " + ((shader != null) ? ((Object)shader).name : null) + ", texture " + (text ?? "none");
					if (src.HasProperty("_BaseColor"))
					{
						color = src.GetColor("_BaseColor");
					}
					else if (src.HasProperty("_Color"))
					{
						color = src.GetColor("_Color");
					}
				}
				catch
				{
				}
			}
			Material val2 = new Material(Models.Lit())
			{
				name = "lj_FallingTree"
			};
			if ((Object)(object)val != (Object)null)
			{
				val2.mainTexture = val;
				if (val2.HasProperty("_BaseMap"))
				{
					val2.SetTexture("_BaseMap", val);
				}
				val2.color = Color.white;
				if (val2.HasProperty("_BaseColor"))
				{
					val2.SetColor("_BaseColor", Color.white);
				}
			}
			else
			{
				val2.color = color;
				if (val2.HasProperty("_BaseColor"))
				{
					val2.SetColor("_BaseColor", color);
				}
			}
			if (val2.HasProperty("_AlphaClip"))
			{
				val2.SetFloat("_AlphaClip", 1f);
			}
			if (val2.HasProperty("_Cutoff"))
			{
				val2.SetFloat("_Cutoff", 0.45f);
			}
			val2.EnableKeyword("_ALPHATEST_ON");
			if (val2.HasProperty("_Cull"))
			{
				val2.SetFloat("_Cull", 0f);
			}
			if (val2.HasProperty("_Smoothness"))
			{
				val2.SetFloat("_Smoothness", 0.05f);
			}
			val2.renderQueue = 2450;
			_treeMats = (Material[])(object)new Material[num];
			for (int k = 0; k < num; k++)
			{
				_treeMats[k] = val2;
			}
			_treeMesh = mesh;
			Instance log = Kit.Log;
			if (log != null)
			{
				log.Msg($"Lumberjack: falling trees use the game's pine ({num} part(s), {value}).");
			}
			return _treeMats;
		}

		private static void Simple(Transform root, float s)
		{
			//IL_0021: 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_009d: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_bark == (Object)null)
			{
				_bark = Models.Mat("lj_fall_bark", new Color(0.28f, 0.18f, 0.1f), 0f, 0.05f);
			}
			if ((Object)(object)_needles == (Object)null)
			{
				_needles = Models.Mat("lj_fall_needles", new Color(0.13f, 0.24f, 0.12f), 0f, 0.05f);
			}
			Part(root, (PrimitiveType)2, new Vector3(0f, 4.5f, 0f) * s, new Vector3(0.45f, 4.5f, 0.45f) * s, _bark);
			for (int i = 0; i < 4; i++)
			{
				float num = 3.2f + (float)i * 1.8f;
				float num2 = 2.6f - (float)i * 0.55f;
				Part(root, (PrimitiveType)0, new Vector3(0f, num, 0f) * s, new Vector3(num2 * 2f, 1.9f, num2 * 2f) * s, _needles);
			}
		}

		private static void Part(Transform root, PrimitiveType type, Vector3 pos, Vector3 scale, Material m)
		{
			//IL_0000: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(type);
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			obj.transform.SetParent(root, false);
			obj.transform.localPosition = pos;
			obj.transform.localScale = scale;
			obj.GetComponent<Renderer>().sharedMaterial = m;
		}

		public static void Update()
		{
			//IL_0081: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			for (int num = All.Count - 1; num >= 0; num--)
			{
				Falling falling = All[num];
				if ((Object)(object)falling.Root == (Object)null)
				{
					All.RemoveAt(num);
				}
				else
				{
					float num2 = time - falling.Start;
					float num3;
					if (num2 < 2.6f)
					{
						num3 = 90f * Mathf.Pow(num2 / 2.6f, 2.4f);
					}
					else
					{
						if (!falling.Landed)
						{
							falling.Landed = true;
							LumberSound.Crash(falling.Base + falling.Away * falling.Height * 0.55f + Vector3.up * 0.5f);
							LumberModels.Chips(falling.Base + Vector3.up * 0.4f, falling.Away, 14);
							Forest.MakeStump(falling.Cut);
						}
						float num4 = num2 - 2.6f;
						num3 = 90f - 4f * Mathf.Exp((0f - num4) * 5f) * Mathf.Sin(num4 * 18f);
					}
					falling.Root.transform.rotation = Quaternion.AngleAxis(num3, falling.Axis);
					if ((Object)(object)falling.Model != (Object)null && falling.Under > 0f)
					{
						falling.Model.localPosition = falling.ModelAt + Vector3.up * (falling.Under * Mathf.Sin(Mathf.Clamp(num3, 0f, 90f) * ((float)Math.PI / 180f)));
					}
					float num5 = 4.8f;
					if (num2 > num5 && !falling.Piled)
					{
						falling.Piled = true;
						Logs.Pile(falling.Base + falling.Away * Mathf.Min(falling.Height * 0.45f, 6f), falling.Away, falling.Height);
					}
					if (num2 > num5)
					{
						float num6 = Mathf.Clamp01((num2 - num5) / 2f);
						falling.Root.transform.position = falling.Base + Vector3.down * (num6 * 1.6f);
						falling.Root.transform.localScale = Vector3.one * (1f - 0.35f * num6);
					}
					if (num2 > num5 + 2f)
					{
						Object.Destroy((Object)(object)falling.Root);
						All.RemoveAt(num);
					}
				}
			}
		}

		public static void Clear()
		{
			foreach (Falling item in All)
			{
				if ((Object)(object)item.Root != (Object)null)
				{
					Object.Destroy((Object)(object)item.Root);
				}
			}
			All.Clear();
		}
	}
	internal static class Forest
	{
		internal sealed class Cut
		{
			public float X;

			public float Y;

			public float Z;

			public float S;

			public bool Stump = true;

			public Texture2D Tex;

			public int Pixel = -1;

			public GameObject Trunk;

			public GameObject StumpGo;
		}

		private sealed class Data
		{
			public Texture2D Tex;

			public int Count;

			public Mesh Mesh;

			public Material Mat;

			public Vector3 Offset;
		}

		private static readonly List<Cut> Cuts = new List<Cut>();

		private static readonly List<Data> Datas = new List<Data>();

		private static float _nextHeal;

		private static float _nextFind;

		private static bool _loaded;

		private const string SaveKey = "Felled";

		public static int Count => Cuts.Count;

		public static bool Ready
		{
			get
			{
				Find();
				return Datas.Count > 0;
			}
		}

		private static void Find()
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			if (Datas.Count > 0 && Datas.TrueForAll((Data d) => (Object)(object)d.Tex != (Object)null))
			{
				return;
			}
			Datas.Clear();
			try
			{
				InstancingManager val = Object.FindObjectOfType<InstancingManager>();
				List<InstanceObjectData> val2 = (((Object)(object)val != (Object)null) ? val.BackedInstanceObjects : null);
				int num = 0;
				while (val2 != null && num < val2.Count)
				{
					InstanceObjectData val3 = val2[num];
					if (!((Object)(object)val3 == (Object)null) && (val3.Id ?? "").IndexOf("tree", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						Texture2D tex = val3.PositionData;
						if (!((Object)(object)tex == (Object)null) && ((Texture)tex).isReadable && (int)tex.format == 20)
						{
							Data data = Datas.Find((Data x) => (Object)(object)x.Tex == (Object)(object)tex);
							if (data != null)
							{
								Vector2Int minMaxLodDistance = val3.MinMaxLodDistance;
								if (((Vector2Int)(ref minMaxLodDistance)).x == 0 && (Object)(object)val3.Mesh != (Object)null)
								{
									data.Mesh = val3.Mesh;
									data.Mat = val3.Material;
									data.Offset = val3.PositionOffset;
								}
							}
							else
							{
								Datas.Add(new Data
								{
									Tex = tex,
									Count = Math.Min(val3.InstanceCount, ((Texture)tex).width * ((Texture)tex).height),
									Mesh = val3.Mesh,
									Mat = val3.Material,
									Offset = val3.PositionOffset
								});
							}
						}
					}
					num++;
				}
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Lumberjack: couldn't read the trees (" + ex.Message + ").");
				}
			}
		}

		public static (Mesh mesh, Material mat, Vector3 offset) Look(Texture2D tex)
		{
			//IL_0030: 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)
			foreach (Data data in Datas)
			{
				if ((Object)(object)data.Tex == (Object)(object)tex)
				{
					return (mesh: data.Mesh, mat: data.Mat, offset: data.Offset);
				}
			}
			return (mesh: null, mat: null, offset: Vector3.zero);
		}

		private static Color Get(Texture2D t, int i)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			return t.GetPixel(i % ((Texture)t).width, i / ((Texture)t).width);
		}

		public static bool Nearest(Vector3 p, float reach, out Texture2D tex, out int pixel, out Vector4 tree)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00c8: 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_00d6: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			tex = null;
			pixel = -1;
			tree = default(Vector4);
			Find();
			float num = reach * reach;
			foreach (Data data in Datas)
			{
				if ((Object)(object)data.Tex == (Object)null)
				{
					continue;
				}
				Color[] array;
				try
				{
					array = Il2CppArrayBase<Color>.op_Implicit((Il2CppArrayBase<Color>)(object)data.Tex.GetPixels());
				}
				catch
				{
					continue;
				}
				int num2 = Math.Min(data.Count, array.Length);
				for (int i = 0; i < num2; i++)
				{
					Color val = array[i];
					if (!(val.a <= 0f))
					{
						float num3 = val.r - p.x;
						float num4 = val.b - p.z;
						float num5 = num3 * num3 + num4 * num4;
						if (!(num5 >= num))
						{
							num = num5;
							tex = data.Tex;
							pixel = i;
							tree = new Vector4(val.r, val.g, val.b, val.a);
						}
					}
				}
			}
			return pixel >= 0;
		}

		private static bool Match(Cut c)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			Find();
			float num = 0.25f;
			foreach (Data data in Datas)
			{
				if ((Object)(object)data.Tex == (Object)null)
				{
					continue;
				}
				Color[] array;
				try
				{
					array = Il2CppArrayBase<Color>.op_Implicit((Il2CppArrayBase<Color>)(object)data.Tex.GetPixels());
				}
				catch
				{
					continue;
				}
				int num2 = Math.Min(data.Count, array.Length);
				for (int i = 0; i < num2; i++)
				{
					Color val = array[i];
					float num3 = val.r - c.X;
					float num4 = val.b - c.Z;
					float num5 = num3 * num3 + num4 * num4;
					if (!(num5 >= num))
					{
						num = num5;
						c.Tex = data.Tex;
						c.Pixel = i;
					}
				}
			}
			return c.Pixel >= 0;
		}

		private static bool Remove(Cut c)
		{
			//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_002b: 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_008a: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)c.Tex == (Object)null || c.Pixel < 0)
			{
				return false;
			}
			Color val = Get(c.Tex, c.Pixel);
			if (val.a <= 0f && val.g < c.Y - 1000f)
			{
				return false;
			}
			c.Tex.SetPixel(c.Pixel % ((Texture)c.Tex).width, c.Pixel / ((Texture)c.Tex).width, new Color(val.r, c.Y - 2000f, val.b, 0f));
			return true;
		}

		public static GameObject TrunkNear(float x, float z, float reach = 1.6f)
		{
			//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_004c: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			GameObject result = null;
			float num = reach * reach;
			try
			{
				foreach (FoliageRustleSound item in Object.FindObjectsOfType<FoliageRustleSound>())
				{
					if (!((Object)(object)item == (Object)null) && ((Object)item).name.StartsWith("Tree", StringComparison.OrdinalIgnoreCase))
					{
						Vector3 position = ((Component)item).transform.position;
						float num2 = (position.x - x) * (position.x - x) + (position.z - z) * (position.z - z);
						if (num2 < num)
						{
							num = num2;
							result = ((Component)item).gameObject;
						}
					}
				}
			}
			catch
			{
			}
			return result;
		}

		public static void DevGoToTree()
		{
			//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)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0075: 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_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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_010c: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Player local = Player.Local;
				if ((Object)(object)local == (Object)null)
				{
					return;
				}
				Vector3 position = ((Component)local).transform.position;
				GameObject val = null;
				float num = 62500f;
				foreach (FoliageRustleSound item in Object.FindObjectsOfType<FoliageRustleSound>())
				{
					if (!((Object)(object)item == (Object)null) && ((Object)item).name.StartsWith("Tree", StringComparison.OrdinalIgnoreCase))
					{
						Vector3 position2 = ((Component)item).transform.position;
						float num2 = (position2.x - position.x) * (position2.x - position.x) + (position2.z - position.z) * (position2.z - position.z);
						if (!(num2 < 4f) && !(num2 >= num))
						{
							num = num2;
							val = ((Component)item).gameObject;
						}
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Msg("Dev: no tree with a trunk nearby.");
					}
					return;
				}
				Vector3 position3 = val.transform.position;
				Vector3 val2 = position - position3;
				val2.y = 0f;
				if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
				{
					val2 = Vector3.back;
				}
				((Vector3)(ref val2)).Normalize();
				Vector3 val3 = position3 + val2 * 2.1f;
				RaycastHit val4 = default(RaycastHit);
				if (Physics.Raycast(val3 + Vector3.up * 4f, Vector3.down, ref val4, 12f, -1, (QueryTriggerInteraction)1))
				{
					val3 = ((RaycastHit)(ref val4)).point;
				}
				PlayerSingleton<PlayerMovement>.Instance.Teleport(val3 + Vector3.up * 0.1f, Quaternion.LookRotation(-val2, Vector3.up), true);
				Instance log2 = Kit.Log;
				if (log2 != null)
				{
					log2.Msg($"Dev: standing by the tree at ({position3.x:0.0}, {position3.y:0.0}, {position3.z:0.0}).");
				}
			}
			catch (Exception ex)
			{
				Instance log3 = Kit.Log;
				if (log3 != null)
				{
					log3.Warning("Dev tree: " + ex.Message);
				}
			}
		}

		public static Transform TrunkOf(Collider col)
		{
			if ((Object)(object)col == (Object)null)
			{
				return null;
			}
			Transform val = ((Component)col).transform;
			int num = 0;
			while (num < 4 && (Object)(object)val != (Object)null)
			{
				try
				{
					if ((Object)(object)((Component)val).GetComponent<FoliageRustleSound>() != (Object)null)
					{
						return val;
					}
				}
				catch
				{
				}
				if (((Object)val).name.StartsWith("Tree", StringComparison.OrdinalIgnoreCase) && ((Object)val).name.IndexOf("rustle", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return val;
				}
				num++;
				val = val.parent;
			}
			return null;
		}

		public static Cut Fell(Transform trunk)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)trunk == (Object)null)
			{
				return null;
			}
			if (!Nearest(trunk.position, 2.2f, out var tex, out var pixel, out var tree))
			{
				return null;
			}
			Cut cut = new Cut
			{
				X = tree.x,
				Y = tree.y,
				Z = tree.z,
				S = tree.w,
				Tex = tex,
				Pixel = pixel,
				Trunk = ((Component)trunk).gameObject
			};
			if (Remove(cut))
			{
				Apply(cut.Tex);
			}
			if ((Object)(object)cut.Trunk != (Object)null)
			{
				cut.Trunk.SetActive(false);
			}
			Cuts.Add(cut);
			return cut;
		}

		private static void Apply(Texture2D t)
		{
			try
			{
				t.Apply(false, false);
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Lumberjack: couldn't redraw the trees (" + ex.Message + ").");
				}
			}
		}

		public static void MakeStump(Cut c)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (c != null && c.Stump && !((Object)(object)c.StumpGo != (Object)null))
			{
				MelonPreferences_Entry<bool> stumps = LumberCore.Stumps;
				if (stumps == null || stumps.Value)
				{
					c.StumpGo = LumberModels.Stump(new Vector3(c.X, c.Y, c.Z), Mathf.Clamp(c.S, 0.6f, 1.8f));
				}
			}
		}

		public static Cut StumpOf(Collider col)
		{
			if ((Object)(object)col == (Object)null)
			{
				return null;
			}
			foreach (Cut cut in Cuts)
			{
				if ((Object)(object)cut.StumpGo != (Object)null && ((Component)col).transform.IsChildOf(cut.StumpGo.transform))
				{
					return cut;
				}
			}
			return null;
		}

		public static void DigUp(Cut c)
		{
			if (c != null)
			{
				c.Stump = false;
				if ((Object)(object)c.StumpGo != (Object)null)
				{
					Object.Destroy((Object)(object)c.StumpGo);
				}
				c.StumpGo = null;
			}
		}

		public static void Update()
		{
			if (!_loaded)
			{
				return;
			}
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime < _nextHeal)
			{
				return;
			}
			_nextHeal = unscaledTime + 2f;
			if (Cuts.Count == 0)
			{
				return;
			}
			if (!Ready)
			{
				if (unscaledTime >= _nextFind)
				{
					_nextFind = unscaledTime + 5f;
				}
				return;
			}
			HashSet<int> hashSet = new HashSet<int>();
			List<Texture2D> list = new List<Texture2D>();
			int num = 0;
			int num2 = 0;
			foreach (Cut cut in Cuts)
			{
				try
				{
					if (!((Object)(object)cut.Tex == (Object)null) && cut.Pixel >= 0)
					{
						goto IL_00a2;
					}
					if (!Match(cut))
					{
						continue;
					}
					num++;
					goto IL_00a2;
					IL_00a2:
					if (Remove(cut))
					{
						num2++;
						if (hashSet.Add(((Object)cut.Tex).GetInstanceID()))
						{
							list.Add(cut.Tex);
						}
					}
					if ((Object)(object)cut.Trunk == (Object)null)
					{
						cut.Trunk = TrunkNear(cut.X, cut.Z, 1.2f);
					}
					if ((Object)(object)cut.Trunk != (Object)null && cut.Trunk.activeSelf)
					{
						cut.Trunk.SetActive(false);
					}
					if (cut.Stump && (Object)(object)cut.StumpGo == (Object)null)
					{
						MakeStump(cut);
					}
					if (!cut.Stump)
					{
						goto IL_0166;
					}
					MelonPreferences_Entry<bool> stumps = LumberCore.Stumps;
					if (stumps != null && !stumps.Value)
					{
						goto IL_0166;
					}
					goto end_IL_0077;
					IL_0166:
					if ((Object)(object)cut.StumpGo != (Object)null)
					{
						Object.Destroy((Object)(object)cut.StumpGo);
						cut.StumpGo = null;
					}
					end_IL_0077:;
				}
				catch
				{
				}
			}
			foreach (Texture2D item in list)
			{
				Apply(item);
			}
			if (num > 0 || num2 > 0)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Msg($"Lumberjack: {Cuts.Count} felled tree(s) kept down ({num2} redrawn).");
				}
			}
		}

		public static void Load()
		{
			Clear(restore: false);
			_loaded = true;
			_nextHeal = Time.unscaledTime + 9f;
			if (LumberCore.RegrowAll != null && LumberCore.RegrowAll.Value)
			{
				LumberCore.RegrowAll.Value = false;
				MelonPreferences.Save();
				FortifyApi.SetData("Felled", "");
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Msg("Lumberjack: every tree you cut down has grown back (Regrow all trees is off again).");
				}
				return;
			}
			string data = FortifyApi.GetData("Felled");
			if (string.IsNullOrEmpty(data))
			{
				return;
			}
			string[] array = data.Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(',');
				if (array2.Length >= 4 && float.TryParse(array2[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					float.TryParse(array2[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2);
					float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3);
					float.TryParse(array2[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result4);
					Cuts.Add(new Cut
					{
						X = result,
						Y = result2,
						Z = result3,
						S = result4,
						Stump = (array2.Length < 5 || array2[4] != "0")
					});
				}
			}
			Instance log2 = Kit.Log;
			if (log2 != null)
			{
				log2.Msg($"Lumberjack: {Cuts.Count} tree(s) you cut down in this save.");
			}
		}

		public static void Save()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (Cut cut in Cuts)
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append(';');
				}
				stringBuilder.Append(cut.X.ToString("0.00", CultureInfo.InvariantCulture)).Append(',').Append(cut.Y.ToString("0.00", CultureInfo.InvariantCulture))
					.Append(',')
					.Append(cut.Z.ToString("0.00", CultureInfo.InvariantCulture))
					.Append(',')
					.Append(cut.S.ToString("0.000", CultureInfo.InvariantCulture))
					.Append(',')
					.Append(cut.Stump ? "1" : "0");
			}
			FortifyApi.SetData("Felled", stringBuilder.ToString());
		}

		public static void Clear(bool restore = true)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			if (restore)
			{
				List<Texture2D> list = new List<Texture2D>();
				foreach (Cut cut in Cuts)
				{
					try
					{
						if ((Object)(object)cut.Tex != (Object)null && cut.Pixel >= 0)
						{
							Color val = Get(cut.Tex, cut.Pixel);
							cut.Tex.SetPixel(cut.Pixel % ((Texture)cut.Tex).width, cut.Pixel / ((Texture)cut.Tex).width, new Color(val.r, cut.Y, val.b, cut.S));
							if (!list.Contains(cut.Tex))
							{
								list.Add(cut.Tex);
							}
						}
						if ((Object)(object)cut.Trunk != (Object)null)
						{
							cut.Trunk.SetActive(true);
						}
					}
					catch
					{
					}
				}
				foreach (Texture2D item in list)
				{
					Apply(item);
				}
			}
			foreach (Cut cut2 in Cuts)
			{
				if ((Object)(object)cut2.StumpGo != (Object)null)
				{
					Object.Destroy((Object)(object)cut2.StumpGo);
				}
			}
			Cuts.Clear();
			Datas.Clear();
			_loaded = false;
		}
	}
	internal static class Logs
	{
		private sealed class PileOf
		{
			public GameObject Go;

			public int Left;
		}

		public const string LogId = "lj_log";

		public static string Hint;

		private static readonly List<PileOf> Piles = new List<PileOf>();

		private static bool _told;

		public static void Pile(Vector3 at, Vector3 along, float treeHeight)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0038: 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_0051: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				RaycastHit val = default(RaycastHit);
				if (Physics.Raycast(at + Vector3.up * 2.5f, Vector3.down, ref val, 6f, -1, (QueryTriggerInteraction)1))
				{
					at = ((RaycastHit)(ref val)).point;
				}
				float yaw = Mathf.Atan2(0f - along.z, along.x) * 57.29578f;
				GameObject go = LumberModels.LogPile(at, yaw);
				Piles.Add(new PileOf
				{
					Go = go,
					Left = Mathf.Clamp(Mathf.RoundToInt(treeHeight / 2.2f), 3, 8)
				});
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Lumberjack: the log pile (" + ex.Message + ").");
				}
			}
		}

		public static void Update()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_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_00d1: Unknown result type (might be due to invalid IL or missing references)
			Hint = null;
			if (Piles.Count == 0)
			{
				return;
			}
			Camera camera = Placement.GetCamera();
			if ((Object)(object)camera == (Object)null || (Object)(object)Player.Local == (Object)null)
			{
				return;
			}
			PileOf pileOf = null;
			float num = 3.2f;
			for (int num2 = Piles.Count - 1; num2 >= 0; num2--)
			{
				PileOf pileOf2 = Piles[num2];
				if ((Object)(object)pileOf2.Go == (Object)null)
				{
					Piles.RemoveAt(num2);
				}
				else
				{
					Vector3 val = pileOf2.Go.transform.position + Vector3.up * 0.3f - ((Component)camera).transform.position;
					float magnitude = ((Vector3)(ref val)).magnitude;
					if (!(magnitude > num) && !(Vector3.Dot(((Component)camera).transform.forward, val / Mathf.Max(magnitude, 0.01f)) < 0.72f))
					{
						pileOf = pileOf2;
						num = magnitude;
					}
				}
			}
			if (pileOf != null)
			{
				Hint = $"[{FortifyApi.UseKey}] Take the logs ({pileOf.Left})";
				if (FortifyApi.KeyDown(FortifyApi.UseKey))
				{
					Take(pileOf);
				}
			}
		}

		private static void Take(PileOf p)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			int num = Give(p.Left);
			if (num <= 0)
			{
				Chop.Say("No room in your pockets for the logs.", 3f);
				return;
			}
			p.Left -= num;
			try
			{
				LumberSound.Dig(p.Go.transform.position);
			}
			catch
			{
			}
			if (p.Left <= 0)
			{
				Object.Destroy((Object)(object)p.Go);
				Piles.Remove(p);
			}
			Chop.Say((p.Left > 0) ? $"{num} Pine Logs. No room for the other {p.Left}." : $"{num} Pine Logs.", 3f);
			if (!_told)
			{
				_told = true;
				FortifyApi.Notify("Lumberjack", "Pine Logs: sell them at the Pawn Shop (haggle for a good price), or stack them at your place as firewood.");
			}
		}

		private static int Give(int n)
		{
			try
			{
				PlayerInventory instance = PlayerSingleton<PlayerInventory>.Instance;
				ItemDefinition item = Registry.GetItem<ItemDefinition>("lj_log");
				if ((Object)(object)instance == (Object)null || (Object)(object)item == (Object)null)
				{
					return 0;
				}
				for (int num = n; num > 0; num--)
				{
					ItemInstance defaultInstance = item.GetDefaultInstance(num);
					if (defaultInstance != null && instance.CanItemFitInInventory(defaultInstance, num))
					{
						instance.AddItemToInventory(defaultInstance);
						return num;
					}
				}
			}
			catch (Exception ex)
			{
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Warning("Lumberjack: giving logs (" + ex.Message + ").");
				}
			}
			return 0;
		}

		public static void Clear()
		{
			foreach (PileOf pile in Piles)
			{
				if ((Object)(object)pile.Go != (Object)null)
				{
					Object.Destroy((Object)(object)pile.Go);
				}
			}
			Piles.Clear();
			Hint = null;
		}

		public static void DevPawnCheck()
		{
			try
			{
				PawnShopInterface instance = Singleton<PawnShopInterface>.Instance;
				ItemDefinition item = Registry.GetItem<ItemDefinition>("lj_log");
				ItemInstance val = ((item != null) ? item.GetDefaultInstance(10) : null);
				if ((Object)(object)instance == (Object)null || val == null)
				{
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Msg($"Lumberjack: pawn check: shop {(Object)(object)instance != (Object)null}, log {val != null}.");
					}
					return;
				}
				Il2CppReferenceArray<ItemSlot> pawnSlots = instance.PawnSlots;
				bool flag = pawnSlots != null && ((Il2CppArrayBase<ItemSlot>)(object)pawnSlots).Length > 0 && ((Il2CppArrayBase<ItemSlot>)(object)pawnSlots)[0].DoesItemMatchHardFilters(val);
				Instance log2 = Kit.Log;
				if (log2 != null)
				{
					log2.Msg($"Lumberjack: the Pawn Shop {(flag ? "takes" : "won't take")} Pine Logs; ten are worth about ${instance.GetItemValue(val):0} to it.");
				}
			}
			catch (Exception ex)
			{
				Instance log3 = Kit.Log;
				if (log3 != null)
				{
					log3.Warning("Lumberjack: pawn check (" + ex.Message + ").");
				}
			}
		}
	}
	public sealed class LumberCore : MelonMod
	{
		internal const string AxeId = "lj_axe";

		internal const string SawId = "lj_chainsaw";

		internal static MelonPreferences_Entry<int> AxeHits;

		internal static MelonPreferences_Entry<float> SawSeconds;

		internal static MelonPreferences_Entry<bool> Stumps;

		internal static MelonPreferences_Entry<bool> RegrowAll;

		private static MelonPreferences_Entry<float> _price;

		internal static int Felled;

		private static float _warnedAt = -100f;

		public override void OnInitializeMelon()
		{
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Host.Init((MelonMod)(object)this, "Lumberjack", "Lumberjack", "lj_", null, Loaded, Unloaded);
				FortifyApi.BeforeSave += Forest.Save;
				MelonPreferences_Category category = MelonPreferences.GetCategory("Lumberjack");
				_price = category.CreateEntry<float>("PriceMultiplier", 1f, "Price multiplier", "Multiplies the shop prices (1 = normal, 0 = free). Applies after a game restart.", false, false, (ValueValidator)null, (string)null);
				AxeHits = category.CreateEntry<int>("AxeHits", 6, "Axe hits per tree", "How many swings of the Felling Axe bring a tree down (a stump takes half as many).", false, false, (ValueValidator)null, (string)null);
				SawSeconds = category.CreateEntry<float>("SawSeconds", 3f, "Chainsaw seconds per tree", "How many seconds of cutting with the Chainsaw bring a tree down (a stump takes half as long).", false, false, (ValueValidator)null, (string)null);
				Stumps = category.CreateEntry<bool>("Stumps", true, "Leave stumps", "A stump is left where each tree stood (off: no stumps at all).", false, false, (ValueValidator)null, (string)null);
				RegrowAll = category.CreateEntry<bool>("RegrowAll", false, "Regrow all trees", "Turn this on and load your save: every tree you've cut down in it grows back, and this turns itself off again.", false, false, (ValueValidator)null, (string)null);
				Kit.PriceMultiplier = () => _price?.Value ?? 1f;
				FortifyApi.SetNotifyIcon("lj_axe");
				Catalog.Add(new ItemSpec
				{
					Id = "lj_axe",
					Name = "Felling Axe",
					Kind = PlaceKind.Ground,
					Price = 160f,
					RotateStep = 0f,
					StackLimit = 1,
					IconColor = new Color(0.55f, 0.1f, 0.06f),
					BuildModel = LumberModels.Axe,
					IconModel = LumberModels.AxeIcon,
					Description = "A hickory-handled felling axe. Hold it, aim at a tree trunk and click to chop: a few good swings and it comes down. Clears room for building anywhere in Hyland Point."
				});
				Catalog.Add(new ItemSpec
				{
					Id = "lj_chainsaw",
					Name = "Chainsaw",
					Kind = PlaceKind.Ground,
					Price = 900f,
					RotateStep = 0f,
					StackLimit = 1,
					IconColor = new Color(0.9f, 0.42f, 0.05f),
					BuildModel = LumberModels.Chainsaw,
					Description = "A gas chainsaw. Hold it, aim at a tree trunk and hold the mouse button: it's through in a few seconds. Cuts out stumps too."
				});
				Catalog.Add(new ItemSpec
				{
					Id = "lj_log",
					Name = "Pine Log",
					Kind = PlaceKind.Ground,
					Price = 60f,
					RotateStep = 45f,
					StackLimit = 20,
					NotSold = true,
					IconColor = new Color(0.36f, 0.24f, 0.14f),
					BuildModel = LumberModels.Log,
					Description = "A length of pine from a tree you cut down. Sell your logs at the Pawn Shop, or stack them at your place as firewood."
				});
				Kit.CustomPlace["lj_axe"] = Chop.Held;
				Kit.CustomPlace["lj_chainsaw"] = Chop.Held;
				Kit.DevGiveKey = (KeyCode)104;
				Host.Ok = true;
				((MelonBase)this).LoggerInstance.Msg("Lumberjack loaded. The Felling Axe and the Chainsaw are at Dan's Hardware and Handy Hank's Hardware.");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Lumberjack couldn't start: " + ex.Message + ". It needs MelonLoader 0.7 and S1API (Bars fork) 3.2.3 or newer.");
			}
		}

		private static void Loaded()
		{
			Felled = 0;
			Forest.Load();
			LumberSound.Prewarm();
		}

		private static void Unloaded()
		{
			Chop.Unload();
			Fall.Clear();
			Logs.Clear();
			Forest.Clear();
		}

		public override void OnUpdate()
		{
			if (!Host.Update())
			{
				return;
			}
			try
			{
				Chop.Update();
				Fall.Update();
				Logs.Update();
				Forest.Update();
				if (FortifyApi.DevKeys && FortifyApi.KeyHeld((KeyCode)308) && FortifyApi.KeyDown((KeyCode)104))
				{
					Forest.DevGoToTree();
					Logs.DevPawnCheck();
				}
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime - _warnedAt > 30f)
				{
					_warnedAt = Time.unscaledTime;
					((MelonBase)this).LoggerInstance.Warning("Lumberjack: " + ex.Message);
				}
			}
		}

		public override void OnGUI()
		{
			if (Host.Ok && FortifyApi.InGame)
			{
				try
				{
					Chop.Draw();
				}
				catch
				{
				}
				Host.DrawHint();
				if (Logs.Hint != null)
				{
					FortifyApi.Hint(Logs.Hint);
				}
			}
		}
	}
	internal static class LumberModels
	{
		private static readonly HashSet<int> Fixed = new HashSet<int>();

		private static GameObject _stump;

		private static Material _chip;

		private static GameObject _pile;

		public static GameObject Load(string name, string file)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			((Object)GltfLoader.LoadEmbedded(file, val.transform)).name = "Model";
			foreach (Renderer componentsInChild in val.GetComponentsInChildren<Renderer>(true))
			{
				foreach (Material item in (Il2CppArrayBase<Material>)(object)componentsInChild.sharedMaterials)
				{
					if (!((Object)(object)item == (Object)null) && Fixed.Add(((Object)item).GetInstanceID()))
					{
						Color color = item.color;
						Color val2 = (item.color = ((Color)(ref color)).gamma);
						Color val3 = val2;
						if (item.HasProperty("_BaseColor"))
						{
							item.SetColor("_BaseColor", val3);
						}
					}
				}
			}
			return val;
		}

		public static GameObject Axe()
		{
			//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_002c: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Load("lj_Axe", "LJ_Axe.glb");
			GameObject val2 = new GameObject("LJ_Hit");
			val2.transform.SetParent(val.transform, false);
			val2.transform.localPosition = new Vector3(0.02f, 0.02f, 0.38f);
			val2.AddComponent<BoxCollider>().size = new Vector3(0.2f, 0.06f, 0.8f);
			return val;
		}

		public static GameObject AxeIcon()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Catalog.Get("lj_axe")?.Template;
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject val2 = new GameObject("lj_AxeIcon");
			GameObject val3 = Object.Instantiate<GameObject>(val, val2.transform, false);
			val3.SetActive(true);
			foreach (Collider componentsInChild in val3.GetComponentsInChildren<Collider>(true))
			{
				Object.Destroy((Object)(object)componentsInChild);
			}
			val3.transform.localRotation = Quaternion.Euler(0f, 0f, -40f) * Quaternion.Euler(-90f, 0f, 0f) * Quaternion.Euler(0f, 0f, 0f);
			val3.transform.localPosition = new Vector3(-0.15f, -0.25f, 0f);
			val3.transform.localScale = new Vector3(1.6f, 1f, 1.6f);
			return val2;
		}

		public static GameObject Chainsaw()
		{
			//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_002c: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Load("lj_Chainsaw", "LJ_Chainsaw.glb");
			GameObject val2 = new GameObject("LJ_Hit");
			val2.transform.SetParent(val.transform, false);
			val2.transform.localPosition = new Vector3(0f, 0.1f, 0.3f);
			val2.AddComponent<BoxCollider>().size = new Vector3(0.16f, 0.22f, 0.85f);
			return val;
		}

		public static GameObject Log()
		{
			//IL_0025: 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)
			GameObject obj = Load("lj_Log", "LJ_Log.glb");
			BoxCollider obj2 = obj.AddComponent<BoxCollider>();
			obj2.center = new Vector3(0f, 0.135f, 0f);
			obj2.size = new Vector3(1.12f, 0.29f, 0.3f);
			return obj;
		}

		public static GameObject LogPile(Vector3 at, float yaw)
		{
			//IL_0059: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_pile == (Object)null)
			{
				_pile = Load("lj_LogPileSrc", "LJ_LogPile.glb");
				_pile.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)_pile);
			}
			GameObject val = Object.Instantiate<GameObject>(_pile);
			((Object)val).name = "lj_LogPile";
			val.SetActive(true);
			val.transform.position = at;
			val.transform.rotation = Quaternion.Euler(0f, yaw, 0f);
			GameObject val2 = new GameObject("LJ_PileHit");
			val2.transform.SetParent(val.transform, false);
			val2.transform.localPosition = new Vector3(0f, 0.26f, 0f);
			val2.AddComponent<BoxCollider>().size = new Vector3(1.3f, 0.52f, 0.95f);
			return val;
		}

		public static GameObject Stump(Vector3 at, float size)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00de: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_stump == (Object)null)
			{
				_stump = Load("lj_StumpSrc", "LJ_Stump.glb");
				_stump.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)_stump);
			}
			GameObject val = Object.Instantiate<GameObject>(_stump);
			((Object)val).name = "lj_Stump";
			val.SetActive(true);
			val.transform.position = at + Vector3.down * 0.05f;
			val.transform.rotation = Quaternion.Euler(0f, (at.x * 37f + at.z * 11f) % 360f, 0f);
			val.transform.localScale = Vector3.one * size;
			GameObject val2 = new GameObject("LJ_StumpHit");
			val2.transform.SetParent(val.transform, false);
			val2.transform.localPosition = new Vector3(0f, 0.17f, 0f);
			val2.AddComponent<BoxCollider>().size = new Vector3(0.62f, 0.34f, 0.62f);
			return val;
		}

		public static void Chips(Vector3 at, Vector3 away, int n)
		{
			//IL_0021: 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_0079: 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)
			//IL_00c5: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_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_0124: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)_chip == (Object)null)
				{
					_chip = Models.Mat("lj_chip", new Color(0.86f, 0.7f, 0.46f), 0f, 0.15f);
				}
				for (int i = 0; i < n; i++)
				{
					GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
					((Object)obj).name = "lj_Chip";
					obj.layer = 2;
					obj.GetComponent<Renderer>().sharedMaterial = _chip;
					obj.transform.position = at + Random.insideUnitSphere * 0.05f;
					obj.transform.localScale = new Vector3(Random.Range(0.02f, 0.045f), Random.Range(0.006f, 0.012f), Random.Range(0.015f, 0.03f));
					obj.transform.rotation = Random.rotation;
					Rigidbody obj2 = obj.AddComponent<Rigidbody>();
					obj2.mass = 0.01f;
					obj2.velocity = away * Random.Range(1.2f, 2.8f) + Vector3.up * Random.Range(1f, 2.5f) + Random.insideUnitSphere * 0.8f;
					obj2.angularVelocity = Random.insideUnitSphere * 20f;
					Object.Destroy((Object)(object)obj, Random.Range(2.5f, 4f));
				}
			}
			catch
			{
			}
		}
	}
	internal static class LumberSound
	{
		private static AudioClip _chop;

		private static AudioClip _crack;

		private static AudioClip _crash;

		private static AudioClip _sawIdle;

		private static AudioClip _sawCut;

		private static AudioClip _dig;

		private static AudioSource _saw;

		private static uint _seed = 2463534242u;

		private static float Noise()
		{
			_seed ^= _seed << 13;
			_seed ^= _seed >> 17;
			_seed ^= _seed << 5;
			return (float)(_seed & 0xFFFF) / 32768f - 1f;
		}

		private static AudioClip Make(string name, float seconds, Func<float, float> w, float smooth = 1f)
		{
			int num = (int)(seconds * 22050f);
			float[] array = new float[num];
			float num2 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num3 = w((float)i / 22050f);
				num2 += (num3 - num2) * smooth;
				array[i] = Mathf.Clamp(num2, -1f, 1f);
			}
			AudioClip obj = Sfx.Create(name, num, 1, 22050, stream: false);
			Sfx.SetData(obj, new Il2CppStructArray<float>(array), 0);
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}

		public static void Prewarm()
		{
			try
			{
				Ensure();
			}
			catch
			{
			}
		}

		private static void Ensure()
		{
			if (!((Object)(object)_chop != (Object)null))
			{
				_chop = Make("LJ_Chop", 0.35f, (float t) => Mathf.Exp((0f - t) * 26f) * (Mathf.Sin((float)Math.PI * 2f * (150f - 140f * t) * t) * 0.8f + Noise() * 0.55f), 0.35f);
				_dig = Make("LJ_Dig", 0.3f, (float t) => Mathf.Exp((0f - t) * 18f) * Noise() * 0.6f, 0.2f);
				_crack = Make("LJ_Crack", 1.6f, delegate(float t)
				{
					float num = 180f + 90f * t + 25f * Mathf.Sin(t * 31f);
					float num2 = Mathf.Sin((float)Math.PI * 2f * num * t) * (0.5f + 0.5f * Mathf.Sin(t * 55f)) * 0.35f * Mathf.Clamp01(t * 4f);
					float num3 = ((t > 1.1f) ? (Noise() * Mathf.Exp((0f - (t - 1.1f)) * 7f) * 0.7f) : 0f);
					return num2 + num3;
				}, 0.5f);
				_crash = Make("LJ_Crash", 2.2f, (float t) => Mathf.Exp((0f - t) * 6f) * Mathf.Sin((float)Math.PI * 2f * (55f - 20f * t) * t) * 0.9f + Noise() * Mathf.Exp((0f - t) * 2.4f) * 0.55f * Mathf.Clamp01(t * 30f), 0.6f);
				_sawIdle = Make("LJ_SawIdle", 1f, (float t) => (t * 48f % 1f * 2f - 1f) * 0.25f + Mathf.Sin((float)Math.PI * 192f * t) * 0.15f + Noise() * 0.05f, 0.6f);
				_sawCut = Make("LJ_SawCut", 1f, (float t) => (t * 120f % 1f * 2f - 1f) * 0.3f + Mathf.Sin((float)Math.PI * 480f * t) * 0.15f + Noise() * 0.2f, 0.7f);
			}
		}

		private static void At(Vector3 p, AudioClip c, float v, float spatial = 0.7f, float pitch = 1f)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			try
			{
				GameObject val = new GameObject("LJ_Sound");
				val.transform.position = p;
				AudioSource obj = val.AddComponent<AudioSource>();
				obj.spatialBlend = spatial;
				obj.minDistance = 4f;
				obj.maxDistance = 70f;
				obj.volume = v;
				obj.pitch = pitch;
				obj.PlayOneShot(c);
				Object.Destroy((Object)val, c.length / Mathf.Max(0.3f, pitch) + 0.2f);
			}
			catch
			{
			}
		}

		public static void Chop(Vector3 p)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Ensure();
				At(p, _chop, 0.9f, 0.6f, Random.Range(0.9f, 1.1f));
			}
			catch
			{
			}
		}

		public static void Dig(Vector3 p)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Ensure();
				At(p, _dig, 0.8f, 0.6f, Random.Range(0.85f, 1.1f));
			}
			catch
			{
			}
		}

		public static void Crack(Vector3 p)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Ensure();
				At(p, _crack, 0.9f, 0.6f);
			}
			catch
			{
			}
		}

		public static void Crash(Vector3 p)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Ensure();
				At(p, _crash, 1f, 0.75f);
			}
			catch
			{
			}
		}

		public static void Saw(Transform at, int mode)
		{
			//IL_0042: 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: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (mode == 0)
				{
					if ((Object)(object)_saw != (Object)null && _saw.isPlaying)
					{
						_saw.Stop();
					}
					return;
				}
				Ensure();
				if ((Object)(object)_saw == (Object)null)
				{
					GameObject val = new GameObject("LJ_SawSound");
					Object.DontDestroyOnLoad((Object)val);
					_saw = val.AddComponent<AudioSource>();
					_saw.loop = true;
					_saw.spatialBlend = 0f;
					_saw.volume = 0.35f;
				}
				AudioClip val2 = ((mode == 2) ? _sawCut : _sawIdle);
				if ((Object)(object)_saw.clip != (Object)(object)val2)
				{
					_saw.clip = val2;
					_saw.Play();
				}
				if ((Object)(object)at != (Object)null)
				{
					((Component)_saw).transform.position = at.position;
				}
				_saw.volume = ((mode == 2) ? 0.45f : 0.3f);
				if (!_saw.isPlaying)
				{
					_saw.Play();
				}
			}
			catch
			{
			}
		}
	}
}
namespace S2_LJ.WoodKit
{
	internal static class Catalog
	{
		public static readonly List<ItemSpec> Items = new List<ItemSpec>();

		private static readonly Dictionary<string, ItemSpec> ById = new Dictionary<string, ItemSpec>(StringComparer.OrdinalIgnoreCase);

		public static void Add(ItemSpec s)
		{
			Items.Add(s);
			ById[s.Id] = s;
		}

		public static ItemSpec Get(string id)
		{
			if (string.IsNullOrEmpty(id) || !ById.TryGetValue(id, out var value))
			{
				return null;
			}
			return value;
		}

		public static void BuildTemplates()
		{
			foreach (ItemSpec item in Items)
			{
				if ((Object)(object)item.Template != (Object)null || item.BuildModel == null)
				{
					continue;
				}
				try
				{
					item.Template = item.BuildModel();
					if ((Object)(object)item.Template != (Object)null && (Object)(object)item.Template.transform.parent == (Object)null)
					{
						item.Template.transform.SetParent(Models.Root, false);
					}
				}
				catch (Exception ex)
				{
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Error("Couldn't build the " + item.Name + " model: " + ex.Message);
					}
				}
			}
		}
	}
	internal static class Core
	{
		internal const string PickupLabel = "Hold Right Click";

		public static Instance Log => Kit.Log;

		public static KeyCode ViewKey => FortifyApi.UseKey;

		public static KeyCode RotateKey => Kit.RotateKey;
	}
	internal static class GltfLoader
	{
		public static GameObject LoadEmbedded(string fileName, Transform parent)
		{
			using Stream stream = Res.Open(Kit.ModelResourcePrefix + fileName);
			if (stream == null)
			{
				throw new FileNotFoundException("Embedded model missing: " + fileName);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return Load(memoryStream.ToArray(), Path.GetFileNameWithoutExtension(fileName), parent);
		}

		public static GameObject Load(byte[] glb, string name, Transform parent)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			if (glb.Length < 20 || BitConverter.ToUInt32(glb, 0) != 1179937895)
			{
				throw new InvalidDataException("Not a GLB file");
			}
			int num = (int)BitConverter.ToUInt32(glb, 12);
			string json = Encoding.UTF8.GetString(glb, 20, num);
			int bin = 20 + num + 8;
			using JsonDocument jsonDocument = JsonDocument.Parse(json);
			JsonElement rootElement = jsonDocument.RootElement;
			Material[] materials = BuildMaterials(rootElement);
			Dictionary<int, (Mesh, Material[])> meshCache = new Dictionary<int, (Mesh, Material[])>();
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			JsonElement property = rootElement.GetProperty("nodes");
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 0; i < property.GetArrayLength(); i++)
			{
				if (!property[i].TryGetProperty("children", out var value))
				{
					continue;
				}
				foreach (JsonElement item in value.EnumerateArray())
				{
					hashSet.Add(item.GetInt32());
				}
			}
			for (int j = 0; j < property.GetArrayLength(); j++)
			{
				if (!hashSet.Contains(j))
				{
					BuildNode(rootElement, property, j, val.transform, glb, bin, materials, meshCache);
				}
			}
			return val;
		}

		private static void BuildNode(JsonElement root, JsonElement nodes, int index, Transform parent, byte[] glb, int bin, Material[] materials, Dictionary<int, (Mesh, Material[])> meshCache)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			JsonElement jsonElement = nodes[index];
			JsonElement value;
			GameObject val = new GameObject(jsonElement.TryGetProperty("name", out value) ? value.GetString() : ("node" + index));
			Transform transform = val.transform;
			transform.SetParent(parent, false);
			if (jsonElement.TryGetProperty("translation", out var value2))
			{
				transform.localPosition = new Vector3(value2[0].GetSingle(), value2[1].GetSingle(), 0f - value2[2].GetSingle());
			}
			if (jsonElement.TryGetProperty("rotation", out var value3))
			{
				transform.localRotation = new Quaternion(0f - value3[0].GetSingle(), 0f - value3[1].GetSingle(), value3[2].GetSingle(), value3[3].GetSingle());
			}
			if (jsonElement.TryGetProperty("scale", out var value4))
			{
				transform.localScale = new Vector3(value4[0].GetSingle(), value4[1].GetSingle(), value4[2].GetSingle());
			}
			if (jsonElement.TryGetProperty("mesh", out var value5))
			{
				int @int = value5.GetInt32();
				if (!meshCache.TryGetValue(@int, out var value6))
				{
					(Mesh, Material[]) tuple = (meshCache[@int] = BuildMesh(root, @int, glb, bin, materials));
					value6 = tuple;
				}
				val.AddComponent<MeshFilter>().sharedMesh = value6.Item1;
				MeshRenderer val2 = val.AddComponent<MeshRenderer>();
				Il2CppReferenceArray<Material> val3 = new Il2CppReferenceArray<Material>((long)value6.Item2.Length);
				for (int i = 0; i < value6.Item2.Length; i++)
				{
					((Il2CppArrayBase<Material>)(object)val3)[i] = value6.Item2[i];
				}
				((Renderer)val2).sharedMaterials = val3;
			}
			if (!jsonElement.TryGetProperty("children", out var value7))
			{
				return;
			}
			foreach (JsonElement item in value7.EnumerateArray())
			{
				BuildNode(root, nodes, item.GetInt32(), transform, glb, bin, materials, meshCache);
			}
		}

		private static (Mesh, Material[]) BuildMesh(JsonElement root, int meshIndex, byte[] glb, int bin, Material[] materials)
		{
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Expected O, but got Unknown
			//IL_00c1: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: 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)
			JsonElement property = root.GetProperty("meshes")[meshIndex].GetProperty("primitives");
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int[]> list4 = new List<int[]>();
			List<Material> list5 = new List<Material>();
			foreach (JsonElement item in property.EnumerateArray())
			{
				JsonElement property2 = item.GetProperty("attributes");
				int count = list.Count;
				int count2;
				float[] array = ReadFloats(root, property2.GetProperty("POSITION").GetInt32(), glb, bin, out count2);
				for (int i = 0; i < count2; i++)
				{
					list.Add(new Vector3(array[i * 3], array[i * 3 + 1], 0f - array[i * 3 + 2]));
				}
				int count3;
				if (property2.TryGetProperty("NORMAL", out var value))
				{
					float[] array2 = ReadFloats(root, value.GetInt32(), glb, bin, out count3);
					for (int j = 0; j < count2; j++)
					{
						list2.Add(new Vector3(array2[j * 3], array2[j * 3 + 1], 0f - array2[j * 3 + 2]));
					}
				}
				else
				{
					for (int k = 0; k < count2; k++)
					{
						list2.Add(Vector3.up);
					}
				}
				if (property2.TryGetProperty("TEXCOORD_0", out var value2))
				{
					float[] array3 = ReadFloats(root, value2.GetInt32(), glb, bin, out count3);
					for (int l = 0; l < count2; l++)
					{
						list3.Add(new Vector2(array3[l * 2], 1f - array3[l * 2 + 1]));
					}
				}
				else
				{
					for (int m = 0; m < count2; m++)
					{
						list3.Add(Vector2.zero);
					}
				}
				int[] array4;
				if (item.TryGetProperty("indices", out var value3))
				{
					array4 = ReadIndices(root, value3.GetInt32(), glb, bin);
				}
				else
				{
					array4 = new int[count2];
					for (int n = 0; n < count2; n++)
					{
						array4[n] = n;
					}
				}
				for (int num = 0; num + 2 < array4.Length; num += 3)
				{
					int num2 = array4[num] + count;
					int num3 = array4[num + 1] + count;
					int num4 = array4[num + 2] + count;
					array4[num] = num2;
					array4[num + 1] = num4;
					array4[num + 2] = num3;
				}
				list4.Add(array4);
				JsonElement value4;
				int num5 = (item.TryGetProperty("material", out value4) ? value4.GetInt32() : (-1));
				list5.Add((num5 >= 0 && num5 < materials.Length) ? materials[num5] : Models.Mat("gltf_default", Color.gray));
			}
			Mesh val = new Mesh
			{
				name = "HTF_" + meshIndex
			};
			if (list.Count > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.vertices = new Il2CppStructArray<Vector3>(list.ToArray());
			val.normals = new Il2CppStructArray<Vector3>(list2.ToArray());
			val.uv = new Il2CppStructArray<Vector2>(list3.ToArray());
			val.subMeshCount = list4.Count;
			for (int num6 = 0; num6 < list4.Count; num6++)
			{
				val.SetTriangles(new Il2CppStructArray<int>(list4[num6]), num6);
			}
			val.RecalculateBounds();
			((Object)val).hideFlags = (HideFlags)32;
			return (val, list5.ToArray());
		}

		private static Material[] BuildMaterials(JsonElement root)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
			if (!root.TryGetProperty("materials", out var value))
			{
				return Array.Empty<Material>();
			}
			Material[] array = (Material[])(object)new Material[value.GetArrayLength()];
			for (int i = 0; i < array.Length; i++)
			{
				JsonElement jsonElement = value[i];
				JsonElement value2;
				string text = (jsonElement.TryGetProperty("name", out value2) ? value2.GetString() : ("mat" + i));
				Color white = Color.white;
				float metallic = 1f;
				float num = 1f;
				if (jsonElement.TryGetProperty("pbrMetallicRoughness", out var value3))
				{
					if (value3.TryGetProperty("baseColorFactor", out var value4))
					{
						((Color)(ref white))..ctor(value4[0].GetSingle(), value4[1].GetSingle(), value4[2].GetSingle(), value4[3].GetSingle());
					}
					if (value3.TryGetProperty("metallicFactor", out var value5))
					{
						metallic = value5.GetSingle();
					}
					if (value3.TryGetProperty("roughnessFactor", out var value6))
					{
						num = value6.GetSingle();
					}
				}
				Color? emission = null;
				if (jsonElement.TryGetProperty("emissiveFactor", out var value7))
				{
					float num2 = 1f;
					if (jsonElement.TryGetProperty("extensions", out var value8) && value8.TryGetProperty("KHR_materials_emissive_strength", out var value9) && value9.TryGetProperty("emissiveStrength", out var value10))
					{
						num2 = value10.GetSingle();
					}
					Color value11 = new Color(value7[0].GetSingle(), value7[1].GetSingle(), value7[2].GetSingle()) * Mathf.Min(num2, 8f) * 0.5f;
					if (((Color)(ref value11)).maxColorComponent > 0.001f)
					{
						emission = value11;
					}
				}
				array[i] = Models.Mat("glb_" + text, white, metallic, 1f - num, emission);
			}
			return array;
		}

		private static float[] ReadFloats(JsonElement root, int accessor, byte[] glb, int bin, out int count)
		{
			JsonElement jsonElement = root.GetProperty("accessors")[accessor];
			count = jsonElement.GetProperty("count").GetInt32();
			int num = Components(jsonElement.GetProperty("type").GetString());
			JsonElement jsonElement2 = root.GetProperty("bufferViews")[jsonElement.GetProperty("bufferView").GetInt32()];
			JsonElement value;
			JsonElement value2;
			int num2 = bin + (jsonElement2.TryGetProperty("byteOffset", out value) ? value.GetInt32() : 0) + (jsonElement.TryGetProperty("byteOffset", out value2) ? value2.GetInt32() : 0);
			JsonElement value3;
			int num3 = (jsonElement2.TryGetProperty("byteStride", out value3) ? value3.GetInt32() : (num * 4));
			float[] array = new float[count * num];
			for (int i = 0; i < count; i++)
			{
				for (int j = 0; j < num; j++)
				{
					array[i * num + j] = BitConverter.ToSingle(glb, num2 + i * num3 + j * 4);
				}
			}
			return array;
		}

		private static int[] ReadIndices(JsonElement root, int accessor, byte[] glb, int bin)
		{
			JsonElement jsonElement = root.GetProperty("accessors")[accessor];
			int @int = jsonElement.GetProperty("count").GetInt32();
			int int2 = jsonElement.GetProperty("componentType").GetInt32();
			JsonElement value;
			JsonElement value2;
			int num = bin + (root.GetProperty("bufferViews")[jsonElement.GetProperty("bufferView").GetInt32()].TryGetProperty("byteOffset", out value) ? value.GetInt32() : 0) + (jsonElement.TryGetProperty("byteOffset", out value2) ? value2.GetInt32() : 0);
			int[] array = new int[@int];
			for (int i = 0; i < @int; i++)
			{
				int[] array2 = array;
				int num2 = i;
				int[] array3 = array2;
				int num3 = num2;
				array3[num3] = int2 switch
				{
					5121 => glb[num + i], 
					5123 => BitConverter.ToUInt16(glb, num + i * 2), 
					_ => (int)BitConverter.ToUInt32(glb, num + i * 4), 
				};
			}
			return array;
		}

		private static int Components(string type)
		{
			return type switch
			{
				"SCALAR" => 1, 
				"VEC2" => 2, 
				"VEC3" => 3, 
				"VEC4" => 4, 
				_ => 1, 
			};
		}
	}
	internal static class Host
	{
		public static bool Ok;

		public static string LinkedInGameNote = "Fortify Your Base already sells these at the hardware stores.";

		private static bool _linkedTold;

		private static bool _whereTold;

		public static string WhereToBuyNote;

		private static string _linkedNote;

		private static Action _onLoaded;

		private static Action _onUnloaded;

		private static string _folder;

		public static void Init(MelonMod mod, string folder, string title, string prefix, string linkedNote =