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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("ShotgunFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes the shotgun sometimes not hitting enemies")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("ShotgunFix")]
[assembly: AssemblyTitle("ShotgunFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 ShotgunFix
{
[BepInPlugin("ShotgunFix", "ShotgunFix", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
private const float root3 = 1.7320508f;
private const float maxDistance = 30f;
private const float sphereCastRadius = 15f;
private const float sphereCastDistance = 25.980762f;
private const int layerMask = 524296;
private static readonly Harmony harmony = new Harmony("ShotgunFix");
private void Awake()
{
harmony.PatchAll(typeof(Plugin));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Patches completed successfully");
}
private static void playAudio(ShotgunItem gun, Vector3 shotgunPosition, Vector3 shotgunForward)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//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_0072: Unknown result type (might be due to invalid IL or missing references)
int num = RoundManager.PlayRandomClip(gun.gunShootAudio, gun.gunShootSFX, true, 1f, 1840, 1000);
WalkieTalkie.TransmitOneShotAudio(gun.gunShootAudio, gun.gunShootSFX[num], 1f);
RaycastHit val = default(RaycastHit);
if (Physics.Raycast(shotgunPosition, shotgunForward, ref val, 30f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
{
((Component)gun.gunBulletsRicochetAudio).transform.position = ((RaycastHit)(ref val)).point - shotgunForward * 0.5f;
gun.gunBulletsRicochetAudio.Play();
}
}
private static bool isShotInvalid(Vector3 shotgunPosition, Vector3 shotgunForward, Vector3 hitPoint)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: 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_0017: Unknown result type (might be due to invalid IL or missing references)
if (Vector3.Angle(shotgunForward, hitPoint - shotgunPosition) > 30f)
{
return true;
}
RaycastHit val = default(RaycastHit);
if (Physics.Linecast(shotgunPosition, hitPoint, ref val, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
{
return true;
}
return false;
}
private static void hitPlayer(ShotgunItem gun, PlayerControllerB player, float distance)
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
float num = 0f;
int num2 = 0;
if (!(distance < 15f))
{
if (!(distance < 23f))
{
if (distance < 30f)
{
num2 = 20;
}
}
else
{
HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
num2 = 40;
}
}
else
{
num = ((distance < 5f) ? 0.8f : 0.5f);
HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
num2 = 100;
}
if (num > 0f && SoundManager.Instance.timeSinceEarsStartedRinging > 16f)
{
((MonoBehaviour)gun).StartCoroutine(gun.delayedEarsRinging(num));
}
player.DamagePlayer(num2, true, true, (CauseOfDeath)7, 0, false, gun.shotgunRayPoint.forward * 30f);
}
private static void hitEnemy(ShotgunItem gun, EnemyAICollisionDetect enemy, Vector3 shotgunForward, float distance)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)gun.heldByEnemy) && !((Object)(object)gun.heldByEnemy != (Object)(object)enemy.mainScript))
{
return;
}
int num = 0;
if (!(distance < 3.7f))
{
if (!(distance < 6f))
{
if (!(distance < 10f))
{
return;
}
num = 2;
}
else
{
num = 3;
}
}
else
{
num = 5;
}
((IHittable)enemy).Hit(num, shotgunForward, ((GrabbableObject)gun).playerHeldBy, true, -1);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ShotgunItem), "Start")]
private static void initRaycastHitArray(ShotgunItem __instance)
{
__instance.enemyColliders = (RaycastHit[])(object)new RaycastHit[128];
}
[HarmonyPrefix]
[HarmonyPriority(0)]
[HarmonyPatch(typeof(ShotgunItem), "ShootGun")]
private static bool shootGun(ShotgunItem __instance, Vector3 shotgunPosition, Vector3 shotgunForward)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: 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)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
__instance.isReloading = false;
__instance.shellsLoaded = Mathf.Max(__instance.shellsLoaded - 1, 0);
__instance.gunShootParticle.Play(true);
playAudio(__instance, shotgunPosition, shotgunForward);
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if (!Object.op_Implicit((Object)(object)localPlayerController))
{
return false;
}
bool flag = false;
if (((GrabbableObject)__instance).isHeld && (Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)localPlayerController)
{
((GrabbableObject)__instance).playerHeldBy.playerBodyAnimator.SetTrigger("ShootShotgun");
flag = true;
}
int num = Physics.SphereCastNonAlloc(shotgunPosition, 15f, shotgunForward, __instance.enemyColliders, 25.980762f, 524296, (QueryTriggerInteraction)2);
for (int i = 0; i < num; i++)
{
RaycastHit val = __instance.enemyColliders[i];
Vector3 val2 = ((((RaycastHit)(ref val)).distance == 0f) ? ((RaycastHit)(ref val)).collider.ClosestPoint(shotgunPosition) : ((RaycastHit)(ref val)).point);
if (!isShotInvalid(shotgunPosition, shotgunForward, val2))
{
float distance = Vector3.Distance(shotgunPosition, val2);
if (!flag && (Object)(object)((RaycastHit)(ref val)).transform == (Object)(object)((Component)localPlayerController).transform)
{
hitPlayer(__instance, localPlayerController, distance);
}
EnemyAICollisionDetect component = ((Component)((RaycastHit)(ref val)).transform).GetComponent<EnemyAICollisionDetect>();
if (Object.op_Implicit((Object)(object)component))
{
hitEnemy(__instance, component, shotgunForward, distance);
}
}
}
return false;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ShotgunFix";
public const string PLUGIN_NAME = "ShotgunFix";
public const string PLUGIN_VERSION = "1.0.2";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}