Decompiled source of AshlandsWaterFix v1.0.0

AshlandsWaterFix.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("AshlandsWaterFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c273eb9a08bef17e6e5fcfa942daa82a3945c132")]
[assembly: AssemblyProduct("AshlandsWaterFix")]
[assembly: AssemblyTitle("AshlandsWaterFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AshlandsWaterFix;

[BepInPlugin("com.igentuman.valheim.ashlandswaterfix", "Ashlands Water Cooldown Fix", "1.0.0")]
public sealed class Plugin : BaseUnityPlugin
{
	public const string Guid = "com.igentuman.valheim.ashlandswaterfix";

	public const string Name = "Ashlands Water Cooldown Fix";

	public const string Version = "1.0.0";

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		_harmony = new Harmony("com.igentuman.valheim.ashlandswaterfix");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Ashlands ocean heat cooldown and overlay fixes enabled.");
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
[HarmonyPatch(typeof(Character), "UpdateAshlandsWater")]
internal static class CharacterUpdateAshlandsWaterPatch
{
	private const float CooldownSeconds = 2f;

	private static readonly FieldRef<Character, float> AshlandsOceanHeatLevel = AccessTools.FieldRefAccess<Character, float>("m_ashlandsOceanHeatLevel");

	[HarmonyPostfix]
	private static void CoolOceanHeat(Character __instance, float dt)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.m_tolerateFire || !__instance.InWater() || !(WorldGenerator.GetAshlandsOceanGradient(((Component)__instance).transform.position) > 0f))
		{
			ref float reference = ref AshlandsOceanHeatLevel.Invoke(__instance);
			if (!(reference <= 0f))
			{
				float num = __instance.m_heatLevelFirstDamageThreshold / 2f;
				reference = Mathf.MoveTowards(reference, 0f, num * dt);
			}
		}
	}
}
[HarmonyPatch(typeof(Character), "UpdateHeatEffects")]
internal static class CharacterUpdateHeatEffectsPatch
{
	private static readonly FieldRef<Character, float> LavaHeatLevel = AccessTools.FieldRefAccess<Character, float>("m_lavaHeatLevel");

	private static readonly FieldRef<Character, float> AshlandsOceanHeatLevel = AccessTools.FieldRefAccess<Character, float>("m_ashlandsOceanHeatLevel");

	[HarmonyPostfix]
	private static void RestoreOceanHeatOverlay(Character __instance)
	{
		if (!((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && !((Object)(object)GameCamera.instance == (Object)null) && !((Object)(object)GameCamera.instance.m_heatDistortImageEffect == (Object)null))
		{
			float num = Mathf.Max(LavaHeatLevel.Invoke(__instance), AshlandsOceanHeatLevel.Invoke(__instance));
			((Behaviour)GameCamera.instance.m_heatDistortImageEffect).enabled = num > 0f;
			GameCamera.instance.m_heatDistortImageEffect.m_intensity = num;
		}
	}
}