using 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 Unity.Netcode;
using UnityEngine;
using WeatherModifiers.Config;
using WeatherModifiers.Data;
using WeatherModifiers.Data.Trackers;
using WeatherModifiers.Types;
[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.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+d9d1ff5db60d2111a4740c8f35afbae74fa195cc")]
[assembly: AssemblyProduct("Weather-Modifiers")]
[assembly: AssemblyTitle("net.aliphaticus.weathermodifiers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 = "";
}
[BepInPlugin("net.aliphaticus.weathermodifiers", "Weather-Modifiers", "1.1.1")]
[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;
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()
{
Logger = ((BaseUnityPlugin)this).Logger;
if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
{
InitializeLobbyCompatibility();
}
Instance = this;
BoundConfig = new ModConfiguration(((BaseUnityPlugin)this).Config);
Patch();
Logger.LogInfo((object)"net.aliphaticus.weathermodifiers v1.1.1 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.1.1"), (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!");
}
public static void RegisterPlugin(string guid, Version version, CompatibilityLevel compatibilityLevel, VersionStrictness versionStrictness)
{
}
}
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.1.1";
}
}
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; }
}
}
namespace WeatherModifiers.Patches.Scrap
{
[HarmonyPatch(typeof(LungProp))]
public class ApparatusScrapPatch
{
[HarmonyPatch("DisconnectFromMachinery")]
[HarmonyPrefix]
private static void DisconnectFromMachineryPrefix(LungProp __instance)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
if (WeatherModifiers.BoundConfig.ApparatusLungValueModifierEnabled.Value)
{
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
((GrabbableObject)__instance).SetScrapValue((int)((float)((GrabbableObject)__instance).scrapValue * value.ValueModifier.Value));
}
}
}
}
[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)
//IL_0085: 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;
}
if (val.HasValue && WeatherModifiers.BoundConfig.Modifiers.TryGetValue(val.Value, out ConfigValueGroup value))
{
try
{
float num = RoundManager.Instance.scrapValueMultiplier * value.ValueModifier.Value;
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) * num);
}
catch (Exception arg)
{
WeatherModifiersLoggerUtil.LogErrorDebug($"Error occured while calculating modified present value: {arg}");
}
}
}
return __instance.objectInPresentValue;
}
[HarmonyPatch("LoadItemSaveData")]
[HarmonyPostfix]
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]
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(RedLocustBees))]
public class RedLocustBeeHivePatch
{
[HarmonyPatch("SpawnHiveNearEnemy")]
[HarmonyPrefix]
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_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_015a: 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)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: 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));
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.RedLocustBeesEnabled.Value && WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value) && WeatherModifiers.BoundConfig.ValueModifierEnabled.Value)
{
num = Mathf.RoundToInt((float)num * value.ValueModifier.Value);
if (num < 1)
{
num = 1;
}
WeatherModifiersLoggerUtil.LogInfoDebug($"Modified Red Locust Bee Hive Scrap Value: {num}");
}
int num2 = num;
__instance.SpawnHiveClientRpc(NetworkObjectReference.op_Implicit(val.GetComponent<NetworkObject>()), num2, randomNavMeshPositionInBoxPredictable + Vector3.up * 0.2f);
return false;
}
return true;
}
}
[HarmonyPatch(typeof(RoundManager))]
public class ScrapPatch
{
[HarmonyPatch("SpawnScrapInLevel")]
[HarmonyPrefix]
private static void SpawnScrapInLevelPrefix()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
if (WeatherModifiers.BoundConfig.ValueModifierEnabled.Value)
{
RoundManager instance = RoundManager.Instance;
instance.scrapValueMultiplier *= value.ValueModifier.Value;
}
if (WeatherModifiers.BoundConfig.AmountModifierEnabled.Value)
{
RoundManager instance2 = RoundManager.Instance;
instance2.scrapAmountMultiplier *= value.AmountModifier.Value;
}
}
else
{
WeatherModifiersLoggerUtil.LogWarning($"No modifier found for weather {currentLevelWeather}.");
}
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]
private static void SpawnScrapInLevelPostfix()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
RoundManager instance = RoundManager.Instance;
instance.scrapValueMultiplier /= value.ValueModifier.Value;
RoundManager instance2 = RoundManager.Instance;
instance2.scrapAmountMultiplier /= value.AmountModifier.Value;
}
else
{
WeatherModifiersLoggerUtil.LogWarning($"No modifier found for weather {currentLevelWeather}.");
}
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]
private static void RefreshEnemiesListPostfix(RoundManager __instance)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
if (!((NetworkBehaviour)__instance).IsServer || (Object)(object)TimeOfDay.Instance == (Object)null)
{
return;
}
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (!WeatherModifiers.BoundConfig.PowerModifierEnabled.Value || !WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
return;
}
int value2 = value.MaxEnemyCountBonus.Value;
if (value2 <= 0)
{
return;
}
foreach (SpawnableEnemyWithRarity enemy in __instance.currentLevel.Enemies)
{
EnemyType enemyType = enemy.enemyType;
enemyType.MaxCount += value2;
}
foreach (SpawnableEnemyWithRarity outsideEnemy in __instance.currentLevel.OutsideEnemies)
{
EnemyType enemyType2 = outsideEnemy.enemyType;
enemyType2.MaxCount += value2;
}
WeatherModifiersLoggerUtil.LogInfoDebug($"Weather {currentLevelWeather} increased all enemy MaxCounts by {value2}.");
}
}
[HarmonyPatch(typeof(RoundManager))]
public class EnemyCurvePatch
{
[HarmonyPatch("RefreshEnemiesList")]
[HarmonyPostfix]
private static void RefreshEnemiesListPostfix(RoundManager __instance)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
if (((NetworkBehaviour)__instance).IsServer)
{
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.PowerModifierEnabled.Value && WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
AdjustCurveInside(__instance.currentLevel.enemySpawnChanceThroughoutDay, value.IndoorPowerBonus.Value);
AdjustCurveOutside(__instance.currentLevel.outsideEnemySpawnChanceThroughDay, value.OutdoorPowerBonus.Value);
}
}
}
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]
private static void RefreshEnemiesListPostfix(RoundManager __instance)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)TimeOfDay.Instance == (Object)null))
{
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.PowerModifierEnabled.Value && WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
__instance.hourTimeBetweenEnemySpawnBatches = 1;
float currentMaxInsidePower = __instance.currentMaxInsidePower;
float currentMaxOutsidePower = __instance.currentMaxOutsidePower;
__instance.currentMaxInsidePower += (float)value.IndoorPowerBonus.Value;
__instance.currentMaxOutsidePower += (float)value.OutdoorPowerBonus.Value;
WeatherModifiersLoggerUtil.LogInfoDebug($"Weather {currentLevelWeather} applied Power Bonuses: " + $"Indoor [{currentMaxInsidePower}+{value.IndoorPowerBonus.Value}={__instance.currentMaxInsidePower}], Outdoor [{currentMaxOutsidePower}+{value.OutdoorPowerBonus.Value}={__instance.currentMaxOutsidePower}]");
}
}
}
}
[HarmonyPatch(typeof(RoundManager))]
public class EnemySpawnTimingPatch
{
private 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()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
if (!WeatherModifiers.BoundConfig.EarlyEnemySpawningEnabled.Value)
{
return false;
}
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
return value.IsEarlyEnemySpawning.Value;
}
return 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]
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.");
}
}
[HarmonyPatch("PlotOutEnemiesForNextHour")]
[HarmonyPrefix]
private static void PlotOutEnemiesPrefix(RoundManager __instance)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
if (!((NetworkBehaviour)__instance).IsServer || !IsEarlySpawningEnabledForCurrentWeather())
{
return;
}
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
bool flag = IsEarlySpawningEnabledForCurrentWeather();
bool flag2 = value.IndoorPowerBonus.Value > 0;
if (flag || flag2)
{
if (__instance.timeScript.currentDayTime >= 150f)
{
__instance.minEnemiesToSpawn = Mathf.Max(1, (int)((float)value.IndoorPowerBonus.Value * 0.2f));
}
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;
__instance.hourTimeBetweenEnemySpawnBatches = 1;
}
[HarmonyPatch("PlotOutEnemiesForNextHour")]
[HarmonyPostfix]
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]
private static void SpawnEnemiesOutsidePrefix(RoundManager __instance)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
if (!((NetworkBehaviour)__instance).IsServer || !IsEarlySpawningEnabledForCurrentWeather())
{
return;
}
LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
if (WeatherModifiers.BoundConfig.Modifiers.TryGetValue(currentLevelWeather, out ConfigValueGroup value))
{
bool flag = IsEarlySpawningEnabledForCurrentWeather();
bool flag2 = value.OutdoorPowerBonus.Value > 0;
if (flag || flag2)
{
if (__instance.timeScript.currentDayTime >= 270f)
{
__instance.minOutsideEnemiesToSpawn = Mathf.Max(1, (int)((float)value.OutdoorPowerBonus.Value * 0.2f));
}
else
{
__instance.minOutsideEnemiesToSpawn = 0;
}
}
}
_originalDayTime = __instance.timeScript.currentDayTime;
__instance.timeScript.currentDayTime = GetModifiedNormalizedTime(__instance, 270f) * __instance.timeScript.totalTime;
}
[HarmonyPatch("SpawnEnemiesOutside")]
[HarmonyPostfix]
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);
}
}
}
}
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> 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<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?");
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.");
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.");
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.");
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.");
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.");
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.");
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
}
},
{
(LevelWeatherType)3,
new ConfigValueGroup
{
ValueModifier = FogValueModifier,
AmountModifier = FogAmountModifier,
IndoorPowerBonus = FogIndoorPowerBonus,
OutdoorPowerBonus = FogOutdoorPowerBonus,
MaxEnemyCountBonus = FogMaxEnemyBonus,
IsEarlyEnemySpawning = FogEarlyEnemySpawning
}
},
{
(LevelWeatherType)1,
new ConfigValueGroup
{
ValueModifier = RainValueModifier,
AmountModifier = RainAmountModifier,
IndoorPowerBonus = RainIndoorPowerBonus,
OutdoorPowerBonus = RainOutdoorPowerBonus,
MaxEnemyCountBonus = RainMaxEnemyBonus,
IsEarlyEnemySpawning = RainEarlyEnemySpawning
}
},
{
(LevelWeatherType)2,
new ConfigValueGroup
{
ValueModifier = StormValueModifier,
AmountModifier = StormAmountModifier,
IndoorPowerBonus = StormIndoorPowerBonus,
OutdoorPowerBonus = StormOutdoorPowerBonus,
MaxEnemyCountBonus = StormMaxEnemyBonus,
IsEarlyEnemySpawning = StormEarlyEnemySpawning
}
},
{
(LevelWeatherType)4,
new ConfigValueGroup
{
ValueModifier = FloodValueModifier,
AmountModifier = FloodAmountModifier,
IndoorPowerBonus = FloodIndoorPowerBonus,
OutdoorPowerBonus = FloodOutdoorPowerBonus,
MaxEnemyCountBonus = FloodMaxEnemyBonus,
IsEarlyEnemySpawning = FloodEarlyEnemySpawning
}
},
{
(LevelWeatherType)5,
new ConfigValueGroup
{
ValueModifier = EclipsedValueModifier,
AmountModifier = EclipsedAmountModifier,
IndoorPowerBonus = EclipsedIndoorPowerBonus,
OutdoorPowerBonus = EclipsedOutdoorPowerBonus,
MaxEnemyCountBonus = EclipsedMaxEnemyBonus,
IsEarlyEnemySpawning = EclipsedEarlyEnemySpawning
}
}
};
ClearOrphanedEntries(config);
config.Save();
config.SaveOnConfigSet = true;
}
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);
}
}
}
}