Please disclose if your mod was created primarily 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 RedPillEnemySpawn v0.3.0
NBFBs.RedPill.dll
Decompiled a year agousing System; 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 HarmonyLib; using Microsoft.CodeAnalysis; using RedPill.Scripts; 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: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("NBFBs.RedPill")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Allows the \"Red Pill\" test enemy (Obunga) to naturally spawn on moons")] [assembly: AssemblyFileVersion("0.3.0.0")] [assembly: AssemblyInformationalVersion("0.3.0")] [assembly: AssemblyProduct("NBFBs.RedPill")] [assembly: AssemblyTitle("NBFBs.RedPill")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.3.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace RedPill { [BepInPlugin("NBFBs.RedPill", "Red Pill Enemy Spawn", "0.3.0")] public class Plugin : BaseUnityPlugin { private const string PLUGIN_GUID = "NBFBs.RedPill"; private const string PLUGIN_NAME = "Red Pill Enemy Spawn"; private const string PLUGIN_VERSION = "0.3.0"; internal static Plugin Instance; internal static Harmony harmony; private void Awake() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown if ((Object)(object)Instance == (Object)null) { Instance = this; } ModDebug.Initialize("NBFBs.RedPill"); ModDebug.LogInfo("Plugin NBFBs.RedPill (\"Red Pill Enemy Spawn\") is loaded!"); ConfigController.Initialize(((BaseUnityPlugin)this).Config); harmony = new Harmony("NBFBs.RedPill"); harmony.PatchAll(); } } public static class PluginInfo { public const string PLUGIN_GUID = "NBFBs.RedPill"; public const string PLUGIN_NAME = "NBFBs.RedPill"; public const string PLUGIN_VERSION = "0.3.0"; } } namespace RedPill.Scripts { internal static class ConfigController { internal enum SpawnLocation { Inside, Outside, Both } internal static ConfigEntry<int> spawnRarityGeneral; internal static ConfigEntry<int> spawnCount; internal static ConfigEntry<SpawnLocation> spawnLocation; internal static ConfigEntry<bool> spawnRarityFromDifficulty; internal static ConfigEntry<bool> useOriginalAI; internal static ConfigEntry<float> agentSpeedBase; internal static ConfigEntry<float> agentSpeedSlowDownAmount; internal static ConfigEntry<float> playerDetectionRadius; internal static void Initialize(ConfigFile configFile) { spawnRarityGeneral = configFile.Bind<int>("Spawning", "Rarity", 1, "Weighted probability of spawning on any moon\nFor reference, the most common enemy on a moon is usually set to around 50-60\nand the least common (like a Nutcracker on Experimentation) is often 1"); spawnCount = configFile.Bind<int>("Spawning", "Max count", 1, "How many Red Pills can potentially spawn in one day"); spawnLocation = configFile.Bind<SpawnLocation>("Spawning", "Location", SpawnLocation.Both, "<description of spawn location>"); useOriginalAI = configFile.Bind<bool>("AI", "Use custom AI", true, "(Overrides all other AI options)\nEnable custom AI behaviors, otherwise use vanilla test enemy AI (you cannot outrun the vanilla AI... well, not for long)"); agentSpeedBase = configFile.Bind<float>("AI", "Base movement speed", 10f, "How fast the Red Pill moves before being slowed down by player proximity"); agentSpeedSlowDownAmount = configFile.Bind<float>("AI", "Proximity speed effect", 4f, "How much the Red Pill slows down when it gets close to a player\nThe movement speed is divided by this value when the Red Pill is extremely close"); playerDetectionRadius = configFile.Bind<float>("AI", "Player tracking distance", 15f, "Changes the distance at which the Red Pill can detect a player\n\n[to be fixed in a later update]\nChanging this seems to mess with Obunga's movement speed\n(but it still slows down when near you, if you don't make this too low)"); } } internal static class ModDebug { private static ManualLogSource manualLogSource; internal static void Initialize(string GUID) { manualLogSource = Logger.CreateLogSource(GUID); } internal static void LogInfo(string message) { manualLogSource.LogInfo((object)message); } internal static void LogWarning(string message) { manualLogSource.LogWarning((object)message); } internal static void LogError(string message) { manualLogSource.LogError((object)message); } } internal class Obunga : EnemyAI { } } namespace RedPill.Patches { [HarmonyPatch(typeof(RoundManager))] internal class RoundManagerPatch { [HarmonyPatch("FinishGeneratingLevel")] [HarmonyPostfix] private static void AddRedPillToEnemiesList() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) EnemyType val = null; AnimationCurve val2 = null; Object[] array = Resources.FindObjectsOfTypeAll(typeof(EnemyType)); for (int i = 0; i < array.Length; i++) { EnemyType val3 = (EnemyType)array[i]; if (((Object)val3).name == "Flowerman") { ModDebug.LogInfo("Found " + ((Object)val3).name + "! Stealing probability curve..."); val2 = val3.probabilityCurve; string text = "curve: "; Keyframe[] keys = val2.keys; for (int j = 0; j < keys.Length; j++) { Keyframe val4 = keys[j]; text += $"[{((Keyframe)(ref val4)).time}:{((Keyframe)(ref val4)).value}]"; } ModDebug.LogInfo(text); } if (((Object)val3).name == "RedPillEnemyType") { ModDebug.LogInfo("Found " + ((Object)val3).name + "!"); val = val3; } ModDebug.LogInfo($"{((Object)val3).name}, max: {val3.MaxCount}, curve: {val3.probabilityCurve.length}, spawningDisabled: {val3.spawningDisabled}, power: {val3.PowerLevel}"); } SpawnableEnemyWithRarity val5 = new SpawnableEnemyWithRarity(); if ((Object)(object)val != (Object)null) { val5.enemyType = val; val5.enemyType.probabilityCurve = val2; val5.enemyType.PowerLevel = 2f; val5.enemyType.MaxCount = ConfigController.spawnCount.Value; val5.rarity = ConfigController.spawnRarityGeneral.Value; if (ConfigController.spawnLocation.Value != ConfigController.SpawnLocation.Outside) { RoundManager.Instance.currentLevel.Enemies.Add(val5); ModDebug.LogInfo("Added RedPill to inside enemies"); } if (ConfigController.spawnLocation.Value != 0) { RoundManager.Instance.currentLevel.OutsideEnemies.Add(val5); ModDebug.LogInfo("Added RedPill to outside enemies"); } } ModDebug.LogInfo("List of enemies on this level"); foreach (SpawnableEnemyWithRarity enemy in RoundManager.Instance.currentLevel.Enemies) { ModDebug.LogInfo($"(Rarity: {enemy.rarity}) {((Object)enemy.enemyType).name}"); } } } [HarmonyPatch(typeof(TestEnemy))] internal class TestEnemyPatch { [HarmonyPatch("Start")] [HarmonyPostfix] private static void ChangeInstanceVars(ref TestEnemy __instance) { //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) __instance.detectionRadius = ConfigController.playerDetectionRadius.Value; Vector3 pos = ((Component)__instance).transform.position; ((EnemyAI)__instance).isOutside = RoundManager.Instance.allEnemyVents.Min(delegate(EnemyVent vent) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)vent).transform.position - pos; return ((Vector3)(ref val)).sqrMagnitude; }) > 5f; ModDebug.LogInfo($"isOutside = {((EnemyAI)__instance).isOutside}"); } [HarmonyPatch("DoAIInterval")] [HarmonyPostfix] private static void UpdateSpeed(ref TestEnemy __instance) { if (ConfigController.useOriginalAI.Value) { float num = Mathf.InverseLerp(15f, 3f, __instance.closestPlayerDist) * ConfigController.agentSpeedSlowDownAmount.Value; ((EnemyAI)__instance).agent.speed = ConfigController.agentSpeedBase.Value; NavMeshAgent agent = ((EnemyAI)__instance).agent; agent.speed /= Mathf.Clamp(num, 1f, 999f); if (((EnemyAI)__instance).isOutside) { NavMeshAgent agent2 = ((EnemyAI)__instance).agent; agent2.speed *= 0.5f; } } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }