Decompiled source of CustomizedBronze v0.0.20

plugin/CustomizedBronze.dll

Decompiled 7 months ago
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Common;
using Jotunn;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Plugin;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CustomizedBronze")]
[assembly: AssemblyDescription("Allows the user to customize the bronze recipe.")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCompany("Nitrinax")]
[assembly: AssemblyProduct("CustomizedBronze")]
[assembly: AssemblyCopyright("GNU GPL V3")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("0.0.20")]
[assembly: NeutralResourcesLanguage("English")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.20.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 Plugin
{
	internal class Data
	{
		public const string Namespace = "CustomizedBronze";

		public const string ModName = "CustomizedBronze";

		public const string Company = "Nitrinax";

		public const string Version = "0.0.20";

		public const string ModGuid = "Nitrinax.CustomizedBronze";

		public const string Description = "Allows the user to customize the bronze recipe.";

		public const string Configuration = "Release";

		public const string Copyright = "GNU GPL V3";

		public const string Trademark = "";

		public const string Culture = "";

		public const string Language = "English";

		public const string PluginDefaultLanguage = "English";

		public static string ConfigCategoryGeneral = "General";

		public static string ConfigEntryEnabled = "Enabled";

		public static string ConfigEntryEnabledDescription = "Enable this mod";

		public static bool ConfigEntryEnabledDefaultState = true;

		public static string ConfigEntryNexusID = "NexusID";

		public static string ConfigEntryNexusIDDescription = "Nexus mod ID for updates";

		public static int ConfigEntryNexusIDID = 1898;

		public static string ConfigCategoryPlugin = "Plugin";

		public static string ConfigEntryShowChangesAtStartup = "ShowChangesAtStartup";

		public static bool ConfigEntryShowChangesAtStartupDefaultState = true;

		public static string ConfigEntryShowChangesAtStartupDescription = "If this option is set, the changes made by this mod are displayed in the console log.";
	}
	internal class Dependencies
	{
		public const string EngineName = "Unity";

		public const string EngineVersion = "2020.3.45f1";

		public const string GameName = "Valheim";

		public const string GameVersion = "0.217.25";

		public const string BepInExName = "BepInExPack Valheim";

		public const string BepInExVersion = "5.4.22.0";

		public const bool IsJotunnRequired = true;

		public const string JotunnName = "Jotunn, the Valheim Library";

		public const string JotunnVersion = "2.14.5";

		public const bool IsOtherPluginsRequired = false;

		public static string[] RequiredPlugins = new string[1] { "" };

		public const bool IsFilesRequired = false;

		public static string[] RequiredFiles = new string[1] { "" };
	}
}
namespace CustomizedBronze
{
	[BepInPlugin("Nitrinax.CustomizedBronze", "CustomizedBronze", "0.0.20")]
	[BepInProcess("valheim.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class CustomizedBronze : BaseUnityPlugin
	{
		public enum BronzeAlloy
		{
			[Description("Default")]
			Default,
			[Description("WoWlike")]
			WoWlike,
			[Description("Realistic")]
			Realistic,
			[Description("Custom")]
			Custom
		}

		public static bool isModded = true;

		private static readonly string s_CRLF = Environment.NewLine;

		private static readonly string s_CRLF2 = Environment.NewLine + Environment.NewLine;

		private static int[] DefaultAlloy = new int[3] { 2, 1, 1 };

		private static int[] WoWlikeAlloy = new int[3] { 1, 1, 2 };

		private static int[] RealisticAlloy = new int[3] { 2, 1, 3 };

		private static string ConfigCategoryRecipeAlloy = "Recipe Alloy";

		private static string ConfigEntryAttention = "Please note: After changing settings, you must log out and log in for the changes to be applied.";

		private static string ConfigEntryRecipeAlloy = "Alloy Type";

		private static string ConfigEntryRecipeAlloyDescription = "Alloy composition:" + s_CRLF + "(" + ConfigEntryAttention + ")" + s_CRLF2 + "Default = the standard alloy from Valheim" + s_CRLF + "(2 Copper + 1 Tin = 1 Bronze)" + s_CRLF + "[If you select this preset, your custom settings will be ignored.]" + s_CRLF2 + "WoWlike = an alloy like in World of Warcraft" + s_CRLF + "(50 percent alloy, 1 Copper + 1 Tin = 2 Bronze)" + s_CRLF + "[If you select this preset, your custom settings will be ignored.]" + s_CRLF2 + "Realistic = a more realistic alloy" + s_CRLF + "(60 percent alloy, 2 Copper + 1 Tin = 3 Bronze)" + s_CRLF + "[If you select this preset, your custom settings will be ignored.]" + s_CRLF2 + "Custom = a custom alloy with the mixing ratio you set " + s_CRLF + "[If you select this, your custom settings will be used.]" + s_CRLF;

		private static string ConfigCategoryRecipeCustom = "Recipe Custom";

		private static string ConfigEntryRecipeCustomCopper = "Required Copper";

		private static string ConfigEntryRecipeCustomCopperDescription = "Sets amount of needed of Copper.";

		private static string ConfigEntryRecipeCustomTin = "Required Tin";

		private static string ConfigEntryRecipeCustomTinDescription = "Sets amount of needed of Tin.";

		private static string ConfigEntryRecipeCustomBronze = "Produced Bronze";

		private static string ConfigEntryRecipeCustomBronzeDescription = "Sets the amount of bronze produced.";

		public static ConfigEntry<bool> configModEnabled;

		public static ConfigEntry<int> configNexusID;

		public static ConfigEntry<bool> configShowChangesAtStartup;

		public static ConfigEntry<BronzeAlloy> configBronzeAlloy;

		public static ConfigEntry<int> configRecipeNeededCopper;

		public static ConfigEntry<int> configRecipeNeededTin;

		public static ConfigEntry<int> configRecipeProducedBronze;

		private int usedRequirementCopper;

		private int usedRequirementTin;

		private int usedQuantityBronze;

		private void Awake()
		{
			if (!DependencyOperations.CheckForDependencyErrors("CustomizedBronze"))
			{
				CreateConfigValues();
				if ((bool)((BaseUnityPlugin)this).Config[Data.ConfigCategoryGeneral, Data.ConfigEntryEnabled].BoxedValue)
				{
					ItemManager.OnItemsRegistered += OnItemsRegistered;
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"CustomizedBronze is disabled by config.");
				}
			}
		}

		private void Update()
		{
		}

		private void CreateConfigValues()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_0147: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Expected O, but got Unknown
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			configModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(Data.ConfigCategoryGeneral, Data.ConfigEntryEnabled, Data.ConfigEntryEnabledDefaultState, new ConfigDescription(Data.ConfigEntryEnabledDescription, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				Order = 0
			} }));
			configNexusID = ((BaseUnityPlugin)this).Config.Bind<int>(Data.ConfigCategoryGeneral, Data.ConfigEntryNexusID, Data.ConfigEntryNexusIDID, new ConfigDescription(Data.ConfigEntryNexusIDDescription, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				Browsable = false,
				Order = 1,
				ReadOnly = true
			} }));
			configShowChangesAtStartup = ((BaseUnityPlugin)this).Config.Bind<bool>(Data.ConfigCategoryPlugin, Data.ConfigEntryShowChangesAtStartup, Data.ConfigEntryShowChangesAtStartupDefaultState, new ConfigDescription(Data.ConfigEntryShowChangesAtStartupDescription, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				Order = 0
			} }));
			configBronzeAlloy = ((BaseUnityPlugin)this).Config.Bind<BronzeAlloy>(ConfigCategoryRecipeAlloy, ConfigEntryRecipeAlloy, BronzeAlloy.Default, new ConfigDescription(ConfigEntryRecipeAlloyDescription, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				DefaultValue = BronzeAlloy.Default,
				Order = 1,
				DispName = ConfigEntryRecipeAlloy + s_CRLF2 + ConfigEntryAttention
			} }));
			configRecipeNeededCopper = ((BaseUnityPlugin)this).Config.Bind<int>(ConfigCategoryRecipeCustom, ConfigEntryRecipeCustomCopper, DefaultAlloy[0], new ConfigDescription(ConfigEntryRecipeCustomCopperDescription, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				Order = 0
			} }));
			configRecipeNeededTin = ((BaseUnityPlugin)this).Config.Bind<int>(ConfigCategoryRecipeCustom, ConfigEntryRecipeCustomTin, DefaultAlloy[1], new ConfigDescription(ConfigEntryRecipeCustomTinDescription, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				Order = 1
			} }));
			configRecipeProducedBronze = ((BaseUnityPlugin)this).Config.Bind<int>(ConfigCategoryRecipeCustom, ConfigEntryRecipeCustomBronze, DefaultAlloy[2], new ConfigDescription(ConfigEntryRecipeCustomBronzeDescription, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				Order = 2
			} }));
			SynchronizationManager.OnConfigurationSynchronized += delegate(object obj, ConfigurationSynchronizationEventArgs attr)
			{
				if (attr.InitialSynchronization)
				{
					Logger.LogMessage((object)"Initial Config sync event received");
				}
				else
				{
					Logger.LogMessage((object)"Config sync event received");
				}
			};
		}

		private void ReadConfigValues()
		{
			bool flag = (bool)((BaseUnityPlugin)this).Config[Data.ConfigCategoryPlugin, Data.ConfigEntryShowChangesAtStartup].BoxedValue;
			switch ((BronzeAlloy)((BaseUnityPlugin)this).Config[ConfigCategoryRecipeAlloy, ConfigEntryRecipeAlloy].BoxedValue)
			{
			case BronzeAlloy.Default:
				if (flag)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Default option selected");
				}
				usedRequirementCopper = DefaultAlloy[0];
				usedRequirementTin = DefaultAlloy[1];
				usedQuantityBronze = DefaultAlloy[2];
				break;
			case BronzeAlloy.WoWlike:
				if (flag)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"WoWlike option selected");
				}
				usedRequirementCopper = WoWlikeAlloy[0];
				usedRequirementTin = WoWlikeAlloy[1];
				usedQuantityBronze = WoWlikeAlloy[2];
				break;
			case BronzeAlloy.Realistic:
				if (flag)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Realistic option selected");
				}
				usedRequirementCopper = RealisticAlloy[0];
				usedRequirementTin = RealisticAlloy[1];
				usedQuantityBronze = RealisticAlloy[2];
				break;
			case BronzeAlloy.Custom:
				if (flag)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Custom option selected");
				}
				usedRequirementCopper = (int)((BaseUnityPlugin)this).Config[ConfigCategoryRecipeCustom, ConfigEntryRecipeCustomCopper].BoxedValue;
				usedRequirementTin = (int)((BaseUnityPlugin)this).Config[ConfigCategoryRecipeCustom, ConfigEntryRecipeCustomTin].BoxedValue;
				usedQuantityBronze = (int)((BaseUnityPlugin)this).Config[ConfigCategoryRecipeCustom, ConfigEntryRecipeCustomBronze].BoxedValue;
				break;
			default:
				if (flag)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"unknown option selected");
				}
				break;
			}
		}

		private void OnItemsRegistered()
		{
			try
			{
				ReadConfigValues();
				ChangeBronzeRecipe();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Error OnItemsRegistered : " + ex.Message));
			}
			finally
			{
				PrefabManager.OnPrefabsRegistered -= OnItemsRegistered;
			}
		}

		private void ChangeBronzeRecipe()
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			int amount = 0;
			int amount2 = 0;
			int amount3 = 0;
			bool flag = (bool)((BaseUnityPlugin)this).Config[Data.ConfigCategoryPlugin, Data.ConfigEntryShowChangesAtStartup].BoxedValue;
			foreach (Recipe item2 in ObjectDB.instance.m_recipes.Where(delegate(Recipe r)
			{
				ItemDrop item = r.m_item;
				return ((item != null) ? ((Object)item).name : null) == "Bronze";
			}))
			{
				if (((Object)item2).name == "Recipe_Bronze")
				{
					amount = usedRequirementCopper;
					amount2 = usedRequirementTin;
					amount3 = usedQuantityBronze;
					item2.m_resources = (Requirement[])(object)new Requirement[2]
					{
						new Requirement
						{
							m_resItem = Cache.GetPrefab<ItemDrop>("Copper"),
							m_amount = amount
						},
						new Requirement
						{
							m_resItem = Cache.GetPrefab<ItemDrop>("Tin"),
							m_amount = amount2
						}
					};
					item2.m_amount = amount3;
				}
				else if (((Object)item2).name == "Recipe_Bronze5")
				{
					amount = usedRequirementCopper * 5;
					amount2 = usedRequirementTin * 5;
					amount3 = usedQuantityBronze * 5;
					item2.m_resources = (Requirement[])(object)new Requirement[2]
					{
						new Requirement
						{
							m_resItem = Cache.GetPrefab<ItemDrop>("Copper"),
							m_amount = amount
						},
						new Requirement
						{
							m_resItem = Cache.GetPrefab<ItemDrop>("Tin"),
							m_amount = amount2
						}
					};
					item2.m_amount = amount3;
				}
				if (flag)
				{
					Logger.LogInfo((object)("changed " + ((Object)item2).name + ", set Copper requirement to " + amount + ", set Tin requirement to " + amount2 + ", set created quantity of Bronze to " + amount3));
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CustomizedBronze";

		public const string PLUGIN_NAME = "CustomizedBronze";

		public const string PLUGIN_VERSION = "0.0.1.1";
	}
}
namespace Common
{
	public class DependencyOperations
	{
		public static bool CheckForDependencyErrors(string pluginName)
		{
			bool result = false;
			if (!VersionOperations.CheckVersionWithOutput(pluginName, "Unity", VersionOperations.GetEngineVersion(), "2020.3.45f1"))
			{
				result = true;
			}
			if (!VersionOperations.CheckVersionWithOutput(pluginName, "Valheim", VersionOperations.GetGameVersion(), "0.217.25"))
			{
				result = true;
			}
			if (!VersionOperations.CheckVersionWithOutput(pluginName, "BepInExPack Valheim", VersionOperations.GetBepinExVersion(), "5.4.22.0"))
			{
				result = true;
			}
			if (!VersionOperations.CheckVersionWithOutput(pluginName, "Jotunn, the Valheim Library", VersionOperations.GetJotunnVersion(), "2.14.5"))
			{
				result = true;
			}
			return result;
		}
	}
	public class FileOperations
	{
		public static bool checkPluginDependencies(string[] plugins)
		{
			bool result = true;
			foreach (string text in plugins)
			{
				string[] files = Directory.GetFiles(Paths.PluginPath, text, SearchOption.AllDirectories);
				for (int j = 0; j < files.Length; j++)
				{
					if (!files[j].Contains(text))
					{
						Logger.LogInfo((object)("Needed plugin " + text + " not installed."));
						result = false;
					}
				}
			}
			return result;
		}

