using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using WeatherGains.Types; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("WeatherGainsFixed")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("WeatherGainsFixed")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("00103934-c803-4cfb-a8da-05799b9af28c")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 WeatherGains { public static class MultiplierManager { public static int ApplyValueMultiplier(int initialValue) { if (!WeatherGains.BoundConfig.ValueMultiEnabled.Value) { return initialValue; } float num = GetMultiplierGroupForCurrentWeather().ValueMultiplier.Value; if (WeatherGains.BoundConfig.ValueMultiVariation.Value > 0f) { float value = WeatherGains.BoundConfig.ValueMultiVariation.Value; float num2 = 1f + Random.Range(0f - value, value) / 100f; num *= num2; } return (int)((float)initialValue * num); } public static float ApplyAmountMultiplier(float initialAmount) { if (!WeatherGains.BoundConfig.AmountMultiEnabled.Value) { return initialAmount; } float value = GetMultiplierGroupForCurrentWeather().AmountMultiplier.Value; return initialAmount * value; } private static MultiValueGroup GetMultiplierGroupForCurrentWeather() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather; if (WeatherGains.BoundConfig.Multipliers.TryGetValue(currentLevelWeather, out var value)) { return value; } return WeatherGains.BoundConfig.Multipliers[(LevelWeatherType)(-1)]; } } public class PluginConfig { private const string SectionMultipliers = "Multipliers"; private const string SectionGeneral = "General"; private const int ConfigVersion = 2; public ConfigEntry LungValueMultiEnabled; public ConfigEntry AmountMultiEnabled; public ConfigEntry ValueMultiEnabled; public ConfigEntry CompatibilityMode; public ConfigEntry PluginEnabled; public ConfigEntry ValueMultiVariation; public readonly Dictionary Multipliers = new Dictionary(); public PluginConfig(ConfigFile config) { config.SaveOnConfigSet = true; ApplyConfig(config); ClearOrphanedEntries(config); config.Save(); } private void ApplyConfig(ConfigFile config) { //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) config.Bind("Meta", "ConfigVersion", 2, "!!! DO NOT CHANGE THIS VALUE !!!"); LungValueMultiEnabled = config.Bind("General", "ApparatusMultiplierEnabled", true, "Toggles the value multiplier on the apparatus (lung)."); ValueMultiVariation = config.Bind("General", "ValueMultiVariation", 5f, "Sets the maximum random variation (in percent) for the value multiplier (makes scrap values more natural). Set to 0 to disable."); AmountMultiEnabled = config.Bind("General", "AmountMultiplierEnabled", true, "Toggles the amount multiplier on scrap."); ValueMultiEnabled = config.Bind("General", "ValueMultiplierEnabled", true, "Toggles the value multiplier on scrap."); CompatibilityMode = config.Bind("General", "CompatibilityMode", false, "Disables all transpilers for compatibility with other mods. This will prevent multipliers from being applied to bee hives."); PluginEnabled = config.Bind("General", "PluginEnabled", true, "Toggles the functionality of the plugin; an easy way to turn everything off!"); foreach (LevelWeatherType value in Enum.GetValues(typeof(LevelWeatherType))) { Multipliers[value] = new MultiValueGroup { AmountMultiplier = BindMultiplier(config, value, "Amount", DefaultAmount(value)), ValueMultiplier = BindMultiplier(config, value, "Value", DefaultValue(value)) }; } } private unsafe static ConfigEntry BindMultiplier(ConfigFile config, LevelWeatherType weather, string type, float defaultValue) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return config.Bind("Multipliers", $"{weather}{type}Multiplier", defaultValue, type + " multiplier applied during " + ((object)(*(LevelWeatherType*)(&weather))/*cast due to .constrained prefix*/).ToString().ToLower() + " weather. Set to 1 to disable."); } private static float DefaultAmount(LevelWeatherType weather) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected I4, but got Unknown if (1 == 0) { } float result = (weather - 1) switch { 2 => 1.1f, 0 => 1.1f, 1 => 1.2f, 3 => 1.2f, 4 => 1.3f, _ => 1f, }; if (1 == 0) { } return result; } private static float DefaultValue(LevelWeatherType weather) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected I4, but got Unknown if (1 == 0) { } float result = (weather - 1) switch { 2 => 1.2f, 0 => 1.2f, 1 => 1.35f, 3 => 1.4f, 4 => 1.75f, _ => 1f, }; if (1 == 0) { } return result; } private static void ClearOrphanedEntries(ConfigFile config) { if (AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(config) is IDictionary dictionary) { dictionary.Clear(); } } } internal static class PluginInfo { public const string GUID = "uk.co.sulphurdev.weathergains"; public const string NAME = "Weather Gains"; public const string VERSION = "2.0.1"; } [BepInPlugin("uk.co.sulphurdev.weathergains", "Weather Gains", "2.0.1")] public class WeatherGains : BaseUnityPlugin { internal static PluginConfig BoundConfig { get; private set; } private static ManualLogSource Logger { get; set; } private static Harmony Harmony { get; set; } private void Awake() { BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config); Logger = ((BaseUnityPlugin)this).Logger; if (!BoundConfig.PluginEnabled.Value) { Logger.LogWarning((object)"Weather Gains v2.0.1 is disabled! If this is not intentional, please enable it in the config file."); return; } Logger.LogInfo((object)"Weather Gains v2.0.1 is loading..."); ApplyPatches(); Logger.LogInfo((object)"Weather Gains v2.0.1 has loaded!"); } private static void ApplyPatches() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("uk.co.sulphurdev.weathergains"); } Logger.LogDebug((object)"Applying patches..."); Harmony.PatchAll(); Logger.LogDebug((object)"Successfully applied all patches!"); } internal static void RemovePatches() { if (Harmony != null) { Logger.LogDebug((object)"Removing patches..."); Harmony.UnpatchSelf(); Logger.LogDebug((object)"Successfully removed all patches!"); Harmony = null; } } } } namespace WeatherGains.Types { public class MultiValueGroup { public ConfigEntry ValueMultiplier { get; set; } public ConfigEntry AmountMultiplier { get; set; } } } namespace WeatherGains.Transpilers { [HarmonyPatch(typeof(RedLocustBees))] public class RedLocustBeesTranspiler { [HarmonyPatch("SpawnHiveNearEnemy")] [HarmonyTranspiler] private static IEnumerable SpawnHiveNearEnemyTranspiler(IEnumerable instructions) { //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Expected O, but got Unknown if (WeatherGains.BoundConfig.CompatibilityMode.Value) { return instructions; } List list = new List(instructions); MethodInfo methodInfo = AccessTools.Method(typeof(RedLocustBees), "SpawnHiveClientRpc", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(MultiplierManager), "ApplyValueMultiplier", (Type[])null, (Type[])null); for (int i = 1; i < list.Count; i++) { if (!CodeInstructionExtensions.Calls(list[i], methodInfo)) { continue; } for (int num = i - 1; num >= 0; num--) { LocalBuilder localBuilder = null; if (list[num].opcode == OpCodes.Ldloc_S || list[num].opcode == OpCodes.Ldloc) { localBuilder = list[num].operand as LocalBuilder; } if (localBuilder != null && !(localBuilder.LocalType != typeof(int))) { list.Insert(num + 1, new CodeInstruction(OpCodes.Call, (object)methodInfo2)); return list; } } return list; } return list; } } } namespace WeatherGains.Patches { [HarmonyPatch(typeof(GrabbableObject))] public class GrabbableObjectPatch { [HarmonyPatch("SetScrapValue")] [HarmonyPrefix] private static void SetScrapValuePrefix(ref int setValueTo) { setValueTo = MultiplierManager.ApplyValueMultiplier(setValueTo); } } [HarmonyPatch(typeof(LungProp))] public class LungPropPatch { [HarmonyPatch("DisconnectFromMachinery")] [HarmonyPrefix] private static void DisconnectFromMachineryPatch(LungProp __instance) { if (WeatherGains.BoundConfig.LungValueMultiEnabled.Value) { ((GrabbableObject)__instance).SetScrapValue(MultiplierManager.ApplyValueMultiplier(((GrabbableObject)__instance).scrapValue)); } } } [HarmonyPatch(typeof(RoundManager))] public class RoundManagerPatch { private static float _appliedMultiplier = 1f; [HarmonyPatch("SpawnScrapInLevel")] [HarmonyPrefix] private static void SpawnScrapInLevelPrefix() { float num = MultiplierManager.ApplyAmountMultiplier(RoundManager.Instance.scrapAmountMultiplier); RoundManager.Instance.scrapAmountMultiplier = num; _appliedMultiplier = num; } [HarmonyPatch("SpawnScrapInLevel")] [HarmonyPostfix] private static void SpawnScrapInLevelPostfix() { RoundManager instance = RoundManager.Instance; instance.scrapAmountMultiplier /= _appliedMultiplier; _appliedMultiplier = 1f; } } }