Decompiled source of SunThroughGrates v1.0.0

SunThroughGrates.dll

Decompiled 2 weeks 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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SunThroughGrates")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9df1ac8aafae593ad8ceb56abd3fd15f10d88e57")]
[assembly: AssemblyProduct("SunThroughGrates")]
[assembly: AssemblyTitle("SunThroughGrates")]
[assembly: AssemblyVersion("1.0.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 SunThroughGrates
{
	[BepInPlugin("nickweedon.SunThroughGrates", "SunThroughGrates", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "nickweedon.SunThroughGrates";

		public const string PluginName = "SunThroughGrates";

		public const string PluginVersion = "1.0.0";

		private const string DefaultIgnored = "iron_floor_1x1,iron_floor_2x2,iron_grate,iron_wall_1x1,iron_wall_2x2";

		internal static ConfigEntry<string> IgnoredPrefabs;

		internal static HashSet<string> IgnoredSet = new HashSet<string>();

		private Harmony _harmony;

		private void Awake()
		{
			IgnoredPrefabs = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Ignored prefabs", "iron_floor_1x1,iron_floor_2x2,iron_grate,iron_wall_1x1,iron_wall_2x2", "Comma-separated prefab names that let sunlight through to plants below.");
			ParseIgnored();
			IgnoredPrefabs.SettingChanged += delegate
			{
				ParseIgnored();
			};
			_harmony = Harmony.CreateAndPatchAll(typeof(PlantPatches), "nickweedon.SunThroughGrates");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("SunThroughGrates 1.0.0 loaded; ignoring: " + string.Join(", ", IgnoredSet)));
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private static void ParseIgnored()
		{
			IgnoredSet = new HashSet<string>(from s in IgnoredPrefabs.Value.Split(new char[1] { ',' })
				select s.Trim() into s
				where s.Length > 0
				select s, StringComparer.OrdinalIgnoreCase);
		}
	}
	[HarmonyPatch]
	internal static class PlantPatches
	{
		private static int _roofMask;

		private static readonly RaycastHit[] Hits = (RaycastHit[])(object)new RaycastHit[32];

		[HarmonyPatch(typeof(Plant), "HaveRoof")]
		[HarmonyPrefix]
		private static bool HaveRoofPrefix(Plant __instance, ref bool __result)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (_roofMask == 0)
			{
				_roofMask = LayerMask.GetMask(new string[3] { "Default", "static_solid", "piece" });
			}
			int num = Physics.RaycastNonAlloc(((Component)__instance).transform.position, Vector3.up, Hits, 100f, _roofMask);
			__result = false;
			for (int i = 0; i < num; i++)
			{
				if (!IsIgnored(((RaycastHit)(ref Hits[i])).collider))
				{
					__result = true;
					break;
				}
			}
			return false;
		}

		private static bool IsIgnored(Collider collider)
		{
			if ((Object)(object)collider == (Object)null)
			{
				return false;
			}
			ZNetView componentInParent = ((Component)collider).GetComponentInParent<ZNetView>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return false;
			}
			return Plugin.IgnoredSet.Contains(Utils.GetPrefabName(((Component)componentInParent).gameObject));
		}
	}
}