Decompiled source of No Particles v1.0.0

NoParticles.dll

Decompiled a month ago
using System;
using System.Collections;
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;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Landfall.TABS;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SuperUnits")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("GeeztJeez")]
[assembly: AssemblyProduct("SuperUnits")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7acfaef0-7669-4401-8bff-5a9a02e18c75")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public class FatMaking : MonoBehaviour
{
	private Unit unit;

	public float size = 1.5f;

	public void Update()
	{
		/*Error: Invalid metadata token*/;
	}

	public void Start()
	{
		/*Error near IL_0001: Invalid metadata token*/;
	}
}
namespace NoParticles;

[BepInPlugin("GeeztJeez.NoParticles", "NoParticles", "1.0.0")]
internal class Loader : BaseUnityPlugin
{
	private static ConfigEntry<bool> configEnableNoParticles;

	private static List<ParticleSystem> cachedParticleSystems = new List<ParticleSystem>();

	private void Awake()
	{
		Debug.Log((object)"No Particles Mod: Awake called");
		((MonoBehaviour)this).StartCoroutine(Call());
	}

	private IEnumerator Call()
	{
		yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null));
		yield return (object)new WaitUntil((Func<bool>)(() => ServiceLocator.GetService<ISaveLoaderService>() != null));
		Debug.Log((object)"Initializing No Particles Mod...");
		new Harmony("NoParticles").PatchAll();
		DoConfig();
		((MonoBehaviour)this).StartCoroutine(GenerateSettings());
		CacheParticleSystems();
		ApplyParticleSettings(configEnableNoParticles.Value);
		Debug.Log((object)"No Particles Mod Loaded Successfully!");
	}

	private IEnumerator GenerateSettings()
	{
		GlobalSettingsHandler service = null;
		yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)(service = ServiceLocator.GetService<GlobalSettingsHandler>()))));
		Debug.Log((object)"GlobalSettingsHandler retrieved");
		List<SettingsInstance> list = service.VideoSettings.ToList();
		SettingsInstance val2 = new SettingsInstance();
		val2.settingsType = (SettingsType)0;
		val2.options = new string[2] { "On", "Off" };
		val2.currentValue = ((!configEnableNoParticles.Value) ? 1 : 0);
		val2.m_settingsKey = "Enable No Particles";
		val2.toolTip = "Disables all particle effects to improve performance.";
		SettingsInstance val3 = val2;
		val3.OnValueChanged += delegate(int val)
		{
			Debug.Log((object)$"OnValueChanged triggered with value: {val}");
			configEnableNoParticles.Value = val == 0;
			Debug.Log((object)$"Config updated: EnableNoParticles = {configEnableNoParticles.Value}");
			ApplyParticleSettings(configEnableNoParticles.Value);
		};
		list.Add(val3);
		FieldInfo field = ((object)service).GetType().GetField("m_videoSettings", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field != null)
		{
			field.SetValue(service, list.ToArray());
			Debug.Log((object)"Video settings updated successfully");
		}
		else
		{
			Debug.LogError((object)"Failed to find m_videoSettings field");
		}
	}

	private void DoConfig()
	{
		configEnableNoParticles = ((BaseUnityPlugin)this).Config.Bind<bool>("Video", "EnableNoParticles", false, "Enable or disable the No Particles Mod.");
		Debug.Log((object)$"Config loaded: EnableNoParticles = {configEnableNoParticles.Value}");
	}

	private void CacheParticleSystems()
	{
		Debug.Log((object)"Caching particle systems...");
		cachedParticleSystems = Resources.FindObjectsOfTypeAll<ParticleSystem>().ToList();
		Debug.Log((object)$"Cached {cachedParticleSystems.Count} particle systems");
	}

	private void ApplyParticleSettings(bool disableParticles)
	{
		Debug.Log((object)$"ApplyParticleSettings called with disableParticles = {disableParticles}");
		foreach (ParticleSystem cachedParticleSystem in cachedParticleSystems)
		{
			if (!((Object)(object)cachedParticleSystem == (Object)null))
			{
				Debug.Log((object)("Processing particle system: " + ((Object)((Component)cachedParticleSystem).gameObject).name));
				if (disableParticles)
				{
					cachedParticleSystem.Stop();
					((Component)cachedParticleSystem).gameObject.SetActive(false);
				}
				else
				{
					((Component)cachedParticleSystem).gameObject.SetActive(true);
					cachedParticleSystem.Play();
				}
			}
		}
		Debug.Log((object)(disableParticles ? "Particles Disabled" : "Particles Enabled"));
	}
}