Decompiled source of LethalExperience v1.1.0

plugins/LethalExperience.dll

Decompiled 12 months ago
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalExperience.Patches;
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: AssemblyTitle("LethalExperience")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalExperience")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("54608efe-5a52-4472-8a06-332d8a1af55a")]
[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 LethalExperience
{
	[BepInPlugin("Stoneman.LethalExperience", "Lethal Experience", "1.1.0")]
	public class LethalXP : BaseUnityPlugin
	{
		private const string modGUID = "Stoneman.LethalExperience";

		private const string modName = "Lethal Experience";

		private const string modVersion = "1.1.0";

		private const string modAuthor = "Stoneman";

		internal static ConfigEntry<int> configXP;

		internal static ConfigEntry<int> configLevel;

		internal static ConfigEntry<int> configProfit;

		internal static ConfigEntry<int> configSkillpoints;

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("Stoneman.LethalExperience");
			val.PatchAll(Assembly.GetExecutingAssembly());
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Lethal Experience loaded!");
			configXP = ((BaseUnityPlugin)this).Config.Bind<int>("General", "XP", 0, "How much XP you've gained while playing with this mod. Best not to touch this :)");
			configLevel = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Level", 0, "What level you are. Don't cheat now.");
			configProfit = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Profit", 0, "How much profit did you make the company? Best not to touch this :)");
			configSkillpoints = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Skillpoints", 0, "How many skillpoints you have. Don't cheat now.");
		}

		public static void AddXP(int xp)
		{
			int value = configXP.Value;
			ConfigEntry<int> obj = configXP;
			obj.Value += xp;
			ConfigEntry<int> obj2 = configProfit;
			obj2.Value += xp;
			int value2 = configXP.Value;
			if (configXP.Value >= GetXPRequirement())
			{
				ConfigEntry<int> obj3 = configXP;
				obj3.Value -= GetXPRequirement();
				ConfigEntry<int> obj4 = configLevel;
				int value3 = obj4.Value;
				obj4.Value = value3 + 1;
				HUDManagerPatch.ShowLevelUp();
				if (configLevel.Value % 5 == 0)
				{
					ConfigEntry<int> obj5 = configSkillpoints;
					value3 = obj5.Value;
					obj5.Value = value3 + 1;
				}
			}
			HUDManagerPatch.ShowXPUpdate(value, value2, xp);
		}

		public static int GetXP()
		{
			return configXP.Value;
		}

		public static int GetLevel()
		{
			return configLevel.Value;
		}

		public static int GetXPRequirement()
		{
			return 100 + GetLevel() * 10;
		}

		public static int GetSkillpoints()
		{
			return configSkillpoints.Value;
		}

		public static void SetSkillpoints(int skillpoints)
		{
			configSkillpoints.Value = skillpoints;
		}
	}
}
namespace LethalExperience.Patches
{
	[HarmonyPatch]
	internal class HUDManagerPatch
	{
		private static GameObject _tempBar;

		private static TextMeshProUGUI _tempText;

		private static float _tempBarTime;

		private static TextMeshProUGUI _LevelText;

