CELua[RU]
    • Категории
    • Последние
    • Метки
    • Популярные
    • Пользователи
    • Группы
    • Зарегистрироваться
    • Войти

    Крафт в StarsOne

    Запланировано Прикреплена Закрыта Перенесена Статьи
    unitydnspyблог
    1 Сообщения 1 Posters 68 Просмотры 1 Watching
    Загружаем больше сообщений
    • Сначала старые
    • Сначала новые
    • По количеству голосов
    Ответить
    • Ответить, создав новую тему
    Авторизуйтесь, чтобы ответить
    Эта тема была удалена. Только пользователи с правом управления темами могут её видеть.
    • MasterGHM Не в сети
      MasterGH Администраторы
      отредактировано

      В оригинале, если нет всех компонентов рецепта, то нельзя скрафтить вещь.
      68960b6a-5bec-46ac-aefb-8ad86b84272c-изображение.png
      Цель: скрафтить без компонетов по нажатию кнопки
      Игра на Unity и можно пробовать использовать в dnSpy модифицировать файл Assembly-CSharp.dll
      Открываем файлик и смотрим на классы связанные с крафтом
      Так находим кнопку, которая создаст указанное количество вещей крафта в CreateItem
      d8824a7d-2174-4f57-b45f-c47ddd94856d-изображение.png
      fd633567-857e-4533-b4de-eabf3eb2f481-изображение.png
      Задача скрафтить по имеющемуся рецепту любую вещь. Для этого я добавляю проверку количества вещей и удаляю лишний код. Под сполерами оригинальный и модифицированный код
      77be2bf2-7c7e-42f8-a7d0-c69b75307a00-изображение.png
      Модифицированный код

      using System;
      using System.Collections.Generic;
      using System.Runtime.CompilerServices;
      using UnityEngine;
      
      public partial class Crafting : MonoBehaviour
      {
      	public void CreateItem(int curCraft, int craftCount)
      	{
      		if (this.timeBreak >= 0.3f)
      		{
                  // Добавили одну вещь крафта
      			if (craftCount == 0)
      			{
      				craftCount = 1;
      			}
      
      			if (craftCount != 0)
      			{
      				this.succes = true;
      				CraftRecipe component = this.craftObjects[curCraft].GetComponent<CraftRecipe>();
                    
                      // Здесь удалили код, который должен расходовать вещи из инвентаря
                      // ...
                    
      				if (this.succes)
      				{
      					this.iks = this.craftObjects[curCraft].GetComponent<CraftRecipe>().countCreate * craftCount;
      					for (int m = 0; m < this.craftObjects[curCraft].GetComponent<CraftRecipe>().countCreate * craftCount; m++)
      					{
      						this.emptyCell = Inventory.inv.FindItemForStack(this.craftObjects[curCraft].name);
      						if (this.emptyCell >= 0)
      						{
      							if (Inventory.inv.items[this.emptyCell].stack + this.iks <= Inventory.inv.items[this.emptyCell].maxStack)
      							{
      								Inventory.inv.items[this.emptyCell].stack += this.iks;
      								break;
      							}
      							this.iks -= Inventory.inv.items[this.emptyCell].maxStack - Inventory.inv.items[this.emptyCell].stack;
      							Inventory.inv.items[this.emptyCell].stack = Inventory.inv.items[this.emptyCell].maxStack;
      						}
      						else
      						{
      							this.emptyCell = Inventory.inv.FindEmptyCell();
      							if (this.emptyCell >= 0)
      							{
      								this.cloneItem = Inventory.inv.CreateItem(this.craftObjects[curCraft]);
      								if (this.cloneItem.maxStack >= this.iks)
      								{
      									this.cloneItem.stack = this.iks;
      									Inventory.inv.items[this.emptyCell] = this.cloneItem;
      									break;
      								}
      								this.cloneItem.stack = this.cloneItem.maxStack;
      								this.iks -= this.cloneItem.maxStack;
      								Inventory.inv.items[this.emptyCell] = this.cloneItem;
      							}
      							else
      							{
      								if (this.craftObjects[curCraft].GetComponent<Item>().maxStack >= this.iks)
      								{
      									PlayerNetwork.inst.CallCmdCreateItem(this.craftObjects[curCraft].name, Inventory.inv.transform.position - Vector3.forward * 2f + FloatingOrigin.offset, Quaternion.identity, this.iks, this.craftObjects[curCraft].GetComponent<Item>().health);
      									break;
      								}
      								PlayerNetwork.inst.CallCmdCreateItem(this.craftObjects[curCraft].name, Inventory.inv.transform.position - Vector3.forward * 2f + FloatingOrigin.offset, Quaternion.identity, this.craftObjects[curCraft].GetComponent<Item>().maxStack, this.craftObjects[curCraft].GetComponent<Item>().health);
      								this.iks -= this.craftObjects[curCraft].GetComponent<Item>().maxStack;
      							}
      							new WaitForEndOfFrame();
      						}
      					}
      				}
      			}
      			this.timeBreak = 0f;
      		}
      	}
      }
      

      Оригинальный

      public void CreateItem(int curCraft, int craftCount)
      	{
      		if (this.timeBreak >= 0.3f)
      		{
      			if (craftCount != 0)
      			{
      				this.succes = true;
      				CraftRecipe component = this.craftObjects[curCraft].GetComponent<CraftRecipe>();
      				int[] array = new int[7];
      				int[] array2 = new int[7];
      				for (int i = 0; i < 7; i++)
      				{
      					if (this.succes && component.ingredients[i] != null)
      					{
      						array2[i] = component.countIngredients[i];
      						if (array2[i] <= 0)
      						{
      							array2[i] = 1;
      						}
      						array2[i] *= craftCount;
      						for (int j = 0; j < Inventory.inv.items.Length; j++)
      						{
      							if (Inventory.inv.items[j] != null && component.ingredients[i].name == Inventory.inv.items[j].prefName)
      							{
      								array[i] += Inventory.inv.items[j].stack;
      							}
      						}
      						if (array[i] < array2[i])
      						{
      							this.succes = false;
      						}
      					}
      				}
      				if (this.succes)
      				{
      					for (int k = 0; k < 7; k++)
      					{
      						if (component.ingredients[k] != null)
      						{
      							for (int l = 0; l < Inventory.inv.items.Length; l++)
      							{
      								if (Inventory.inv.items[l] != null && array2[k] > 0 && component.ingredients[k].name == Inventory.inv.items[l].prefName)
      								{
      									this.iks = Inventory.inv.items[l].stack;
      									Inventory.inv.items[l].stack -= array2[k];
      									array2[k] -= this.iks;
      									if (array2[k] <= 0)
      									{
      										break;
      									}
      								}
      							}
      						}
      					}
      					this.iks = this.craftObjects[curCraft].GetComponent<CraftRecipe>().countCreate * craftCount;
      					for (int m = 0; m < this.craftObjects[curCraft].GetComponent<CraftRecipe>().countCreate * craftCount; m++)
      					{
      						this.emptyCell = Inventory.inv.FindItemForStack(this.craftObjects[curCraft].name);
      						if (this.emptyCell >= 0)
      						{
      							if (Inventory.inv.items[this.emptyCell].stack + this.iks <= Inventory.inv.items[this.emptyCell].maxStack)
      							{
      								Inventory.inv.items[this.emptyCell].stack += this.iks;
      								break;
      							}
      							this.iks -= Inventory.inv.items[this.emptyCell].maxStack - Inventory.inv.items[this.emptyCell].stack;
      							Inventory.inv.items[this.emptyCell].stack = Inventory.inv.items[this.emptyCell].maxStack;
      						}
      						else
      						{
      							this.emptyCell = Inventory.inv.FindEmptyCell();
      							if (this.emptyCell >= 0)
      							{
      								this.cloneItem = Inventory.inv.CreateItem(this.craftObjects[curCraft]);
      								if (this.cloneItem.maxStack >= this.iks)
      								{
      									this.cloneItem.stack = this.iks;
      									Inventory.inv.items[this.emptyCell] = this.cloneItem;
      									break;
      								}
      								this.cloneItem.stack = this.cloneItem.maxStack;
      								this.iks -= this.cloneItem.maxStack;
      								Inventory.inv.items[this.emptyCell] = this.cloneItem;
      							}
      							else
      							{
      								if (this.craftObjects[curCraft].GetComponent<Item>().maxStack >= this.iks)
      								{
      									PlayerNetwork.inst.CallCmdCreateItem(this.craftObjects[curCraft].name, Inventory.inv.transform.position - Vector3.forward * 2f + FloatingOrigin.offset, Quaternion.identity, this.iks, this.craftObjects[curCraft].GetComponent<Item>().health);
      									break;
      								}
      								PlayerNetwork.inst.CallCmdCreateItem(this.craftObjects[curCraft].name, Inventory.inv.transform.position - Vector3.forward * 2f + FloatingOrigin.offset, Quaternion.identity, this.craftObjects[curCraft].GetComponent<Item>().maxStack, this.craftObjects[curCraft].GetComponent<Item>().health);
      								this.iks -= this.craftObjects[curCraft].GetComponent<Item>().maxStack;
      							}
      							new WaitForEndOfFrame();
      						}
      					}
      				}
      			}
      			this.timeBreak = 0f;
      		}
      	}
      

      Изменяем весь класс или метов в этом окне
      fc19935c-d36c-4dbf-9f7c-4eb458eab3b0-изображение.png
      Если выводит ошибки при компяляции, то скачиваем IlSpy и его код вставляем в код в dnSpy. Или качаем DnSpy 3.2.0 или ранее
      Изменения сохраняем в модуль, запускаем игру и крафтим.
      Получить все рецепты (не проверял правда, попробуйте если хотите)
      c40b6907-64ba-4ea9-8a60-6ceeb36db575-изображение.png
      Вещи не ломаются. Убрать отнятие "здоровья" у вещи
      8f6337fb-51cc-4e59-a841-84a854fbd53d-изображение.png
      8edb5aba-652b-40ec-8e1f-64414389fd26-изображение.png

      1 ответ Последний ответ Ответить Цитировать 0
      • MasterGHM MasterGH переместил эту тему из в

      • 1 / 1
      • Первое сообщение
        Последнее сообщение
      Powered by NodeBB | Contributors
      СeLua[RU] 2025©