Decompiled source of Grab Count Tracker v1.3.1

ObjectGrabber.dll

Decompiled 3 months ago
using System;
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 TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ObjectGrabber")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ObjectGrabber")]
[assembly: AssemblyTitle("ObjectGrabber")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ObjectGrabber;

[BepInPlugin("top.zman350x.hff.objectgrabber", "Grab Count Tracker", "1.3.1")]
[BepInProcess("Human.exe")]
public sealed class GrabberTracker : BaseUnityPlugin
{
	public static GrabberTracker instance;

	public bool isEnabled;

	private ConfigEntry<bool> defaultEnabled;

	private uint grabs;

	private GameObject textObj;

	private TextMeshProUGUI textVisuals;

	private void Awake()
	{
		instance = this;
		defaultEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General.Toggles", "DefaultEnabled", false, "Whether or not the \"Grab: X\" text is visible by default when you launch the game.");
		isEnabled = defaultEnabled.Value;
		Harmony.CreateAndPatchAll(typeof(GrabberTracker), "GrabberTracker");
	}

	private void OnDestroy()
	{
		Object.Destroy((Object)(object)textObj);
		Harmony.UnpatchID("GrabberTracker");
	}

	private void Start()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		SetupTMP(ref textObj, ref textVisuals, new Vector3(106.4688f, 9f, 0f));
		textObj.SetActive(isEnabled);
		grabs = 0u;
		UpdateText();
		Shell.RegisterCommand("grab_reset", (Action<string>)delegate
		{
			ResetGrabCounter();
		}, "Reset grab counter to 0");
		Shell.RegisterCommand("grab_toggle", (Action<string>)delegate
		{
			SetGrabCounterState(!isEnabled);
		}, "Enable/disable grab counter");
	}

	public void ResetGrabCounter(bool print = true)
	{
		grabs = 0u;
		UpdateText();
		if (print)
		{
			Shell.Print("Grab counter reset");
		}
	}

	public void SetGrabCounterState(bool state, bool print = true)
	{
		isEnabled = state;
		textObj.SetActive(isEnabled);
		ResetGrabCounter(print: false);
		if (print)
		{
			Shell.Print(isEnabled ? "Grab counter enabled" : "Grab counter disabled");
		}
	}

	private void UpdateText()
	{
		((TMP_Text)textVisuals).text = "Grabs: " + grabs;
	}

	[HarmonyPatch(typeof(GrabManager), "ObjectGrabbed")]
	[HarmonyPrefix]
	private static void ObjectGrabbed(GameObject grabObject)
	{
		instance.grabs++;
		instance.UpdateText();
	}

	private static void SetupTMP(ref GameObject gameObj, ref TextMeshProUGUI textContent, Vector3 coords)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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)
		gameObj = new GameObject("GrabberText");
		gameObj.transform.parent = GameObject.Find("Menu").transform;
		gameObj.AddComponent<CanvasRenderer>();
		textContent = gameObj.AddComponent<TextMeshProUGUI>();
		((Graphic)textContent).color = Color.white;
		((TMP_Text)textContent).fontSize = 50f;
		((TMP_Text)textContent).font = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().Single((TMP_FontAsset font) => ((Object)font).name == "Blogger_Sans-Bold SDF");
		((TMP_Text)textContent).fontMaterial = Resources.FindObjectsOfTypeAll<Material>().Single((Material material) => ((Object)material).name == "Blogger_Sans-Bold SDF Instruction");
		((TMP_Text)textContent).enableWordWrapping = false;
		((TMP_Text)textContent).alignment = (TextAlignmentOptions)2049;
		RectTransform component = gameObj.GetComponent<RectTransform>();
		component.anchorMin = Vector2.zero;
		component.anchorMax = Vector2.zero;
		component.anchoredPosition3D = coords;
		gameObj.transform.localRotation = Quaternion.identity;
		gameObj.transform.localScale = Vector3.one;
		gameObj.layer = LayerMask.NameToLayer("UI");
	}
}