Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of IdolCrafting v1.0.0
plugins/IdolCrafting/IdolCrafting.dll
Decompiled 5 days agousing 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 HarmonyLib; 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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("IdolCrafting")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("IdolCrafting")] [assembly: AssemblyTitle("IdolCrafting")] [assembly: AssemblyVersion("1.0.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 IdolCrafting { [BepInPlugin("com.yourname.idolcrafting", "Idol Crafting", "1.0.0")] public class IdolCraftingPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class ObjectDBAwakePatch { private static void Postfix(ObjectDB __instance) { if ((Object)(object)Instance == (Object)null) { return; } try { Instance.RegisterRecipes(__instance); } catch (Exception arg) { ((BaseUnityPlugin)Instance).Logger.LogError((object)$"Failed to register idol recipes:\n{arg}"); } } } public const string ModGuid = "com.yourname.idolcrafting"; public const string ModName = "Idol Crafting"; public const string ModVersion = "1.0.0"; private static IdolCraftingPlugin Instance; private Harmony _harmony; private readonly ConfigEntry<int>[] _coinCosts = new ConfigEntry<int>[7]; private ConfigEntry<int> _workbenchLevel; private static readonly string[] ArmorPrefabs = new string[8] { "Upgrader0Armor", "Upgrader1Armor", "Upgrader2Armor", "Upgrader3Armor", "Upgrader4Armor", "Upgrader5Armor", "Upgrader6Armor", "Upgrader7Armor" }; private static readonly string[] WeaponPrefabs = new string[8] { "Upgrader0Weapon", "Upgrader1Weapon", "Upgrader2Weapon", "Upgrader3Weapon", "Upgrader4Weapon", "Upgrader5Weapon", "Upgrader6Weapon", "Upgrader7Weapon" }; private static readonly int[] DefaultCosts = new int[7] { 25, 50, 100, 200, 400, 800, 1600 }; private void Awake() { //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown Instance = this; _workbenchLevel = ((BaseUnityPlugin)this).Config.Bind<int>("General", "WorkbenchLevel", 1, "Required workbench level."); for (int i = 0; i < 7; i++) { _coinCosts[i] = ((BaseUnityPlugin)this).Config.Bind<int>("Costs", $"Tier{i}ToTier{i + 1}", DefaultCosts[i], $"Coins required to craft tier {i + 1} idol from tier {i}."); } _harmony = new Harmony("com.yourname.idolcrafting"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Idol Crafting 1.0.0 loaded."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void RegisterRecipes(ObjectDB objectDB) { if ((Object)(object)objectDB == (Object)null || objectDB.m_items == null || objectDB.m_items.Count == 0) { return; } CraftingStation val = FindCraftingStation("piece_workbench"); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Could not find crafting station 'piece_workbench'."); return; } ItemDrop val2 = FindItem(objectDB, "Coins"); if ((Object)(object)val2 == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Could not find item prefab 'Coins'."); return; } for (int i = 0; i < 7; i++) { CreateRecipe(objectDB, ArmorPrefabs[i], ArmorPrefabs[i + 1], val2, val, _coinCosts[i].Value); CreateRecipe(objectDB, WeaponPrefabs[i], WeaponPrefabs[i + 1], val2, val, _coinCosts[i].Value); } } private void CreateRecipe(ObjectDB objectDB, string previousPrefab, string resultPrefab, ItemDrop coins, CraftingStation workbench, int coinCost) { //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Expected O, but got Unknown //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Expected O, but got Unknown ItemDrop val = FindItem(objectDB, previousPrefab); ItemDrop val2 = FindItem(objectDB, resultPrefab); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)("Could not find ingredient prefab '" + previousPrefab + "'.")); return; } if ((Object)(object)val2 == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)("Could not find result prefab '" + resultPrefab + "'.")); return; } string recipeName = "IdolCrafting_" + resultPrefab; Recipe val3 = ((IEnumerable<Recipe>)objectDB.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe r) => (Object)(object)r != (Object)null && ((Object)r).name == recipeName)); if ((Object)(object)val3 != (Object)null) { objectDB.m_recipes.Remove(val3); } Recipe val4 = ScriptableObject.CreateInstance<Recipe>(); ((Object)val4).name = recipeName; val4.m_item = val2; val4.m_craftingStation = workbench; val4.m_minStationLevel = Math.Max(1, _workbenchLevel.Value); val4.m_amount = 1; val4.m_enabled = true; Requirement val5 = new Requirement { m_resItem = val, m_amount = 1, m_amountPerLevel = 0, m_recover = true }; Requirement val6 = new Requirement { m_resItem = coins, m_amount = Math.Max(0, coinCost), m_amountPerLevel = 0, m_recover = true }; val4.m_resources = (Requirement[])(object)new Requirement[2] { val5, val6 }; objectDB.m_recipes.Add(val4); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Registered recipe: " + previousPrefab + " + " + $"{coinCost} Coins -> {resultPrefab}")); } private static ItemDrop FindItem(ObjectDB objectDB, string prefabName) { if ((Object)(object)objectDB == (Object)null) { return null; } GameObject itemPrefab = objectDB.GetItemPrefab(prefabName); if ((Object)(object)itemPrefab != (Object)null) { return itemPrefab.GetComponent<ItemDrop>(); } foreach (GameObject item in objectDB.m_items) { if ((Object)(object)item != (Object)null && ((Object)item).name == prefabName) { return item.GetComponent<ItemDrop>(); } } return null; } private static CraftingStation FindCraftingStation(string prefabName) { if ((Object)(object)ZNetScene.instance != (Object)null) { GameObject prefab = ZNetScene.instance.GetPrefab(prefabName); if ((Object)(object)prefab != (Object)null) { CraftingStation component = prefab.GetComponent<CraftingStation>(); if ((Object)(object)component != (Object)null) { return component; } } } CraftingStation[] array = Resources.FindObjectsOfTypeAll<CraftingStation>(); CraftingStation[] array2 = array; foreach (CraftingStation val in array2) { if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && ((Object)((Component)val).gameObject).name == prefabName) { return val; } } return null; } } }