using System;
using System.Diagnostics;
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 UnityEngine;
using UnityEngine.AI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("NBFBs.RedPill")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows the \"Red Pill\" test enemy (Obunga) to naturally spawn on moons")]
[assembly: AssemblyFileVersion("0.2.3.0")]
[assembly: AssemblyInformationalVersion("0.2.3")]
[assembly: AssemblyProduct("NBFBs.RedPill")]
[assembly: AssemblyTitle("NBFBs.RedPill")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.3.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
{
internal static class ConfigController
{
internal static ConfigEntry<int> spawnRarityGeneral;
internal static ConfigEntry<int> spawnCount;
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");
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)
{
}
internal static void LogWarning(string message)
{
}
internal static void LogError(string message)
{
}
}
[BepInPlugin("NBFBs.RedPill", "Red Pill Enemy Spawn", "0.2.3")]
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.2.3";
internal static Plugin Instance;
internal static Harmony harmony;
private void Awake()
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: 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.2.3";
}
}
namespace RedPill.Patches
{
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("FinishGeneratingLevel")]
[HarmonyPostfix]
private static void AddRedPillToEnemiesList()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Expected O, but got Unknown
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: 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 + "!");
val3.MaxCount = ConfigController.spawnCount.Value;
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 = 2;
val5.rarity = ConfigController.spawnRarityGeneral.Value;
RoundManager.Instance.currentLevel.Enemies.Add(val5);
}
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)
{
__instance.detectionRadius = ConfigController.playerDetectionRadius.Value;
}
[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);
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}