using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace NoDynamitePlayerDamage;
[BepInPlugin("elliott.howtofish.nodynamiteplayerdamage", "No Dynamite Player Damage", "1.0.0")]
[BepInProcess("How to Fish.exe")]
public class Plugin : BaseUnityPlugin
{
public const string Guid = "elliott.howtofish.nodynamiteplayerdamage";
public const string Name = "No Dynamite Player Damage";
public const string Version = "1.0.0";
internal static ManualLogSource Log;
internal static ConfigEntry<bool> BlockDynamite;
internal static ConfigEntry<bool> BlockWhale;
internal static ConfigEntry<bool> Verbose;
private void Awake()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
BlockDynamite = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "BlockDynamitePlayerDamage", true, "Dynamite (and any lit/thrown explosive item) deals no damage to players. Fish, creatures and boats are completely unaffected. HOST ONLY - damage is server-authoritative, so only the lobby host needs this mod.");
BlockWhale = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "BlockWhaleLandingPlayerDamage", false, "Also block player damage from the Bowhead Whale landing explosion. Off by default so only dynamite is changed.");
Verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogBlockedHits", false, "Write a log line every time a player hit is suppressed.");
new Harmony("elliott.howtofish.nodynamiteplayerdamage").PatchAll(typeof(Patches));
Log.LogInfo((object)("No Dynamite Player Damage 1.0.0 loaded. Dynamite player damage suppression is " + ((!BlockDynamite.Value) ? "OFF" : "ON") + " (host only)."));
}
}
[HarmonyPatch]
internal static class Patches
{
private static int _inDynamite;
private static int _inWhale;
private static bool ShouldSuppress()
{
if (_inDynamite > 0 && Plugin.BlockDynamite.Value)
{
return true;
}
if (_inWhale > 0 && Plugin.BlockWhale.Value)
{
return true;
}
return false;
}
[HarmonyPatch(typeof(Explosive), "ServerExplode")]
[HarmonyPrefix]
private static void Explosive_Pre()
{
_inDynamite++;
}
[HarmonyPatch(typeof(Explosive), "ServerExplode")]
[HarmonyFinalizer]
private static void Explosive_Post()
{
if (_inDynamite > 0)
{
_inDynamite--;
}
}
[HarmonyPatch(typeof(BowheadWhale), "OnLanded")]
[HarmonyPrefix]
private static void Whale_Pre()
{
_inWhale++;
}
[HarmonyPatch(typeof(BowheadWhale), "OnLanded")]
[HarmonyFinalizer]
private static void Whale_Post()
{
if (_inWhale > 0)
{
_inWhale--;
}
}
[HarmonyPatch(typeof(Server), "HitPlayer")]
[HarmonyPrefix]
private static bool Server_HitPlayer_Pre(Player player, int damage)
{
if (!ShouldSuppress())
{
return true;
}
if (Plugin.Verbose.Value && Plugin.Log != null)
{
string text = ((!((Object)(object)player != (Object)null)) ? "<null>" : player.SteamName);
Plugin.Log.LogInfo((object)("Suppressed " + damage + " explosion damage to " + text));
}
return false;
}
}