Decompiled source of Calm Seas v1.1.0

BepInEx/plugins/CalmSeas.dll

Decompiled a week 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 Jotunn;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CalmSeas")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+b729fcdc1c08bf36b936be388b244a636c6a48ac")]
[assembly: AssemblyProduct("CalmSeas")]
[assembly: AssemblyTitle("CalmSeas")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace CalmSeas;

[BepInPlugin("com.mous.calmseas", "Calm Seas", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class CalmSeasPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "com.mous.calmseas";

	public const string PluginName = "Calm Seas";

	public const string PluginVersion = "1.1.0";

	private static ConfigEntry<float> _landScale;

	private static ConfigEntry<float> _seaScale;

	private static ConfigEntry<float> _openSeaDepth;

	internal static float Scale = 1f;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Expected O, but got Unknown
		ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		};
		AcceptableValueRange<float> val2 = new AcceptableValueRange<float>(0f, 5f);
		_landScale = ((BaseUnityPlugin)this).Config.Bind<float>("Waves", "LandWaveScale", 0.3f, new ConfigDescription("Wave height multiplier while you are on land or in shallow water. 1 = vanilla, 0 = flat.", (AcceptableValueBase)(object)val2, new object[1] { val }));
		_seaScale = ((BaseUnityPlugin)this).Config.Bind<float>("Waves", "SeaWaveScale", 0.7f, new ConfigDescription("Wave height multiplier while you are over open sea. 1 = vanilla, 0 = flat.", (AcceptableValueBase)(object)val2, new object[1] { val }));
		_openSeaDepth = ((BaseUnityPlugin)this).Config.Bind<float>("Waves", "OpenSeaDepth", 20f, new ConfigDescription("Water depth (m) under you at which SeaWaveScale fully applies. Between the shore and this depth the two scales blend.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 200f), new object[1] { val }));
		_harmony = new Harmony("com.mous.calmseas");
		_harmony.PatchAll();
		Logger.LogInfo((object)"Calm Seas 1.1.0 loaded");
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	private void Update()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		float num = default(float);
		Scale = ScaleFor((Object.op_Implicit((Object)(object)localPlayer) && Object.op_Implicit((Object)(object)ZoneSystem.instance) && ZoneSystem.instance.GetGroundHeight(((Component)localPlayer).transform.position, ref num)) ? (ZoneSystem.instance.m_waterLevel - num) : float.MaxValue, _landScale.Value, _seaScale.Value, _openSeaDepth.Value);
	}

	internal static float ScaleFor(float depth, float land, float sea, float openSeaDepth)
	{
		return Mathf.Lerp(land, sea, Mathf.Clamp01(depth / openSeaDepth));
	}

	internal static Vector4 ScaleWind(Vector4 wind, float scale)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		return new Vector4(wind.x, wind.y, wind.z, wind.w * scale);
	}
}
[HarmonyPatch(typeof(WaterVolume), "CalcWave", new Type[]
{
	typeof(Vector3),
	typeof(float),
	typeof(float),
	typeof(float),
	typeof(float)
})]
internal static class CalcWavePatch
{
	private static void Postfix(ref float __result)
	{
		__result *= CalmSeasPlugin.Scale;
	}
}
[HarmonyPatch(typeof(EnvMan), "UpdateWindTransition")]
internal static class WindShaderPatch
{
	private static readonly int GlobalWind1 = Shader.PropertyToID("_GlobalWind1");

	private static readonly int GlobalWind2 = Shader.PropertyToID("_GlobalWind2");

	private static void Postfix(EnvMan __instance)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		Vector4 wind = default(Vector4);
		Vector4 wind2 = default(Vector4);
		float num = default(float);
		__instance.GetWindData(ref wind, ref wind2, ref num);
		Shader.SetGlobalVector(GlobalWind1, CalmSeasPlugin.ScaleWind(wind, CalmSeasPlugin.Scale));
		Shader.SetGlobalVector(GlobalWind2, CalmSeasPlugin.ScaleWind(wind2, CalmSeasPlugin.Scale));
	}
}