Decompiled source of Outbound Valuables v1.0.0

OutboundValuables.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using REPOLib.Modules;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Empress")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5f1b735e473ca4ccf3b383128fbebd889cb564da")]
[assembly: AssemblyProduct("OutboundValuables")]
[assembly: AssemblyTitle("OutboundValuables")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 Empress.REPO.OutboundValuables
{
	internal static class OutboundValuableBundleVisuals
	{
		private const string BundleFileName = "outboundvaluablesassets";

		private static readonly Dictionary<string, GameObject?> VisualPrefabs = new Dictionary<string, GameObject>();

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

		private static ManualLogSource? _log;

		private static AssetBundle? _bundle;

		private static bool _loadAttempted;

		private static bool _audioLoadAttempted;

		public static void Initialize(string pluginDirectory, ManualLogSource log)
		{
			_log = log;
			if (_loadAttempted)
			{
				return;
			}
			_loadAttempted = true;
			string text = Path.Combine(pluginDirectory, "outboundvaluablesassets");
			if (!File.Exists(text))
			{
				log.LogWarning((object)("Outbound valuable asset bundle was not found at " + text + ". Falling back to procedural visuals."));
				return;
			}
			try
			{
				foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
				{
					if (string.Equals(((Object)allLoadedAssetBundle).name, "outboundvaluablesassets", StringComparison.OrdinalIgnoreCase))
					{
						_bundle = allLoadedAssetBundle;
						log.LogInfo((object)"Using already-loaded Outbound valuable asset bundle: outboundvaluablesassets");
						return;
					}
				}
				_bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)_bundle == (Object)null)
				{
					log.LogWarning((object)("Unity returned null when loading " + text + ". Falling back to procedural visuals."));
				}
				else
				{
					log.LogInfo((object)("Loaded Outbound valuable asset bundle: " + text));
				}
			}
			catch (Exception arg)
			{
				log.LogWarning((object)$"Failed to load Outbound valuable asset bundle {text}: {arg}");
				_bundle = null;
			}
		}

		public static bool TryAttach(Transform parent, OutboundValuableDefinition definition)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = LoadVisualPrefab(definition.PrefabName);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, parent, false);
			((Object)val2).name = "OutboundValuableVisual";
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			((Object)val2).hideFlags = (HideFlags)52;
			SetLayerRecursively(val2.transform, ((Component)parent).gameObject.layer);
			Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
			StripBoxedParticleEffects(val2);
			return true;
		}

		public static AudioClip[] GetGrabAudioClips(OutboundValuableDefinition definition)
		{
			return GetGrabAudioClips(definition.GrabSoundNames, definition.DisplayName);
		}

		public static AudioClip[] GetGrabAudioClips(IReadOnlyList<string> clipNames, string displayName)
		{
			EnsureGrabAudioLoaded();
			if (GrabAudioClips.Count == 0 || clipNames.Count == 0)
			{
				return Array.Empty<AudioClip>();
			}
			List<AudioClip> list = new List<AudioClip>();
			foreach (string clipName in clipNames)
			{
				if (TryGetAudioClip(clipName, out AudioClip clip))
				{
					list.Add(clip);
					continue;
				}
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogWarning((object)("Outbound bundle is missing grab audio clip '" + clipName + "' for " + displayName + "."));
				}
			}
			return list.ToArray();
		}

		private static GameObject? LoadVisualPrefab(string prefabName)
		{
			if (VisualPrefabs.TryGetValue(prefabName, out GameObject value))
			{
				return value;
			}
			if ((Object)(object)_bundle == (Object)null)
			{
				VisualPrefabs[prefabName] = null;
				return null;
			}
			try
			{
				GameObject val = _bundle.LoadAsset<GameObject>(prefabName);
				if ((Object)(object)val == (Object)null)
				{
					val = _bundle.LoadAsset<GameObject>("Assets/OutboundValuables/Prefabs/" + prefabName + ".prefab");
				}
				if ((Object)(object)val == (Object)null)
				{
					ManualLogSource? log = _log;
					if (log != null)
					{
						log.LogWarning((object)("Outbound bundle is missing valuable visual prefab '" + prefabName + "'."));
					}
				}
				VisualPrefabs[prefabName] = val;
				return val;
			}
			catch (Exception arg)
			{
				ManualLogSource? log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)$"Failed to load visual prefab '{prefabName}' from Outbound bundle: {arg}");
				}
				VisualPrefabs[prefabName] = null;
				return null;
			}
		}

		private static void EnsureGrabAudioLoaded()
		{
			if (_audioLoadAttempted)
			{
				return;
			}
			_audioLoadAttempted = true;
			if ((Object)(object)_bundle == (Object)null)
			{
				return;
			}
			try
			{
				AudioClip[] array = _bundle.LoadAllAssets<AudioClip>();
				foreach (AudioClip val in array)
				{
					if (!((Object)(object)val == (Object)null))
					{
						AddAudioClipKey(((Object)val).name, val);
						AddAudioClipKey(Path.GetFileNameWithoutExtension(((Object)val).name), val);
					}
				}
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogInfo((object)$"Loaded {GrabAudioClips.Count} Outbound grab audio key(s) from the valuable bundle.");
				}
			}
			catch (Exception arg)
			{
				ManualLogSource? log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)$"Failed to load grab audio clips from Outbound bundle: {arg}");
				}
			}
		}

		private static bool TryGetAudioClip(string clipName, out AudioClip clip)
		{
			if (GrabAudioClips.TryGetValue(clipName, out clip))
			{
				return true;
			}
			return GrabAudioClips.TryGetValue(NormalizeAudioKey(clipName), out clip);
		}

		private static void AddAudioClipKey(string clipName, AudioClip clip)
		{
			if (!string.IsNullOrWhiteSpace(clipName))
			{
				GrabAudioClips[clipName] = clip;
				GrabAudioClips[NormalizeAudioKey(clipName)] = clip;
			}
		}

		private static string NormalizeAudioKey(string clipName)
		{
			return clipName.Replace(" ", "").Replace("_", "").Replace("-", "")
				.ToLowerInvariant();
		}

		private static void SetLayerRecursively(Transform root, int layer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			((Component)root).gameObject.layer = layer;
			foreach (Transform item in root)
			{
				SetLayerRecursively(item, layer);
			}
		}

		private static void StripBoxedParticleEffects(GameObject root)
		{
			ParticleSystem[] componentsInChildren = root.GetComponentsInChildren<ParticleSystem>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
			ParticleSystemRenderer[] componentsInChildren2 = root.GetComponentsInChildren<ParticleSystemRenderer>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren2[i]);
			}
			TrailRenderer[] componentsInChildren3 = root.GetComponentsInChildren<TrailRenderer>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren3[i]);
			}
			LineRenderer[] componentsInChildren4 = root.GetComponentsInChildren<LineRenderer>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren4[i]);
			}
		}
	}
	internal sealed class OutboundValuableDefinition
	{
		public string PrefabName { get; }

		public string DisplayName { get; }

		public string SourceReference { get; }

		public Type VolumeType { get; }

		public int ValueMin { get; }

		public int ValueMax { get; }

		public float Fragility { get; }

		public float Durability { get; }

		public float Mass { get; }

		public Color Primary { get; }

		public Color Secondary { get; }

		public Color Accent { get; }

		public Vector3 GrabBoundsCenter { get; }

		public Vector3 GrabBoundsSize { get; }

		public string[] GrabSoundNames { get; }

		public bool PlayGrabAnimation { get; }

		public bool GrabGlow { get; }

		public OutboundValuableDefinition(string prefabName, string displayName, string sourceReference, Type volumeType, int valueMin, int valueMax, float fragility, float durability, float mass, Color primary, Color secondary, Color accent, Vector3 grabBoundsCenter, Vector3 grabBoundsSize, string[]? grabSoundNames = null, bool playGrabAnimation = false, bool grabGlow = true)
		{
			//IL_001c: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			PrefabName = prefabName;
			DisplayName = displayName;
			SourceReference = sourceReference;
			VolumeType = volumeType;
			ValueMin = valueMin;
			ValueMax = valueMax;
			Fragility = fragility;
			Durability = durability;
			Mass = mass;
			Primary = primary;
			Secondary = secondary;
			Accent = accent;
			GrabBoundsCenter = grabBoundsCenter;
			GrabBoundsSize = grabBoundsSize;
			GrabSoundNames = grabSoundNames ?? Array.Empty<string>();
			PlayGrabAnimation = playGrabAnimation;
			GrabGlow = grabGlow;
		}
	}
	internal static class OutboundValuableDefinitions
	{
		public static readonly OutboundValuableDefinition[] All = new OutboundValuableDefinition[10]
		{
			Def("OutboundValuable_Dog", "Outbound Dog Companion", "Outbound prefab: Companion Researcher / Doggo_simplified", (Type)2, 3400, 7600, 42f, 64f, 1.4f, new Color(0.82f, 0.58f, 0.38f), new Color(0.24f, 0.18f, 0.14f), new Color(0.95f, 0.74f, 0.36f), new Vector3(0f, 0.38f, 0f), new Vector3(0.96f, 0.78f, 0.62f), Sounds("research", "research-charge", "Footstep_Dirt_1_0")),
			Def("OutboundValuable_MiniCamperVan", "Mini Outbound Camper Van", "Outbound prefab: Van Model Large", (Type)4, 5200, 9800, 32f, 82f, 3.1f, new Color(0.84f, 0.9f, 0.88f), new Color(0.08f, 0.29f, 0.44f), new Color(0.95f, 0.74f, 0.22f), new Vector3(0f, 0.36f, 0f), new Vector3(1.24f, 0.72f, 0.72f), Sounds("lumber", "litter", "Item_Bottle_1_0", "Item_Bottle_2_0")),
			Def("OutboundValuable_BobbleheadVan", "Outbound Van Bobblehead", "Outbound prefab: Van Model / Bobblehead_van_base_01", (Type)2, 4200, 8500, 45f, 62f, 1.6f, new Color(0.88f, 0.78f, 0.58f), new Color(0.12f, 0.23f, 0.36f), new Color(0.93f, 0.26f, 0.22f), new Vector3(0f, 0.34f, 0f), new Vector3(0.88f, 0.72f, 0.64f), Sounds("litter", "cloths", "Item_Bottle_3_0")),
			Def("OutboundValuable_BobbleheadDog", "Outbound Dog Bobblehead", "Outbound prefab: Bobblehead Dog", (Type)1, 3000, 6900, 52f, 56f, 1.1f, new Color(0.72f, 0.52f, 0.34f), new Color(0.26f, 0.18f, 0.12f), new Color(0.96f, 0.82f, 0.32f), new Vector3(0f, 0.34f, 0f), new Vector3(0.72f, 0.72f, 0.62f), Sounds("research", "Footstep_Dirt_1_0", "cloths")),
			Def("OutboundValuable_CoffeeMaker", "Outbound Coffee Maker", "Outbound prefab: Coffee Maker", (Type)2, 2600, 6200, 48f, 60f, 2f, new Color(0.18f, 0.2f, 0.22f), new Color(0.66f, 0.43f, 0.24f), new Color(0.82f, 0.38f, 0.16f), new Vector3(0f, 0.36f, 0f), new Vector3(0.78f, 0.76f, 0.62f), Sounds("cofee-maker", "sipping-drink_0", "Spoon_1", "Spoon_2", "Spoon_3"), playGrabAnimation: true),
			Def("OutboundValuable_SolarPanel", "Outbound Solar Panel", "Outbound prefab: Solar Panel", (Type)4, 3600, 8000, 55f, 50f, 1.7f, new Color(0.1f, 0.22f, 0.34f), new Color(0.16f, 0.52f, 0.58f), new Color(0.92f, 0.86f, 0.3f), new Vector3(0f, 0.4f, 0f), new Vector3(0.96f, 0.88f, 0.62f), Sounds("minerals", "lumber")),
			Def("OutboundValuable_CampingLamp", "Outbound Camping Lamp", "Outbound prefab: Camping Lamp", (Type)1, 2200, 5400, 50f, 58f, 1.1f, new Color(0.18f, 0.22f, 0.18f), new Color(0.74f, 0.78f, 0.56f), new Color(1f, 0.86f, 0.34f), new Vector3(0f, 0.36f, 0f), new Vector3(0.64f, 0.72f, 0.64f), Sounds("Item_Bottle_1_0", "Item_Bottle_2_0", "minerals")),
			Def("OutboundValuable_RubberDuck", "Outbound Rubber Duck", "Outbound prefab: Rubber Duck", (Type)0, 1400, 4200, 68f, 40f, 0.5f, new Color(1f, 0.78f, 0.16f), new Color(0.95f, 0.46f, 0.08f), new Color(0.16f, 0.48f, 0.95f), new Vector3(0f, 0.24f, 0f), new Vector3(0.52f, 0.48f, 0.46f), Sounds("fruit", "fruit_0", "sipping-drink_0")),
			Def("OutboundValuable_GuitarCharm", "Outbound Guitar Charm", "Outbound prefab: Guitar Charm", (Type)0, 1800, 4600, 60f, 44f, 0.45f, new Color(0.72f, 0.36f, 0.18f), new Color(0.12f, 0.12f, 0.14f), new Color(0.28f, 0.68f, 0.95f), new Vector3(0f, 0.26f, 0f), new Vector3(0.58f, 0.58f, 0.32f), Sounds("Spoon_1_0", "Spoon_2_0", "Spoon_3_0", "cloths")),
			Def("OutboundValuable_Kite", "Outbound Kite", "Outbound prefab: Kite Standard", (Type)4, 2400, 6000, 70f, 35f, 0.6f, new Color(0.18f, 0.36f, 0.68f), new Color(0.9f, 0.22f, 0.18f), new Color(0.95f, 0.82f, 0.28f), new Vector3(0f, 0.22f, 0f), new Vector3(0.96f, 0.44f, 0.9f), Sounds("cut-grass", "cut-grass_0", "cloths"))
		};

		public static OutboundValuableDefinition? FindByPrefabName(string prefabName)
		{
			string b = NormalizePrefabName(prefabName);
			OutboundValuableDefinition[] all = All;
			foreach (OutboundValuableDefinition outboundValuableDefinition in all)
			{
				if (string.Equals(outboundValuableDefinition.PrefabName, b, StringComparison.OrdinalIgnoreCase))
				{
					return outboundValuableDefinition;
				}
			}
			return null;
		}

		private static string NormalizePrefabName(string value)
		{
			if (string.IsNullOrWhiteSpace(value))
			{
				return string.Empty;
			}
			int num = value.IndexOf("(Clone)", StringComparison.OrdinalIgnoreCase);
			if (num >= 0)
			{
				value = value.Substring(0, num);
			}
			return value.Trim();
		}

		private static OutboundValuableDefinition Def(string prefabName, string displayName, string sourceReference, Type volumeType, int valueMin, int valueMax, float fragility, float durability, float mass, Color primary, Color secondary, Color accent, Vector3 center, Vector3 size, string[]? grabSoundNames = null, bool playGrabAnimation = false)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			return new OutboundValuableDefinition(prefabName, displayName, sourceReference, volumeType, valueMin, valueMax, fragility, durability, mass, primary, secondary, accent, center, size, grabSoundNames, playGrabAnimation);
		}

		private static string[] Sounds(params string[] names)
		{
			return names;
		}
	}
	internal static class OutboundValuableGrabBounds
	{
		private const int MaxColliderTriangles = 40;

		private const float MinColliderExtent = 0.015f;

		public static void Add(Transform root, OutboundValuableDefinition definition)
		{
			RemoveTemplateColliders(root);
			if (AddMeshColliders(root) == 0)
			{
				AddFallbackBox(root, definition);
				OutboundValuablesPlugin.Log.LogWarning((object)(definition.DisplayName + " had no usable renderer meshes for grab colliders; using fitted fallback bounds."));
			}
		}

		private static int AddMeshColliders(Transform root)
		{
			int num = 0;
			Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (val.enabled && !(val is ParticleSystemRenderer))
				{
					Mesh val2 = CreateCollisionMesh(val);
					if ((Object)(object)val2 == (Object)null || !HasValidCollisionShape(val2))
					{
						DestroyMesh(val2);
						continue;
					}
					MeshCollider obj = ((Component)val).gameObject.AddComponent<MeshCollider>();
					obj.cookingOptions = (MeshColliderCookingOptions)14;
					obj.convex = true;
					((Collider)obj).isTrigger = false;
					obj.sharedMesh = val2;
					ConfigureColliderObject(((Component)val).gameObject);
					((Component)val).gameObject.AddComponent<PhysGrabObjectCollider>();
					((Component)val).gameObject.AddComponent<PhysGrabObjectMeshCollider>().showGizmo = false;
					num++;
				}
			}
			return num;
		}

		private static Mesh? CreateCollisionMesh(Renderer renderer)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = null;
			Mesh val2 = null;
			SkinnedMeshRenderer val3 = (SkinnedMeshRenderer)(object)((renderer is SkinnedMeshRenderer) ? renderer : null);
			if (val3 != null && (Object)(object)val3.sharedMesh != (Object)null)
			{
				val2 = new Mesh
				{
					name = ((Object)renderer).name + "_OutboundGrabCollider",
					hideFlags = (HideFlags)61
				};
				try
				{
					val3.BakeMesh(val2);
					val = val2;
				}
				catch
				{
					val = val3.sharedMesh;
				}
			}
			else
			{
				MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
				{
					val = component.sharedMesh;
				}
			}
			Mesh val4 = CreateReducedMesh(val, ((Object)renderer).name + "_OutboundGrabCollider");
			if ((Object)(object)val4 == (Object)null && (Object)(object)val != (Object)null)
			{
				val4 = CreateBoxMesh(val.bounds, ((Object)renderer).name + "_OutboundGrabCollider");
			}
			DestroyMesh(val2);
			return val4;
		}

		private static Mesh? CreateReducedMesh(Mesh? sourceMesh, string name)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			if ((Object)(object)sourceMesh == (Object)null)
			{
				return null;
			}
			if (!sourceMesh.isReadable)
			{
				return null;
			}
			Vector3[] vertices = sourceMesh.vertices;
			int[] triangles = sourceMesh.triangles;
			if (!HasValidVertexSet(vertices, sourceMesh.bounds) || triangles.Length < 3)
			{
				return null;
			}
			int num = triangles.Length / 3;
			int num2 = Mathf.Min(num, 40);
			Vector3[] array = (Vector3[])(object)new Vector3[num2 * 3];
			int[] array2 = new int[num2 * 3];
			for (int i = 0; i < num2; i++)
			{
				int num3 = ((num2 > 1) ? Mathf.RoundToInt((float)i * ((float)num - 1f) / ((float)num2 - 1f)) : 0) * 3;
				int num4 = i * 3;
				array[num4] = vertices[triangles[num3]];
				array[num4 + 1] = vertices[triangles[num3 + 1]];
				array[num4 + 2] = vertices[triangles[num3 + 2]];
				array2[num4] = num4;
				array2[num4 + 1] = num4 + 1;
				array2[num4 + 2] = num4 + 2;
			}
			Mesh val = new Mesh
			{
				name = name,
				hideFlags = (HideFlags)61
			};
			val.vertices = array;
			val.triangles = array2;
			val.RecalculateBounds();
			if (!HasValidCollisionShape(val))
			{
				DestroyMesh(val);
				return null;
			}
			return val;
		}

		private static Mesh? CreateBoxMesh(Bounds bounds, string name)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_0103: 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)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			Vector3 size = ((Bounds)(ref bounds)).size;
			if (Mathf.Max(new float[3] { size.x, size.y, size.z }) < 0.015f)
			{
				return null;
			}
			Vector3 min = ((Bounds)(ref bounds)).min;
			Vector3 max = ((Bounds)(ref bounds)).max;
			Vector3[] vertices = (Vector3[])(object)new Vector3[8]
			{
				new Vector3(min.x, min.y, min.z),
				new Vector3(max.x, min.y, min.z),
				new Vector3(max.x, max.y, min.z),
				new Vector3(min.x, max.y, min.z),
				new Vector3(min.x, min.y, max.z),
				new Vector3(max.x, min.y, max.z),
				new Vector3(max.x, max.y, max.z),
				new Vector3(min.x, max.y, max.z)
			};
			int[] triangles = new int[36]
			{
				0, 2, 1, 0, 3, 2, 4, 5, 6, 4,
				6, 7, 0, 1, 5, 0, 5, 4, 2, 3,
				7, 2, 7, 6, 1, 2, 6, 1, 6, 5,
				3, 0, 4, 3, 4, 7
			};
			Mesh val = new Mesh
			{
				name = name,
				hideFlags = (HideFlags)61,
				vertices = vertices,
				triangles = triangles
			};
			val.RecalculateBounds();
			return val;
		}

		private static bool HasValidCollisionShape(Mesh mesh)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (mesh.isReadable && mesh.vertexCount >= 3)
			{
				return HasValidVertexSet(mesh.vertices, mesh.bounds);
			}
			return false;
		}

		private static bool HasValidVertexSet(IReadOnlyList<Vector3> vertices, Bounds bounds)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0022: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 size = ((Bounds)(ref bounds)).size;
			if (Mathf.Max(new float[3] { size.x, size.y, size.z }) < 0.015f)
			{
				return false;
			}
			HashSet<Vector3Int> hashSet = new HashSet<Vector3Int>();
			for (int i = 0; i < vertices.Count; i++)
			{
				Vector3 val = vertices[i];
				hashSet.Add(new Vector3Int(Mathf.RoundToInt(val.x * 10000f), Mathf.RoundToInt(val.y * 10000f), Mathf.RoundToInt(val.z * 10000f)));
				if (hashSet.Count >= 3)
				{
					return true;
				}
			}
			return false;
		}

		private static void AddFallbackBox(Transform root, OutboundValuableDefinition definition)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			Bounds val = CalculateVisualBounds(root);
			GameObject val2 = new GameObject("OutboundValuableFallbackGrabBounds");
			val2.transform.SetParent(root, false);
			val2.transform.localPosition = root.InverseTransformPoint(((Bounds)(ref val)).center);
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			Vector3 size = ((Bounds)(ref val)).size;
			Vector3 lossyScale = root.lossyScale;
			size.x = ((lossyScale.x == 0f) ? definition.GrabBoundsSize.x : (size.x / Mathf.Abs(lossyScale.x)));
			size.y = ((lossyScale.y == 0f) ? definition.GrabBoundsSize.y : (size.y / Mathf.Abs(lossyScale.y)));
			size.z = ((lossyScale.z == 0f) ? definition.GrabBoundsSize.z : (size.z / Mathf.Abs(lossyScale.z)));
			BoxCollider obj = val2.AddComponent<BoxCollider>();
			obj.center = Vector3.zero;
			obj.size = Vector3.Max(size, Vector3.one * 0.12f);
			((Collider)obj).isTrigger = false;
			ConfigureColliderObject(val2);
			val2.AddComponent<PhysGrabObjectCollider>();
			val2.AddComponent<PhysGrabObjectBoxCollider>().drawGizmos = false;
		}

		private static void ConfigureColliderObject(GameObject gameObject)
		{
			gameObject.tag = "Phys Grab Object";
			int num = LayerMask.NameToLayer("PhysGrabObject");
			if (num >= 0)
			{
				gameObject.layer = num;
			}
		}

		private static Bounds CalculateVisualBounds(Transform root)
		{
			//IL_000a: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true);
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(root.position, Vector3.one * 0.3f);
			bool flag = false;
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				if (val.enabled && !(val is ParticleSystemRenderer))
				{
					if (flag)
					{
						((Bounds)(ref bounds)).Encapsulate(val.bounds);
						continue;
					}
					bounds = val.bounds;
					flag = true;
				}
			}
			return bounds;
		}

		private static void RemoveTemplateColliders(Transform root)
		{
			PhysGrabObjectCollider[] componentsInChildren = ((Component)root).GetComponentsInChildren<PhysGrabObjectCollider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				DestroyComponent((Component)(object)componentsInChildren[i]);
			}
			PhysGrabObjectBoxCollider[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<PhysGrabObjectBoxCollider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				DestroyComponent((Component)(object)componentsInChildren2[i]);
			}
			PhysGrabObjectMeshCollider[] componentsInChildren3 = ((Component)root).GetComponentsInChildren<PhysGrabObjectMeshCollider>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				DestroyComponent((Component)(object)componentsInChildren3[i]);
			}
			Collider[] componentsInChildren4 = ((Component)root).GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				DestroyComponent((Component)(object)componentsInChildren4[i]);
			}
		}

		private static void DestroyComponent(Component component)
		{
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
		}

		private static void DestroyMesh(Mesh? mesh)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mesh != (Object)null && (((Object)mesh).hideFlags & 0x3D) != 0)
			{
				Object.DestroyImmediate((Object)(object)mesh);
			}
		}
	}
	internal sealed class OutboundValuableGrabFeedback : MonoBehaviour
	{
		private OutboundValuableDefinition? _definition;

		private PhysGrabObject? _physGrabObject;

		private AudioSource? _audioSource;

		private Transform? _visualRoot;

		private AudioClip[] _audioClips = Array.Empty<AudioClip>();

		private Animator[] _animators = Array.Empty<Animator>();

		private Animation[] _animations = Array.Empty<Animation>();

		private Vector3 _visualBasePosition;

		private Quaternion _visualBaseRotation;

		private Vector3 _visualBaseScale = Vector3.one;

		private bool _wasGrabbed;

		private int _grabCount;

		private float _nextSoundTime;

		private float _animationStopAt;

		private float _proceduralGrabUntil;

		[SerializeField]
		private string _prefabName = "";

		[SerializeField]
		private string[] _grabSoundNames = Array.Empty<string>();

		[SerializeField]
		private bool _playGrabAnimation;

		public void Configure(OutboundValuableDefinition definition)
		{
			_definition = definition;
			_prefabName = definition.PrefabName;
			_grabSoundNames = definition.GrabSoundNames;
			_playGrabAnimation = definition.PlayGrabAnimation;
			_audioClips = OutboundValuableBundleVisuals.GetGrabAudioClips(definition);
		}

		private void Start()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			ResolveDefinition();
			_physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			_visualRoot = ((Component)this).transform.Find("OutboundValuableVisual");
			if ((Object)(object)_visualRoot != (Object)null)
			{
				_visualBasePosition = _visualRoot.localPosition;
				_visualBaseRotation = _visualRoot.localRotation;
				_visualBaseScale = _visualRoot.localScale;
			}
			_animators = ((Component)this).GetComponentsInChildren<Animator>(true);
			_animations = ((Component)this).GetComponentsInChildren<Animation>(true);
			if (_playGrabAnimation)
			{
				StopGrabAnimation();
			}
			if (_audioClips.Length != 0)
			{
				_audioSource = ((Component)this).gameObject.GetComponent<AudioSource>() ?? ((Component)this).gameObject.AddComponent<AudioSource>();
				_audioSource.playOnAwake = false;
				_audioSource.spatialBlend = 1f;
				_audioSource.rolloffMode = (AudioRolloffMode)1;
				_audioSource.minDistance = 1.5f;
				_audioSource.maxDistance = 18f;
				_audioSource.dopplerLevel = 0f;
			}
		}

		private void Update()
		{
			if (!((Object)(object)_physGrabObject == (Object)null))
			{
				bool flag = RepoValuableAccess.IsGrabbedForVoice(_physGrabObject);
				if (flag && !_wasGrabbed)
				{
					OnGrabbed();
				}
				_wasGrabbed = flag;
				UpdateProceduralAnimation();
				if (_animationStopAt > 0f && Time.time >= _animationStopAt)
				{
					StopGrabAnimation();
				}
			}
		}

		private void OnGrabbed()
		{
			_grabCount++;
			_proceduralGrabUntil = Time.time + 0.8f;
			PlayGrabAnimation();
			PlayGrabSound();
		}

		private void PlayGrabAnimation()
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			if (!_playGrabAnimation)
			{
				return;
			}
			float num = 0f;
			Animator[] animators = _animators;
			foreach (Animator val in animators)
			{
				if (!((Object)(object)val == (Object)null))
				{
					((Behaviour)val).enabled = true;
					val.speed = 1f;
					RuntimeAnimatorController runtimeAnimatorController = val.runtimeAnimatorController;
					AnimationClip[] array = (((Object)(object)runtimeAnimatorController == (Object)null) ? Array.Empty<AnimationClip>() : runtimeAnimatorController.animationClips);
					if (array.Length == 0)
					{
						val.Rebind();
						val.Update(0f);
						continue;
					}
					AnimationClip val2 = array[Mathf.Abs(_grabCount) % array.Length];
					num = Mathf.Max(num, val2.length);
					val.Rebind();
					val.Play(((Object)val2).name, 0, 0f);
					val.Update(0f);
				}
			}
			Animation[] animations = _animations;
			foreach (Animation val3 in animations)
			{
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				{
					IEnumerator enumerator = val3.GetEnumerator();
					try
					{
						if (enumerator.MoveNext())
						{
							AnimationState val4 = (AnimationState)enumerator.Current;
							num = Mathf.Max(num, val4.length);
							val3.Stop();
							val3.Play(val4.name);
						}
					}
					finally
					{
						IDisposable disposable = enumerator as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
			}
			if (_animators.Length != 0 || _animations.Length != 0)
			{
				_animationStopAt = Time.time + Mathf.Clamp((num <= 0f) ? 1.2f : num, 0.4f, 4f);
			}
		}

		private void StopGrabAnimation()
		{
			Animator[] animators = _animators;
			foreach (Animator val in animators)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.Update(0f);
					((Behaviour)val).enabled = false;
				}
			}
			Animation[] animations = _animations;
			foreach (Animation val2 in animations)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.Stop();
				}
			}
			_animationStopAt = 0f;
		}

		private void UpdateProceduralAnimation()
		{
			//IL_0040: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_visualRoot == (Object)null))
			{
				bool flag = _prefabName.Contains("Dog", StringComparison.OrdinalIgnoreCase);
				float num = _proceduralGrabUntil - Time.time;
				if (!flag && num <= 0f)
				{
					_visualRoot.localPosition = _visualBasePosition;
					_visualRoot.localRotation = _visualBaseRotation;
					_visualRoot.localScale = _visualBaseScale;
					return;
				}
				float num2 = (flag ? Mathf.Sin(Time.time * 3.6f) : 0f);
				float num3 = Mathf.Clamp01(num / 0.8f);
				float num4 = ((num3 > 0f) ? (Mathf.Sin((1f - num3) * MathF.PI * 7f) * num3) : 0f);
				Vector3 localPosition = _visualBasePosition + new Vector3(0f, num2 * 0.012f + Mathf.Abs(num4) * 0.035f, 0f);
				Quaternion localRotation = _visualBaseRotation * Quaternion.Euler(num4 * 10f, num2 * 3f, num4 * -7f);
				Vector3 localScale = _visualBaseScale * (1f + Mathf.Abs(num4) * 0.035f);
				_visualRoot.localPosition = localPosition;
				_visualRoot.localRotation = localRotation;
				_visualRoot.localScale = localScale;
			}
		}

		private void PlayGrabSound()
		{
			if (!((Object)(object)_audioSource == (Object)null) && _audioClips.Length != 0 && !(Time.time < _nextSoundTime))
			{
				_nextSoundTime = Time.time + 0.25f;
				AudioClip val = _audioClips[Random.Range(0, _audioClips.Length)];
				_audioSource.pitch = Random.Range(0.94f, 1.06f);
				_audioSource.PlayOneShot(val, 0.92f);
			}
		}

		private void ResolveDefinition()
		{
			if (_definition == null)
			{
				if (string.IsNullOrWhiteSpace(_prefabName))
				{
					_prefabName = ((Object)((Component)this).gameObject).name;
				}
				_definition = OutboundValuableDefinitions.FindByPrefabName(_prefabName) ?? OutboundValuableDefinitions.FindByPrefabName(((Object)((Component)this).gameObject).name);
			}
			if (_definition != null)
			{
				_prefabName = _definition.PrefabName;
				_grabSoundNames = _definition.GrabSoundNames;
				_playGrabAnimation = _definition.PlayGrabAnimation;
				_audioClips = OutboundValuableBundleVisuals.GetGrabAudioClips(_definition);
			}
			else if (_audioClips.Length == 0 && _grabSoundNames.Length != 0)
			{
				_audioClips = OutboundValuableBundleVisuals.GetGrabAudioClips(_grabSoundNames, _prefabName);
			}
		}
	}
	internal sealed class OutboundValuableGrabGlow : MonoBehaviour
	{
		private readonly List<Material> _materials = new List<Material>();

		private PhysGrabObject? _physGrabObject;

		[SerializeField]
		private Color _glowColor = Color.cyan;

		private bool _wasGrabbed;

		public void Configure(Color glowColor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			_glowColor = glowColor;
		}

		private void Start()
		{
			_physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!val.enabled)
				{
					continue;
				}
				Material[] materials = val.materials;
				foreach (Material val2 in materials)
				{
					if ((Object)(object)val2 != (Object)null && val2.HasProperty("_EmissionColor"))
					{
						val2.EnableKeyword("_EMISSION");
						_materials.Add(val2);
					}
				}
			}
		}

		private void Update()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_physGrabObject == (Object)null)
			{
				return;
			}
			bool flag = RepoValuableAccess.IsGrabbed(_physGrabObject);
			if (flag == _wasGrabbed)
			{
				return;
			}
			_wasGrabbed = flag;
			Color val = (flag ? (_glowColor * 1.35f) : Color.black);
			foreach (Material material in _materials)
			{
				if ((Object)(object)material != (Object)null)
				{
					material.SetColor("_EmissionColor", val);
				}
			}
		}
	}
	internal sealed class OutboundValuablePrefabFactory
	{
		private static readonly List<string> GenericPreset = new List<string> { "Valuables - Generic" };

		private readonly ManualLogSource _log;

		private readonly Dictionary<Type, GameObject> _templates = new Dictionary<Type, GameObject>();

		private GameObject? _prefabBank;

		public OutboundValuablePrefabFactory(ManualLogSource log)
		{
			_log = log;
		}

		public bool TryRegisterAll()
		{
			//IL_002a: 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)
			ResolveTemplates();
			if (_templates.Count == 0)
			{
				return false;
			}
			int num = 0;
			OutboundValuableDefinition[] all = OutboundValuableDefinitions.All;
			foreach (OutboundValuableDefinition outboundValuableDefinition in all)
			{
				GameObject template = GetTemplate(outboundValuableDefinition.VolumeType);
				if ((Object)(object)template == (Object)null)
				{
					_log.LogWarning((object)$"Skipping {outboundValuableDefinition.DisplayName}: no template valuable exists for {outboundValuableDefinition.VolumeType}.");
					continue;
				}
				if (Valuables.RegisterValuable(CreatePrefab(outboundValuableDefinition, template), GenericPreset) == null)
				{
					_log.LogWarning((object)("REPOLib rejected " + outboundValuableDefinition.DisplayName + "."));
					continue;
				}
				num++;
				_log.LogInfo((object)("Registered " + outboundValuableDefinition.DisplayName + " from " + outboundValuableDefinition.SourceReference + "."));
			}
			return num > 0;
		}

		private void ResolveTemplates()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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)
			_templates.Clear();
			foreach (LevelValuables value in ValuablePresets.AllValuablePresets.Values)
			{
				Type[] volumeTypes = OutboundValuableVisuals.VolumeTypes;
				foreach (Type val in volumeTypes)
				{
					if (!_templates.ContainsKey(val))
					{
						GameObject val2 = FindTemplateInList(RepoValuableAccess.GetList(value, val));
						if ((Object)(object)val2 != (Object)null)
						{
							_templates.Add(val, val2);
						}
					}
				}
			}
		}

		private static GameObject? FindTemplateInList(List<PrefabRef>? prefabRefs)
		{
			if (prefabRefs == null)
			{
				return null;
			}
			foreach (PrefabRef prefabRef in prefabRefs)
			{
				if (prefabRef != null && prefabRef.IsValid())
				{
					GameObject prefab = prefabRef.Prefab;
					if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<ValuableObject>() != (Object)null)
					{
						return prefab;
					}
				}
			}
			return null;
		}

		private GameObject? GetTemplate(Type type)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (_templates.TryGetValue(type, out GameObject value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			if (_templates.TryGetValue((Type)2, out value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			foreach (GameObject value2 in _templates.Values)
			{
				if ((Object)(object)value2 != (Object)null)
				{
					return value2;
				}
			}
			return null;
		}

		private GameObject CreatePrefab(OutboundValuableDefinition definition, GameObject template)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = EnsurePrefabBank();
			GameObject val2 = Object.Instantiate<GameObject>(template, val.transform, false);
			((Object)val2).name = definition.PrefabName;
			((Object)val2).hideFlags = (HideFlags)61;
			val2.SetActive(true);
			RepoValuableAccess.ConfigureValuable(val2.GetComponent<ValuableObject>(), definition);
			DisableTemplateRenderers(val2);
			if (!OutboundValuableBundleVisuals.TryAttach(val2.transform, definition))
			{
				OutboundValuableVisuals.Build(val2.transform, definition);
			}
			OutboundValuableGrabBounds.Add(val2.transform, definition);
			if (definition.GrabGlow)
			{
				(val2.GetComponent<OutboundValuableGrabGlow>() ?? val2.AddComponent<OutboundValuableGrabGlow>()).Configure(definition.Accent);
			}
			(val2.GetComponent<OutboundValuableGrabFeedback>() ?? val2.AddComponent<OutboundValuableGrabFeedback>()).Configure(definition);
			return val2;
		}

		private GameObject EnsurePrefabBank()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			if ((Object)(object)_prefabBank != (Object)null)
			{
				return _prefabBank;
			}
			_prefabBank = new GameObject("OutboundValuables Prefab Bank")
			{
				hideFlags = (HideFlags)61
			};
			_prefabBank.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)_prefabBank);
			return _prefabBank;
		}

		private static void DisableTemplateRenderers(GameObject prefab)
		{
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Empress.REPO.OutboundValuables", "Outbound Valuables", "1.0.0")]
	public sealed class OutboundValuablesPlugin : BaseUnityPlugin
	{
		internal const string PluginGuid = "Empress.REPO.OutboundValuables";

		internal const string PluginName = "Outbound Valuables";

		internal const string PluginVersion = "1.0.0";

		private static readonly Harmony Harmony = new Harmony("Empress.REPO.OutboundValuables");

		private bool _registrationStarted;

		private bool _registered;

		internal static ManualLogSource Log { get; private set; } = null;


		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			Harmony.PatchAll(typeof(OutboundValuablesPlugin).Assembly);
			((MonoBehaviour)this).StartCoroutine(RegisterWhenREPOLibIsReady());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Outbound Valuables v1.0.0 loaded.");
		}

		private IEnumerator RegisterWhenREPOLibIsReady()
		{
			if (!_registrationStarted)
			{
				_registrationStarted = true;
				while ((Object)(object)RunManager.instance == (Object)null || ValuablePresets.AllValuablePresets.Count == 0)
				{
					yield return null;
				}
				yield return null;
				OutboundValuableBundleVisuals.Initialize(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? string.Empty, ((BaseUnityPlugin)this).Logger);
				OutboundValuablePrefabFactory outboundValuablePrefabFactory = new OutboundValuablePrefabFactory(((BaseUnityPlugin)this).Logger);
				_registered = outboundValuablePrefabFactory.TryRegisterAll();
				((BaseUnityPlugin)this).Logger.LogInfo((object)(_registered ? $"Registered {OutboundValuableDefinitions.All.Length} Outbound valuables with REPOLib." : "Outbound valuables could not be registered because no vanilla valuable templates were available."));
			}
		}
	}
	internal static class OutboundValuableVisuals
	{
		public static readonly Type[] VolumeTypes;

		public static void Build(Transform root, OutboundValuableDefinition definition)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("OutboundValuableProceduralVisual");
			val.transform.SetParent(root, false);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one;
			string text = definition.PrefabName.ToLowerInvariant();
			if (text.Contains("dog"))
			{
				BuildDog(val.transform, definition);
			}
			else if (text.Contains("van"))
			{
				BuildVan(val.transform, definition);
			}
			else
			{
				BuildProp(val.transform, definition);
			}
		}

		private static void BuildDog(Transform root, OutboundValuableDefinition definition)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			Material material = MaterialFor(definition.PrefabName + " Body", definition.Primary);
			Material material2 = MaterialFor(definition.PrefabName + " Accent", definition.Accent, emission: true);
			AddSphere(root, "Body", new Vector3(0f, 0.34f, 0f), new Vector3(0.34f, 0.2f, 0.2f), material);
			AddSphere(root, "Head", new Vector3(0f, 0.5f, -0.24f), new Vector3(0.18f, 0.16f, 0.16f), material);
			AddCube(root, "Ears", new Vector3(0f, 0.62f, -0.24f), new Vector3(0.34f, 0.06f, 0.08f), material2);
			AddCylinder(root, "Stand", new Vector3(0f, 0.035f, 0f), Quaternion.identity, new Vector3(0.56f, 0.035f, 0.56f), MaterialFor(definition.PrefabName + " Stand", definition.Secondary));
		}

		private static void BuildVan(Transform root, OutboundValuableDefinition definition)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			Material material = MaterialFor(definition.PrefabName + " Body", definition.Primary);
			Material material2 = MaterialFor(definition.PrefabName + " Trim", definition.Secondary);
			Material material3 = MaterialFor(definition.PrefabName + " Lights", definition.Accent, emission: true);
			AddCube(root, "Body", new Vector3(0f, 0.35f, 0f), new Vector3(0.78f, 0.36f, 0.42f), material);
			AddCube(root, "Cabin", new Vector3(0.16f, 0.58f, 0f), new Vector3(0.4f, 0.22f, 0.38f), material2);
			AddCube(root, "Lights", new Vector3(0.4f, 0.36f, -0.22f), new Vector3(0.22f, 0.06f, 0.025f), material3);
			AddCylinder(root, "Front Wheel", new Vector3(0.26f, 0.14f, -0.25f), Quaternion.Euler(90f, 0f, 0f), new Vector3(0.13f, 0.08f, 0.13f), material2);
			AddCylinder(root, "Rear Wheel", new Vector3(-0.26f, 0.14f, -0.25f), Quaternion.Euler(90f, 0f, 0f), new Vector3(0.13f, 0.08f, 0.13f), material2);
		}

		private static void BuildProp(Transform root, OutboundValuableDefinition definition)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			Material material = MaterialFor(definition.PrefabName + " Primary", definition.Primary);
			Material material2 = MaterialFor(definition.PrefabName + " Secondary", definition.Secondary);
			Material material3 = MaterialFor(definition.PrefabName + " Accent", definition.Accent, emission: true);
			AddCube(root, "Core", new Vector3(0f, 0.36f, 0f), new Vector3(0.5f, 0.52f, 0.38f), material);
			AddCube(root, "Face", new Vector3(0f, 0.42f, -0.2f), new Vector3(0.42f, 0.2f, 0.025f), material3);
			AddCylinder(root, "Base", new Vector3(0f, 0.035f, 0f), Quaternion.identity, new Vector3(0.58f, 0.035f, 0.58f), material2);
		}

		private static GameObject AddCube(Transform parent, string name, Vector3 localPosition, Vector3 localScale, Material material)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return AddPrimitive(parent, name, (PrimitiveType)3, localPosition, Quaternion.identity, localScale, material);
		}

		private static GameObject AddSphere(Transform parent, string name, Vector3 localPosition, Vector3 localScale, Material material)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return AddPrimitive(parent, name, (PrimitiveType)0, localPosition, Quaternion.identity, localScale, material);
		}

		private static GameObject AddCylinder(Transform parent, string name, Vector3 localPosition, Quaternion localRotation, Vector3 localScale, Material material)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: 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)
			return AddPrimitive(parent, name, (PrimitiveType)2, localPosition, localRotation, localScale, material);
		}

		private static GameObject AddPrimitive(Transform parent, string name, PrimitiveType primitiveType, Vector3 localPosition, Quaternion localRotation, Vector3 localScale, Material material)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(primitiveType);
			((Object)obj).name = name;
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = localPosition;
			obj.transform.localRotation = localRotation;
			obj.transform.localScale = localScale;
			Collider component = obj.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			obj.GetComponent<Renderer>().sharedMaterial = material;
			return obj;
		}

		private static Material MaterialFor(string name, Color color, bool emission = false)
		{
			//IL_000a: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_003a: 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)
			Material val = new Material(Shader.Find("Standard"))
			{
				name = name,
				color = color,
				hideFlags = (HideFlags)61
			};
			if (emission)
			{
				val.EnableKeyword("_EMISSION");
				val.SetColor("_EmissionColor", color * 0.85f);
			}
			return val;
		}

		static OutboundValuableVisuals()
		{
			Type[] array = new Type[7];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			VolumeTypes = (Type[])(object)array;
		}
	}
	internal static class RepoValuableAccess
	{
		private static readonly FieldRef<LevelValuables, List<PrefabRef>> TinyRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("tiny");

		private static readonly FieldRef<LevelValuables, List<PrefabRef>> SmallRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("small");

		private static readonly FieldRef<LevelValuables, List<PrefabRef>> MediumRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("medium");

		private static readonly FieldRef<LevelValuables, List<PrefabRef>> BigRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("big");

		private static readonly FieldRef<LevelValuables, List<PrefabRef>> WideRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("wide");

		private static readonly FieldRef<LevelValuables, List<PrefabRef>> TallRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("tall");

		private static readonly FieldRef<LevelValuables, List<PrefabRef>> VeryTallRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("veryTall");

		private static readonly FieldRef<ValuableObject, Value> ValuePresetRef = AccessTools.FieldRefAccess<ValuableObject, Value>("valuePreset");

		private static readonly FieldRef<ValuableObject, Durability> DurabilityPresetRef = AccessTools.FieldRefAccess<ValuableObject, Durability>("durabilityPreset");

		private static readonly FieldRef<ValuableObject, PhysAttribute> PhysAttributePresetRef = AccessTools.FieldRefAccess<ValuableObject, PhysAttribute>("physAttributePreset");

		private static readonly FieldRef<ValuableObject, Type> VolumeTypeRef = AccessTools.FieldRefAccess<ValuableObject, Type>("volumeType");

		private static readonly FieldRef<ValuableObject, int> DollarValueOverrideRef = AccessTools.FieldRefAccess<ValuableObject, int>("dollarValueOverride");

		private static readonly FieldRef<ValuableObject, bool> DebugVolumeRef = AccessTools.FieldRefAccess<ValuableObject, bool>("debugVolume");

		private static readonly FieldRef<ValuableObject, Gradient> ParticleColorsRef = AccessTools.FieldRefAccess<ValuableObject, Gradient>("particleColors");

		private static readonly FieldRef<Value, float> ValueMinRef = AccessTools.FieldRefAccess<Value, float>("valueMin");

		private static readonly FieldRef<Value, float> ValueMaxRef = AccessTools.FieldRefAccess<Value, float>("valueMax");

		private static readonly FieldRef<Durability, float> FragilityRef = AccessTools.FieldRefAccess<Durability, float>("fragility");

		private static readonly FieldRef<Durability, float> DurabilityRef = AccessTools.FieldRefAccess<Durability, float>("durability");

		private static readonly FieldRef<PhysAttribute, float> MassRef = AccessTools.FieldRefAccess<PhysAttribute, float>("mass");

		private static readonly FieldRef<PhysGrabObject, bool> GrabbedRef = AccessTools.FieldRefAccess<PhysGrabObject, bool>("grabbed");

		private static readonly FieldRef<PhysGrabObject, bool> GrabbedLocalRef = AccessTools.FieldRefAccess<PhysGrabObject, bool>("grabbedLocal");

		private static readonly FieldRef<PhysGrabObject, bool> HeldByLocalPlayerRef = AccessTools.FieldRefAccess<PhysGrabObject, bool>("heldByLocalPlayer");

		private static readonly FieldRef<PhysGrabObject, List<PhysGrabber>> PlayerGrabbingRef = AccessTools.FieldRefAccess<PhysGrabObject, List<PhysGrabber>>("playerGrabbing");

		public static List<PrefabRef> GetList(LevelValuables preset, Type type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected I4, but got Unknown
			return (int)type switch
			{
				0 => TinyRef.Invoke(preset), 
				1 => SmallRef.Invoke(preset), 
				2 => MediumRef.Invoke(preset), 
				3 => BigRef.Invoke(preset), 
				4 => WideRef.Invoke(preset), 
				5 => TallRef.Invoke(preset), 
				6 => VeryTallRef.Invoke(preset), 
				_ => MediumRef.Invoke(preset), 
			};
		}

		public static void ConfigureValuable(ValuableObject valuable, OutboundValuableDefinition definition)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected I4, but got Unknown
			ValuePresetRef.Invoke(valuable) = CreateValuePreset(definition);
			DurabilityPresetRef.Invoke(valuable) = CreateDurabilityPreset(definition);
			PhysAttributePresetRef.Invoke(valuable) = CreatePhysAttributePreset(definition);
			VolumeTypeRef.Invoke(valuable) = (Type)(int)definition.VolumeType;
			DollarValueOverrideRef.Invoke(valuable) = 0;
			DebugVolumeRef.Invoke(valuable) = false;
			ParticleColorsRef.Invoke(valuable) = CreateParticleGradient(definition);
		}

		public static bool IsGrabbed(PhysGrabObject physGrabObject)
		{
			return GrabbedRef.Invoke(physGrabObject);
		}

		public static bool IsGrabbedForVoice(PhysGrabObject physGrabObject)
		{
			List<PhysGrabber> list = PlayerGrabbingRef.Invoke(physGrabObject);
			if (!GrabbedRef.Invoke(physGrabObject) && !GrabbedLocalRef.Invoke(physGrabObject) && !HeldByLocalPlayerRef.Invoke(physGrabObject))
			{
				if (list != null)
				{
					return list.Count > 0;
				}
				return false;
			}
			return true;
		}

		private static Value CreateValuePreset(OutboundValuableDefinition definition)
		{
			Value val = ScriptableObject.CreateInstance<Value>();
			((Object)val).hideFlags = (HideFlags)61;
			((Object)val).name = "Value - " + definition.DisplayName;
			ValueMinRef.Invoke(val) = definition.ValueMin;
			ValueMaxRef.Invoke(val) = definition.ValueMax;
			return val;
		}

		private static Durability CreateDurabilityPreset(OutboundValuableDefinition definition)
		{
			Durability val = ScriptableObject.CreateInstance<Durability>();
			((Object)val).hideFlags = (HideFlags)61;
			((Object)val).name = "Durability - " + definition.DisplayName;
			FragilityRef.Invoke(val) = Mathf.Clamp(definition.Fragility + StableJitter(definition.PrefabName, "fragility", 5.5f), 5f, 95f);
			DurabilityRef.Invoke(val) = Mathf.Clamp(definition.Durability + StableJitter(definition.PrefabName, "durability", 5.5f), 5f, 100f);
			return val;
		}

		private static PhysAttribute CreatePhysAttributePreset(OutboundValuableDefinition definition)
		{
			PhysAttribute val = ScriptableObject.CreateInstance<PhysAttribute>();
			((Object)val).hideFlags = (HideFlags)61;
			((Object)val).name = "PhysAttribute - " + definition.DisplayName;
			MassRef.Invoke(val) = definition.Mass;
			return val;
		}

		private static float StableJitter(string name, string salt, float radius)
		{
			uint num = 2166136261u;
			string text = name + ":" + salt;
			for (int i = 0; i < text.Length; i++)
			{
				num ^= text[i];
				num *= 16777619;
			}
			return ((float)(num & 0xFFFFu) / 65535f * 2f - 1f) * radius;
		}

		private static Gradient CreateParticleGradient(OutboundValuableDefinition definition)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
			{
				new GradientColorKey(definition.Accent, 0f),
				new GradientColorKey(Color.Lerp(definition.Primary, definition.Secondary, 0.6f), 0.55f),
				new GradientColorKey(definition.Secondary, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(1f, 0f),
				new GradientAlphaKey(0.8f, 0.75f),
				new GradientAlphaKey(0f, 1f)
			});
			return val;
		}
	}
}