using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Tidal")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Tidal")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1c50cc1f-aa9f-4e4d-9805-257cf3966daa")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("sfpdecresc.TidalMod", "Tidal", "2.0.0")]
[HarmonyPatch]
public class TidalMod : BaseUnityPlugin
{
private const string modGUID = "sfpdecresc.TidalMod";
private const string modName = "Tidal";
private const string modVersion = "2.0.0";
private readonly Harmony harmony = new Harmony("sfpdecresc.TidalMod");
private const int companyId = 3;
private const int rendId = 5;
private const int dineId = 6;
private static readonly float[] maximumWaterLevel = new float[2] { 1f, 1f };
private static readonly float[] centerWaterLevel = new float[2] { -7f, -15f };
private static readonly float[] minimumWaterLevel = new float[2] { -15f, -31f };
private const float shipWaterLevel = -7f;
private const float waterLevelCompany = -7f;
private static readonly float[,] amplitudeArray = new float[2, 2]
{
{ 8f, 1f },
{ 16f, 2f }
};
private static readonly float[,] frequencyArray = new float[2, 2]
{
{ 0.1f, 0.2f },
{ 0.05f, 0.1f }
};
private static FloodWeather floodWeather = null;
private static bool inOrbit = true;
private static float seed = 0f;
private void Awake()
{
harmony.PatchAll();
}
[HarmonyPatch(typeof(StartOfRound))]
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void Update(ref StartOfRound __instance)
{
inOrbit = __instance.inShipPhase;
seed = __instance.randomMapSeed;
}
[HarmonyPatch(typeof(TimeOfDay))]
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void Update(ref TimeOfDay __instance)
{
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)floodWeather == (Object)null)
{
FloodWeather val = Object.FindObjectOfType<FloodWeather>(true);
if ((Object)(object)val == (Object)null)
{
return;
}
floodWeather = Object.Instantiate<FloodWeather>(val, ((Component)val).transform.parent);
((Component)floodWeather).gameObject.SetActive(true);
}
float num = __instance.globalTime / __instance.globalTimeSpeedMultiplier;
SelectableLevel currentLevel = __instance.currentLevel;
float num2;
if (inOrbit)
{
num2 = -7f;
}
else if (currentLevel.levelID == 3)
{
num2 = -7f;
}
else
{
int num3 = ((currentLevel.levelID == 5 || currentLevel.levelID == 6) ? 1 : 0);
num2 = centerWaterLevel[num3];
int i = 0;
for (int length = frequencyArray.GetLength(num3); i < length; i++)
{
float num4 = Mathf.PerlinNoise1D(seed * (float)i) * ((float)Math.PI * 2f);
float num5 = frequencyArray[num3, i] * (0.9f + Mathf.PerlinNoise1D(seed * 1f) * 0.20000005f);
float num6 = amplitudeArray[num3, i] * (0.9f + Mathf.PerlinNoise1D(seed * 2f) * 0.20000005f);
float num7 = Mathf.Sin(num * num5 + num4) * num6;
num2 += num7;
}
num2 = Mathf.Clamp(num2, minimumWaterLevel[num3], maximumWaterLevel[num3]);
}
((Component)floodWeather).gameObject.transform.position = new Vector3(0f, num2, 0f);
}
}