Decompiled source of ShrinkerGun v0.6.0

ShrinkerGun.dll

Decompiled 6 days ago
using System;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using ScalerCore;
using ScalerCore.AprilFools;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Vippy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: AssemblyInformationalVersion("0.6.0+f3021341dec4e2fc604b4399164a1e4edf966fbe")]
[assembly: AssemblyProduct("ShrinkerGun")]
[assembly: AssemblyTitle("ShrinkerGun")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.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 ShrinkerGun
{
	internal static class BuildInfo
	{
		public const string Version = "0.6.0";
	}
	public class ItemGunShrink : MonoBehaviour
	{
		private void Start()
		{
			MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshRenderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Renderer)componentsInChildren[i]).material.shader = Shader.Find("Fresnel Opaque");
			}
		}
	}
	public class ItemGunShrinkBullet : MonoBehaviour
	{
		public static ScaleController? PendingSourceCtrl;

		private ScaleController? _sourceCtrl;

		private void Awake()
		{
			_sourceCtrl = PendingSourceCtrl;
			PendingSourceCtrl = null;
		}

		private void Start()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				ItemGunBullet component = ((Component)this).GetComponent<ItemGunBullet>();
				if (!((Object)(object)component == (Object)null) && component.bulletHit)
				{
					ShrinkAtPoint(component.hitPosition);
				}
			}
		}

		private void ShrinkAtPoint(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			int num = LayerMask.op_Implicit(SemiFunc.LayerMaskGetPhysGrabObject()) | LayerMask.GetMask(new string[2] { "Enemy", "Player" });
			Collider[] array = Physics.OverlapSphere(point, 0.3f, num, (QueryTriggerInteraction)2);
			int num2 = LayerMask.NameToLayer("Player");
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				ScaleController val2 = ((Component)val).GetComponent<PlayerShrinkLink>()?.Controller ?? ((Component)val).GetComponentInParent<ScaleController>();
				if ((Object)(object)val2 == (Object)null && ((Component)val).gameObject.layer == num2)
				{
					val2 = FindNearestPlayerCtrl(((Component)val).transform.position);
				}
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)_sourceCtrl))
				{
					Toggle(val2);
					break;
				}
			}
		}

		private static ScaleController? FindNearestPlayerCtrl(Vector3 pos)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (GameDirector.instance?.PlayerList == null)
			{
				return null;
			}
			ScaleController result = null;
			float num = 2f;
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if ((Object)(object)player == (Object)null || player.isDisabled)
				{
					continue;
				}
				ScaleController component = ((Component)player).GetComponent<ScaleController>();
				if (!((Object)(object)component == (Object)null))
				{
					PlayerAvatarCollision component2 = ((Component)player).GetComponent<PlayerAvatarCollision>();
					float num2 = Vector3.Distance(((Object)(object)component2?.CollisionTransform != (Object)null) ? component2.CollisionTransform.position : ((Component)player).transform.position, pos);
					if (num2 < num)
					{
						num = num2;
						result = component;
					}
				}
			}
			return result;
		}

		private static void Toggle(ScaleController ctrl)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			ScaleOptions shrinkOptions = Plugin.ShrinkOptions;
			if ((int)ctrl.TargetType == 2)
			{
				shrinkOptions.Duration = Plugin._enemyDuration;
			}
			else if ((int)ctrl.TargetType == 4)
			{
				shrinkOptions.Duration = Plugin._itemDuration;
			}
			ScaleManager.Apply(((Component)ctrl).gameObject, shrinkOptions);
		}
	}
	internal enum LevelCollapseMode
	{
		Auto,
		On,
		Off
	}
	[BepInPlugin("Vippy.ShrinkerGun", "ShrinkerGun", "0.6.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ItemGun), "ShootBulletRPC")]
		private class GunSourcePatch
		{
			private static void Prefix(ItemGun __instance)
			{
				ItemGunShrinkBullet.PendingSourceCtrl = ((Component)__instance).GetComponent<ScaleController>();
			}
		}

		[HarmonyPatch(typeof(ItemGunBullet), "ActivateAll")]
		private class LevelCollapseHitPatch
		{
			private static void Postfix(ItemGunBullet __instance)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				if (!LevelCollapseEnabled || !__instance.bulletHit || (Object)(object)((Component)__instance).GetComponent<ItemGunShrinkBullet>() == (Object)null)
				{
					return;
				}
				int num = LayerMask.op_Implicit(SemiFunc.LayerMaskGetPhysGrabObject()) | LayerMask.GetMask(new string[2] { "Enemy", "Player" });
				Collider[] array = Physics.OverlapSphere(__instance.hitPosition, 0.3f, num, (QueryTriggerInteraction)2);
				foreach (Collider val in array)
				{
					if ((Object)(object)((Component)val).GetComponent<PlayerShrinkLink>()?.Controller != (Object)null || (Object)(object)((Component)val).GetComponentInParent<ScaleController>() != (Object)null)
					{
						return;
					}
				}
				MapCollapse.OnMapHit();
			}
		}

		internal static ManualLogSource Log = null;

		internal static ScaleOptions ShrinkOptions;

		internal static float _enemyDuration = 120f;

		internal static float _itemDuration = 0f;

		private static ConfigEntry<bool> _enableDebugKeys = null;

		private static ConfigEntry<bool> _challengeMode = null;

		private static ConfigEntry<LevelCollapseMode> _levelCollapse = null;

		internal static bool LevelCollapseEnabled
		{
			get
			{
				switch (_levelCollapse.Value)
				{
				case LevelCollapseMode.On:
					return true;
				case LevelCollapseMode.Off:
					return false;
				default:
				{
					DateTime now = DateTime.Now;
					return now.Month == 4 && now.Day == 1;
				}
				}
			}
		}

		private void Awake()
		{
			//IL_000b: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			ShrinkOptions = ScaleOptions.Default;
			_enableDebugKeys = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugKeys", false, "Enable F9 to shrink/unshrink yourself. Off by default.");
			ScaleController.AllowManualScale = _enableDebugKeys.Value;
			_enableDebugKeys.SettingChanged += delegate
			{
				ScaleController.AllowManualScale = _enableDebugKeys.Value;
			};
			_challengeMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Challenge", "ShrinkChallengeMode", false, "All players start shrunken. Shrink guns temporarily grow you back to full size. Taking damage while full size shrinks you back down. Enemies behave normally.");
			ScaleController.ChallengeMode = _challengeMode.Value;
			_challengeMode.SettingChanged += delegate
			{
				ScaleController.ChallengeMode = _challengeMode.Value;
				if (SemiFunc.RunIsLobbyMenu())
				{
					PlayerVoiceChat[] array = Object.FindObjectsOfType<PlayerVoiceChat>();
					foreach (PlayerVoiceChat val in array)
					{
						if (_challengeMode.Value)
						{
							val.OverridePitch(1.3f, 0.2f, 0.5f, 9999f, 0f, 0f);
						}
						else
						{
							val.OverridePitchCancel();
						}
					}
				}
			};
			_levelCollapse = ((BaseUnityPlugin)this).Config.Bind<LevelCollapseMode>("Chaos", "LevelCollapse", LevelCollapseMode.Auto, "Shooting the map with the shrink gun triggers a 90-second collapse event. Auto = April 1st only. On = always. Off = never.");
			new Harmony("Vippy.ShrinkerGun").PatchAll();
		}

		private void Update()
		{
			PlayerAvatar instance = PlayerAvatar.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			ScaleController component = ((Component)instance).GetComponent<ScaleController>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)290))
			{
				if (component.IsScaled)
				{
					component.RequestManualExpand();
				}
				else
				{
					component.RequestManualShrink();
				}
			}
			if (Input.GetKeyDown((KeyCode)279) && _levelCollapse.Value == LevelCollapseMode.On && (Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated && SemiFunc.IsMasterClientOrSingleplayer())
			{
				MapCollapse.OnMapHit();
			}
		}
	}
}