Decompiled source of GunPowdered v1.0.2

GunPowdered/GunPowdered.dll

Decompiled 20 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GunPowdered.Bootstrap;
using GunPowdered.Configuration;
using GunPowdered.Core;
using GunPowdered.Features.Cannon.Domain;
using GunPowdered.Features.Cannon.Infrastructure;
using GunPowdered.Features.Dynamite.Domain;
using GunPowdered.Features.Dynamite.Infrastructure;
using GunPowdered.Features.Example.Application;
using GunPowdered.Features.Example.Domain;
using GunPowdered.Features.Example.Execution;
using GunPowdered.Features.Example.Infrastructure;
using GunPowdered.Features.ExplosiveArrows.Infrastructure;
using GunPowdered.Features.Grenades.Domain;
using GunPowdered.Features.Grenades.Infrastructure;
using GunPowdered.Features.Guano.Domain;
using GunPowdered.Features.Guano.Infrastructure;
using GunPowdered.Features.Gunpowder.Domain;
using GunPowdered.Features.Gunpowder.Infrastructure;
using GunPowdered.Features.MobileCannon.Domain;
using GunPowdered.Features.MobileCannon.Infrastructure;
using GunPowdered.Features.Musket.Domain;
using GunPowdered.Features.Musket.Infrastructure;
using GunPowdered.Features.Saltpeter.Domain;
using GunPowdered.Features.Saltpeter.Infrastructure;
using GunPowdered.Features.Skilling.Domain;
using GunPowdered.Features.Skilling.Infrastructure;
using GunPowdered.Features.Sulfur.Domain;
using GunPowdered.Features.Sulfur.Infrastructure;
using GunPowdered.Features.Water.Domain;
using GunPowdered.Features.Water.Infrastructure;
using GunPowdered.Integrations.HarmonyPatches;
using GunPowdered.Integrations.Items;
using GunPowdered.Integrations.KyRegistry;
using GunPowdered.Integrations.Valheim;
using GunPowdered.Presentation.Hub.Commands;
using GunPowdered.Presentation.Hub.Registration;
using GunPowdered.Presentation.Hub.ViewModels;
using GunPowdered.Testing.TestHooks;
using GunPowdered.Ui;
using HarmonyLib;
using KydlCore.Common;
using KydlCore.Core;
using KydlCore.Features.Diagnostics.Contracts;
using KydlCore.Features.Hub.Contracts;
using KydlCore.Features.Items.Contracts;
using KydlCore.ServerSync;
using KydlCore.Ui;
using Microsoft.CodeAnalysis;
using SoftReferenceableAssets;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
using UnityEngine.UIElements;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GunPowdered
{
	public static class GunPowderedApi
	{
		public static class Prefabs
		{
			public const string BatGuano = "GP_BatGuano";

			public const string Saltpeter = "GP_Saltpeter";

			public const string Gunpowder = "GP_Gunpowder";

			public const string Water = "GP_Water";

			public const string Bucket = "GP_Bucket";

			public const string BucketFull = "GP_BucketFull";

			public const string LeachingVat = "GP_LeachingVat";

			public const string PowderMill = "GP_PowderMill";

			public const string RainBarrel = "GP_RainBarrel";

			public const string GuanoDeposit = "GP_GuanoDeposit";

			public const string SulfurousMud = "GP_SulfurousMud";

			public const string SpikedGrenade = "GP_SpikedGrenade";

			public const string CannonBall = "GP_CannonBall";

			public const string FlametalCannonBall = "GP_FlametalCannonBall";

			public const string Cannon = "GP_Cannon";

			public const string CannonStock = "GP_CannonStock";

			public const string Musket = "GP_Musket";

			public const string ExplosiveArrow = "GP_ExplosiveArrow";

			public const string Dynamite = "GP_Dynamite";

			public const string MobileCannon = "GP_MobileCannon";

			public const string AsksvinHarness = "GP_AsksvinHarness";

			public const string Paper = "GP_Paper";

			public const string IronBullet = "GP_IronBullet";

			public const string PaperCartridge = "GP_PaperCartridge";

			public const string DeepNorthPack = "GP_DeepNorthPack";

			public const string LeachBarrel = "GP_LeachBarrel";

			public const string SettlingTank = "GP_SettlingTank";

			public const string BlackMetalBoiler = "GP_BlackMetalBoiler";

			public const string DvergrDripPipes = "GP_DvergrDripPipes";

			public const string FlametalHeater = "GP_FlametalHeater";

			public const string MillGrindstone = "GP_MillGrindstone";

			public const string MillSieve = "GP_MillSieve";

			public const string MillOven = "GP_MillOven";
		}

		public static class Musket
		{
			public const int Capacity = 5;

			public const float BulletPierce = 50f;

			public const float BulletSpeed = 110f;

			public const float BulletSpreadDegrees = 0.6f;

			public const float BulletSeconds = 3f;

			public const float ShotIntervalSeconds = 0.8f;

			public const float ReloadSecondsPerCartridge = 1.2f;

			public const string Ammunition = "GP_PaperCartridge";

			private static bool _hooked;

			private static event Action<MusketShot> _shotFired;

			public static event Action<MusketShot> ShotFired
			{
				add
				{
					Hook();
					_shotFired += value;
				}
				remove
				{
					_shotFired -= value;
				}
			}

			public static int CartridgesToLoad(int loaded, int carried)
			{
				return MusketRules.CartridgesToLoad(loaded, carried);
			}

			public static bool IsMusket(ItemData item)
			{
				return MusketGun.IsMusket(item);
			}

			public static int GetLoaded(ItemData musket)
			{
				if (!MusketGun.IsMusket(musket))
				{
					return -1;
				}
				return MusketGun.Loaded(musket);
			}

			public static int SetLoaded(ItemData musket, int loaded)
			{
				if (!MusketGun.IsMusket(musket))
				{
					return -1;
				}
				return MusketGun.SetLoaded(musket, loaded);
			}

			public static ItemData HeldBy(Player player)
			{
				return MusketGun.Held(player);
			}

			private static void Hook()
			{
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("Musket.Hook()");
				}
				if (!_hooked)
				{
					_hooked = true;
					MusketGun.Fired += Pass;
				}
			}

			private static void Pass(Player shooter, ItemData musket, Vector3 muzzle, Vector3 direction, int left, GameObject bullet)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				Action<MusketShot> shotFired = Musket._shotFired;
				if (shotFired == null)
				{
					if (RuleLog.IsOn())
					{
						ModLog.Verbose("Musket.Pass: returns because listeners == null (line 55)");
					}
					return;
				}
				MusketShot obj = new MusketShot(shooter, musket, muzzle, direction, left, bullet);
				Delegate[] invocationList = shotFired.GetInvocationList();
				foreach (Delegate obj2 in invocationList)
				{
					try
					{
						((Action<MusketShot>)obj2)(obj);
					}
					catch (Exception ex)
					{
						ModLog.Warn("GunPowderedApi.Musket.ShotFired: a listener failed (" + obj2.Method.DeclaringType?.ToString() + "." + obj2.Method.Name + "): " + ex.GetType().Name + ": " + ex.Message + "\n" + ex.StackTrace);
					}
				}
			}
		}

		public sealed class MusketShot
		{
			public Player Shooter { get; }

			public ItemData Weapon { get; }

			public Vector3 Muzzle { get; }

			public Vector3 Direction { get; }

			public int CartridgesLeft { get; }

			public GameObject Bullet { get; }

			internal MusketShot(Player shooter, ItemData musket, Vector3 muzzle, Vector3 direction, int cartridgesLeft, GameObject bullet)
			{
				//IL_00b4: 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_00bb: 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_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("MusketShot.MusketShot(shooter=" + RuleLog.Shown(shooter) + ", musket=" + RuleLog.Shown(musket) + ", muzzle=" + RuleLog.Shown(muzzle) + ", direction=" + RuleLog.Shown(direction) + ", cartridgesLeft=" + RuleLog.Shown(cartridgesLeft) + ", bullet=" + RuleLog.Shown(bullet) + ")");
				}
				Shooter = shooter;
				Weapon = musket;
				Muzzle = muzzle;
				Direction = direction;
				CartridgesLeft = cartridgesLeft;
				Bullet = bullet;
			}
		}

		public const int ApiVersion = 1;

		public static IReadOnlyList<string> AllPrefabs => ItemCatalog.All.Select((ItemSpec i) => i.Id).ToList();

		public static string DisplayName(string prefab)
		{
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose("Prefabs.DisplayName(prefab=" + RuleLog.Shown(prefab) + ")");
			}
			string text = ItemCatalog.All.FirstOrDefault((ItemSpec i) => i.Id == prefab)?.Name;
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose("Prefabs.DisplayName: returns " + text + " (line 73)");
			}
			return text;
		}

		public static bool IsGunpowderIngredient(string prefab)
		{
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose("Prefabs.IsGunpowderIngredient(prefab=" + RuleLog.Shown(prefab) + ")");
			}
			if (!(prefab == "GP_Saltpeter") && !(prefab == "Coal"))
			{
				return prefab == "SulfurStone";
			}
			return true;
		}

		public static int GunpowderFrom(int saltpeter, int charcoal, int sulfur)
		{
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose("Prefabs.GunpowderFrom(saltpeter=" + RuleLog.Shown(saltpeter) + ", charcoal=" + RuleLog.Shown(charcoal) + ", sulfur=" + RuleLog.Shown(sulfur) + ")");
			}
			int num = GunpowderRules.Output(GunpowderRules.Batches(saltpeter, charcoal, sulfur, 3, 1, 1), 5);
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose($"Prefabs.GunpowderFrom: returns {num} (line 88)");
			}
			return num;
		}

		public static int SaltpeterFrom(int guano, int water)
		{
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose("Prefabs.SaltpeterFrom(guano=" + RuleLog.Shown(guano) + ", water=" + RuleLog.Shown(water) + ")");
			}
			int num = LeachingVatRules.Saltpeter(LeachingVatRules.Batches(guano, water, 10, 10), 5);
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose($"Prefabs.SaltpeterFrom: returns {num} (line 96)");
			}
			return num;
		}

		public static float RainBarrelWater(float current, float seconds, bool raining, bool covered)
		{
			//IL_0086: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose("Prefabs.RainBarrelWater(current=" + RuleLog.Shown(current) + ", seconds=" + RuleLog.Shown(seconds) + ", raining=" + RuleLog.Shown(raining) + ", covered=" + RuleLog.Shown(covered) + ")");
			}
			OperationResponse<float> val = RainBarrelRules.Fill(current, 200f, 5f, seconds, raining, covered);
			float num = (((int)val.Status == 0) ? val.Value : current);
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose($"Prefabs.RainBarrelWater: returns {num} (line 104)");
			}
			return num;
		}

		public static int GuanoDeposits(CaveKind kind, Func<double> next01)
		{
			if (RuleLog.IsOn())
			{
				RuleLog.Verbose("Musket.GuanoDeposits(kind=" + RuleLog.Shown(kind) + ", next01=" + RuleLog.Shown(next01) + ")");
			}
			return GuanoDepositRules.DepositCount(kind, next01);
		}
	}
}
namespace GunPowdered.Ui
{
	internal sealed class DetailGroup
	{
		internal readonly string Title;

