Decompiled source of RandomPotato v1.0.1

WWAG_RandomPotato.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Inventory;
using Skins;
using TMPro;
using UI;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("WWAG_RandomPotato")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WWAG_RandomPotato")]
[assembly: AssemblyTitle("WWAG_RandomPotato")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace WWAG_RandomPotato;

[BepInPlugin("org.NikoTheFox.RandomPotato", "WWAG Random Main Menu Wizard", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	private void Awake()
	{
		Debug.Log((object)"Plugin WWAG_RandomPotato is loaded!");
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Expected O, but got Unknown
		if (((Scene)(ref scene)).name == "title-screen")
		{
			Debug.Log((object)"Found scene, randomizing Wiz");
			GameObject val = GameObject.Find("background-canvas/player-animation");
			val.AddComponent<PluginRandomWiz>();
			val.AddComponent<BoxCollider>();
		}
		if (!(((Scene)(ref scene)).name == "core-simple-all"))
		{
			return;
		}
		Debug.Log((object)"Found customizestuff");
		GameObject val2 = GameObject.Find("ui/cross-world-ui(Clone)/customize-wizard-ui/window/item-selection-panel/finalize-selectable-button");
		if ((Object)(object)val2 == (Object)null)
		{
			Debug.Log((object)"Couldnt find the object to copy");
			return;
		}
		val2.transform.position = new Vector3(490f, 150f, 0f);
		val2.transform.localPosition = new Vector3(-500f, -410f, 0f);
		RectTransform component = val2.GetComponent<RectTransform>();
		component.sizeDelta = new Vector2(200f, component.sizeDelta.y);
		GameObject val3 = Object.Instantiate<GameObject>(val2);
		val3.transform.SetParent(val2.transform.parent, false);
		((Object)val3).name = "randomize";
		val3.transform.localPosition = new Vector3(-290f, -410f, 0f);
		RectTransform component2 = val3.GetComponent<RectTransform>();
		component2.sizeDelta = new Vector2(220f, component.sizeDelta.y);
		GameObject gameObject = ((Component)val3.transform.Find("Text")).gameObject;
		TextMeshProUGUI component3 = gameObject.GetComponent<TextMeshProUGUI>();
		((TMP_Text)component3).text = "Randomize";
		SelectableButton component4 = val3.GetComponent<SelectableButton>();
		PluginRandomCustomizeWiz plugin = val3.AddComponent<PluginRandomCustomizeWiz>();
		component4.SetClickAction((UnityAction)delegate
		{
			plugin.ChangeWizard();
		});
	}

	private void OnEnable()
	{
		Debug.Log((object)"Plugin enabled");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}
}
public class PluginRandomWiz : MonoBehaviour
{
	private void Awake()
	{
		ChangeWizard();
	}

	private void ChangeWizard()
	{
		GameObject gameObject = ((Component)this).gameObject;
		PlayerSkins component = gameObject.GetComponent<PlayerSkins>();
		SkinGroup[] array = Resources.FindObjectsOfTypeAll<SkinGroup>();
		List<SkinGroup> list = new List<SkinGroup>();
		List<SkinGroup> list2 = new List<SkinGroup>();
		List<SkinGroup> list3 = new List<SkinGroup>();
		List<SkinGroup> list4 = new List<SkinGroup>();
		List<SkinGroup> list5 = new List<SkinGroup>();
		Random random = new Random();
		string[] array2 = new string[7] { "crimson", "warlock", "mustard", "engineer", "magus", "oakley", "azure" };
		string[] array3 = new string[14]
		{
			"alchemist", "warlock", "mustard", "engineer", "magus", "oakley", "azure", "calamity", "corsair", "crimson",
			"farmhand", "necromancer", "occultist", "maninblack"
		};
		SkinGroup[] array4 = array;
		foreach (SkinGroup val in array4)
		{
			string[] array5 = array2;
			foreach (string text in array5)
			{
				if (((Object)val).name == "sg-hat-" + text)
				{
					list.Add(val);
				}
				if (((Object)val).name == "sg-robes-" + text)
				{
					list3.Add(val);
				}
				if (((Object)val).name == "sg-gloves-" + text)
				{
					list2.Add(val);
				}
				if (((Object)val).name == "sg-boots-" + text)
				{
					list4.Add(val);
				}
			}
			string[] array6 = array3;
			foreach (string text2 in array6)
			{
				if (((Object)val).name == "sg-eyes-" + text2)
				{
					list5.Add(val);
				}
			}
		}
		if (list.Count > 0)
		{
			SkinGroup val2 = list[random.Next(list.Count)];
			component.SetEquipSlot(val2, (EquipSlot)0);
		}
		if (list2.Count > 0)
		{
			SkinGroup val3 = list2[random.Next(list2.Count)];
			component.SetEquipSlot(val3, (EquipSlot)3);
		}
		if (list3.Count > 0)
		{
			SkinGroup val4 = list3[random.Next(list3.Count)];
			component.SetEquipSlot(val4, (EquipSlot)4);
		}
		if (list4.Count > 0)
		{
			SkinGroup val5 = list4[random.Next(list4.Count)];
			component.SetEquipSlot(val5, (EquipSlot)5);
		}
		if (list5.Count > 1)
		{
			SkinGroup val6 = list5[random.Next(list5.Count)];
			component.SetEquipSlot(val6, (EquipSlot)7);
		}
	}

	private void Update()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetMouseButtonDown(0))
		{
			Ray val = Camera.main.ScreenPointToRay(Input.mousePosition);
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, ref val2) && (Object)(object)((RaycastHit)(ref val2)).transform == (Object)(object)((Component)this).transform)
			{
				OnObjectClicked();
			}
		}
	}

	private void OnObjectClicked()
	{
		ChangeWizard();
	}
}
public class PluginRandomCustomizeWiz : MonoBehaviour
{
	private PlayerSpawnGameData _spawnGameData;

