Decompiled source of Teleport Instantly Updates Weather And Removes Wet Debuff v1.0.2

TeleportWeatherWetAndColdFixes.dll

Decompiled 7 months ago
using System.Diagnostics;
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;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TeleportWeatherWetAndColdFixes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TeleportWeatherWetAndColdFixes")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cd7576d0-6317-4e49-be67-acdce7744c7d")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace TeleportWeatherWetAndColdFixes;

[HarmonyPatch(typeof(Player), "UpdateTeleport")]
internal static class PatchPlayer
{
	public static void Prefix(Player __instance, ref bool __state)
	{
		__state = __instance.m_teleporting;
		if (TeleportWeatherWetAndColdFixesPlugin.TeleportChange.Value != 0 && __instance.m_distantTeleport && __instance.m_teleporting && __instance.m_teleportTimer == 0f)
		{
			TeleportHelper.RemoveAndBackupTransition(ref EnvMan.instance.m_wetTransitionDuration, ref TeleportHelper.oldWetTransitionDuration);
			TeleportHelper.RemoveAndBackupTransition(ref EnvMan.instance.m_windTransitionDuration, ref TeleportHelper.oldWindTransitionDuration);
			TeleportHelper.RemoveAndBackupTransition(ref EnvMan.instance.m_transitionDuration, ref TeleportHelper.oldTransitionDuration);
		}
	}

	public static void Postfix(Player __instance, ref bool __state)
	{
		if (__instance.m_distantTeleport && __state && !__instance.m_teleporting)
		{
			if (TeleportWeatherWetAndColdFixesPlugin.TeleportChange.Value != 0)
			{
				TeleportHelper.ResetTransition(ref EnvMan.instance.m_wetTransitionDuration, ref TeleportHelper.oldWetTransitionDuration, 15f);
				TeleportHelper.ResetTransition(ref EnvMan.instance.m_windTransitionDuration, ref TeleportHelper.oldWindTransitionDuration, 10f);
				TeleportHelper.ResetTransition(ref EnvMan.instance.m_transitionDuration, ref TeleportHelper.oldTransitionDuration, 10f);
			}
			if (TeleportWeatherWetAndColdFixesPlugin.TeleportChange.Value == TeleportChange.InstantlyUpdateWeatherAndClearWetAndColdDebuff)
			{
				((Character)__instance).m_seman.RemoveStatusEffect(Player.s_statusEffectWet, false);
				((Character)__instance).m_seman.RemoveStatusEffect(Player.s_statusEffectCold, false);
				((Character)__instance).m_seman.RemoveStatusEffect(Player.s_statusEffectFreezing, false);
			}
		}
	}
}
public enum TeleportChange
{
	Disabled,
	InstantlyUpdateWeather,
	InstantlyUpdateWeatherAndClearWetAndColdDebuff
}
internal static class TeleportHelper
{
	internal static float oldWetTransitionDuration = float.Epsilon;

	internal static float oldTransitionDuration = float.Epsilon;

	internal static float oldWindTransitionDuration = float.Epsilon;

	internal static void ResetTransition(ref float transitionDuration, ref float preTeleportDuration, float defaultValue)
	{
		if (transitionDuration == float.Epsilon)
		{
			if (preTeleportDuration != float.Epsilon)
			{
				transitionDuration = preTeleportDuration;
				preTeleportDuration = float.Epsilon;
			}
			else
			{
				transitionDuration = defaultValue;
			}
		}
	}

	internal static void RemoveAndBackupTransition(ref float transitionDuration, ref float backup)
	{
		if (transitionDuration != float.Epsilon)
		{
			backup = transitionDuration;
			transitionDuration = float.Epsilon;
		}
	}
}
[BepInIncompatibility("goldenrevolver.CapeAndTorchResistanceChanges")]
[BepInPlugin("goldenrevolver.TeleportWeatherWetAndColdFixes", "Teleport Instantly Updates Weather - Removes Wet Debuff", "1.0.2")]
public class TeleportWeatherWetAndColdFixesPlugin : BaseUnityPlugin
{
	public const string NAME = "Teleport Instantly Updates Weather - Removes Wet Debuff";

	public const string VERSION = "1.0.2";

	public static ConfigEntry<TeleportChange> TeleportChange;

	protected void Awake()
	{
		LoadConfig();
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
	}

	private void LoadConfig()
	{
		string text = "General";
		TeleportChange = ((BaseUnityPlugin)this).Config.Bind<TeleportChange>(text, "TeleportChange", TeleportWeatherWetAndColdFixes.TeleportChange.InstantlyUpdateWeatherAndClearWetAndColdDebuff, string.Empty);
	}
}