Decompiled source of MuckCharcoal v1.3.0

MuckCharcoal.dll

Decompiled 4 months 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("MuckCharcoal")]
[assembly: AssemblyConfiguration("RELEASE")]
[assembly: AssemblyDescription("A simple plugin which adds Charcoal. Wood can be burned in a Furnace to produce Charcoal, which functions similarly to coal. The wood which can be turned into charcoal, how long it takes to create charcoal, and how many items charcoal smelts can be confiugred.")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+c83f9cd55aa6877169f18117cf58bacd7dbf7b9a")]
[assembly: AssemblyProduct("MuckCharcoal")]
[assembly: AssemblyTitle("MuckCharcoal")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BepInEx
{
	public static class Extensions
	{
		public static void LogItemCreated(this ManualLogSource log, InventoryItem item)
		{
			log.LogInfo((object)("Item \"" + item.name + "\" created, ID " + item.id));
		}

		public static ConfigEntry<int> BindMoreThanZero(this ConfigFile config, string section, string key, int defaultValue, string description)
		{
			ConfigEntry<int> val = config.Bind<int>(section, key, defaultValue, description);
			if (val.Value <= 0)
			{
				val.Value = defaultValue;
			}
			return val;
		}

		public static ConfigEntry<float> BindMoreThanZero(this ConfigFile config, string section, string key, float defaultValue, string description)
		{
			ConfigEntry<float> val = config.Bind<float>(section, key, defaultValue, description);
			if (val.Value <= 0f)
			{
				val.Value = defaultValue;
			}
			return val;
		}

		public static ConfigEntry<float> BindNonNegative(this ConfigFile config, string section, string key, float defaultValue, string description)
		{
			ConfigEntry<float> val = config.Bind<float>(section, key, defaultValue, description);
			if (val.Value < 0f)
			{
				val.Value = defaultValue;
			}
			return val;
		}

		public static ConfigEntry<int> BindNonNegative(this ConfigFile config, string section, string key, int defaultValue, string description)
		{
			ConfigEntry<int> val = config.Bind<int>(section, key, defaultValue, description);
			if ((float)val.Value < 0f)
			{
				val.Value = defaultValue;
			}
			return val;
		}

		public static InventoryItem Clone(this InventoryItem i)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			InventoryItem obj = ScriptableObject.CreateInstance<InventoryItem>();
			obj.amount = i.amount;
			obj.armor = i.armor;
			obj.armorComponent = i.armorComponent;
			obj.attackDamage = i.attackDamage;
			obj.attackRange = i.attackRange;
			obj.attackSpeed = i.attackSpeed;
			obj.attackTypes = i.attackTypes;
			obj.bowComponent = i.bowComponent;
			obj.buildRotation = i.buildRotation;
			obj.buildable = i.buildable;
			obj.craftAmount = i.craftAmount;
			obj.craftable = i.craftable;
			obj.description = i.description;
			obj.fuel = i.fuel;
			obj.grid = i.grid;
			obj.heal = i.heal;
			((Object)obj).hideFlags = ((Object)i).hideFlags;
			obj.hunger = i.hunger;
			obj.id = i.id;
			obj.important = i.important;
			obj.material = i.material;
			obj.max = i.max;
			obj.mesh = i.mesh;
			obj.name = i.name;
			obj.positionOffset = i.positionOffset;
			obj.prefab = i.prefab;
			obj.processTime = i.processTime;
			obj.processType = i.processType;
			obj.processable = i.processable;
			obj.processedItem = i.processedItem;
			obj.rarity = i.rarity;
			obj.requirements = i.requirements;
			obj.resourceDamage = i.resourceDamage;
			obj.rotationOffset = i.rotationOffset;
			obj.scale = i.scale;
			obj.sharpness = i.sharpness;
			obj.sprite = i.sprite;
			obj.stackable = i.stackable;
			obj.stamina = i.stamina;
			obj.stationRequirement = i.stationRequirement;
			obj.swingFx = i.swingFx;
			obj.tag = i.tag;
			obj.tier = i.tier;
			obj.type = i.type;
			obj.unlockWithFirstRequirementOnly = i.unlockWithFirstRequirementOnly;
			return obj;
		}
	}
}
namespace MuckCharcoal
{
	public class CreateRecipesPatch
	{
		[HarmonyPatch(typeof(ItemManager), "InitAllItems")]
		[HarmonyPostfix]
		private static void AddCoalRecipes()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: 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)
			InventoryItem val = ItemManager.Instance.allItems[2];
			InventoryItem val2 = ScriptableObject.CreateInstance<InventoryItem>();
			val2.important = val.important;
			val2.name = "Charcoal";
			val2.description = "crispy wood";
			val2.type = val.type;
			val2.tier = val.tier;
			val2.sprite = val.sprite;
			val2.material = val.material;
			val2.mesh = val.mesh;
			val2.rotationOffset = val.rotationOffset;
			val2.positionOffset = val.positionOffset;
			val2.scale = val.scale;
			val2.stackable = val.stackable;
			val2.amount = val.amount;
			val2.max = val.max;
			val2.resourceDamage = val.resourceDamage;
			val2.attackDamage = val.attackDamage;
			val2.attackSpeed = val.attackSpeed;
			val2.attackRange = val.attackRange;
			val2.sharpness = val.sharpness;
			val2.craftable = val.craftable;
			val2.unlockWithFirstRequirementOnly = val.unlockWithFirstRequirementOnly;
			val2.stationRequirement = val.stationRequirement;
			val2.buildable = val.buildable;
			val2.grid = val.grid;
			val2.prefab = val.prefab;
			val2.buildRotation = val.buildRotation;
			val2.processable = val.processable;
			val2.processType = val.processType;
			val2.processedItem = val.processedItem;
			val2.processTime = val.processTime;
			val2.heal = val.heal;
			val2.hunger = val.hunger;
			val2.stamina = val.stamina;
			val2.armor = val.armor;
			val2.swingFx = val.swingFx;
			val2.bowComponent = val.bowComponent;
			val2.armorComponent = val.armorComponent;
			val2.tag = val.tag;
			val2.rarity = val.rarity;
			val2.attackTypes = val.attackTypes;
			((Object)val2).hideFlags = ((Object)val).hideFlags;
			val2.craftAmount = 1;
			val2.requirements = val.requirements;
			val2.fuel = ScriptableObject.CreateInstance<ItemFuel>();
			val2.fuel.speedMultiplier = val.fuel.speedMultiplier;
			((Object)val2.fuel).hideFlags = ((Object)val.fuel).hideFlags;
			val2.fuel.maxUses = Plugin.MaxUses;
			val2.fuel.currentUses = Plugin.MaxUses;
			((Object)val2.fuel).name = val.name;
			val2.id = ItemManager.Instance.allItems.Keys.DefaultIfEmpty(0).Max() + 1;
			ItemManager.Instance.allItems.Add(val2.id, val2);
			Plugin.Log.LogItemCreated(val2);
			ItemManager.Instance.allScriptableItems = ItemManager.Instance.allScriptableItems.Concat((IEnumerable<InventoryItem>)(object)new InventoryItem[1] { val2 }).ToArray();
			HashSet<string> hashSet = new HashSet<string>(Plugin.ProcessableItems);
			foreach (InventoryItem value in ItemManager.Instance.allItems.Values)
			{
				if (hashSet.Contains(value.name))
				{
					Plugin.Log.LogInfo((object)("Making item smeltable into charcoal: " + value.name));
					value.processable = true;
					value.processType = (ProcessType)0;
					value.processTime = Plugin.WoodProcessTime;
					value.processedItem = val2;
					hashSet.Remove(value.name);
				}
			}
			foreach (string item in hashSet)
			{
				Plugin.Log.LogError((object)("This item was not found: " + item));
			}
		}
	}
	[BepInPlugin("MuckCharcoal.MichMcb", "Muck Charcoal", "1.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log = null;

		public static int MaxUses = 3;

		public static int WoodProcessTime = 5;

		public static string ProcessableItemNames = "Wood,Birch Wood,Fir Wood,Oak Wood,Dark Oak Wood";

		public static string[] ProcessableItems = new string[0];

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			MaxUses = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Main", "MaxUses", MaxUses, "The number of items that one piece of charcoal can smelt or cook").Value;
			WoodProcessTime = ((BaseUnityPlugin)this).Config.BindMoreThanZero("Main", "WoodProcessTime", WoodProcessTime, "The time, in seconds, it takes to burn one piece of wood and turn it into charcoal").Value;
			ProcessableItemNames = ((BaseUnityPlugin)this).Config.Bind<string>("Main", "ProcessableItemNames", ProcessableItemNames, "The comma-separated item names which can be processed in a furnace and turned into charcoal").Value;
			ProcessableItems = ProcessableItemNames.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"MuckCharcoal loaded!");
			((BaseUnityPlugin)this).Config.Save();
			Harmony.CreateAndPatchAll(typeof(CreateRecipesPatch), (string)null);
		}
	}
}