		internal readonly List<DetailRow> Rows = new List<DetailRow>();

		internal DetailGroup(string title)
		{
			Title = title ?? "";
		}

		internal DetailRow Add(string label, string value, string maxValue = "")
		{
			DetailRow detailRow = new DetailRow(label, value, maxValue);
			Rows.Add(detailRow);
			return detailRow;
		}

		public override string ToString()
		{
			return Title + " (" + Rows.Count + " rows)";
		}
	}
	internal sealed class DetailRow
	{
		internal readonly string Label;

		internal readonly string Value;

		internal readonly string MaxValue;

		internal bool HasMax => MaxValue.Length > 0;

		internal DetailRow(string label, string value, string maxValue = "")
		{
			Label = label ?? "";
			Value = value ?? "";
			MaxValue = maxValue ?? "";
		}

		public override string ToString()
		{
			return Label + " = " + Value + (HasMax ? (" -> " + MaxValue) : "");
		}
	}
	internal static class DetailsView
	{
		private const float LabelWidth = 210f;

		private const float ValueWidth = 140f;

		internal static VisualElement Build(IList<DetailGroup> groups, string qualityHeader, string maxQualityHeader)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			VisualElement val = new VisualElement
			{
				name = "kydl-details"
			};
			val.style.flexShrink = StyleFloat.op_Implicit(0f);
			int num = 0;
			if (groups != null)
			{
				foreach (DetailGroup group in groups)
				{
					val.Add(UiControls.Heading(group.Title));
					bool flag = false;
					foreach (DetailRow row in group.Rows)
					{
						if (row.HasMax)
						{
							flag = true;
							break;
						}
					}
					if (flag)
					{
						val.Add(ColumnHeader(qualityHeader, maxQualityHeader));
					}
					foreach (DetailRow row2 in group.Rows)
					{
						val.Add(StatRow(row2, flag));
						num++;
					}
				}
			}
			UiLog.Verbose("DetailsView: " + (groups?.Count ?? 0) + " group(s), " + num + " row(s)");
			return val;
		}

		private static VisualElement ColumnHeader(string q, string max)
		{
			VisualElement obj = RowBox();
			obj.Add((VisualElement)(object)Cell("", 210f, (TextRole)5));
			obj.Add((VisualElement)(object)Cell(q ?? "", 140f, (TextRole)5));
			obj.Add((VisualElement)(object)Cell(max ?? "", 140f, (TextRole)5));
			return obj;
		}

		private static VisualElement StatRow(DetailRow row, bool blockHasMax)
		{
			VisualElement val = RowBox();
			val.Add((VisualElement)(object)Cell(row.Label, 210f, (TextRole)3));
			val.Add((VisualElement)(object)Cell(row.Value, (blockHasMax && row.HasMax) ? 140f : (-1f), (TextRole)0));
			if (blockHasMax && row.HasMax)
			{
				val.Add((VisualElement)(object)Cell(row.MaxValue, 140f, (TextRole)2));
			}
			return val;
		}

