using System;
using System.Collections.Generic;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CoilHeadMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CoilHeadMod")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("acc7c5fe-9136-45ea-b4a1-4a6c3d8aad65")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CoilHeadMod
{
public class NetworkHandler : NetworkBehaviour
{
[ServerRpc(RequireOwnership = false)]
public void TPCoilServerRpc(SpringManAI __instance, ref bool ___hasStopped, Vector3 pos, bool isPassiveTP)
{
//IL_000b: 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_0067: Unknown result type (might be due to invalid IL or missing references)
Plugin instance = Plugin.instance;
Vector3 val = pos;
instance.DebugLog("Received TP Rpc " + ((object)(Vector3)(ref val)).ToString());
if (isPassiveTP && Random.value <= Plugin.instance.aggroChance / 100f)
{
((EnemyAI)__instance).currentBehaviourStateIndex = 1;
}
else
{
((EnemyAI)__instance).currentBehaviourStateIndex = 0;
}
NavMeshAgent component = ((Component)__instance).gameObject.GetComponent<NavMeshAgent>();
component.Warp(pos);
}
}
[BepInPlugin("CoilHeadMod.Lusacan1", "CoilTeleport", "1.0.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string modGUID = "CoilHeadMod.Lusacan1";
public const string modName = "CoilTeleport";
public const string modVersion = "1.0.0.0";
private readonly Harmony harmony = new Harmony("CoilHeadMod.Lusacan1");
public float tpChance;
public float tpMin;
public float tpMax;
public float tpTimer;
public float aggroChance;
public bool debugCoil;
public bool bigLogs;
public bool hasSpawned = false;
public bool hasStopped = false;
public float nextTPChance = 0f;
public float lastEncounter = 0f;
public EnemyType coilHead;
public ManualLogSource LogSource;
public RoundManager rm;
public GameObject netManagerPrefab;
public NetworkHandler netHandler;
public static Plugin instance;
private void Awake()
{
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array2 = methods;
foreach (MethodInfo methodInfo in array2)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
instance = this;
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "netcode");
AssetBundle val = AssetBundle.LoadFromFile(text);
netManagerPrefab = val.LoadAsset<GameObject>("Assets/NetworkManager/NetworkManager.prefab");
netManagerPrefab.AddComponent<NetworkHandler>();
netHandler = netManagerPrefab.GetComponent<NetworkHandler>();
LogSource = Logger.CreateLogSource("CoilHeadMod.Lusacan1");
DebugLog("Loaded version (1.0.0.0)");
string text2 = "Teleport";
ConfigEntry<float> val2 = ((BaseUnityPlugin)this).Config.Bind<float>(text2, "Teleport Chance", 33.3f, "The chance for the coil head to teleport when you look away (1-100)\nset to -1 to disable");
tpChance = val2.Value;
ConfigEntry<float> val3 = ((BaseUnityPlugin)this).Config.Bind<float>(text2, "Minimum Cooldown", 1f, "Minimum time between the chances of the coil head teleporting away");
tpMin = val3.Value;
ConfigEntry<float> val4 = ((BaseUnityPlugin)this).Config.Bind<float>(text2, "Maximum Cooldown", 10f, "Maximum time between the chances of the coil head teleporting away");
tpMax = val4.Value;
text2 = "Passive Teleport";
ConfigEntry<float> val5 = ((BaseUnityPlugin)this).Config.Bind<float>(text2, "Timer to Teleport", 20f, "After this many seconds without encountering a player the coil head will teleport\nset to -1 to disable");
tpTimer = val5.Value;
ConfigEntry<float> val6 = ((BaseUnityPlugin)this).Config.Bind<float>(text2, "Chance to Chase", 50f, "The chance for the coil head to chase a player after passively teleporting");
aggroChance = val6.Value;
text2 = "Debug";
ConfigEntry<bool> val7 = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Debug Coil", true, "Spawn a coil inside the dungeon before landing");
debugCoil = val7.Value;
ConfigEntry<bool> val8 = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Ingame Logs", true, "Displays a HUD tip for mod logs");
bigLogs = val8.Value;
harmony.PatchAll();
}
public void DebugLog(string txt)
{
LogSource.LogMessage((object)txt);
if (Object.op_Implicit((Object)(object)HUDManager.Instance) && bigLogs)
{
HUDManager.Instance.DisplayTip("CoilHeadMod.Lusacan1", txt, false, false, "LC_Tip1");
}
}
}
}
namespace CoilHeadMod.Patches
{
[HarmonyPatch(typeof(EnemyVent))]
internal class EnemyVent_Patch
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void SpawnDebugCoil(EnemyVent __instance)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.instance.hasSpawned && Plugin.instance.debugCoil)
{
Plugin.instance.hasSpawned = true;
Plugin.instance.rm.SpawnEnemyGameObject(__instance.floorNode.position, __instance.floorNode.eulerAngles.y, __instance.enemyTypeIndex, Plugin.instance.coilHead);
Plugin.instance.DebugLog("Spawned debug coil <3");
}
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatcher
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void AddToPrefabs(ref GameNetworkManager __instance)
{
((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(Plugin.instance.netManagerPrefab);
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManager_Patch
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void StartFunc(RoundManager __instance)
{
Plugin.instance.rm = __instance;
Plugin.instance.coilHead = GetEnemies().Find((SpawnableEnemyWithRarity x) => ((Object)x.enemyType).name == "SpringMan").enemyType;
Plugin.instance.hasSpawned = false;
}
private static List<SpawnableEnemyWithRarity> GetEnemies()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
List<SpawnableEnemyWithRarity> result = null;
GameObject[] array = rootGameObjects;
foreach (GameObject val in array)
{
if (((Object)val).name == "Environment")
{
result = val.GetComponentInChildren<Terminal>().moonsCatalogueList.SelectMany((SelectableLevel x) => x.Enemies, (SelectableLevel k, SpawnableEnemyWithRarity v) => v).ToList();
}
}
return result;
}
}
[HarmonyPatch(typeof(SpringManAI))]
internal class SpringManAI_Patch
{
[HarmonyPrefix]
[HarmonyPatch("Update")]
private static void CoilLogic(ref bool ___hasStopped)
{
Plugin.instance.hasStopped = ___hasStopped;
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void LateCoilLogic(SpringManAI __instance, ref bool ___hasStopped)
{
float num = Time.timeSinceLevelLoad - Plugin.instance.lastEncounter;
if (Plugin.instance.tpTimer >= 0f && num > Plugin.instance.tpTimer)
{
TPCoil(__instance, ref ___hasStopped, isPassiveTP: true);
}
if (!Plugin.instance.hasStopped)
{
return;
}
Plugin.instance.lastEncounter = Time.timeSinceLevelLoad;
if (Plugin.instance.hasStopped == ___hasStopped)
{
return;
}
Plugin.instance.LogSource.LogMessage((object)"CoilHeadMod.Lusacan1 Player looked away");
if (Time.timeSinceLevelLoad >= Plugin.instance.nextTPChance)
{
Plugin.instance.nextTPChance = Time.timeSinceLevelLoad + Random.value * (Plugin.instance.tpMax - Plugin.instance.tpMin) + Plugin.instance.tpMin;
if (Random.value <= Plugin.instance.tpChance / 100f)
{
TPCoil(__instance, ref ___hasStopped, isPassiveTP: false);
}
}
}
private static void TPCoil(SpringManAI __instance, ref bool ___hasStopped, bool isPassiveTP)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
Plugin.instance.lastEncounter = Time.timeSinceLevelLoad;
GameObject[] array = GameObject.FindGameObjectsWithTag("EnemySpawn");
EnemyVent component = array[Random.Range(0, array.Length - 1)].GetComponent<EnemyVent>();
Vector3 randomNavMeshPositionInRadius = Plugin.instance.rm.GetRandomNavMeshPositionInRadius(component.floorNode.position, 50f, default(NavMeshHit));
Plugin.instance.DebugLog("Sent TP Rpc");
Plugin.instance.netHandler.TPCoilServerRpc(__instance, ref ___hasStopped, randomNavMeshPositionInRadius, isPassiveTP);
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatcher
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void spawnNetManager(StartOfRound __instance)
{
if (((NetworkBehaviour)__instance).IsHost)
{
GameObject val = Object.Instantiate<GameObject>(Plugin.instance.netManagerPrefab);
val.GetComponent<NetworkObject>().Spawn(false);
}
}
}
}