Decompiled source of KarmaMithrixTweaks v1.0.0

KarmaMithrixTweaks.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.BrotherMonster;
using EntityStates.BrotherMonster.KarmaSpire;
using EntityStates.BrotherMonster.Weapon;
using EntityStates.Missions.BrotherEncounter;
using HarmonyLib;
using KarmaMithrixTweaks.Configuration;
using KarmaMithrixTweaks.Patches;
using Microsoft.CodeAnalysis;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KarmaMithrixTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+652a68f48c7d1a69dd00e9c59a98acc57fd30f99")]
[assembly: AssemblyProduct("KarmaMithrixTweaks")]
[assembly: AssemblyTitle("KarmaMithrixTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace KarmaMithrixTweaks
{
	[BepInPlugin("ua.quest-play.karmamithrixtweaks", "KarmaMithrixTweaks", "1.0.0")]
	public class KarmaMithrixTweaksPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "ua.quest-play.karmamithrixtweaks";

		public const string PluginName = "KarmaMithrixTweaks";

		public const string PluginVersion = "1.0.0";

		private Harmony _harmony;

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			Log.LogInfo((object)"Initializing KarmaMithrixTweaks v1.0.0...");
			_harmony = new Harmony("ua.quest-play.karmamithrixtweaks");
			_harmony.PatchAll(typeof(SuperArmorPatches));
			_harmony.PatchAll(typeof(SpirePatches));
			_harmony.PatchAll(typeof(PassiveUltPatches));
			_harmony.PatchAll(typeof(Phase2Patches));
			_harmony.PatchAll(typeof(HazardPatches));
			_harmony.PatchAll(typeof(StatPatches));
			Log.LogInfo((object)"KarmaMithrixTweaks v1.0.0 loaded successfully with per-Karma-level customizations!");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace KarmaMithrixTweaks.Patches
{
	public static class HazardPatches
	{
		[HarmonyPatch(typeof(BaseSlideState), "AttemptFireHomingBombAuthority")]
		[HarmonyPrefix]
		public static bool SlideHomingBombPrefix()
		{
			if (!ModConfig.SlideHomingBombsEnabled.Value)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(BaseSlideState), "AttemptFireCrystalsAuthority")]
		[HarmonyPrefix]
		public static bool SlideSpikeCrystalsPrefix()
		{
			if (!ModConfig.SlideSpikeCrystalsEnabled.Value)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(EnterSkyLeap), "AttemptFireGravZoneAuthority")]
		[HarmonyPrefix]
		public static bool SkyLeapGravZonePrefix()
		{
			if (!ModConfig.SkyLeapGravZoneEnabled.Value)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(EnterSkyLeap), "AttemptFireSkyLeapBombsAuthority")]
		[HarmonyPrefix]
		public static bool SkyLeapCardinalBombsPrefix()
		{
			if (!ModConfig.SkyLeapCardinalBombsEnabled.Value)
			{
				return false;
			}
			return true;
		}
	}
	public static class PassiveUltPatches
	{
		[HarmonyPatch(typeof(Idle), "FixedUpdate")]
		[HarmonyPrefix]
		public static bool WeaponIdleFixedUpdatePrefix()
		{
			int num = ((!Object.op_Implicit((Object)(object)PhaseCounter.instance)) ? 1 : PhaseCounter.instance.phase);
			if (num == 1 && !ModConfig.PassiveMobileUltPhase1Enabled.Value)
			{
				return false;
			}
			if (num == 3 && !ModConfig.PassiveMobileUltPhase3Enabled.Value)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(IdleHurt), "FixedUpdate")]
		[HarmonyPrefix]
		public static bool WeaponIdleHurtFixedUpdatePrefix()
		{
			if (!ModConfig.PassiveHurtUltPhase4Enabled.Value)
			{
				return false;
			}
			return true;
		}
	}
	public static class Phase2Patches
	{
		[HarmonyPatch(typeof(Phase2), "KarmaDeathPizza")]
		[HarmonyPrefix]
		public static bool KarmaDeathPizzaPrefix()
		{
			if (!ModConfig.Phase2DeathPizzasEnabled.Value)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(GiftItem), "SendItemServer")]
		[HarmonyPrefix]
		public static bool GiftItemSendItemServerPrefix()
		{
			if (!ModConfig.Phase2ThroneGiftItemsEnabled.Value)
			{
				return false;
			}
			return true;
		}
	}
	public static class SpirePatches
	{
		[HarmonyPatch(typeof(CharacterMaster), "GetDeployableSameSlotLimit")]
		[HarmonyPostfix]
		public static void GetDeployableLimitPostfix(DeployableSlot slot, ref int __result)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)slot == 44)
			{
				__result = Mathf.Max(0, ModConfig.MaxKarmicSpires.Value);
			}
		}

		[HarmonyPatch(typeof(UltChannelState), "FireWave")]
		[HarmonyPrefix]
		public static bool FireWavePrefix(bool useStationary)
		{
			if (useStationary && !ModConfig.SpiresCastPizzaDuringUlt.Value)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(SpireBaseState), "OnEnter")]
		[HarmonyPostfix]
		public static void SpireBaseStateOnEnterPostfix(SpireBaseState __instance)
		{
			if (!ModConfig.SpiresCrippleAuraEnabled.Value)
			{
				BuffWard val = (((Object)(object)((EntityState)__instance).outer != (Object)null) ? ((Component)((EntityState)__instance).outer).GetComponent<BuffWard>() : null);
				if ((Object)(object)val != (Object)null)
				{
					val.Networkradius = 0f;
					((Behaviour)val).enabled = false;
				}
			}
		}
	}
	public static class StatPatches
	{
		private static Action<CharacterBody, float> _setMaxHealth;

		private static Action<CharacterBody, float> _setMoveSpeed;

		private static Action<CharacterBody, float> _setAttackSpeed;

		private static Action<CharacterBody, float> _setDamage;

		static StatPatches()
		{
			PropertyInfo property = typeof(CharacterBody).GetProperty("maxHealth", BindingFlags.Instance | BindingFlags.Public);
			if (property?.GetSetMethod(nonPublic: true) != null)
			{
				_setMaxHealth = (Action<CharacterBody, float>)Delegate.CreateDelegate(typeof(Action<CharacterBody, float>), property.GetSetMethod(nonPublic: true));
			}
			PropertyInfo property2 = typeof(CharacterBody).GetProperty("moveSpeed", BindingFlags.Instance | BindingFlags.Public);
			if (property2?.GetSetMethod(nonPublic: true) != null)
			{
				_setMoveSpeed = (Action<CharacterBody, float>)Delegate.CreateDelegate(typeof(Action<CharacterBody, float>), property2.GetSetMethod(nonPublic: true));
			}
			PropertyInfo property3 = typeof(CharacterBody).GetProperty("attackSpeed", BindingFlags.Instance | BindingFlags.Public);
			if (property3?.GetSetMethod(nonPublic: true) != null)
			{
				_setAttackSpeed = (Action<CharacterBody, float>)Delegate.CreateDelegate(typeof(Action<CharacterBody, float>), property3.GetSetMethod(nonPublic: true));
			}
			PropertyInfo property4 = typeof(CharacterBody).GetProperty("damage", BindingFlags.Instance | BindingFlags.Public);
			if (property4?.GetSetMethod(nonPublic: true) != null)
			{
				_setDamage = (Action<CharacterBody, float>)Delegate.CreateDelegate(typeof(Action<CharacterBody, float>), property4.GetSetMethod(nonPublic: true));
			}
		}

		[HarmonyPatch(typeof(CharacterBody), "RecalculateStats")]
		[HarmonyPostfix]
		public static void RecalculateStatsPostfix(CharacterBody __instance)
		{
			if (!BrotherKarmaUtils.IsBrother(__instance))
			{
				return;
			}
			int num = (Object.op_Implicit((Object)(object)KarmaManager.instance) ? KarmaManager.instance.GetEffectiveKarma() : 0);
			if (num <= 0)
			{
				return;
			}
			if (num >= 2 && !ModConfig.Karma2StatBuffEnabled.Value)
			{
				if (_setMoveSpeed != null)
				{
					_setMoveSpeed(__instance, __instance.moveSpeed / 1.3f);
				}
				if (_setAttackSpeed != null)
				{
					_setAttackSpeed(__instance, __instance.attackSpeed / 1.3f);
				}
			}
			if (!ModConfig.Karma7DamageScalingEnabled.Value && _setDamage != null)
			{
				_setDamage(__instance, __instance.damage / (float)(1.0 + 0.01 * (double)num));
			}
			if (num >= 8 && _setMaxHealth != null)
			{
				float num2 = Mathf.Clamp(ModConfig.Karma8HealthMultiplier.Value, 1f, 3f);
				if (Mathf.Abs(num2 - 1.5f) > 0.01f)
				{
					_setMaxHealth(__instance, __instance.maxHealth / 1.5f * num2);
				}
			}
		}
	}
	public static class SuperArmorPatches
	{
		[HarmonyPatch(typeof(BrotherSuperArmorController), "OnDamageDealtServer")]
		[HarmonyPrefix]
		public static bool OnDamageDealtServerPrefix(BrotherSuperArmorController __instance, DamageReport dmgReport)
		{
			int num = ((!Object.op_Implicit((Object)(object)PhaseCounter.instance)) ? 1 : PhaseCounter.instance.phase);
			if ((Object)(object)((Component)__instance).gameObject != (Object)null && ((Object)((Component)__instance).gameObject).name.Contains("BrotherHurt"))
			{
				num = 4;
			}
			if (num switch
			{
				1 => ModConfig.SuperArmorPhase1Enabled.Value ? 1 : 0, 
				3 => ModConfig.SuperArmorPhase3Enabled.Value ? 1 : 0, 
				4 => ModConfig.SuperArmorPhase4Enabled.Value ? 1 : 0, 
				_ => 1, 
			} == 0)
			{
				return false;
			}
			__instance.buffDuration = ModConfig.SuperArmorBuffDuration.Value;
			__instance.healthThreshold = ModConfig.SuperArmorHealthThreshold.Value;
			return true;
		}

		[HarmonyPatch(typeof(HealthComponent), "TakeDamage")]
		[HarmonyPrefix]
		public static void TakeDamagePrefix(HealthComponent __instance, DamageInfo damageInfo)
		{
			if (damageInfo == null || (Object)(object)__instance == (Object)null || (Object)(object)__instance.body == (Object)null)
			{
				return;
			}
			CharacterBody body = __instance.body;
			if ((BrotherKarmaUtils.IsBrother(body) || ((Object)body).name.Contains("Brother")) && body.HasBuff(Buffs.DamageReduction))
			{
				float num = Mathf.Clamp(ModConfig.SuperArmorDamageMultiplier.Value, 0.01f, 1f);
				if (Mathf.Abs(num - 0.1f) > 0.001f)
				{
					damageInfo.damage *= num / 0.1f;
				}
			}
		}
	}
}
namespace KarmaMithrixTweaks.Configuration
{
	public static class ModConfig
	{
		public static ConfigEntry<bool> SuperArmorPhase1Enabled { get; private set; }

