using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("DocumentScanner")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+a796883e7fa279adca377cfd45c796769c2a622f")]
[assembly: AssemblyProduct("DocumentScanner")]
[assembly: AssemblyTitle("DocumentScanner")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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]
[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 DocumentScanner
{
[BepInPlugin("sm3gm.documentscanner", "Document Scanner", "1.0.0")]
public class DocumentScannerPlugin : BasePlugin
{
internal const string VER = "1.0.0";
internal static ManualLogSource LogSource;
public override void Load()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
LogSource = ((BasePlugin)this).Log;
Harmony.CreateAndPatchAll(typeof(ReadingOverlayPatch), (string)null);
((BasePlugin)this).AddComponent<LookWatcher>();
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Document Scanner ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
}
log.LogInfo(val);
}
}
internal static class Scanner
{
private static readonly HashSet<string> OverlayItems = new HashSet<string> { "WorkRota" };
private static readonly HashSet<string> LookItems = new HashSet<string> { "PrintedEmployeeRecord", "WorkDocument", "IDCard" };
private static readonly HashSet<string> Excluded = new HashSet<string> { "CityDirectory" };
private static bool loggedError;
internal static void OnReadingOverlay(Interactable interactable)
{
InteractablePreset preset = interactable.preset;
Evidence evidence = interactable.evidence;
if (!((SoCustomComparison)(object)preset == (SoCustomComparison)null) && evidence != null && !Excluded.Contains(((Object)preset).name))
{
EvidenceMultiPage val = ((Il2CppObjectBase)evidence).TryCast<EvidenceMultiPage>();
if (val != null)
{
RevealVisiblePage(val);
}
else if (OverlayItems.Contains(((Object)preset).name))
{
MarkFound(evidence);
}
}
}
internal static void OnLookedAt(Interactable interactable)
{
InteractablePreset preset = interactable.preset;
Evidence evidence = interactable.evidence;
if (!((SoCustomComparison)(object)preset == (SoCustomComparison)null) && evidence != null && !Excluded.Contains(((Object)preset).name) && LookItems.Contains(((Object)preset).name))
{
MarkFound(evidence);
}
}
private static void RevealVisiblePage(EvidenceMultiPage multiPage)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
List<MultiPageContent> pageContent = multiPage.pageContent;
if (pageContent == null)
{
return;
}
int page = multiPage.page;
for (int i = 0; i < pageContent.Count; i++)
{
MultiPageContent val = pageContent[i];
if (val == null || val.page != page)
{
continue;
}
if (!string.IsNullOrEmpty(val.discEvID) && TryGetEvidence(val.discEvID, out Evidence evidence))
{
evidence.AddDiscovery(val.disc);
}
if (!string.IsNullOrEmpty(val.evID) && TryGetEvidence(val.evID, out Evidence evidence2))
{
MarkFound(evidence2);
}
if (val.meta != 0)
{
CityData instance = CityData.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
MetaObject obj2 = instance.FindMetaObject(val.meta);
obj = ((obj2 != null) ? obj2.GetEvidence(false, default(Vector3Int)) : null);
}
Evidence val2 = (Evidence)obj;
if (val2 != null)
{
MarkFound(val2);
}
}
}
}
private static bool TryGetEvidence(string id, out Evidence evidence)
{
evidence = null;
if ((Object)(object)Toolbox.Instance != (Object)null && Toolbox.Instance.TryGetEvidence(id, ref evidence))
{
return evidence != null;
}
return false;
}
private static void MarkFound(Evidence ev)
{
if (!((CaseComponent)ev).isFound)
{
((CaseComponent)ev).SetFound(true);
}
}
internal static void Guard(Action action)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
try
{
action();
}
catch (Exception ex)
{
if (!loggedError)
{
loggedError = true;
ManualLogSource logSource = DocumentScannerPlugin.LogSource;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(52, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Document Scanner error (further errors suppressed): ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
logSource.LogError(val);
}
}
}
}
[HarmonyPatch(typeof(InteractionController), "SetReadingMode")]
internal static class ReadingOverlayPatch
{
private static void Postfix(bool val)
{
if (!val)
{
return;
}
Scanner.Guard(delegate
{
InteractionController instance = InteractionController.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
InteractableController currentLookingAtReadingRange = instance.currentLookingAtReadingRange;
obj = ((currentLookingAtReadingRange != null) ? currentLookingAtReadingRange.interactable : null);
}
Interactable val2 = (Interactable)obj;
if (val2 != null)
{
Scanner.OnReadingOverlay(val2);
}
});
}
}
public class LookWatcher : MonoBehaviour
{
private IntPtr last;
public LookWatcher(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
Scanner.Guard(delegate
{
InteractionController instance = InteractionController.Instance;
InteractableController val = ((instance != null) ? instance.currentLookingAtInteractable : null);
IntPtr intPtr = (((Object)(object)val == (Object)null) ? IntPtr.Zero : ((Il2CppObjectBase)val).Pointer);
if (!(intPtr == last))
{
last = intPtr;
Interactable val2 = ((val != null) ? val.interactable : null);
if (val2 != null)
{
Scanner.OnLookedAt(val2);
}
}
});
}
}
}