using System;
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.Configuration;
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: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace ReadyToCook;
[BepInPlugin("Wyvern.ReadyToCook", "ReadyToCook", "1.0.1")]
internal class ReadyToCookMod : BaseUnityPlugin
{
public const string PluginGUID = "Wyvern.ReadyToCook";
public const string PluginName = "ReadyToCook";
public const string PluginVersion = "1.0.1";
private Harmony _harmony;
public static SE_Stats cookingStatusEffect;
public static ConfigEntry<float> cookingSkillGainMultiplier;
public static ConfigEntry<float> cookingSkillLevelBonus;
public static ConfigEntry<bool> enableVerboseLogging;
private static ManualLogSource LoggingSource;
private void Awake()
{
AddConfigValues();
MakeStatusEffect();
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Wyvern.ReadyToCook");
LoggingSource = ((BaseUnityPlugin)this).Logger;
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void AddConfigValues()
{
cookingSkillGainMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "cookingSkillGainMultiplier", 2.5f, "The multiplier for cooking skill experience gain when effect is active");
cookingSkillGainMultiplier.SettingChanged += RefreshCookingSkillGainMultiplier;
cookingSkillLevelBonus = ((BaseUnityPlugin)this).Config.Bind<float>("General", "cookingSkillLevelBonus", 10f, "The amount of bonus cooking skill levels when effect is active");
cookingSkillLevelBonus.SettingChanged += RefreshCookingSkillLevelBonus;
enableVerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("", "enableVerboseLogging", false, "Enable logging to console for debug purposes");
}
private static SE_Stats MakeStatusEffect()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
cookingStatusEffect = ScriptableObject.CreateInstance<SE_Stats>();
((Object)cookingStatusEffect).name = "Cooking";
((StatusEffect)cookingStatusEffect).m_name = "Cooking";
cookingStatusEffect.m_raiseSkill = (SkillType)105;
cookingStatusEffect.m_raiseSkillModifier = cookingSkillGainMultiplier.Value;
cookingStatusEffect.m_skillLevel = (SkillType)105;
cookingStatusEffect.m_skillLevelModifier = cookingSkillLevelBonus.Value;
((StatusEffect)cookingStatusEffect).m_tooltip = Utils.MakeTooltip();
((StatusEffect)cookingStatusEffect).m_startMessageType = (MessageType)2;
((StatusEffect)cookingStatusEffect).m_startMessage = "You are ready to cook";
((StatusEffect)cookingStatusEffect).m_stopMessageType = (MessageType)2;
((StatusEffect)cookingStatusEffect).m_stopMessage = "You are no longer cooking";
return cookingStatusEffect;
}
public void RefreshCookingSkillGainMultiplier(object sender, EventArgs e)
{
cookingStatusEffect.m_raiseSkillModifier = cookingSkillGainMultiplier.Value;
((StatusEffect)cookingStatusEffect).m_tooltip = Utils.MakeTooltip();
if ((Object)(object)ZNetScene.instance != (Object)null)
{
ZNetScene_Awake_Patch.AddSEToHeadscarves();
}
}
public void RefreshCookingSkillLevelBonus(object sender, EventArgs e)
{
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
cookingStatusEffect.m_skillLevelModifier = cookingSkillLevelBonus.Value;
((StatusEffect)cookingStatusEffect).m_tooltip = Utils.MakeTooltip();
LogVerbose(string.Format("Refreshed value: {0}, value at itemdrop: {1}", cookingStatusEffect.m_skillLevelModifier, ((SE_Stats)Utils.GetPrefab("HelmetHat1").GetComponent<ItemDrop>().m_itemData.m_shared.m_equipStatusEffect).m_skillLevelModifier));
}
public static void LogVerbose(object message)
{
if (enableVerboseLogging.Value)
{
if (LoggingSource != null)
{
LoggingSource.LogInfo(message);
}
else
{
Debug.Log((object)$"ReadyToCook: {message}");
}
}
}
public static void LogError(object message)
{
if (LoggingSource != null)
{
LoggingSource.LogError(message);
}
else
{
Debug.LogError((object)$"ReadyToCook: {message}");
}
}
}
[HarmonyPatch(typeof(ObjectDB), "Awake")]
public static class ObjectDBAwake
{
public static void Postfix(ObjectDB __instance)
{
Utils.AddCookingStatusEffect(__instance);
}
}
[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
public static class ObjectDBCopyOtherDB
{
public static void Postfix(ObjectDB __instance)
{
Utils.AddCookingStatusEffect(__instance);
}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
public static class ZNetScene_Awake_Patch
{
public static void Postfix()
{
AddSEToHeadscarves();
FillOutEffectIcon();
}
private static void FillOutEffectIcon()
{
((StatusEffect)ReadyToCookMod.cookingStatusEffect).m_icon = Utils.GetPrefab("HelmetHat1").GetComponent<ItemDrop>().m_itemData.GetIcon();
}
public static void AddSEToHeadscarves()
{
AddSEToItem("HelmetHat1");
AddSEToItem("HelmetHat2");
AddSEToItem("HelmetHat6");
AddSEToItem("HelmetHat7");
}
private static void AddSEToItem(string prefabName)
{
GameObject prefab = Utils.GetPrefab(prefabName);
if ((Object)(object)prefab != (Object)null)
{
ItemDrop component = prefab.GetComponent<ItemDrop>();
if ((Object)(object)component != (Object)null)
{
component.m_itemData.m_shared.m_equipStatusEffect = (StatusEffect)(object)ReadyToCookMod.cookingStatusEffect;
ReadyToCookMod.LogVerbose("Adding cookingStatusEffect to " + prefabName);
}
else
{
ReadyToCookMod.LogError(prefabName + " itemDrop is null");
}
}
else
{
ReadyToCookMod.LogError("Prefab " + prefabName + " was not found!");
}
}
}
public static class Utils
{
public static void AddCookingStatusEffect(ObjectDB odb)
{
if (!Object.op_Implicit((Object)(object)odb.m_StatusEffects.Find((StatusEffect se) => ((Object)se).name == "Cooking")))
{
ReadyToCookMod.LogVerbose("Adding the status effect to ODB");
odb.m_StatusEffects.Add((StatusEffect)(object)ReadyToCookMod.cookingStatusEffect);
}
else
{
ReadyToCookMod.LogVerbose("ODB already has the status effect");
}
}
public static string MakeTooltip()
{
return $"Cooking experience gain: <color=#FF8000>{ReadyToCookMod.cookingSkillGainMultiplier.Value}x</color>";
}
public static GameObject GetPrefab(string name)
{
if ((Object)(object)ZNetScene.instance != (Object)null)
{
GameObject prefab = ZNetScene.instance.GetPrefab(name);
if ((Object)(object)prefab != (Object)null)
{
return prefab;
}
}
if ((Object)(object)ObjectDB.instance != (Object)null)
{
GameObject prefab = ObjectDB.instance.GetItemPrefab(name);
if ((Object)(object)prefab != (Object)null)
{
return prefab;
}
}
return null;
}
}