		public static ConfigEntry<bool> SuperArmorPhase3Enabled { get; private set; }

		public static ConfigEntry<bool> SuperArmorPhase4Enabled { get; private set; }

		public static ConfigEntry<float> SuperArmorBuffDuration { get; private set; }

		public static ConfigEntry<float> SuperArmorHealthThreshold { get; private set; }

		public static ConfigEntry<float> SuperArmorDamageMultiplier { get; private set; }

		public static ConfigEntry<bool> Karma2StatBuffEnabled { get; private set; }

		public static ConfigEntry<bool> SkyLeapGravZoneEnabled { get; private set; }

		public static ConfigEntry<bool> SkyLeapCardinalBombsEnabled { get; private set; }

		public static ConfigEntry<bool> SlideSpikeCrystalsEnabled { get; private set; }

		public static ConfigEntry<bool> Phase2ThroneGiftItemsEnabled { get; private set; }

		public static ConfigEntry<bool> Phase2DeathPizzasEnabled { get; private set; }

		public static ConfigEntry<bool> PassiveMobileUltPhase1Enabled { get; private set; }

		public static ConfigEntry<bool> PassiveMobileUltPhase3Enabled { get; private set; }

		public static ConfigEntry<bool> PassiveHurtUltPhase4Enabled { get; private set; }

