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 Photon.Pun;
using ScalerCore;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Vippy")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+61b15c6020608a7c220575bc325398686ff70440")]
[assembly: AssemblyProduct("ShrinkerGun")]
[assembly: AssemblyTitle("ShrinkerGun")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.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.1.1";
}
public class ItemGunShrink : MonoBehaviour
{
private void Start()
{
MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer val in componentsInChildren)
{
((Renderer)val).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_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
Plugin.Log.LogInfo((object)$"[SG] Bullet Start isMaster={SemiFunc.IsMasterClientOrSingleplayer()} instanceID={((Object)this).GetInstanceID()} GO={((Object)((Component)this).gameObject).name}");
if (SemiFunc.IsMasterClientOrSingleplayer())
{
ItemGunBullet component = ((Component)this).GetComponent<ItemGunBullet>();
if ((Object)(object)component == (Object)null || !component.bulletHit)
{
Plugin.Log.LogInfo((object)$"[SG] Bullet SKIP bullet={(Object)(object)component != (Object)null} hit={component?.bulletHit}");
return;
}
Plugin.Log.LogInfo((object)$"[SG] Bullet HIT at {component.hitPosition}");
ShrinkAtPoint(component.hitPosition);
}
}
private void ShrinkAtPoint(Vector3 point)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: 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);
Plugin.Log.LogInfo((object)$"[SG] OverlapSphere center={point} radius=0.3 hits={array.Length}");
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);
}
Plugin.Log.LogInfo((object)$"[SG] collider={((Object)((Component)val).gameObject).name} layer={((Component)val).gameObject.layer} ctrl={(Object)(object)val2 != (Object)null} ctrlID={((val2 != null) ? new int?(((Object)val2).GetInstanceID()) : null)} IsScaled={((val2 != null) ? new bool?(val2.IsScaled) : null)}");
if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)_sourceCtrl))
{
Toggle(val2);
return;
}
}
Plugin.Log.LogInfo((object)"[SG] No target found");
}
private static ScaleController? FindNearestPlayerCtrl(Vector3 pos)
{
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: 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>();
Vector3 val = (((Object)(object)component2?.CollisionTransform != (Object)null) ? component2.CollisionTransform.position : ((Component)player).transform.position);
float num2 = Vector3.Distance(val, pos);
if (num2 < num)
{
num = num2;
result = component;
}
}
}
return result;
}
private static void Toggle(ScaleController ctrl)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
Plugin.Log.LogInfo((object)$"[SG] Toggle ctrl={((Object)ctrl).GetInstanceID()} IsScaled={ctrl.IsScaled} currentScale={((Component)ctrl).transform.localScale}");
if (ctrl.IsScaled)
{
ScaleManager.Restore(((Component)ctrl).gameObject);
}
else
{
ScaleManager.Apply(((Component)ctrl).gameObject, 0f);
}
}
}
[BepInPlugin("Vippy.ShrinkerGun", "ShrinkerGun", "0.1.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>();
}
}
internal static ManualLogSource Log;
private static ConfigEntry<bool> _enableDebugKeys;
private void Awake()
{
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
ShrinkConfig.Factor = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "ShrinkFactor", 0.4f, "Scale multiplier applied when shrunk (0.4 = 40% of original).").Value;
ShrinkConfig.Speed = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "ShrinkSpeed", 2f, "Animation speed. Scaled by the object's original size.").Value;
ShrinkConfig.EnemyDamageMult = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "EnemyDamageMultiplier", 0.1f, "Damage multiplier for shrunken enemies (0.1 = 10%).").Value;
ShrinkConfig.EnemyShrinkDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "EnemyShrinkDuration", 120f, "Seconds until a shrunken enemy auto-restores. 0 = never.").Value;
ShrinkConfig.ItemShrinkDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "ItemShrinkDuration", 300f, "Seconds until a shrunken item auto-restores. 0 = never.").Value;
ShrinkConfig.EnemyShrinkSpeedFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "EnemySpeedFactor", 0.65f, "Movement speed multiplier for shrunken enemies.").Value;
_enableDebugKeys = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugKeys", false, "Enable F9/F10 keys to shrink/unshrink yourself. Off by default.");
new Harmony("Vippy.ShrinkerGun").PatchAll();
}
private void Update()
{
if (!_enableDebugKeys.Value)
{
return;
}
PlayerAvatar instance = PlayerAvatar.instance;
if ((Object)(object)instance == (Object)null)
{
return;
}
ScaleController component = ((Component)instance).GetComponent<ScaleController>();
if (!((Object)(object)component == (Object)null) && (!PhotonNetwork.InRoom || ((Object)(object)instance.photonView != (Object)null && instance.photonView.IsMine)))
{
if (!component.IsScaled && Input.GetKeyDown((KeyCode)290))
{
component.RequestManualShrink();
}
if (component.IsScaled && Input.GetKeyDown((KeyCode)291))
{
component.RequestManualExpand();
}
}
}
}
}