Decompiled source of WeatherRegistry v0.5.3
WeatherRegistry.dll
Decompiled 3 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using ConsoleTables; using GameNetcodeStuff; using HarmonyLib; using JLL.Components; using LethalLib.Modules; using LobbyCompatibility.Enums; using LobbyCompatibility.Features; using Microsoft.CodeAnalysis; using MonoMod.RuntimeDetour; using MrovLib; using MrovLib.Compatibility; using MrovLib.Events; using Newtonsoft.Json; using On; using TMPro; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.ProBuilder; using WeatherRegistry.Compatibility; using WeatherRegistry.Definitions; using WeatherRegistry.Events; using WeatherRegistry.Modules; using WeatherRegistry.NetcodePatcher; using WeatherRegistry.Networking; using WeatherRegistry.Patches; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("ClientNetworkTransform")] [assembly: IgnoresAccessChecksTo("DissonanceVoip")] [assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")] [assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")] [assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")] [assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")] [assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")] [assembly: IgnoresAccessChecksTo("Unity.Burst")] [assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")] [assembly: IgnoresAccessChecksTo("Unity.Collections")] [assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")] [assembly: IgnoresAccessChecksTo("Unity.Jobs")] [assembly: IgnoresAccessChecksTo("Unity.Mathematics")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")] [assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")] [assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")] [assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")] [assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")] [assembly: IgnoresAccessChecksTo("Unity.Services.QoS")] [assembly: IgnoresAccessChecksTo("Unity.Services.Relay")] [assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")] [assembly: IgnoresAccessChecksTo("Unity.Timeline")] [assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")] [assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")] [assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")] [assembly: IgnoresAccessChecksTo("UnityEngine.UI")] [assembly: AssemblyCompany("WeatherRegistry")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("A Weather API for Lethal Company.")] [assembly: AssemblyFileVersion("0.5.3.0")] [assembly: AssemblyInformationalVersion("0.5.3+78f6df48269ccba350bd96262dfc70c34a8d7bb8")] [assembly: AssemblyProduct("WeatherRegistry")] [assembly: AssemblyTitle("WeatherRegistry")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/AndreyMrovol/LethalWeatherRegistry/")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: NetcodePatchedAssembly] internal class <Module> { static <Module>() { NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedINetworkSerializable<WeatherSyncDataWrapper>(); NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedValueEquals<WeatherSyncDataWrapper>(); NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedINetworkSerializable<WeatherEffectDataWrapper>(); NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedValueEquals<WeatherEffectDataWrapper>(); NetworkVariableSerializationTypes.InitializeSerializer_FixedString<FixedString4096Bytes>(); NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<FixedString4096Bytes>(); } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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 WeatherRegistry { public class Rarity { private int _weight; public int Weight { get { return _weight; } set { _weight = Math.Clamp(value, 0, 10000); } } } public class NameRarity : Rarity { public string Name { get; set; } } public class LevelRarity : Rarity { public SelectableLevel Level { get; set; } } public class WeatherRarity : Rarity { public Weather Weather { get; set; } } public abstract class ConfigHandler<T, CT> : WeatherRegistry.Definitions.ConfigHandler<T, CT> { public ConfigFile ConfigFile { get; set; } = ConfigManager.configFile; public ConfigHandler(CT value, bool enabled = true) { ((ConfigHandler<T, CT>)this).DefaultValue = value; base.Enabled = enabled; } public void SetConfigEntry(Weather weather, string configTitle, ConfigDescription configDescription = null) { if (base.Enabled) { ((ConfigHandler<T, CT>)this).ConfigEntry = ConfigFile.Bind<CT>(weather.ConfigCategory, configTitle, ((ConfigHandler<T, CT>)this).DefaultValue, configDescription); return; } ((ConfigHandler<T, CT>)this).ConfigEntry = null; Plugin.debugLogger.LogDebug((object)("Config entry for " + weather.Name + ": " + configTitle + " is disabled")); } public void SetConfigEntry(string configCategory, string configTitle, ConfigDescription configDescription = null) { if (base.Enabled) { ((ConfigHandler<T, CT>)this).ConfigEntry = ConfigFile.Bind<CT>(configCategory, configTitle, ((ConfigHandler<T, CT>)this).DefaultValue, configDescription); return; } ((ConfigHandler<T, CT>)this).ConfigEntry = null; Plugin.debugLogger.LogDebug((object)("Config entry " + configTitle + " is disabled")); } } public class LevelListConfigHandler : ConfigHandler<SelectableLevel[], string> { public override SelectableLevel[] Value => ConfigHelper.ConvertStringToLevels(base.ConfigEntryActive ? ((ConfigHandler<SelectableLevel[], string>)this).ConfigEntry.Value : ((ConfigHandler<SelectableLevel[], string>)this).DefaultValue); public LevelListConfigHandler(string value, bool enabled = true) : base(value, enabled) { } public LevelListConfigHandler(string[] value, bool enabled = true) : base(string.Join(";", value), enabled) { } } public class LevelWeightsConfigHandler : ConfigHandler<LevelRarity[], string> { public override LevelRarity[] Value => ConfigHelper.ConvertStringToLevelRarities(base.ConfigEntryActive ? ((ConfigHandler<LevelRarity[], string>)this).ConfigEntry.Value : ((ConfigHandler<LevelRarity[], string>)this).DefaultValue); public LevelWeightsConfigHandler(string value, bool enabled = true) : base(value, enabled) { } public LevelWeightsConfigHandler(string[] value, bool enabled = true) : base(string.Join(";", value), enabled) { } } public class WeatherWeightsConfigHandler : ConfigHandler<WeatherRarity[], string> { public override WeatherRarity[] Value => ConfigHelper.ConvertStringToWeatherWeights(base.ConfigEntryActive ? ((ConfigHandler<WeatherRarity[], string>)this).ConfigEntry.Value : ((ConfigHandler<WeatherRarity[], string>)this).DefaultValue); public WeatherWeightsConfigHandler(string value, bool enabled = true) : base(value, enabled) { } public WeatherWeightsConfigHandler(string[] value, bool enabled = true) : base(string.Join(";", value), enabled) { } } public class BooleanConfigHandler : ConfigHandler<bool, bool> { public override bool Value { get { if (!base.ConfigEntryActive) { return ((ConfigHandler<bool, bool>)this).DefaultValue; } return ((ConfigHandler<bool, bool>)this).ConfigEntry.Value; } } public BooleanConfigHandler(bool value, bool enabled = true) : base(value, enabled) { } public BooleanConfigHandler(FilteringOption filteringOption, bool enabled = true) : base(filteringOption == FilteringOption.Include, enabled) { } } public class IntegerConfigHandler : ConfigHandler<int, int> { public override int Value { get { if (!base.ConfigEntryActive) { return ((ConfigHandler<int, int>)this).DefaultValue; } return ((ConfigHandler<int, int>)this).ConfigEntry.Value; } } public IntegerConfigHandler(int value, bool enabled = true) : base(value, enabled) { } } public class FloatConfigHandler : ConfigHandler<float, float> { public override float Value { get { if (!base.ConfigEntryActive) { return ((ConfigHandler<float, float>)this).DefaultValue; } return ((ConfigHandler<float, float>)this).ConfigEntry.Value; } } public FloatConfigHandler(float value, bool enabled = true) : base(value, enabled) { } } public class StringConfigHandler : ConfigHandler<string, string> { public override string Value { get { if (!base.ConfigEntryActive) { return ((ConfigHandler<string, string>)this).DefaultValue; } return ((ConfigHandler<string, string>)this).ConfigEntry.Value; } } public StringConfigHandler(string value, bool enabled = true) : base(value, enabled) { } } internal class ConfigHelper { private static Logger logger = new Logger("WeatherRegistry", ConfigManager.LogWeightResolving); private static Dictionary<string, Weather> _weathersDictionary = null; public static Dictionary<string, Weather> StringToWeather { get { if (_weathersDictionary != null) { return _weathersDictionary; } Dictionary<string, Weather> Weathers = new Dictionary<string, Weather>(); WeatherManager.Weathers.ToList().ForEach(delegate(Weather weather) { Weathers.TryAdd(((Object)weather).name.ToLowerInvariant(), weather); Weathers.TryAdd(weather.Name.ToLowerInvariant(), weather); Weathers.TryAdd(GetAlphanumericName(weather).ToLowerInvariant(), weather); }); _weathersDictionary = Weathers; return Weathers; } set { _weathersDictionary = value; } } public static Weather ResolveStringToWeather(string str) { return StringToWeather.GetValueOrDefault(str.ToLowerInvariant()); } public static string GetNumberlessName(SelectableLevel level) { return StringResolver.GetNumberlessName(level); } public static string GetAlphanumericName(SelectableLevel level) { Regex regex = new Regex("^[0-9]+|[-_/\\\\\\ ]"); return new string(regex.Replace(level.PlanetName, "")); } public static string GetAlphanumericName(Weather weather) { Regex regex = new Regex("^[0-9]+|[-_/\\\\\\ ]"); return new string(regex.Replace(weather.Name, "")); } public static string[] ConvertStringToArray(string str) { return (from s in str.Split(';') where !string.IsNullOrWhiteSpace(s) select s.Trim()).ToArray(); } public static SelectableLevel[] ConvertStringToLevels(string str) { return StringResolver.ResolveStringToLevels(str); } public static NameRarity[] ConvertStringToRarities(string str) { string[] array = ConvertStringToArray(str); Dictionary<string, int> dictionary = new Dictionary<string, int>(); string[] array2 = array; foreach (string text in array2) { string[] array3 = text.Split('@'); if (array3.Length == 2 && int.TryParse(array3[1], out var result)) { string key = array3[0].Trim(); if (!dictionary.ContainsKey(key)) { dictionary.Add(key, result); } } } return dictionary.Select((KeyValuePair<string, int> rarity) => new NameRarity { Name = rarity.Key, Weight = rarity.Value }).ToArray(); } public static LevelRarity[] ConvertStringToLevelRarities(string str) { Dictionary<SelectableLevel, int> dictionary = new Dictionary<SelectableLevel, int>(); NameRarity[] array = ConvertStringToRarities(str); NameRarity[] array2 = array; foreach (NameRarity nameRarity in array2) { SelectableLevel[] array3 = StringResolver.ResolveStringToLevels(nameRarity.Name); SelectableLevel[] array4 = array3; foreach (SelectableLevel val in array4) { if (!((Object)(object)val == (Object)null)) { dictionary.TryAdd(val, nameRarity.Weight); } } } return dictionary.Select((KeyValuePair<SelectableLevel, int> rarity) => new LevelRarity { Level = rarity.Key, Weight = rarity.Value }).ToArray(); } public static WeatherRarity[] ConvertStringToWeatherWeights(string str) { Dictionary<Weather, int> dictionary = new Dictionary<Weather, int>(); NameRarity[] array = ConvertStringToRarities(str); NameRarity[] array2 = array; foreach (NameRarity nameRarity in array2) { Weather weather = ResolveStringToWeather(nameRarity.Name); if (!((Object)(object)weather == (Object)null)) { dictionary.TryAdd(weather, nameRarity.Weight); } } return dictionary.Select((KeyValuePair<Weather, int> rarity) => new WeatherRarity { Weather = rarity.Key, Weight = rarity.Value }).ToArray(); } } internal class ConfigManager { [CompilerGenerated] private static class <>O { public static Event <0>__StartupActions; public static EventHandler <1>__OnConfigChange; } internal static ConfigFile configFile; internal static ConfigManager Instance { get; private set; } internal static ConfigEntry<bool> LogWeatherChanges { get; private set; } internal static ConfigEntry<bool> LogStartup { get; private set; } internal static ConfigEntry<bool> LogStartupWeights { get; private set; } internal static ConfigEntry<bool> LogWeightResolving { get; private set; } internal static ConfigEntry<bool> ColoredWeathers { get; private set; } internal static ConfigEntry<bool> PlanetVideos { get; private set; } internal static ConfigEntry<bool> UseWeatherWeights { get; private set; } internal static ConfigEntry<bool> UseScrapMultipliers { get; private set; } internal static ConfigEntry<string> SunAnimatorBlacklist { get; set; } internal static SelectableLevel[] SunAnimatorBlacklistLevels { get; set; } internal static void Init(ConfigFile config) { Instance = new ConfigManager(config); } private ConfigManager(ConfigFile config) { //IL_0021: 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) //IL_002c: Expected O, but got Unknown configFile = config; WeatherRegistryEvent setupFinished = EventManager.SetupFinished; object obj = <>O.<0>__StartupActions; if (obj == null) { Event val = StartupActions; <>O.<0>__StartupActions = val; obj = (object)val; } ((CustomEvent)setupFinished).AddListener((Event)obj); LogWeatherChanges = configFile.Bind<bool>("|Debugging", "Log Weather Changes", true, "Log weather changes to console"); LogStartup = configFile.Bind<bool>("|Debugging", "Log Startup", true, "Log startup information to console"); LogStartupWeights = configFile.Bind<bool>("|Debugging", "Log Startup Weights", true, "Log all defined weights during startup"); LogWeightResolving = configFile.Bind<bool>("|Debugging", "Log Weight Resolving", true, "Log weight resolving to console"); ColoredWeathers = configFile.Bind<bool>("|General", "Colored Weathers", true, "Enable colored weathers on map screen"); PlanetVideos = configFile.Bind<bool>("|General", "Planet Videos", true, "Display planet videos on map screen"); UseWeatherWeights = configFile.Bind<bool>("|General", "Weather weights", true, "Use weights for selecting weathers. Disable if you want to use vanilla algorithm."); UseScrapMultipliers = configFile.Bind<bool>("|General", "Scrap multipliers", true, "Use Registry's scrap multipliers. Disable if you prefer to use other mod's multiplier settings."); SunAnimatorBlacklist = configFile.Bind<string>("|SunAnimator", "Blacklist", "Asteroid-13;", "Semicolon-separated list of level names to blacklist from being patched by sun animator"); } private static void OnConfigChange(object sender, EventArgs eventArgs) { SunAnimatorBlacklistLevels = ConfigHelper.ConvertStringToLevels(SunAnimatorBlacklist.Value); } internal static void StartupActions() { SunAnimatorBlacklistLevels = ConfigHelper.ConvertStringToLevels(SunAnimatorBlacklist.Value); SunAnimatorBlacklist.SettingChanged += OnConfigChange; } } internal class Defaults { internal static List<LevelWeatherType> VanillaWeathers = Defaults.VanillaWeathers; internal static Dictionary<LevelWeatherType, Color> VanillaWeatherColors = new Dictionary<LevelWeatherType, Color> { { (LevelWeatherType)(-1), new Color(0.41f, 1f, 0.42f, 1f) }, { (LevelWeatherType)0, new Color(0.28f, 0.19f, 0.1f, 1f) }, { (LevelWeatherType)3, new Color(1f, 0.86f, 0f, 1f) }, { (LevelWeatherType)1, new Color(1f, 0.86f, 0f, 1f) }, { (LevelWeatherType)2, new Color(1f, 0.57f, 0f, 1f) }, { (LevelWeatherType)4, new Color(1f, 0.57f, 0f, 1f) }, { (LevelWeatherType)5, new Color(1f, 0f, 0f, 1f) } }; internal static Dictionary<LevelWeatherType, string> VanillaWeatherToWeatherWeights = new Dictionary<LevelWeatherType, string> { { (LevelWeatherType)(-1), "None@160; Rainy@100; Stormy@70; Flooded@20; Foggy@40; Eclipsed@10" }, { (LevelWeatherType)1, "None@100; Rainy@60; Stormy@40; Flooded@30; Foggy@50; Eclipsed@20" }, { (LevelWeatherType)2, "None@160; Rainy@110; Stormy@10; Flooded@120; Foggy@20; Eclipsed@80" }, { (LevelWeatherType)4, "None@160; Rainy@60; Stormy@50; Flooded@10; Foggy@60; Eclipsed@40" }, { (LevelWeatherType)3, "None@200; Rainy@60; Stormy@50; Flooded@10; Foggy@30; Eclipsed@20" }, { (LevelWeatherType)5, "None@300; Rainy@40; Stormy@16; Flooded@20; Foggy@60; Eclipsed@10" } }; public static readonly string DefaultLevelFilters = "Company"; public static readonly string DefaultLevelWeights = "MoonName@50"; public static readonly string DefaultWeatherToWeatherWeights = "WeatherName@50"; public static readonly int DefaultWeight = 100; public static readonly float ScrapAmountMultiplier = 1f; public static readonly float ScrapValueMultiplier = 1f; public static readonly FilteringOption FilteringOption = FilteringOption.Exclude; internal static Color LethalLibColor = new Color(0f, 0.44f, 0.76f, 1f); internal static readonly string WeatherSaveKey = "WeatherRegistryCurrentWeathers"; } [CreateAssetMenu(fileName = "WeatherEffect", menuName = "WeatherRegistry/WeatherEffect", order = 10)] public class ImprovedWeatherEffect : ScriptableObject { [JsonIgnore] public GameObject EffectObject; [JsonIgnore] public GameObject WorldObject; private bool _effectEnabled; [field: SerializeField] public string SunAnimatorBool { get; set; } [field: SerializeField] public int DefaultVariable1 { get; set; } [field: SerializeField] public int DefaultVariable2 { get; set; } public LevelWeatherType LevelWeatherType { get; set; } = (LevelWeatherType)(-1); public virtual bool EffectEnabled { get { return _effectEnabled; } set { //IL_0058: Unknown result type (might be due to invalid IL or missing references) Plugin.logger.LogDebug((object)$"Setting effect {((Object)this).name} to {value}"); Plugin.logger.LogDebug((object)$"Is player inside? {EntranceTeleportPatch.isPlayerInside}"); if (!EntranceTeleportPatch.isPlayerInside) { GameObject effectObject = EffectObject; if (effectObject != null) { effectObject.SetActive(value); } WeatherEffectController.SetTimeOfDayEffect(LevelWeatherType, value); } GameObject worldObject = WorldObject; if (worldObject != null) { worldObject.SetActive(value); } _effectEnabled = value; } } public bool EffectActive { get { GameObject effectObject = EffectObject; if (effectObject == null) { return false; } return effectObject.activeSelf; } } public virtual void DisableEffect(bool permament = false) { if (permament) { EffectEnabled = false; return; } GameObject effectObject = EffectObject; if (effectObject != null) { effectObject.SetActive(false); } } public ImprovedWeatherEffect(GameObject effectObject, GameObject worldObject) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) EffectObject = effectObject; WorldObject = worldObject; GameObject effectObject2 = EffectObject; if (effectObject2 != null) { effectObject2.SetActive(false); } GameObject worldObject2 = WorldObject; if (worldObject2 != null) { worldObject2.SetActive(false); } } public ImprovedWeatherEffect(WeatherEffect weatherEffect) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) EffectObject = weatherEffect.effectObject; WorldObject = weatherEffect.effectPermanentObject; GameObject effectObject = EffectObject; if (effectObject != null) { effectObject.SetActive(false); } GameObject worldObject = WorldObject; if (worldObject != null) { worldObject.SetActive(false); } } } public enum WeatherType { Clear, Vanilla, Modded } public enum WeatherOrigin { Vanilla, WeatherRegistry, LethalLib, LethalLevelLoader, WeatherTweaks } public enum FilteringOption { Include, Exclude } [JsonObject(/*Could not decode attribute arguments.*/)] [CreateAssetMenu(fileName = "Weather", menuName = "WeatherRegistry/WeatherDefinition", order = 5)] public class Weather : ScriptableObject { [JsonProperty] public string Name; [JsonIgnore] public ImprovedWeatherEffect Effect; [JsonIgnore] public Dictionary<SelectableLevel, LevelWeatherVariables> WeatherVariables = new Dictionary<SelectableLevel, LevelWeatherVariables>(); [JsonIgnore] public AnimationClip AnimationClip; [JsonIgnore] public RegistryWeatherConfig Config = new RegistryWeatherConfig(); [JsonIgnore] internal Dictionary<SelectableLevel, WeatherEffectOverride> WeatherEffectOverrides = new Dictionary<SelectableLevel, WeatherEffectOverride>(); [Obsolete("Use Weather.Config.DefaultWeight instead")] internal int _defaultWeight = 100; [Obsolete("Use Weather.Config.ScrapAmountMultiplier instead")] internal float _scrapAmountMultiplier = 1f; [Obsolete("Use Weather.Config.ScrapValueMultiplier instead")] internal float _scrapValueMultiplier = 1f; [JsonProperty] public LevelWeatherType VanillaWeatherType { get; internal set; } = (LevelWeatherType)(-1); [JsonIgnore] internal WeatherOrigin Origin { get; set; } = WeatherOrigin.WeatherRegistry; [JsonProperty] public WeatherType Type { get; internal set; } = WeatherType.Modded; [field: SerializeField] public Color Color { get; set; } = Color.cyan; [SerializeField] public int DefaultWeight { get { return ((ConfigHandler<int, int>)Config.DefaultWeight).Value; } [Obsolete("Use Weather.Config.DefaultWeight instead")] set { _defaultWeight = value; } } [Obsolete("Use Weather.Config.LevelFilters instead")] public string[] DefaultLevelFilters { get { return ((ConfigHandler<SelectableLevel[], string>)Config.LevelFilters).DefaultValue.Split(";"); } set { Config.LevelFilters = new LevelListConfigHandler(value); } } [Obsolete("Use Weather.Config.LevelWeights instead")] public string[] DefaultLevelWeights { get { return ((ConfigHandler<LevelRarity[], string>)Config.LevelWeights).DefaultValue.Split(";"); } set { Config.LevelWeights = new LevelWeightsConfigHandler(value); } } [Obsolete("Use Weather.Config.WeatherToWeatherWeights instead")] public string[] DefaultWeatherToWeatherWeights { get { return ((ConfigHandler<WeatherRarity[], string>)Config.WeatherToWeatherWeights).DefaultValue.Split(";"); } set { Config.WeatherToWeatherWeights = new WeatherWeightsConfigHandler(value); } } public float ScrapAmountMultiplier { get { return ((ConfigHandler<float, float>)Config.ScrapAmountMultiplier).Value; } [Obsolete("Use Weather.Config.ScrapAmountMultiplier instead")] set { Config.ScrapAmountMultiplier = new FloatConfigHandler(value); } } public float ScrapValueMultiplier { get { return ((ConfigHandler<float, float>)Config.ScrapValueMultiplier).Value; } [Obsolete("Use Weather.Config.ScrapValueMultiplier instead")] set { Config.ScrapValueMultiplier = new FloatConfigHandler(value); } } [SerializeField] [JsonIgnore] public FilteringOption LevelFilteringOption { get { if (!((ConfigHandler<bool, bool>)Config.FilteringOption).Value) { return FilteringOption.Exclude; } return FilteringOption.Include; } [Obsolete("Use Weather.Config.FilteringOption instead")] set { Config.FilteringOption = new BooleanConfigHandler(value == FilteringOption.Include); } } [JsonIgnore] public List<SelectableLevel> LevelFilters => ((ConfigHandler<SelectableLevel[], string>)Config.LevelFilters).Value.ToList(); [JsonIgnore] public Dictionary<LevelWeatherType, int> WeatherWeights => ((ConfigHandler<WeatherRarity[], string>)Config.WeatherToWeatherWeights).Value.ToDictionary((WeatherRarity rarity) => rarity.Weather.VanillaWeatherType, (WeatherRarity rarity) => rarity.Weight); [JsonIgnore] public Dictionary<SelectableLevel, int> LevelWeights => ((ConfigHandler<LevelRarity[], string>)Config.LevelWeights).Value.ToDictionary((LevelRarity rarity) => rarity.Level, (LevelRarity rarity) => rarity.Weight); internal virtual string ConfigCategory => ((Type == WeatherType.Vanilla || Type == WeatherType.Clear) ? "Vanilla" : "Modded") + " Weather: " + ((Object)this).name + ((Origin != WeatherOrigin.WeatherRegistry && Origin != 0) ? $" ({Origin})" : ""); public Weather(string name = "None", ImprovedWeatherEffect effect = null) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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) Plugin.logger.LogDebug((object)("Called Weather constructor for weather " + name)); Regex regex = new Regex("<.*?>"); Name = regex.Replace(name, ""); ((Object)this).name = regex.Replace(name, ""); Effect = effect; if ((Object)(object)effect != (Object)null) { ((Object)Effect).name = name; } Object.DontDestroyOnLoad((Object)(object)this); } internal virtual void Init() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) Config.Init(this); if ((Object)(object)Effect != (Object)null) { Effect.LevelWeatherType = VanillaWeatherType; } ((Object)this).hideFlags = (HideFlags)61; } public void RemoveFromMoon(string moonNames) { ConfigHelper.ConvertStringToLevels(moonNames).ToList().ForEach(delegate(SelectableLevel level) { LevelFilters.Remove(level); }); } public void RemoveFromMoon(SelectableLevel moon) { LevelFilters.Remove(moon); } public int GetWeight(SelectableLevel level) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) Logger logger = WeatherCalculation.Logger; int num = DefaultWeight; Weather weather = WeatherManager.GetWeather(level.currentWeather); if ((Object)(object)weather == (Object)null) { logger.LogError((object)("Previous weather is null for " + ((Object)level).name)); } int value2; if (LevelWeights.TryGetValue(level, out var value)) { logger.LogDebug((object)$"{Name} has level weight {value}"); num = value; } else if (weather.WeatherWeights.TryGetValue(VanillaWeatherType, out value2) && StartOfRound.Instance.gameStats.daysSpent != 0) { logger.LogDebug((object)$"{Name} has weather>weather weight {value2}"); num = value2; } else { logger.LogDebug((object)$"{Name} has default weight {num}"); } return num; } public (bool isWTW, int weight) GetWeatherToWeatherWeight(Weather previousWeather) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (previousWeather.WeatherWeights.TryGetValue(VanillaWeatherType, out var value)) { return (true, value); } return (false, DefaultWeight); } public WeatherEffectOverride GetEffectOverride(SelectableLevel level) { if (WeatherEffectOverrides.ContainsKey(level)) { return WeatherEffectOverrides[level]; } return null; } } public class LevelWeatherVariables { public SelectableLevel Level; public int WeatherVariable1; public int WeatherVariable2; } public class LevelWeather : LevelWeatherVariables { public Weather Weather; public LevelWeatherVariables Variables; } public class EventManager { public static WeatherRegistryEvent DisableAllWeathers = new WeatherRegistryEvent(); public static WeatherRegistryEvent BeforeSetupStart = new WeatherRegistryEvent(); public static WeatherRegistryEvent SetupFinished = new WeatherRegistryEvent(); public static WeatherRegistryEvent<int> DayChanged = new WeatherRegistryEvent<int>(); public static WeatherRegistryEvent<(SelectableLevel level, Weather weather, string screenText)> MapScreenUpdated = new WeatherRegistryEvent<(SelectableLevel, Weather, string)>(); public static WeatherRegistryEvent<(SelectableLevel level, Weather weather)> WeatherChanged = new WeatherRegistryEvent<(SelectableLevel, Weather)>(); public static WeatherRegistryEvent<(SelectableLevel level, Weather weather)> ShipLanding = new WeatherRegistryEvent<(SelectableLevel, Weather)>(); } [HarmonyPatch(typeof(StartOfRound))] internal class OpeningDoorsSequencePatch { [HarmonyTranspiler] [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static IEnumerable<CodeInstruction> StartOfRound_openingDoorsSequence(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Expected O, but got Unknown //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Expected O, but got Unknown //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Expected O, but got Unknown //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Expected O, but got Unknown //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Expected O, but got Unknown //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Expected O, but got Unknown //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Expected O, but got Unknown //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Expected O, but got Unknown //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Expected O, but got Unknown //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Expected O, but got Unknown //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Expected O, but got Unknown //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Expected O, but got Unknown //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Expected O, but got Unknown //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Expected O, but got Unknown //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Expected O, but got Unknown //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Expected O, but got Unknown //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Expected O, but got Unknown //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Expected O, but got Unknown //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Expected O, but got Unknown //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_038c: Expected O, but got Unknown //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Expected O, but got Unknown //IL_03cb: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Expected O, but got Unknown //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Expected O, but got Unknown //IL_0419: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Expected O, but got Unknown //IL_0438: Unknown result type (might be due to invalid IL or missing references) //IL_043e: Expected O, but got Unknown //IL_045b: Unknown result type (might be due to invalid IL or missing references) //IL_0461: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); CodeMatcher val2 = val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[19] { new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(TimeOfDay), "get_Instance", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TimeOfDay), "effects"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(StartOfRound), "currentLevel"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(SelectableLevel), "currentWeather"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_2, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(WeatherEffect), "effectEnabled"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(WeatherEffect), "effectPermanentObject"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldnull, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Object), "op_Inequality", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(WeatherEffect), "effectPermanentObject"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(GameObject), "SetActive", (Type[])null, (Type[])null), (string)null) }); val2.RemoveInstructions(19); CodeMatcher val3 = val2.MatchForward(false, (CodeMatch[])(object)new CodeMatch[7] { new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(TimeOfDay), "get_Instance", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TimeOfDay), "effects"), (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(TimeOfDay), "get_Instance", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TimeOfDay), "currentLevelWeather"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(WeatherEffect), "effectEnabled"), (string)null) }); val3.RemoveInstructions(7); val3.Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(OpeningDoorsSequencePatch), "RunWeatherPatches", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(OpeningDoorsSequencePatch), "SetWeatherEffects", (Type[])null, (Type[])null)) }); val3.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldloc_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(StartOfRound), "currentLevel"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(SelectableLevel), "LevelDescription"), (string)null) }).Advance(3).Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldloc_1, (object)null), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(OpeningDoorsSequencePatch), "ModifyDescription", (Type[])null, (Type[])null)) }); return val.InstructionEnumeration(); } private static string ModifyDescription(string description, StartOfRound instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 string text = (((int)instance.currentLevel.currentWeather != -1) ? WeatherManager.GetCurrentWeatherName(instance.currentLevel) : "Clear"); string text2 = "WEATHER: " + text; Plugin.logger.LogDebug((object)text2); return text2 + "\n" + description; } internal static void RunWeatherPatches() { TimeOfDay.Instance.nextTimeSync = 0f; } internal static void SetWeatherEffects() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown //IL_0024: Unknown result type (might be due to invalid IL or missing references) SelectableLevel currentLevel = StartOfRound.Instance.currentLevel; Weather currentWeather = WeatherManager.GetCurrentWeather(currentLevel); if (((NetworkBehaviour)StartOfRound.Instance).IsHost) { WeatherSync.Instance.SetWeatherEffectOnHost(currentWeather.VanillaWeatherType); } Plugin.logger.LogDebug((object)("Landing at " + ConfigHelper.GetNumberlessName(currentLevel) + " with weather " + JsonConvert.SerializeObject((object)currentWeather, (Formatting)0, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 }))); ((CustomEvent<(SelectableLevel, Weather)>)(object)EventManager.ShipLanding).Invoke((currentLevel, currentWeather)); } } [HarmonyPatch(typeof(Terminal))] internal class TerminalPostprocessPatch { [HarmonyTranspiler] [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static IEnumerable<CodeInstruction> Terminal_textPostProcess(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Expected O, but got Unknown //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); CodeMatcher val2 = val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldflda, (object)AccessTools.Field(typeof(SelectableLevel), "currentWeather"), (string)null), new CodeMatch((OpCode?)OpCodes.Constrained, (object)AccessTools.TypeByName("LevelWeatherType"), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(object), "ToString", (Type[])null, (Type[])null), (string)null) }); val2.RemoveInstructions(3); val2.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(TerminalPostprocessPatch), "GetPlanetWeatherDisplayString", (Type[])null, (Type[])null)) }); CodeMatcher val3 = val2.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Ldflda, (object)AccessTools.Field(typeof(SelectableLevel), "currentWeather"), (string)null), new CodeMatch((OpCode?)OpCodes.Constrained, (object)AccessTools.TypeByName("LevelWeatherType"), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(object), "ToString", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(string), "ToLower", (Type[])null, (Type[])null), (string)null) }); val3.RemoveInstructions(4); val3.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(TerminalPostprocessPatch), "GetPlanetWeatherDisplayString", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.Method(typeof(string), "ToLower", (Type[])null, (Type[])null)) }); return val.InstructionEnumeration(); } private static string GetPlanetWeatherDisplayString(SelectableLevel level) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) Plugin.logger.LogDebug((object)("GetPlanetWeatherDisplayString called for " + level.PlanetName)); string text = WeatherManager.WeatherDisplayOverride(level); if (!(text == string.Empty)) { return text; } return WeatherManager.GetWeather(level.currentWeather).Name; } [HarmonyPatch(typeof(Terminal), "TextPostProcess")] [HarmonyPrefix] internal static void Prefix(ref TerminalNode node, ref string modifiedDisplayText) { if (node.displayPlanetInfo != -1) { Regex regex = new Regex("\\ It is (\\n)"); node.displayText = regex.Replace(node.displayText, " It is "); modifiedDisplayText = regex.Replace(modifiedDisplayText, " It is "); } } } [BepInPlugin("mrov.WeatherRegistry", "WeatherRegistry", "0.5.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string GUID = "mrov.WeatherRegistry"; internal static ManualLogSource logger; internal static Logger debugLogger = new Logger("mrov.WeatherRegistry", (ConfigEntry<bool>)null); internal static Harmony harmony = new Harmony("mrov.WeatherRegistry"); internal static bool IsLethalLibLoaded = false; internal static JLLCompat JLLCompat; internal static LobbyControlCompat LobbyControlCompat; internal static FacilityMeltdownCompat FacilityMeltdownCompat; internal static OrbitsCompat OrbitsCompat; internal static Hook WeatherTypeEnumHook; private void Awake() { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown logger = ((BaseUnityPlugin)this).Logger; harmony.PatchAll(); ConfigManager.Init(((BaseUnityPlugin)this).Config); SunAnimator.Init(); if (Chainloader.PluginInfos.ContainsKey("evaisa.lethallib")) { IsLethalLibLoaded = true; LethalLibPatch.Init(); } else { logger.LogInfo((object)"LethalLib not detected!"); } WeatherTypeEnumHook = new Hook((MethodBase)typeof(Enum).GetMethod("ToString", Array.Empty<Type>()), typeof(WeatherManager).GetMethod("LevelWeatherTypeEnumHook")); if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility")) { LobbyCompatibilityCompatibility.Init(); } JLLCompat = new JLLCompat("JacobG5.JLL"); LobbyControlCompat = new LobbyControlCompat("mattymatty.LobbyControl"); LobbyControlCompat.Init(); FacilityMeltdownCompat = new FacilityMeltdownCompat("me.loaforc.facilitymeltdown"); OrbitsCompat = new OrbitsCompat("com.fiufki.orbits"); OrbitsCompat.Init(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin mrov.WeatherRegistry is loaded!"); } } public class Settings { public static Dictionary<string, Color> ScreenMapColors = new Dictionary<string, Color>(); public static bool SetupFinished => WeatherManager.IsSetupFinished; public static bool SelectWeathers { get; set; } = true; public static WeatherSelectionAlgorithm WeatherSelectionAlgorithm { get; set; } = ConfigManager.UseWeatherWeights.Value ? WeatherCalculation.RegistryAlgorithm : WeatherCalculation.VanillaAlgorithm; public static bool ScrapMultipliers { get; set; } = ConfigManager.UseScrapMultipliers.Value; public static bool ColoredWeathers { get; set; } = ConfigManager.ColoredWeathers.Value; public static bool PlanetVideos { get; set; } = ConfigManager.PlanetVideos.Value; public static bool MapScreenOverride { get; set; } = true; } public class WeatherCalculation { internal class WeatherRegistryWeatherSelection : WeatherSelectionAlgorithm { public override Dictionary<SelectableLevel, LevelWeatherType> SelectWeathers(int connectedPlayersOnServer, StartOfRound startOfRound) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) if (!((NetworkBehaviour)startOfRound).IsHost) { Logger.LogInfo((object)"Not a host, cannot generate weathers!"); return null; } previousDayWeather.Clear(); Dictionary<SelectableLevel, LevelWeatherType> dictionary = new Dictionary<SelectableLevel, LevelWeatherType>(); Random random = GetRandom(startOfRound); List<SelectableLevel> list = startOfRound.levels.ToList(); Logger.LogDebug((object)("Levels: " + string.Join(';', list.Select((SelectableLevel level) => level.PlanetName)))); foreach (SelectableLevel item in list) { previousDayWeather[item.PlanetName] = item.currentWeather; Logger.LogMessage((object)"-------------"); Logger.LogMessage((object)(item.PlanetName ?? "")); Logger.LogDebug((object)$"previousDayWeather: {previousDayWeather[item.PlanetName]}"); if (item.overrideWeather) { Logger.LogMessage((object)$"Override weather present, changing weather to {item.overrideWeatherType}"); Weather weather = WeatherManager.GetWeather(item.overrideWeatherType); dictionary[item] = weather.VanillaWeatherType; ((CustomEvent<(SelectableLevel, Weather)>)(object)EventManager.WeatherChanged).Invoke((item, weather)); continue; } dictionary[item] = (LevelWeatherType)(-1); WeightHandler<Weather> planetWeightedList = WeatherManager.GetPlanetWeightedList(item); Weather weather2 = planetWeightedList.Random(); dictionary[item] = weather2.VanillaWeatherType; ((CustomEvent<(SelectableLevel, Weather)>)(object)EventManager.WeatherChanged).Invoke((item, weather2)); Logger.LogMessage((object)$"Selected weather: {weather2.Name} with chance {planetWeightedList.Get(weather2)} / {planetWeightedList.Sum} ({(float)planetWeightedList.Get(weather2) / (float)planetWeightedList.Sum * 100f}%)"); } Logger.LogMessage((object)"-------------"); return dictionary; } } internal class VanillaWeatherSelection : WeatherSelectionAlgorithm { public override Dictionary<SelectableLevel, LevelWeatherType> SelectWeathers(int connectedPlayersOnServer, StartOfRound startOfRound) { //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) Dictionary<SelectableLevel, LevelWeatherType> vanillaSelectedWeather = new Dictionary<SelectableLevel, LevelWeatherType>(); Random random = GetRandom(startOfRound); List<SelectableLevel> list = startOfRound.levels.ToList(); float num = 1f; if (connectedPlayersOnServer + 1 > 1 && startOfRound.daysPlayersSurvivedInARow > 2 && startOfRound.daysPlayersSurvivedInARow % 3 == 0) { num = (float)random.Next(15, 25) / 10f; } int num2 = Mathf.Clamp((int)((double)Mathf.Clamp(startOfRound.planetsWeatherRandomCurve.Evaluate((float)random.NextDouble()) * num, 0f, 1f) * (double)startOfRound.levels.Length), 0, startOfRound.levels.Length); list.ForEach(delegate(SelectableLevel level) { vanillaSelectedWeather[level] = (LevelWeatherType)(-1); }); Logger.LogMessage((object)"Selected vanilla algorithm - weights are not being used!"); Logger.LogMessage((object)$"Picking weathers for {num2} moons:"); Logger.LogMessage((object)"-------------"); for (int i = 0; i < num2; i++) { SelectableLevel val = list[random.Next(0, list.Count)]; if (val.randomWeathers != null && val.randomWeathers.Length != 0) { vanillaSelectedWeather[val] = val.randomWeathers[random.Next(0, val.randomWeathers.Length)].weatherType; Logger logger = Logger; string planetName = val.PlanetName; LevelWeatherType val2 = vanillaSelectedWeather[val]; logger.LogMessage((object)("Selected weather for " + planetName + ": " + ((object)(LevelWeatherType)(ref val2)).ToString())); } else { Logger.LogDebug((object)("Cannot pick weather for " + val.PlanetName)); } list.Remove(val); } Logger.LogMessage((object)"-------------"); return vanillaSelectedWeather; } } internal static Dictionary<string, LevelWeatherType> previousDayWeather = new Dictionary<string, LevelWeatherType>(); public static Logger Logger = new Logger("WeatherRegistry", ConfigManager.LogWeatherChanges); internal static WeatherSelectionAlgorithm RegistryAlgorithm = new WeatherRegistryWeatherSelection(); internal static WeatherSelectionAlgorithm VanillaAlgorithm = new VanillaWeatherSelection(); [Obsolete("Use Settings.WeatherSelectionAlgorithm instead")] public static WeatherSelectionAlgorithm WeatherSelectionAlgorithm { get { return Settings.WeatherSelectionAlgorithm; } set { Settings.WeatherSelectionAlgorithm = value; } } } public static class WeatherController { private static ManualLogSource Logger = new ManualLogSource("WeatherController"); public static void ChangeCurrentWeather(Weather weather) { SelectableLevel currentLevel = StartOfRound.Instance.currentLevel; ChangeWeather(currentLevel, weather); } public static void ChangeCurrentWeather(LevelWeatherType weatherType) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) SelectableLevel currentLevel = StartOfRound.Instance.currentLevel; ChangeWeather(currentLevel, weatherType); } public static void ChangeWeather(SelectableLevel level, LevelWeatherType weatherType) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) Weather weather = WeatherManager.GetWeather(weatherType); ChangeWeather(level, weather); } public static void ChangeWeather(SelectableLevel level, Weather weather) { //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_0025: Unknown result type (might be due to invalid IL or missing references) if (Settings.SelectWeathers) { level.currentWeather = weather.VanillaWeatherType; Logger.LogDebug((object)$"Changed weather for {ConfigHelper.GetNumberlessName(level)} to {weather.VanillaWeatherType}"); if (!StartOfRound.Instance.inShipPhase) { Logger.LogDebug((object)"Ship has already landed, only changing weather effects"); SetWeatherEffects(weather); } else { WeatherManager.CurrentWeathers.SetWeather(level, weather); ((CustomEvent<(SelectableLevel, Weather)>)(object)EventManager.WeatherChanged).Invoke((level, weather)); StartOfRound.Instance.SetMapScreenInfoToCurrentLevel(); } } } public static void SetRandomWeathers(SelectableLevel level, List<RandomWeatherWithVariables> randomWeathers) { SetRandomWeathers(level, randomWeathers.ToArray()); } public static void SetRandomWeathers(SelectableLevel level, RandomWeatherWithVariables[] randomWeathers) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) level.randomWeathers = randomWeathers.ToArray(); string alphanumericName = ConfigHelper.GetAlphanumericName(level); foreach (RandomWeatherWithVariables val in randomWeathers) { Logger.LogWarning((object)$"Adding random weather {val.weatherType} to {alphanumericName}"); WeatherManager.GetWeather(val.weatherType).WeatherVariables[level] = new LevelWeatherVariables { Level = level, WeatherVariable1 = val.weatherVariable, WeatherVariable2 = val.weatherVariable2 }; } } public static void AddRandomWeather(SelectableLevel level, RandomWeatherWithVariables randomWeather) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) List<RandomWeatherWithVariables> list = level.randomWeathers.ToList(); if ((int)randomWeather.weatherType == -1) { Logger.LogInfo((object)"Cannot add None weather to random weathers, skipping"); return; } list.Add(randomWeather); level.randomWeathers = list.Distinct().ToArray(); Plugin.logger.LogInfo((object)$"Adding random weather {randomWeather.weatherType} to {ConfigHelper.GetAlphanumericName(level)}"); WeatherManager.GetWeather(randomWeather.weatherType).WeatherVariables[level] = new LevelWeatherVariables { Level = level, WeatherVariable1 = randomWeather.weatherVariable, WeatherVariable2 = randomWeather.weatherVariable2 }; } public static void RemoveRandomWeather(SelectableLevel level, RandomWeatherWithVariables randomWeather) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) List<RandomWeatherWithVariables> list = level.randomWeathers.ToList(); list.Remove(randomWeather); level.randomWeathers = list.ToArray(); WeatherManager.GetWeather(randomWeather.weatherType).WeatherVariables.Remove(level); } public static void SetWeatherEffects(LevelWeatherType weatherType) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) WeatherSync.Instance.SetWeatherEffectOnHost(weatherType); } public static void SetWeatherEffects(Weather weather) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) SetWeatherEffects(weather.VanillaWeatherType); } public static void AddWeatherEffect(LevelWeatherType weatherType) { //IL_000a: 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) Plugin.logger.LogDebug((object)$"Adding weather effect {weatherType}"); List<LevelWeatherType> list = WeatherSync.Instance.Effects.Effects.ToList(); list.Add(weatherType); WeatherSync.Instance.SetWeatherEffectsOnHost(list.ToArray()); } public static void AddWeatherEffect(Weather weather) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) AddWeatherEffect(weather.VanillaWeatherType); } } public static class WeatherEffectController { internal static void SetTimeOfDayEffect(LevelWeatherType weatherType, bool enabled) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if ((int)weatherType != -1) { if (EntranceTeleportPatch.isPlayerInside) { Plugin.logger.LogWarning((object)"Player is inside, not setting time of day effect"); } else if (TimeOfDay.Instance.effects[weatherType] != null) { Plugin.debugLogger.LogDebug((object)$"Setting time of day effect {weatherType} to {enabled}"); TimeOfDay.Instance.effects[weatherType].effectEnabled = enabled; } } } [Obsolete("Use SetWeatherEffects(Weather[]) instead")] public static void SetWeatherEffects(Weather weather) { SetWeatherEffects(new Weather[1] { weather }); } public static void SetWeatherEffects(Weather[] weathers) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Invalid comparison between Unknown and I4 //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) SelectableLevel currentLevel = StartOfRound.Instance.currentLevel; DisableWeatherEffects(weathers); foreach (Weather weather2 in weathers) { if ((Object)(object)weather2 == (Object)null) { return; } if ((int)weather2.VanillaWeatherType != 4) { PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController; localPlayerController.isUnderwater = false; localPlayerController.sourcesCausingSinking = Mathf.Clamp(localPlayerController.sourcesCausingSinking - 1, 0, 100); localPlayerController.isMovementHindered = Mathf.Clamp(localPlayerController.isMovementHindered - 1, 0, 100); localPlayerController.hinderedMultiplier = 1f; } if ((int)weather2.VanillaWeatherType == -1) { SunAnimator.OverrideSunAnimator(weather2.VanillaWeatherType); return; } if (((CompatibilityBase)Plugin.JLLCompat).IsModPresent) { var (flag, val) = Plugin.JLLCompat.GetJLLData(); if (flag) { Plugin.logger.LogInfo((object)"Enabling JLL WeatherEffect"); val.effectEnabled = true; GameObject effectObject = val.effectObject; if (effectObject != null) { effectObject.SetActive(true); } return; } } WeatherEffectOverride effectOverride = weather2.GetEffectOverride(currentLevel); if (effectOverride == null) { weather2.Effect.EffectEnabled = true; SetTimeOfDayEffect(weather2.VanillaWeatherType, enabled: true); } else { weather2.Effect.EffectEnabled = false; effectOverride.OverrideEffect.EffectEnabled = true; } } try { SunAnimator.OverrideSunAnimator(weathers.Any((Weather weather) => Defaults.VanillaWeathers.Contains(weather.VanillaWeatherType)) ? weathers.Where((Weather weather) => Defaults.VanillaWeathers.Contains(weather.VanillaWeatherType)).Max((Weather weather) => weather.VanillaWeatherType) : weathers.Max((Weather weather) => weather.VanillaWeatherType)); } catch (Exception ex) { Plugin.logger.LogError((object)("SunAnimator exception: " + ex.Message)); Plugin.logger.LogWarning((object)"PLEASE report this issue to the mod developer with your modpack code and this log!"); } } public static void SetWeatherEffects(LevelWeatherType[] weatherTypes) { Weather[] weatherEffects = weatherTypes.Select(WeatherManager.GetWeather).ToArray(); SetWeatherEffects(weatherEffects); } public static void DisableWeatherEffects(Weather[] newWeathers) { foreach (WeatherEffectOverride weatherEffectOverride in WeatherManager.WeatherEffectOverrides) { if (!newWeathers.Contains(weatherEffectOverride.Weather)) { weatherEffectOverride.OverrideEffect.DisableEffect(permament: true); } } foreach (Weather weather in WeatherManager.Weathers) { if (!newWeathers.Contains(weather)) { weather.Effect.DisableEffect(permament: true); } } if (!((CompatibilityBase)Plugin.JLLCompat).IsModPresent) { return; } var (flag, val) = Plugin.JLLCompat.GetJLLData(); if (flag) { Plugin.logger.LogInfo((object)"Disabling JLL WeatherEffect"); val.effectEnabled = false; GameObject effectObject = val.effectObject; if (effectObject != null) { effectObject.SetActive(false); } } } public static void EnableCurrentWeatherEffects() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) if (((CompatibilityBase)Plugin.JLLCompat).IsModPresent) { var (flag, val) = Plugin.JLLCompat.GetJLLData(); if (flag) { Plugin.logger.LogInfo((object)"Enabling JLL WeatherEffect"); val.effectEnabled = true; GameObject effectObject = val.effectObject; if (effectObject != null) { effectObject.SetActive(true); } } } foreach (LevelWeatherType currentEffectType in WeatherManager.CurrentEffectTypes) { Weather weather = WeatherManager.GetWeather(currentEffectType); weather.Effect.EffectEnabled = true; SetTimeOfDayEffect(weather.VanillaWeatherType, enabled: true); } } public static void HandleJLLOverride(LevelWeatherType weatherType, bool enable) { if (Plugin.JLLCompat.IsJLLDoingWeatherOverride()) { Plugin.logger.LogInfo((object)"Detected JLL WeatherOverride"); } } } public static class WeatherManager { internal static bool IsSetupFinished = false; public static Dictionary<int, Weather> ModdedWeatherEnumExtension = new Dictionary<int, Weather>(); public static CurrentWeathers CurrentWeathers = new CurrentWeathers(); public static List<Weather> RegisteredWeathers { get; internal set; } = new List<Weather>(); public static List<LevelWeather> LevelWeathers { get; internal set; } = new List<LevelWeather>(); public static List<WeatherEffectOverride> WeatherEffectOverrides { get; internal set; } = new List<WeatherEffectOverride>(); public static List<WeatherMatcher> WeatherMatchers { get; internal set; } = new List<WeatherMatcher>(); public static List<Weather> Weathers => WeathersDictionary.Values.ToList(); public static Dictionary<LevelWeatherType, Weather> WeathersDictionary { get; internal set; } = new Dictionary<LevelWeatherType, Weather>(); public static Weather NoneWeather { get; internal set; } public static List<LevelWeatherType> LevelWeatherTypes => Weathers.Select((Weather weather) => weather.VanillaWeatherType).ToList(); [Obsolete("Use WeatherManager.CurrentWeathers instead")] public static CurrentWeathers currentWeathers => CurrentWeathers; public static List<LevelWeatherType> CurrentEffectTypes => (from weather in Weathers where (Object)(object)weather.Effect != (Object)null where weather.Effect.EffectEnabled select weather.VanillaWeatherType).ToList(); public static void RegisterWeather(Weather weather) { RegisteredWeathers.Add(weather); } public static Weather GetWeather(LevelWeatherType levelWeatherType) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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) if (WeathersDictionary.ContainsKey(levelWeatherType)) { return WeathersDictionary[levelWeatherType]; } Plugin.logger.LogWarning((object)$"Weather {levelWeatherType} not found in dictionary"); return null; } public static List<Weather> GetWeathers() { return Weathers; } internal static void Reset() { IsSetupFinished = false; Weathers.ForEach(delegate(Weather weather) { if (weather.Origin != WeatherOrigin.WeatherRegistry && weather.Origin != WeatherOrigin.WeatherTweaks) { Object.Destroy((Object)(object)weather.Effect); Object.Destroy((Object)(object)weather); } }); LevelWeathers.Clear(); Weathers.Clear(); WeathersDictionary.Clear(); ModdedWeatherEnumExtension.Clear(); WeatherEffectOverrides.Clear(); CurrentWeathers.Clear(); Settings.ScreenMapColors.Clear(); ConfigHelper.StringToWeather = null; RegisteredWeathers.RemoveAll((Weather weather) => weather.Origin != WeatherOrigin.WeatherRegistry && weather.Origin != WeatherOrigin.WeatherTweaks); WeatherLevelData.LatestWeathersReceived = Array.Empty<WeatherSyncData>(); } public static string WeatherDisplayOverride(SelectableLevel level) { return string.Empty; } public static string LevelWeatherTypeEnumHook(Func<Enum, string> orig, Enum self) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected I4, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected I4, but got Unknown if (self.GetType() == typeof(LevelWeatherType) && ModdedWeatherEnumExtension.ContainsKey((int)(LevelWeatherType)(object)self)) { return ((Object)ModdedWeatherEnumExtension[(int)(LevelWeatherType)(object)self]).name; } return orig(self); } internal static List<LevelWeatherType> GetPlanetPossibleWeathers(SelectableLevel level) { List<LevelWeatherType> list = (from randomWeather in level.randomWeathers where (int)randomWeather.weatherType != -1 select randomWeather into x select x.weatherType).Distinct().ToList(); list.Insert(0, (LevelWeatherType)(-1)); Plugin.logger.LogDebug((object)("Possible weathers: " + string.Join("; ", list.Select((LevelWeatherType x) => ((object)(LevelWeatherType)(ref x)).ToString())))); if (list == null || list.Count() == 0) { Plugin.logger.LogError((object)"Level's random weathers are null"); return new List<LevelWeatherType>(); } return list; } public static WeightHandler<Weather> GetPlanetWeightedList(SelectableLevel level) { //IL_003a: 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_0041: Unknown result type (might be due to invalid IL or missing references) WeightHandler<Weather> val = new WeightHandler<Weather>(); Logger logger = WeatherCalculation.Logger; List<LevelWeatherType> planetPossibleWeathers = GetPlanetPossibleWeathers(level); if (planetPossibleWeathers == null || planetPossibleWeathers.Count() == 0) { Plugin.logger.LogError((object)"Level's random weathers are null"); return val; } foreach (LevelWeatherType item in planetPossibleWeathers) { Weather weather = GetWeather(item); int weight = weather.GetWeight(level); val.Add(weather, weight); } return val; } public static Weather GetCurrentWeather(SelectableLevel level) { if (!Settings.SetupFinished) { Plugin.logger.LogWarning((object)"Something is trying to get the current weather before setup is finished!"); return null; } return CurrentWeathers.GetLevelWeather(level); } public static Weather GetCurrentLevelWeather() { return GetCurrentWeather(StartOfRound.Instance.currentLevel); } public static string GetCurrentWeatherName(SelectableLevel level) { return GetCurrentWeather(level).Name; } internal static AnimationClip GetWeatherAnimationClip(LevelWeatherType weatherType) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return GetWeather(weatherType).AnimationClip; } public static WeatherEffectOverride GetCurrentWeatherOverride(SelectableLevel level, Weather weather) { weather.WeatherEffectOverrides.TryGetValue(level, out var value); return value; } public static string GetWeatherList() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected I4, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown List<WeatherListData> list = new List<WeatherListData>(); foreach (Weather weather in Weathers) { list.Add(new WeatherListData { WeatherID = FixedString64Bytes.op_Implicit(((int)weather.VanillaWeatherType).ToString()), WeatherName = FixedString64Bytes.op_Implicit(((Object)weather).name) }); } return JsonConvert.SerializeObject((object)list, (Formatting)0, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 }); } } public class WeatherResolvable { public virtual string WeatherName { get; } public virtual LevelWeatherType WeatherType { get; } public override string ToString() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected I4, but got Unknown return $"{WeatherName} ({(int)WeatherType})"; } } public class WeatherNameResolvable : WeatherResolvable { [CompilerGenerated] private string <weatherName>P; public override string WeatherName => <weatherName>P; public override LevelWeatherType WeatherType { get { //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (WeatherManager.IsSetupFinished) { Weather weather = ConfigHelper.ResolveStringToWeather(<weatherName>P); if (!((Object)(object)weather == (Object)null)) { return weather.VanillaWeatherType; } return (LevelWeatherType)(-1); } return (LevelWeatherType)(-1); } } public WeatherNameResolvable(string weatherName) { <weatherName>P = weatherName; base..ctor(); } } public class WeatherTypeResolvable : WeatherResolvable { [CompilerGenerated] private LevelWeatherType <weatherType>P; public override LevelWeatherType WeatherType => <weatherType>P; public override string WeatherName { get { //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (WeatherManager.IsSetupFinished) { return WeatherManager.GetWeather(<weatherType>P).Name; } return ""; } } public WeatherTypeResolvable(LevelWeatherType weatherType) { //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) <weatherType>P = weatherType; base..ctor(); } } internal class WeatherSync : NetworkBehaviour { public NetworkVariable<WeatherSyncDataWrapper> WeathersSynced = new NetworkVariable<WeatherSyncDataWrapper>(new WeatherSyncDataWrapper { Weathers = Array.Empty<WeatherSyncData>() }, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0); public NetworkVariable<WeatherEffectDataWrapper> EffectsSynced = new NetworkVariable<WeatherEffectDataWrapper>(new WeatherEffectDataWrapper { Effects = (LevelWeatherType[])(object)new LevelWeatherType[1] { (LevelWeatherType)(-1) } }, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0); public NetworkVariable<FixedString4096Bytes> WeatherData = new NetworkVariable<FixedString4096Bytes>(default(FixedString4096Bytes), (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0); public static GameObject WeatherSyncPrefab; public static NetworkManager networkManager; public static bool networkHasStarted = false; private static WeatherSync _instance; private static List<GameObject> queuedNetworkPrefabs = new List<GameObject>(); public WeatherSyncData[] Weather { get { return WeathersSynced.Value.Weathers; } set { WeathersSynced.Value = new WeatherSyncDataWrapper { Weathers = value }; } } public WeatherEffectDataWrapper Effects { get { return EffectsSynced.Value; } set { EffectsSynced.Value = new WeatherEffectDataWrapper { Effects = value.Effects }; } } public FixedString4096Bytes WeatherList { get { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return WeatherData.Value; } set { //IL_0006: Unknown result type (might be due to invalid IL or missing references) WeatherData.Value = value; } } public static WeatherSync Instance { get { if ((Object)(object)_instance == (Object)null) { _instance = Object.FindObjectOfType<WeatherSync>(); if ((Object)(object)_instance == (Object)null) { Plugin.logger.LogError((object)"WeatherSync instance is null"); } } return _instance; } private set { _instance = value; } } public override void OnNetworkSpawn() { ((NetworkBehaviour)this).OnNetworkSpawn(); InitializeInstance(); NetworkVariable<WeatherSyncDataWrapper> weathersSynced = WeathersSynced; weathersSynced.OnValueChanged = (OnValueChangedDelegate<WeatherSyncDataWrapper>)(object)Delegate.Combine((Delegate?)(object)weathersSynced.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<WeatherSyncDataWrapper>(WeatherLevelData.WeathersReceived)); NetworkVariable<WeatherEffectDataWrapper> effectsSynced = EffectsSynced; effectsSynced.OnValueChanged = (OnValueChangedDelegate<WeatherEffectDataWrapper>)(object)Delegate.Combine((Delegate?)(object)effectsSynced.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<WeatherEffectDataWrapper>(WeatherEffectData.EffectsReceived)); } public void SetNewOnHost(Dictionary<string, LevelWeatherType> weathers) { if (!((NetworkBehaviour)StartOfRound.Instance).IsHost) { Plugin.logger.LogDebug((object)"Cannot set weathers, not a host!"); return; } WeatherSyncData[] weather = weathers.Select(delegate(KeyValuePair<string, LevelWeatherType> kvp) { //IL_000c: 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) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) WeatherSyncData result = default(WeatherSyncData); result.Weather = kvp.Value; result.LevelName = new FixedString64Bytes(kvp.Key); return result; }).ToArray(); Weather = weather; } public void SetWeatherEffectOnHost(LevelWeatherType weatherType) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected I4, but got Unknown SetWeatherEffectsOnHost((LevelWeatherType[])(object)new LevelWeatherType[1] { (LevelWeatherType)(int)weatherType }); } public void SetWeatherEffectsOnHost(LevelWeatherType[] weatherTypes) { if (!((NetworkBehaviour)StartOfRound.Instance).IsHost) { Plugin.logger.LogDebug((object)"Cannot set effects, not a host!"); return; } Plugin.logger.LogDebug((object)("Settings effects: [" + string.Join("; ", weatherTypes) + "]")); Effects = new WeatherEffectDataWrapper { Effects = weatherTypes }; } public static void RegisterNetworkPrefab(GameObject prefab) { if (!networkHasStarted) { Plugin.logger.LogDebug((object)("Registering NetworkPrefab: " + (object)prefab)); queuedNetworkPrefabs.Add(prefab); } else { Plugin.logger.LogWarning((object)("Attempted To Register NetworkPrefab: " + ((object)prefab)?.ToString() + " After GameNetworkManager Has Started!")); } } internal static void RegisterPrefabs(NetworkManager networkManager) { Plugin.logger.LogDebug((object)"Registering NetworkPrefabs in NetworkManager"); List<GameObject> existingPrefabs = GetExistingPrefabs(networkManager); RegisterQueuedPrefabs(networkManager, existingPrefabs); networkHasStarted = true; } private void InitializeInstance() { ((Object)((Component)this).gameObject).name = "WeatherSync"; Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); Plugin.logger.LogDebug((object)$"WeathersSynced: {WeathersSynced.Value}"); } private static List<GameObject> GetExistingPrefabs(NetworkManager networkManager) { List<GameObject> list = new List<GameObject>(); foreach (NetworkPrefab prefab in networkManager.NetworkConfig.Prefabs.m_Prefabs) { list.Add(prefab.Prefab); } return list; } private static void RegisterQueuedPrefabs(NetworkManager networkManager, List<GameObject> addedNetworkPrefabs) { int num = 0; foreach (GameObject queuedNetworkPrefab in queuedNetworkPrefabs) { Plugin.logger.LogDebug((object)("Trying To Register Prefab: " + (object)queuedNetworkPrefab)); if (!addedNetworkPrefabs.Contains(queuedNetworkPrefab)) { networkManager.AddNetworkPrefab(queuedNetworkPrefab); addedNetworkPrefabs.Add(queuedNetworkPrefab); } else { num++; } } Plugin.logger.LogDebug((object)("Skipped Registering " + num + " NetworkObjects As They Were Already Registered.")); } protected override void __initializeVariables() { if (WeathersSynced == null) { throw new Exception("WeatherSync.WeathersSynced cannot be null. All NetworkVariableBase instances must be initialized."); } ((NetworkVariableBase)WeathersSynced).Initialize((NetworkBehaviour)(object)this); ((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)WeathersSynced, "WeathersSynced"); base.NetworkVariableFields.Add((NetworkVariableBase)(object)WeathersSynced); if (EffectsSynced == null) { throw new Exception("WeatherSync.EffectsSynced cannot be null. All NetworkVariableBase instances must be initialized."); } ((NetworkVariableBase)EffectsSynced).Initialize((NetworkBehaviour)(object)this); ((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)EffectsSynced, "EffectsSynced"); base.NetworkVariableFields.Add((NetworkVariableBase)(object)EffectsSynced); if (WeatherData == null) { throw new Exception("WeatherSync.WeatherData cannot be null. All NetworkVariableBase instances must be initialized."); } ((NetworkVariableBase)WeatherData).Initialize((NetworkBehaviour)(object)this); ((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)WeatherData, "WeatherData"); base.NetworkVariableFields.Add((NetworkVariableBase)(object)WeatherData); ((NetworkBehaviour)this).__initializeVariables(); } [MethodImpl(MethodImplOptions.NoInlining)] protected internal override string __getTypeName() { return "WeatherSync"; } } public static class PluginInfo { public const string PLUGIN_GUID = "WeatherRegistry"; public const string PLUGIN_NAME = "WeatherRegistry"; public const string PLUGIN_VERSION = "0.5.3"; } } namespace WeatherRegistry.Patches { [HarmonyPatch(typeof(AudioReverbTrigger))] public class AudioReverbTriggerPatches { [HarmonyTranspiler] [HarmonyPatch("ChangeAudioReverbForPlayer")] internal static IEnumerable<CodeInstruction> ChangeAudioReverbForPlayerPatch(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); CodeMatcher val2 = val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[7] { new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(TimeOfDay), "get_Instance", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TimeOfDay), "effects"), (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(TimeOfDay), "get_Instance", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TimeOfDay), "currentLevelWeather"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(WeatherEffect), "effectEnabled"), (string)null) }); val2.RemoveInstructions(7); return val.InstructionEnumeration(); } } [HarmonyPatch(typeof(EntranceTeleport))] internal class EntranceTeleportPatch { internal static Logger logger = new Logger("EntranceTeleport", (ConfigEntry<bool>)null); internal static bool isPlayerInside = false; [HarmonyPostfix] [HarmonyPatch(typeof(EntranceTeleport), "TeleportPlayer")] private static void TeleportPlayerPatch(EntranceTeleport __instance) { logger.LogDebug((object)("TeleportPlayerPatch called with " + ((Object)__instance).name)); isPlayerInside = __instance.isEntranceToBuilding; if (isPlayerInside) { logger.LogDebug((object)"Player is inside"); return; } logger.LogDebug((object)"Player is outside"); WeatherEffectController.EnableCurrentWeatherEffects(); } } [HarmonyPatch(typeof(GameNetworkManager), "Start")] internal class GameNetworkManagerStartPatch { [HarmonyPrefix] public static void GameMethodPatch(GameNetworkManager __instance) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown WeatherSync.networkManager = ((Component)__instance).GetComponent<NetworkManager>(); GameObject val = new GameObject("WeatherRegistrySyncInnit"); ((Object)val).hideFlags = (HideFlags)61; val.AddComponent<NetworkObject>(); byte[] value = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes("weatherregistryweathersync")); val.GetComponent<NetworkObject>().GlobalObjectIdHash = BitConverter.ToUInt32(value, 0); val.AddComponent<WeatherSync>(); val.GetComponent<NetworkObject>().DontDestroyWithOwner = true; val.GetComponent<NetworkObject>().SceneMigrationSynchronization = true; val.GetComponent<NetworkObject>().DestroyWithScene = false; Object.DontDestroyOnLoad((Object)(object)val); WeatherSync.WeatherSyncPrefab = val; WeatherSync.RegisterNetworkPrefab(val); WeatherSync.RegisterPrefabs(((Component)__instance).GetComponent<NetworkManager>()); Plugin.logger.LogDebug((object)"WeatherSync initialized in GameNetworkManager.Start"); } } public class LethalLibPatch { public static Dictionary<int, CustomWeather> GetLethalLibWeathers() { return Weathers.customWeathers; } public static List<Weather> ConvertLLWeathers() { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) Dictionary<int, CustomWeather> lethalLibWeathers = GetLethalLibWeathers(); List<Weather> list = new List<Weather>(); foreach (KeyValuePair<int, CustomWeather> item in lethalLibWeathers) { CustomWeather value = item.Value; ImprovedWeatherEffect improvedWeatherEffect = new ImprovedWeatherEffect(value.weatherEffect.effectObject, value.weatherEffect.effectPermanentObject); ((Object)improvedWeatherEffect).name = value.name; improvedWeatherEffect.SunAnimatorBool = value.weatherEffect.sunAnimatorBool; improvedWeatherEffect.DefaultVariable1 = value.weatherVariable1; improvedWeatherEffect.DefaultVariable2 = value.weatherVariable2; ImprovedWeatherEffect effect = improvedWeatherEffect; Weather weather = new Weather(value.name, effect) { VanillaWeatherType = (LevelWeatherType)item.Key, Origin = WeatherOrigin.LethalLib, Color = Defaults.LethalLibColor, Config = { DefaultWeight = new IntegerConfigHandler(50) } }; list.Add(weather); WeatherManager.ModdedWeatherEnumExtension.Add(item.Key, weather); } return list; } public static void Init() { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Expected O, but got Unknown Plugin.logger.LogDebug((object)"Disabling LethalLib injections"); FieldInfo field = typeof(Weathers).GetField("weatherEnumHook", BindingFlags.Static | BindingFlags.NonPublic); Hook val = (Hook)field.GetValue(null); val.Undo(); Plugin.harmony.Patch((MethodBase)AccessTools.Method(typeof(Weathers), "RegisterLevelWeathers_StartOfRound_Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(LethalLibPatch), "StartOfRoundAwakePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Plugin.harmony.Patch((MethodBase)AccessTools.Method(typeof(Weathers), "TimeOfDay_Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(LethalLibPatch), "TimeOfDayAwakePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } internal static bool StartOfRoundAwakePrefix(orig_Awake orig, StartOfRound self) { Plugin.logger.LogDebug((object)"Skipping LethalLib StartOfRound method"); orig.Invoke(self); return false; } internal static bool TimeOfDayAwakePrefix(orig_Awake orig, TimeOfDay self) { Plugin.logger.LogDebug((object)"Skipping LethalLib TimeOfDay method"); orig.Invoke(self); return false; } } internal class LobbyCompatibilityCompatibility { public static void Init() { Plugin.logger.LogDebug((object)"LobbyCompatibility detected, registering plugin with LobbyCompatibility."); Version version = Version.Parse("0.5.3"); PluginHelper.RegisterPlugin("mrov.WeatherRegistry", version, (CompatibilityLevel)2, (VersionStrictness)0); } } [HarmonyPatch(typeof(LungProp))] internal static class LungPropPatch { [HarmonyPrefix] [HarmonyPatch("Start")] public static bool StartPatch(LungProp __instance) { if (((CompatibilityBase)Plugin.FacilityMeltdownCompat).IsModPresent) { Plugin.logger.LogInfo((object)"FacilityMeltdown is present - WeatherRegistry will not run its apparatus patch."); return true; } if (!Settings.ScrapMultipliers) { Plugin.logger.LogInfo((object)"Skipped using WeatherRegistry's scrap multipliers."); return true; } try { Plugin.debugLogger.LogInfo((object)$"ApparatusSpawnBefore: {((GrabbableObject)__instance).scrapValue}"); Weather currentLevelWeather = WeatherManager.GetCurrentLevelWeather(); Plugin.debugLogger.LogInfo((object)$"Scrap multiplier: {currentLevelWeather.ScrapValueMultiplier}"); ((GrabbableObject)__instance).SetScrapValue((int)((float)((GrabbableObject)__instance).scrapValue * currentLevelWeather.ScrapValueMultiplier)); Plugin.debugLogger.LogInfo((object)$"ApparatusSpawnAfter: {((GrabbableObject)__instance).scrapValue}"); } catch (Exception ex) { Plugin.logger.LogError((object)ex.Message); return true; } return true; } } [HarmonyPatch(typeof(GameNetworkManager))] internal class ResetLobbyPatch { [HarmonyPatch("ResetSavedGameValues")] [HarmonyPrefix] public static void ResetSavedGameValuesPatch() { Plugin.logger.LogDebug((object)"Removing all save entries made by WeatherRegistry"); WeatherManager.CurrentWeathers.Clear(); for (int i = 0; i <= 100; i++) { string text = $"{Defaults.WeatherSaveKey}-{i}"; if (ES3.KeyExists(text, GameNetworkManager.Instance.currentSaveFileName)) { ES3.DeleteKey(text, GameNetworkManager.Instance.currentSaveFileName); } } } } [HarmonyPatch(typeof(StartOfRound))] public static class SetMapScreenInfoToCurrentLevelPatch { [HarmonyPatch("SetMapScreenInfoToCurrentLevel")] [HarmonyPostfix] [HarmonyPriority(0)] internal static void GameMethodPatch(ref TextMeshProUGUI ___screenLevelDescription, ref SelectableLevel ___currentLevel, StartOfRound __instance) { if (!WeatherManager.IsSetupFinished) { Plugin.logger.LogWarning((object)"WeatherManager is not set up yet."); } else if (Settings.MapScreenOverride) { Regex regex = new Regex("\\n{2,}"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("ORBITING: " + ___currentLevel.PlanetName + "\n"); stringBuilder.Append("WEATHER: " + GetColoredString(___currentLevel) + "\n"); stringBuilder.Append(regex.Replace(___currentLevel.LevelDescription, "\n") ?? ""); ((TMP_Text)___screenLevelDescription).fontWeight = (FontWeight)700; ((TMP_Text)___screenLevelDescription).SetText(stringBuilder.ToString(), true); ((Behaviour)__instance.screenLevelVideoReel).enabled = Settings.PlanetVideos; ((CustomEvent<(SelectableLevel, Weather, string)>)(object)EventManager.MapScreenUpdated).Invoke((___currentLevel, WeatherManager.GetCurrentWeather(___currentLevel), stringBuilder.ToString())); } } private static string GetDisplayWeatherString(SelectableLevel level, Weather weather) { return weather.Name; } private static string GetColoredString(SelectableLevel level) { Weather currentWeather = WeatherManager.GetCurrentWeather(level); string displayWeatherString = GetDisplayWeatherString(level, currentWeather); if (!Settings.ColoredWeathers) { return displayWeatherString; } string outputString = ""; Regex regex = new Regex("(\\/)|(\\?)|(>)|(\\+)"); regex.Split(displayWeatherString).ToList().ForEach(delegate(string word) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) string text = word.Trim(); Color value; string text2 = ColorUtility.ToHtmlStringRGB(Settings.ScreenMapColors.TryGetValue(text, out value) ? value : Color.black); outputString += ((text2 != "000000") ? ("<color=#" + text2 + ">" + word + "</color>") : (text ?? "")); }); return outputString; } } [HarmonyPatch(typeof(StartOfRound))] internal class SetPlanetsWeatherPatch { [HarmonyPatch("SetPlanetsWeather")] [HarmonyPrefix] public static bool GameMethodPatch(int connectedPlayersOnServer, StartOfRound __instance) { Plugin.logger.LogDebug((object)"SetPlanetsWeather called."); if (!WeatherManager.IsSetupFinished) { Plugin.logger.LogWarning((object)"WeatherManager is not set up yet."); return false; } if (!Settings.SelectWeathers) { Plugin.logger.LogDebug((object)"Weather selection is disabled."); return true; } if ((Object)(object)__instance == (Object)null) { Plugin.logger.LogWarning((object)"Instance is null"); return true; } Plugin.logger.LogInfo((object)$"Picking weathers on day {StartOfRound.Instance.gameStats.daysSpent}, file {GameNetworkManager.Instance.currentSaveFileName}"); if (((NetworkBehaviour)__instance).IsHost) { string text = $"{Defaults.WeatherSaveKey}-{StartOfRound.Instance.gameStats.daysSpent}"; bool flag = ES3.KeyExists(text, GameNetworkManager.Instance.currentSaveFileName); Plugin.logger.LogInfo((object)$"Save file has weather data: {flag}"); if (flag) { Plugin.logger.LogInfo((object)$"Loading picked weathers from save: day {StartOfRound.Instance.gameStats.daysSpent}, file {GameNetworkManager.Instance.currentSaveFileName}"); Plugin.logger.LogDebug((object)("Weathers: " + ES3.Load<string>(text, GameNetworkManager.Instance.currentSaveFileName))); WeatherManager.CurrentWeathers.SetWeathersFromStringDictionary(ES3.Load<string>(text, GameNetworkManager.Instance.currentSaveFileName)); } else { Plugin.debugLogger.LogDebug((object)("Weather selection algorithm: " + Settings.WeatherSelectionAlgorithm.GetType().Name)); Dictionary<SelectableLevel, LevelWeatherType> weathers = Settings.WeatherSelectionAlgorithm.SelectWeathers(connectedPlayersOnServer, __instance); WeatherManager.CurrentWeathers.SetWeathers(weathers); ES3.Save<string>(text, JsonConvert.SerializeObject((object)WeatherManager.CurrentWeathers.GetWeatherNames), GameNetworkManager.Instance.currentSaveFileName); Plugin.logger.LogDebug((object)$"Saved picked weathers: day {StartOfRound.Instance.gameStats.daysSpent}, file {GameNetworkManager.Instance.currentSaveFileName}"); } } ((CustomEvent<int>)EventManager.DayChanged).Invoke(__instance.gameStats.daysSpent); return false; } } [HarmonyPatch(typeof(RoundManager))] public class SpawnScrapInLevelPatches { [HarmonyPatch("SpawnScrapInLevel")] [HarmonyAfter(new string[] { "com.github.fredolx.meteomultiplier", "DarthLilo.WeatherBonuses" })] [HarmonyPriority(0)] [HarmonyPrefix] private static void ChangeMultipliers(RoundManager __instance) { if (!Settings.ScrapMultipliers) { Plugin.logger.LogInfo((object)"Skipped using WeatherRegistry's scrap multipliers."); return; } Weather currentWeather = WeatherManager.GetCurrentWeather(__instance.currentLevel); __instance.scrapValueMultiplier = currentWeather.ScrapValueMultiplier * 0.4f; __instance.scrapAmountMultiplier = currentWeather.ScrapAmountMultiplier; } [HarmonyPatch("SpawnScrapInLevel")] [HarmonyPostfix] [HarmonyPriority(800)] private static void LogMultipliers(RoundManager __instance) { Plugin.logger.LogInfo((object)$"Spawned scrap in level with multipliers: {__instance.scrapValueMultiplier} (value), {__instance.scrapAmountMultiplier} (amount)"); } } [HarmonyPatch(typeof(StartOfRound))] internal class StartOfRoundPatch { [HarmonyPatch("OnDisable")] [HarmonyPrefix] public static void DisableWeathersPatch() { foreach (Weather weather in WeatherManager.Weathers) { weather.Effect.DisableEffect(permament: true)