Decompiled source of Item Giver v1.0.1

ScheduleIMods2.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppSystem.Collections.Generic;
using ItemSpawnerMod;
using MelonLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "JoiveItemSpawner", "1.0.0", "Joive", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ScheduleIMods2")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScheduleIMods2")]
[assembly: AssemblyTitle("ScheduleIMods2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ItemSpawnerMod;

public class Main : MelonMod
{
	private bool _showMenu = false;

	private Rect _windowRect = new Rect(20f, 20f, 450f, 500f);

	private Vector2 _scrollPosition = Vector2.zero;

	private List<ItemDefinition> _cachedItems = new List<ItemDefinition>();

	private string _searchQuery = "";

	private int _spawnAmount = 1;

	private bool _isTypingSearch = false;

	public override void OnInitializeMelon()
	{
		((MelonBase)this).LoggerInstance.Msg("Joive's Item Spawner загружен! Нажми F4 для открытия меню.");
	}

	public override void OnUpdate()
	{
		if (Input.GetKeyDown((KeyCode)285))
		{
			_showMenu = !_showMenu;
			if (_showMenu && _cachedItems.Count == 0)
			{
				RefreshItemCache();
			}
			if (!_showMenu)
			{
				_isTypingSearch = false;
			}
		}
		if (!_showMenu || !_isTypingSearch)
		{
			return;
		}
		string inputString = Input.inputString;
		for (int i = 0; i < inputString.Length; i++)
		{
			char c = inputString[i];
			switch (c)
			{
			case '\b':
				if (_searchQuery.Length > 0)
				{
					_searchQuery = _searchQuery.Substring(0, _searchQuery.Length - 1);
				}
				break;
			default:
				if (c != '\r')
				{
					_searchQuery += c;
					break;
				}
				goto case '\n';
			case '\n':
				_isTypingSearch = false;
				break;
			}
		}
	}

	public override void OnGUI()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		if (_showMenu)
		{
			_windowRect = GUI.Window(1001, _windowRect, WindowFunction.op_Implicit((Action<int>)DrawMenu), "Joive's Item Spawner");
		}
	}

	private void DrawMenu(int windowID)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Поиск:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
		GUI.color = (_isTypingSearch ? Color.yellow : Color.white);
		string text = (string.IsNullOrEmpty(_searchQuery) ? "Нажми сюда и печатай..." : _searchQuery);
		if (GUILayout.Button(text, Array.Empty<GUILayoutOption>()))
		{
			_isTypingSearch = !_isTypingSearch;
		}
		GUI.color = Color.white;
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label($"Кол-во: {_spawnAmount}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
		if (GUILayout.Button("-10", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) }))
		{
			_spawnAmount = Mathf.Max(1, _spawnAmount - 10);
		}
		if (GUILayout.Button("-1", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) }))
		{
			_spawnAmount = Mathf.Max(1, _spawnAmount - 1);
		}
		if (GUILayout.Button("+1", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) }))
		{
			_spawnAmount = Mathf.Min(9999, _spawnAmount + 1);
		}
		if (GUILayout.Button("+10", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) }))
		{
			_spawnAmount = Mathf.Min(9999, _spawnAmount + 10);
		}
		if (GUILayout.Button("+100", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
		{
			_spawnAmount = Mathf.Min(9999, _spawnAmount + 100);
		}
		GUILayout.EndHorizontal();
		GUILayout.Space(10f);
		_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, Array.Empty<GUILayoutOption>());
		string value = _searchQuery.ToLower();
		foreach (ItemDefinition cachedItem in _cachedItems)
		{
			if ((Object)(object)cachedItem == (Object)null)
			{
				continue;
			}
			string text2 = ((BaseItemDefinition)cachedItem).Name ?? ((BaseItemDefinition)cachedItem).ID ?? "Unknown";
			if (string.IsNullOrEmpty(value) || text2.ToLower().Contains(value))
			{
				GUILayout.BeginHorizontal(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
				GUILayout.Label(text2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(250f) });
				if (GUILayout.Button("Спавн", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }))
				{
					SpawnItem(cachedItem);
				}
				GUILayout.EndHorizontal();
			}
		}
		GUILayout.EndScrollView();
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}

	private void RefreshItemCache()
	{
		_cachedItems.Clear();
		try
		{
			Registry val = Object.FindObjectOfType<Registry>();
			if ((Object)(object)val != (Object)null)
			{
				List<ItemDefinition> allItems = val.GetAllItems();
				Enumerator<ItemDefinition> enumerator = allItems.GetEnumerator();
				while (enumerator.MoveNext())
				{
					ItemDefinition current = enumerator.Current;
					if ((Object)(object)current != (Object)null && !string.IsNullOrEmpty(((BaseItemDefinition)current).ID))
					{
						_cachedItems.Add(current);
					}
				}
			}
			if (_cachedItems.Count == 0)
			{
				Il2CppArrayBase<ItemDefinition> val2 = Resources.FindObjectsOfTypeAll<ItemDefinition>();
				foreach (ItemDefinition item in val2)
				{
					if ((Object)(object)item != (Object)null && !string.IsNullOrEmpty(((BaseItemDefinition)item).ID))
					{
						_cachedItems.Add(item);
					}
				}
			}
			((MelonBase)this).LoggerInstance.Msg($"Кэшировано {_cachedItems.Count} предметов.");
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Error("Ошибка при поиске предметов: " + ex.Message);
		}
	}

	private void SpawnItem(ItemDefinition itemDef)
	{
		try
		{
			int num = Mathf.Clamp(_spawnAmount, 1, 9999);
			PlayerInventory val = Object.FindObjectOfType<PlayerInventory>();
			if ((Object)(object)val == (Object)null)
			{
				((MelonBase)this).LoggerInstance.Warning("Инвентарь игрока не найден!");
				return;
			}
			ItemInstance defaultInstance = itemDef.GetDefaultInstance(num);
			if (defaultInstance != null)
			{
				val.AddItemToInventory(defaultInstance);
				((MelonBase)this).LoggerInstance.Msg($"Успешно выдано: {num}x {((BaseItemDefinition)itemDef).Name}");
			}
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Error("Ошибка при спавне предмета: " + ex.Message);
		}
	}
}