using System;
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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using MrovLib;
using MrovLib.Events;
using UnityEngine;
using WeatherRegistry;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WeatherInjector")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WeatherInjector")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("744944a1-3e69-4d97-a708-cdaf12151b51")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace WeatherInjector;
[BepInPlugin("ZetaArcade.WeatherInjector", "WeatherInjector", "1.1.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class WeatherInjectorBase : BaseUnityPlugin
{
private const string modGUID = "ZetaArcade.WeatherInjector";
private const string modName = "WeatherInjector";
private const string modVersion = "1.1.3";
private readonly Harmony harmony = new Harmony("ZetaArcade.WeatherInjector");
private void Awake()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
((CustomEvent)EventManager.SetupFinished).AddListener(new Event(OnSetupFinished));
((CustomEvent<(SelectableLevel, Weather)>)(object)EventManager.ShipLanding).AddListener((ParameterEvent<(SelectableLevel, Weather)>)WeatherDebug);
ConfigManager.Init(((BaseUnityPlugin)this).Config);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin is loaded!");
harmony.PatchAll(typeof(WeatherInjectorBase));
}
private void WeatherDebug((SelectableLevel level, Weather weather) param)
{
if (((ConfigHandler<bool, bool>)(object)ConfigManager.DebugMode).Value && Object.op_Implicit((Object)(object)StartOfRound.Instance) && Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel))
{
SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
RandomWeatherWithVariables[] randomWeathers = currentLevel.randomWeathers;
foreach (RandomWeatherWithVariables val in randomWeathers)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)(((object)(LevelWeatherType)(ref val.weatherType)).ToString() + " on " + ((Object)currentLevel).name + " has these weather variables: " + val.weatherVariable + " & " + val.weatherVariable2));
}
}
}
private void OnSetupFinished()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Injecting weathers!");
if (((ConfigHandler<bool, bool>)(object)ConfigManager.UnregisterAllVanillaWeathers).Value)
{
UnregisterAllVanillaWeathers();
}
TryInjectWeather(ConfigManager.NoneInjectionLevels, (LevelWeatherType)(-1));
TryInjectWeather(ConfigManager.DustInjectionLevels, (LevelWeatherType)0);
TryInjectWeather(ConfigManager.RainInjectionLevels, (LevelWeatherType)1);
TryInjectWeather(ConfigManager.FogInjectionLevels, (LevelWeatherType)3);
TryInjectWeather(ConfigManager.StormInjectionLevels, (LevelWeatherType)2);
TryInjectWeather(ConfigManager.FloodInjectionLevels, (LevelWeatherType)4);
TryInjectWeather(ConfigManager.EclipsedInjectionLevels, (LevelWeatherType)5);
}
private void UnregisterAllVanillaWeathers()
{
SelectableLevel[] levels = StartOfRound.Instance.levels;
SelectableLevel[] array = levels;
foreach (SelectableLevel levelToCheck in array)
{
CheckForWeather(levelToCheck, (LevelWeatherType)(-1));
CheckForWeather(levelToCheck, (LevelWeatherType)0);
CheckForWeather(levelToCheck, (LevelWeatherType)1);
CheckForWeather(levelToCheck, (LevelWeatherType)3);
CheckForWeather(levelToCheck, (LevelWeatherType)2);
CheckForWeather(levelToCheck, (LevelWeatherType)4);
CheckForWeather(levelToCheck, (LevelWeatherType)5);
}
}
private void CheckForWeather(SelectableLevel levelToCheck, LevelWeatherType weatherToCheck)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
Dictionary<LevelWeatherType, RandomWeatherWithVariables> dictionary = levelToCheck.randomWeathers.ToDictionary((RandomWeatherWithVariables l) => l.weatherType);
if (dictionary.TryGetValue(weatherToCheck, out var value))
{
WeatherController.RemoveRandomWeather(levelToCheck, value);
}
}
private void TryInjectWeather(StringConfigHandler FirstConfig, LevelWeatherType injectedWeatherType)
{
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Expected O, but got Unknown
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
int num = 0;
string[] array = ((ConfigHandler<string, string>)(object)FirstConfig).Value.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
string[] array2 = array;
foreach (string text in array2)
{
string[] array3 = text.Split(new char[1] { '@' }, StringSplitOptions.RemoveEmptyEntries);
if (array3.Length != 3)
{
continue;
}
string text2 = array3[0];
if (int.TryParse(array3[1], out var result) && int.TryParse(array3[2], out var result2))
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Converting " + text2 + " to level refs"));
SelectableLevel[] array4 = ConfigHelper.ConvertStringToLevels(text2);
((BaseUnityPlugin)this).Logger.LogInfo((object)(array4.Length + " level refs found!"));
RandomWeatherWithVariables val = new RandomWeatherWithVariables
{
weatherType = injectedWeatherType,
weatherVariable = result,
weatherVariable2 = result2
};
SelectableLevel[] array5 = array4;
foreach (SelectableLevel val2 in array5)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Injecting " + ((object)(LevelWeatherType)(ref val.weatherType)).ToString() + " into " + val2.PlanetName + ", with weather variables of '" + val.weatherVariable + "' and '" + val.weatherVariable2 + "'"));
SelectableLevel[] levels = StartOfRound.Instance.levels;
Dictionary<string, SelectableLevel> dictionary = levels.ToDictionary((SelectableLevel l) => ((Object)l).name);
if (dictionary.TryGetValue(((Object)val2).name, out var value))
{
Dictionary<LevelWeatherType, RandomWeatherWithVariables> dictionary2 = value.randomWeathers.ToDictionary((RandomWeatherWithVariables l) => l.weatherType);
if (dictionary2.TryGetValue(injectedWeatherType, out var value2))
{
WeatherController.RemoveRandomWeather(value, value2);
}
WeatherController.AddRandomWeather(value, val);
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Couldn't find " + ((Object)val2).name));
}
}
}
num++;
}
}
}
public class ConfigManager
{
public static ConfigFile config;
public static BooleanConfigHandler DebugMode = new BooleanConfigHandler(false, true);
public static BooleanConfigHandler UnregisterAllVanillaWeathers = new BooleanConfigHandler(false, true);
public static StringConfigHandler NoneInjectionLevels = new StringConfigHandler("", true);
public static StringConfigHandler RainInjectionLevels = new StringConfigHandler("", true);
public static StringConfigHandler DustInjectionLevels = new StringConfigHandler("", true);
public static StringConfigHandler StormInjectionLevels = new StringConfigHandler("", true);
public static StringConfigHandler FloodInjectionLevels = new StringConfigHandler("", true);
public static StringConfigHandler FogInjectionLevels = new StringConfigHandler("", true);
public static StringConfigHandler EclipsedInjectionLevels = new StringConfigHandler("", true);
public static void Init(ConfigFile configFile)
{
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Expected O, but got Unknown
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Expected O, but got Unknown
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Expected O, but got Unknown
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Expected O, but got Unknown
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Expected O, but got Unknown
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Expected O, but got Unknown
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Expected O, but got Unknown
//IL_0259: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Expected O, but got Unknown
config = configFile;
((ConfigHandler<bool, bool>)(object)DebugMode).ConfigFile = config;
((ConfigHandler<bool, bool>)(object)UnregisterAllVanillaWeathers).ConfigFile = configFile;
((ConfigHandler<string, string>)(object)NoneInjectionLevels).ConfigFile = configFile;
((ConfigHandler<string, string>)(object)RainInjectionLevels).ConfigFile = config;
((ConfigHandler<string, string>)(object)DustInjectionLevels).ConfigFile = config;
((ConfigHandler<string, string>)(object)FogInjectionLevels).ConfigFile = config;
((ConfigHandler<string, string>)(object)FloodInjectionLevels).ConfigFile = config;
((ConfigHandler<string, string>)(object)StormInjectionLevels).ConfigFile = config;
((ConfigHandler<string, string>)(object)EclipsedInjectionLevels).ConfigFile = config;
((ConfigHandler<bool, bool>)(object)DebugMode).DefaultValue = false;
((ConfigHandler<bool, bool>)(object)DebugMode).SetConfigEntry("Debug", "Debug Mode", new ConfigDescription("Enable logging of all weather variables for every weather registered to the current moon after landing, useful if you want to see what WeatherVariables those moons use", (AcceptableValueBase)null, Array.Empty<object>()));
((ConfigHandler<bool, bool>)(object)UnregisterAllVanillaWeathers).DefaultValue = false;
((ConfigHandler<bool, bool>)(object)UnregisterAllVanillaWeathers).SetConfigEntry("General", "Unregister All Vanilla Weathers", new ConfigDescription("When enabled, before any injections from this mod happen, all vanilla weather (including Clear weather!) is unregistered from every moon, ensuring that only vanilla weathers on moon will be ones you inject yourself. This is mostly for if you want to remove clear weather from moons, as you can already prevent a weather appearing on a moon by just blacklisting it in WeatherRegistry.", (AcceptableValueBase)null, Array.Empty<object>()));
((ConfigHandler<string, string>)(object)NoneInjectionLevels).DefaultValue = "";
((ConfigHandler<string, string>)(object)NoneInjectionLevels).SetConfigEntry("None (Clear)", "None (Clear) Levels", new ConfigDescription("Levels to inject 'None' (Clear) weather into, in a semi-colon seperated list, with each entry being the moon internal name, followed by an @ and the first weather variable as an int and then an @ with the 2nd variable E.g. Experimentation@1@9;Assurance@1@3;Gloom@0@0; If you don't know what a weather variable is, leave them both as 0. WARNING, might lead to some incredibly buggy behaviour, some things in mods might break if Clear isn't a possible weather, use at your own risk!", (AcceptableValueBase)null, Array.Empty<object>()));
((ConfigHandler<string, string>)(object)DustInjectionLevels).DefaultValue = "";
((ConfigHandler<string, string>)(object)DustInjectionLevels).SetConfigEntry("DustClouds", "Dust Clouds Levels", new ConfigDescription("Levels to inject DustClouds weather into, in a semi-colon seperated list, with each entry being the moon internal name, followed by an @ and the first weather variable as an int and then an @ with the 2nd variable E.g. Experimentation@1@9;Assurance@1@3;Gloom@0@0; If you don't know what a weather variable is, leave them both as 0. To my knowledge, these values do nothing with DustClouds anyways.", (AcceptableValueBase)null, Array.Empty<object>()));
((ConfigHandler<string, string>)(object)RainInjectionLevels).DefaultValue = "Experimentation@0@0;Assurance@0@0;Vow@0@0;March@0@0;Offense@0@0;Adamance@0@0;Rend@0@0;Dine@0@0;Titan@0@0;Artifice@0@0;";
((ConfigHandler<string, string>)(object)RainInjectionLevels).SetConfigEntry("Rainy", "Rainy Levels", new ConfigDescription("Levels to inject Rainy weather into, in a semi-colon seperated list, with each entry being the moon internal name, followed by an @ and the first weather variable as an int and then an @ with the 2nd variable E.g. Experimentation@1@9;Assurance@1@3;Gloom@0@0; If you don't know what a weather variable is, leave them both as 0. To my knowledge, these values do nothing with Rainy anyways.", (AcceptableValueBase)null, Array.Empty<object>()));
((ConfigHandler<string, string>)(object)FogInjectionLevels).DefaultValue = "Experimentation@4@7;Assurance@6@17;Vow@4@18;March@6@16;Offense@5@18;Adamance@5@13;Embrion@4@15;Titan@4@12;";
((ConfigHandler<string, string>)(object)FogInjectionLevels).SetConfigEntry("Foggy", "Foggy Levels", new ConfigDescription("Levels to inject Foggy weather into, in a semi-colon seperated list, with each entry being the moon internal name, followed by an @ and the first weather variable as an int and then an @ with the 2nd variable E.g. Experimentation@1@9;Assurance@1@3;Gloom@10@10; If you don't know what a weather variable is, leave them both as 0. For Foggy, the variables are used to control the min/max fog density.", (AcceptableValueBase)null, Array.Empty<object>()));
((ConfigHandler<string, string>)(object)FloodInjectionLevels).DefaultValue = "Experimentation@-4@5;Assurance@-2@2;Vow@-6@6;March@-8@7;Offense@-4@5;Adamance@-3@-24;Dine@-11@-10;Artifice@-10@6;";
((ConfigHandler<string, string>)(object)FloodInjectionLevels).SetConfigEntry("Flooded", "Flooded Levels", new ConfigDescription("Levels to inject Flooded weather into, in a semi-colon seperated list, with each entry being the moon internal name, followed by an @ and the first weather variable as an int and then an @ with the 2nd variable E.g. Experimentation@1@9;Assurance@1@3;Gloom@0@0; If you don't know what a weather variable is, leave them both as 0. For Flooded, the 1st number controls the starting height of the water, and the 2nd controls the delta (how much height to add/subtract). For reference, Experimentation's defaults are -4@5, and Adamance (Which starts high but ends up low) is -3@-24.", (AcceptableValueBase)null, Array.Empty<object>()));
((ConfigHandler<string, string>)(object)StormInjectionLevels).DefaultValue = "Experimentation@1@0;Assurance@1@0;Vow@1@0;March@1@0;Offense@1@0;Adamance@1@0;Rend@1@0;Titan@1@0;Artifice@1@0;";
((ConfigHandler<string, string>)(object)StormInjectionLevels).SetConfigEntry("Stormy", "Stormy Levels", new ConfigDescription("Levels to inject Stormy weather into, in a semi-colon seperated list, with each entry being the moon internal name, followed by an @ and the first weather variable as an int and then an @ with the 2nd variable E.g. Experimentation@1@0;Assurance0@0;Gloom@3@0; If you don't know what a weather variable is, leave them both as 1. For Stormy, the 1st number controls how often lightning strikes. The 2nd value does nothing.", (AcceptableValueBase)null, Array.Empty<object>()));
((ConfigHandler<string, string>)(object)EclipsedInjectionLevels).DefaultValue = "Experimentation@1@0;Assurance@1@0;Vow@1@0;March@2@0;Offense@4@0;Adamance@3@0;Embrion@4@0;Rend@3@0;Dine@4@0;Titan@3@0;Artifice@3@0;";
((ConfigHandler<string, string>)(object)EclipsedInjectionLevels).SetConfigEntry("Eclipsed", "Eclipsed Levels", new ConfigDescription("Levels to inject Eclipsed weather into, in a semi-colon seperated list, with each entry being the moon internal name, followed by an @ and the first weather variable as an int and then an @ with the 2nd variable E.g. Experimentation@3@0;Assurance@4@0;Gloom@10@0; If you don't know what a weather variable is, leave them both as 3. For Eclipsed, the 1st number controls how many extra enemies to spawn at the start of the day. The 2nd value does nothing.", (AcceptableValueBase)null, Array.Empty<object>()));
}
}