Decompiled source of BossStealthOpener v1.1.1

BossStealthOpener.dll

Decompiled 2 days ago
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace BossStealthOpener;

[BepInPlugin("codex.valheim.bossstealthopener", "Boss Stealth Opener", "1.1.1")]
public sealed class Plugin : BaseUnityPlugin
{
	public const string PluginGuid = "codex.valheim.bossstealthopener";

	public const string PluginName = "Boss Stealth Opener";

	public const string PluginVersion = "1.1.1";

	internal static ConfigEntry<bool> Enabled;

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Allows one Sneak-scaled backstab opener per boss and prevents offering bowls from force-alerting summoned bosses.");
		new Harmony("codex.valheim.bossstealthopener").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Boss Stealth Opener 1.1.1 loaded. One opener is available per player for each boss instance.");
	}
}
[HarmonyPatch(typeof(OfferingBowl), "DelayedSpawnBoss")]
internal static class OfferingBowlDelayedSpawnBossPatch
{
	private static void Prefix(OfferingBowl __instance)
	{
		if (Plugin.Enabled.Value && (Object)(object)__instance.m_bossPrefab != (Object)null)
		{
			__instance.m_alertOnSpawn = false;
		}
	}
}
[HarmonyPatch(typeof(Character), "RPC_Damage")]
internal static class CharacterDamagePatch
{
	private static void Prefix(Character __instance, HitData hit)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.Enabled.Value || (Object)(object)__instance == (Object)null || hit == null || !__instance.IsBoss())
		{
			return;
		}
		Character attacker = hit.GetAttacker();
		Player val = (Player)(object)((attacker is Player) ? attacker : null);
		if ((Object)(object)val == (Object)null || !((Character)val).IsCrouching() || hit.m_backstabBonus <= 1f)
		{
			return;
		}
		ZDO zDO = ZDOMan.instance.GetZDO(__instance.GetZDOID());
		if (zDO == null || !zDO.IsValid())
		{
			Plugin.Log.LogWarning((object)"Boss stealth opener skipped because the boss has no valid network state.");
			return;
		}
		long playerID = val.GetPlayerID();
		string text = "BossStealthOpener_used_" + playerID;
		if (!zDO.GetBool(text, false))
		{
			float skillLevel = ((Character)val).GetSkillLevel((SkillType)101);
			float num = Mathf.Clamp01(skillLevel / 100f);
			float num2 = 1f + (hit.m_backstabBonus - 1f) * (0.25f + 0.75f * num);
			hit.ApplyModifier(num2);
			hit.m_backstabBonus = 1f;
			zDO.Set(text, true);
			Plugin.Log.LogInfo((object)("Boss stealth opener applied to " + __instance.GetHoverName() + " for player " + playerID + ": Sneak " + skillLevel.ToString("0.0") + ", damage multiplier x" + num2.ToString("0.00") + "."));
		}
	}
}