Decompiled source of ClearTheAir v1.2.3

ClearTheAir.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using ConditionalConfigSync;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ClearTheAir")]
[assembly: AssemblyDescription("ClearTheAir")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Crystal")]
[assembly: AssemblyProduct("ClearTheAir")]
[assembly: AssemblyCopyright("Copyright © 2026 Crystal Ferrai")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b3201fce-dc8e-457b-8adc-c625dbf2fed6")]
[assembly: AssemblyFileVersion("1.2.3.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.2.3.0")]
namespace ClearTheAir;

[BepInPlugin("dev.crystal.cleartheair", "Clear The Air", "1.2.3.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("valheim.exe")]
[BepInProcess("valheim_server.exe")]
public class ClearTheAirPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Demister))]
	private static class Demister_Patches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void Awake_Postfix(Demister __instance)
		{
			SetMistClearRadius(__instance, 1f, MistClearRadiusMultiplier.Value);
		}
	}

	public const string ModId = "dev.crystal.cleartheair";

	public const string ModName = "Clear The Air";

	public const string ModVersion = "1.2.3.0";

	internal static readonly ConfigSync ConfigSync;

	public static ConfigEntry<float> MistClearRadiusMultiplier;

	private static Harmony sDemisterHarmony;

	private static readonly FieldInfo sAllDemistersField;

	private float mMistClearRadiusMultiplier;

	static ClearTheAirPlugin()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		ConfigSync = new ConfigSync("dev.crystal.cleartheair")
		{
			DisplayName = "Clear The Air",
			CurrentVersion = "1.2.3.0",
			MinimumRequiredVersion = "1.2.3.0",
			ModRequired = true,
			ModRequirementMode = (ModRequirementMode)1
		};
		sAllDemistersField = typeof(Demister).GetField("m_instances", BindingFlags.Static | BindingFlags.NonPublic);
	}

	private void Awake()
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		MistClearRadiusMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Mist", "MistClearRadiusMultiplier", 1f, "Multiplier to apply to the fog clear radius of all items which can clear mist. Game default 1. [The value will be enforced on a server.]");
		MistClearRadiusMultiplier.SettingChanged += MistClearRadiusMultiplier_SettingChanged;
		((ConditionalConfigSync)ConfigSync).AddConfigEntry<float>(MistClearRadiusMultiplier, (ConfigSyncMode)0);
		ClampConfig();
		mMistClearRadiusMultiplier = MistClearRadiusMultiplier.Value;
		sDemisterHarmony = new Harmony("dev.crystal.cleartheair_Demister");
		sDemisterHarmony.PatchAll(typeof(Demister_Patches));
	}

	private void OnDestroy()
	{
		sDemisterHarmony.UnpatchSelf();
	}

	private void MistClearRadiusMultiplier_SettingChanged(object sender, EventArgs e)
	{
		ClampConfig();
		foreach (Demister item in (List<Demister>)sAllDemistersField.GetValue(null))
		{
			SetMistClearRadius(item, mMistClearRadiusMultiplier, MistClearRadiusMultiplier.Value);
		}
		mMistClearRadiusMultiplier = MistClearRadiusMultiplier.Value;
	}

	private void ClampConfig()
	{
		if (MistClearRadiusMultiplier.Value < 0.1f)
		{
			MistClearRadiusMultiplier.Value = 0.1f;
		}
		if (MistClearRadiusMultiplier.Value > 100f)
		{
			MistClearRadiusMultiplier.Value = 100f;
		}
	}

	private static void SetMistClearRadius(Demister demister, float oldMultiplier, float newMultiplier)
	{
		float endRange = demister.m_forceField.endRange / oldMultiplier * newMultiplier;
		demister.m_forceField.endRange = endRange;
	}
}