Decompiled source of FortnitePirateToken v1.0.1

FortnitePirateToken.dll

Decompiled 25 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FortnitePirateToken.Runtime;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Joja")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+aa2a3847fb2e9419e5a41f7e2ba1e254ff9e40c4")]
[assembly: AssemblyProduct("FortnitePirateToken")]
[assembly: AssemblyTitle("FortnitePirateToken")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 FortnitePirateToken
{
	[BepInPlugin("Joja.FortnitePirateToken", "FortnitePirateToken", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class FortnitePirateTokenPlugin : BaseUnityPlugin
	{
		internal enum SpawnChance
		{
			OneIn30000,
			OneIn137500
		}

		internal static FortnitePirateTokenPlugin Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		internal static ConfigEntry<SpawnChance> Chance { get; private set; }

		internal static int OneInN
		{
			get
			{
				if (Chance.Value != SpawnChance.OneIn137500)
				{
					return 30000;
				}
				return 137500;
			}
		}

		private void Awake()
		{
			//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_0064: Expected O, but got Unknown
			//IL_0069: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Chance = ((BaseUnityPlugin)this).Config.Bind<SpawnChance>("Spawning", "Chance", SpawnChance.OneIn30000, "Chance for each valuable spawned in a level to become a Pirate Shop Token. OneIn30000 is the default; OneIn137500 is the original Fortnite drop chance.");
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
			((MonoBehaviour)this).StartCoroutine(RegisterWhenReady());
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private static IEnumerator RegisterWhenReady()
		{
			for (int attempt = 0; attempt < 1200; attempt++)
			{
				if (TokenBuilder.TryRegister())
				{
					yield break;
				}
				yield return null;
			}
			Logger.LogError((object)"Gave up registering 'Pirate Shop Token': no vanilla valuable template became available.");
		}

		private void OnDestroy()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(ValuableDirector), "SpawnValuable")]
	internal static class TokenSpawnPatch
	{
		private static void Prefix(ref PrefabRef _valuable, List<PrefabRef> ___bigValuables)
		{
			PrefabRef token = TokenBuilder.Prefab;
			if (token == null)
			{
				return;
			}
			if (IsToken(_valuable, token))
			{
				List<PrefabRef> list = ___bigValuables.Where((PrefabRef v) => !IsToken(v, token)).ToList();
				if (list.Count > 0)
				{
					_valuable = list[Random.Range(0, list.Count)];
				}
			}
			int oneInN = FortnitePirateTokenPlugin.OneInN;
			if (Random.Range(0, oneInN) == 0)
			{
				FortnitePirateTokenPlugin.Logger.LogInfo((object)"A Pirate Shop Token spawned!");
				_valuable = token;
			}
		}

		private static bool IsToken(PrefabRef? candidate, PrefabRef token)
		{
			if (candidate != null)
			{
				if (candidate != token)
				{
					return ((PrefabRef<GameObject>)(object)candidate).PrefabName == ((PrefabRef<GameObject>)(object)token).PrefabName;
				}
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ValuableDirector), "SetupHost")]
	internal static class FreeShopResetPatch
	{
		private static void Prefix()
		{
			if (!SemiFunc.RunIsShop())
			{
				FreeShop.Active = false;
			}
		}
	}
	[HarmonyPatch(typeof(ExtractionPoint), "DestroyAllPhysObjectsInHaulList")]
	internal static class TokenExtractedAllPatch
	{
		private static void Prefix()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				List<GameObject> dollarHaulList = RoundDirector.instance.dollarHaulList;
				if (dollarHaulList.Any((GameObject item) => (Object)(object)item != (Object)null && (Object)(object)item.GetComponent<TokenMarker>() != (Object)null))
				{
					TokenExtractedPatchHelper.Mark();
				}
			}
		}
	}
	[HarmonyPatch(typeof(ExtractionPoint), "DestroyTheFirstPhysObjectsInHaulList")]
	internal static class TokenExtractedFirstPatch
	{
		private static void Prefix()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				List<GameObject> dollarHaulList = RoundDirector.instance.dollarHaulList;
				if (dollarHaulList.Count > 0 && (Object)(object)dollarHaulList[0] != (Object)null && (Object)(object)dollarHaulList[0].GetComponent<TokenMarker>() != (Object)null)
				{
					TokenExtractedPatchHelper.Mark();
				}
			}
		}
	}
	internal static class TokenExtractedPatchHelper
	{
		public static void Mark()
		{
			if (!FreeShop.Active)
			{
				FreeShop.Active = true;
				FortnitePirateTokenPlugin.Logger.LogInfo((object)"Pirate Shop Token extracted: the next shop is free.");
			}
		}
	}
	[HarmonyPatch(typeof(ItemAttributes), "GetValue")]
	internal static class FreeShopPricePatch
	{
		private static void Postfix(ItemAttributes __instance)
		{
			if (FreeShop.Active && SemiFunc.RunIsShop() && SemiFunc.IsMasterClientOrSingleplayer())
			{
				__instance.value = 0;
				if (SemiFunc.IsMultiplayer() && (Object)(object)__instance.photonView != (Object)null && __instance.photonView.ViewID != 0)
				{
					__instance.photonView.RPC("GetValueRPC", (RpcTarget)1, new object[1] { 0 });
				}
				SemiFunc.ShopUpdateCost();
			}
		}
	}
}
namespace FortnitePirateToken.Runtime
{
	internal static class EmbeddedAssets
	{
		private static readonly Assembly Assembly = typeof(EmbeddedAssets).Assembly;

