using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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: AssemblyCompany("TestAccount666.ScannableTools")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("This mod allows you to scan tools, which are normally not scannable.")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: AssemblyInformationalVersion("1.1.4+28a8031879343be7695578f61076420574dcf8b3")]
[assembly: AssemblyProduct("ScannableTools")]
[assembly: AssemblyTitle("TestAccount666.ScannableTools")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.4.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 ScannableTools
{
[HarmonyPatch]
public static class GrabbableObjectPatch
{
[HarmonyPatch(typeof(GrabbableObject), "Start")]
[HarmonyPostfix]
public static void AddScanNodeToCompanyIssuedItems(GrabbableObject __instance)
{
HandleGrabbableObject(__instance);
}
[HarmonyPatch(typeof(GrabbableObject), "LateUpdate")]
[HarmonyPostfix]
public static void UpdateScanNodeOfCompanyIssuedItems(GrabbableObject __instance)
{
UpdateGrabbableObject(__instance);
}
[HarmonyPatch(typeof(BoomboxItem), "Update")]
[HarmonyPostfix]
public static void UpdateScanNodeOfCompanyIssuedItems(BoomboxItem __instance)
{
UpdateGrabbableObject((GrabbableObject)(object)__instance);
}
internal static void HandleGrabbableObject(GrabbableObject grabbableObject)
{
ScanNodeContainer scanNodeContainer = default(ScanNodeContainer);
if (!((Object)(object)grabbableObject == (Object)null) && !grabbableObject.itemProperties.isScrap && !((Component)grabbableObject).gameObject.TryGetComponent<ScanNodeContainer>(ref scanNodeContainer) && !grabbableObject.isHeld && !ScannableTools.ScanToolsConfig.blacklistedItemsList.Contains(grabbableObject.itemProperties.itemName.ToLower()) && (ScannableTools.ScanToolsConfig.blacklistedItemsRegex == null || !ScannableTools.ScanToolsConfig.blacklistedItemsRegex.IsMatch(grabbableObject.itemProperties.itemName)))
{
ScanNodeProperties componentInChildren = ((Component)grabbableObject).gameObject.GetComponentInChildren<ScanNodeProperties>();
if (grabbableObject.itemProperties.itemName.Equals("Key") && ScannableTools.ScanToolsConfig.keyScanNodeType.Value == 0 && (Object)(object)componentInChildren != (Object)null)
{
scanNodeContainer = ((Component)grabbableObject).gameObject.AddComponent<ScanNodeContainer>();
scanNodeContainer.scanNodeGameObject = ((Component)componentInChildren).gameObject;
scanNodeContainer.scanNode = componentInChildren;
}
else if (!((Object)(object)componentInChildren != (Object)null))
{
CreateScanNodeOnObject(((Component)grabbableObject).gameObject, grabbableObject.itemProperties.itemName, GetBatteryPercentage(grabbableObject));
}
}
}
internal static void UpdateGrabbableObject(GrabbableObject grabbableObject)
{
if ((Object)(object)grabbableObject == (Object)null || grabbableObject.itemProperties.isScrap)
{
return;
}
ScanNodeContainer scanNodeContainer = default(ScanNodeContainer);
if (!((Component)grabbableObject).gameObject.TryGetComponent<ScanNodeContainer>(ref scanNodeContainer) || (Object)(object)scanNodeContainer.scanNode == (Object)null)
{
if (!grabbableObject.isHeld)
{
HandleGrabbableObject(grabbableObject);
}
}
else if (grabbableObject.isHeld)
{
Object.Destroy((Object)(object)scanNodeContainer.scanNodeGameObject);
Object.Destroy((Object)(object)scanNodeContainer);
}
else if (grabbableObject.itemProperties.requiresBattery)
{
string batteryPercentage = GetBatteryPercentage(grabbableObject);
if (batteryPercentage != null)
{
scanNodeContainer.scanNode.subText = batteryPercentage;
}
}
}
private static string? GetBatteryPercentage(GrabbableObject grabbableObject)
{
if ((Object)(object)grabbableObject == (Object)null || !grabbableObject.itemProperties.requiresBattery)
{
return null;
}
return grabbableObject.insertedBattery.empty ? "Battery: 0%" : $"Battery: {(int)(grabbableObject.insertedBattery.charge * 100f)}%";
}
private static void CreateScanNodeOnObject(GameObject gameObject, string headerText, string? subText)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("ScanNode", new Type[2]
{
typeof(ScanNodeProperties),
typeof(BoxCollider)
})
{
layer = LayerMask.NameToLayer("ScanNode")
};
val.transform.localScale = Vector3.one * 1f;
val.transform.parent = gameObject.transform;
GameObject val2 = val;
BoxCollider component = val2.GetComponent<BoxCollider>();
((Collider)component).isTrigger = true;
val2.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
ScanNodeProperties component2 = val2.GetComponent<ScanNodeProperties>();
component2.scrapValue = 0;
component2.creatureScanID = -1;
component2.nodeType = 0;
component2.minRange = 1;
component2.maxRange = 13;
component2.requiresLineOfSight = true;
component2.headerText = headerText;
if (subText != null)
{
component2.subText = subText;
}
ScanNodeContainer scanNodeContainer = gameObject.AddComponent<ScanNodeContainer>();
scanNodeContainer.scanNodeGameObject = val2;
scanNodeContainer.scanNode = component2;
}
}
[BepInPlugin("TestAccount666.ScannableTools", "ScannableTools", "1.1.4")]
public class ScannableTools : BaseUnityPlugin
{
public static ScannableTools Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; private set; }
internal static ScanToolsConfig ScanToolsConfig { get; private set; }
public static void AddScanNodeToGrabbableObject(GrabbableObject grabbableObject)
{
GrabbableObjectPatch.HandleGrabbableObject(grabbableObject);
}
public static void UpdateScanNodeOfGrabbableObject(GrabbableObject grabbableObject)
{
GrabbableObjectPatch.UpdateGrabbableObject(grabbableObject);
}
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
ScanToolsConfig = new ScanToolsConfig(((BaseUnityPlugin)this).Config);
ScanToolsConfig.HandleConfig();
Patch();
Logger.LogInfo((object)"TestAccount666.ScannableTools v1.1.4 has loaded!");
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("TestAccount666.ScannableTools");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public class ScanNodeContainer : MonoBehaviour
{
public GameObject? scanNodeGameObject;
public ScanNodeProperties? scanNode;
}
public class ScanToolsConfig
{
[CompilerGenerated]
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ConfigFile <configFile>P;
internal ConfigEntry<int> keyScanNodeType;
internal ConfigEntry<string> blacklistedItems;
internal ConfigEntry<string> blacklistedItemsRegexEntry;
internal readonly List<string> blacklistedItemsList;
internal Regex? blacklistedItemsRegex;
public ScanToolsConfig(ConfigFile configFile)
{
<configFile>P = configFile;
keyScanNodeType = null;
blacklistedItems = null;
blacklistedItemsRegexEntry = null;
blacklistedItemsList = new List<string>();
base..ctor();
}
internal void HandleConfig()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
keyScanNodeType = <configFile>P.Bind<int>("Keys", "Key ScanNode Look", 0, new ConfigDescription("Defines how the scan node for keys look. 0 = Green, but Blue after pickup. 1 = Teal colored. (Try setting this to 1, if you're experiencing lags, for some reason)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1), Array.Empty<object>()));
blacklistedItems = <configFile>P.Bind<string>("Items", "Blacklisted Items", "clipboard, polaroid, test", "A comma separated list of items that will be ignored by this mod");
blacklistedItems.SettingChanged += delegate
{
SetBlackListedItems();
};
blacklistedItemsRegexEntry = <configFile>P.Bind<string>("Items", "Blacklisted Items Regex", "", "Regex for blacklisted items. Leave blank, if you don't know how to use regex!");
blacklistedItemsRegexEntry.SettingChanged += delegate
{
SetBlackListedItems();
};
SetBlackListedItems();
}
private void SetBlackListedItems()
{
blacklistedItemsList.Clear();
blacklistedItemsList.AddRange(blacklistedItems.Value.ToLower().Replace(", ", ",").Split(","));
if (string.IsNullOrEmpty(blacklistedItemsRegexEntry.Value))
{
blacklistedItemsRegex = null;
}
else
{
blacklistedItemsRegex = new Regex(blacklistedItemsRegexEntry.Value);
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TestAccount666.ScannableTools";
public const string PLUGIN_NAME = "ScannableTools";
public const string PLUGIN_VERSION = "1.1.4";
}
}