Decompiled source of SCT Perk MiningReach v2.0.0

plugins/SCTPerk.MiningReach.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SCTCommon;
using TMPro;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SCTPerk.MiningReach")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SCTPerk.MiningReach")]
[assembly: AssemblyTitle("SCTPerk.MiningReach")]
[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 SCTCommon
{
	internal static class Il2CppUtil
	{
		public static bool IsPlayer(Driller driller)
		{
			if (driller != null)
			{
				return (Object)(object)((Il2CppObjectBase)driller).TryCast<Player>() != (Object)null;
			}
			return false;
		}

		public static string Guid(BasePlugin plugin)
		{
			return MetadataHelper.GetMetadata((object)plugin).GUID;
		}

		public static IEnumerable<PluginInfo> Plugins()
		{
			if (IL2CPPChainloader.Instance == null)
			{
				yield break;
			}
			foreach (PluginInfo value in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.Values)
			{
				yield return value;
			}
		}
	}
	internal static class Safe
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("SCT Safe");

		private static readonly HashSet<string> Reported = new HashSet<string>();

		public static void Run(string where, Action action)
		{
			try
			{
				action();
			}
			catch (Exception e)
			{
				Report(where, e);
			}
		}

		public static bool Prefix(string where, Func<bool> prefix)
		{
			try
			{
				return prefix();
			}
			catch (Exception e)
			{
				Report(where, e);
				return true;
			}
		}

		private static void Report(string where, Exception e)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			if (Reported.Add(where + e.GetType().Name + e.Message))
			{
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(33, 4, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(where);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" : ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.GetType().Name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" : ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.Message);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (ignoré, le jeu continue)\n");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.StackTrace);
				}
				Log.LogError(val);
			}
		}
	}
	internal static class Vanilla
	{
		private const string Key = "sct.vanilla";

		public static bool Active
		{
			get
			{
				object data = AppDomain.CurrentDomain.GetData("sct.vanilla");
				bool flag = default(bool);
				int num;
				if (data is bool)
				{
					flag = (bool)data;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
		}

		public static void Set(bool active)
		{
			AppDomain.CurrentDomain.SetData("sct.vanilla", active);
		}
	}
	internal static class Lang
	{
		public static bool IsFrench
		{
			get
			{
				try
				{
					Locale selectedLocale = LocalizationSettings.SelectedLocale;
					return ((selectedLocale != null) ? selectedLocale.Identifier.Code : null)?.StartsWith("fr", StringComparison.OrdinalIgnoreCase) ?? false;
				}
				catch (Exception)
				{
					return false;
				}
			}
		}

		public static string Pick(string fr, string en)
		{
			if (!IsFrench)
			{
				return en;
			}
			return fr;
		}
	}
	internal static class PlayerLight
	{
		private static readonly Dictionary<IntPtr, bool> IsPlayerEmitter = new Dictionary<IntPtr, bool>();

		private static readonly List<IntPtr> Scaled = new List<IntPtr>(8);

		public static void Scale(LightEmitter emitter, float multiplier)
		{
			if (!IsPlayerEmitter.TryGetValue(((Il2CppObjectBase)emitter).Pointer, out var value))
			{
				value = (Object)(object)((Component)emitter).GetComponentInParent<Build>() == (Object)null;
				IsPlayerEmitter[((Il2CppObjectBase)emitter).Pointer] = value;
			}
			if (value)
			{
				Scaled.Clear();
				Apply((Component)(object)emitter.lightRenderer, multiplier);
				Apply((Component)(object)emitter.smallLightRenderer, multiplier);
				Apply((Component)(object)emitter.smallMask, multiplier);
				Apply((Component)(object)emitter.bigMask, multiplier);
				Apply((Component)(object)emitter.shadowMask, multiplier);
				Apply((Component)(object)emitter.backgroundMask, multiplier);
			}
		}

		private static void Apply(Component component, float multiplier)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)component == (Object)null))
			{
				Transform transform = component.transform;
				if (!Scaled.Contains(((Il2CppObjectBase)transform).Pointer))
				{
					Scaled.Add(((Il2CppObjectBase)transform).Pointer);
					transform.localScale *= multiplier;
				}
			}
		}
	}
	internal static class CraftCosts
	{
		private const string OwnerKey = "sct.craft.owner";

		private const string ProvidersKey = "sct.craft.providers";

		private const float MinFactor = 0.25f;

		private const int MaxBuildId = 512;

		private static readonly Dictionary<int, int[]> Originals = new Dictionary<int, int[]>();

		private static float _appliedFactor = 1f;

		private static bool _isOwner;

		public static float Factor
		{
			get
			{
				float num = 1f;
				if (AppDomain.CurrentDomain.GetData("sct.craft.providers") is Dictionary<string, Func<float>> dictionary)
				{
					foreach (Func<float> value in dictionary.Values)
					{
						try
						{
							num *= 1f - Mathf.Clamp(value(), 0f, 0.9f);
						}
						catch (Exception)
						{
						}
					}
				}
				return Mathf.Max(0.25f, num);
			}
		}

		public static void RegisterDiscount(string id, Func<float> discount)
		{
			lock (AppDomain.CurrentDomain)
			{
				Dictionary<string, Func<float>> dictionary = (AppDomain.CurrentDomain.GetData("sct.craft.providers") as Dictionary<string, Func<float>>) ?? new Dictionary<string, Func<float>>();
				dictionary[id] = discount;
				AppDomain.CurrentDomain.SetData("sct.craft.providers", dictionary);
			}
		}

		public static void Install(Harmony harmony, string owner)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			lock (AppDomain.CurrentDomain)
			{
				if (AppDomain.CurrentDomain.GetData("sct.craft.owner") != null)
				{
					return;
				}
				AppDomain.CurrentDomain.SetData("sct.craft.owner", owner);
				_isOwner = true;
			}
			HarmonyMethod val = new HarmonyMethod(typeof(CraftCosts), "SyncPrefix", (Type[])null);
			string[] array = new string[3] { "Open", "RefreshCostItems", "TryPurchase" };
			foreach (string text in array)
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(CraftMenu), text, (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
		}

		private static void SyncPrefix()
		{
			Safe.Run("Coûts de craft", Sync);
		}

		public static void Sync()
		{
			//IL_002f: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			if (!_isOwner)
			{
				return;
			}
			Dictionary<BuildType, List<ResourceTypeQuantity>> craftingCosts = CraftMenu._craftingCosts;
			if (craftingCosts == null)
			{
				return;
			}
			float factor = Factor;
			bool flag = !Mathf.Approximately(factor, _appliedFactor);
			for (int i = 0; i < 512; i++)
			{
				BuildType val = (BuildType)i;
				if (!craftingCosts.ContainsKey(val))
				{
					continue;
				}
				List<ResourceTypeQuantity> val2 = craftingCosts[val];
				if (!Originals.TryGetValue(i, out var value) || value.Length != val2.Count)
				{
					value = new int[val2.Count];
					for (int j = 0; j < val2.Count; j++)
					{
						value[j] = val2[j].quantity;
					}
					Originals[i] = value;
					flag = true;
				}
				if (flag)
				{
					for (int k = 0; k < val2.Count; k++)
					{
						ResourceTypeQuantity val3 = val2[k];
						val3.quantity = ((factor >= 1f) ? value[k] : Mathf.Max(1, Mathf.CeilToInt((float)value[k] * factor)));
						val2[k] = val3;
					}
				}
			}
			_appliedFactor = factor;
		}

		public static void AddRecipe(BuildType type, params (ResourceType Resource, int Quantity)[] ingredients)
		{
			//IL_001a: 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_002b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<BuildType, List<ResourceTypeQuantity>> craftingCosts = CraftMenu._craftingCosts;
			List<ResourceTypeQuantity> val = new List<ResourceTypeQuantity>();
			for (int i = 0; i < ingredients.Length; i++)
			{
				var (resourceType, quantity) = ingredients[i];
				val.Add(new ResourceTypeQuantity
				{
					resourceType = resourceType,
					quantity = quantity
				});
			}
			craftingCosts[type] = val;
		}
	}
	internal static class PngLoader
	{
		public static Texture2D LoadTexture(byte[] png)
		{
			//IL_0092: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00b9: Expected O, but got Unknown
			//IL_0068: 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)
			int width;
			int height;
			byte[] array = Decode(png, out width, out height);
			Color[] array2 = (Color[])(object)new Color[width * height];
			for (int i = 0; i < height; i++)
			{
				int num = (height - 1 - i) * width * 4;
				int num2 = i * width;
				int num3 = 0;
				while (num3 < width)
				{
					array2[num2 + num3] = new Color((float)(int)array[num] / 255f, (float)(int)array[num + 1] / 255f, (float)(int)array[num + 2] / 255f, (float)(int)array[num + 3] / 255f);
					num3++;
					num += 4;
				}
			}
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1
			};
			val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array2));
			val.Apply(false);
			return val;
		}

		public static byte[] Decode(byte[] png, out int width, out int height)
		{
			if (png.Length < 8 || png[0] != 137 || png[1] != 80 || png[2] != 78 || png[3] != 71)
			{
				throw new InvalidDataException("pas un PNG");
			}
			width = (height = 0);
			int num = -1;
			byte[] array = null;
			byte[] array2 = null;
			using MemoryStream memoryStream = new MemoryStream();
			int num3;
			int num4;
			for (int num2 = 8; num2 + 8 <= png.Length; num2 = num4 + num3 + 4)
			{
				num3 = ReadInt(png, num2);
				string text = Encoding.ASCII.GetString(png, num2 + 4, 4);
				num4 = num2 + 8;
				if (num3 < 0 || num4 + num3 > png.Length)
				{
					throw new InvalidDataException("PNG tronqué");
				}
				switch (text)
				{
				case "IHDR":
					width = ReadInt(png, num4);
					height = ReadInt(png, num4 + 4);
					num = png[num4 + 9];
					if (png[num4 + 8] == 8 && png[num4 + 12] == 0)
					{
						continue;
					}
					throw new NotSupportedException("PNG 8 bits non entrelacé attendu");
				case "PLTE":
					array = png.AsSpan(num4, num3).ToArray();
					continue;
				case "tRNS":
					array2 = png.AsSpan(num4, num3).ToArray();
					continue;
				case "IDAT":
					memoryStream.Write(png, num4, num3);
					continue;
				default:
					continue;
				case "IEND":
					break;
				}
				break;
			}
			int num5 = num switch
			{
				0 => 1, 
				2 => 3, 
				3 => 1, 
				4 => 2, 
				6 => 4, 
				_ => throw new NotSupportedException($"type de couleur PNG {num}"), 
			};
			if (width <= 0 || height <= 0)
			{
				throw new InvalidDataException("PNG sans en-tête");
			}
			if (num == 3 && array == null)
			{
				throw new InvalidDataException("PNG sans palette");
			}
			int num6 = width * num5;
			byte[] array3 = new byte[(num6 + 1) * height];
			memoryStream.Position = 0L;
			using (ZLibStream zLibStream = new ZLibStream(memoryStream, CompressionMode.Decompress))
			{
				int num7;
				for (int i = 0; i < array3.Length; i += num7)
				{
					num7 = zLibStream.Read(array3, i, array3.Length - i);
					if (num7 <= 0)
					{
						throw new InvalidDataException("données PNG incomplètes");
					}
				}
			}
			byte[] array4 = new byte[num6 * height];
			for (int j = 0; j < height; j++)
			{
				int num8 = array3[j * (num6 + 1)];
				int num9 = j * (num6 + 1) + 1;
				int num10 = j * num6;
				int num11 = num10 - num6;
				for (int k = 0; k < num6; k++)
				{
					int num12 = ((k >= num5) ? array4[num10 + k - num5] : 0);
					int num13 = ((j > 0) ? array4[num11 + k] : 0);
					int upLeft = ((j > 0 && k >= num5) ? array4[num11 + k - num5] : 0);
					int num14 = num8 switch
					{
						0 => 0, 
						1 => num12, 
						2 => num13, 
						3 => (num12 + num13) / 2, 
						4 => Paeth(num12, num13, upLeft), 
						_ => throw new InvalidDataException($"filtre PNG {num8}"), 
					};
					array4[num10 + k] = (byte)(array3[num9 + k] + num14);
				}
			}
			if (num == 6)
			{
				return array4;
			}
			byte[] array5 = new byte[width * height * 4];
			int num15 = 0;
			int num16 = 0;
			int num17 = 0;
			while (num15 < width * height)
			{
				switch (num)
				{
				case 0:
					array5[num17] = (array5[num17 + 1] = (array5[num17 + 2] = array4[num16]));
					array5[num17 + 3] = byte.MaxValue;
					break;
				case 2:
					array5[num17] = array4[num16];
					array5[num17 + 1] = array4[num16 + 1];
					array5[num17 + 2] = array4[num16 + 2];
					array5[num17 + 3] = byte.MaxValue;
					break;
				case 3:
				{
					int num18 = array4[num16];
					if (num18 * 3 + 2 >= array.Length)
					{
						throw new InvalidDataException("couleur hors palette");
					}
					array5[num17] = array[num18 * 3];
					array5[num17 + 1] = array[num18 * 3 + 1];
					array5[num17 + 2] = array[num18 * 3 + 2];
					array5[num17 + 3] = ((array2 != null && num18 < array2.Length) ? array2[num18] : byte.MaxValue);
					break;
				}
				case 4:
					array5[num17] = (array5[num17 + 1] = (array5[num17 + 2] = array4[num16]));
					array5[num17 + 3] = array4[num16 + 1];
					break;
				}
				num15++;
				num16 += num5;
				num17 += 4;
			}
			return array5;
		}

		private static int ReadInt(byte[] bytes, int offset)
		{
			return (bytes[offset] << 24) | (bytes[offset + 1] << 16) | (bytes[offset + 2] << 8) | bytes[offset + 3];
		}

		private static int Paeth(int left, int up, int upLeft)
		{
			int num = left + up - upLeft;
			int num2 = Math.Abs(num - left);
			int num3 = Math.Abs(num - up);
			int num4 = Math.Abs(num - upLeft);
			if (num2 > num3 || num2 > num4)
			{
				if (num3 > num4)
				{
					return upLeft;
				}
				return up;
			}
			return left;
		}
	}
	internal static class RefundBonus
	{
		private const string ProvidersKey = "sct.refund.providers";

		private const string ActiveKey = "sct.refund.active";

		public static bool SalvageActive
		{
			get
			{
				if (!(AppDomain.CurrentDomain.GetData("sct.refund.active") is Dictionary<string, Func<bool>> dictionary))
				{
					return false;
				}
				foreach (Func<bool> value in dictionary.Values)
				{
					try
					{
						if (value())
						{
							return true;
						}
					}
					catch (Exception)
					{
					}
				}
				return false;
			}
		}

		public static float Total
		{
			get
			{
				float num = 0f;
				if (AppDomain.CurrentDomain.GetData("sct.refund.providers") is Dictionary<string, Func<float>> dictionary)
				{
					foreach (Func<float> value in dictionary.Values)
					{
						try
						{
							num += Mathf.Max(0f, value());
						}
						catch (Exception)
						{
						}
					}
				}
				return num;
			}
		}

		public static void Register(string id, Func<float> bonus, Func<bool> active)
		{
			lock (AppDomain.CurrentDomain)
			{
				Dictionary<string, Func<float>> dictionary = (AppDomain.CurrentDomain.GetData("sct.refund.providers") as Dictionary<string, Func<float>>) ?? new Dictionary<string, Func<float>>();
				dictionary[id] = bonus;
				AppDomain.CurrentDomain.SetData("sct.refund.providers", dictionary);
				Dictionary<string, Func<bool>> dictionary2 = (AppDomain.CurrentDomain.GetData("sct.refund.active") as Dictionary<string, Func<bool>>) ?? new Dictionary<string, Func<bool>>();
				dictionary2[id] = active;
				AppDomain.CurrentDomain.SetData("sct.refund.active", dictionary2);
			}
		}
	}
	internal static class RunEnd
	{
		public static bool WillEndThisFrame(Game game)
		{
			if ((Object)(object)game != (Object)null && !game._runEnded && !game.paused && game.started && game._runTimer <= 0f)
			{
				return game._runTimerTick + Time.deltaTime >= 1f;
			}
			return false;
		}
	}
	internal static class SaveSlotApi
	{
		private const string VersionKey = "sct.saveslot.version";

		public const string Prefix = "sct_";

		public static string Directory => GameInstance.SaveDirectory;

		public static int Version
		{
			get
			{
				object data = AppDomain.CurrentDomain.GetData("sct.saveslot.version");
				if (data is int)
				{
					return (int)data;
				}
				return 0;
			}
		}

		public static string PathOf(string name)
		{
			return Path.Combine(Directory, "sct_" + name);
		}

		public static void BumpVersion()
		{
			AppDomain.CurrentDomain.SetData("sct.saveslot.version", Version + 1);
		}

		public static void Migrate(string oldPath, string name)
		{
			try
			{
				string text = PathOf(name);
				if (File.Exists(oldPath) && !File.Exists(text))
				{
					File.Move(oldPath, text);
				}
			}
			catch (Exception)
			{
			}
		}
	}
	internal static class GameInstance
	{
		private const string IndexKey = "sct.instance.index";

		private const string MutexKey = "sct.instance.mutex";

		private const string ErrorKey = "sct.instance.error";

		private const string MutexName = "SCT_SpaceCatDigger_Instance_";

		public const int Max = 4;

		public static int Index
		{
			get
			{
				object data = AppDomain.CurrentDomain.GetData("sct.instance.index");
				if (data is int)
				{
					return (int)data;
				}
				int i = 0;
				Mutex data2 = null;
				for (; i < 4; i++)
				{
					bool createdNew;
					Mutex mutex = new Mutex(initiallyOwned: false, "SCT_SpaceCatDigger_Instance_" + i, out createdNew);
					if (createdNew)
					{
						data2 = mutex;
						break;
					}
					mutex.Dispose();
				}
				AppDomain.CurrentDomain.SetData("sct.instance.mutex", data2);
				AppDomain.CurrentDomain.SetData("sct.instance.index", i);
				if (i > 0)
				{
					PrepareTestSaves(i);
				}
				return i;
			}
		}

		public static bool IsTest => Index > 0;

		public static string Suffix
		{
			get
			{
				if (!IsTest)
				{
					return "";
				}
				return "_test" + (Index + 1);
			}
		}

		public static string SaveDirectory => DirectoryOf(Index);

		public static string Error => AppDomain.CurrentDomain.GetData("sct.instance.error") as string;

		private static string DirectoryOf(int index)
		{
			if (index <= 0)
			{
				return Application.persistentDataPath;
			}
			return Path.Combine(Application.persistentDataPath, "coop_test_" + (index + 1));
		}

		public static int OthersRunning()
		{
			int index = Index;
			int num = 0;
			for (int i = 0; i < 4; i++)
			{
				if (i != index && Mutex.TryOpenExisting("SCT_SpaceCatDigger_Instance_" + i, out Mutex result))
				{
					result.Dispose();
					num++;
				}
			}
			return num;
		}

		private static void PrepareTestSaves(int index)
		{
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			ManualLogSource val = Logger.CreateLogSource("SCT Instance");
			bool flag = default(bool);
			try
			{
				string persistentDataPath = Application.persistentDataPath;
				string text = DirectoryOf(index);
				Directory.CreateDirectory(text);
				string[] files = Directory.GetFiles(text);
				for (int i = 0; i < files.Length; i++)
				{
					File.Delete(files[i]);
				}
				files = Directory.GetFiles(persistentDataPath);
				foreach (string text2 in files)
				{
					string fileName = Path.GetFileName(text2);
					if (fileName == "persistent.save" || fileName.StartsWith("sct_", StringComparison.Ordinal))
					{
						File.Copy(text2, Path.Combine(text, fileName), overwrite: true);
					}
				}
				string text3 = text + "/game.save";
				string text4 = text + "/persistent.save";
				SaveSystem.GameFileName = text3;
				SaveSystem.PersistentFileName = text4;
				if (SaveSystem.GameFileName != text3 || SaveSystem.PersistentFileName != text4)
				{
					throw new InvalidOperationException("chemins de sauvegarde du jeu non modifiables");
				}
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(58, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Exemplaire n° ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(index + 1);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" du jeu sur ce PC : sauvegarde de test dans ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
				}
				val.LogInfo(val2);
			}
			catch (Exception ex)
			{
				AppDomain.CurrentDomain.SetData("sct.instance.error", ex.Message);
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(97, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Exemplaire n° ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(index + 1);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" : sauvegarde de test impossible (");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("). CET EXEMPLAIRE ÉCRIT DANS LA VRAIE SAUVEGARDE.");
				}
				val.LogError(val3);
			}
		}
	}
}
namespace SCTPerks
{
	internal static class ExtraHits
	{
		private const string Key = "sct.perk.extraHits";

