using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Unity.Netcode; using UnityEngine; using UnityEngine.Events; using UnityEngine.Localization; using UnityEngine.Localization.Settings; using UnityEngine.Localization.Tables; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("OneClickCrafting")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("OneClickCrafting")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("0082065B-72A9-4638-88F3-1A0ABE86AA6B")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] public static class AnvilMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockAnvil machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; machine.CraftItemServerRpc(default(ServerRpcParams)); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List blockAnvils, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); for (int num = blockAnvils.Count - 1; num >= 0; num--) { BlockAnvil val = blockAnvils[num]; if (!((Object)val).name.Contains("Clone")) { blockAnvils.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { blockAnvils.RemoveAt(num); } } Block val2 = null; if (blockAnvils != null && blockAnvils.Count > 0) { foreach (RecipeSO recipe2 in blockAnvils[0].recipes) { if (recipe2.output.id == recipe.output.id) { if (blockAnvils.Count == 0) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } val2 = (Block)(object)CheckRecipe.GetMachine(component, recipe, blockAnvils, blockAnvils[0].recipes); } } } if ((Object)(object)val2 != (Object)null) { BlockAnvil val3 = (BlockAnvil)(object)((val2 is BlockAnvil) ? val2 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val3.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val3)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockAnvil machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } public static class CheckRecipe { public static bool CheckAndConsumeIngredients(RecipeSO recipe, PlayerInventory bag, UIManager uiManager) { //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03be: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_0332: Unknown result type (might be due to invalid IL or missing references) Dictionary dictionary = new Dictionary(); Dictionary dictionary2 = new Dictionary(); foreach (Ingredient ingredient in recipe.ingredients) { if (dictionary.ContainsKey(ingredient.itemSO.id)) { dictionary[ingredient.itemSO.id] += ingredient.amount * ingredient.itemSO.amount; dictionary2[ingredient.itemSO.id] += ingredient.amount * ingredient.itemSO.amount; } else { dictionary.Add(ingredient.itemSO.id, ingredient.amount * ingredient.itemSO.amount); dictionary2.Add(ingredient.itemSO.id, ingredient.amount * ingredient.itemSO.amount); } } foreach (InventorySlot slot in bag.slots) { if (dictionary.ContainsKey(slot.itemId)) { int num = dictionary[slot.itemId]; if (num > slot.amount) { dictionary[slot.itemId] -= slot.amount; } else if (num <= slot.amount) { dictionary.Remove(slot.itemId); } } } if (dictionary.Count == 0) { for (int num2 = dictionary2.Count - 1; num2 >= 0; num2--) { KeyValuePair keyValuePair = dictionary2.ElementAt(num2); for (int i = 0; i < bag.slots.Count; i++) { InventorySlot val = bag.slots[i]; if (val.itemId == keyValuePair.Key) { if (val.amount <= keyValuePair.Value) { dictionary2[keyValuePair.Key] -= val.amount; bag.slots[i] = new InventorySlot { itemId = -1L, amount = -1, cost = -1, dayCounter = -1 }; keyValuePair = dictionary2.ElementAt(num2); } else if (val.amount > keyValuePair.Value) { dictionary2.Remove(keyValuePair.Key); bag.slots[i] = new InventorySlot { itemId = val.itemId, amount = val.amount - keyValuePair.Value, cost = val.cost, dayCounter = val.dayCounter }; keyValuePair = default(KeyValuePair); } } } } return true; } string text = "背包材料不足,缺少的食材为:\n"; for (int j = 0; j < dictionary.Count; j++) { ItemSO itemById = GameManager.Instance.GetItemById(dictionary.Keys.ElementAt(j)); string localizedString = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit(itemById.itemName), (Locale)null, (FallbackBehavior)0, Array.Empty()); text += $"{localizedString} x{dictionary.Values.ElementAt(j) / itemById.amount} "; } uiManager.ShowBankruptcyWarningDialog(text); return false; } public static void SpawnItemsForRecipe(RecipeSO recipe, BoxCollider inputTrigger) { //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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) Bounds bounds = ((Collider)inputTrigger).bounds; Vector3 center = ((Bounds)(ref bounds)).center; foreach (Ingredient ingredient in recipe.ingredients) { for (int i = 0; i < ingredient.amount; i++) { GameManager.Instance.SpawnItemAtPositionServerRpc(ingredient.itemSO.id, center, false, ingredient.itemSO.amount, ingredient.itemSO.basePrice * ingredient.amount, 0); } } } public static T GetMachine(PlayerInventory bag, RecipeSO recipe, List machines, List machinesRecipe) where T : Block { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) bool flag = false; float num = 0f; T result = default(T); foreach (T machine in machines) { foreach (RecipeSO item in machinesRecipe) { if (((Object)item).name.Equals(((Object)recipe).name)) { float num2 = Vector3.Distance(((Component)(object)machine).transform.position, ((Component)bag).transform.position); if (!flag || num2 < num) { flag = true; result = machine; num = num2; } } } } return result; } } public static class CheeseMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockCheeseMachine machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; machine.StartServerRpc(); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List cheeseMachines, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); List list = new List(); for (int num = cheeseMachines.Count - 1; num >= 0; num--) { BlockCheeseMachine val = cheeseMachines[num]; if (!((Object)val).name.Contains("Clone")) { cheeseMachines.RemoveAt(num); } else { if (list.Count == 0) { foreach (RecipeSO recipe2 in val.recipes) { list.Add(recipe2.output.id); } } FieldInfo fieldInfo = AccessTools.Field(typeof(BlockCheeseMachine), "currentOutput"); NetworkVariable val2 = (NetworkVariable)fieldInfo.GetValue(val); if (val2.Value != -1) { cheeseMachines.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { cheeseMachines.RemoveAt(num); } } } Block val3 = null; if (cheeseMachines != null && cheeseMachines.Count > 0) { foreach (RecipeSO recipe3 in cheeseMachines[0].recipes) { if (recipe3.output.id == recipe.output.id) { val3 = (Block)(object)CheckRecipe.GetMachine(component, recipe, cheeseMachines, cheeseMachines[0].recipes); } } } else if ((Object)(object)val3 == (Object)null && list.Contains(recipe.output.id)) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } if ((Object)(object)val3 != (Object)null) { BlockCheeseMachine val4 = (BlockCheeseMachine)(object)((val3 is BlockCheeseMachine) ? val3 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val4.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val4)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockCheeseMachine machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } [HarmonyPatch] public class BlockMeltingHook : BaseUnityPlugin { [HarmonyPrefix] [HarmonyPatch(typeof(RecipePaper), "__initializeVariables")] private static bool Prefix(RecipePaper __instance) { if (__instance == null) { return true; } RecipeSO val = null; if (__instance.recipes == null) { __instance.recipes = new List(); } for (int i = 0; i < __instance.recipes.Count; i++) { if (!((Object)(object)__instance.recipes[i] == (Object)null) && !((Object)(object)__instance.recipes[i].output == (Object)null) && __instance.recipes[i].output.itemName.Contains("copper_ingot")) { val = __instance.recipes[i]; break; } } if ((Object)(object)val == (Object)null) { return true; } List list = new List(); RecipeSO item = InputItem.createRecipeSO(1734622864907L, 5, 0, new List { new InputItem(1734622792143L, 20) }); RecipeSO item2 = InputItem.createRecipeSO(1734623167027L, 5, 0, new List { new InputItem(1734623109544L, 20) }); RecipeSO item3 = InputItem.createRecipeSO(1734623060980L, 5, 0, new List { new InputItem(1734622959366L, 20) }); RecipeSO item4 = InputItem.createRecipeSO(1734623245362L, 5, 0, new List { new InputItem(1734622959366L, 10), new InputItem(1734623109544L, 10) }); list.Add(item); list.Add(item2); list.Add(item3); list.Add(item4); __instance.recipes.AddRange(list); __instance.recipes = new List(__instance.recipes.OrderBy((RecipeSO x) => x.output.itemName)); return true; } [HarmonyPostfix] [HarmonyPatch(typeof(BlockMeltingMachine), "__initializeVariables")] private static void Postfix(BlockMeltingMachine __instance) { List list = new List(); RecipeSO item = InputItem.createRecipeSO(1734622864907L, 5, 0, new List { new InputItem(1734622792143L, 20) }); RecipeSO item2 = InputItem.createRecipeSO(1734623167027L, 5, 0, new List { new InputItem(1734623109544L, 20) }); RecipeSO item3 = InputItem.createRecipeSO(1734623060980L, 5, 0, new List { new InputItem(1734622959366L, 20) }); RecipeSO item4 = InputItem.createRecipeSO(1734623245362L, 5, 0, new List { new InputItem(1734622959366L, 10), new InputItem(1734623109544L, 10) }); list.Add(item); list.Add(item2); list.Add(item3); list.Add(item4); __instance.recipes.AddRange(list); __instance.recipes = new List(__instance.recipes.OrderBy((RecipeSO x) => x.output.itemName)); } } public class InputItem { public long inputItemid; public int inputAmount; public InputItem(long inputItemId, int inputAmount) { inputItemid = inputItemId; this.inputAmount = inputAmount; } public static RecipeSO createRecipeSO(long outputItemId, int outputAmount, int requiredDays, List inputItems) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_0097: Expected O, but got Unknown RecipeSO val = ScriptableObject.CreateInstance(); ItemSO itemById = GameManager.Instance.GetItemById(outputItemId); if ((Object)(object)itemById == (Object)null) { return null; } val.output = itemById; val.amount = outputAmount; val.requiredDays = requiredDays; List list = new List(); foreach (InputItem inputItem in inputItems) { ItemSO itemById2 = GameManager.Instance.GetItemById(inputItem.inputItemid); if (!((Object)(object)itemById2 == (Object)null)) { Ingredient item = new Ingredient { itemSO = itemById2, amount = inputItem.inputAmount }; list.Add(item); } } val.ingredients = list; return val; } } public static class JamMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockJamMachine machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; machine.CraftItemServerRpc(default(ServerRpcParams)); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List blockJamMachines, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); List list = new List(); for (int num = blockJamMachines.Count - 1; num >= 0; num--) { BlockJamMachine val = blockJamMachines[num]; if (!((Object)val).name.Contains("Clone")) { blockJamMachines.RemoveAt(num); } else { if (list.Count == 0) { foreach (RecipeSO recipe2 in val.recipes) { list.Add(recipe2.output.id); } } val.preparationTime = 1.5f; FieldInfo fieldInfo = AccessTools.Field(typeof(BlockJamMachine), "isPreparing"); NetworkVariable val2 = (NetworkVariable)fieldInfo.GetValue(val); if (val2.Value) { blockJamMachines.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { blockJamMachines.RemoveAt(num); } } } Block val3 = null; if (blockJamMachines != null && blockJamMachines.Count > 0) { foreach (RecipeSO recipe3 in blockJamMachines[0].recipes) { if (recipe3.output.id == recipe.output.id) { val3 = (Block)(object)CheckRecipe.GetMachine(component, recipe, blockJamMachines, blockJamMachines[0].recipes); } } } else if ((Object)(object)val3 == (Object)null && list.Contains(recipe.output.id)) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } if ((Object)(object)val3 != (Object)null) { BlockJamMachine val4 = (BlockJamMachine)(object)((val3 is BlockJamMachine) ? val3 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val4.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val4)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockJamMachine machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } public static class MaceratorMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockAlcoholMachine machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; machine.StartServerRpc(); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List blockAlcoholMachines, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); List list = new List(); for (int num = blockAlcoholMachines.Count - 1; num >= 0; num--) { BlockAlcoholMachine val = blockAlcoholMachines[num]; if (!((Object)val).name.Contains("Clone")) { blockAlcoholMachines.RemoveAt(num); } else { if (list.Count == 0) { foreach (RecipeSO recipe2 in val.recipes) { list.Add(recipe2.output.id); } } FieldInfo fieldInfo = AccessTools.Field(typeof(BlockAlcoholMachine), "currentOutput"); NetworkVariable val2 = (NetworkVariable)fieldInfo.GetValue(val); if (val2.Value != -1) { blockAlcoholMachines.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { blockAlcoholMachines.RemoveAt(num); } } } Block val3 = null; if (blockAlcoholMachines != null && blockAlcoholMachines.Count > 0) { foreach (RecipeSO recipe3 in blockAlcoholMachines[0].recipes) { if (recipe3.output.id == recipe.output.id) { val3 = (Block)(object)CheckRecipe.GetMachine(component, recipe, blockAlcoholMachines, blockAlcoholMachines[0].recipes); } } } else if ((Object)(object)val3 == (Object)null && list.Contains(recipe.output.id)) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } if ((Object)(object)val3 != (Object)null) { BlockAlcoholMachine val4 = (BlockAlcoholMachine)(object)((val3 is BlockAlcoholMachine) ? val3 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val4.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val4)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockAlcoholMachine machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } public static class MeatCutterMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockMeatCutter machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; machine.CraftItemServerRpc(default(ServerRpcParams)); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List blockMeatCutters, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); for (int num = blockMeatCutters.Count - 1; num >= 0; num--) { BlockMeatCutter val = blockMeatCutters[num]; if (!((Object)val).name.Contains("Clone")) { blockMeatCutters.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { blockMeatCutters.RemoveAt(num); } } Block val2 = null; if (blockMeatCutters != null && blockMeatCutters.Count > 0) { foreach (RecipeSO recipe2 in blockMeatCutters[0].recipes) { if (recipe2.output.id == recipe.output.id) { if (blockMeatCutters.Count == 0) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } val2 = (Block)(object)CheckRecipe.GetMachine(component, recipe, blockMeatCutters, blockMeatCutters[0].recipes); } } } if ((Object)(object)val2 != (Object)null) { BlockMeatCutter val3 = (BlockMeatCutter)(object)((val2 is BlockMeatCutter) ? val2 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val3.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val3)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockMeatCutter machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } public static class MeltingMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockMeltingMachine machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; machine.CraftItemServerRpc(default(ServerRpcParams)); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List blockMeltingMachines, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); List list = new List(); for (int num = blockMeltingMachines.Count - 1; num >= 0; num--) { BlockMeltingMachine val = blockMeltingMachines[num]; if (!((Object)val).name.Contains("Clone")) { blockMeltingMachines.RemoveAt(num); } else { if (list.Count == 0) { foreach (RecipeSO recipe2 in val.recipes) { list.Add(recipe2.output.id); } } blockMeltingMachines[num].bakingTime = 1.5f; FieldInfo fieldInfo = AccessTools.Field(typeof(BlockMeltingMachine), "isCooking"); NetworkVariable val2 = (NetworkVariable)fieldInfo.GetValue(val); if (val2.Value) { blockMeltingMachines.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { blockMeltingMachines.RemoveAt(num); } } } Block val3 = null; if (blockMeltingMachines != null && blockMeltingMachines.Count > 0) { foreach (RecipeSO recipe3 in blockMeltingMachines[0].recipes) { if (recipe3.output.id == recipe.output.id) { val3 = (Block)(object)CheckRecipe.GetMachine(component, recipe, blockMeltingMachines, blockMeltingMachines[0].recipes); } } } else if ((Object)(object)val3 == (Object)null && list.Contains(recipe.output.id)) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } if ((Object)(object)val3 != (Object)null) { BlockMeltingMachine val4 = (BlockMeltingMachine)(object)((val3 is BlockMeltingMachine) ? val3 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val4.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val4)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockMeltingMachine machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } public static class OilPressMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockOilMachine machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; ((Interactable)machine).Interact(); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List oilPressMachines, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); List list = new List(); for (int num = oilPressMachines.Count - 1; num >= 0; num--) { BlockOilMachine val = oilPressMachines[num]; if (!((Object)val).name.Contains("Clone")) { oilPressMachines.RemoveAt(num); } else { if (list.Count == 0) { foreach (RecipeSO recipe2 in val.recipes) { list.Add(recipe2.output.id); } } FieldInfo field = typeof(BlockOilMachine).GetField("remainingDays", BindingFlags.Instance | BindingFlags.NonPublic); NetworkVariable val2 = (NetworkVariable)field.GetValue(val); if (val2.Value > 0) { oilPressMachines.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { oilPressMachines.RemoveAt(num); } } } Block val3 = null; if (oilPressMachines != null && oilPressMachines.Count > 0) { foreach (RecipeSO recipe3 in oilPressMachines[0].recipes) { if (recipe3.output.id == recipe.output.id) { val3 = (Block)(object)CheckRecipe.GetMachine(component, recipe, oilPressMachines, oilPressMachines[0].recipes); } } } else if ((Object)(object)val3 == (Object)null && list.Contains(recipe.output.id)) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } if ((Object)(object)val3 != (Object)null) { BlockOilMachine val4 = (BlockOilMachine)(object)((val3 is BlockOilMachine) ? val3 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val4.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val4)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockOilMachine machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } public static class OvenMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockOven machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; machine.CraftItemServerRpc(default(ServerRpcParams)); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List blockOvens, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); List list = new List(); for (int num = blockOvens.Count - 1; num >= 0; num--) { BlockOven val = blockOvens[num]; if (!((Object)val).name.Contains("Clone")) { blockOvens.RemoveAt(num); } else { if (list.Count == 0) { foreach (RecipeSO recipe2 in val.recipes) { list.Add(recipe2.output.id); } } val.bakingTime = 1.5f; FieldInfo fieldInfo = AccessTools.Field(typeof(BlockOven), "isCooking"); NetworkVariable val2 = (NetworkVariable)fieldInfo.GetValue(val); if (val2.Value) { blockOvens.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { blockOvens.RemoveAt(num); } } } Block val3 = null; if (blockOvens != null && blockOvens.Count > 0) { foreach (RecipeSO recipe3 in blockOvens[0].recipes) { if (recipe3.output.id == recipe.output.id) { val3 = (Block)(object)CheckRecipe.GetMachine(component, recipe, blockOvens, blockOvens[0].recipes); } } } else if ((Object)(object)val3 == (Object)null && list.Contains(recipe.output.id)) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } if ((Object)(object)val3 != (Object)null) { BlockOven val4 = (BlockOven)(object)((val3 is BlockOven) ? val3 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val4.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val4)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockOven machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } public static class PotionMechineAutoMake { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockPotionBoiler machine; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; machine.CraftItemServerRpc(default(ServerRpcParams)); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static bool start(RecipeSO recipe, List blockPotionBoilers, UIManager uiManagerInstance) { PlayerInventory component = ((Component)NetworkManager.Singleton.LocalClient.PlayerObject).GetComponent(); List list = new List(); for (int num = blockPotionBoilers.Count - 1; num >= 0; num--) { BlockPotionBoiler val = blockPotionBoilers[num]; if (!((Object)val).name.Contains("Clone")) { blockPotionBoilers.RemoveAt(num); } else { if (list.Count == 0) { foreach (RecipeSO recipe2 in val.recipes) { list.Add(recipe2.output.id); } } val.bakingTime = 1.5f; FieldInfo fieldInfo = AccessTools.Field(typeof(BlockPotionBoiler), "isCooking"); NetworkVariable val2 = (NetworkVariable)fieldInfo.GetValue(val); if (val2.Value) { blockPotionBoilers.RemoveAt(num); } List itemsInTrigger = GameManager.Instance.GetItemsInTrigger(val.inputTrigger); if (itemsInTrigger.Count > 0) { blockPotionBoilers.RemoveAt(num); } } } Block val3 = null; if (blockPotionBoilers != null && blockPotionBoilers.Count > 0) { foreach (RecipeSO recipe3 in blockPotionBoilers[0].recipes) { if (recipe3.output.id == recipe.output.id) { val3 = (Block)(object)CheckRecipe.GetMachine(component, recipe, blockPotionBoilers, blockPotionBoilers[0].recipes); } } } else if ((Object)(object)val3 == (Object)null && list.Contains(recipe.output.id)) { uiManagerInstance.ShowBankruptcyWarningDialog("找不到空闲的机器,请检查机器是否将成品取出(doesn't find a machine, please check whether the machine has taken the finished product)"); return true; } if ((Object)(object)val3 != (Object)null) { BlockPotionBoiler val4 = (BlockPotionBoiler)(object)((val3 is BlockPotionBoiler) ? val3 : null); if (!CheckRecipe.CheckAndConsumeIngredients(recipe, component, uiManagerInstance)) { return false; } BoxCollider inputTrigger = val4.inputTrigger; CheckRecipe.SpawnItemsForRecipe(recipe, inputTrigger); ((MonoBehaviour)uiManagerInstance).StartCoroutine(DelayedCraft(val4)); return true; } return false; } [IteratorStateMachine(typeof(d__1))] private static IEnumerator DelayedCraft(BlockPotionBoiler machine) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { machine = machine }; } } [BepInPlugin("com.lan.OneClickCrafting", "一键制作", "1.4.1")] public class OneClickCraftPlugin : BaseUnityPlugin { public static class RecipePanelState { public static List CurrentRecipes { get; set; } public static int CurrentIndex { get; set; } public static UIManager CurrentUIManager { get; set; } } [HarmonyPatch] public class Patch_OpenRecipesPanel_Prefix { [CompilerGenerated] private sealed class d__4 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockMeltingMachine machine; public RecipeSO recipeSO; public int cost; private FieldInfo <_isCooking>5__1; private NetworkVariable 5__2; private int 5__3; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__4(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <_isCooking>5__1 = null; 5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(machine.bakingTime); <>1__state = 1; return true; case 1: <>1__state = -1; if ((Object)(object)playerInventory != (Object)null) { 5__3 = 0; while (5__3 < recipeSO.amount) { playerInventory.GiveItemServerRpc(recipeSO.output.id, recipeSO.output.amount, cost, 0); int num = 5__3 + 1; 5__3 = num; } } <_isCooking>5__1 = AccessTools.Field(typeof(BlockMeltingMachine), "isCooking"); 5__2 = (NetworkVariable)<_isCooking>5__1.GetValue(machine); 5__2.Value = false; return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__6 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public BlockSpiceMachine machine; public RecipeSO recipeSO; public int cost; private FieldInfo <_isCooking>5__1; private NetworkVariable 5__2; private int 5__3; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__6(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <_isCooking>5__1 = null; 5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(machine.bakingTime); <>1__state = 1; return true; case 1: <>1__state = -1; if ((Object)(object)playerInventory != (Object)null) { 5__3 = 0; while (5__3 < recipeSO.amount) { playerInventory.GiveItemServerRpc(recipeSO.output.id, recipeSO.output.amount, cost, 0); int num = 5__3 + 1; 5__3 = num; } } <_isCooking>5__1 = AccessTools.Field(typeof(BlockSpiceMachine), "isCooking"); 5__2 = (NetworkVariable)<_isCooking>5__1.GetValue(machine); 5__2.Value = false; return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static PlayerInventory playerInventory; [HarmonyPostfix] [HarmonyPatch(typeof(PlayerInventory), "CheckBag")] private static void Prefix(PlayerInventory __instance) { playerInventory = __instance; } [HarmonyPrefix] [HarmonyPatch(typeof(UIManager), "OpenRecipesPanel")] private static void Prefix(UIManager __instance, List recipes) { if ((Object)(object)__instance == (Object)null || recipes == null) { RecipePanelState.CurrentRecipes = null; RecipePanelState.CurrentIndex = 0; RecipePanelState.CurrentUIManager = null; } else { RecipePanelState.CurrentRecipes = new List(recipes); RecipePanelState.CurrentIndex = 0; RecipePanelState.CurrentUIManager = __instance; } } [HarmonyPrefix] [HarmonyPatch(typeof(BlockMeltingMachine), "SpawnOutput")] private static bool Prefix(BlockMeltingMachine __instance, RecipeSO recipeSO, int cost, ref IEnumerator __result) { __result = CustomMeltingSpawnOutput(__instance, recipeSO, cost); return false; } [IteratorStateMachine(typeof(d__4))] private static IEnumerator CustomMeltingSpawnOutput(BlockMeltingMachine machine, RecipeSO recipeSO, int cost) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__4(0) { machine = machine, recipeSO = recipeSO, cost = cost }; } [HarmonyPrefix] [HarmonyPatch(typeof(BlockSpiceMachine), "SpawnOutput")] private static bool Prefix(BlockSpiceMachine __instance, RecipeSO recipeSO, int cost, ref IEnumerator __result) { __result = CustomSpiceSpawnOutput(__instance, recipeSO, cost); return false; } [IteratorStateMachine(typeof(d__6))] private static IEnumerator CustomSpiceSpawnOutput(BlockSpiceMachine machine, RecipeSO recipeSO, int cost) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__6(0) { machine = machine, recipeSO = recipeSO, cost = cost }; } } [HarmonyPatch(typeof(ListButton), "BuildButton")] public class Patch_ListButton_BuildButton_Postfix { private const string ButtonName = "OneClickCraftButton"; [HarmonyPostfix] private static void Postfix(ListButton __instance) { GameObject gameObject = ((Component)__instance).gameObject; if (RecipePanelState.CurrentRecipes != null && !((Object)(object)RecipePanelState.CurrentUIManager == (Object)null) && RecipePanelState.CurrentIndex < RecipePanelState.CurrentRecipes.Count) { RecipeSO recipe = RecipePanelState.CurrentRecipes[RecipePanelState.CurrentIndex]; UIManager currentUIManager = RecipePanelState.CurrentUIManager; Transform val = gameObject.transform.Find("OneClickCraftButton"); if ((Object)(object)val != (Object)null) { Object.DestroyImmediate((Object)(object)((Component)val).gameObject); } AddOneClickButton(gameObject, recipe, currentUIManager); RecipePanelState.CurrentIndex++; } } private static void AddOneClickButton(GameObject listButtonObj, RecipeSO recipe, UIManager uiManagerInstance) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("OneClickCraftButton"); val.transform.SetParent(listButtonObj.transform, false); val.transform.localPosition = new Vector3(250f, 20f, 0f); Button val2 = val.AddComponent