Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Map Value Tracker v1.1.0
MapValueTracker.dll
Decompiled 11 months agousing 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 BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using MapValueTracker.Config; using MapValueTracker.Utils; using Microsoft.CodeAnalysis; using TMPro; 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("MapValueTracker")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+1be53d022750b648679838d88584d8f23c88eae1")] [assembly: AssemblyProduct("MapValueTracker")] [assembly: AssemblyTitle("MapValueTracker")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.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 MapValueTracker { [BepInPlugin("MapValueTracker", "MapValueTracker", "1.1.0")] public class MapValueTracker : BaseUnityPlugin { private const string PLUGIN_GUID = "MapValueTracker"; private const string PLUGIN_NAME = "MapValueTracker"; private const string PLUGIN_VERSION = "1.1.0"; private readonly Harmony harmony = new Harmony("Luken.REPO.MapValueTracker"); public static ManualLogSource Logger; public static MapValueTracker instance; public static GameObject textInstance; public static TextMeshProUGUI valueText; public void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Logger.LogInfo((object)"MapValueTracker loaded"); if ((Object)(object)instance == (Object)null) { instance = this; } Configuration.Init(((BaseUnityPlugin)this).Config); harmony.PatchAll(); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "MapValueTracker"; public const string PLUGIN_NAME = "MapValueTracker"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace MapValueTracker.Utils { public class ValuableTracker { private static ValuableTracker _instance; private List<ValuableObject> _allItems = new List<ValuableObject>(); public static ValuableTracker Instance => _instance ?? (_instance = new ValuableTracker()); public List<ValuableObject> StrayItems { get; private set; } = new List<ValuableObject>(); public float StrayValue { get; private set; } = 0f; public void Add(ValuableObject item) { if (((Behaviour)item).isActiveAndEnabled) { MapValueTracker.Logger.LogDebug((object)("ValuableTracker::Add | " + ((Object)item).name)); _allItems.Add(item); Update(); } } public void Remove(ValuableObject item) { _allItems.Remove(item); Update(); } public void Reset() { _allItems.Clear(); StrayValue = 0f; StrayItems.Clear(); } public void Update() { List<GameObject> dollarHaulList = RoundDirector.instance.dollarHaulList; _allItems.RemoveAll((ValuableObject item) => (Object)(object)item == (Object)null || (Object)(object)((Component)item).gameObject == (Object)null); StrayValue = 0f; StrayItems.Clear(); foreach (ValuableObject allItem in _allItems) { if (!dollarHaulList.Contains(((Component)allItem).gameObject)) { float value = Traverse.Create((object)allItem).Field("dollarValueCurrent").GetValue<float>(); StrayValue += value; StrayItems.Add(allItem); } } MapValueTracker.Logger.LogDebug((object)$"ValuableTracker::Update | StrayCount: {StrayItems.Count} Value: {StrayValue:N0}"); } public float GetItemDistance() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_00b3: Unknown result type (might be due to invalid IL or missing references) if (StrayItems.Count == 0) { return 0f; } ValuableObject val = null; float num = 0f; Vector3 position = ((Component)PlayerController.instance).transform.position; foreach (ValuableObject strayItem in StrayItems) { if (!((Object)(object)strayItem == (Object)null) && !((Object)(object)((Component)strayItem).gameObject == (Object)null) && !Traverse.Create((object)strayItem).Field("discovered").GetValue<bool>()) { Vector3 position2 = ((Component)strayItem).gameObject.transform.position; Vector3 val2 = position2 - position; float magnitude = ((Vector3)(ref val2)).magnitude; if (!((Object)(object)val != (Object)null) || !(magnitude > num)) { val = strayItem; num = magnitude; } } } return num; } } } namespace MapValueTracker.Patches { [HarmonyPatch(typeof(LevelGenerator))] internal static class LevelGeneratorPatches { [HarmonyPatch("StartRoomGeneration")] [HarmonyPrefix] public static void StartRoomGeneration() { MapValueTracker.Logger.LogInfo((object)"Generation Started"); ValuableTracker.Instance.Reset(); } [HarmonyPatch("GenerateDone")] [HarmonyPrefix] public static void GenerateDonePostfix() { MapValueTracker.Logger.LogInfo((object)"Generation Finished"); } } [HarmonyPatch(typeof(PhysGrabObjectImpactDetector))] public static class PhysGrabObjectImpactDetectorPatches { [HarmonyPatch("BreakRPC")] [HarmonyPostfix] private static void BreakRPC(float valueLost, PhysGrabObjectImpactDetector? __instance, bool _loseValue) { if (_loseValue) { MapValueTracker.Logger.LogDebug((object)$"PhysGrabObjectImpactDetector::BreakRPC | Lost: {valueLost}"); ValuableTracker.Instance.Update(); } } [HarmonyPatch(typeof(PhysGrabObject), "DestroyPhysGrabObjectRPC")] [HarmonyPostfix] public static void DestroyPhysGrabObjectRPC(PhysGrabObject __instance) { if (SemiFunc.RunIsLevel()) { ValuableObject component = ((Component)__instance).GetComponent<ValuableObject>(); if (!((Object)(object)component == (Object)null)) { float value = Traverse.Create((object)component).Field("dollarValueOriginal").GetValue<float>(); MapValueTracker.Logger.LogDebug((object)$"PhysGrabObjectImpactDetector::DestroyPhysGrabObjectRPC | Original Value: {value}"); ValuableTracker.Instance.Remove(component); } } } } [HarmonyPatch(typeof(RoundDirector))] public static class RoundDirectorPatches { [HarmonyPatch(typeof(RoundDirector), "Update")] [HarmonyPostfix] public static void UpdateUI() { if (!SemiFunc.RunIsLevel() || ((Object)(object)MapValueTracker.textInstance == (Object)null && !InitTextOverlay())) { return; } bool value = Traverse.Create((object)RoundDirector.instance).Field("allExtractionPointsCompleted").GetValue<bool>(); int value2 = Traverse.Create((object)RoundDirector.instance).Field("extractionPoints").GetValue<int>(); int value3 = Traverse.Create((object)RoundDirector.instance).Field("extractionPointsCompleted").GetValue<int>(); int value4 = Traverse.Create((object)RoundDirector.instance).Field("currentHaul").GetValue<int>(); int value5 = Traverse.Create((object)RoundDirector.instance).Field("extractionHaulGoal").GetValue<int>(); bool flag = SemiFunc.InputHold((InputKey)8) || Traverse.Create((object)MapToolController.instance).Field("mapToggled").GetValue<bool>(); if (value || ValuableTracker.Instance.StrayItems.Count == 0 || (!flag && !Configuration.AlwaysOn.Value)) { MapValueTracker.textInstance.SetActive(false); return; } MapValueTracker.textInstance.SetActive(true); RectTransform component = MapValueTracker.textInstance.GetComponent<RectTransform>(); SetCoordinates(component); List<string> list = new List<string>(); bool flag2 = value3 >= value2 - 1 && value4 >= value5; if (Configuration.ShowItemDistance.Value && (flag2 || Configuration.AlwaysShowDistance.Value)) { float itemDistance = ValuableTracker.Instance.GetItemDistance(); if (itemDistance > 0f) { if (Configuration.UsePreciseDistance.Value) { list.Add($"{itemDistance:N1}m"); } else { float num = itemDistance; float num2 = num; if (!(num2 < 5f)) { if (!(num2 < 15f)) { if (num2 < 25f) { list.Add("•"); } else { list.Add(""); } } else { list.Add("••"); } } else { list.Add("•••"); } } } } if (Configuration.ShowTotalValue.Value) { list.Add($"${ValuableTracker.Instance.StrayValue:N0}"); } if (Configuration.ShowItemCount.Value) { list.Add($"x{ValuableTracker.Instance.StrayItems.Count}"); } ((TMP_Text)MapValueTracker.valueText).SetText(GeneralExtensions.Join<string>((IEnumerable<string>)list, (Func<string, string>)null, " "), true); } private static bool InitTextOverlay() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.Find("Game Hud"); GameObject val2 = GameObject.Find("Tax Haul"); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return false; } TMP_FontAsset font = val2.GetComponent<TMP_Text>().font; MapValueTracker.textInstance = new GameObject(); MapValueTracker.textInstance.SetActive(false); ((Object)MapValueTracker.textInstance).name = "Value HUD"; MapValueTracker.textInstance.AddComponent<TextMeshProUGUI>(); MapValueTracker.valueText = MapValueTracker.textInstance.GetComponent<TextMeshProUGUI>(); ((TMP_Text)MapValueTracker.valueText).font = font; ((Graphic)MapValueTracker.valueText).color = Color.op_Implicit(new Vector4(0.7882f, 0.9137f, 0.902f, 1f)); ((TMP_Text)MapValueTracker.valueText).fontSize = 24f; ((TMP_Text)MapValueTracker.valueText).enableWordWrapping = false; ((TMP_Text)MapValueTracker.valueText).alignment = (TextAlignmentOptions)2052; ((TMP_Text)MapValueTracker.valueText).horizontalAlignment = (HorizontalAlignmentOptions)4; ((TMP_Text)MapValueTracker.valueText).verticalAlignment = (VerticalAlignmentOptions)2048; MapValueTracker.textInstance.transform.SetParent(val.transform, false); return true; } private static void SetCoordinates(RectTransform component) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0157: 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_0188: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) switch (Configuration.UIPosition.Value) { case Positions.Default: component.pivot = new Vector2(1f, 1f); component.anchoredPosition = new Vector2(1f, -1f); component.anchorMin = new Vector2(0f, 0f); component.anchorMax = new Vector2(1f, 0f); component.sizeDelta = new Vector2(0f, 0f); component.offsetMax = new Vector2(0f, 225f); component.offsetMin = new Vector2(0f, 225f); break; case Positions.LowerRight: component.pivot = new Vector2(1f, 1f); component.anchoredPosition = new Vector2(1f, -1f); component.anchorMin = new Vector2(0f, 0f); component.anchorMax = new Vector2(1f, 0f); component.sizeDelta = new Vector2(0f, 0f); component.offsetMax = new Vector2(0f, 125f); component.offsetMin = new Vector2(0f, 125f); break; case Positions.BottomRight: component.pivot = new Vector2(1f, 1f); component.anchoredPosition = new Vector2(1f, -1f); component.anchorMin = new Vector2(0f, 0f); component.anchorMax = new Vector2(1f, 0f); component.sizeDelta = new Vector2(0f, 0f); component.offsetMax = new Vector2(0f, 0f); component.offsetMin = new Vector2(0f, 0f); break; case Positions.Custom: component.pivot = new Vector2(1f, 1f); component.anchoredPosition = new Vector2(1f, -1f); component.anchorMin = new Vector2(0f, 0f); component.anchorMax = new Vector2(1f, 0f); component.sizeDelta = new Vector2(0f, 0f); component.offsetMax = Configuration.CustomPositionCoords.Value; component.offsetMin = Configuration.CustomPositionCoords.Value; break; default: component.pivot = new Vector2(1f, 1f); component.anchoredPosition = new Vector2(1f, -1f); component.anchorMin = new Vector2(0f, 0f); component.anchorMax = new Vector2(1f, 0f); component.sizeDelta = new Vector2(0f, 0f); component.offsetMax = new Vector2(0f, 225f); component.offsetMin = new Vector2(0f, 225f); break; } } } [HarmonyPatch(typeof(ValuableObject))] internal static class ValuableObjectPatches { [HarmonyPatch("DollarValueSetRPC")] [HarmonyPostfix] private static void DollarValueSet(ValuableObject __instance, float value) { MapValueTracker.Logger.LogDebug((object)$"ValuableObject::DollarValueSetRPC | New Valuable Object: {((Object)__instance).name} - ${value:N0}"); ValuableTracker.Instance.Add(__instance); } [HarmonyPatch("DollarValueSetLogic")] [HarmonyPostfix] private static void DollarValueSetLogic(ValuableObject __instance) { if (SemiFunc.IsMasterClientOrSingleplayer()) { float value = Traverse.Create((object)__instance).Field("dollarValueCurrent").GetValue<float>(); MapValueTracker.Logger.LogDebug((object)$"ValuableObject::DollarValueSetLogic | New Valuable Object: {((Object)__instance).name} - ${value:N0}"); ValuableTracker.Instance.Add(__instance); } } [HarmonyPatch("AddToDollarHaulList")] [HarmonyPostfix] private static void AddToDollarHaulList(ValuableObject __instance) { float value = Traverse.Create((object)__instance).Field("dollarValueCurrent").GetValue<float>(); MapValueTracker.Logger.LogDebug((object)$"ValuableObject::AddToDollarHaulList | Moved to Extract: {((Object)__instance).name} - ${value:N0}"); ValuableTracker.Instance.Update(); } [HarmonyPatch("AddToDollarHaulListRPC")] [HarmonyPostfix] private static void AddToDollarHaulListRPC(ValuableObject __instance) { float value = Traverse.Create((object)__instance).Field("dollarValueCurrent").GetValue<float>(); MapValueTracker.Logger.LogDebug((object)$"ValuableObject::AddToDollarHaulListRPC | Moved to Extract: {((Object)__instance).name} - ${value:N0}"); ValuableTracker.Instance.Update(); } [HarmonyPatch("RemoveFromDollarHaulList")] [HarmonyPostfix] private static void RemoveFromDollarHaulList(ValuableObject __instance) { float value = Traverse.Create((object)__instance).Field("dollarValueCurrent").GetValue<float>(); MapValueTracker.Logger.LogDebug((object)$"ValuableObject::RemoveFromDollarHaulList | Removed from Extract: {((Object)__instance).name} - ${value:N0}"); ValuableTracker.Instance.Update(); } [HarmonyPatch("RemoveFromDollarHaulListRPC")] [HarmonyPostfix] private static void RemoveFromDollarHaulListRPC(ValuableObject __instance) { float value = Traverse.Create((object)__instance).Field("dollarValueCurrent").GetValue<float>(); MapValueTracker.Logger.LogDebug((object)$"ValuableObject::RemoveFromDollarHaulListRPC | Removed from Extract: {((Object)__instance).name} - ${value:N0}"); ValuableTracker.Instance.Update(); } } } namespace MapValueTracker.Config { public enum Positions { Default, LowerRight, BottomRight, Custom } internal class Configuration { public static ConfigEntry<bool> AlwaysOn; public static ConfigEntry<bool> ShowTotalValue; public static ConfigEntry<bool> ShowItemCount; public static ConfigEntry<bool> ShowItemDistance; public static ConfigEntry<bool> UsePreciseDistance; public static ConfigEntry<bool> AlwaysShowDistance; public static ConfigEntry<Positions> UIPosition; public static ConfigEntry<Vector2> CustomPositionCoords; public static void Init(ConfigFile config) { //IL_00db: Unknown result type (might be due to invalid IL or missing references) config.SaveOnConfigSet = false; AlwaysOn = config.Bind<bool>("Default", "AlwaysOn", false, "Toggle to always display map value when an extraction goal is active. If false, use the menu key to pull up the tracker (Tab by default)."); ShowTotalValue = config.Bind<bool>("Default", "ShowTotalValue", true, "Toggle to show the total value of all stray items on the map."); ShowItemCount = config.Bind<bool>("Default", "ShowItemCount", true, "Toggle to show the number of stray items on the map."); ShowItemDistance = config.Bind<bool>("Default", "ShowItemDistance", true, "Toggle to display the distance to the closest valuable."); UsePreciseDistance = config.Bind<bool>("Default", "UsePreciseDistance", false, "Toggle to display the distance in meters instead of a rough estimate."); AlwaysShowDistance = config.Bind<bool>("Default", "AlwaysShowDistance", false, "Toggle to always display the distance, instead of only being active after meeting the last extract goal."); UIPosition = config.Bind<Positions>("UIPosition", "UIPosition", Positions.Default, "Preset Position of the Value Tracker UI element. Default is on the right side, below the extraction targets."); CustomPositionCoords = config.Bind<Vector2>("UIPosition", "CustomPositionCoords", new Vector2(0f, 0f), "Custom X,Y coordates of the Value Tracker UI element. Bottom Right corner is 0,0. Default position is 0,225."); ClearOrphanedEntries(config); config.Save(); config.SaveOnConfigSet = true; } private static void ClearOrphanedEntries(ConfigFile cfg) { PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries"); Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg); dictionary.Clear(); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }