using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MenuLib;
using Microsoft.CodeAnalysis;
using SpawnManager.Extensions;
using SpawnManager.Managers;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SpawnManager")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+118c4261cc02cebbf75afa80e80b762428a4cdfb")]
[assembly: AssemblyProduct("SpawnManager")]
[assembly: AssemblyTitle("SpawnManager")]
[assembly: AssemblyVersion("0.1.0.0")]
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;
}
}
}
namespace SpawnManager
{
[BepInPlugin("soundedsquash.spawnmanager", "Enemy/Valuable Spawn Manager", "0.1.0.0")]
public class MuteToggleBase : BaseUnityPlugin
{
private const string PluginGuid = "soundedsquash.spawnmanager";
private const string PluginName = "Enemy/Valuable Spawn Manager";
private const string PluginVersion = "0.1.0.0";
private readonly Harmony _harmony = new Harmony("soundedsquash.spawnmanager");
private static readonly ManualLogSource ManualLogSource = Logger.CreateLogSource("soundedsquash.spawnmanager");
public void Awake()
{
Settings.Initialize(((BaseUnityPlugin)this).Config, ManualLogSource);
MenuModManager.Initialize();
_harmony.PatchAll();
ManualLogSource.LogInfo((object)"Enemy/Valuable Spawn Manager loaded");
}
}
public static class Settings
{
public static ConfigEntry<string> DisabledEnemies { get; set; }
public static ConfigEntry<string> DisabledValuables { get; set; }
public static ManualLogSource Logger { get; private set; }
internal static void Initialize(ConfigFile config, ManualLogSource logger)
{
Logger = logger;
DisabledEnemies = config.Bind<string>("Enemies", "DisabledList", "", "Comma-separated list of enemy names to disable. (e.g. \"Apex Predator,Headman\")");
DisabledValuables = config.Bind<string>("Valuables", "DisabledList", "", "Comma-separated list of valuable names to disable. (e.g. \"Valuable Television,Valuable Diamond Display\")");
}
public static List<string> GetDisabledEnemyNames()
{
return ConvertStringToList(DisabledEnemies.Value);
}
private static List<string> ConvertStringToList(string str)
{
if (string.IsNullOrEmpty(str))
{
return new List<string>();
}
return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
}
public static void UpdateEnemyEntry(string enemyName, bool enabled)
{
List<string> disabledEnemyNames = GetDisabledEnemyNames();
if (enabled)
{
disabledEnemyNames.Remove(enemyName);
}
else if (!disabledEnemyNames.Contains(enemyName))
{
disabledEnemyNames.Add(enemyName);
}
SaveEnemyList(disabledEnemyNames);
}
public static void SaveEnemyList(List<string> enemyNames)
{
DisabledEnemies.Value = string.Join(",", enemyNames);
}
public static bool IsEnemyEnabled(string enemyName)
{
return !GetDisabledEnemyNames().Contains(enemyName);
}
public static List<string> GetDisabledValuableNames()
{
return ConvertStringToList(DisabledValuables.Value);
}
public static void UpdateValuableEntry(string valuableName, bool enabled)
{
List<string> disabledValuableNames = GetDisabledValuableNames();
if (enabled)
{
disabledValuableNames.Remove(valuableName);
}
else if (!disabledValuableNames.Contains(valuableName))
{
disabledValuableNames.Add(valuableName);
}
SaveValuableList(disabledValuableNames);
}
public static void SaveValuableList(List<string> valuableNames)
{
DisabledValuables.Value = string.Join(",", valuableNames);
}
public static bool IsValuableEnabled(string valuableName)
{
return !GetDisabledValuableNames().Contains(valuableName);
}
}
}
namespace SpawnManager.Patches
{
[HarmonyPatch(typeof(EnemyDirector))]
public static class EnemyDirectorPatches
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void EnemyDirectorStartPostfix()
{
if (!SemiFunc.RunIsLevel())
{
EnemyManager.RefreshAllEnemyNames();
return;
}
Settings.Logger.LogDebug((object)"Not on menu level, removing enemies.");
EnemyManager.RemoveEnemies();
}
}
[HarmonyPatch(typeof(RunManager))]
public static class RunManagerPatches
{
[HarmonyPatch("Awake")]
[HarmonyPrefix]
[HarmonyPriority(0)]
private static void RunManagerStartPrefix()
{
if (SemiFunc.MenuLevel())
{
ValuableManager.RestoreValuableObjects();
return;
}
Settings.Logger.LogDebug((object)"Removing valuables.");
ValuableManager.RemoveValuables();
}
}
}
namespace SpawnManager.Managers
{
public static class EnemyManager
{
public static Dictionary<string, IEnumerable<GameObject>> EnemySpawnList = new Dictionary<string, IEnumerable<GameObject>>();
public static void RefreshAllEnemyNames()
{
EnemyDirector instance = EnemyDirector.instance;
EnemySpawnList = (from so in instance.enemiesDifficulty1.Concat(instance.enemiesDifficulty2).Concat(instance.enemiesDifficulty3).SelectMany((EnemySetup ed) => ed.spawnObjects)
group so by ((Object)so).GetInstanceID() into so
select so.First() into so
where (Object)(object)so.GetComponent<EnemyParent>() != (Object)null
group so by so.GetComponent<EnemyParent>().enemyName).ToDictionary((IGrouping<string, GameObject> g) => g.Key, (IGrouping<string, GameObject> g) => g.AsEnumerable());
}
public static void RemoveEnemies()
{
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Expected O, but got Unknown
List<string> disabledEnemyNames = Settings.GetDisabledEnemyNames();
if (disabledEnemyNames.Count == 0)
{
return;
}
if (EnemySpawnList.Count == 0)
{
RefreshAllEnemyNames();
}
EnemyDirector instance = EnemyDirector.instance;
List<GameObject> spawnObjectsToRemove = EnemySpawnList.Where<KeyValuePair<string, IEnumerable<GameObject>>>((KeyValuePair<string, IEnumerable<GameObject>> kvp) => disabledEnemyNames.Contains(kvp.Key)).SelectMany((KeyValuePair<string, IEnumerable<GameObject>> kvp) => kvp.Value).ToList();
Settings.Logger.LogDebug((object)string.Format("Enemies to disable: {0} | Removing {1} spawnObjects from enemy director.", string.Join(", ", disabledEnemyNames), spawnObjectsToRemove.Count));
List<EnemySetup> list = (from s in instance.enemiesDifficulty1.Concat(instance.enemiesDifficulty2).Concat(instance.enemiesDifficulty3)
where s.spawnObjects.Any((GameObject so) => spawnObjectsToRemove.Contains(so))
select s).ToList();
for (int num = list.Count - 1; num >= 0; num--)
{
EnemySetup val = list[num];
Settings.Logger.LogDebug((object)("Removed enemy setup " + ((Object)val).name));
instance.enemiesDifficulty1.Remove(val);
instance.enemiesDifficulty2.Remove(val);
instance.enemiesDifficulty3.Remove(val);
}
EnemySetup val2 = ScriptableObject.CreateInstance<EnemySetup>();
val2.spawnObjects = new List<GameObject>
{
new GameObject("EmptyEnemy")
};
if (instance.enemiesDifficulty1.Count == 0)
{
instance.enemiesDifficulty1.Add(val2);
}
if (instance.enemiesDifficulty2.Count == 0)
{
instance.enemiesDifficulty2.Add(val2);
}
if (instance.enemiesDifficulty3.Count == 0)
{
instance.enemiesDifficulty3.Add(val2);
}
}
}
public static class MenuModManager
{
private static REPOButton _currentPageButton;
public static void Initialize()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
MenuAPI.AddElementToMainMenu((REPOElement)new REPOButton("Spawn Manager", (Action)delegate
{
((REPOSimplePage)CreatePopup()).OpenPage(false);
}), new Vector2(550f, 22f));
}
private static REPOPopupPage CreatePopup()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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_0070: Expected O, but got Unknown
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
REPOPopupPage menu = new REPOPopupPage("Spawn Manager", (Action<REPOPopupPage>)null).SetBackgroundDimming(true).SetMaskPadding((Padding?)new Padding(0f, 70f, 20f, 50f));
((REPOSimplePage)menu).AddElementToPage((REPOElement)new REPOButton("Back", (Action)delegate
{
((Action)delegate
{
((REPOSimplePage)menu).ClosePage(true);
})();
}), new Vector2(77f, 34f));
CreateEnemyPage(out REPOButton modButton);
menu.AddElementToScrollView((REPOElement)(object)modButton, new Vector2(0f, -80f));
CreateValuablePage(out REPOButton modButton2);
menu.AddElementToScrollView((REPOElement)(object)modButton2, new Vector2(0f, -114f));
return menu;
}
private static void CreateEnemyPage(out REPOButton modButton)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_003d: 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_0044: Expected O, but got Unknown
//IL_0045: Expected O, but got Unknown
REPOPopupPage enemyPage2 = new REPOPopupPage("Enemies", (Action<REPOPopupPage>)delegate(REPOPopupPage enemyPage)
{
//IL_000b: 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_0041: Unknown result type (might be due to invalid IL or missing references)
enemyPage.SetPosition(new Vector2(510f, 190.6f));
enemyPage.SetSize(new Vector2(300f, 342f));
enemyPage.SetMaskPadding((Padding?)new Padding(0f, 70f, 0f, 50f));
});
REPOButton val = new REPOButton("Enemies", (Action)null);
REPOButton val2 = val;
modButton = val;
REPOButton modButtonTemp = val2;
modButton.SetOnClick((Action)delegate
{
if (_currentPageButton != modButtonTemp)
{
((Action)delegate
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Expected O, but got Unknown
MenuManager.instance.PageCloseAllAddedOnTop();
enemyPage2.ClearButtons();
_currentPageButton = modButtonTemp;
REPOButton val3 = new REPOButton("Enable All", (Action)null);
val3.SetOnClick((Action)delegate
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
MenuAPI.OpenPopup("Enable All", Color.red, "Enable all enemies?", "Yes", (Action)delegate
{
((ConfigEntryBase)Settings.DisabledEnemies).BoxedValue = ((ConfigEntryBase)Settings.DisabledEnemies).DefaultValue;
_currentPageButton = null;
modButtonTemp.onClick();
}, "No", (Action)null);
});
REPOButton val4 = new REPOButton("Disable All", (Action)null);
val4.SetOnClick((Action)delegate
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
MenuAPI.OpenPopup("Disable All", Color.red, "Disable all valuables?", "Yes", (Action)delegate
{
Settings.DisabledEnemies.Value = string.Join(',', EnemyManager.EnemySpawnList.Select<KeyValuePair<string, IEnumerable<GameObject>>, string>((KeyValuePair<string, IEnumerable<GameObject>> kvp) => kvp.Key));
_currentPageButton = null;
modButtonTemp.onClick();
}, "No", (Action)null);
});
((REPOSimplePage)enemyPage2).AddElementToPage((REPOElement)(object)val3, new Vector2(360f, 25f));
((REPOSimplePage)enemyPage2).AddElementToPage((REPOElement)(object)val4, new Vector2(527f, 25f));
EnemyManager.RefreshAllEnemyNames();
Settings.Logger.LogDebug((object)"Refreshed enemy names for menu.");
List<string> list = EnemyManager.EnemySpawnList.Keys.ToList();
list.Sort();
float num = -80f;
foreach (string name in list)
{
enemyPage2.AddElementToScrollView((REPOElement)new REPOToggle(name, (Action<bool>)delegate(bool b)
{
Settings.UpdateEnemyEntry(name, b);
}, "ON", "OFF", Settings.IsEnemyEnabled(name)), new Vector2(120f, num));
num -= 30f;
}
((REPOSimplePage)enemyPage2).OpenPage(true);
})();
}
});
}
private static void CreateValuablePage(out REPOButton modButton)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_003d: 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_0044: Expected O, but got Unknown
//IL_0045: Expected O, but got Unknown
REPOPopupPage valuablePage2 = new REPOPopupPage("Valuables", (Action<REPOPopupPage>)delegate(REPOPopupPage valuablePage)
{
//IL_000b: 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_0041: Unknown result type (might be due to invalid IL or missing references)
valuablePage.SetPosition(new Vector2(510f, 190.6f));
valuablePage.SetSize(new Vector2(300f, 342f));
valuablePage.SetMaskPadding((Padding?)new Padding(0f, 70f, 0f, 50f));
});
REPOButton val = new REPOButton("Valuables", (Action)null);
REPOButton val2 = val;
modButton = val;
REPOButton modButtonTemp = val2;
modButton.SetOnClick((Action)delegate
{
if (_currentPageButton != modButtonTemp)
{
((Action)delegate
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Expected O, but got Unknown
MenuManager.instance.PageCloseAllAddedOnTop();
valuablePage2.ClearButtons();
_currentPageButton = modButtonTemp;
REPOButton val3 = new REPOButton("Enable All", (Action)null);
val3.SetOnClick((Action)delegate
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
MenuAPI.OpenPopup("Enable All", Color.red, "Enable all valuables?", "Yes", (Action)delegate
{
((ConfigEntryBase)Settings.DisabledValuables).BoxedValue = ((ConfigEntryBase)Settings.DisabledValuables).DefaultValue;
_currentPageButton = null;
modButtonTemp.onClick();
}, "No", (Action)null);
});
REPOButton val4 = new REPOButton("Disable All", (Action)null);
val4.SetOnClick((Action)delegate
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
MenuAPI.OpenPopup("Disable All", Color.red, "Disable all valuables?", "Yes", (Action)delegate
{
Settings.DisabledValuables.Value = string.Join(',', ValuableManager.ValuableList.Select((ValuableObject vo) => ((Object)vo).name));
_currentPageButton = null;
modButtonTemp.onClick();
}, "No", (Action)null);
});
((REPOSimplePage)valuablePage2).AddElementToPage((REPOElement)(object)val3, new Vector2(360f, 25f));
((REPOSimplePage)valuablePage2).AddElementToPage((REPOElement)(object)val4, new Vector2(527f, 25f));
ValuableManager.RefreshAllValuables();
Settings.Logger.LogDebug((object)$"Refreshed {ValuableManager.ValuableList.Count} valuable names for menu.");
IOrderedEnumerable<ValuableObject> orderedEnumerable = ValuableManager.ValuableList.OrderBy((ValuableObject vo) => ((Object)vo).name);
float num = -80f;
foreach (ValuableObject valuableObject in orderedEnumerable)
{
valuablePage2.AddElementToScrollView((REPOElement)new REPOToggle(valuableObject.FriendlyName(), (Action<bool>)delegate(bool b)
{
Settings.UpdateValuableEntry(((Object)valuableObject).name, b);
}, "ON", "OFF", Settings.IsValuableEnabled(((Object)valuableObject).name)), new Vector2(120f, num));
num -= 30f;
}
((REPOSimplePage)valuablePage2).OpenPage(true);
})();
}
});
}
}
public static class ValuableManager
{
public static List<ValuableObject> ValuableList = new List<ValuableObject>();
public static Dictionary<string, GameObject> RemovedList = new Dictionary<string, GameObject>();
public static Dictionary<string, LevelValuables> LevelValuablesDictionary = new Dictionary<string, LevelValuables>();
public static void RefreshAllValuables()
{
if ((Object)(object)RunManager.instance != (Object)null && RunManager.instance.levels != null)
{
ValuableList = (from go in RunManager.instance.levels.SelectMany(delegate(Level l)
{
IEnumerable<LevelValuables> valuablePresets = l.ValuablePresets;
return valuablePresets ?? Enumerable.Empty<LevelValuables>();
}).SelectMany(delegate(LevelValuables lv)
{
IEnumerable<GameObject> enumerable = lv?.tiny;
IEnumerable<GameObject> first = enumerable ?? Enumerable.Empty<GameObject>();
enumerable = lv?.small;
IEnumerable<GameObject> first2 = first.Concat(enumerable ?? Enumerable.Empty<GameObject>());
enumerable = lv?.medium;
IEnumerable<GameObject> first3 = first2.Concat(enumerable ?? Enumerable.Empty<GameObject>());
enumerable = lv?.big;
IEnumerable<GameObject> first4 = first3.Concat(enumerable ?? Enumerable.Empty<GameObject>());
enumerable = lv?.wide;
IEnumerable<GameObject> first5 = first4.Concat(enumerable ?? Enumerable.Empty<GameObject>());
enumerable = lv?.tall;
IEnumerable<GameObject> first6 = first5.Concat(enumerable ?? Enumerable.Empty<GameObject>());
enumerable = lv?.veryTall;
return first6.Concat(enumerable ?? Enumerable.Empty<GameObject>());
})
select (go == null) ? null : go.GetComponent<ValuableObject>() into vo
where (Object)(object)vo != (Object)null
select vo).Distinct().ToList();
}
else
{
ValuableList = new List<ValuableObject>();
}
}
public static void RemoveValuables()
{
List<string> disabledValuableNames = Settings.GetDisabledValuableNames();
if (disabledValuableNames.Count != 0)
{
RefreshAllValuables();
List<ValuableObject> list = ValuableList.Where((ValuableObject valuableObject) => disabledValuableNames.Contains(((Object)valuableObject).name)).ToList();
Settings.Logger.LogDebug((object)string.Format("Valuables to disable: {0} | Removing {1} valuables from levels.", string.Join(", ", disabledValuableNames), list.Count));
RemoveValuableObjects(list);
}
}
private static void RemoveValuableObjects(List<ValuableObject> valuableObjectsToRemove)
{
if ((Object)(object)RunManager.instance == (Object)null || RunManager.instance.levels == null)
{
return;
}
foreach (LevelValuables item in RunManager.instance.levels.SelectMany((Level level) => level.ValuablePresets))
{
RemoveValuableObjectsFromList(item.tiny, valuableObjectsToRemove);
RemoveValuableObjectsFromList(item.small, valuableObjectsToRemove);
RemoveValuableObjectsFromList(item.medium, valuableObjectsToRemove);
RemoveValuableObjectsFromList(item.big, valuableObjectsToRemove);
RemoveValuableObjectsFromList(item.wide, valuableObjectsToRemove);
RemoveValuableObjectsFromList(item.tall, valuableObjectsToRemove);
RemoveValuableObjectsFromList(item.veryTall, valuableObjectsToRemove);
}
}
private static void RemoveValuableObjectsFromList(List<GameObject> list, List<ValuableObject> valuableObjectsToRemove)
{
List<ValuableObject> valuableObjectsToRemove2 = valuableObjectsToRemove;
int count = list.Count;
foreach (GameObject item in from obj in list.ToList()
where valuableObjectsToRemove2.Contains(obj.GetComponent<ValuableObject>())
select obj)
{
Settings.Logger.LogDebug((object)("Removed valuable object " + ((Object)item).name + " from list."));
list.Remove(item);
}
if (count - list.Count > 0)
{
Settings.Logger.LogDebug((object)$"Removed {count - list.Count} valuable objects from list.");
}
}
public static void RestoreValuableObjects()
{
}
}
}
namespace SpawnManager.Extensions
{
public static class Extensions
{
public static string FriendlyName(this ValuableObject valuableObject)
{
return ((Object)valuableObject).name.Replace("Valuable ", "");
}
public static string GetKey(this Level level)
{
return ((Object)level).name;
}
public static string GetKey(this LevelValuables levelValuables)
{
return ((Object)levelValuables).name;
}
}
}