using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ValuableTracker")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ValuableTracker")]
[assembly: AssemblyTitle("ValuableTracker")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ValuableTracker
{
[BepInPlugin("com.repo.valuabletracker", "Valuable Tracker", "1.0.3")]
public class ValuableTracker : BaseUnityPlugin
{
public class ItemState
{
public ValuableObject itemRef;
public bool markedAsSold;
public bool isLost;
public bool isExtracted;
}
public static ValuableTracker Instance;
public static GameObject UIObject;
public static TextMeshProUGUI UIText;
public static List<ItemState> TrackedItems = new List<ItemState>();
public static int TotalItemsRecorded = 0;
private static float _updateTimer = 0f;
private const float UPDATE_INTERVAL = 0.25f;
private void Awake()
{
Instance = this;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Valuable Tracker Loaded!");
PluginConfig.Init(((BaseUnityPlugin)this).Config);
Harmony.CreateAndPatchAll(typeof(ValuableTracker), (string)null);
}
private static void ApplyUIPosition(RectTransform rect)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: 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)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
switch (PluginConfig.UIPosition.Value)
{
case PluginConfig.Positions.TopLeft:
rect.anchorMin = new Vector2(0f, 1f);
rect.anchorMax = new Vector2(0f, 1f);
rect.pivot = new Vector2(0f, 1f);
rect.anchoredPosition = new Vector2(20f, -20f);
rect.sizeDelta = new Vector2(400f, 50f);
break;
case PluginConfig.Positions.Custom:
rect.anchorMin = Vector2.zero;
rect.anchorMax = Vector2.zero;
rect.pivot = Vector2.zero;
rect.anchoredPosition = PluginConfig.CustomPositionCoords.Value;
rect.sizeDelta = new Vector2(400f, 50f);
break;
}
}
public static void RegisterItem(ValuableObject val)
{
if (!((Object)(object)val == (Object)null) && !TrackedItems.Any((ItemState x) => (Object)(object)x.itemRef == (Object)(object)val))
{
TrackedItems.Add(new ItemState
{
itemRef = val,
markedAsSold = false,
isLost = false,
isExtracted = false
});
TotalItemsRecorded++;
}
}
[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
[HarmonyPostfix]
private static void OnLevelGenDone()
{
TrackedItems.Clear();
TotalItemsRecorded = 0;
ValuableObject[] array = Object.FindObjectsOfType<ValuableObject>();
foreach (ValuableObject val in array)
{
RegisterItem(val);
}
}
[HarmonyPatch(typeof(ValuableObject), "Start")]
[HarmonyPostfix]
private static void OnValuableStart(ValuableObject __instance)
{
if (SemiFunc.LevelGenDone())
{
RegisterItem(__instance);
}
}
[HarmonyPatch(typeof(RoundDirector), "HaulCheck")]
[HarmonyPostfix]
private static void OnHaulCheck()
{
List<GameObject> dollarHaulList = RoundDirector.instance.dollarHaulList;
foreach (ItemState trackedItem in TrackedItems)
{
if ((Object)(object)trackedItem.itemRef != (Object)null && dollarHaulList.Contains(((Component)trackedItem.itemRef).gameObject))
{
trackedItem.markedAsSold = true;
}
}
}
[HarmonyPatch(typeof(RoundDirector), "Update")]
[HarmonyPostfix]
private static void UpdateUI_Patch()
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Expected O, but got Unknown
//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0322: Unknown result type (might be due to invalid IL or missing references)
//IL_0336: Unknown result type (might be due to invalid IL or missing references)
//IL_0343: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_04db: Unknown result type (might be due to invalid IL or missing references)
//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
if (!SemiFunc.RunIsLevel())
{
if ((Object)(object)UIObject != (Object)null && UIObject.activeSelf)
{
UIObject.SetActive(false);
}
return;
}
if ((Object)(object)UIObject == (Object)null)
{
GameObject val = GameObject.Find("Game Hud");
GameObject val2 = GameObject.Find("Tax Haul");
if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
{
UIObject = new GameObject("ValuableTracker_HUD");
UIObject.transform.SetParent(val.transform, false);
UIText = UIObject.AddComponent<TextMeshProUGUI>();
TMP_Text component = val2.GetComponent<TMP_Text>();
((TMP_Text)UIText).font = component.font;
((TMP_Text)UIText).fontSize = 24f;
((TMP_Text)UIText).alignment = (TextAlignmentOptions)2052;
((TMP_Text)UIText).enableWordWrapping = false;
((TMP_Text)UIText).lineSpacing = component.lineSpacing;
((TMP_Text)UIText).text = "Items: -- / --";
UIObject.SetActive(true);
}
}
if (!((Object)(object)UIObject != (Object)null))
{
return;
}
if (!UIObject.activeSelf)
{
UIObject.SetActive(true);
}
_updateTimer += Time.deltaTime;
if (!(_updateTimer >= 0.25f))
{
return;
}
_updateTimer = 0f;
float num = 225f;
if (PluginConfig.UIPosition.Value == PluginConfig.Positions.Default || PluginConfig.UIPosition.Value == PluginConfig.Positions.BottomRight)
{
Transform parent = UIObject.transform.parent;
foreach (RectTransform item in parent)
{
RectTransform val3 = item;
if (!((Object)(object)val3 == (Object)(object)UIObject.transform) && ((Component)val3).gameObject.activeSelf)
{
bool flag = val3.anchoredPosition.y > 220f && val3.anchoredPosition.y < 230f;
bool flag2 = val3.offsetMax.y > 220f && val3.offsetMax.y < 230f;
if (flag || flag2)
{
num = 195f;
break;
}
}
}
RectTransform component2 = UIObject.GetComponent<RectTransform>();
component2.pivot = new Vector2(1f, 1f);
component2.anchorMin = new Vector2(0f, 0f);
component2.anchorMax = new Vector2(1f, 0f);
component2.anchoredPosition = new Vector2(1f, -1f);
component2.offsetMax = new Vector2(0f, num);
component2.offsetMin = new Vector2(0f, num);
component2.sizeDelta = Vector2.zero;
}
else
{
ApplyUIPosition(UIObject.GetComponent<RectTransform>());
}
int num2 = 0;
int num3 = 0;
foreach (ItemState trackedItem in TrackedItems)
{
if (trackedItem.isLost)
{
if (trackedItem.isExtracted)
{
num2++;
}
else
{
num3++;
}
continue;
}
if ((Object)(object)trackedItem.itemRef != (Object)null)
{
if (trackedItem.markedAsSold)
{
num2++;
}
continue;
}
trackedItem.isLost = true;
if (trackedItem.markedAsSold)
{
trackedItem.isExtracted = true;
num2++;
}
else
{
trackedItem.isExtracted = false;
num3++;
}
}
int num4 = TotalItemsRecorded - num3;
if ((Object)(object)UIText != (Object)null)
{
string text = $"Items: {num2} / {num4}";
if (num3 > 0)
{
text += $"\n<color=#FF4444>Lost: {num3}</color>";
}
((TMP_Text)UIText).text = text;
if (num2 == num4 && num4 > 0)
{
((Graphic)UIText).color = Color.green;
}
else
{
((Graphic)UIText).color = new Color(0.78f, 0.91f, 0.9f, 1f);
}
}
}
}
public static class PluginConfig
{
public enum Positions
{
Default,
TopLeft,
BottomRight,
Custom
}
public static ConfigEntry<Positions> UIPosition;
public static ConfigEntry<Vector2> CustomPositionCoords;
public static void Init(ConfigFile config)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
UIPosition = config.Bind<Positions>("UI Layout", "Position Preset", Positions.Default, "Where should the tracker appear?");
CustomPositionCoords = config.Bind<Vector2>("UI Layout", "Custom Coords", new Vector2(0f, 0f), "X,Y offset if Position Preset is set to 'Custom'.");
}
}
}