using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComputerysModdingUtilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: StraftatMod(true)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("WallLeaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WallLeaks")]
[assembly: AssemblyTitle("WallLeaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 WallLeaks
{
[BepInPlugin("com.nya0.wallleaks", "WallLeaks", "0.1.671")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
internal static ConfigEntry<KeyCode> ToggleKey;
private void Awake()
{
//IL_0034: 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_003f: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)287, "Key to toggle invisible visibility");
GameObject val = new GameObject("BigBugWallLeaker");
Object.DontDestroyOnLoad((Object)val);
((Object)val).hideFlags = (HideFlags)61;
val.AddComponent<WallLeaksRunner>();
SceneManager.sceneLoaded += delegate
{
if (WallLeaksRunner.Instance.Revealed)
{
WallLeaksRunner.Instance.Hide();
}
};
new Harmony("com.nya0.wallleaks").PatchAll();
Logger.LogInfo((object)"WallLeaks v0.1.671 loaded");
}
}
public class WallLeaksRunner : MonoBehaviour
{
private struct MeshEntry
{
public Component source;
public Mesh mesh;
public Vector3 offset;
public Vector3 scale;
public MeshEntry(Component src, Mesh m, Vector3 off, Vector3 sc)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
source = src;
mesh = m;
offset = off;
scale = sc;
}
public MeshEntry(Component src, Mesh m)
: this(src, m, Vector3.zero, Vector3.one)
{
}//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
}
private readonly Dictionary<int, MeshEntry> tracked = new Dictionary<int, MeshEntry>();
private readonly Queue<GameObject> pending = new Queue<GameObject>();
private readonly List<int> stale = new List<int>();
private Material wallMat;
private Mesh cubeMesh;
private Mesh sphereMesh;
private Mesh capsuleMesh;
public static WallLeaksRunner Instance { get; private set; }
public bool Revealed { get; private set; }
private void Awake()
{
Instance = this;
cubeMesh = GetPrimitiveMesh((PrimitiveType)3);
sphereMesh = GetPrimitiveMesh((PrimitiveType)0);
capsuleMesh = GetPrimitiveMesh((PrimitiveType)1);
}
private static Mesh GetPrimitiveMesh(PrimitiveType type)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
GameObject obj = GameObject.CreatePrimitive(type);
Mesh sharedMesh = obj.GetComponent<MeshFilter>().sharedMesh;
Object.DestroyImmediate((Object)(object)obj);
return sharedMesh;
}
private Material GetMaterial()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)wallMat != (Object)null)
{
return wallMat;
}
wallMat = new Material(Shader.Find("Sprites/Default"));
wallMat.color = new Color(1f, 0f, 0f, 0.2f);
return wallMat;
}
private static bool IsUnderPlayerIK(Transform t)
{
while ((Object)(object)t != (Object)null)
{
if (((Object)t).name.Contains("PlayerIK"))
{
return true;
}
t = t.parent;
}
return false;
}
private static bool Skip(Component c)
{
if (!c.gameObject.activeInHierarchy || IsUnderPlayerIK(c.transform))
{
return true;
}
Renderer component = c.GetComponent<Renderer>();
if ((Object)(object)component != (Object)null)
{
return component.enabled;
}
return false;
}
private static bool IsGone(Component c)
{
if ((Object)(object)c == (Object)null || !c.gameObject.activeInHierarchy)
{
return true;
}
Collider val = (Collider)(object)((c is Collider) ? c : null);
if (val != null && !val.enabled)
{
return true;
}
Renderer component = c.GetComponent<Renderer>();
if ((Object)(object)component != (Object)null)
{
return component.enabled;
}
return false;
}
public void Enqueue(GameObject go)
{
if (Revealed)
{
pending.Enqueue(go);
}
}
private void Update()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(Plugin.ToggleKey.Value))
{
if (!Revealed)
{
Reveal();
}
else
{
Hide();
}
}
}
private void LateUpdate()
{
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
if (!Revealed)
{
return;
}
while (pending.Count > 0)
{
GameObject val = pending.Dequeue();
if ((Object)(object)val != (Object)null)
{
Scan(val);
}
}
stale.Clear();
Material material = GetMaterial();
foreach (KeyValuePair<int, MeshEntry> item in tracked)
{
MeshEntry value = item.Value;
if (IsGone(value.source))
{
stale.Add(item.Key);
}
else
{
Graphics.DrawMesh(value.mesh, value.source.transform.localToWorldMatrix * Matrix4x4.TRS(value.offset, Quaternion.identity, value.scale), material, 0);
}
}
for (int i = 0; i < stale.Count; i++)
{
tracked.Remove(stale[i]);
}
}
private void Reveal()
{
Hide();
MeshFilter[] array = Resources.FindObjectsOfTypeAll<MeshFilter>();
foreach (MeshFilter mf in array)
{
Add(mf);
}
Collider[] array2 = Object.FindObjectsOfType<Collider>();
foreach (Collider col in array2)
{
Add(col);
}
Revealed = true;
Plugin.Logger.LogInfo((object)$"revealed :> {tracked.Count}");
}
private void Scan(GameObject go)
{
MeshFilter[] componentsInChildren = go.GetComponentsInChildren<MeshFilter>(true);
foreach (MeshFilter mf in componentsInChildren)
{
Add(mf);
}
Collider[] componentsInChildren2 = go.GetComponentsInChildren<Collider>(true);
foreach (Collider col in componentsInChildren2)
{
Add(col);
}
}
private void Add(MeshFilter mf)
{
if (!((Object)(object)mf.sharedMesh == (Object)null) && !Skip((Component)(object)mf))
{
int instanceID = ((Object)mf).GetInstanceID();
if (!tracked.ContainsKey(instanceID))
{
tracked[instanceID] = new MeshEntry((Component)(object)mf, mf.sharedMesh);
}
}
}
private void Add(Collider col)
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
if (Skip((Component)(object)col))
{
return;
}
int instanceID = ((Object)col).GetInstanceID();
if (tracked.ContainsKey(instanceID))
{
return;
}
BoxCollider val = (BoxCollider)(object)((col is BoxCollider) ? col : null);
if (val == null)
{
MeshCollider val2 = (MeshCollider)(object)((col is MeshCollider) ? col : null);
if (val2 == null)
{
SphereCollider val3 = (SphereCollider)(object)((col is SphereCollider) ? col : null);
if (val3 == null)
{
CapsuleCollider val4 = (CapsuleCollider)(object)((col is CapsuleCollider) ? col : null);
if (val4 != null)
{
float num = val4.radius * 2f;
tracked[instanceID] = new MeshEntry((Component)(object)col, capsuleMesh, val4.center, new Vector3(num, val4.height, num));
}
}
else
{
float num2 = val3.radius * 2f;
tracked[instanceID] = new MeshEntry((Component)(object)col, sphereMesh, val3.center, new Vector3(num2, num2, num2));
}
}
else if ((Object)(object)val2.sharedMesh != (Object)null)
{
tracked[instanceID] = new MeshEntry((Component)(object)col, val2.sharedMesh);
}
}
else
{
tracked[instanceID] = new MeshEntry((Component)(object)col, cubeMesh, val.center, val.size);
}
}
public void Hide()
{
tracked.Clear();
pending.Clear();
Revealed = false;
}
}
[HarmonyPatch(typeof(GameObject), "SetActive")]
internal static class PatchSetActive
{
private static void Postfix(GameObject __instance)
{
if (__instance.activeSelf)
{
WallLeaksRunner.Instance?.Enqueue(__instance);
}
}
}
internal static class PluginInfo
{
public const string GUID = "com.nya0.wallleaks";
public const string NAME = "WallLeaks";
public const string VERSION = "0.1.671";
}
}