Decompiled source of Minecraft Minecart v1.0.0

MinecraftMinecart.dll

Decompiled 5 hours 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using REPOLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("yzch")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MinecraftMinecart")]
[assembly: AssemblyTitle("MinecraftMinecart")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 MinecraftMinecart
{
	[HarmonyPatch(typeof(LevelGenerator))]
	internal static class LevelGeneratorPatch
	{
		[HarmonyPatch(typeof(LevelGenerator), "Generate")]
		private class LevelGeneratorCoroutinePatch
		{
			[CompilerGenerated]
			private sealed class <WrapCoroutine>d__1 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public IEnumerator original;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <WrapCoroutine>d__1(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						break;
					case 1:
						<>1__state = -1;
						break;
					}
					if (original.MoveNext())
					{
						<>2__current = original.Current;
						<>1__state = 1;
						return true;
					}
					ReplaceCartModel();
					return false;
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			private static IEnumerator Postfix(IEnumerator result)
			{
				return WrapCoroutine(result);
			}

			[IteratorStateMachine(typeof(<WrapCoroutine>d__1))]
			private static IEnumerator WrapCoroutine(IEnumerator original)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <WrapCoroutine>d__1(0)
				{
					original = original
				};
			}
		}

		[Harmony]
		private static void ReplaceCartModel()
		{
			//IL_00a4: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			PhysGrabCart[] array = Object.FindObjectsOfType<PhysGrabCart>();
			MinecraftMinecart.Logger.LogInfo((object)("Replacing cart models! (" + array.Length + " carts detected)"));
			PhysGrabCart[] array2 = array;
			foreach (PhysGrabCart val in array2)
			{
				if (((Object)((Component)val).gameObject).name.StartsWith("Item Cart Medium"))
				{
					Transform val2 = ((Component)val).transform.Find("Cart Mesh");
					((Component)val2).GetComponent<MeshFilter>().mesh = MinecraftMinecart.cart_model;
					((Renderer)((Component)val2).GetComponent<MeshRenderer>()).SetMaterial(MinecraftMinecart.cart_material);
					val2.localEulerAngles = new Vector3(-90f, 0f, -90f);
					val2.localScale = new Vector3(1f, 1f, 1f);
					for (int num = val2.childCount - 1; num >= 0; num--)
					{
						Object.Destroy((Object)(object)((Component)val2.GetChild(num)).gameObject);
					}
					Transform val3 = ((Component)val).transform.Find("Screen");
					val3.localPosition = new Vector3(0f, 0f, -1.037f);
					Object.Destroy((Object)(object)((Component)val3.Find("Cube (13)")).gameObject);
					Object.Destroy((Object)(object)((Component)val3.Find("Display Wide")).gameObject);
					((Component)((Component)val).transform.Find("Thrust Effect")).gameObject.SetActive(false);
				}
			}
		}
	}
	[BepInPlugin("yzch.Minecraft_Minecart", "Minecraft Minecart", "1.0")]
	public class MinecraftMinecart : BaseUnityPlugin
	{
		internal static string modFolder;

		internal static Mesh cart_model;

		internal static Material cart_material;

		internal static MinecraftMinecart Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			modFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			BundleLoader.LoadBundle(Path.Combine(modFolder, "minecraft_minecart"), (Action<AssetBundle>)delegate(AssetBundle assetBundle)
			{
				cart_model = assetBundle.LoadAsset<GameObject>("cart_mesh").GetComponent<MeshFilter>().sharedMesh;
				cart_material = assetBundle.LoadAsset<Material>("cart_material");
			}, false);
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//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_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}