Decompiled source of DadsMistClear v1.0.0

DadsMistClear.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DadsMistClear")]
[assembly: AssemblyProduct("DadsMistClear")]
[assembly: AssemblyCompany("Dad_Is_Bored")]
[assembly: AssemblyCopyright("Copyright (c) 2026 Dad_Is_Bored")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 DadsMistClear
{
	[BepInPlugin("com.dadisbored.dadsmistclear", "DadsMistClear", "1.0.0")]
	[BepInProcess("valheim.exe")]
	public sealed class DadsMistClearPlugin : BaseUnityPlugin
	{
		public const string Guid = "com.dadisbored.dadsmistclear";

		public const string Name = "DadsMistClear";

		public const string Version = "1.0.0";

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> UseGlobalKeys;

		internal static ConfigEntry<string> GlobalKeysNeeded;

		private Harmony? _harmony;

		private ParticleSystem? _mistParticles;

		private bool _originalEmission;

		private bool _suppressed;

		private float _nextRefresh;

		private void Awake()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Clear vanilla Mistlands mist on this client.");
			UseGlobalKeys = ((BaseUnityPlugin)this).Config.Bind<bool>("Progression", "Use Global Keys", false, "Clear mist only after every listed world key is set.");
			GlobalKeysNeeded = ((BaseUnityPlugin)this).Config.Bind<string>("Progression", "Global Keys Needed", "defeated_eikthyr,defeated_dragon,defeated_gdking,defeated_bonemass,defeated_goblinking", "Comma-separated world keys required when Use Global Keys is enabled.");
			_harmony = new Harmony("com.dadisbored.dadsmistclear");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("DadsMistClear 1.0.0 loaded for Valheim " + ((object)Version.CurrentVersion/*cast due to .constrained prefix*/).ToString() + "."));
		}

		internal static bool ShouldClear()
		{
			if (!Enabled.Value)
			{
				return false;
			}
			if (!UseGlobalKeys.Value)
			{
				return true;
			}
			ZoneSystem instance = ZoneSystem.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			string[] array = GlobalKeysNeeded.Value.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length != 0 && !instance.GetGlobalKey(text))
				{
					return false;
				}
			}
			return true;
		}

		private void LateUpdate()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextRefresh)
			{
				return;
			}
			_nextRefresh = Time.unscaledTime + 0.2f;
			ParticleMist instance = ParticleMist.instance;
			ParticleSystem val = (((Object)(object)instance != (Object)null) ? ((Component)instance).GetComponent<ParticleSystem>() : null);
			if (val != _mistParticles)
			{
				RestoreEmission();
				_mistParticles = val;
				if ((Object)(object)val != (Object)null)
				{
					EmissionModule emission = val.emission;
					_originalEmission = ((EmissionModule)(ref emission)).enabled;
				}
			}
			if (!((Object)(object)_mistParticles == (Object)null))
			{
				bool flag = ShouldClear();
				if (flag != _suppressed)
				{
					EmissionModule emission2 = _mistParticles.emission;
					((EmissionModule)(ref emission2)).enabled = !flag && _originalEmission;
					_suppressed = flag;
				}
				if (flag)
				{
					_mistParticles.Clear(true);
				}
			}
		}

		private void RestoreEmission()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_mistParticles != (Object)null && _suppressed)
			{
				EmissionModule emission = _mistParticles.emission;
				((EmissionModule)(ref emission)).enabled = _originalEmission;
			}
			_mistParticles = null;
			_suppressed = false;
		}

		private void OnDestroy()
		{
			RestoreEmission();
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(ParticleMist), "Update")]
	internal static class ParticleMistUpdatePatch
	{
		private static bool Prefix(ParticleMist __instance)
		{
			if (!DadsMistClearPlugin.ShouldClear())
			{
				return true;
			}
			ParticleSystem component = ((Component)__instance).GetComponent<ParticleSystem>();
			if (component != null)
			{
				component.Clear(true);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ParticleMist), "IsInMist")]
	internal static class ParticleMistDetectionPatch
	{
		private static bool Prefix(ref bool __result)
		{
			if (!DadsMistClearPlugin.ShouldClear())
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(ParticleMist), "IsMistBlocked")]
	internal static class ParticleMistBlockingPatch
	{
		private static bool Prefix(ref bool __result)
		{
			if (!DadsMistClearPlugin.ShouldClear())
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(MistEmitter), "Update")]
	internal static class MistEmitterUpdatePatch
	{
		private static bool Prefix(MistEmitter __instance)
		{
			if (!DadsMistClearPlugin.ShouldClear())
			{
				return true;
			}
			if ((Object)(object)__instance.m_psystem != (Object)null)
			{
				__instance.m_psystem.Clear(true);
			}
			return false;
		}
	}
}