Decompiled source of SnowyWeeds v1.4.0

SnowyWeeds.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WeatherRegistry;

[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("SnowyWeeds")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Template plugin description")]
[assembly: AssemblyFileVersion("1.3.4.0")]
[assembly: AssemblyInformationalVersion("1.3.4+75efac5843ccfe9cdad2912e19acbf85d3b8b26e")]
[assembly: AssemblyProduct("SnowyWeeds")]
[assembly: AssemblyTitle("SnowyWeeds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.4.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SnowyWeeds
{
	[BepInPlugin("dopadream.lethalcompany.snowyweeds", "SnowyWeeds", "1.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		private class SnowyWeedPatches
		{
			[HarmonyPatch(typeof(MoldSpreadManager), "Start")]
			[HarmonyPostfix]
			private static void PostStart(MoldSpreadManager __instance)
			{
				if ((Object)(object)weedMaterial == (Object)null && (Object)(object)weedTexture != (Object)null)
				{
					GameObject moldPrefab = __instance.moldPrefab;
					Renderer val = ((moldPrefab == null) ? null : moldPrefab.GetComponentsInChildren<Renderer>()?.Where((Renderer rend) => ((Component)rend).gameObject.layer != 22)?.FirstOrDefault());
					if ((Object)(object)val != (Object)null)
					{
						weedMaterial = Object.Instantiate<Material>(val.sharedMaterial);
						weedMaterial.mainTexture = weedTexture;
						Logger.LogDebug((object)"Cached snowy material");
					}
					else
					{
						Logger.LogError((object)"Failed to create snowy weeds material");
					}
				}
			}

			[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
			[HarmonyPostfix]
			private static void PostSpreadMold()
			{
				if ((Object)(object)weedMaterial == (Object)null || !IsSnowLevel())
				{
					return;
				}
				MoldSpreadManager obj = Object.FindAnyObjectByType<MoldSpreadManager>();
				object obj2;
				if (obj == null)
				{
					obj2 = null;
				}
				else
				{
					Transform moldContainer = obj.moldContainer;
					obj2 = ((moldContainer != null) ? ((Component)moldContainer).GetComponentsInChildren<Renderer>() : null);
				}
				Renderer[] array = (Renderer[])obj2;
				if (array != null && array.Length >= 1)
				{
					Renderer[] array2 = array;
					for (int i = 0; i < array2.Length; i++)
					{
						array2[i].sharedMaterial = weedMaterial;
						Logger.LogDebug((object)(((Object)weedMaterial.mainTexture).name + " applied to shroud"));
					}
				}
			}
		}

		private const string PLUGIN_GUID = "dopadream.lethalcompany.snowyweeds";

		private const string PLUGIN_NAME = "SnowyWeeds";

		private const string PLUGIN_VERSION = "1.4.0";

		private const string WEATHER_REGISTRY = "mrov.WeatherRegistry";

		private const string ARTIFICE_BLIZZARD = "butterystancakes.lethalcompany.artificeblizzard";

		internal static ManualLogSource Logger;

		internal static Texture weedTexture;

		internal static Material weedMaterial;

		private void Awake()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			try
			{
				Object obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "snowyweeds")).LoadAsset("InvasiveWeedSnowy", typeof(Texture));
				weedTexture = (Texture)(object)((obj is Texture) ? obj : null);
			}
			catch
			{
				Logger.LogError((object)"Encountered some error loading asset bundle. Did you install the plugin correctly?");
				return;
			}
			new Harmony("dopadream.lethalcompany.snowyweeds").PatchAll();
			Logger.LogInfo((object)"SnowyWeeds v1.4.0 loaded");
		}

		private static bool IsSnowLevel()
		{
			if (Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry") && WeatherRegistrySnowCheck())
			{
				return true;
			}
			if (StartOfRound.Instance.currentLevel.levelIncludesSnowFootprints)
			{
				if (!(((Object)StartOfRound.Instance.currentLevel).name != "ArtificeLevel") && Chainloader.PluginInfos.ContainsKey("butterystancakes.lethalcompany.artificeblizzard"))
				{
					return (Object)(object)GameObject.Find("/Systems/Audio/BlizzardAmbience") == (Object)null;
				}
				return true;
			}
			return false;
		}

		private static bool WeatherRegistrySnowCheck()
		{
			if (!((Object)WeatherManager.GetCurrentLevelWeather()).name.Equals("Snowfall"))
			{
				return ((Object)WeatherManager.GetCurrentLevelWeather()).name.Equals("Blizzard");
			}
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SnowyWeeds";

		public const string PLUGIN_NAME = "SnowyWeeds";

		public const string PLUGIN_VERSION = "1.3.4";
	}
}