Decompiled source of CleanLargeWoodGate v1.0.1

plugins/CleanLargeWoodGate.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 CleanLargeWoodGate.Common;
using CleanLargeWoodGate.Prefabs;
using CleanLargeWoodGate.Prefabs.Code;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CleanLargeWoodGate")]
[assembly: AssemblyDescription("Removes blood from MountainKit_wood_gate.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CleanLargeWoodGate")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d0363e6e-6dd2-0454-b7e1-974f32d6b742")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
internal static class PluginInfo
{
	public const string PluginGUID = "noglow.CleanLargeWoodGate";

	public const string PluginName = "CleanLargeWoodGate";

	public const string PluginDescription = "Removes blood from MountainKit_wood_gate.";

	public const string PluginVersion = "1.0.1";
}
namespace CleanLargeWoodGate
{
	internal class PluginConfig
	{
		public static ConfigFile File;

		public static ConfigEntry<bool> DisableBloodOnMountainKitWoodGate;

		public static void Bind(ConfigFile config)
		{
			if (File == null)
			{
				File = config;
				DisableBloodOnMountainKitWoodGate = config.Bind<bool>("Disable blood decals", "MountainKitWoodGate", true, "MountainKitWoodGate");
			}
		}
	}
	[BepInPlugin("noglow.CleanLargeWoodGate", "CleanLargeWoodGate", "1.0.1")]
	[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 CleanLargeWoodGate.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 CleanLargeWoodGate.Prefabs
{
	internal static class Flags
	{
		public static PrefabState MountainKitWoodGate;

		public static bool Evaluate()
		{
			bool flag = false;
			return Evaluate(ref MountainKitWoodGate, PluginConfig.DisableBloodOnMountainKitWoodGate.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;
		}
	}
	internal static class Controller
	{
		private static readonly HashSet<string> Names = new HashSet<string> { "MountainKit_wood_gate" };

		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;
			return MountainKitWoodGate.Modify(prefabs) && flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			bool flag = true;
			return MountainKitWoodGate.Restore(prefabs) && flag;
		}
	}
}
namespace CleanLargeWoodGate.Prefabs.Code
{
	internal static class MountainKitWoodGate
	{
		public const string PrefabName = "MountainKit_wood_gate";

		public static bool Modify(Dictionary<string, GameObject> prefabs)
		{
			if (!PluginConfig.DisableBloodOnMountainKitWoodGate.Value)
			{
				return true;
			}
			if (Flags.MountainKitWoodGate != PrefabState.ToModify)
			{
				return false;
			}
			if (!prefabs.TryGetValue("MountainKit_wood_gate", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenInactive("CastleKit_decal_fenrir_blood") && flag;
			flag = value.SetChildrenInactive("CastleKit_decal_fenrir_blood (1)") && flag;
			flag = value.SetChildrenInactive("CastleKit_decal_fenrir_blood (2)") && flag;
			flag = value.SetChildrenInactive("CastleKit_decal_fenrir_blood (3)") && flag;
			if (flag)
			{
				Flags.MountainKitWoodGate = PrefabState.Modified;
			}
			return flag;
		}

		public static bool Restore(Dictionary<string, GameObject> prefabs)
		{
			if (Flags.MountainKitWoodGate != PrefabState.ToRestore)
			{
				return false;
			}
			if (!prefabs.TryGetValue("MountainKit_wood_gate", out var value))
			{
				return false;
			}
			bool flag = true;
			flag = value.SetChildrenActive("CastleKit_decal_fenrir_blood") && flag;
			flag = value.SetChildrenActive("CastleKit_decal_fenrir_blood (1)") && flag;
			flag = value.SetChildrenActive("CastleKit_decal_fenrir_blood (2)") && flag;
			flag = value.SetChildrenActive("CastleKit_decal_fenrir_blood (3)") && flag;
			if (flag)
			{
				Flags.MountainKitWoodGate = PrefabState.Restored;
			}
			return flag;
		}
	}
}