Decompiled source of ExtraKeys v1.1.1

ExtraKeys.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ExtraKeys")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExtraKeys")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
namespace ExtraKeys;

[BepInPlugin("com.digitaltoast.extrakeys", "ExtraKeys", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class ExtraKeys : BaseUnityPlugin
{
	public const string PluginGUID = "com.digitaltoast.extrakeys";

	public const string PluginName = "ExtraKeys";

	public const string PluginVersion = "1.1.1";

	private AssetBundle keyBundle;

	private CustomLocalization Localization;

	private readonly string[] keyNames = new string[27]
	{
		"ExtraKeys_Amethyst", "ExtraKeys_Bank", "ExtraKeys_BlackMarble", "ExtraKeys_Blue", "ExtraKeys_Castle", "ExtraKeys_Crystal", "ExtraKeys_Dungeon", "ExtraKeys_Fire", "ExtraKeys_Garden", "ExtraKeys_Green",
		"ExtraKeys_Ice", "ExtraKeys_Inn", "ExtraKeys_Lightning", "ExtraKeys_Magma", "ExtraKeys_Meadows", "ExtraKeys_Mountain", "ExtraKeys_Odin", "ExtraKeys_Plains", "ExtraKeys_Red", "ExtraKeys_Skeleton",
		"ExtraKeys_Stone", "ExtraKeys_Stoned", "ExtraKeys_Swamp", "ExtraKeys_Thor", "ExtraKeys_Wood", "ExtraKeys_Yellow", "ExtraKeys_Yggdrasil"
	};

	private void Awake()
	{
		Logger.LogInfo((object)"Loading ExtraKeys…");
		string directoryName = Path.GetDirectoryName(typeof(ExtraKeys).Assembly.Location);
		string text = Path.Combine(directoryName, "ExtraKeys");
		keyBundle = AssetBundle.LoadFromFile(text);
		if ((Object)(object)keyBundle == (Object)null)
		{
			Logger.LogError((object)"Failed to load ExtraKeys asset bundle!");
			return;
		}
		Localization = LocalizationManager.Instance.GetLocalization();
		AddLocalizations();
		PrefabManager.OnVanillaPrefabsAvailable += RegisterKeys;
		Logger.LogInfo((object)"ExtraKeys will register on world load.");
	}

	private void AddLocalizations()
	{
		CustomLocalization localization = Localization;
		string text = "English";
		localization.AddTranslation(ref text, new Dictionary<string, string>
		{
			{ "item_extrakeys_amethyst", "Amethyst Key" },
			{ "item_extrakeys_amethyst_description", "An ornate key with a deep purple gemstone." },
			{ "item_extrakeys_bank", "Bank Key" },
			{ "item_extrakeys_bank_description", "You're rich! Well, maybe." },
			{ "item_extrakeys_blackmarble", "Black Marble Key" },
			{ "item_extrakeys_blackmarble_description", "A beautifully crafted key made from polished black marble." },
			{ "item_extrakeys_blue", "Blue Key" },
			{ "item_extrakeys_blue_description", "A generic looking blue key." },
			{ "item_extrakeys_castle", "Castle Key" },
			{ "item_extrakeys_castle_description", "A key carved from stone, used to unlock grand halls and royal chambers." },
			{ "item_extrakeys_crystal", "Crystal Key" },
			{ "item_extrakeys_crystal_description", "An elegant key crafted from pure crystal." },
			{ "item_extrakeys_dungeon", "Dungeon Key" },
			{ "item_extrakeys_dungeon_description", "A rusty and ancient key. Cold to the touch." },
			{ "item_extrakeys_fire", "Fire Key" },
			{ "item_extrakeys_fire_description", "This key emits a warm glow, seemingly fueled by an eternal flame." },
			{ "item_extrakeys_garden", "Garden Key" },
			{ "item_extrakeys_garden_description", "Covered in ivy, this key holds the secrets of the forest." },
			{ "item_extrakeys_green", "Green Key" },
			{ "item_extrakeys_green_description", "A generic looking green key." },
			{ "item_extrakeys_ice", "Ice Key" },
			{ "item_extrakeys_ice_description", "This key is unnaturally cold to the touch." },
			{ "item_extrakeys_inn", "Inn Key" },
			{ "item_extrakeys_inn_description", "A simple key for a simple room." },
			{ "item_extrakeys_lightning", "Lightning Key" },
			{ "item_extrakeys_lightning_description", "Static electricity fills the air as this key crackles with energy." },
			{ "item_extrakeys_magma", "Magma Key" },
			{ "item_extrakeys_magma_description", "A key forged from molten rock, radiating intense heat." },
			{ "item_extrakeys_meadows", "Meadows Key" },
			{ "item_extrakeys_meadows_description", "This key is warm and comforting." },
			{ "item_extrakeys_mountain", "Mountain Key" },
			{ "item_extrakeys_mountain_description", "A rugged key chiseled from mountain rock." },
			{ "item_extrakeys_odin", "Odin Key" },
			{ "item_extrakeys_odin_description", "A mysterious key " },
			{ "item_extrakeys_plains", "Plains Key" },
			{ "item_extrakeys_plains_description", "A sturdy key crafted for the open plains." },
			{ "item_extrakeys_red", "Red Key" },
			{ "item_extrakeys_red_description", "A generic looking red key." },
			{ "item_extrakeys_skeleton", "Skeleton Key" },
			{ "item_extrakeys_skeleton_description", "Made of bones, but it probably doesn't open every door." },
			{ "item_extrakeys_stone", "Stone Key" },
			{ "item_extrakeys_stone_description", "Heavy and rugged, this key is sculpted from solid stone." },
			{ "item_extrakeys_stoned", "Stoned Key" },
			{ "item_extrakeys_stoned_description", "Half stone, half tree. This key is well baked." },
			{ "item_extrakeys_swamp", "Swamp Key" },
			{ "item_extrakeys_swamp_description", "A damp, heavy key imbued with swampy essence." },
			{ "item_extrakeys_thor", "Thor Key" },
			{ "item_extrakeys_thor_description", "A thunderous key echoing with Thor’s power." },
			{ "item_extrakeys_wood", "Wood Key" },
			{ "item_extrakeys_wood_description", "A simple key carved from sturdy oak wood." },
			{ "item_extrakeys_yellow", "Yellow Key" },
			{ "item_extrakeys_yellow_description", "A generic looking yellow key." },
			{ "item_extrakeys_yggdrasil", "Yggdrasil Key" },
			{ "item_extrakeys_yggdrasil_description", "A sacred key carved from a branch of the World Tree." }
		});
		Logger.LogInfo((object)"ExtraKeys localizations added.");
	}

	private void RegisterKeys()
	{
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Expected O, but got Unknown
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Expected O, but got Unknown
		//IL_0518: Unknown result type (might be due to invalid IL or missing references)
		//IL_051d: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0539: Unknown result type (might be due to invalid IL or missing references)
		//IL_053e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0548: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04be: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0530: Unknown result type (might be due to invalid IL or missing references)
		//IL_0535: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Unknown result type (might be due to invalid IL or missing references)
		//IL_0505: Unknown result type (might be due to invalid IL or missing references)
		PrefabManager.OnVanillaPrefabsAvailable -= RegisterKeys;
		GameObject prefab = PrefabManager.Instance.GetPrefab("HildirKey_forestcrypt");
		Mesh val = null;
		Material[] array = null;
		if ((Object)(object)prefab != (Object)null)
		{
			MeshFilter val2 = default(MeshFilter);
			if (prefab.TryGetComponent<MeshFilter>(ref val2))
			{
				val = val2.sharedMesh;
			}
			MeshRenderer val3 = default(MeshRenderer);
			if (prefab.TryGetComponent<MeshRenderer>(ref val3))
			{
				array = ((Renderer)val3).sharedMaterials;
			}
		}
		string[] array2 = keyNames;
		MeshFilter val9 = default(MeshFilter);
		Light val12 = default(Light);
		foreach (string text in array2)
		{
			if ((Object)(object)PrefabManager.Instance.GetPrefab(text) != (Object)null)
			{
				Logger.LogWarning((object)("Skipping duplicate prefab: " + text));
				continue;
			}
			GameObject val4 = keyBundle.LoadAsset<GameObject>(text);
			if ((Object)(object)val4 == (Object)null)
			{
				Logger.LogError((object)("Missing prefab in bundle: " + text));
				continue;
			}
			MeshFilter component = val4.GetComponent<MeshFilter>();
			Mesh val5 = ((component != null) ? component.sharedMesh : null);
			Sprite val6 = keyBundle.LoadAsset<Sprite>(text + ".png");
			if ((Object)(object)val6 == (Object)null)
			{
				Logger.LogWarning((object)("Icon missing: " + text + ".png"));
			}
			string text2 = text.ToLower();
			ItemConfig val7 = new ItemConfig();
			val7.Name = "$item_" + text2;
			val7.Description = "$item_" + text2 + "_description";
			val7.Icons = (Sprite[])(object)((!((Object)(object)val6 != (Object)null)) ? null : new Sprite[1] { val6 });
			val7.Enabled = false;
			ItemConfig val8 = val7;
			ItemManager.Instance.AddItem(new CustomItem(text, "HildirKey_forestcrypt", val8));
			GameObject prefab2 = PrefabManager.Instance.GetPrefab(text);
			if ((Object)(object)prefab2 == (Object)null)
			{
				Logger.LogError((object)("Failed to retrieve clone: " + text));
				continue;
			}
			if (prefab2.TryGetComponent<MeshFilter>(ref val9))
			{
				val9.sharedMesh = val5 ?? val;
			}
			Material val10 = keyBundle.LoadAsset<Material>(text + "Mat");
			MeshRenderer[] componentsInChildren = prefab2.GetComponentsInChildren<MeshRenderer>();
			foreach (MeshRenderer val11 in componentsInChildren)
			{
				((Renderer)val11).sharedMaterials = (Material[])(((Object)(object)val10 != (Object)null) ? ((Array)new Material[1] { val10 }) : ((Array)(array ?? ((Renderer)val11).sharedMaterials)));
			}
			bool flag;
			switch (text)
			{
			case "ExtraKeys_Fire":
			case "ExtraKeys_Ice":
			case "ExtraKeys_Lightning":
			case "ExtraKeys_Magma":
			case "ExtraKeys_Odin":
			case "ExtraKeys_Yggdrasil":
			case "ExtraKeys_Thor":
				flag = true;
				break;
			default:
				flag = false;
				break;
			}
			if (flag)
			{
				if (prefab2.TryGetComponent<Light>(ref val12))
				{
					Object.Destroy((Object)(object)val12);
				}
				Light val13 = prefab2.AddComponent<Light>();
				val13.type = (LightType)2;
				val13.range = 2.5f;
				val13.intensity = 1.8f;
				Light val14 = val13;
				if (1 == 0)
				{
				}
				Color color = (Color)(text switch
				{
					"ExtraKeys_Fire" => new Color(1f, 0.4f, 0.1f), 
					"ExtraKeys_Ice" => Color.cyan, 
					"ExtraKeys_Lightning" => Color.yellow, 
					"ExtraKeys_Magma" => new Color(1f, 0.2f, 0f), 
					"ExtraKeys_Odin" => new Color(0.2f, 0.6f, 1f), 
					"ExtraKeys_Yggdrasil" => new Color(0.2f, 0.6f, 1f), 
					"ExtraKeys_Thor" => new Color(1f, 1f, 0.2f), 
					_ => Color.white, 
				});
				if (1 == 0)
				{
				}
				val14.color = color;
			}
		}
		PrefabExtension.FixReferences((object)PrefabManager.Instance);
		Logger.LogInfo((object)"ExtraKeys registration complete.");
	}
}