Decompiled source of App Usage v1.3.0

plugins/kstelakis.AppUsage.dll

Decompiled 12 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Aggro.Core;
using Aggro.Core.Networking;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("febjam")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("kstelakis.AppUsage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+f7be66accbef905deb6d9a4db279929707e9eb05")]
[assembly: AssemblyProduct("kstelakis.AppUsage")]
[assembly: AssemblyTitle("AppUsage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace AppUsage
{
	[HarmonyPatch(typeof(LobbyManager), "RpcRunStarting")]
	internal class RpcRunStartingPatch
	{
		private static void Postfix(LobbyManager __instance)
		{
			Plugin.Log.LogInfo((object)"New Contract Starting");
			Plugin.TipTapSecondsContract = 0.0;
			float num = default(float);
			if (Platform.TryGetStat("stat_tiptap_minutes", ref num))
			{
				Plugin.TipTapSeconds = num * 60f;
				Plugin.Log.LogInfo((object)$"Retrieved {num * 60f} already watched seconds of TipTap from Steam");
			}
		}
	}
	[BepInPlugin("kstelakis.AppUsage", "AppUsage", "1.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		private static GameObject textParent;

		private static TMP_Text _tipTapTimeText;

		private static TMP_Text _tipTapTimeShiftText;

		private static TMP_Text _tipTapTimeContractText;

		private static double _tipTapSeconds;

		private static double _tipTapSecondsShift;

		private static double _tipTapSecondsContract;

		public const string Id = "kstelakis.AppUsage";

		internal static ManualLogSource Log { get; private set; }

		public static double TipTapSeconds
		{
			get
			{
				return _tipTapSeconds;
			}
			set
			{
				_tipTapSeconds = value;
				UpdateAppUsage();
			}
		}

		public static double TipTapSecondsShift
		{
			get
			{
				return _tipTapSecondsShift;
			}
			set
			{
				_tipTapSecondsShift = value;
				UpdateAppUsage();
			}
		}

		public static double TipTapSecondsContract
		{
			get
			{
				return _tipTapSecondsContract;
			}
			set
			{
				_tipTapSecondsContract = value;
				UpdateAppUsage();
			}
		}

		public static string Name => "AppUsage";

		public static string Version => "1.3.0";

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("com.github.Stelios-Kourlis.AppUsage");
			_harmony.PatchAll();
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private static void UpdateAppUsage()
		{
			if ((Object)(object)_tipTapTimeText != (Object)null)
			{
				TimeSpan timeSpan = TimeSpan.FromSeconds(TipTapSeconds);
				int num = (int)timeSpan.TotalHours;
				_tipTapTimeText.text = $"Total: {num:D2}:{timeSpan.Minutes:D2}:{timeSpan.Seconds:D2}";
			}
			if ((Object)(object)_tipTapTimeContractText != (Object)null)
			{
				TimeSpan timeSpan2 = TimeSpan.FromSeconds(TipTapSecondsContract);
				_tipTapTimeContractText.text = $"Contract: {timeSpan2.Minutes:D2}:{timeSpan2.Seconds:D2}";
			}
			if ((Object)(object)_tipTapTimeShiftText != (Object)null)
			{
				TimeSpan timeSpan3 = TimeSpan.FromSeconds(TipTapSecondsShift);
				_tipTapTimeShiftText.text = $"Shift: {timeSpan3.Minutes:D2}:{timeSpan3.Seconds:D2}";
			}
		}

		public static void SpawnUI()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_008e: Expected O, but got Unknown
			//IL_00a6: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			Scene sceneByName = SceneManager.GetSceneByName("scene-run");
			if (!((Scene)(ref sceneByName)).isLoaded)
			{
				Debug.LogWarning((object)"'scene-run' is not currently loaded.");
				return;
			}
			GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
			RectTransform component = ((Component)((IEnumerable<GameObject>)rootGameObjects).FirstOrDefault((Func<GameObject, bool>)((GameObject gameObject) => ((Object)gameObject).name == "ui")).transform.Find("game-ui").Find("UICamera").Find("Canvas")
				.Find("prefab-tiptap")).GetComponent<RectTransform>();
			textParent = new GameObject("appUsage");
			RectTransform val = textParent.AddComponent<RectTransform>();
			((Transform)val).SetParent((Transform)(object)component, false);
			RectTransform val2 = new GameObject("tipTapTimeText").AddComponent<RectTransform>();
			((Transform)val2).position = GetRelativeScreenSpaceCoordinates(1500f, 650f);
			((Transform)val2).SetParent((Transform)(object)val, true);
			val2.sizeDelta = new Vector2(400f, 50f);
			_tipTapTimeText = (TMP_Text)(object)((Component)val2).gameObject.AddComponent<TextMeshProUGUI>();
			RectTransform val3 = new GameObject("tipTapTimeShiftText").AddComponent<RectTransform>();
			((Transform)val3).position = GetRelativeScreenSpaceCoordinates(1500f, 600f);
			((Transform)val3).SetParent((Transform)(object)val, true);
			val3.sizeDelta = new Vector2(400f, 50f);
			_tipTapTimeShiftText = (TMP_Text)(object)((Component)val3).gameObject.AddComponent<TextMeshProUGUI>();
			RectTransform val4 = new GameObject("tipTapTimeContractText").AddComponent<RectTransform>();
			((Transform)val4).position = GetRelativeScreenSpaceCoordinates(1500f, 550f);
			((Transform)val4).SetParent((Transform)(object)val, true);
			val4.sizeDelta = new Vector2(400f, 50f);
			_tipTapTimeContractText = (TMP_Text)(object)((Component)val4).gameObject.AddComponent<TextMeshProUGUI>();
			UpdateAppUsage();
		}

		public static void DestroyUI()
		{
			if ((Object)(object)textParent != (Object)null)
			{
				Object.Destroy((Object)(object)textParent);
				textParent = null;
				_tipTapTimeText = null;
				_tipTapTimeShiftText = null;
				_tipTapTimeContractText = null;
			}
		}

		private static Vector3 GetRelativeScreenSpaceCoordinates(float baselineX, float baselineY)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			float num = baselineX / 1920f * (float)Screen.width;
			float num2 = baselineY / 1080f * (float)Screen.height;
			return new Vector3(num, num2, 10f);
		}
	}
	[HarmonyPatch(typeof(ShiftManager), "ShiftChanged")]
	internal class ShiftChangedPatch
	{
		private static void Postfix(ShiftManager __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)__instance._shiftPhase == 2)
			{
				Plugin.Log.LogInfo((object)"Shift Changed to Organizational");
				Plugin.TipTapSecondsShift = 0.0;
			}
		}
	}
	[HarmonyPatch(typeof(TipTapManager), "AddToTipTapSeconds")]
	internal class TipTapManagerPatch
	{
		private static void Postfix(TipTapManager __instance, float dt)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			if (!GameUtil.isTutorial && GameUtil.isRun && NetworkAggroManagerBase<ShiftManager>.ManagerExists() && (int)NetworkAggroManagerBase<ShiftManager>.instance.GetShiftPhase() == 3)
			{
				Plugin.TipTapSecondsShift = __instance._tipTapSecondsThisShift;
				Plugin.TipTapSecondsContract = __instance._tipTapSeconds;
				Plugin.TipTapSeconds += dt;
			}
		}
	}
	[HarmonyPatch(typeof(TipTapPhoneVisual), "OpenTipTap")]
	internal class OpenTipTapPatch
	{
		private static void Postfix(TipTapPhoneVisual __instance)
		{
			Plugin.Log.LogInfo((object)"Opened TipTap");
			Plugin.SpawnUI();
		}
	}
	[HarmonyPatch(typeof(TipTapPhoneVisual), "CloseTipTap")]
	internal class CloseTipTapPatch
	{
		private static void Postfix(TipTapPhoneVisual __instance)
		{
			Plugin.Log.LogInfo((object)"Closed TipTap");
			Plugin.DestroyUI();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}