Decompiled source of Free Powder v1.0.0

WWAG_FreePowder.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using GGUtil;
using UI;
using Unity.Collections;
using UnityEngine;

[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_FreePowder")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WWAG_FreePowder")]
[assembly: AssemblyTitle("WWAG_FreePowder")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace WWAG_FreePowder;

public class ConstInfo
{
	public const string PLUGIN_GUID = "com.xatini.plugins.freepowder";

	public const string PLUGIN_NAME = "WWAG_FreePowder";

	public const string PLUGIN_VERSION = "1.0.0";
}
[BepInPlugin("com.xatini.plugins.freepowder", "WWAG_FreePowder", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.xatini.plugins.freepowder is loaded!");
		UIDialogueStack.OnFocusChanged += new FocusChangedHandler(OnFocusChanged);
	}

	private async void OnFocusChanged(IUIDialogue from, IUIDialogue to)
	{
		UIWindow window = (UIWindow)(object)((to is UIWindow) ? to : null);
		if (window == null)
		{
			return;
		}
		LoadingBenchCraftingUI component = ((Component)window).GetComponent<LoadingBenchCraftingUI>();
		if ((Object)(object)component == (Object)null)
		{
			return;
		}
		RecipeCollection collection = await EnsureThatCollectionExist(component);
		if ((Object)(object)collection == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Cant find powder collection");
			return;
		}
		RecipeDescDatabase recipeDescDatabase = GameUniverse.persistentWorld.world.GetMainThreadData<RecipeDescDatabase>();
		Type databaseType = typeof(RecipeDescDatabase);
		FieldInfo recipesFieldInfo = databaseType.GetField("_recipeDescs", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		NativeHashMap<AssetHandle<RecipeBase>, RecipeDesc> hashSet = (NativeHashMap<AssetHandle<RecipeBase>, RecipeDesc>)recipesFieldInfo.GetValue(recipeDescDatabase);
		RecipeSubCollection[] recipeSubCollections = collection.recipeSubCollections;
		for (int j = 0; j < recipeSubCollections.Length; j++)
		{
			RecipeSubCollection subCollection = recipeSubCollections[j];
			RecipeList[] collections = subCollection.collections;
			for (int k = 0; k < collections.Length; k++)
			{
				RecipeList recipeList = collections[k];
				RecipeBase[] collection2 = recipeList.collection;
				foreach (RecipeBase recipe in collection2)
				{
					recipe.requiredArcana = 0;
					recipe.requirements = Array.Empty<RecipeAssetRequirement>();
					AssetHandle<RecipeBase> handle = Assets<RecipeBase>.Get(recipe);
					RecipeDesc desc = hashSet[handle];
					for (int i = 0; i < desc.requirements.Count; i++)
					{
						RecipeRequirementData requirement = desc.requirements[i];
						requirement.requiredCount = 0;
						desc.requirements[i] = requirement;
					}
					desc.requiredArcana = 0;
					hashSet[handle] = desc;
				}
			}
		}
		recipesFieldInfo.SetValue(recipeDescDatabase, hashSet);
		UIDialogueStack.OnFocusChanged -= new FocusChangedHandler(OnFocusChanged);
	}

	private async Task<RecipeCollection> EnsureThatCollectionExist(LoadingBenchCraftingUI ui)
	{
		Type type = typeof(LoadingBenchCraftingUI);
		int index = 0;
		while (index < 100)
		{
			object value = type.GetField("_powderRecipeCollection", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(ui);
			if (value != null)
			{
				return (RecipeCollection)((value is RecipeCollection) ? value : null);
			}
			index++;
			await Task.Delay(TimeSpan.FromSeconds(0.10000000149011612));
		}
		return null;
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "WWAG_FreePowder";

	public const string PLUGIN_NAME = "WWAG_FreePowder";

	public const string PLUGIN_VERSION = "1.0.0";
}