#define DEBUG
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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;
[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.3.0")]
[assembly: AssemblyInformationalVersion("1.1.3+8aefe25b5e6068c2751dca7cf252d8d279893be4")]
[assembly: AssemblyProduct("ScannableTools")]
[assembly: AssemblyTitle("TestAccount666.ScannableTools")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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.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)))
{
return;
}
if (grabbableObject.itemProperties.itemName.Equals("Key") && ScannableTools.ScanToolsConfig.keyScanNodeType.Value == 0)
{
ScanNodeProperties componentInChildren = ((Component)grabbableObject).gameObject.GetComponentInChildren<ScanNodeProperties>();
if ((Object)(object)componentInChildren != (Object)null)
{
scanNodeContainer = ((Component)grabbableObject).gameObject.AddComponent<ScanNodeContainer>();
scanNodeContainer.scanNodeGameObject = ((Component)componentInChildren).gameObject;
scanNodeContainer.scanNode = componentInChildren;
return;
}
}
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.3")]
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.3 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 Test
{
[HarmonyPatch("UpdateScanNodes")]
[HarmonyPostfix]
private static void UpdateScanNodesPostfix(PlayerControllerB playerScript)
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)playerScript != (Object)(object)StartOfRound.Instance.localPlayerController)
{
return;
}
Debug.WriteLine("Updating ScanNodes!");
RectTransform[] scanElements = HUDManager.Instance.scanElements;
Color color = default(Color);
foreach (RectTransform val in scanElements)
{
if (!((Object)(object)val == (Object)null))
{
Transform child = ((Transform)val).GetChild(1);
Transform child2 = child.GetChild(0);
Transform child3 = child.GetChild(2);
Image component = ((Component)child2).GetComponent<Image>();
Image component2 = ((Component)child3).GetComponent<Image>();
Animator component3 = ((Component)val).GetComponent<Animator>();
if ((Object)(object)component3 != (Object)null)
{
component3.SetInteger("colorNumber", 4);
}
((Color)(ref color))..ctor(Color.yellow.r, Color.yellow.g, Color.yellow.b, Color.yellow.a / 2f);
((Graphic)component).color = color;
Texture mainTexture = ((Graphic)component2).mainTexture;
Texture2D texture = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null);
Debug.Assert((Object)(object)texture != (Object)null, "subTextBoxTexture != null");
SetPixels(ref texture);
}
}
}
private static void SetPixels(ref Texture2D texture)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
Color[] array = new ReadOnlySpan<Color>(texture.GetPixels()).ToArray();
for (int i = 0; i < array.Length; i++)
{
array[i] = Color.yellow;
}
texture.SetPixels(array);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TestAccount666.ScannableTools";
public const string PLUGIN_NAME = "ScannableTools";
public const string PLUGIN_VERSION = "1.1.3";
}
}