Decompiled source of BlastFurnaceOres v0.1.0

plugins/BlastFurnaceOres.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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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("BlastFurnaceOres")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+66b9bf994e70cf56944faaa61088bfab5411a354")]
[assembly: AssemblyProduct("BlastFurnaceOres")]
[assembly: AssemblyTitle("BlastFurnaceOres")]
[assembly: AssemblyVersion("0.1.0.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 BlastFurnaceOres
{
	[BepInPlugin("sansara.BlastFurnaceOres", "Blast Furnace Ores", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "sansara.BlastFurnaceOres";

		public const string Name = "Blast Furnace Ores";

		public const string Version = "0.1.0";

		internal const string FurnacePrefab = "blastfurnace";

		internal const string SourcePrefab = "smelter";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<string> Excluded;

		private static List<ItemConversion> s_original;

		private void Awake()
		{
			//IL_002a: 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_0037: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Server", "Enabled", true, new ConfigDescription("Доменная печь принимает всё, что принимает плавильня (руда и лом меди, олова, железа, серебра, бронзы).", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			Excluded = ((BaseUnityPlugin)this).Config.Bind<string>("Server", "Excluded", "", new ConfigDescription("Имена префабов через запятую, которые доменной печи не добавлять, например: CopperOre, TinOre.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			Enabled.SettingChanged += delegate
			{
				Apply();
			};
			Excluded.SettingChanged += delegate
			{
				Apply();
			};
			new Harmony("sansara.BlastFurnaceOres").PatchAll();
			Log.LogInfo((object)"Blast Furnace Ores 0.1.0 загружен.");
		}

		internal static void Apply()
		{
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Expected O, but got Unknown
			ZNetScene instance = ZNetScene.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			GameObject prefab = instance.GetPrefab("blastfurnace");
			Smelter val = ((prefab != null) ? prefab.GetComponent<Smelter>() : null);
			GameObject prefab2 = instance.GetPrefab("smelter");
			Smelter val2 = ((prefab2 != null) ? prefab2.GetComponent<Smelter>() : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Log.LogWarning((object)"Не найден префаб blastfurnace или smelter, доменная печь не изменена.");
				return;
			}
			if (s_original == null)
			{
				s_original = val.m_conversion.ToList();
			}
			List<ItemConversion> list = s_original.ToList();
			List<string> list2 = new List<string>();
			if (Enabled.Value)
			{
				HashSet<string> hashSet = new HashSet<string>(Excluded.Value.Split(new char[3] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries), StringComparer.OrdinalIgnoreCase);
				foreach (ItemConversion item in val2.m_conversion)
				{
					if (!((Object)(object)item.m_from == (Object)null) && !((Object)(object)item.m_to == (Object)null))
					{
						string from = ((Object)((Component)item.m_from).gameObject).name;
						if (!hashSet.Contains(from) && !list.Any((ItemConversion c) => (Object)(object)c.m_from != (Object)null && ((Object)((Component)c.m_from).gameObject).name == from))
						{
							list.Add(new ItemConversion
							{
								m_from = item.m_from,
								m_to = item.m_to
							});
							list2.Add(Describe(item));
						}
					}
				}
			}
			val.m_conversion = list;
			int num = 0;
			Smelter[] array = Object.FindObjectsByType<Smelter>((FindObjectsSortMode)0);
			foreach (Smelter val3 in array)
			{
				if ((Object)(object)val3 != (Object)(object)val && Utils.GetPrefabName(((Component)val3).gameObject) == "blastfurnace")
				{
					val3.m_conversion = list.ToList();
					num++;
				}
			}
			string arg = string.Join(", ", s_original.Where((ItemConversion c) => (Object)(object)c.m_from != (Object)null && (Object)(object)c.m_to != (Object)null).Select(Describe));
			Log.LogInfo((object)(string.Format("Доменная печь: своё [{0}]; добавлено {1} [{2}]; ", arg, list2.Count, string.Join(", ", list2)) + $"печей в сцене обновлено: {num}."));
		}

		private static string Describe(ItemConversion c)
		{
			return ((Object)((Component)c.m_from).gameObject).name + "(" + c.m_from.m_itemData.m_shared.m_name + ")→" + ((Object)((Component)c.m_to).gameObject).name;
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	internal static class ZNetSceneAwakePatch
	{
		private static void Postfix()
		{
			Plugin.Apply();
		}
	}
}