using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("RightDrag")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RightDrag")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("64443039-edc2-4adb-8193-a459b7477663")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.2.0")]
namespace RightDrag;
[BepInPlugin("ScanGrenade.nhickling.co.uk", "ScanGrenade", "0.0.0.2")]
public class ScanGrenade : BaseUnityPlugin
{
private class ModSystemMessage : SystemMessageInfo
{
public override MessageType type => (MessageType)5;
public ModSystemMessage(string message)
: base(message)
{
}
}
public const string pluginGuid = "ScanGrenade.nhickling.co.uk";
public const string pluginName = "ScanGrenade";
public const string pluginShort = "UFB.SG";
public const string pluginVersion = "0.0.0.2";
private static ConfigEntry<int> ScanRange;
private static ConfigEntry<bool> shouldPreventOverburden;
private static ManualLogSource ModLogger;
private static List<int> activatedSlots = new List<int>();
private static bool readyToRun = false;
private static bool isProcessing = false;
private static ScannableData currentlyScanning;
private static Queue<InstanceLookup> instanceLookups = new Queue<InstanceLookup>();
private static int betweenSends = 3;
private static int waitingFor = 0;
public void Awake()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Expected O, but got Unknown
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Expected O, but got Unknown
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected O, but got Unknown
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Expected O, but got Unknown
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
((BaseUnityPlugin)this).Logger.LogInfo((object)"ScanGrenade: started");
Harmony val = new Harmony("ScanGrenade.nhickling.co.uk");
((BaseUnityPlugin)this).Logger.LogInfo((object)"ScanGrenade: Fetching patch references");
((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching Outbound");
MethodInfo methodInfo = AccessTools.Method(typeof(ScannableData), "CompleteScan", new Type[1] { typeof(InstanceLookup) }, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(ScanGrenade), "CompleteScan_MyPatch", (Type[])null, (Type[])null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"ScanGrenade: Starting Patch");
val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"ScanGrenade: Patched");
ScanRange = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "ScanRange", 15, new ConfigDescription("Distance to scan. (0 to disable)", (AcceptableValueBase)new AcceptableValueRange<int>(0, 30), Array.Empty<object>()));
shouldPreventOverburden = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "ShouldPreventOverburden", true, new ConfigDescription("Only scan additional buildings if there is at least 2 slots available before becoming overburdened.", (AcceptableValueBase)new AcceptableValueRange<bool>(false, true), Array.Empty<object>()));
ModLogger = ((BaseUnityPlugin)this).Logger;
}
public void FixedUpdate()
{
if (!readyToRun)
{
return;
}
if (waitingFor <= 0)
{
Func<bool> func = delegate
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: 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_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_0092: Expected O, but got Unknown
if (instanceLookups.Any())
{
if (shouldPreventOverburden.Value)
{
int nonEncumberedSlotsCount = GameState.instance.nonEncumberedSlotsCount;
int numConsolidatedSlots = ((InventoryWrapper)Player.instance.inventory).myInv.numConsolidatedSlots;
if (nonEncumberedSlotsCount - numConsolidatedSlots - 2 <= 0)
{
TryShowNotification("UFB.SG: Inventory too full!");
instanceLookups.Clear();
return true;
}
}
InstanceLookup lookup = instanceLookups.Dequeue();
PropState val = default(PropState);
if (PropManager.instance.GetPropData(ref lookup, ref val))
{
if (val.isAlive)
{
ScanAction val2 = new ScanAction
{
info = new ScanInfo
{
lookup = lookup
}
};
NetworkMessageRelay.instance.SendNetworkAction((NetworkAction)(object)val2);
waitingFor = betweenSends;
return false;
}
return true;
}
return false;
}
readyToRun = false;
isProcessing = false;
return false;
};
while (func())
{
}
}
else if (waitingFor > 0)
{
waitingFor--;
}
}
public static void CompleteScan_MyPatch(ScannableData __instance, InstanceLookup lookup)
{
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
if (isProcessing)
{
return;
}
isProcessing = true;
currentlyScanning = __instance;
Unlock unlock = __instance.unlock;
if (unlock == null || unlock.discovered)
{
PropManager instance = PropManager.instance;
_ = instance.frobManager;
List<ScannableData> list = new List<ScannableData>();
List<InstanceLookup[]> list2 = new List<InstanceLookup[]>();
ChunkData[] chunkDataArray = instance.chunkDataArray;
ScannableData val = default(ScannableData);
for (int i = 0; i < chunkDataArray.Length; i++)
{
foreach (PrefabData prefabDatum in chunkDataArray[i].prefabData)
{
for (int j = 0; j < prefabDatum.totalCount; j++)
{
if (prefabDatum.propStates[j].isAlive && instance.GetScannableData(ref prefabDatum.typeID, ref val) && ((Object)val).name == ((Object)__instance).name)
{
list.Add(val);
list2.Add(prefabDatum.lookups);
}
}
}
}
double num = Math.Pow(ScanRange.Value, 2.0);
SpawnData val2 = default(SpawnData);
instance.GetPropData(ref lookup, ref val2);
Vector3 positionFast = FHG_Utils.GetPositionFast(val2.matrix);
new List<Vector3Int>();
SpawnData val4 = default(SpawnData);
for (int k = 0; k < list.Count; k++)
{
_ = list[k];
for (int l = 0; l < list2[k].Count(); l++)
{
InstanceLookup val3 = list2[k][l];
if ((lookup.chunkID != val3.chunkID || lookup.instanceIndex != val3.instanceIndex) && instance.GetPropData(ref val3, ref val4))
{
float num2 = FHG_Utils.SqrDistance(FHG_Utils.GetPositionFast(val4.matrix), ref positionFast);
if ((double)num2 > 0.1 && (double)num2 < num)
{
instanceLookups.Enqueue(val3);
}
}
}
}
}
readyToRun = true;
}
private static void TryShowNotification(string message)
{
SystemLogUI systemLog = UIManager.instance.systemLog;
ModSystemMessage modSystemMessage = new ModSystemMessage(message);
systemLog.FlashMessage((SystemMessageInfo)(object)modSystemMessage);
}
}