Decompiled source of DarkwaterDamageConfiguration v1.1.7

D.D.C.dll

Decompiled 5 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Fusion;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DarkwaterReduction")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DarkwaterReduction")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("87c62d6b-b0e2-4474-ab07-efa02cc6bc20")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DarkwaterDamageConfig;

[BepInPlugin("Darkwater.DamageConfig", "Darkwater Damage Config", "1.1.6")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	public static ConfigEntry<bool> EnableDamageMultiplier;

	public static ConfigEntry<float> DamageMultiplier;

	public static ConfigEntry<bool> EnableKillOverride;

	public static ConfigEntry<int> KillOverrideDamage;

	private void Awake()
	{
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		EnableDamageMultiplier = ((BaseUnityPlugin)this).Config.Bind<bool>("Damage Taken Multiplier Toggle", "Enable", false, "Enable or disable the damage taken multiplier.");
		DamageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Damage Taken Multiplier", "Multiplier", 1f, "Multiplier for incoming damage. Example: 0.5 = -50% damage, 1.0 = normal, 1.5 = +50% damage.");
		EnableKillOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("Enable Kill Override", "Enable", false, "Enable or disable replacing KillPlayer with flat damage instead.");
		KillOverrideDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Kill Override Forced Damage", "Damage", 100, "Amount of forced damage to apply to the player if they happen to receive an attack that would have normally killed them instead.");
		Harmony val = new Harmony("Darkwater.DamageConfig");
		val.PatchAll();
	}
}
[HarmonyPatch(typeof(E_HealthController))]
public static class HealthControllerPatch
{
	[HarmonyPrefix]
	[HarmonyPatch("DamagePlayer", new Type[] { typeof(int) })]
	public static void DamagePlayer_Prefix(E_HealthController __instance, ref int P_damage)
	{
		if (Plugin.EnableDamageMultiplier.Value)
		{
			C_Controller e_player = __instance.E_player;
			C_Controller_Player val = (C_Controller_Player)(object)((e_player is C_Controller_Player) ? e_player : null);
			if (val != null && !((Object)(object)CMD_PlayerManager.Instance?.localPlayer != (Object)(object)val))
			{
				float value = Plugin.DamageMultiplier.Value;
				P_damage = Mathf.Max(0, (int)((float)P_damage * value));
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch("HealPlayer", new Type[] { typeof(int) })]
	public static void HealPlayer_Prefix(E_HealthController __instance, ref int P_value)
	{
		if (Plugin.EnableDamageMultiplier.Value)
		{
			C_Controller e_player = __instance.E_player;
			C_Controller_Player val = (C_Controller_Player)(object)((e_player is C_Controller_Player) ? e_player : null);
			if (val != null && !((Object)(object)CMD_PlayerManager.Instance?.localPlayer != (Object)(object)val) && P_value < 0)
			{
				float value = Plugin.DamageMultiplier.Value;
				P_value = Mathf.Min(0, (int)((float)P_value * value));
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch("KillPlayer")]
	public static bool KillPlayer_Prefix(E_HealthController __instance)
	{
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.EnableKillOverride.Value)
		{
			return true;
		}
		C_Controller e_player = __instance.E_player;
		C_Controller_Player val = (C_Controller_Player)(object)((e_player is C_Controller_Player) ? e_player : null);
		if (val == null)
		{
			return true;
		}
		if ((Object)(object)CMD_PlayerManager.Instance?.localPlayer != (Object)(object)val)
		{
			return true;
		}
		if (((C_Controller)val).hitpoints <= 0f)
		{
			return true;
		}
		int num = Mathf.Max(1, Plugin.KillOverrideDamage.Value);
		float num2 = Mathf.Clamp(((C_Controller)val).hitpoints - (float)num, 0f, ((C_Controller)val).GetMaxHitpoints());
		((C_Controller)val).RPC_SetHitpoints(num2, default(RpcInfo));
		return ((C_Controller)val).hitpoints <= 0f;
	}
}