		public static ConfigEntry<int> MaxKarmicSpires { get; private set; }

		public static ConfigEntry<bool> SpiresCastPizzaDuringUlt { get; private set; }

		public static ConfigEntry<bool> SpiresCrippleAuraEnabled { get; private set; }

		public static ConfigEntry<bool> SlideHomingBombsEnabled { get; private set; }

		public static ConfigEntry<bool> Karma7DamageScalingEnabled { get; private set; }

		public static ConfigEntry<float> Karma8HealthMultiplier { get; private set; }

		public static void Init(ConfigFile config)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Expected O, but got Unknown
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Expected O, but got Unknown
			SuperArmorPhase1Enabled = config.Bind<bool>("Karma 1", "SuperArmor_Phase1_Enabled", true, "Enable Super-Armor shell during Phase 1. In vanilla, taking 10% max HP damage grants a 5-second DamageReduction shell.");
			SuperArmorPhase3Enabled = config.Bind<bool>("Karma 1", "SuperArmor_Phase3_Enabled", true, "Enable Super-Armor shell during Phase 3.");
			SuperArmorPhase4Enabled = config.Bind<bool>("Karma 1", "SuperArmor_Phase4_Enabled", false, "Enable Super-Armor shell during Phase 4.");
			SuperArmorBuffDuration = config.Bind<float>("Karma 1", "SuperArmor_BuffDuration", 2f, new ConfigDescription("Duration (in seconds) of the DamageReduction buff when triggered. Vanilla is 5.0 seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			SuperArmorHealthThreshold = config.Bind<float>("Karma 1", "SuperArmor_HealthThreshold", 0.2f, new ConfigDescription("Fraction of total HP Mithrix must lose before triggering Super-Armor. 0.20 = 20% max HP. Vanilla is 0.10 (10%).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 1f), Array.Empty<object>()));
			SuperArmorDamageMultiplier = config.Bind<float>("Karma 1", "SuperArmor_DamageMultiplier", 0.5f, new ConfigDescription("Incoming damage multiplier while Super-Armor buff is active. 0.50 = -50% damage taken. In vanilla this is 0.10 (-90% damage taken)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), Array.Empty<object>()));
			Karma2StatBuffEnabled = config.Bind<bool>("Karma 2", "StatBuff_SpeedAttack_Enabled", true, "If true, Mithrix gains +30% movement speed and +30% attack speed at Karma 2 or higher. Set to false to remove this speed increase.");
			SkyLeapGravZoneEnabled = config.Bind<bool>("Karma 2", "SkyLeap_GravZone_Enabled", true, "If true, Sky Leap generates a gravity vortex pulling players towards the center. Vanilla is true.");
			SkyLeapCardinalBombsEnabled = config.Bind<bool>("Karma 2", "SkyLeap_CardinalBombs_Enabled", true, "If true, Sky Leap places delayed bombs that detonate into shockwave rings. Vanilla is true.");
			SlideSpikeCrystalsEnabled = config.Bind<bool>("Karma 2", "Slide_SpikeCrystals_Enabled", true, "If true, Mithrix leaves crystal spikes behind his slide dash. Vanilla is true.");
			Phase2ThroneGiftItemsEnabled = config.Bind<bool>("Karma 2", "Phase2_ThroneGiftItems_Enabled", true, "If true, the throne gifts items to living monsters. Vanilla is true.");
			Phase2DeathPizzasEnabled = config.Bind<bool>("Karma 3", "Phase2_DeathPizzas_Enabled", false, "If true, every Lunar Chimera killed in Phase 2 detonates at its death position. Vanilla is true.");
			PassiveMobileUltPhase1Enabled = config.Bind<bool>("Karma 4", "PassiveMobileUlt_Phase1_Enabled", false, "If true, Mithrix can passively charge and cast his Ultimate while running around in Phase 1. Vanilla is true.");
			PassiveMobileUltPhase3Enabled = config.Bind<bool>("Karma 4", "PassiveMobileUlt_Phase3_Enabled", false, "If true, Mithrix can passively charge and cast his Ultimate while running around in Phase 3 Vanilla is true.");
			PassiveHurtUltPhase4Enabled = config.Bind<bool>("Karma 4", "PassiveHurtUlt_Phase4_Enabled", false, "If true, Mithrix can passively charge and cast his Ultimate while crawling in Phase 4 when below low HP threshold. Vanilla is true.");
			MaxKarmicSpires = config.Bind<int>("Karma 5", "MaxKarmicSpires", 3, new ConfigDescription("Maximum number of Karmic Spires that Mithrix can deploy at start of Phase 3 / after Pizza. Vanilla is 6.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 12), Array.Empty<object>()));
			SpiresCastPizzaDuringUlt = config.Bind<bool>("Karma 5", "SpiresCastPizzaDuringUlt", false, "If true, active Karmic Spires cast stationary pizza waves.");
			SpiresCrippleAuraEnabled = config.Bind<bool>("Karma 5", "SpiresCrippleAura_Enabled", true, "If true, Karmic Spires project a widening Cripple aura");
			SlideHomingBombsEnabled = config.Bind<bool>("Karma 6", "Slide_HomingBombs_Enabled", true, "If true, Mithrix launches a 500% damage homing bomb upon performing a slide dash. Vanilla is true.");
			Karma7DamageScalingEnabled = config.Bind<bool>("Karma 7", "DamageScaling_Enabled", true, "If true, Mithrix gains +1% bonus damage per Karma level.");
			Karma8HealthMultiplier = config.Bind<float>("Karma 8", "HealthBonus_Multiplier", 1.5f, new ConfigDescription("Max HP multiplier for Mithrix at Karma 8. Vanilla is 1.50 (+50% health). Set to 1.0 for no health increase.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 3f), Array.Empty<object>()));
		}
	}
}