Decompiled source of LobbyParkour v0.1.0

plugins/gg.amgg.PeakLobbyParkour.dll

Decompiled a month ago
using System;
using System.Collections;
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 Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("gg.amgg.PeakLobbyParkour")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+c08623690b90249f9f99465e2c5aa2b4a743f542")]
[assembly: AssemblyProduct("gg.amgg.PeakLobbyParkour")]
[assembly: AssemblyTitle("LobbyParkour")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.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]
	[Microsoft.CodeAnalysis.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]
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace LobbyParkour
{
	[BepInPlugin("gg.amgg.PeakLobbyParkour", "LobbyParkour", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static class Util
		{
			public static IEnumerable<GameObject> GetChildrenOf(GameObject target)
			{
				Transform component = target.GetComponent<Transform>();
				if (component == null)
				{
					return Array.Empty<GameObject>();
				}
				return from Transform childTransform in (IEnumerable)component
					select ((Component)childTransform).gameObject;
			}

			public static Mesh EnsureMeshReadable(Mesh mesh)
			{
				if (!mesh.isReadable)
				{
					return MakeReadableMeshCopy(mesh);
				}
				return mesh;
			}

			public static Mesh MakeReadableMeshCopy(Mesh nonReadableMesh)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Expected O, but got Unknown
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				Mesh val = new Mesh();
				val.indexFormat = nonReadableMesh.indexFormat;
				GraphicsBuffer vertexBuffer = nonReadableMesh.GetVertexBuffer(0);
				int num = vertexBuffer.stride * vertexBuffer.count;
				byte[] array = new byte[num];
				vertexBuffer.GetData((Array)array);
				val.SetVertexBufferParams(nonReadableMesh.vertexCount, nonReadableMesh.GetVertexAttributes());
				val.SetVertexBufferData<byte>(array, 0, 0, num, 0, (MeshUpdateFlags)0);
				vertexBuffer.Release();
				val.subMeshCount = nonReadableMesh.subMeshCount;
				GraphicsBuffer indexBuffer = nonReadableMesh.GetIndexBuffer();
				int num2 = indexBuffer.stride * indexBuffer.count;
				byte[] array2 = new byte[num2];
				indexBuffer.GetData((Array)array2);
				val.SetIndexBufferParams(indexBuffer.count, nonReadableMesh.indexFormat);
				val.SetIndexBufferData<byte>(array2, 0, 0, num2, (MeshUpdateFlags)0);
				indexBuffer.Release();
				uint num3 = 0u;
				for (int i = 0; i < val.subMeshCount; i++)
				{
					uint indexCount = nonReadableMesh.GetIndexCount(i);
					val.SetSubMesh(i, new SubMeshDescriptor((int)num3, (int)indexCount, (MeshTopology)0), (MeshUpdateFlags)0);
					num3 += indexCount;
				}
				val.RecalculateNormals();
				val.RecalculateBounds();
				return val;
			}
		}

		private class SceneTreeQueryNode
		{
			public class Epsilon : SceneTreeQueryNode
			{
				protected override void Run(GameObject target, int depth)
				{
					foreach (SceneTreeQueryNode child in Children)
					{
						child.Run(target, depth);
					}
				}
			}

			[CompilerGenerated]
			private Predicate<GameObject>? <Predicate>P;

			[CompilerGenerated]
			private Action<GameObject>? <Action>P;

			private readonly List<SceneTreeQueryNode> Children;

			public SceneTreeQueryNode(Predicate<GameObject>? Predicate = null, Action<GameObject>? Action = null)
			{
				<Predicate>P = Predicate;
				<Action>P = Action;
				Children = new List<SceneTreeQueryNode>();
				base..ctor();
			}

			public bool Matches(GameObject target)
			{
				return <Predicate>P?.Invoke(target) ?? true;
			}

			protected virtual void Run(GameObject target, int depth)
			{
				<Action>P?.Invoke(target);
				foreach (var (target2, sceneTreeQueryNode) in from GameObject childGameObject in Util.GetChildrenOf(target)
					from childNode in Children.Cast<SceneTreeQueryNode>()
					where childNode.Matches(childGameObject)
					select (childGameObject, childNode))
				{
					sceneTreeQueryNode.Run(target2);
				}
			}

			public void Run(GameObject target)
			{
				Run(target, 0);
			}

			public void Run(IEnumerable<GameObject> targets)
			{
				foreach (GameObject target in targets)
				{
					Run(target);
				}
			}

			public SceneTreeQueryNode Tap(Action<SceneTreeQueryNode> f)
			{
				f(this);
				return this;
			}

			public SceneTreeQueryNode Child(SceneTreeQueryNode child)
			{
				Children.Add(child);
				return child;
			}

			public SceneTreeQueryNode Child(Predicate<GameObject> predicate)
			{
				return Child(new SceneTreeQueryNode(predicate));
			}

			public SceneTreeQueryNode Child(Predicate<GameObject> predicate, Action<GameObject> action)
			{
				return Child(new SceneTreeQueryNode(predicate, action));
			}

			public void Tee(params Action<SceneTreeQueryNode>[] tees)
			{
				foreach (Action<SceneTreeQueryNode> action in tees)
				{
					action(this);
				}
			}
		}

		private Coroutine? AirportLoadCompleteCoroutine;

		public const string Id = "gg.amgg.PeakLobbyParkour";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "LobbyParkour";

		public static string Version => "0.1.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (((Scene)(ref scene)).path == "Assets/8_SCENES/Airport.unity")
			{
				Log.LogInfo((object)"started loading airport scene...");
				if (AirportLoadCompleteCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(AirportLoadCompleteCoroutine);
					AirportLoadCompleteCoroutine = null;
				}
				AirportLoadCompleteCoroutine = ((MonoBehaviour)this).StartCoroutine(PatchAfterLoadFinished());
			}
			IEnumerator PatchAfterLoadFinished()
			{
				while (LoadingScreenHandler.loading)
				{
					yield return null;
				}
				PatchAirportScene(scene);
			}
		}

		private void PatchAirportScene(Scene scene)
		{
			Log.LogInfo((object)"finished loading airport scene, patching it now");
			int num = LayerMask.NameToLayer("Terrain");
			int? num2 = ((num != -1) ? new int?(num) : null);
			int? terrainLayer = num2;
			new SceneTreeQueryNode.Epsilon().Tap(delegate(SceneTreeQueryNode n)
			{
				n.Child((GameObject o) => o != null && ((Object)o).name == "Map").Tee(delegate(SceneTreeQueryNode n)
				{
					n.Child(delegate(GameObject o)
					{
						if (o != null)
						{
							switch (((Object)o).name)
							{
							case "Flight Board":
							case "Flight Board (1)":
							case "Flight Board (2)":
							case "Flight Board (3)":
							case "Boarding Sign":
								return true;
							}
						}
						return false;
					}, makeClimbable);
				}, delegate(SceneTreeQueryNode n)
				{
					n.Child((GameObject o) => o != null && ((Object)o).name == "BL_Airport").Tee(delegate(SceneTreeQueryNode n)
					{
						n.Child(delegate(GameObject o)
						{
							if (o != null)
							{
								string name3 = ((Object)o).name;
								if (name3 == "OutofBoundsBlockers" || name3 == "OutofBoundsBlockers (1)")
								{
									return true;
								}
							}
							return false;
						}, delegate(GameObject o)
						{
							o.SetActive(false);
						});
					}, delegate(SceneTreeQueryNode n)
					{
						n.Child((GameObject o) => o != null && ((Object)o).name == "Main Meshes").Tee(delegate(SceneTreeQueryNode n)
						{
							n.Child((GameObject o) => o != null && ((Object)o).name == "Schaffold", makeClimbable);
						}, delegate(SceneTreeQueryNode n)
						{
							n.Child((GameObject o) => o != null && ((Object)o).name == "Climbing wall blockers").Child((GameObject _) => true, delegate(GameObject o)
							{
								o.SetActive(false);
							});
						}, delegate(SceneTreeQueryNode n)
						{
							n.Child((GameObject o) => o != null && ((Object)o).name == "Airport (1)Roof").Child((GameObject _) => true, makeClimbable);
						}, delegate(SceneTreeQueryNode n)
						{
							n.Child(delegate(GameObject o)
							{
								if (o != null)
								{
									string name2 = ((Object)o).name;
									if (name2 == "Cube" || name2 == "Cube (1)")
									{
										return true;
									}
								}
								return false;
							}, makeClimbable);
						}, delegate(SceneTreeQueryNode n)
						{
							n.Child((GameObject o) => o != null && ((Object)o).name == "Carpet", makeClimbable);
						}, delegate(SceneTreeQueryNode n)
						{
							n.Child(delegate(GameObject o)
							{
								if (o != null)
								{
									string name = ((Object)o).name;
									if (name == "Outside grid" || name == "Outside grid (1)")
									{
										return true;
									}
								}
								return false;
							}, makeClimbable);
						});
					}, delegate(SceneTreeQueryNode n)
					{
						n.Child((GameObject o) => o != null && ((Object)o).name == "Lights").Child((GameObject _) => true, makeClimbable);
					}, delegate(SceneTreeQueryNode n)
					{
						n.Child((GameObject o) => o != null && ((Object)o).name == "Displays").Child((GameObject _) => true, makeClimbable);
					}, delegate(SceneTreeQueryNode n)
					{
						n.Child((GameObject o) => o != null && ((Object)o).name == "GlassFence", makeClimbable);
					}, delegate(SceneTreeQueryNode n)
					{
						n.Child(delegate(GameObject o)
						{
							if (o != null)
							{
								switch (((Object)o).name)
								{
								case "Plane":
								case "Plane (1)":
								case "Plane (2)":
									return true;
								}
							}
							return false;
						}, makeClimbable).Child((GameObject _) => true, makeClimbable);
					});
				}, delegate(SceneTreeQueryNode n)
				{
					n.Child((GameObject o) => o != null && ((Object)o).name == "Mirror (1)").Tee(delegate(SceneTreeQueryNode n)
					{
						n.Child((GameObject o) => o != null && ((Object)o).name == "Mirror").Child((GameObject o) => o != null && ((Object)o).name == "Mirror Collider", makeClimbable);
					}, delegate(SceneTreeQueryNode n)
					{
						n.Child((GameObject o) => o != null && ((Object)o).name == "Details").Child(delegate(GameObject o)
						{
							if (o != null)
							{
								switch (((Object)o).name)
								{
								case "Cube (10)":
								case "Cube (9)":
								case "Cube (2)":
								case "Cube (1)":
									return true;
								}
							}
							return false;
						}, makeClimbable);
					});
				});
			}).Run((IEnumerable<GameObject>)((Scene)(ref scene)).GetRootGameObjects());
			void makeClimbable(GameObject target)
			{
				if (terrainLayer.HasValue)
				{
					int valueOrDefault = terrainLayer.GetValueOrDefault();
					target.layer = valueOrDefault;
				}
				Log.LogInfo((object)$"makeClimbable({target})");
				if (target.GetComponent<MeshCollider>() == null)
				{
					MeshFilter component = target.GetComponent<MeshFilter>();
					if (component != null)
					{
						Mesh sharedMesh = component.sharedMesh;
						if (sharedMesh != null)
						{
							MeshCollider val = target.AddComponent<MeshCollider>();
							Log.LogInfo((object)$"adding collider to {target} with mesh {component.sharedMesh}, which is (readable?{sharedMesh.isReadable})");
							val.sharedMesh = Util.EnsureMeshReadable(sharedMesh);
						}
					}
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}