		private static VisualElement RowBox()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			VisualElement val = new VisualElement();
			val.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
			val.style.alignItems = StyleEnum<Align>.op_Implicit((Align)1);
			val.style.flexShrink = StyleFloat.op_Implicit(0f);
			val.style.marginTop = StyleLength.op_Implicit(2f);
			val.style.marginBottom = StyleLength.op_Implicit(2f);
			return val;
		}

		private static Label Cell(string content, float width, TextRole role)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			Label val = UiKit.TextLabel(content, role);
			((VisualElement)val).style.whiteSpace = StyleEnum<WhiteSpace>.op_Implicit((WhiteSpace)0);
			if (width >= 0f)
			{
				((VisualElement)val).style.width = StyleLength.op_Implicit(width);
				((VisualElement)val).style.flexShrink = StyleFloat.op_Implicit(0f);
			}
			else
			{
				((VisualElement)val).style.flexGrow = StyleFloat.op_Implicit(1f);
				((VisualElement)val).style.flexShrink = StyleFloat.op_Implicit(1f);
			}
			return val;
		}
	}
	internal sealed class ExamplePage
	{
		internal float Value { get; }

		internal float Min { get; }

		internal float Max { get; }

		internal Action<float> OnValue { get; }

		internal ExamplePage(float value, float min, float max, Action<float> onValue)
		{
			Value = value;
			Min = min;
			Max = max;
			OnValue = onValue ?? ((Action<float>)delegate
			{
			});
		}
	}
	internal static class ExampleTabView
	{
		internal static VisualElement Build(Func<string, string> text, ExamplePage page)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			VisualElement val = new VisualElement();
			val.Add(UiControls.Heading(text("gunpowdered_tab_example_section")));
			val.Add((VisualElement)(object)UiControls.Note(text("gunpowdered_tab_example_note")));
			val.Add(UiControls.Row(text("gunpowdered_tab_example_slider"), UiControls.Slider(page.Min, page.Max, page.Value, "0.0", (Action<float>)delegate(float v)
			{
				page.OnValue(v);
			})));
			UiLog.Verbose("ExampleTabView: built");
			return val;
		}
	}
	internal interface IModelScene : IDisposable
	{
		Texture Texture { get; }

		bool Show(string modelId);

		bool Resize(int widthPx, int heightPx);

		bool Render(float yawDeg, float pitchDeg, float zoom, float panX, float panY, float panZ);
	}
	internal sealed class ModelViewerRig : IModelScene, IDisposable
	{
		internal static readonly Vector3 Park = new Vector3(0f, -1500f, 0f);

		internal const float FieldOfView = 30f;

		private const float LogEverySeconds = 0.5f;

		private readonly Func<string, GameObject> _makeModel;

		private readonly ViewerSettings _settings;

		private readonly Action<string> _log;

		private readonly int _layer;

		private readonly string _rigName;

		private GameObject _root;

		private GameObject _pivot;

		private GameObject _model;

		private Camera _camera;

		private readonly List<Light> _lights = new List<Light>();

		private RenderTexture _texture;

		private string _modelId;

		private float _halfWidth;

		private float _halfHeight;

		private float _radius;

		private float _lastLog = -100f;

		private float _lastLightLog = -100f;

		private int _renders;

		public Texture Texture => (Texture)(object)_texture;

		internal unsafe ModelViewerRig(Func<string, GameObject> makeModel, int layer, ViewerSettings settings, Color background, Action<string> log, string rigName = "Kydl_ViewerRig")
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00b9: 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)
			//IL_00d3: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: 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_0261: 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)
			_makeModel = makeModel;
			_settings = settings ?? new ViewerSettings();
			_log = log;
			_layer = Mathf.Clamp(layer, 0, 31);
			_rigName = (string.IsNullOrEmpty(rigName) ? "Kydl_ViewerRig" : rigName);
			if (_layer != layer)
			{
				Log("ModelViewerRig: layer " + layer + " is outside 0..31, using " + _layer);
			}
			_root = new GameObject(_rigName);
			_root.transform.position = Park;
			_pivot = new GameObject("Pivot");
			_pivot.transform.SetParent(_root.transform, false);
			GameObject val = new GameObject("Camera");
			val.transform.SetParent(_root.transform, false);
			_camera = val.AddComponent<Camera>();
			((Behaviour)_camera).enabled = false;
			_camera.cullingMask = 1 << _layer;
			_camera.clearFlags = (CameraClearFlags)2;
			_camera.backgroundColor = background;
			_camera.fieldOfView = 30f;
			_camera.nearClipPlane = 0.02f;
			_camera.farClipPlane = 200f;
			_camera.allowHDR = false;
			_camera.useOcclusionCulling = false;
			_camera.renderingPath = (RenderingPath)1;
			AddLight(val.transform, "KeyLight", new Vector3(25f, 30f, 0f), _settings.KeyLight);
			AddLight(val.transform, "FillLight", new Vector3(-10f, -45f, 0f), _settings.FillLight);
			string[] obj = new string[10]
			{
				"ModelViewerRig: made at ",
				V(Park),
				", layer ",
				_layer.ToString(),
				", fov ",
				30f.ToString(),
				" deg, background ",
				null,
				null,
				null
			};
			Color val2 = background;
			obj[7] = ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj[8] = ", ";
			obj[9] = _settings?.ToString();
			Log(string.Concat(obj));
		}

		private void AddLight(Transform parent, string name, Vector3 euler, float intensity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localRotation = Quaternion.Euler(euler);
			Light val2 = val.AddComponent<Light>();
			val2.type = (LightType)1;
			val2.intensity = intensity;
			val2.color = new Color(1f, 0.96f, 0.9f);
			val2.shadows = (LightShadows)0;
			val2.cullingMask = 1 << _layer;
			val2.renderMode = (LightRenderMode)1;
			((Behaviour)val2).enabled = false;
			_lights.Add(val2);
		}

		public bool Show(string modelId)
		{
			//IL_011d: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: 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_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: 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_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root == (Object)null)
			{
				Log("ModelViewerRig: Show(" + modelId + ") after Dispose - ignored");
				return false;
			}
			if ((Object)(object)_model != (Object)null)
			{
				_model.SetActive(false);
				Object.Destroy((Object)(object)_model);
				_model = null;
			}
			_modelId = modelId;
			if (string.IsNullOrEmpty(modelId))
			{
				Log("ModelViewerRig: no model to show");
				return false;
			}
			GameObject val = null;
			Log("ModelViewerRig: making the model '" + modelId + "'");
			try
			{
				val = ((_makeModel != null) ? _makeModel(modelId) : null);
			}
			catch (Exception ex)
			{
				Log("ModelViewerRig: making the model '" + modelId + "' failed: " + ex.GetType().Name + ": " + ex.Message);
			}
			if ((Object)(object)val == (Object)null)
			{
				Log("ModelViewerRig: no model for '" + modelId + "' (model maker gave null)");
				return false;
			}
			_model = val;
			_pivot.transform.localRotation = Quaternion.identity;
			_model.transform.SetParent(_pivot.transform, false);
			_model.transform.localPosition = Vector3.zero;
			_model.transform.localRotation = Quaternion.identity;
			int num = Prepare(_model);
			if (num == 0)
			{
				Log("ModelViewerRig: model '" + modelId + "' has no renderers - nothing to see");
				return false;
			}
			Bounds val2 = WorldBounds(_model);
			Vector3 size = ((Bounds)(ref val2)).size;
			Quaternion localRotation = Quaternion.identity;
			string text = "X";
			if (size.y >= size.x && size.y >= size.z)
			{
				localRotation = Quaternion.Euler(0f, 0f, -90f);
				text = "Y";
			}
			else if (size.z >= size.x && size.z >= size.y)
			{
				localRotation = Quaternion.Euler(0f, 90f, 0f);
				text = "Z";
			}
			_model.transform.localRotation = localRotation;
			Bounds val3 = WorldBounds(_model);
			Transform transform = _model.transform;
			transform.position -= ((Bounds)(ref val3)).center - _pivot.transform.position;
			Bounds val4 = WorldBounds(_model);
			_halfWidth = ((Bounds)(ref val4)).extents.x;
			_halfHeight = Mathf.Max(((Bounds)(ref val4)).extents.y, ((Bounds)(ref val4)).extents.z);
			Vector3 extents = ((Bounds)(ref val4)).extents;
			_radius = ((Vector3)(ref extents)).magnitude;
			Log("ModelViewerRig: showing '" + modelId + "': " + num + " renderer(s), size " + V(((Bounds)(ref val2)).size) + " m, longest axis " + text + " laid across, centre offset " + V(((Bounds)(ref val4)).center - _pivot.transform.position) + " m, half width " + F(_halfWidth) + " / height " + F(_halfHeight) + " / radius " + F(_radius) + " m");
			return true;
		}

		private int Prepare(GameObject model)
		{
			int num = 0;
			int num2 = 0;
			Transform[] componentsInChildren = model.GetComponentsInChildren<Transform>(true);
			int i;
			for (i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = _layer;
			}
			Renderer[] componentsInChildren2 = model.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer obj in componentsInChildren2)
			{
				obj.shadowCastingMode = (ShadowCastingMode)0;
				obj.receiveShadows = false;
				SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((obj is SkinnedMeshRenderer) ? obj : null);
				if ((Object)(object)val != (Object)null)
				{
					val.updateWhenOffscreen = true;
				}
				num++;
			}
			Collider[] componentsInChildren3 = model.GetComponentsInChildren<Collider>(true);
			for (i = 0; i < componentsInChildren3.Length; i++)
			{
				componentsInChildren3[i].enabled = false;
				num2++;
			}
			string[] obj2 = new string[9]
			{
				"ModelViewerRig: prepared model '",
				((Object)model).name,
				"': ",
				num.ToString(),
				" renderer(s) on layer ",
				null,
				null,
				null,
				null
			};
			i = _layer;
			obj2[5] = i.ToString();
			obj2[6] = ", ";
			obj2[7] = num2.ToString();
			obj2[8] = " collider(s) off";
			Log(string.Concat(obj2));
			return num;
		}

		private static Bounds WorldBounds(GameObject go)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			if (componentsInChildren.Length == 0)
			{
				return new Bounds(go.transform.position, Vector3.zero);
			}
			Bounds bounds = componentsInChildren[0].bounds;
			for (int i = 1; i < componentsInChildren.Length; i++)
			{
				((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds);
			}
			return bounds;
		}

		public bool Resize(int widthPx, int heightPx)
		{
			//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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			if ((Object)(object)_root == (Object)null)
			{
				Log("ModelViewerRig: Resize after Dispose - ignored");
				return false;
			}
			int num = Mathf.Clamp(widthPx, 16, 4096);
			int num2 = Mathf.Clamp(heightPx, 16, 4096);
			if ((Object)(object)_texture != (Object)null && ((Texture)_texture).width == num && ((Texture)_texture).height == num2)
			{
				return true;
			}
			if ((Object)(object)_texture != (Object)null)
			{
				_camera.targetTexture = null;
				_texture.Release();
				Object.Destroy((Object)(object)_texture);
			}
			_texture = new RenderTexture(num, num2, 24, (RenderTextureFormat)0)
			{
				name = _rigName + "_Texture",
				antiAliasing = 4
			};
			_texture.Create();
			_camera.targetTexture = _texture;
			Log("ModelViewerRig: texture " + num + "x" + num2 + " px (asked " + widthPx + "x" + heightPx + ")");
			return true;
		}

		public bool Render(float yawDeg, float pitchDeg, float zoom, float panX, float panY, float panZ)
		{
			//IL_00b7: 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_00c2: 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_00e2: 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)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root == (Object)null || (Object)(object)_texture == (Object)null)
			{
				Log("ModelViewerRig: Render skipped (" + (((Object)(object)_root == (Object)null) ? "disposed" : "no texture yet") + ")");
				return false;
			}
			float num = (float)((Texture)_texture).width / (float)((Texture)_texture).height;
			float num2 = ViewerMath.FitDistance(_halfWidth, _halfHeight, _radius, 30f, num, _settings.Margin);
			float num3 = num2 / Mathf.Max(0.01f, zoom);
			float num4 = 2f * num2 * Mathf.Tan((float)Math.PI / 12f);
			Vector3 val = new Vector3(panX, panY, panZ) * num4;
			ViewerMath.Orbit(yawDeg, pitchDeg, num3, out var x, out var y, out var z);
			Vector3 val2 = _pivot.transform.position + val;
			((Component)_camera).transform.position = val2 + new Vector3(x, y, z);
			((Component)_camera).transform.LookAt(val2, Vector3.up);
			_camera.nearClipPlane = Mathf.Clamp(num3 - ((Vector3)(ref val)).magnitude - _radius * 1.2f, 0.01f, 0.5f);
			RenderLit();
			_renders++;
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (realtimeSinceStartup - _lastLog >= 0.5f)
			{
				_lastLog = realtimeSinceStartup;
				Log("ModelViewerRig: render #" + _renders + " of " + (_modelId ?? "nothing") + ": yaw " + F(yawDeg) + " / pitch " + F(pitchDeg) + " deg, zoom x" + F(zoom) + ", fit " + F(num2) + " m, distance " + F(num3) + " m, aspect " + F(num) + ", pan " + V(val) + " m (" + V(new Vector3(panX, panY, panZ)) + " view heights of " + F(num4) + " m), near " + F(_camera.nearClipPlane) + " m, model " + (((Object)(object)_model != (Object)null) ? "shown" : "none"));
			}
			return true;
		}

		private unsafe void RenderLit()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			AmbientMode ambientMode = RenderSettings.ambientMode;
			Color ambientLight = RenderSettings.ambientLight;
			float ambientIntensity = RenderSettings.ambientIntensity;
			bool fog = RenderSettings.fog;
			try
			{
				if (_lights.Count > 0 && (Object)(object)_lights[0] != (Object)null)
				{
					_lights[0].intensity = _settings.KeyLight;
				}
				if (_lights.Count > 1 && (Object)(object)_lights[1] != (Object)null)
				{
					_lights[1].intensity = _settings.FillLight;
				}
				for (int i = 0; i < _lights.Count; i++)
				{
					if ((Object)(object)_lights[i] != (Object)null)
					{
						((Behaviour)_lights[i]).enabled = true;
					}
				}
				RenderSettings.ambientMode = (AmbientMode)3;
				RenderSettings.ambientLight = new Color(_settings.Ambient, _settings.Ambient * 0.95f, _settings.Ambient * 0.9f);
				RenderSettings.ambientIntensity = 1f;
				RenderSettings.fog = false;
				_camera.Render();
			}
			finally
			{
				int num = 0;
				for (int j = 0; j < _lights.Count; j++)
				{
					if ((Object)(object)_lights[j] != (Object)null)
					{
						((Behaviour)_lights[j]).enabled = false;
						if (((Behaviour)_lights[j]).enabled)
						{
							num++;
						}
					}
				}
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				if (realtimeSinceStartup - _lastLightLog >= 2f)
				{
					_lastLightLog = realtimeSinceStartup;
					string[] obj = new string[12]
					{
						"ModelViewerRig: lights ",
						_lights.Count.ToString(),
						" switched on for this render only, ",
						num.ToString(),
						" still on after it (expect 0); ambient put back to ",
						((object)(*(AmbientMode*)(&ambientMode))/*cast due to .constrained prefix*/).ToString(),
						" / ",
						null,
						null,
						null,
						null,
						null
					};
					Color val = ambientLight;
					obj[7] = ((object)(*(Color*)(&val))/*cast due to .constrained prefix*/).ToString();
					obj[8] = " x";
					obj[9] = ambientIntensity.ToString();
					obj[10] = ", fog ";
					obj[11] = fog.ToString();
					Log(string.Concat(obj));
				}
				RenderSettings.ambientMode = ambientMode;
				RenderSettings.ambientLight = ambientLight;
				RenderSettings.ambientIntensity = ambientIntensity;
				RenderSettings.fog = fog;
			}
		}

		public void Dispose()
		{
			if (!((Object)(object)_root == (Object)null))
			{
				if ((Object)(object)_camera != (Object)null)
				{
					_camera.targetTexture = null;
				}
				if ((Object)(object)_texture != (Object)null)
				{
					_texture.Release();
					Object.Destroy((Object)(object)_texture);
					_texture = null;
				}
				Object.Destroy((Object)(object)_root);
				_root = null;
				_model = null;
				_camera = null;
				Log("ModelViewerRig: disposed after " + _renders + " render(s)");
			}
		}

		private static string F(float v)
		{
			return v.ToString("0.###", CultureInfo.InvariantCulture);
		}

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

		private void Log(string s)
		{
			if (_log != null)
			{
				_log(s);
			}
		}
	}
	internal static class ModelViewportView
	{
		private sealed class Viewport
		{
			private readonly IModelScene _scene;

			private readonly ViewerOrbit _orbit;

			private readonly Image _image;

			private readonly VisualElement _frame;

			private readonly string _modelId;

			private bool _dragging;

			private bool _panning;

			private int _dragButton = -1;

			private Vector2 _last;

			private int _pointer = -1;

			internal Viewport(string title, string modelId, IModelScene scene, ViewerSettings settings, VisualElement frame, string hint, string reset)
			{
				//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_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Expected O, but got Unknown
				//IL_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_012f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_018f: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01db: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e7: Expected O, but got Unknown
				//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_0203: Unknown result type (might be due to invalid IL or missing references)
				//IL_0218: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				Viewport viewport = this;
				_scene = scene;
				_frame = frame;
				_modelId = modelId;
				_orbit = new ViewerOrbit(settings, (Action<string>)UiLog.Verbose);
				_image = new Image
				{
					name = "kydl-viewport-image",
					scaleMode = (ScaleMode)0
				};
				((VisualElement)_image).style.position = StyleEnum<Position>.op_Implicit((Position)1);
				((VisualElement)_image).style.left = StyleLength.op_Implicit(0f);
				((VisualElement)_image).style.top = StyleLength.op_Implicit(0f);
				((VisualElement)_image).style.right = StyleLength.op_Implicit(0f);
				((VisualElement)_image).style.bottom = StyleLength.op_Implicit(0f);
				frame.Add((VisualElement)(object)_image);
				Label val = UiKit.TextLabel(title ?? "", (TextRole)6);
				((VisualElement)val).style.position = StyleEnum<Position>.op_Implicit((Position)1);
				((VisualElement)val).style.left = StyleLength.op_Implicit(10f);
				((VisualElement)val).style.top = StyleLength.op_Implicit(6f);
				((VisualElement)val).pickingMode = (PickingMode)1;
				frame.Add((VisualElement)(object)val);
				Label val2 = UiKit.TextLabel(hint ?? "", (TextRole)5);
				((VisualElement)val2).style.position = StyleEnum<Position>.op_Implicit((Position)1);
				((VisualElement)val2).style.left = StyleLength.op_Implicit(10f);
				((VisualElement)val2).style.bottom = StyleLength.op_Implicit(8f);
				((VisualElement)val2).pickingMode = (PickingMode)1;
				frame.Add((VisualElement)(object)val2);
				VisualElement val3 = new VisualElement
				{
					name = "kydl-viewport-buttons"
				};
				val3.style.position = StyleEnum<Position>.op_Implicit((Position)1);
				val3.style.right = StyleLength.op_Implicit(6f);
				val3.style.bottom = StyleLength.op_Implicit(4f);
				val3.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
				val3.Add((VisualElement)(object)UiControls.Button("+", (Action)delegate
				{
					viewport.Changed(viewport._orbit.StepZoom(1f), "zoom in button");
				}, false));
				val3.Add((VisualElement)(object)UiControls.Button("-", (Action)delegate
				{
					viewport.Changed(viewport._orbit.StepZoom(-1f), "zoom out button");
				}, false));
				val3.Add((VisualElement)(object)UiControls.Button(reset ?? "Reset", (Action)delegate
				{
					viewport.Changed(viewport._orbit.Reset(), "reset button");
				}, false));
				frame.Add(val3);
				((CallbackEventHandler)_image).RegisterCallback<PointerDownEvent>((EventCallback<PointerDownEvent>)OnDown, (TrickleDown)0);
				((CallbackEventHandler)_image).RegisterCallback<PointerMoveEvent>((EventCallback<PointerMoveEvent>)OnMove, (TrickleDown)0);
				((CallbackEventHandler)_image).RegisterCallback<PointerUpEvent>((EventCallback<PointerUpEvent>)OnUp, (TrickleDown)0);
				((CallbackEventHandler)_image).RegisterCallback<PointerCaptureOutEvent>((EventCallback<PointerCaptureOutEvent>)delegate
				{
					viewport.EndDrag("capture lost");
				}, (TrickleDown)0);
				((CallbackEventHandler)frame).RegisterCallback<WheelEvent>((EventCallback<WheelEvent>)OnWheel, (TrickleDown)0);
				((CallbackEventHandler)frame).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
				{
					viewport.OnResized(frame);
				}, (TrickleDown)0);
				((CallbackEventHandler)frame).RegisterCallback<DetachFromPanelEvent>((EventCallback<DetachFromPanelEvent>)delegate
				{
					viewport.Teardown();
				}, (TrickleDown)0);
				bool flag = _scene.Show(_modelId);
				_orbit.Reset();
				UiLog.Verbose("ModelViewportView: 3D viewport built for '" + _modelId + "', model " + (flag ? "shown" : "NOT shown (see the ModelViewerRig lines above)") + " (" + settings?.ToString() + ")");
			}

			private void OnDown(PointerDownEvent e)
			{
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: Unknown result type (might be due to invalid IL or missing references)
				if (((PointerEventBase<PointerDownEvent>)(object)e).button == 0 || ((PointerEventBase<PointerDownEvent>)(object)e).button == 1)
				{
					if (_dragging)
					{
						UiLog.Verbose("ModelViewportView: button " + ((PointerEventBase<PointerDownEvent>)(object)e).button + " pressed during a " + (_panning ? "pan" : "rotate") + " drag (button " + _dragButton + ") - ignored");
						return;
					}
					_dragging = true;
					_panning = ((PointerEventBase<PointerDownEvent>)(object)e).button == 1;
					_dragButton = ((PointerEventBase<PointerDownEvent>)(object)e).button;
					_pointer = ((PointerEventBase<PointerDownEvent>)(object)e).pointerId;
					_last = new Vector2(((PointerEventBase<PointerDownEvent>)(object)e).position.x, ((PointerEventBase<PointerDownEvent>)(object)e).position.y);
					PointerCaptureHelper.CapturePointer((IEventHandler)(object)_image, ((PointerEventBase<PointerDownEvent>)(object)e).pointerId);
					((EventBase)e).StopPropagation();
					UiLog.Verbose("ModelViewportView: " + (_panning ? "pan" : "rotate") + " drag started at " + P(_last) + " (button " + ((PointerEventBase<PointerDownEvent>)(object)e).button + ", pointer " + ((PointerEventBase<PointerDownEvent>)(object)e).pointerId + ", frame " + FrameHeightPx().ToString("0", CultureInfo.InvariantCulture) + " UI px high)");
				}
			}

			private void OnMove(PointerMoveEvent e)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: 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_007e: 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_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				if (!_dragging || ((PointerEventBase<PointerMoveEvent>)(object)e).pointerId != _pointer)
				{
					return;
				}
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(((PointerEventBase<PointerMoveEvent>)(object)e).position.x, ((PointerEventBase<PointerMoveEvent>)(object)e).position.y);
				Vector2 val2 = val - _last;
				_last = val;
				if (!(((Vector2)(ref val2)).sqrMagnitude <= 0f))
				{
					if (_panning ? _orbit.Pan(val2.x, val2.y, FrameHeightPx()) : _orbit.Drag(val2.x, val2.y))
					{
						Draw(null);
					}
					((EventBase)e).StopPropagation();
				}
			}

			private void OnUp(PointerUpEvent e)
			{
				if (((PointerEventBase<PointerUpEvent>)(object)e).button == _dragButton && ((PointerEventBase<PointerUpEvent>)(object)e).pointerId == _pointer)
				{
					if (PointerCaptureHelper.HasPointerCapture((IEventHandler)(object)_image, ((PointerEventBase<PointerUpEvent>)(object)e).pointerId))
					{
						PointerCaptureHelper.ReleasePointer((IEventHandler)(object)_image, ((PointerEventBase<PointerUpEvent>)(object)e).pointerId);
					}
					EndDrag("button " + ((PointerEventBase<PointerUpEvent>)(object)e).button + " released");
					((EventBase)e).StopPropagation();
				}
			}

			private void EndDrag(string why)
			{
				if (_dragging)
				{
					_dragging = false;
					_pointer = -1;
					UiLog.Verbose("ModelViewportView: " + (_panning ? "pan" : "rotate") + " drag ended (" + why + "), view " + _orbit);
					_panning = false;
					_dragButton = -1;
				}
			}

			private float FrameHeightPx()
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				Rect contentRect = _frame.contentRect;
				return ((Rect)(ref contentRect)).height;
			}

			private void OnWheel(WheelEvent e)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				Changed(_orbit.Wheel(e.delta.y), "wheel " + e.delta.y.ToString("0.##", CultureInfo.InvariantCulture));
				((EventBase)e).StopPropagation();
			}

			private void OnResized(VisualElement frame)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				Rect contentRect = frame.contentRect;
				float num = PixelsPerPoint();
				int num2 = Mathf.RoundToInt(((Rect)(ref contentRect)).width * num);
				int num3 = Mathf.RoundToInt(((Rect)(ref contentRect)).height * num);
				if (num2 < 16 || num3 < 16)
				{
					UiLog.Verbose("ModelViewportView: frame " + ((Rect)(ref contentRect)).width + "x" + ((Rect)(ref contentRect)).height + " UI px is too small (hidden tab?), no texture");
					return;
				}
				UiLog.Verbose("ModelViewportView: frame " + ((Rect)(ref contentRect)).width.ToString("0", CultureInfo.InvariantCulture) + "x" + ((Rect)(ref contentRect)).height.ToString("0", CultureInfo.InvariantCulture) + " UI px x " + num.ToString("0.###", CultureInfo.InvariantCulture) + " = " + num2 + "x" + num3 + " screen px");
				if (_scene.Resize(num2, num3))
				{
					_image.image = _scene.Texture;
				}
				Draw("resized");
			}

			private static float PixelsPerPoint()
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Invalid comparison between Unknown and I4
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				PanelSettings settings = UiKit.Settings;
				if (!((Object)(object)settings == (Object)null) && (int)settings.scaleMode == 2)
				{
					Vector2Int referenceResolution = settings.referenceResolution;
					if (((Vector2Int)(ref referenceResolution)).y > 0)
					{
						float num = (((Object)(object)settings.targetTexture != (Object)null) ? ((Texture)settings.targetTexture).height : Screen.height);
						referenceResolution = settings.referenceResolution;
						return Mathf.Clamp(num / (float)((Vector2Int)(ref referenceResolution)).y, 0.25f, 8f);
					}
				}
				return 1f;
			}

			private void Changed(bool changed, string why)
			{
				if (changed)
				{
					Draw(why);
					return;
				}
				UiLog.Verbose("ModelViewportView: " + why + " - view unchanged (" + _orbit?.ToString() + ")");
			}

			private void Draw(string why)
			{
				bool flag = _scene.Render(_orbit.Yaw, _orbit.Pitch, _orbit.Zoom, _orbit.PanX, _orbit.PanY, _orbit.PanZ);
				((VisualElement)_image).MarkDirtyRepaint();
				if (why != null)
				{
					UiLog.Verbose("ModelViewportView: drawn after " + why + " (" + _orbit?.ToString() + ")" + (flag ? "" : " - scene did not render"));
				}
			}

			private void Teardown()
			{
				_image.image = null;
				_scene.Dispose();
				UiLog.Verbose("ModelViewportView: viewport closed, 3D scene of '" + _modelId + "' disposed");
			}

			private static string P(Vector2 v)
			{
				return "(" + v.x.ToString("0", CultureInfo.InvariantCulture) + ", " + v.y.ToString("0", CultureInfo.InvariantCulture) + ")";
			}
		}

		internal static VisualElement Build(string title, string modelId, Func<IModelScene> makeScene, ViewerSettings settings, string hint, string reset, string unavailable)
		{
			//IL_002e: 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_003f: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			settings = settings ?? new ViewerSettings();
			settings.Clamp((Action<string>)UiLog.Verbose);
			VisualElement val = new VisualElement
			{
				name = "kydl-viewport"
			};
			val.style.flexShrink = StyleFloat.op_Implicit(0f);
			val.style.height = StyleLength.op_Implicit(settings.FrameHeight);
			val.style.marginTop = StyleLength.op_Implicit(10f);
			val.style.backgroundColor = StyleColor.op_Implicit(UiKit.Track);
			UiKit.Borders(val, 1f, UiKit.Border);
			UiKit.Radius(val, 4f);
			val.style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)1);
			IModelScene modelScene = null;
			try
			{
				modelScene = makeScene?.Invoke();
			}
			catch (Exception ex)
			{
				UiLog.Error("ModelViewportView: making the 3D scene failed: " + ex.GetType().Name + ": " + ex.Message);
			}
			if (modelScene == null)
			{
				val.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
				val.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
				val.Add((VisualElement)(object)UiKit.TextLabel(title ?? "", (TextRole)7));
				val.Add((VisualElement)(object)UiKit.TextLabel(unavailable ?? "", (TextRole)3));
				UiLog.Verbose("ModelViewportView: no 3D scene, showing the title '" + title + "' only");
				return val;
			}
			new Viewport(title, modelId, modelScene, settings, val, hint, reset);
			return val;
		}
	}
	internal sealed class TabBar
	{
		private const float RailMargin = 18f;

		private readonly List<Button> _buttons = new List<Button>();

		private readonly Action<int> _changed;

		private int _selected = -1;

		internal VisualElement Root { get; private set; }

		internal int Selected => _selected;

		internal TabBar(IList<string> names, int selected, Action<int> changed)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_00a9: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_0121: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			_changed = changed;
			Root = new VisualElement
			{
				name = "kydl-tabs"
			};
			Root.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
			Root.style.flexShrink = StyleFloat.op_Implicit(0f);
			Root.style.marginLeft = StyleLength.op_Implicit(18f);
			Root.style.marginRight = StyleLength.op_Implicit(18f);
			Root.style.marginTop = StyleLength.op_Implicit(8f);
			Root.style.borderBottomWidth = StyleFloat.op_Implicit(1f);
			Root.style.borderBottomColor = StyleColor.op_Implicit(UiKit.Border);
			for (int i = 0; i < names.Count; i++)
			{
				int index = i;
				Button val = new Button((Action)delegate
				{
					Select(index);
				})
				{
					text = names[i]
				};
				((VisualElement)val).style.flexShrink = StyleFloat.op_Implicit(0f);
				((VisualElement)val).style.marginLeft = StyleLength.op_Implicit(0f);
				((VisualElement)val).style.marginRight = StyleLength.op_Implicit(4f);
				((VisualElement)val).style.marginTop = StyleLength.op_Implicit(0f);
				((VisualElement)val).style.marginBottom = StyleLength.op_Implicit(0f);
				UiKit.Pad((VisualElement)(object)val, 8f, 22f);
				((VisualElement)val).style.borderTopWidth = StyleFloat.op_Implicit(0f);
				((VisualElement)val).style.borderLeftWidth = StyleFloat.op_Implicit(0f);
				((VisualElement)val).style.borderRightWidth = StyleFloat.op_Implicit(0f);
				((VisualElement)val).style.borderBottomWidth = StyleFloat.op_Implicit(3f);
				UiKit.Radius((VisualElement)(object)val, 0f);
				UiKit.Fade((VisualElement)(object)val, new string[2] { "background-color", "color" });
				((CallbackEventHandler)val).RegisterCallback<PointerEnterEvent>((EventCallback<PointerEnterEvent>)delegate
				{
					Paint(index, hover: true);
				}, (TrickleDown)0);
				((CallbackEventHandler)val).RegisterCallback<PointerLeaveEvent>((EventCallback<PointerLeaveEvent>)delegate
				{
					Paint(index, hover: false);
				}, (TrickleDown)0);
				_buttons.Add(val);
				Root.Add((VisualElement)(object)val);
			}
			Show(Mathf.Clamp(selected, 0, Math.Max(0, names.Count - 1)));
			UiLog.Verbose("TabBar: built with " + names.Count + " tab(s) [" + string.Join(", ", names) + "], selected " + _selected);
		}

		internal bool Select(int index)
		{
			if (index < 0 || index >= _buttons.Count)
			{
				UiLog.Verbose("TabBar: tab " + index + " does not exist (" + _buttons.Count + " tabs), selection stays " + _selected);
				return _selected == index;
			}
			if (index == _selected)
			{
				return _selected == index;
			}
			UiLog.Verbose("TabBar: tab " + _selected + " -> " + index + " ('" + ((TextElement)_buttons[index]).text + "')");
			Show(index);
			if (_changed != null)
			{
				_changed(index);
			}
			return _selected == index;
		}

		private void Show(int index)
		{
			_selected = index;
			for (int i = 0; i < _buttons.Count; i++)
			{
				Paint(i, hover: false);
			}
		}

		private void Paint(int index, bool hover)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			Button obj = _buttons[index];
			bool flag = index == _selected;
			((VisualElement)obj).style.backgroundColor = StyleColor.op_Implicit(flag ? UiKit.PanelLight : (hover ? UiKit.PanelHover : Color.clear));
			UiKit.TabText((VisualElement)(object)obj, flag, hover);
			((VisualElement)obj).style.borderBottomColor = StyleColor.op_Implicit(flag ? UiKit.Gold : Color.clear);
		}
	}
	internal static class UiText
	{
		internal static readonly Dictionary<string, string> En = new Dictionary<string, string>
		{
			{ "gunpowdered_menu_title", "GunPowdered" },
			{ "gunpowdered_menu_footer", "Esc to close" },
			{ "gunpowdered_tab_example", "Example" },
			{ "gunpowdered_tab_settings", "Settings" },
			{ "gunpowdered_tab_example_section", "Example" },
			{ "gunpowdered_tab_example_note", "This is the starting tab of the mod in the KY hub (F6). Replace its content in ExampleTabView." },
			{ "gunpowdered_tab_example_slider", "Example value" }
		};

		internal static string English(string key)
		{
			if (!En.TryGetValue(key, out var value))
			{
				return key;
			}
			return value;
		}
	}
	internal static class ViewerMath
	{
		private const double Rad = Math.PI / 180.0;

		internal const float MinDistanceRadii = 1.5f;

		internal static float FitDistance(float halfWidth, float halfHeight, float radius, float verticalFovDeg, float aspect, float margin)
		{
			if (!(verticalFovDeg > 1f) || !(verticalFovDeg < 179f))
			{
				verticalFovDeg = 30f;
			}
			if (!(aspect > 0.01f) || float.IsInfinity(aspect))
			{
				aspect = 1f;
			}
			if (!(margin >= 0f) || float.IsInfinity(margin))
			{
				margin = 0f;
			}
			if (!(radius > 0f) || float.IsInfinity(radius))
			{
				radius = 0.5f;
			}
			halfWidth = ((halfWidth > 0f && !float.IsInfinity(halfWidth)) ? halfWidth : radius);
			halfHeight = ((halfHeight > 0f && !float.IsInfinity(halfHeight)) ? halfHeight : radius);
			double num = Math.Tan((double)verticalFovDeg * 0.5 * (Math.PI / 180.0));
			double num2 = num * (double)aspect;
			double num3 = 1.0 + (double)margin;
			double val = (double)halfWidth * num3 / num2;
			double val2 = (double)halfHeight * num3 / num;
			return (float)Math.Max(radius * 1.5f, Math.Max(val, val2));
		}

		internal static float ClampPitch(float pitch, float limit)
		{
			limit = Math.Max(0f, Math.Min(89f, float.IsNaN(limit) ? 0f : limit));
			if (float.IsNaN(pitch))
			{
				return 0f;
			}
			return Math.Max(0f - limit, Math.Min(limit, pitch));
		}

		internal static float WrapYaw(float yaw)
		{
			if (float.IsNaN(yaw) || float.IsInfinity(yaw))
			{
				return 0f;
			}
			double num = (double)yaw % 360.0;
			if (num > 180.0)
			{
				num -= 360.0;
			}
			if (num <= -180.0)
			{
				num += 360.0;
			}
			return (float)num;
		}

		internal static float StepZoom(float zoom, float steps, float factor, float min, float max)
		{
			if (!(min > 0f))
			{
				min = 0.01f;
			}
			if (max < min)
			{
				max = min;
			}
			if (!(factor > 1f))
			{
				factor = 1f;
			}
			if (!(zoom > 0f) || float.IsInfinity(zoom))
			{
				zoom = 1f;
			}
			double val = (double)zoom * Math.Pow(factor, float.IsNaN(steps) ? 0f : steps);
			return (float)Math.Max(min, Math.Min(max, val));
		}

		internal static void Orbit(float yawDeg, float pitchDeg, float distance, out float x, out float y, out float z)
		{
			double num = (double)yawDeg * (Math.PI / 180.0);
			double num2 = (double)pitchDeg * (Math.PI / 180.0);
			double num3 = (double)distance * Math.Cos(num2);
			x = (float)((0.0 - num3) * Math.Sin(num));
			y = (float)((double)distance * Math.Sin(num2));
			z = (float)((0.0 - num3) * Math.Cos(num));
		}

		internal static void CameraAxes(float yawDeg, float pitchDeg, out float rx, out float ry, out float rz, out float ux, out float uy, out float uz)
		{
			double num = (double)yawDeg * (Math.PI / 180.0);
			double num2 = (double)pitchDeg * (Math.PI / 180.0);
			double num3 = Math.Sin(num);
			double num4 = Math.Cos(num);
			double num5 = Math.Sin(num2);
			double num6 = Math.Cos(num2);
			rx = (float)num4;
			ry = 0f;
			rz = (float)(0.0 - num3);
			ux = (float)(num5 * num3);
			uy = (float)num6;
			uz = (float)(num5 * num4);
		}

		internal static bool ClampLength(ref float x, ref float y, ref float z, float limit)
		{
			if (float.IsNaN(x) || float.IsNaN(y) || float.IsNaN(z))
			{
				x = 0f;
				y = 0f;
				z = 0f;
				return true;
			}
			limit = (float.IsNaN(limit) ? 0f : Math.Max(0f, limit));
			double num = Math.Sqrt((double)x * (double)x + (double)y * (double)y + (double)z * (double)z);
			if (num <= (double)limit)
			{
				return false;
			}
			double num2 = ((num > 0.0) ? ((double)limit / num) : 0.0);
			x = (float)((double)x * num2);
			y = (float)((double)y * num2);
			z = (float)((double)z * num2);
			return true;
		}
	}
	internal sealed class ViewerOrbit
	{
		private readonly ViewerSettings _settings;

		private const float Tiny = 1E-06f;

		private readonly Action<string> _log;

		internal float Yaw { get; private set; }

		internal float Pitch { get; private set; }

		internal float Zoom { get; private set; }

		internal float PanX { get; private set; }

		internal float PanY { get; private set; }

		internal float PanZ { get; private set; }

		private static bool Differs(float a, float b)
		{
			return !(Math.Abs(a - b) <= 1E-06f);
		}

		internal ViewerOrbit(ViewerSettings settings, Action<string> log = null)
		{
			_settings = settings ?? new ViewerSettings();
			_log = log;
			Reset();
		}

		internal bool Reset()
		{
			float num = ViewerMath.WrapYaw(_settings.StartYaw);
			float num2 = ViewerMath.ClampPitch(_settings.StartPitch, _settings.PitchLimit);
			bool flag = PanX != 0f || PanY != 0f || PanZ != 0f;
			bool flag2 = Differs(num, Yaw) || Differs(num2, Pitch) || Differs(Zoom, 1f) || flag;
			Yaw = num;
			Pitch = num2;
			Zoom = 1f;
			PanX = 0f;
			PanY = 0f;
			PanZ = 0f;
			Log("ViewerOrbit: reset to " + this?.ToString() + (flag2 ? "" : " (already there)"));
			return flag2;
		}

		internal bool Pan(float dx, float dy, float frameHeightPx)
		{
			if (float.IsNaN(dx) || float.IsNaN(dy))
			{
				Log("ViewerOrbit: pan with NaN ignored");
				return false;
			}
			if (!(frameHeightPx >= 1f) || float.IsInfinity(frameHeightPx))
			{
				Log("ViewerOrbit: pan ignored, frame height " + F(frameHeightPx) + " px is not usable");
				return false;
			}
			float num = _settings.PanSpeed / (frameHeightPx * Math.Max(0.01f, Zoom));
			ViewerMath.CameraAxes(Yaw, Pitch, out var rx, out var ry, out var rz, out var ux, out var uy, out var uz);
			float x = PanX + ((0f - rx) * dx + ux * dy) * num;
			float y = PanY + ((0f - ry) * dx + uy * dy) * num;
			float z = PanZ + ((0f - rz) * dx + uz * dy) * num;
			bool flag = ViewerMath.ClampLength(ref x, ref y, ref z, _settings.PanLimit);
			int num2;
			if (!(Math.Abs(x - PanX) > 1E-06f) && !(Math.Abs(y - PanY) > 1E-06f))
			{
				num2 = ((Math.Abs(z - PanZ) > 1E-06f) ? 1 : 0);
				if (num2 == 0)
				{
					if (flag)
					{
						Log("ViewerOrbit: pan at the limit (" + F(_settings.PanLimit) + " view heights), view " + this);
					}
					return (byte)num2 != 0;
				}
			}
			else
			{
				num2 = 1;
			}
			PanX = x;
			PanY = y;
			PanZ = z;
			return (byte)num2 != 0;
		}

		internal bool Drag(float dx, float dy)
		{
			if (float.IsNaN(dx) || float.IsNaN(dy))
			{
				Log("ViewerOrbit: drag with NaN ignored");
				return false;
			}
			float num = ViewerMath.WrapYaw(Yaw - dx * _settings.RotateSpeed);
			float num2 = ViewerMath.ClampPitch(Pitch + dy * _settings.RotateSpeed, _settings.PitchLimit);
			bool result = Differs(num, Yaw) || Differs(num2, Pitch);
			Yaw = num;
			Pitch = num2;
			return result;
		}

		internal bool StepZoom(float steps)
		{
			float num = ViewerMath.StepZoom(Zoom, steps, _settings.ZoomStep, _settings.ZoomMin, _settings.ZoomMax);
			bool flag = Differs(num, Zoom);
			Log("ViewerOrbit: zoom " + F(Zoom) + " -> " + F(num) + " (" + F(steps) + " step(s), range " + F(_settings.ZoomMin) + ".." + F(_settings.ZoomMax) + ")" + (flag ? "" : " - at the limit"));
			Zoom = num;
			return flag;
		}

		internal bool Wheel(float deltaY)
		{
			if (deltaY == 0f || float.IsNaN(deltaY))
			{
				return false;
			}
			return StepZoom((deltaY > 0f) ? (-1f) : 1f);
		}

		private static string F(float v)
		{
			return v.ToString("0.##", CultureInfo.InvariantCulture);
		}

		public override string ToString()
		{
			return "yaw " + F(Yaw) + " deg, pitch " + F(Pitch) + " deg, zoom x" + F(Zoom) + ", pan (" + F(PanX) + ", " + F(PanY) + ", " + F(PanZ) + ") view heights";
		}

		private void Log(string s)
		{
			if (_log != null)
			{
				_log(s);
			}
		}
	}
	internal sealed class ViewerSettings
	{
		internal const float RotateSpeedMin = 0.05f;

		internal const float RotateSpeedMax = 2f;

		internal const float RotateSpeedDefault = 0.4f;

		internal const float ZoomStepMin = 1.02f;

		internal const float ZoomStepMax = 2f;

		internal const float ZoomStepDefault = 1.2f;

		internal const float ZoomMaxMin = 1f;

		internal const float ZoomMaxMax = 20f;

		internal const float ZoomMaxDefault = 8f;

		internal const float ZoomMinMin = 0.2f;

		internal const float ZoomMinMax = 1f;

		internal const float ZoomMinDefault = 0.5f;

		internal const float PitchLimitMin = 0f;

		internal const float PitchLimitMax = 89f;

		internal const float PitchLimitDefault = 80f;

		internal const float FrameHeightMin = 200f;

		internal const float FrameHeightMax = 800f;

		internal const float FrameHeightDefault = 420f;

		internal const float MarginMin = 0f;

		internal const float MarginMax = 0.5f;

		internal const float MarginDefault = 0.08f;

		internal const float StartYawMin = -180f;

		internal const float StartYawMax = 180f;

		internal const float StartYawDefault = 20f;

		internal const float StartPitchMin = -89f;

		internal const float StartPitchMax = 89f;

		internal const float StartPitchDefault = 12f;

		internal const float PanSpeedMin = 0.2f;

		internal const float PanSpeedMax = 3f;

		internal const float PanSpeedDefault = 1f;

		internal const float PanLimitMin = 0f;

		internal const float PanLimitMax = 3f;

		internal const float PanLimitDefault = 0.8f;

		internal const float KeyLightMin = 0f;

		internal const float KeyLightMax = 2f;

		internal const float KeyLightDefault = 0.7f;

		internal const float FillLightMin = 0f;

		internal const float FillLightMax = 1.5f;

		internal const float FillLightDefault = 0.25f;

		internal const float AmbientMin = 0f;

		internal const float AmbientMax = 1f;

		internal const float AmbientDefault = 0.22f;

		internal float RotateSpeed = 0.4f;

		internal float ZoomStep = 1.2f;

		internal float ZoomMax = 8f;

		internal float ZoomMin = 0.5f;

		internal float PitchLimit = 80f;

		internal float FrameHeight = 420f;

		internal float Margin = 0.08f;

		internal float StartYaw = 20f;

		internal float StartPitch = 12f;

		internal float PanSpeed = 1f;

		internal float PanLimit = 0.8f;

		internal float KeyLight = 0.7f;

		internal float FillLight = 0.25f;

		internal float Ambient = 0.22f;

		internal int Clamp(Action<string> log = null)
		{
			int changed = 0;
			RotateSpeed = Fix("RotateSpeed", RotateSpeed, 0.05f, 2f, 0.4f, ref changed, log);
			ZoomStep = Fix("ZoomStep", ZoomStep, 1.02f, 2f, 1.2f, ref changed, log);
			ZoomMax = Fix("ZoomMax", ZoomMax, 1f, 20f, 8f, ref changed, log);
			ZoomMin = Fix("ZoomMin", ZoomMin, 0.2f, 1f, 0.5f, ref changed, log);
			PitchLimit = Fix("PitchLimit", PitchLimit, 0f, 89f, 80f, ref changed, log);
			FrameHeight = Fix("FrameHeight", FrameHeight, 200f, 800f, 420f, ref changed, log);
			Margin = Fix("Margin", Margin, 0f, 0.5f, 0.08f, ref changed, log);
			StartYaw = Fix("StartYaw", StartYaw, -180f, 180f, 20f, ref changed, log);
			StartPitch = Fix("StartPitch", StartPitch, -89f, 89f, 12f, ref changed, log);
			PanSpeed = Fix("PanSpeed", PanSpeed, 0.2f, 3f, 1f, ref changed, log);
			PanLimit = Fix("PanLimit", PanLimit, 0f, 3f, 0.8f, ref changed, log);
			KeyLight = Fix("KeyLight", KeyLight, 0f, 2f, 0.7f, ref changed, log);
			FillLight = Fix("FillLight", FillLight, 0f, 1.5f, 0.25f, ref changed, log);
			Ambient = Fix("Ambient", Ambient, 0f, 1f, 0.22f, ref changed, log);
			if (StartPitch > PitchLimit || StartPitch < 0f - PitchLimit)
			{
				float startPitch = StartPitch;
				StartPitch = Math.Max(0f - PitchLimit, Math.Min(PitchLimit, StartPitch));
				changed++;
				log?.Invoke("ViewerSettings: StartPitch " + F(startPitch) + " is outside PitchLimit " + F(PitchLimit) + ", using " + F(StartPitch));
			}
			log?.Invoke("ViewerSettings: " + this?.ToString() + " (" + changed + " value(s) put into range)");
			return changed;
		}

		private static float Fix(string name, float v, float min, float max, float def, ref int changed, Action<string> log)
		{
			float num = ((float.IsNaN(v) || float.IsInfinity(v)) ? def : Math.Max(min, Math.Min(max, v)));
			if (!(Math.Abs(num - v) <= 1E-06f))
			{
				changed++;
				log?.Invoke("ViewerSettings: " + name + " " + F(v) + " is outside " + F(min) + ".." + F(max) + ", using " + F(num));
			}
			return num;
		}

		private static string F(float v)
		{
			return v.ToString("0.###", CultureInfo.InvariantCulture);
		}

		public override string ToString()
		{
			return "rotate " + F(RotateSpeed) + " deg/px, zoom step x" + F(ZoomStep) + ", zoom " + F(ZoomMin) + ".." + F(ZoomMax) + ", pitch limit " + F(PitchLimit) + " deg, frame " + F(FrameHeight) + " px, margin " + F(Margin) + ", start yaw " + F(StartYaw) + " / pitch " + F(StartPitch) + " deg, pan speed x" + F(PanSpeed) + ", pan limit " + F(PanLimit) + " view heights, light key " + F(KeyLight) + " / fill " + F(FillLight) + " / ambient " + F(Ambient);
		}
	}
}
namespace GunPowdered.Testing
{
	internal static class InGameTests
	{
		private static string Startup_ConfigBound()
		{
			if (RuleLog.IsOn())
			{
				ModLog.Verbose("InGameTests.Startup_ConfigBound()");
			}
			if (ModSettings.EnableMod == null)
			{
				return "FAIL: ModSettings.Bind did not run (EnableMod is null)";
			}
			string text = (ModSettings.On ? "PASS: EnableMod on" : "SKIP: EnableMod is off in the config");
			if (RuleLog.IsOn())
			{
				ModLog.Verbose("InGameTests.Startup_ConfigBound: returns " + text + " (line 23)");
			}
			return text;
		}

