using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Rewired;
using StarterAssets;
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("NoBroomSlapMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoBroomSlapMod")]
[assembly: AssemblyTitle("NoBroomSlapMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 NoBroomSlapMod
{
[BepInPlugin("uta-a.supermarkettogether.nobroomslap", "No Broom Slap", "1.0.0")]
public sealed class NoBroomSlapPlugin : BaseUnityPlugin
{
public const string PluginGuid = "uta-a.supermarkettogether.nobroomslap";
public const string PluginName = "No Broom Slap";
public const string PluginVersion = "1.0.0";
private const int BroomItemId = 7;
private ConfigEntry<float> reach;
private ConfigEntry<float> hitRadius;
private ConfigEntry<float> cooldownSeconds;
private ConfigEntry<bool> requireEmptyHands;
private ConfigEntry<bool> playBroomSound;
private ConfigEntry<bool> useRewiredMainAction;
private ConfigEntry<KeyCode> fallbackKey;
private ConfigEntry<KeyboardShortcut> modifierShortcut;
private ConfigEntry<bool> suppressNeedBroomNotification;
private Player rewiredPlayer;
private float nextAllowedHitTime;
private AudioSource localAudioSource;
private AudioSource broomPrefabAudioSource;
internal static NoBroomSlapPlugin Instance { get; private set; }
internal bool SuppressNeedBroomNotification => suppressNeedBroomNotification?.Value ?? false;
private void Awake()
{
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
reach = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Reach", 3f, "素手ではたける距離。");
hitRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "HitRadius", 0.35f, "前方判定の半径。小さいほど正確、大きいほど当てやすい。");
cooldownSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CooldownSeconds", 0.35f, "連続ヒット防止のクールダウン秒数。");
requireEmptyHands = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RequireEmptyHands", true, "trueなら何も持っていない時だけ発動。falseならほうき以外の装備中も発動。");
playBroomSound = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PlayBroomSound", true, "ヒット成功時に既存のほうきSEを鳴らす。");
suppressNeedBroomNotification = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SuppressNeedBroomNotification", true, "trueなら「これにはほうきが必要です」通知だけを非表示にする。");
useRewiredMainAction = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "UseRewiredMainAction", true, "trueならゲーム内の Main Action 入力を使う。");
fallbackKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input", "FallbackKey", (KeyCode)323, "Rewiredが使えない場合の代替キー。");
modifierShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "ModifierShortcut", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), "必要なら修飾キーを指定。Noneなら修飾キーなし。");
Harmony.CreateAndPatchAll(typeof(NoBroomSlapPlugin).Assembly, "uta-a.supermarkettogether.nobroomslap");
((BaseUnityPlugin)this).Logger.LogInfo((object)"No Broom Slap 1.0.0 loaded.");
}
private void Update()
{
if (ShouldProcessInput() && !(Time.time < nextAllowedHitTime) && WasHitInputPressed())
{
nextAllowedHitTime = Time.time + Mathf.Max(0.01f, cooldownSeconds.Value);
TrySlapForward();
}
}
private bool ShouldProcessInput()
{
if ((Object)(object)FirstPersonController.Instance == (Object)null || (Object)(object)Camera.main == (Object)null)
{
return false;
}
if (!FirstPersonController.Instance.allowPlayerInput)
{
return false;
}
PlayerNetwork component = ((Component)FirstPersonController.Instance).GetComponent<PlayerNetwork>();
if ((Object)(object)component == (Object)null)
{
return false;
}
if (component.equippedItem == 7)
{
return false;
}
if (requireEmptyHands.Value && component.equippedItem != 0)
{
return false;
}
return true;
}
private bool WasHitInputPressed()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
KeyboardShortcut value = modifierShortcut.Value;
if ((int)((KeyboardShortcut)(ref value)).MainKey != 0 && !((KeyboardShortcut)(ref value)).IsPressed())
{
return false;
}
if (useRewiredMainAction.Value)
{
try
{
if (rewiredPlayer == null)
{
rewiredPlayer = ReInput.players.GetPlayer(0);
}
if (rewiredPlayer != null && rewiredPlayer.GetButtonDown("Main Action"))
{
return true;
}
}
catch
{
}
}
return Input.GetKeyDown(fallbackKey.Value);
}
private void TrySlapForward()
{
//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_0011: 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_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
Transform transform = ((Component)Camera.main).transform;
Vector3 position = transform.position;
Vector3 forward = transform.forward;
float num = Mathf.Max(0.1f, reach.Value);
float num2 = Mathf.Clamp(hitRadius.Value, 0.01f, 1.5f);
RaycastHit[] array = Physics.SphereCastAll(position, num2, forward, num, -1, (QueryTriggerInteraction)2);
if (array == null || array.Length == 0)
{
return;
}
Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
RaycastHit[] array2 = array;
for (int num3 = 0; num3 < array2.Length; num3++)
{
RaycastHit val = array2[num3];
if (TryHitNpc(((RaycastHit)(ref val)).transform) || TryHitPlayer(((RaycastHit)(ref val)).transform))
{
PlayLocalHitFeedback();
break;
}
}
}
private void PlayLocalHitFeedback()
{
PlayerNetwork val = (((Object)(object)FirstPersonController.Instance != (Object)null) ? ((Component)FirstPersonController.Instance).GetComponent<PlayerNetwork>() : null);
if ((Object)(object)val != (Object)null)
{
val.CmdPlayAnimation(1);
}
if (playBroomSound.Value)
{
AudioSource val2 = GetBroomPrefabAudioSource(val);
if ((Object)(object)val2 != (Object)null && (Object)(object)val2.clip != (Object)null)
{
AudioSource obj = GetLocalAudioSource();
obj.clip = val2.clip;
obj.volume = val2.volume;
obj.pitch = val2.pitch;
obj.spatialBlend = 0f;
obj.Play();
}
else if ((Object)(object)GameData.Instance != (Object)null)
{
GameData.Instance.PlayBroomSound();
}
}
}
private AudioSource GetBroomPrefabAudioSource(PlayerNetwork playerNetwork)
{
if ((Object)(object)broomPrefabAudioSource != (Object)null)
{
return broomPrefabAudioSource;
}
if ((Object)(object)playerNetwork == (Object)null || playerNetwork.equippedPrefabs == null || playerNetwork.equippedPrefabs.Length <= 7 || (Object)(object)playerNetwork.equippedPrefabs[7] == (Object)null)
{
return null;
}
broomPrefabAudioSource = playerNetwork.equippedPrefabs[7].GetComponent<AudioSource>();
return broomPrefabAudioSource;
}
private AudioSource GetLocalAudioSource()
{
if ((Object)(object)localAudioSource != (Object)null)
{
return localAudioSource;
}
localAudioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
localAudioSource.playOnAwake = false;
return localAudioSource;
}
private static bool TryHitNpc(Transform hitTransform)
{
if ((Object)(object)hitTransform == (Object)null || ((Object)hitTransform).name != "HitTrigger")
{
return false;
}
if (!((Component)hitTransform).CompareTag("Interactable"))
{
return false;
}
if ((Object)(object)hitTransform.parent == (Object)null)
{
return false;
}
NPC_Info component = ((Component)hitTransform.parent).GetComponent<NPC_Info>();
if ((Object)(object)component == (Object)null)
{
return false;
}
component.CmdAnimationPlay(0);
return true;
}
private static bool TryHitPlayer(Transform hitTransform)
{
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: 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)
if ((Object)(object)hitTransform == (Object)null)
{
return false;
}
PlayerNetwork val = null;
if (((Component)hitTransform).CompareTag("Player"))
{
val = ((Component)hitTransform).GetComponent<PlayerNetwork>();
}
else if (((Object)hitTransform).name == "HitTrigger" && (Object)(object)hitTransform.parent != (Object)null && (Object)(object)hitTransform.parent.parent != (Object)null)
{
val = ((Component)hitTransform.parent.parent).GetComponent<PlayerNetwork>();
}
if ((Object)(object)val == (Object)null)
{
return false;
}
GameObject gameObject = ((Component)FirstPersonController.Instance).gameObject;
if ((Object)(object)((Component)val).gameObject == (Object)(object)gameObject || (Object)(object)((Component)val).transform == (Object)(object)gameObject.transform || (Object)(object)((Component)val).GetComponent<FirstPersonController>() == (Object)(object)FirstPersonController.Instance)
{
return false;
}
Vector3 position = ((Component)FirstPersonController.Instance).transform.position;
Vector3 val2 = ((Component)val).transform.position - position;
val2.y = 0f;
if (((Vector3)(ref val2)).sqrMagnitude < 0.001f)
{
val2 = ((Component)FirstPersonController.Instance).transform.forward;
}
val.PushPlayer(((Vector3)(ref val2)).normalized);
return true;
}
}
[HarmonyPatch(typeof(GameCanvas), "CreateCanvasNotification")]
internal static class GameCanvasCreateCanvasNotificationPatch
{
private static bool Prefix(string hash)
{
if ((Object)(object)NoBroomSlapPlugin.Instance != (Object)null && NoBroomSlapPlugin.Instance.SuppressNeedBroomNotification && hash == "message14")
{
return false;
}
return true;
}
}
}