Decompiled source of SimpleTides v1.0.1

SimpleTides.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Crest;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SimpleTides")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SimpleTides")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("939d240e-2f8e-43f9-a51d-4eba9938b034")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
internal sealed class ConfigurationManagerAttributes
{
	public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);

	public bool? ShowRangeAsPercent;

	public Action<ConfigEntryBase> CustomDrawer;

	public CustomHotkeyDrawerFunc CustomHotkeyDrawer;

	public bool? Browsable;

	public string Category;

	public object DefaultValue;

	public bool? HideDefaultButton;

	public bool? HideSettingName;

	public string Description;

	public string DispName;

	public int? Order;

	public bool? ReadOnly;

	public bool? IsAdvanced;

	public Func<object, string> ObjToStr;

	public Func<string, object> StrToObj;
}
namespace SimpleTides;

internal class Dictionaries
{
	public static Dictionary<int, float> islandOffsets = new Dictionary<int, float>
	{
		{ 8, -0.5f },
		{ 15, 0.25f },
		{ 20, -0.5f },
		{ 26, -0.42f }
	};
}
internal class RegionList
{
	internal ConfigEntry<float> alankh;

	internal ConfigEntry<float> aestrin;

	internal ConfigEntry<float> emerald;

	internal ConfigEntry<float> firefish;

	internal ConfigEntry<float> chronos;
}
[BepInPlugin("com.nandbrew.simpletides", "Simple Tides", "1.0.1")]
internal class Main : BaseUnityPlugin
{
	public const string GUID = "com.nandbrew.simpletides";

	public const string NAME = "Simple Tides";

	public const string VERSION = "1.0.1";

	internal static Main instance;

	internal static ManualLogSource logSource;

	internal static ConfigEntry<bool> solarTides;

	internal static ConfigEntry<bool> antipode;

	internal static RegionList regionTides = new RegionList();

	internal static RegionList regionOffsets = new RegionList();

