using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.InputSystem; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("BetterItemScan")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BetterItemScan")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("04cd6816-7aba-4c14-a9a7-bf328df25692")] [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 BetterItemScan { [BepInPlugin("PopleZoo.BetterItemScan", "Better Item Scan", "2.1.0.0")] public class BetterItemScanModBase : BaseUnityPlugin { private const string modGUID = "PopleZoo.BetterItemScan"; private const string modName = "Better Item Scan"; private const string modVersion = "2.1.0.0"; private readonly Harmony harmony = new Harmony("PopleZoo.BetterItemScan"); public static BetterItemScanModBase Instance; public ManualLogSource mls; public static ConfigEntry ItemScanRadius; public static ConfigEntry AdjustScreenPositionXaxis; public static ConfigEntry AdjustScreenPositionYaxis; public static ConfigEntry ItemScaningUICooldown; public static ConfigEntry FontSize; public static ConfigEntry ShowDebugMode; public static ConfigEntry ShowShipTotalOnShipOnly; public static ConfigEntry ShowTotalOnShipOnly; public static ConfigEntry CalculateForQuota; public static ConfigEntry ItemTextColorHex; public static ConfigEntry ItemTextCalculatorColorHex; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = Logger.CreateLogSource("PopleZoo.BetterItemScan"); mls.LogInfo((object)"Plugin BetterItemScan is loaded!"); LoadConfigs(); harmony.PatchAll(); } private void LoadConfigs() { ShowDebugMode = ((BaseUnityPlugin)this).Config.Bind("Settings", "ShowDebugMode", false, "Shows the change in width of the area to scan"); ShowShipTotalOnShipOnly = ((BaseUnityPlugin)this).Config.Bind("Settings", "ShowShipTotalOnShipOnly", false, "Whether or not to show the ship's total only in the ship"); ShowTotalOnShipOnly = ((BaseUnityPlugin)this).Config.Bind("Settings", "ShowTotalOnShipOnly", false, "Whether or not to show the total scanned in the ship only"); CalculateForQuota = ((BaseUnityPlugin)this).Config.Bind("Settings", "CalculateForQuota", true, "Whether or not to calculate scanned items to see which meet the quota and if any do"); ItemScanRadius = ((BaseUnityPlugin)this).Config.Bind("Settings", "ItemScanRadius", 20f, "The default width is 20"); FontSize = ((BaseUnityPlugin)this).Config.Bind("Settings", "FontSize", 20f, "The default font size is 20, to make/see this change you may have to do this manually in the config file itself in the bepinex folder"); ItemTextColorHex = ((BaseUnityPlugin)this).Config.Bind("Settings", "ItemTextColorHex", "#78FFAE", "The default text color for items that have been scanned, value must be a hexadecimal"); ItemTextCalculatorColorHex = ((BaseUnityPlugin)this).Config.Bind("Settings", "ItemTextCalculatorColorHex", "#FF3333", "The default text color for items that meet the criteria, value must be a hexadecimal"); ItemScaningUICooldown = ((BaseUnityPlugin)this).Config.Bind("Settings", "ItemScaningUICooldown", 3f, "The default value is 5f, how long the ui stays on screen"); AdjustScreenPositionXaxis = ((BaseUnityPlugin)this).Config.Bind("Settings", "AdjustScreenPositionXaxis", 0f, "The default value is 0, you will add or take away from its original position"); AdjustScreenPositionYaxis = ((BaseUnityPlugin)this).Config.Bind("Settings", "AdjustScreenPositionYaxis", 0f, "The default value is 0, you will add or take away from its original position"); } } } namespace BetterItemScan.Patches { [HarmonyPatch] internal class HudManagerPatch_UI { private static GameObject _totalCounter; private static TextMeshProUGUI _textMesh; private static float _displayTimeLeft = BetterItemScanModBase.ItemScaningUICooldown.Value; private static float Totalsum = 0f; private static float Totalship = 0f; public static List scannedNodeObjects = new List(); public static List meetQuotaItemNames = new List(); public static Dictionary ItemsDictionary = new Dictionary(); public static int MeetQuota(List items, int quota) { items = items.Where((int item) => item >= quota).ToList(); if (!items.Any()) { return -1; } return items.Aggregate((int a, int b) => (Math.Abs(quota - a) < Math.Abs(quota - b)) ? a : b); } public static List> FindCombinations(List items, int quota) { List> list = new List>(); int count = items.Count; int num = int.MaxValue; for (int i = 0; i < 1 << count; i++) { List list2 = new List(); for (int j = 0; j < count; j++) { if ((i & (1 << j)) > 0) { list2.Add(items[j]); } } int num2 = list2.Sum(); int num3 = Math.Abs(quota - num2); if (num3 < num) { num = num3; list.Clear(); list.Add(list2); } else if (num3 == num) { list.Add(list2); } } list.Sort((List a, List b) => a.Count.CompareTo(b.Count)); return list; } private static bool IsHexColor(string value) { string pattern = "^#(?:[0-9a-fA-F]{3}){1,2}$"; return Regex.IsMatch(value, pattern); } [HarmonyPrefix] [HarmonyPatch(typeof(HUDManager), "PingScan_performed")] private static void OnScan(HUDManager __instance, CallbackContext context) { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Expected O, but got Unknown FieldInfo field = typeof(HUDManager).GetField("playerPingingScan", BindingFlags.Instance | BindingFlags.NonPublic); float num = (float)field.GetValue(__instance); MethodInfo method = typeof(HUDManager).GetMethod("CanPlayerScan", BindingFlags.Instance | BindingFlags.NonPublic); if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null || !((CallbackContext)(ref context)).performed || !(bool)method.Invoke(__instance, null) || (double)num > -1.0) { return; } if (!Object.op_Implicit((Object)(object)_totalCounter)) { CopyValueCounter(); } if (!Object.op_Implicit((Object)(object)_textMesh)) { _textMesh = new TextMeshProUGUI(); } List list = CalculateLootItems(); meetQuotaItemNames.Clear(); foreach (ScanNodeProperties item in list) { ItemsDictionary.Add(item, item.scrapValue); } int num2 = TimeOfDay.Instance.profitQuota - TimeOfDay.Instance.quotaFulfilled; List list2 = ItemsDictionary.Values.ToList(); list2.Sort(); list2.Reverse(); int bestIndividualItem = MeetQuota(list2, num2); List> source = FindCombinations(list2, num2); if (source.Any()) { int num3 = source.First().Sum(); if (Math.Abs(num2 - bestIndividualItem) <= Math.Abs(num2 - num3)) { if (bestIndividualItem != -1) { ScanNodeProperties key = ItemsDictionary.FirstOrDefault((KeyValuePair x) => x.Value == bestIndividualItem).Key; if ((Object)(object)key != (Object)null) { meetQuotaItemNames.Add(key.headerText); } } } else { foreach (int combination in source.First()) { ScanNodeProperties key2 = ItemsDictionary.FirstOrDefault((KeyValuePair x) => x.Value == combination).Key; if ((Object)(object)key2 != (Object)null) { meetQuotaItemNames.Add(key2.headerText); } } } } ItemsDictionary.Clear(); string text = ""; string text2 = ""; foreach (ScanNodeProperties item2 in list) { text2 = $"{item2.headerText}: ${item2.scrapValue}"; if (BetterItemScanModBase.CalculateForQuota.Value) { if (meetQuotaItemNames.Contains(item2.headerText)) { meetQuotaItemNames.Remove(item2.headerText); if (IsHexColor(BetterItemScanModBase.ItemTextCalculatorColorHex.Value)) { text2 = "* " + text2 + ""; } else { Debug.LogError((object)(BetterItemScanModBase.ItemTextCalculatorColorHex.Value + " is an invalid colour. Please remember the'#'")); text2 = "* " + text2 + ""; } } else { if (IsHexColor(BetterItemScanModBase.ItemTextColorHex.Value)) { text2 = " " + text2 + ""; } text2 = "" + text2 + ""; } } else { if (IsHexColor(BetterItemScanModBase.ItemTextColorHex.Value)) { Debug.LogError((object)(BetterItemScanModBase.ItemTextColorHex.Value + " is an invalid colour. Please remember the'#'")); text2 = " " + text2 + ""; } text2 = "" + text2 + ""; } text = text + text2 + "\n"; } ((TMP_Text)_textMesh).text = text; if (BetterItemScanModBase.ShowShipTotalOnShipOnly.Value) { if (!GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom) { TextMeshProUGUI textMesh = _textMesh; ((TMP_Text)textMesh).text = ((TMP_Text)textMesh).text + "\nTotal Scanned: " + Totalsum; } else { TextMeshProUGUI textMesh2 = _textMesh; ((TMP_Text)textMesh2).text = ((TMP_Text)textMesh2).text + "\nTotal Scanned: " + Totalsum + " Ship Total: " + Totalship; } } else { TextMeshProUGUI textMesh2 = _textMesh; ((TMP_Text)textMesh2).text = ((TMP_Text)textMesh2).text + "\nTotal Scanned: " + Totalsum + " Ship Total: " + Totalship; } if (BetterItemScanModBase.ShowTotalOnShipOnly.Value) { if (!GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom) { ((Component)_textMesh).gameObject.SetActive(false); ((Component)((TMP_Text)__instance.totalValueText).transform.parent).gameObject.SetActive(true); } else { ((Component)_textMesh).gameObject.SetActive(true); ((Component)((TMP_Text)__instance.totalValueText).transform.parent).gameObject.SetActive(false); } } _displayTimeLeft = BetterItemScanModBase.ItemScaningUICooldown.Value; if (!_totalCounter.activeSelf) { ((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(ValueCoroutine()); } } private static List CalculateLootItems() { List source = (from obj in GameObject.Find("/Environment/HangarShip").GetComponentsInChildren() where ((Object)obj).name != "ClipboardManual" && ((Object)obj).name != "StickyNoteItem" select obj).ToList(); List list = scannedNodeObjects.Where((ScanNodeProperties obj) => obj.headerText != "ClipboardManual" && obj.headerText != "StickyNoteItem" && obj.scrapValue != 0).ToList(); Totalsum = list.Sum((ScanNodeProperties scrap) => scrap.scrapValue); Totalship = source.Sum((GrabbableObject scrap) => scrap.scrapValue); return list; } private static IEnumerator ValueCoroutine() { _totalCounter.SetActive(true); while ((double)_displayTimeLeft > 0.0) { float displayTimeLeft = _displayTimeLeft; _displayTimeLeft = 0f; yield return (object)new WaitForSeconds(displayTimeLeft); } _totalCounter.SetActive(false); } private static void CopyValueCounter() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0191: 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)) { BetterItemScanModBase.Instance.mls.LogError((object)"Failed to find ValueCounter object to copy!"); } _totalCounter = Object.Instantiate(val.gameObject, val.transform.parent, false); Vector3 localPosition = _totalCounter.transform.localPosition; float num = Mathf.Clamp(localPosition.x + BetterItemScanModBase.AdjustScreenPositionXaxis.Value + 50f, -6000f, (float)Screen.width); float num2 = Mathf.Clamp(localPosition.y + BetterItemScanModBase.AdjustScreenPositionYaxis.Value - 80f, -6000f, (float)Screen.height); _totalCounter.transform.localPosition = new Vector3(num, num2, localPosition.z); _textMesh = _totalCounter.GetComponentInChildren(); ((TMP_Text)_textMesh).fontSizeMin = 5f; ((TMP_Text)_textMesh).fontSize = BetterItemScanModBase.FontSize.Value; ((TMP_Text)_textMesh).ForceMeshUpdate(false, false); ((TMP_Text)_textMesh).alignment = (TextAlignmentOptions)1025; RectTransform rectTransform = ((TMP_Text)_textMesh).rectTransform; rectTransform.anchorMin = new Vector2(0.5f, 2f); rectTransform.anchorMax = new Vector2(0.5f, 2f); rectTransform.pivot = new Vector2(0.5f, 0f); Vector3 localPosition2 = ((Transform)rectTransform).localPosition; ((Transform)rectTransform).localPosition = new Vector3(localPosition2.x, localPosition2.y - 140f, localPosition2.z); } } [HarmonyPatch] public class PlayerControllerBPatch_A { private static LineRenderer lineRenderer; private static GameObject lineObject; private static float maxDistance = 80f; [HarmonyPrefix] [HarmonyPatch(typeof(HUDManager), "AssignNewNodes")] private static bool AssignNewNodes_patch(HUDManager __instance, PlayerControllerB playerScript) { //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) HudManagerPatch_UI.scannedNodeObjects.Clear(); if ((Object)(object)lineRenderer == (Object)null) { lineObject = new GameObject("LineObject"); lineRenderer = lineObject.AddComponent(); lineRenderer.positionCount = 2; lineObject.SetActive(false); } FieldInfo field = typeof(HUDManager).GetField("nodesOnScreen", BindingFlags.Instance | BindingFlags.NonPublic); List list = field.GetValue(__instance) as List; FieldInfo field2 = typeof(HUDManager).GetField("scannedScrapNum", BindingFlags.Instance | BindingFlags.NonPublic); object value = field2.GetValue(__instance); FieldInfo field3 = typeof(HUDManager).GetField("scanNodesHit", BindingFlags.Instance | BindingFlags.NonPublic); RaycastHit[] array = field3.GetValue(__instance) as RaycastHit[]; MethodInfo method = typeof(HUDManager).GetMethod("AttemptScanNode", BindingFlags.Instance | BindingFlags.NonPublic); int num = Physics.SphereCastNonAlloc(new Ray(((Component)playerScript.gameplayCamera).transform.position + ((Component)playerScript.gameplayCamera).transform.forward * 20f, ((Component)playerScript.gameplayCamera).transform.forward), BetterItemScanModBase.ItemScanRadius.Value, array, maxDistance, 4194304); Vector3 val = new Vector3(((Component)playerScript.gameplayCamera).transform.position.x, ((Component)playerScript.gameplayCamera).transform.position.y - 2f, ((Component)playerScript.gameplayCamera).transform.position.z) + ((Component)playerScript.gameplayCamera).transform.forward; Vector3 forward = ((Component)playerScript.gameplayCamera).transform.forward; if (BetterItemScanModBase.ShowDebugMode.Value) { lineObject.SetActive(true); lineRenderer.SetPosition(0, val); lineRenderer.SetPosition(1, val + forward * maxDistance); LineRenderer obj = lineRenderer; float startWidth = (lineRenderer.endWidth = BetterItemScanModBase.ItemScanRadius.Value); obj.startWidth = startWidth; } if (num > __instance.scanElements.Length) { num = __instance.scanElements.Length; } list.Clear(); value = 0; if (num > __instance.scanElements.Length) { for (int i = 0; i < num; i++) { ScanNodeProperties component = ((Component)((RaycastHit)(ref array[i])).transform).gameObject.GetComponent(); GrabbableObject component2 = ((Component)((RaycastHit)(ref array[i])).transform.parent).gameObject.GetComponent(); if (component2.itemProperties.isScrap) { HudManagerPatch_UI.scannedNodeObjects.Add(component); } if (component.nodeType == 1 || component.nodeType == 2) { object[] parameters = new object[3] { component, i, playerScript }; method.Invoke(__instance, parameters); } } } if (list.Count < __instance.scanElements.Length) { for (int j = 0; j < num; j++) { ScanNodeProperties component3 = ((Component)((RaycastHit)(ref array[j])).transform).gameObject.GetComponent(); object[] parameters2 = new object[3] { component3, j, playerScript }; method.Invoke(__instance, parameters2); } } return false; } } [HarmonyPatch] public class PlayerControllerBPatch_B { [HarmonyPrefix] [HarmonyPatch(typeof(HUDManager), "AttemptScanNode")] private static bool AttemptScanNode_patch(HUDManager __instance, ScanNodeProperties node, int i, PlayerControllerB playerScript) { MethodInfo method = typeof(HUDManager).GetMethod("MeetsScanNodeRequirements", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method2 = typeof(HUDManager).GetMethod("AssignNodeToUIElement", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field = typeof(HUDManager).GetField("nodesOnScreen", BindingFlags.Instance | BindingFlags.NonPublic); List list = field.GetValue(__instance) as List; FieldInfo field2 = typeof(HUDManager).GetField("scannedScrapNum", BindingFlags.Instance | BindingFlags.NonPublic); int num = (int)field2.GetValue(__instance); FieldInfo field3 = typeof(HUDManager).GetField("playerPingingScan", BindingFlags.Instance | BindingFlags.NonPublic); float num2 = (float)field3.GetValue(__instance); object[] parameters = new object[2] { node, playerScript }; object[] parameters2 = new object[1] { node }; if (!(bool)method.Invoke(__instance, parameters)) { return false; } if (node.nodeType == 2) { num++; } if (!list.Contains(node)) { list.Add(node); } if (node.creatureScanID == -1) { HudManagerPatch_UI.scannedNodeObjects.Add(node); } if ((double)num2 < 0.0) { return false; } method2.Invoke(__instance, parameters2); return false; } } [HarmonyPatch] public class PlayerControllerBPatch_C { [HarmonyPostfix] [HarmonyPatch(typeof(HUDManager), "Update")] private static void Update_patch(HUDManager __instance) { FieldInfo field = typeof(HUDManager).GetField("addingToDisplayTotal", BindingFlags.Instance | BindingFlags.NonPublic); object value = field.GetValue(__instance); ((Component)((TMP_Text)__instance.totalValueText).transform.parent).gameObject.SetActive(false); value = false; } } }