Decompiled source of GuckLantern v0.0.1

plugins/GuckLantern.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
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("GuckLantern")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GuckLantern")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace GuckLantern;

[BepInPlugin("thedefside.GuckLantern", "GuckLantern", "0.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class GuckLantern : BaseUnityPlugin
{
	public const string PluginGUID = "thedefside.GuckLantern";

	public const string PluginName = "GuckLantern";

	public const string PluginVersion = "0.0.1";

	public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

	private void Awake()
	{
		PrefabManager.OnPrefabsRegistered += AddClonedItems;
	}

	private void AddClonedItems()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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)
		//IL_0079: 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_008a: Expected O, but got Unknown
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Expected O, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Expected O, but got Unknown
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: 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_0128: Expected O, but got Unknown
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Expected O, but got Unknown
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Expected O, but got Unknown
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Expected O, but got Unknown
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Expected O, but got Unknown
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Expected O, but got Unknown
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Expected O, but got Unknown
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Expected O, but got Unknown
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Expected O, but got Unknown
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Expected O, but got Unknown
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Expected O, but got Unknown
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Expected O, but got Unknown
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_036e: Expected O, but got Unknown
		//IL_0370: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: Unknown result type (might be due to invalid IL or missing references)
		//IL_0381: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Expected O, but got Unknown
		//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Expected O, but got Unknown
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Expected O, but got Unknown
		//IL_0411: Unknown result type (might be due to invalid IL or missing references)
		//IL_0416: Unknown result type (might be due to invalid IL or missing references)
		//IL_0422: Unknown result type (might be due to invalid IL or missing references)
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0433: Expected O, but got Unknown
		//IL_0435: Unknown result type (might be due to invalid IL or missing references)
		//IL_043a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0446: Unknown result type (might be due to invalid IL or missing references)
		//IL_044e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0457: Expected O, but got Unknown
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Expected O, but got Unknown
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_049e: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a5: Expected O, but got Unknown
		//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04db: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f8: Expected O, but got Unknown
		//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_050b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0513: Unknown result type (might be due to invalid IL or missing references)
		//IL_051c: Expected O, but got Unknown
		//IL_0537: Unknown result type (might be due to invalid IL or missing references)
		//IL_053e: Expected O, but got Unknown
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_0563: Unknown result type (might be due to invalid IL or missing references)
		//IL_056a: Expected O, but got Unknown
		//IL_059b: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bd: Expected O, but got Unknown
		//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e1: Expected O, but got Unknown
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0603: Expected O, but got Unknown
		//IL_0606: Unknown result type (might be due to invalid IL or missing references)
		//IL_0628: Unknown result type (might be due to invalid IL or missing references)
		//IL_062f: Expected O, but got Unknown
		//IL_0660: Unknown result type (might be due to invalid IL or missing references)
		//IL_0665: Unknown result type (might be due to invalid IL or missing references)
		//IL_0671: Unknown result type (might be due to invalid IL or missing references)
		//IL_0679: Unknown result type (might be due to invalid IL or missing references)
		//IL_0682: Expected O, but got Unknown
		//IL_0684: Unknown result type (might be due to invalid IL or missing references)
		//IL_0689: Unknown result type (might be due to invalid IL or missing references)
		//IL_0695: Unknown result type (might be due to invalid IL or missing references)
		//IL_069d: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a6: Expected O, but got Unknown
		//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c8: Expected O, but got Unknown
		//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			PieceConfig val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Guck Lantern";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "Guck",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("GuckLamp");
			CustomPiece val2 = new CustomPiece("GuckLantern", "rk_lamp", val);
			ChangeColor(val2, Color.green);
			PieceManager.Instance.AddPiece(val2);
			val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Guck Hanging Lantern";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "Guck",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("GuckLampHanging");
			CustomPiece val3 = new CustomPiece("GuckHangingLantern", "rk_lamphanging", val);
			ChangeColor(val3, Color.green);
			PieceManager.Instance.AddPiece(val3);
			val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Guck Lamp Post";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "Guck",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("GuckLampPost");
			CustomPiece val4 = new CustomPiece("GuckLampPost", "rk_lamppost", val);
			ChangeColor(val4, Color.green);
			PieceManager.Instance.AddPiece(val4);
			val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Blood Lantern";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "Bloodbag",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("BloodLamp");
			CustomPiece val5 = new CustomPiece("BloodLantern", "rk_lamp", val);
			ChangeColor(val5, Color.red);
			PieceManager.Instance.AddPiece(val5);
			val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Blood Hanging Lantern";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "Bloodbag",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("BloodLampHanging");
			CustomPiece val6 = new CustomPiece("BloodHangingLantern", "rk_lamphanging", val);
			ChangeColor(val6, Color.red);
			PieceManager.Instance.AddPiece(val6);
			val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Blood Lamp Post";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "Bloodbag",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("BloodLampPost");
			CustomPiece val7 = new CustomPiece("BloodLampPost", "rk_lamppost", val);
			ChangeColor(val7, Color.red);
			PieceManager.Instance.AddPiece(val7);
			val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Frost Lantern";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "FreezeGland",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("FrostLamp");
			CustomPiece val8 = new CustomPiece("FrostLantern", "rk_lamp", val);
			ChangeColor(val8, Color.blue);
			PieceManager.Instance.AddPiece(val8);
			val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Frost Hanging Lantern";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "FreezeGland",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("FrostLampHanging");
			CustomPiece val9 = new CustomPiece("FrostHangingLantern", "rk_lamphanging", val);
			ChangeColor(val9, Color.blue);
			PieceManager.Instance.AddPiece(val9);
			val = new PieceConfig();
			val.PieceTable = "_RKCustomTable";
			val.Name = "Frost Lamp Post";
			val.Category = "Furniture";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig
				{
					Item = "Tin",
					Amount = 2,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "FreezeGland",
					Amount = 2,
					Recover = true
				}
			};
			val.Icon = LoadEmbeddedSprite("FrostLampPost");
			CustomPiece val10 = new CustomPiece("FrostLampPost", "rk_lamppost", val);
			ChangeColor(val10, Color.blue);
			PieceManager.Instance.AddPiece(val10);
		}
		catch (Exception ex)
		{
			Logger.LogError((object)(ex.Message + ex.StackTrace));
		}
		finally
		{
			PrefabManager.OnPrefabsRegistered -= AddClonedItems;
		}
	}

	private Sprite LoadEmbeddedSprite(string imageName)
	{
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected O, but got Unknown
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		string text = executingAssembly.GetManifestResourceNames().SingleOrDefault((string str) => str.EndsWith("." + imageName + ".png"));
		if (text == null)
		{
			throw new Exception(imageName + ".png not found.");
		}
		Logger.LogDebug((object)("Resource name : " + text));
		Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(text);
		byte[] array = ReadFully(manifestResourceStream);
		Logger.LogDebug((object)$"Byte array length : {array.Length}");
		Texture2D val = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, array);
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero);
	}

	public static byte[] ReadFully(Stream input)
	{
		using MemoryStream memoryStream = new MemoryStream();
		input.CopyTo(memoryStream);
		return memoryStream.ToArray();
	}

	private void ChangeColor(CustomPiece go, Color color)
	{
		//IL_000c: 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_0035: 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)
		//IL_0042: Expected O, but got Unknown
		go.PiecePrefab.GetComponentInChildren<Light>().color = color;
		MeshRenderer[] componentsInChildren = go.PiecePrefab.GetComponentsInChildren<MeshRenderer>();
		foreach (MeshRenderer val in componentsInChildren)
		{
			((Renderer)val).material = new Material(((Renderer)val).material)
			{
				color = color
			};
		}
	}
}