		private static string Startup_FeaturesInstalled()
		{
			ModInstaller current = ModInstaller.Current;
			if (current == null)
			{
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("InGameTests.Startup_FeaturesInstalled: returns \"FAIL: ModInstaller.Install did not run\" because inst == null (line 30)");
				}
				return "FAIL: ModInstaller.Install did not run";
			}
			int num = 0;
			foreach (IFeature item in current.Features.All)
			{
				if (current.Features.IsRunning(item.Id))
				{
					num++;
				}
			}
			ModLog.Verbose("InGameTests: Startup_FeaturesInstalled " + current.Features.Count + " feature(s), " + num + " running");
			if (current.Features.Count <= 0)
			{
				return "FAIL: no feature registered";
			}
			return "PASS: " + current.Features.Count + " feature(s), " + num + " running";
		}

		private static string Startup_CoreLoaded()
		{
			bool flag = Chainloader.PluginInfos.ContainsKey("com.kydldev.KydlCore");
			ModLog.Verbose("InGameTests: Startup_CoreLoaded " + flag);
			if (!flag)
			{
				return "FAIL: com.kydldev.KydlCore is not loaded (this mod requires it)";
			}
			return "PASS: com.kydldev.KydlCore is loaded";
		}

		private static string Startup_BundleLoaded()
		{
			AssetBundle bundle = Plugin.Bundle;
			if ((Object)(object)bundle == (Object)null)
			{
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("InGameTests.Startup_BundleLoaded: returns \"FAIL: Plugin.Bundle is null, the mod runs on placeholder looks\" because b == null (line 49)");
				}
				return "FAIL: Plugin.Bundle is null, the mod runs on placeholder looks";
			}
			int num = bundle.GetAllAssetNames().Length;
			ModLog.Verbose("InGameTests: Startup_BundleLoaded " + num + " assets");
			if (num < 22)
			{
				return "FAIL: bundle has " + num + " assets, expected at least 22 (11 prefabs + 11 icons)";
			}
			return "PASS: bundle has " + num + " assets";
		}

		private static string World_BundleModels()
		{
			StringBuilder stringBuilder = new StringBuilder();
			int num = 0;
			foreach (ItemSpec item in ItemCatalog.All)
			{
				GameObject val = KyPrefabs.Get(item.Id);
				if ((Object)(object)val == (Object)null)
				{
					stringBuilder.Append(item.Id).Append(" missing; ");
					if (RuleLog.IsOn())
					{
						ModLog.Verbose("InGameTests.World_BundleModels: skips to the next item (continue) because go == null (line 63)");
					}
					continue;
				}
				Transform val2 = WorldModel(val.transform);
				if ((Object)(object)val2 == (Object)null)
				{
					stringBuilder.Append(item.Id).Append(" no gp_model; ");
					if (RuleLog.IsOn())
					{
						ModLog.Verbose("InGameTests.World_BundleModels: skips to the next item (continue) because model == null (line 65)");
					}
					continue;
				}
				Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>(true);
				if (componentsInChildren.Length == 0)
				{
					stringBuilder.Append(item.Id).Append(" no renderer; ");
					if (RuleLog.IsOn())
					{
						ModLog.Verbose("InGameTests.World_BundleModels: skips to the next item (continue) because rends.Length == 0 (line 67)");
					}
					continue;
				}
				Renderer[] array = componentsInChildren;
				foreach (Renderer val3 in array)
				{
					Material[] sharedMaterials = val3.sharedMaterials;
					foreach (Material val4 in sharedMaterials)
					{
						if ((Object)(object)val4 == (Object)null || (Object)(object)val4.shader == (Object)null || ((Object)val4.shader).name.Contains("InternalErrorShader"))
						{
							stringBuilder.Append(item.Id).Append("/").Append(((Object)val3).name)
								.Append(" bad shader; ");
						}
					}
				}
				MeshFilter[] componentsInChildren2 = ((Component)val2).GetComponentsInChildren<MeshFilter>(true);
				foreach (MeshFilter val5 in componentsInChildren2)
				{
					if ((Object)(object)val5.sharedMesh != (Object)null && !val5.sharedMesh.isReadable)
					{
						stringBuilder.Append(item.Id).Append("/").Append(((Object)val5).name)
							.Append(" mesh not readable; ");
					}
				}
				ItemDrop component = val.GetComponent<ItemDrop>();
				if ((Object)(object)component != (Object)null && (component.m_itemData.m_shared.m_icons == null || component.m_itemData.m_shared.m_icons.Length == 0 || (Object)(object)component.m_itemData.m_shared.m_icons[0] == (Object)null))
				{
					stringBuilder.Append(item.Id).Append(" no icon; ");
				}
				num++;
			}
			ModLog.Verbose("InGameTests: World_BundleModels " + num + " of " + ItemCatalog.All.Count + " ok");
			if (stringBuilder.Length != 0)
			{
				return "FAIL: " + stringBuilder;
			}
			return "PASS: " + num + " prefabs use the bundle model";
		}

		private static Transform WorldModel(Transform root)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			Transform val = root.Find("gp_model");
			if ((Object)(object)val != (Object)null)
			{
				Transform val2 = val;
				if (RuleLog.IsOn())
				{
					ModLog.Verbose($"InGameTests.WorldModel: returns {val2} because direct != null (line 87)");
				}
				return val2;
			}
			foreach (Transform item in root)
			{
				Transform val3 = item;
				if (((Object)val3).name == "attach")
				{
					if (RuleLog.IsOn())
					{
						ModLog.Verbose("InGameTests.WorldModel: skips to the next item (continue) because child.name == \"attach\" (line 90)");
					}
					continue;
				}
				Transform val4 = val3.Find("gp_model");
				if (!((Object)(object)val4 != (Object)null))
				{
					continue;
				}
				ModLog.Verbose("InGameTests: " + ((Object)root).name + " carries its model under " + ((Object)val3).name);
				return val4;
			}
			if (RuleLog.IsOn())
			{
				ModLog.Verbose("InGameTests.WorldModel: returns null (line 98)");
			}
			return null;
		}

		private static string World_ApiPrefabs()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (string allPrefab in GunPowderedApi.AllPrefabs)
			{
				if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ZNetScene.instance.GetPrefab(allPrefab) == (Object)null)
				{
					stringBuilder.Append(allPrefab).Append(' ');
				}
			}
			int count = GunPowderedApi.AllPrefabs.Count;
			ModLog.Verbose("InGameTests: World_ApiPrefabs " + count + " names, missing: " + ((stringBuilder.Length == 0) ? "none" : stringBuilder.ToString()));
			if (stringBuilder.Length != 0)
			{
				return "FAIL: not registered: " + stringBuilder;
			}
			return "PASS: all " + count + " API prefab names exist (API version " + 1 + ")";
		}

		private static string World_PowderMillAutomatic()
		{
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("GP_PowderMill") : null);
			if ((Object)(object)val == (Object)null)
			{
				ModLog.Verbose("InGameTests: World_PowderMillAutomatic prefab missing");
				return "FAIL: GP_PowderMill is not registered";
			}
			bool flag = (Object)(object)val.GetComponent<PowderMill>() != (Object)null;
			bool flag2 = (Object)(object)val.GetComponent<PowderMillSpin>() != (Object)null;
			bool flag3 = (Object)(object)val.GetComponent<CraftingStation>() != (Object)null;
			ModLog.Verbose($"InGameTests: World_PowderMillAutomatic mill {flag}, arm {flag2}, crafting station {flag3}");
			if (!flag || !flag2)
			{
				return $"FAIL: the Powder Mill lacks its automatic parts (mill {flag}, arm {flag2})";
			}
			string text = (flag3 ? "FAIL: the Powder Mill still has a crafting station" : "PASS: the Powder Mill grinds by itself (no crafting station)");
			if (RuleLog.IsOn())
			{
				ModLog.Verbose("InGameTests.World_PowderMillAutomatic: returns " + text + " (line 123)");
			}
			return text;
		}

		private static string World_GrenadeReady()
		{
			ZNetScene instance = ZNetScene.instance;
			GameObject val = (((Object)(object)instance != (Object)null) ? instance.GetPrefab("GP_SpikedGrenade") : null);
			GameObject val2 = (((Object)(object)instance != (Object)null) ? instance.GetPrefab("GP_SpikedGrenade_projectile") : null);
			GameObject val3 = (((Object)(object)instance != (Object)null) ? instance.GetPrefab("GP_SpikedGrenade_explosion") : null);
			Attack val4 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>().m_itemData.m_shared.m_attack : null);
			Aoe val5 = (((Object)(object)val3 != (Object)null) ? val3.GetComponent<Aoe>() : null);
			Transform val6 = (((Object)(object)val != (Object)null) ? val.transform.Find("attach") : null);
			ModLog.Verbose("InGameTests: World_GrenadeReady item " + ((Object)(object)val != (Object)null) + ", flight " + ((Object)(object)val2 != (Object)null) + ", blast " + ((Object)(object)val3 != (Object)null) + ((val4 != null) ? (", accuracy " + val4.m_projectileAccuracy + "/" + val4.m_projectileAccuracyMin + ", projectile " + (((Object)(object)val4.m_attackProjectile != (Object)null) ? ((Object)val4.m_attackProjectile).name : "none")) : "") + (((Object)(object)val5 != (Object)null) ? (", blast hits props " + val5.m_hitProps + ", radius " + val5.m_radius) : ""));
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				string text = "FAIL: missing prefab - item " + ((Object)(object)val != (Object)null) + ", flight " + ((Object)(object)val2 != (Object)null) + ", blast " + ((Object)(object)val3 != (Object)null);
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("InGameTests.World_GrenadeReady: returns " + text + " because item == null || flight == null || blast == null (line 140)");
				}
				return text;
			}
			if ((Object)(object)val4.m_attackProjectile != (Object)(object)val2)
			{
				string text2 = "FAIL: the grenade throws " + (((Object)(object)val4.m_attackProjectile != (Object)null) ? ((Object)val4.m_attackProjectile).name : "nothing") + ", not its own flight";
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("InGameTests.World_GrenadeReady: returns " + text2 + " because attack.m_attackProjectile != flight (line 141)");
				}
				return text2;
			}
			if (val4.m_projectileAccuracy > 0f || val4.m_projectileAccuracyMin > 0f || val4.m_randomVelocity)
			{
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("InGameTests.World_GrenadeReady: returns \"FAIL: the throw has random spread, it would not follow the arc\" because attack.m_projectileAccuracy > 0f || attack.m_projectileAccuracyMin > 0f || attack.m_randomVelocity (line 142)");
				}
				return "FAIL: the throw has random spread, it would not follow the arc";
			}
			if ((Object)(object)val5 == (Object)null || !val5.m_hitProps || val5.m_hitTerrain)
			{
				string text3 = "FAIL: the blast " + (((Object)(object)val5 == (Object)null) ? "has no Aoe" : ((!val5.m_hitProps) ? "spares buildings (D-100: it must damage them)" : "changes the terrain"));
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("InGameTests.World_GrenadeReady: returns " + text3 + " because aoe == null || !aoe.m_hitProps || aoe.m_hitTerrain (line 143)");
				}
				return text3;
			}
			if (val4.m_recoilPushback <= 0f)
			{
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("InGameTests.World_GrenadeReady: returns \"FAIL: the throw has no recoil (D-045: every weapon has some)\" because attack.m_recoilPushback <= 0f (line 144)");
				}
				return "FAIL: the throw has no recoil (D-045: every weapon has some)";
			}
			if ((Object)(object)val6 == (Object)null || (Object)(object)val6.Find("gp_model") == (Object)null)
			{
				if (RuleLog.IsOn())
				{
					ModLog.Verbose("InGameTests.World_GrenadeReady: returns \"FAIL: no clay pot in the hand model (attach)\" because attach == null || attach.Find(\"gp_model\") == null (line 145)");
				}
				return "FAIL: no clay pot in the hand model (attach)";
			}
			string text4 = "PASS: grenade, flight and blast ready (radius " + val5.m_radius + " m, speed " + val4.m_projectileVel + " m/s, no spread, recoil " + val4.m_recoilPushback + ", buildings spared)";
			if (RuleLog.IsOn())
			{
				ModLog.Verbose("InGameTests.World_GrenadeReady: returns " + text4 + " (line 146)");
			}
			return text4;
		}

		private static string World_PlayerPresent()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			ModLog.Verbose("InGameTests: World_PlayerPresent player " + (((Object)(object)localPlayer != (Object)null) ? localPlayer.GetPlayerName() : "null"));
			if (!((Object)(object)localPlayer != (Object)null))
			{
				return "FAIL: no local player 5 s after the world loaded";
			}
			string playerName = localPlayer.GetPlayerName();
			Vector3 position = ((Component)localPlayer).transform.position;
			return "PASS: " + playerName + " at " + ((Vector3)(ref position)).ToString("F1");
		}
	}
}
namespace GunPowdered.Testing.TestHooks
{
	internal static class AshlandsTestHooks
	{
		private const string WallPrefab = "woodwall";

