Decompiled source of UpgradesPlus v0.0.3

UpgradesPlus.dll

Decompiled 2 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.Bootstrap;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UpgradeLib;

[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.6.1", FrameworkDisplayName = ".NET Framework 4.6.1")]
[assembly: AssemblyCompany("UpgradesPlus")]
[assembly: AssemblyConfiguration("b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UpgradesPlus")]
[assembly: AssemblyTitle("UpgradesPlus")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.tawoly.upgpl", "Upgrades Plus", "0.0.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class UpgradesPlusMod : BaseUnityPlugin
{
	public static MethodInfo originalUpdate;

	public static MethodInfo scanLockPrefix;

	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("com.tawoly.upgpl");
		val.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"UpgradesPlusMod: Loaded and Harmony-Patches active");
		UpgradesPlus.Init();
	}
}
public static class UpgradesPlus
{
	public static void Init()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		UpgradeLibManager.Init("com.tawoly.upgpl");
		UpgradeDefinition val = new UpgradeDefinition(76770, "scanning_station", "Scanning Station", "You dont need a Scanner for scanning anymore", 500, false, (Action<bool>)delegate
		{
			GameObject[] equipmentObjects = PlayerItemManager.instance.equipmentObjects;
			foreach (GameObject val4 in equipmentObjects)
			{
				if (((Object)val4).name == "Scanner")
				{
					val4.SetActive(true);
				}
			}
			ScanningStationPatches.InitScannerController();
			addScanningStationUpgrades();
		}, (Action)null);
		UpgradeDefinition val2 = new UpgradeDefinition(76780, "Cargo_Pants", "Cargo Pants", "Grants an extra Inventore Slot", 100, false, (Action<bool>)delegate
		{
			CargoSlotPatches.cargoPantsActive = true;
			addCargoPantsUpgrades();
		}, (Action)null);
		UpgradeDefinition val3 = new UpgradeDefinition(76790, "Pocket_Watch", "Pocket Watch", "Shows Daytime on GUI", 50, false, (Action<bool>)delegate
		{
			PocketWatchPatches.pocketWatchActive = true;
		}, (Action)null);
		UpgradeLibManager.RegisterUpgrade(val);
		UpgradeLibManager.RegisterUpgrade(val2);
		UpgradeLibManager.RegisterUpgrade(val3);
	}

	public static void addScanningStationUpgrades()
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Expected O, but got Unknown
		if ((Object)(object)ScanningStationPatches.scannerController == (Object)null)
		{
			return;
		}
		UpgradeDefinition val = new UpgradeDefinition(76771, "scan_distance_plus", "Scanning Distance+", "The scanning radius now has a higher radius", 100, true, (Action<bool>)delegate
		{
			ScanningStationPatches.scanDistMod += 0.75f;
		}, (Action)null);
		if (Chainloader.PluginInfos.ContainsKey("com.tawoly.ScanLock"))
		{
			UpgradeDefinition val2 = new UpgradeDefinition(76772, "scan_lock", "Scan Lock", "press the scan key once to activate continuous scanning", 20, false, (Action<bool>)delegate
			{
				ScanningStationPatches.scanLockActive = true;
			}, (Action)null);
			UpgradeLibManager.RegisterUpgrade(val2);
		}
		UpgradeLibManager.RegisterUpgrade(val);
	}

	public static void addCargoPantsUpgrades()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		UpgradeDefinition val = new UpgradeDefinition(76781, "Utility_Belt", "Utility Belt", "If you put the Flashlight in your CargoPants-Slot the Flashlight stays on even if not in Hand", 50, false, (Action<bool>)delegate
		{
			CargoSlotPatches.utilityBeltActive = true;
		}, (Action)null);
	}
}
[HarmonyPatch]
public static class CargoSlotPatches
{
	public static bool cargoPantsActive;

	public static bool utilityBeltActive;

