using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DunGen.Graph;
using HarmonyLib;
using LethalLib.Extras;
using LethalLib.Modules;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LethalExtension")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalExtension")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("94d2de4e-bed1-40e3-b759-cf53352d4930")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace ScoopysVarietyPack
{
[BepInPlugin("ScoopysVarietyPack", "Scoopy's Variety Pack", "0.2.2")]
public class plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Object))]
private class ItemGroupPatch
{
[HarmonyPatch("Equals")]
[HarmonyPrefix]
public static bool FixItemGroupEquals(ref bool __result, object __instance, object other)
{
ItemGroup val = (ItemGroup)((__instance is ItemGroup) ? __instance : null);
if (val != null)
{
ItemGroup val2 = (ItemGroup)((other is ItemGroup) ? other : null);
if (val2 != null)
{
__result = val.itemSpawnTypeName == val2.itemSpawnTypeName;
return false;
}
}
return true;
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("GenerateNewFloor")]
[HarmonyPostfix]
private static void FixTeleportDoors()
{
Instance.MLS.LogInfo((object)"Attempting to fix entrance teleporters.");
SpawnSyncedObject[] array = Object.FindObjectsOfType<SpawnSyncedObject>();
NetworkManager val = Object.FindObjectOfType<NetworkManager>();
bool flag = false;
bool flag2 = false;
int num = 0;
SpawnSyncedObject[] array2 = array;
foreach (SpawnSyncedObject val2 in array2)
{
if (((Object)val2.spawnPrefab).name == "EntranceTeleportA_LE")
{
NetworkPrefab val3 = val.NetworkConfig.Prefabs.m_Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "EntranceTeleportA");
if (val3 == null)
{
Instance.MLS.LogError((object)"Failed to find EntranceTeleportA prefab.");
return;
}
Instance.MLS.LogInfo((object)"Found EntranceTeleportA prefab.");
flag = true;
val2.spawnPrefab = val3.Prefab;
Instance.MLS.LogInfo((object)"Replaced EntranceTeleportA prefab.");
}
else if (((Object)val2.spawnPrefab).name == "EntranceTeleportB_LE")
{
NetworkPrefab val4 = val.NetworkConfig.Prefabs.m_Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "EntranceTeleportB");
if (val4 == null)
{
Instance.MLS.LogError((object)"Failed to find EntranceTeleportB prefab.");
return;
}
Instance.MLS.LogInfo((object)"Found EntranceTeleportB prefab.");
flag2 = true;
val2.spawnPrefab = val4.Prefab;
Instance.MLS.LogInfo((object)"Replaced EntranceTeleportB prefab.");
}
else if (((Object)val2.spawnPrefab).name == "VentPlaceholder")
{
NetworkPrefab val5 = val.NetworkConfig.Prefabs.m_Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "VentEntrance");
if (val5 == null)
{
Instance.MLS.LogError((object)"Failed to find VentEntrance prefab.");
return;
}
Instance.MLS.LogInfo((object)"Found and replaced VentEntrance prefab.");
num++;
val2.spawnPrefab = val5.Prefab;
}
}
if (!flag && !flag2)
{
Instance.MLS.LogError((object)"Failed to find entrance teleporters to replace.");
}
if (num == 0)
{
Instance.MLS.LogError((object)"No vents found to replace.");
}
else
{
Instance.MLS.LogInfo((object)$"{num} vents were successfully replacd.");
}
}
}
private const string modGUID = "ScoopysVarietyPack";
private const string modName = "Scoopy's Variety Pack";
private const string modVersion = "0.2.2";
private static plugin Instance;
private readonly Harmony harmony = new Harmony("ScoopysVarietyPack");
private ConfigEntry<int> configCastleRarity;
private ConfigEntry<string> configCastleMoons;
private ConfigEntry<bool> configGuaranteeCastle;
private ConfigEntry<int> configGuitarRarity;
private ConfigEntry<int> configFireaxeRarity;
private string[] MoonConfigs = new string[11]
{
"all", "paid", "unpaid", "titan", "rend", "dine", "vow", "experimentation", "assurance", "offense",
"march"
};
internal ManualLogSource MLS;
public static AssetBundle Assets;
private void Awake()
{
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Expected O, but got Unknown
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Expected O, but got Unknown
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Expected O, but got Unknown
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Expected O, but got Unknown
//IL_0304: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
MLS = Logger.CreateLogSource("ScoopysVarietyPack");
string? directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
configCastleRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Castle Interior", "CastleDungeonSpawnChance", 300, new ConfigDescription("Adjusts likelihood of the castle dungeon spawning. Higher values increases the chance of spawning. At the max value of 300, the spawn chance would be approx 50% on vanilla moons", (AcceptableValueBase)new AcceptableValueRange<int>(0, 300), Array.Empty<object>()));
configCastleMoons = ((BaseUnityPlugin)this).Config.Bind<string>("Castle Interior", "CastleDungeonMoons", "all", new ConfigDescription("The moon(s) that the castle dungeon can spawn on. Invalid valueas will prevent spawning", (AcceptableValueBase)new AcceptableValueList<string>(MoonConfigs), Array.Empty<object>()));
configGuaranteeCastle = ((BaseUnityPlugin)this).Config.Bind<bool>("Castle Interior", "CastleDungeonGuaranteed", false, new ConfigDescription("If enabled, the castle dungeon will be effectively guaranteed to spawn on moons where it can spawn as per CastleDungeonMoons.", (AcceptableValueBase)null, Array.Empty<object>()));
configGuitarRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "GuitarRarity", 10, new ConfigDescription("Frequency of Guitar scrap spawning. Higher values are more common. Set to 0 to disable spawns.", (AcceptableValueBase)new AcceptableValueRange<int>(0, 300), Array.Empty<object>()));
configFireaxeRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "FireaxeRarity", 5, new ConfigDescription("Frequency of Fire Axe scrap spawning. Higher values are more common. Set to 0 to disable spawns.", (AcceptableValueBase)new AcceptableValueRange<int>(0, 300), Array.Empty<object>()));
Assets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "ScoopysVarietyPack"));
if ((Object)(object)Assets == (Object)null)
{
MLS.LogError((object)"Failed to unpack ScoopysVarietyPack assetbundle.");
}
Item val = Assets.LoadAsset<Item>("Assets/ScoopysVarietyPack/ScrapAssets/Guitar/WeezerGuitar.asset");
Item val2 = Assets.LoadAsset<Item>("Assets/ScoopysVarietyPack/ScrapAssets/FireAxe/FireAxe.asset");
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
{
MLS.LogError((object)"Failed to load all items");
}
else
{
NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
Items.RegisterScrap(val, configGuitarRarity.Value, (LevelTypes)(-1));
Items.RegisterScrap(val2, configFireaxeRarity.Value, (LevelTypes)896);
MLS.LogInfo((object)"Custom Scrap Loaded Successfully");
}
GameObject val3 = Assets.LoadAsset<GameObject>("Assets/ScoopysVarietyPack/CastleAssets/Prefabs/RoundWoodDoor.prefab");
GameObject val4 = Assets.LoadAsset<GameObject>("Assets/ScoopysVarietyPack/CastleAssets/Prefabs/CellDoorFull.prefab");
if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null)
{
MLS.LogError((object)"Failed to load a door asset.");
return;
}
NetworkPrefabs.RegisterNetworkPrefab(val3);
NetworkPrefabs.RegisterNetworkPrefab(val4);
MLS.LogInfo((object)"Unpacking Castle Dungeon Assets...");
DungeonFlow val5 = Assets.LoadAsset<DungeonFlow>("Assets/ScoopysVarietyPack/CastleAssets/CastleFlow.asset");
if ((Object)(object)val5 == (Object)null)
{
MLS.LogError((object)"Failed to load Castle Dungeon Flow.");
return;
}
MLS.LogInfo((object)"Loading dungeon defs...");
DungeonDef obj = ScriptableObject.CreateInstance<DungeonDef>();
obj.dungeonFlow = val5;
obj.rarity = (configGuaranteeCastle.Value ? 99999 : configCastleRarity.Value);
MLS.LogInfo((object)"Registering dungeon flows");
Dungeon.AddDungeon(obj, LevelsFromConfig(configCastleMoons.Value.ToLower()));
harmony.PatchAll(typeof(plugin));
harmony.PatchAll(typeof(RoundManagerPatch));
harmony.PatchAll(typeof(ItemGroupPatch));
MLS.LogInfo((object)"Initialised Successfully");
}
private LevelTypes LevelsFromConfig(string configValue)
{
switch (configValue)
{
case "all":
return (LevelTypes)956;
case "paid":
return (LevelTypes)896;
case "unpaid":
return (LevelTypes)60;
case "titan":
return (LevelTypes)512;
case "offense":
return (LevelTypes)32;
case "vow":
return (LevelTypes)16;
case "assurance":
return (LevelTypes)8;
case "experimentation":
return (LevelTypes)4;
case "dine":
return (LevelTypes)256;
case "rend":
return (LevelTypes)128;
case "march":
return (LevelTypes)64;
default:
MLS.LogError((object)"Invalid config value for dungeon moon spawning. Config value must match the preset values");
return (LevelTypes)1;
}
}
}
}