Decompiled source of ParticleConfig v1.0.0

plugin/ParticleConfig.dll

Decompiled a month 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 JetBrains.Annotations;
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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.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 ParticleConfig
{
	[BepInPlugin("patricnox.valheim.ParticleConfig", "ParticleConfig", "1.0.0")]
	public class ParticleConfigPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(EnvMan), "SetParticleArrayEnabled")]
		private static class SetParticleArrayEnabled_Patch
		{
			private static bool Prefix(GameObject[] psystems, bool enabled)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				foreach (GameObject val in psystems)
				{
					ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>();
					foreach (ParticleSystem obj in componentsInChildren)
					{
						EmissionModule emission = obj.emission;
						if (IsParticleDisabled(((Object)obj).name))
						{
							((EmissionModule)(ref emission)).enabled = false;
						}
						else
						{
							((EmissionModule)(ref emission)).enabled = enabled;
						}
					}
					MistEmitter componentInChildren = val.GetComponentInChildren<MistEmitter>();
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						((Behaviour)componentInChildren).enabled = enabled;
					}
				}
				return false;
			}
		}

		public const string PluginId = "patricnox.valheim.ParticleConfig";

		private Harmony _harmony;

		private static ParticleConfigPlugin _instance;

		public static ManualLogSource p = Logger.CreateLogSource("patricnox.valheim.ParticleConfig");

		private Dictionary<string, ConfigEntry<bool>> settings = new Dictionary<string, ConfigEntry<bool>>();

		private static List<string> disabledParticles = new List<string>();

		[UsedImplicitly]
		private void Awake()
		{
			_instance = this;
			settings = PluginConfig.Setup(((BaseUnityPlugin)this).Config);
			AddDisabledParticales();
			_harmony = Harmony.CreateAndPatchAll(typeof(ParticleConfigPlugin).Assembly, "patricnox.valheim.ParticleConfig");
			p.LogInfo((object)"[ParticleConfig] Started");
		}

		private void AddDisabledParticales()
		{
			foreach (KeyValuePair<string, ConfigEntry<bool>> setting in settings)
			{
				if (!setting.Value.Value)
				{
					disabledParticles.Add(setting.Key);
				}
			}
		}

		private static bool IsParticleDisabled(string settingName)
		{
			return disabledParticles.Contains(settingName);
		}

		[UsedImplicitly]
		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal class PluginConfig
	{
		private static string[] settingNames = new string[24]
		{
			"FogClouds", "cloud", "snow", "vfx_ground_fog", "fog_ball", "air dust", "splash spawner", "splash", "RainTest", "InfectedMine",
			"dust particles", "mist", "cloud (1)", "fastmoving_wetmist", "balls", "zinder", "Rain", "distant_rain", "snow (1)", "distant snow",
			"Whirl", "ash", "InteriorDust", "interior_dust (1)"
		};

		public static Dictionary<string, ConfigEntry<bool>> Setup(ConfigFile config)
		{
			Dictionary<string, ConfigEntry<bool>> dictionary = new Dictionary<string, ConfigEntry<bool>>();
			string[] array = settingNames;
			foreach (string text in array)
			{
				dictionary[text] = config.Bind<bool>("Particles", text, true, "");
			}
			return dictionary;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ParticleConfig";

		public const string PLUGIN_NAME = "ParticleConfig";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}