Decompiled source of Cooked Clean v1.0.0

tony4twentys-Cooked Clean.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Cooked Clean")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cooked Clean")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9ef79194-5328-4415-9481-0fda8c5fd49a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CookedClean;

public static class CookedCleanDataEntryKey
{
	public static readonly DataEntryKey PoisonRemoved;
}
[BepInPlugin("tony4twents.CookedClean", "Cooked Clean", "1.0.0")]
public class CookedCleanPlugin : BaseUnityPlugin
{
	private static readonly Harmony harmony = new Harmony("tony4twents.CookedClean");

	internal static ManualLogSource logger;

	private void Awake()
	{
		logger = ((BaseUnityPlugin)this).Logger;
		logger.LogInfo((object)"Cooked Clean mod loaded successfully!");
		harmony.PatchAll();
		logger.LogInfo((object)"Harmony patches applied successfully!");
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	public static void RemoveHarmfulEffectsFromItem(Item item)
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Invalid comparison between Unknown and I4
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)item))
		{
			return;
		}
		bool flag = false;
		Action_InflictPoison component = ((Component)item).GetComponent<Action_InflictPoison>();
		if ((Object)(object)component != (Object)null)
		{
			logger.LogInfo((object)("Removing Action_InflictPoison component from " + ((Object)item).name));
			Object.Destroy((Object)(object)component);
			flag = true;
		}
		Action_ModifyStatus[] components = ((Component)item).GetComponents<Action_ModifyStatus>();
		Action_ModifyStatus[] array = components;
		foreach (Action_ModifyStatus val in array)
		{
			if ((int)val.statusType == 3)
			{
				logger.LogInfo((object)("Modifying Action_ModifyStatus poison component on " + ((Object)item).name));
				val.changeAmount = 0f;
				flag = true;
			}
		}
		Action_AddOrRemoveThorns component2 = ((Component)item).GetComponent<Action_AddOrRemoveThorns>();
		if ((Object)(object)component2 != (Object)null)
		{
			logger.LogInfo((object)("Removing Action_AddOrRemoveThorns component from " + ((Object)item).name));
			Object.Destroy((Object)(object)component2);
			flag = true;
		}
		if (flag)
		{
			BoolItemData data = item.GetData<BoolItemData>(CookedCleanDataEntryKey.PoisonRemoved);
			data.Value = true;
			logger.LogInfo((object)("Successfully removed harmful effects from " + ((Object)item).name));
		}
	}

	public static bool HasHarmfulEffectsRemoved(Item item)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)item))
		{
			return false;
		}
		return item.HasData(CookedCleanDataEntryKey.PoisonRemoved) && item.GetData<BoolItemData>(CookedCleanDataEntryKey.PoisonRemoved).Value;
	}
}
[HarmonyPatch(typeof(ItemCooking), "FinishCookingRPC")]
public class ItemCooking_FinishCookingRPC_Patch
{
	private static void Postfix(ItemCooking __instance)
	{
		try
		{
			CookedCleanPlugin.RemoveHarmfulEffectsFromItem(((ItemComponent)__instance).item);
		}
		catch (Exception ex)
		{
			CookedCleanPlugin.logger.LogError((object)("Error removing harmful effects from cooked item: " + ex.Message));
			CookedCleanPlugin.logger.LogError((object)("Stack trace: " + ex.StackTrace));
		}
	}
}
[HarmonyPatch(typeof(Item), "Start")]
public class Item_Start_Patch
{
	private static void Postfix(Item __instance)
	{
		try
		{
			if (CookedCleanPlugin.HasHarmfulEffectsRemoved(__instance))
			{
				CookedCleanPlugin.logger.LogDebug((object)("Restoring harmful effects removal state for " + ((Object)__instance).name));
				CookedCleanPlugin.RemoveHarmfulEffectsFromItem(__instance);
			}
		}
		catch (Exception ex)
		{
			CookedCleanPlugin.logger.LogError((object)("Error restoring harmful effects removal state: " + ex.Message));
			CookedCleanPlugin.logger.LogError((object)("Stack trace: " + ex.StackTrace));
		}
	}
}