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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HellWeather.Helpers;
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("HellWeather")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HellWeather")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4ba09a9d-299a-4967-aeac-399f036eb7ec")]
[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]
namespace HellWeather
{
[BepInPlugin("stormytuna.HellWeather", "HellWeather", "1.0.3")]
public class HellWeatherBase : BaseUnityPlugin
{
public const string ModGUID = "stormytuna.HellWeather";
public const string ModName = "HellWeather";
public const string ModVersion = "1.0.3";
public static ManualLogSource Log = Logger.CreateLogSource("stormytuna.HellWeather");
public static HellWeatherBase Instance;
public static LevelWeatherType HellWeather;
private readonly Harmony harmony = new Harmony("stormytuna.HellWeather");
public static ConfigEntry<bool> AllowRainyWeather;
public static ConfigEntry<bool> AllowFoggyWeather;
public static ConfigEntry<bool> AllowFloodedWeather;
public static ConfigEntry<bool> AllowStormyWeather;
public static ConfigEntry<bool> AllowEclipsedWeather;
public static ConfigEntry<bool> AlwaysHellWeather;
private void Awake()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
if (Instance == null)
{
Instance = this;
}
HellWeather = (LevelWeatherType)(Enum.GetValues(typeof(LevelWeatherType)).Cast<LevelWeatherType>().Max() + 1);
Log.LogInfo((object)"Hell Weather has awoken!");
LoadConfigs();
harmony.PatchAll();
}
public void LoadConfigs()
{
AllowRainyWeather = ((BaseUnityPlugin)this).Config.Bind<bool>("AllowedWeathers", "AllowRainyWeather", true, "Whether or not to allow the Rainy weather type to appear in Hell weather planets");
AllowFoggyWeather = ((BaseUnityPlugin)this).Config.Bind<bool>("AllowedWeathers", "AllowFoggyWeather", true, "Whether or not to allow the Foggy weather type to appear in Hell weather planets");
AllowFloodedWeather = ((BaseUnityPlugin)this).Config.Bind<bool>("AllowedWeathers", "AllowFloodedWeather", true, "Whether or not to allow the Flooded weather type to appear in Hell weather planets");
AllowStormyWeather = ((BaseUnityPlugin)this).Config.Bind<bool>("AllowedWeathers", "AllowStormyWeather", true, "Whether or not to allow the Stormy weather type to appear in Hell weather planets");
AllowEclipsedWeather = ((BaseUnityPlugin)this).Config.Bind<bool>("AllowedWeathers", "AllowEclipsedWeather", true, "Whether or not to allow the Eclipsed weather type to appear in Hell weather planets");
AlwaysHellWeather = ((BaseUnityPlugin)this).Config.Bind<bool>("HellWeatherRarity", "AlwaysHellWeather", false, "Whether all planets will always have Hell weather");
}
public static bool CanApplyChangesToWeather(LevelWeatherType weather)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected I4, but got Unknown
return (weather - 1) switch
{
0 => AllowRainyWeather.Value,
2 => AllowFoggyWeather.Value,
3 => AllowFloodedWeather.Value,
1 => AllowStormyWeather.Value,
4 => AllowEclipsedWeather.Value,
_ => false,
};
}
}
}
namespace HellWeather.Patches
{
[HarmonyPatch]
public class EnableDisableWeatherEffectsPatches
{
private static void EnablePossibleWeatherEffects()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
foreach (RandomWeatherWithVariables vanillaRandomWeathersWithEffect in WeatherHelpers.GetVanillaRandomWeathersWithEffects(StartOfRound.Instance.currentLevel))
{
if (HellWeatherBase.CanApplyChangesToWeather(vanillaRandomWeathersWithEffect.weatherType))
{
WeatherEffect val = TimeOfDay.Instance.effects[vanillaRandomWeathersWithEffect.weatherType];
val.effectEnabled = true;
if ((Object)(object)val.effectPermanentObject != (Object)null)
{
val.effectPermanentObject.SetActive(true);
}
}
}
}
private static void DisableWeatherEffects()
{
foreach (WeatherEffect vanillaWeatherEffect in WeatherHelpers.GetVanillaWeatherEffects())
{
vanillaWeatherEffect.effectEnabled = false;
if ((Object)(object)vanillaWeatherEffect.effectPermanentObject != (Object)null)
{
vanillaWeatherEffect.effectPermanentObject.SetActive(false);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")]
public static void EnableWeathersAtStartOfGame()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if (StartOfRound.Instance.currentLevel.currentWeather == HellWeatherBase.HellWeather)
{
EnablePossibleWeatherEffects();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(AudioReverbTrigger), "ChangeAudioReverbForPlayer")]
public static void EnableWeathersOnChangeAudioReverb(AudioReverbTrigger __instance)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
if (__instance.enableCurrentLevelWeather && TimeOfDay.Instance.currentLevelWeather == HellWeatherBase.HellWeather)
{
EnablePossibleWeatherEffects();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
public static void DisableWeathers()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if (StartOfRound.Instance.currentLevel.currentWeather == HellWeatherBase.HellWeather)
{
DisableWeatherEffects();
}
}
}
[HarmonyPatch]
public class CurrentLevelWeatherPatches
{
private static bool changeBackToHellWeather;
private static void FuckCurrentLevelWeatherType(LevelWeatherType newWeatherType)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
if (TimeOfDay.Instance.currentLevelWeather == HellWeatherBase.HellWeather && HellWeatherBase.CanApplyChangesToWeather(newWeatherType))
{
TimeOfDay.Instance.currentLevelWeather = newWeatherType;
changeBackToHellWeather = true;
}
}
private static void UnfuckCurrentLevelWeatherType()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
if (changeBackToHellWeather)
{
TimeOfDay.Instance.currentLevelWeather = HellWeatherBase.HellWeather;
changeBackToHellWeather = false;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(EnemyAI), "CheckLineOfSightForPlayer")]
[HarmonyPatch(typeof(EnemyAI), "CheckLineOfSightForClosestPlayer")]
[HarmonyPatch(typeof(EnemyAI), "GetAllPlayersInLineOfSight")]
public static void PreCheckLineOfSight()
{
FuckCurrentLevelWeatherType((LevelWeatherType)3);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(EnemyAI), "CheckLineOfSightForPlayer")]
[HarmonyPatch(typeof(EnemyAI), "CheckLineOfSightForClosestPlayer")]
[HarmonyPatch(typeof(EnemyAI), "GetAllPlayersInLineOfSight")]
public static void PostCheckLineOfSight()
{
UnfuckCurrentLevelWeatherType();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(RoundManager), "SpawnOutsideHazards")]
public static void PreSpawnOutsideHazards()
{
FuckCurrentLevelWeatherType((LevelWeatherType)1);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(RoundManager), "SpawnOutsideHazards")]
public static void PostSpawnOutsideHazards()
{
UnfuckCurrentLevelWeatherType();
}
}
[HarmonyPatch(typeof(Enum))]
public class LevelWeatherTypePatch
{
[HarmonyPrefix]
[HarmonyPatch("ToString", new Type[] { })]
public static bool GetHellWeatherString(ref string __result, Enum __instance)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: 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)
if (__instance is LevelWeatherType val && val == HellWeatherBase.HellWeather)
{
__result = "Hell";
return false;
}
return true;
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class StartOfRoundPatch
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void Awake(SelectableLevel[] ___levels)
{
//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)
//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_0029: Expected O, but got Unknown
foreach (SelectableLevel val in ___levels)
{
val.randomWeathers = CollectionExtensions.AddToArray<RandomWeatherWithVariables>(val.randomWeathers, new RandomWeatherWithVariables
{
weatherType = HellWeatherBase.HellWeather
});
}
}
[HarmonyPrefix]
[HarmonyPatch("SetPlanetsWeather")]
public static bool MakeAllPlanetsHell(SelectableLevel[] ___levels)
{
//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_003c: Unknown result type (might be due to invalid IL or missing references)
if (!HellWeatherBase.AlwaysHellWeather.Value)
{
return true;
}
foreach (SelectableLevel val in ___levels)
{
val.currentWeather = HellWeatherBase.HellWeather;
HellWeatherBase.Log.LogInfo((object)$"Current weather: {val.currentWeather}");
}
return false;
}
[HarmonyPostfix]
[HarmonyPatch("OnShipLandedMiscEvents")]
public static void DisplayHellWeatherPopup()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
if (TimeOfDay.Instance.currentLevelWeather == HellWeatherBase.HellWeather)
{
IEnumerable<RandomWeatherWithVariables> source = TimeOfDay.Instance.currentLevel.randomWeathers.Where((RandomWeatherWithVariables rw) => rw.weatherType != HellWeatherBase.HellWeather && HellWeatherBase.CanApplyChangesToWeather(rw.weatherType));
IEnumerable<LevelWeatherType> values = source.Select((RandomWeatherWithVariables rw) => rw.weatherType);
string text = string.Join(", ", values);
HUDManager.Instance.DisplayTip("Weather alert!", "You have landed in some severe weather anomalies. Good luck.\nWeathers active: " + text, true, false, "LC_Tip1");
}
}
}
[HarmonyPatch(typeof(TimeOfDay))]
public class TimeOfDayPatch
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void Awake(ref WeatherEffect[] ___effects)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: 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_0037: Expected O, but got Unknown
___effects = CollectionExtensions.AddToArray<WeatherEffect>(___effects, new WeatherEffect
{
name = "hell",
sunAnimatorBool = (HellWeatherBase.AllowEclipsedWeather.Value ? "eclipse" : "")
});
}
}
[HarmonyPatch]
public class CurrentWeatherVariablePatches
{
private static float[] currentWeatherVariables = new float[7];
private static float[] currentWeatherVariables2 = new float[7];
private static LevelWeatherType? weatherTypeToUnfuck;
private static void FuckCurrentWeatherVariable(LevelWeatherType weatherType)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if (TimeOfDay.Instance.currentLevelWeather == HellWeatherBase.HellWeather && HellWeatherBase.CanApplyChangesToWeather(weatherType))
{
TimeOfDay.Instance.currentWeatherVariable = currentWeatherVariables[weatherType];
weatherTypeToUnfuck = weatherType;
}
}
private static void FuckCurrentWeatherVariable2(LevelWeatherType weatherType)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if (TimeOfDay.Instance.currentLevelWeather == HellWeatherBase.HellWeather && HellWeatherBase.CanApplyChangesToWeather(weatherType))
{
TimeOfDay.Instance.currentWeatherVariable2 = currentWeatherVariables2[weatherType];
weatherTypeToUnfuck = weatherType;
}
}
private static void UnfuckCurrentWeatherVariable()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
if (weatherTypeToUnfuck.HasValue)
{
currentWeatherVariables[weatherTypeToUnfuck.Value] = TimeOfDay.Instance.currentWeatherVariable;
weatherTypeToUnfuck = null;
}
}
private static void UnfuckCurrentWeatherVariable2()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
if (weatherTypeToUnfuck.HasValue)
{
currentWeatherVariables2[weatherTypeToUnfuck.Value] = TimeOfDay.Instance.currentWeatherVariable2;
weatherTypeToUnfuck = null;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(RoundManager), "SetToCurrentLevelWeather")]
public static void SetupCurrentWeatherVariables(RoundManager __instance)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
foreach (RandomWeatherWithVariables vanillaRandomWeathersWithEffect in WeatherHelpers.GetVanillaRandomWeathersWithEffects(__instance.currentLevel))
{
currentWeatherVariables[vanillaRandomWeathersWithEffect.weatherType] = vanillaRandomWeathersWithEffect.weatherVariable;
currentWeatherVariables2[vanillaRandomWeathersWithEffect.weatherType] = vanillaRandomWeathersWithEffect.weatherVariable2;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
public static void ResetCurrentWeatherVariables()
{
currentWeatherVariables = new float[7];
currentWeatherVariables2 = new float[7];
}
[HarmonyPrefix]
[HarmonyPatch(typeof(EclipseWeather), "OnEnable")]
public static void FuckEclipsedWeatherVariables()
{
FuckCurrentWeatherVariable((LevelWeatherType)5);
FuckCurrentWeatherVariable2((LevelWeatherType)5);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(EclipseWeather), "OnEnable")]
public static void UnfuckEclipsedWeatherVariables()
{
UnfuckCurrentWeatherVariable();
UnfuckCurrentWeatherVariable2();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(FloodWeather), "OnEnable")]
[HarmonyPatch(typeof(FloodWeather), "Update")]
[HarmonyPatch(typeof(FloodWeather), "OnGlobalTimeSync")]
public static void FuckFloodedWeatherVariables()
{
FuckCurrentWeatherVariable((LevelWeatherType)4);
FuckCurrentWeatherVariable2((LevelWeatherType)4);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FloodWeather), "OnEnable")]
[HarmonyPatch(typeof(FloodWeather), "Update")]
[HarmonyPatch(typeof(FloodWeather), "OnGlobalTimeSync")]
public static void UnfuckFloodedWeatherVariables()
{
UnfuckCurrentWeatherVariable();
UnfuckCurrentWeatherVariable2();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StormyWeather), "DetermineNextStrikeInterval")]
[HarmonyPatch(typeof(StormyWeather), "LightningStrikeRandom")]
public static void FuckStormyWeatherVariables()
{
FuckCurrentWeatherVariable((LevelWeatherType)2);
FuckCurrentWeatherVariable2((LevelWeatherType)2);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StormyWeather), "DetermineNextStrikeInterval")]
[HarmonyPatch(typeof(StormyWeather), "LightningStrikeRandom")]
public static void UnfuckStormyWeatherVariables()
{
FuckCurrentWeatherVariable((LevelWeatherType)2);
FuckCurrentWeatherVariable2((LevelWeatherType)2);
}
}
}
namespace HellWeather.Helpers
{
public static class WeatherHelpers
{
public static bool IsVanillaWeather(LevelWeatherType weatherType)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Invalid comparison between Unknown and I4
return (int)weatherType >= -1 && (int)weatherType <= 5;
}
public static bool IsVanillaWeatherWithEffect(LevelWeatherType weatherType)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Invalid comparison between Unknown and I4
return (int)weatherType > -1 && (int)weatherType <= 5;
}
public static IEnumerable<RandomWeatherWithVariables> GetVanillaRandomWeathersWithEffects(SelectableLevel level)
{
return level.randomWeathers.Where((RandomWeatherWithVariables rw) => IsVanillaWeatherWithEffect(rw.weatherType));
}
public static IEnumerable<WeatherEffect> GetVanillaWeatherEffects()
{
for (int weatherType = 0; weatherType <= 5; weatherType++)
{
yield return TimeOfDay.Instance.effects[weatherType];
}
}
}
}