Перейти к содержанию
  • записи
    104
  • комментариев
    125
  • просмотров
    15 460

Взлом крафта в StarsOne


MasterGH

2 999 просмотров

В оригинале, если нет всех компонентов рецепта, то нельзя скрафтить вещь.

image.png

Цель: скрафтить без компонетов по нажатию кнопки

 

Игра на Unity и можно пробовать использовать в dnSpy модифицировать файл Assembly-CSharp.dll

Открываем файлик и смотрим на классы связанные с крафтом

 

Так находим кнопку, которая создаст указанное количество вещей крафта в CreateItem

Спойлер

   

Задача скрафтить по имеющемуся рецепту любую вещь. Для этого я добавляю проверку количества вещей  и удаляю лишний код. Под сполерами оригинальный и модифицированный код

 

Визуальное сравнение

Спойлер

image.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;
		}
	}

 

 

Изменяем весь класс или метов в этом окне

Спойлер

image.png

 

Если выводит ошибки при компяляции, то скачиваем IlSpy и его код вставляем в код в dnSpy. Или качаем DnSpy 3.2.0 или ранее

 

Изменения сохраняем в модуль, запускаем игру и крафтим.

 

Получить все рецепты (не проверял правда, попробуйте если хотите)

Спойлер

image.png

 

Вещи не ломаются. Убрать отнятие "здоровья" у вещи

 

Спойлер

image.pngimage.png  

 

  • Понравилось 2
  • Плюс 1

0 Комментариев


Рекомендуемые комментарии

Комментариев нет

Пожалуйста, войдите, чтобы комментировать

Вы сможете оставить комментарий после входа в



Войти
×
×
  • Создать...

Важная информация

Находясь на нашем сайте, Вы автоматически соглашаетесь соблюдать наши Условия использования.