Decompiled source of DeathGivesBack v1.1.1

plugins/DeathGivesBack/DeathGivesBack.dll

Decompiled 11 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 BepInEx.Logging;
using DarkScreenSystem;
using HarmonyLib;
using PotionCraft.LocalizationSystem;
using PotionCraft.ManagersSystem;
using PotionCraft.ManagersSystem.Game;
using PotionCraft.ManagersSystem.Potion;
using PotionCraft.ManagersSystem.RecipeMap;
using PotionCraft.ObjectBased.RecipeMap.RecipeMapObject;
using PotionCraft.ObjectBased.UIElements.ConfirmationWindow;
using PotionCraft.ObjectBased.UIElements.FloatingText;
using PotionCraft.ObjectBased.UIElements.PotionCraftPanel;
using PotionCraft.ScriptableObjects;
using PotionCraft.ScriptableObjects.Potion;
using PotionCraft.Settings;
using UnityEngine;
using UnityEngine.Events;

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

internal class ClassPatches
{
	public static bool giveback = true;

	private static ManualLogSource Log => Plugin.Log;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PotionResetButton), "OnButtonReleasedPointerInside")]
	public static void OnButtonReleasedPointerInside_Postfix()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		//IL_0050: Expected O, but got Unknown
		ConfirmationWindow.Show((DarkScreenLayer)0, new Key("#reset_potion_warning_title", (List<string>)null, false), new Key("DGB_resetpotion_text", (List<string>)null, false), Settings<GameManagerSettings>.Asset.confirmationWindowPosition, (Action)delegate
		{
			Managers.Potion.ResetPotion(true);
		}, (Action)null, (DarkScreenType)1, 0f, false);
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PotionManager), "ResetPotion")]
	public static void ResetPotion_Prefix(bool resetEffectMapItems = true)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Invalid comparison between Unknown and I4
		if ((int)Managers.SaveLoad.SystemState == 2)
		{
			Log.LogInfo((object)"Nope. Not gonna try while the save is loading");
		}
		else if (giveback)
		{
			Functions.GiveBackIngredients();
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PotionCraftPanel), "MakePotion")]
	public static void MakePotion_Prefix(bool addToInventory)
	{
		Log.LogInfo((object)"Giveback disabled for potion creation");
		giveback = false;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PotionCraftPanel), "MakePotion")]
	public static void MakePotion_Postfix(bool addToInventory)
	{
		Log.LogInfo((object)"Giveback re-enabled after potion creation");
		giveback = true;
	}
}
internal class Functions
{
	public static Dictionary<InventoryItem, int> used = new Dictionary<InventoryItem, int>();

	private static ManualLogSource Log => Plugin.Log;

	public static void AddLocaleText(string key, string text)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected I4, but got Unknown
		foreach (Locale value in Enum.GetValues(typeof(Locale)))
		{
			LocalizationManager.localizationData.Add((int)value, key, text);
		}
	}

	public static void SetModText()
	{
		AddLocaleText("DGB_text", "Ingredients retrieved!");
		AddLocaleText("DGB_resetpotion_text", "All the ingredients will be returned to your inventory. Reset potion?");
	}

	public static void GiveBackIngredients()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Invalid comparison between Unknown and I4
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		List<PotionUsedComponent> usedComponents = Managers.Potion.usedComponents;
		Log.LogInfo((object)"# Ingredients retrieved:");
		for (int i = 0; i < usedComponents.Count; i++)
		{
			if ((int)usedComponents[i].componentType == 0)
			{
				used.Add((InventoryItem)usedComponents[i].componentObject, usedComponents[i].amount);
			}
			foreach (KeyValuePair<InventoryItem, int> item in used)
			{
				Managers.Player.inventory.AddItem(item.Key, item.Value, true, true);
				Log.LogInfo((object)$"  > {((Object)item.Key).name} ({item.Value})");
			}
			used.Clear();
		}
		RecipeMapObject recipeMapObject = Managers.RecipeMap.recipeMapObject;
		RecipeMapManagerPotionBasesSettings asset = Settings<RecipeMapManagerPotionBasesSettings>.Asset;
		Rect viewRect = recipeMapObject.transmitterWindow.ViewRect;
		Vector2 val = ((Rect)(ref viewRect)).center + asset.potionFailTextPos;
		CollectedFloatingText.SpawnNewText(asset.floatingTextSelectBase, Vector2.op_Implicit(val + new Vector2(0f, -1f)), new FloatingTextContent(new Key("DGB_text", (List<string>)null, false).GetText(), (Type)1, 0f), ((Component)Managers.Game.Cam).transform, false, false);
	}
}
[BepInPlugin("DeathGivesBack", "PotionCraftDeathGivesBack", "1.1.1.0")]
public class Plugin : BaseUnityPlugin
{
	public const string PLUGIN_GUID = "com.mattdeduck.potioncraftdeathgivesback";

	public static ManualLogSource Log { get; set; }

	private void Awake()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin DeathGivesBack is loaded!");
		Log = ((BaseUnityPlugin)this).Logger;
		LocalizationManager.OnInitialize.AddListener(new UnityAction(Functions.SetModText));
		Log.LogInfo((object)"Plugin com.mattdeduck.potioncraftdeathgivesback is loaded!");
		Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		Harmony.CreateAndPatchAll(typeof(Functions), (string)null);
		Harmony.CreateAndPatchAll(typeof(ClassPatches), (string)null);
		Log.LogInfo((object)"Plugin com.mattdeduck.potioncraftdeathgivesback: Patch Succeeded!");
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "DeathGivesBack";

	public const string PLUGIN_NAME = "DeathGivesBack";

	public const string PLUGIN_VERSION = "1.0.0";
}