Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Weather Modifiers v1.3.3
net.aliphaticus.weathermodifiers.dll
Decompiled 4 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using LobbyCompatibility.Enums; using LobbyCompatibility.Features; using Microsoft.CodeAnalysis; using MrovLib; using MrovLib.Events; using Unity.Netcode; using UnityEngine; using WeatherModifiers.Config; using WeatherModifiers.Data; using WeatherModifiers.Data.Trackers; using WeatherModifiers.Types; using WeatherRegistry; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("net.aliphaticus.weathermodifiers")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.2.0.0")] [assembly: AssemblyInformationalVersion("1.2.0+6d18f2ac7094cef31f773534e9fe8b645de68ca6")] [assembly: AssemblyProduct("Weather-Modifiers")] [assembly: AssemblyTitle("net.aliphaticus.weathermodifiers")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 WeatherModifiers { public static class BuildInfo { private const bool IsSnapshot = false; public const string Snapshot = ""; } public static class WeatherModifierManager { public static ConfigValueGroup? GetCurrentModifierGroup() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected I4, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)TimeOfDay.Instance == (Object)null) { return null; } LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather; WeatherModifiersLoggerUtil.LogInfoDebug(string.Format("Current Weather ID: {0}. Registered IDs: {1}", (int)currentLevelWeather, string.Join(", ", WeatherModifiers.BoundConfig.Modifiers.Keys.Select((LevelWeatherType k) => (int)k)))); if (WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value)) { return value; } return null; } public static bool IsFeatureEnabled(Func<ModConfiguration, ConfigEntry<bool>> featureSelector) { return featureSelector(WeatherModifiers.BoundConfig).Value; } public static bool IsWeatherRegistryLoaded() { return Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry"); } } [BepInPlugin("net.aliphaticus.weathermodifiers", "Weather-Modifiers", "1.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("robuxtrex.weathergains")] [BepInIncompatibility("WeatherMultipliers")] public class WeatherModifiers : BaseUnityPlugin { private static readonly string LobbyCompatibilityNamespace = "LobbyCompatibility"; internal static ModConfiguration BoundConfig { get; private set; } = null; internal static ConfigFile ModdedWeatherConfig { get; private set; } public static WeatherModifiers Instance { get; private set; } = null; internal static ManualLogSource Logger { get; private set; } = null; internal static Harmony? Harmony { get; set; } private void Awake() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility")) { InitializeLobbyCompatibility(); } Instance = this; BoundConfig = new ModConfiguration(((BaseUnityPlugin)this).Config); ModdedWeatherConfig = new ConfigFile(Path.Combine(Paths.ConfigPath, "net.aliphaticus.weathermodfiers_modded_weathers.cfg"), true); Patch(); Logger.LogInfo((object)"net.aliphaticus.weathermodifiers v1.2.0 has loaded!"); if (!Utility.IsNullOrWhiteSpace("")) { Logger.LogMessage((object)"net.aliphaticus.weathermodifiers is running on a snapshot build:"); Logger.LogMessage((object)"Weather-Modifiers:"); } } [MethodImpl(MethodImplOptions.NoInlining)] private void InitializeLobbyCompatibility() { try { PluginHelper.RegisterPlugin("net.aliphaticus.weathermodifiers", new Version("1.2.0"), (CompatibilityLevel)3, (VersionStrictness)2); Logger.LogInfo((object)"LobbyCompatibility registered successfully."); } catch (Exception ex) { Logger.LogWarning((object)("LobbyCompatibility was detected but failed to register: " + ex.Message)); } } internal static void Patch() { //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_0017: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("net.aliphaticus.weathermodifiers"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(); Logger.LogDebug((object)"Finished patching!"); } internal static void Unpatch() { Logger.LogDebug((object)"Unpatching..."); Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Logger.LogDebug((object)"Finished unpatching!"); } private void Start() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown if (Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry")) { Logger.LogInfo((object)"Subscribing to WeatherRegistry.SetupFinished..."); ((CustomEvent)EventManager.SetupFinished).AddListener(new Event(OnWeatherRegistrySetupFinished)); } } private void OnWeatherRegistrySetupFinished() { //IL_0041: 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) //IL_0120: Expected O, but got Unknown //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Expected O, but got Unknown //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown Logger.LogInfo((object)"WeatherRegistry setup finished, registering modded weather modifiers..."); BoundConfig.RegisterModdedWeathers(ModdedWeatherConfig); foreach (Weather weather in WeatherManager.Weathers) { if (BoundConfig.Modifiers.TryGetValue(weather.VanillaWeatherType, out ConfigValueGroup value)) { Logger.LogDebug((object)("Injecting modifiers into WeatherRegistry for " + weather.Name)); float num = ((ConfigHandler<float, float>)(object)weather.Config.ScrapValueMultiplier).Value * value.ValueModifier.Value; float num2 = ((ConfigHandler<float, float>)(object)weather.Config.ScrapAmountMultiplier).Value * value.AmountModifier.Value; if (BoundConfig.ValueModifierEnabled.Value) { weather.Config.ScrapValueMultiplier = new FloatConfigHandler(num, true); } if (BoundConfig.AmountModifierEnabled.Value) { weather.Config.ScrapAmountMultiplier = new FloatConfigHandler(num2, true); } } } ((CustomEvent)EventManager.SetupFinished).RemoveListener(new Event(OnWeatherRegistrySetupFinished)); } } public static class WeatherModifiersLoggerUtil { public static void LogInfo(string message) { WeatherModifiers.Logger.LogInfo((object)message); } public static void LogError(string message) { WeatherModifiers.Logger.LogError((object)message); } public static void LogWarning(string message) { WeatherModifiers.Logger.LogWarning((object)message); } public static void LogDebug(string message) { if (WeatherModifiers.BoundConfig.DebugLogsEnabled.Value) { WeatherModifiers.Logger.LogDebug((object)message); } } public static void LogInfoDebug(string message) { if (WeatherModifiers.BoundConfig.DebugLogsEnabled.Value) { WeatherModifiers.Logger.LogInfo((object)message); } } public static void LogErrorDebug(string message) { if (WeatherModifiers.BoundConfig.DebugLogsEnabled.Value) { WeatherModifiers.Logger.LogError((object)message); } } public static void LogWarningDebug(string message) { if (WeatherModifiers.BoundConfig.DebugLogsEnabled.Value) { WeatherModifiers.Logger.LogWarning((object)message); } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "net.aliphaticus.weathermodifiers"; public const string PLUGIN_NAME = "Weather-Modifiers"; public const string PLUGIN_VERSION = "1.2.0"; } } namespace WeatherModifiers.Types { public class ConfigValueGroup { public ConfigEntry<float> ValueModifier { get; set; } public ConfigEntry<float> AmountModifier { get; set; } public ConfigEntry<int> IndoorPowerBonus { get; set; } public ConfigEntry<int> OutdoorPowerBonus { get; set; } public ConfigEntry<int> MaxEnemyCountBonus { get; set; } public ConfigEntry<bool> IsEarlyEnemySpawning { get; set; } public ConfigEntry<bool> IsProgressiveModifiers { get; set; } } } namespace WeatherModifiers.Patches { [HarmonyPatch(typeof(TimeOfDay))] public class TimeOfDayPatch { [HarmonyPatch("UpdateProfitQuotaCurrentTime")] [HarmonyPostfix] private static void UpdateQuotaPostfix(TimeOfDay __instance) { QuotaTracker.TimesFulfilled = __instance.timesFulfilledQuota; } [HarmonyPatch("Start")] [HarmonyPostfix] private static void StartPostfix(TimeOfDay __instance) { QuotaTracker.TimesFulfilled = __instance.timesFulfilledQuota; } [HarmonyPatch("SetNewProfitQuota")] [HarmonyPostfix] private static void SetNewProfitQuotaPostfix(TimeOfDay __instance) { QuotaTracker.TimesFulfilled = __instance.timesFulfilledQuota; WeatherModifiersLoggerUtil.LogInfoDebug($"Quota fulfilled! Updated QuotaTracker.TimesFulfilled to: {QuotaTracker.TimesFulfilled}"); } } } namespace WeatherModifiers.Patches.Scrap { [HarmonyPatch(typeof(LungProp))] public class ApparatusScrapPatch { [HarmonyPatch("DisconnectFromMachinery")] [HarmonyPrefix] [HarmonyPriority(100)] private static void DisconnectFromMachineryPrefix(LungProp __instance) { if (!WeatherModifiers.BoundConfig.ApparatusLungValueModifierEnabled.Value) { return; } ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (currentModifierGroup != null) { float num; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num = (float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalValueModifier.Value + currentModifierGroup.ValueModifier.Value; } else { num = currentModifierGroup.ValueModifier.Value; } ((GrabbableObject)__instance).SetScrapValue((int)((float)((GrabbableObject)__instance).scrapValue * num)); } } } [HarmonyPatch(typeof(GiftBoxItem))] public class GiftBoxItemScrapPatch { private static int GetPresentObjectValue(GiftBoxItem __instance, LevelWeatherType? weatherType) { //IL_0050: 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) if (WeatherModifiers.BoundConfig.ValueModifierEnabled.Value) { LevelWeatherType? val = null; if (!weatherType.HasValue) { string giftBoxWeather = GiftBoxWeatherDataManager.GetGiftBoxWeather(__instance); WeatherModifiersLoggerUtil.LogInfoDebug("Loading GiftBox, saved weather type is " + giftBoxWeather + " and will be used to calculate present value."); if (Enum.TryParse<LevelWeatherType>(giftBoxWeather, out LevelWeatherType result)) { WeatherModifiersLoggerUtil.LogInfoDebug($"Loading GiftBox using weather: {result}, saved weather type is {giftBoxWeather}."); val = result; } } else { val = weatherType; } ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (val.HasValue && currentModifierGroup != null) { float num; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num = (float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalValueModifier.Value + currentModifierGroup.ValueModifier.Value; } else { num = currentModifierGroup.ValueModifier.Value; } try { float num2 = RoundManager.Instance.scrapValueMultiplier * num; Random random = new Random((int)((GrabbableObject)__instance).targetFloorPosition.x + (int)((GrabbableObject)__instance).targetFloorPosition.y); return (int)((float)random.Next(__instance.objectInPresentItem.minValue + 25, __instance.objectInPresentItem.maxValue + 35) * num2); } catch (Exception arg) { WeatherModifiersLoggerUtil.LogErrorDebug($"Error occured while calculating modified present value: {arg}"); } } } return __instance.objectInPresentValue; } [HarmonyPatch("LoadItemSaveData")] [HarmonyPostfix] [HarmonyPriority(700)] private static void LoadItemSaveDataPostfix(GiftBoxItem __instance, int saveData) { GiftBoxItemTracker.TrackGiftBox(__instance); __instance.objectInPresentValue = GetPresentObjectValue(__instance, null); WeatherModifiersLoggerUtil.LogInfoDebug($"GiftBoxItem {((Object)__instance).name} has been loaded with a modified present value of {__instance.objectInPresentValue}."); } [HarmonyPatch("InitializeAfterPositioning")] [HarmonyPostfix] [HarmonyPriority(700)] private static void StartPostfix(GiftBoxItem __instance) { GiftBoxItemTracker.TrackGiftBox(__instance); __instance.objectInPresentValue = GetPresentObjectValue(__instance, null); WeatherModifiersLoggerUtil.LogInfoDebug($"GiftBoxItem {((Object)__instance).name} has been loaded with a modified present value of {__instance.objectInPresentValue}."); } [HarmonyPatch(typeof(GiftBoxItem), "OpenGiftBoxServerRpc")] [HarmonyPrefix] private static void OpenGiftBoxServerRpcPrefix(GiftBoxItem __instance) { if (((NetworkBehaviour)__instance).IsServer) { __instance.objectInPresentValue = GetPresentObjectValue(__instance, null); WeatherModifiersLoggerUtil.LogInfoDebug($"Live-adjusting GiftBox value to {__instance.objectInPresentValue} before opening."); } } } [HarmonyPatch(typeof(RedLocustBees))] public class RedLocustBeeHivePatch { [HarmonyPatch("SpawnHiveNearEnemy")] [HarmonyPrefix] [HarmonyPriority(100)] private static bool SpawnHiveNearEnemyPrefix(RedLocustBees __instance) { //IL_0038: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) if (((NetworkBehaviour)__instance).IsServer) { Random random = new Random(StartOfRound.Instance.randomMapSeed + 1314 + ((EnemyAI)__instance).enemyType.numberSpawned); Vector3 randomNavMeshPositionInBoxPredictable = RoundManager.Instance.GetRandomNavMeshPositionInBoxPredictable(((Component)__instance).transform.position, 10f, RoundManager.Instance.navHit, random, -5, 1f); GameObject val = Object.Instantiate<GameObject>(__instance.hivePrefab, randomNavMeshPositionInBoxPredictable + Vector3.up * 0.2f, Quaternion.Euler(Vector3.zero), RoundManager.Instance.spawnedScrapContainer); val.SetActive(true); val.GetComponent<NetworkObject>().Spawn(false); int num = ((!(Vector3.Distance(randomNavMeshPositionInBoxPredictable, ((Component)StartOfRound.Instance.elevatorTransform).transform.position) < 40f)) ? random.Next(50, 150) : random.Next(40, 100)); ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (WeatherModifiers.BoundConfig.RedLocustBeesEnabled.Value && currentModifierGroup != null) { float num2; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num2 = (float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalValueModifier.Value + currentModifierGroup.ValueModifier.Value; } else { num2 = currentModifierGroup.ValueModifier.Value; } if (WeatherModifiers.BoundConfig.ValueModifierEnabled.Value) { num = Mathf.RoundToInt((float)num * num2); if (num < 1) { num = 1; } WeatherModifiersLoggerUtil.LogInfoDebug($"Modified Red Locust Bee Hive Scrap Value: {num}"); } } int num3 = num; __instance.SpawnHiveClientRpc(NetworkObjectReference.op_Implicit(val.GetComponent<NetworkObject>()), num3, randomNavMeshPositionInBoxPredictable + Vector3.up * 0.2f); return false; } return true; } } [HarmonyPatch(typeof(RoundManager))] public class ScrapPatch { [HarmonyPatch("SpawnScrapInLevel")] [HarmonyPrefix] [HarmonyPriority(100)] private static void SpawnScrapInLevelPrefix() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (currentModifierGroup == null) { WeatherModifiersLoggerUtil.LogWarning($"No modifier found for weather {TimeOfDay.Instance.currentLevelWeather}."); } else if (!WeatherModifierManager.IsWeatherRegistryLoaded()) { float num; float num2; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num = (float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalValueModifier.Value + currentModifierGroup.ValueModifier.Value; num2 = (float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalAmountModifier.Value + currentModifierGroup.AmountModifier.Value; } else { num = currentModifierGroup.ValueModifier.Value; num2 = currentModifierGroup.AmountModifier.Value; } if (WeatherModifiers.BoundConfig.ValueModifierEnabled.Value) { RoundManager instance = RoundManager.Instance; instance.scrapValueMultiplier *= num; } if (WeatherModifiers.BoundConfig.AmountModifierEnabled.Value) { RoundManager instance2 = RoundManager.Instance; instance2.scrapAmountMultiplier *= num2; } WeatherModifiersLoggerUtil.LogInfoDebug("Scrap value and generation and modifier values successfully adjusted. They are now:\n" + $"Scrap value modifier: {RoundManager.Instance.scrapValueMultiplier}\n" + $"Scrap amount modifier: {RoundManager.Instance.scrapAmountMultiplier}"); } } [HarmonyPatch("SpawnScrapInLevel")] [HarmonyPostfix] [HarmonyPriority(700)] private static void SpawnScrapInLevelPostfix() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (currentModifierGroup == null) { WeatherModifiersLoggerUtil.LogWarning($"No modifier found for weather {TimeOfDay.Instance.currentLevelWeather}."); } else if (!WeatherModifierManager.IsWeatherRegistryLoaded()) { float num; float num2; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num = (float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalValueModifier.Value + currentModifierGroup.ValueModifier.Value; num2 = (float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalAmountModifier.Value + currentModifierGroup.AmountModifier.Value; } else { num = currentModifierGroup.ValueModifier.Value; num2 = currentModifierGroup.AmountModifier.Value; } if (WeatherModifiers.BoundConfig.ValueModifierEnabled.Value) { RoundManager instance = RoundManager.Instance; instance.scrapValueMultiplier /= num; } if (WeatherModifiers.BoundConfig.AmountModifierEnabled.Value) { RoundManager instance2 = RoundManager.Instance; instance2.scrapAmountMultiplier /= num2; } WeatherModifiersLoggerUtil.LogInfoDebug("Reverted Scrap value and generation and modifier values to their original values. This is intended, scrap has already been generated with the configured parameters.\n" + $"Reverted Scrap Modifier Value: {RoundManager.Instance.scrapValueMultiplier}\n" + $"Reverted Scrap Amount Modifier Value: {RoundManager.Instance.scrapAmountMultiplier}"); } } } } namespace WeatherModifiers.Patches.GiftBox { [HarmonyPatch(typeof(NetworkBehaviour))] public class GiftBoxItemTrackingOnDestroyPatch { [HarmonyPatch("OnDestroy")] [HarmonyPostfix] private static void OnDestroyPostFix(NetworkBehaviour __instance) { if (__instance is GiftBoxItem) { WeatherModifiersLoggerUtil.LogInfoDebug("GiftBoxItem has been destroyed. Calling GiftBoxTracker.Cleanup()."); GiftBoxTracker.Cleanup(); } } } [HarmonyPatch(typeof(GiftBoxItem))] public class GiftBoxLoadPatch { [HarmonyPatch("LoadItemSaveData")] [HarmonyPostfix] private static void LoadItemSaveDataPostfix(GiftBoxItem __instance, int saveData) { //IL_010f: Unknown result type (might be due to invalid IL or missing references) if (!ES3.KeyExists("shipGrabbableItemIDs", GameNetworkManager.Instance.currentSaveFileName) || !ES3.KeyExists("shipGiftBoxItemCollectedWeather", GameNetworkManager.Instance.currentSaveFileName)) { WeatherModifiersLoggerUtil.LogWarning("No ship grabbable item IDs found, skipping gift box weather data load."); return; } string[] array = ES3.Load<string[]>("shipGiftBoxItemCollectedWeather", GameNetworkManager.Instance.currentSaveFileName); int[] array2 = ES3.Load<int[]>("shipGrabbableItemIDs", GameNetworkManager.Instance.currentSaveFileName); if (array.Length != array2.Length) { WeatherModifiersLoggerUtil.LogError("Saved weather types and saved item IDs arrays do not match in length. Skipping load."); return; } LevelWeatherType? val = null; for (int i = 0; i < array2.Length; i++) { WeatherModifiersLoggerUtil.LogInfoDebug($"Checking if saved item ID {array2[i]} matches item {((Object)((GrabbableObject)__instance).itemProperties).name}."); if (array2[i] < StartOfRound.Instance.allItemsList.itemsList.Count && (Object)(object)StartOfRound.Instance.allItemsList.itemsList[array2[i]] == (Object)(object)((GrabbableObject)__instance).itemProperties) { WeatherModifiersLoggerUtil.LogInfoDebug("Trying to load weather from " + ((Object)((GrabbableObject)__instance).itemProperties).name + "."); if (Enum.TryParse<LevelWeatherType>(array[i], out LevelWeatherType result)) { val = result; } } } WeatherModifiersLoggerUtil.LogInfoDebug($"Loaded GiftBoxItem: weather {val}."); GiftBoxItemTracker.TrackGiftBox(__instance); } } [HarmonyPatch(typeof(GameNetworkManager))] public class GiftBoxSavePatch { public const string ShipGiftBoxWeatherSaveKey = "shipGiftBoxItemCollectedWeather"; [HarmonyPatch("SaveItemsInShip")] [HarmonyPostfix] private static void SaveItemsInShipPostFix(GameNetworkManager __instance) { GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsInactive)0, (FindObjectsSortMode)0); GiftBoxItem[] array2 = Object.FindObjectsOfType<GiftBoxItem>(); if (array2 == null || array2.Length == 0) { ES3.DeleteKey("shipGiftBoxItemCollectedWeather"); } else { if (StartOfRound.Instance.isChallengeFile) { return; } List<string> list = new List<string>(); for (int i = 0; i < array.Length && i <= StartOfRound.Instance.maxShipItemCapacity; i++) { if (!StartOfRound.Instance.allItemsList.itemsList.Contains(array[i].itemProperties) || array[i].deactivated) { continue; } if ((Object)(object)array[i].itemProperties.spawnPrefab == (Object)null) { Debug.LogError((object)("Item '" + array[i].itemProperties.itemName + "' has no spawn prefab set!")); } else { if (array[i].itemUsedUp) { continue; } for (int j = 0; j < StartOfRound.Instance.allItemsList.itemsList.Count; j++) { if ((Object)(object)StartOfRound.Instance.allItemsList.itemsList[j] == (Object)(object)array[i].itemProperties) { GrabbableObject obj = array[i]; GiftBoxItem val = (GiftBoxItem)(object)((obj is GiftBoxItem) ? obj : null); if (val != null) { WeatherModifiersLoggerUtil.LogInfoDebug("Saving weather for GiftBoxItem, weather present for giftBox uniqueID: " + GiftBoxTracker.GetOrCreateUniqueID(val) + " in DataManager: " + GiftBoxWeatherDataManager.GetGiftBoxWeather(val)); list.Add(GiftBoxWeatherDataManager.GetGiftBoxWeather(val)); } else { list.Add("null"); } break; } } } } if (list.Count > 0) { ES3.Save<string[]>("shipGiftBoxItemCollectedWeather", list.ToArray(), __instance.currentSaveFileName); WeatherModifiersLoggerUtil.LogInfoDebug(string.Format("Saved weather for {0} items in {1}. Weathers: [{2}]", list.Count, __instance.currentSaveFileName, string.Join(", ", list))); } else { ES3.DeleteKey("shipGiftBoxItemCollectedWeather", __instance.currentSaveFileName); } } } } [HarmonyPatch(typeof(StartOfRound))] public class StartOfRoundLoadShipGiftBoxItemsPatch { private static int[] capturedShipItemIds; private static Vector3[] capturedItemPositions; private static int[] capturedScrapValues; private static string[] savedWeatherTypes; private static Dictionary<int, NetworkObject> spawnedNetworkObjects = new Dictionary<int, NetworkObject>(); private static bool isFoundIDsAndWeatherData = false; [HarmonyPatch("LoadShipGrabbableItems")] [HarmonyPrefix] private static void LoadShipGrabbableItemsPrefix() { if (!ES3.KeyExists("shipGrabbableItemIDs", GameNetworkManager.Instance.currentSaveFileName) || !ES3.KeyExists("shipGrabbableItemPos", GameNetworkManager.Instance.currentSaveFileName) || !ES3.KeyExists("shipScrapValues", GameNetworkManager.Instance.currentSaveFileName) || !ES3.KeyExists("shipGiftBoxItemCollectedWeather", GameNetworkManager.Instance.currentSaveFileName)) { WeatherModifiersLoggerUtil.LogWarning("One of the required save data arrays to load gift box weather data was not found, skipping gift box weather data load."); return; } isFoundIDsAndWeatherData = true; capturedShipItemIds = ES3.Load<int[]>("shipGrabbableItemIDs", GameNetworkManager.Instance.currentSaveFileName); capturedItemPositions = ES3.Load<Vector3[]>("shipGrabbableItemPos", GameNetworkManager.Instance.currentSaveFileName); capturedScrapValues = ES3.Load<int[]>("shipScrapValues", GameNetworkManager.Instance.currentSaveFileName); savedWeatherTypes = ES3.Load<string[]>("shipGiftBoxItemCollectedWeather", GameNetworkManager.Instance.currentSaveFileName); spawnedNetworkObjects.Clear(); } [HarmonyPatch("LoadShipGrabbableItems")] [HarmonyPostfix] private static void LoadShipGrabbableItemsPostfix(StartOfRound __instance) { if (capturedShipItemIds == null || capturedShipItemIds.Length == 0 || capturedItemPositions == null || capturedItemPositions.Length == 0 || capturedScrapValues == null || capturedScrapValues.Length == 0 || savedWeatherTypes == null || savedWeatherTypes.Length == 0) { WeatherModifiersLoggerUtil.LogWarning("No ship grabbable item IDs found, or one of the arrays was length 0/null, skipping gift box weather data load."); return; } int num = 0; for (int i = 0; i < capturedShipItemIds.Length; i++) { if (__instance.allItemsList.itemsList[capturedShipItemIds[i]].isScrap) { num++; } } if (capturedShipItemIds.Length != capturedItemPositions.Length || num != capturedScrapValues.Length || capturedShipItemIds.Length != savedWeatherTypes.Length) { WeatherModifiersLoggerUtil.LogError("Inconsistent array lengths in saved data, aborting gift box item weather modifier loading." + $"capturedShipItemIds.Length={capturedShipItemIds.Length}, " + $"capturedItemPositions.Length={capturedItemPositions.Length}, " + $"capturedScrapValues.Length={capturedScrapValues.Length}, " + $"expected capturedScrapValues.Length={num}, " + $"savedWeatherTypes.Length={savedWeatherTypes.Length}."); return; } if (!isFoundIDsAndWeatherData) { WeatherModifiersLoggerUtil.LogWarning("One of the required save data arrays to load gift box weather data was not found, skipping gift box weather data load."); return; } TrackSpawnedGrabbableObjectsNetworkObjects(__instance); foreach (KeyValuePair<int, NetworkObject> spawnedNetworkObject in spawnedNetworkObjects) { int key = spawnedNetworkObject.Key; NetworkObject value = spawnedNetworkObject.Value; WeatherModifiersLoggerUtil.LogInfoDebug($"Processing custom save for item. Array index: {key}, NetworkObject ID: {value.NetworkObjectId}"); GrabbableObject component = ((Component)value).gameObject.GetComponent<GrabbableObject>(); GiftBoxItem val = (GiftBoxItem)(object)((component is GiftBoxItem) ? component : null); if (val != null) { WeatherModifiersLoggerUtil.LogInfo("Found a gift box item, attempting to load custom save data."); LoadCustomSaveData(key, val); } } } private static void LoadCustomSaveData(int arrayIndex, GiftBoxItem giftBoxItem) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) WeatherModifiersLoggerUtil.LogInfoDebug($"Gift box item {((NetworkBehaviour)giftBoxItem).NetworkObjectId} has a saved weather type of {savedWeatherTypes[arrayIndex]}."); if (Enum.TryParse<LevelWeatherType>(savedWeatherTypes[arrayIndex], out LevelWeatherType result)) { GiftBoxItemTracker.TrackGiftBox(giftBoxItem, overrideExisting: true, result); WeatherModifiersLoggerUtil.LogInfoDebug($"Found saved weather and force set gift box item {((NetworkBehaviour)giftBoxItem).NetworkObjectId} to weather {result} in the gift box weather data manager."); } } private static void TrackSpawnedGrabbableObjectsNetworkObjects(StartOfRound __instance) { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0395: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) //IL_05b2: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_040a: Unknown result type (might be due to invalid IL or missing references) List<GrabbableObject> source = Object.FindObjectsByType<GrabbableObject>((FindObjectsInactive)0, (FindObjectsSortMode)0).ToList(); List<GiftBoxItem> list = source.OfType<GiftBoxItem>().ToList(); Dictionary<GiftBoxItem, LevelWeatherType> dictionary = new Dictionary<GiftBoxItem, LevelWeatherType>(); Dictionary<Vector3, int?> itemPositionsWithScrapValues = new Dictionary<Vector3, int?>(); int num = 0; for (int i = 0; i < capturedItemPositions.Length; i++) { if (__instance.allItemsList.itemsList[capturedShipItemIds[i]].isScrap) { itemPositionsWithScrapValues.Add(capturedItemPositions[i], capturedScrapValues[num]); num++; } else { itemPositionsWithScrapValues.Add(capturedItemPositions[i], null); } } float num2 = 0.1f; List<GiftBoxItem> list2 = new List<GiftBoxItem>(); List<KeyValuePair<Vector3, int?>> list3 = new List<KeyValuePair<Vector3, int?>>(); foreach (GiftBoxItem item in list) { foreach (KeyValuePair<Vector3, int?> item2 in itemPositionsWithScrapValues) { if (!(((Component)item).transform.position == item2.Key) || ((GrabbableObject)item).scrapValue != item2.Value) { continue; } num = 0; for (int num3 = 0; num3 < capturedShipItemIds.Length; num3++) { if (ValidateSaveDataArraysAndItemId(__instance, num3) && (Object)(object)__instance.allItemsList.itemsList[capturedShipItemIds[num3]] == (Object)(object)((GrabbableObject)item).itemProperties && capturedItemPositions[num3] == ((Component)item).transform.position && capturedScrapValues[num] == ((GrabbableObject)item).scrapValue && !spawnedNetworkObjects.ContainsKey(num3)) { try { spawnedNetworkObjects.Add(num3, ((Component)item).gameObject.GetComponent<NetworkObject>()); list3.Add(item2); list2.Add(item); WeatherModifiersLoggerUtil.LogInfoDebug($"Found exact match for giftbox at position {((Component)item).transform.position} with scrap value {((GrabbableObject)item).scrapValue}, saved itemID: {num3}."); } catch (Exception arg) { WeatherModifiersLoggerUtil.LogError($"Error occured while adding gift box network object to dictionary, was the itemID key already present?: {arg}"); goto IL_0237; } break; } goto IL_0237; IL_0237: if (__instance.allItemsList.itemsList[capturedShipItemIds[num3]].isScrap) { num++; } } } } list.RemoveAll(list2.Contains); list3.ForEach(delegate(KeyValuePair<Vector3, int?> itemPositionScrapValue) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) itemPositionsWithScrapValues.Remove(itemPositionScrapValue.Key); }); list3.Clear(); foreach (GiftBoxItem item3 in list) { foreach (KeyValuePair<Vector3, int?> item4 in itemPositionsWithScrapValues) { if (!(Vector3.Distance(((Component)item3).transform.position, item4.Key) <= num2) || ((GrabbableObject)item3).scrapValue != item4.Value) { continue; } num = 0; for (int num4 = 0; num4 < capturedShipItemIds.Length; num4++) { if (ValidateSaveDataArraysAndItemId(__instance, num4) && (Object)(object)__instance.allItemsList.itemsList[capturedShipItemIds[num4]] == (Object)(object)((GrabbableObject)item3).itemProperties && Vector3.Distance(((Component)item3).transform.position, capturedItemPositions[num4]) <= num2 && capturedScrapValues[num] == ((GrabbableObject)item3).scrapValue && !spawnedNetworkObjects.ContainsKey(num4)) { try { spawnedNetworkObjects.Add(num4, ((Component)item3).gameObject.GetComponent<NetworkObject>()); list3.Add(item4); list2.Add(item3); WeatherModifiersLoggerUtil.LogInfoDebug($"Found tolerance match for giftbox at position {((Component)item3).transform.position} with scrap value {((GrabbableObject)item3).scrapValue}, saved itemID: {num4}."); } catch (Exception arg2) { WeatherModifiersLoggerUtil.LogError($"Error occured while adding gift box network object to dictionary, was the itemID key already present?: {arg2}"); goto IL_0448; } break; } goto IL_0448; IL_0448: if (__instance.allItemsList.itemsList[capturedShipItemIds[num4]].isScrap) { num++; } } } } list.RemoveAll(list2.Contains); list3.ForEach(delegate(KeyValuePair<Vector3, int?> itemPositionScrapValue) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) itemPositionsWithScrapValues.Remove(itemPositionScrapValue.Key); }); list3.Clear(); foreach (GiftBoxItem item5 in list) { foreach (KeyValuePair<Vector3, int?> item6 in itemPositionsWithScrapValues) { num = 0; for (int num5 = 0; num5 < capturedShipItemIds.Length; num5++) { if (ValidateSaveDataArraysAndItemId(__instance, num5) && (Object)(object)__instance.allItemsList.itemsList[capturedShipItemIds[num5]] == (Object)(object)((GrabbableObject)item5).itemProperties && !spawnedNetworkObjects.ContainsKey(num5) && capturedScrapValues[num] == ((GrabbableObject)item5).scrapValue) { try { spawnedNetworkObjects.Add(num5, ((Component)item5).gameObject.GetComponent<NetworkObject>()); list3.Add(item6); list2.Add(item5); WeatherModifiersLoggerUtil.LogInfoDebug($"Found only scrap value match for giftbox at position {((Component)item5).transform.position} with scrap value {((GrabbableObject)item5).scrapValue}, saved itemID: {num5}."); } catch (Exception arg3) { WeatherModifiersLoggerUtil.LogError($"Error occured while adding gift box network object to dictionary, was the itemID key already present?: {arg3}"); goto IL_05f0; } break; } goto IL_05f0; IL_05f0: if (__instance.allItemsList.itemsList[capturedShipItemIds[num5]].isScrap) { num++; } } } } list.RemoveAll(list2.Contains); list3.ForEach(delegate(KeyValuePair<Vector3, int?> itemPositionScrapValue) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) itemPositionsWithScrapValues.Remove(itemPositionScrapValue.Key); }); list3.Clear(); if (list.Count == 0) { WeatherModifiersLoggerUtil.LogInfo("All gift boxes have been matched to saved items, proceeding with loading."); } else { WeatherModifiersLoggerUtil.LogWarning($"Found {list.Count} unmatched gift boxes, proceeding with loading. Those gift boxes will not have modified values."); } } private static bool ValidateSaveDataArraysAndItemId(StartOfRound __instance, int arrayIndex) { if (arrayIndex < capturedShipItemIds.Length && arrayIndex < capturedItemPositions.Length) { return capturedShipItemIds[arrayIndex] < __instance.allItemsList.itemsList.Count; } return false; } } } namespace WeatherModifiers.Patches.Enemy { [HarmonyPatch(typeof(RoundManager))] public class EnemyCapPatch { [HarmonyPatch("RefreshEnemiesList")] [HarmonyPostfix] [HarmonyPriority(700)] private static void RefreshEnemiesListPostfix(RoundManager __instance) { //IL_0112: Unknown result type (might be due to invalid IL or missing references) if (!((NetworkBehaviour)__instance).IsServer || (Object)(object)TimeOfDay.Instance == (Object)null) { return; } ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (!WeatherModifiers.BoundConfig.PowerModifierEnabled.Value || currentModifierGroup == null) { return; } int value = currentModifierGroup.MaxEnemyCountBonus.Value; if (value < 0) { return; } int num = 0; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num = (int)((float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalMaxEnemyBonus.Value); } foreach (SpawnableEnemyWithRarity enemy in __instance.currentLevel.Enemies) { EnemyType enemyType = enemy.enemyType; enemyType.MaxCount += value + num; } foreach (SpawnableEnemyWithRarity outsideEnemy in __instance.currentLevel.OutsideEnemies) { EnemyType enemyType2 = outsideEnemy.enemyType; enemyType2.MaxCount += value + num; } WeatherModifiersLoggerUtil.LogInfoDebug($"Weather {TimeOfDay.Instance.currentLevelWeather} increased all enemy MaxCounts by {value + num}."); } } [HarmonyPatch(typeof(RoundManager))] public class EnemyCurvePatch { [HarmonyPatch("RefreshEnemiesList")] [HarmonyPostfix] [HarmonyPriority(700)] private static void RefreshEnemiesListPostfix(RoundManager __instance) { if (!((NetworkBehaviour)__instance).IsServer) { return; } ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (WeatherModifiers.BoundConfig.PowerModifierEnabled.Value && currentModifierGroup != null) { int num = 0; int num2 = 0; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num = (int)((float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalIndoorPowerBonus.Value); num2 = (int)((float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalOutdoorPowerBonus.Value); } AdjustCurveInside(__instance.currentLevel.enemySpawnChanceThroughoutDay, currentModifierGroup.IndoorPowerBonus.Value + num); AdjustCurveOutside(__instance.currentLevel.outsideEnemySpawnChanceThroughDay, currentModifierGroup.OutdoorPowerBonus.Value + num2); } } private static void AdjustCurveInside(AnimationCurve curve, int bonus) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (bonus <= 0) { return; } float num = 0.1389f; float num2 = curve.Evaluate(num); curve.AddKey(new Keyframe(num, num2)); Keyframe[] keys = curve.keys; for (int i = 0; i < keys.Length; i++) { if (((Keyframe)(ref keys[i])).time > num) { ref Keyframe reference = ref keys[i]; ((Keyframe)(ref reference)).value = ((Keyframe)(ref reference)).value + (float)bonus * 0.075f; } } curve.keys = keys; } private static void AdjustCurveOutside(AnimationCurve curve, int bonus) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (bonus <= 0) { return; } float num = 0.25f; float num2 = curve.Evaluate(num); curve.AddKey(new Keyframe(num, num2)); Keyframe[] keys = curve.keys; for (int i = 0; i < keys.Length; i++) { if (((Keyframe)(ref keys[i])).time > num) { ref Keyframe reference = ref keys[i]; ((Keyframe)(ref reference)).value = ((Keyframe)(ref reference)).value + (float)bonus * 0.075f; } } curve.keys = keys; } } [HarmonyPatch(typeof(RoundManager))] public class EnemyPowerPatch { [HarmonyPatch("RefreshEnemiesList")] [HarmonyPostfix] [HarmonyPriority(700)] private static void RefreshEnemiesListPostfix(RoundManager __instance) { //IL_00c1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)TimeOfDay.Instance == (Object)null) { return; } ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (WeatherModifiers.BoundConfig.PowerModifierEnabled.Value && currentModifierGroup != null) { float currentMaxInsidePower = __instance.currentMaxInsidePower; float currentMaxOutsidePower = __instance.currentMaxOutsidePower; int num = 0; int num2 = 0; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num = (int)((float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalIndoorPowerBonus.Value); num2 = (int)((float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalOutdoorPowerBonus.Value); } __instance.currentMaxInsidePower += (float)(currentModifierGroup.IndoorPowerBonus.Value + num); __instance.currentMaxOutsidePower += (float)(currentModifierGroup.OutdoorPowerBonus.Value + num2); WeatherModifiersLoggerUtil.LogInfoDebug($"Weather {TimeOfDay.Instance.currentLevelWeather} applied Power Bonuses: " + $"Indoor [{currentMaxInsidePower}+{currentModifierGroup.IndoorPowerBonus.Value}={__instance.currentMaxInsidePower}], Outdoor [{currentMaxOutsidePower}+{currentModifierGroup.OutdoorPowerBonus.Value}={__instance.currentMaxOutsidePower}]"); } } } [HarmonyPatch(typeof(RoundManager))] public class EnemySpawnTimingPatch { public const float EarlySpawnTime = 150f; private const float EarlySpawnTimeInside = 150f; private const float EarlySpawnTimeOutside = 270f; private static float _originalDayTime; private static int _originalBatchTime; private static bool IsEarlySpawningEnabledForCurrentWeather() { if (!WeatherModifiers.BoundConfig.EarlyEnemySpawningEnabled.Value) { return false; } return WeatherModifierManager.GetCurrentModifierGroup()?.IsEarlyEnemySpawning.Value ?? false; } private static float GetModifiedNormalizedTime(RoundManager instance, float startThreshold) { if (!IsEarlySpawningEnabledForCurrentWeather()) { return instance.timeScript.currentDayTime / instance.timeScript.totalTime; } float currentDayTime = instance.timeScript.currentDayTime; if (currentDayTime < startThreshold) { return 0f; } float totalTime = instance.timeScript.totalTime; float num = (currentDayTime - startThreshold) / (totalTime - startThreshold); return Mathf.Clamp01(num); } [HarmonyPatch("Update")] [HarmonyPrefix] [HarmonyPriority(100)] private static void UpdatePrefix(RoundManager __instance) { if (((NetworkBehaviour)__instance).IsServer && __instance.dungeonFinishedGeneratingForAllPlayers && !__instance.isSpawningEnemies && !__instance.begunSpawningEnemies && IsEarlySpawningEnabledForCurrentWeather() && __instance.timeScript.currentDayTime >= 150f) { __instance.begunSpawningEnemies = true; __instance.BeginEnemySpawning(); WeatherModifiersLoggerUtil.LogInfo("Early spawning sequence initiated."); } } private static float CalculateMinEnemyModifier(int totalBonusIndoorPower) { float num = ((float)totalBonusIndoorPower - 0.2f) * -0.001f + 0.2f; return Mathf.Clamp(num, 0.1f, 0.2f); } [HarmonyPatch("PlotOutEnemiesForNextHour")] [HarmonyPrefix] [HarmonyPriority(100)] private static void PlotOutEnemiesPrefix(RoundManager __instance) { if (!((NetworkBehaviour)__instance).IsServer || !IsEarlySpawningEnabledForCurrentWeather()) { return; } int num = 0; bool flag = false; float num2 = 0.2f; ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (currentModifierGroup != null) { int num3 = 0; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num3 = (int)((float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalIndoorPowerBonus.Value); } num = currentModifierGroup.IndoorPowerBonus.Value + num3; if (IsEarlySpawningEnabledForCurrentWeather()) { if (__instance.timeScript.currentDayTime >= 150f) { __instance.minEnemiesToSpawn = Mathf.Max(1, (int)((float)num * CalculateMinEnemyModifier(num))); flag = true; } else { __instance.minEnemiesToSpawn = 0; } } } _originalDayTime = __instance.timeScript.currentDayTime; float modifiedNormalizedTime = GetModifiedNormalizedTime(__instance, 150f); __instance.timeScript.currentDayTime = modifiedNormalizedTime * __instance.timeScript.totalTime; __instance.timeScript.normalizedTimeOfDay = modifiedNormalizedTime; _originalBatchTime = __instance.hourTimeBetweenEnemySpawnBatches; if ((IsEarlySpawningEnabledForCurrentWeather() && __instance.timeScript.currentDayTime >= 150f) || (__instance.begunSpawningEnemies && num > 0)) { __instance.hourTimeBetweenEnemySpawnBatches = 1; if (!flag && num > 0) { __instance.minEnemiesToSpawn = Mathf.Max(0, (int)((float)num * CalculateMinEnemyModifier(num))); flag = true; } } } [HarmonyPatch("PlotOutEnemiesForNextHour")] [HarmonyPostfix] [HarmonyPriority(700)] private static void PlotOutEnemiesPostfix(RoundManager __instance) { if (((NetworkBehaviour)__instance).IsServer && IsEarlySpawningEnabledForCurrentWeather()) { __instance.hourTimeBetweenEnemySpawnBatches = _originalBatchTime; __instance.timeScript.currentDayTime = _originalDayTime; __instance.timeScript.normalizedTimeOfDay = _originalDayTime / __instance.timeScript.totalTime; } } [HarmonyPatch("SpawnEnemiesOutside")] [HarmonyPrefix] [HarmonyPriority(100)] private static void SpawnEnemiesOutsidePrefix(RoundManager __instance) { if (!((NetworkBehaviour)__instance).IsServer || !IsEarlySpawningEnabledForCurrentWeather()) { return; } ConfigValueGroup currentModifierGroup = WeatherModifierManager.GetCurrentModifierGroup(); if (currentModifierGroup != null) { int num = 0; if (currentModifierGroup.IsProgressiveModifiers.Value) { int timesFulfilled = QuotaTracker.TimesFulfilled; num = (int)((float)timesFulfilled * WeatherModifiers.BoundConfig.ProgressiveAdditionalOutdoorPowerBonus.Value); } if (IsEarlySpawningEnabledForCurrentWeather()) { if (__instance.timeScript.currentDayTime >= 270f) { __instance.minOutsideEnemiesToSpawn = Mathf.Max(1, (int)((float)(currentModifierGroup.OutdoorPowerBonus.Value + num) * 0.2f)); } else { __instance.minOutsideEnemiesToSpawn = 0; } } } _originalDayTime = __instance.timeScript.currentDayTime; __instance.timeScript.currentDayTime = GetModifiedNormalizedTime(__instance, 270f) * __instance.timeScript.totalTime; } [HarmonyPatch("SpawnEnemiesOutside")] [HarmonyPostfix] [HarmonyPriority(700)] private static void SpawnEnemiesOutsidePostfix(RoundManager __instance) { if (((NetworkBehaviour)__instance).IsServer && IsEarlySpawningEnabledForCurrentWeather()) { __instance.timeScript.currentDayTime = _originalDayTime; } } } } namespace WeatherModifiers.Data { public static class GiftBoxTracker { private static readonly Dictionary<int, string> InstanceToUniqueID = new Dictionary<int, string>(); private static readonly Dictionary<string, int> UniqueIDToInstance = new Dictionary<string, int>(); public static string GetOrCreateUniqueID(GiftBoxItem giftBox) { try { if ((Object)(object)giftBox == (Object)null) { throw new ArgumentNullException("giftBox"); } } catch (Exception arg) { WeatherModifiersLoggerUtil.LogError($"Failed to create unique id for gift box as it was null: {arg}"); } int instanceID = ((Object)giftBox).GetInstanceID(); if (InstanceToUniqueID.TryGetValue(instanceID, out string value)) { return value; } value = Guid.NewGuid().ToString(); InstanceToUniqueID.Add(instanceID, value); UniqueIDToInstance.Add(value, instanceID); return value; } public static GiftBoxItem? GetGiftBoxFromUniqueID(string uniqueID) { try { if (string.IsNullOrEmpty(uniqueID)) { throw new ArgumentNullException("uniqueID"); } if (UniqueIDToInstance.TryGetValue(uniqueID, out var value)) { Object obj = Object.FindObjectFromInstanceID(value); return (GiftBoxItem?)(object)((obj is GiftBoxItem) ? obj : null); } } catch (Exception arg) { WeatherModifiersLoggerUtil.LogError($"Failed to retrieve gift box from unique id: {arg}"); } return null; } public static void Cleanup() { List<int> list = new List<int>(); foreach (KeyValuePair<int, string> item in InstanceToUniqueID) { Object val = Object.FindObjectFromInstanceID(item.Key); if (val == (Object)null) { list.Add(item.Key); } } foreach (int item2 in list) { GiftBoxWeatherDataManager.RemoveGiftBox(InstanceToUniqueID[item2]); UniqueIDToInstance.Remove(InstanceToUniqueID[item2]); InstanceToUniqueID.Remove(item2); WeatherModifiersLoggerUtil.LogInfo($"Removed obsolete mapping for GiftBoxItem instance ID {item2}."); } } } public static class GiftBoxWeatherDataManager { private static Dictionary<string, string> GiftBoxWeatherData { get; set; } = new Dictionary<string, string>(); public static void AddGiftBox(GiftBoxItem giftBox, LevelWeatherType? weatherType) { string text = "null"; if (weatherType.HasValue) { text = weatherType.ToString(); GiftBoxWeatherData.Add(GiftBoxTracker.GetOrCreateUniqueID(giftBox), text); WeatherModifiersLoggerUtil.LogInfoDebug("Added weather for gift box of unique id: " + GiftBoxTracker.GetOrCreateUniqueID(giftBox) + ", weather type: " + text); } else { GiftBoxWeatherData.Add(GiftBoxTracker.GetOrCreateUniqueID(giftBox), text); WeatherModifiersLoggerUtil.LogWarning("weatherType was null, adding null weather for gift box of unique id: " + GiftBoxTracker.GetOrCreateUniqueID(giftBox) + ", weather type: " + text); } } public static string GetGiftBoxWeather(GiftBoxItem giftBox) { string result = "null"; if (GiftBoxWeatherData.ContainsKey(GiftBoxTracker.GetOrCreateUniqueID(giftBox))) { WeatherModifiersLoggerUtil.LogInfoDebug("Found weather for gift box of unique id: " + GiftBoxTracker.GetOrCreateUniqueID(giftBox)); return GiftBoxWeatherData[GiftBoxTracker.GetOrCreateUniqueID(giftBox)]; } WeatherModifiersLoggerUtil.LogWarning("No weather found for gift box of unique id: " + GiftBoxTracker.GetOrCreateUniqueID(giftBox)); return result; } public static void SetGiftBoxWeather(GiftBoxItem giftBox, string weather) { GiftBoxWeatherData[GiftBoxTracker.GetOrCreateUniqueID(giftBox)] = weather; } public static KeyValuePair<string, string>? IsGiftBoxInWeatherData(GiftBoxItem giftBox) { if (GiftBoxWeatherData.ContainsKey(GiftBoxTracker.GetOrCreateUniqueID(giftBox))) { return new KeyValuePair<string, string>(GiftBoxTracker.GetOrCreateUniqueID(giftBox), GiftBoxWeatherData[GiftBoxTracker.GetOrCreateUniqueID(giftBox)]); } return null; } public static void RemoveGiftBox(string giftBoxID) { GiftBoxWeatherData.Remove(giftBoxID); } } } namespace WeatherModifiers.Data.Trackers { public static class GiftBoxItemTracker { public static void TrackGiftBox(GiftBoxItem giftBox, bool overrideExisting = false, LevelWeatherType? overrideWeather = null) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) string orCreateUniqueID = GiftBoxTracker.GetOrCreateUniqueID(giftBox); WeatherModifiersLoggerUtil.LogInfoDebug("GiftBoxItem " + ((Object)giftBox).name + " has been loaded with a unique ID of " + orCreateUniqueID + "."); WeatherModifiersLoggerUtil.LogInfoDebug($"GiftBoxItem {orCreateUniqueID} has been loaded with a weather of {TimeOfDay.Instance?.currentLevelWeather}."); LevelWeatherType? val = TimeOfDay.Instance?.currentLevelWeather; KeyValuePair<string, string>? keyValuePair = GiftBoxWeatherDataManager.IsGiftBoxInWeatherData(giftBox); LevelWeatherType value; if (overrideExisting) { if (overrideWeather.HasValue) { WeatherModifiersLoggerUtil.LogInfoDebug($"GiftBoxItem {orCreateUniqueID} has been force set in weatherDataManager with a weather of {overrideWeather}."); if (GiftBoxWeatherDataManager.IsGiftBoxInWeatherData(giftBox).HasValue) { value = overrideWeather.Value; GiftBoxWeatherDataManager.SetGiftBoxWeather(giftBox, ((object)(LevelWeatherType)(ref value)).ToString()); } else { GiftBoxWeatherDataManager.AddGiftBox(giftBox, overrideWeather); } return; } WeatherModifiersLoggerUtil.LogError("Override weather is null, this MUST be included when overriding, cannot override existing box. Defaulting to current weather. Which is likely wrong"); } if (keyValuePair.HasValue) { if ((keyValuePair.Value.Value == null || keyValuePair.Value.Value == "null") && val.HasValue) { WeatherModifiersLoggerUtil.LogInfoDebug($"GiftBoxItem {orCreateUniqueID} has been updated in weatherDataManager with a weather of {val.Value}."); value = val.Value; GiftBoxWeatherDataManager.SetGiftBoxWeather(giftBox, ((object)(LevelWeatherType)(ref value)).ToString()); } } else { WeatherModifiersLoggerUtil.LogInfoDebug($"GiftBoxItem {orCreateUniqueID} has been created in weatherDataManager with a weather of {val}."); KeyValuePair<string, string>? keyValuePair2 = GiftBoxWeatherDataManager.IsGiftBoxInWeatherData(giftBox); GiftBoxWeatherDataManager.AddGiftBox(giftBox, val); } } } public static class QuotaTracker { public static int TimesFulfilled { get; set; } } } namespace WeatherModifiers.Config { public class ModConfiguration : SyncedInstance<ModConfiguration> { public ConfigEntry<bool> ValueModifierEnabled; public ConfigEntry<bool> AmountModifierEnabled; public ConfigEntry<bool> PowerModifierEnabled; public ConfigEntry<bool> EarlyEnemySpawningEnabled; public ConfigEntry<bool> ApparatusLungValueModifierEnabled; public ConfigEntry<bool> RedLocustBeesEnabled; public ConfigEntry<bool> DebugLogsEnabled; public ConfigEntry<float> ProgressiveAdditionalValueModifier; public ConfigEntry<float> ProgressiveAdditionalAmountModifier; public ConfigEntry<float> ProgressiveAdditionalIndoorPowerBonus; public ConfigEntry<float> ProgressiveAdditionalOutdoorPowerBonus; public ConfigEntry<float> ProgressiveAdditionalMaxEnemyBonus; public ConfigEntry<float> ClearValueModifier; public ConfigEntry<float> ClearAmountModifier; public ConfigEntry<float> FogValueModifier; public ConfigEntry<float> FogAmountModifier; public ConfigEntry<float> RainValueModifier; public ConfigEntry<float> RainAmountModifier; public ConfigEntry<float> StormValueModifier; public ConfigEntry<float> StormAmountModifier; public ConfigEntry<float> FloodValueModifier; public ConfigEntry<float> FloodAmountModifier; public ConfigEntry<float> EclipsedValueModifier; public ConfigEntry<float> EclipsedAmountModifier; public ConfigEntry<bool> ClearProgressiveModifiersEnabled; public ConfigEntry<bool> FogProgressiveModifiersEnabled; public ConfigEntry<bool> RainProgressiveModifiersEnabled; public ConfigEntry<bool> StormProgressiveModifiersEnabled; public ConfigEntry<bool> FloodProgressiveModifiersEnabled; public ConfigEntry<bool> EclipsedProgressiveModifiersEnabled; public ConfigEntry<int> ClearIndoorPowerBonus; public ConfigEntry<int> ClearOutdoorPowerBonus; public ConfigEntry<int> FogIndoorPowerBonus; public ConfigEntry<int> FogOutdoorPowerBonus; public ConfigEntry<int> RainIndoorPowerBonus; public ConfigEntry<int> RainOutdoorPowerBonus; public ConfigEntry<int> StormIndoorPowerBonus; public ConfigEntry<int> StormOutdoorPowerBonus; public ConfigEntry<int> FloodIndoorPowerBonus; public ConfigEntry<int> FloodOutdoorPowerBonus; public ConfigEntry<int> EclipsedIndoorPowerBonus; public ConfigEntry<int> EclipsedOutdoorPowerBonus; public ConfigEntry<int> ClearMaxEnemyBonus; public ConfigEntry<int> FogMaxEnemyBonus; public ConfigEntry<int> RainMaxEnemyBonus; public ConfigEntry<int> StormMaxEnemyBonus; public ConfigEntry<int> FloodMaxEnemyBonus; public ConfigEntry<int> EclipsedMaxEnemyBonus; public ConfigEntry<bool> ClearEarlyEnemySpawning; public ConfigEntry<bool> FogEarlyEnemySpawning; public ConfigEntry<bool> RainEarlyEnemySpawning; public ConfigEntry<bool> StormEarlyEnemySpawning; public ConfigEntry<bool> FloodEarlyEnemySpawning; public ConfigEntry<bool> EclipsedEarlyEnemySpawning; public readonly Dictionary<LevelWeatherType, ConfigValueGroup> Modifiers; public ConfigFile ApplyConfig(ConfigFile config) { ValueModifierEnabled = config.Bind<bool>("Features", "Value Modifier Enabled", true, "Whether the scrap value is modified."); AmountModifierEnabled = config.Bind<bool>("Features", "Amount Modifier Enabled", true, "Whether the scrap amount is modified."); PowerModifierEnabled = config.Bind<bool>("Features", "Power Modifier Enabled", true, "Whether the amount of enemies that can be spawned is modified. Also affects the spawn chance and frequency."); EarlyEnemySpawningEnabled = config.Bind<bool>("Features", "Early Enemy Spawning Enabled", false, "If enabled, enemies will be able to spawn earlier in the day (hardcoded to 10:30am outside, 8:30am inside). NOTE: each weather also needs an early spawning flag enabled"); ApparatusLungValueModifierEnabled = config.Bind<bool>("Features", "Apparatus (Lung Prop) Modifier Enabled", true, "Whether the scrap value of the apparatus (lung prop) is modified."); RedLocustBeesEnabled = config.Bind<bool>("Features", "Circuit Bee Hive Modifier Enabled", true, "Whether the scrap value of the circuit bee hive is modified."); DebugLogsEnabled = config.Bind<bool>("Features", "Enable Debug Logs", !string.IsNullOrEmpty(""), "Should debug logs be enabled?"); ProgressiveAdditionalValueModifier = config.Bind<float>("Progressive Values", "Progressive Additional Scrap Value Modifier", 0.1f, "An increase to the scrap modifer which is added every quota"); ProgressiveAdditionalAmountModifier = config.Bind<float>("Progressive Values", "Progressive Additional Scrap Amount Modifier", 0.05f, "An increase to the scrap amount modifier which is added every quota"); ProgressiveAdditionalIndoorPowerBonus = config.Bind<float>("Progressive Values", "Progressive Additional Indoor Power Bonus", 0.334f, "An increase to the indoor power bonus which is added every quota, rounded down to the nearest whole number"); ProgressiveAdditionalOutdoorPowerBonus = config.Bind<float>("Progressive Values", "Progressive Additional Outdoor Power Bonus", 0.25f, "An increase to the outdoor power bonus which is added every quota, rounded down to the nearest whole number"); ProgressiveAdditionalMaxEnemyBonus = config.Bind<float>("Progressive Values", "Progressive Additional Max Enemy Bonus", 0.2f, "An increase to the max enemy bonus which is added every quota, rounded down to the nearest whole number"); ClearValueModifier = config.Bind<float>("Values", "Clear Weather Scrap Value Modifier", 1f, "The scrap value modifier for clear weather."); ClearAmountModifier = config.Bind<float>("Values", "Clear Weather Scrap Amount Modifier", 1f, "The scrap amount modifier for clear weather."); ClearIndoorPowerBonus = config.Bind<int>("Values", "Clear Weather Indoor Power Bonus", 0, "The power bonus for clear weather indoors."); ClearOutdoorPowerBonus = config.Bind<int>("Values", "Clear Weather Outdoor Power Bonus", 0, "The power bonus for clear weather outdoors."); ClearMaxEnemyBonus = config.Bind<int>("Values", "Clear Weather Max Enemy Bonus", 0, "The bonus applied to inidividual enemy limits, e.g. +x extra brackens/coilheads"); ClearEarlyEnemySpawning = config.Bind<bool>("Values", "Clear Weather Early Enemy Spawning", false, "Enable early enemy spawning for clear weather."); ClearProgressiveModifiersEnabled = config.Bind<bool>("Values", "Progressive Clear Weather Modifiers", true, "Enable progressive modifiers for clear weather."); FogValueModifier = config.Bind<float>("Values", "Fog Weather Scrap Value Modifier", 1.15f, "The scrap value modifier for fog weather."); FogAmountModifier = config.Bind<float>("Values", "Fog Weather Scrap Amount Modifier", 1f, "The scrap amount modifier for fog weather."); FogIndoorPowerBonus = config.Bind<int>("Values", "Fog Weather Indoor Power Bonus", 0, "The power bonus for fog weather indoors."); FogOutdoorPowerBonus = config.Bind<int>("Values", "Fog Weather Outdoor Power Bonus", 5, "The power bonus for fog weather outdoors."); FogMaxEnemyBonus = config.Bind<int>("Values", "Fog Weather Max Enemy Bonus", 1, "The bonus applied to inidividual enemy limits, e.g. +x extra brackens/coilheads"); FogEarlyEnemySpawning = config.Bind<bool>("Values", "Fog Weather Early Enemy Spawning", false, "Enable early enemy spawning for fog weather."); FogProgressiveModifiersEnabled = config.Bind<bool>("Values", "Progressive Fog Weather Modifiers", true, "Enable progressive modifiers for fog weather."); RainValueModifier = config.Bind<float>("Values", "Rain Weather Scrap Value Modifier", 1.2f, "The scrap value modifier for rain weather."); RainAmountModifier = config.Bind<float>("Values", "Rain Weather Scrap Amount Modifier", 1f, "The scrap amount modifier for rain weather."); RainIndoorPowerBonus = config.Bind<int>("Values", "Rain Weather Indoor Power Bonus", 5, "The power bonus for rain weather indoors."); RainOutdoorPowerBonus = config.Bind<int>("Values", "Rain Weather Outdoor Power Bonus", 2, "The power bonus for rain weather outdoors."); RainMaxEnemyBonus = config.Bind<int>("Values", "Rain Weather Max Enemy Bonus", 1, "The bonus applied to inidividual enemy limits, e.g. +x extra brackens/coilheads"); RainEarlyEnemySpawning = config.Bind<bool>("Values", "Rain Weather Early Enemy Spawning", true, "Enable early enemy spawning for rain weather."); RainProgressiveModifiersEnabled = config.Bind<bool>("Values", "Progressive Rain Weather Modifiers", true, "Enable progressive modifiers for rain weather."); StormValueModifier = config.Bind<float>("Values", "Storm Weather Scrap Value Modifier", 1.35f, "The scrap value modifier for storm weather."); StormAmountModifier = config.Bind<float>("Values", "Storm Weather Scrap Amount Modifier", 1.15f, "The scrap amount modifier for storm weather."); StormIndoorPowerBonus = config.Bind<int>("Values", "Storm Weather Indoor Power Bonus", 7, "The power bonus for storm weather indoors."); StormOutdoorPowerBonus = config.Bind<int>("Values", "Storm Weather Outdoor Power Bonus", 4, "The power bonus for storm weather outdoors."); StormMaxEnemyBonus = config.Bind<int>("Values", "Storm Weather Max Enemy Bonus", 3, "The bonus applied to inidividual enemy limits, e.g. +x extra brackens/coilheads"); StormEarlyEnemySpawning = config.Bind<bool>("Values", "Storm Weather Early Enemy Spawning", true, "Enable early enemy spawning for storm weather."); StormProgressiveModifiersEnabled = config.Bind<bool>("Values", "Progressive Storm Weather Modifiers", true, "Enable progressive modifiers for storm weather."); FloodValueModifier = config.Bind<float>("Values", "Flood Weather Scrap Value Modifier", 1.5f, "The scrap value modifier for flood weather."); FloodAmountModifier = config.Bind<float>("Values", "Flood Weather Scrap Amount Modifier", 1.2f, "The scrap amount modifier for flood weather."); FloodIndoorPowerBonus = config.Bind<int>("Values", "Flood Weather Indoor Power Bonus", 5, "The power bonus for flood weather indoors."); FloodOutdoorPowerBonus = config.Bind<int>("Values", "Flood Weather Outdoor Power Bonus", 3, "The power bonus for flood weather outdoors."); FloodMaxEnemyBonus = config.Bind<int>("Values", "Flood Weather Max Enemy Bonus", 2, "The bonus applied to inidividual enemy limits, e.g. +x extra brackens/coilheads"); FloodEarlyEnemySpawning = config.Bind<bool>("Values", "Flood Weather Early Enemy Spawning", true, "Enable early enemy spawning for flood weather."); FloodProgressiveModifiersEnabled = config.Bind<bool>("Values", "Progressive Flood Weather Modifiers", true, "Enable progressive modifiers for flood weather."); EclipsedValueModifier = config.Bind<float>("Values", "Eclipse Weather Scrap Value Modifier", 1.8f, "The scrap value modifier for eclipse weather."); EclipsedAmountModifier = config.Bind<float>("Values", "Eclipse Weather Scrap Amount Modifier", 1.35f, "The scrap amount modifier for eclipse weather."); EclipsedIndoorPowerBonus = config.Bind<int>("Values", "Eclipse Weather Indoor Power Bonus", 5, "The power bonus for eclipse weather indoors."); EclipsedOutdoorPowerBonus = config.Bind<int>("Values", "Eclipse Weather Outdoor Power Bonus", 5, "The power bonus for eclipse weather outdoors."); EclipsedMaxEnemyBonus = config.Bind<int>("Values", "Eclipsed Weather Max Enemy Bonus", 5, "The bonus applied to inidividual enemy limits, e.g. +x extra brackens/coilheads"); EclipsedEarlyEnemySpawning = config.Bind<bool>("Values", "Eclipse Weather Early Enemy Spawning", true, "Enable early enemy spawning for eclipse weather."); EclipsedProgressiveModifiersEnabled = config.Bind<bool>("Values", "Progressive Eclipse Weather Modifiers", true, "Enable progressive modifiers for eclipse weather."); return config; } public ModConfiguration(ConfigFile config) { InitInstance(this); config.SaveOnConfigSet = false; config = ApplyConfig(config); Modifiers = new Dictionary<LevelWeatherType, ConfigValueGroup> { { (LevelWeatherType)(-1), new ConfigValueGroup { ValueModifier = ClearValueModifier, AmountModifier = ClearAmountModifier, IndoorPowerBonus = ClearIndoorPowerBonus, OutdoorPowerBonus = ClearOutdoorPowerBonus, MaxEnemyCountBonus = ClearMaxEnemyBonus, IsEarlyEnemySpawning = ClearEarlyEnemySpawning, IsProgressiveModifiers = ClearProgressiveModifiersEnabled } }, { (LevelWeatherType)3, new ConfigValueGroup { ValueModifier = FogValueModifier, AmountModifier = FogAmountModifier, IndoorPowerBonus = FogIndoorPowerBonus, OutdoorPowerBonus = FogOutdoorPowerBonus, MaxEnemyCountBonus = FogMaxEnemyBonus, IsEarlyEnemySpawning = FogEarlyEnemySpawning, IsProgressiveModifiers = FogProgressiveModifiersEnabled } }, { (LevelWeatherType)1, new ConfigValueGroup { ValueModifier = RainValueModifier, AmountModifier = RainAmountModifier, IndoorPowerBonus = RainIndoorPowerBonus, OutdoorPowerBonus = RainOutdoorPowerBonus, MaxEnemyCountBonus = RainMaxEnemyBonus, IsEarlyEnemySpawning = RainEarlyEnemySpawning, IsProgressiveModifiers = RainProgressiveModifiersEnabled } }, { (LevelWeatherType)2, new ConfigValueGroup { ValueModifier = StormValueModifier, AmountModifier = StormAmountModifier, IndoorPowerBonus = StormIndoorPowerBonus, OutdoorPowerBonus = StormOutdoorPowerBonus, MaxEnemyCountBonus = StormMaxEnemyBonus, IsEarlyEnemySpawning = StormEarlyEnemySpawning, IsProgressiveModifiers = StormProgressiveModifiersEnabled } }, { (LevelWeatherType)4, new ConfigValueGroup { ValueModifier = FloodValueModifier, AmountModifier = FloodAmountModifier, IndoorPowerBonus = FloodIndoorPowerBonus, OutdoorPowerBonus = FloodOutdoorPowerBonus, MaxEnemyCountBonus = FloodMaxEnemyBonus, IsEarlyEnemySpawning = FloodEarlyEnemySpawning, IsProgressiveModifiers = FloodProgressiveModifiersEnabled } }, { (LevelWeatherType)5, new ConfigValueGroup { ValueModifier = EclipsedValueModifier, AmountModifier = EclipsedAmountModifier, IndoorPowerBonus = EclipsedIndoorPowerBonus, OutdoorPowerBonus = EclipsedOutdoorPowerBonus, MaxEnemyCountBonus = EclipsedMaxEnemyBonus, IsEarlyEnemySpawning = EclipsedEarlyEnemySpawning, IsProgressiveModifiers = EclipsedProgressiveModifiersEnabled } } }; ClearOrphanedEntries(config); config.Save(); config.SaveOnConfigSet = true; } public void RegisterModdedWeathers(ConfigFile config) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Invalid comparison between Unknown and I4 //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected I4, but got Unknown //IL_0203: Unknown result type (might be due to invalid IL or missing references) if (!Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry")) { return; } List<Weather> weathers = WeatherManager.Weathers; string text = string.Join(", ", weathers.Select((Weather w) => w.Name)); ConfigEntry<string> val = config.Bind<string>("General", "Detected Weathers", text, "A list of modded weathers detected by LethalWeatherRegistry on the last launch."); if (val.Value != text) { val.Value = text; } foreach (Weather item in weathers) { if ((int)item.Type == 2) { string text2 = $"Weather({(int)item.VanillaWeatherType}): {item.Name}"; ConfigValueGroup value = new ConfigValueGroup { ValueModifier = config.Bind<float>(text2, "Scrap Value Modifier", 1f, "Scrap value modifier for " + item.Name + "."), AmountModifier = config.Bind<float>(text2, "Scrap Amount Modifier", 1f, "Scrap amount modifier for " + item.Name + "."), IndoorPowerBonus = config.Bind<int>(text2, "Indoor Power Bonus", 0, "Indoor power bonus for " + item.Name + "."), OutdoorPowerBonus = config.Bind<int>(text2, "Outdoor Power Bonus", 0, "Outdoor power bonus for " + item.Name + "."), MaxEnemyCountBonus = config.Bind<int>(text2, "Max Enemy Bonus", 0, "Max Bonus enemies for " + item.Name + "."), IsEarlyEnemySpawning = config.Bind<bool>(text2, "Is Early Enemy Spawning", false, "Is early enemy spawning enabled for " + item.Name + "."), IsProgressiveModifiers = config.Bind<bool>(text2, "Progressive " + item.Name + " modifiers", true, "Is progressive modifiers enabled for " + item.Name + ".") }; Modifiers[item.VanillaWeatherType] = value; } } ClearOrphanedEntries(config); config.Save(); } private static void ClearOrphanedEntries(ConfigFile config) { ((Dictionary<ConfigDefinition, string>)AccessTools.Property(typeof(ConfigFile), "OrphanedEntries").GetValue(config)).Clear(); } } [Serializable] public class SyncedInstance<T> { [NonSerialized] protected static int IntSize = 4; internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager; internal static bool IsClient => NetworkManager.Singleton.IsClient; internal static bool IsHost => NetworkManager.Singleton.IsHost; public static T Default { get; private set; } public static T Instance { get; private set; } public static bool Synced { get; internal set; } protected void InitInstance(T instance) { Default = instance; Instance = instance; IntSize = 4; } internal static void SyncInstance(byte[] data) { Instance = DeserializeFromBytes(data); Synced = true; } internal static void RevertSync() { Instance = Default; Synced = false; } public static byte[] SerializeToBytes(T val) { BinaryFormatter binaryFormatter = new BinaryFormatter(); using MemoryStream memoryStream = new MemoryStream(); try { binaryFormatter.Serialize(memoryStream, val); return memoryStream.ToArray(); } catch (Exception arg) { WeatherModifiers.Logger.LogError((object)$"Error serializing instance: {arg}"); return null; } } public static T DeserializeFromBytes(byte[] data) { BinaryFormatter binaryFormatter = new BinaryFormatter(); using MemoryStream serializationStream = new MemoryStream(data); try { return (T)binaryFormatter.Deserialize(serializationStream); } catch (Exception arg) { WeatherModifiers.Logger.LogError((object)$"Error deserializing instance: {arg}"); return default(T); } } } }