	private Dictionary<ItemType, ItemAssetHandle> _currentEquipmentItems = new Dictionary<ItemType, ItemAssetHandle>();

	private SkinGroup _currentEyeShape;

	private Color _currentEyeColor;

	public PlayerSkins wizardPreview;

	private void Awake()
	{
		GameObject gameObject = ((Component)((Component)this).transform.Find("Text")).gameObject;
		if ((Object)(object)gameObject == (Object)null)
		{
			Debug.Log((object)"Couldnt find the text object.");
			return;
		}
		TextMeshProUGUI component = gameObject.GetComponent<TextMeshProUGUI>();
		((TMP_Text)component).text = "Randomize";
	}

	public void ChangeWizard()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Invalid comparison between Unknown and I4
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)"Randomizing Wiz");
		GameObject val = GameObject.Find("ui/cross-world-ui(Clone)/customize-wizard-ui/window/item-selection-panel/player-animation");
		GameObject val2 = GameObject.Find("ui/cross-world-ui(Clone)/customize-wizard-ui");
		CustomizeWizardUI component = val2.GetComponent<CustomizeWizardUI>();
		wizardPreview = val.GetComponent<PlayerSkins>();
		_spawnGameData = GameDataCache.GetGameData<PlayerSpawnGameData>();
		Random val3 = default(Random);
		((Random)(ref val3)).InitState((uint)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
		if (_spawnGameData.eyeShapeItems.Length != 0)
		{
			StaticItemEquipmentComponent component2 = _spawnGameData.eyeShapeItems[((Random)(ref val3)).NextInt(0, _spawnGameData.eyeShapeItems.Length)].GetComponent<StaticItemEquipmentComponent>();
			wizardPreview.SetEquipSlot(component2.skinGroup, (EquipSlot)7);
			_currentEyeShape = component2.skinGroup;
		}
		if (_spawnGameData.eyeColorOptions.Length != 0)
		{
			Color val4 = _spawnGameData.eyeColorOptions[((Random)(ref val3)).NextInt(0, _spawnGameData.eyeColorOptions.Length)];
			wizardPreview.SetSlotColor((ColorSlot)2, val4);
			wizardPreview.SetAllColors();
			_currentEyeColor = val4;
		}
		Dictionary<ItemType, List<GameObject>> allEquipmentOptions = _spawnGameData.GetAllEquipmentOptions();
		EquipSlot val6 = default(EquipSlot);
		foreach (ItemType key in allEquipmentOptions.Keys)
		{
			if ((key & 0x1FC0) > 0)
			{
				int count = allEquipmentOptions[key].Count;
				int index = ((Random)(ref val3)).NextInt(0, count);
				GameObject val5 = allEquipmentOptions[key][index];
				StaticItemEquipmentComponent component3 = val5.GetComponent<StaticItemEquipmentComponent>();
				if (SkinsUtil.TryGetEquipSlot(key, ref val6))
				{
					wizardPreview.SetEquipSlot(component3.skinGroup, val6);
					_currentEquipmentItems[key] = new ItemAssetHandle(val5);
				}
			}
		}
		FieldInfo field = typeof(CustomizeWizardUI).GetField("_currentEyeShape", BindingFlags.Instance | BindingFlags.NonPublic);
		field.SetValue(component, _currentEyeShape);
		FieldInfo field2 = typeof(CustomizeWizardUI).GetField("_currentEquipmentItems", BindingFlags.Instance | BindingFlags.NonPublic);
		field2.SetValue(component, _currentEquipmentItems);
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "WWAG_RandomPotato";

	public const string PLUGIN_NAME = "WWAG_RandomPotato";

	public const string PLUGIN_VERSION = "1.0.0";
}