Decompiled source of NoOceanFog v1.1.0

plugins\TeflonTed.NoOceanFog.dll

Decompiled 20 hours ago
using System;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("TeflonTed.NoOceanFog")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Teflon Ted's No Ocean Fog — disables Misty whiteout fog weather")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+a84409f38cff9312b3e2ebc25e47b06ad340a0e8")]
[assembly: AssemblyProduct("TeflonTed.NoOceanFog")]
[assembly: AssemblyTitle("TeflonTed.NoOceanFog")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 TeflonTed.NoOceanFog
{
	[BepInPlugin("com.teflonted.valheim.nooceanfog", "Teflon Ted's No Ocean Fog", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.teflonted.valheim.nooceanfog";

		public const string PluginName = "Teflon Ted's No Ocean Fog";

		public const string PluginVersion = "1.1.0";

		private void Awake()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.teflonted.valheim.nooceanfog");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Teflon Ted's No Ocean Fog 1.1.0 loaded");
		}
	}
	internal static class MistyWeather
	{
		internal static bool IsMistyName(string name)
		{
			if (!string.IsNullOrEmpty(name))
			{
				return name.IndexOf("Misty", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}

		internal static bool IsMisty(EnvEntry entry)
		{
			if (entry == null)
			{
				return false;
			}
			if (IsMistyName(entry.m_environment))
			{
				return true;
			}
			if (entry.m_env != null)
			{
				return IsMistyName(entry.m_env.m_name);
			}
			return false;
		}

		internal static int PurgeAll(EnvMan envMan)
		{
			if (envMan?.m_biomes == null)
			{
				return 0;
			}
			int num = 0;
			foreach (BiomeEnvSetup biome in envMan.m_biomes)
			{
				if (biome?.m_environments != null)
				{
					num += biome.m_environments.RemoveAll(IsMisty);
				}
			}
			return num;
		}

		internal static void StripList(List<EnvEntry> entries)
		{
			if (entries != null && entries.Count != 0)
			{
				entries.RemoveAll(IsMisty);
			}
		}

		internal static void LogRemoved(int removed, string where)
		{
			if (removed > 0)
			{
				Logger.CreateLogSource("Teflon Ted's No Ocean Fog").LogInfo((object)string.Format("Removed {0} Misty entr{1} ({2})", removed, (removed == 1) ? "y" : "ies", where));
			}
		}
	}
	[HarmonyPatch(typeof(EnvMan), "Awake")]
	internal static class EnvMan_Awake_Patch
	{
		private static void Postfix(EnvMan __instance)
		{
			MistyWeather.LogRemoved(MistyWeather.PurgeAll(__instance), "Awake");
		}
	}
	[HarmonyPatch(typeof(EnvMan), "AppendBiomeSetup")]
	internal static class EnvMan_AppendBiomeSetup_Patch
	{
		private static void Postfix(EnvMan __instance, BiomeEnvSetup biomeEnv)
		{
			if (biomeEnv != null)
			{
				MistyWeather.StripList(biomeEnv.m_environments);
			}
			MistyWeather.LogRemoved(MistyWeather.PurgeAll(__instance), "AppendBiomeSetup");
		}
	}
	[HarmonyPatch(typeof(EnvMan), "GetAvailableEnvironments")]
	internal static class EnvMan_GetAvailableEnvironments_Patch
	{
		private static void Postfix(List<EnvEntry> __result)
		{
			MistyWeather.StripList(__result);
		}
	}
	[HarmonyPatch(typeof(EnvMan), "UpdateEnvironment")]
	internal static class EnvMan_UpdateEnvironment_Patch
	{
		private static void Postfix(EnvMan __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				EnvSetup currentEnvironment = __instance.GetCurrentEnvironment();
				if (currentEnvironment != null && MistyWeather.IsMistyName(currentEnvironment.m_name))
				{
					__instance.QueueEnvironment("Clear");
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}