Decompiled source of DrugEditor v2.0.0

ScheduleIMods4.dll

Decompiled 2 months 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;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Effects;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Product;
using Il2CppSystem.Collections.Generic;
using JoiveDrugEditor;
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), "Joive Drug Editor", "2.0.0", "Joive", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ScheduleIMods4")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScheduleIMods4")]
[assembly: AssemblyTitle("ScheduleIMods4")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace JoiveDrugEditor;

public class Main : MelonMod
{
	private KeyCode menuKey = (KeyCode)282;

	private bool showMenu = false;

	private Rect windowRect = new Rect(50f, 50f, 420f, 700f);

	private Vector2 scrollCurrentEffects = Vector2.zero;

	private Vector2 scrollAvailableEffects = Vector2.zero;

	private float selectedQuality = 4f;

	private string[] qualityNames = new string[5] { "Red (0)", "Green (1)", "Blue (2)", "Purple (3)", "Yellow (4 - MAX)" };

	private List<Effect> currentItemEffects = new List<Effect>();

	private List<Effect> allGameEffects = new List<Effect>();

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("Joive Drug Editor v2.0.0 loaded! Press F1 in-game.");
	}

	public override void OnUpdate()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(menuKey))
		{
			showMenu = !showMenu;
			if (showMenu)
			{
				ScanEquippedItem();
			}
		}
	}

	public override void OnGUI()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Unknown result type (might be due to invalid IL or missing references)
		if (!showMenu)
		{
			return;
		}
		GUI.Box(windowRect, "\ud83d\udc8a DRUG EDITOR (Joive) v2.0");
		GUILayout.BeginArea(new Rect(((Rect)(ref windowRect)).x + 15f, ((Rect)(ref windowRect)).y + 35f, ((Rect)(ref windowRect)).width - 30f, ((Rect)(ref windowRect)).height - 45f));
		int num = Mathf.Clamp(Mathf.RoundToInt(selectedQuality), 0, 4);
		GUILayout.Label("Set Quality: " + qualityNames[num], (Il2CppReferenceArray<GUILayoutOption>)null);
		selectedQuality = GUILayout.HorizontalSlider(selectedQuality, 0f, 4f, (Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.Space(15f);
		GUILayout.Label("Current Effects (On Item):", (Il2CppReferenceArray<GUILayoutOption>)null);
		GUI.backgroundColor = new Color(1f, 0.5f, 0.5f);
		scrollCurrentEffects = GUILayout.BeginScrollView(scrollCurrentEffects, GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(150f) });
		GUI.backgroundColor = Color.white;
		if (currentItemEffects.Count == 0)
		{
			GUILayout.Label("  [ No effects found on this item ]", (Il2CppReferenceArray<GUILayoutOption>)null);
		}
		else
		{
			for (int i = 0; i < currentItemEffects.Count; i++)
			{
				Effect val = currentItemEffects[i];
				GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Label("- " + ((Object)val).name, (Il2CppReferenceArray<GUILayoutOption>)null);
				if (GUILayout.Button("Remove", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
				{
					currentItemEffects.RemoveAt(i);
					break;
				}
				GUILayout.EndHorizontal();
			}
		}
		GUILayout.EndScrollView();
		GUILayout.Space(15f);
		GUILayout.Label("Available Effects (Database):", (Il2CppReferenceArray<GUILayoutOption>)null);
		GUI.backgroundColor = new Color(0.5f, 1f, 0.5f);
		scrollAvailableEffects = GUILayout.BeginScrollView(scrollAvailableEffects, GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(250f) });
		GUI.backgroundColor = Color.white;
		foreach (Effect allGameEffect in allGameEffects)
		{
			if (!currentItemEffects.Contains(allGameEffect))
			{
				GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Label("+ " + ((Object)allGameEffect).name, (Il2CppReferenceArray<GUILayoutOption>)null);
				if (GUILayout.Button("Add", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
				{
					currentItemEffects.Add(allGameEffect);
					break;
				}
				GUILayout.EndHorizontal();
			}
		}
		GUILayout.EndScrollView();
		GUILayout.Space(15f);
		GUI.backgroundColor = Color.green;
		if (GUILayout.Button("APPLY CHANGES TO ITEM", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
		{
			ApplyDrugHack();
		}
		GUI.backgroundColor = Color.white;
		GUILayout.Space(5f);
		if (GUILayout.Button("CLOSE MENU", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) }))
		{
			showMenu = false;
		}
		GUILayout.EndArea();
	}

	private void ScanEquippedItem()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		PlayerInventory instance = PlayerSingleton<PlayerInventory>.Instance;
		if ((Object)(object)instance == (Object)null || instance.EquippedItem == null)
		{
			return;
		}
		ItemInstance equippedItem = instance.EquippedItem;
		QualityItemInstance val = ((Il2CppObjectBase)equippedItem).TryCast<QualityItemInstance>();
		if (val != null)
		{
			selectedQuality = (float)val.Quality;
		}
		currentItemEffects.Clear();
		PropertyItemDefinition val2 = ((Il2CppObjectBase)equippedItem.Definition).TryCast<PropertyItemDefinition>();
		if ((Object)(object)val2 != (Object)null && val2.Properties != null)
		{
			Enumerator<Effect> enumerator = val2.Properties.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Effect current = enumerator.Current;
				currentItemEffects.Add(current);
			}
		}
		if (allGameEffects.Count != 0)
		{
			return;
		}
		Il2CppArrayBase<Effect> val3 = Resources.FindObjectsOfTypeAll<Effect>();
		foreach (Effect item in val3)
		{
			if ((Object)(object)item != (Object)null && !string.IsNullOrEmpty(((Object)item).name))
			{
				allGameEffects.Add(item);
			}
		}
		allGameEffects.Sort((Effect a, Effect b) => string.Compare(((Object)a).name, ((Object)b).name));
	}

	private void ApplyDrugHack()
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		PlayerInventory instance = PlayerSingleton<PlayerInventory>.Instance;
		if ((Object)(object)instance == (Object)null || instance.EquippedItem == null)
		{
			MelonLogger.Warning("Inventory is empty or no item in hands!");
			return;
		}
		ItemInstance equippedItem = instance.EquippedItem;
		QualityItemInstance val = ((Il2CppObjectBase)equippedItem).TryCast<QualityItemInstance>();
		if (val != null)
		{
			EQuality quality = (EQuality)Mathf.Clamp(Mathf.RoundToInt(selectedQuality), 0, 4);
			val.SetQuality(quality);
		}
		PropertyItemDefinition val2 = ((Il2CppObjectBase)equippedItem.Definition).TryCast<PropertyItemDefinition>();
		if ((Object)(object)val2 != (Object)null)
		{
			List<Effect> val3 = new List<Effect>();
			foreach (Effect currentItemEffect in currentItemEffects)
			{
				val3.Add(currentItemEffect);
			}
			val2.Properties = val3;
			MelonLogger.Msg($"[+] Successfully applied {val3.Count} effects to the item!");
		}
		try
		{
			instance.UpdateInventoryVariables();
			instance.RepositionUI();
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error updating UI: " + ex.Message);
		}
	}
}