using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using PlayerScanNode.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PlayerScanNode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlayerScanNode")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("eddef2b8-546f-4419-ac1e-ece0665d4e31")]
[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 PlayerScanNode
{
[BepInPlugin("com.kroes.playerscannode", "Player Scan Node", "1.0.1")]
public class ScanPlugin : BaseUnityPlugin
{
private const string GUID = "com.kroes.playerscannode";
private const string NAME = "Player Scan Node";
private const string VERSION = "1.0.1";
internal static ManualLogSource Log;
private Harmony harmony = new Harmony("com.kroes.playerscannode");
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
harmony.PatchAll(typeof(SteamValveHazardPatch));
harmony.PatchAll(typeof(EnemyVentPatch));
harmony.PatchAll(typeof(StartOfRoundPatch));
harmony.PatchAll(typeof(DoorLockPatch));
Log.LogInfo((object)"Loaded successfully!");
}
}
internal class Utils
{
internal enum NodeType
{
GENERAL,
DANGER,
SCRAP
}
public static void UpdateScrapValue(ref GrabbableObject grabbableObject, int scrapValue = -1)
{
ScanNodeProperties scanNodeProperties = ((Component)grabbableObject).GetComponentInChildren<ScanNodeProperties>();
ChangeScanNode(ref scanNodeProperties, (NodeType)scanNodeProperties.nodeType, scanNodeProperties.headerText, $"Value: ${scrapValue}", -1, scrapValue);
}
public static void ChangeScanNode(ref ScanNodeProperties scanNodeProperties, NodeType nodeType, string header = "LGU Scan Node", string subText = "Used for LGU stuff", int creatureScanID = -1, int scrapValue = 0, int minRange = 2, int maxRange = 7)
{
scanNodeProperties.headerText = header;
scanNodeProperties.subText = subText;
scanNodeProperties.nodeType = (int)nodeType;
scanNodeProperties.creatureScanID = creatureScanID;
scanNodeProperties.scrapValue = scrapValue;
scanNodeProperties.minRange = minRange;
scanNodeProperties.maxRange = maxRange;
}
private static GameObject CreateCanvasScanNode(ref GameObject objectToAddScanNode)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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)
GameObject val = Object.Instantiate<GameObject>(GameObject.CreatePrimitive((PrimitiveType)3), objectToAddScanNode.transform.position, Quaternion.Euler(Vector3.zero), objectToAddScanNode.transform);
((Object)val).name = "ScanNode";
val.layer = LayerMask.NameToLayer("ScanNode");
Object.Destroy((Object)(object)val.GetComponent<MeshRenderer>());
Object.Destroy((Object)(object)val.GetComponent<MeshFilter>());
return val;
}
private static void AddScanNode(GameObject objectToAddScanNode, NodeType nodeType, string header = "LGU Scan Node", string subText = "Used for LGU stuff", int creatureScanID = -1, int minRange = 2, int maxRange = 7)
{
GameObject val = CreateCanvasScanNode(ref objectToAddScanNode);
ScanNodeProperties scanNodeProperties = val.AddComponent<ScanNodeProperties>();
ChangeScanNode(ref scanNodeProperties, nodeType, header, subText, creatureScanID, 0, minRange, maxRange);
}
public static void AddGeneralScanNode(GameObject objectToAddScanNode, string header = "LGU Scan Node", string subText = "Used for LGU stuff", int creatureScanID = -1, int minRange = 2, int maxRange = 7)
{
ScanPlugin.Log.LogInfo((object)("AddScanNode: " + ((Object)objectToAddScanNode).name));
AddScanNode(objectToAddScanNode, NodeType.GENERAL, header, subText, creatureScanID, minRange, maxRange);
}
public static void RemoveScanNode(GameObject objectToRemoveScanNode)
{
Object.Destroy((Object)(object)objectToRemoveScanNode.GetComponentInChildren<ScanNodeProperties>());
}
public static void AddScannerNodeToValve(ref SteamValveHazard steamValveHazard)
{
AddGeneralScanNode(((Component)steamValveHazard).gameObject, "Bursted Steam Valve", "Fix it to get rid of the steam", -1, 3);
}
public static void RemoveScannerNodeFromValve(ref SteamValveHazard steamValveHazard)
{
RemoveScanNode(((Component)steamValveHazard).gameObject);
}
public static void AddScannerNodeToVent(ref EnemyVent enemyVent)
{
AddGeneralScanNode(((Component)enemyVent).gameObject, "Open Vent", "Something crawled out...", -1, 3);
}
public static void RemoveScannerNodeFromVent(ref EnemyVent enemyVent)
{
RemoveScanNode(((Component)enemyVent).gameObject);
}
private static GameObject CreatePlayerScanNode(PlayerControllerB player)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
ScanPlugin.Log.LogInfo((object)("Creating Player Scan Node Canvas: " + player.playerUsername));
Transform val = (((Object)(object)player.playerGlobalHead != (Object)null) ? player.playerGlobalHead : ((Component)player).transform);
GameObject val2 = Object.Instantiate<GameObject>(GameObject.CreatePrimitive((PrimitiveType)3), val.position, Quaternion.identity, val);
((Object)val2).name = "PlayerScanNode";
val2.layer = LayerMask.NameToLayer("ScanNode");
Object.Destroy((Object)(object)val2.GetComponent<MeshRenderer>());
Object.Destroy((Object)(object)val2.GetComponent<MeshFilter>());
return val2;
}
public static void AddScannerNodeToPlayer(PlayerControllerB player)
{
ScanPlugin.Log.LogInfo((object)("AddScannerNodeToPlayer: " + player.playerUsername));
if (!((Object)(object)player == (Object)null) && !((Object)(object)((Component)player.playerGlobalHead).GetComponentInChildren<ScanNodeProperties>() != (Object)null))
{
GameObject val = CreatePlayerScanNode(player);
ScanNodeProperties scanNodeProperties = val.AddComponent<ScanNodeProperties>();
ChangeScanNode(ref scanNodeProperties, NodeType.GENERAL, "Player", "Name: " + player.playerUsername, -1, 0, 3);
}
}
public static void RemoveScannerNodeFromPlayer(PlayerControllerB player)
{
ScanPlugin.Log.LogInfo((object)("RemoveScanNode: " + player.playerUsername));
if (!((Object)(object)player == (Object)null))
{
ScanNodeProperties componentInChildren = ((Component)player.playerGlobalHead).GetComponentInChildren<ScanNodeProperties>();
if ((Object)(object)componentInChildren != (Object)null)
{
Object.Destroy((Object)(object)((Component)componentInChildren).gameObject);
}
}
}
public static void AddScannerNodeToAllPlayers(ref StartOfRound startOfRound)
{
PlayerControllerB[] allPlayerScripts = startOfRound.allPlayerScripts;
foreach (PlayerControllerB val in allPlayerScripts)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject.GetComponentInChildren<ScanNodeProperties>() != (Object)null))
{
ScanPlugin.Log.LogInfo((object)("AddScannerNodeToAllPlayers: " + val.playerUsername));
AddScannerNodeToPlayer(val);
}
}
}
public static void RemoveScannerNodeFromAllPlayers(ref StartOfRound startOfRound)
{
PlayerControllerB[] allPlayerScripts = startOfRound.allPlayerScripts;
foreach (PlayerControllerB val in allPlayerScripts)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject.GetComponentInChildren<ScanNodeProperties>() == (Object)null))
{
ScanPlugin.Log.LogInfo((object)("RemoveScannerNodeFromAllPlayers: " + val.playerUsername));
RemoveScannerNodeFromPlayer(val);
}
}
}
public static void AddScannerNodeToDoor(ref DoorLock door)
{
AddGeneralScanNode(((Component)door).gameObject, "Door", "Unlocked.", -1, 3);
}
public static void RemoveScannerNodeFromDoor(ref DoorLock door)
{
RemoveScanNode(((Component)door).gameObject);
}
public static void SetDoorLocked(ref DoorLock door)
{
ScanNodeProperties scanNodeProperties = ((Component)door).gameObject.GetComponentInChildren<ScanNodeProperties>();
if (!((Object)(object)scanNodeProperties == (Object)null))
{
ChangeScanNode(ref scanNodeProperties, NodeType.GENERAL, "Door", "Locked.", -1, 0, 3);
}
}
public static void SetDoorUnlocked(ref DoorLock door)
{
ScanNodeProperties scanNodeProperties = ((Component)door).gameObject.GetComponentInChildren<ScanNodeProperties>();
if (!((Object)(object)scanNodeProperties == (Object)null))
{
ChangeScanNode(ref scanNodeProperties, NodeType.GENERAL, "Door", "Unlocked.", -1, 0, 3);
}
}
}
}
namespace PlayerScanNode.Patches
{
[HarmonyPatch(typeof(DoorLock))]
internal class DoorLockPatch
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void Postfix(DoorLock __instance)
{
Utils.AddScannerNodeToDoor(ref __instance);
}
[HarmonyPostfix]
[HarmonyPatch("LockDoor")]
private static void LockDoorPostfix(DoorLock __instance)
{
Utils.SetDoorLocked(ref __instance);
}
[HarmonyPostfix]
[HarmonyPatch("UnlockDoor")]
private static void UnlockDoorPostfix(DoorLock __instance)
{
Utils.SetDoorUnlocked(ref __instance);
}
}
[HarmonyPatch(typeof(EnemyVent))]
internal class EnemyVentPatch
{
[HarmonyPostfix]
[HarmonyPatch("OpenVentClientRpc")]
private static void StartPostfix(ref EnemyVent __instance)
{
Utils.AddScannerNodeToVent(ref __instance);
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPostfix]
[HarmonyPatch("OnPlayerConnectedClientRpc")]
private static void SpawnPlayersPostfix(StartOfRound __instance)
{
Utils.AddScannerNodeToAllPlayers(ref __instance);
}
[HarmonyPatch("EndGameClientRpc")]
[HarmonyPrefix]
private static void EndPrefix(StartOfRound __instance)
{
Utils.RemoveScannerNodeFromAllPlayers(ref __instance);
}
}
[HarmonyPatch(typeof(SteamValveHazard))]
internal class SteamValveHazardPatch
{
[HarmonyPostfix]
[HarmonyPatch("BurstValve")]
private static void BurstValvePostFix(ref SteamValveHazard __instance)
{
Utils.AddScannerNodeToValve(ref __instance);
}
[HarmonyPostfix]
[HarmonyPatch("FixValveLocalClient")]
private static void FixValvePostFix(ref SteamValveHazard __instance)
{
Utils.RemoveScannerNodeFromValve(ref __instance);
}
}
}