Decompiled source of KillMeForMyPower v1.0.2

KillMeForMyPower.dll

Decompiled 3 hours 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 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("PowersForbiddenForNewbies")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PowersForbiddenForNewbies")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e78efca2-b045-4686-8901-4fedba31614f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KillMeForMyPower;

public class KillMeForMyPowerUtils
{
	private static bool hasUniqueKey(string key)
	{
		return ((Humanoid)Player.m_localPlayer).HaveUniqueKey(key);
	}

	public static bool isEikthyrDefeatedForPlayer()
	{
		return hasUniqueKey("Eikthyr_Defeated");
	}

	public static bool isElderForPlayer()
	{
		return hasUniqueKey("gd_king_Defeated");
	}

	public static bool isBonemassDefeatedForPlayer()
	{
		return hasUniqueKey("Bonemass_Defeated");
	}

	public static bool isModerDefeatedForPlayer()
	{
		return hasUniqueKey("Dragon_Defeated");
	}

	public static bool isYagluthDefeatedForPlayer()
	{
		return hasUniqueKey("GoblinKing_Defeated");
	}

	public static bool isQueenDefeatedForPlayer()
	{
		return hasUniqueKey("SeekerQueen_Defeated");
	}

	public static bool isFaderDefeatedForPlayer()
	{
		return hasUniqueKey("Fader_Defeated");
	}

	public static bool HasDefeatedBoss(string bossName)
	{
		return bossName switch
		{
			"Eikthyr" => isEikthyrDefeatedForPlayer(), 
			"TheElder" => isElderForPlayer(), 
			"Bonemass" => isBonemassDefeatedForPlayer(), 
			"Moder" => isModerDefeatedForPlayer(), 
			"Yagluth" => isYagluthDefeatedForPlayer(), 
			"Queen" => isQueenDefeatedForPlayer(), 
			"Fader" => isFaderDefeatedForPlayer(), 
			_ => false, 
		};
	}
}
public class BossPowerRestriction
{
	[HarmonyPatch(typeof(Player), "ActivateGuardianPower")]
	public static class ActivateGuardianPowerPatch
	{
		public static bool Prefix(Player __instance, ref bool __result)
		{
			string text = __instance.GetGuardianPowerName().Replace("GP_", "");
			Logger.Log("Guardian power name: " + text);
			if (!KillMeForMyPowerUtils.HasDefeatedBoss(text))
			{
				((Character)__instance).Message((MessageType)2, ConfigurationFile.forbiddenMessage.Value, 0, (Sprite)null);
				ApplyBlockedEffect(text);
				__result = false;
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(ItemStand), "DelayedPowerActivation")]
	public static class DelayedPowerActivationPatch
	{
		public static bool Prefix(ItemStand __instance)
		{
			StatusEffect guardianPower = __instance.m_guardianPower;
			string text = ((guardianPower != null) ? ((Object)guardianPower).name.Replace("GP_", "") : null);
			Logger.Log("guardianPowerName: " + text);
			if (!KillMeForMyPowerUtils.HasDefeatedBoss(text))
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, ConfigurationFile.forbiddenMessage.Value, 0, (Sprite)null);
				ApplyBlockedEffect(text);
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Character), "OnDeath")]
	public static class RegisterBossDefeatPatch
	{
		public static void Postfix(Character __instance)
		{
			if ((Object)(object)__instance != (Object)null && __instance.IsBoss())
			{
				string text = ((Object)__instance).name.Replace("(Clone)", "");
				long playerID = Player.m_localPlayer.GetPlayerID();
				((Humanoid)Player.m_localPlayer).AddUniqueKey(text + "_Defeated");
			}
		}
	}

	private static void ApplyBlockedEffect(string bossName)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Expected O, but got Unknown
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Expected O, but got Unknown
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Expected O, but got Unknown
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Expected O, but got Unknown
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Expected O, but got Unknown
		SEMan sEMan = ((Character)Player.m_localPlayer).GetSEMan();
		switch (bossName)
		{
		case "Eikthyr":
		{
			StatusEffect val3 = ((sEMan != null) ? sEMan.AddStatusEffect("Lightning".GetHashCode(), false, 0, 0f) : null);
			val3.m_ttl = 5f;
			break;
		}
		case "TheElder":
		{
			SE_Burning val6 = (SE_Burning)((sEMan != null) ? sEMan.AddStatusEffect("Burning".GetHashCode(), false, 0, 0f) : null);
			val6.AddFireDamage(Math.Max(2f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			break;
		}
		case "Bonemass":
		{
			SE_Poison val4 = (SE_Poison)((sEMan != null) ? sEMan.AddStatusEffect("Poison".GetHashCode(), false, 0, 0f) : null);
			val4.AddDamage(Math.Max(1f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			break;
		}
		case "Moder":
		{
			SE_Frost val7 = (SE_Frost)((sEMan != null) ? sEMan.AddStatusEffect("Frost".GetHashCode(), false, 0, 0f) : null);
			((StatusEffect)val7).m_ttl = 5f;
			break;
		}
		case "Yagluth":
		{
			SE_Burning val2 = (SE_Burning)((sEMan != null) ? sEMan.AddStatusEffect("Burning".GetHashCode(), false, 0, 0f) : null);
			val2.AddFireDamage(Math.Max(2f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			break;
		}
		case "Queen":
		{
			SE_Poison val5 = (SE_Poison)((sEMan != null) ? sEMan.AddStatusEffect("Poison".GetHashCode(), false, 0, 0f) : null);
			val5.AddDamage(Math.Max(1f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			break;
		}
		case "Fader":
		{
			SE_Burning val = (SE_Burning)((sEMan != null) ? sEMan.AddStatusEffect("Burning".GetHashCode(), false, 0, 0f) : null);
			val.AddFireDamage(Math.Max(2f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			break;
		}
		}
	}
}
internal class ConfigurationFile
{
	public static ConfigEntry<bool> debug;

	public static ConfigEntry<string> forbiddenMessage;

	private static ConfigFile config;

	internal static void LoadConfig(BaseUnityPlugin plugin)
	{
		config = plugin.Config;
		debug = config.Bind<bool>("1 - General", "DebugMode", false, "Enabling/Disabling the debugging in the console (default = false)");
		forbiddenMessage = config.Bind<string>("2 - Config", "ForbiddenMessage", "Kill the forsaken first!", "Message to show when you cannot obtain the forsaken power");
	}
}
[BepInPlugin("Turbero.KillMeForMyPower", "Kill Me For My Power", "1.0.2")]
public class KillMeForMyPower : BaseUnityPlugin
{
	public const string GUID = "Turbero.KillMeForMyPower";

	public const string NAME = "Kill Me For My Power";

	public const string VERSION = "1.0.2";

	private readonly Harmony harmony = new Harmony("Turbero.KillMeForMyPower");

	private void Awake()
	{
		ConfigurationFile.LoadConfig((BaseUnityPlugin)(object)this);
		harmony.PatchAll();
	}

	private void onDestroy()
	{
		harmony.UnpatchSelf();
	}
}
public static class Logger
{
	public static ManualLogSource logger = Logger.CreateLogSource("Kill Me For My Power");

	internal static void Log(object s)
	{
		if (ConfigurationFile.debug.Value)
		{
			logger.LogInfo((object)s?.ToString());
		}
	}

	internal static void LogInfo(object s)
	{
		logger.LogInfo((object)s?.ToString());
	}

	internal static void LogWarning(object s)
	{
		logger.LogWarning((object)s?.ToString());
	}

	internal static void LogError(object s)
	{
		logger.LogError((object)s?.ToString());
	}
}