using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using InteriorHazardsPlus.Data;
using InteriorHazardsPlus.Patches;
using InteriorHazardsPlus.plugins;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.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;
}
}
}
public class RandomHazardManager
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static CanModifyDelegate <>9__11_0;
public static Func<KeyValuePair<string, Plugin.HazardSettings>, bool> <>9__19_0;
public static Func<KeyValuePair<string, Plugin.HazardSettings>, bool> <>9__19_1;
internal CanModifyResult <Initialize>b__11_0()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
return CanModifyResult.op_Implicit((false, "This value is controlled by Random Hazards"));
}
internal bool <RandomizeHazards>b__19_0(KeyValuePair<string, Plugin.HazardSettings> h)
{
return !Plugin.Instance.IsBearTrapVariant(h.Key);
}
internal bool <RandomizeHazards>b__19_1(KeyValuePair<string, Plugin.HazardSettings> h)
{
return Plugin.Instance.IsBearTrapVariant(h.Key);
}
}
private static RandomHazardManager? _instance;
private List<ConfigEntry<string>> selectedHazards = new List<ConfigEntry<string>>();
private ConfigEntry<bool> EnableRandomHazards = null;
private ConfigEntry<bool> ResetAllHazards = null;
private ConfigEntry<bool> EnableAllHazards = null;
private Dictionary<string, Dictionary<string, int>> randomizedSpawnCounts = new Dictionary<string, Dictionary<string, int>>();
private Dictionary<string, int> randomizedBerthaScales = new Dictionary<string, int>();
private Dictionary<string, HashSet<string>> lastUsedHazards = new Dictionary<string, HashSet<string>>();
private bool lastResetAllHazardsState = false;
private bool lastEnableAllHazardsState = false;
public static RandomHazardManager Instance
{
get
{
if (_instance == null)
{
_instance = new RandomHazardManager();
}
return _instance;
}
}
private RandomHazardManager()
{
}
public void Initialize(Plugin plugin, ConfigEntry<bool> enableRandomHazardsConfig)
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
EnableRandomHazards = enableRandomHazardsConfig;
for (int i = 1; i <= 5; i++)
{
ConfigEntry<string> item = ((BaseUnityPlugin)plugin).Config.Bind<string>("02. RANDOM HAZARDS", $"Selected Hazard {i}", "None", $"Randomly selected hazard #{i} (Read-only)");
selectedHazards.Add(item);
}
plugin.CheckForSurfacedAndRegisterConfig();
if (!LethalConfigProxy.Enabled)
{
return;
}
foreach (ConfigEntry<string> selectedHazard in selectedHazards)
{
TextInputFieldOptions val = new TextInputFieldOptions
{
RequiresRestart = false,
Name = ((ConfigEntryBase)selectedHazard).Definition.Key,
Section = ((ConfigEntryBase)selectedHazard).Definition.Section
};
object obj = <>c.<>9__11_0;
if (obj == null)
{
CanModifyDelegate val2 = () => CanModifyResult.op_Implicit((false, "This value is controlled by Random Hazards"));
<>c.<>9__11_0 = val2;
obj = (object)val2;
}
((BaseOptions)val).CanModifyCallback = (CanModifyDelegate)obj;
TextInputFieldOptions val3 = val;
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(selectedHazard, val3));
}
}
public void SetupResetAllWatcher(ConfigEntry<bool> resetAllHazardsConfig)
{
ResetAllHazards = resetAllHazardsConfig;
ResetAllHazards.SettingChanged += delegate
{
if (ResetAllHazards.Value)
{
ResetAllHazardsToDisabled();
StartCoroutineHelper(ResetCheckboxAfterDelay());
}
};
if (ResetAllHazards.Value)
{
ResetAllHazardsToDisabled();
ResetAllHazards.Value = false;
}
}
private void StartCoroutineHelper(IEnumerator routine)
{
if ((Object)(object)StartOfRound.Instance != (Object)null)
{
((MonoBehaviour)StartOfRound.Instance).StartCoroutine(routine);
return;
}
ResetAllHazards.Value = false;
Plugin.LogInfo("Reset All Hazards checkbox has been turned off (immediate)");
}
private IEnumerator ResetCheckboxAfterDelay()
{
yield return (object)new WaitForSeconds(0.5f);
ResetAllHazards.Value = false;
Plugin.LogInfo("Reset All Hazards checkbox has been turned off");
}
public void ResetAllHazardsToDisabled()
{
Plugin.LogInfo("Resetting all hazards to disabled...");
foreach (KeyValuePair<string, Dictionary<string, Plugin.HazardSettings>> item in Plugin.Instance.HazardSettingsDictionary)
{
string key = item.Key;
Dictionary<string, Plugin.HazardSettings> value = item.Value;
foreach (KeyValuePair<string, Plugin.HazardSettings> item2 in value)
{
string key2 = item2.Key;
Plugin.HazardSettings value2 = item2.Value;
if (value2.Enabled != null)
{
value2.Enabled.Value = false;
Plugin.LogInfo("Disabled hazard: " + key2 + " on " + key);
}
}
}
foreach (string item3 in randomizedSpawnCounts.Keys.ToList())
{
ClearRandomizedValuesForMoon(item3);
}
Plugin.LogInfo("All hazards have been reset to disabled");
}
public void EnableAllHazardsToEnabled()
{
Plugin.LogInfo("Enabling all hazards...");
foreach (KeyValuePair<string, Dictionary<string, Plugin.HazardSettings>> item in Plugin.Instance.HazardSettingsDictionary)
{
string key = item.Key;
Dictionary<string, Plugin.HazardSettings> value = item.Value;
foreach (KeyValuePair<string, Plugin.HazardSettings> item2 in value)
{
string key2 = item2.Key;
Plugin.HazardSettings value2 = item2.Value;
if (value2.Enabled != null)
{
value2.Enabled.Value = true;
Plugin.LogInfo("Enabled hazard: " + key2 + " on " + key);
}
}
}
if (IsEnabled())
{
StartOfRound instance = StartOfRound.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
SelectableLevel currentLevel = instance.currentLevel;
obj = ((currentLevel != null) ? ((Object)currentLevel).name : null);
}
if (obj == null)
{
obj = "";
}
string text = (string)obj;
if (!string.IsNullOrEmpty(text))
{
text = text.Replace("level", "", StringComparison.OrdinalIgnoreCase);
text = char.ToUpper(text[0]) + text.Substring(1).ToLower();
if (Plugin.Instance.HazardSettingsDictionary.TryGetValue(text, out Dictionary<string, Plugin.HazardSettings> value3))
{
Plugin.LogInfo("Re-randomizing hazards for " + text + " after enabling all hazards");
RandomizeHazards(value3);
}
}
}
Plugin.LogInfo("All hazards have been enabled");
}
public void SetupEnableAllWatcher(ConfigEntry<bool> enableAllHazardsConfig)
{
EnableAllHazards = enableAllHazardsConfig;
EnableAllHazards.SettingChanged += delegate
{
if (EnableAllHazards.Value)
{
EnableAllHazardsToEnabled();
StartCoroutineHelper(ResetEnableAllCheckboxAfterDelay());
}
};
if (EnableAllHazards.Value)
{
EnableAllHazardsToEnabled();
EnableAllHazards.Value = false;
}
}
private IEnumerator ResetEnableAllCheckboxAfterDelay()
{
yield return (object)new WaitForSeconds(0.5f);
EnableAllHazards.Value = false;
Plugin.LogInfo("Enable All Hazards checkbox has been turned off");
}
public void RandomizeHazards(Dictionary<string, Plugin.HazardSettings> settingsDict, List<string> availableBearTrapVariants = null)
{
Dictionary<string, Plugin.HazardSettings> settingsDict2 = settingsDict;
if (!EnableRandomHazards.Value)
{
Plugin.LogInfo("Random hazards disabled - Use Custom Hazards config values");
ClearSelectedHazards();
randomizedSpawnCounts.Clear();
return;
}
try
{
StartOfRound instance = StartOfRound.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
SelectableLevel currentLevel = instance.currentLevel;
obj = ((currentLevel != null) ? ((Object)currentLevel).name : null);
}
if (obj == null)
{
obj = "";
}
string currentMoon = (string)obj;
if (string.IsNullOrEmpty(currentMoon))
{
Plugin.LogError("Cannot determine current moon for randomization");
return;
}
currentMoon = currentMoon.Replace("level", "", StringComparison.OrdinalIgnoreCase);
currentMoon = char.ToUpper(currentMoon[0]) + currentMoon.Substring(1).ToLower();
if (!randomizedSpawnCounts.ContainsKey(currentMoon))
{
randomizedSpawnCounts[currentMoon] = new Dictionary<string, int>();
}
else
{
randomizedSpawnCounts[currentMoon].Clear();
}
List<KeyValuePair<string, Plugin.HazardSettings>> list = settingsDict2.ToList();
Plugin.LogInfo($"Found {list.Count} total hazards for randomization");
foreach (KeyValuePair<string, Plugin.HazardSettings> item5 in list)
{
Plugin.LogInfo($"Available hazard for randomization: {item5.Key} (IsBearTrap: {Plugin.Instance.IsBearTrapVariant(item5.Key)})");
}
List<KeyValuePair<string, Plugin.HazardSettings>> list2 = list.Where((KeyValuePair<string, Plugin.HazardSettings> h) => !Plugin.Instance.IsBearTrapVariant(h.Key)).ToList();
Plugin.LogInfo($"Found {list2.Count} non-bear trap hazards");
List<KeyValuePair<string, Plugin.HazardSettings>> list3 = list.Where((KeyValuePair<string, Plugin.HazardSettings> h) => Plugin.Instance.IsBearTrapVariant(h.Key)).ToList();
Plugin.LogInfo($"Found {list3.Count} bear trap variants in settings");
Random random = new Random();
string text = null;
if (availableBearTrapVariants != null && availableBearTrapVariants.Count > 0)
{
List<string> list4 = availableBearTrapVariants.Where((string v) => settingsDict2.ContainsKey(v)).ToList();
Plugin.LogInfo($"Found {list4.Count} enabled bear trap variants from scene");
if (list4.Count > 0)
{
int index = random.Next(list4.Count);
text = list4[index];
Plugin.LogInfo("Selected bear trap variant from scene: " + text);
}
else if (list3.Count > 0)
{
int index2 = random.Next(list3.Count);
text = list3[index2].Key;
Plugin.LogInfo("Selected bear trap variant from settings: " + text);
}
}
else if (list3.Count > 0)
{
int index3 = random.Next(list3.Count);
text = list3[index3].Key;
Plugin.LogInfo("Selected bear trap variant from settings (no scene variants): " + text);
}
List<KeyValuePair<string, Plugin.HazardSettings>> list5 = new List<KeyValuePair<string, Plugin.HazardSettings>>(list2);
if (text != null && settingsDict2.ContainsKey(text))
{
list5.Add(new KeyValuePair<string, Plugin.HazardSettings>(text, settingsDict2[text]));
Plugin.LogInfo("Added " + text + " to consolidated hazards list");
}
else if (text != null)
{
Plugin.LogError("Selected bear trap variant " + text + " not found in settings dictionary");
}
int count = list5.Count;
Plugin.LogInfo($"Consolidated hazards count: {count}");
if (count <= 5)
{
Plugin.LogInfo($"Only {count} hazards detected - randomizing hazards and their spawn counts");
ClearSelectedHazards();
foreach (KeyValuePair<string, Plugin.HazardSettings> item6 in list5)
{
string key = item6.Key;
Plugin.HazardSettings value = item6.Value;
(int, int) hazardSpawnLimits = Plugin.Instance.GetHazardSpawnLimits(key);
int item = hazardSpawnLimits.Item1;
int item2 = hazardSpawnLimits.Item2;
int num = random.Next(1, item2 + 1);
randomizedSpawnCounts[currentMoon][key] = num;
string displayName = Plugin.Instance.GetDisplayName(key);
Plugin.LogInfo($"Randomized spawn count for {displayName} to {num}");
int num2 = list5.IndexOf(item6);
if (num2 < 5)
{
selectedHazards[num2].Value = $"{displayName} (Spawn Count: {num})";
}
}
}
else
{
Plugin.LogInfo($"{count} hazards detected - randomizing hazard selection");
if (!lastUsedHazards.ContainsKey(currentMoon))
{
lastUsedHazards[currentMoon] = new HashSet<string>();
}
List<KeyValuePair<string, Plugin.HazardSettings>> list6 = list5.Where((KeyValuePair<string, Plugin.HazardSettings> h) => !lastUsedHazards[currentMoon].Contains(h.Key)).ToList();
List<KeyValuePair<string, Plugin.HazardSettings>> list7 = list5.Where((KeyValuePair<string, Plugin.HazardSettings> h) => lastUsedHazards[currentMoon].Contains(h.Key)).ToList();
Plugin.LogInfo($"Unused hazards: {list6.Count}, Used hazards: {list7.Count}");
ShuffleList(list6, random);
ShuffleList(list7, random);
List<KeyValuePair<string, Plugin.HazardSettings>> list8 = list6.Concat(list7).ToList();
Plugin.LogInfo("Prioritized hazards order:");
for (int i = 0; i < Math.Min(10, list8.Count); i++)
{
Plugin.LogInfo($"{i + 1}. {list8[i].Key}");
}
lastUsedHazards[currentMoon].Clear();
for (int j = 0; j < list8.Count; j++)
{
KeyValuePair<string, Plugin.HazardSettings> keyValuePair = list8[j];
if (j < 5)
{
(int, int) hazardSpawnLimits2 = Plugin.Instance.GetHazardSpawnLimits(keyValuePair.Key);
int item3 = hazardSpawnLimits2.Item1;
int item4 = hazardSpawnLimits2.Item2;
int num3 = random.Next(1, item4 + 1);
randomizedSpawnCounts[currentMoon][keyValuePair.Key] = num3;
lastUsedHazards[currentMoon].Add(keyValuePair.Key);
string displayName2 = Plugin.Instance.GetDisplayName(keyValuePair.Key);
selectedHazards[j].Value = $"{displayName2} (Spawn Count: {num3})";
Plugin.LogInfo($"Randomly enabled hazard {displayName2} with spawn count: {num3}");
}
}
for (int k = Math.Min(5, list8.Count); k < 5; k++)
{
selectedHazards[k].Value = "None";
}
Plugin.LogInfo("Final selected hazards:");
foreach (KeyValuePair<string, int> item7 in randomizedSpawnCounts[currentMoon])
{
Plugin.LogInfo($"Selected: {item7.Key} with count {item7.Value}");
}
}
if (randomizedSpawnCounts.ContainsKey(currentMoon) && randomizedSpawnCounts[currentMoon].ContainsKey("Bertha"))
{
int spawnCount = randomizedSpawnCounts[currentMoon]["Bertha"];
int scaleValue = CalculateBerthaScaleValueForSpawnCount(spawnCount);
SetRandomizedBerthaScale(currentMoon, scaleValue);
}
else
{
SetRandomizedBerthaScale(currentMoon, 5);
}
}
catch (Exception ex)
{
Plugin.LogError("Error in RandomizeHazards: " + ex.Message);
Plugin.LogError("Stack trace: " + ex.StackTrace);
ClearSelectedHazards();
}
}
public int CalculateBerthaScaleValueForSpawnCount(int spawnCount)
{
if (spawnCount >= 10)
{
return 1;
}
float num = (float)(spawnCount - 1) / 9f;
return 10 - (int)Math.Round(num * 9f);
}
public float ScaleValueToPercentage(int scaleValue)
{
return 63f + (float)(scaleValue - 1) * 4.111111f;
}
public void SetRandomizedBerthaScale(string moonName, int scaleValue)
{
randomizedBerthaScales[moonName] = scaleValue;
float num = ScaleValueToPercentage(scaleValue);
Plugin.LogInfo($"Set randomized Bertha scale for {moonName} to {scaleValue} ({num:F1}%)");
}
public int GetRandomizedBerthaScale(string moonName, int defaultValue = 5)
{
if (randomizedBerthaScales.TryGetValue(moonName, out var value))
{
return value;
}
return defaultValue;
}
public void ClearRandomizedBerthaScale(string moonName)
{
if (randomizedBerthaScales.ContainsKey(moonName))
{
randomizedBerthaScales.Remove(moonName);
}
}
private void ShuffleList<T>(List<T> list, Random random)
{
int num = list.Count;
while (num > 1)
{
num--;
int index = random.Next(num + 1);
T value = list[index];
list[index] = list[num];
list[num] = value;
}
}
private void ClearSelectedHazards()
{
foreach (ConfigEntry<string> selectedHazard in selectedHazards)
{
selectedHazard.Value = "None";
}
}
public bool IsEnabled()
{
return EnableRandomHazards?.Value ?? false;
}
public int GetRandomizedSpawnCount(string moonName, string hazardType, int defaultValue)
{
if (!IsEnabled() || !randomizedSpawnCounts.ContainsKey(moonName) || !randomizedSpawnCounts[moonName].ContainsKey(hazardType))
{
return defaultValue;
}
return randomizedSpawnCounts[moonName][hazardType];
}
public bool ShouldHazardBeEnabled(string moonName, string hazardType)
{
if (!IsEnabled() || !randomizedSpawnCounts.ContainsKey(moonName))
{
return true;
}
return randomizedSpawnCounts[moonName].ContainsKey(hazardType);
}
public bool HasRandomizedValues(string moonName)
{
return randomizedSpawnCounts.ContainsKey(moonName) && randomizedSpawnCounts[moonName].Count > 0;
}
public void ClearRandomizedValuesForMoon(string moonName)
{
if (randomizedSpawnCounts.ContainsKey(moonName))
{
randomizedSpawnCounts[moonName].Clear();
Plugin.LogInfo("Cleared randomized hazard values for " + moonName);
}
ClearRandomizedBerthaScale(moonName);
}
public void Update()
{
if (ResetAllHazards == null)
{
return;
}
if (ResetAllHazards.Value && !lastResetAllHazardsState)
{
Plugin.LogInfo("Reset All Hazards triggered via config value check");
ResetAllHazardsToDisabled();
ResetAllHazards.Value = false;
}
lastResetAllHazardsState = ResetAllHazards.Value;
if (EnableAllHazards != null && EnableAllHazards.Value && !lastEnableAllHazardsState)
{
Plugin.LogInfo("Enable All Hazards triggered via config value check");
EnableAllHazardsToEnabled();
EnableAllHazards.Value = false;
}
lastEnableAllHazardsState = EnableAllHazards?.Value ?? false;
if (!LethalConfigProxy.Enabled)
{
return;
}
try
{
MethodInfo method = typeof(LethalConfigManager).GetMethod("OnConfigChanged", BindingFlags.Static | BindingFlags.Public);
if (method != null)
{
method.Invoke(null, new object[2]);
Plugin.LogInfo("LethalConfig display refreshed");
}
else
{
Plugin.LogWarning("Could not find method to refresh LethalConfig display");
}
}
catch (Exception ex)
{
Plugin.LogError("Error refreshing LethalConfig display: " + ex.Message);
}
}
}
namespace InteriorHazardsPlus.Strategy
{
public enum CombinedSpawnOption
{
MainEntranceOnly,
FireExitsOnly,
Both
}
internal class CombinedEntranceSpawnStrategy : SpawnStrategy
{
public CombinedSpawnOption Option { get; private set; }
private CombinedEntranceSpawnStrategy(CombinedSpawnOption option)
{
Option = option;
}
public CombinedEntranceSpawnStrategy()
{
}
public static CombinedEntranceSpawnStrategy GetInstance(CombinedSpawnOption option)
{
return new CombinedEntranceSpawnStrategy(option);
}
public override List<SpawnPositionData> CalculateCenterPositions(Vector3 shipLandPosition, Vector3 mainEntrancePosition, List<Vector3> fireExitPositions, float spawnRadiusMultiplier)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: 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_0049: 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)
//IL_0053: 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_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
List<SpawnPositionData> list = new List<SpawnPositionData>();
switch (Option)
{
case CombinedSpawnOption.MainEntranceOnly:
list.Add(CalculateCenterWithSpawnRadius(shipLandPosition, mainEntrancePosition, spawnRadiusMultiplier));
break;
case CombinedSpawnOption.FireExitsOnly:
foreach (Vector3 fireExitPosition in fireExitPositions)
{
list.Add(CalculateCenterWithSpawnRadius(shipLandPosition, fireExitPosition, spawnRadiusMultiplier));
}
break;
case CombinedSpawnOption.Both:
list.Add(CalculateCenterWithSpawnRadius(shipLandPosition, mainEntrancePosition, spawnRadiusMultiplier));
foreach (Vector3 fireExitPosition2 in fireExitPositions)
{
list.Add(CalculateCenterWithSpawnRadius(shipLandPosition, fireExitPosition2, spawnRadiusMultiplier));
}
break;
}
return list;
}
}
public abstract class SpawnStrategy
{
public abstract List<SpawnPositionData> CalculateCenterPositions(Vector3 shipLandPosition, Vector3 mainEntrancePosition, List<Vector3> fireExitPositions, float spawnRadiusMultiplier);
protected SpawnPositionData CalculateCenterWithSpawnRadius(Vector3 shipLandPosition, Vector3 targetPosition, float spawnRadiusMultiplier)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
Vector3 centerPosition = Vector3.Lerp(shipLandPosition, targetPosition, 0.5f);
float num = Vector3.Distance(shipLandPosition, targetPosition);
float spawnRadius = num * spawnRadiusMultiplier;
return new SpawnPositionData(centerPosition, spawnRadius);
}
}
}
namespace InteriorHazardsPlus.Patches
{
[HarmonyPatch]
internal class BearTrapDamagePatch
{
[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
private static class DamagePlayerPatch
{
private static bool Prepare()
{
return Chainloader.PluginInfos.ContainsKey("CodeRebirth");
}
private static bool Prefix(PlayerControllerB __instance, ref int damageNumber, bool callRPC, CauseOfDeath causeOfDeath)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Invalid comparison between Unknown and I4
if ((Object)(object)__instance == (Object)(object)_currentPlayer && damageNumber == 25 && (int)causeOfDeath == 8)
{
damageNumber = 10;
Plugin.LogInfo("Changed bear trap damage from 25 to 10");
}
return true;
}
}
private static PlayerControllerB? _currentPlayer;
private static bool Prepare()
{
return Chainloader.PluginInfos.ContainsKey("CodeRebirth");
}
public static void PatchBearTrapIfAvailable(Harmony harmony)
{
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
if (!Chainloader.PluginInfos.ContainsKey("CodeRebirth"))
{
return;
}
try
{
Type type = Type.GetType("CodeRebirth.src.Content.Maps.BearTrap, CodeRebirth");
if (type == null)
{
Plugin.LogWarning("Could not find CodeRebirth.src.Content.Maps.BearTrap type");
return;
}
MethodInfo method = type.GetMethod("TriggerTrap", new Type[1] { typeof(PlayerControllerB) });
if (method == null)
{
Plugin.LogWarning("Could not find TriggerTrap method on BearTrap");
return;
}
HarmonyMethod val = new HarmonyMethod(typeof(BearTrapDamagePatch).GetMethod("TriggerTrapPrefix", BindingFlags.Static | BindingFlags.NonPublic));
harmony.Patch((MethodBase)method, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogInfo("Successfully patched BearTrap.TriggerTrap method");
}
catch (Exception ex)
{
Plugin.LogError("Error patching BearTrap: " + ex.Message);
}
}
private static void TriggerTrapPrefix(ref PlayerControllerB player)
{
_currentPlayer = player;
}
}
public static class CodeRebirthAssetAccess
{
private static GameObject? gravelBearTrapPrefab;
private static GameObject? grassBearTrapPrefab;
private static GameObject? snowBearTrapPrefab;
private static GameObject? boomBearTrapPrefab;
private static bool initialized;
public static void Initialize()
{
if (initialized)
{
return;
}
try
{
if (!Chainloader.PluginInfos.ContainsKey("CodeRebirth"))
{
Plugin.LogInfo("CodeRebirth mod not detected, skipping asset access initialization");
return;
}
Plugin.LogInfo("Initializing CodeRebirth asset access...");
Type type = Type.GetType("CodeRebirth.src.Util.ContentHandler`1[[CodeRebirth.src.Util.MapObjectHandler, CodeRebirth]], CodeRebirth");
if (type == null)
{
return;
}
PropertyInfo property = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public);
if (property == null)
{
Plugin.LogError("Could not find Instance property");
return;
}
object value = property.GetValue(null);
if (value == null)
{
return;
}
PropertyInfo property2 = type.GetProperty("BearTrap");
if (property2 == null)
{
Plugin.LogError("Could not find BearTrap property");
return;
}
object value2 = property2.GetValue(value);
if (value2 == null)
{
Plugin.LogError("BearTrap handler is null");
return;
}
Type type2 = value2.GetType();
FieldInfo field = type2.GetField("GravelMatPrefab", BindingFlags.Instance | BindingFlags.Public);
if (field != null)
{
object value3 = field.GetValue(value2);
if (value3 != null)
{
gravelBearTrapPrefab = (GameObject?)((value3 is GameObject) ? value3 : null);
}
}
FieldInfo field2 = type2.GetField("GrassMatPrefab", BindingFlags.Instance | BindingFlags.Public);
if (field2 != null)
{
object value4 = field2.GetValue(value2);
if (value4 != null)
{
grassBearTrapPrefab = (GameObject?)((value4 is GameObject) ? value4 : null);
}
}
FieldInfo field3 = type2.GetField("SnowMatPrefab", BindingFlags.Instance | BindingFlags.Public);
if (field3 != null)
{
object value5 = field3.GetValue(value2);
if (value5 != null)
{
snowBearTrapPrefab = (GameObject?)((value5 is GameObject) ? value5 : null);
}
}
FieldInfo field4 = type2.GetField("BoomTrapPrefab", BindingFlags.Instance | BindingFlags.Public);
if (field4 != null)
{
object value6 = field4.GetValue(value2);
if (value6 != null)
{
boomBearTrapPrefab = (GameObject?)((value6 is GameObject) ? value6 : null);
}
}
Plugin.LogInfo("Gravel bear trap prefab: " + (((Object)(object)gravelBearTrapPrefab != (Object)null) ? ((Object)gravelBearTrapPrefab).name : "null"));
Plugin.LogInfo("Grass bear trap prefab: " + (((Object)(object)grassBearTrapPrefab != (Object)null) ? ((Object)grassBearTrapPrefab).name : "null"));
Plugin.LogInfo("Snow bear trap prefab: " + (((Object)(object)snowBearTrapPrefab != (Object)null) ? ((Object)snowBearTrapPrefab).name : "null"));
Plugin.LogInfo("Boom bear trap prefab: " + (((Object)(object)boomBearTrapPrefab != (Object)null) ? ((Object)boomBearTrapPrefab).name : "null"));
initialized = true;
Plugin.LogInfo("CodeRebirth asset access initialized successfully");
}
catch (Exception ex)
{
Plugin.LogError("Error initializing CodeRebirth asset access: " + ex.Message);
}
}
public static GameObject? GetBearTrapPrefab(string type)
{
if (!initialized)
{
Initialize();
}
if (1 == 0)
{
}
GameObject result = (GameObject)(type switch
{
"GravelBearTrap" => gravelBearTrapPrefab,
"GrassBearTrap" => grassBearTrapPrefab,
"SnowBearTrap" => snowBearTrapPrefab,
"BoomBearTrap" => boomBearTrapPrefab,
_ => gravelBearTrapPrefab,
});
if (1 == 0)
{
}
return result;
}
public static bool IsBearTrapPrefabAvailable(string type)
{
if (!initialized)
{
Initialize();
}
if (1 == 0)
{
}
bool result = type switch
{
"GravelBearTrap" => (Object)(object)gravelBearTrapPrefab != (Object)null,
"GrassBearTrap" => (Object)(object)grassBearTrapPrefab != (Object)null,
"SnowBearTrap" => (Object)(object)snowBearTrapPrefab != (Object)null,
"BoomBearTrap" => (Object)(object)boomBearTrapPrefab != (Object)null,
_ => false,
};
if (1 == 0)
{
}
return result;
}
}
[HarmonyPatch]
public class CodeRebirthOverridePatch
{
[HarmonyPatch]
private static class BearTrapStartPatch
{
private static bool Prepare()
{
return Chainloader.PluginInfos.ContainsKey("CodeRebirth");
}
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
Type type = Type.GetType("CodeRebirth.src.Content.Maps.BearTrap, CodeRebirth");
if (type == null)
{
Plugin.LogError("Could not find CodeRebirth.src.Content.Maps.BearTrap type");
return null;
}
MethodInfo method = type.GetMethod("Start", BindingFlags.Instance | BindingFlags.Public);
if (method == null)
{
Plugin.LogError("Could not find Start method on BearTrap");
return null;
}
return method;
}
[HarmonyPrefix]
private static bool Prefix(object __instance)
{
try
{
Type type = __instance.GetType();
FieldInfo field = type.GetField("byProduct");
if (field != null)
{
field.SetValue(__instance, true);
Plugin.LogInfo("Disabled CodeRebirth bear trap auto-spawning");
}
return false;
}
catch (Exception ex)
{
Plugin.LogError("Error in BearTrapStartPatch: " + ex.Message);
return true;
}
}
}
[HarmonyPatch(typeof(RoundManager), "SpawnMapObjects")]
private static class SpawnMapObjectsPatch
{
private static bool Prepare()
{
return Chainloader.PluginInfos.ContainsKey("CodeRebirth");
}
[HarmonyPostfix]
private static void Postfix(RoundManager __instance)
{
try
{
Type type = Type.GetType("CodeRebirth.src.Content.Maps.BearTrap, CodeRebirth");
if (type == null)
{
Plugin.LogInfo("CodeRebirth BearTrap type not found, skipping SpawnMapObjectsPostfix");
return;
}
Object[] array = Object.FindObjectsOfType(type);
Plugin.LogInfo($"Found {array.Length} CodeRebirth bear traps in the scene");
Object[] array2 = array;
foreach (Object val in array2)
{
FieldInfo field = type.GetField("byProduct");
if (field != null)
{
field.SetValue(val, true);
Plugin.LogInfo("Marked bear trap " + val.name + " as byProduct");
}
}
}
catch (Exception ex)
{
Plugin.LogError("Error in SpawnMapObjectsPostfix: " + ex.Message);
}
}
}
private static bool Prepare()
{
return Chainloader.PluginInfos.ContainsKey("CodeRebirth");
}
}
[HarmonyPatch]
internal class MapHazardPatch
{
public static void PatchHazards(Harmony harmony)
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Expected O, but got Unknown
try
{
Plugin.LogInfo("Starting hazard patching process");
List<Type> list = new List<Type>();
TryAddVanillaHazards(list);
TryAddModHazards(list);
foreach (Type item in list)
{
try
{
MethodInfo method = item.GetMethod("OnTriggerEnter");
if (method != null)
{
harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(MapHazardPatch).GetMethod("HazardTriggerPrefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogInfo("Patched OnTriggerEnter for " + item.Name);
}
MethodInfo method2 = item.GetMethod("OnTriggerStay");
if (method2 != null)
{
harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(MapHazardPatch).GetMethod("HazardTriggerPrefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.LogInfo("Patched OnTriggerStay for " + item.Name);
}
}
catch (Exception ex)
{
Plugin.LogError("Error patching methods for " + item.Name + ": " + ex.Message);
}
}
Plugin.LogInfo($"Finished patching {list.Count} hazard types");
}
catch (Exception arg)
{
Plugin.LogError($"Critical error in PatchHazards: {arg}");
}
}
private static void TryAddVanillaHazards(List<Type> hazardTypes)
{
try
{
Plugin.LogInfo("Attempting to add vanilla hazards");
Type type = FindVanillaType("Landmine");
if (type != null)
{
hazardTypes.Add(type);
}
Type type2 = FindVanillaType("Turret");
if (type2 != null)
{
hazardTypes.Add(type2);
}
Type type3 = FindVanillaType("SpikeRoofTrap");
if (type3 != null)
{
hazardTypes.Add(type3);
}
Plugin.LogInfo($"Added {hazardTypes.Count} vanilla hazard types");
}
catch (Exception ex)
{
Plugin.LogError("Error adding vanilla hazards: " + ex.Message);
}
}
private static Type FindVanillaType(string typeName)
{
try
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (!(assembly.GetName().Name == "Assembly-CSharp"))
{
continue;
}
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (type.Name == typeName)
{
Plugin.LogInfo("Found vanilla hazard type: " + type.FullName);
return type;
}
}
}
Assembly[] assemblies2 = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly2 in assemblies2)
{
try
{
Type[] types2 = assembly2.GetTypes();
foreach (Type type2 in types2)
{
if (type2.Name == typeName)
{
Plugin.LogInfo("Found hazard type in assembly " + assembly2.GetName().Name + ": " + type2.FullName);
return type2;
}
}
}
catch (ReflectionTypeLoadException)
{
}
}
Plugin.LogWarning("Could not find hazard type: " + typeName);
return null;
}
catch (Exception ex2)
{
Plugin.LogError("Error finding type " + typeName + ": " + ex2.Message);
return null;
}
}
private static void TryAddModHazards(List<Type> hazardTypes)
{
if (Chainloader.PluginInfos.ContainsKey("CodeRebirth"))
{
try
{
Plugin.LogInfo("CodeRebirth mod is loaded, attempting to add its hazards");
TryAddHazardType(hazardTypes, "LaserTurret", "CodeRebirth.src.Content.Maps");
TryAddHazardType(hazardTypes, "BugZapper", "CodeRebirth.src.Content.Maps");
TryAddHazardType(hazardTypes, "IndustrialFan", "CodeRebirth.src.Content.Maps");
TryAddHazardType(hazardTypes, "FunctionalMicrowave", "CodeRebirth.src.Content.Maps");
TryAddHazardType(hazardTypes, "FlashTurretUpdated", "CodeRebirth.src.Content.Maps");
}
catch (Exception ex)
{
Plugin.LogError("Error adding CodeRebirth hazards: " + ex.Message);
}
}
else
{
Plugin.LogInfo("CodeRebirth mod is not loaded, skipping its hazards");
}
if (Chainloader.PluginInfos.ContainsKey("evaisa.lethalthings"))
{
try
{
Plugin.LogInfo("LethalThings mod is loaded, attempting to add its hazards");
TryAddHazardType(hazardTypes, "TeleporterTrap", "LethalThings.MonoBehaviours");
}
catch (Exception ex2)
{
Plugin.LogError("Error adding LethalThings hazards: " + ex2.Message);
}
}
else
{
Plugin.LogInfo("LethalThings mod is not loaded, skipping its hazards");
}
if (Chainloader.PluginInfos.ContainsKey("Surfaced"))
{
try
{
Plugin.LogInfo("Surfaced mod is loaded, attempting to add its hazards");
TryAddHazardType(hazardTypes, "Bertha", "Surfaced");
TryAddHazardType(hazardTypes, "Seamine", "Surfaced");
}
catch (Exception ex3)
{
Plugin.LogError("Error adding Surfaced hazards: " + ex3.Message);
}
}
else
{
Plugin.LogInfo("Surfaced mod is not loaded, skipping its hazards");
}
if (Chainloader.PluginInfos.ContainsKey("TestAccountVarity") || Chainloader.PluginInfos.ContainsKey("TestAccount666.TestAccountVariety"))
{
try
{
Plugin.LogInfo("TestAccountVariety mod is loaded, attempting to add its hazards");
TryAddHazardType(hazardTypes, "PrefabAcidSpitter", "TestAccountVariety.Hazards.AcidSpitter");
TryAddHazardType(hazardTypes, "Yeetmine", "TestAccountVariety.Hazards.Yeetmine");
TryAddHazardType(hazardTypes, "CageTrap", "TestAccountVariety.Hazards.CageTrap");
}
catch (Exception ex4)
{
Plugin.LogError("Error adding TestAccountCore hazards: " + ex4.Message);
}
}
else
{
Plugin.LogInfo("TestAccountCore mod is not loaded, skipping its hazards");
}
if (Chainloader.PluginInfos.ContainsKey("TestAccountCore") || Chainloader.PluginInfos.ContainsKey("TestAccount666.TestAccountCore"))
{
try
{
Plugin.LogInfo("TestAccountCore mod is loaded, attempting to add its hazards");
TryAddHazardType(hazardTypes, "PrefabAcidSpitter", "TestAccountCore.Hazards.AcidSpitter");
TryAddHazardType(hazardTypes, "Yeetmine", "TestAccountCore.Hazards.Yeetmine");
TryAddHazardType(hazardTypes, "CageTrap", "TestAccountCore.Hazards.CageTrap");
return;
}
catch (Exception ex5)
{
Plugin.LogError("Error adding TestAccountCore hazards: " + ex5.Message);
return;
}
}
Plugin.LogInfo("TestAccountCore mod is not loaded, skipping its hazards");
}
private static bool TryAddHazardType(List<Type> hazardTypes, string primaryTypeName, string primaryNamespace, string alternativeTypeName = null, string alternativeNamespace = null)
{
try
{
string fullTypeName = primaryNamespace + "." + primaryTypeName;
Type type = FindTypeInAssemblies(fullTypeName, primaryTypeName);
if (type == null && alternativeTypeName != null)
{
string fullTypeName2 = alternativeNamespace + "." + alternativeTypeName;
type = FindTypeInAssemblies(fullTypeName2, alternativeTypeName);
if (type != null)
{
Plugin.LogInfo("Primary hazard " + primaryTypeName + " not found, using alternative " + alternativeTypeName + " instead");
}
}
if (type != null)
{
hazardTypes.Add(type);
Plugin.LogInfo("Added hazard type: " + type.FullName);
return true;
}
Plugin.LogWarning("Could not find hazard type: " + primaryTypeName + " or its alternative");
return false;
}
catch (Exception ex)
{
Plugin.LogError("Error adding hazard type " + primaryTypeName + ": " + ex.Message);
return false;
}
}
private static Type FindTypeInAssemblies(string fullTypeName, string typeName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
try
{
Type type = assembly.GetType(fullTypeName);
if (type != null)
{
return type;
}
Type[] types = assembly.GetTypes();
foreach (Type type2 in types)
{
if (type2.Name == typeName)
{
return type2;
}
}
}
catch (ReflectionTypeLoadException)
{
}
}
return null;
}
public static bool HazardTriggerPrefix(object __instance, Collider other)
{
try
{
EnemyAICollisionDetect component = ((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>();
if ((Object)(object)component != (Object)null && (Object)(object)component.mainScript != (Object)null)
{
if (!Plugin.Instance.HazardsKillEnemy.Value)
{
Plugin.LogInfo("Prevented " + __instance.GetType().Name + " damage to enemy: " + ((Object)((Component)component.mainScript).gameObject).name);
return false;
}
Plugin.LogInfo("Allowed " + __instance.GetType().Name + " damage to enemy: " + ((Object)((Component)component.mainScript).gameObject).name);
}
return true;
}
catch (Exception ex)
{
Plugin.LogError("Error in HazardTriggerPrefix: " + ex.Message);
return true;
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class ReRandomizePatch
{
private static bool initialRandomizationDone;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPostfix()
{
try
{
if (!initialRandomizationDone && RandomHazardManager.Instance.IsEnabled())
{
Plugin.LogInfo("Initial game start - randomizing Experimentation moon");
if (Plugin.Instance.HazardSettingsDictionary.TryGetValue("Experimentation", out Dictionary<string, Plugin.HazardSettings> value))
{
RandomHazardManager.Instance.RandomizeHazards(value);
}
initialRandomizationDone = true;
}
}
catch (Exception arg)
{
Plugin.LogError($"Error in Start postfix: {arg}");
}
}
[HarmonyPatch("ShipLeave")]
[HarmonyPostfix]
private static void Postfix()
{
try
{
if (!RandomHazardManager.Instance.IsEnabled())
{
Plugin.LogInfo("Random hazards disabled - skipping re-randomization");
return;
}
string text = null;
if ((Object)(object)StartOfRound.Instance?.currentLevel != (Object)null)
{
text = ((Object)StartOfRound.Instance.currentLevel).name;
if (!string.IsNullOrEmpty(text))
{
text = text.Replace("level", "", StringComparison.OrdinalIgnoreCase);
text = char.ToUpper(text[0]) + text.Substring(1).ToLower();
}
}
if (string.IsNullOrEmpty(text))
{
Plugin.LogInfo("No next moon found during ship leave");
return;
}
if (!Plugin.Instance.HazardSettingsDictionary.TryGetValue(text, out Dictionary<string, Plugin.HazardSettings> value))
{
Plugin.LogInfo("No hazard settings found for next moon: " + text);
return;
}
Plugin.LogInfo("Ship is leaving - Re-randomizing hazards for next round on " + text);
RandomHazardManager.Instance.ClearRandomizedValuesForMoon(text);
RandomHazardManager.Instance.RandomizeHazards(value);
}
catch (Exception arg)
{
Plugin.LogError($"Error in ShipLeave patch while re-randomizing: {arg}");
}
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
private static readonly Dictionary<string, string> vanillaHazardPrefabNames = new Dictionary<string, string>
{
{ "Landmine", "Landmine" },
{ "TurretContainer", "Turret" },
{ "SpikeRoofTrapHazard", "SpikeRoofTrap" }
};
private static string currentlyLoadedBearTrapVariant = null;
[HarmonyPatch("SpawnMapObjects")]
[HarmonyPrefix]
private static bool Prefix(RoundManager __instance)
{
//IL_033c: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0352: Unknown result type (might be due to invalid IL or missing references)
//IL_0357: Unknown result type (might be due to invalid IL or missing references)
//IL_035c: Unknown result type (might be due to invalid IL or missing references)
//IL_0366: Expected O, but got Unknown
//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
//IL_02eb: Expected O, but got Unknown
try
{
currentlyLoadedBearTrapVariant = null;
if (__instance?.currentLevel?.spawnableMapObjects != null)
{
for (int i = 0; i < __instance.currentLevel.spawnableMapObjects.Length; i++)
{
SpawnableMapObject val = __instance.currentLevel.spawnableMapObjects[i];
if ((Object)(object)val?.prefabToSpawn != (Object)null && IsHazardPrefab(val.prefabToSpawn))
{
val.requireDistanceBetweenSpawns = true;
Plugin.LogInfo("Enabled distance checking for hazard: " + ((Object)val.prefabToSpawn).name);
}
}
}
if ((Object)(object)__instance?.currentLevel == (Object)null)
{
Plugin.LogWarning("Current level is null, cannot determine moon name");
return true;
}
string text = ((Object)__instance.currentLevel).name;
if (!string.IsNullOrEmpty(text))
{
text = text.Replace("level", "", StringComparison.OrdinalIgnoreCase);
text = char.ToUpper(text[0]) + text.Substring(1).ToLower();
}
Plugin.LogInfo("Processing spawns for moon: " + text);
List<string> list = FindAvailableBearTrapVariants(__instance);
Plugin.LogInfo(string.Format("Found {0} available bear trap variants: {1}", list.Count, string.Join(", ", list)));
if (list.Count == 0)
{
Plugin.LogInfo("No bear trap variants available, skipping bear trap randomization");
}
Dictionary<string, Plugin.HazardSettings> value2;
if (!Plugin.Instance.HazardSettingsDictionary.ContainsKey(text))
{
Plugin.LogInfo("Detected new moon during gameplay: " + text);
Plugin.Instance.LoadCustomMoonConfigs();
if (RandomHazardManager.Instance.IsEnabled() && Plugin.Instance.HazardSettingsDictionary.TryGetValue(text, out Dictionary<string, Plugin.HazardSettings> value))
{
Plugin.LogInfo("New moon detected during gameplay - randomizing hazards for: " + text);
RandomHazardManager.Instance.RandomizeHazards(value);
}
}
else if (RandomHazardManager.Instance.IsEnabled() && !RandomHazardManager.Instance.HasRandomizedValues(text) && Plugin.Instance.HazardSettingsDictionary.TryGetValue(text, out value2))
{
Plugin.LogInfo("First visit to " + text + " - randomizing hazards now");
RandomHazardManager.Instance.RandomizeHazards(value2);
}
if (!RandomHazardManager.Instance.IsEnabled() && !Plugin.Instance.CustomizeHazards.Value)
{
SpawnableMapObject[] spawnableMapObjects = __instance.currentLevel.spawnableMapObjects;
foreach (SpawnableMapObject val2 in spawnableMapObjects)
{
val2.numberToSpawn = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
{
new Keyframe(0f, 0f),
new Keyframe(1f, 0f)
});
}
Plugin.LogInfo("Both Random Hazards and Customize Hazards are disabled - All hazards disabled");
return true;
}
SpawnableMapObject[] spawnableMapObjects2 = __instance.currentLevel.spawnableMapObjects;
foreach (SpawnableMapObject val3 in spawnableMapObjects2)
{
val3.numberToSpawn = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
{
new Keyframe(0f, 0f),
new Keyframe(1f, 0f)
});
}
if (!Plugin.Instance.HazardSettingsDictionary.TryGetValue(text, out Dictionary<string, Plugin.HazardSettings> value3))
{
return true;
}
List<string> list2 = value3.Keys.ToList();
string text2 = SelectRandomBearTrapVariant(list2);
if (text2 != null)
{
Plugin.LogInfo("Selected bear trap variant for this moon: " + text2);
}
foreach (KeyValuePair<string, Plugin.HazardSettings> item in value3)
{
string key = item.Key;
Plugin.HazardSettings value4 = item.Value;
if (!IsBearTrapVariant(key))
{
ProcessHazard(__instance, text, key, value4);
}
}
if (text2 != null)
{
Plugin.HazardSettings hazardSettings = value3[text2];
if (!ProcessHazard(__instance, text, text2, hazardSettings) && currentlyLoadedBearTrapVariant == null)
{
Plugin.LogInfo("Selected bear trap variant " + text2 + " couldn't be loaded, trying alternatives");
foreach (string item2 in list2.Where(IsBearTrapVariant))
{
if (!(item2 == text2))
{
Plugin.LogInfo("Trying alternative bear trap variant: " + item2);
hazardSettings = value3[item2];
if (ProcessHazard(__instance, text, item2, hazardSettings))
{
Plugin.LogInfo("Successfully loaded alternative bear trap variant: " + item2);
break;
}
}
}
}
}
return true;
}
catch (Exception arg)
{
Plugin.LogError($"Error in SpawnMapObjects patch: {arg}");
return true;
}
}
private static bool IsHazardPrefab(GameObject prefab)
{
if ((Object)(object)prefab == (Object)null)
{
return false;
}
string name = ((Object)prefab).name;
string[] array = new string[18]
{
"Landmine", "TurretContainer", "SpikeRoofTrapHazard", "GravelBearTrap", "SnowBearTrap", "BoomBearTrap", "GrassBearTrap", "Yeetmine", "TeleporterTrap", "LaserTurret",
"BugZapper", "FlashTurretUpdated", "FunctionalMicrowave", "FanTrapAnimated", "Bertha", "Seamine", "CageTrap", "PrefabAcidSpitter"
};
string[] array2 = array;
foreach (string value in array2)
{
if (name.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
{
return true;
}
}
string prefabNameLower = name.ToLower();
return prefabNameLower.Contains("trap") || prefabNameLower.Contains("Mine") || prefabNameLower.Contains("mine") || prefabNameLower.Contains("Microwave") || prefabNameLower.Contains("Spitter") || prefabNameLower.Contains("Zapper") || prefabNameLower.Contains("Bertha") || prefabNameLower.Contains("Seamine") || prefabNameLower.Contains("Turret") || prefabNameLower.Contains("Spike") || prefabNameLower.Contains("Hazard") || prefabNameLower.Contains("Gravel") || prefabNameLower.Contains("Snow") || prefabNameLower.Contains("Boom") || prefabNameLower.Contains("Grass") || vanillaHazardPrefabNames.Keys.Any((string key) => prefabNameLower.Contains(key.ToLower()));
}
private static List<string> FindAvailableBearTrapVariants(RoundManager __instance)
{
List<string> list = new List<string>();
string[] array = new string[4] { "GravelBearTrap", "SnowBearTrap", "BoomBearTrap", "GrassBearTrap" };
SelectableLevel[] levels = StartOfRound.Instance.levels;
foreach (SelectableLevel val in levels)
{
SpawnableMapObject[] spawnableMapObjects = val.spawnableMapObjects;
foreach (SpawnableMapObject val2 in spawnableMapObjects)
{
if (!((Object)(object)val2.prefabToSpawn != (Object)null))
{
continue;
}
string name = ((Object)val2.prefabToSpawn).name;
string[] array2 = array;
foreach (string text in array2)
{
if (name.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0 && !list.Contains(text))
{
list.Add(text);
Plugin.LogInfo("Found bear trap variant in scene: " + text + " (prefab: " + name + ")");
}
}
}
}
if (Chainloader.PluginInfos.ContainsKey("CodeRebirth"))
{
string[] array3 = array;
foreach (string text2 in array3)
{
if (CodeRebirthAssetAccess.IsBearTrapPrefabAvailable(text2) && !list.Contains(text2))
{
list.Add(text2);
Plugin.LogInfo("Found bear trap variant in CodeRebirth assets: " + text2);
}
}
}
return list;
}
private static bool ProcessHazard(RoundManager __instance, string currentMoon, string hazardType, Plugin.HazardSettings hazardSettings)
{
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
if (RandomHazardManager.Instance.IsEnabled())
{
if (!RandomHazardManager.Instance.ShouldHazardBeEnabled(currentMoon, hazardType))
{
Plugin.LogInfo("Hazard " + hazardType + " is disabled for " + currentMoon + " by randomization");
return false;
}
}
else if (!hazardSettings.Enabled.Value)
{
Plugin.LogInfo("Hazard " + hazardType + " is disabled for " + currentMoon + " by configuration");
return false;
}
int num;
if (RandomHazardManager.Instance.IsEnabled())
{
num = RandomHazardManager.Instance.GetRandomizedSpawnCount(currentMoon, hazardType, hazardSettings.SpawnCount.Value);
Plugin.LogInfo($"Using randomized value for {hazardType}: {num}");
}
else
{
num = hazardSettings.SpawnCount.Value;
}
if (num <= 0)
{
return false;
}
SpawnableMapObject val = FindOrBorrowHazardPrefab(__instance, hazardType);
if (val != null)
{
val.requireDistanceBetweenSpawns = true;
val.numberToSpawn = AnimationCurve.Constant(0f, 1f, (float)num);
Plugin.LogInfo($"Set spawn count to {num} for hazard {hazardType}");
if (hazardType == "Bertha" && (Object)(object)val.prefabToSpawn != (Object)null && RandomHazardManager.Instance.IsEnabled())
{
Vector3 localScale = val.prefabToSpawn.transform.localScale;
int randomizedBerthaScale = RandomHazardManager.Instance.GetRandomizedBerthaScale(currentMoon);
float num2 = RandomHazardManager.Instance.ScaleValueToPercentage(randomizedBerthaScale);
float num3 = num2 / 100f;
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(localScale.x * num3, localScale.y * num3, localScale.z * num3);
val.prefabToSpawn.transform.localScale = val2;
SurfacedBerthaAccess.BerthaScalingMarker berthaScalingMarker = default(SurfacedBerthaAccess.BerthaScalingMarker);
if (!val.prefabToSpawn.TryGetComponent<SurfacedBerthaAccess.BerthaScalingMarker>(ref berthaScalingMarker))
{
berthaScalingMarker = val.prefabToSpawn.AddComponent<SurfacedBerthaAccess.BerthaScalingMarker>();
berthaScalingMarker.AppliedScaleFactor = num3;
}
Plugin.LogInfo($"Scaled Bertha prefab from {localScale} to {val2} (factor: {num3})");
}
if (IsBearTrapVariant(hazardType))
{
currentlyLoadedBearTrapVariant = hazardType;
Plugin.LogInfo("Successfully loaded bear trap variant: " + hazardType);
}
return true;
}
return false;
}
private static SpawnableMapObject FindOrBorrowHazardPrefab(RoundManager __instance, string hazardType)
{
string hazardType2 = hazardType;
if (IsBearTrapVariant(hazardType2))
{
SpawnableMapObject val = ((IEnumerable<SpawnableMapObject>)__instance.currentLevel.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => (Object)(object)x.prefabToSpawn != (Object)null && ((Object)x.prefabToSpawn).name.IndexOf(hazardType2, StringComparison.OrdinalIgnoreCase) >= 0));
if (val != null)
{
Plugin.LogInfo("Found " + hazardType2 + " in current level");
return val;
}
SpawnableMapObject val2 = StartOfRound.Instance.levels.SelectMany((SelectableLevel x) => x.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => (Object)(object)x.prefabToSpawn != (Object)null && ((Object)x.prefabToSpawn).name.IndexOf(hazardType2, StringComparison.OrdinalIgnoreCase) >= 0));
if (val2 != null)
{
try
{
SpawnableMapObject[] spawnableMapObjects = __instance.currentLevel.spawnableMapObjects;
SpawnableMapObject[] array = (SpawnableMapObject[])(object)new SpawnableMapObject[spawnableMapObjects.Length + 1];
Array.Copy(spawnableMapObjects, array, spawnableMapObjects.Length);
array[spawnableMapObjects.Length] = val2;
__instance.currentLevel.spawnableMapObjects = array;
Plugin.LogInfo("Successfully borrowed " + hazardType2 + " from another level");
return val2;
}
catch (Exception ex)
{
Plugin.LogError("Error borrowing " + hazardType2 + ": " + ex.Message);
}
}
string[] array2 = new string[4] { "GravelBearTrap", "SnowBearTrap", "BoomBearTrap", "GrassBearTrap" };
string[] array3 = array2;
foreach (string variant in array3)
{
if (variant == hazardType2)
{
continue;
}
SpawnableMapObject val3 = StartOfRound.Instance.levels.SelectMany((SelectableLevel x) => x.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => (Object)(object)x.prefabToSpawn != (Object)null && ((Object)x.prefabToSpawn).name.IndexOf(variant, StringComparison.OrdinalIgnoreCase) >= 0));
if (val3 != null)
{
try
{
SpawnableMapObject[] spawnableMapObjects2 = __instance.currentLevel.spawnableMapObjects;
SpawnableMapObject[] array4 = (SpawnableMapObject[])(object)new SpawnableMapObject[spawnableMapObjects2.Length + 1];
Array.Copy(spawnableMapObjects2, array4, spawnableMapObjects2.Length);
array4[spawnableMapObjects2.Length] = val3;
__instance.currentLevel.spawnableMapObjects = array4;
Plugin.LogInfo("Using " + variant + " as fallback for " + hazardType2);
return val3;
}
catch (Exception ex2)
{
Plugin.LogError("Error using " + variant + " as fallback: " + ex2.Message);
}
}
}
if (Chainloader.PluginInfos.ContainsKey("CodeRebirth"))
{
if (CodeRebirthAssetAccess.IsBearTrapPrefabAvailable(hazardType2))
{
GameObject bearTrapPrefab = CodeRebirthAssetAccess.GetBearTrapPrefab(hazardType2);
if ((Object)(object)bearTrapPrefab != (Object)null)
{
string[] array5 = new string[3] { "Landmine", "TurretContainer", "SpikeRoofTrapHazard" };
string[] array6 = array5;
foreach (string templateName3 in array6)
{
SpawnableMapObject val4 = ((IEnumerable<SpawnableMapObject>)__instance.currentLevel.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => (Object)(object)x.prefabToSpawn != (Object)null && ((Object)x.prefabToSpawn).name.IndexOf(templateName3, StringComparison.OrdinalIgnoreCase) >= 0));
if (val4 != null)
{
SpawnableMapObject val5 = val4;
val5.prefabToSpawn = bearTrapPrefab;
Plugin.LogInfo("Created SpawnableMapObject for " + hazardType2 + " using " + templateName3 + " as template");
return val5;
}
}
string[] array7 = array5;
foreach (string templateName2 in array7)
{
SpawnableMapObject val6 = StartOfRound.Instance.levels.SelectMany((SelectableLevel x) => x.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => (Object)(object)x.prefabToSpawn != (Object)null && ((Object)x.prefabToSpawn).name.IndexOf(templateName2, StringComparison.OrdinalIgnoreCase) >= 0));
if (val6 != null)
{
try
{
SpawnableMapObject[] spawnableMapObjects3 = __instance.currentLevel.spawnableMapObjects;
SpawnableMapObject[] array8 = (SpawnableMapObject[])(object)new SpawnableMapObject[spawnableMapObjects3.Length + 1];
Array.Copy(spawnableMapObjects3, array8, spawnableMapObjects3.Length);
SpawnableMapObject val7 = val6;
val7.prefabToSpawn = bearTrapPrefab;
array8[spawnableMapObjects3.Length] = val7;
__instance.currentLevel.spawnableMapObjects = array8;
Plugin.LogInfo("Added SpawnableMapObject for " + hazardType2 + " using " + templateName2 + " as template from another level");
return val7;
}
catch (Exception ex3)
{
Plugin.LogError("Error creating SpawnableMapObject for " + hazardType2 + ": " + ex3.Message);
}
}
}
}
}
string[] array9 = array2;
foreach (string text in array9)
{
if (text == hazardType2 || !CodeRebirthAssetAccess.IsBearTrapPrefabAvailable(text))
{
continue;
}
GameObject bearTrapPrefab2 = CodeRebirthAssetAccess.GetBearTrapPrefab(text);
if (!((Object)(object)bearTrapPrefab2 != (Object)null))
{
continue;
}
string[] array10 = new string[3] { "Landmine", "TurretContainer", "SpikeRoofTrapHazard" };
string[] array11 = array10;
foreach (string templateName in array11)
{
SpawnableMapObject val8 = ((IEnumerable<SpawnableMapObject>)__instance.currentLevel.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => (Object)(object)x.prefabToSpawn != (Object)null && ((Object)x.prefabToSpawn).name.IndexOf(templateName, StringComparison.OrdinalIgnoreCase) >= 0));
if (val8 != null)
{
SpawnableMapObject val9 = val8;
val9.prefabToSpawn = bearTrapPrefab2;
Plugin.LogInfo("Created SpawnableMapObject for " + hazardType2 + " using " + text + " prefab and " + templateName + " as template");
return val9;
}
}
}
}
Plugin.LogWarning("Could not find any bear trap variant for " + hazardType2);
return null;
}
SpawnableMapObject val10 = ((IEnumerable<SpawnableMapObject>)__instance.currentLevel.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => (Object)(object)x.prefabToSpawn != (Object)null && ((Object)x.prefabToSpawn).name.IndexOf(hazardType2, StringComparison.OrdinalIgnoreCase) >= 0));
if (val10 == null)
{
SpawnableMapObject val11 = StartOfRound.Instance.levels.SelectMany((SelectableLevel x) => x.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => (Object)(object)x.prefabToSpawn != (Object)null && ((Object)x.prefabToSpawn).name.IndexOf(hazardType2, StringComparison.OrdinalIgnoreCase) >= 0));
if (val11 == null)
{
Plugin.LogWarning("Could not find hazard " + hazardType2 + " in any moon to borrow");
return null;
}
try
{
SpawnableMapObject[] spawnableMapObjects4 = __instance.currentLevel.spawnableMapObjects;
SpawnableMapObject[] array12 = (SpawnableMapObject[])(object)new SpawnableMapObject[spawnableMapObjects4.Length + 1];
Array.Copy(spawnableMapObjects4, array12, spawnableMapObjects4.Length);
array12[spawnableMapObjects4.Length] = val11;
__instance.currentLevel.spawnableMapObjects = array12;
val10 = array12[spawnableMapObjects4.Length];
Plugin.LogInfo("Successfully borrowed hazard " + hazardType2 + " from another moon");
}
catch (Exception ex4)
{
Plugin.LogError("Error adding spawnable object for " + hazardType2 + ": " + ex4.Message);
return null;
}
}
return val10;
}
private static string SelectRandomBearTrapVariant(List<string> availableHazards)
{
List<string> list = availableHazards.Where((string h) => Plugin.Instance.IsBearTrapVariant(h)).ToList();
Plugin.LogInfo($"Found {list.Count} enabled bear trap variants in settings");
if (list.Count == 0)
{
string[] array = new string[4] { "GravelBearTrap", "SnowBearTrap", "BoomBearTrap", "GrassBearTrap" };
string[] array2 = array;
foreach (string text in array2)
{
if (CodeRebirthAssetAccess.IsBearTrapPrefabAvailable(text))
{
list.Add(text);
Plugin.LogInfo("Found available bear trap variant: " + text);
}
}
}
if (list.Count == 0)
{
Plugin.LogInfo("No bear trap variants available for randomization");
return null;
}
int index = new Random().Next(list.Count);
string text2 = list[index];
Plugin.LogInfo("Selected bear trap variant for randomization: " + text2);
return text2;
}
private static bool IsBearTrapVariant(string hazardType)
{
return Plugin.Instance.IsBearTrapVariant(hazardType);
}
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
internal class StartOfRoundPatch
{
[HarmonyPostfix]
private static void Postfix()
{
Plugin.LogInfo("StartOfRound.Start completed, loading custom moon configs...");
Plugin.Instance.LoadCustomMoonConfigs();
StartOfRound instance = StartOfRound.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
SelectableLevel currentLevel = instance.currentLevel;
obj = ((currentLevel != null) ? ((Object)currentLevel).name : null);
}
string text = (string)obj;
if (!string.IsNullOrEmpty(text))
{
text = text.Replace("level", "", StringComparison.OrdinalIgnoreCase);
text = char.ToUpper(text[0]) + text.Substring(1).ToLower();
if (Plugin.Instance.HazardSettingsDictionary.TryGetValue(text, out Dictionary<string, Plugin.HazardSettings> value))
{
if (RandomHazardManager.Instance.IsEnabled())
{
Plugin.LogInfo("Random hazards enabled - randomizing for moon: " + text);
RandomHazardManager.Instance.RandomizeHazards(value);
}
else if (Plugin.Instance.CustomizeHazards.Value)
{
Plugin.LogInfo("Using custom hazard settings for moon: " + text);
}
else
{
Plugin.LogInfo("Using default hazard settings for moon: " + text);
}
}
}
Plugin.LogInfo("Custom moon configurations completed.");
}
}
public static class SurfacedBerthaAccess
{
public class BerthaScalingMarker : MonoBehaviour
{
public float AppliedScaleFactor { get; set; } = 1f;
}
[HarmonyPatch(typeof(RoundManager), "SpawnMapObjects")]
public class SurfacedBerthaSpawnPatch
{
[HarmonyPostfix]
private static void Postfix(RoundManager __instance)
{
try
{
if (!IsInitialized())
{
Initialize();
}
if (__instance?.currentLevel?.spawnableMapObjects != null)
{
SpawnableMapObject[] spawnableMapObjects = __instance.currentLevel.spawnableMapObjects;
foreach (SpawnableMapObject val in spawnableMapObjects)
{
if ((Object)(object)val?.prefabToSpawn != (Object)null && ((Object)val.prefabToSpawn).name.Contains("Bertha"))
{
ModifyBerthaScale(val.prefabToSpawn);
Plugin.LogInfo("Modified Bertha prefab scale in current level: " + ((Object)val.prefabToSpawn).name);
}
}
}
GameObject[] array = Object.FindObjectsOfType<GameObject>();
int num = 0;
GameObject[] array2 = array;
foreach (GameObject val2 in array2)
{
if (((Object)val2).name.Contains("Bertha"))
{
ModifyBerthaScale(val2);
num++;
}
}
if (num > 0)
{
Plugin.LogInfo($"Modified {num} Bertha objects in the scene");
}
}
catch (Exception ex)
{
Plugin.LogError("Error in SurfacedBerthaSpawnPatch: " + ex.Message);
}
}
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
public class SurfacedBerthaStartPatch
{
[HarmonyPostfix]
private static void Postfix()
{
try
{
DelayedBerthaSearch();
}
catch (Exception ex)
{
Plugin.LogError("Error in SurfacedBerthaStartPatch: " + ex.Message);
}
}
private static async void DelayedBerthaSearch()
{
await Task.Delay(2000);
try
{
MonoBehaviour[] allBehaviours = Object.FindObjectsOfType<MonoBehaviour>();
int berthaCount = 0;
MonoBehaviour[] array = allBehaviours;
foreach (MonoBehaviour behaviour in array)
{
if (((object)behaviour).GetType().Name == "Bertha")
{
ModifyBerthaScale(((Component)behaviour).gameObject);
berthaCount++;
}
}
if (berthaCount > 0)
{
Plugin.LogInfo($"Modified {berthaCount} Bertha components after delay");
}
}
catch (Exception ex2)
{
Exception ex = ex2;
Plugin.LogError("Error in delayed Bertha search: " + ex.Message);
}
}
}
private static bool initialized;
private static Type berthaType;
private static GameObject berthaPrefab;
public static void Initialize()
{
initialized = true;
try
{
if (Chainloader.PluginInfos.ContainsKey("Surfaced"))
{
Plugin.LogInfo("Initializing Surfaced Bertha access...");
}
}
catch (Exception)
{
}
}
public static bool IsInitialized()
{
return initialized;
}
public static Type GetBerthaType()
{
if (!initialized)
{
Initialize();
}
return berthaType;
}
public static GameObject GetBerthaPrefab()
{
if (!initialized)
{
Initialize();
}
return berthaPrefab;
}
public static void ModifyBerthaScale(GameObject berthaObject)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: 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_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)berthaObject == (Object)null)
{
return;
}
try
{
BerthaScalingMarker berthaScalingMarker = default(BerthaScalingMarker);
if (!berthaObject.TryGetComponent<BerthaScalingMarker>(ref berthaScalingMarker))
{
float desiredScaleFactor = GetDesiredScaleFactor();
Vector3 localScale = berthaObject.transform.localScale;
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(localScale.x * desiredScaleFactor, localScale.y * desiredScaleFactor, localScale.z * desiredScaleFactor);
berthaObject.transform.localScale = val;
Plugin.LogInfo($"Scaled Bertha from {localScale} to {val} (factor: {desiredScaleFactor})");
berthaScalingMarker = berthaObject.AddComponent<BerthaScalingMarker>();
berthaScalingMarker.AppliedScaleFactor = desiredScaleFactor;
}
else
{
Plugin.LogInfo($"Bertha object {((Object)berthaObject).name} has already been scaled to factor {berthaScalingMarker.AppliedScaleFactor}, skipping");
}
Transform parent = berthaObject.transform.parent;
BerthaScalingMarker berthaScalingMarker2 = default(BerthaScalingMarker);
if ((Object)(object)parent != (Object)null && ((Object)parent).name.Contains("BigBertha") && !((Component)parent).TryGetComponent<BerthaScalingMarker>(ref berthaScalingMarker2))
{
float appliedScaleFactor = berthaObject.GetComponent<BerthaScalingMarker>().AppliedScaleFactor;
Vector3 localScale2 = parent.localScale;
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(localScale2.x * appliedScaleFactor, localScale2.y * appliedScaleFactor, localScale2.z * appliedScaleFactor);
parent.localScale = val2;
berthaScalingMarker2 = ((Component)parent).gameObject.AddComponent<BerthaScalingMarker>();
berthaScalingMarker2.AppliedScaleFactor = appliedScaleFactor;
Plugin.LogInfo($"Scaled BigBertha parent from {localScale2} to {val2}");
}
}
catch (Exception ex)
{
Plugin.LogError("Error modifying Bertha scale: " + ex.Message);
Plugin.LogError("Stack trace: " + ex.StackTrace);
}
}
private static float GetDesiredScaleFactor()
{
if (RandomHazardManager.Instance.IsEnabled())
{
StartOfRound instance = StartOfRound.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
SelectableLevel currentLevel = instance.currentLevel;
obj = ((currentLevel != null) ? ((Object)currentLevel).name : null);
}
if (obj == null)
{
obj = "";
}
string text = (string)obj;
if (!string.IsNullOrEmpty(text))
{
text = text.Replace("level", "", StringComparison.OrdinalIgnoreCase);
text = char.ToUpper(text[0]) + text.Substring(1).ToLower();
int randomizedBerthaScale = RandomHazardManager.Instance.GetRandomizedBerthaScale(text);
float num = RandomHazardManager.Instance.ScaleValueToPercentage(randomizedBerthaScale);
float num2 = num / 100f;
Plugin.LogInfo($"Using randomized Bertha scale: value={randomizedBerthaScale}, percentage={num:F1}%, factor={num2:F4}");
return num2;
}
return 0.7f;
}
Plugin.LogInfo("Using fixed 70% scaling for Bertha in Customize Hazards mode");
return 0.7f;
}
}
}
namespace InteriorHazardsPlus.Data
{
public class HazardConfiguration
{
public bool Enabled { get; set; }
public int SpawnCount { get; set; }
public ConfigEntry<bool> EnableConfig { get; set; } = null;
public HazardConfiguration(bool enabled, int spawnCount)
{
Enabled = enabled;
SpawnCount = spawnCount;
}
public int GetSpawnCount()
{
return SpawnCount;
}
}
public enum HazardType
{
Landmine,
TurretContainer,
SpikeRoofTrapHazard,
LaserTurret,
CageTrap,
Yeetmine,
PrefabAcidSpitter,
TeleporterTrap,
BugZapper,
FlashTurretUpdated,
FunctionalMicrowave,
FanTrapAnimated,
Seamine,
Bertha,
GrassBearTrap,
SnowBearTrap,
BoomBearTrap,
GravelBearTrap
}
public static class LCUtils
{
public static readonly Dictionary<string, string[]> CUSTOM_LAYER_MASK = new Dictionary<string, string[]> {
{
"march",
new string[1] { "Room" }
} };
private static Random random = new Random();
public static float RandomNumberInRadius(float radius)
{
return (float)((random.NextDouble() - 0.5) * (double)radius);
}
public static (Vector3 position, Quaternion rotation) GetRandomInteriorPositionAndRotation(Vector3 centerPoint, float radius = 10f, int maxAttempts = 10)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: 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)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
int mask = LayerMask.GetMask(new string[1] { "Room" });
float y = centerPoint.y;
NavMeshHit val2 = default(NavMeshHit);
RaycastHit val3 = default(RaycastHit);
for (int i = 0; i < maxAttempts; i++)
{
try
{
float num = RandomNumberInRadius(radius);
float num2 = RandomNumberInRadius(radius);
float num3 = RandomNumberInRadius(radius);
Vector3 val = centerPoint + new Vector3(num, num2, num3);
val.y = y;
float num4 = Vector3.Distance(centerPoint, val) + 30f;
if (NavMesh.SamplePosition(val, ref val2, num4, mask) && Physics.Raycast(((NavMeshHit)(ref val2)).position + Vector3.up, Vector3.down, ref val3, 50f, mask))
{
return (((RaycastHit)(ref val3)).point + Vector3.up * 0.1f, Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val3)).normal));
}
}
catch (Exception ex)
{
Plugin.LogError("Error finding spawn position: " + ex.Message);
}
}
return (Vector3.zero, Quaternion.identity);
}
}
public struct SpawnPositionData
{
public Vector3 CenterPosition { get; }
public float SpawnRadius { get; }
public SpawnPositionData(Vector3 centerPosition, float spawnRadius)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
CenterPosition = centerPosition;
SpawnRadius = spawnRadius;
}
}
}
namespace InteriorHazardsPlus.plugins
{
public class ConfigWatcher : MonoBehaviour
{
private void Update()
{
RandomHazardManager.Instance.Update();
}
public static void Initialize()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
GameObject val = new GameObject("ConfigWatcher");
val.AddComponent<ConfigWatcher>();
Object.DontDestroyOnLoad((Object)(object)val);
}
}
public static class LethalConfigProxy
{
private static bool? _enabled;
public static bool Enabled
{
get
{
bool valueOrDefault = _enabled.GetValueOrDefault();
if (!_enabled.HasValue)
{
valueOrDefault = Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");
_enabled = valueOrDefault;
}
return _enabled.Value;
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig(ConfigEntry<bool> entry, bool requiresRestart = false)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(entry, new BoolCheckBoxOptions
{
RequiresRestart = requiresRestart,
Name = ((ConfigEntryBase)entry).Definition.Key,
Section = ((ConfigEntryBase)entry).Definition.Section
}));
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig(ConfigEntry<int> entry, bool requiresRestart = false)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(entry, new IntInputFieldOptions
{
RequiresRestart = requiresRestart,
Name = ((ConfigEntryBase)entry).Definition.Key,
Section = ((ConfigEntryBase)entry).Definition.Section
}));
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig(ConfigEntry<string> entry, bool requiresRestart = false)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(entry, new TextInputFieldOptions
{
RequiresRestart = requiresRestart,
Name = ((ConfigEntryBase)entry).Definition.Key,
Section = ((ConfigEntryBase)entry).Definition.Section
}));
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig(ConfigEntry<string> entry, bool isReadOnly, string customName = null, string customSection = null)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Expected O, but got Unknown
//IL_003d: Expected O, but got Unknown
TextInputFieldOptions val = new TextInputFieldOptions
{
RequiresRestart = false,
Name = (customName ?? ((ConfigEntryBase)entry).Definition.Key),
Section = (customSection ?? ((ConfigEntryBase)entry).Definition.Section)
};
try
{
PropertyInfo property = typeof(TextInputFieldOptions).GetProperty("ReadOnly");
if (property != null)
{
property.SetValue(val, isReadOnly);
}
else
{
Plugin.LogWarning("ReadOnly property not found in TextInputFieldOptions");
}
}
catch (Exception ex)
{
Plugin.LogError("Error setting ReadOnly property: " + ex.Message);
}
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(entry, val));
}
}
[BepInPlugin("GinjeesPacks.InteriorHazardsPlus", "InteriorHazardsPlus", "1.0.7")]
[BepInProcess("Lethal Company.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public class HazardSettings
{
public ConfigEntry<bool> Enabled = null;
public ConfigEntry<int> SpawnCount = null;
}
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
internal class GameNetworkManagerStartPatch
{
[HarmonyPostfix]
private static void Postfix(GameNetworkManager __instance)
{
Instance.CheckForSurfacedAndRegisterConfig();
}
}
public const string GUID = "GinjeesPacks.InteriorHazardsPlus";
public const string NAME = "InteriorHazardsPlus";
public const string VERSION = "1.0.7";
public static Plugin Instance;
private readonly Harmony harmony = new Harmony("GinjeesPacks.InteriorHazardsPlus");
private static ManualLogSource Log;
public ConfigEntry<bool> CustomizeHazards = null;
public ConfigEntry<bool> EnableRandomHazards = null;
public ConfigEntry<bool> RandomizeEnabled = null;
private ConfigEntry<bool> ResetAllHazards = null;
private ConfigEntry<bool> EnableAllHazards = null;
public ConfigEntry<bool> HazardsKillEnemy = null;
public ConfigEntry<int> MinHazards = null;
public ConfigEntry<int> MaxHazards = null;
public Dictionary<string, Dictionary<string, HazardSettings>> HazardSettingsDictionary = new Dictionary<string, Dictionary<string, HazardSettings>>();
public readonly Dictionary<string, string> vanillaMoons = new Dictionary<string, string>
{
{ "03. Experimentation", "Experimentation" },
{ "04. Assurance", "Assurance" },
{ "05. Vow", "Vow" },
{ "06. Offense", "Offense" },
{ "07. March", "March" },
{ "08. Adamance", "Adamance" },
{ "09. Rend", "Rend" },
{ "10. Dine", "Dine" },
{ "11. Titan", "Titan" },
{ "12. Artifice", "Artifice" },
{ "13. Embrion", "Embrion" }
};
private bool berthaAccessInitialized = false;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
Log = ((BaseUnityPlugin)this).Logger;
MapHazardPatch.PatchHazards(harmony);
if (Chainloader.PluginInfos.ContainsKey("CodeRebirth"))
{
LogInfo("CodeRebirth mod detected, initializing asset access");
CodeRebirthAssetAccess.Initialize();
BearTrapDamagePatch.PatchBearTrapIfAvailable(harmony);
}
LoadConfig();
CheckForSurfacedAndRegisterConfig();
RandomHazardManager.Instance.Initialize(this, EnableRandomHazards);
RegisterRandomHazardsSection();
RandomHazardManager.Instance.SetupResetAllWatcher(ResetAllHazards);
RandomHazardManager.Instance.SetupResetAllWatcher(ResetAllHazards);
if (LethalConfigProxy.Enabled)
{
LogInfo("Registering configs with LethalConfig");
LethalConfigProxy.AddConfig(CustomizeHazards);
LethalConfigProxy.AddConfig(EnableRandomHazards);
LethalConfigProxy.AddConfig(ResetAllHazards);
LethalConfigProxy.AddConfig(HazardsKillEnemy);
}
ConfigWatcher.Initialize();
RandomHazardManager.Instance.SetupResetAllWatcher(ResetAllHazards);
RandomHazardManager.Instance.SetupEnableAllWatcher(EnableAllHazards);
try
{
harmony.PatchAll();
LogInfo("InteriorHazardsPlus 1.0.7 patches applied successfully!");
}
catch (Exception arg)
{
LogError($"Failed to apply patches: {arg}");
}
LogInfo("InteriorHazardsPlus 1.0.7 is loaded!");
}
public void RegisterRandomHazardsSection()
{
if (LethalConfigProxy.Enabled)
{
ConfigEntry<string> entry = ((BaseUnityPlugin)this).Config.Bind<string>("02. RANDOM HAZARDS", "RandomHazardsInfo", "Random Hazards sets random spawn rate values. Use spawn rate value settings from Customize Hazards when disabled and Customize Hazards is Enabled.", "Information about Random Hazards");
LethalConfigProxy.AddConfig(entry);
}
}
public void CheckForSurfacedAndRegisterConfig()
{
if (Chainloader.PluginInfos.ContainsKey("Surfaced") && !berthaAccessInitialized)
{
SurfacedBerthaAccess.Initialize();
berthaAccessInitialized = true;
LogInfo("Initialized Bertha access");
}
}
public HashSet<string> DetectAvailableHazardTypes()
{
HashSet<string> hashSet = new HashSet<string>();
string[] array = new string[3] { "Landmine", "TurretContainer", "SpikeRoofTrapHazard" };
string[] array2 = array;
foreach (string text in array2)
{
hashSet.Add(text);
LogInfo("Added vanilla hazard: " + text);
}
Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>();
dictionary.Add("TestAccount666.TestAccountCore", new string[3] { "PrefabAcidSpitter", "CageTrap", "Yeetmine" });
dictionary.Add("TestAccount666.TestAccountVariety", new string[3] { "PrefabAcidSpitter", "CageTrap", "Yeetmine" });
dictionary.Add("CodeRebirth", new string[9] { "LaserTurret", "BugZapper", "FanTrapAnimated", "FunctionalMicrowave", "FlashTurretUpdated", "GravelBearTrap", "SnowBearTrap", "BoomBearTrap", "GrassBearTrap" });
dictionary.Add("Surfaced", new string[2] { "Bertha", "Seamine" });
dictionary.Add("evaisa.lethalthings", new string[1] { "TeleporterTrap" });
Dictionary<string, string[]> dictionary2 = dictionary;
HashSet<string> hashSet2 = new HashSet<string>();
foreach (KeyValuePair<string, string[]> item in dictionary2)
{
if (Chainloader.PluginInfos.ContainsKey(item.Key))
{
LogInfo("Mod " + item.Key + " is loaded, adding its hazards");
string[] value = item.Value;
foreach (string text2 in value)
{
if (!hashSet2.Contains(text2))
{
hashSet2.Add(text2);
LogInfo("Marked hazard as available: " + text2);
}
}
}
else
{
LogInfo("Mod " + item.Key + " is not loaded, skipping its hazards");
}
}
foreach (string item2 in hashSet2)
{
if (!hashSet.Contains(item2))
{
hashSet.Add(item2);
LogInfo("Added mod hazard: " + item2);
}
}
return hashSet;
}
public (int defaultCount, int maxCount) GetHazardSpawnLimits(string hazardType)
{
return GetHazardLimits(hazardType);
}
public void LoadConfig()
{
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Expected O, but got Unknown
CustomizeHazards = ((BaseUnityPlugin)this).Config.Bind<bool>("01. GENERAL", "Customize Hazards", false, "Enable individual hazard and spawn rate customization for each moon. When disabled, uses default spawn values.");
EnableRandomHazards = ((BaseUnityPlugin)this).Config.Bind<bool>("01. GENERAL", "Random Hazards", true, "When enabled: Chooses 5 random hazards and sets random spawn rate values. Use spawn rate value settings from Customize Hazards when disabled and Customize Hazards is Enabled.");
EnableAllHazards = ((BaseUnityPlugin)this).Config.Bind<bool>("01. GENERAL", "Enable All Hazards", false, "ATTN: This works in game with LethalConfig or if using Mod Manager read the following. Enable this checkbox to enable all hazards. Will automatically toggle back to off after completion. You will need to restart the game with this enabled and let it load up before the presets will all be enabled. You also have to refresh this page.");
ResetAllHazards = ((BaseUnityPlugin)this).Config.Bind<bool>("01. GENERAL", "Reset All Hazards", false, "ATTN: This works in game with LethalConfig or if using Mod Manager read the following. Enable this checkbox to reset all hazards to disabled state. Will automatically toggle back to off after reset is complete.You will need to start the game with this enabled and let it load up before the presets will disabled. You also have to refresh this page.");
HazardsKillEnemy = ((BaseUnityPlugin)this).Config.Bind<bool>("01. GENERAL", "Hazards Kill Enemy", false, "When enabled, hazards can damage enemies. When disabled, hazards will not affect enemies.");
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.AddConfig(CustomizeHazards);
LethalConfigProxy.AddConfig(EnableRandomHazards);
LethalConfigProxy.AddConfig(ResetAllHazards);
LethalConfigProxy.AddConfig(HazardsKillEnemy);
}
HazardSettingsDictionary = new Dictionary<string, Dictionary<string, HazardSettings>>();
HashSet<string> hashSet = DetectAvailableHazardTypes();
foreach (KeyValuePair<string, string> vanillaMoon in vanillaMoons)
{
Dictionary<string, HazardSettings> dictionary = new Dictionary<string, HazardSettings>();
string key = vanillaMoon.Key;
string value = vanillaMoon.Value;
LogInfo("Creating config section: " + key);
foreach (string item3 in hashSet)
{
string displayName = GetDisplayName(item3);
(int defaultCount, int maxCount) hazardLimits = GetHazardLimits(item3);
int item = hazardLimits.defaultCount;
int item2 = hazardLimits.maxCount;
HazardSettings hazardSettings = new HazardSettings
{
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>(key, displayName + "_Enabled", true, "Enable " + displayName + " spawns on " + value),
SpawnCount = ((BaseUnityPlugin)this).Config.Bind<int>(key, displayName + "_SpawnCount", item, new ConfigDescription("Number of " + displayName + " to spawn on " + value, (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, item2), Array.Empty<object>()))
};
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.AddConfig(hazardSettings.Enabled);
LethalConfigProxy.AddConfig(hazardSettings.SpawnCount);
}
dictionary.Add(item3, hazardSettings);
}
HazardSettingsDictionary.Add(vanillaMoon.Value, dictionary);
LogInfo($"Added config section for {vanillaMoon.Value} with {dictionary.Count} hazards");
}
}
public bool IsBearTrapVariant(string hazardType)
{
int result;
switch (hazardType)
{
default:
result = ((hazardType == "GrassBearTrap") ? 1 : 0);
break;
case "GravelBearTrap":
case "SnowBearTrap":
case "BoomBearTrap":
result = 1;
break;
}
return (byte)result != 0;
}
public string GetDisplayName(string hazardType)
{
if (IsBearTrapVariant(hazardType))
{
return "Bear Trap";
}
if (1 == 0)
{
}
string result = hazardType switch
{
"Landmine" => "Land Mine",
"PrefabAcidSpitter" => "Acid Spitter",
"TurretContainer" => "Turret",
"SpikeRoofTrapHazard" => "Spike Trap",
"LaserTurret" => "Laser Turret",
"Yeetmine" => "Yeet Mine",
"TeleporterTrap" => "Teleporter Trap",
"BugZapper" => "Bug Zapper",
"FlashTurretUpdated" => "Flash Turret",
"FunctionalMicrowave" => "Functional Microwave",
"FanTrapAnimated" => "Industrial Fan",
"Bertha" => "Bertha",
"Seamine" => "Sea Mine",
"CageTrap" => "Cage Mine",
"BearTrap" => "Bear Trap",
_ => string.Join(" ", from s in hazardType.Split('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
where !string.IsNullOrEmpty(s)
select s into word
select char.ToUpper(word[0]) + word.Substring(1).ToLower()),
};
if (1 == 0)
{
}
return result;
}
private (int defaultCount, int maxCount) GetHazardLimits(string hazardType)
{
if (1 == 0)
{
}
(int, int) result = hazardType switch
{
"Landmine" => (5, 35),
"TurretContainer" => (5, 20),
"SpikeRoofTrapHazard" => (5, 25),
"Yeetmine" => (5, 30),
"TeleporterTrap" => (5, 20),
"BugZapper" => (5, 20),
"LaserTurret" => (5, 30),
"FlashTurretUpdated" => (5, 15),
"FunctionalMicrowave" => (5, 12),
"FanTrapAnimated" => (5, 12),
"Bertha" => (1, 10),
"Seamine" => (5, 35),
"CageTrap" => (5, 30),
"GravelBearTrap" => (5, 30),
"SnowBearTrap" => (5, 30),
"BoomBearTrap" => (5, 30),
"GrassBearTrap" => (5, 30),
_ => (5, 30),
};
if (1 == 0)
{
}
return result;
}
public void LoadCustomMoonConfigs()
{
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Expected O, but got Unknown
if ((Object)(object)StartOfRound.Instance == (Object)null || StartOfRound.Instance.levels == null)
{
LogWarning("StartOfRound levels not available at initialization.");
return;
}
HashSet<string> hashSet = DetectAvailableHazardTypes();
int num = 14;
SelectableLevel[] levels = StartOfRound.Instance.levels;
foreach (SelectableLevel val in levels)
{
string text = ((Object)val).name;
if (!string.IsNullOrEmpty(text))
{
text = text.Replace("level", "", StringComparison.OrdinalIgnoreCase);
text = char.ToUpper(text[0]) + text.Substring(1).ToLower();
}
if (text.Contains("Companybuilding") || text.Contains("Liquidation") || text.Contains("Gordion") || HazardSettingsDictionary.ContainsKey(text) || vanillaMoons.ContainsValue(text))
{
continue;
}
LogInfo("Detected new moon at startup: " + text + ". Setting up custom configs.");
Dictionary<string, HazardSettings> dictionary = new Dictionary<string, HazardSettings>();
string text2 = $"{num:D2}. {text}";
num++;
foreach (string item3 in hashSet)
{
string displayName = GetDisplayName(item3);
(int defaultCount, int maxCount) hazardLimits = GetHazardLimits(item3);
int item = hazardLimits.defaultCount;
int item2 = hazardLimits.maxCount;
HazardSettings hazardSettings = new HazardSettings
{
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, displayName + "_Enabled", true, "Enable " + displayName + " spawns on " + text),
SpawnCount = ((BaseUnityPlugin)this).Config.Bind<int>(text2, displayName + "_SpawnCount", item, new ConfigDescription("Number of " + displayName + " to spawn on " + text, (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, item2), Array.Empty<object>()))
};
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.AddConfig(hazardSettings.Enabled);
LethalConfigProxy.AddConfig(hazardSettings.SpawnCount);
}
dictionary.Add(item3, hazardSettings);
LogInfo("Configured hazard " + item3 + " for " + text);
}
HazardSettingsDictionary.Add(text, dictionary);
LogInfo("Successfully added " + text + " to custom configs during load.");
if (RandomHazardManager.Instance.IsEnabled())
{
LogInfo("Randomizing hazards for newly detected moon: " + text);
RandomHazardManager.Instance.RandomizeHazards(dictionary);
}
}
}
public static void LogInfo(string message)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogInfo((object)message);
}
}
public static void LogError(string message)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogError((object)message);
}
}
public static void LogDebug(string message)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogDebug((object)message);
}
}
public static void LogWarning(string message)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogWarning((object)message);
}
}
}
}