Decompiled source of BetterDiving v1.1.1

MainStreetGaming-BetterDiving\BetterDiving.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Valheim BetterDiving")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Main Street Gaming")]
[assembly: AssemblyProduct("BetterDiving")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
namespace BetterDiving
{
	[BepInPlugin("MainStreetGaming.BetterDiving", "BetterDiving", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInIncompatibility("ch.easy.develope.vh.diving.mod")]
	[BepInIncompatibility("blacks7ar.VikingsDoSwim")]
	[BepInIncompatibility("projjm.improvedswimming")]
	internal class BetterDiving : BaseUnityPlugin
	{
		public const string PluginGUID = "MainStreetGaming.BetterDiving";

		public const string PluginName = "BetterDiving";

		public const string PluginVersion = "1.1.0";

		public static Harmony harmony;

		public static ConfigEntry<string> configGreeting;

		public static ConfigEntry<bool> configDisplayGreeting;

		public static ConfigEntry<bool> showYouCanBreatheMsg;

		public static ConfigEntry<bool> showDivingMsg;

		public static ConfigEntry<string> divingMsg;

		public static ConfigEntry<string> divingCancelledMsg;

		public static ConfigEntry<bool> showSurfacingMsg;

		public static ConfigEntry<string> surfacingMsg;

		public static ConfigEntry<bool> allowRestInWater;

		public static ConfigEntry<bool> owBIPos;

		public static ConfigEntry<float> owBIPosX;

		public static ConfigEntry<float> owBIPosY;

		public static ConfigEntry<float> breatheDrain;

		public static ConfigEntry<bool> allowFastSwimming;

		public static ConfigEntry<float> c_swimStaminaDrainMinSkill;

		public static ConfigEntry<float> c_swimStaminaDrainMaxSkill;

		public static ConfigEntry<bool> ow_staminaRestoreValue;

		public static ConfigEntry<float> ow_staminaRestorPerTick;

		public static ConfigEntry<float> ow_color_brightness_factor;

		public static ConfigEntry<float> ow_fogdensity_factor;

		public static ConfigEntry<float> ow_Min_fogdensity;

		public static ConfigEntry<float> ow_Max_fogdensity;

		public static ConfigEntry<bool> doDebug;

		public static float loc_m_m_maxDistance = 0f;

		public static float loc_m_diveAaxis = 0f;

		public static float loc_cam_pos_y = 0f;

		public static float char_swim_depth = 0f;

		public static bool render_settings_updated_camera = true;

		public static bool set_force_env = false;

		public static float minwaterdist = 0f;

		public static Material mai_water_mat = null;

		public static float water_level_camera = 30f;

		public static float water_level_player = 30f;

		public static float m_swimStaminaDrainMinSkill = 0f;

		public static float m_swimStaminaDrainMaxSkill = 0f;

		public static bool dive_timer_is_running = false;

		public static float breathBarRemoveDelay = 2f;

		public static float breathDelayTimer;

		public static float highestOxygen = 1f;

		public static bool has_created_breathe_bar = false;

		public static GameObject loc_breath_bar;

		public static GameObject loc_depleted_breath;

		public static GameObject loc_breath_bar_bg;

		public static GameObject loc_breathe_overlay;

		public static Sprite breath_prog_sprite;

		public static Texture2D breath_prog_tex;

		public static Sprite breath_bg_sprite;

		public static Texture2D breath_bg_tex;

		public static Sprite breath_overlay_sprite;

		public static Texture2D breath_overlay_tex;

		public static Shader water_shader;

		public static Texture2D water_texture;

		public static Material water_mat;

		public static Material[] water_volum_list;

		public static string EnvName = "";

		public static SkillType DivingSkillType = (SkillType)0;

		public static Texture2D dive_texture;

		public static Sprite DivingSprite;

		public static float m_diveSkillImproveTimer = 0f;

		public static float m_minDiveSkillImprover = 0f;

		public static float baseSwimSpeed = 2f;

		public static float fastSwimSpeedMultiplier = 0.01f;

		public static float swimStaminaDrainRate = 10f;

		public static float fastSwimSpeed;

		public static float fastSwimStamDrain;

		public static string graphicsDeviceType;

		public IEnumerator Start()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			DebugLog("Better Diving Mod: Ienumerator start!");
			AssetBundle val = AssetUtils.LoadAssetBundleFromResources("watermat.assets");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"load_watermat_assets_failed");
				return null;
			}
			AssetBundle val2 = AssetUtils.LoadAssetBundleFromResources("betterdiving.assets");
			if ((Object)(object)val2 == (Object)null)
			{
				Debug.LogError((object)"load_betterdiving_assets_failed");
				return null;
			}
			water_mat = val.LoadAsset<Material>("WaterMat");
			dive_texture = val.LoadAsset<Texture2D>("vhdm_dive_icon_1");
			breath_prog_tex = val2.LoadAsset<Texture2D>("BreathBar.png");
			breath_prog_sprite = Sprite.Create(breath_prog_tex, new Rect(0f, 0f, (float)((Texture)breath_prog_tex).width, (float)((Texture)breath_prog_tex).height), Vector2.zero);
			breath_bg_tex = val2.LoadAsset<Texture2D>("BreathBar_BG.png");
			breath_bg_sprite = Sprite.Create(breath_bg_tex, new Rect(0f, 0f, (float)((Texture)breath_bg_tex).width, (float)((Texture)breath_bg_tex).height), Vector2.zero);
			breath_overlay_tex = val2.LoadAsset<Texture2D>("BreathBarOverlay.png");
			breath_overlay_sprite = Sprite.Create(breath_overlay_tex, new Rect(0f, 0f, (float)((Texture)breath_overlay_tex).width, (float)((Texture)breath_overlay_tex).height), Vector2.zero);
			DivingSprite = Sprite.Create(dive_texture, new Rect(0f, 0f, (float)((Texture)dive_texture).width, (float)((Texture)dive_texture).height), Vector2.zero);
			DivingSkillType = SkillManager.Instance.AddSkill(new SkillConfig
			{
				Identifier = "MainStreetGaming.BetterDiving.divingduration.1",
				Name = "Diving",
				Description = "Dive duration.",
				IncreaseStep = 0.25f,
				Icon = DivingSprite
			});
			val.Unload(false);
			return null;
		}

		private void Awake()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			CreateConfigValues();
			if (configDisplayGreeting.Value)
			{
				Debug.Log((object)("BetterDiving: " + configGreeting.Value));
			}
			GraphicsDeviceType val = SystemInfo.graphicsDeviceType;
			graphicsDeviceType = ((object)(GraphicsDeviceType)(ref val)).ToString();
		}

		private void Update()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)loc_breath_bar != (Object)null)
			{
				if (owBIPos.Value)
				{
					loc_breath_bar_bg.transform.position = new Vector3(owBIPosX.Value, owBIPosY.Value, ((Component)Hud.instance).transform.position.y);
				}
				if (owBIPos.Value)
				{
					loc_depleted_breath.transform.position = new Vector3(owBIPosX.Value, owBIPosY.Value, ((Component)Hud.instance).transform.position.y);
				}
				if (owBIPos.Value)
				{
					loc_breath_bar.transform.position = new Vector3(owBIPosX.Value, owBIPosY.Value, ((Component)Hud.instance).transform.position.y);
				}
				if (owBIPos.Value)
				{
					loc_breathe_overlay.transform.position = new Vector3(owBIPosX.Value, owBIPosY.Value, ((Component)Hud.instance).transform.position.y);
				}
			}
		}

		private void CreateConfigValues()
		{
			//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_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Expected O, but got Unknown
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Expected O, but got Unknown
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Expected O, but got Unknown
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Expected O, but got Unknown
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Expected O, but got Unknown
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Expected O, but got Unknown
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Expected O, but got Unknown
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Expected O, but got Unknown
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Expected O, but got Unknown
			ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
			doDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "doDebug", false, "Debug mode on or off");
			configGreeting = ((BaseUnityPlugin)this).Config.Bind<string>("Local config", "GreetingText", "Hello, thanks for using the Better Diving Mod by Main Street Gaming!", "");
			configDisplayGreeting = ((BaseUnityPlugin)this).Config.Bind<bool>("Local config", "DisplayGreeting", true, "Whether or not to show the greeting text");
			showYouCanBreatheMsg = ((BaseUnityPlugin)this).Config.Bind<bool>("Local config", "showYouCanBreatheMsg", false, "Whether or not to show the You Can Breathe message. Disable if the surfacing message is enabled.");
			showDivingMsg = ((BaseUnityPlugin)this).Config.Bind<bool>("Local config", "showDivingMsg", true, "Whether or not to show messages when triggering/cancelling diving");
			divingMsg = ((BaseUnityPlugin)this).Config.Bind<string>("Local config", "Diving message", "You prepare to dive", (ConfigDescription)null);
			divingCancelledMsg = ((BaseUnityPlugin)this).Config.Bind<string>("Local config", "Diving cancelled message", "You remain on the surface", (ConfigDescription)null);
			showSurfacingMsg = ((BaseUnityPlugin)this).Config.Bind<bool>("Local config", "showSurfacingMsg", true, "Whether or not to show a message when surfacing");
			surfacingMsg = ((BaseUnityPlugin)this).Config.Bind<string>("Local config", "Surfacing message", "You have surfaced", (ConfigDescription)null);
			owBIPos = ((BaseUnityPlugin)this).Config.Bind<bool>("Local config", "owBIPos", false, "Override breathe indicator position");
			owBIPosX = ((BaseUnityPlugin)this).Config.Bind<float>("Local config", "owBIPosX", 30f, "Override breathe indicator position X");
			owBIPosY = ((BaseUnityPlugin)this).Config.Bind<float>("Local config", "owBIPosY", 150f, "Override breathe indicator position Y");
			allowRestInWater = ((BaseUnityPlugin)this).Config.Bind<bool>("Server config", "allowRestInWater", true, new ConfigDescription("Whether or not to allow stamina regen in water when able to breath and not moving", (AcceptableValueBase)null, new object[1] { val }));
			allowFastSwimming = (allowRestInWater = ((BaseUnityPlugin)this).Config.Bind<bool>("Server config", "allowFastSwimming", true, new ConfigDescription("Allow fast swimming when holding the Run button", (AcceptableValueBase)null, new object[1] { val })));
			breatheDrain = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "breatheDrain", 4f, new ConfigDescription("Breathe indicator reduction per tick", (AcceptableValueBase)null, new object[1] { val }));
			c_swimStaminaDrainMinSkill = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "c_swimStaminaDrainMinSkill", 0.7f, new ConfigDescription("Min stamina drain while diving", (AcceptableValueBase)null, new object[1] { val }));
			c_swimStaminaDrainMaxSkill = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "c_swimStaminaDrainMaxSkill", 0.8f, new ConfigDescription("Max stamina drain while diving", (AcceptableValueBase)null, new object[1] { val }));
			ow_staminaRestoreValue = ((BaseUnityPlugin)this).Config.Bind<bool>("Server config", "ow_staminaRestoreValue", false, new ConfigDescription("Overwrite stamina restore value per tick when take rest in water", (AcceptableValueBase)null, new object[1] { val }));
			ow_staminaRestorPerTick = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "ow_staminaRestorPerTick", 0.7f, new ConfigDescription("Stamina restore value per tick when take rest in water", (AcceptableValueBase)null, new object[1] { val }));
			ow_color_brightness_factor = ((BaseUnityPlugin)this).Config.Bind<float>("Server config - Water", "ow_color_brightness_factor", -0.0092f, new ConfigDescription("Reduce color brightness based on swimdepth (RGB)\n\nchar_swim_depth * ow_color_brightness_factor = correctionFactor.\n\nCorrection:\ncorrectionFactor *= -1;\nred -= red * correctionFactor;\ngreen -= green * correctionFactor;\nblue -= blue * correctionFactor;\n\now_color_brightness_factor must be a negative value", (AcceptableValueBase)null, new object[1] { val }));
			ow_fogdensity_factor = ((BaseUnityPlugin)this).Config.Bind<float>("Server config - Water", "ow_fogdensity_factor", 0.00092f, new ConfigDescription("Set fog density based on swimdepth\n\nCorrection:\nRenderSettings.fogDensity = RenderSettings.fogDensity + (char_swim_depth * ow_fogdensity_factor)", (AcceptableValueBase)null, new object[1] { val }));
			ow_Min_fogdensity = ((BaseUnityPlugin)this).Config.Bind<float>("Server config - Water", "ow_Min_fogdensity", 0.175f, new ConfigDescription("Set min fog density", (AcceptableValueBase)null, new object[1] { val }));
			ow_Max_fogdensity = ((BaseUnityPlugin)this).Config.Bind<float>("Server config - Water", "ow_Max_fogdensity", 2f, new ConfigDescription("Set max fog density", (AcceptableValueBase)null, new object[1] { val }));
		}

		public static bool IsEnvAllowed()
		{
			if (EnvName == "SunkenCrypt")
			{
				return false;
			}
			return true;
		}

		public static void DebugLog(string data)
		{
			if (doDebug.Value)
			{
				Debug.Log((object)("BetterDiving: " + data));
			}
		}
	}
}
namespace BetterDiving.Patches
{
	[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
	public class GameCamera_UpdateCamera
	{
		public static Color ChangeColorBrightness(Color color, float correctionFactor)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			float num = color.r;
			float num2 = color.g;
			float num3 = color.b;
			if (correctionFactor < 0f)
			{
				correctionFactor *= -1f;
				num -= num * correctionFactor;
				if (num < 0f)
				{
					num = 0f;
				}
				num2 -= num2 * correctionFactor;
				if (num2 < 0f)
				{
					num2 = 0f;
				}
				num3 -= num3 * correctionFactor;
				if (num3 < 0f)
				{
					num3 = 0f;
				}
			}
			return new Color(num, num2, num3, color.a);
		}

		[HarmonyPrefix]
		public static void Prefix(GameCamera __instance, Camera ___m_camera)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			if (BetterDiving.EnvName != EnvMan.instance.GetCurrentEnvironment().m_name)
			{
				BetterDiving.EnvName = EnvMan.instance.GetCurrentEnvironment().m_name;
			}
			if ((((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().is_diving || ((Character)Player.m_localPlayer).IsSwimming()) && !((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().isTakeRestInWater && BetterDiving.IsEnvAllowed())
			{
				__instance.m_minWaterDistance = -5000f;
			}
			else
			{
				__instance.m_minWaterDistance = 0.3f;
			}
			if (__instance.m_maxDistance != 3f && BetterDiving.loc_m_m_maxDistance == 0f)
			{
				BetterDiving.loc_m_m_maxDistance = __instance.m_maxDistance;
			}
			BetterDiving.loc_cam_pos_y = ((Component)___m_camera).gameObject.transform.position.y;
			if (((Component)___m_camera).gameObject.transform.position.y < BetterDiving.water_level_camera && (((Character)Player.m_localPlayer).IsSwimming() || ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().is_diving) && BetterDiving.IsEnvAllowed())
			{
				if (__instance.m_minWaterDistance != -5000f)
				{
					__instance.m_minWaterDistance = -5000f;
				}
				if (((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().is_diving)
				{
					__instance.m_maxDistance = 3f;
				}
				EnvSetup currentEnvironment = EnvMan.instance.GetCurrentEnvironment();
				Color color = ((!EnvMan.IsNight()) ? currentEnvironment.m_fogColorDay : currentEnvironment.m_fogColorNight);
				color.a = 1f;
				color = ChangeColorBrightness(color, BetterDiving.char_swim_depth * BetterDiving.ow_color_brightness_factor.Value);
				RenderSettings.fogColor = color;
				float num = RenderSettings.fogDensity + BetterDiving.char_swim_depth * BetterDiving.ow_fogdensity_factor.Value;
				if (num < BetterDiving.ow_Min_fogdensity.Value)
				{
					num = BetterDiving.ow_Min_fogdensity.Value;
				}
				if (num > BetterDiving.ow_Max_fogdensity.Value)
				{
					num = BetterDiving.ow_Max_fogdensity.Value;
				}
				RenderSettings.fogDensity = num;
				BetterDiving.render_settings_updated_camera = false;
				return;
			}
			if (((Component)___m_camera).gameObject.transform.position.y > BetterDiving.water_level_camera)
			{
				if (!BetterDiving.render_settings_updated_camera)
				{
					if (BetterDiving.loc_m_m_maxDistance != 0f)
					{
						__instance.m_maxDistance = BetterDiving.loc_m_m_maxDistance;
					}
					EnvMan.instance.SetForceEnvironment(EnvMan.instance.GetCurrentEnvironment().m_name);
					BetterDiving.render_settings_updated_camera = true;
					BetterDiving.set_force_env = true;
				}
				if (BetterDiving.set_force_env)
				{
					EnvMan.instance.SetForceEnvironment("");
					BetterDiving.set_force_env = false;
				}
			}
			if (!((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().is_diving && BetterDiving.loc_m_m_maxDistance != 0f)
			{
				__instance.m_maxDistance = BetterDiving.loc_m_m_maxDistance;
			}
			if (!((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().is_diving && BetterDiving.minwaterdist != 0f)
			{
				__instance.m_minWaterDistance = BetterDiving.minwaterdist;
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Awake")]
	public class Character_Awake
	{
		[HarmonyPrefix]
		public static void Prefix(Character __instance)
		{
			BetterDiving.DebugLog("---------------------Section Character Awake Start------------------------");
			BetterDiving.DebugLog("__instance.IsPlayer() -> " + __instance.IsPlayer());
			if (__instance.IsPlayer() && Object.op_Implicit((Object)(object)Player.m_localPlayer) && __instance == Player.m_localPlayer)
			{
				__instance.m_swimDepth = 1.6f;
				BetterDiving.DebugLog("__instance.IsPlayer() -> " + __instance.IsPlayer());
			}
			BetterDiving.DebugLog("----------------------Section Character Awake End-------------------------");
		}
	}
	[HarmonyPatch(typeof(Character), "OnDestroy")]
	public class Character_OnDestroy
	{
		[HarmonyPrefix]
		public static void Prefix(Character __instance)
		{
			if (__instance == Player.m_localPlayer && Object.op_Implicit((Object)(object)Player.m_localPlayer) && __instance.IsPlayer())
			{
				BetterDiving.has_created_breathe_bar = false;
				BetterDiving.dive_timer_is_running = false;
				BetterDiving.DebugLog("Better Diving Mod: OnDestroy Character...");
			}
		}
	}
	[HarmonyPatch(typeof(Character), "UpdateMotion")]
	public class Character_UpdateMovement
	{
		[HarmonyPrefix]
		public static void Prefix(Character __instance, ref float ___m_lastGroundTouch, ref float ___m_swimTimer)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (__instance != Player.m_localPlayer || !__instance.IsPlayer() || !BetterDiving.IsEnvAllowed() || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			if (__instance.m_swimDepth > 2.5f && Mathf.Max(0f, __instance.GetLiquidLevel() - ((Component)__instance).transform.position.y) > 2.5f)
			{
				((Component)__instance).GetComponent<BetterDivingExtension>().is_diving = true;
				((Component)__instance).GetComponent<BetterDivingExtension>().isUnderwater = true;
				___m_lastGroundTouch = 0.3f;
				___m_swimTimer = 0f;
				return;
			}
			((Component)__instance).GetComponent<BetterDivingExtension>().is_diving = false;
			if (((Component)__instance).GetComponent<BetterDivingExtension>().remainingDiveTime >= 1f)
			{
				BetterDiving.breathDelayTimer += Time.deltaTime;
				if (BetterDiving.breathDelayTimer >= BetterDiving.breathBarRemoveDelay)
				{
					BetterDiving.loc_breath_bar_bg.SetActive(false);
					BetterDiving.loc_depleted_breath.SetActive(false);
					BetterDiving.loc_breath_bar.SetActive(false);
					BetterDiving.loc_breathe_overlay.SetActive(false);
					BetterDiving.breathDelayTimer = 0f;
				}
			}
			else
			{
				BetterDiving.breathDelayTimer = 0f;
			}
			if (((Component)__instance).GetComponent<BetterDivingExtension>().isUnderwater && (Object)(object)__instance.GetStandingOnShip() == (Object)null)
			{
				if (!__instance.IsDead() && BetterDiving.showYouCanBreatheMsg.Value)
				{
					__instance.Message((MessageType)2, "You can breath now.", 0, (Sprite)null);
				}
				((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive = false;
				((Component)__instance).GetComponent<BetterDivingExtension>().lastDiveCancel = "PlayerSurfaced";
				if (!__instance.IsDead() && BetterDiving.showSurfacingMsg.Value)
				{
					__instance.Message((MessageType)2, BetterDiving.surfacingMsg.Value, 0, (Sprite)null);
				}
				((Component)__instance).GetComponent<BetterDivingExtension>().isUnderwater = false;
			}
		}
	}
	[HarmonyPatch(typeof(Character), "CustomFixedUpdate")]
	public class Character_FixedUpdate
	{
		[HarmonyPrefix]
		public static void Prefix(Character __instance, ref Vector3 ___m_moveDir, ref Vector3 ___m_lookDir, ref float ___m_lastGroundTouch, ref bool ___m_walking, ref bool ___m_wallRunning, ref bool ___m_sliding, ref bool ___m_running, ref float ___m_swimTimer)
		{
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			if (__instance != Player.m_localPlayer || !__instance.IsPlayer() || !BetterDiving.IsEnvAllowed() || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			if (!__instance.InWater())
			{
				__instance.m_swimDepth = 1.6f;
			}
			bool flag = false;
			if ((ZInput.GetButtonDown("Crouch") || ZInput.GetButtonDown("JoyCrouch")) && !flag && __instance.InWater() && !__instance.IsOnGround() && __instance.IsSwimming())
			{
				flag = true;
				if (!((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive)
				{
					((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive = true;
					((Component)__instance).GetComponent<BetterDivingExtension>().lastDiveCancel = "None";
					if (BetterDiving.showDivingMsg.Value)
					{
						__instance.Message((MessageType)2, BetterDiving.divingMsg.Value, 0, (Sprite)null);
					}
				}
				else if (((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive && __instance.m_swimDepth <= 2.5f)
				{
					((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive = false;
					((Component)__instance).GetComponent<BetterDivingExtension>().lastDiveCancel = "PlayerCancelled";
					if (BetterDiving.showDivingMsg.Value)
					{
						__instance.Message((MessageType)2, BetterDiving.divingCancelledMsg.Value, 0, (Sprite)null);
					}
				}
			}
			else if (ZInput.GetButtonUp("Crouch") || ZInput.GetButtonUp("JoyCrouch"))
			{
				flag = false;
			}
			if (__instance.IsOnGround() || !__instance.IsSwimming() || !__instance.InWater())
			{
				((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive = false;
				((Component)__instance).GetComponent<BetterDivingExtension>().lastDiveCancel = "PlayerOnLand";
			}
			if (((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive && __instance.InWater() && !__instance.IsOnGround() && __instance.IsSwimming())
			{
				if (__instance.IsPlayer() && __instance.m_swimDepth > 2.5f)
				{
					BetterDiving.m_diveSkillImproveTimer += Time.deltaTime;
					if (BetterDiving.m_diveSkillImproveTimer > 1f)
					{
						BetterDiving.m_diveSkillImproveTimer = 0f;
						__instance.RaiseSkill(BetterDiving.DivingSkillType, 0.25f);
					}
				}
				BetterDiving.char_swim_depth = __instance.m_swimDepth;
				float num = 0f;
				if ((double)___m_lookDir.y < -0.25)
				{
					BetterDiving.loc_m_diveAaxis = 1f;
				}
				if ((double)___m_lookDir.y > 0.15)
				{
					BetterDiving.loc_m_diveAaxis = 0f;
				}
				num = ___m_lookDir.y * ___m_lookDir.y * 0.25f;
				if (num > 0.025f)
				{
					num = 0.025f;
				}
				if (!ZInput.GetButton("Forward") && !ZInput.GetButton("JoyLStickUp"))
				{
					return;
				}
				if (___m_lookDir.y > -0.25f && ___m_lookDir.y < 0.15f)
				{
					num = 0f;
				}
				if (BetterDiving.loc_m_diveAaxis == 1f)
				{
					__instance.m_swimDepth += num;
				}
				if (BetterDiving.loc_m_diveAaxis == 0f)
				{
					if (__instance.m_swimDepth > 1.6f)
					{
						__instance.m_swimDepth -= num;
					}
					if (__instance.m_swimDepth < 1.6f)
					{
						__instance.m_swimDepth = 1.6f;
					}
				}
				if (__instance.m_swimDepth > 2.5f)
				{
					__instance.SetMoveDir(___m_lookDir);
				}
			}
			else if ((__instance.IsOnGround() || !((Component)__instance).GetComponent<BetterDivingExtension>().is_diving) && !((Component)__instance).GetComponent<BetterDivingExtension>().isTakeRestInWater)
			{
				__instance.m_swimDepth = 1.6f;
			}
		}
	}
	[HarmonyPatch(typeof(Character), "UpdateSwimming")]
	internal class Character_UpdateSwiming_Patch
	{
		private static void Prefix(Character __instance)
		{
			if (__instance != Player.m_localPlayer || !__instance.IsPlayer() || !BetterDiving.allowFastSwimming.Value || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			float skillFactor = __instance.GetSkillFactor((SkillType)103);
			float num = skillFactor * 100f;
			float num2 = BetterDiving.fastSwimSpeedMultiplier * num + 1f;
			BetterDiving.fastSwimSpeed = BetterDiving.baseSwimSpeed + num2;
			float num3 = skillFactor / 100f;
			float num4 = 0.5f * num3;
			float num5 = 0.1f * skillFactor;
			float num6 = num4 + num5;
			float num7 = 0.5f - num6;
			float num8 = (BetterDiving.fastSwimStamDrain = BetterDiving.swimStaminaDrainRate * num7 * 2f + 5f);
			if (ZInput.GetButton("Run") || ZInput.GetButton("JoyRun"))
			{
				if (!((Component)__instance).GetComponent<BetterDivingExtension>().isUnderwater)
				{
					float num9 = Time.deltaTime * num8;
					__instance.UseStamina(num9);
				}
				__instance.m_swimSpeed = BetterDiving.fastSwimSpeed;
			}
			else
			{
				__instance.m_swimSpeed = BetterDiving.baseSwimSpeed;
			}
		}
	}
	[HarmonyPatch(typeof(Hud), "Update")]
	public class Hud_Update
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			if (!BetterDiving.has_created_breathe_bar && (Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)Hud.instance != (Object)null && (Object)(object)Hud.instance.m_pieceSelectionWindow != (Object)null)
			{
				BetterDiving.loc_breath_bar_bg = GUIManager.Instance.CreateWoodpanel(((Component)Hud.instance).transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(60f, -60f), 20f, 124f, false);
				((Object)BetterDiving.loc_breath_bar_bg).name = "BreathBarBG";
				BetterDiving.loc_breath_bar_bg.GetComponent<Image>().sprite = BetterDiving.breath_bg_sprite;
				BetterDiving.loc_depleted_breath = GUIManager.Instance.CreateWoodpanel(((Component)Hud.instance).transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(60f, -60f), 15f, 120f, false);
				((Object)BetterDiving.loc_depleted_breath).name = "depleted_breath_progress";
				BetterDiving.loc_depleted_breath.GetComponent<Image>().sprite = BetterDiving.breath_prog_sprite;
				BetterDiving.loc_depleted_breath.GetComponent<Image>().type = (Type)3;
				BetterDiving.loc_depleted_breath.GetComponent<Image>().fillMethod = (FillMethod)1;
				BetterDiving.loc_depleted_breath.GetComponent<Image>().fillAmount = 1f;
				((Graphic)BetterDiving.loc_depleted_breath.GetComponent<Image>()).color = Color32.op_Implicit(new Color32((byte)204, (byte)204, (byte)204, byte.MaxValue));
				BetterDiving.loc_breath_bar = GUIManager.Instance.CreateWoodpanel(((Component)Hud.instance).transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(60f, -60f), 15f, 120f, false);
				((Object)BetterDiving.loc_breath_bar).name = "breathbar_progress";
				BetterDiving.loc_breath_bar.GetComponent<Image>().sprite = BetterDiving.breath_prog_sprite;
				BetterDiving.loc_breath_bar.GetComponent<Image>().type = (Type)3;
				BetterDiving.loc_breath_bar.GetComponent<Image>().fillMethod = (FillMethod)1;
				BetterDiving.loc_breath_bar.GetComponent<Image>().fillAmount = 1f;
				BetterDiving.loc_breathe_overlay = GUIManager.Instance.CreateWoodpanel(((Component)Hud.instance).transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(60f, -60f), 15f, 120f, false);
				((Object)BetterDiving.loc_breathe_overlay).name = "BreathBarOverlay";
				BetterDiving.loc_breathe_overlay.GetComponent<Image>().sprite = BetterDiving.breath_overlay_sprite;
				if (BetterDiving.owBIPos.Value)
				{
					BetterDiving.loc_breath_bar_bg.transform.position = new Vector3(BetterDiving.owBIPosX.Value, BetterDiving.owBIPosY.Value, ((Component)Hud.instance).transform.position.y);
					BetterDiving.loc_depleted_breath.transform.position = new Vector3(BetterDiving.owBIPosX.Value, BetterDiving.owBIPosY.Value, ((Component)Hud.instance).transform.position.y);
					BetterDiving.loc_breath_bar.transform.position = new Vector3(BetterDiving.owBIPosX.Value, BetterDiving.owBIPosY.Value, ((Component)Hud.instance).transform.position.y);
					BetterDiving.loc_breathe_overlay.transform.position = new Vector3(BetterDiving.owBIPosX.Value, BetterDiving.owBIPosY.Value, ((Component)Hud.instance).transform.position.y);
				}
				BetterDiving.loc_breath_bar_bg.SetActive(false);
				BetterDiving.loc_depleted_breath.SetActive(false);
				BetterDiving.loc_breath_bar.SetActive(false);
				BetterDiving.loc_breathe_overlay.SetActive(false);
				BetterDiving.has_created_breathe_bar = true;
			}
		}
	}
	[HarmonyPatch(typeof(Player))]
	public static class Player_Patch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			((Component)__instance).gameObject.AddComponent<BetterDivingExtension>();
		}
	}
	public class BetterDivingExtension : MonoBehaviour
	{
		public bool toggleDive;

		public bool is_diving;

		public float remainingDiveTime = 1f;

		public string lastActivity = "";

		public string lastDiveCancel = "";

		public bool cameFromDiving;

		public bool isUnderwater;

		public bool isTakeRestInWater;

		public float maxStamina = 100f;

		public float staminaToUpdate = 100f;
	}
	[HarmonyPatch(typeof(Player), "OnDeath")]
	public class Player_OnDeath
	{
		[HarmonyPrefix]
		public static void Prefix(Player __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				((Component)__instance).GetComponent<BetterDivingExtension>().is_diving = false;
				BetterDiving.loc_breath_bar_bg.SetActive(false);
				BetterDiving.loc_depleted_breath.SetActive(false);
				BetterDiving.loc_breath_bar.SetActive(false);
				BetterDiving.loc_breathe_overlay.SetActive(false);
				BetterDiving.DebugLog("Better Diving Mod: OnDeath...");
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	public class Player_Update
	{
		[HarmonyPrefix]
		public static void Prefix(Player __instance, ref float ___m_stamina, ref float ___m_maxStamina)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && !BetterDiving.dive_timer_is_running)
			{
				((MonoBehaviour)__instance).StartCoroutine(StartCountdown());
				BetterDiving.dive_timer_is_running = true;
			}
			if (((Character)__instance).IsDead())
			{
				BetterDiving.loc_breath_bar_bg.SetActive(false);
				BetterDiving.loc_depleted_breath.SetActive(false);
				BetterDiving.loc_breath_bar.SetActive(false);
				BetterDiving.loc_breathe_overlay.SetActive(false);
			}
			((Component)__instance).GetComponent<BetterDivingExtension>().maxStamina = ___m_maxStamina;
			Vector3 velocity = ((Character)__instance).GetVelocity();
			if (((Vector3)(ref velocity)).magnitude >= 1f || ((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive || !((Character)__instance).InWater() || !((Character)__instance).IsSwimming())
			{
				((Component)__instance).GetComponent<BetterDivingExtension>().isTakeRestInWater = false;
			}
			if (!((Component)__instance).GetComponent<BetterDivingExtension>().isTakeRestInWater && ((Component)__instance).GetComponent<BetterDivingExtension>().is_diving && ((Component)__instance).GetComponent<BetterDivingExtension>().remainingDiveTime <= 0f && ___m_stamina > ((Component)__instance).GetComponent<BetterDivingExtension>().staminaToUpdate && ___m_stamina != 0f)
			{
				___m_stamina = ((Component)__instance).GetComponent<BetterDivingExtension>().staminaToUpdate;
			}
			if (((Component)__instance).GetComponent<BetterDivingExtension>().isTakeRestInWater)
			{
				___m_stamina = ((Component)__instance).GetComponent<BetterDivingExtension>().staminaToUpdate;
			}
			if (___m_stamina < 0f)
			{
				___m_stamina = 0f;
			}
			if (BetterDiving.m_swimStaminaDrainMaxSkill == 0f)
			{
				BetterDiving.m_swimStaminaDrainMaxSkill = __instance.m_swimStaminaDrainMaxSkill;
			}
			if (BetterDiving.m_swimStaminaDrainMinSkill == 0f)
			{
				BetterDiving.m_swimStaminaDrainMinSkill = __instance.m_swimStaminaDrainMinSkill;
			}
			if (((Component)__instance).GetComponent<BetterDivingExtension>().is_diving && ((Character)__instance).IsSwimming())
			{
				if (BetterDiving.m_swimStaminaDrainMaxSkill != BetterDiving.c_swimStaminaDrainMaxSkill.Value)
				{
					__instance.m_swimStaminaDrainMaxSkill = BetterDiving.c_swimStaminaDrainMaxSkill.Value;
				}
				if (BetterDiving.m_swimStaminaDrainMinSkill != BetterDiving.c_swimStaminaDrainMinSkill.Value)
				{
					__instance.m_swimStaminaDrainMinSkill = BetterDiving.c_swimStaminaDrainMinSkill.Value;
				}
				((Component)__instance).GetComponent<BetterDivingExtension>().lastActivity = "diving";
				((Component)__instance).GetComponent<BetterDivingExtension>().cameFromDiving = true;
				bool flag = false;
				if ((Object)(object)Minimap.instance != (Object)null && Minimap.IsOpen())
				{
					flag = true;
				}
				bool flag2 = false;
				if ((Object)(object)InventoryGui.instance != (Object)null && InventoryGui.IsVisible())
				{
					flag2 = true;
				}
				bool flag3 = false;
				if ((Object)(object)Menu.instance != (Object)null && Menu.IsVisible())
				{
					flag3 = true;
				}
				if ((Object)(object)BetterDiving.loc_breath_bar != (Object)null && (Object)(object)Hud.instance != (Object)null && BetterDiving.has_created_breathe_bar && !BetterDiving.loc_breath_bar.activeSelf && !flag && !flag2 && !flag3)
				{
					BetterDiving.loc_breath_bar_bg.SetActive(true);
					BetterDiving.loc_depleted_breath.SetActive(true);
					BetterDiving.loc_breath_bar.SetActive(true);
					BetterDiving.loc_breathe_overlay.SetActive(true);
				}
				else if ((Object)(object)BetterDiving.loc_breath_bar != (Object)null && (Object)(object)Hud.instance != (Object)null && BetterDiving.has_created_breathe_bar && BetterDiving.loc_breath_bar.activeSelf && (flag || flag2 || flag3))
				{
					BetterDiving.loc_breath_bar_bg.SetActive(false);
					BetterDiving.loc_depleted_breath.SetActive(false);
					BetterDiving.loc_breath_bar.SetActive(false);
					BetterDiving.loc_breathe_overlay.SetActive(false);
				}
			}
			else if (((Character)__instance).IsSwimming())
			{
				velocity = ((Character)__instance).GetVelocity();
				if (((Vector3)(ref velocity)).magnitude < 1f && !((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive)
				{
					if (BetterDiving.allowRestInWater.Value)
					{
						((Component)__instance).GetComponent<BetterDivingExtension>().isTakeRestInWater = true;
					}
				}
				else
				{
					velocity = ((Character)__instance).GetVelocity();
					if (((Vector3)(ref velocity)).magnitude >= 1f || ((Component)__instance).GetComponent<BetterDivingExtension>().toggleDive)
					{
						((Component)__instance).GetComponent<BetterDivingExtension>().cameFromDiving = false;
						((Component)__instance).GetComponent<BetterDivingExtension>().lastActivity = "swimming";
						((Component)__instance).GetComponent<BetterDivingExtension>().isTakeRestInWater = false;
					}
				}
				if (__instance.m_swimStaminaDrainMaxSkill == BetterDiving.c_swimStaminaDrainMaxSkill.Value)
				{
					__instance.m_swimStaminaDrainMaxSkill = BetterDiving.m_swimStaminaDrainMaxSkill;
					__instance.m_swimStaminaDrainMinSkill = BetterDiving.m_swimStaminaDrainMinSkill;
				}
			}
			if (!((Object)(object)BetterDiving.loc_breath_bar != (Object)null) || !((Object)(object)Hud.instance != (Object)null) || !BetterDiving.has_created_breathe_bar || !BetterDiving.loc_breath_bar.activeSelf)
			{
				return;
			}
			BetterDiving.loc_breath_bar.GetComponent<Image>().fillAmount = Mathf.Lerp(BetterDiving.loc_breath_bar.GetComponent<Image>().fillAmount, ((Component)__instance).GetComponent<BetterDivingExtension>().remainingDiveTime, Time.deltaTime);
			float num = 1.5f;
			if (!((Component)__instance).GetComponent<BetterDivingExtension>().is_diving)
			{
				if (BetterDiving.loc_depleted_breath.GetComponent<Image>().fillAmount >= ((Component)__instance).GetComponent<BetterDivingExtension>().remainingDiveTime)
				{
					BetterDiving.loc_depleted_breath.GetComponent<Image>().fillAmount = Mathf.Lerp(BetterDiving.loc_depleted_breath.GetComponent<Image>().fillAmount, 0f, Time.deltaTime * num);
				}
				else if (BetterDiving.loc_depleted_breath.GetComponent<Image>().fillAmount < ((Component)__instance).GetComponent<BetterDivingExtension>().remainingDiveTime)
				{
					BetterDiving.loc_depleted_breath.SetActive(false);
					BetterDiving.highestOxygen = 0f;
				}
			}
			else
			{
				BetterDiving.loc_depleted_breath.SetActive(true);
				if (BetterDiving.loc_breath_bar.GetComponent<Image>().fillAmount > BetterDiving.highestOxygen)
				{
					BetterDiving.highestOxygen = BetterDiving.loc_breath_bar.GetComponent<Image>().fillAmount;
				}
				BetterDiving.loc_depleted_breath.GetComponent<Image>().fillAmount = BetterDiving.highestOxygen;
			}
			if (((Component)__instance).GetComponent<BetterDivingExtension>().remainingDiveTime <= 0.25f)
			{
				((Graphic)BetterDiving.loc_breath_bar.GetComponent<Image>()).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)68, (byte)68, byte.MaxValue));
			}
			else
			{
				((Graphic)BetterDiving.loc_breath_bar.GetComponent<Image>()).color = Color32.op_Implicit(new Color32((byte)0, byte.MaxValue, (byte)239, byte.MaxValue));
			}
		}

		public static IEnumerator StartCountdown()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(1f);
				BetterDiving.DebugLog("---------------------Section Debug Start------------------------");
				BetterDiving.DebugLog("Rendering API -> " + BetterDiving.graphicsDeviceType);
				BetterDiving.DebugLog("is_swimming -> " + ((Character)Player.m_localPlayer).IsSwimming());
				BetterDiving.DebugLog("m_minDiveSkillImprover -> " + BetterDiving.m_minDiveSkillImprover);
				BetterDiving.DebugLog("Player_remainingDiveTime -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().remainingDiveTime);
				BetterDiving.DebugLog("loc_m_m_maxDistance -> " + BetterDiving.loc_m_m_maxDistance);
				BetterDiving.DebugLog("loc_m_diveAaxis -> " + BetterDiving.loc_m_diveAaxis);
				BetterDiving.DebugLog("Player_swimDepth -> " + ((Character)Player.m_localPlayer).m_swimDepth);
				BetterDiving.DebugLog("char_swim_depth -> " + BetterDiving.char_swim_depth);
				BetterDiving.DebugLog("loc_cam_pos_y -> " + BetterDiving.loc_cam_pos_y);
				BetterDiving.DebugLog("render_settings_updated_camera -> " + BetterDiving.render_settings_updated_camera);
				BetterDiving.DebugLog("set_force_env -> " + BetterDiving.set_force_env);
				BetterDiving.DebugLog("minwaterdist -> " + BetterDiving.minwaterdist);
				BetterDiving.DebugLog("water_level_camera -> " + BetterDiving.water_level_camera);
				BetterDiving.DebugLog("water_level_player -> " + BetterDiving.water_level_player);
				BetterDiving.DebugLog("m_swimStaminaDrainMinSkill -> " + BetterDiving.m_swimStaminaDrainMinSkill);
				BetterDiving.DebugLog("m_swimStaminaDrainMaxSkill -> " + BetterDiving.m_swimStaminaDrainMaxSkill);
				BetterDiving.DebugLog("dive_timer_is_running -> " + BetterDiving.dive_timer_is_running);
				BetterDiving.DebugLog("Player_lastActivity -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().lastActivity);
				BetterDiving.DebugLog("Player_cameFromDiving -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().cameFromDiving);
				BetterDiving.DebugLog("Player_isUnderwater -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().isUnderwater);
				BetterDiving.DebugLog("has_created_breathe_bar -> " + BetterDiving.has_created_breathe_bar);
				BetterDiving.DebugLog("Player_isTakeRestInWater -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().isTakeRestInWater);
				BetterDiving.DebugLog("player_staminaToUpdate -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().staminaToUpdate);
				BetterDiving.DebugLog("Player_maxStamina -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().maxStamina);
				BetterDiving.DebugLog("EnvName -> " + BetterDiving.EnvName);
				BetterDiving.DebugLog("m_diveSkillImproveTimer -> " + BetterDiving.m_diveSkillImproveTimer);
				BetterDiving.DebugLog("m_minDiveSkillImprover -> " + BetterDiving.m_minDiveSkillImprover);
				BetterDiving.DebugLog("Player_toggleDive -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().toggleDive);
				BetterDiving.DebugLog("Player_lastDiveCancel -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().lastDiveCancel);
				BetterDiving.DebugLog("fastSwimSpeed -> " + BetterDiving.fastSwimSpeed);
				BetterDiving.DebugLog("fastSwimStamDrain -> " + BetterDiving.fastSwimStamDrain);
				BetterDiving.DebugLog("----------------------Section Debug End-------------------------");
				BetterDiving.DebugLog("---------------------Section Update Some Values Start------------------------");
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().maxStamina = ((Character)Player.m_localPlayer).GetMaxStamina();
					((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().staminaToUpdate = Player.m_localPlayer.GetStamina();
					if (((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().is_diving && ((Character)Player.m_localPlayer).IsSwimming())
					{
						BetterDiving.m_minDiveSkillImprover += 1f;
						if (((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().remainingDiveTime >= 0f)
						{
							if (((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().remainingDiveTime >= 1f)
							{
								((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().remainingDiveTime = 1f;
							}
							float num = 1f / 120f;
							float value = BetterDiving.breatheDrain.Value;
							float num2 = BetterDiving.breatheDrain.Value / 120f;
							BetterDiving.DebugLog("one_percentage -> " + num);
							BetterDiving.DebugLog("final_dive_drain -> " + value);
							BetterDiving.DebugLog("final_dive_drain_one_percentage -> " + num2);
							float skillFactor = ((Character)Player.m_localPlayer).GetSkillFactor(BetterDiving.DivingSkillType);
							float num3 = Mathf.Lerp(1f, 0.5f, skillFactor);
							value = value * num3 / 120f;
							if (value > num2)
							{
								value = num2;
							}
							if ((ZInput.GetButton("Run") || ZInput.GetButton("JoyRun")) && BetterDiving.allowFastSwimming.Value)
							{
								value *= 2f;
							}
							((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().remainingDiveTime -= value;
							BetterDiving.DebugLog("skillFactor -> " + skillFactor);
							BetterDiving.DebugLog("converted skillFactor -> " + num3);
							BetterDiving.DebugLog("final_dive_drain -> " + value);
						}
						if (((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().remainingDiveTime <= 0f)
						{
							((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().staminaToUpdate -= ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().maxStamina * 0.2f;
						}
					}
					else if (((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().remainingDiveTime < 1f)
					{
						float num4 = 1f / 120f;
						float value2 = BetterDiving.breatheDrain.Value;
						float num5 = BetterDiving.breatheDrain.Value / 120f;
						BetterDiving.DebugLog("one_percentage -> " + num4);
						BetterDiving.DebugLog("final_dive_drain -> " + value2);
						BetterDiving.DebugLog("final_dive_drain_one_percentage -> " + num5);
						float skillFactor2 = ((Character)Player.m_localPlayer).GetSkillFactor(BetterDiving.DivingSkillType);
						float num6 = Mathf.Lerp(1f, 0.5f, skillFactor2);
						value2 = value2 * num6 / 120f;
						if (value2 > num5)
						{
							value2 = num5;
						}
						((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().remainingDiveTime += 0.125f;
						BetterDiving.DebugLog("skillFactor -> " + skillFactor2);
						BetterDiving.DebugLog("converted skillFactor -> " + num6);
						BetterDiving.DebugLog("final_dive_drain -> " + value2);
					}
					BetterDiving.DebugLog("Player_isTakeRestInWater -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().isTakeRestInWater);
					if (((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().isTakeRestInWater && ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().staminaToUpdate < ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().maxStamina)
					{
						if (BetterDiving.ow_staminaRestoreValue.Value)
						{
							((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().staminaToUpdate += BetterDiving.ow_staminaRestorPerTick.Value;
							BetterDiving.DebugLog("ow_staminaRestorPerTick -> " + BetterDiving.ow_staminaRestorPerTick.Value);
							BetterDiving.DebugLog("Player_staminaToUpdate -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().staminaToUpdate);
						}
						else
						{
							((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().staminaToUpdate += ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().maxStamina * 0.0115f;
							BetterDiving.DebugLog("ow_staminaRestorPerTick -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().maxStamina * 0.0115f);
							BetterDiving.DebugLog("Player_staminaToUpdate -> " + ((Component)Player.m_localPlayer).GetComponent<BetterDivingExtension>().staminaToUpdate);
						}
					}
				}
				BetterDiving.DebugLog("----------------------Section Update Some Values End-------------------------");
			}
		}
	}
	[HarmonyPatch(typeof(WaterVolume), "UpdateMaterials")]
	public class WaterVolume_Update
	{
		public static int RandomDigits(int length)
		{
			Random random = new Random();
			string text = string.Empty;
			for (int i = 0; i < length; i++)
			{
				text += random.Next(10);
			}
			return int.Parse(text);
		}

		[HarmonyPrefix]
		public static void Prefix(WaterVolume __instance, ref float[] ___m_normalizedDepth)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)GameCamera.instance))
			{
				BetterDiving.water_level_camera = __instance.GetWaterSurface(new Vector3(((Component)GameCamera.instance).transform.position.x, ((Component)GameCamera.instance).transform.position.y, ((Component)GameCamera.instance).transform.position.z), 1f);
			}
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				BetterDiving.water_level_player = __instance.GetWaterSurface(new Vector3(((Component)Player.m_localPlayer).transform.position.x, ((Component)Player.m_localPlayer).transform.position.y, ((Component)Player.m_localPlayer).transform.position.z), 1f);
			}
			Quaternion rotation;
			if (BetterDiving.loc_cam_pos_y < BetterDiving.water_level_camera && ((Character)Player.m_localPlayer).IsSwimming())
			{
				rotation = ((Component)((Component)__instance.m_waterSurface).GetComponent<MeshRenderer>()).transform.rotation;
				if (((Quaternion)(ref rotation)).eulerAngles.y != 180f && BetterDiving.IsEnvAllowed())
				{
					((Component)__instance.m_waterSurface).transform.Rotate(180f, 0f, 0f);
					if (!BetterDiving.graphicsDeviceType.Equals("Vulkan", StringComparison.OrdinalIgnoreCase))
					{
						((Renderer)__instance.m_waterSurface).material = BetterDiving.water_mat;
					}
					((Renderer)__instance.m_waterSurface).shadowCastingMode = (ShadowCastingMode)2;
					if (__instance.m_forceDepth >= 0f)
					{
						((Renderer)__instance.m_waterSurface).material.SetFloatArray(Shader.PropertyToID("_depth"), new float[4] { __instance.m_forceDepth, __instance.m_forceDepth, __instance.m_forceDepth, __instance.m_forceDepth });
					}
					else
					{
						((Renderer)__instance.m_waterSurface).material.SetFloatArray(Shader.PropertyToID("_depth"), ___m_normalizedDepth);
					}
					((Renderer)__instance.m_waterSurface).material.SetFloat(Shader.PropertyToID("_UseGlobalWind"), __instance.m_useGlobalWind ? 1f : 0f);
				}
				((Component)__instance.m_waterSurface).transform.position = new Vector3(((Component)__instance.m_waterSurface).transform.position.x, BetterDiving.water_level_camera, ((Component)__instance.m_waterSurface).transform.position.z);
				return;
			}
			rotation = ((Component)((Component)__instance.m_waterSurface).GetComponent<MeshRenderer>()).transform.rotation;
			if (((Quaternion)(ref rotation)).eulerAngles.y == 180f && BetterDiving.IsEnvAllowed())
			{
				((Component)__instance.m_waterSurface).transform.Rotate(-180f, 0f, 0f);
				((Renderer)__instance.m_waterSurface).material = BetterDiving.mai_water_mat;
				if (__instance.m_forceDepth >= 0f)
				{
					((Renderer)__instance.m_waterSurface).material.SetFloatArray(Shader.PropertyToID("_depth"), new float[4] { __instance.m_forceDepth, __instance.m_forceDepth, __instance.m_forceDepth, __instance.m_forceDepth });
				}
				else
				{
					((Renderer)__instance.m_waterSurface).material.SetFloatArray(Shader.PropertyToID("_depth"), ___m_normalizedDepth);
				}
				((Component)__instance.m_waterSurface).transform.position = new Vector3(((Component)__instance.m_waterSurface).transform.position.x, 30f, ((Component)__instance.m_waterSurface).transform.position.z);
				((Renderer)__instance.m_waterSurface).material.SetFloat(Shader.PropertyToID("_UseGlobalWind"), __instance.m_useGlobalWind ? 1f : 0f);
			}
		}
	}
	[HarmonyPatch(typeof(WaterVolume), "Awake")]
	public class WaterVolume_Awake
	{
		[HarmonyPrefix]
		public static void Prefix(WaterVolume __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				BetterDiving.DebugLog("---------------------Section WaterVolume Awake Prefix Start------------------------");
				BetterDiving.DebugLog("water_volume_awake -> true");
				BetterDiving.DebugLog("----------------------Section WaterVolume Awake Prefix End-------------------------");
			}
		}

		[HarmonyPostfix]
		public static void Postfix(WaterVolume __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				BetterDiving.DebugLog("---------------------Section WaterVolume Awake Postfix Start------------------------");
				BetterDiving.DebugLog("mai_water_mat -> " + (((Object)(object)BetterDiving.mai_water_mat == (Object)null) ? "null" : "not null"));
				if ((Object)(object)BetterDiving.mai_water_mat == (Object)null)
				{
					BetterDiving.mai_water_mat = ((Renderer)__instance.m_waterSurface).material;
					BetterDiving.DebugLog("Info -> set water mat");
				}
				BetterDiving.DebugLog("----------------------Section WaterVolume Awake Postfix End-------------------------");
			}
		}
	}
}