Decompiled source of NoPlantsGlow v1.0.6

plugins/NoPlantsGlow.dll

Decompiled 11 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using NoPlantsGlow.Common;
using NoPlantsGlow.Prefabs;
using NoPlantsGlow.Prefabs.Code;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("NoPlantsGlow")]
[assembly: AssemblyDescription("Disables glow of various plants in Valheim.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NoPlantsGlow")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ad6da0bd-8c3f-7df9-9d39-59136b34a716")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
internal static class PluginInfo
{
	public const string PluginGUID = "noglow.NoPlantsGlow";

	public const string PluginName = "NoPlantsGlow";

	public const string PluginDescription = "Disables glow of various plants in Valheim.";

	public const string PluginVersion = "1.0.6";
}
namespace NoPlantsGlow
{
	[BepInPlugin("noglow.NoPlantsGlow", "NoPlantsGlow", "1.0.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

		public void Awake()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)SystemInfo.graphicsDeviceType != 4)
			{
				PluginConfig.Bind(((BaseUnityPlugin)this).Config);
				PrefabManager.OnVanillaPrefabsAvailable += OnVanillaPrefabsAvailable;
			}
		}

		private static void OnVanillaPrefabsAvailable()
		{
			if (Flags.Evaluate())
			{
				Dictionary<string, GameObject> dictionary = Controller.Find();
				if (dictionary.Count != 0)
				{
					Controller.Restore(dictionary);
					Controller.Modify(dictionary);
				}
			}
		}
	}
}
namespace NoPlantsGlow.Common
{
	internal enum PrefabState
	{
		Unknown,
		ToModify,
		Modified,
		ToRestore,
		Restored
	}
	internal static class GameObjectExtensions
	{
		public static bool SetChildrenInactive(this GameObject prefab, params string[] names)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return false;
			}
			int num = 0;
			Transform[] componentsInChildren = prefab.GetComponentsInChildren<Transform>(false);
			foreach (Transform val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && names.Contains<string>(((Object)val).name, StringComparer.InvariantCultureIgnoreCase))
				{
					GameObject gameObject = ((Component)val).gameObject;
					if ((Object)(object)gameObject != (Object)null)
					{
						gameObject.SetActive(false);
						num++;
					}
				}
			}
			return num > 0;
		}

		public static bool SetSubChildrenInactive(this GameObject prefab, string subParent, params string[] names)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return false;
			}
			Transform val = prefab.GetComponentsInChildren<Transform>(true)?.FirstOrDefault((Func<Transform, bool>)((Transform x) => string.Compare(((Object)x).name, subParent, StringComparison.InvariantCultureIgnoreCase) == 0));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			int num = 0;
			Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(false);
			foreach (Transform val2 in componentsInChildren)
			{
				if ((Object)(object)val2 != (Object)null && names.Contains<string>(((Object)val2).name, StringComparer.InvariantCultureIgnoreCase))
				{
					GameObject gameObject = ((Component)val2).gameObject;
					if ((Object)(object)gameObject != (Object)null)
					{
						gameObject.SetActive(false);
						num++;
					}
				}
			}
			return num > 0;
		}

		public static bool SetChildrenActive(this GameObject prefab, params string[] names)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return false;
			}
			int num = 0;
			Transform[] componentsInChildren = prefab.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && names.Contains<string>(((Object)val).name, StringComparer.InvariantCultureIgnoreCase))
				{
					GameObject gameObject = ((Component)val).gameObject;
					if ((Object)(object)gameObject != (Object)null)
					{
						gameObject.SetActive(true);
						num++;
					}
				}
			}
			return num > 0;
		}

		public static bool SetSubChildrenActive(this GameObject prefab, string subParent, params string[] names)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return false;
			}
			Transform val = prefab.GetComponentsInChildren<Transform>(true)?.FirstOrDefault((Func<Transform, bool>)((Transform x) => string.Compare(((Object)x).name, subParent, StringComparison.InvariantCultureIgnoreCase) == 0));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			int num = 0;
			Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				if ((Object)(object)val2 != (Object)null && names.Contains<string>(((Object)val2).name, StringComparer.InvariantCultureIgnoreCase))
				{
					GameObject gameObject = ((Component)val2).gameObject;
					if ((Object)(object)gameObject != (Object)null)
					{
						gameObject.SetActive(true);
						num++;
					}
				}
			}
			return num > 0;
		}

		public static bool DisableShaderKeyword(this GameObject prefab, string rendererName, string keyword)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return false;
			}
			Renderer val = ((prefab == null) ? null : prefab.GetComponentsInChildren<Renderer>()?.FirstOrDefault((Func<Renderer, bool>)((Renderer x) => StringComparer.InvariantCultureIgnoreCase.Compare(((Object)x).name, rendererName) == 0)));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Material sharedMaterial = val.sharedMaterial;
			if ((Object)(object)sharedMaterial == (Object)null)
			{
				return false;
			}
			sharedMaterial.DisableKeyword(keyword);
			return true;
		}

		public static bool EnableShaderKeyword(this GameObject prefab, string rendererName, string keyword)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return false;
			}
			Renderer val = ((prefab == null) ? null : prefab.GetComponentsInChildren<Renderer>()?.FirstOrDefault((Func<Renderer, bool>)((Renderer x) => StringComparer.InvariantCultureIgnoreCase.Compare(((Object)x).name, rendererName) == 0)));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Material sharedMaterial = val.sharedMaterial;
			if ((Object)(object)sharedMaterial == (Object)null)
			{
				return false;
			}
			sharedMaterial.EnableKeyword(keyword);
			return true;
		}
	}
}
namespace NoPlantsGlow.Prefabs
{
	internal class PluginConfig
	{
		public static ConfigFile File;

