using System;
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 Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmpressOptimzier")]
[assembly: AssemblyTitle("EmpressOptimzier")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 EmpressOptimzier
{
[BepInPlugin("Omniscye.EmpressOptimzier", "EmpressOptimzier", "1.1")]
public class EmpressOptimzier : BaseUnityPlugin
{
public enum ParticleMode
{
Vanilla,
Off
}
private sealed class ParticleLimiterManager : MonoBehaviour
{
internal Func<float> ScanIntervalGetter = null;
private float _scanTimer;
private void Update()
{
_scanTimer -= Time.unscaledDeltaTime;
if (_scanTimer <= 0f)
{
_scanTimer = ((ScanIntervalGetter != null) ? ScanIntervalGetter() : 0.5f);
TryTagNewParticleSystems();
}
}
private void TryTagNewParticleSystems()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
ParticleSystem[] array = Resources.FindObjectsOfTypeAll<ParticleSystem>();
int num = 0;
ParticleTweaker particleTweaker = default(ParticleTweaker);
foreach (ParticleSystem val in array)
{
if (!Object.op_Implicit((Object)(object)val))
{
continue;
}
GameObject gameObject = ((Component)val).gameObject;
Scene scene = gameObject.scene;
if (!((Scene)(ref scene)).IsValid())
{
continue;
}
scene = gameObject.scene;
if (((Scene)(ref scene)).isLoaded)
{
if (!gameObject.TryGetComponent<ParticleTweaker>(ref particleTweaker))
{
particleTweaker = gameObject.AddComponent<ParticleTweaker>();
num++;
}
particleTweaker.Apply(soft: false);
}
}
if (num > 0)
{
Logger.LogDebug((object)$"Tagged {num} new ParticleSystems.");
}
}
}
private sealed class ParticleTweaker : MonoBehaviour
{
private ParticleSystem _ps = null;
private ParticleSystemRenderer _renderer = null;
private bool _captured;
private bool _origEmissionEnabled;
private float _origRateOverTimeMultiplier;
private float _origRateOverDistanceMultiplier;
private int _origMaxParticles;
private bool _origRendererEnabled = true;
private void Awake()
{
_ps = ((Component)this).GetComponent<ParticleSystem>();
_renderer = ((Component)this).GetComponent<ParticleSystemRenderer>();
CaptureIfNeeded();
OnReapplyAll += HandleReapply;
}
private void OnDestroy()
{
OnReapplyAll -= HandleReapply;
}
private void OnEnable()
{
Apply(soft: false);
}
private void LateUpdate()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
if (CurrentMode != ParticleMode.Off || !Object.op_Implicit((Object)(object)_ps))
{
return;
}
try
{
EmissionModule emission = _ps.emission;
if (((EmissionModule)(ref emission)).enabled)
{
((EmissionModule)(ref emission)).enabled = false;
}
if (_ps.isPlaying || _ps.particleCount > 0)
{
_ps.Stop(true, (ParticleSystemStopBehavior)0);
}
if (Object.op_Implicit((Object)(object)_renderer) && ((Renderer)_renderer).enabled)
{
((Renderer)_renderer).enabled = false;
}
}
catch
{
}
}
private void HandleReapply()
{
Apply(soft: false);
}
private void CaptureIfNeeded()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (!_captured && Object.op_Implicit((Object)(object)_ps))
{
EmissionModule emission = _ps.emission;
MainModule main = _ps.main;
_origEmissionEnabled = ((EmissionModule)(ref emission)).enabled;
_origRateOverTimeMultiplier = ((EmissionModule)(ref emission)).rateOverTimeMultiplier;
_origRateOverDistanceMultiplier = ((EmissionModule)(ref emission)).rateOverDistanceMultiplier;
_origMaxParticles = ((MainModule)(ref main)).maxParticles;
if (Object.op_Implicit((Object)(object)_renderer))
{
_origRendererEnabled = ((Renderer)_renderer).enabled;
}
_captured = true;
}
}
public void Apply(bool soft)
{
if (!Object.op_Implicit((Object)(object)_ps))
{
return;
}
if (!_captured)
{
CaptureIfNeeded();
}
switch (CurrentMode)
{
case ParticleMode.Vanilla:
Restore();
break;
case ParticleMode.Off:
Kill();
break;
}
if (soft || CurrentMode != ParticleMode.Off)
{
return;
}
try
{
if (_ps.isPlaying)
{
_ps.Stop(true, (ParticleSystemStopBehavior)1);
_ps.Play();
}
}
catch
{
}
}
private void Restore()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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)
try
{
EmissionModule emission = _ps.emission;
MainModule main = _ps.main;
((EmissionModule)(ref emission)).enabled = _origEmissionEnabled;
((EmissionModule)(ref emission)).rateOverTimeMultiplier = _origRateOverTimeMultiplier;
((EmissionModule)(ref emission)).rateOverDistanceMultiplier = _origRateOverDistanceMultiplier;
((MainModule)(ref main)).maxParticles = Mathf.Max(1, _origMaxParticles);
if (Object.op_Implicit((Object)(object)_renderer))
{
((Renderer)_renderer).enabled = _origRendererEnabled;
}
}
catch
{
}
}
private void Kill()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
try
{
EmissionModule emission = _ps.emission;
((EmissionModule)(ref emission)).enabled = false;
_ps.Stop(true, (ParticleSystemStopBehavior)0);
if (Object.op_Implicit((Object)(object)_renderer))
{
((Renderer)_renderer).enabled = false;
}
}
catch
{
}
}
}
private ConfigEntry<ParticleMode> _mode = null;
private ConfigEntry<float> _scanInterval = null;
private ParticleLimiterManager _limiter = null;
private const string EmbeddedAscii = "\r\n ______ \r\n | ____| \r\n | |__ _ __ ___ _ __ _ __ ___ ___ ___ \r\n | __| | '_ ` _ \\| '_ \\| '__/ _ \\/ __/ __| \r\n | |____| | | | | | |_) | | | __/\\__ \\__ \\ \r\n |______|_| |_| |_| .__/|_| \\___||___/___/ \r\n | | \r\n ____ _ |_| _ \r\n / __ \\ | | (_) (_) \r\n | | | |_ __ | |_ _ _ __ ___ _ _______ _ __ \r\n | | | | '_ \\| __| | '_ ` _ \\| |_ / _ \\ '__|\r\n | |__| | |_) | |_| | | | | | | |/ / __/ | \r\n \\____/| .__/ \\__|_|_| |_| |_|_/___\\___|_| \r\n | | \r\n |_| \r\n";
internal static EmpressOptimzier Instance { get; private set; } = null;
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
internal static ParticleMode CurrentMode => Instance?._mode.Value ?? ParticleMode.Off;
internal static event Action OnReapplyAll;
private void Awake()
{
Instance = this;
PrintAsciiBanner();
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Patch();
_mode = ((BaseUnityPlugin)this).Config.Bind<ParticleMode>("Particles", "Mode", ParticleMode.Off, "Vanilla = untouched, Off = stop & clear all particles.");
_scanInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Particles", "ScanIntervalSeconds", 0.5f, "How often to rescan for new ParticleSystems.");
_mode.SettingChanged += delegate
{
ReapplyAll();
};
SceneManager.sceneLoaded += delegate
{
ReapplyAll();
};
SceneManager.activeSceneChanged += delegate
{
ReapplyAll();
};
_limiter = ((Component)this).gameObject.AddComponent<ParticleLimiterManager>();
_limiter.ScanIntervalGetter = () => Mathf.Max(0.1f, _scanInterval.Value);
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} loaded. Particle mode={_mode.Value}");
}
private void PrintAsciiBanner()
{
Logger.LogInfo((object)"================================================================================");
string[] array = "\r\n ______ \r\n | ____| \r\n | |__ _ __ ___ _ __ _ __ ___ ___ ___ \r\n | __| | '_ ` _ \\| '_ \\| '__/ _ \\/ __/ __| \r\n | |____| | | | | | |_) | | | __/\\__ \\__ \\ \r\n |______|_| |_| |_| .__/|_| \\___||___/___/ \r\n | | \r\n ____ _ |_| _ \r\n / __ \\ | | (_) (_) \r\n | | | |_ __ | |_ _ _ __ ___ _ _______ _ __ \r\n | | | | '_ \\| __| | '_ ` _ \\| |_ / _ \\ '__|\r\n | |__| | |_) | |_| | | | | | | |/ / __/ | \r\n \\____/| .__/ \\__|_|_| |_| |_|_/___\\___|_| \r\n | | \r\n |_| \r\n".Split(new string[2] { "\r\n", "\n" }, StringSplitOptions.None);
foreach (string text in array)
{
Logger.LogInfo((object)text);
}
Logger.LogInfo((object)"================================================================================");
}
internal void Patch()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
internal static void ReapplyAll()
{
try
{
EmpressOptimzier.OnReapplyAll();
Logger.LogInfo((object)$"Reapplied particle settings (Mode={CurrentMode}).");
}
catch (Exception ex)
{
Logger.LogError((object)ex);
}
}
static EmpressOptimzier()
{
EmpressOptimzier.OnReapplyAll = delegate
{
};
}
}
[HarmonyPatch]
internal static class Patchme
{
}
}