Decompiled source of ShowTotalLoot v1.0.50

ShowTotalLoot.dll

Decompiled a week 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.Logging;
using HarmonyLib;
using MenuLib;
using MenuLib.MonoBehaviors;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[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("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("ItsAGeBa")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+bfbbe9cfc727702984b5d4692f73adf5c2ae3b7d")]
[assembly: AssemblyProduct("ShowTotalLoot")]
[assembly: AssemblyTitle("ShowTotalLoot")]
[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 ShowTotalLoot
{
	[BepInPlugin("ItsAGeBa.ShowTotalLoot", "Show Total Loot", "1.0.5")]
	public class ShowTotalLoot : BaseUnityPlugin
	{
		private const string ModGuid = "ItsAGeBa.ShowTotalLoot";

		private const string ModName = "Show Total Loot";

		private const string ModVersion = "1.0.5";

		internal static ShowTotalLoot Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
		}

		internal void Patch()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}
namespace ShowTotalLoot.Patches
{
	[HarmonyPatch(typeof(RoundDirector))]
	public class ShowMaxHaulPatch
	{
		[CompilerGenerated]
		private sealed class <DelayedAddEnemyValuable>d__10 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public EnemyValuable enemyValuable;

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

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

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

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

			private bool MoveNext()
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					ValuableObject component = ((Component)enemyValuable).GetComponent<ValuableObject>();
					ShowTotalLoot.Logger.LogDebug((object)("DelayedAddEnemyValuable2(): EnemyValuable name: " + ((Object)enemyValuable).name));
					ShowTotalLoot.Logger.LogDebug((object)$"DelayedAddEnemyValuable2(): EnemyValuable name: {component.dollarValueOriginal}");
					int num = (int)component.dollarValueOriginal;
					_currentMaxHaul += num;
					UpdateLabel(_currentMaxHaul, "DelayedAddEnemyValuable");
					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 int _currentMaxHaul;

		private static Transform? _gameHud;

		private static REPOLabel? _maxHaulGoalLabel;

		private static bool isBreakRunning;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ExtractionPoint), "ActivateTheFirstExtractionPointAutomaticallyWhenAPlayerLeaveTruck")]
		private static void StartRound_Postfix(ExtractionPoint __instance)
		{
			ShowTotalLoot.Logger.LogDebug((object)$"StartRound_Postfix(): {__instance} Start Postfix");
			_currentMaxHaul = 0;
			if (!LevelGenerator.Instance.Generated)
			{
				ShowTotalLoot.Logger.LogError((object)"AddEnemyValuable_Postfix(): LevelGenerator has not finished generating the level");
				return;
			}
			if ((Object)(object)_gameHud == (Object)null)
			{
				ShowTotalLoot.Logger.LogError((object)"AddEnemyValuable_Postfix(): _gameHud is null");
				return;
			}
			if ((Object)(object)_maxHaulGoalLabel == (Object)null)
			{
				ShowTotalLoot.Logger.LogError((object)"AddEnemyValuable_Postfix(): _maxHaulGoalLabel is null");
				return;
			}
			((Component)_maxHaulGoalLabel).gameObject.SetActive(true);
			foreach (ValuableObject valuable in ValuableDirector.instance.valuableList)
			{
				_currentMaxHaul += (int)valuable.dollarValueCurrent;
			}
			ShowTotalLoot.Logger.LogDebug((object)$"StartRound_Postfix(): Total valuables in map: {ValuableDirector.instance.valuableList.Count}");
			UpdateLabel(_currentMaxHaul, "StartRound_Postfix");
			ShowTotalLoot.Logger.LogDebug((object)$"Round Max Haul: {_currentMaxHaul}");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")]
		private static void BreakRPC_Postfix()
		{
			isBreakRunning = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")]
		private static void BreakRPC_Postfix(PhysGrabObjectImpactDetector __instance, float valueLost, bool _loseValue)
		{
			isBreakRunning = false;
			if (!Object.op_Implicit((Object)(object)__instance.valuableObject))
			{
				return;
			}
			ShowTotalLoot.Logger.LogDebug((object)$"BreakRPC_Postfix(): {__instance} Start Postfix");
			ShowTotalLoot.Logger.LogDebug((object)$"BreakRPC_Postfix(): Item loseValue?: {_loseValue}");
			if (_loseValue)
			{
				if (__instance.valuableObject.dollarValueCurrent < __instance.valuableObject.dollarValueOriginal * 0.15f)
				{
					ShowTotalLoot.Logger.LogDebug((object)$"BreakRPC_Postfix(): {((Object)__instance.valuableObject).name} Has been destroyed ${valueLost}");
				}
				else
				{
					ShowTotalLoot.Logger.LogDebug((object)$"BreakRPC_Postfix(): {((Object)__instance.valuableObject).name} lost ${valueLost}");
				}
				_currentMaxHaul -= (int)valueLost;
				UpdateLabel(_currentMaxHaul, "BreakRPC_Postfix");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObjectRPC")]
		private static void DestroyObjectRPC_Postfix(PhysGrabObjectImpactDetector __instance)
		{
			if (Object.op_Implicit((Object)(object)__instance.valuableObject) && !isBreakRunning)
			{
				ShowTotalLoot.Logger.LogDebug((object)$"DestroyObjectRPC_Postfix(): {__instance} Start Postfix");
				ShowTotalLoot.Logger.LogDebug((object)$"DestroyObjectRPC_Postfix(): {((Object)__instance.valuableObject).name} Has been destroyed ${__instance.valuableObject.dollarValueCurrent}");
				_currentMaxHaul -= (int)__instance.valuableObject.dollarValueCurrent;
				UpdateLabel(_currentMaxHaul, "DestroyObjectRPC_Postfix");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LoadingUI), "StopLoading")]
		private static void StopLoading_Postfix(LoadingUI __instance)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			ShowTotalLoot.Logger.LogDebug((object)$"StopLoading_Postfix(): {__instance} Start Postfix");
			_gameHud = GameObject.Find("Game Hud").transform;
			_maxHaulGoalLabel = MenuAPI.CreateREPOLabel("Total Value", _gameHud, new Vector2(146f, -200f));
			((Component)_maxHaulGoalLabel).gameObject.SetActive(false);
			ShowTotalLoot.Logger.LogDebug((object)$"maxHaulGoalLabel {_maxHaulGoalLabel}");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyDirector), "AddEnemyValuable")]
		private static void AddEnemyValuable_Postfix(EnemyDirector __instance, EnemyValuable _newValuable)
		{
			ShowTotalLoot.Logger.LogDebug((object)"AddEnemyValuable_Postfix(): Start Postfix");
			if (!LevelGenerator.Instance.Generated)
			{
				ShowTotalLoot.Logger.LogError((object)"AddEnemyValuable_Postfix(): LevelGenerator has not finished generating the level");
			}
			else if ((Object)(object)_gameHud == (Object)null)
			{
				ShowTotalLoot.Logger.LogError((object)"AddEnemyValuable_Postfix(): _gameHud is null");
			}
			else if ((Object)(object)_maxHaulGoalLabel == (Object)null)
			{
				ShowTotalLoot.Logger.LogError((object)"AddEnemyValuable_Postfix(): _maxHaulGoalLabel is null");
			}
			else
			{
				((MonoBehaviour)ShowTotalLoot.Instance).StartCoroutine(DelayedAddEnemyValuable(_newValuable));
			}
		}

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

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ClownTrap), "TrapStop")]
		private static void ClowTrapStop_Postfix(ClownTrap __instance)
		{
			ShowTotalLoot.Logger.LogDebug((object)$"ClowTrapStop_Postfix(): {__instance} Start Postfix");
			int num = (int)((Component)__instance).GetComponentInParent<ValuableObject>().dollarValueCurrent;
			ShowTotalLoot.Logger.LogDebug((object)$"ClowTrapStop_Postfix(): Clown Current Value: ${num}");
			_currentMaxHaul -= num;
			UpdateLabel(_currentMaxHaul, "ClowTrapStop_Postfix");
		}

		private static void UpdateLabel(int newMaxHaulGoal, [CallerMemberName] string callerName = "")
		{
			ShowTotalLoot.Logger.LogDebug((object)(callerName + "(): running UpdateLabel()"));
			if ((Object)(object)_maxHaulGoalLabel == (Object)null)
			{
				ShowTotalLoot.Logger.LogError((object)"UpdateLabel(): _maxHaulGoalLabel is null");
				return;
			}
			ShowTotalLoot.Logger.LogDebug((object)_maxHaulGoalLabel);
			ShowTotalLoot.Logger.LogDebug((object)$"New Max Haul Goal: {newMaxHaulGoal}");
			((TMP_Text)_maxHaulGoalLabel.labelTMP).text = $"Total Value: {newMaxHaulGoal}";
		}
	}
}