		private static readonly string[] Names = Assembly.GetManifestResourceNames();

		public static byte[] ReadBytes(string path)
		{
			using Stream stream = Open(path);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		public static string ReadText(string path)
		{
			using Stream stream = Open(path);
			using StreamReader streamReader = new StreamReader(stream);
			return streamReader.ReadToEnd();
		}

		public static Texture2D LoadTexture(string path)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
			{
				name = Path.GetFileNameWithoutExtension(path)
			};
			if (!ImageConversion.LoadImage(val, ReadBytes(path)))
			{
				throw new InvalidDataException("Could not decode texture '" + path + "'.");
			}
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return val;
		}

		private static Stream Open(string path)
		{
			string wanted = path.Replace('\\', '/');
			string text = Names.FirstOrDefault((string n) => n.Replace('\\', '/').EndsWith(wanted, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				throw new FileNotFoundException("Embedded asset '" + path + "' not found. Available: " + string.Join(", ", Names));
			}
			return Assembly.GetManifestResourceStream(text);
		}
	}
	internal static class FreeShop
	{
		public static bool Active;
	}
	internal static class ObjLoader
	{
		private sealed class Group
		{
			public readonly string Name;

			public readonly List<int> Triangles = new List<int>();

			private readonly List<Vector3> _vertices = new List<Vector3>();

			private readonly List<Vector2> _uvs = new List<Vector2>();

			private readonly List<Vector3> _normals = new List<Vector3>();

			private readonly Dictionary<(int, int, int), int> _lookup = new Dictionary<(int, int, int), int>();

			private bool _hasUv;

			private bool _hasNormals;

			public Group(string name)
			{
				Name = name;
			}

			public int Vertex(int v, int t, int n, List<Vector3> positions, List<Vector2> uvs, List<Vector3> normals)
			{
				//IL_001c: 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_0028: 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_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: 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_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: 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)
				if (_lookup.TryGetValue((v, t, n), out var value))
				{
					return value;
				}
				Vector3 val = positions[v];
				_vertices.Add(new Vector3(0f - val.x, val.y, val.z));
				if (t >= 0)
				{
					_hasUv = true;
					_uvs.Add(uvs[t]);
				}
				else
				{
					_uvs.Add(Vector2.zero);
				}
				if (n >= 0)
				{
					_hasNormals = true;
					Vector3 val2 = normals[n];
					_normals.Add(new Vector3(0f - val2.x, val2.y, val2.z));
				}
				else
				{
					_normals.Add(Vector3.up);
				}
				int num = _vertices.Count - 1;
				_lookup[(v, t, n)] = num;
				return num;
			}