		public static bool Active
		{
			get
			{
				if (AppDomain.CurrentDomain.GetData("sct.perk.extraHits") is int num)
				{
					return num > 0;
				}
				return false;
			}
		}

		public static void Run(Action hits)
		{
			int num = ((AppDomain.CurrentDomain.GetData("sct.perk.extraHits") is int num2) ? num2 : 0);
			AppDomain.CurrentDomain.SetData("sct.perk.extraHits", num + 1);
			try
			{
				hits();
			}
			finally
			{
				AppDomain.CurrentDomain.SetData("sct.perk.extraHits", num);
			}
		}
	}
	internal static class Mining
	{
		public static Vector3Int Forward(Vector2 hitDirection)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			return new Vector3Int(-Mathf.RoundToInt(hitDirection.x), -Mathf.RoundToInt(hitDirection.y), 0);
		}

		public static Vector3Int Side(Vector3Int forward)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3Int(((Vector3Int)(ref forward)).y, ((Vector3Int)(ref forward)).x, 0);
		}

		public static TileData Tile(BlockManager blocks, Vector3Int cell)
		{
			//IL_0008: 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)
			Dictionary<Vector3Int, TileData> tileDatas = blocks.TileDatas;
			if (!tileDatas.ContainsKey(cell))
			{
				return null;
			}
			return tileDatas[cell];
		}

		public static bool IsMineable(BlockManager blocks, Vector3Int cell)
		{
			//IL_0001: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			TileData val = Tile(blocks, cell);
			if (val != null && !val.locked && val.health > 0)
			{
				if ((int)val.tileType != 0 && (int)val.tileType != 1)
				{
					return (int)val.tileType == 3;
				}
				return true;
			}
			return false;
		}

		public static void RevealOre(BlockManager blocks, Vector3Int cell)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			TileData val = Tile(blocks, cell);
			if (val != null && (int)val.tileType == 1 && !val.visibleOre)
			{
				val.ShowOre();
				val.RefreshOre();
			}
		}
	}
	internal struct HitState
	{
		public bool ByPlayer;

		public bool WasStanding;

		public TileType TileType;

		public static HitState Capture(BlockManager blocks, Vector3Int position, Driller driller)
		{
			//IL_0018: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			HitState result = new HitState
			{
				ByPlayer = Il2CppUtil.IsPlayer(driller)
			};
			TileData val = Mining.Tile(blocks, position);
			if (val != null)
			{
				result.WasStanding = val.health > 0;
				result.TileType = val.tileType;
			}
			return result;
		}

		public bool BrokeTile(BlockManager blocks, Vector3Int position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			TileData val = Mining.Tile(blocks, position);
			if (ByPlayer && WasStanding)
			{
				if (val != null)
				{
					return val.health <= 0;
				}
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(AudioManager), "PlayRandomized")]
	internal static class ExtraHitsMutePatch
	{
		private static bool Prefix()
		{
			return !ExtraHits.Active;
		}
	}
	[HarmonyPatch(typeof(AudioManager), "PlaySpatialRandomized")]
	internal static class ExtraHitsMuteSpatialPatch
	{
		private static bool Prefix(ref AudioSource __result)
		{
			if (!ExtraHits.Active)
			{
				return true;
			}
			__result = null;
			return false;
		}
	}
	internal readonly struct Text
	{
		public readonly string Fr;

		public readonly string En;

		private Text(string fr, string en)
		{
			Fr = fr;
			En = en;
		}

		public static Text Of(string fr, string en)
		{
			return new Text(fr, en);
		}

		public static string Pick(string fr, string en)
		{
			return Lang.Pick(fr, en);
		}

		public override string ToString()
		{
			return Lang.Pick(Fr, En);
		}
	}
	internal class PerkDefinition
	{
		public UpgradeType Type;

		public Text Name;

		public UpgradeType IconSource;

		public float BaseValue;

		public TemporaryUpgradeRarity MinRarity;

		public float CommonDelta;

		public float RareDelta;

		public float EpicDelta;

		public float LegendaryDelta;

		public float DefaultMaxValue;

		public Func<TemporaryUpgradeChoice, string> FormatChoice;

		public Func<float, string> FormatHud;

		public float GetValue()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)UpgradeManager.Instance != (Object)null))
			{
				return BaseValue;
			}
			return UpgradeManager.Instance.GetValue(Type);
		}
	}
	public abstract class PerkPlugin : BasePlugin
	{
		internal static PerkDefinition Definition;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<float> MaxValue;

		internal static ConfigEntry<bool> ShowInHud;

		internal static readonly Dictionary<TemporaryUpgradeRarity, ConfigEntry<float>> Deltas = new Dictionary<TemporaryUpgradeRarity, ConfigEntry<float>>();

		internal static ConfigFile PerkConfig;

		internal static ManualLogSource PerkLog;

		public UpgradeType PerkType => Definition.Type;

		public string PerkName => Definition.Name.ToString();

		internal static bool IsCapped
		{
			get
			{
				if (MaxValue.Value > 0f)
				{
					return Definition.GetValue() >= MaxValue.Value - 0.0001f;
				}
				return false;
			}
		}

		internal abstract PerkDefinition CreateDefinition();

		protected virtual void BindConfig()
		{
		}

		public override void Load()
		{
			//IL_0109: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Expected O, but got Unknown
			Definition = CreateDefinition();
			PerkConfig = ((BasePlugin)this).Config;
			PerkLog = ((BasePlugin)this).Log;
			string fr = Definition.Name.Fr;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("Perk", "Enabled", true, "Ajoute la perk " + fr + " aux choix de level up.");
			MaxValue = ((BasePlugin)this).Config.Bind<float>("Perk", "MaxValue", Definition.DefaultMaxValue, "Plafond de la valeur cumulée (0 = pas de plafond). Plafond atteint : la perk n'est plus proposée.");
			if (Definition.FormatHud != null)
			{
				ShowInHud = ((BasePlugin)this).Config.Bind<bool>("Perk", "ShowInHud", true, "Affiche le bonus cumulé dans la liste des stats (à gauche de l'écran) dès que la perk est prise.");
			}
			float[] array = new float[4] { Definition.CommonDelta, Definition.RareDelta, Definition.EpicDelta, Definition.LegendaryDelta };
			foreach (TemporaryUpgradeRarity value in Enum.GetValues(typeof(TemporaryUpgradeRarity)))
			{
				if (value >= Definition.MinRarity)
				{
					Deltas[value] = ((BasePlugin)this).Config.Bind<float>("Rarete", ((object)value/*cast due to .constrained prefix*/).ToString(), array[value], $"Gain par perk {value}.");
				}
			}
			BindConfig();
			PerkIcons.Load(((object)this).GetType().Assembly, ((BasePlugin)this).Log);
			new Harmony(Il2CppUtil.Guid((BasePlugin)(object)this)).PatchAll(((object)this).GetType().Assembly);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(13, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Perk ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(fr);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" chargée");
			}
			log.LogInfo(val2);
		}

		internal static float GetDelta(TemporaryUpgradeRarity rarity)
		{
			//IL_0000: 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_001e: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			if (rarity < Definition.MinRarity)
			{
				rarity = Definition.MinRarity;
			}
			if (!Deltas.TryGetValue(rarity, out var value))
			{
				return 0f;
			}
			return value.Value;
		}

		internal static float Cap(float value)
		{
			if (!(MaxValue.Value > 0f))
			{
				return value;
			}
			return Mathf.Min(value, MaxValue.Value);
		}
	}
	internal static class PerkIcons
	{
		private static readonly Dictionary<TemporaryUpgradeRarity, Sprite> Sprites = new Dictionary<TemporaryUpgradeRarity, Sprite>();

		private static Sprite _default;

		public static void Load(Assembly assembly, ManualLogSource log)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_002d: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				_default = LoadSprite(assembly, "icons/icon.png");
				foreach (TemporaryUpgradeRarity value in Enum.GetValues(typeof(TemporaryUpgradeRarity)))
				{
					Sprite val = LoadSprite(assembly, "icons/icon_" + ((object)value/*cast due to .constrained prefix*/).ToString().ToLowerInvariant() + ".png");
					if ((Object)(object)val != (Object)null)
					{
						Sprites[value] = val;
					}
				}
			}
			catch (Exception ex)
			{
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(57, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Icônes de perk non chargées (");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(") : icône empruntée utilisée");
				}
				log.LogWarning(val2);
			}
		}

		public static Sprite Get(TemporaryUpgradeRarity rarity)
		{
			//IL_0005: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			if (Sprites.TryGetValue(rarity, out var value))
			{
				return value;
			}
			if ((Object)(object)_default != (Object)null)
			{
				return _default;
			}
			if (!((Object)(object)SpriteManager.Instance != (Object)null))
			{
				return null;
			}
			return SpriteManager.Instance.GetTemporaryUpgradeIcon(PerkPlugin.Definition.IconSource, rarity);
		}

		private static Sprite LoadSprite(Assembly assembly, string resource)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			using Stream stream = assembly.GetManifestResourceStream(resource);
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = PngLoader.LoadTexture(array);
			((Object)val).hideFlags = (HideFlags)61;
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}
	}
	[HarmonyPatch(typeof(PlayerStatsHUD), "Refresh")]
	internal static class PerkHudPatch
	{
		private static StatLineUI _line;

		private static int _hud;

		private static void Postfix(PlayerStatsHUD __instance)
		{
			Safe.Run("Perk " + PerkPlugin.Definition.Name.Fr + " stats", delegate
			{
				Refresh(__instance);
			});
		}

		internal static void Refresh()
		{
			if ((Object)(object)PlayerStatsHUD.Instance != (Object)null)
			{
				Safe.Run("Perk " + PerkPlugin.Definition.Name.Fr + " stats", delegate
				{
					Refresh(PlayerStatsHUD.Instance);
				});
			}
		}

		private static void Refresh(PlayerStatsHUD hud)
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected I4, but got Unknown
			PerkDefinition definition = PerkPlugin.Definition;
			if (definition.FormatHud == null || (Object)(object)hud.playerStatPrefab == (Object)null)
			{
				return;
			}
			float value = definition.GetValue();
			bool flag = PerkPlugin.Enabled.Value && PerkPlugin.ShowInHud.Value && value > definition.BaseValue + 0.0001f;
			int instanceID = ((Object)hud).GetInstanceID();
			if ((Object)(object)_line == (Object)null || _hud != instanceID)
			{
				if (!flag)
				{
					return;
				}
				Transform val = (((Object)(object)hud.statsContainer != (Object)null) ? hud.statsContainer : ((Component)hud).transform);
				_line = Object.Instantiate<StatLineUI>(hud.playerStatPrefab, val);
				((Object)_line).name = $"PlayerStat_SCT_{(int)definition.Type}";
				_hud = instanceID;
			}
			if (flag)
			{
				_line.Set(PerkIcons.Get(definition.MinRarity), definition.FormatHud(value));
			}
			_line.SetVisible(flag);
		}
	}
	[HarmonyPatch(typeof(TemporaryUpgradeManager), "Awake")]
	internal static class PerkRegisterPatch
	{
		private static void Postfix(TemporaryUpgradeManager __instance)
		{
			Safe.Run("Perk " + PerkPlugin.Definition.Name.Fr + " ajout", delegate
			{
				Register(__instance);
			});
		}

		private static void Register(TemporaryUpgradeManager __instance)
		{
			//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_001c: 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_0041: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			List<TemporaryUpgradeScaling> temporaryScalings = __instance._temporaryScalings;
			for (int i = 0; i < temporaryScalings.Count; i++)
			{
				if (temporaryScalings[i].upgradeType == PerkPlugin.Definition.Type)
				{
					return;
				}
			}
			temporaryScalings.Add(new TemporaryUpgradeScaling
			{
				upgradeType = PerkPlugin.Definition.Type,
				commonDelta = PerkPlugin.GetDelta((TemporaryUpgradeRarity)0),
				rareDelta = PerkPlugin.GetDelta((TemporaryUpgradeRarity)1),
				epicDelta = PerkPlugin.GetDelta((TemporaryUpgradeRarity)2),
				legendaryDelta = PerkPlugin.GetDelta((TemporaryUpgradeRarity)3),
				maxValue = PerkPlugin.MaxValue.Value
			});
		}
	}
	[HarmonyPatch(typeof(TemporaryUpgradeManager), "CalculateTemporaryDelta")]
	internal static class PerkDeltaPatch
	{
		private static bool Prefix(UpgradeType upgradeType, TemporaryUpgradeRarity rarity, ref float __result)
		{
			//IL_0007: 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_000d: 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)
			if (upgradeType != PerkPlugin.Definition.Type)
			{
				return true;
			}
			float delta = 0f;
			bool num = Safe.Prefix("Perk " + PerkPlugin.Definition.Name.Fr + " valeur", delegate
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				delta = PerkPlugin.GetDelta(rarity);
				return false;
			});
			if (!num)
			{
				__result = delta;
			}
			return num;
		}
	}
	[HarmonyPatch(typeof(TemporaryUpgradeManager), "IsTemporaryUpgradeTypeUnlocked")]
	internal static class PerkUnlockPatch
	{
		private static void Postfix(UpgradeType upgradeType, ref bool __result)
		{
			//IL_0000: 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)
			if (upgradeType == PerkPlugin.Definition.Type)
			{
				__result = PerkPlugin.Enabled.Value && !PerkPlugin.IsCapped && !Vanilla.Active;
			}
		}
	}
	[HarmonyPatch(typeof(TemporaryUpgradeManager), "CreateChoice")]
	internal static class PerkMinRarityPatch
	{
		private static void Postfix(ref TemporaryUpgradeChoice __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			if (__result.upgradeType == PerkPlugin.Definition.Type && __result.rarity < PerkPlugin.Definition.MinRarity)
			{
				__result.rarity = PerkPlugin.Definition.MinRarity;
				__result.delta = PerkPlugin.GetDelta(__result.rarity);
				__result.resultValue = PerkPlugin.Cap(__result.baseValue + __result.delta);
			}
		}
	}
	[HarmonyPatch(typeof(UpgradeManager), "GetValue")]
	internal static class PerkValuePatch
	{
		private static void Postfix(UpgradeType type, ref float __result)
		{
			//IL_0000: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			if (type != PerkPlugin.Definition.Type)
			{
				return;
			}
			if (Vanilla.Active)
			{
				__result = PerkPlugin.Definition.BaseValue;
				return;
			}
			float num = 0f;
			if ((Object)(object)TemporaryUpgradeManager.Instance != (Object)null)
			{
				num = Mathf.Max(0f, TemporaryUpgradeManager.Instance.ApplyToValue(type, 0f));
				if (num <= 0.01f)
				{
					num = 0f;
				}
			}
			__result = PerkPlugin.Cap(PerkPlugin.Definition.BaseValue + num);
		}
	}
	[HarmonyPatch(typeof(TemporaryUpgradeChoiceLine), "RefreshLocalizedTexts")]
	internal static class PerkTitlePatch
	{
		private static void Postfix(TemporaryUpgradeChoiceLine __instance)
		{
			//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_0007: 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_0012: 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)
			TemporaryUpgradeChoice choice = __instance.choice;
			if (choice.upgradeType == PerkPlugin.Definition.Type)
			{
				if ((Object)(object)__instance.titleText != (Object)null)
				{
					((TMP_Text)__instance.titleText).text = PerkPlugin.Definition.Name.ToString();
				}
				if ((Object)(object)__instance.valueText != (Object)null)
				{
					((TMP_Text)__instance.valueText).text = FormatCapped(choice);
				}
			}
		}

		internal static string FormatCapped(TemporaryUpgradeChoice choice)
		{
			//IL_0002: 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)
			choice.resultValue = PerkPlugin.Cap(choice.resultValue);
			return PerkPlugin.Definition.FormatChoice(choice);
		}
	}
	[HarmonyPatch(typeof(TemporaryUpgradeChoiceLine), "Init")]
	internal static class PerkLinePatch
	{
		private static void Postfix(TemporaryUpgradeChoiceLine __instance)
		{
			//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_0007: 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_0012: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			TemporaryUpgradeChoice choice = __instance.choice;
			if (choice.upgradeType == PerkPlugin.Definition.Type)
			{
				if ((Object)(object)__instance.upgradeIcon != (Object)null)
				{
					__instance.upgradeIcon.sprite = PerkIcons.Get(choice.rarity);
				}
				if ((Object)(object)__instance.valueText != (Object)null)
				{
					((TMP_Text)__instance.valueText).text = PerkTitlePatch.FormatCapped(choice);
				}
			}
		}
	}
}
namespace SCTPerks.MiningReach
{
	public enum MiningAreaShape
	{
		Ligne,
		Carre
	}
	[BepInPlugin("sct.perk.miningreach", "SCT Perk - Portée de minage", "2.0.0")]
	public class MiningReachPerk : PerkPlugin
	{
		internal static ConfigEntry<int> BaseWidth;