		private static GameObject _wall;

		private static float _cannonBefore = float.NaN;

		private static float _wallBefore = float.NaN;

		private static Vector3 _spot;

		private static float _ashBefore = float.NaN;

		private static Vector3 _goal;

		private const float AboveSea = 36f;

		[TestHook("GunPowdered.spawnBlock")]
		private static string SpawnBlockArm(double radius)
		{
			return SpawnBlock.Arm((float)radius);
		}

		[TestHook("GunPowdered.ashDamageReset")]
		private static string AshDamageReset()
		{
			if ((Object)(object)Game.instance == (Object)null || float.IsNaN(_ashBefore))
			{
				ModLog.Verbose("AshlandsTestHooks.AshDamageReset: returns \"unchanged\" because Game.instance == null || float.IsNaN(_ashBefore)");
				return "unchanged";
			}
			Game.instance.m_ashDamage = _ashBefore;
			string text = $"ash damage back to {_ashBefore:0.##}";
			_ashBefore = float.NaN;
			ModLog.Info("AshlandsTestHooks: " + text);
			return text;
		}

		[TestHook("GunPowdered.ashlandsGo")]
		private static string AshlandsGo(bool lava)
		{
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			WorldGenerator instance = WorldGenerator.instance;
			if ((Object)(object)localPlayer == (Object)null || instance == null)
			{
				ModLog.Verbose("AshlandsTestHooks.AshlandsGo: returns \"no player or no world generator\" because p == null || g == null (line 50)");
				return "no player or no world generator";
			}
			Vector3 val = default(Vector3);
			for (float num = -6000f; num >= -10000f; num -= 37f)
			{
				for (float num2 = -2000f; num2 <= 2000f; num2 += 41f)
				{
					if (!DeepInAshlands(instance, num2, num))
					{
						if (RuleLog.Due("AshlandsTestHooks.AshlandsGo:biome", 2.0))
						{
							ModLog.Every("AshlandsTestHooks.AshlandsGo:biome", 2.0, "AshlandsTestHooks.AshlandsGo: skips to the next item (continue) because the point is not deep in the Ashlands (line 54)");
						}
						continue;
					}
					float num3 = MaskLava(instance, num2, num);
					float num4 = MaskLava(instance, num2 - 2.5f, num);
					bool num5;
					if (!lava)
					{
						if (instance.GetHeight(num2, num) > 36f && instance.GetHeight(num2 - 2.5f, num) > 36f)
						{
							num5 = DryAround(instance, num2, num, 8f);
							goto IL_00e9;
						}
					}
					else if (num3 >= 0.7f)
					{
						num5 = num4 >= 0.7f;
						goto IL_00e9;
					}
					goto IL_00eb;
					IL_00e9:
					if (num5)
					{
						((Vector3)(ref val))..ctor(num2, instance.GetHeight(num2, num) + 3f, num - 4f);
						_goal = new Vector3(num2, 0f, num);
						if (!((Character)localPlayer).TeleportTo(val, Quaternion.identity, true))
						{
							ModLog.Verbose($"AshlandsTestHooks.AshlandsGo: returns \"teleport refused\" because the game's TeleportTo said no (teleporting {((Character)localPlayer).IsTeleporting()})");
							return "teleport refused (teleporting " + ((Character)localPlayer).IsTeleporting() + ")";
						}
						string text = $"going to ({num2:0}, {num:0}), lava {num3:0.00}";
						ModLog.Info("AshlandsTestHooks: " + text);
						return text;
					}
					goto IL_00eb;
					IL_00eb:
					if (RuleLog.Due("AshlandsTestHooks.AshlandsGo:fit", 2.0))
					{
						ModLog.Every("AshlandsTestHooks.AshlandsGo:fit", 2.0, "AshlandsTestHooks.AshlandsGo: skips to the next item (continue) because the point does not fit (line 58)");
					}
				}
			}
			ModLog.Verbose("AshlandsTestHooks.AshlandsGo: returns \"no place found\" because the scan found none (line 67)");
			return "no place found";
		}