		public static ConfigEntry<bool> DisableGlowOnThistle;

		public static ConfigEntry<bool> DisableGlowOnYellowMushroom;

		public static ConfigEntry<bool> DisableGlowOnBlueMushroom;

		public static ConfigEntry<bool> DisableGlowOnLargeGlowingMushroom;

		public static ConfigEntry<bool> DisableGlowOnMagecap;

		public static ConfigEntry<bool> DisableGlowOnJotunPuffs;

		public static void Bind(ConfigFile config)
		{
			if (File == null)
			{
				File = config;
				DisableGlowOnThistle = config.Bind<bool>("Disable glow and effects", "Thistle", true, "Thistle");
				DisableGlowOnYellowMushroom = config.Bind<bool>("Disable glow and effects", "Yellow mushroom", true, "Yellow mushroom");
				DisableGlowOnBlueMushroom = config.Bind<bool>("Disable glow and effects", "Blue mushroom", true, "Blue mushroom");
				DisableGlowOnLargeGlowingMushroom = config.Bind<bool>("Disable glow and effects", "Large glowing mushroom", true, "Large glowing mushroom");
				DisableGlowOnMagecap = config.Bind<bool>("Disable glow and effects", "Magecap", true, "Magecap");
				DisableGlowOnJotunPuffs = config.Bind<bool>("Disable glow and effects", "Jotun puffs", true, "Jotun puffs");
			}
		}
	}
	internal static class Controller
	{
		private static readonly HashSet<string> Names = new HashSet<string> { "Pickable_Mushroom_blue", "MushroomBlue", "Pickable_Mushroom_JotunPuffs", "GlowingMushroom", "Pickable_Mushroom_Magecap", "Pickable_Thistle", "Pickable_Mushroom_yellow", "MushroomYellow" };

		public static Dictionary<string, GameObject> Find()
		{
			Dictionary<string, GameObject> dictionary = new Dictionary<string, GameObject>();
			foreach (string name2 in Names)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab(name2);
				if (!((Object)(object)prefab == (Object)null) && !string.IsNullOrEmpty(((Object)prefab).name))
				{
					string name = ((Object)prefab).name;
					dictionary.Add(name, prefab);
				}
			}
			return dictionary;
		}

		public static bool Modify(Dictionary<string, GameObject> prefabs)
		{
			bool flag = true;
			flag = Thistle.Modify(prefabs) && flag;
			flag = YellowMushroom.Modify(prefabs) && flag;
			flag = BlueMushroom.Modify(prefabs) && flag;
			flag = LargeGlowingMushroom.Modify(prefabs) && flag;
			flag = JotunPuffs.Modify(prefabs) && flag;
			return Magecap.Modify(prefabs) && flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			bool flag = true;
			flag = Thistle.Restore(prefabs) && flag;
			flag = YellowMushroom.Restore(prefabs) && flag;
			flag = BlueMushroom.Restore(prefabs) && flag;
			flag = LargeGlowingMushroom.Restore(prefabs) && flag;
			flag = JotunPuffs.Restore(prefabs) && flag;
			return Magecap.Restore(prefabs) && flag;
		}
	}
	internal static class Flags
	{
		public static PrefabState Thistle;

		public static PrefabState YellowMushroom;

		public static PrefabState BlueMushroom;

		public static PrefabState LargeGlowingMushroom;

		public static PrefabState Magecap;

		public static PrefabState JotunPuffs;

		public static bool Evaluate()
		{
			bool flag = false;
			flag = Evaluate(ref Thistle, PluginConfig.DisableGlowOnThistle.Value) || flag;
			flag = Evaluate(ref YellowMushroom, PluginConfig.DisableGlowOnYellowMushroom.Value) || flag;
			flag = Evaluate(ref BlueMushroom, PluginConfig.DisableGlowOnBlueMushroom.Value) || flag;
			flag = Evaluate(ref LargeGlowingMushroom, PluginConfig.DisableGlowOnLargeGlowingMushroom.Value) || flag;
			flag = Evaluate(ref Magecap, PluginConfig.DisableGlowOnMagecap.Value) || flag;
			return Evaluate(ref JotunPuffs, PluginConfig.DisableGlowOnJotunPuffs.Value) || flag;
		}

		private static bool Evaluate(ref PrefabState state, bool config)
		{
			if (config)
			{
				state = PrefabState.ToModify;
				return true;
			}
			if (state == PrefabState.ToRestore)
			{
				return false;
			}
			if (state == PrefabState.Modified)
			{
				state = PrefabState.ToRestore;
				return true;
			}
			state = PrefabState.Unknown;
			return false;
		}
	}
}
namespace NoPlantsGlow.Prefabs.Code
{
	internal static class LargeGlowingMushroom
	{
		public const string PrefabName = "GlowingMushroom";

