Decompiled source of CookingXP v1.1.2

CookingXP_v1.1.2.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CookingXP")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyProduct("CookingXP")]
[assembly: AssemblyTitle("CookingXP")]
[assembly: AssemblyVersion("1.1.2.0")]
namespace CookingXP;

[BepInPlugin("frost.cookingxp", "CookingXP", "1.1.2")]
public class CookingXPPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "frost.cookingxp";

	public const string PluginName = "CookingXP";

	public const string PluginVersion = "1.1.2";

	internal static ManualLogSource Log;

	internal static ConfigEntry<float> GlobalMultiplier;

	internal static ConfigEntry<float> BonusPerFoodPoint;

	internal static ConfigEntry<float> MaxXP;

	private void Awake()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		GlobalMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("CookingXP", "GlobalMultiplier", 2.5f, "Во сколько раз усиливается весь опыт Кулинарии (котёл, стойки, печь)");
		BonusPerFoodPoint = ((BaseUnityPlugin)this).Config.Bind<float>("CookingXP", "BonusPerFoodPoint", 0.04f, "Бонусный опыт за каждую единицу силы блюда (здоровье + выносливость + эйтр)");
		MaxXP = ((BaseUnityPlugin)this).Config.Bind<float>("CookingXP", "MaxXP", 8f, "Максимум опыта за одно действие");
		new Harmony("frost.cookingxp").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"CookingXP 1.1.2 загружен");
	}
}
internal static class DishContext
{
	public const float None = -1f;

	public static float Bonus = -1f;
}
[HarmonyPatch(typeof(Player), "RaiseSkill")]
internal static class Player_RaiseSkill_Patch
{
	private static float _nextLogTime;

	private static void Prefix(Player __instance, SkillType skill, ref float value)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		if ((int)skill == 105 && !(value <= 0f))
		{
			float num = ((DishContext.Bonus > 0f) ? DishContext.Bonus : 0f);
			DishContext.Bonus = -1f;
			value = Mathf.Min(value * CookingXPPlugin.GlobalMultiplier.Value + num, CookingXPPlugin.MaxXP.Value);
			if (Time.time >= _nextLogTime)
			{
				_nextLogTime = Time.time + 10f;
				CookingXPPlugin.Log.LogInfo((object)$"Cooking XP: {value:F2} (бонус за блюдо: {num:F2})");
			}
		}
	}
}
[HarmonyPatch(typeof(CookingStation), "OnUseItem")]
internal static class CookingStation_OnUseItem_Patch
{
	private static void Prefix(ItemData item)
	{
		if (item?.m_shared != null)
		{
			DishContext.Bonus = FoodMath.FoodPower(item.m_shared);
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "DoCrafting")]
internal static class InventoryGui_DoCrafting_Patch
{
	private static void Prefix(InventoryGui __instance)
	{
		try
		{
			object? obj = AccessTools.Field(typeof(InventoryGui), "m_craftRecipe")?.GetValue(__instance);
			SharedData val = ((Recipe)(((obj is Recipe) ? obj : null)?)).m_item?.m_itemData?.m_shared;
			if (val != null && !(val.m_food <= 0f))
			{
				DishContext.Bonus = FoodMath.FoodPower(val);
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[CookingXP] Ошибка бонуса за блюдо: " + ex));
		}
	}
}
internal static class FoodMath
{
	public static float FoodPower(SharedData shared)
	{
		return shared.m_food + shared.m_foodStamina + shared.m_foodEitr;
	}
}