			public Mesh Build()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				Mesh val = new Mesh
				{
					name = Name
				};
				if (_vertices.Count > 65535)
				{
					val.indexFormat = (IndexFormat)1;
				}
				val.SetVertices(_vertices);
				if (_hasUv)
				{
					val.SetUVs(0, _uvs);
				}
				val.SetTriangles(Triangles, 0);
				if (_hasNormals)
				{
					val.SetNormals(_normals);
				}
				else
				{
					val.RecalculateNormals();
				}
				val.RecalculateBounds();
				return val;
			}
		}

		public static Dictionary<string, Mesh> Load(string text, bool mergeGroups = false)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<Vector3> list3 = new List<Vector3>();
			Dictionary<string, Group> dictionary = new Dictionary<string, Group>();
			Group obj = null;
			string[] array = text.Split('\n');
			foreach (string text2 in array)
			{
				string text3 = text2.Trim();
				if (text3.Length == 0 || text3[0] == '#')
				{
					continue;
				}
				string[] array2 = text3.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
				switch (array2[0])
				{
				case "v":
					list.Add(new Vector3(F(array2[1]), F(array2[2]), F(array2[3])));
					break;
				case "vt":
					list2.Add(new Vector2(F(array2[1]), F(array2[2])));
					break;
				case "vn":
					list3.Add(new Vector3(F(array2[1]), F(array2[2]), F(array2[3])));
					break;
				case "o":
				case "g":
					obj = GetGroup(dictionary, mergeGroups ? "*" : ((array2.Length > 1) ? array2[1] : "mesh"));
					break;
				case "f":
					if (obj == null)
					{
						obj = GetGroup(dictionary, mergeGroups ? "*" : "mesh");
					}
					AddFace(obj, array2, list, list2, list3);
					break;
				}
			}
			Dictionary<string, Mesh> dictionary2 = new Dictionary<string, Mesh>();
			foreach (KeyValuePair<string, Group> item in dictionary)
			{
				dictionary2[item.Key] = item.Value.Build();
			}
			return dictionary2;
		}

		private static Group GetGroup(Dictionary<string, Group> groups, string name)
		{
			if (!groups.TryGetValue(name, out Group value))
			{
				value = (groups[name] = new Group(name));
			}
			return value;
		}

		private static float F(string s)
		{
			return float.Parse(s, CultureInfo.InvariantCulture);
		}

		private static void AddFace(Group group, string[] parts, List<Vector3> positions, List<Vector2> uvs, List<Vector3> normals)
		{
			int[] array = new int[parts.Length - 1];
			for (int i = 1; i < parts.Length; i++)
			{
				string[] array2 = parts[i].Split('/');
				int v = Resolve(int.Parse(array2[0], CultureInfo.InvariantCulture), positions.Count);
				int t = ((array2.Length > 1 && array2[1].Length > 0) ? Resolve(int.Parse(array2[1], CultureInfo.InvariantCulture), uvs.Count) : (-1));
				int n = ((array2.Length > 2 && array2[2].Length > 0) ? Resolve(int.Parse(array2[2], CultureInfo.InvariantCulture), normals.Count) : (-1));
				array[i - 1] = group.Vertex(v, t, n, positions, uvs, normals);
			}
			for (int j = 1; j < array.Length - 1; j++)
			{
				group.Triangles.Add(array[0]);
				group.Triangles.Add(array[j + 1]);
				group.Triangles.Add(array[j]);
			}
		}

