Decompiled source of scanForItemsFix v1.0.4

BepInEx/plugins/ThePotato-scanFixForItemsFix.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ThePotato-scanFixForItemsFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes an error that occurs when scanning for scrap")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("ThePotato-scanFixForItemsFix")]
[assembly: AssemblyTitle("ThePotato-scanFixForItemsFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ScanFix
{
	[BepInPlugin("ThePotato-scanFixForItemsFix", "ThePotato-scanFixForItemsFix", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Terminal), "TextPostProcess")]
		internal class TextProcessPatch
		{
			private static bool Prefix(ref string modifiedDisplayText, TerminalNode node)
			{
				if (modifiedDisplayText.Contains("[scanForItems]"))
				{
					try
					{
						Random random = new Random(StartOfRound.Instance.randomMapSeed + 91);
						int num = 0;
						int num2 = 0;
						foreach (var item in Object.FindObjectsOfType<GrabbableObject>().Select((GrabbableObject grabbable, int index) => new { grabbable, index }))
						{
							GrabbableObject grabbable2 = item.grabbable;
							int index2 = item.index;
							Item itemProperties = grabbable2.itemProperties;
							if (grabbable2 != null && !grabbable2.isInShipRoom && !grabbable2.isInElevator && itemProperties != null && itemProperties.minValue > 0 && itemProperties.maxValue > 0 && itemProperties.isScrap)
							{
								int minValue = Mathf.Min(itemProperties.minValue, itemProperties.maxValue);
								int maxValue = Mathf.Max(itemProperties.minValue, itemProperties.maxValue);
								int num3 = Mathf.Clamp(random.Next(minValue, maxValue), grabbable2.scrapValue - 6 * index2, grabbable2.scrapValue + 9 * index2);
								num2 += num3;
								num++;
							}
						}
						modifiedDisplayText = modifiedDisplayText.Replace("[scanForItems]", $"There are {num} objects outside the ship, totalling at an approximate value of ${num2}.");
					}
					catch
					{
						modifiedDisplayText = modifiedDisplayText.Replace("[scanForItems]", "FAILED TO SCAN FOR ITEMS");
					}
				}
				return true;
			}
		}

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ThePotato-scanFixForItemsFix is loaded!");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ThePotato-scanFixForItemsFix is patched!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ThePotato-scanFixForItemsFix";

		public const string PLUGIN_NAME = "ThePotato-scanFixForItemsFix";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}