using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using FistVR;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MoreLethalHeadshot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreLethalHeadshot")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f8685d33-f2b4-480b-b8ed-f97142962a29")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreLethalHeadshotMod;
[BepInPlugin("com.anpan.morelethalheadshot", "More Lethal Headshot", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "com.anpan.morelethalheadshot";
public const string PluginName = "More Lethal Headshot";
public const string PluginVersion = "1.0.0";
internal static ConfigEntry<float> PiercingThreshold;
internal static ConfigEntry<float> BluntThreshold;
internal static ConfigEntry<float> KineticThreshold;
internal static ConfigEntry<bool> EnableHitLog;
private void Awake()
{
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
PiercingThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Headshot Lethal Thresholds", "PiercingLowerBound", 0f, "Projectile headshots become lethal when Dam_Piercing is at or above this value. Set to 0 or less to disable this check.");
BluntThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Headshot Lethal Thresholds", "BluntLowerBound", 0f, "Projectile headshots become lethal when Dam_Blunt is at or above this value. Set to 0 or less to disable this check.");
KineticThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Headshot Lethal Thresholds", "KineticLowerBound", 0f, "Projectile headshots become lethal when Dam_TotalKinetic is at or above this value. Set to 0 or less to disable this check.");
EnableHitLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableHitLog", false, "Write a log line on every hit, regardless of body part.");
new Harmony("com.anpan.morelethalheadshot").PatchAll();
}
}
[HarmonyPatch(typeof(SosigLink), "Damage")]
internal static class SosigLinkDamagePatch
{
private static bool Prefix(SosigLink __instance, Damage d)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
if (d == null)
{
return true;
}
if (Plugin.EnableHitLog != null && Plugin.EnableHitLog.Value)
{
Debug.Log((object)BuildHitLog(__instance, d));
}
if (ShouldForceHeadshotKill(__instance, d))
{
__instance.LinkExplodes(d.Class);
return false;
}
return true;
}
private static bool ShouldForceHeadshotKill(SosigLink link, Damage d)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Invalid comparison between Unknown and I4
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)link == (Object)null)
{
return false;
}
if ((int)d.Class != 1)
{
return false;
}
if ((int)link.BodyPart != 0)
{
return false;
}
if (!MeetsThreshold(d.Dam_Piercing, Plugin.PiercingThreshold) && !MeetsThreshold(d.Dam_Blunt, Plugin.BluntThreshold))
{
return MeetsThreshold(d.Dam_TotalKinetic, Plugin.KineticThreshold);
}
return true;
}
private static bool MeetsThreshold(float damageValue, ConfigEntry<float> threshold)
{
if (threshold == null)
{
return false;
}
return damageValue >= threshold.Value;
}
private static string BuildHitLog(SosigLink link, Damage d)
{
string text = (((Object)(object)link != (Object)null) ? ((object)(SosigBodyPart)(ref link.BodyPart)).ToString() : "null");
return $"HIT | BodyPart={text} | Piercing: {d.Dam_Piercing:F1} | Blunt: {d.Dam_Blunt:F1} | Kinetic: {d.Dam_TotalKinetic:F1}";
}
}