using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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("NoRainParticles")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+59934f601cac64d0499828fc202711abc8a17992")]
[assembly: AssemblyProduct("NoRainParticles")]
[assembly: AssemblyTitle("NoRainParticles")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace NoRainParticles
{
[BepInPlugin("MysticDEV.NoRainParticles", "NoRainParticles", "1.0.3")]
public class NoRainParticlesPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(StartOfRound), "SetShipLanding")]
internal class StartLandingPatch
{
private static bool hasTriggered;
[HarmonyPostfix]
private static void OnStartLanding()
{
if (!hasTriggered)
{
hasTriggered = true;
DisableRainParticles();
}
}
internal static void Reset()
{
hasTriggered = false;
}
}
[HarmonyPatch(typeof(StartOfRound), "StartGame")]
internal class ResetLandingTrigger
{
[HarmonyPrefix]
private static void Reset()
{
StartLandingPatch.Reset();
}
}
internal static ManualLogSource? logger;
private readonly Harmony harmony = new Harmony("MysticDEV.NoRainParticles");
private static bool hasLoggedParticles;
private void Awake()
{
logger = ((BaseUnityPlugin)this).Logger;
harmony.PatchAll();
logger.LogInfo((object)"NoRainParticles v1.0.3 is loaded!");
}
public static bool CanScan()
{
StartOfRound instance = StartOfRound.Instance;
if ((Object)(object)instance == (Object)null)
{
return false;
}
return !instance.inShipPhase;
}
public static void LogAllParticleSystems()
{
if (hasLoggedParticles)
{
return;
}
try
{
ManualLogSource? obj = logger;
if (obj != null)
{
obj.LogWarning((object)"===== LOGGING ALL PARTICLE SYSTEMS =====");
}
ParticleSystem[] array = Object.FindObjectsOfType<ParticleSystem>();
ManualLogSource? obj2 = logger;
if (obj2 != null)
{
obj2.LogWarning((object)$"Found {array.Length} total particle systems in scene");
}
ParticleSystem[] array2 = array;
foreach (ParticleSystem val in array2)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)null))
{
string name = ((Object)((Component)val).gameObject).name;
string text = (((Object)(object)((Component)val).transform.parent != (Object)null) ? ((Object)((Component)val).transform.parent).name : "NO_PARENT");
bool activeInHierarchy = ((Component)val).gameObject.activeInHierarchy;
bool isEmitting = val.isEmitting;
int particleCount = val.particleCount;
ManualLogSource? obj3 = logger;
if (obj3 != null)
{
obj3.LogWarning((object)$"Particle: '{name}' | Parent: '{text}' | Active: {activeInHierarchy} | Emitting: {isEmitting} | Count: {particleCount}");
}
}
}
ManualLogSource? obj4 = logger;
if (obj4 != null)
{
obj4.LogWarning((object)"===== END PARTICLE SYSTEMS LOG =====");
}
hasLoggedParticles = true;
}
catch (Exception ex)
{
ManualLogSource? obj5 = logger;
if (obj5 != null)
{
obj5.LogError((object)("Error logging particles: " + ex.Message));
}
}
}
public static void LogTimeOfDayEffects()
{
try
{
TimeOfDay val = Object.FindObjectOfType<TimeOfDay>();
if ((Object)(object)val != (Object)null)
{
ManualLogSource? obj = logger;
if (obj != null)
{
obj.LogWarning((object)"===== LOGGING TIMEOFDAY EFFECTS =====");
}
if (val.effects != null && val.effects.Length != 0)
{
ManualLogSource? obj2 = logger;
if (obj2 != null)
{
obj2.LogWarning((object)$"Found {val.effects.Length} weather effects");
}
for (int i = 0; i < val.effects.Length; i++)
{
WeatherEffect val2 = val.effects[i];
if (val2 == null || !((Object)(object)val2.effectObject != (Object)null))
{
continue;
}
ManualLogSource? obj3 = logger;
if (obj3 != null)
{
obj3.LogWarning((object)$"Effect[{i}]: '{((Object)val2.effectObject).name}' | Enabled: {val2.effectEnabled} | Active: {val2.effectObject.activeSelf}");
}
Transform[] componentsInChildren = val2.effectObject.GetComponentsInChildren<Transform>(true);
foreach (Transform val3 in componentsInChildren)
{
if ((Object)(object)((Component)val3).gameObject != (Object)(object)val2.effectObject)
{
ManualLogSource? obj4 = logger;
if (obj4 != null)
{
obj4.LogWarning((object)$" Child: '{((Object)((Component)val3).gameObject).name}' | Active: {((Component)val3).gameObject.activeSelf}");
}
}
}
}
}
else
{
ManualLogSource? obj5 = logger;
if (obj5 != null)
{
obj5.LogWarning((object)"TimeOfDay.effects is null or empty!");
}
}
ManualLogSource? obj6 = logger;
if (obj6 != null)
{
obj6.LogWarning((object)"===== END TIMEOFDAY EFFECTS LOG =====");
}
}
else
{
ManualLogSource? obj7 = logger;
if (obj7 != null)
{
obj7.LogWarning((object)"Could not find TimeOfDay object!");
}
}
}
catch (Exception ex)
{
ManualLogSource? obj8 = logger;
if (obj8 != null)
{
obj8.LogError((object)("Error logging TimeOfDay effects: " + ex.Message));
}
}
}
public static void DisableRainParticles()
{
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!CanScan())
{
return;
}
int num = 0;
ParticleSystem[] array = Object.FindObjectsOfType<ParticleSystem>();
ManualLogSource? obj = logger;
if (obj != null)
{
obj.LogInfo((object)$"[DESCENT] Scanning {array.Length} particle systems...");
}
ParticleSystem[] array2 = array;
foreach (ParticleSystem val in array2)
{
if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).gameObject == (Object)null)
{
continue;
}
string text = ((Object)((Component)val).gameObject).name.ToLower();
string text2 = (((Object)(object)((Component)val).transform.parent != (Object)null) ? ((Object)((Component)val).transform.parent).name.ToLower() : "");
bool num2 = text.Contains("rain") || text2.Contains("rain") || (text2.Contains("storm") && text.Contains("particle"));
bool flag = text.Contains("lightning") || text.Contains("thunder") || text.Contains("bolt") || text.Contains("strike") || text.Contains("puddle") || text.Contains("splash") || text.Contains("mud") || text.Contains("ground") || text.Contains("magnet") || text.Contains("spark") || text.Contains("electric") || text.Contains("charge") || text.Contains("static") || text.Contains("blast") || text.Contains("warning") || text.Contains("flash") || text2.Contains("magnet") || (text2.Contains("stormy") && (text.Contains("static") || text.Contains("blast") || text.Contains("warning")));
if (num2 && !flag)
{
val.Stop(true, (ParticleSystemStopBehavior)0);
val.Clear();
EmissionModule emission = val.emission;
((EmissionModule)(ref emission)).enabled = false;
ParticleSystemRenderer component = ((Component)val).GetComponent<ParticleSystemRenderer>();
if ((Object)(object)component != (Object)null)
{
((Renderer)component).enabled = false;
((Renderer)component).forceRenderingOff = true;
}
((Component)val).gameObject.SetActive(false);
num++;
ManualLogSource? obj2 = logger;
if (obj2 != null)
{
string[] obj3 = new string[5]
{
"DISABLED: '",
((Object)((Component)val).gameObject).name,
"' (Parent: '",
null,
null
};
Transform parent = ((Component)val).transform.parent;
obj3[3] = ((parent != null) ? ((Object)parent).name : null);
obj3[4] = "')";
obj2.LogInfo((object)string.Concat(obj3));
}
}
}
ManualLogSource? obj4 = logger;
if (obj4 != null)
{
obj4.LogInfo((object)$"Disabled {num} rain particle systems");
}
}
catch (Exception ex)
{
ManualLogSource? obj5 = logger;
if (obj5 != null)
{
obj5.LogError((object)("Error disabling rain particles: " + ex.Message));
}
}
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("SetToCurrentLevelWeather")]
[HarmonyPostfix]
private static void OnSetWeather()
{
ManualLogSource? logger = NoRainParticlesPlugin.logger;
if (logger != null)
{
logger.LogInfo((object)"RoundManager.SetToCurrentLevelWeather called");
}
NoRainParticlesPlugin.LogTimeOfDayEffects();
NoRainParticlesPlugin.LogAllParticleSystems();
NoRainParticlesPlugin.DisableRainParticles();
}
[HarmonyPatch("GenerateNewLevelClientRpc")]
[HarmonyPostfix]
private static void OnGenerateNewLevel()
{
ManualLogSource? logger = NoRainParticlesPlugin.logger;
if (logger != null)
{
logger.LogInfo((object)"RoundManager.GenerateNewLevelClientRpc called");
}
}
}
[HarmonyPatch(typeof(TimeOfDay))]
internal class TimeOfDayPatch
{
private static float lastCheckTime;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void OnTimeOfDayStart()
{
ManualLogSource? logger = NoRainParticlesPlugin.logger;
if (logger != null)
{
logger.LogInfo((object)"TimeOfDay.Start called");
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void OnTimeOfDayUpdate()
{
if (Time.time - lastCheckTime > 5f)
{
lastCheckTime = Time.time;
NoRainParticlesPlugin.DisableRainParticles();
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("StartGame")]
[HarmonyPostfix]
private static void OnStartGame()
{
ManualLogSource? logger = NoRainParticlesPlugin.logger;
if (logger != null)
{
logger.LogInfo((object)"StartOfRound.StartGame called");
}
NoRainParticlesPlugin.DisableRainParticles();
}
}
}