using System.Collections;
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 LCItemValue.Patches;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
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: AssemblyTitle("LCItemValue")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCItemValue")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d92df2d5-f152-4f85-8b6d-b471027ce17d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCItemValue
{
[BepInPlugin("com.github.DeathGOD7.LCItemValue", "ItemValue", "1.0.0")]
public class ItemValue : BaseUnityPlugin
{
private const string modGUID = "com.github.DeathGOD7.LCItemValue";
private const string modName = "ItemValue";
private const string modVersion = "1.0.0";
private static ManualLogSource logger;
internal static ManualLogSource getLogger()
{
return logger;
}
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("com.github.DeathGOD7.LCItemValue");
logger = Logger.CreateLogSource("ItemValue");
logger.LogInfo((object)"Item Value is loaded successfully.");
val.PatchAll(typeof(ItemValue));
val.PatchAll(typeof(ValueCounterPatcher));
}
}
}
namespace LCItemValue.Patches
{
[HarmonyPatch(typeof(HUDManager))]
internal class ValueCounterPatcher
{
private static GameObject _itemValueCounter;
private static TextMeshProUGUI _textValueCounter;
private static float _displayTimeLeft;
private const float DisplayTime = 5f;
[HarmonyPrefix]
[HarmonyPatch("PingScan_performed")]
private static void onScan(CallbackContext context)
{
ItemValue.getLogger().LogDebug((object)"Method is being invoked of (onScan)");
_displayTimeLeft = 5f;
if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
{
return;
}
ItemValue.getLogger().LogDebug((object)("Player Object Name : " + ((Object)GameNetworkManager.Instance.localPlayerController).name));
if (((CallbackContext)(ref context)).performed)
{
ItemValue.getLogger().LogDebug((object)"Actual code is being invoked of (onScan)");
if (!Object.op_Implicit((Object)(object)_itemValueCounter))
{
LoadValueCounter();
}
float num = CalculateHeldValue();
((TMP_Text)_textValueCounter).text = $"<align=\"left\">ITEMS VALUE : ${num}";
_displayTimeLeft = 5f;
if (!_itemValueCounter.activeSelf)
{
((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(ShowValues());
}
}
}
private static IEnumerator ShowValues()
{
_itemValueCounter.SetActive(true);
while (_displayTimeLeft > 0f)
{
float displayTimeLeft = _displayTimeLeft;
_displayTimeLeft = 0f;
yield return (object)new WaitForSeconds(displayTimeLeft);
}
_itemValueCounter.SetActive(false);
}
private static void LoadValueCounter()
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/ValueCounter");
if (!Object.op_Implicit((Object)(object)val))
{
ItemValue.getLogger().LogError((object)"Failed to load ValueCounter object!");
}
_itemValueCounter = Object.Instantiate<GameObject>(val.gameObject, val.transform.parent, false);
((Object)_itemValueCounter).name = "ItemValue UI";
((Behaviour)_itemValueCounter.GetComponentInChildren<Image>()).enabled = false;
_textValueCounter = _itemValueCounter.GetComponentInChildren<TextMeshProUGUI>();
((TMP_Text)_textValueCounter).transform.localPosition = new Vector3(30f, -75f, 0f);
((TMP_Text)_textValueCounter).transform.localRotation = new Quaternion(0f, 0f, 0.0175f, 0.9998f);
((TMP_Text)_textValueCounter).text = "<align=\"left\">ITEMS VALUE : $???";
}
private static float CalculateHeldValue()
{
float num = 0f;
PlayerControllerB componentInChildren = ((Component)GameNetworkManager.Instance.localPlayerController).GetComponentInChildren<PlayerControllerB>();
if ((Object)(object)componentInChildren == (Object)null)
{
ItemValue.getLogger().LogDebug((object)"Thats strange!!! No Player???");
}
ItemValue.getLogger().LogDebug((object)("Player Name : " + componentInChildren.playerUsername));
GrabbableObject[] itemSlots = componentInChildren.ItemSlots;
foreach (GrabbableObject val in itemSlots)
{
if (!((Object)(object)val == (Object)null) && !(((Object)val.itemProperties).name == "ClipboardManual") && !(((Object)val.itemProperties).name == "StickyNoteItem"))
{
ItemValue.getLogger().LogDebug((object)("Scrap Name: " + ((Object)val.itemProperties).name));
ItemValue.getLogger().LogDebug((object)("Scrap Value: " + val.scrapValue));
num += (float)val.scrapValue;
}
}
return num;
}
}
}