Decompiled source of ScanFix v1.0.3

ScanFix.dll

Decompiled a year ago
using System.Collections.Generic;
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 BepInEx.Logging;
using HarmonyLib;
using ScanFix.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ScanFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Fixes the scan command so it will show the true value of scrap, instead of the max value")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("ScanFix")]
[assembly: AssemblyTitle("ScanFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
namespace ScanFix
{
	[BepInPlugin("ScanFix", "ScanFix", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		private bool _patched;

		public static string textStored = "[scanForItems]";

		public static ManualLogSource Logger { get; set; }

		private void Awake()
		{
			if (_patched)
			{
				Logger.LogWarning((object)"Already Patched");
				return;
			}
			Harmony.CreateAndPatchAll(typeof(TerminalPatch), "ScanFix");
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"ScanFix is loaded!");
			_patched = true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ScanFix";

		public const string PLUGIN_NAME = "ScanFix";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace ScanFix.Patches
{
	internal class TerminalPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Terminal), "BeginUsingTerminal")]
		internal static void ScanFixPatch(Terminal __instance)
		{
			Plugin.Logger.LogInfo((object)"Entered Patch");
			List<TerminalKeyword> list = __instance.terminalNodes.allKeywords.ToList();
			TerminalKeyword val = list.Find((TerminalKeyword keyword) => keyword.word == "scan");
			if ((Object)(object)val != (Object)null)
			{
				GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
				if (!val.specialKeywordResult.displayText.Contains(Plugin.textStored))
				{
					return;
				}
				int num = 0;
				int num2 = 0;
				int num3 = 0;
				int num4 = 0;
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i].itemProperties.isScrap && !array[i].isInShipRoom && !array[i].isInElevator && !array[i].scrapPersistedThroughRounds)
					{
						num++;
						num3 += array[i].scrapValue;
					}
					else if (array[i].itemProperties.isScrap && array[i].isInShipRoom && array[i].isInElevator)
					{
						num2++;
						num4 += array[i].scrapValue;
					}
				}
				string text = $"There are {num} objects outside the ship, totalling at an exact value of {num3}.";
				string text2 = $"There are {num2} objects inside the ship, totalling at an exact value of {num4}.";
				if (num3 == 0)
				{
					val.specialKeywordResult.displayText = val.specialKeywordResult.displayText.Replace(Plugin.textStored, text2);
					Plugin.textStored = text2;
				}
				else
				{
					val.specialKeywordResult.displayText = val.specialKeywordResult.displayText.Replace(Plugin.textStored, text);
					Plugin.textStored = text;
				}
				__instance.terminalNodes.allKeywords = list.ToArray();
				Plugin.Logger.LogInfo((object)"Replaced Scan");
			}
			else
			{
				Plugin.Logger.LogWarning((object)"WHERE IS SCAN!!!!");
			}
		}
	}
}