using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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("RawFishWithoutCauldron")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RawFishWithoutCauldron")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fb2837b6-b086-4210-8013-54edec033593")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace RawFishWithoutCauldron;
[HarmonyPatch]
internal class CraftingStationPatches
{
[HarmonyPatch(typeof(CookingStation), "UseItem")]
[HarmonyPrefix]
public static bool FilletFishPatch(CookingStation __instance, Humanoid user, ItemData item, ref bool __result)
{
string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject);
if (prefabName != "piece_cookingstation" && prefabName != "piece_cookingstation_iron")
{
return true;
}
return !FishCutter.TryFilletFish(user, item, ref __result);
}
[HarmonyPatch(typeof(CraftingStation), "UseItem")]
[HarmonyPrefix]
public static bool FilletFishPatch(CraftingStation __instance, Humanoid user, ItemData item, ref bool __result)
{
string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject);
if (prefabName != "piece_workbench")
{
return true;
}
return !FishCutter.TryFilletFish(user, item, ref __result);
}
}
internal class FishCutter
{
private static readonly Dictionary<string, Recipe> soloFishRecipes = new Dictionary<string, Recipe>();
internal static bool TryFilletFish(Humanoid user, ItemData item, ref bool __result)
{
if (!((Character)user).IsPlayer() || (Object)(object)user != (Object)(object)Player.m_localPlayer || !((Character)user).TakeInput())
{
return false;
}
Recipe val = ObjectDB.instance.m_recipes.Find((Recipe x) => ((Object)x).name.Equals("Recipe_Fish1"));
if (ItemChecker.IsKnife(item.m_shared))
{
InventoryGui.instance.m_craftUpgradeItem = null;
InventoryGui.instance.m_craftRecipe = val;
}
else
{
if (!ItemChecker.IsRecipeFish(item.m_shared, val, out var foundRecipePart))
{
return false;
}
if (!ItemChecker.HasKnife(Player.m_localPlayer))
{
((Character)Player.m_localPlayer).Message((MessageType)1, "$msg_missingrequirement: $skill_knives", 0, (Sprite)null);
__result = true;
return true;
}
InventoryGui.instance.m_craftUpgradeItem = null;
InventoryGui.instance.m_craftRecipe = GetSoloFishRecipe(item, val, foundRecipePart);
}
if (TryDoCrafting(InventoryGui.instance))
{
((MonoBehaviour)Player.m_localPlayer).StartCoroutine(SpawnFishBlood());
}
InventoryGui.instance.m_craftRecipe = null;
__result = true;
return true;
}
private static Recipe GetSoloFishRecipe(ItemData item, Recipe baseFishRecipe, Requirement foundRecipePart)
{
if (soloFishRecipes.TryGetValue(item.m_shared.m_name, out var value) && (Object)(object)value != (Object)null && value.m_resources != null && value.m_resources.Length == 1 && value.m_resources[0] != null)
{
return value;
}
if ((Object)(object)value != (Object)null)
{
RawFishWithoutCauldronPlugin.LogSource.LogInfo((object)"Found a fish recipe that is not null, but still invalid. If this happens a lot, please report.");
}
Recipe val = Object.Instantiate<Recipe>(baseFishRecipe);
val.m_resources = (Requirement[])(object)new Requirement[1] { foundRecipePart };
soloFishRecipes[item.m_shared.m_name] = val;
return val;
}
private static bool TryDoCrafting(InventoryGui inventoryGui)
{
Recipe craftRecipe = inventoryGui.m_craftRecipe;
string name = craftRecipe.m_item.m_itemData.m_shared.m_name;
Dictionary<string, float> itemCraftStats = Game.instance.GetPlayerProfile().m_itemCraftStats;
CraftingStation craftingStation = craftRecipe.m_craftingStation;
craftRecipe.m_craftingStation = null;
float valueSafe = GeneralExtensions.GetValueSafe<string, float>(itemCraftStats, name);
inventoryGui.DoCrafting(Player.m_localPlayer);
float valueSafe2 = GeneralExtensions.GetValueSafe<string, float>(itemCraftStats, name);
craftRecipe.m_craftingStation = craftingStation;
return valueSafe2 > valueSafe;
}
private static IEnumerator SpawnFishBlood()
{
yield return (object)new WaitForSeconds(0.22f);
GameObject prefab = ZNetScene.instance.GetPrefab("fx_TickBloodHit");
if (Object.op_Implicit((Object)(object)prefab))
{
Vector3 position = ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 0.8f + ((Component)Player.m_localPlayer).transform.up * 1f;
Object.Instantiate<GameObject>(prefab, position, Quaternion.identity);
}
}
}
internal class ItemChecker
{
internal static bool IsRecipeFish(SharedData shared, Recipe fishRecipe, out Requirement foundRecipePart)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Invalid comparison between Unknown and I4
foundRecipePart = null;
if (shared == null || (int)shared.m_itemType != 21)
{
return false;
}
Requirement[] resources = fishRecipe.m_resources;
foreach (Requirement val in resources)
{
if (Object.op_Implicit((Object)(object)val.m_resItem) && val.m_resItem.m_itemData?.m_shared?.m_name == shared.m_name)
{
foundRecipePart = val;
return true;
}
}
return false;
}
internal static bool IsKnife(SharedData shared)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Invalid comparison between Unknown and I4
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Invalid comparison between Unknown and I4
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Invalid comparison between Unknown and I4
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Invalid comparison between Unknown and I4
if (shared == null)
{
return false;
}
ItemType itemType = shared.m_itemType;
ItemType val = itemType;
if ((int)val == 3 || (int)val == 14 || (int)val == 22)
{
return (int)shared.m_skillType == 2;
}
return false;
}
internal static bool HasKnife(Player player)
{
foreach (ItemData item in ((Humanoid)player).m_inventory.m_inventory)
{
if (item != null && IsKnife(item.m_shared))
{
return true;
}
}
return false;
}
}
[BepInPlugin("goldenrevolver.RawFishWithoutCauldron", "Quickly Cut Raw Fish Without Cauldron", "1.1.0")]
public class RawFishWithoutCauldronPlugin : BaseUnityPlugin
{
public const string GUID = "goldenrevolver.RawFishWithoutCauldron";
public const string NAME = "Quickly Cut Raw Fish Without Cauldron";
public const string VERSION = "1.1.0";
internal static ManualLogSource LogSource { get; private set; }
protected void Awake()
{
LogSource = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
}
}