Decompiled source of MercExtraEffects v1.0.0

BepInEx/plugins/MercExtraEffects/MercExtraEffects.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Merc;
using On.EntityStates.Merc;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Skills;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ExamplePlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExamplePlugin")]
[assembly: AssemblyTitle("ExamplePlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ExamplePlugin;

[BepInPlugin("com.fafnir62.merc_extra_effects", "Merc Extra Effects", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class MercExtraEffectsPlugin : BaseUnityPlugin
{
	private class MercTracker : MonoBehaviour
	{
		public bool uppercutActive;

		public bool whirlwindActive;

		public bool evisActive;
	}

	public const string PluginGUID = "com.fafnir62.merc_extra_effects";

	public const string PluginName = "Merc Extra Effects";

	public const string PluginVersion = "1.0.0";

	private static BodyIndex mercBodyIndex = (BodyIndex)(-1);

	private static ConfigEntry<float> cfgSecondaryLifestealPercent;

	private static ConfigEntry<float> cfgEvisBarrierPercent;

	private const float UtilityCooldownSeconds = 6f;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[MercExtraEffects] Awake");
		InitConfig();
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnGameLoaded));
	}

	private void OnGameLoaded()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Expected O, but got Unknown
		mercBodyIndex = BodyCatalog.FindBodyIndex("MercBody");
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[MercExtraEffects] MercBodyIndex=" + ((object)(BodyIndex)(ref mercBodyIndex)).ToString()));
		CharacterBody.onBodyStartGlobal += OnBodyStart;
		Uppercut.OnEnter += new hook_OnEnter(Uppercut_OnEnter);
		Uppercut.OnExit += new hook_OnExit(Uppercut_OnExit);
		WhirlwindBase.OnEnter += new hook_OnEnter(WhirlwindBase_OnEnter);
		WhirlwindBase.OnExit += new hook_OnExit(WhirlwindBase_OnExit);
		Evis.OnEnter += new hook_OnEnter(Evis_OnEnter);
		Evis.OnExit += new hook_OnExit(Evis_OnExit);
		GlobalEventManager.onServerDamageDealt += OnServerDamageDealt;
		TrySetMercUtilityCooldownFromBodyPrefab(6f);
	}

	private void InitConfig()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Expected O, but got Unknown
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		cfgSecondaryLifestealPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Merc", "Secondary Lifesteal (%)", 50f, new ConfigDescription("How much of damage dealt is healed while Merc M2 (Uppercut/Whirlwind) is active.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
		cfgEvisBarrierPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Merc", "Evis Barrier Per Hit (%)", 7f, new ConfigDescription("Barrier gained per hit while Eviscerate is active, as % of max combined health.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		try
		{
			ModSettingsManager.SetModDescription("Merc skill effects: Secondary lifesteal + Evis barrier per hit.");
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(cfgSecondaryLifestealPercent, new StepSliderConfig
			{
				min = 0f,
				max = 200f,
				increment = 1f
			}));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(cfgEvisBarrierPercent, new StepSliderConfig
			{
				min = 0f,
				max = 100f,
				increment = 0.5f
			}));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[MercExtraEffects] RiskOfOptions UI not available: " + ex.Message));
		}
	}

	private static bool IsMerc(CharacterBody body)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		return (Object)(object)body != (Object)null && body.bodyIndex == mercBodyIndex;
	}

	private void OnBodyStart(CharacterBody body)
	{
		if (!((Object)(object)body == (Object)null) && (Object)(object)((Component)body).GetComponent<MercTracker>() == (Object)null)
		{
			((Component)body).gameObject.AddComponent<MercTracker>();
		}
	}

	private static MercTracker GetTracker(CharacterBody body)
	{
		return ((Object)(object)body != (Object)null) ? ((Component)body).GetComponent<MercTracker>() : null;
	}

	private void Uppercut_OnEnter(orig_OnEnter orig, Uppercut self)
	{
		orig.Invoke(self);
		CharacterBody characterBody = ((EntityState)self).characterBody;
		if (IsMerc(characterBody))
		{
			MercTracker tracker = GetTracker(characterBody);
			if ((Object)(object)tracker != (Object)null)
			{
				tracker.uppercutActive = true;
			}
		}
	}

	private void Uppercut_OnExit(orig_OnExit orig, Uppercut self)
	{
		CharacterBody characterBody = ((EntityState)self).characterBody;
		if (IsMerc(characterBody))
		{
			MercTracker tracker = GetTracker(characterBody);
			if ((Object)(object)tracker != (Object)null)
			{
				tracker.uppercutActive = false;
			}
		}
		orig.Invoke(self);
	}

	private void WhirlwindBase_OnEnter(orig_OnEnter orig, WhirlwindBase self)
	{
		orig.Invoke(self);
		CharacterBody characterBody = ((EntityState)self).characterBody;
		if (IsMerc(characterBody))
		{
			MercTracker tracker = GetTracker(characterBody);
			if ((Object)(object)tracker != (Object)null)
			{
				tracker.whirlwindActive = true;
			}
		}
	}

	private void WhirlwindBase_OnExit(orig_OnExit orig, WhirlwindBase self)
	{
		CharacterBody characterBody = ((EntityState)self).characterBody;
		if (IsMerc(characterBody))
		{
			MercTracker tracker = GetTracker(characterBody);
			if ((Object)(object)tracker != (Object)null)
			{
				tracker.whirlwindActive = false;
			}
		}
		orig.Invoke(self);
	}

	private void Evis_OnEnter(orig_OnEnter orig, Evis self)
	{
		orig.Invoke(self);
		CharacterBody characterBody = ((EntityState)self).characterBody;
		if (IsMerc(characterBody))
		{
			MercTracker tracker = GetTracker(characterBody);
			if ((Object)(object)tracker != (Object)null)
			{
				tracker.evisActive = true;
			}
		}
	}

	private void Evis_OnExit(orig_OnExit orig, Evis self)
	{
		CharacterBody characterBody = ((EntityState)self).characterBody;
		if (IsMerc(characterBody))
		{
			MercTracker tracker = GetTracker(characterBody);
			if ((Object)(object)tracker != (Object)null)
			{
				tracker.evisActive = false;
			}
		}
		orig.Invoke(self);
	}

	private void OnServerDamageDealt(DamageReport report)
	{
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (report == null)
			{
				return;
			}
			CharacterBody attackerBody = report.attackerBody;
			if (!IsMerc(attackerBody))
			{
				return;
			}
			MercTracker tracker = GetTracker(attackerBody);
			if ((Object)(object)tracker == (Object)null)
			{
				return;
			}
			HealthComponent healthComponent = attackerBody.healthComponent;
			if (!Object.op_Implicit((Object)(object)healthComponent))
			{
				return;
			}
			float damageDealt = report.damageDealt;
			if (damageDealt <= 0f)
			{
				return;
			}
			if (tracker.uppercutActive || tracker.whirlwindActive)
			{
				float num = Mathf.Clamp(cfgSecondaryLifestealPercent.Value, 0f, 200f) / 100f;
				float num2 = damageDealt * num;
				if (num2 > 0f)
				{
					healthComponent.Heal(num2, default(ProcChainMask), true);
				}
			}
			if (tracker.evisActive)
			{
				float num3 = Mathf.Clamp(cfgEvisBarrierPercent.Value, 0f, 100f) / 100f;
				float num4 = healthComponent.fullCombinedHealth * num3;
				if (num4 > 0f)
				{
					healthComponent.AddBarrier(num4);
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[MercExtraEffects] OnServerDamageDealt error: " + ex));
		}
	}

	private void TrySetMercUtilityCooldownFromBodyPrefab(float cooldownSeconds)
	{
		try
		{
			GameObject val = BodyCatalog.FindBodyPrefab("MercBody");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"[MercExtraEffects] Could not find MercBody prefab to set utility cooldown.");
				return;
			}
			SkillLocator component = val.GetComponent<SkillLocator>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.utility == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"[MercExtraEffects] MercBody SkillLocator or utility slot not found.");
				return;
			}
			SkillDef skillDef = component.utility.skillDef;
			if ((Object)(object)skillDef == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"[MercExtraEffects] Merc utility SkillDef not found.");
				return;
			}
			float baseRechargeInterval = skillDef.baseRechargeInterval;
			skillDef.baseRechargeInterval = cooldownSeconds;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[MercExtraEffects] Utility cooldown changed: " + baseRechargeInterval + " -> " + skillDef.baseRechargeInterval));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[MercExtraEffects] Failed to set utility cooldown: " + ex));
		}
	}
}
internal static class Log
{
	private static ManualLogSource _logSource;

	internal static void Init(ManualLogSource logSource)
	{
		_logSource = logSource;
	}

	internal static void Debug(object data)
	{
		_logSource.LogDebug(data);
	}

	internal static void Error(object data)
	{
		_logSource.LogError(data);
	}

	internal static void Fatal(object data)
	{
		_logSource.LogFatal(data);
	}

	internal static void Info(object data)
	{
		_logSource.LogInfo(data);
	}

	internal static void Message(object data)
	{
		_logSource.LogMessage(data);
	}

	internal static void Warning(object data)
	{
		_logSource.LogWarning(data);
	}
}