Decompiled source of TemTem Valuables v1.0.0

TemtemValuables.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")]
[assembly: AssemblyProduct("TemtemValuables")]
[assembly: AssemblyTitle("TemtemValuables")]
[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.TemtemValuables
{
	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 readonly Type[] VolumeTypes;

		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, TemtemValuableDefinition 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 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(TemtemValuableDefinition 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(TemtemValuableDefinition definition)
		{
			Durability val = ScriptableObject.CreateInstance<Durability>();
			((Object)val).hideFlags = (HideFlags)61;
			((Object)val).name = "Durability - " + definition.DisplayName;
			FragilityRef.Invoke(val) = Mathf.Clamp(definition.Fragility, 5f, 95f);
			DurabilityRef.Invoke(val) = Mathf.Clamp(definition.Durability, 5f, 100f);
			return val;
		}

		private static PhysAttribute CreatePhysAttributePreset(TemtemValuableDefinition 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 Gradient CreateParticleGradient(TemtemValuableDefinition 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_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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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)
			//IL_005c: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
			{
				new GradientColorKey(definition.Accent, 0f),
				new GradientColorKey(Color.Lerp(definition.Accent, Color.white, 0.35f), 0.5f),
				new GradientColorKey(Color.Lerp(definition.Accent, Color.black, 0.25f), 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(1f, 0f),
				new GradientAlphaKey(0.8f, 0.75f),
				new GradientAlphaKey(0f, 1f)
			});
			return val;
		}

		static RepoValuableAccess()
		{
			Type[] array = new Type[7];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			VolumeTypes = (Type[])(object)array;
		}
	}
	internal static class TemtemValuableBounds
	{
		private const int MaxColliderTriangles = 48;

		private const float MinColliderExtent = 0.015f;

		public static void Add(Transform root, TemtemValuableDefinition definition)
		{
			RemoveTemplateColliders(root);
			if (AddMeshColliders(root) == 0)
			{
				AddFallbackMesh(root, definition);
				TemtemValuablesPlugin.Log.LogWarning((object)(definition.DisplayName + " had no usable renderer meshes for grab colliders."));
			}
		}

		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 + "_TemtemGrabCollider",
					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 + "_TemtemGrabCollider");
			if ((Object)(object)val4 == (Object)null && (Object)(object)val != (Object)null)
			{
				val4 = CreateBoxMesh(val.bounds, ((Object)renderer).name + "_TemtemGrabCollider");
			}
			DestroyMesh(val2);
			return val4;
		}

		private static Mesh? CreateReducedMesh(Mesh? sourceMesh, string name)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_010f: Expected O, but got Unknown
			//IL_0096: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)sourceMesh == (Object)null || !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, 48);
			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 void AddFallbackMesh(Transform root, TemtemValuableDefinition 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_0012: Expected O, but got Unknown
			//IL_0028: 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_003d: 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_0059: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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)
			Bounds val = CalculateVisualBounds(root);
			GameObject val2 = new GameObject("Empress Temtem Grab Mesh");
			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 val3 = WorldSizeToLocalSize(((Bounds)(ref val)).size, root.lossyScale);
			Mesh val4 = CreateBoxMesh(new Bounds(Vector3.zero, Vector3.Max(val3, Vector3.one * 0.18f)), definition.PrefabName + "_TemtemFallbackMesh");
			if (!((Object)(object)val4 == (Object)null))
			{
				MeshCollider obj = val2.AddComponent<MeshCollider>();
				obj.cookingOptions = (MeshColliderCookingOptions)14;
				obj.convex = true;
				((Collider)obj).isTrigger = false;
				obj.sharedMesh = val4;
				ConfigureColliderObject(val2);
				val2.AddComponent<PhysGrabObjectCollider>();
				val2.AddComponent<PhysGrabObjectMeshCollider>().showGizmo = false;
			}
		}

		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 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.5f);
			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 Vector3 WorldSizeToLocalSize(Vector3 size, Vector3 rootScale)
		{
			//IL_0002: 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_0015: 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_003c: 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_005c: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			size.x = ((rootScale.x == 0f) ? 1f : (size.x / Mathf.Abs(rootScale.x)));
			size.y = ((rootScale.y == 0f) ? 1f : (size.y / Mathf.Abs(rootScale.y)));
			size.z = ((rootScale.z == 0f) ? 1f : (size.z / Mathf.Abs(rootScale.z)));
			return size;
		}

		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 ConfigureColliderObject(GameObject gameObject)
		{
			gameObject.tag = "Phys Grab Object";
			int num = LayerMask.NameToLayer("PhysGrabObject");
			if (num >= 0)
			{
				gameObject.layer = num;
			}
		}

		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 static class TemtemValuableBundle
	{
		private const string BundleFileName = "temtemvaluablesassets";

		private static ManualLogSource? _log;

		private static AssetBundle? _bundle;

		private static bool _loadAttempted;

		private static GameObject[] _visualPrefabs = Array.Empty<GameObject>();

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

		public static IReadOnlyList<GameObject> VisualPrefabs => _visualPrefabs;

		public static void Initialize(string pluginDirectory, ManualLogSource log)
		{
			_log = log;
			if (_loadAttempted)
			{
				return;
			}
			_loadAttempted = true;
			string text = Path.Combine(pluginDirectory, "temtemvaluablesassets");
			if (!File.Exists(text))
			{
				log.LogWarning((object)("Empress Temtem valuable asset bundle was not found at " + text + "."));
				return;
			}
			try
			{
				foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
				{
					if (string.Equals(((Object)allLoadedAssetBundle).name, "temtemvaluablesassets", StringComparison.OrdinalIgnoreCase))
					{
						_bundle = allLoadedAssetBundle;
						LoadVisualPrefabs();
						LoadGrabClips();
						return;
					}
				}
				_bundle = AssetBundle.LoadFromFile(text);
				LoadVisualPrefabs();
				LoadGrabClips();
				log.LogInfo((object)("Loaded Empress Temtem valuable asset bundle: " + text));
			}
			catch (Exception ex)
			{
				log.LogWarning((object)("Failed to load Empress Temtem valuable asset bundle: " + ex));
				_bundle = null;
			}
		}

		public static AudioClip? GetGrabClip(TemtemValuableDefinition definition)
		{
			if (GrabClips.TryGetValue(definition.ModelId, out AudioClip value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			if (GrabClips.TryGetValue("M001", out value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			foreach (AudioClip value2 in GrabClips.Values)
			{
				if ((Object)(object)value2 != (Object)null)
				{
					return value2;
				}
			}
			return null;
		}

		public static bool TryAttach(Transform parent, GameObject visualPrefab)
		{
			//IL_0024: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)visualPrefab == (Object)null)
			{
				return false;
			}
			GameObject obj = Object.Instantiate<GameObject>(visualPrefab, parent, false);
			((Object)obj).name = "TemtemValuableVisual";
			obj.transform.localPosition = Vector3.zero;
			obj.transform.localRotation = Quaternion.identity;
			obj.transform.localScale = Vector3.one;
			((Object)obj).hideFlags = (HideFlags)52;
			SetLayerRecursively(obj.transform, ((Component)parent).gameObject.layer);
			RemoveBundleColliders(obj);
			return true;
		}

		private static void LoadVisualPrefabs()
		{
			if ((Object)(object)_bundle == (Object)null)
			{
				_visualPrefabs = Array.Empty<GameObject>();
				return;
			}
			List<GameObject> list = new List<GameObject>();
			GameObject[] array = _bundle.LoadAllAssets<GameObject>();
			foreach (GameObject val in array)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name.StartsWith("TemtemValuable_", StringComparison.OrdinalIgnoreCase))
				{
					list.Add(val);
				}
			}
			list.Sort((GameObject a, GameObject b) => string.Compare(((Object)a).name, ((Object)b).name, StringComparison.OrdinalIgnoreCase));
			_visualPrefabs = list.ToArray();
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogInfo((object)("Loaded " + _visualPrefabs.Length + " Empress Temtem valuable visuals."));
			}
		}

		private static void LoadGrabClips()
		{
			GrabClips.Clear();
			if ((Object)(object)_bundle == (Object)null)
			{
				return;
			}
			AudioClip[] array = _bundle.LoadAllAssets<AudioClip>();
			foreach (AudioClip val in array)
			{
				if (!((Object)(object)val == (Object)null) && ((Object)val).name.StartsWith("TemtemAudio_", StringComparison.OrdinalIgnoreCase))
				{
					string key = ((Object)val).name.Substring("TemtemAudio_".Length);
					GrabClips[key] = val;
				}
			}
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogInfo((object)("Loaded " + GrabClips.Count + " Empress Temtem grab sounds."));
			}
		}

		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 RemoveBundleColliders(GameObject root)
		{
			Collider[] componentsInChildren = root.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
		}
	}
	internal sealed class TemtemValuableDefinition
	{
		public string PrefabName { get; }

		public string DisplayName { get; }

		public string ModelId { 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 Accent { get; }

		public float VoiceVolume { get; }

		private TemtemValuableDefinition(string prefabName, string displayName, string modelId, Type volumeType, int valueMin, int valueMax, float fragility, float durability, float mass, Color accent, float voiceVolume)
		{
			//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)
			PrefabName = prefabName;
			DisplayName = displayName;
			ModelId = modelId;
			VolumeType = volumeType;
			ValueMin = valueMin;
			ValueMax = valueMax;
			Fragility = fragility;
			Durability = durability;
			Mass = mass;
			Accent = accent;
			VoiceVolume = voiceVolume;
		}

		public static TemtemValuableDefinition FromVisualPrefab(GameObject visualPrefab)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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)
			string name = ((Object)visualPrefab).name;
			string obj = (name.StartsWith("TemtemValuable_", StringComparison.OrdinalIgnoreCase) ? name.Substring("TemtemValuable_".Length) : name);
			string modelId = GetModelId(obj);
			string displayName = BuildDisplayName(obj);
			int num = StableHash(obj);
			int num2 = 1300 + num % 1700;
			int valueMax = num2 + 1400 + num / 17 % 2600;
			float fragility = 24f + (float)(num % 1600) / 100f;
			float durability = 72f + (float)(num % 2000) / 100f;
			float mass = 0.75f + (float)(num % 320) / 100f;
			float voiceVolume = 0.78f + (float)(num % 22) / 100f;
			Color accent = Color.HSVToRGB((float)(num % 360) / 360f, 0.72f, 1f);
			return new TemtemValuableDefinition(name, displayName, modelId, (Type)2, num2, valueMax, fragility, durability, mass, accent, voiceVolume);
		}

		private static string GetModelId(string id)
		{
			string[] array = id.Split(new char[1] { '_' }, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length != 0 && array[0].StartsWith("M", StringComparison.OrdinalIgnoreCase))
			{
				return array[0];
			}
			return id;
		}

		private static string BuildDisplayName(string id)
		{
			string[] array = id.Split(new char[1] { '_' }, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length == 0)
			{
				return "Temtem Valuable";
			}
			string text = "Temtem " + array[0].TrimStart('M');
			for (int i = 1; i < array.Length; i++)
			{
				text = text + " " + array[i];
			}
			return text;
		}

		private static int StableHash(string value)
		{
			uint num = 2166136261u;
			for (int i = 0; i < value.Length; i++)
			{
				num ^= value[i];
				num *= 16777619;
			}
			return (int)(num & 0x7FFFFFFF);
		}
	}
	internal sealed class TemtemValuableGrabAudio : MonoBehaviour
	{
		[SerializeField]
		private AudioClip? _clip;

		[SerializeField]
		private float _volume = 0.86f;

		private AudioSource? _audioSource;

		private PhysGrabObject? _physGrabObject;

		private bool _wasGrabbed;

		private float _nextAllowedTime;

		public void Configure(AudioClip clip, float volume)
		{
			_clip = clip;
			_volume = Mathf.Clamp(volume, 0f, 1.5f);
			PreloadClip();
		}

		internal void TryPlayFromGrab()
		{
			EnsureComponents();
			PreloadClip();
			if (!((Object)(object)_audioSource == (Object)null) && !((Object)(object)_clip == (Object)null) && !(Time.time < _nextAllowedTime))
			{
				_audioSource.pitch = Random.Range(0.96f, 1.05f);
				_audioSource.volume = _volume;
				_audioSource.Stop();
				_audioSource.PlayOneShot(_clip, _volume);
				_nextAllowedTime = Time.time + Mathf.Clamp(_clip.length * 0.45f, 0.65f, 2.2f);
			}
		}

		private void Awake()
		{
			EnsureComponents();
		}

		private void OnEnable()
		{
			EnsureComponents();
			PreloadClip();
			_wasGrabbed = false;
		}

		private void Update()
		{
			if (!((Object)(object)_physGrabObject == (Object)null) && !((Object)(object)_clip == (Object)null))
			{
				bool flag = RepoValuableAccess.IsGrabbedForVoice(_physGrabObject);
				if (flag && !_wasGrabbed)
				{
					TryPlayFromGrab();
				}
				_wasGrabbed = flag;
			}
		}

		private void EnsureComponents()
		{
			if ((Object)(object)_physGrabObject == (Object)null)
			{
				_physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			}
			if ((Object)(object)_audioSource == (Object)null)
			{
				_audioSource = ((Component)this).GetComponent<AudioSource>() ?? ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			_audioSource.playOnAwake = false;
			_audioSource.loop = false;
			_audioSource.spatialBlend = 0.86f;
			_audioSource.rolloffMode = (AudioRolloffMode)1;
			_audioSource.minDistance = 3.2f;
			_audioSource.maxDistance = 32f;
			_audioSource.dopplerLevel = 0f;
			_audioSource.priority = 32;
			_audioSource.ignoreListenerPause = true;
			_audioSource.volume = _volume;
		}

		private void PreloadClip()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_clip != (Object)null && (int)_clip.loadState == 0)
			{
				_clip.LoadAudioData();
			}
		}
	}
	internal static class TemtemValuableGrabAudioPatches
	{
		[HarmonyPatch(typeof(PhysGrabObject), "GrabStarted")]
		[HarmonyPostfix]
		private static void PhysGrabObjectGrabStartedPostfix(PhysGrabObject __instance)
		{
			TryPlay(__instance);
		}

		[HarmonyPatch(typeof(PhysGrabObject), "GrabLinkRPC")]
		[HarmonyPostfix]
		private static void PhysGrabObjectGrabLinkRpcPostfix(PhysGrabObject __instance)
		{
			TryPlay(__instance);
		}

		[HarmonyPatch(typeof(PhysGrabObject), "GrabPlayerAddRPC")]
		[HarmonyPostfix]
		private static void PhysGrabObjectGrabPlayerAddRpcPostfix(PhysGrabObject __instance)
		{
			TryPlay(__instance);
		}

		private static void TryPlay(PhysGrabObject physGrabObject)
		{
			((Component)physGrabObject).GetComponent<TemtemValuableGrabAudio>()?.TryPlayFromGrab();
		}
	}
	internal sealed class TemtemValuablePrefabFactory
	{
		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 TemtemValuablePrefabFactory(ManualLogSource log)
		{
			_log = log;
		}

		public int RegisterAll()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			ResolveTemplates();
			if (_templates.Count == 0)
			{
				_log.LogWarning((object)"Empress Temtem valuables could not be registered because no vanilla valuable templates were available.");
				return 0;
			}
			int num = 0;
			foreach (GameObject visualPrefab in TemtemValuableBundle.VisualPrefabs)
			{
				TemtemValuableDefinition temtemValuableDefinition = TemtemValuableDefinition.FromVisualPrefab(visualPrefab);
				string modelId = temtemValuableDefinition.ModelId;
				if ((!(modelId == "M046") && !(modelId == "M047")) || 1 == 0)
				{
					GameObject template = GetTemplate(temtemValuableDefinition.VolumeType);
					if ((Object)(object)template == (Object)null)
					{
						ManualLogSource log = _log;
						string[] obj = new string[5] { "Skipping ", temtemValuableDefinition.DisplayName, ": no valuable template exists for ", null, null };
						Type volumeType = temtemValuableDefinition.VolumeType;
						obj[3] = ((object)(Type)(ref volumeType)).ToString();
						obj[4] = ".";
						log.LogWarning((object)string.Concat(obj));
					}
					else if (Valuables.RegisterValuable(CreatePrefab(temtemValuableDefinition, visualPrefab, template), GenericPreset) == null)
					{
						_log.LogWarning((object)("REPOLib rejected " + temtemValuableDefinition.DisplayName + "."));
					}
					else
					{
						num++;
					}
				}
			}
			return num;
		}

		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 = RepoValuableAccess.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(TemtemValuableDefinition definition, GameObject visualPrefab, GameObject template)
		{
			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);
			TemtemValuableBundle.TryAttach(val2.transform, visualPrefab);
			TemtemValuableBounds.Add(val2.transform, definition);
			AudioClip grabClip = TemtemValuableBundle.GetGrabClip(definition);
			if ((Object)(object)grabClip != (Object)null)
			{
				(val2.GetComponent<TemtemValuableGrabAudio>() ?? val2.AddComponent<TemtemValuableGrabAudio>()).Configure(grabClip, definition.VoiceVolume);
			}
			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("Empress Temtem Valuables 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("com.empress.repo.temtemvaluables", "Empress Temtem Valuables", "1.0.0")]
	public sealed class TemtemValuablesPlugin : BaseUnityPlugin
	{
		internal const string PluginGuid = "com.empress.repo.temtemvaluables";

		internal const string PluginName = "Empress Temtem Valuables";

		internal const string PluginVersion = "1.0.0";

		private static readonly Harmony Harmony = new Harmony("com.empress.repo.temtemvaluables");

		private bool _registrationStarted;

		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(TemtemValuablesPlugin).Assembly);
			((MonoBehaviour)this).StartCoroutine(RegisterWhenREPOLibIsReady());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Empress Temtem 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;
				TemtemValuableBundle.Initialize(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? string.Empty, ((BaseUnityPlugin)this).Logger);
				int num = new TemtemValuablePrefabFactory(((BaseUnityPlugin)this).Logger).RegisterAll();
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Registered " + num + " Empress Temtem valuables with REPOLib."));
			}
		}
	}
}