		private static bool DeepInAshlands(WorldGenerator g, float x, float z)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Invalid comparison between Unknown and I4
			bool flag = (int)g.GetBiome(x, z, 0.02f, false) == 32 && (int)g.GetBiome(x + 48f, z, 0.02f, false) == 32 && (int)g.GetBiome(x - 48f, z, 0.02f, false) == 32 && (int)g.GetBiome(x, z + 48f, 0.02f, false) == 32 && (int)g.GetBiome(x, z - 48f, 0.02f, false) == 32;
			if (RuleLog.Due("AshlandsTestHooks.DeepInAshlands", 2.0))
			{
				ModLog.Every("AshlandsTestHooks.DeepInAshlands", 2.0, $"AshlandsTestHooks.DeepInAshlands: returns {flag} at ({x:0}, {z:0})");
			}
			return flag;
		}

		private static float MaskLava(WorldGenerator g, float x, float z)
		{
			//IL_0055: 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)
			Color val = default(Color);
			g.GetHeight(x, z, ref val);
			if (RuleLog.Due("AshlandsTestHooks.MaskLava", 2.0))
			{
				ModLog.Every("AshlandsTestHooks.MaskLava", 2.0, $"AshlandsTestHooks.MaskLava: returns {val.a:0.00} at ({x:0}, {z:0})");
			}
			return val.a;
		}