		public static bool checkFileDependencies(string[] files)
		{
			bool result = true;
			foreach (string text in files)
			{
				string[] obj = new string[5]
				{
					Paths.PluginPath,
					null,
					null,
					null,
					null
				};
				char directorySeparatorChar = Path.DirectorySeparatorChar;
				obj[1] = directorySeparatorChar.ToString();
				obj[2] = "CustomizedBronze";
				directorySeparatorChar = Path.DirectorySeparatorChar;
				obj[3] = directorySeparatorChar.ToString();
				obj[4] = text;
				string text2 = string.Concat(obj);
				if (!File.Exists(text2))
				{
					Logger.LogError((object)("File " + text2 + " not exists."));
					result = false;
				}
			}
			return result;
		}
	}
	public class VersionOperations
	{
		internal static string BepInExVersion => typeof(BaseUnityPlugin).Assembly.GetName().Version.ToString();

		public static bool CheckVersionWithOutput(string pluginName, string dependencyName, string dependencyInstalledVersion, string dependencyNeededMinVersion)
		{
			if (!CheckVersion(dependencyInstalledVersion, dependencyNeededMinVersion))
			{
				Logger.LogError((object)(pluginName + " need " + dependencyName + " version " + dependencyNeededMinVersion + " or higher, installed version is " + dependencyInstalledVersion + ", pls update"));
				return false;
			}
			return true;
		}

		private static bool CheckVersion(string v1, string v2)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			num = 0;
			for (num2 = 0; num < v1.Length || num2 < v2.Length; num2++)
			{
				for (; num < v1.Length && v1[num] != '.'; num++)
				{
					num3 = num3 * 10 + (v1[num] - 48);
				}
				for (; num2 < v2.Length && v2[num2] != '.'; num2++)
				{
					num4 = num4 * 10 + (v2[num2] - 48);
				}
				if (num3 > num4)
				{
					return true;
				}
				if (num4 > num3)
				{
					return false;
				}
				num3 = (num4 = 0);
				num++;
			}
			return true;
		}

		public static string GetEngineVersion()
		{
			return Application.unityVersion;
		}

		public static string GetGameVersion()
		{
			return Version.GetVersionString(false);
		}

		private static string GetCompatiblePlayerVersions()
		{
			return string.Join(", ", 27);
		}

		private static string GetCompatibleWorldVersion()
		{
			return string.Join(", ", 9);
		}

		public static string GetBepinExVersion()
		{
			return BepInExVersion;
		}

		public static string GetJotunnVersion()
		{
			return "2.14.5";
		}
	}
}