	private static UsableItem tmpComp;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerItemManager), "Update")]
	private static void OnAfterUpdate(PlayerItemManager __instance)
	{
		HandleCargoPants(__instance);
	}

	private static void HandleCargoPants(PlayerItemManager __instance)
	{
		if (cargoPantsActive)
		{
			if (PlayerItemManager.instance.inventory.Length == 7)
			{
				PlayerItemManager.instance.ChangeInventorySize(8);
			}
			else if (PlayerItemManager.instance.inventory.Length == 5)
			{
				PlayerItemManager.instance.ChangeInventorySize(6);
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(InventoryUI), "UpdateSlots")]
	public static void OnAfterUpdateSlots(InventoryUI __instance)
	{
		ChangeCargoSlotColor(__instance);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(InventoryUI), "Update")]
	private static void OnAfterUpdate(InventoryUI __instance)
	{
		ChangeCargoSlotColor(__instance);
	}

	private static void ChangeCargoSlotColor(InventoryUI __instance)
	{
		if (!cargoPantsActive)
		{
			return;
		}
		FieldInfo field = typeof(InventoryUI).GetField("slots", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null)
		{
			return;
		}
		GameObject[] array = (GameObject[])field.GetValue(__instance);
		if (array != null && array.Length != 0)
		{
			TMP_Text componentInChildren = array[0].GetComponentInChildren<TMP_Text>();
			if (!((Object)(object)componentInChildren == (Object)null) && !componentInChildren.text.Contains("<color="))
			{
				componentInChildren.text = "<color=#28612A>|" + componentInChildren.text + "|</color>";
				field.SetValue(__instance, array);
			}
		}
	}
}
[HarmonyPatch]
public static class ScanningStationPatches
{
	public static bool scanLockActive;

	public static ScannerController scannerController;

	public static float defaultScanDist;

	public static float scanDistMod;

	public static void InitScannerController()
	{
		scannerController = Resources.FindObjectsOfTypeAll<ScannerController>().FirstOrDefault();
		defaultScanDist = scannerController.scanDistance;
		scanDistMod = 0.75f;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(ScannerController), "Scan")]
	public static void OnBeforeScan(ScannerController __instance)
	{
		if (!((Object)(object)scannerController == (Object)null) && !scannerController.scanning)
		{
			if (PlayerItemManager.instance.equipment.hotbarName.Equals("Scanner", StringComparison.OrdinalIgnoreCase))
			{
				scannerController.scanDistance = defaultScanDist;
			}
			else
			{
				scannerController.scanDistance = defaultScanDist * scanDistMod;
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerItemManager), "DeactivateEquipmentItem")]
	private static bool OnBeforeDeactivateEquipmentItem()
	{
		if ((Object)(object)scannerController == (Object)null)
		{
			return true;
		}
		GameObject[] equipmentObjects = PlayerItemManager.instance.equipmentObjects;
		for (int i = 0; i < equipmentObjects.Length; i++)
		{
			if (((Object)equipmentObjects[i]).name == "Scanner")
			{
				equipmentObjects[i].SetActive(true);
			}
			else
			{
				equipmentObjects[i].SetActive(false);
			}
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(ScannerControllerPatch), "UpdatePatch")]
	private static bool OnBeforeUpdatePatch()
	{
		return scanLockActive;
	}
}
[HarmonyPatch]
public static class PocketWatchPatches
{
	public static bool pocketWatchActive;

	[HarmonyPrefix]
	[HarmonyPatch(typeof(HUDClock), "Update")]
	private static bool OnBeforeUpdate(HUDClock __instance)
	{
		if (pocketWatchActive)
		{
			return true;
		}
		FieldInfo field = typeof(HUDClock).GetField("textDisplay", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null)
		{
			return true;
		}
		object? value = field.GetValue(__instance);
		TMP_Text val = (TMP_Text)((value is TMP_Text) ? value : null);
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		val.text = " ";
		return false;
	}
}
[HarmonyPatch]
public static class MiscPatches
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(TerminalManager), "OnGUI")]
	private static void OnBeforeGUI(TerminalManager __instance)
	{
		int num = Array.FindIndex(__instance.commands, (TerminalCommand n) => n.command.ToLower() == "buy_upgrade");
		if (num >= 0)
		{
			__instance.commands[num].command = "BUY";
		}
	}
}