		private static bool DryAround(WorldGenerator g, float x, float z, float r)
		{
			for (float num = 0f - r; num <= r; num += 2f)
			{
				for (float num2 = 0f - r; num2 <= r; num2 += 2f)
				{
					if (MaskLava(g, x + num, z + num2) > 0.02f)
					{
						if (RuleLog.Due("AshlandsTestHooks.DryAround:no", 2.0))
						{
							ModLog.Every("AshlandsTestHooks.DryAround:no", 2.0, "AshlandsTestHooks.DryAround: returns false because there is lava nearby (line 95)");
						}
						return false;
					}
				}
			}
			if (RuleLog.Due("AshlandsTestHooks.DryAround:yes", 2.0))
			{
				ModLog.Every("AshlandsTestHooks.DryAround:yes", 2.0, $"AshlandsTestHooks.DryAround: returns true - no lava within {r} m (line 96)");
			}
			return true;
		}

		[TestHook("GunPowdered.whereAmI")]
		private static string WhereAmI()
		{
			//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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				ModLog.Verbose("AshlandsTestHooks.WhereAmI: returns \"no player\" because p == null (line 105)");
				return "no player";
			}
			Vector3 position = ((Component)localPlayer).transform.position;
			bool flag = (Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.IsZoneLoaded(position);
			string text = $"biome {Heightmap.FindBiome(position)}, teleporting {((Character)localPlayer).IsTeleporting()}, zone loaded {flag}";
			if (RuleLog.Due("AshlandsTestHooks.WhereAmI", 2.0))
			{
				ModLog.Every("AshlandsTestHooks.WhereAmI", 2.0, "AshlandsTestHooks.WhereAmI: returns " + text);
			}
			return text;
		}

		[TestHook("GunPowdered.ashSpot")]
		private static string AshSpot(bool lava)
		{
			//IL_001f: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: 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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				ModLog.Verbose("AshlandsTestHooks.AshSpot: returns \"no player\" because p == null (line 120)");
				return "no player";
			}
			Vector3 val = (Vector3)((_goal != Vector3.zero) ? new Vector3(_goal.x, ((Component)localPlayer).transform.position.y, _goal.z) : ((Component)localPlayer).transform.position);
			for (float num = 0f; num <= 60f; num += 2f)
			{
				for (float num2 = 0f; num2 < 360f; num2 += ((num == 0f) ? 360f : 20f))
				{
					Vector3 val2 = val + Quaternion.Euler(0f, num2, 0f) * Vector3.forwa