Decompiled source of ExtraKeys v1.1.0

ExtraKeys.dll

Decompiled a week ago
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.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
namespace ExtraKeys;

[BepInPlugin("com.digitaltoast.extrakeys", "ExtraKeys", "1.0.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.0.1";

	private AssetBundle keyBundle;

	private CustomLocalization Localization;

	private readonly string[] keyNames = new string[18]
	{
		"ExtraKeys_Magma", "ExtraKeys_BlackMarble", "ExtraKeys_Wood", "ExtraKeys_Stone", "ExtraKeys_Garden", "ExtraKeys_Lightning", "ExtraKeys_Ice", "ExtraKeys_Fire", "ExtraKeys_Amethyst", "ExtraKeys_Crystal",
		"ExtraKeys_Dungeon", "ExtraKeys_Skeleton", "ExtraKeys_Stoned", "ExtraKeys_Castle", "ExtraKeys_Red", "ExtraKeys_Blue", "ExtraKeys_Green", "ExtraKeys_Yellow"
	};

	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 assets!");
			return;
		}
		Logger.LogInfo((object)"ExtraKeys assets loaded.");
		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_blackmarble", "Black Marble Key" },
			{ "item_extrakeys_blackmarble_description", "A beautifully crafted key made from polished black marble." },
			{ "item_extrakeys_magma", "Magma Key" },
			{ "item_extrakeys_magma_description", "A key forged from molten rock, radiating intense heat." },
			{ "item_extrakeys_wood", "Wood Key" },
			{ "item_extrakeys_wood_description", "A simple key carved from sturdy oak wood." },
			{ "item_extrakeys_stone", "Stone Key" },
			{ "item_extrakeys_stone_description", "Heavy and rugged, this key is sculpted from solid stone." },
			{ "item_extrakeys_garden", "Garden Key" },
			{ "item_extrakeys_garden_description", "Covered in ivy, this key holds the secrets of the forest." },
			{ "item_extrakeys_lightning", "Lightning Key" },
			{ "item_extrakeys_lightning_description", "Static electricity fills the air as this key crackles with energy." },
			{ "item_extrakeys_ice", "Ice Key" },
			{ "item_extrakeys_ice_description", "This key is unnaturally 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_amethyst", "Amethyst Key" },
			{ "item_extrakeys_amethyst_description", "An ornate key with a deep purple gemstone." },
			{ "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_skeleton", "Skeleton Key" },
			{ "item_extrakeys_skeleton_description", "Made of bones, but it probably doesn't open every door." },
			{ "item_extrakeys_stoned", "Stoned Key" },
			{ "item_extrakeys_stoned_description", "Half stone, half tree. This key is well baked." },
			{ "item_extrakeys_castle", "Castle Key" },
			{ "item_extrakeys_castle_description", "A key carved from stone, used to unlock grand halls and royal chambers." },
			{ "item_extrakeys_red", "Red Key" },
			{ "item_extrakeys_red_description", "A generic looking red key." },
			{ "item_extrakeys_blue", "Blue Key" },
			{ "item_extrakeys_blue_description", "A generic looking blue key." },
			{ "item_extrakeys_green", "Green Key" },
			{ "item_extrakeys_green_description", "A generic looking green key." },
			{ "item_extrakeys_yellow", "Yellow Key" },
			{ "item_extrakeys_yellow_description", "A generic looking yellow key." }
		});
		Logger.LogInfo((object)"ExtraKeys localizations added.");
	}

	private void RegisterKeys()
	{
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Expected O, but got Unknown
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: 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");
			ItemConfig val7 = new ItemConfig();
			val7.Name = "$item_" + text.ToLower();
			val7.Description = "$item_" + text.ToLower() + "_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>();
			MeshRenderer[] array3 = componentsInChildren;
			foreach (MeshRenderer val11 in array3)
			{
				if ((Object)(object)val10 != (Object)null)
				{
					((Renderer)val11).sharedMaterials = (Material[])(object)new Material[1] { val10 };
				}
				else
				{
					((Renderer)val11).sharedMaterials = array ?? ((Renderer)val11).sharedMaterials;
				}
			}
			bool flag;
			switch (text)
			{
			case "ExtraKeys_Fire":
			case "ExtraKeys_Ice":
			case "ExtraKeys_Lightning":
			case "ExtraKeys_Magma":
				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, 
					_ => new Color(1f, 0.2f, 0f), 
				});
				if (1 == 0)
				{
				}
				val14.color = color;
			}
		}
		PrefabExtension.FixReferences((object)PrefabManager.Instance);
		Logger.LogInfo((object)"ExtraKeys registration complete.");
	}
}