Decompiled source of CruiserLoot v1.0.0

CruiserLoot.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CruiserLoot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CruiserLoot")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7af209c4-3f54-44b2-bec4-0be24f98d857")]
[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 CruiserLoot;

[BepInPlugin("azumi.cruiserloot", "CruiserLoot", "1.0.0")]
public class CruiserLootPlugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> DisplayEnabled;

	internal static ConfigEntry<float> DisplayTime;

	internal static ConfigEntry<bool> AllowOutsideAtTheCompany;

	private Harmony harmony;

	private void Awake()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		DisplayEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Display Enabled", true, "Enable CruiserLoot UI display.");
		DisplayTime = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Display Time", 5f, new ConfigDescription("UI display duration (seconds).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
		AllowOutsideAtTheCompany = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Allow Outside At The Company", false, "Allow UI outside ship at The Company Building.");
		harmony = new Harmony("azumi.cruiserloot");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"CruiserLoot v1.0.0 loaded.");
	}
}
[HarmonyPatch(typeof(HUDManager), "PingScan_performed")]
internal class CruiserScanPatch
{
	[CompilerGenerated]
	private sealed class <HideAfterTime>d__4 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <HideAfterTime>d__4(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(CruiserLootPlugin.DisplayTime.Value);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				HideUI();
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private static GameObject counterObject;

	private static TextMeshProUGUI counterText;

	private static Coroutine displayCoroutine;

	public static void Postfix()
	{
		if (!CruiserLootPlugin.DisplayEnabled.Value)
		{
			HideUI();
		}
		else
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null)
			{
				HideUI();
				return;
			}
			bool isInHangarShipRoom = localPlayerController.isInHangarShipRoom;
			bool flag = (Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.currentLevel != (Object)null && StartOfRound.Instance.currentLevel.PlanetName != null && StartOfRound.Instance.currentLevel.sceneName == "CompanyBuilding";
			bool flag2 = isInHangarShipRoom;
			if (CruiserLootPlugin.AllowOutsideAtTheCompany.Value && flag)
			{
				flag2 = true;
			}
			if (!flag2)
			{
				HideUI();
				return;
			}
			VehicleController val = Object.FindObjectOfType<VehicleController>();
			if ((Object)(object)val == (Object)null)
			{
				HideUI();
				return;
			}
			if (!val.magnetedToShip)
			{
				HideUI();
				return;
			}
			PlayerPhysicsRegion componentInChildren = ((Component)val).GetComponentInChildren<PlayerPhysicsRegion>();
			if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.physicsTransform == (Object)null)
			{
				HideUI();
				return;
			}
			GrabbableObject[] componentsInChildren = ((Component)componentInChildren.physicsTransform).GetComponentsInChildren<GrabbableObject>(true);
			int num = 0;
			int num2 = 0;
			GrabbableObject[] array = componentsInChildren;
			foreach (GrabbableObject val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null) && !(val2 is RagdollGrabbableObject) && !((Object)(object)val2.itemProperties == (Object)null) && val2.itemProperties.isScrap)
				{
					num += val2.scrapValue;
					num2++;
				}
			}
			CreateUI();
			if (!((Object)(object)counterText == (Object)null))
			{
				((TMP_Text)counterText).text = $"CRUISER: ${num} ({num2})";
				counterObject.SetActive(true);
				if (displayCoroutine != null)
				{
					((MonoBehaviour)GameNetworkManager.Instance).StopCoroutine(displayCoroutine);
				}
				displayCoroutine = ((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(HideAfterTime());
			}
		}
	}

	[IteratorStateMachine(typeof(<HideAfterTime>d__4))]
	private static IEnumerator HideAfterTime()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <HideAfterTime>d__4(0);
	}

	private static void HideUI()
	{
		if ((Object)(object)counterObject != (Object)null)
		{
			counterObject.SetActive(false);
		}
	}

	private static void CreateUI()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)counterObject != (Object)null)
		{
			return;
		}
		GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/ValueCounter");
		if ((Object)(object)val == (Object)null)
		{
			CruiserLootPlugin.Log.LogError((object)"ValueCounter not found.");
			return;
		}
		counterObject = Object.Instantiate<GameObject>(val, val.transform.parent, false);
		((Object)counterObject).name = "CruiserLootUI";
		Transform transform = counterObject.transform;
		transform.localPosition += new Vector3(50f, -2f, 0f);
		counterText = counterObject.GetComponentInChildren<TextMeshProUGUI>();
		if ((Object)(object)counterText != (Object)null)
		{
			RectTransform rectTransform = ((TMP_Text)counterText).rectTransform;
			rectTransform.anchoredPosition += new Vector2(200f, 0f);
			rectTransform.sizeDelta = new Vector2(600f, rectTransform.sizeDelta.y);
		}
		counterObject.SetActive(false);
	}
}