	private void Awake()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Expected O, but got Unknown
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Expected O, but got Unknown
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Expected O, but got Unknown
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Expected O, but got Unknown
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Expected O, but got Unknown
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Expected O, but got Unknown
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Expected O, but got Unknown
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Expected O, but got Unknown
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Expected O, but got Unknown
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Expected O, but got Unknown
		instance = this;
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.nandbrew.simpletides");
		solarTides = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Solar tides", false, new ConfigDescription("Sun affects tides (40% as much as moon)", (AcceptableValueBase)null, Array.Empty<object>()));
		antipode = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Antipodal tides", true, new ConfigDescription("Two high tides per day (off: one per day)", (AcceptableValueBase)null, Array.Empty<object>()));
		regionTides.alankh = ((BaseUnityPlugin)this).Config.Bind<float>("Regional tides", "Al Ankh", 2f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionTides.aestrin = ((BaseUnityPlugin)this).Config.Bind<float>("Regional tides", "Aestrin", 1.8f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionTides.emerald = ((BaseUnityPlugin)this).Config.Bind<float>("Regional tides", "Emerald", 1.4f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionTides.firefish = ((BaseUnityPlugin)this).Config.Bind<float>("Regional tides", "Fire Fish", 1.3f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionTides.chronos = ((BaseUnityPlugin)this).Config.Bind<float>("Regional tides", "Chronos", 4f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionOffsets.alankh = ((BaseUnityPlugin)this).Config.Bind<float>("Regional offsets", "Al Ankh", 0.5f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionOffsets.aestrin = ((BaseUnityPlugin)this).Config.Bind<float>("Regional offsets", "Aestrin", 0.35f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionOffsets.emerald = ((BaseUnityPlugin)this).Config.Bind<float>("Regional offsets", "Emerald", 0.45f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionOffsets.firefish = ((BaseUnityPlugin)this).Config.Bind<float>("Regional offsets", "Fire Fish", 0.4f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
		regionOffsets.chronos = ((BaseUnityPlugin)this).Config.Bind<float>("Regional offsets", "Chronos", 0.95f, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
		{
			new ConfigurationManagerAttributes
			{
				IsAdvanced = true
			}
		}));
	}

	private void FixedUpdate()
	{
		Tides.OnFixedUpdate();
	}
}
internal class Patches
{
	[HarmonyPatch(typeof(RegionBlender))]
	private static class RegionBlenderPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch(Region ___currentTargetRegion, Region ___initialRegion)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Tides.ocean = RefsDirectory.instance.oceanRenderer;
			Tides.defaultSeaLevel = ((Component)RefsDirectory.instance.oceanRenderer).transform.position.y;
			Tides.currentRegion = ___currentTargetRegion;
			Tides.magnitude = Tides.GetRegionalTide(___currentTargetRegion);
		}

		[HarmonyPatch("UpdateBlend")]
		[HarmonyPostfix]
		public static void UpdateBlendPatch(Region ___currentTargetRegion, Transform ___player)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			float num = Vector3.Distance(___player.position, ((Component)___currentTargetRegion).transform.position);
			float num2 = Mathf.InverseLerp(45000f, 43000f, num);
			Tides.magnitude = Mathf.Lerp(Tides.magnitude, Tides.GetRegionalTide(___currentTargetRegion), num2);
			Tides.offset = Mathf.Lerp(Tides.offset, Tides.GetRegionalOffset(___currentTargetRegion), num2);
		}
	}

	[HarmonyPatch(typeof(IslandHorizon))]
	private static class IslandHorizonPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("SetHeight")]
		public static void IslandSetHeightPatch(int ___islandIndex, ref float y)
		{
			if (Dictionaries.islandOffsets.TryGetValue(___islandIndex, out var value))
			{
				y -= value;
			}
		}
	}
}
public static class Tides
{
	public static OceanRenderer ocean;

	public static float defaultSeaLevel;

	public static Region currentRegion;

	public static float magnitude;

	public static float offset;

	public static float SetTide()
	{
		int num = 12;
		float num2 = 2f;
		double num3 = 0.0;
		float num4 = 1f;
		if (Main.antipode.Value)
		{
			num = 6;
			num2 = 4f;
		}
		if (Main.solarTides.Value)
		{
			num3 = Math.Cos((double)Sun.sun.localTime / ((double)num / Math.PI) + (double)(num2 / 2f) * Math.PI) * 0.4000000059604645;
			num4 = 0.71428f;
		}
		double num5 = Math.Cos((double)Sun.sun.localTime / ((double)num / Math.PI) - (double)Moon.instance.currentPhase * ((double)num2 * Math.PI));
		return (float)((num3 + num5) * (double)(num4 * magnitude / 2f) - (double)(magnitude / 2f - offset));
	}

	public static void OnFixedUpdate()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ocean != (Object)null)
		{
			((Component)ocean).transform.position = new Vector3(((Component)ocean).transform.position.x, defaultSeaLevel + SetTide(), ((Component)ocean).transform.position.z);
		}
	}

	public static void OnChange()
	{
		magnitude = GetRegionalTide(currentRegion);
		offset = GetRegionalOffset(currentRegion);
	}

	public static float GetRegionalTide(Region region)
	{
		if (((Object)region).name.Contains("ankh"))
		{
			return Main.regionTides.alankh.Value;
		}
		if (((Object)region).name.Contains("Medi"))
		{
			if (((Object)region).name.Contains("East"))
			{
				return Main.regionTides.chronos.Value;
			}
			return Main.regionTides.aestrin.Value;
		}
		if (((Object)region).name.Contains("Emerald"))
		{
			if (((Object)region).name.Contains("Lagoon"))
			{
				return Main.regionTides.firefish.Value;
			}
			return Main.regionTides.emerald.Value;
		}
		return 1f;
	}

	public static float GetRegionalOffset(Region region)
	{
		if (((Object)region).name.Contains("ankh"))
		{
			return Main.regionOffsets.alankh.Value;
		}
		if (((Object)region).name.Contains("Medi"))
		{
			if (((Object)region).name.Contains("East"))
			{
				return Main.regionOffsets.chronos.Value;
			}
			return Main.regionOffsets.aestrin.Value;
		}
		if (((Object)region).name.Contains("Emerald"))
		{
			if (((Object)region).name.Contains("Lagoon"))
			{
				return Main.regionOffsets.firefish.Value;
			}
			return Main.regionOffsets.emerald.Value;
		}
		return 1f;
	}
}