Decompiled source of Ranensols Carpentry v1.0.0

Ranensol.BepInEx.Aska.Carpentry.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SSSGame;
using SandSailorStudio.Inventory;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Ranensol.BepInEx.Aska.Carpentry")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+94489916dd359dba49d0f9f5aa328113dd2f1f0c")]
[assembly: AssemblyProduct("Ranensol Carpentry")]
[assembly: AssemblyTitle("Ranensol.BepInEx.Aska.Carpentry")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Ranensol.BepInEx.Aska.Carpentry
{
	[HarmonyPatch(typeof(InventoryComponent), "Start")]
	internal class InventoryComponent_Start_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(InventoryComponent __instance)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			if (Plugin.MaxCarpentryQuantityA <= 0 || __instance == null || ((Object)__instance).name == null || !((Object)__instance).name.Contains("CarpenterHorse_A") || __instance.items == null || __instance.items._containers == null || __instance.items._containers.Count <= 0)
			{
				return;
			}
			int capacity = __instance.items._containers[0].capacity;
			if (capacity < Plugin.MaxCarpentryQuantityA)
			{
				__instance.items._containers[0].capacity = Plugin.MaxCarpentryQuantityA;
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(40, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Adjusted CarpenterHorse_A capacity: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(capacity);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Plugin.MaxCarpentryQuantityA);
				}
				log.LogInfo(val);
			}
		}
	}
	[HarmonyPatch(typeof(ItemContainerComponent), "Initialize")]
	internal class ItemContainerComponent_Initialize_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(ItemContainerComponent __instance)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			if (Plugin.MaxCarpentryQuantityB <= 0 || __instance == null || ((Object)__instance).name == null || !((Object)__instance).name.Contains("CarpenterHorse_B") || __instance.container == null)
			{
				return;
			}
			int capacity = __instance.container.capacity;
			if (capacity < Plugin.MaxCarpentryQuantityB)
			{
				__instance.container.capacity = Plugin.MaxCarpentryQuantityB;
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(40, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Adjusted CarpenterHorse_B capacity: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(capacity);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Plugin.MaxCarpentryQuantityB);
				}
				log.LogInfo(val);
			}
		}
	}
	[HarmonyPatch(typeof(ItemInfoDatabase), "Initialize")]
	internal class ItemInfoDatabase_Initialize_Patch
	{
		private static bool _hasRun;

		[HarmonyPostfix]
		private static void Postfix(ItemInfoDatabase __instance)
		{
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Expected O, but got Unknown
			if (_hasRun)
			{
				return;
			}
			_hasRun = true;
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Modifying carpenter recipes");
			}
			log.LogInfo(val);
			try
			{
				Enumerator<int, ItemInfo> enumerator = ((Il2CppObjectBase)__instance._itemsMap).Cast<Dictionary<int, ItemInfo>>().GetEnumerator();
				while (enumerator.MoveNext())
				{
					ForgingBlueprintInfo val2 = ((Il2CppObjectBase)enumerator.Current.Value).TryCast<ForgingBlueprintInfo>();
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					ItemInfo result = ((BlueprintInfo)val2).result;
					if (((result != null) ? ((Object)result).name : null) == "Item_Wood_Shaft" && ((BlueprintInfo)val2).parts != null && ((Il2CppArrayBase<ItemInfoQuantity>)(object)((BlueprintInfo)val2).parts).Length > 0)
					{
						ItemInfo itemInfo = ((Il2CppArrayBase<ItemInfoQuantity>)(object)((BlueprintInfo)val2).parts)[0].itemInfo;
						if (((itemInfo != null) ? ((Object)itemInfo).name : null) == "Item_Wood_HardWoodLongStick")
						{
							ModifyRecipe(val2, "Shafts", Plugin.Recipes["Shafts"].ValidatedQuantity, isBenchA: true);
							continue;
						}
					}
					ItemInfo result2 = ((BlueprintInfo)val2).result;
					if (((result2 != null) ? ((Object)result2).name : null) == "Item_Wood_Plank" && ((BlueprintInfo)val2).parts != null && ((Il2CppArrayBase<ItemInfoQuantity>)(object)((BlueprintInfo)val2).parts).Length > 0)
					{
						ItemInfo itemInfo2 = ((Il2CppArrayBase<ItemInfoQuantity>)(object)((BlueprintInfo)val2).parts)[0].itemInfo;
						if (((itemInfo2 != null) ? ((Object)itemInfo2).name : null) == "Item_Wood_HardWoodLog")
						{
							ModifyRecipe(val2, "Planks", Plugin.Recipes["Planks"].ValidatedQuantity, isBenchA: true);
							continue;
						}
					}
					ItemInfo result3 = ((BlueprintInfo)val2).result;
					if (((result3 != null) ? ((Object)result3).name : null) == "Item_Wood_Beam" && ((BlueprintInfo)val2).parts != null && ((Il2CppArrayBase<ItemInfoQuantity>)(object)((BlueprintInfo)val2).parts).Length > 0)
					{
						ItemInfo itemInfo3 = ((Il2CppArrayBase<ItemInfoQuantity>)(object)((BlueprintInfo)val2).parts)[0].itemInfo;
						if (((itemInfo3 != null) ? ((Object)itemInfo3).name : null) == "Item_Wood_HardWoodLongStick")
						{
							ModifyRecipe(val2, "Beams", Plugin.Recipes["Beams"].ValidatedQuantity, isBenchA: false);
							continue;
						}
					}
					ItemInfo result4 = ((BlueprintInfo)val2).result;
					if (((result4 != null) ? ((Object)result4).name : null) == "Item_Wood_Post" && ((BlueprintInfo)val2).parts != null && ((Il2CppArrayBase<ItemInfoQuantity>)(object)((BlueprintInfo)val2).parts).Length > 0)
					{
						ItemInfo itemInfo4 = ((Il2CppArrayBase<ItemInfoQuantity>)(object)((BlueprintInfo)val2).parts)[0].itemInfo;
						if (((itemInfo4 != null) ? ((Object)itemInfo4).name : null) == "Item_Wood_HardWoodLog")
						{
							ModifyRecipe(val2, "Posts", Plugin.Recipes["Posts"].ValidatedQuantity, isBenchA: false);
						}
					}
				}
				ManualLogSource log2 = Plugin.Log;
				val = new BepInExInfoLogInterpolatedStringHandler(28, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Recipe modification complete");
				}
				log2.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource log3 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Error modifying recipes: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
				}
				log3.LogError(val3);
			}
		}

		private static void ModifyRecipe(ForgingBlueprintInfo blueprint, string recipeName, int newQuantity, bool isBenchA)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			int quantity = ((BlueprintInfo)blueprint).quantity;
			((BlueprintInfo)blueprint).quantity = newQuantity;
			if (isBenchA)
			{
				Plugin.MaxCarpentryQuantityA = Math.Max(Plugin.MaxCarpentryQuantityA, newQuantity);
			}
			else
			{
				Plugin.MaxCarpentryQuantityB = Math.Max(Plugin.MaxCarpentryQuantityB, newQuantity);
			}
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(15, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Modified ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(recipeName);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(quantity);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(newQuantity);
			}
			log.LogInfo(val);
		}
	}
	[BepInPlugin("Ranensol.BepInEx.Aska.Carpentry", "Ranensol Carpentry", "1.0.0")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Log;

		internal static Dictionary<string, RecipeConfig> Recipes { get; private set; }

		internal static int MaxCarpentryQuantityA { get; set; }

		internal static int MaxCarpentryQuantityB { get; set; }

		public override void Load()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(14, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loading plugin");
			}
			log.LogInfo(val);
			InitializeRecipes();
			InitializeConfig();
			ValidateConfig();
			new Harmony("Ranensol.BepInEx.Aska.Carpentry").PatchAll();
			ManualLogSource log2 = Log;
			val = new BepInExInfoLogInterpolatedStringHandler(26, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin loaded successfully");
			}
			log2.LogInfo(val);
		}

		private void InitializeRecipes()
		{
			Recipes = new Dictionary<string, RecipeConfig>
			{
				{
					"Shafts",
					new RecipeConfig("Shafts", 2, "Carpentry A - Quantities", "Number of shafts produced from 1 hardwood long stick")
				},
				{
					"Planks",
					new RecipeConfig("Planks", 2, "Carpentry A - Quantities", "Number of planks produced from 1 hardwood log")
				},
				{
					"Beams",
					new RecipeConfig("Beams", 1, "Carpentry B - Quantities", "Number of beams produced from 1 hardwood long stick")
				},
				{
					"Posts",
					new RecipeConfig("Posts", 1, "Carpentry B - Quantities", "Number of posts produced from 1 hardwood log")
				}
			};
		}

		private void InitializeConfig()
		{
			foreach (RecipeConfig value in Recipes.Values)
			{
				value.ConfigEntry = ((BasePlugin)this).Config.Bind<int>(value.Section, value.Name, value.DefaultValue, $"{value.Description} (default: {value.DefaultValue})");
			}
		}

		private static void ValidateConfig()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			foreach (RecipeConfig value in Recipes.Values)
			{
				value.ValidatedQuantity = ValidateQuantity(value.ConfigEntry.Value, value.Name, value.DefaultValue);
			}
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(52, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Config loaded - Shafts: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Recipes["Shafts"].ValidatedQuantity);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Planks: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Recipes["Planks"].ValidatedQuantity);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Beams: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Recipes["Beams"].ValidatedQuantity);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Posts: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Recipes["Posts"].ValidatedQuantity);
			}
			log.LogInfo(val);
		}

		private static int ValidateQuantity(int value, string itemName, int defaultValue)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			if (value < 1)
			{
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(56, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Invalid ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(itemName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" quantity: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(value);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(". Must be at least 1. Using default: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(defaultValue);
				}
				log.LogError(val);
				return defaultValue;
			}
			return value;
		}
	}
	internal class RecipeConfig
	{
		public string Name { get; }

		public int DefaultValue { get; }

		public string Section { get; }

		public string Description { get; }

		public ConfigEntry<int> ConfigEntry { get; set; }

		public int ValidatedQuantity { get; set; }

		public RecipeConfig(string name, int defaultValue, string section, string description)
		{
			Name = name;
			DefaultValue = defaultValue;
			Section = section;
			Description = description;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Ranensol.BepInEx.Aska.Carpentry";

		public const string PLUGIN_NAME = "Ranensol Carpentry";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}