Decompiled source of MagicPreview v0.1.1

plugins/legocool.MagicPreview.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("legocool.MagicPreview")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("legocool.MagicPreview")]
[assembly: AssemblyTitle("MagicPreview")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace MagicPreview
{
	public enum PreviewVineColor
	{
		Red,
		Yellow,
		Cyan,
		Green,
		Blue,
		Magenta,
		Black,
		White
	}
	[BepInPlugin("legocool.MagicPreview", "MagicPreview", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(MagicBean))]
		public static class MagicBean_GrowHelper
		{
			[HarmonyPatch("Update")]
			[HarmonyPostfix]
			public static void Update_Hijack(MagicBean __instance)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Invalid comparison between Unknown and I4
				//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_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Expected O, but got Unknown
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: 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_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: 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_0202: Unknown result type (might be due to invalid IL or missing references)
				//IL_0214: 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)
				if (!((ItemComponent)__instance).photonView.IsMine)
				{
					return;
				}
				PreviewState component = ((Component)__instance).GetComponent<PreviewState>();
				if ((int)((ItemComponent)__instance).item.itemState == 1)
				{
					component.hasRun = false;
				}
				else if (__instance.isPlanted && !component.hasRun)
				{
					component.hasRun = true;
					MagicBeanVine val = Object.Instantiate<MagicBeanVine>(__instance.plantPrefab, ((Component)__instance).transform.position, Quaternion.identity);
					RemoveAfterSeconds val2 = ((Component)val).gameObject.AddComponent<RemoveAfterSeconds>();
					val2.Config(ShrinkOnDestroy.Value, 3f);
					Transform val3 = ((Component)val).transform.Find("VineOrigin/Stalk");
					Renderer component2 = ((Component)val3).GetComponent<Renderer>();
					Material val4 = new Material(Shader.Find("Scouts/ItemPreview"));
					val4.renderQueue = 3021;
					val4.SetColor("_Tint", new Color(0f, 1.388976f, 2.934567f, 0f));
					Vector3 normalized = ((Vector3)(ref __instance.averageNormal)).normalized;
					if (Vector3.Angle(normalized, Vector3.up) > 40f || Vector3.Angle(normalized, Vector3.up) < -40f)
					{
						val4.SetColor("_Color0", ColorMap[WalkableColor.Value]);
					}
					else
					{
						val4.SetColor("_Color0", ColorMap[NonWalkableColor.Value]);
					}
					val4.SetFloat("_PhongTessStrength", 0.5f);
					val4.SetFloat("_MaxTessellation", 16f);
					val4.SetFloat("_TessMinDistance", 10f);
					val4.SetFloat("_TessMaxDistance", 25f);
					val4.SetFloat("_EdgeLength", 16f);
					val4.SetFloat("_MaxDisplacement", 25f);
					val4.doubleSidedGI = false;
					component2.material = val4;
					Collider[] componentsInChildren = ((Component)val).GetComponentsInChildren<Collider>();
					Collider[] array = componentsInChildren;
					foreach (Collider val5 in array)
					{
						Object.Destroy((Object)(object)val5);
					}
					((Component)val).transform.up = __instance.averageNormal;
					val.maxLength = __instance.GetVineDistance(((Component)__instance).transform.position, __instance.averageNormal);
					val.growingSpeed = GrowSpeed.Value;
					val.rotationSpeed = -20f;
				}
			}
		}

		private Harmony _harmony;

		internal static ConfigEntry<PreviewVineColor> WalkableColor;

		internal static ConfigEntry<PreviewVineColor> NonWalkableColor;

		internal static ConfigEntry<bool> ShrinkOnDestroy;

		internal static ConfigEntry<float> GrowSpeed;

		private static readonly Dictionary<PreviewVineColor, Color> ColorMap = new Dictionary<PreviewVineColor, Color>
		{
			{
				PreviewVineColor.Red,
				Color.red
			},
			{
				PreviewVineColor.Yellow,
				Color.yellow
			},
			{
				PreviewVineColor.Cyan,
				Color.cyan
			},
			{
				PreviewVineColor.Blue,
				Color.blue
			},
			{
				PreviewVineColor.Green,
				Color.green
			},
			{
				PreviewVineColor.Magenta,
				Color.magenta
			},
			{
				PreviewVineColor.Black,
				Color.black
			},
			{
				PreviewVineColor.White,
				Color.white
			}
		};

		public const string Id = "legocool.MagicPreview";

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


		public static string Name => "MagicPreview";

		public static string Version => "0.1.0";

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("legocool.MagicPreview");
			_harmony.PatchAll();
			Item val = default(Item);
			ItemDatabase.TryGetItem((ushort)45, ref val);
			((Component)val).gameObject.AddComponent<PreviewState>();
			WalkableColor = ((BaseUnityPlugin)this).Config.Bind<PreviewVineColor>("Preview Vine", "WalkableColor", PreviewVineColor.Green, "Vine color when the vine is at a walkable angle.");
			NonWalkableColor = ((BaseUnityPlugin)this).Config.Bind<PreviewVineColor>("Preview Vine", "NonWalkableColor", PreviewVineColor.Red, "Vine color when the vine isn't at a walkable angle.");
			ShrinkOnDestroy = ((BaseUnityPlugin)this).Config.Bind<bool>("Preview Vine", "ShrinkOnDestroy", true, "Vine shrinks and then destroys destroys its self");
			GrowSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Preview Vine", "GrowSpeed", 40f, "Speed the Preview vine grows at");
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}
	}
	internal class PreviewState : MonoBehaviour
	{
		public bool hasRun;
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}