Decompiled source of Crowned v1.0.1

Crowned.dll

Decompiled 4 days ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Crowned")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Crowned")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("900f1f33-351f-4eb4-bfe1-4b9d0488580e")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace Crowned;

[BepInPlugin("org.ssmvc.crowned", "Crowned", "1.0.1")]
[BepInProcess("valheim.exe")]
public class Crowned : BaseUnityPlugin
{
	public const string PluginGUID = "org.ssmvc.crowned";

	public const string PluginName = "Crowned";

	public const string PluginVersion = "1.0.1";

	private static Harmony _harmony;

	private volatile bool _refreshCrownMode;

	public static ConfigEntry<bool> Enabled { get; set; }

	public static ConfigEntry<bool> DisableCrownEffect { get; set; }

	public static ConfigEntry<string> DisabledText { get; set; }

	public void Awake()
	{
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod.");
		DisableCrownEffect = ((BaseUnityPlugin)this).Config.Bind<bool>("Crown", "disableCrownEffect", true, "Disable the crown's monster fear effect.");
		DisabledText = ((BaseUnityPlugin)this).Config.Bind<string>("Crown", "disabledText", "Ceremonial", "Text to show if crown effect is disabled.");
		_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "org.ssmvc.crowned");
		((BaseUnityPlugin)this).Config.SettingChanged += OnSettingChanged;
		SetCrownMode();
	}

	private void OnSettingChanged(object sender, SettingChangedEventArgs args)
	{
		if ((object)args.ChangedSetting == Enabled || (object)args.ChangedSetting == DisableCrownEffect)
		{
			_refreshCrownMode = true;
		}
	}

	public void Update()
	{
		if (_refreshCrownMode)
		{
			_refreshCrownMode = false;
			SetCrownMode();
		}
	}

	private static void SetCrownMode()
	{
		Player localPlayer = Player.m_localPlayer;
		if (Object.op_Implicit((Object)(object)localPlayer))
		{
			localPlayer.SetCrownMode(((Character)localPlayer).GetSEMan().GetStatusEffects().OfType<SE_Crowned>()
				.Any());
		}
	}

	public void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingChanged;
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		SetCrownMode();
	}
}
[HarmonyPatch(typeof(Player))]
internal static class PlayerPatch
{
	[HarmonyPrefix]
	[HarmonyPatch("SetCrownMode")]
	private static void SetCrownModePrefix(ref bool crownMode)
	{
		if (Crowned.Enabled.Value && Crowned.DisableCrownEffect.Value)
		{
			crownMode = false;
		}
	}
}
[HarmonyPatch(typeof(StatusEffect), "GetIconText")]
internal static class StatusEffectPatch
{
	public static void Postfix(StatusEffect __instance, ref string __result)
	{
		if (Crowned.Enabled.Value && Crowned.DisableCrownEffect.Value && __instance is SE_Crowned)
		{
			__result = Crowned.DisabledText.Value;
		}
	}
}