using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 PotionCraft.Core.SerializableDictionary;
using PotionCraft.InventorySystem;
using PotionCraft.ManagersSystem;
using PotionCraft.ManagersSystem.Potion.Entities;
using PotionCraft.ManagersSystem.RecipeMap;
using PotionCraft.ManagersSystem.Trade;
using PotionCraft.NotificationSystem;
using PotionCraft.ObjectBased.RecipeMap.RecipeMapObject;
using PotionCraft.ObjectBased.Stack;
using PotionCraft.ObjectBased.UIElements.Dialogue;
using PotionCraft.ObjectBased.UIElements.FloatingText;
using PotionCraft.ScriptableObjects;
using PotionCraft.ScriptableObjects.BuildableInventoryItem;
using PotionCraft.Settings;
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 = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MoreChanceForSeeds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("MoreChanceForSeeds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MoreChanceForSeeds;
internal class Functions
{
public static void CreateText(string text)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
RecipeMapObject recipeMapObject = Managers.RecipeMap.recipeMapObject;
RecipeMapManagerPotionBasesSettings asset = Settings<RecipeMapManagerPotionBasesSettings>.Asset;
Rect viewRect = recipeMapObject.transmitterWindow.ViewRect;
Vector2 center = ((Rect)(ref viewRect)).center;
CollectedFloatingText.SpawnNewText(asset.floatingTextSelectBase, Vector2.op_Implicit(center), new FloatingTextContent(text, (Type)1, 0f), ((Component)Managers.Game.Cam).transform, false, false);
}
public static string GetLastComponent()
{
List<AlchemySubstanceComponent> components = Managers.Potion.PotionUsedComponents.components;
return ((Object)components[components.Count - 1].Component).name;
}
public static int GetRandomInt()
{
return Random.Range(1, 4);
}
public static float ChanceForSeed()
{
return Random.Range(0f, 1f);
}
public static Seed ReturnSeed(string name)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
return (Seed)BuildableInventoryItem.allBuildableItems[(BuildableInventoryItemType)1].Where((BuildableInventoryItem s) => ((Object)s).name.Contains(name)).First();
}
public static bool isValidItem(InventoryItem item)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
List<InventoryItemType> list = new List<InventoryItemType>
{
(InventoryItemType)3,
(InventoryItemType)4,
(InventoryItemType)2
};
return list.Contains(item.GetItemType()) ? true : false;
}
public static void GetTheSeed(string name, int random, bool isTrading)
{
Seed val = ReturnSeed(name);
string text = ((random > 1) ? "seeds" : "seed");
string text2 = "Got " + random + " " + name + " " + text + "!";
if (isTrading)
{
Notification.ShowText("More Chance For Seeds", text2, (TextType)1);
}
else
{
CreateText(text2);
}
Managers.Player.Inventory.AddItem((InventoryItem)(object)val, random, true, true);
}
}
internal class Patches
{
private static float seedChance = Plugin.configSeedChance.Value;
[HarmonyPostfix]
[HarmonyPatch(typeof(Stack), "AddIngredientPathToMapPath")]
public static void AddIngredientPathToMapPath_Postfix()
{
if (Plugin.configCauldronSeeds.Value)
{
float num = Functions.ChanceForSeed();
if (!(num > seedChance))
{
string lastComponent = Functions.GetLastComponent();
int randomInt = Functions.GetRandomInt();
Functions.GetTheSeed(lastComponent, randomInt, isTrading: false);
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(TradeManager), "MakeDeal")]
public static void MakeDeal_Prefix()
{
if (!Plugin.configMerchantSeeds.Value)
{
return;
}
TradingPanel tradingPanel = Managers.Trade.GetTradingPanel((Owner)1);
Inventory inventory = ((ItemsPanel)tradingPanel).Inventory;
foreach (KeyValuePair<InventoryItem, int> item in (SerializableDictionaryBase<InventoryItem, int, int>)(object)inventory.items)
{
float num = Functions.ChanceForSeed();
if (num < seedChance)
{
string name = ((Object)item.Key).name;
if (Functions.isValidItem(item.Key))
{
}
if ((Object)(object)Functions.ReturnSeed(name) != (Object)null)
{
int randomInt = Functions.GetRandomInt();
Functions.GetTheSeed(name, randomInt, isTrading: true);
}
}
}
}
}
[BepInPlugin("mattdeduck.PotionMoreChanceForSeeds", "PotionMoreChanceForSeeds", "1.0.0.0")]
[BepInProcess("Potion Craft.exe")]
public class Plugin : BaseUnityPlugin
{
public const string PLUGIN_GUID = "mattdeduck.PotionMoreChanceForSeeds";
public const string PLUGIN_VERSION = "1.0.0.0";
public static ConfigEntry<bool> configCauldronSeeds;
public static ConfigEntry<bool> configMerchantSeeds;
public static ConfigEntry<float> configSeedChance;
public static ManualLogSource Log { get; set; }
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
configCauldronSeeds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CauldronSeeds", true, "Enables/Disables the chance for seeds to drop when adding ingredients to the cauldron");
configMerchantSeeds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "MerchantSeeds", true, "Enables/Disables the chance for seeds to drop when buying ingredients from merchants");
configSeedChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SeedChance", 0.33f, "The percentage float the random chance needs to be under to gain seed(s)");
Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
Harmony.CreateAndPatchAll(typeof(Functions), (string)null);
Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
Log.LogInfo((object)"Plugin MoreChanceForSeeds is loaded!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "MoreChanceForSeeds";
public const string PLUGIN_NAME = "My first plugin";
public const string PLUGIN_VERSION = "1.0.0";
}