Decompiled source of MinecraftStrongholdLevelFix v0.4.0

BepInEx/patchers/MinecraftStrongholdLevelFix.Patcher.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;

[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("MinecraftStrongholdLevelFix.Patcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0")]
[assembly: AssemblyProduct("MinecraftStrongholdLevelFix.Patcher")]
[assembly: AssemblyTitle("MinecraftStrongholdLevelFix.Patcher")]
[assembly: AssemblyVersion("0.4.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MinecraftStrongholdLevelFix.Patcher
{
	public static class ValuableVolumeVisualizerPatcher
	{
		public static IEnumerable<string> TargetDLLs { get; } = new string[1] { "Assembly-CSharp.dll" };

		public static void Patch(AssemblyDefinition assembly)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0095: 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_00a3: Expected O, but got Unknown
			//IL_00b0: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			ModuleDefinition mainModule = assembly.MainModule;
			if (mainModule.GetType("ValuableVolumeVisualizer") == null)
			{
				AssemblyNameReference val = ((IEnumerable<AssemblyNameReference>)mainModule.AssemblyReferences).First((AssemblyNameReference reference) => reference.Name == "UnityEngine.CoreModule");
				TypeReference val2 = new TypeReference("UnityEngine", "MonoBehaviour", mainModule, (IMetadataScope)(object)val);
				TypeDefinition val3 = new TypeDefinition(string.Empty, "ValuableVolumeVisualizer", (TypeAttributes)1048577, val2);
				MethodDefinition val4 = new MethodDefinition(".ctor", (MethodAttributes)6150, mainModule.TypeSystem.Void);
				MethodReference val5 = new MethodReference(".ctor", mainModule.TypeSystem.Void, val2)
				{
					HasThis = true
				};
				ILProcessor iLProcessor = val4.Body.GetILProcessor();
				iLProcessor.Append(Instruction.Create(OpCodes.Ldarg_0));
				iLProcessor.Append(Instruction.Create(OpCodes.Call, val5));
				iLProcessor.Append(Instruction.Create(OpCodes.Ret));
				val3.Methods.Add(val4);
				mainModule.Types.Add(val3);
			}
		}
	}
}

MinecraftStrongholdLevelFix.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("nezzy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0")]
[assembly: AssemblyProduct("MinecraftStrongholdLevelFix")]
[assembly: AssemblyTitle("MinecraftStrongholdLevelFix")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 MinecraftStrongholdLevelFix
{
	internal static class GoldenAppleLocalization
	{
		internal const string DisplayName = "Golden Apple";

		internal static bool IsAffectedPrefab(string name)
		{
			return name.StartsWith("MC Item Golden Apple", StringComparison.Ordinal);
		}
	}
	[HarmonyPatch(typeof(PhysGrabCart), "StateMessages")]
	internal static class MinecartCartStateMessagesPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(PhysGrabCart __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)((Component)__instance).GetComponent<MinecartReplacementMarker>() == (Object)null)
			{
				return true;
			}
			PhysGrabObject component = ((Component)__instance).GetComponent<PhysGrabObject>();
			if ((bool?)AccessTools.Field(typeof(PhysGrabObject), "grabbedLocal")?.GetValue(component) == true)
			{
				bool flag = AccessTools.Field(typeof(PhysGrabCart), "currentState")?.GetValue(__instance)?.ToString() == "Handled";
				ItemInfoExtraUI.instance.ItemInfoText(flag ? "Mode: Strong" : "Mode: Weak", flag ? new Color(0.2f, 0.8f, 0.1f) : new Color(1f, 0.46f, 0f));
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(PhysGrabCart), "ObjectsInCart")]
	internal static class MinecartCartStoragePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(PhysGrabCart __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (Object)((Component)__instance).GetComponent<MinecartReplacementMarker>() == (Object)null;
		}
	}
	[HarmonyPatch(typeof(PhysGrabCart), "StateSwitch")]
	internal static class MinecartCartVisualStatePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(PhysGrabCart __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return (Object)((Component)__instance).GetComponent<MinecartReplacementMarker>() == (Object)null;
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "OnCollisionStay")]
	internal static class MinecartImpactDetectorPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(PhysGrabObjectImpactDetector __instance, Collision __0)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			if ((Object)((Component)__instance).GetComponent<MinecartReplacementMarker>() != (Object)null)
			{
				return false;
			}
			if (__0 != null)
			{
				return (Object)((Component)__0.collider).GetComponentInParent<MinecartReplacementMarker>() == (Object)null;
			}
			return true;
		}
	}
	internal static class MinecartReplacementAssets
	{
		internal const string PrefabId = "nezzy.MinecartFix";

		internal const string PrefabAssetName = "StrongholdMinecartReplacement";

		private static bool loadRequested;

		internal static void Load(string pluginLocation)
		{
			if (loadRequested)
			{
				return;
			}
			loadRequested = true;
			string path = Path.GetDirectoryName(pluginLocation) ?? string.Empty;
			string text = Path.Combine(path, "assets", "minecart", "StrongholdMinecartReplacement.bundle");
			if (!File.Exists(text))
			{
				string text2 = Path.Combine(path, "StrongholdMinecartReplacement.bundle");
				if (!File.Exists(text2))
				{
					Plugin.Log.LogError((object)("Minecart replacement bundle is missing at '" + text + "' or '" + text2 + "'. Spawned Minecarts will remain suppressed."));
					return;
				}
				text = text2;
			}
			BundleLoader.LoadBundle(text, (Action<AssetBundle>)delegate(AssetBundle bundle)
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Expected O, but got Unknown
				GameObject val = bundle.LoadAsset<GameObject>("StrongholdMinecartReplacement");
				if ((Object)val == (Object)null)
				{
					Plugin.Log.LogError((object)"Minecart replacement bundle does not contain prefab 'StrongholdMinecartReplacement'. Spawned Minecarts will remain suppressed.");
				}
				else if (!ValidateNativeComponents(val))
				{
					Plugin.Log.LogError((object)"Minecart replacement bundle is not a complete native Small Cart prefab.");
				}
				else if (NetworkPrefabs.RegisterNetworkPrefab("nezzy.MinecartFix", val) == null)
				{
					Plugin.Log.LogError((object)"Minecart replacement prefab 'StrongholdMinecartReplacement' could not be registered for networking. Spawned Minecarts will remain suppressed.");
				}
			}, false);
		}

		internal static void ConfigureSpawnedReplacement(GameObject replacement)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			if ((Object)replacement.GetComponent<MinecartReplacementMarker>() == (Object)null)
			{
				replacement.AddComponent<MinecartReplacementMarker>();
			}
			if (!ValidateNativeComponents(replacement))
			{
				Plugin.Log.LogError((object)"Dedicated Minecart replacement is missing a native Small Cart component.");
			}
		}

		internal static bool IsReplacement(GameObject gameObject)
		{
			return ((Object)gameObject).name.StartsWith("StrongholdMinecartReplacement", StringComparison.Ordinal);
		}

		private static bool ValidateNativeComponents(GameObject prefab)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			if ((Object)prefab.GetComponent<PhotonView>() != (Object)null && (Object)prefab.GetComponent<PhotonTransformView>() != (Object)null && (Object)prefab.GetComponent<Rigidbody>() != (Object)null && (Object)prefab.GetComponent<PhysGrabObject>() != (Object)null && (Object)prefab.GetComponent<PhysGrabObjectImpactDetector>() != (Object)null && (Object)prefab.GetComponent<PhysGrabCart>() != (Object)null && (Object)prefab.GetComponent<PhysGrabObjectGrabArea>() != (Object)null && (Object)prefab.GetComponent<ItemAttributes>() != (Object)null)
			{
				return (Object)prefab.GetComponent<ItemEquippable>() != (Object)null;
			}
			return false;
		}
	}
	internal sealed class MinecartReplacementController : MonoBehaviour
	{
		private readonly MinecartSpawnPolicy spawnPolicy = new MinecartSpawnPolicy();

		private readonly Dictionary<MinecartSpawnIdentity, GameObject> suppressedMinecarts = new Dictionary<MinecartSpawnIdentity, GameObject>();

		private readonly Dictionary<string, int> positionOccurrences = new Dictionary<string, int>();

		private readonly HashSet<int> processedInstanceIds = new HashSet<int>();

		private const float UniqueVisualMatchDistanceSquared = 0.25f;

		internal static void Replace(GameObject legacyCart)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			MinecartReplacementController minecartReplacementController = Object.FindFirstObjectByType<MinecartReplacementController>();
			if ((Object)minecartReplacementController == (Object)null)
			{
				minecartReplacementController = new GameObject("Stronghold Minecart Replacement").AddComponent<MinecartReplacementController>();
				Object.DontDestroyOnLoad((Object)((Component)minecartReplacementController).gameObject);
			}
			minecartReplacementController.HandleLegacyMinecart(legacyCart);
		}

		internal static void ResetForLevelLoad()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			MinecartReplacementController minecartReplacementController = Object.FindFirstObjectByType<MinecartReplacementController>();
			if (!((Object)minecartReplacementController == (Object)null))
			{
				minecartReplacementController.spawnPolicy.ResetForLevelLoad();
				minecartReplacementController.suppressedMinecarts.Clear();
				minecartReplacementController.positionOccurrences.Clear();
				minecartReplacementController.processedInstanceIds.Clear();
			}
		}

		internal static void AttachIncomingReplacement(GameObject replacement)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0039: 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_0054: Expected O, but got Unknown
			MinecartReplacementAssets.ConfigureSpawnedReplacement(replacement);
			if (!TryGetReplacementIdentity(replacement, out MinecartSpawnIdentity identity))
			{
				Plugin.Log.LogError((object)"Dedicated Minecart replacement was spawned without valid host identity data; its local Minecart visual cannot be attached.");
				return;
			}
			MinecartReplacementController minecartReplacementController = Object.FindFirstObjectByType<MinecartReplacementController>();
			if ((Object)minecartReplacementController == (Object)null)
			{
				minecartReplacementController = new GameObject("Stronghold Minecart Replacement").AddComponent<MinecartReplacementController>();
				Object.DontDestroyOnLoad((Object)((Component)minecartReplacementController).gameObject);
			}
			((MonoBehaviour)minecartReplacementController).StartCoroutine(minecartReplacementController.AttachVisualWhenReady(replacement, identity));
		}

		private void HandleLegacyMinecart(GameObject legacyCart)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0034: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Expected O, but got Unknown
			if ((Object)legacyCart == (Object)null || !processedInstanceIds.Add(((Object)legacyCart).GetInstanceID()))
			{
				return;
			}
			Vector3 position = legacyCart.transform.position;
			Quaternion rotation = legacyCart.transform.rotation;
			MinecartSpawnIdentity minecartSpawnIdentity = CreateIdentity(position);
			ValidateSpawnedMinecartPreset(legacyCart, minecartSpawnIdentity);
			legacyCart.SetActive(false);
			suppressedMinecarts[minecartSpawnIdentity] = legacyCart;
			AttachWaitingReplacements();
			bool isHost = !SemiFunc.IsMultiplayer() || PhotonNetwork.IsMasterClient;
			if (!spawnPolicy.TryClaim(minecartSpawnIdentity, isHost))
			{
				return;
			}
			PrefabRef val = null;
			if (!NetworkPrefabs.TryGetNetworkPrefabRef("nezzy.MinecartFix", ref val))
			{
				Plugin.Log.LogError((object)$"Minecart {minecartSpawnIdentity} was spawned, but the dedicated replacement prefab is not registered. The malformed original remains suppressed.");
				return;
			}
			GameObject val2 = NetworkPrefabs.SpawnNetworkPrefab(val, position, rotation, (byte)0, new object[7] { 1f, 1f, 1f, minecartSpawnIdentity.XMillimeters, minecartSpawnIdentity.YMillimeters, minecartSpawnIdentity.ZMillimeters, minecartSpawnIdentity.Occurrence });
			if ((Object)val2 == (Object)null)
			{
				Plugin.Log.LogError((object)$"Minecart {minecartSpawnIdentity} could not be network-spawned by the host. The malformed original remains suppressed.");
				return;
			}
			((Object)val2).name = "Minecart";
			if ((Object)val2.GetComponent<MinecartReplacementMarker>() == (Object)null)
			{
				val2.AddComponent<MinecartReplacementMarker>();
			}
			AttachVisual(val2, minecartSpawnIdentity);
			Plugin.Log.LogInfo((object)"Broken Minecart found and replaced.");
		}

		private MinecartSpawnIdentity CreateIdentity(Vector3 position)
		{
			//IL_0005: 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_0029: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			string key = $"{Math.Round(position.x, 3)}:{Math.Round(position.y, 3)}:{Math.Round(position.z, 3)}";
			positionOccurrences.TryGetValue(key, out var value);
			positionOccurrences[key] = value + 1;
			return MinecartSpawnIdentity.FromPosition(position.x, position.y, position.z, value);
		}

		private bool AttachVisual(GameObject replacement, MinecartSpawnIdentity identity, bool logFailure = true)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Expected O, but got Unknown
			//IL_01a4: Expected O, but got Unknown
			if ((Object)replacement.transform.Find("Minecart Visual") != (Object)null)
			{
				return true;
			}
			if (!suppressedMinecarts.TryGetValue(identity, out GameObject value))
			{
				value = FindUniqueLocalMinecartNear(identity);
				if ((Object)value == (Object)null)
				{
					return false;
				}
			}
			MeshRenderer val = Array.Find(value.GetComponentsInChildren<MeshRenderer>(true), (MeshRenderer candidate) => ((Object)candidate).name == "Cart Mesh");
			MeshFilter val2 = (((Object)val == (Object)null) ? null : ((Component)val).GetComponent<MeshFilter>());
			if ((Object)val2 == (Object)null || (Object)val2.sharedMesh == (Object)null)
			{
				return false;
			}
			Material fallbackMaterial = FindNativeFallbackMaterial(replacement);
			GameObject val3 = new GameObject("Minecart Visual");
			val3.transform.SetParent(replacement.transform, false);
			Transform transform = ((Component)val).transform;
			val3.transform.localPosition = value.transform.InverseTransformPoint(transform.position);
			val3.transform.localRotation = Quaternion.Inverse(value.transform.rotation) * transform.rotation;
			val3.transform.localScale = transform.localScale;
			val3.AddComponent<MeshFilter>().sharedMesh = val2.sharedMesh;
			MeshRenderer obj = val3.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterials = CompatibleMaterials(((Renderer)val).sharedMaterials, fallbackMaterial);
			((Renderer)obj).shadowCastingMode = ((Renderer)val).shadowCastingMode;
			((Renderer)obj).receiveShadows = ((Renderer)val).receiveShadows;
			Renderer[] componentsInChildren = replacement.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val4 in componentsInChildren)
			{
				if ((Object)((Component)val4).gameObject != (Object)val3 && ((Object)((Component)val4).gameObject).name != "Minecart Strong Grab Marker")
				{
					val4.enabled = false;
				}
			}
			Canvas[] componentsInChildren2 = replacement.GetComponentsInChildren<Canvas>(true);
			for (int num = 0; num < componentsInChildren2.Length; num++)
			{
				((Behaviour)componentsInChildren2[num]).enabled = false;
			}
			return true;
		}

		private GameObject? FindUniqueLocalMinecartNear(MinecartSpawnIdentity identity)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor((float)identity.XMillimeters / 1000f, (float)identity.YMillimeters / 1000f, (float)identity.ZMillimeters / 1000f);
			List<GameObject> list = new List<GameObject>();
			foreach (GameObject value in suppressedMinecarts.Values)
			{
				if ((Object)value != (Object)null && Vector3.SqrMagnitude(value.transform.position - val) <= 0.25f)
				{
					list.Add(value);
				}
			}
			if (list.Count != 1)
			{
				return null;
			}
			return list[0];
		}

		private static Material? FindNativeFallbackMaterial(GameObject replacement)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			MeshRenderer[] componentsInChildren = replacement.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val in componentsInChildren)
			{
				if ((Object)((Renderer)val).sharedMaterial != (Object)null && (Object)((Renderer)val).sharedMaterial.shader != (Object)null)
				{
					return ((Renderer)val).sharedMaterial;
				}
			}
			return null;
		}

		private static Material[] CompatibleMaterials(Material[] materials, Material? fallbackMaterial)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			Material[] array = (Material[])(object)new Material[materials.Length];
			for (int i = 0; i < materials.Length; i++)
			{
				Material val = materials[i];
				if ((Object)val == (Object)null || (Object)val.shader != (Object)null || (Object)(((Object)(object)fallbackMaterial != (Object)null) ? fallbackMaterial.shader : null) == (Object)null)
				{
					array[i] = val;
					continue;
				}
				array[i] = new Material(fallbackMaterial.shader)
				{
					mainTexture = val.mainTexture,
					color = val.color
				};
			}
			return array;
		}

		private void AttachWaitingReplacements()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			PhysGrabCart[] array = Object.FindObjectsByType<PhysGrabCart>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				GameObject gameObject = ((Component)array[i]).gameObject;
				if ((MinecartReplacementAssets.IsReplacement(gameObject) || (Object)gameObject.GetComponent<MinecartReplacementMarker>() != (Object)null) && TryGetReplacementIdentity(gameObject, out MinecartSpawnIdentity identity))
				{
					AttachVisual(gameObject, identity, logFailure: false);
				}
			}
		}

		private IEnumerator AttachVisualWhenReady(GameObject replacement, MinecartSpawnIdentity identity)
		{
			for (int frame = 0; frame < 300; frame++)
			{
				if ((Object)replacement == (Object)null)
				{
					break;
				}
				if (AttachVisual(replacement, identity, logFailure: false))
				{
					break;
				}
				yield return null;
			}
		}

		private static bool TryGetReplacementIdentity(GameObject replacement, out MinecartSpawnIdentity identity)
		{
			PhotonView component = replacement.GetComponent<PhotonView>();
			object[] array = (((Object)(object)component != (Object)null) ? component.InstantiationData : null);
			if (array == null || array.Length != 7 || !(array[3] is int num) || !(array[4] is int num2) || !(array[5] is int num3) || !(array[6] is int occurrence))
			{
				identity = null;
				return false;
			}
			identity = MinecartSpawnIdentity.FromPosition((float)num / 1000f, (float)num2 / 1000f, (float)num3 / 1000f, occurrence);
			return true;
		}

		private static void ValidateSpawnedMinecartPreset(GameObject legacyCart, MinecartSpawnIdentity identity)
		{
			MonoBehaviour[] components = legacyCart.GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val in components)
			{
				FieldInfo field = ((object)val).GetType().GetField("physAttributePreset", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (!(field == null) && field.GetValue(val) == null)
				{
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
	internal static class MinecartReplacementLevelResetPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			MinecartReplacementController.ResetForLevelLoad();
		}
	}
	internal sealed class MinecartReplacementMarker : MonoBehaviour
	{
	}
	public sealed class MinecartSpawnIdentity : IEquatable<MinecartSpawnIdentity>
	{
		public int XMillimeters { get; }

		public int YMillimeters { get; }

		public int ZMillimeters { get; }

		public int Occurrence { get; }

		private MinecartSpawnIdentity(int xMillimeters, int yMillimeters, int zMillimeters, int occurrence)
		{
			XMillimeters = xMillimeters;
			YMillimeters = yMillimeters;
			ZMillimeters = zMillimeters;
			Occurrence = occurrence;
		}

		public static MinecartSpawnIdentity FromPosition(float x, float y, float z, int occurrence)
		{
			return new MinecartSpawnIdentity(ToMillimeters(x), ToMillimeters(y), ToMillimeters(z), occurrence);
		}

		public bool Equals(MinecartSpawnIdentity? other)
		{
			if (other != null && XMillimeters == other.XMillimeters && YMillimeters == other.YMillimeters && ZMillimeters == other.ZMillimeters)
			{
				return Occurrence == other.Occurrence;
			}
			return false;
		}

		public override bool Equals(object? obj)
		{
			return Equals(obj as MinecartSpawnIdentity);
		}

		public override int GetHashCode()
		{
			return (((17 * 31 + XMillimeters) * 31 + YMillimeters) * 31 + ZMillimeters) * 31 + Occurrence;
		}

		public override string ToString()
		{
			return $"({(float)XMillimeters / 1000f:F3}, {(float)YMillimeters / 1000f:F3}, {(float)ZMillimeters / 1000f:F3}) #{Occurrence}";
		}

		public static bool operator ==(MinecartSpawnIdentity? left, MinecartSpawnIdentity? right)
		{
			return object.Equals(left, right);
		}

		public static bool operator !=(MinecartSpawnIdentity? left, MinecartSpawnIdentity? right)
		{
			return !object.Equals(left, right);
		}

		private static int ToMillimeters(float coordinate)
		{
			return (int)Math.Round(coordinate * 1000f, MidpointRounding.AwayFromZero);
		}
	}
	public sealed class MinecartSpawnPolicy
	{
		private readonly HashSet<MinecartSpawnIdentity> claimed = new HashSet<MinecartSpawnIdentity>();

		public bool TryClaim(MinecartSpawnIdentity identity, bool isHost)
		{
			if (isHost)
			{
				return claimed.Add(identity);
			}
			return false;
		}

		public void ResetForLevelLoad()
		{
			claimed.Clear();
		}
	}
	[BepInPlugin("nezzy.MinecraftStrongholdLevelFix", "Minecraft Stronghold Level Fix", "0.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Application.quitting += StrongholdIconTextureCleanup.OnQuitting;
			MinecartReplacementAssets.Load(((BaseUnityPlugin)this).Info.Location);
			Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			int num = 0;
			foreach (Type item in from type in Assembly.GetExecutingAssembly().GetTypes()
				where type.IsDefined(typeof(HarmonyPatch), inherit: false)
				select type)
			{
				try
				{
					val.CreateClassProcessor(item).Patch();
					num++;
				}
				catch (Exception arg)
				{
					Log.LogError((object)$"Failed to install {item.Name}: {arg}");
				}
			}
			Log.LogInfo((object)$"Installed {num} Stronghold patch classes.");
		}

		private void OnDestroy()
		{
			Application.quitting -= StrongholdIconTextureCleanup.OnQuitting;
		}

		internal static bool IsStrongholdLevel()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if ((Object)RunManager.instance != (Object)null && (Object)RunManager.instance.levelCurrent != (Object)null)
			{
				return ((Object)RunManager.instance.levelCurrent).name.IndexOf("Stronghold", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}

		[Conditional("DEBUG")]
		internal static void DebugLog(string message)
		{
			Log.LogInfo((object)message);
		}
	}
	[HarmonyPatch(typeof(ItemAttributes), "Start")]
	internal static class StrongholdCarvedPumpkinIconPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemAttributes __instance)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Expected O, but got Unknown
			if (!Plugin.IsStrongholdLevel() || (Object)__instance.icon != (Object)null || !((Object)((Component)__instance).gameObject).name.StartsWith("Item Carved Pumpkin", StringComparison.Ordinal))
			{
				return;
			}
			SemiIconMaker val = ((Component)__instance).GetComponentInChildren<SemiIconMaker>(true);
			if ((Object)val == (Object)null)
			{
				GameObject val2 = new GameObject("Stronghold Pumpkin Icon Maker");
				val2.transform.SetParent(((Component)__instance).transform, false);
				val = val2.AddComponent<SemiIconMaker>();
			}
			Bounds? val3 = CalculateRenderableBounds(((Component)__instance).transform);
			if (!val3.HasValue)
			{
				Plugin.Log.LogError((object)"Carved Pumpkin icon repair could not find a renderable mesh.");
				return;
			}
			Camera val4 = val.iconCamera;
			if ((Object)val4 == (Object)null)
			{
				GameObject val5 = new GameObject("Icon Camera");
				val5.transform.SetParent(((Component)val).transform, false);
				val4 = (val.iconCamera = val5.AddComponent<Camera>());
			}
			((Component)val4).transform.SetParent(((Component)val).transform, false);
			val4.orthographic = true;
			val4.clearFlags = (CameraClearFlags)2;
			val4.backgroundColor = new Color(0f, 0f, 0f, 0f);
			val4.cullingMask = -1;
			val4.nearClipPlane = 0.01f;
			val4.farClipPlane = 100f;
			Transform transform = ((Component)__instance).transform;
			Bounds value = val3.Value;
			Vector3 val6 = transform.InverseTransformPoint(((Bounds)(ref value)).center);
			value = val3.Value;
			Vector3 size = ((Bounds)(ref value)).size;
			((Component)val4).transform.localPosition = val6 + Vector3.back * (Mathf.Max(new float[3] { size.x, size.y, size.z }) + 1f);
			((Component)val4).transform.localRotation = Quaternion.identity;
			val4.orthographicSize = Mathf.Max(new float[3]
			{
				size.y * 0.6f,
				size.x * 0.6f,
				0.5f
			});
			if ((Object)val.renderTexture == (Object)null)
			{
				val.renderTexture = new RenderTexture(256, 256, 16, (RenderTextureFormat)0)
				{
					name = "Stronghold Pumpkin Icon RenderTexture"
				};
			}
			val.ambientLight = Color.white;
			val.iconCameraPlacementDone = true;
			((Component)val).gameObject.SetActive(false);
			Plugin.Log.LogInfo((object)"Repaired the Carved Pumpkin inventory icon renderer.");
		}

		private static Bounds? CalculateRenderableBounds(Transform root)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			Bounds value = default(Bounds);
			Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!(val is ParticleSystemRenderer) && !((Object)((Component)val).gameObject).name.Contains("Icon", StringComparison.Ordinal))
				{
					if (!flag)
					{
						value = val.bounds;
						flag = true;
					}
					else
					{
						((Bounds)(ref value)).Encapsulate(val.bounds);
					}
				}
			}
			if (!flag)
			{
				return null;
			}
			return value;
		}
	}
	[HarmonyPatch(typeof(AudioSource), "Play", new Type[] { })]
	internal static class StrongholdEmptyAudioPatch
	{
		private static bool Prefix(AudioSource __instance)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Plugin.IsStrongholdLevel())
			{
				return (Object)__instance.clip != (Object)null;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ExtractionPoint), "Start")]
	internal static class StrongholdExtractionButtonOriginPatch
	{
		[HarmonyPrefix]
		private static void Prefix(ExtractionPoint __instance)
		{
			if (Plugin.IsStrongholdLevel() && Object.op_Implicit((Object)(object)__instance.buttonDenyTransform))
			{
				NormalizePivot(__instance.buttonDenyTransform);
			}
		}

		internal static void NormalizePivot(Transform pivot)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			Vector3[] array = (Vector3[])(object)new Vector3[pivot.childCount];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = pivot.GetChild(i).position;
			}
			pivot.localPosition = Vector3.zero;
			for (int j = 0; j < array.Length; j++)
			{
				pivot.GetChild(j).position = array[j];
			}
		}
	}
	[HarmonyPatch]
	internal static class StrongholdFontLookupPatch
	{
		private const string FontName = "1_Minecraft-Regular";

		private static readonly HashSet<int> reportedMissing = new HashSet<int>();

		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			Type type = typeof(BundleLoader).Assembly.GetType("REPOLib.Patches.FontAssetMaterialPatch", throwOnError: true);
			return AccessTools.Method(type, "LoadFontAssetPrefix", new Type[1] { typeof(TMP_Text) }, (Type[])null) ?? throw new MissingMethodException(type.FullName, "LoadFontAssetPrefix");
		}

		[HarmonyPrefix]
		private static bool Prefix(TMP_Text __0)
		{
			if (!Plugin.IsStrongholdLevel() || !Object.op_Implicit((Object)(object)__0) || !Object.op_Implicit((Object)(object)__0.font) || !string.Equals(((Object)__0.font).name, "1_Minecraft-Regular", StringComparison.Ordinal))
			{
				return true;
			}
			TMP_FontAsset font = __0.font;
			if (Object.op_Implicit((Object)(object)((TMP_Asset)font).material))
			{
				return false;
			}
			Texture val = (Texture)(object)((font.atlasTextures != null && font.atlasTextures.Length != 0) ? font.atlasTextures[0] : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				Material[] array = Resources.FindObjectsOfTypeAll<Material>();
				foreach (Material val2 in array)
				{
					if (Object.op_Implicit((Object)(object)val2) && ((Object)val2).name == "1_Minecraft-Regular Material" && val2.HasProperty("_MainTex") && (Object)(object)val2.GetTexture("_MainTex") == (Object)(object)val)
					{
						((TMP_Asset)font).material = val2;
						return false;
					}
				}
			}
			if (reportedMissing.Add(((Object)font).GetInstanceID()))
			{
				Plugin.Log.LogError((object)"The base mod's Minecraft font material/atlas pair is not loaded. No replacement asset was substituted.");
			}
			return false;
		}
	}
	internal static class StrongholdIconTextureCleanup
	{
		internal static void OnQuitting()
		{
			//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)
			HashSet<RenderTexture> hashSet = new HashSet<RenderTexture>();
			SemiIconMaker[] array = Resources.FindObjectsOfTypeAll<SemiIconMaker>();
			foreach (SemiIconMaker val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Scene scene = ((Component)val).gameObject.scene;
					if (!((Scene)(ref scene)).IsValid() && !(((Object)((Component)val).transform.root).name != "MC Item Apple") && Object.op_Implicit((Object)(object)val.renderTexture) && Object.op_Implicit((Object)(object)val.iconCamera) && !((Object)(object)val.iconCamera.targetTexture != (Object)(object)val.renderTexture))
					{
						hashSet.Add(val.renderTexture);
					}
				}
			}
			if (hashSet.Count == 0)
			{
				return;
			}
			int num = 0;
			Camera[] array2 = Resources.FindObjectsOfTypeAll<Camera>();
			foreach (Camera val2 in array2)
			{
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.targetTexture) && hashSet.Contains(val2.targetTexture))
				{
					val2.targetTexture = null;
					num++;
				}
			}
			Plugin.Log.LogInfo((object)$"Shutdown cleanup detached {num} Stronghold icon camera target(s).");
		}
	}
	[HarmonyPatch(typeof(ItemAttributes), "RefreshLocalizations")]
	internal static class StrongholdItemNamePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ItemAttributes __instance, ref string ___cachedItemName)
		{
			GameObject gameObject = ((Component)__instance).gameObject;
			if (MinecartReplacementAssets.IsReplacement(gameObject) || (Object)(object)gameObject.GetComponent<MinecartReplacementMarker>() != (Object)null)
			{
				___cachedItemName = "Minecart";
				return false;
			}
			if (GoldenAppleLocalization.IsAffectedPrefab(((Object)gameObject).name))
			{
				___cachedItemName = "Golden Apple";
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class StrongholdJukeboxMixerPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			Type type = AccessTools.TypeByName("REPOLib.Extensions.AudioSourceExtensions");
			MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "FixAudioMixerGroup", new Type[1] { typeof(AudioSource) }, (Type[])null));
			MethodInfo sourceAndObject = ((type == null) ? null : AccessTools.Method(type, "FixAudioMixerGroup", new Type[2]
			{
				typeof(AudioSource),
				typeof(GameObject)
			}, (Type[])null));
			if (methodInfo != null)
			{
				yield return methodInfo;
			}
			if (sourceAndObject != null)
			{
				yield return sourceAndObject;
			}
		}

		private static bool Prefix(AudioSource __0)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if ((Object)__0.outputAudioMixerGroup != (Object)null || !IsLegacyJukeboxAudio(__0))
			{
				return true;
			}
			AudioSource[] array = Resources.FindObjectsOfTypeAll<AudioSource>();
			foreach (AudioSource val in array)
			{
				if ((Object)val.outputAudioMixerGroup != (Object)null && ((Object)val.outputAudioMixerGroup).name == "Sound Effects")
				{
					__0.outputAudioMixerGroup = val.outputAudioMixerGroup;
					return false;
				}
			}
			return true;
		}

		private static bool IsLegacyJukeboxAudio(AudioSource source)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			Transform val = ((Component)source).transform;
			while ((Object)val != (Object)null)
			{
				if (((Object)val).name == "Valuable Jukebox 13" || ((Object)val).name == "Valuable Jukebox Cat" || ((Object)val).name == "Valuable Jukebox OS")
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}
	}
	[HarmonyPatch]
	internal static class StrongholdKinematicInventoryItemPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool LinearVelocityPrefix(Rigidbody __instance)
		{
			return !IsLegacyStrongholdInventoryBody(__instance);
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool AngularVelocityPrefix(Rigidbody __instance)
		{
			return !IsLegacyStrongholdInventoryBody(__instance);
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool LinearVelocityCurrentPrefix(Rigidbody __instance)
		{
			return !IsLegacyStrongholdInventoryBody(__instance);
		}

		private static bool IsLegacyStrongholdInventoryBody(Rigidbody body)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if (Plugin.IsStrongholdLevel() && body.isKinematic)
			{
				return (Object)((Component)body).GetComponent<ItemEquippable>() != (Object)null;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(NotValuableObject), "Start")]
	internal static class StrongholdLegacyMinecartInitPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(NotValuableObject __instance)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			if (!Plugin.IsStrongholdLevel() || (Object)__instance.physAttributePreset != (Object)null)
			{
				return true;
			}
			GameObject gameObject = ((Component)__instance).gameObject;
			if (((Object)gameObject).name.IndexOf("Minecart", StringComparison.OrdinalIgnoreCase) >= 0 && !MinecartReplacementAssets.IsReplacement(gameObject))
			{
				return (Object)gameObject.GetComponent<PhysGrabCart>() == (Object)null;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Map), "MapObjectSetup")]
	internal static class StrongholdMapDrawingDepthPatch
	{
		[HarmonyPrefix]
		private static void Prefix(Map __instance, GameObject _object)
		{
			//IL_000f: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			if (Plugin.IsStrongholdLevel())
			{
				Transform transform = _object.transform;
				Vector3 localPosition = transform.localPosition;
				localPosition.y = 0f;
				transform.localPosition = localPosition;
				Vector3 localScale = transform.localScale;
				localScale.y *= __instance.Scale;
				transform.localScale = localScale;
			}
		}
	}
	[HarmonyPatch]
	internal static class StrongholdMapGlyphScalePatch
	{
		private static void AttachLabel(CodeInstruction instruction, object label)
		{
			((IList)typeof(CodeInstruction).GetField("labels").GetValue(instruction)).Add(label);
		}

		[HarmonyTargetMethods]
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return typeof(Map).GetMethod("AddFloor", new Type[1] { typeof(DirtFinderMapFloor) }) ?? throw new MissingMethodException(typeof(Map).FullName, "AddFloor");
			yield return typeof(Map).GetMethod("AddWall", new Type[1] { typeof(DirtFinderMapWall) }) ?? throw new MissingMethodException(typeof(Map).FullName, "AddWall");
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			MethodInfo methodInfo = typeof(Transform).GetProperty("lossyScale")?.GetGetMethod() ?? throw new MissingMethodException(typeof(Transform).FullName, "get_lossyScale");
			MethodInfo methodInfo2 = typeof(Transform).GetProperty("localScale")?.GetGetMethod() ?? throw new MissingMethodException(typeof(Transform).FullName, "get_localScale");
			MethodInfo methodInfo3 = typeof(Plugin).GetMethod("IsStrongholdLevel", BindingFlags.Static | BindingFlags.NonPublic) ?? throw new MissingMethodException(typeof(Plugin).FullName, "IsStrongholdLevel");
			List<CodeInstruction> list = new List<CodeInstruction>();
			int num = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, methodInfo))
				{
					Label label = generator.DefineLabel();
					Label label2 = generator.DefineLabel();
					list.Add(CodeInstructionExtensions.MoveBlocksFrom(CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Call, (object)methodInfo3), instruction), instruction));
					list.Add(new CodeInstruction(OpCodes.Brfalse, (object)label));
					list.Add(new CodeInstruction(OpCodes.Callvirt, (object)methodInfo2));
					list.Add(new CodeInstruction(OpCodes.Br, (object)label2));
					AttachLabel(instruction, label);
					list.Add(instruction);
					CodeInstruction val = new CodeInstruction(OpCodes.Nop, (object)null);
					AttachLabel(val, label2);
					list.Add(val);
					num++;
				}
				else
				{
					list.Add(instruction);
				}
			}
			if (num != 1)
			{
				throw new InvalidOperationException($"Expected one native map glyph scale assignment, found {num}.");
			}
			return list;
		}
	}
	internal static class StrongholdMapLayers
	{
		private sealed class RoomOverlay
		{
			internal Transform Root;

			internal Vector3 LocalPosition;

			internal MapLayer Bottom;

			internal MapLayer Top;

			internal MapLayer SelectLayer(MapLayer current)
			{
				if (current.layer < Bottom.layer)
				{
					return Bottom;
				}
				if (current.layer > Top.layer)
				{
					return Top;
				}
				return current;
			}
		}

		private sealed class ModuleOverlays
		{
			internal MapModule Module;

			internal Vector3 GraphicLocalPosition;

			internal readonly List<RoomOverlay> Rooms = new List<RoomOverlay>();
		}

		private sealed class MapOverlays
		{
			internal readonly Dictionary<MapModule, ModuleOverlays> Modules = new Dictionary<MapModule, ModuleOverlays>();
		}

		private static readonly ConditionalWeakTable<Map, MapOverlays> maps = new ConditionalWeakTable<Map, MapOverlays>();

		internal static int ExistingChildCount(Map map, Module module)
		{
			if (!Plugin.IsStrongholdLevel())
			{
				return -1;
			}
			foreach (MapModule mapModule in map.MapModules)
			{
				if (Object.op_Implicit((Object)(object)mapModule) && (Object)(object)mapModule.module == (Object)(object)module)
				{
					return ((Component)mapModule).transform.childCount;
				}
			}
			return map.ModulePrefab.transform.childCount;
		}

		internal static void Register(Map map, MapModule module, int firstChild, Vector3 position, Quaternion rotation, Vector3 scale, Mesh mesh)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0041: 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_0044: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			if (firstChild >= 0 && Object.op_Implicit((Object)(object)module))
			{
				float num = position.y - Mathf.Abs(scale.y);
				float num2 = position.y + Mathf.Abs(scale.y);
				if (Object.op_Implicit((Object)(object)mesh))
				{
					Matrix4x4 val = Matrix4x4.TRS(position, rotation, scale * 2f);
					Bounds bounds = mesh.bounds;
					float y = ((Matrix4x4)(ref val)).MultiplyPoint3x4(((Bounds)(ref bounds)).center).y;
					Vector3 extents = ((Bounds)(ref bounds)).extents;
					float num3 = Mathf.Abs(val.m10) * extents.x + Mathf.Abs(val.m11) * extents.y + Mathf.Abs(val.m12) * extents.z;
					num = y - num3;
					num2 = y + num3;
				}
				MapLayer layerParent = map.GetLayerParent(num);
				MapLayer layerParent2 = map.GetLayerParent(Mathf.Max(num, num2 - 0.001f));
				MapOverlays value = maps.GetValue(map, (Map _) => new MapOverlays());
				if (!value.Modules.TryGetValue(module, out ModuleOverlays value2))
				{
					value2 = new ModuleOverlays
					{
						Module = module,
						GraphicLocalPosition = (Object.op_Implicit((Object)(object)module.graphic) ? module.graphic.localPosition : Vector3.zero)
					};
					value.Modules.Add(module, value2);
				}
				for (int num4 = firstChild; num4 < ((Component)module).transform.childCount; num4++)
				{
					Transform child = ((Component)module).transform.GetChild(num4);
					value2.Rooms.Add(new RoomOverlay
					{
						Root = child,
						LocalPosition = child.localPosition,
						Bottom = layerParent,
						Top = layerParent2
					});
				}
			}
		}

		internal static void Update(Map map)
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			if (!map.Active || !maps.TryGetValue(map, out MapOverlays value))
			{
				return;
			}
			MapLayer val = null;
			foreach (MapLayer layer in map.Layers)
			{
				if (Object.op_Implicit((Object)(object)layer) && layer.layer == map.PlayerLayer)
				{
					val = layer;
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			foreach (ModuleOverlays value2 in value.Modules.Values)
			{
				if (!Object.op_Implicit((Object)(object)value2.Module) || Mathf.Abs(((Component)value2.Module).transform.lossyScale.y) < 1E-05f)
				{
					continue;
				}
				MapLayer val2 = null;
				foreach (RoomOverlay room in value2.Rooms)
				{
					if (Object.op_Implicit((Object)(object)room.Root) && Object.op_Implicit((Object)(object)room.Bottom) && Object.op_Implicit((Object)(object)room.Top))
					{
						MapLayer val3 = room.SelectLayer(val);
						Vector3 position = room.Root.parent.TransformPoint(room.LocalPosition);
						position.y += ((Component)val3).transform.position.y - map.OverLayerParent.position.y;
						room.Root.position = position;
						if (!Object.op_Implicit((Object)(object)val2) || Mathf.Abs(val3.layer - val.layer) < Mathf.Abs(val2.layer - val.layer) || (Mathf.Abs(val3.layer - val.layer) == Mathf.Abs(val2.layer - val.layer) && val3.layer < val2.layer))
						{
							val2 = val3;
						}
					}
				}
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)value2.Module.graphic))
				{
					Transform graphic = value2.Module.graphic;
					Vector3 position2 = graphic.parent.TransformPoint(value2.GraphicLocalPosition);
					position2.y += ((Component)val2).transform.position.y - ((Component)value2.Module).transform.position.y;
					graphic.position = position2;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Map), "AddRoomVolume")]
	internal static class StrongholdMapRoomVolumePatch
	{
		[HarmonyPrefix]
		private static void Prefix(Map __instance, Module _module, out int __state)
		{
			__state = StrongholdMapLayers.ExistingChildCount(__instance, _module);
		}

		[HarmonyPostfix]
		private static void Postfix(Map __instance, MapModule __result, Vector3 _position, Quaternion _rotation, Vector3 _scale, Mesh _mesh, int __state)
		{
			//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)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			StrongholdMapLayers.Register(__instance, __result, __state, _position, _rotation, _scale, _mesh);
		}
	}
	[HarmonyPatch(typeof(Map), "Update")]
	internal static class StrongholdMapDisplayPatch
	{
		[HarmonyPostfix]
		private static void Postfix(Map __instance)
		{
			StrongholdMapLayers.Update(__instance);
		}
	}
	[HarmonyPatch(typeof(Map), "CustomPositionSet")]
	internal static class StrongholdMapMarkerPatch
	{
		[HarmonyPostfix]
		private static void Postfix(Map __instance, Transform transformTarget, Transform transformSource)
		{
			//IL_000a: 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_0026: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.IsStrongholdLevel())
			{
				return;
			}
			MapLayer layerParent = __instance.GetLayerParent(transformSource.position.y + 1f);
			Vector3 position = transformTarget.position;
			position.y = ((Component)layerParent).transform.position.y + 0.02f;
			transformTarget.position = position;
			MapCustomEntity component = ((Component)transformTarget).GetComponent<MapCustomEntity>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.mapCustom))
			{
				return;
			}
			RoomVolumeCheck componentInParent = ((Component)transformSource).GetComponentInParent<RoomVolumeCheck>();
			if (!Object.op_Implicit((Object)(object)componentInParent) || componentInParent.CurrentRooms == null)
			{
				return;
			}
			foreach (RoomVolume currentRoom in componentInParent.CurrentRooms)
			{
				if (Object.op_Implicit((Object)(object)currentRoom) && Object.op_Implicit((Object)(object)currentRoom.MapModule))
				{
					component.mapCustom.Hide();
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(CosmeticWorldObject), "Start")]
	internal static class StrongholdCosmeticMapRegistrationPatch
	{
		[HarmonyPostfix]
		private static void Postfix(CosmeticWorldObject __instance)
		{
			if (!Plugin.IsStrongholdLevel())
			{
				return;
			}
			ValuableDiscoverCustom component = ((Component)__instance).GetComponent<ValuableDiscoverCustom>();
			if (!Object.op_Implicit((Object)(object)component) || !component.hasCustomMap || component.customMap == null)
			{
				return;
			}
			foreach (MapCustom item in component.customMap)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					item.autoAdd = true;
					((Behaviour)item).enabled = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(MapCustom), "Add")]
	internal static class StrongholdCosmeticMapDuplicatePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(MapCustom __instance, MapCustomEntity ___mapCustomEntity)
		{
			if (!Plugin.IsStrongholdLevel() || !Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInParent<CosmeticWorldObject>()))
			{
				return true;
			}
			return !Object.op_Implicit((Object)(object)___mapCustomEntity);
		}
	}
	[HarmonyPatch(typeof(Map), "GetLayerParent")]
	internal static class StrongholdMapResolutionPatch
	{
		[HarmonyPrefix]
		private static void Prefix(ref float ___LayerHeight, ref float _positionY)
		{
			Configure(ref ___LayerHeight);
			_positionY = AlignHeight(_positionY);
		}

		internal static float AlignHeight(float height)
		{
			if (!Plugin.IsStrongholdLevel())
			{
				return height;
			}
			return height - 0.5f;
		}

		internal static void Configure(ref float layerHeight)
		{
			if (Plugin.IsStrongholdLevel())
			{
				layerHeight = 6f;
			}
		}

		internal static Vector3 DisplayPosition(Vector3 position)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.IsStrongholdLevel())
			{
				position.y *= 1f / 3f;
			}
			return position;
		}
	}
	[HarmonyPatch(typeof(Map), "Update")]
	internal static class StrongholdMapDisplayDepthPatch
	{
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>();
			MethodInfo methodInfo = typeof(Map).GetMethod("GetLayerPosition", new Type[1] { typeof(int) }) ?? throw new MissingMethodException(typeof(Map).FullName, "GetLayerPosition");
			MethodInfo methodInfo2 = typeof(StrongholdMapResolutionPatch).GetMethod("DisplayPosition", BindingFlags.Static | BindingFlags.NonPublic) ?? throw new MissingMethodException(typeof(StrongholdMapResolutionPatch).FullName, "DisplayPosition");
			int num = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				list.Add(instruction);
				if (CodeInstructionExtensions.Calls(instruction, methodInfo))
				{
					list.Add(new CodeInstruction(OpCodes.Call, (object)methodInfo2));
					num++;
				}
			}
			if (num != 2)
			{
				throw new InvalidOperationException($"Expected two native map display-depth calls, found {num}.");
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(PhysGrabCart), "Start")]
	internal static class StrongholdMinecartReplacementPatch
	{
		private static bool Prefix(PhysGrabCart __instance)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if (MinecartReplacementAssets.IsReplacement(((Component)__instance).gameObject) || (Object)((Component)__instance).GetComponent<MinecartReplacementMarker>() != (Object)null)
			{
				__instance.localizedCartModeStrong = null;
				__instance.localizedCartModeWeak = null;
				MinecartReplacementController.AttachIncomingReplacement(((Component)__instance).gameObject);
				return true;
			}
			if (!Plugin.IsStrongholdLevel() || ((Object)((Component)__instance).gameObject).name.IndexOf("Minecart", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return true;
			}
			MinecartReplacementController.Replace(((Component)__instance).gameObject);
			return false;
		}
	}
	[HarmonyPatch(typeof(TextMeshPro), "Awake")]
	internal static class StrongholdSignLayoutPatch
	{
		[HarmonyPostfix]
		private static void Postfix(TextMeshPro __instance)
		{
			Apply(__instance);
		}

		internal static void Apply(TextMeshPro text)
		{
			if (!Plugin.IsStrongholdLevel() || !Object.op_Implicit((Object)(object)text) || !Object.op_Implicit((Object)(object)((TMP_Text)text).font) || ((Object)((TMP_Text)text).font).name != "1_Minecraft-Regular" || !Object.op_Implicit((Object)(object)text.transform.parent))
			{
				return;
			}
			string name = ((Object)text.transform.parent).name;
			if (!(name != "Sign") || name.StartsWith("Sign (", StringComparison.Ordinal) || name.StartsWith("Wall Sign", StringComparison.Ordinal))
			{
				float fontSize = ((TMP_Text)text).fontSize;
				if (!(fontSize <= 0f))
				{
					((TMP_Text)text).textWrappingMode = (TextWrappingModes)1;
					((TMP_Text)text).fontSizeMax = fontSize;
					((TMP_Text)text).fontSizeMin = Mathf.Min(fontSize, 0.05f);
					((TMP_Text)text).enableAutoSizing = true;
					((TMP_Text)text).overflowMode = (TextOverflowModes)3;
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class StrongholdSpriteRegistrationPatch
	{
		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			Type type = typeof(BundleLoader).Assembly.GetType("REPOLib.Patches.FontAssetMaterialPatch", throwOnError: true);
			return type.GetMethod("EndLegacyBundle", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[3]
			{
				typeof(string),
				typeof(AssetBundle),
				typeof(HashSet<Object>)
			}, null) ?? throw new MissingMethodException(type.FullName, "EndLegacyBundle");
		}

		[HarmonyPostfix]
		private static void Postfix(string path, HashSet<Object> ____legacyAssets)
		{
			PreserveOriginalSprite(path, ____legacyAssets);
		}

		internal static void PreserveOriginalSprite(string path, HashSet<Object> legacyAssets)
		{
			if (string.Equals(Path.GetFileName(path), "MinecraftStrongholdLevel.repobundle", StringComparison.OrdinalIgnoreCase))
			{
				legacyAssets.RemoveWhere((Object asset) => asset is TMP_SpriteAsset && Object.op_Implicit(asset) && string.Equals(asset.name, "emojis Extraction Point", StringComparison.Ordinal));
			}
		}
	}
	[HarmonyPatch]
	internal static class StrongholdWeaponPhotonRepairPatch
	{
		private static MethodBase? TargetMethod()
		{
			return AccessTools.Method(typeof(PhotonView), "Awake", (Type[])null, (Type[])null);
		}

		private static void Prefix(PhotonView __instance)
		{
			if (IsAffectedWeapon(((Object)((Component)__instance).gameObject).name))
			{
				__instance.ObservedComponents.RemoveAll((Component component) => component is ItemMelee);
			}
		}

		private static bool IsAffectedWeapon(string name)
		{
			if (!name.StartsWith("MC Item Iron Pickaxe", StringComparison.Ordinal) && !name.StartsWith("MC Item Iron Sword", StringComparison.Ordinal))
			{
				return name.StartsWith("MC Item Diamond Sword", StringComparison.Ordinal);
			}
			return true;
		}
	}
}