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.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Managers; using Jotunn.Utils; using MasterCrafting; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("MasterCrafting")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("A mod that adds an Artisanship skill granting permanent stat bonuses to crafted items")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("MasterCrafting")] [assembly: AssemblyTitle("MasterCrafting")] [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; } } } [HarmonyPatch] internal class MasterCraftingPatches { private const string MasterCraftingPowerKey = "MasterCrafting_Power"; private static readonly Dictionary CraftingStationXP = new Dictionary { { "piece_workbench", 22 }, { "forge", 45 }, { "piece_artisanstation", 55 }, { "blackforge", 65 }, { "galdr_table", 65 } }; [HarmonyPatch(typeof(InventoryGui), "DoCrafting")] [HarmonyPostfix] private static void DoCraftingPostfix(InventoryGui __instance, Player player) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance.m_craftRecipe == (Object)null || (Object)(object)player == (Object)null) { return; } CraftingStation currentCraftingStation = player.GetCurrentCraftingStation(); if ((Object)(object)currentCraftingStation == (Object)null) { return; } int craftingStationXP = GetCraftingStationXP(currentCraftingStation); if (craftingStationXP > 0) { ((Character)player).RaiseSkill(MasterCraftingPlugin.ArtisanshipSkillType, (float)craftingStationXP); } ItemData itemData = __instance.m_craftRecipe.m_item.m_itemData; if (itemData == null) { return; } float skillLevel = ((Character)player).GetSkillLevel(MasterCraftingPlugin.ArtisanshipSkillType); float num = Mathf.Min(skillLevel / 100f, 1f); ItemData val = FindCraftedItem(player, itemData, __instance.m_craftUpgradeItem); if (val == null) { return; } if (val.m_customData.TryGetValue("MasterCrafting_Power", out var value)) { float num2 = float.Parse(value); if (num > num2) { val.m_customData["MasterCrafting_Power"] = num.ToString("F4"); } } else { val.m_customData["MasterCrafting_Power"] = num.ToString("F4"); } float num3 = MasterCraftingPlugin.MasterworkBaseChance.Value + MasterCraftingPlugin.MasterworkChancePerLevel.Value * skillLevel; if (Random.value < num3) { int maxQuality = val.m_shared.m_maxQuality; if (maxQuality > 1 && val.m_quality < maxQuality) { val.m_quality = Mathf.Min(val.m_quality + 1, maxQuality); Vector3 val2 = ((Component)currentCraftingStation).transform.position + Vector3.up; DamageText.instance.ShowText((TextType)7, val2, "Masterwork!", true); } } } private static ItemData FindCraftedItem(Player player, ItemData template, ItemData upgradeItem) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) List list = new List(); ((Humanoid)player).GetInventory().GetAllItems(template.m_shared.m_name, list); if (upgradeItem != null) { foreach (ItemData item in list) { if (item.m_gridPos == upgradeItem.m_gridPos) { return item; } } } else if (list.Count > 0) { return list[list.Count - 1]; } return null; } private static int GetCraftingStationXP(CraftingStation station) { if ((Object)(object)station == (Object)null) { return 0; } string text = ((Object)station).name.ToLower(); foreach (KeyValuePair item in CraftingStationXP) { if (text.Contains(item.Key)) { return item.Value; } } return 0; } [HarmonyPatch(typeof(ItemData), "GetDamage", new Type[] { typeof(int), typeof(float) })] [HarmonyPostfix] private static void GetDamagePostfix(ItemData __instance, ref DamageTypes __result) { if (__instance.m_customData.TryGetValue("MasterCrafting_Power", out var value) && float.TryParse(value, out var result)) { float num = 1f + result * MasterCraftingPlugin.DamageBonusPerLevel.Value * 100f; ((DamageTypes)(ref __result)).Modify(num); } } [HarmonyPatch(typeof(ItemData), "GetArmor", new Type[] { typeof(int), typeof(float) })] [HarmonyPostfix] private static void GetArmorPostfix(ItemData __instance, ref float __result) { if (__instance.m_customData.TryGetValue("MasterCrafting_Power", out var value) && float.TryParse(value, out var result)) { float num = 1f + result * MasterCraftingPlugin.ArmorBonusPerLevel.Value * 100f; __result *= num; } } [HarmonyPatch(typeof(ItemData), "GetMaxDurability", new Type[] { typeof(int) })] [HarmonyPostfix] private static void GetMaxDurabilityPostfix(ItemData __instance, ref float __result) { if (__instance.m_customData.TryGetValue("MasterCrafting_Power", out var value) && float.TryParse(value, out var result)) { float num = 1f + result * MasterCraftingPlugin.DurabilityBonusPerLevel.Value * 100f; __result *= num; } } [HarmonyPatch(typeof(ItemData), "GetBlockPower", new Type[] { typeof(int), typeof(float) })] [HarmonyPostfix] private static void GetBlockPowerPostfix(ItemData __instance, ref float __result) { if (__instance.m_customData.TryGetValue("MasterCrafting_Power", out var value) && float.TryParse(value, out var result)) { float num = 1f + result * MasterCraftingPlugin.ArmorBonusPerLevel.Value * 100f; __result *= num; } } [HarmonyPatch(typeof(Attack), "GetAttackStamina")] [HarmonyPostfix] private static void GetAttackStaminaPostfix(Attack __instance, ref float __result) { if (__instance.m_weapon != null && __instance.m_weapon.m_customData.TryGetValue("MasterCrafting_Power", out var value) && float.TryParse(value, out var result)) { float num = result * MasterCraftingPlugin.EfficiencyBonusPerLevel.Value * 100f; __result *= 1f - num; } } [HarmonyPatch(typeof(Attack), "GetAttackEitr")] [HarmonyPostfix] private static void GetAttackEitrPostfix(Attack __instance, ref float __result) { if (__instance.m_weapon != null && __instance.m_weapon.m_customData.TryGetValue("MasterCrafting_Power", out var value) && float.TryParse(value, out var result)) { float num = result * MasterCraftingPlugin.EfficiencyBonusPerLevel.Value * 100f; __result *= 1f - num; } } [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int) })] [HarmonyPostfix] private static void GetTooltipPostfix(ItemData item, int qualityLevel, bool crafting, float worldLevel, int stackOverride, ref string __result) { if (item != null && item.m_customData.TryGetValue("MasterCrafting_Power", out var _)) { __result += "\nMasterCrafted"; } } } namespace MasterCrafting { [BepInPlugin("com.ruijven.mastercrafting", "MasterCrafting", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class MasterCraftingPlugin : BaseUnityPlugin { public const string PluginGUID = "com.ruijven.mastercrafting"; public const string PluginName = "MasterCrafting"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Logger; public static SkillType ArtisanshipSkillType; public static ConfigEntry DamageBonusPerLevel; public static ConfigEntry ArmorBonusPerLevel; public static ConfigEntry DurabilityBonusPerLevel; public static ConfigEntry EfficiencyBonusPerLevel; public static ConfigEntry MasterworkBaseChance; public static ConfigEntry MasterworkChancePerLevel; internal static MasterCraftingPlugin Instance { get; private set; } private void Awake() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown Instance = this; Logger = ((BaseUnityPlugin)this).Logger; InitializeConfig(); RegisterArtisanshipSkill(); Harmony val = new Harmony("com.ruijven.mastercrafting"); val.PatchAll(Assembly.GetExecutingAssembly()); Logger.LogInfo((object)"MasterCrafting v1.0.0 loaded successfully!"); } private void InitializeConfig() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Expected O, but got Unknown //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Expected O, but got Unknown //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Expected O, but got Unknown DamageBonusPerLevel = ((BaseUnityPlugin)this).Config.Bind("Stat Bonuses", "DamageBonusPerLevel", 0.002f, new ConfigDescription("Damage bonus per Artisanship level (e.g., 0.002 = 0.2% per level)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); ArmorBonusPerLevel = ((BaseUnityPlugin)this).Config.Bind("Stat Bonuses", "ArmorBonusPerLevel", 0.0015f, new ConfigDescription("Armor bonus per Artisanship level (e.g., 0.0015 = 0.15% per level)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); DurabilityBonusPerLevel = ((BaseUnityPlugin)this).Config.Bind("Stat Bonuses", "DurabilityBonusPerLevel", 0.003f, new ConfigDescription("Durability bonus per Artisanship level (e.g., 0.003 = 0.3% per level)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); EfficiencyBonusPerLevel = ((BaseUnityPlugin)this).Config.Bind("Stat Bonuses", "EfficiencyBonusPerLevel", 0.002f, new ConfigDescription("Stamina/Eitr usage reduction per Artisanship level (e.g., 0.002 = 0.2% per level)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); MasterworkBaseChance = ((BaseUnityPlugin)this).Config.Bind("Masterwork Proc", "MasterworkBaseChance", 0.02f, new ConfigDescription("Base chance for masterwork proc (e.g., 0.02 = 2%)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); MasterworkChancePerLevel = ((BaseUnityPlugin)this).Config.Bind("Masterwork Proc", "MasterworkChancePerLevel", 0.001f, new ConfigDescription("Additional masterwork chance per Artisanship level (e.g., 0.001 = 0.1% per level)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); } private void RegisterArtisanshipSkill() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) try { SkillConfig val = new SkillConfig { Identifier = "com.ruijven.mastercrafting.artisanship", Name = "Artisanship", Description = "Your skill in crafting grants permanent bonuses to items you create.", Icon = null, IncreaseStep = 1f }; ArtisanshipSkillType = SkillManager.Instance.AddSkill(val); Logger.LogInfo((object)$"Artisanship skill registered successfully. SkillType: {ArtisanshipSkillType}"); } catch (Exception ex) { Logger.LogError((object)("Failed to register Artisanship skill: " + ex.Message + "\n" + ex.StackTrace)); } } } }