using System;
using System.Diagnostics;
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 Photon.Pun;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BetterItemScanner")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterItemScanner")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("36e306eb-6522-4a3c-985f-74e2b9f5a458")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ValuableScanner;
[BepInPlugin("reepchik.betteritemscanner", "Better Item Scanner", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private readonly Harmony harmony = new Harmony("reepchik.betteritemscanner");
public static ConfigEntry<float> ScanRange;
public static ConfigEntry<KeyCode> ScanKey;
public static ConfigEntry<bool> DisableAnimations;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"Loading Better Item Scanner plugin!");
ScanRange = ((BaseUnityPlugin)this).Config.Bind<float>("Scanner", "ScanRange", 10f, "The detection range in meters for valuable objects");
ScanKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Scanner", "ScanKey", (KeyCode)102, "Key to activate the scanner");
DisableAnimations = ((BaseUnityPlugin)this).Config.Bind<bool>("Scanner", "DisableAnimations", false, "Disables camera animations when scanning");
harmony.PatchAll(typeof(Plugin));
Log.LogInfo((object)"Better Item Scanner successfully patched!");
}
[HarmonyPatch(typeof(GameDirector), "Update")]
[HarmonyPostfix]
private static void GameDirectorUpdatePatch(GameDirector __instance)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
if ((int)__instance.currentState == 2 && (!GameManager.Multiplayer() || PhotonNetwork.IsConnectedAndReady) && Input.GetKeyDown(ScanKey.Value) && CanUseScanner())
{
ScanForValuables();
}
}
private static bool CanUseScanner()
{
if ((Object)(object)PlayerController.instance == (Object)null || (Object)(object)PlayerController.instance.playerAvatarScript == (Object)null)
{
return false;
}
return !GameDirector.instance.DisableInput;
}
private static void ScanForValuables()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)PlayerController.instance == (Object)null)
{
return;
}
Vector3 position = ((Component)PlayerController.instance).transform.position;
if (!DisableAnimations.Value && (Object)(object)CameraGlitch.Instance != (Object)null)
{
CameraGlitch.Instance.PlayShort();
}
Collider[] array = Physics.OverlapSphere(position, ScanRange.Value);
for (int i = 0; i < array.Length; i++)
{
ValuableObject componentInParent = ((Component)array[i]).GetComponentInParent<ValuableObject>();
if ((Object)(object)componentInParent != (Object)null)
{
HighlightValuable(componentInParent);
}
}
}
private static void HighlightValuable(ValuableObject valuable)
{
if ((Object)(object)valuable == (Object)null)
{
return;
}
valuable.Discover((State)0);
if (!((Object)(object)Map.Instance != (Object)null))
{
return;
}
try
{
Map.Instance.AddValuable(valuable);
}
catch (Exception ex)
{
Log.LogError((object)("Error adding valuable object to map: " + ex.Message));
}
}
}
internal static class PluginInfo
{
public const string PLUGIN_GUID = "reepchik.betteritemscanner";
public const string PLUGIN_NAME = "Better Item Scanner";
public const string PLUGIN_VERSION = "1.0.0";
}