using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalKnockback.Patches;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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("LethalKnockback")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d69992ab497fc1d0e40a2ea61c4b3d32246af2b8")]
[assembly: AssemblyProduct("LethalKnockback")]
[assembly: AssemblyTitle("LethalKnockback")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class KickIfModNotInstalled
{
private static readonly string MOD_GUID = "com.jacobot5.LethalKnockback";
[HarmonyPostfix]
[HarmonyPatch("SetSingleton")]
private static void RegisterPrefab()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject(MOD_GUID + " Prefab");
((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
Object.DontDestroyOnLoad((Object)(object)val);
NetworkObject obj = val.AddComponent<NetworkObject>();
typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, GetHash(MOD_GUID));
NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
static uint GetHash(string value)
{
return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
}
}
}
namespace LethalKnockback
{
[BepInPlugin("com.jacobot5.LethalKnockback", "LethalKnockback", "1.1.0")]
public class LethalKnockbackMod : BaseUnityPlugin
{
public const string modGUID = "com.jacobot5.LethalKnockback";
public const string modName = "LethalKnockback";
public const string modVersion = "1.1.0";
private readonly Harmony harmony = new Harmony("com.jacobot5.LethalKnockback");
private static LethalKnockbackMod Instance;
public static ConfigEntry<float> configKnockbackForce;
public static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("com.jacobot5.LethalKnockback");
mls.LogInfo((object)"LethalKnockback has awoken.");
configKnockbackForce = ((BaseUnityPlugin)this).Config.Bind<float>("Knockback", "KnockbackForce", 15f, "How much knockback force to apply. Default is 15. Feel free to break physics.");
harmony.PatchAll(typeof(LethalKnockbackMod));
harmony.PatchAll(typeof(ShotgunItemPatch));
harmony.PatchAll(typeof(KickIfModNotInstalled));
}
}
}
namespace LethalKnockback.Patches
{
[HarmonyPatch(typeof(ShotgunItem))]
internal class ShotgunItemPatch
{
private static float currentKnockbackForce;
[HarmonyPatch("ShootGun")]
[HarmonyPostfix]
private static void AddKnockbackPatch(ShotgunItem __instance)
{
if (!__instance.safetyOn && (Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController && ((GrabbableObject)__instance).isHeld)
{
currentKnockbackForce += LethalKnockbackMod.configKnockbackForce.Value;
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void ContinuousKnockbackPatch(ShotgunItem __instance)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController && ((GrabbableObject)__instance).isHeld)
{
PlayerControllerB playerHeldBy = ((GrabbableObject)__instance).playerHeldBy;
playerHeldBy.externalForces += ((Component)__instance).transform.forward * (0f - currentKnockbackForce);
currentKnockbackForce = Mathf.Lerp(currentKnockbackForce, 0f, 5f * Time.deltaTime);
}
}
}
}