		public static bool Modify(Dictionary<string, GameObject> prefabs)
		{
			if (!PluginConfig.DisableGlowOnLargeGlowingMushroom.Value)
			{
				return true;
			}
			if (Flags.LargeGlowingMushroom != PrefabState.ToModify)
			{
				return false;
			}
			if (!prefabs.TryGetValue("GlowingMushroom", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenInactive("Point light") && flag;
			flag = value.DisableShaderKeyword("Cube", "_EMISSION") && flag;
			if (flag)
			{
				Flags.LargeGlowingMushroom = PrefabState.Modified;
			}
			return flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			if (Flags.LargeGlowingMushroom != PrefabState.ToRestore)
			{
				return false;
			}
			if (!prefabs.TryGetValue("GlowingMushroom", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenActive("Point light") && flag;
			flag = value.EnableShaderKeyword("Cube", "_EMISSION") && flag;
			if (flag)
			{
				Flags.LargeGlowingMushroom = PrefabState.Restored;
			}
			return flag;
		}
	}
	internal static class BlueMushroom
	{
		public const string Prefab1Name = "Pickable_Mushroom_blue";

		public const string Prefab2Name = "MushroomBlue";

		public static bool Modify(Dictionary<string, GameObject> prefabs)
		{
			if (!PluginConfig.DisableGlowOnBlueMushroom.Value)
			{
				return true;
			}
			if (Flags.BlueMushroom != PrefabState.ToModify)
			{
				return false;
			}
			bool flag = true;
			flag = ModifyPrefab1(prefabs) && flag;
			flag = ModifyPrefab2(prefabs) && flag;
			if (flag)
			{
				Flags.BlueMushroom = PrefabState.Modified;
			}
			return flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			if (Flags.BlueMushroom != PrefabState.ToRestore)
			{
				return false;
			}
			bool flag = true;
			flag = RestorePrefab1(prefabs) && flag;
			flag = RestorePrefab2(prefabs) && flag;
			if (flag)
			{
				Flags.BlueMushroom = PrefabState.Restored;
			}
			return flag;
		}

		private static bool ModifyPrefab1(Dictionary<string, GameObject> prefabs)
		{
			if (!prefabs.TryGetValue("Pickable_Mushroom_blue", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenInactive("Point light") && flag;
			return value.DisableShaderKeyword("visual", "_EMISSION") && flag;
		}

		private static bool ModifyPrefab2(Dictionary<string, GameObject> prefabs)
		{
			if (!prefabs.TryGetValue("MushroomBlue", out var value))
			{
				return false;
			}
			bool flag = true;
			return value.SetChildrenInactive("Point light") && flag;
		}

		private static bool RestorePrefab1(Dictionary<string, GameObject> prefabs)
		{
			if (!prefabs.TryGetValue("Pickable_Mushroom_blue", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenActive("Point light") && flag;
			return value.EnableShaderKeyword("visual", "_EMISSION") && flag;
		}

		private static bool RestorePrefab2(Dictionary<string, GameObject> prefabs)
		{
			if (!prefabs.TryGetValue("MushroomBlue", out var value))
			{
				return false;
			}
			bool flag = true;
			return value.SetChildrenActive("Point light") && flag;
		}
	}
	internal static class Magecap
	{
		public const string PrefabName = "Pickable_Mushroom_Magecap";

		public static bool Modify(Dictionary<string, GameObject> prefabs)
		{
			if (!PluginConfig.DisableGlowOnMagecap.Value)
			{
				return true;
			}
			if (Flags.Magecap != PrefabState.ToModify)
			{
				return false;
			}
			if (!prefabs.TryGetValue("Pickable_Mushroom_Magecap", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenInactive("Point Light", "Particle System") && flag;
			if (flag)
			{
				Flags.Magecap = PrefabState.Modified;
			}
			return flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			if (Flags.Magecap != PrefabState.ToRestore)
			{
				return false;
			}
			if (!prefabs.TryGetValue("Pickable_Mushroom_Magecap", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenActive("Point Light", "Particle System") && flag;
			if (flag)
			{
				Flags.Magecap = PrefabState.Restored;
			}
			return flag;
		}
	}
	internal static class JotunPuffs
	{
		public const string PrefabName = "Pickable_Mushroom_JotunPuffs";

		public static bool Modify(Dictionary<string, GameObject> prefabs)
		{
			if (!PluginConfig.DisableGlowOnJotunPuffs.Value)
			{
				return true;
			}
			if (Flags.JotunPuffs != PrefabState.ToModify)
			{
				return false;
			}
			if (!prefabs.TryGetValue("Pickable_Mushroom_JotunPuffs", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenInactive("Point light") && flag;
			if (flag)
			{
				Flags.JotunPuffs = PrefabState.Modified;
			}
			return flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			if (Flags.JotunPuffs != PrefabState.ToRestore)
			{
				return false;
			}
			if (!prefabs.TryGetValue("Pickable_Mushroom_JotunPuffs", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenActive("Point light") && flag;
			if (flag)
			{
				Flags.JotunPuffs = PrefabState.Restored;
			}
			return flag;
		}
	}
	internal static class YellowMushroom
	{
		public const string Prefab1Name = "Pickable_Mushroom_yellow";

		public const string Prefab2Name = "MushroomYellow";

		public static bool Modify(Dictionary<string, GameObject> prefabs)
		{
			if (!PluginConfig.DisableGlowOnYellowMushroom.Value)
			{
				return true;
			}
			if (Flags.YellowMushroom != PrefabState.ToModify)
			{
				return false;
			}
			bool flag = true;
			flag = ModifyPrefab1(prefabs) && flag;
			flag = ModifyPrefab2(prefabs) && flag;
			if (flag)
			{
				Flags.YellowMushroom = PrefabState.Modified;
			}
			return flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			if (Flags.YellowMushroom != PrefabState.ToRestore)
			{
				return false;
			}
			bool flag = true;
			flag = RestorePrefab1(prefabs) && flag;
			flag = RestorePrefab2(prefabs) && flag;
			if (flag)
			{
				Flags.YellowMushroom = PrefabState.Restored;
			}
			return flag;
		}

		private static bool ModifyPrefab1(Dictionary<string, GameObject> prefabs)
		{
			if (!prefabs.TryGetValue("Pickable_Mushroom_yellow", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenInactive("Point light") && flag;
			return value.DisableShaderKeyword("visual", "_EMISSION") && flag;
		}

		private static bool ModifyPrefab2(Dictionary<string, GameObject> prefabs)
		{
			if (!prefabs.TryGetValue("MushroomYellow", out var value))
			{
				return false;
			}
			bool flag = true;
			return value.SetChildrenInactive("Point light") && flag;
		}

		private static bool RestorePrefab1(Dictionary<string, GameObject> prefabs)
		{
			if (!prefabs.TryGetValue("Pickable_Mushroom_yellow", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenActive("Point light") && flag;
			return value.EnableShaderKeyword("visual", "_EMISSION") && flag;
		}

		private static bool RestorePrefab2(Dictionary<string, GameObject> prefabs)
		{
			if (!prefabs.TryGetValue("MushroomYellow", out var value))
			{
				return false;
			}
			bool flag = true;
			return value.SetChildrenActive("Point light") && flag;
		}
	}
	internal static class Thistle
	{
		public const string PrefabName = "Pickable_Thistle";

		public static bool Modify(Dictionary<string, GameObject> prefabs)
		{
			if (!PluginConfig.DisableGlowOnThistle.Value)
			{
				return true;
			}
			if (Flags.Thistle != PrefabState.ToModify)
			{
				return false;
			}
			if (!prefabs.TryGetValue("Pickable_Thistle", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenInactive("Point light", "flare", "bees") && flag;
			if (flag)
			{
				Flags.Thistle = PrefabState.Modified;
			}
			return flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			if (Flags.Thistle != PrefabState.ToRestore)
			{
				return false;
			}
			if (!prefabs.TryGetValue("Pickable_Thistle", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenActive("Point light", "flare", "bees") && flag;
			if (flag)
			{
				Flags.Thistle = PrefabState.Restored;
			}
			return flag;
		}
	}
}