Decompiled source of DrakkarLantern v1.0.2

DrakkarLantern.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DrakkarLantern")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DrakkarLantern")]
[assembly: AssemblyTitle("DrakkarLantern")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 DrakkarLantern
{
	public class LanterneDeProue : MonoBehaviour
	{
		private static readonly List<LanterneDeProue> Toutes = new List<LanterneDeProue>();

		internal static bool SansAffichageAutorise = false;

		private static readonly float TanArriere = Mathf.Tan(0.38397244f);

		private static readonly float TanAvant = Mathf.Tan(0.9599311f);

		private static readonly float TanCote = Mathf.Tan(0.87266463f);

		private const float Amortissement = 0.45f;

		private const float PasMax = 1f / 90f;

		private const float EffetVent = 0.6f;

		private static readonly Vector3 Pesanteur = new Vector3(0f, -9.81f, 0f);

		private static readonly MethodInfo EnregistrerRendus = AccessTools.Method(typeof(MaterialMan), "RegisterRenderers", (Type[])null, (Type[])null);

		private Transform racine;

		private Transform pivot;

		private Renderer[] rendus = (Renderer[])(object)new Renderer[0];

		private float longueur = 1f;

		private Vector3 bob;

		private Vector3 bobPrec;

		private Vector3 pivotPrec;

		private float pasPrec = 1f / 90f;

		private bool lance;

		private bool fantome;

		internal static void Equiper(Ship ship)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			if ((Object)(object)ship == (Object)null || (Object)(object)((Component)ship).GetComponent<LanterneDeProue>() != (Object)null || ((int)SystemInfo.graphicsDeviceType == 4 && !SansAffichageAutorise) || Utils.GetPrefabName(((Component)ship).gameObject) != "VikingShip_Ashlands")
			{
				return;
			}
			ZNetView component = ((Component)ship).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null))
			{
				bool flag = component.GetZDO() == null;
				if (!flag || ZNetView.m_forceDisableInit)
				{
					((Component)ship).gameObject.AddComponent<LanterneDeProue>().fantome = flag;
				}
			}
		}

		internal static void ToutReconstruire()
		{
			foreach (LanterneDeProue item in Toutes.ToList())
			{
				if ((Object)(object)item != (Object)null)
				{
					item.Construire();
				}
			}
		}

		private void Awake()
		{
			Toutes.Add(this);
		}

		private void OnDestroy()
		{
			Toutes.Remove(this);
		}

		private void Start()
		{
			Construire();
		}

		internal void Construire()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_0114: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: 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_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			Demonter();
			if (!Plugin.Active.Value)
			{
				return;
			}
			Modeles modeles = Modeles.Obtenir();
			if (modeles == null)
			{
				return;
			}
			float value = Plugin.Taille.Value;
			racine = new GameObject("DrakkarLantern").transform;
			racine.SetParent(((Component)this).transform, false);
			racine.localPosition = Modeles.Fixation + new Vector3(0f, Plugin.DecalageHaut.Value, Plugin.DecalageAvant.Value);
			racine.localRotation = Quaternion.Euler(0f, 90f, 0f);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0.06f - modeles.BaseBras * value, (0f - modeles.Pivot.y) * value, 0f);
			Objet("Potence", modeles.Potence, modeles.Materiau, racine, val, value);
			pivot = new GameObject("Pivot").transform;
			pivot.SetParent(racine, false);
			pivot.localPosition = val + modeles.Pivot * value;
			Objet("Balancier", modeles.Balancier, modeles.Materiau, pivot, -modeles.Pivot * value, value);
			if (fantome)
			{
				int num = LayerMask.NameToLayer("ghost");
				Transform[] componentsInChildren = ((Component)racine).GetComponentsInChildren<Transform>(true);
				foreach (Transform val2 in componentsInChildren)
				{
					if (num >= 0)
					{
						((Component)val2).gameObject.layer = num;
					}
				}
				Renderer[] componentsInChildren2 = ((Component)racine).GetComponentsInChildren<Renderer>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					componentsInChildren2[i].shadowCastingMode = (ShadowCastingMode)0;
				}
			}
			else
			{
				GameObject val3 = Object.Instantiate<GameObject>(modeles.Lueur, pivot, false);
				((Object)val3).name = "Lueur";
				val3.transform.localPosition = (modeles.CentreLanterne - modeles.Pivot) * value;
				ParticleSystemForceField[] componentsInChildren3 = val3.GetComponentsInChildren<ParticleSystemForceField>(true);
				for (int i = 0; i < componentsInChildren3.Length; i++)
				{
					componentsInChildren3[i].endRange = Plugin.RayonBrume.Value;
				}
				if (!Plugin.AntiBrume.Value)
				{
					Demister[] componentsInChildren4 = val3.GetComponentsInChildren<Demister>(true);
					foreach (Demister obj in componentsInChildren4)
					{
						((Component)obj).gameObject.SetActive(false);
						Object.Destroy((Object)(object)((Component)obj).gameObject);
					}
				}
			}
			Vector3 val4 = modeles.CentreLanterne - modeles.Pivot;
			longueur = Mathf.Max(0.2f, ((Vector3)(ref val4)).magnitude * value);
			rendus = ((Component)racine).GetComponentsInChildren<Renderer>(true);
			Lod(ajouter: true);
			if ((Object)(object)MaterialMan.instance != (Object)null && EnregistrerRendus != null)
			{
				EnregistrerRendus.Invoke(MaterialMan.instance, new object[2]
				{
					((Component)this).gameObject,
					true
				});
			}
			lance = false;
		}

		private void Demonter()
		{
			Lod(ajouter: false);
			if ((Object)(object)racine != (Object)null)
			{
				((Component)racine).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)racine).gameObject);
			}
			racine = null;
			pivot = null;
			rendus = (Renderer[])(object)new Renderer[0];
		}

		private static void Objet(string nom, Mesh mesh, Material mat, Transform parent, Vector3 position, float echelle)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(nom);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = position;
			val.transform.localScale = Vector3.one * echelle;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = mat;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
		}

		private void Lod(bool ajouter)
		{
			LODGroup component = ((Component)this).GetComponent<LODGroup>();
			if ((Object)(object)component == (Object)null || rendus.Length == 0)
			{
				return;
			}
			LOD[] lODs = component.GetLODs();
			for (int i = 0; i < lODs.Length; i++)
			{
				IEnumerable<Renderer> enumerable = lODs[i].renderers.Where((Renderer r) => (Object)(object)r != (Object)null && !rendus.Contains(r));
				if (ajouter)
				{
					enumerable = enumerable.Concat(rendus);
				}
				lODs[i].renderers = enumerable.ToArray();
			}
			component.SetLODs(lODs);
		}

		private void LateUpdate()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_008a: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_016d: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: 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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: 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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)pivot == (Object)null)
			{
				return;
			}
			if (!Plugin.Balance.Value)
			{
				pivot.localRotation = Quaternion.identity;
				lance = false;
				return;
			}
			float deltaTime = Time.deltaTime;
			if (deltaTime <= 0f)
			{
				return;
			}
			deltaTime = Mathf.Min(deltaTime, 0.1f);
			Vector3 up = ((Component)this).transform.up;
			Vector3 forward = ((Component)this).transform.forward;
			Vector3 right = ((Component)this).transform.right;
			Vector3 position = pivot.position;
			Vector3 val;
			if (lance)
			{
				val = position - pivotPrec;
				if (!(((Vector3)(ref val)).sqrMagnitude > 25f))
				{
					Vector3 val2 = Pesanteur + Vent();
					int num = Mathf.Clamp(Mathf.CeilToInt(deltaTime / (1f / 90f)), 1, 10);
					float num2 = deltaTime / (float)num;
					float num3 = Mathf.Exp(-0.45f * num2);
					Vector3 val3 = (position - pivotPrec) / deltaTime;
					for (int i = 1; i <= num; i++)
					{
						Vector3 val4 = Vector3.Lerp(pivotPrec, position, (float)i / (float)num);
						Vector3 val5 = (bob - bobPrec) / pasPrec;
						val5 = val3 + (val5 - val3) * num3;
						Vector3 val6 = bob + val5 * num2 + val2 * (num2 * num2);
						val = val6 - val4;
						val6 = val4 + ((Vector3)(ref val)).normalized * longueur;
						Vector3 val7 = Borner(val4, val6, up, forward, right);
						Vector3 val8 = (val7 - bob) / num2;
						val = val7 - val6;
						if (((Vector3)(ref val)).sqrMagnitude > 1E-08f)
						{
							val8 = val3 + (val8 - val3) * 0.3f;
						}
						bob = val7;
						bobPrec = val7 - val8 * num2;
						pasPrec = num2;
					}
					goto IL_0262;
				}
			}
			val = (bob = (bobPrec = position - up * longueur));
			pasPrec = 1f / 90f;
			lance = true;
			goto IL_0262;
			IL_0262:
			pivotPrec = position;
			Vector3 val9 = bob - position;
			if (((Vector3)(ref val9)).sqrMagnitude > 1E-06f)
			{
				pivot.rotation = Quaternion.FromToRotation(-up, val9) * racine.rotation;
			}
		}

		private Vector3 Borner(Vector3 pi, Vector3 x, Vector3 haut, Vector3 avant, Vector3 droite)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_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_008a: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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)
			Vector3 val = (x - pi) / longueur;
			float num = Vector3.Dot(val, -haut);
			float num2 = Vector3.Dot(val, avant) / Mathf.Max(num, 0.05f);
			float num3 = Vector3.Dot(val, droite) / Mathf.Max(num, 0.05f);
			float num4 = Mathf.Clamp(num2, 0f - TanArriere, TanAvant);
			float num5 = Mathf.Clamp(num3, 0f - TanCote, TanCote);
			if (num >= 0.05f && num4 == num2 && num5 == num3)
			{
				return x;
			}
			Vector3 val2 = -haut + avant * num4 + droite * num5;
			return pi + ((Vector3)(ref val2)).normalized * longueur;
		}

		private static Vector3 Vent()
		{
			//IL_0016: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			EnvMan instance = EnvMan.instance;
			if (!((Object)(object)instance != (Object)null))
			{
				return Vector3.zero;
			}
			return instance.GetWindForce() * 0.6f;
		}
	}
	internal sealed class Modeles
	{
		private enum Role
		{
			Plaque,
			Bras,
			Jambe,
			Balancier
		}

		internal const string PrefabDrakkar = "VikingShip_Ashlands";

		internal static readonly Vector3 Fixation = new Vector3(0f, 6.55f, 15.75f);

		internal const float Enfoncement = 0.06f;

		internal const float Teinte = 0.55f;

		internal const float AllongementJambe = 0.193f;

		internal Mesh Potence;

		internal Mesh Balancier;

		internal Material Materiau;

		internal GameObject Lueur;

		internal Vector3 Pivot;

		internal Vector3 CentreLanterne;

		internal float BaseBras;

		private static Modeles instance;

		private static bool echec;

		private static GameObject porteur;

		private static Sprite iconeOrigine;

		private static Sprite iconeLanterne;

		private static readonly Color Fer = new Color(0.13f, 0.13f, 0.15f);

		private static readonly Color Bronze = new Color(0.36f, 0.26f, 0.16f);

		private static readonly Color Verre = new Color(0.55f, 0.92f, 1f);

		private static readonly Color HaloCouleur = new Color(0.24f, 0.67f, 1f);

		private const float HaloX = 6f;

		private const float HaloY = 51f;

		private const float HaloRayon = 6.5f;

		private const float HaloOpacite = 0.62f;

		internal static Modeles Obtenir()
		{
			if (instance != null && ((Object)(object)instance.Lueur == (Object)null || (Object)(object)instance.Materiau == (Object)null))
			{
				instance = null;
			}
			if (instance != null || echec)
			{
				return instance;
			}
			try
			{
				instance = Creer();
			}
			catch (Exception ex)
			{
				echec = true;
				Plugin.Journal.LogWarning((object)Traductions.Format("journal_modele", null, new object[1] { ex.Message }));
			}
			return instance;
		}

		private static Modeles Creer()
		{
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_018d: Expected O, but got Unknown
			ZNetScene obj = ZNetScene.instance;
			if ((Object)(object)obj == (Object)null)
			{
				throw new InvalidOperationException("ZNetScene");
			}
			GameObject prefab = obj.GetPrefab("piece_dvergr_lantern");
			GameObject prefab2 = obj.GetPrefab("piece_groundtorch_mist");
			if ((Object)(object)prefab == (Object)null || (Object)(object)prefab2 == (Object)null)
			{
				throw new InvalidOperationException(((Object)(object)prefab == (Object)null) ? "piece_dvergr_lantern" : "piece_groundtorch_mist");
			}
			Transform val = prefab.transform.Find("New/default");
			MeshFilter val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<MeshFilter>() : null);
			MeshRenderer val3 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<MeshRenderer>() : null);
			if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)((Renderer)val3).sharedMaterial == (Object)null)
			{
				throw new InvalidOperationException("piece_dvergr_lantern/New/default");
			}
			if (!val2.sharedMesh.isReadable)
			{
				throw new InvalidOperationException("piece_dvergr_lantern : maillage illisible");
			}
			Transform val4 = prefab2.transform.Find("_enabled");
			if ((Object)(object)val4 == (Object)null)
			{
				throw new InvalidOperationException("piece_groundtorch_mist/_enabled");
			}
			Modeles modeles = new Modeles();
			modeles.Decouper(val2.sharedMesh);
			Transform val5 = prefab.transform.Find("New/Point Light");
			modeles.CentreLanterne = (Vector3)(((Object)(object)val5 != (Object)null) ? val5.localPosition : new Vector3(-0.952f, -0.536f, 0f));
			modeles.Materiau = Vitres(((Renderer)val3).sharedMaterial);
			if ((Object)(object)porteur == (Object)null)
			{
				porteur = new GameObject("DrakkarLantern_modeles");
				porteur.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)porteur);
			}
			modeles.Lueur = Lueurs(((Component)val4).gameObject, porteur.transform);
			return modeles;
		}

		private void Decouper(Mesh mesh)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: 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)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] vertices = mesh.vertices;
			int[] triangles = mesh.triangles;
			int[] parent = new int[vertices.Length];
			for (int i = 0; i < vertices.Length; i++)
			{
				parent[i] = i;
			}
			Dictionary<Vector3Int, int> dictionary = new Dictionary<Vector3Int, int>();
			for (int j = 0; j < vertices.Length; j++)
			{
				Vector3Int key = Vector3Int.RoundToInt(vertices[j] * 10000f);
				if (dictionary.TryGetValue(key, out var value))
				{
					Unir(j, value);
				}
				else
				{
					dictionary[key] = j;
				}
			}
			for (int k = 0; k + 2 < triangles.Length; k += 3)
			{
				Unir(triangles[k], triangles[k + 1]);
				Unir(triangles[k], triangles[k + 2]);
			}
			Dictionary<int, Bounds> dictionary2 = new Dictionary<int, Bounds>();
			int[] array = triangles;
			foreach (int num in array)
			{
				int key2 = Racine(num);
				if (dictionary2.TryGetValue(key2, out var value2))
				{
					((Bounds)(ref value2)).Encapsulate(vertices[num]);
					dictionary2[key2] = value2;
				}
				else
				{
					dictionary2[key2] = new Bounds(vertices[num], Vector3.zero);
				}
			}
			Dictionary<int, Role> role = new Dictionary<int, Role>();
			foreach (KeyValuePair<int, Bounds> item in dictionary2)
			{
				Bounds value3 = item.Value;
				role[item.Key] = ((!(((Bounds)(ref value3)).min.x > -0.12f) || !(((Bounds)(ref value3)).size.y > 0.5f)) ? ((((Bounds)(ref value3)).size.x > 0.5f) ? Role.Bras : ((((Bounds)(ref value3)).max.x > -0.1f) ? Role.Jambe : Role.Balancier)) : Role.Plaque);
			}
			List<Bounds> list = (from kv in dictionary2
				where role[kv.Key] == Role.Bras
				select kv.Value).ToList();
			List<Bounds> list2 = (from kv in dictionary2
				where role[kv.Key] == Role.Balancier
				select kv.Value).ToList();
			if (list.Count != 1 || list2.Count < 3)
			{
				throw new InvalidOperationException($"forme inattendue : {list.Count} bras, {list2.Count} morceaux de lanterne");
			}
			Bounds val = list2.OrderByDescending((Bounds b) => ((Bounds)(ref b)).max.y).First();
			Bounds val2 = list[0];
			BaseBras = ((Bounds)(ref val2)).max.x;
			float x = ((Bounds)(ref val)).center.x;
			val2 = list[0];
			Pivot = new Vector3(x, ((Bounds)(ref val2)).center.y, 0f);
			AllongerJambe(vertices, (from i2 in Enumerable.Range(0, vertices.Length)
				where role.TryGetValue(Racine(i2), out var value4) && value4 == Role.Jambe
				select i2).ToList());
			Potence = Extraire(mesh, vertices, triangles, (int i2) => role[Racine(i2)] == Role.Bras || role[Racine(i2)] == Role.Jambe, "DrakkarLantern_potence");
			Balancier = Extraire(mesh, vertices, triangles, (int i2) => role[Racine(i2)] == Role.Balancier, "DrakkarLantern_balancier");
			int Racine(int num2)
			{
				while (parent[num2] != num2)
				{
					parent[num2] = parent[parent[num2]];
					num2 = parent[num2];
				}
				return num2;
			}
			void Unir(int a, int b)
			{
				a = Racine(a);
				b = Racine(b);
				if (a != b)
				{
					parent[a] = b;
				}
			}
		}

		private static void AllongerJambe(Vector3[] v, List<int> jambe)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			if (jambe.Count < 2)
			{
				return;
			}
			Vector3 val = v[jambe[0]];
			Vector3 val2 = v[jambe[1]];
			float num = -1f;
			Vector3 val3;
			foreach (int item in jambe)
			{
				foreach (int item2 in jambe)
				{
					val3 = v[item] - v[item2];
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (sqrMagnitude > num)
					{
						num = sqrMagnitude;
						val = v[item];
						val2 = v[item2];
					}
				}
			}
			Vector3 val4 = ((val.y > val2.y) ? val : val2);
			Vector3 val5 = ((val.y > val2.y) ? val2 : val);
			val3 = val5 - val4;
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			float num2 = Vector3.Dot((val4 + val5) * 0.5f - val4, normalized);
			foreach (int item3 in jambe)
			{
				if (Vector3.Dot(v[item3] - val4, normalized) > num2)
				{
					ref Vector3 reference = ref v[item3];
					reference += normalized * 0.193f;
				}
			}
		}

		private static Mesh Extraire(Mesh source, Vector3[] v, int[] t, Func<int, bool> garder, string nom)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] normals = source.normals;
			Vector4[] tangents = source.tangents;
			List<Vector2> list = new List<Vector2>();
			source.GetUVs(0, list);
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector3> list3 = new List<Vector3>();
			List<Vector4> list4 = new List<Vector4>();
			List<Vector2> list5 = new List<Vector2>();
			List<int> list6 = new List<int>();
			for (int i = 0; i + 2 < t.Length; i += 3)
			{
				if (!garder(t[i]))
				{
					continue;
				}
				for (int j = 0; j < 3; j++)
				{
					int num = t[i + j];
					if (!dictionary.TryGetValue(num, out var value))
					{
						value = (dictionary[num] = list2.Count);
						list2.Add(v[num]);
						if (normals.Length == v.Length)
						{
							list3.Add(normals[num]);
						}
						if (tangents.Length == v.Length)
						{
							list4.Add(tangents[num]);
						}
						if (list.Count == v.Length)
						{
							list5.Add(list[num]);
						}
					}
					list6.Add(value);
				}
			}
			Mesh val = new Mesh
			{
				name = nom
			};
			val.SetVertices(list2);
			if (list3.Count == list2.Count)
			{
				val.SetNormals(list3);
			}
			if (list4.Count == list2.Count)
			{
				val.SetTangents(list4);
			}
			if (list5.Count == list2.Count)
			{
				val.SetUVs(0, list5);
			}
			val.SetTriangles(list6, 0);
			val.RecalculateBounds();
			return val;
		}

		private static Material Vitres(Material source)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			Material val = new Material(source)
			{
				name = "DrakkarLantern_lanterne"
			};
			if ((int)SystemInfo.graphicsDeviceType == 4)
			{
				return val;
			}
			try
			{
				Texture texture = source.GetTexture("_MainTex");
				Texture texture2 = source.GetTexture("_EmissionMap");
				if ((Object)(object)texture == (Object)null || (Object)(object)texture2 == (Object)null)
				{
					throw new InvalidOperationException("textures absentes");
				}
				if (texture.width != texture2.width || texture.height != texture2.height)
				{
					throw new InvalidOperationException($"textures de tailles différentes ({texture.width}×{texture.height}, {texture2.width}×{texture2.height})");
				}
				Color32[] px = Lire(texture);
				Color32[] array = Lire(texture2);
				bool[] array2 = array.Select((Color32 c) => Math.Max(c.r, Math.Max(c.g, c.b)) > 20).ToArray();
				if (!array2.Any((bool x) => x))
				{
					throw new InvalidOperationException("vitres introuvables");
				}
				val.SetTexture("_MainTex", (Texture)(object)Ecrire(Bleuir(px, array2), texture, "DrakkarLantern_couleur"));
				val.SetTexture("_EmissionMap", (Texture)(object)Ecrire(Bleuir(array, array2), texture2, "DrakkarLantern_emission"));
			}
			catch (Exception ex)
			{
				Plugin.Journal.LogWarning((object)Traductions.Format("journal_couleur", null, new object[1] { ex.Message }));
			}
			return val;
		}

		private static Color32[] Bleuir(Color32[] px, bool[] vitre)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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)
			Color32[] array = (Color32[])px.Clone();
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			for (int i = 0; i < array.Length; i++)
			{
				if (vitre[i])
				{
					Color.RGBToHSV(Color32.op_Implicit(array[i]), ref num, ref num2, ref num3);
					Color32 val = Color32.op_Implicit(Color.HSVToRGB(0.55f, num2, num3));
					val.a = array[i].a;
					array[i] = val;
				}
			}
			return array;
		}

		private static Color32[] Lire(Texture t, Rect? zone = null)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			Rect val = (Rect)(((??)zone) ?? new Rect(0f, 0f, (float)t.width, (float)t.height));
			int num = Mathf.RoundToInt(((Rect)(ref val)).width);
			int num2 = Mathf.RoundToInt(((Rect)(ref val)).height);
			RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
			RenderTexture active = RenderTexture.active;
			Texture2D val2 = new Texture2D(num, num2, (TextureFormat)4, false, false);
			try
			{
				Graphics.Blit(t, temporary, new Vector2(((Rect)(ref val)).width / (float)t.width, ((Rect)(ref val)).height / (float)t.height), new Vector2(((Rect)(ref val)).x / (float)t.width, ((Rect)(ref val)).y / (float)t.height));
				RenderTexture.active = temporary;
				val2.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0, false);
				val2.Apply(false);
				return val2.GetPixels32();
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				Object.Destroy((Object)(object)val2);
			}
		}

		private static Texture2D Ecrire(Color32[] px, Texture modele, string nom)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			Texture2D val = new Texture2D(modele.width, modele.height, (TextureFormat)4, true, false)
			{
				name = nom,
				filterMode = modele.filterMode,
				wrapMode = modele.wrapMode,
				anisoLevel = modele.anisoLevel
			};
			val.SetPixels32(px);
			val.Apply(true, true);
			return val;
		}

		private static IEnumerable<(int x, int y, Color c)> PixelsLanterne()
		{
			for (int x = 6; x < 12; x++)
			{
				yield return (x: x, y: 47, c: Fer);
			}
			yield return (x: 6, y: 48, c: Fer);
			for (int x = 49; x <= 53; x++)
			{
				for (int i = 5; i <= 7; i++)
				{
					yield return (x: i, y: x, c: (i == 6 && x >= 50 && x <= 52) ? Verre : Bronze);
				}
			}
		}

		internal static void IconeMenu(bool avecLanterne)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Invalid comparison between Unknown and I4
			try
			{
				object obj;
				if (!((Object)(object)ZNetScene.instance != (Object)null))
				{
					obj = null;
				}
				else
				{
					GameObject prefab = ZNetScene.instance.GetPrefab("VikingShip_Ashlands");
					obj = ((prefab != null) ? prefab.GetComponent<Piece>() : null);
				}
				Piece val = (Piece)obj;
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.m_icon == (Object)null))
				{
					if ((Object)(object)val.m_icon != (Object)(object)iconeOrigine && (Object)(object)val.m_icon != (Object)(object)iconeLanterne)
					{
						iconeOrigine = val.m_icon;
						iconeLanterne = null;
					}
					if (avecLanterne && (Object)(object)iconeLanterne == (Object)null && (int)SystemInfo.graphicsDeviceType != 4)
					{
						iconeLanterne = IconeAvecLanterne(iconeOrigine);
					}
					val.m_icon = ((avecLanterne && (Object)(object)iconeLanterne != (Object)null) ? iconeLanterne : iconeOrigine);
				}
			}
			catch (Exception ex)
			{
				Plugin.Journal.LogWarning((object)Traductions.Format("journal_icone", null, new object[1] { ex.Message }));
			}
		}

		private static Sprite IconeAvecLanterne(Sprite s)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_012f: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: 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_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Expected O, but got Unknown
			//IL_0238: 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_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			Rect textureRect = s.textureRect;
			int w = Mathf.RoundToInt(((Rect)(ref textureRect)).width);
			int h = Mathf.RoundToInt(((Rect)(ref textureRect)).height);
			Color32[] px = Lire((Texture)(object)s.texture, textureRect);
			float num = (float)w / 64f;
			int num2 = Mathf.RoundToInt(6f * num);
			int num3 = Mathf.RoundToInt(51f * num);
			int num4 = Mathf.CeilToInt(6.5f * num);
			for (int i = Math.Max(0, num3 - num4); i <= Math.Min(h - 1, num3 + num4); i++)
			{
				for (int j = Math.Max(0, num2 - num4); j <= Math.Min(w - 1, num2 + num4); j++)
				{
					float num5 = Mathf.Sqrt(((float)j - 6f * num) * ((float)j - 6f * num) + ((float)i - 51f * num) * ((float)i - 51f * num)) / num;
					float num6 = 0.62f * Mathf.Pow(Mathf.Clamp01(1f - num5 / 6.5f), 2f);
					if (!(num6 <= 0f))
					{
						Color val = Color32.op_Implicit(Lu(j, i));
						float num7 = num6 + val.a * (1f - num6);
						Color val2 = (HaloCouleur * num6 + val * val.a * (1f - num6)) / Mathf.Max(num7, 1E-05f);
						val2.a = num7;
						Ecrit(j, i, Color32.op_Implicit(val2));
					}
				}
			}
			foreach (var item4 in PixelsLanterne())
			{
				int item = item4.x;
				int item2 = item4.y;
				Color item3 = item4.c;
				for (int k = 0; k < Mathf.Max(1, Mathf.RoundToInt(num)); k++)
				{
					for (int l = 0; l < Mathf.Max(1, Mathf.RoundToInt(num)); l++)
					{
						int num8 = Mathf.RoundToInt((float)item * num) + l;
						int num9 = Mathf.RoundToInt((float)item2 * num) + k;
						if (num8 < w && num9 < h)
						{
							Ecrit(num8, num9, Color32.op_Implicit(new Color(item3.r, item3.g, item3.b, 1f)));
						}
					}
				}
			}
			Texture2D val3 = new Texture2D(w, h, (TextureFormat)4, false, false)
			{
				name = "DrakkarLantern_icone",
				filterMode = ((Texture)s.texture).filterMode,
				wrapMode = (TextureWrapMode)1
			};
			val3.SetPixels32(px);
			val3.Apply(false, true);
			Rect val4 = new Rect(0f, 0f, (float)w, (float)h);
			float x = s.pivot.x;
			Rect rect = s.rect;
			float num10 = x / ((Rect)(ref rect)).width;
			float y = s.pivot.y;
			rect = s.rect;
			Sprite obj = Sprite.Create(val3, val4, new Vector2(num10, y / ((Rect)(ref rect)).height), s.pixelsPerUnit);
			((Object)obj).name = ((Object)s).name;
			return obj;
			void Ecrit(int num12, int num11, Color32 c)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				px[(h - 1 - num11) * w + num12] = c;
			}
			Color32 Lu(int num12, int num11)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				return px[(h - 1 - num11) * w + num12];
			}
		}

		private static GameObject Lueurs(GameObject allume, Transform porteur)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(allume, porteur, false);
			((Object)val).name = "Lueur";
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one;
			foreach (Transform item in ((IEnumerable)val.transform).Cast<Transform>().ToList())
			{
				GameObject gameObject = ((Component)item).gameObject;
				if (!gameObject.activeSelf || (Object)(object)gameObject.GetComponentInChildren<AudioSource>(true) != (Object)null || (Object)(object)gameObject.GetComponentInChildren<ZSFX>(true) != (Object)null || (Object)(object)gameObject.GetComponent<MeshRenderer>() != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)gameObject);
				}
			}
			Demister[] componentsInChildren = val.GetComponentsInChildren<Demister>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].m_disableForcefieldDelay = 0f;
			}
			ParticleSystem[] componentsInChildren2 = val.GetComponentsInChildren<ParticleSystem>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				MainModule main = componentsInChildren2[i].main;
				((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
			}
			return val;
		}
	}
	[BepInPlugin("com.Azura.drakkarlantern", "DrakkarLantern", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Azura.drakkarlantern";

		public const string PluginName = "DrakkarLantern";

		public const string PluginVersion = "1.0.2";

		internal static ManualLogSource Journal;

		internal static ConfigEntry<bool> Active;

		internal static ConfigEntry<bool> AntiBrume;

		internal static ConfigEntry<float> RayonBrume;

		internal static ConfigEntry<bool> Balance;

		internal static ConfigEntry<float> Taille;

		internal static ConfigEntry<float> DecalageAvant;

		internal static ConfigEntry<float> DecalageHaut;

		private void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			Journal = ((BaseUnityPlugin)this).Logger;
			Active = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Hang the wisp lantern at the bow of every drakkar.\nSuspend la lanterne de lucioles à la proue de chaque drakkar.");
			AntiBrume = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ClearsMist", true, "The lantern pushes back the Mistlands mist like a wisp torch.\nLa lanterne repousse la brume des Terres brumeuses comme une torche à lucioles.");
			RayonBrume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MistRadius", 32.4f, new ConfigDescription("Radius of the clear area around the lantern, in metres (a wisp torch clears 24 m; default 35 % more).\nRayon de la zone sans brume autour de la lanterne, en mètres (une torche à lucioles dégage 24 m ; par défaut 35 % de plus).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 60f), Array.Empty<object>()));
			Balance = ((BaseUnityPlugin)this).Config.Bind<bool>("Lantern", "Swing", true, "The lantern swings on its chain with the ship's movements (otherwise it stays still).\nLa lanterne balance au bout de sa chaîne avec les mouvements du bateau (sinon elle reste immobile).");
			Taille = ((BaseUnityPlugin)this).Config.Bind<float>("Lantern", "Scale", 1.5f, new ConfigDescription("Size of the lantern, its chain and its arm (1 = the size of the Dvergr wall lantern).\nTaille de la lanterne, de sa chaîne et de son bras (1 = la taille de la lanterne murale dvergr).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>()));
			DecalageAvant = ((BaseUnityPlugin)this).Config.Bind<float>("Lantern", "OffsetForward", 0f, new ConfigDescription("Moves where the arm is fixed on the dragon's neck, in metres (positive = towards the front).\nDéplace l'endroit où le bras est fixé sur le cou du dragon, en mètres (positif = vers l'avant).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2f, 3f), Array.Empty<object>()));
			DecalageHaut = ((BaseUnityPlugin)this).Config.Bind<float>("Lantern", "OffsetUp", 0f, new ConfigDescription("Moves where the arm is fixed on the dragon's neck, in metres (positive = higher).\nDéplace l'endroit où le bras est fixé sur le cou du dragon, en mètres (positif = plus haut).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-3f, 3f), Array.Empty<object>()));
			((BaseUnityPlugin)this).Config.SettingChanged += delegate
			{
				LanterneDeProue.ToutReconstruire();
				Modeles.IconeMenu(Active.Value);
			};
			new Harmony("com.Azura.drakkarlantern").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)Traductions.Format("journal_charge", null, new object[2] { "DrakkarLantern", "1.0.2" }));
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	public static class ZNetScene_Awake_Patch
	{
		public static void Postfix()
		{
			Modeles.IconeMenu(Plugin.Active.Value);
		}
	}
	[HarmonyPatch(typeof(Ship), "Awake")]
	public static class Ship_Awake_Patch
	{
		public static void Postfix(Ship __instance)
		{
			try
			{
				LanterneDeProue.Equiper(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Journal.LogWarning((object)Traductions.Format("journal_erreur", null, new object[1] { ex.Message }));
			}
		}
	}
	internal static class Traductions
	{
		internal static readonly string[] Langues = new string[36]
		{
			"English", "Swedish", "French", "Italian", "German", "Spanish", "Russian", "Romanian", "Bulgarian", "Macedonian",
			"Finnish", "Danish", "Norwegian", "Icelandic", "Turkish", "Lithuanian", "Czech", "Hungarian", "Slovak", "Polish",
			"Dutch", "Portuguese_European", "Portuguese_Brazilian", "Chinese", "Chinese_Trad", "Japanese", "Korean", "Hindi", "Thai", "Abenaki",
			"Croatian", "Georgian", "Greek", "Serbian", "Ukrainian", "Latvian"
		};

		private static readonly string[] Cultures = new string[36]
		{
			"en-US", "sv-SE", "fr-FR", "it-IT", "de-DE", "es-ES", "ru-RU", "ro-RO", "bg-BG", "mk-MK",
			"fi-FI", "da-DK", "nb-NO", "is-IS", "tr-TR", "lt-LT", "cs-CZ", "hu-HU", "sk-SK", "pl-PL",
			"nl-NL", "pt-PT", "pt-BR", "zh-CN", "zh-TW", "ja-JP", "ko-KR", "hi-IN", "th-TH", "en-US",
			"hr-HR", "ka-GE", "el-GR", "sr-Latn-RS", "uk-UA", "lv-LV"
		};

		internal static readonly Dictionary<string, string[]> Textes;

		private static readonly FieldInfo TraductionDuJeu;

		private static bool jeuPret;

		internal static string LangueDuJeu
		{
			get
			{
				try
				{
					if (!jeuPret)
					{
						if (TraductionDuJeu != null && TraductionDuJeu.GetValue(null) == null)
						{
							return PlayerPrefs.GetString("language", "English");
						}
						jeuPret = true;
					}
					return Localization.instance.GetSelectedLanguage();
				}
				catch (Exception)
				{
					return "English";
				}
			}
		}

		internal static string Texte(string cle, string langue = null)
		{
			if (!Textes.TryGetValue(cle, out var value))
			{
				return cle;
			}
			int num = Array.IndexOf(Langues, langue ?? LangueDuJeu);
			if (num <= 0 || num >= value.Length || string.IsNullOrEmpty(value[num]))
			{
				return value[0];
			}
			return value[num];
		}

		internal static string Format(string cle, string langue, object[] valeurs)
		{
			string text = Texte(cle, langue);
			if (valeurs != null && valeurs.Length != 0)
			{
				return string.Format(Culture(langue), text, valeurs);
			}
			return text;
		}

		internal static CultureInfo Culture(string langue = null)
		{
			int num = Array.IndexOf(Langues, langue ?? LangueDuJeu);
			try
			{
				return CultureInfo.GetCultureInfo((num >= 0) ? Cultures[num] : "en-US");
			}
			catch
			{
				return CultureInfo.InvariantCulture;
			}
		}

		static Traductions()
		{
			Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>();
			string[] array = new string[36];
			array[0] = "{0} v{1} loaded.";
			array[2] = "{0} v{1} chargé.";
			dictionary["journal_charge"] = array;
			string[] array2 = new string[36];
			array2[0] = "The drakkar lantern can't be built ({0}): drakkars keep their usual look.";
			array2[2] = "Impossible de préparer la lanterne du drakkar ({0}) : les drakkars gardent leur aspect habituel.";
			dictionary["journal_modele"] = array2;
			string[] array3 = new string[36];
			array3[0] = "The lantern glass couldn't be turned blue ({0}): it keeps the game's yellow glass.";
			array3[2] = "Les vitres de la lanterne n'ont pas pu passer au bleu ({0}) : elles gardent le jaune du jeu.";
			dictionary["journal_couleur"] = array3;
			string[] array4 = new string[36];
			array4[0] = "No lantern added to a drakkar: {0}";
			array4[2] = "Lanterne non ajoutée à un drakkar : {0}";
			dictionary["journal_erreur"] = array4;
			string[] array5 = new string[36];
			array5[0] = "The drakkar's icon in the build menu couldn't get its lantern ({0}): it keeps the game's icon.";
			array5[2] = "L'icône du drakkar dans le menu de construction n'a pas pu recevoir sa lanterne ({0}) : elle garde celle du jeu.";
			dictionary["journal_icone"] = array5;
			Textes = dictionary;
			TraductionDuJeu = typeof(Localization).GetField("m_instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		}
	}
}