		private static int Resolve(int index, int count)
		{
			if (index <= 0)
			{
				return count + index;
			}
			return index - 1;
		}
	}
	internal static class PresetLibrary
	{
		public static T? Find<T>(string kind, string name) where T : Object
		{
			if (string.IsNullOrEmpty(name))
			{
				return default(T);
			}
			T val = Resources.FindObjectsOfTypeAll<T>().FirstOrDefault((T p) => ((Object)p).name == name);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			if (!PresetSources.Map.TryGetValue((kind, name), out string value))
			{
				return default(T);
			}
			GameObject obj = Resources.Load<GameObject>(value);
			ValuableObject val2 = ((obj != null) ? obj.GetComponent<ValuableObject>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return default(T);
			}
			object obj2 = kind switch
			{
				"durability" => val2.durabilityPreset, 
				"value" => val2.valuePreset, 
				"phys" => val2.physAttributePreset, 
				"audio" => val2.audioPreset, 
				_ => null, 
			};
			return (T)((obj2 is T) ? obj2 : null);
		}
	}
	internal static class PresetSources
	{
		public static readonly Dictionary<(string Kind, string Name), string> Map = new Dictionary<(string, string), string>
		{
			[("audio", "PhysAudio - Alchemy Table")] = "Valuables/05 Wide/Valuable Wizard Alchemy Station",
			[("audio", "PhysAudio - Balloon")] = "Valuables/03 Medium/Valuable Museum Handface",
			[("audio", "PhysAudio - Barrel")] = "Valuables/03 Medium/Valuable Arctic Propane Tank",
			[("audio", "PhysAudio - Basket ball")] = "Valuables/02 Small/Valuable Museum Cube ball",
			[("audio", "PhysAudio - Bottle Pack")] = "Valuables/03 Medium/Valuable Arctic Sample Six Pack",
			[("audio", "PhysAudio - Cardboard")] = "Valuables/03 Medium/Valuable Museum MonkeyBox",
			[("audio", "PhysAudio - Cauldron box")] = "Valuables/04 Big/Valuable Wizard Cauldron Box",
			[("audio", "PhysAudio - Ceramic Big")] = "Valuables/04 Big/Valuable Manor Vase Big",
			[("audio", "PhysAudio - Ceramic Medium")] = "Valuables/03 Medium/Valuable Manor Kettle",
			[("audio", "PhysAudio - Ceramic Small")] = "Valuables/01 Tiny/Valuable Arctic Coffee Cup",
			[("audio", "PhysAudio - Computer")] = "Valuables/03 Medium/Valuable Arctic 3D Printer",
			[("audio", "PhysAudio - Concrete")] = "Valuables/02 Small/Valuable Desert Fossil",
			[("audio", "PhysAudio - Egg")] = "Valuables/04 Big/Valuable Museum Egg",
			[("audio", "PhysAudio - Fire Extinguisher")] = "Valuables/03 Medium/Valuable Arctic Fire Extinguisher",
			[("audio", "PhysAudio - Flamethrower")] = "Valuables/04 Big/Valuable Arctic Flamethrower",
			[("audio", "PhysAudio - Flesh Medium")] = "Valuables/03 Medium/Valuable Manor Clown",
			[("audio", "PhysAudio - Flesh Small")] = "Valuables/01 Tiny/Valuable Museum Cool brain",
			[("audio", "PhysAudio - Gem Burger")] = "Valuables/02 Small/Valuable Desert Gold Bar",
			[("audio", "PhysAudio - Glass Big")] = "Valuables/07 Very Tall/Valuable Desert Zero Grav crystal",
			[("audio", "PhysAudio - Glass Liquid Big")] = "Valuables/04 Big/Valuable Wizard Master Potion",
			[("audio", "PhysAudio - Glass Liquid Medium")] = "Valuables/01 Tiny/Valuable Wizard Glowing Jar",
			[("audio", "PhysAudio - Glass Medium")] = "Valuables/03 Medium/Valuable Manor Ship in a bottle",
			[("audio", "PhysAudio - Glass Small")] = "Valuables/01 Tiny/Valuable Arctic Uranium Petri Dish",
			[("audio", "PhysAudio - Gnome")] = "Valuables/04 Big/Valuable Manor Scream Doll",
			[("audio", "PhysAudio - Golden Swirl")] = "Valuables/03 Medium/Valuable Wizard Star Wand",
			[("audio", "PhysAudio - Gross")] = "Valuables/01 Tiny/Valuable Wizard Eye Ball",
			[("audio", "PhysAudio - Guitar")] = "Valuables/04 Big/Valuable Arctic Guitar",
			[("audio", "PhysAudio - Harp")] = "Valuables/06 Tall/Valuable Manor Harp",
			[("audio", "PhysAudio - Hay")] = "Valuables/03 Medium/Valuable Desert Fluffy Buddy",
			[("audio", "PhysAudio - Heavy Water")] = "Valuables/06 Tall/Valuable Arctic Heavy Water",
			[("audio", "PhysAudio - Ice Block")] = "Valuables/04 Big/Valuable Arctic Creature Leg",
			[("audio", "PhysAudio - Leather Medium")] = "Valuables/01 Tiny/Valuable Arctic Eraser",
			[("audio", "PhysAudio - Metal Hollow Big")] = "Valuables/03 Medium/Valuable Museum Gumball",
			[("audio", "PhysAudio - Metal Hollow Medium")] = "Valuables/03 Medium/Valuable Arctic Fan",
			[("audio", "PhysAudio - Metal Hollow Small")] = "Valuables/01 Tiny/Valuable Arctic Stapler",
			[("audio", "PhysAudio - Milk")] = "Valuables/06 Tall/Valuable Museum Milk",
			[("audio", "PhysAudio - Paper")] = "Valuables/03 Medium/Valuable Manor Map",
			[("audio", "PhysAudio - Piano")] = "Valuables/05 Wide/Valuable Manor Piano",
			[("audio", "PhysAudio - Pill bottle")] = "Valuables/01 Tiny/Valuable Arctic Pills",
			[("audio", "PhysAudio - Plastic Big")] = "Valuables/03 Medium/Valuable Desert Suitcase",
			[("audio", "PhysAudio - Plastic Medium")] = "Valuables/01 Tiny/Valuable Arctic Keycard",
			[("audio", "PhysAudio - Player")] = "Valuables/03 Medium/Valuable Museum Teeth Bot",
			[("audio", "PhysAudio - Rock Medium")] = "Valuables/02 Small/Valuable Wizard Pendant",
			[("audio", "PhysAudio - Spider Potion")] = "Valuables/04 Big/Valuable Wizard Spider Potion",
			[("audio", "PhysAudio - Unicorn Horn")] = "Valuables/04 Big/Valuable Wizard Unicorn Horn",
			[("audio", "PhysAudio - VHS")] = "Valuables/02 Small/Valuable Arctic VHS",
			[("audio", "PhysAudio - Wood Door")] = "Valuables/04 Big/Valuable Desert Golden Shovel",
			[("audio", "PhysAudio - Wood Hollow Big")] = "Valuables/05 Wide/Valuable Manor Animal Crate",
			[("audio", "PhysAudio - Wood Hollow Medium")] = "Valuables/01 Tiny/Valuable Museum Fish",
			[("audio", "PhysAudio - Wood Hollow Small")] = "Valuables/01 Tiny/Valuable Museum RubenDoll",
			[("durability", "Durability Default")] = "Valuables/01 Tiny/Valuable Arctic Phone",
			[("durability", "Durability Strong")] = "Valuables/01 Tiny/Valuable Arctic Eraser",
			[("durability", "Durability Strong+")] = "Valuables/01 Tiny/Valuable Arctic Keycard",
			[("durability", "Durability Weak")] = "Valuables/01 Tiny/Valuable Arctic Coffee Cup",
			[("durability", "Durability Weak+")] = "Valuables/01 Tiny/Valuable Museum GoldFish",
			[("durability", "Durability Weak++")] = "Valuables/01 Tiny/Valuable Museum GoldTooth",
			[("durability", "Durability Weak+++")] = "Valuables/03 Medium/Valuable Desert Mineral case",
			[("phys", "PhysAttribute Heavy")] = "Valuables/04 Big/Valuable Arctic Barrel",
			[("phys", "PhysAttribute Heavy+")] = "Valuables/04 Big/Valuable Arctic Creature Leg",
			[("phys", "PhysAttribute Heavy++")] = "Valuables/04 Big/Valuable Manor Vase Chunky",
			[("phys", "PhysAttribute Light")] = "Valuables/01 Tiny/Valuable Arctic Phone",
			[("phys", "PhysAttribute Light+")] = "Valuables/01 Tiny/Valuable Arctic Coffee Cup",
			[("phys", "PhysAttribute Light++")] = "Valuables/01 Tiny/Valuable Arctic Eraser",
			[("phys", "PhysAttribute Medium")] = "Valuables/01 Tiny/Valuable Desert Golden Coin",
			[("phys", "PhysAttribute Medium+")] = "Valuables/02 Small/Valuable Manor Instrument",
			[("phys", "PhysAttribute Medium++")] = "Valuables/02 Small/Valuable Arctic HDD",
			[("phys", "PhysAttribute Medium+++")] = "Valuables/02 Small/Valuable Desert Rocking Chair",
			[("phys", "PhysAttribute Medium++++")] = "Valuables/03 Medium/Valuable Wizard Eye of Orpigox",
			[("phys", "PhysAttribute Very Heavy")] = "Valuables/05 Wide/Valuable Museum Horse",
			[("value", "Value Cheap")] = "Valuables/01 Tiny/Valuable Arctic Eraser",
			[("value", "Value Cheap+")] = "Valuables/01 Tiny/Valuable Desert Lighter",
			[("value", "Value Cheap++")] = "Valuables/01 Tiny/Valuable Arctic Phone",
			[("value", "Value Expensive")] = "Valuables/05 Wide/Valuable Arctic Centrifuge",
			[("value", "Value Expensive+")] = "Valuables/05 Wide/Valuable Manor Piano",
			[("value", "Value Expensive++")] = "Valuables/05 Wide/Valuable Wizard Dragon Skull",
			[("value", "Value High")] = "Valuables/03 Medium/Valuable Arctic 3D Printer",
			[("value", "Value High+")] = "Valuables/04 Big/Valuable Arctic Barrel",
			[("value", "Value Medium")] = "Valuables/01 Tiny/Valuable Arctic Coffee Cup",
			[("value", "Value Medium+")] = "Valuables/02 Small/Valuable Manor Music Box",
			[("value", "Value Medium++")] = "Valuables/02 Small/Valuable Desert Rocking Chair",
			[("value", "Value Very Cheap")] = "Valuables/01 Tiny/Valuable Arctic Keycard"
		};
	}
	internal static class TokenBuilder
	{
		public const string Name = "Pirate Shop Token";

		private const string Folder = "token";

		private const float Scale = 4.5f;

		private const float ModelCentreY = -0.0083f;

		private static GameObject? _holder;

		private static readonly PropertyInfo? SharedMaterialProperty = typeof(Collider).GetProperty("sharedMaterial");

		public static PrefabRef? Prefab { get; private set; }

		private static Transform Holder
		{
			get
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)_holder == (Object)null)
				{
					_holder = new GameObject("FortnitePirateToken Prefabs");
					_holder.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)_holder);
				}
				return _holder.transform;
			}
		}

		public static bool TryRegister()
		{
			GameObject val = FindTemplate();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			try
			{
				GameObject val2 = Build(val);
				Prefab = Valuables.RegisterValuable(val2, new List<string> { "Valuables - Generic" });
				if (Prefab == null)
				{
					FortnitePirateTokenPlugin.Logger.LogError((object)"REPOLib refused to register the token prefab.");
				}
				else
				{
					FortnitePirateTokenPlugin.Logger.LogInfo((object)("Registered 'Pirate Shop Token' (template '" + ((Object)val).name + "')."));
				}
			}
			catch (Exception arg)
			{
				FortnitePirateTokenPlugin.Logger.LogError((object)string.Format("Failed to build '{0}': {1}", "Pirate Shop Token", arg));
			}
			return true;
		}

		private static GameObject? FindTemplate()
		{
			GameObject val = Resources.Load<GameObject>("Valuables/01 Tiny/Valuable Diamond");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			return ((IEnumerable<GameObject>)Resources.LoadAll<GameObject>("Valuables/01 Tiny")).FirstOrDefault((Func<GameObject, bool>)IsPlainValuable) ?? (from v in Resources.FindObjectsOfTypeAll<ValuableObject>().Where(delegate(ValuableObject v)
				{
					//IL_0006: 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)
					Scene scene = ((Component)v).gameObject.scene;
					return !((Scene)(ref scene)).IsValid() && (Object)(object)((Component)v).GetComponent<Rigidbody>() != (Object)null;
				})
				select ((Component)v).gameObject).FirstOrDefault();
		}

		private static bool IsPlainValuable(GameObject go)
		{
			if ((Object)(object)go.GetComponent<ValuableObject>() != (Object)null)
			{
				return (Object)(object)go.GetComponent<Rigidbody>() != (Object)null;
			}
			return false;
		}

		private static GameObject Build(GameObject template)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(template, Holder);
			((Object)val).name = "Pirate Shop Token";
			object physicsMaterial = GetPhysicsMaterial(template.GetComponentInChildren<Collider>(true));
			foreach (Transform item in ((IEnumerable)val.transform).Cast<Transform>().ToList())
			{
				Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
			}
			Transform transform = new GameObject("Object").transform;
			transform.SetParent(val.transform, false);
			BuildVisuals(transform);
			BuildColliders(transform, physicsMaterial);
			ApplyValuableSettings(val);
			val.AddComponent<TokenMarker>();
			return val;
		}

		private static void BuildVisuals(Transform objectNode)
		{
			//IL_0016: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Mesh> dictionary = ObjLoader.Load(EmbeddedAssets.ReadText("token/token.obj"));
			Transform transform = new GameObject("token").transform;
			transform.SetParent(objectNode, false);
			transform.localScale = Vector3.one * 4.5f;
			transform.localPosition = new Vector3(0f, 0.03735f, 0f);
			ProjectFromTop(dictionary["gem"], dictionary["gem_rim"]);
			(string, string)[] array = new(string, string)[4]
			{
				("base", "base.png"),
				("spike", "spike.png"),
				("gem", "gem.png"),
				("gem_rim", "")
			};
			for (int i = 0; i < array.Length; i++)
			{
				var (text, text2) = array[i];
				if (!dictionary.TryGetValue(text, out var value))
				{
					throw new KeyNotFoundException("token.obj has no part '" + text + "'. Parts: " + string.Join(", ", dictionary.Keys));
				}
				GameObject val = new GameObject(text);
				val.transform.SetParent(transform, false);
				val.AddComponent<MeshFilter>().sharedMesh = value;
				((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = ((text2.Length == 0) ? CreateColorMaterial(text, new Color(0.5f, 0.28f, 0.12f)) : CreateMaterial(text, text2));
			}
		}

		private static void ProjectFromTop(Mesh dome, Mesh rim)
		{
			//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_000a: 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_0045: 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)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = dome.bounds;
			((Bounds)(ref bounds)).Encapsulate(rim.bounds);
			Vector3[] vertices = dome.vertices;
			Vector2[] array = (Vector2[])(object)new Vector2[vertices.Length];
			for (int i = 0; i < vertices.Length; i++)
			{
				array[i] = new Vector2((((Bounds)(ref bounds)).max.x - vertices[i].x) / ((Bounds)(ref bounds)).size.x, (((Bounds)(ref bounds)).max.z - vertices[i].z) / ((Bounds)(ref bounds)).size.z);
			}
			dome.uv = array;
		}

		private static Material CreateColorMaterial(string name, Color color)
		{
			//IL_0028: 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_0034: 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_003c: Expected O, but got Unknown
			Shader val = Shader.Find("Standard") ?? Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Sprites/Default");
			Material val2 = new Material(val)
			{
				name = name,
				color = color
			};
			if (val2.HasProperty("_Metallic"))
			{
				val2.SetFloat("_Metallic", 0.3f);
			}
			if (val2.HasProperty("_Glossiness"))
			{
				val2.SetFloat("_Glossiness", 0.5f);
			}
			return val2;
		}

		private static Material CreateMaterial(string name, string texturePath)
		{
			//IL_0028: 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_0034: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			Shader val = Shader.Find("Standard") ?? Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Sprites/Default");
			Material val2 = new Material(val)
			{
				name = name,
				color = Color.white,
				mainTexture = (Texture)(object)EmbeddedAssets.LoadTexture("token/" + texturePath)
			};
			if (val2.HasProperty("_Metallic"))
			{
				val2.SetFloat("_Metallic", 0.3f);
			}
			if (val2.HasProperty("_Glossiness"))
			{
				val2.SetFloat("_Glossiness", 0.5f);
			}
			return val2;
		}

		private static object? GetPhysicsMaterial(Collider? collider)
		{
			if (!((Object)(object)collider == (Object)null))
			{
				return SharedMaterialProperty?.GetValue(collider);
			}
			return null;
		}

		private static void BuildColliders(Transform objectNode, object? physicsMaterial)
		{
			//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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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)
			int num = LayerMask.NameToLayer("PhysGrabObject");
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0.8325f, 0.22500001f, 0.8325f);
			for (int i = 0; i < 2; i++)
			{
				GameObject val2 = new GameObject($"Valuable Collider ({i})")
				{
					layer = ((num != -1) ? num : 0),
					tag = "Phys Grab Object"
				};
				val2.transform.SetParent(objectNode, false);
				val2.transform.localRotation = Quaternion.Euler(0f, 45f * (float)i, 0f);
				BoxCollider val3 = val2.AddComponent<BoxCollider>();
				val3.size = (Vector3)((i == 0) ? val : new Vector3(val.x * 0.8f, val.y, val.z * 0.8f));
				val2.AddComponent<PhysGrabObjectBoxCollider>();
				if (physicsMaterial != null)
				{
					SharedMaterialProperty?.SetValue(val3, physicsMaterial);
				}
				val2.AddComponent<PhysGrabObjectCollider>().colliderID = i;
			}
		}

		private static void ApplyValuableSettings(GameObject root)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_0135: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_0178: 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)
			ValuableObject val = root.GetComponent<ValuableObject>() ?? throw new InvalidOperationException("Template has no ValuableObject.");
			Value val2 = ScriptableObject.CreateInstance<Value>();
			((Object)val2).name = "Pirate Shop Token value";
			val2.valueMin = 0f;
			val2.valueMax = 0f;
			((Object)val2).hideFlags = (HideFlags)32;
			val.valuePreset = val2;
			Durability val3 = ScriptableObject.CreateInstance<Durability>();
			((Object)val3).name = "Pirate Shop Token durability";
			val3.fragility = 0f;
			val3.durability = 100f;
			((Object)val3).hideFlags = (HideFlags)32;
			val.durabilityPreset = val3;
			PhysGrabObjectImpactDetector[] componentsInChildren = root.GetComponentsInChildren<PhysGrabObjectImpactDetector>(true);
			foreach (PhysGrabObjectImpactDetector val4 in componentsInChildren)
			{
				val4.destroyDisable = true;
			}
			val.physAttributePreset = PresetLibrary.Find<PhysAttribute>("phys", "PhysAttribute Medium") ?? val.physAttributePreset;
			val.audioPreset = PresetLibrary.Find<PhysAudio>("audio", "PhysAudio - Gem Burger") ?? val.audioPreset;
			val.volumeType = (Type)3;
			Gradient val5 = new Gradient();
			val5.colorKeys = (GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(new Color(0.95f, 0.6f, 0.15f), 0f),
				new GradientColorKey(new Color(0.55f, 0.3f, 0.1f), 1f)
			};
			val5.alphaKeys = (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(1f, 0f),
				new GradientAlphaKey(1f, 1f)
			};
			val5.mode = (GradientMode)1;
			val.particleColors = val5;
		}
	}
	internal sealed class TokenMarker : MonoBehaviour
	{
	}
}