		internal static ConfigEntry<MiningAreaShape> Shape;

		internal override PerkDefinition CreateDefinition()
		{
			//IL_0008: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			return new PerkDefinition
			{
				Type = (UpgradeType)102,
				Name = Text.Of("Portée de minage", "Mining Reach"),
				IconSource = (UpgradeType)2,
				BaseValue = 0f,
				MinRarity = (TemporaryUpgradeRarity)3,
				LegendaryDelta = 1f,
				DefaultMaxValue = 3f,
				FormatHud = (float v) => $"{1 + 2 * Mathf.RoundToInt(v)}",
				FormatChoice = (TemporaryUpgradeChoice c) => $"{1 + 2 * Mathf.RoundToInt(c.baseValue)} -> {1 + 2 * Mathf.RoundToInt(c.resultValue)} " + Text.Pick("blocs de large", "blocks wide")
			};
		}

		protected override void BindConfig()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			BaseWidth = ((BasePlugin)this).Config.Bind<int>("Zone", "BaseWidth", 1, new ConfigDescription("Largeur de base de la zone minée, avant les perks (1 = jeu normal).", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[4] { 1, 3, 5, 7 }), Array.Empty<object>()));
			Shape = ((BasePlugin)this).Config.Bind<MiningAreaShape>("Zone", "Shape", MiningAreaShape.Ligne, "Ligne = largeur sur 1 bloc de profondeur, Carre = BaseWidth blocs de profondeur.");
		}

		public static int GetWidth()
		{
			return BaseWidth.Value + 2 * Mathf.RoundToInt(PerkPlugin.Definition.GetValue());
		}
	}
	[HarmonyPatch(typeof(BlockManager), "ModifyTileDurability")]
	internal static class MiningAreaPatch
	{
		private static void Postfix(BlockManager __instance, Vector3Int position, int amount, Driller driller, Vector2 hitDirection)
		{
			//IL_0007: 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_0023: 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_007c: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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)
			if (ExtraHits.Active || Vanilla.Active || !Il2CppUtil.IsPlayer(driller))
			{
				return;
			}
			int width = MiningReachPerk.GetWidth();
			int depth = ((MiningReachPerk.Shape.Value != MiningAreaShape.Carre) ? 1 : MiningReachPerk.BaseWidth.Value);
			if (width <= 1 && depth <= 1)
			{
				return;
			}
			Vector3Int forward = Mining.Forward(hitDirection);
			Vector3Int side = Mining.Side(forward);
			int half = width / 2;
			ExtraHits.Run(delegate
			{
				//IL_0015: 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_0021: 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_002c: 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_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < depth; i++)
				{
					for (int j = -half; j <= half; j++)
					{
						if (i != 0 || j != 0)
						{
							Vector3Int val = position + forward * i + side * j;
							if (Mining.IsMineable(__instance, val))
							{
								__instance.ModifyTileDurability(val, amount, driller, hitDirection);
							}
						}
					}
				}
			});
		}
	}
}