Decompiled source of SuperSoundSliderThingPlus v1.0.1

SuperSoundSliderThingPlus/SuperSoundSliderThingPlus.dll

Decompiled 10 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Utils;
using KydlCore.Common;
using KydlCore.Core;
using KydlCore.Features.Hub.Contracts;
using KydlCore.Ui;
using Microsoft.CodeAnalysis;
using SuperSoundSliderThingPlus.Bootstrap;
using SuperSoundSliderThingPlus.Configuration;
using SuperSoundSliderThingPlus.Core;
using SuperSoundSliderThingPlus.Features.Example.Application;
using SuperSoundSliderThingPlus.Features.Example.Domain;
using SuperSoundSliderThingPlus.Features.Example.Execution;
using SuperSoundSliderThingPlus.Features.Example.Infrastructure;
using SuperSoundSliderThingPlus.Features.Sound.Application;
using SuperSoundSliderThingPlus.Features.Sound.Domain;
using SuperSoundSliderThingPlus.Features.Sound.Execution;
using SuperSoundSliderThingPlus.Features.Sound.Infrastructure;
using SuperSoundSliderThingPlus.Integrations.Harmony;
using SuperSoundSliderThingPlus.Integrations.Valheim;
using SuperSoundSliderThingPlus.Presentation.Hub.Commands;
using SuperSoundSliderThingPlus.Presentation.Hub.Registration;
using SuperSoundSliderThingPlus.Presentation.Hub.ViewModels;
using SuperSoundSliderThingPlus.Ui;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
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 SuperSoundSliderThingPlus.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("supersoundsliderthingplus_tab_example_section")));
			val.Add((VisualElement)(object)UiControls.Note(text("supersoundsliderthingplus_tab_example_note")));
			val.Add(UiControls.Row(text("supersoundsliderthingplus_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>
		{
			{ "supersoundsliderthingplus_menu_title", "SuperSoundSliderThingPlus" },
			{ "supersoundsliderthingplus_menu_footer", "Esc to close" },
			{ "supersoundsliderthingplus_tab_example", "Example" },
			{ "supersoundsliderthingplus_tab_settings", "Settings" },
			{ "supersoundsliderthingplus_tab_example_section", "Example" },
			{ "supersoundsliderthingplus_tab_example_note", "This is the starting tab of the mod in the KY hub (F6). Replace its content in ExampleTabView." },
			{ "supersoundsliderthingplus_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 SuperSoundSliderThingPlus.Testing
{
	internal static class InGameTests
	{
		private static string Startup_ConfigBound()
		{
			if (ModSettings.EnableMod == null)
			{
				return "FAIL: ModSettings.Bind did not run (EnableMod is null)";
			}
			if (!ModSettings.On)
			{
				return "SKIP: EnableMod is off in the config";
			}
			return "PASS: EnableMod on";
		}

		private static string Startup_FeaturesInstalled()
		{
			ModInstaller current = ModInstaller.Current;
			if (current == null)
			{
				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_SoundFactorsMatchTheConfig()
		{
			if (ModSettings.MasterMute == null)
			{
				return "FAIL: the slider config is not bound";
			}
			SoundFeature instance = SoundFeature.Instance;
			if (instance == null || !instance.Running)
			{
				return "SKIP: the sound feature is not running (mod off)";
			}
			string text = string.Empty;
			foreach (SoundCategory value in Enum.GetValues(typeof(SoundCategory)))
			{
				float num = 1f - SoundLevels.MuteOf(value) / 100f;
				float num2 = SoundLevels.Factor(value);
				ModLog.Verbose("InGameTests: Startup_SoundFactorsMatchTheConfig " + value.ToString() + " factor " + num2.ToString("F3") + ", expected " + num.ToString("F3"));
				if (Math.Abs(num2 - num) > 0.001f)
				{
					text = value.ToString() + " factor " + num2.ToString("F3") + ", expected " + num.ToString("F3");
				}
			}
			if (text.Length != 0)
			{
				return "FAIL: " + text;
			}
			return "PASS: every category factor matches its own mute level";
		}

		private static string World_SoundsAreClassified()
		{
			int distinct = SoundRecorder.Distinct;
			ModLog.Verbose("InGameTests: World_SoundsAreClassified " + distinct + " distinct sound(s): " + SoundRecorder.Summary());
			if (distinct <= 0)
			{
				return "PASS: no sound has played yet, nothing to classify (the classified-sounds suite test plays one)";
			}
			return "PASS: " + distinct + " distinct sound(s) classified (" + SoundRecorder.Summary() + ")";
		}

		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 SuperSoundSliderThingPlus.Testing.TestHooks
{
	internal static class MixTestHooks
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static PCMReaderCallback <>9__7_0;

			internal void <Tone>b__7_0(float[] buffer)
			{
				for (int i = 0; i < buffer.Length; i++)
				{
					buffer[i] = 0.6f * Mathf.Sin((float)Math.PI * 880f * (float)(_phase % 44100) / 44100f);
					_phase++;
				}
			}
		}

		private const int BlockSize = 1024;

		private const int SampleRate = 44100;

		private static GameObject _tone;

		private static double _marked = double.NaN;

		private static long _phase;

		private static readonly float[] Left = new float[1024];

		private static readonly float[] Right = new float[1024];

		[TestHook("SuperSoundSliderThingPlus.mix.tone")]
		private static string Tone(string group)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			Stop();
			AudioMixerGroup val = null;
			if (group != "none")
			{
				if ((Object)(object)AudioMan.instance == (Object)null || (Object)(object)AudioMan.instance.m_masterMixer == (Object)null)
				{
					return "Failed: no AudioMan";
				}
				AudioMixerGroup[] array = AudioMan.instance.m_masterMixer.FindMatchingGroups(group);
				foreach (AudioMixerGroup val2 in array)
				{
					if (((Object)val2).name == group)
					{
						val = val2;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					return "Failed: no mixer group '" + group + "'";
				}
			}
			object obj = <>c.<>9__7_0;
			if (obj == null)
			{
				PCMReaderCallback val3 = delegate(float[] buffer)
				{
					for (int j = 0; j < buffer.Length; j++)
					{
						buffer[j] = 0.6f * Mathf.Sin((float)Math.PI * 880f * (float)(_phase % 44100) / 44100f);
						_phase++;
					}
				};
				<>c.<>9__7_0 = val3;
				obj = (object)val3;
			}
			AudioClip clip = AudioClip.Create("ssst_tone", 44100, 1, 44100, true, (PCMReaderCallback)obj);
			_tone = new GameObject("SSST_Tone");
			AudioSource obj2 = _tone.AddComponent<AudioSource>();
			obj2.clip = clip;
			obj2.loop = true;
			obj2.spatialBlend = 0f;
			obj2.volume = 1f;
			obj2.outputAudioMixerGroup = val;
			obj2.Play();
			return "tone through " + (((Object)(object)val != (Object)null) ? ((Object)val).name : "no group");
		}

		[TestHook("SuperSoundSliderThingPlus.mix.level")]
		private static double Level()
		{
			return Math.Round(Measure(), 5);
		}

		[TestHook("SuperSoundSliderThingPlus.mix.mark")]
		private static double Mark()
		{
			_marked = Measure();
			ModLog.Info("SoundTestHooks: MIX mark " + _marked.ToString("F5"));
			return Math.Round(_marked, 5);
		}

		[TestHook("SuperSoundSliderThingPlus.mix.ratioNear")]
		private static bool RatioNear(double expected, double tolerance)
		{
			double num = Measure();
			if (double.IsNaN(_marked) || _marked < 0.005)
			{
				ModLog.Info("SoundTestHooks: MIX reference too quiet to judge (" + _marked.ToString("F5") + ")");
				return false;
			}
			double num2 = num / _marked;
			bool flag = Math.Abs(num2 - expected) <= tolerance;
			ModLog.Info("SoundTestHooks: MIX marked " + _marked.ToString("F5") + " now " + num.ToString("F5") + " ratio " + num2.ToString("F3") + " expected " + expected.ToString("F3") + " -> " + (flag ? "ok" : "WRONG"));
			return flag;
		}

		[TestHook("SuperSoundSliderThingPlus.mix.stop")]
		private static bool Stop()
		{
			if ((Object)(object)_tone != (Object)null)
			{
				Object.Destroy((Object)(object)_tone);
			}
			_tone = null;
			_marked = double.NaN;
			return (Object)(object)_tone == (Object)null;
		}

		private static double Measure()
		{
			AudioListener.GetOutputData(Left, 0);
			AudioListener.GetOutputData(Right, 1);
			double num = 0.0;
			for (int i = 0; i < 1024; i++)
			{
				num += (double)(Left[i] * Left[i] + Right[i] * Right[i]);
			}
			return Math.Sqrt(num / 2048.0);
		}
	}
	internal static class MobTestHooks
	{
		private static readonly List<GameObject> Spawned = new List<GameObject>();

		[TestHook("SuperSoundSliderThingPlus.mob.moveAway")]
		private static string MoveAway(double metres)
		{
			//IL_004c: 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_0043: 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_005b: 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_0061: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: 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_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				return "Failed: no player or zones";
			}
			Vector3 val = ((AppDomain.CurrentDomain.GetData("Kydl.TestArena.Start") is Vector3 val2) ? val2 : ((Component)localPlayer).transform.position);
			Vector3 val3 = ((Component)localPlayer).transform.position - val;
			val3.y = 0f;
			float num = ((((Vector3)(ref val3)).sqrMagnitude > 1f) ? Mathf.Atan2(val3.z, val3.x) : 0f);
			Vector3 val4 = Vector3.zero;
			float num2 = float.MaxValue;
			for (int i = 0; i < 16; i++)
			{
				float num3 = num + (float)i * (float)Math.PI * 2f / 16f;
				Vector3 val5 = val + new Vector3(Mathf.Cos(num3), 0f, Mathf.Sin(num3)) * (float)metres;
				float num4 = float.MaxValue;
				float num5 = float.MinValue;
				for (int j = -2; j <= 2; j++)
				{
					for (int k = -2; k <= 2; k++)
					{
						float groundHeight = ZoneSystem.instance.GetGroundHeight(val5 + new Vector3((float)j * 10f, 0f, (float)k * 10f));
						num4 = Mathf.Min(num4, groundHeight);
						num5 = Mathf.Max(num5, groundHeight);
					}
				}
				if (!(num4 < 31f))
				{
					float num6 = num5 - num4;
					if (num6 < num2)
					{
						num2 = num6;
						val4 = val5;
					}
				}
			}
			if (num2 >= float.MaxValue)
			{
				return "Failed: no dry ground " + metres + " m from the start";
			}
			val4.y = ZoneSystem.instance.GetGroundHeight(val4) + 0.3f;
			Rigidbody component = ((Component)localPlayer).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.linearVelocity = Vector3.zero;
				component.position = val4;
			}
			((Component)localPlayer).transform.position = val4;
			((Component)localPlayer).transform.rotation = Quaternion.identity;
			if ((Object)(object)ZNet.instance != (Object)null)
			{
				ZNet.instance.SetReferencePosition(val4);
			}
			string text = "moved to " + ((Vector3)(ref val4)).ToString("F0") + ", " + Vector3.Distance(new Vector3(val4.x, 0f, val4.z), new Vector3(val.x, 0f, val.z)).ToString("F0") + " m from the lab start, height spread " + num2.ToString("F1") + " m";
			ModLog.Info("MobTestHooks: " + text);
			return text;
		}

		[TestHook("SuperSoundSliderThingPlus.mob.noFly")]
		private static string NoFly()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return "Failed: no player";
			}
			FieldInfo field = typeof(Player).GetField("m_debugFly", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				return "Failed: Player has no m_debugFly field";
			}
			bool flag = (bool)field.GetValue(localPlayer);
			if (flag)
			{
				MethodInfo method = typeof(Player).GetMethod("ToggleDebugFly", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null)
				{
					return "Failed: Player has no ToggleDebugFly";
				}
				method.Invoke(localPlayer, null);
			}
			bool flag2 = (bool)field.GetValue(localPlayer);
			string text = "fly before " + flag + " after " + flag2 + ", god mode " + ((Character)localPlayer).InGodMode() + ", ghost " + ((Character)localPlayer).InGhostMode() + ", flying " + ((Character)localPlayer).IsFlying();
			ModLog.Info("MobTestHooks: " + text);
			return text;
		}

		[TestHook("SuperSoundSliderThingPlus.mob.tourStart")]
		private static bool TourStart(double seconds, string filter)
		{
			return MobTour.Begin((float)seconds, filter);
		}

		[TestHook("SuperSoundSliderThingPlus.mob.tourDone")]
		private static bool TourDone()
		{
			return MobTour.IsDone();
		}

		[TestHook("SuperSoundSliderThingPlus.mob.tourSummary")]
		private static string TourSummary()
		{
			return MobTour.State();
		}

		[TestHook("SuperSoundSliderThingPlus.mob.ghost")]
		private static string Ghost(bool on)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return "Failed: no player";
			}
			localPlayer.SetGhostMode(on);
			return "ghost " + on;
		}

		[TestHook("SuperSoundSliderThingPlus.mob.spawn")]
		private static string Spawn(string prefabs)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return "Failed: no player or scene";
			}
			StringBuilder stringBuilder = new StringBuilder();
			StringBuilder stringBuilder2 = new StringBuilder();
			string[] array = prefabs.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				GameObject prefab = ZNetScene.instance.GetPrefab(text);
				if ((Object)(object)prefab == (Object)null)
				{
					stringBuilder2.Append(text).Append(' ');
					continue;
				}
				float num = ((float)i + 0.5f) / (float)array.Length * (float)Math.PI * 2f;
				Vector3 val = ((Component)localPlayer).transform.position + new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * (6f + (float)(i % 3) * 3f);
				Spawned.Add(Object.Instantiate<GameObject>(prefab, val, Quaternion.identity));
				stringBuilder.Append(text).Append(' ');
			}
			string text2 = "spawned: " + stringBuilder?.ToString() + "| missing: " + stringBuilder2;
			ModLog.Info("MobTestHooks: " + text2);
			return text2;
		}

		[TestHook("SuperSoundSliderThingPlus.mob.report")]
		private static int Report()
		{
			ModLog.Info("MobTestHooks: REPORT distinct pairs " + SoundRecorder.Distinct + " | " + SoundRecorder.Summary());
			ModLog.Info("MobTestHooks: PAIRS " + SoundRecorder.List());
			return SoundRecorder.Distinct;
		}

		[TestHook("SuperSoundSliderThingPlus.mob.forget")]
		private static bool Forget()
		{
			return SoundRecorder.Clear();
		}

		[TestHook("SuperSoundSliderThingPlus.mob.clear")]
		private static bool Clear()
		{
			foreach (GameObject item in Spawned)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)ZNetScene.instance != (Object)null)
				{
					ZNetScene.instance.Destroy(item);
				}
			}
			Spawned.Clear();
			return Spawned.Count == 0;
		}
	}
	internal sealed class MobTour : MonoBehaviour
	{
		private static MobTour _current;

		private float _seconds;

		private string _filter;

		private const float ClearRadius = 150f;

		private const float NatureRadius = 180f;

		internal string Summary { get; private set; } = "not started";

		internal bool Done { get; private set; }

		internal static bool Begin(float seconds, string filter)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)_current != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_current).gameObject);
			}
			_current = new GameObject("SSST_MobTour").AddComponent<MobTour>();
			_current._seconds = seconds;
			_current._filter = filter ?? "";
			((MonoBehaviour)_current).StartCoroutine(_current.Run());
			return true;
		}

		internal static string State()
		{
			if (!((Object)(object)_current == (Object)null))
			{
				return _current.Summary;
			}
			return "not started";
		}

		internal static bool IsDone()
		{
			if ((Object)(object)_current != (Object)null)
			{
				return _current.Done;
			}
			return false;
		}

		private static HashSet<string> Pairs()
		{
			return new HashSet<string>(SoundRecorder.List().Split(new string[1] { "; " }, StringSplitOptions.RemoveEmptyEntries));
		}

		private static int ClearArea()
		{
			//IL_0050: 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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return 0;
			}
			List<GameObject> list = new List<GameObject>();
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (!((Object)(object)allCharacter == (Object)null) && !(allCharacter is Player) && Vector3.Distance(((Component)allCharacter).transform.position, ((Component)localPlayer).transform.position) <= 150f)
				{
					list.Add(((Component)allCharacter).gameObject);
				}
			}
			foreach (GameObject item in list)
			{
				if ((Object)(object)item != (Object)null)
				{
					ZNetScene.instance.Destroy(item);
				}
			}
			return list.Count;
		}

		private static int ClearNature()
		{
			//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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return 0;
			}
			List<GameObject> list = new List<GameObject>();
			ZNetView[] array = Object.FindObjectsByType<ZNetView>((FindObjectsSortMode)0);
			foreach (ZNetView val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					GameObject gameObject = ((Component)val).gameObject;
					if (!(Vector3.Distance(gameObject.transform.position, ((Component)localPlayer).transform.position) > 180f) && ((Object)(object)gameObject.GetComponent<TreeBase>() != (Object)null || (Object)(object)gameObject.GetComponent<TreeLog>() != (Object)null || (Object)(object)gameObject.GetComponent<MineRock>() != (Object)null || (Object)(object)gameObject.GetComponent<MineRock5>() != (Object)null || (Object)(object)gameObject.GetComponent<Pickable>() != (Object)null))
					{
						list.Add(gameObject);
					}
				}
			}
			foreach (GameObject item in list)
			{
				if ((Object)(object)item != (Object)null)
				{
					ZNetScene.instance.Destroy(item);
				}
			}
			return list.Count;
		}

		private IEnumerator Run()
		{
			int num = ClearNature();
			ModLog.Info("MobTour: removed " + num + " trees, logs, rocks and pickables within " + 180f + " m of the player");
			yield return null;
			int num2 = ClearArea();
			ModLog.Info("MobTour: cleared " + num2 + " creatures within " + 150f + " m of the player");
			yield return null;
			string text = Environment.GetEnvironmentVariable("SSST_TOUR_FROM") ?? "";
			string text2 = Environment.GetEnvironmentVariable("SSST_TOUR_TO") ?? "";
			List<string> names = new List<string>();
			foreach (GameObject prefab2 in ZNetScene.instance.m_prefabs)
			{
				if (!((Object)(object)prefab2 == (Object)null) && !((Object)(object)prefab2.GetComponent<Character>() == (Object)null) && !((Object)(object)prefab2.GetComponent<Player>() != (Object)null) && (_filter.Length <= 0 || ((Object)prefab2).name.Contains(_filter)) && (text.Length <= 0 || string.CompareOrdinal(((Object)prefab2).name, text) >= 0) && (text2.Length <= 0 || string.CompareOrdinal(((Object)prefab2).name, text2) < 0))
				{
					names.Add(((Object)prefab2).name);
				}
			}
			names.Sort();
			ModLog.Info("MobTour: " + names.Count + " creatures: " + string.Join(" ", names.ToArray()));
			int withNew = 0;
			int totalNew = 0;
			StringBuilder quiet = new StringBuilder();
			Vector3 start = (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform.position : Vector3.zero);
			foreach (string name in names)
			{
				Player player = Player.m_localPlayer;
				GameObject prefab = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(name) : null);
				if ((Object)(object)player == (Object)null || (Object)(object)prefab == (Object)null)
				{
					break;
				}
				int num3 = ClearArea();
				if (num3 > 0)
				{
					ModLog.Info("MobTour: removed " + num3 + " other creatures before " + name);
				}
				yield return null;
				HashSet<string> before = Pairs();
				Vector3 val = ((Component)player).transform.position + ((Component)player).transform.forward * 5f;
				GameObject mob = Object.Instantiate<GameObject>(prefab, val, Quaternion.identity);
				Vector3 back = -((Component)player).transform.forward;
				float waited = 0f;
				int phase = 0;
				while (waited < _seconds && (Object)(object)mob != (Object)null)
				{
					waited += Time.deltaTime;
					int num4 = ((!(waited < _seconds / 3f)) ? ((waited < _seconds * 2f / 3f) ? 1 : 2) : 0);
					if (num4 != phase && (Object)(object)Player.m_localPlayer != (Object)null)
					{
						phase = num4;
						Vector3 val2 = mob.transform.position + back * ((phase == 1) ? 20f : 45f);
						val2.y = ZoneSystem.instance.GetGroundHeight(val2) + 0.3f;
						Player localPlayer = Player.m_localPlayer;
						Rigidbody component = ((Component)localPlayer).GetComponent<Rigidbody>();
						if ((Object)(object)component != (Object)null)
						{
							component.linearVelocity = Vector3.zero;
							component.position = val2;
						}
						((Component)localPlayer).transform.position = val2;
						if ((Object)(object)ZNet.instance != (Object)null)
						{
							ZNet.instance.SetReferencePosition(val2);
						}
					}
					yield return null;
				}
				bool flag = (Object)(object)mob == (Object)null;
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					Player localPlayer2 = Player.m_localPlayer;
					Rigidbody component2 = ((Component)localPlayer2).GetComponent<Rigidbody>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.linearVelocity = Vector3.zero;
						component2.position = start;
					}
					((Component)localPlayer2).transform.position = start;
					if ((Object)(object)ZNet.instance != (Object)null)
					{
						ZNet.instance.SetReferencePosition(start);
					}
				}
				if ((Object)(object)mob != (Object)null && (Object)(object)ZNetScene.instance != (Object)null)
				{
					ZNetScene.instance.Destroy(mob);
				}
				HashSet<string> hashSet = Pairs();
				hashSet.ExceptWith(before);
				if (hashSet.Count > 0)
				{
					withNew++;
					totalNew += hashSet.Count;
				}
				else
				{
					quiet.Append(name).Append(' ');
				}
				ModLog.Info("MobTour: " + name + (flag ? " (died early)" : "") + " -> " + hashSet.Count + " new sound pairs: " + string.Join("; ", new List<string>(hashSet).ToArray()));
				yield return null;
			}
			Summary = "tour of " + names.Count + " creatures: " + withNew + " added sounds (" + totalNew + " new pairs), " + SoundRecorder.Distinct + " pairs in total (" + SoundRecorder.Summary() + "); added nothing new: " + quiet;
			ModLog.Info("MobTour: DONE " + Summary);
			Done = true;
		}
	}
	internal static class ModTestHooks
	{
		[TestHook("SuperSoundSliderThingPlus.arena")]
		private static string Arena()
		{
			return TestArena.MovePlayer();
		}

		[TestHook("SuperSoundSliderThingPlus.selftest")]
		private static string SelfTest()
		{
			return TestLabSupport.RunInGameTests(typeof(InGameTests), true);
		}

		[TestHook("SuperSoundSliderThingPlus.featureRunning")]
		private static bool FeatureRunning(string id)
		{
			if (ModInstaller.Current != null)
			{
				return ModInstaller.Current.Features.IsRunning(id);
			}
			return false;
		}
	}
	internal sealed class SoundSweeper : MonoBehaviour
	{
		private const int FramesPerSound = 3;

		private const float LateSeconds = 0.5f;

		private static SoundSweeper _current;

		internal bool Done { get; private set; }

		internal string Summary { get; private set; } = "not started";

		internal static bool Begin()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return false;
			}
			if ((Object)(object)_current != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_current).gameObject);
			}
			_current = new GameObject("SSST_SoundSweep").AddComponent<SoundSweeper>();
			((MonoBehaviour)_current).StartCoroutine(_current.Run());
			return true;
		}

		internal static string State()
		{
			if (!((Object)(object)_current == (Object)null))
			{
				return _current.Summary;
			}
			return "not started";
		}

		internal static bool IsDone()
		{
			if ((Object)(object)_current != (Object)null)
			{
				return _current.Done;
			}
			return false;
		}

		private IEnumerator Run()
		{
			List<GameObject> list = new List<GameObject>();
			GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
			foreach (GameObject val in array)
			{
				Scene scene = val.scene;
				if (!((Scene)(ref scene)).IsValid() && (Object)(object)val.GetComponent<ZSFX>() != (Object)null && (Object)(object)val.GetComponent<AudioSource>() != (Object)null)
				{
					list.Add(val);
				}
			}
			list.Sort((GameObject a, GameObject b) => string.CompareOrdinal(((Object)a).name, ((Object)b).name));
			SortedDictionary<string, int> groups = new SortedDictionary<string, int>();
			SortedDictionary<string, int> categories = new SortedDictionary<string, int>();
			int played = 0;
			int notPlaying = 0;
			int noGroup = 0;
			int ratioWrong = 0;
			int late = 0;
			Vector3 position = ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 6f;
			ModLog.Info("SWEEP start: " + list.Count + " sound prefabs, game master volume " + GameVolume.Master().ToString("F2"));
			foreach (GameObject prefab in list)
			{
				GameObject instance = Object.Instantiate<GameObject>(prefab, position, Quaternion.identity);
				ZSFX zsfx = instance.GetComponent<ZSFX>();
				AudioSource source = instance.GetComponent<AudioSource>();
				if ((Object)(object)zsfx != (Object)null && !zsfx.m_playOnAwake)
				{
					zsfx.Play();
				}
				for (int i2 = 0; i2 < 3; i2++)
				{
					yield return null;
				}
				if ((Object)(object)instance == (Object)null)
				{
					continue;
				}
				float waited = 0f;
				SoundCategory category;
				float raw;
				float scaled;
				while (waited < 0.5f && (!source.isPlaying || !ZsfxCustomUpdatePatch.TryGetLast(zsfx, out category, out raw, out scaled)))
				{
					waited += Time.unscaledDeltaTime;
					yield return null;
					if ((Object)(object)instance == (Object)null)
					{
						break;
					}
				}
				if (!((Object)(object)instance == (Object)null))
				{
					if (waited > 0f)
					{
						late++;
					}
					SoundCategory category2;
					float raw2;
					float scaled2;
					bool flag = ZsfxCustomUpdatePatch.TryGetLast(zsfx, out category2, out raw2, out scaled2);
					string text = (((Object)(object)source.outputAudioMixerGroup != (Object)null) ? ((Object)source.outputAudioMixerGroup).name : "(none)");
					bool isPlaying = source.isPlaying;
					float num = (flag ? SoundLevels.Factor(category2) : (-1f));
					float num2 = ((flag && raw2 > 0.0005f) ? (scaled2 / raw2) : (-1f));
					bool flag2 = flag && num2 >= 0f && Math.Abs(num2 - num) > 0.02f;
					played++;
					if (!isPlaying)
					{
						notPlaying++;
					}
					if (text == "(none)")
					{
						noGroup++;
					}
					if (flag2)
					{
						ratioWrong++;
					}
					Increment(groups, text);
					Increment(categories, flag ? category2.ToString() : "unseen");
					ModLog.Info("SWEEP " + ((Object)prefab).name + " (root " + ((Object)prefab.transform.root).name + ") | group " + text + " | " + (isPlaying ? "playing" : "not playing") + " | category " + (flag ? category2.ToString() : "unseen") + " | raw " + raw2.ToString("F3") + " scaled " + scaled2.ToString("F3") + " ratio " + num2.ToString("F3") + " expected " + num.ToString("F3") + (flag2 ? " | WRONG" : string.Empty) + " | played volume " + (scaled2 * GameVolume.Sfx()).ToString("F3") + " (scaled x mixer " + GameVolume.Sfx().ToString("F2") + ")");
					Object.Destroy((Object)(object)instance);
					yield return null;
				}
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(played).Append(" sounds, ").Append(notPlaying)
				.Append(" not playing even after waiting up to " + 0.5f + " s (" + late + " needed the longer wait), ")
				.Append(noGroup)
				.Append(" without a mixer group (the master cannot reach them), ")
				.Append(ratioWrong)
				.Append(" with a wrong category factor; groups ")
				.Append(Join(groups))
				.Append("; categories ")
				.Append(Join(categories));
			Summary = stringBuilder.ToString();
			ModLog.Info("SWEEP done: " + Summary);
			Done = true;
		}

		private static void Increment(SortedDictionary<string, int> map, string key)
		{
			map.TryGetValue(key, out var value);
			map[key] = value + 1;
		}

		private static string Join(SortedDictionary<string, int> map)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<string, int> item in map)
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append(", ");
				}
				stringBuilder.Append(item.Key).Append(' ').Append(item.Value);
			}
			return stringBuilder.ToString();
		}
	}
	internal static class SoundTestHooks
	{
		private const float AudibleAbove = 0.001f;

		private const float SilentBelow = 0.0001f;

		private static GameObject _probe;

		private static AudioSource _probeSource;

		private static GameObject _cub;

		private static float _baseline = float.NaN;

		private static float _savedGame = float.NaN;

		[TestHook("SuperSoundSliderThingPlus.mute.set")]
		private static string MuteSet(string slider, double value)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (ModInstaller.Current == null)
			{
				return "Failed: mod not installed";
			}
			if (!TryParse(slider, out var slider2))
			{
				return "Failed: unknown slider '" + slider + "'";
			}
			return ((object)SoundCommands.SetMute(ModInstaller.Current.Deps.Commands, slider2, (float)value)/*cast due to .constrained prefix*/).ToString();
		}

		[TestHook("SuperSoundSliderThingPlus.mute.value")]
		private static double MuteValue(string slider)
		{
			if (!TryParse(slider, out var slider2))
			{
				return double.NaN;
			}
			return SoundLevels.MuteOf(slider2);
		}

		[TestHook("SuperSoundSliderThingPlus.sound.factor")]
		private static double Factor(string category)
		{
			if (!Enum.TryParse<SoundCategory>(category, ignoreCase: true, out var result))
			{
				return double.NaN;
			}
			return SoundLevels.Factor(result);
		}

		[TestHook("SuperSoundSliderThingPlus.sound.classified")]
		private static bool Classified(string sound, string category)
		{
			SoundCategory result2;
			bool result = Enum.TryParse<SoundCategory>(category, ignoreCase: true, out result2) && SoundRecorder.Has(sound, result2);
			ModLog.Verbose("SoundTestHooks: classified '" + sound + "' as " + category + " -> " + result + " (recorded: " + SoundRecorder.Summary() + ")");
			return result;
		}

		[TestHook("SuperSoundSliderThingPlus.sound.play")]
		private static string Play(string prefab)
		{
			//IL_0043: 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)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			Clear();
			GameObject val = FindPrefab(prefab);
			if ((Object)(object)val == (Object)null)
			{
				return "Failed: no loaded prefab named '" + prefab + "'";
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return "Failed: no local player";
			}
			_probe = Object.Instantiate<GameObject>(val, ((Component)localPlayer).transform.position + Vector3.up,