		private static float _LevelTextTime;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(HUDManager), "DisplayNewScrapFound")]
		private static void GiveXPForScrap(HUDManager __instance)
		{
			List<GrabbableObject> itemsToBeDisplayed = __instance.itemsToBeDisplayed;
			if (itemsToBeDisplayed != null)
			{
				int scrapValue = itemsToBeDisplayed[0].scrapValue;
				LethalXP.AddXP(scrapValue);
			}
		}

		public static void ShowXPUpdate(int oldXP, int newXP, int xp)
		{
			if (!Object.op_Implicit((Object)(object)_tempBar))
			{
				MakeBar();
			}
			GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/XPUpdate/XPBarProgress");
			val.GetComponent<Image>().fillAmount = (float)newXP / (float)LethalXP.GetXPRequirement();
			((TMP_Text)_tempText).text = newXP + " / " + (float)LethalXP.GetXPRequirement();
			_tempBarTime = 2f;
			if (!_tempBar.activeSelf)
			{
				((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(XPBarCoroutine());
			}
		}

		private static IEnumerator XPBarCoroutine()
		{
			_tempBar.SetActive(true);
			while (_tempBarTime > 0f)
			{
				float time = _tempBarTime;
				_tempBarTime = 0f;
				yield return (object)new WaitForSeconds(time);
			}
			_tempBar.SetActive(false);
		}

		public static void ShowLevelUp()
		{
			if (!Object.op_Implicit((Object)(object)_LevelText))
			{
				MakeLevelUp();
			}
			_LevelTextTime = 2f;
			if (!((Component)_LevelText).gameObject.activeSelf)
			{
				((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(LevelUpCoroutine());
			}
		}

		public static void MakeLevelUp()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			_LevelText = new GameObject().AddComponent<TextMeshProUGUI>();
			((Object)_LevelText).name = "LevelUp";
			GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle");
			((TMP_Text)_LevelText).transform.SetParent(val.transform, false);
			((TMP_Text)_LevelText).transform.Translate(1.5f, 0.4f, 0f);
			((TMP_Text)((Component)_LevelText).GetComponent<TextMeshProUGUI>()).text = "Level Up!";
			((Graphic)((Component)_LevelText).GetComponent<TextMeshProUGUI>()).color = new Color(0.6f, 1f, 1f, 1f);
			TMP_FontAsset font = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset t) => ((Object)t).name == "3270-HUDIngame"));
			((TMP_Text)((Component)_LevelText).GetComponent<TextMeshProUGUI>()).font = font;
			((TMP_Text)((Component)_LevelText).GetComponent<TextMeshProUGUI>()).fontSize = 50f;
			((TMP_Text)((Component)_LevelText).GetComponent<TextMeshProUGUI>()).alignment = (TextAlignmentOptions)514;
			((Component)_LevelText).gameObject.SetActive(false);
		}

		private static IEnumerator LevelUpCoroutine()
		{
			((Component)_LevelText).gameObject.SetActive(true);
			while (_LevelTextTime > 0f)
			{
				float time = _LevelTextTime;
				_LevelTextTime = 0f;
				yield return (object)new WaitForSeconds(time);
			}
			((Component)_LevelText).gameObject.SetActive(false);
		}

		private static void MakeBar()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("/Systems/UI/Canvas/QuickMenu/XPBar");
			QuickMenuManagerPatch.MakeNewXPBar();
			val = GameObject.Find("/Systems/UI/Canvas/QuickMenu/XPBar");
			_tempBar = Object.Instantiate<GameObject>(val);
			((Object)_tempBar).name = "XPUpdate";
			_tempText = _tempBar.GetComponentInChildren<TextMeshProUGUI>();
			GameObject val2 = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle");
			_tempBar.transform.SetParent(val2.transform, false);
			_tempBar.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
			GameObject val3 = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/XPUpdate/XPLevel");
			Object.Destroy((Object)(object)val3);
			GameObject val4 = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/XPUpdate/XPProfit");
			Object.Destroy((Object)(object)val4);
			_tempBar.transform.Translate(3.1f, -2.1f, 0f);
			Vector3 localPosition = _tempBar.transform.localPosition;
			_tempBar.transform.localPosition = new Vector3(localPosition.x, localPosition.y + 5f, localPosition.z);
			_tempBar.SetActive(false);
		}
	}
	[HarmonyPatch]
	internal class QuickMenuManagerPatch
	{
		private static GameObject _xpBar;

		private static GameObject _xpBarProgress;

		private static TextMeshProUGUI _xpText;

		private static TextMeshProUGUI _xpLevel;

		private static TextMeshProUGUI _profit;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(QuickMenuManager), "OpenQuickMenu")]
		private static void QuickMenuXPBar(QuickMenuManager __instance)
		{
			if (__instance.isMenuOpen)
			{
				if (!Object.op_Implicit((Object)(object)_xpBar) || !Object.op_Implicit((Object)(object)_xpBarProgress))
				{
					MakeNewXPBar();
				}
				_xpBar.SetActive(true);
				_xpBarProgress.SetActive(true);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(QuickMenuManager), "Update")]
		private static void XPMenuUpdate(QuickMenuManager __instance)
		{
			if (Object.op_Implicit((Object)(object)_xpBar) && Object.op_Implicit((Object)(object)_xpBarProgress))
			{
				if (__instance.settingsPanel.activeSelf || __instance.leaveGameConfirmPanel.activeSelf)
				{
					_xpBar.SetActive(false);
					_xpBarProgress.SetActive(false);
					return;
				}
				_xpBar.SetActive(true);
				_xpBarProgress.SetActive(true);
				((TMP_Text)_xpText).text = LethalXP.configXP.Value + " / " + LethalXP.GetXPRequirement();
				((TMP_Text)_xpLevel).text = "Level: " + LethalXP.configLevel.Value;
				((TMP_Text)_profit).text = "You've made.. " + LethalXP.configProfit.Value + "$";
				_xpBarProgress.GetComponent<Image>().fillAmount = (float)LethalXP.configXP.Value / (float)LethalXP.GetXPRequirement();
			}
		}

		public static void MakeNewXPBar()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("/Systems/UI/Canvas/QuickMenu");
			if (!Object.op_Implicit((Object)(object)_xpBar))
			{
				GameObject val2 = GameObject.Find("/Systems/UI/Canvas/EndgameStats/LevelUp/LevelUpBox");
				_xpBar = Object.Instantiate<GameObject>(val2);
				((Object)_xpBar).name = "XPBar";
				_xpBar.transform.SetParent(val.transform, false);
				_xpBar.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f);
				_xpBar.transform.Translate(-2f, 1f, 0f);
			}
			if (!Object.op_Implicit((Object)(object)_xpBarProgress))
			{
				GameObject val3 = GameObject.Find("/Systems/UI/Canvas/EndgameStats/LevelUp/LevelUpMeter");
				_xpBarProgress = Object.Instantiate<GameObject>(val3);
				((Object)_xpBarProgress).name = "XPBarProgress";
				_xpBarProgress.transform.SetParent(_xpBar.transform, false);
				_xpBarProgress.GetComponent<Image>().fillAmount = 0f;
				_xpBarProgress.transform.localScale = new Vector3(0.597f, 5.21f, 1f);
				_xpBarProgress.transform.Translate(-0.8f, 0.2f, 0f);
				Vector3 localPosition = _xpBarProgress.transform.localPosition;
				_xpBarProgress.transform.localPosition = new Vector3(localPosition.x + 7f, localPosition.y - 3.5f, 0f);
				GameObject val4 = GameObject.Find("/Systems/UI/Canvas/EndgameStats/LevelUp/Total");
				_xpText = Object.Instantiate<GameObject>(val4).GetComponent<TextMeshProUGUI>();
				((Object)_xpText).name = "XPText";
				((TMP_Text)_xpText).alignment = (TextAlignmentOptions)514;
				((TMP_Text)_xpText).SetText("0/1000", true);
				((TMP_Text)_xpText).transform.SetParent(_xpBar.transform, false);
				((Graphic)_xpText).color = new Color(1f, 0.6f, 0f, 1f);
				((TMP_Text)_xpText).transform.Translate(-0.75f, 0.21f, 0f);
				_xpLevel = Object.Instantiate<GameObject>(val4).GetComponent<TextMeshProUGUI>();
				((Object)_xpLevel).name = "XPLevel";
				((TMP_Text)_xpLevel).alignment = (TextAlignmentOptions)514;
				((TMP_Text)_xpLevel).SetText("Level: 0", true);
				((TMP_Text)_xpLevel).transform.SetParent(_xpBar.transform, false);
				((Graphic)_xpLevel).color = new Color(1f, 0.6f, 0f, 1f);
				((TMP_Text)_xpLevel).transform.Translate(-1f, 0.4f, 0f);
				_profit = Object.Instantiate<GameObject>(val4).GetComponent<TextMeshProUGUI>();
				((Object)_profit).name = "XPProfit";
				((TMP_Text)_profit).alignment = (TextAlignmentOptions)514;
				((TMP_Text)_profit).SetText("You've made.. 0$.", true);
				((TMP_Text)_profit).transform.SetParent(_xpBar.transform, false);
				((Graphic)_profit).color = new Color(1f, 0.6f, 0f, 1f);
				((TMP_Text)_profit).transform.Translate(-0.8f, 0f, 0f);
			}
		}
	}
}