Decompiled source of MassScan v1.0.0

plugins/MassScan/MassScan.dll

Decompiled a week ago
using System;
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 HarmonyLib;
using PropStreaming;
using Unity.Mathematics;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MassScan")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MassScan")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6a487e42-571e-47b8-9964-75a1335eb250")]
[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 MassScan;

[BepInPlugin("MassScan.Casper.com", "MassScan", "1.0.0")]
public class MassScan : BaseUnityPlugin
{
	private static ConfigEntry<int> ScanRange;

	private static ManualLogSource ModLogger;

	private static Queue<InstanceLookup> instanceLookups = new Queue<InstanceLookup>();

	private static bool readyToRun = false;

	private static bool isProcessing = false;

	private static byte currentStrata = 0;

	private static byte previousStrata = byte.MaxValue;

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		ModLogger = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("MassScan.Casper.com");
		val.Patch((MethodBase)AccessTools.Method(typeof(ScannableData), "CompleteScan", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(MassScan), "CompleteScanPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(FactorySimManager), "SimUpdateAll", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(MassScan), "UpdateStrata", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		ScanRange = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "ScanRange", 15, "Distance to scan. (0 to disable)");
	}

	private void FixedUpdate()
	{
		if (readyToRun && ProcessInstanceQueue())
		{
			readyToRun = false;
		}
	}

	public static void CompleteScanPatch(ScannableData __instance, InstanceLookup lookup)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		if (isProcessing)
		{
			return;
		}
		isProcessing = true;
		int num = default(int);
		if (!PropManager.instance.propLookUpToArrayIndex.TryGetValue(lookup, ref num))
		{
			isProcessing = false;
			return;
		}
		float3 position = FHG_Utils.GetPosition(PropManager.instance.propMatrices[num]);
		float num2 = ScanRange.Value;
		ModLogger.LogInfo((object)$"Scanning with radius: {num2}, strata: {currentStrata}");
		HashSet<InstanceLookup> hashSet = ScannableData.FindFragmentsWithinRadius(float3.op_Implicit(position), currentStrata, num2, false);
		ModLogger.LogInfo((object)$"Found {hashSet.Count} fragments. ");
		PropState val = default(PropState);
		foreach (InstanceLookup item in hashSet)
		{
			InstanceLookup current = item;
			if (PropManager.instance.GetPropState(ref current, ref val) && val.isAlive && !instanceLookups.Contains(current))
			{
				instanceLookups.Enqueue(current);
			}
		}
		ProcessInstanceQueue();
		readyToRun = true;
		isProcessing = false;
	}

	private static bool ProcessInstanceQueue()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_0045: Expected O, but got Unknown
		PropState val = default(PropState);
		while (instanceLookups.Count > 0)
		{
			InstanceLookup lookup = instanceLookups.Dequeue();
			if (PropManager.instance.GetPropState(ref lookup, ref val) && val.isAlive)
			{
				ScanAction val2 = new ScanAction
				{
					info = new ScanInfo
					{
						lookup = lookup
					}
				};
				NetworkMessageRelay.instance.SendNetworkAction((NetworkAction)(object)val2);
				return false;
			}
		}
		isProcessing = false;
		return true;
	}

	public static void UpdateStrata()
	{
		byte b = (byte)((GameState.instance != null) ? GameState.instance.GetStrata() : 0);
		if (b != previousStrata)
		{
			currentStrata = (previousStrata = b);
			ModLogger.LogInfo((object)$"Strata changed to: {currentStrata}");
		}
	}
}