Decompiled source of QuanDupeLightsources v1.1.1

QuanDupeLightsources.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("QuanDupeLightsources")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+03a0ff6312d709fbf10ff6ca1ec84c093d5597c5")]
[assembly: AssemblyProduct("QuanDupeLightsources")]
[assembly: AssemblyTitle("QuanDupeLightsources")]
[assembly: AssemblyVersion("1.1.1.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 QuanDupeLightsources
{
	[BepInPlugin("quandru.QuanDupeLightsources", "QuanDupeLightsources", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class QuanDupeLightsourcesPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "quandru.QuanDupeLightsources";

		public const string PluginName = "QuanDupeLightsources";

		public const string PluginVersion = "1.1.1";

		private const string QuanPiecesGuid = "quandru.QuanPieces";

		private const string NoSmokeStayLitGuid = "TastyChickenLegs.NoSmokeStayLit";

		private const string PrefabPrefix = "Quan_";

		private const string PrefabSuffix = "_alwayslit";

		private const string JotunnMockPrefix = "JVLmock_";

		private const string NameSuffix = " (Always Lit)";

		private const string HammerCategory = "QuanAlwaysLit";

		private static readonly string[] BasePrefabs = new string[8] { "piece_walltorch", "piece_groundtorch", "piece_groundtorch_wood", "piece_groundtorch_green", "piece_groundtorch_blue", "piece_brazierfloor01", "piece_brazierceiling01", "piece_jackoturnip" };

		private static readonly string[] QuanPiecesPrefabs = new string[2] { "Quan_streetlight_brazier", "Quan_streetlight_lantern" };

		private void Awake()
		{
			PrefabManager.OnVanillaPrefabsAvailable += AddClones;
		}

		private void AddClones()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= AddClones;
			List<string> list = BasePrefabs.Select((string b) => AddClone(b, "Quan_" + b)).ToList();
			if (Chainloader.PluginInfos.ContainsKey("quandru.QuanPieces"))
			{
				list.AddRange(QuanPiecesPrefabs.Select((string b) => AddClone(b, b + "_alwayslit")));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("QuanPieces isn't installed, so its street light duplicates (" + string.Join(", ", QuanPiecesPrefabs.Select((string b) => b + "_alwayslit")) + ") aren't added. The vanilla duplicates are unaffected. Install QuanPieces to get them."));
			}
			list.RemoveAll((string name) => name == null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Light source duplicates registered. Add to NoSmokeStayLit Custom Items Keep Lit: " + string.Join(",", list)));
			if (!Chainloader.PluginInfos.ContainsKey("TastyChickenLegs.NoSmokeStayLit"))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"NoSmokeStayLit isn't installed. The duplicates are still added, but without it they work exactly like the originals (they burn fuel and have no timer or always-lit behaviour). Install NoSmokeStayLit and list them under Custom Items Keep Lit to keep them lit.");
			}
		}

		private static string RealName(string name)
		{
			if (!name.StartsWith("JVLmock_", StringComparison.Ordinal))
			{
				return name;
			}
			return name.Substring("JVLmock_".Length);
		}

		private string AddClone(string baseName, string cloneName)
		{
			//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_005f: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab(baseName);
			Piece val = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<Piece>() : null);
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Base prefab '" + baseName + "' not found or has no Piece component; skipped."));
				return null;
			}
			PieceConfig val2 = new PieceConfig
			{
				Name = val.m_name + " (Always Lit)",
				Description = val.m_description,
				PieceTable = PieceTables.Hammer,
				Category = "QuanAlwaysLit",
				CraftingStation = (Object.op_Implicit((Object)(object)val.m_craftingStation) ? RealName(((Object)val.m_craftingStation).name) : string.Empty),
				Requirements = val.m_resources.Where((Requirement r) => r != null && (Object)(object)r.m_resItem != (Object)null).Select((Func<Requirement, RequirementConfig>)((Requirement r) => new RequirementConfig(RealName(((Object)r.m_resItem).name), r.m_amount, r.m_amountPerLevel, r.m_recover))).ToArray()
			};
			PieceManager.Instance.AddPiece(new CustomPiece(cloneName, baseName, val2));
			return cloneName;
		}
	}
	internal static class PluginInfo
	{
		public const string Version = "1.1.1";
	}
}