Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BiomeProgressionControl v1.0.0
plugins\BiomeGate.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; 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("BiomeGate")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("BiomeGate")] [assembly: AssemblyTitle("BiomeGate")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BiomeGate { [BepInPlugin("com.sophie.biomegate", "Biome Progression Control", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "com.sophie.biomegate"; public const string Name = "Biome Progression Control"; public const string Version = "1.0.0"; internal static ManualLogSource Log; private static readonly Dictionary<Biome, ConfigEntry<bool>> Unlocked = new Dictionary<Biome, ConfigEntry<bool>>(); private static readonly Dictionary<Biome, ConfigEntry<bool>> BossSummoningAllowed = new Dictionary<Biome, ConfigEntry<bool>>(); private static readonly HashSet<string> LoggedBlockedSpawnPaths = new HashSet<string>(); private Harmony _harmony; private void Awake() { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; BindBiome((Biome)1, defaultUnlocked: true, true); BindBiome((Biome)8, defaultUnlocked: false, false); BindBiome((Biome)2, defaultUnlocked: false, false); BindBiome((Biome)4, defaultUnlocked: false, false); BindBiome((Biome)16, defaultUnlocked: false, false); BindBiome((Biome)512, defaultUnlocked: false, false); BindBiome((Biome)32, defaultUnlocked: false, false); BindBiome((Biome)64, defaultUnlocked: false, false); BindBiome((Biome)256, defaultUnlocked: true); _harmony = new Harmony("com.sophie.biomegate"); ApplyPatchesIndividually(); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Biome access settings: " + FormatBiomeSettings())); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Biome Progression Control loaded. Server admins can change biome access live in the in-game Configuration Manager."); } private void ApplyPatchesIndividually() { Type[] types = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type type in types) { if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0) { try { _harmony.CreateClassProcessor(type).Patch(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to apply Biome Progression Control patch " + type.FullName + ": " + ex)); } } } } private unsafe void BindBiome(Biome biome, bool defaultUnlocked, bool? defaultBossSummoningAllowed = null) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) ConfigurationManagerAttributes val = new ConfigurationManagerAttributes { IsAdminOnly = true }; ConfigDescription val2 = new ConfigDescription("When enabled, players may use actions in this biome and its world spawners may spawn creatures. Changes synchronize live from the server.", (AcceptableValueBase)null, new object[1] { val }); string text = ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString(); Unlocked[biome] = ((BaseUnityPlugin)this).Config.Bind<bool>("Biome access", text, defaultUnlocked, val2); if (defaultBossSummoningAllowed.HasValue) { ConfigDescription val3 = new ConfigDescription("When enabled, boss offerings and boss progression gates in this biome are allowed, including the Queen’s Sealbreaker entrance. This setting is separate from biome access and synchronizes live from the server.", (AcceptableValueBase)null, new object[1] { val }); BossSummoningAllowed[biome] = ((BaseUnityPlugin)this).Config.Bind<bool>("Boss summoning", text, defaultBossSummoningAllowed.Value, val3); } } internal static bool IsUnlocked(Biome biome) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) foreach (KeyValuePair<Biome, ConfigEntry<bool>> item in Unlocked) { if ((biome & item.Key) != 0 && !item.Value.Value) { return false; } } return true; } private static string FormatBiomeSettings() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) List<string> list = new List<string>(); foreach (KeyValuePair<Biome, ConfigEntry<bool>> item in Unlocked) { list.Add(((object)item.Key/*cast due to .constrained prefix*/).ToString() + "=" + (item.Value.Value ? "unlocked" : "locked")); } return string.Join(", ", list.ToArray()); } internal unsafe static void LogSpawnDecision(string source, Vector3 position, Biome biome, bool blocked) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) string item = source + ":" + ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString(); if (Log != null && LoggedBlockedSpawnPaths.Add(item)) { ManualLogSource log = Log; string[] obj = new string[7] { blocked ? "Blocked " : "Allowed ", source, " spawn in ", ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString(), " at ", null, null }; Vector3 val = position; obj[5] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString(); obj[6] = "."; log.LogInfo((object)string.Concat(obj)); } } internal unsafe static void LogBlockedLoot(Vector3 position, Biome biome) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) string item = "Loot:" + ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString(); if (Log != null && LoggedBlockedSpawnPaths.Add(item)) { ManualLogSource log = Log; string[] obj = new string[5] { "Suppressed creature loot in locked biome ", ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString(), " at ", null, null }; Vector3 val = position; obj[3] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString(); obj[4] = "."; log.LogInfo((object)string.Concat(obj)); } } internal static bool CanSummonBoss(Biome biome) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (BossSummoningAllowed.TryGetValue(biome, out var value)) { return value.Value; } return false; } private void OnDestroy() { if (_harmony != null) { _harmony.UnpatchSelf(); } } } internal static class BiomeRestriction { internal static bool IsLocked(Player player) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)player != (Object)null) { return IsLocked(((Component)player).transform.position); } return false; } internal static bool IsLocked(Vector3 position) { //IL_000c: 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) if (WorldGenerator.instance != null) { return !Plugin.IsUnlocked(WorldGenerator.instance.GetBiome(position)); } return false; } } [HarmonyPatch(typeof(Player), "Interact", new Type[] { typeof(GameObject), typeof(bool), typeof(bool) })] internal static class LockedBiomeInteractionPatch { private static bool Prefix(Player __instance) { return !BiomeRestriction.IsLocked(__instance); } } [HarmonyPatch(typeof(Humanoid), "StartAttack")] internal static class LockedBiomeAttackPatch { private static bool Prefix(Humanoid __instance) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (!((Object)(object)val == (Object)null)) { return !BiomeRestriction.IsLocked(val); } return true; } } [HarmonyPatch(typeof(Humanoid), "UseItem")] internal static class LockedBiomeItemUsePatch { private static bool Prefix(Humanoid __instance) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (!((Object)(object)val == (Object)null)) { return !BiomeRestriction.IsLocked(val); } return true; } } [HarmonyPatch(typeof(Humanoid), "Pickup", new Type[] { typeof(GameObject), typeof(bool), typeof(bool) })] internal static class LockedBiomePickupPatch { private static bool Prefix(Humanoid __instance) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (!((Object)(object)val == (Object)null)) { return !BiomeRestriction.IsLocked(val); } return true; } } [HarmonyPatch(typeof(Player), "AutoPickup")] internal static class LockedBiomeAutoPickupPatch { private static bool Prefix(Player __instance) { return !BiomeRestriction.IsLocked(__instance); } } [HarmonyPatch(typeof(ItemDrop), "Pickup")] internal static class LockedBiomeItemMagnetPickupPatch { private static bool Prefix(ItemDrop __instance, Humanoid character) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)character == (Object)null) { return true; } return !BiomeRestriction.IsLocked(((Component)__instance).transform.position); } } [HarmonyPatch(typeof(Player), "PlacePiece")] internal static class LockedBiomeBuildPatch { private static bool Prefix(Player __instance) { return !BiomeRestriction.IsLocked(__instance); } } [HarmonyPatch(typeof(Player), "RemovePiece")] internal static class LockedBiomeDismantlePatch { private static bool Prefix(Player __instance) { return !BiomeRestriction.IsLocked(__instance); } } [HarmonyPatch(typeof(Minimap), "Explore", new Type[] { typeof(Vector3), typeof(float) })] internal static class LockedBiomeMapExplorePatch { private static bool Prefix(Vector3 __0) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return !BiomeRestriction.IsLocked(__0); } } [HarmonyPatch] internal static class LockedBiomePlayerDamagePatch { private static readonly string[] DamageableTypes = new string[6] { "Character", "Destructible", "WearNTear", "TreeBase", "MineRock", "MineRock5" }; private static IEnumerable<MethodBase> TargetMethods() { HashSet<MethodBase> seen = new HashSet<MethodBase>(); string[] damageableTypes = DamageableTypes; for (int i = 0; i < damageableTypes.Length; i++) { Type type = AccessTools.TypeByName(damageableTypes[i]); if (!(type == null)) { MethodBase methodBase = AccessTools.Method(type, "Damage", new Type[1] { typeof(HitData) }, (Type[])null); if (methodBase != null && seen.Add(methodBase)) { yield return methodBase; } } } } private static bool Prefix(object __instance, HitData __0) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) if (__0 == null) { return true; } Character attacker = __0.GetAttacker(); Player val = (Player)(object)((attacker is Player) ? attacker : null); if ((Object)(object)val == (Object)null) { return true; } Component val2 = (Component)((__instance is Component) ? __instance : null); if ((Object)(object)val2 == (Object)null) { return true; } if (!BiomeRestriction.IsLocked(val)) { return !BiomeRestriction.IsLocked(val2.transform.position); } return false; } } [HarmonyPatch] internal static class BiomeSpawnGatePatch { private static IEnumerable<MethodBase> TargetMethods() { foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeof(SpawnSystem))) { if (!(declaredMethod.Name != "Spawn")) { ParameterInfo[] parameters = declaredMethod.GetParameters(); if (parameters.Length >= 2 && parameters[1].ParameterType == typeof(Vector3)) { yield return declaredMethod; } } } } private static bool Prefix(Vector3 __1) { //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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (WorldGenerator.instance == null) { return true; } Biome biome = WorldGenerator.instance.GetBiome(__1); bool flag = Plugin.IsUnlocked(biome); Plugin.LogSpawnDecision("SpawnSystem.Spawn", __1, biome, !flag); return flag; } } [HarmonyPatch] internal static class LockedBiomeLocalSpawnerPatch { private static IEnumerable<MethodBase> TargetMethods() { Type creatureSpawner = AccessTools.TypeByName("CreatureSpawner"); foreach (MethodBase item in MethodsNamed(creatureSpawner, "UpdateSpawner")) { yield return item; } foreach (MethodBase item2 in MethodsNamed(creatureSpawner, "Spawn")) { yield return item2; } Type spawnArea = AccessTools.TypeByName("SpawnArea"); foreach (MethodBase item3 in MethodsNamed(spawnArea, "UpdateSpawn")) { yield return item3; } foreach (MethodBase item4 in MethodsNamed(spawnArea, "SpawnOne")) { yield return item4; } } private static bool Prefix(Component __instance) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || WorldGenerator.instance == null) { return true; } Vector3 position = __instance.transform.position; Biome biome = WorldGenerator.instance.GetBiome(position); bool flag = Plugin.IsUnlocked(biome); Plugin.LogSpawnDecision(((object)__instance).GetType().Name, position, biome, !flag); return flag; } private static IEnumerable<MethodBase> MethodsNamed(Type type, string name) { if (type == null) { yield break; } foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(type)) { if (declaredMethod.Name == name) { yield return declaredMethod; } } } } [HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")] internal static class LockedBiomeCreatureLootPatch { [HarmonyPostfix] [HarmonyPriority(0)] private static void Postfix(CharacterDrop __instance, ref List<KeyValuePair<GameObject, int>> __result) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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) //IL_0046: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || __result == null) { return; } Character component = ((Component)__instance).GetComponent<Character>(); if ((Object)(object)component == (Object)null || component is Player) { return; } Vector3 position = ((Component)__instance).transform.position; if (WorldGenerator.instance != null) { Biome biome = WorldGenerator.instance.GetBiome(position); if (!Plugin.IsUnlocked(biome)) { __result.Clear(); Plugin.LogBlockedLoot(position, biome); } } } } [HarmonyPatch(typeof(OfferingBowl), "Interact")] internal static class BossAltarInteractionGatePatch { private static bool Prefix(OfferingBowl __instance, bool hold, ref bool __result) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || WorldGenerator.instance == null) { return true; } if (Plugin.CanSummonBoss(WorldGenerator.instance.GetBiome(((Component)__instance).transform.position))) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(OfferingBowl), "UseItem")] internal static class BossAltarOfferingGatePatch { private static bool Prefix(OfferingBowl __instance, Humanoid user, ItemData item, ref bool __result) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || item == null || WorldGenerator.instance == null) { return true; } if (Plugin.CanSummonBoss(WorldGenerator.instance.GetBiome(((Component)__instance).transform.position))) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(OfferingBowl), "RPC_SpawnBoss")] internal static class BossAltarSpawnGatePatch { private static bool Prefix(OfferingBowl __instance) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || WorldGenerator.instance == null) { return true; } return Plugin.CanSummonBoss(WorldGenerator.instance.GetBiome(((Component)__instance).transform.position)); } } [HarmonyPatch] internal static class QueenSealbreakerDoorGatePatch { private static IEnumerable<MethodBase> TargetMethods() { Type type = AccessTools.TypeByName("Door"); if (type == null) { yield break; } foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(type)) { if (declaredMethod.Name == "Interact" || declaredMethod.Name == "UseItem") { yield return declaredMethod; } } } private static bool Prefix(Component __instance, object[] __args) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || WorldGenerator.instance == null || !IsSealbreakerDoor(__instance, __args)) { return true; } return Plugin.CanSummonBoss(WorldGenerator.instance.GetBiome(__instance.transform.position)); } private static bool IsSealbreakerDoor(Component door, object[] args) { if (ContainsSealbreakerName(GetFieldValue(door, "m_keyItem"))) { return true; } if (args != null) { for (int i = 0; i < args.Length; i++) { if (ContainsSealbreakerName(args[i])) { return true; } } } return false; } private static object GetFieldValue(object instance, string name) { Type type = instance.GetType(); while (type != null) { FieldInfo fieldInfo = AccessTools.Field(type, name); if (fieldInfo != null) { return fieldInfo.GetValue(instance); } type = type.BaseType; } return null; } private static bool ContainsSealbreakerName(object value) { if (value == null) { return false; } string text = value.ToString(); GameObject val = (GameObject)((value is GameObject) ? value : null); if ((Object)(object)val != (Object)null) { text = text + " " + ((Object)val).name; } Component val2 = (Component)((value is Component) ? value : null); if ((Object)(object)val2 != (Object)null) { text = text + " " + ((Object)val2.gameObject).name; } ItemData val3 = (ItemData)((value is ItemData) ? value : null); if (val3 != null) { if ((Object)(object)val3.m_dropPrefab != (Object)null) { text = text + " " + ((Object)val3.m_dropPrefab).name; } if (val3.m_shared != null) { text = text + " " + val3.m_shared.m_name; } } text = text.ToLowerInvariant(); if (!text.Contains("sealbreaker")) { return text.Contains("dvergrkey"); } return true; } } }