Decompiled source of SimpleVikingsDoSwim v1.0.0

SimpleVikingsDoSwim.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SimpleVikingsDoSwim")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("Simple Vikings Do Swim")]
[assembly: AssemblyTitle("SimpleVikingsDoSwim")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SimpleVikingsDoSwim
{
	[BepInPlugin("SimpleVikingsDoSwim", "Simple Vikings Do Swim", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Character), "Awake")]
		public class CharacterAwakePatch
		{
			public static void Prefix(Character __instance)
			{
				if (__instance.IsPlayer())
				{
					__instance.m_swimDepth = 1.5f;
					p_swimDepth = __instance.m_swimDepth;
				}
			}
		}

		[HarmonyPatch(typeof(Character), "CustomFixedUpdate")]
		public class CharacterFixedUpdatePatch
		{
			public static void Prefix(Character __instance, ref Vector3 ___m_lookDir)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Expected O, but got Unknown
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0219: Unknown result type (might be due to invalid IL or missing references)
				if (!__instance.IsPlayer() || (Object)__instance == (Object)null)
				{
					return;
				}
				if (!__instance.InWater())
				{
					__instance.m_swimDepth = 1.4f;
				}
				if (ZInput.GetKey((KeyCode)306, true) && __instance.InWater() && !__instance.IsOnGround() && __instance.IsSwimming())
				{
					if (__instance.m_swimDepth > 2.2f)
					{
						Player localPlayer = Player.m_localPlayer;
						localPlayer.m_swimSkillImproveTimer += Time.deltaTime;
						if (localPlayer.m_swimSkillImproveTimer > 1f)
						{
							localPlayer.m_swimSkillImproveTimer = 0f;
							((Character)localPlayer).RaiseSkill((SkillType)103, 1f);
						}
					}
					c_position = ((Component)__instance).transform.position;
					c_swimDepth = __instance.m_swimDepth;
					if ((double)___m_lookDir.y < -0.25)
					{
						_diveAxis = 1f;
					}
					if ((double)___m_lookDir.y > 0.15)
					{
						_diveAxis = 0f;
					}
					float num = ___m_lookDir.y * ___m_lookDir.y * 0.25f;
					if (num > 0.025f)
					{
						num = 0.025f;
					}
					float y = ___m_lookDir.y;
					if (y > -0.25f && y < 0.15f)
					{
						num = 0f;
					}
					y = _diveAxis;
					if (y != 1f)
					{
						if (y == 0f)
						{
							if (__instance.m_swimDepth > 1.5f)
							{
								__instance.m_swimDepth -= num;
							}
							if (__instance.m_swimDepth < 1.5f)
							{
								__instance.m_swimDepth = 1.5f;
							}
						}
					}
					else
					{
						__instance.m_swimDepth += num;
					}
					if (__instance.m_swimDepth > 2.2f)
					{
						__instance.SetMoveDir(___m_lookDir);
					}
				}
				else if ((__instance.IsOnGround() || !_isDiving) && !_restInWater)
				{
					__instance.m_swimDepth = 1.5f;
				}
			}
		}

		[HarmonyPatch(typeof(Character), "UpdateMotion")]
		public class CharacterUpdateMotionPatch
		{
			public static void Prefix(Character __instance, ref float ___m_lastGroundTouch, ref float ___m_swimTimer)
			{
				if (__instance.IsPlayer())
				{
					if (__instance.m_swimDepth > 2.2f)
					{
						_isDiving = true;
						_restInWater = false;
						___m_lastGroundTouch = 0.3f;
						___m_swimTimer = 0f;
					}
					else
					{
						_isDiving = false;
					}
					p_swimDepth = __instance.m_swimDepth;
				}
			}
		}

		[HarmonyPatch(typeof(Character), "UpdateSwimming")]
		public class CharacterUpdateSwimmingPatch
		{
			public static bool Prefix(float dt, ref Character __instance)
			{
				//IL_0034: 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_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				//IL_017c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0181: Unknown result type (might be due to invalid IL or missing references)
				//IL_0186: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01aa: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0276: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: Unknown result type (might be due to invalid IL or missing references)
				//IL_0232: Unknown result type (might be due to invalid IL or missing references)
				//IL_0237: Unknown result type (might be due to invalid IL or missing references)
				//IL_023b: Unknown result type (might be due to invalid IL or missing references)
				//IL_025c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0341: 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_0395: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_03af: Unknown result type (might be due to invalid IL or missing references)
				//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_037b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0387: Unknown result type (might be due to invalid IL or missing references)
				//IL_048a: Unknown result type (might be due to invalid IL or missing references)
				if (!__instance.IsPlayer())
				{
					return true;
				}
				bool flag = __instance.IsOnGround();
				if (Mathf.Max(0f, __instance.m_maxAirAltitude - ((Component)__instance).transform.position.y) > 0.5f && __instance.m_onLand != null)
				{
					__instance.m_onLand(new Vector3(((Component)__instance).transform.position.x, __instance.GetLiquidLevel(), ((Component)__instance).transform.position.z));
				}
				__instance.m_maxAirAltitude = ((Component)__instance).transform.position.y;
				float num = __instance.m_swimSpeed * __instance.GetAttackSpeedFactorMovement();
				if (ZInput.GetKey((KeyCode)304, true))
				{
					num *= _swimSprintSpeed.Value;
				}
				if (__instance.InMinorActionSlowdown())
				{
					num = 0f;
				}
				__instance.m_seman.ApplyStatusEffectSpeedMods(ref num, __instance.m_moveDir);
				Vector3 val = __instance.m_moveDir * num;
				__instance.m_currentVel = Vector3.Lerp(__instance.m_currentVel, val, __instance.m_swimAcceleration);
				if (((Vector3)(ref __instance.m_currentVel)).magnitude > 0.1f)
				{
					__instance.AddNoise(15f);
				}
				__instance.AddPushbackForce(ref __instance.m_currentVel);
				Vector3 val2 = __instance.m_currentVel - __instance.m_body.linearVelocity;
				val2.y = 0f;
				if (((Vector3)(ref val2)).magnitude > 20f)
				{
					val2 = ((Vector3)(ref val2)).normalized * 20f;
				}
				__instance.m_body.AddForce(val2, (ForceMode)2);
				float num2 = __instance.GetLiquidLevel() - __instance.m_swimDepth;
				if (((Component)__instance).transform.position.y < num2)
				{
					float num3 = Mathf.Clamp01((num2 - ((Component)__instance).transform.position.y) / 2f);
					float num4 = Mathf.Lerp(0f, 10f, num3);
					Vector3 linearVelocity = __instance.m_body.linearVelocity;
					linearVelocity.y = Mathf.MoveTowards(linearVelocity.y, num4, 50f * dt);
					__instance.m_body.linearVelocity = linearVelocity;
				}
				else
				{
					float num5 = Mathf.Clamp01((0f - (num2 - ((Component)__instance).transform.position.y)) / 1f);
					float num6 = Mathf.Lerp(0f, 10f, num5);
					Vector3 linearVelocity2 = __instance.m_body.linearVelocity;
					linearVelocity2.y = Mathf.MoveTowards(linearVelocity2.y, 0f - num6, 30f * dt);
					__instance.m_body.linearVelocity = linearVelocity2;
				}
				float num7 = 0f;
				if (((Vector3)(ref __instance.m_moveDir)).magnitude > 0.1f || __instance.AlwaysRotateCamera())
				{
					float swimTurnSpeed = __instance.m_swimTurnSpeed;
					__instance.m_seman.ApplyStatusEffectSpeedMods(ref swimTurnSpeed, __instance.m_currentVel);
					num7 = __instance.UpdateRotation(swimTurnSpeed, dt, false);
				}
				__instance.m_body.angularVelocity = Vector3.zero;
				__instance.UpdateEyeRotation();
				__instance.m_body.useGravity = true;
				float num8 = ((__instance.IsPlayer() || __instance.HaveRider()) ? Vector3.Dot(__instance.m_currentVel, ((Component)__instance).transform.forward) : Vector3.Dot(__instance.m_body.linearVelocity, ((Component)__instance).transform.forward));
				float num9 = Vector3.Dot(__instance.m_currentVel, ((Component)__instance).transform.right);
				__instance.m_currentTurnVel = Mathf.SmoothDamp(__instance.m_currentTurnVel, num7, ref __instance.m_currentTurnVelChange, 0.5f, 99f);
				__instance.m_zanim.SetFloat(_forwardSpeed, num8);
				__instance.m_zanim.SetFloat(_sidewaySpeed, num9);
				__instance.m_zanim.SetFloat(_turnSpeed, __instance.m_currentTurnVel);
				__instance.m_zanim.SetBool(_inWater, !flag);
				__instance.m_zanim.SetBool(_onGround, false);
				__instance.m_zanim.SetBool(_encumbered, false);
				__instance.m_zanim.SetBool(_flying, false);
				if (!flag)
				{
					__instance.OnSwimming(val, dt);
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
		public class GameCameraUpdateCameraPatch
		{
			public static void Prefix(GameCamera __instance, Camera ___m_camera)
			{
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Unknown result type (might be due to invalid IL or missing references)
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				//IL_0175: Unknown result type (might be due to invalid IL or missing references)
				//IL_0177: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				int num = (((_isDiving || _isSwimming) && !_restInWater) ? 1 : 0);
				__instance.m_minWaterDistance = ((num == 0) ? 0.3f : (-5000f));
				if (__instance.m_maxDistance != 4f && _maxDistance == 0f)
				{
					_maxDistance = __instance.m_maxDistance;
				}
				((Component)__instance).GetComponent<CameraEffects>();
				camera_positionY = ((Component)___m_camera).gameObject.transform.position.y;
				if (((Component)___m_camera).gameObject.transform.position.y < camera_waterLevel && (_isSwimming || _isDiving))
				{
					if (__instance.m_minWaterDistance != -5000f)
					{
						__instance.m_minWaterDistance = -5000f;
					}
					if (_isDiving)
					{
						__instance.m_maxDistance = 4f;
					}
					if (((Character)Player.m_localPlayer).m_swimDepth > 2.2f)
					{
						EnvSetup currentEnvironment = EnvMan.instance.GetCurrentEnvironment();
						Color val = ((!EnvMan.IsNight()) ? currentEnvironment.m_fogColorDay : currentEnvironment.m_fogColorNight);
						val.a = 1f;
						val = Color32.op_Implicit(ChangeColorBrightness(Color32.op_Implicit(val), c_swimDepth * _colorBrightnessFactor.Value));
						RenderSettings.fogColor = val;
						float num2 = 0f;
						if (num2 < _minFogDensity.Value)
						{
							num2 = _minFogDensity.Value;
						}
						if (num2 > _maxFogDensity.Value)
						{
							num2 = _maxFogDensity.Value;
						}
						RenderSettings.fogDensity = num2;
						camera_renderSettingsUpdate = false;
					}
					return;
				}
				if (((Component)___m_camera).gameObject.transform.position.y > camera_waterLevel && !camera_renderSettingsUpdate)
				{
					if (_maxDistance != 0f)
					{
						__instance.m_maxDistance = _maxDistance;
					}
					EnvMan.instance.SetForceEnvironment(EnvMan.instance.GetCurrentEnvironment().m_name);
					camera_renderSettingsUpdate = true;
					EnvMan.instance.SetForceEnvironment("");
				}
				if (!_isDiving && _maxDistance != 0f)
				{
					__instance.m_maxDistance = _maxDistance;
				}
				if (!_isDiving && _minWaterDistance != 0f)
				{
					__instance.m_minWaterDistance = _minWaterDistance;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "OnSwimming")]
		public class PlayerOnSwimmingPatch
		{
			public static bool Prefix(ref Vector3 targetVel, float dt, Player __instance)
			{
				//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Expected O, but got Unknown
				//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0223: Unknown result type (might be due to invalid IL or missing references)
				//IL_0228: Unknown result type (might be due to invalid IL or missing references)
				//IL_023d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0245: Unknown result type (might be due to invalid IL or missing references)
				//IL_0253: Unknown result type (might be due to invalid IL or missing references)
				//IL_0259: Unknown result type (might be due to invalid IL or missing references)
				bool flag = (Object)(object)__instance == (Object)(object)Player.m_localPlayer;
				float skillFactor = __instance.m_skills.GetSkillFactor((SkillType)103);
				float num = Mathf.Lerp(__instance.m_swimStaminaDrainMinSkill, __instance.m_swimStaminaDrainMaxSkill, skillFactor);
				if (flag && ZInput.GetKey((KeyCode)304, true))
				{
					num *= _swimStaminaDrain.Value;
				}
				num += num * ((Character)__instance).GetEquipmentSwimStaminaModifier();
				((Character)__instance).m_seman.ModifySwimStaminaUsage(num, ref num, true);
				if (((Vector3)(ref targetVel)).magnitude <= 0.1f && !_isDiving && !(((Character)__instance).m_swimDepth > 2.2f) && !((Character)__instance).IsEncumbered())
				{
					_restInWater = true;
				}
				else if (((Vector3)(ref targetVel)).magnitude <= 0.1f && _isDiving && ((Character)__instance).m_swimDepth > 2.2f && !_restInWater)
				{
					if (((Character)__instance).IsEncumbered())
					{
						((Character)__instance).UseStamina(dt * num * Game.m_moveStaminaRate);
					}
					((Character)__instance).UseStamina(dt * num * Game.m_moveStaminaRate * 0.2f);
					_restInWater = false;
				}
				if (((Vector3)(ref targetVel)).magnitude > 0.1f)
				{
					((Character)__instance).UseStamina(dt * num * Game.m_moveStaminaRate);
					__instance.m_swimSkillImproveTimer += dt;
					if (__instance.m_swimSkillImproveTimer > 1f)
					{
						__instance.m_swimSkillImproveTimer = 0f;
						((Character)__instance).RaiseSkill((SkillType)103, 1f);
					}
				}
				if (!((Character)__instance).HaveStamina(0f))
				{
					__instance.m_drownDamageTimer += dt;
					if (__instance.m_drownDamageTimer > 1f)
					{
						__instance.m_drownDamageTimer = 0f;
						float damage = Mathf.Ceil(((Character)__instance).GetMaxHealth() / 20f);
						HitData val = new HitData();
						val.m_damage.m_damage = damage;
						val.m_point = ((Character)__instance).GetCenterPoint();
						val.m_dir = Vector3.down;
						val.m_pushForce = 10f;
						val.m_hitType = (HitType)4;
						((Character)__instance).Damage(val);
						Vector3 position = ((Component)__instance).transform.position;
						position.y = ((Character)__instance).GetLiquidLevel();
						__instance.m_drownEffects.Create(position, ((Component)__instance).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
					}
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(Player), "Update")]
		public class PlayerUpdatePatch
		{
			public static void Prefix(Player __instance)
			{
				//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return;
				}
				if (!_isDiving && ((Character)Player.m_localPlayer).IsSwimming())
				{
					_restInWater = false;
				}
				if (ZInput.GetKeyDown((KeyCode)306, true))
				{
					_isDiving = true;
					_restInWater = false;
				}
				if (ZInput.GetKeyDown((KeyCode)119, true) || ZInput.GetKeyDown((KeyCode)115, true) || ZInput.GetKeyDown((KeyCode)100, true) || (ZInput.GetKeyDown((KeyCode)97, true) && ZInput.GetKeyDown((KeyCode)306, true)))
				{
					_restInWater = false;
				}
				if (_isSwimming != ((Character)Player.m_localPlayer).IsSwimming())
				{
					_isSwimming = ((Character)Player.m_localPlayer).IsSwimming();
				}
				if (_isDiving && _isSwimming && ZInput.GetKeyDown((KeyCode)32, true))
				{
					((Character)__instance).SetMoveDir(((Component)__instance).transform.forward);
					((Character)__instance).m_swimDepth = ((Character)__instance).m_swimDepth - 1f;
					if (((Character)__instance).m_swimDepth > 1.5f)
					{
						((Character)__instance).m_swimDepth = 1.5f;
					}
				}
			}
		}

		[HarmonyPatch(typeof(WaterVolume), "UpdateMaterials")]
		public class WaterVolumeUpdatePatch
		{
			public static void Prefix(WaterVolume __instance, ref float[] ___m_normalizedDepth)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_018b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: Unknown result type (might be due to invalid IL or missing references)
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)GameCamera.instance != (Object)null)
				{
					Vector3 position = ((Component)GameCamera.instance).transform.position;
					camera_waterLevel = __instance.GetWaterSurface(new Vector3(position.x, position.y, position.z), 1f);
				}
				Quaternion rotation;
				if (camera_positionY < camera_waterLevel && _isSwimming)
				{
					rotation = ((Component)((Component)__instance.m_waterSurface).GetComponent<MeshRenderer>()).transform.rotation;
					if (!((Quaternion)(ref rotation)).eulerAngles.y.Equals(180f))
					{
						((Component)__instance.m_waterSurface).transform.Rotate(180f, 0f, 0f);
						((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);
					}
					Transform transform = ((Component)__instance.m_waterSurface).transform;
					Vector3 position2 = transform.position;
					((Vector3)(ref position2))..ctor(position2.x, camera_waterLevel, position2.z);
					transform.position = position2;
					return;
				}
				rotation = ((Component)((Component)__instance.m_waterSurface).GetComponent<MeshRenderer>()).transform.rotation;
				if (((Quaternion)(ref rotation)).eulerAngles.y.Equals(180f))
				{
					((Component)__instance.m_waterSurface).transform.Rotate(-180f, 0f, 0f);
					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);
					}
					Transform transform2 = ((Component)__instance.m_waterSurface).transform;
					Vector3 position3 = transform2.position;
					((Vector3)(ref position3))..ctor(position3.x, 30f, position3.z);
					transform2.position = position3;
					((Renderer)__instance.m_waterSurface).material.SetFloat(Shader.PropertyToID("_UseGlobalWind"), __instance.m_useGlobalWind ? 1f : 0f);
				}
			}
		}

		internal static Plugin Instance;

		internal static ManualLogSource Logger;

		internal static Harmony Harmony = new Harmony("SimpleVikingsDoSwim");

		internal static float p_swimDepth = 0f;

		internal static Vector3 c_position;

		internal static float c_swimDepth = 0f;

		internal static float _diveAxis = 0f;

		public static float _maxDistance = 0f;

		public static float _waterDistance = -5000f;

		public static float _minWaterDistance = 0f;

		public static float camera_positionY;

		public static float camera_waterLevel = 30f;

		public static bool camera_renderSettingsUpdate = true;

		internal static bool _isDiving = false;

		internal static bool _isSwimming = false;

		internal static bool _restInWater = false;

		public static int _forwardSpeed;

		public static int _sidewaySpeed;

		public static int _turnSpeed;

		public static int _inWater;

		public static int _onGround;

		public static int _encumbered;

		public static int _flying;

		public static PluginConfig _swimSprintSpeed;

		public static PluginConfig _swimStaminaDrain;

		public static PluginConfig _colorBrightnessFactor;

		public static PluginConfig _minFogDensity;

		public static PluginConfig _maxFogDensity;

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			_swimSprintSpeed = new PluginConfig("General", "Swim Sprint Speed Multiplier", "Set Swim Sprint Speed Multiplier", 1.7f, 1f, 3f);
			_swimStaminaDrain = new PluginConfig("General", "Swim Stamina Drain Multiplier", "Set Swim Stamina Drain Multiplier", 2.5f, 1f, 3f);
			_colorBrightnessFactor = new PluginConfig("Underwater Effects", "Color Brightness Factor", "Brightness factor, higher value, darker surroundings.\nRecommended: -0.0392", -0.0392f, -1f, 1f);
			_minFogDensity = new PluginConfig("Underwater Effects", "Minimum Fog Density", "Minimum fog density, higher value, thicker fog.\nSet to 0 to disable fog Effect", 0.065f, 0f, 10f);
			_maxFogDensity = new PluginConfig("Underwater Effects", "Maximum Fog Density", "Maximim fog density, higher value, thicker fog.", 1.8f, 0f, 10f);
			_forwardSpeed = ZSyncAnimation.GetHash("forward_speed");
			_sidewaySpeed = ZSyncAnimation.GetHash("sideway_speed");
			_turnSpeed = ZSyncAnimation.GetHash("turn_speed");
			_inWater = ZSyncAnimation.GetHash("inWater");
			_onGround = ZSyncAnimation.GetHash("onGround");
			_encumbered = ZSyncAnimation.GetHash("encumbered");
			_flying = ZSyncAnimation.GetHash("flying");
			Harmony.PatchAll();
			Logger.LogInfo((object)"Plugin SimpleVikingsDoSwim is loaded!");
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
			Harmony.UnpatchSelf();
			Logger.LogInfo((object)"Plugin SimpleVikingsDoSwim is unloaded!");
		}

		internal static Color32 ChangeColorBrightness(Color32 color, float correctionFactor)
		{
			//IL_0001: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			int num = color.r;
			int num2 = color.g;
			int num3 = color.b;
			int a = color.a;
			if (correctionFactor < 0f)
			{
				correctionFactor *= -1f;
				num -= (int)((float)num * correctionFactor);
				num2 -= (int)((float)num2 * correctionFactor);
				num3 -= (int)((float)num3 * correctionFactor);
			}
			num = Mathf.Clamp(num, 0, 255);
			num2 = Mathf.Clamp(num2, 0, 255);
			num3 = Mathf.Clamp(num3, 0, 255);
			return new Color32((byte)num, (byte)num2, (byte)num3, (byte)a);
		}
	}
	public class PluginConfig
	{
		private ConfigEntry<bool> status = null;

		private bool LastStatus = false;

		private Action onTrigger = null;

		private ConfigEntry<float> valueConfig = null;

		public string Section { get; private set; }

		public string Name { get; private set; }

		public bool Status
		{
			get
			{
				if (status != null)
				{
					return status.Value;
				}
				return false;
			}
			set
			{
				if (status != null && status.Value != value)
				{
					status.Value = value;
				}
			}
		}

		public bool isTrigger { get; private set; } = false;

		public float Value
		{
			get
			{
				if (valueConfig != null)
				{
					return valueConfig.Value;
				}
				return 0f;
			}
			set
			{
				if (valueConfig != null)
				{
					valueConfig.Value = value;
				}
			}
		}

		public PluginConfig(string section, string name, string description, bool defaultValue, bool trigger = false)
		{
			Section = section;
			Name = name;
			isTrigger = trigger;
			status = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>(Section, (isTrigger ? "Trigger" : "Status") + " of " + Name, defaultValue, description ?? "");
		}

		public PluginConfig(string section, string name, string description, float defaultValue, float minValue, float maxValue)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			Section = section;
			Name = name;
			valueConfig = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>(Section, "Value of " + Name, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(minValue, maxValue), Array.Empty<object>()));
		}

		public PluginConfig SetAction(Action action)
		{
			onTrigger = action;
			if (valueConfig != null)
			{
				valueConfig.SettingChanged += delegate
				{
					action();
				};
			}
			return this;
		}

		public virtual void Update()
		{
			if (status != null && Status != LastStatus)
			{
				string text = Section + " " + Name + " " + (isTrigger ? "<color=green>Triggered</color>" : (Status ? "<color=green>Enabled</color>" : "<color=red>Disabled</color>"));
				if ((Object)(object)MessageHud.instance != (Object)null)
				{
					MessageHud.instance.ShowMessage((MessageType)1, text, 0, (Sprite)null, false, true);
				}
				if (onTrigger != null)
				{
					onTrigger();
				}
				if (isTrigger)
				{
					Status = false;
				}
				else
				{
					LastStatus = Status;
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SimpleVikingsDoSwim";

		public const string PLUGIN_NAME = "Simple Vikings Do Swim";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}