Decompiled source of ShipLootCruiser v1.0.5

OreoM.ShipLootCruiser.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HQoL.Network;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("OreoM.HQoL.72")]
[assembly: IgnoresAccessChecksTo("OreoM.HQoL.73")]
[assembly: AssemblyCompany("OreoM.ShipLootCruiser")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyProduct("ShipLootCruiser")]
[assembly: AssemblyTitle("OreoM.ShipLootCruiser")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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 ShipLootCruiser
{
	[BepInPlugin("OreoM.ShipLootCruiser", "ShipLootCruiser", "1.0.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ShipLootCruiser : BaseUnityPlugin
	{
		private const string HQoL72GUID = "OreoM.HQoL.72";

		private const string HQoL73GUID = "OreoM.HQoL.73";

		internal static readonly FieldInfo? gObjDeactivated = AccessTools.Field(typeof(GrabbableObject), "deactivated");

		internal static ShipLootCruiserConfig config = null;

		internal static bool isHQoLLoaded = false;

		public static ShipLootCruiser Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			config = new ShipLootCruiserConfig(((BaseUnityPlugin)this).Config);
			isHQoLLoaded = Chainloader.PluginInfos.ContainsKey("OreoM.HQoL.72") || Chainloader.PluginInfos.ContainsKey("OreoM.HQoL.73");
			Patch();
			Logger.LogInfo((object)"OreoM.ShipLootCruiser v1.0.5 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("OreoM.ShipLootCruiser");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	internal class ShipLootCruiserConfig
	{
		private readonly ConfigFile _configFile;

		public ConfigEntry<float> DisplayTime;

		public ShipLootCruiserConfig(ConfigFile configFile)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			_configFile = configFile;
			DisplayTime = _configFile.Bind<float>("General", "DisplayTime", 5f, new ConfigDescription("How long to display the total scrap value for, counted in seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "OreoM.ShipLootCruiser";

		public const string PLUGIN_NAME = "ShipLootCruiser";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}
namespace ShipLootCruiser.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HudManagerPatcher
	{
		[CompilerGenerated]
		private sealed class <ShipLootCoroutine>d__5 : IEnumerator<object>, IEnumerator, IDisposable
		{
			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 <ShipLootCoroutine>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					_totalCounter.SetActive(true);
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (_displayTimeLeft > 0f)
				{
					float displayTimeLeft = _displayTimeLeft;
					_displayTimeLeft = 0f;
					<>2__current = (object)new WaitForSeconds(displayTimeLeft);
					<>1__state = 1;
					return true;
				}
				_totalCounter.SetActive(false);
				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 _totalCounter;

		private static TextMeshProUGUI _textMesh;

		private static float _displayTimeLeft;

		[HarmonyPatch("PingScan_performed")]
		[HarmonyPrefix]
		private static void PingScan_performedPrePatch(HUDManager __instance, ref CallbackContext context)
		{
			if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && ((CallbackContext)(ref context)).performed && __instance.CanPlayerScan() && !(__instance.playerPingingScan > -0.5f) && (StartOfRound.Instance.inShipPhase || GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom))
			{
				if (!Object.op_Implicit((Object)(object)_totalCounter))
				{
					CopyValueCounter();
				}
				float num = GetValueOfAllScrap() - StartOfRound.Instance.GetBodiesInShip() * 5;
				if (ShipLootCruiser.isHQoLLoaded)
				{
					num += (float)GetHQoLStorageValue();
				}
				((TMP_Text)_textMesh).text = $"SHIP: ${num:F0}";
				_displayTimeLeft = ShipLootCruiser.config.DisplayTime.Value;
				if (!_totalCounter.activeSelf)
				{
					((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(ShipLootCoroutine());
				}
			}
		}

		private static int GetValueOfAllScrap(bool onlyScrapCollected = true, bool onlyNewScrap = false)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			int num = 0;
			for (int i = 0; i < array.Length; i++)
			{
				Bounds bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
				if (((Bounds)(ref bounds)).Contains(((Component)array[i]).transform.position))
				{
					array[i].isInShipRoom = true;
				}
			}
			for (int j = 0; j < array.Length; j++)
			{
				if ((!onlyNewScrap || !array[j].scrapPersistedThroughRounds) && array[j].itemProperties.isScrap && (!(ShipLootCruiser.gObjDeactivated != null) || !(bool)ShipLootCruiser.gObjDeactivated.GetValue(array[j])) && !array[j].itemUsedUp && (array[j].isInShipRoom || !onlyScrapCollected))
				{
					num += array[j].scrapValue;
				}
			}
			return num;
		}

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

		private static void CopyValueCounter()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/ValueCounter");
			if (!Object.op_Implicit((Object)(object)val))
			{
				ShipLootCruiser.Logger.LogError((object)"Failed to find ValueCounter object to copy!");
			}
			_totalCounter = Object.Instantiate<GameObject>(val.gameObject, val.transform.parent, false);
			_totalCounter.transform.Translate(0f, 1f, 0f);
			Vector3 localPosition = _totalCounter.transform.localPosition;
			_totalCounter.transform.localPosition = new Vector3(localPosition.x + 50f, -50f, localPosition.z);
			_textMesh = _totalCounter.GetComponentInChildren<TextMeshProUGUI>();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static int GetHQoLStorageValue()
		{
			if ((Object)(object)HQoLNetwork.Instance != (Object)null)
			{
				return HQoLNetwork.Instance.totalStorageValue.Value;
			}
			if ((Object)(object)HQoLNetwork.Instance != (Object)null)
			{
				return HQoLNetwork.Instance.totalStorageValue.Value;
			}
			return 0;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}