Decompiled source of ParticleOverdrive v0.3.1

ParticleOverdrive.dll

Decompiled 20 hours ago
using System;
using System.Diagnostics;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("ParticleOverdrive")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.1.0")]
[assembly: AssemblyInformationalVersion("0.3.1+b9dbd7422fb5fa3ad185850dc31854d30c2431bc")]
[assembly: AssemblyProduct("ParticleOverdrive")]
[assembly: AssemblyTitle("ParticleOverdrive")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/alexkiri/ParticleOverdrivePlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.1.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;
		}
	}
}
internal sealed class ConfigurationManagerAttributes
{
	public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);

	public bool? ShowRangeAsPercent;

	public Action<ConfigEntryBase> CustomDrawer;

	public CustomHotkeyDrawerFunc CustomHotkeyDrawer;

	public bool? Browsable;

	public string Category;

	public object DefaultValue;

	public bool? HideDefaultButton;

	public bool? HideSettingName;

	public string Description;

	public string DispName;

	public int? Order;

	public bool? ReadOnly;

	public bool? IsAdvanced;

	public Func<object, string> ObjToStr;

	public Func<string, object> StrToObj;
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace ParticleOverdrive
{
	[BepInPlugin("io.github.alexkiri.particleoverdrive", "ParticleOverdrive", "0.3.1")]
	public class ParticleOverdrive : BaseUnityPlugin
	{
		public enum ParticlesMultiplier
		{
			VanillaLow,
			VanillaHigh,
			Double,
			Triple,
			Quadruple,
			High5x,
			High6x,
			High7x,
			High8x,
			Ultra10x,
			Ultra12x,
			Ultra16x,
			Extreme16xPlus
		}

		internal static ManualLogSource Log;

		private readonly Harmony harmony = new Harmony("io.github.alexkiri.particleoverdrive");

		public static ConfigEntry<ParticlesMultiplier> particlesMultiplierConfigEntry;

		public static ConfigEntry<bool> upgradeAllParticleSystemsConfigEntry;

		public static ConfigEntry<int> extremeMultiplierConfigEntry;

		public const string Id = "io.github.alexkiri.particleoverdrive";

		public static string Name => "ParticleOverdrive";

		public static string Version => "0.3.1";

		public static float MultiplierToFloat(ParticlesMultiplier multiplier)
		{
			return multiplier switch
			{
				ParticlesMultiplier.VanillaLow => 0.5f, 
				ParticlesMultiplier.VanillaHigh => 1f, 
				ParticlesMultiplier.Double => 2f, 
				ParticlesMultiplier.Triple => 3f, 
				ParticlesMultiplier.Quadruple => 4f, 
				ParticlesMultiplier.High5x => 5f, 
				ParticlesMultiplier.High6x => 6f, 
				ParticlesMultiplier.High7x => 7f, 
				ParticlesMultiplier.High8x => 8f, 
				ParticlesMultiplier.Ultra10x => 10f, 
				ParticlesMultiplier.Ultra12x => 12f, 
				ParticlesMultiplier.Ultra16x => 16f, 
				_ => 1f, 
			};
		}

		private void Awake()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			particlesMultiplierConfigEntry = ((BaseUnityPlugin)this).Config.Bind<ParticlesMultiplier>("General", "ParticlesMultiplier", ParticlesMultiplier.VanillaHigh, new ConfigDescription("Increases the amount of particles, while decreasing performance.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 3
				}
			}));
			particlesMultiplierConfigEntry.SettingChanged += delegate
			{
				GameManager.instance.RefreshParticleSystems();
			};
			upgradeAllParticleSystemsConfigEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UpgradeAllParticleSystems", true, new ConfigDescription("Upgrades all the particle systems to be affected by the multiplier. Requires quit & reload in order to be applied.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}));
			extremeMultiplierConfigEntry = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ExtremeMultiplier", 16, new ConfigDescription("Same as above, but in addition, ridiculously high values are allowed. It's recommended to disable the `UpgradeAllParticleSystems` option when using this multiplier, otherwise the game would be unplayable. Use carefully, as it can greatly decrease the performance.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(16, 128), new object[1]
			{
				new ConfigurationManagerAttributes
				{
					IsAdvanced = true,
					Order = 2
				}
			}));
			extremeMultiplierConfigEntry.SettingChanged += delegate
			{
				particlesMultiplierConfigEntry.Value = ParticlesMultiplier.Extreme16xPlus;
				GameManager.instance.RefreshParticleSystems();
			};
			Log.LogInfo((object)("Plugin " + Name + " (io.github.alexkiri.particleoverdrive) has loaded!"));
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
			Log.LogInfo((object)("Plugin " + Name + " (io.github.alexkiri.particleoverdrive) has unloaded!"));
		}

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			Log.LogDebug((object)("loaded '" + ((Scene)(ref scene)).name + "'"));
			if (upgradeAllParticleSystemsConfigEntry.Value)
			{
				upgradeAllParticleSystems();
			}
		}

		private void upgradeAllParticleSystems()
		{
			ParticleSystem[] array = Object.FindObjectsByType<ParticleSystem>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Log.LogDebug((object)$"Found particleSystems: {array.Length}");
			ParticleSystem[] array2 = array.Where(delegate(ParticleSystem ps)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Invalid comparison between Unknown and I4
				EmissionModule emission = ps.emission;
				if (((EmissionModule)(ref emission)).enabled)
				{
					emission = ps.emission;
					MinMaxCurve rateOverTime = ((EmissionModule)(ref emission)).rateOverTime;
					if (((MinMaxCurve)(ref rateOverTime)).constant > 0f)
					{
						emission = ps.emission;
						if (((EmissionModule)(ref emission)).rateOverTimeMultiplier > 0f)
						{
							MainModule main = ps.main;
							if ((int)((MainModule)(ref main)).cullingMode == 1)
							{
								return (Object)(object)((Component)ps).gameObject.GetComponent<ReduceParticleEffects>() == (Object)null;
							}
						}
					}
				}
				return false;
			}).ToArray();
			ParticleSystem[] array3 = array2;
			for (int i = 0; i < array3.Length; i++)
			{
				Extensions.AddComponentIfNotPresent<ReduceParticleEffects>(((Component)array3[i]).gameObject);
			}
			Log.LogInfo((object)$"Filtered and upgraded: {array2.Length}");
		}
	}
	[HarmonyPatch]
	public class Patcher
	{
		private static readonly ManualLogSource Log = ParticleOverdrive.Log;

		[HarmonyPatch(typeof(ReduceParticleEffects), "SetEmission")]
		[HarmonyPrefix]
		private static bool ReduceParticleEffects_SetEmission(ReduceParticleEffects __instance)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			ParticleOverdrive.ParticlesMultiplier value = ParticleOverdrive.particlesMultiplierConfigEntry.Value;
			float num = ((value != ParticleOverdrive.ParticlesMultiplier.Extreme16xPlus) ? ParticleOverdrive.MultiplierToFloat(value) : ((float)ParticleOverdrive.extremeMultiplierConfigEntry.Value));
			if ((Object)(object)__instance.emitter != (Object)null)
			{
				EmissionModule emission = __instance.emitter.emission;
				((EmissionModule)(ref emission)).rateOverTimeMultiplier = __instance.emissionRateHigh * num;
				MainModule main = __instance.emitter.main;
				((MainModule)(ref main)).maxParticles = (int)((float)__instance.maxParticlesHigh * num);
			}
			return false;
		}
	}
}