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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using On.RoR2;
using RoR2;
using UnityEngine;
[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 = "")]
[assembly: AssemblyCompany("SpawnDistanceStandardization")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpawnDistanceStandardization")]
[assembly: AssemblyTitle("SpawnDistanceStandardization")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SpawnDistanceStandardization;
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
[BepInPlugin("Samuel17.SpawnDistanceStandardization", "SpawnDistanceStandardization", "1.0.4")]
public class Main : BaseUnityPlugin
{
public static List<GameObject> masterPrefabsFar = new List<GameObject>();
public static List<GameObject> masterPrefabsStandard = new List<GameObject>();
public static List<GameObject> masterPrefabsClose = new List<GameObject>();
public static List<GameObject> minStagesMasterPrefabs = new List<GameObject>();
public static List<int> minStagesCounts = new List<int>();
public static string defaultDistance = null;
public static bool noStageCountRestrictions = false;
public static bool isFamilyEventActive = false;
public static ConfigEntry<string> farSpawns { get; private set; }
public static ConfigEntry<string> standardSpawns { get; private set; }
public static ConfigEntry<string> closeSpawns { get; private set; }
public static ConfigEntry<string> minStages { get; private set; }
public void Awake()
{
Log.Init(((BaseUnityPlugin)this).Logger);
farSpawns = ((BaseUnityPlugin)this).Config.Bind<string>("Spawn Distances", "Far", "JellyfishMaster, AcidLarvaMaster, MagmaWormMaster, ElectricWormMaster", "Specify the monsters that should be set to Far (70-120m) by entering their internal master names.\nMake sure to separate them with commas.\nAlso accepts EverythingElse as a value.");
standardSpawns = ((BaseUnityPlugin)this).Config.Bind<string>("Spawn Distances", "Standard", "BeetleMaster, ChildMaster, VerminMaster, ScorchlingMaster", "Specify the monsters that should be set to Standard (25-40m) by entering their internal master names.\nMake sure to separate them with commas.\nAlso accepts EverythingElse as a value.");
closeSpawns = ((BaseUnityPlugin)this).Config.Bind<string>("Spawn Distances", "Close", "", "Specify the monsters that should be set to Close (8-20m) by entering their internal master names.\nMake sure to separate them with commas.\nAlso accepts EverythingElse as a value.");
minStages = ((BaseUnityPlugin)this).Config.Bind<string>("Miscellaneous", "Minimum Stages", "", "Specify a monster's master name, followed by the lowest stage number it's allowed to appear in. Example: 'FlyingVerminMaster - 2' will make Blind Pests spawn on Stage 2 onwards.\nMake sure to separate the different entries with commas.\nAlternatively, enter 'NoRestrictions' to remove stage count restrictions for every monster.");
RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected O, but got Unknown
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Expected O, but got Unknown
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Expected O, but got Unknown
SortDistConfigs(farSpawns.Value, masterPrefabsFar, "Far");
SortDistConfigs(standardSpawns.Value, masterPrefabsStandard, "Standard");
SortDistConfigs(closeSpawns.Value, masterPrefabsClose, "Close");
SortMinStageConfigs(minStages.Value);
if (defaultDistance != null || masterPrefabsFar.Count > 0 || masterPrefabsStandard.Count > 0 || masterPrefabsClose.Count > 0)
{
ClassicStageInfo.RebuildCards += new hook_RebuildCards(AdjustSpawnDistances);
}
if (minStagesMasterPrefabs.Count > 0 || noStageCountRestrictions)
{
DirectorCard.IsAvailable += new hook_IsAvailable(AdjustMinimumStage);
ClassicStageInfo.BroadcastFamilySelection += new hook_BroadcastFamilySelection(TrackFamilyEvent);
ClassicStageInfo.Start += new hook_Start(ResetFamilyEvent);
}
});
}
private void SortDistConfigs(string spawns, List<GameObject> listPrefabs, string distance)
{
spawns = new string((from c in spawns.ToCharArray()
where !char.IsWhiteSpace(c)
select c).ToArray());
string[] array = spawns.Split(',');
string[] array2 = array;
foreach (string text in array2)
{
GameObject val = MasterCatalog.FindMasterPrefab(text);
if (Object.op_Implicit((Object)(object)val))
{
listPrefabs.Add(val);
Log.Message(((Object)val).name + " has been added to the " + distance + " spawn list.");
}
else if (text == "EverythingElse")
{
defaultDistance = distance;
Log.Message("Default spawn distance has been set to " + distance + ".");
}
}
}
private void SortMinStageConfigs(string spawns)
{
spawns = new string((from c in spawns.ToCharArray()
where !char.IsWhiteSpace(c)
select c).ToArray());
string[] array = spawns.Split(',');
string[] array2 = array;
foreach (string text in array2)
{
if (text == "NoRestrictions")
{
noStageCountRestrictions = true;
Log.Message("Cleared minimum stage restrictions for every monster.");
continue;
}
string[] array3 = text.Split('-');
if (array3.Length == 2 && int.TryParse(array3[1], out var result))
{
GameObject val = MasterCatalog.FindMasterPrefab(array3[0]);
if (Object.op_Implicit((Object)(object)val))
{
minStagesMasterPrefabs.Add(val);
minStagesCounts.Add(result);
Log.Message(((Object)val).name + " minimum stage set to " + result + ".");
}
}
}
}
private void AdjustSpawnDistances(orig_RebuildCards orig, ClassicStageInfo self, DirectorCardCategorySelection forcedMonsterCategory = null, DirectorCardCategorySelection forcedInteractableCategory = null)
{
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
orig.Invoke(self, forcedMonsterCategory, forcedInteractableCategory);
if (!((Object)(object)SceneCatalog.mostRecentSceneDef != (Object)(object)SceneCatalog.FindSceneDef("arena")) || self.monsterSelection == null || self.monsterSelection.choices == null)
{
return;
}
List<MasterIndex> list = new List<MasterIndex>(self.monsterSelection.choices.Length);
for (int i = 0; i < self.monsterSelection.Count; i++)
{
DirectorCard value = self.monsterSelection.choices[i].value;
SpawnCard spawnCard = value.GetSpawnCard();
if (!Object.op_Implicit((Object)(object)spawnCard))
{
continue;
}
if (defaultDistance != null)
{
switch (defaultDistance)
{
case "Far":
value.spawnDistance = (MonsterSpawnDistance)2;
break;
case "Standard":
value.spawnDistance = (MonsterSpawnDistance)0;
break;
case "Close":
value.spawnDistance = (MonsterSpawnDistance)1;
break;
}
}
if (masterPrefabsFar.Contains(spawnCard.prefab))
{
value.spawnDistance = (MonsterSpawnDistance)2;
Log.Message(((Object)spawnCard.prefab).name + " spawn distance set to Far.");
}
else if (masterPrefabsStandard.Contains(spawnCard.prefab))
{
value.spawnDistance = (MonsterSpawnDistance)0;
Log.Message(((Object)spawnCard.prefab).name + " spawn distance set to Standard.");
}
else if (masterPrefabsClose.Contains(spawnCard.prefab))
{
value.spawnDistance = (MonsterSpawnDistance)1;
Log.Message(((Object)spawnCard.prefab).name + " spawn distance set to Close.");
}
}
}
private bool AdjustMinimumStage(orig_IsAvailable orig, DirectorCard self)
{
RunArtifactManager instance = RunArtifactManager.instance;
if ((instance == null || !instance.IsArtifactEnabled(Artifacts.mixEnemyArtifactDef)) && !isFamilyEventActive && ((Object)(object)SceneCatalog.mostRecentSceneDef != (Object)(object)SceneCatalog.FindSceneDef("arena") || noStageCountRestrictions))
{
SpawnCard spawnCard = self.GetSpawnCard();
if (Object.op_Implicit((Object)(object)spawnCard))
{
if (minStagesMasterPrefabs.Contains(spawnCard.prefab))
{
int index = minStagesMasterPrefabs.IndexOf(spawnCard.prefab);
self.minimumStageCompletions = minStagesCounts[index] - 1;
}
else if (noStageCountRestrictions)
{
GameObject val = MasterCatalog.FindMasterPrefab(((Object)spawnCard.prefab).name);
if (Object.op_Implicit((Object)(object)val))
{
self.minimumStageCompletions = 0;
}
}
}
}
return orig.Invoke(self);
}
private IEnumerator TrackFamilyEvent(orig_BroadcastFamilySelection orig, ClassicStageInfo self, string familySelectionChatString)
{
isFamilyEventActive = true;
return orig.Invoke(self, familySelectionChatString);
}
private void ResetFamilyEvent(orig_Start orig, ClassicStageInfo self)
{
isFamilyEventActive = false;
orig.Invoke(self);
}
}