using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using PotionCraft;
using PotionCraft.Core;
using PotionCraft.ManagersSystem;
using PotionCraft.ManagersSystem.Room;
using PotionCraft.ObjectBased;
using PotionCraft.ObjectBased.AlchemyMachineProduct;
using PotionCraft.ObjectBased.Garden.GrowingSpot;
using PotionCraft.ObjectBased.InteractiveItem;
using PotionCraft.ObjectBased.Potion;
using PotionCraft.ObjectBased.UIElements.FinishLegendarySubstanceMenu;
using PotionCraft.ScriptableObjects;
using PotionCraft.ScriptableObjects.AlchemyMachineProducts;
using PotionCraft.ScriptableObjects.Potion;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PlentifulHarvest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlentifulHarvest")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("144c051f-d407-464f-93df-5d180fad006b")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("2.0.1.0")]
namespace PlentifulHarvest;
[BepInPlugin("VIP.TommySoucy.PlentifulHarvest", "Plentiful Harvest", "2.0.1")]
public class PlentifulHarvestMod : BaseUnityPlugin
{
public class GrowthTimer
{
public PotionItem potion;
public int level;
public float time;
public GrowthTimer(PotionItem potion, int level, float time)
{
this.potion = potion;
this.level = level;
this.time = time;
}
}
public const string pluginGuid = "VIP.TommySoucy.PlentifulHarvest";
public const string pluginName = "Plentiful Harvest";
public const string pluginVersion = "2.0.1";
public static int harvestIngredientMultiplier = 1;
public static int harvestExperienceMutliplier = 1;
public static int nigredoCountMultiplier = 1;
public static int albedoCountMultiplier = 1;
public static int citrinitasCountMultiplier = 1;
public static int rubedoCountMultiplier = 1;
public static int philosopherStoneCountMultiplier = 1;
public static int saltCountMultiplier = 1;
public static float growthDelay = 3f;
public static int growthIncrement = 2;
public static int harvestIncrement = 1;
public static List<GrowthTimer> currentGrowthTimers;
private static List<GrowthTimer> growthTimers;
public static List<PotionItem> harvestPotions;
public static int harvestCount = 0;
public static bool alchemicalMachineProductFinish = false;
public void Start()
{
Init();
DoPatching();
}
private void Init()
{
growthTimers = new List<GrowthTimer>();
currentGrowthTimers = new List<GrowthTimer>();
harvestPotions = new List<PotionItem>();
LoadConfig();
}
public void Update()
{
for (int i = 0; i < growthTimers.Count; i++)
{
growthTimers[i].time -= Time.deltaTime;
if (!(growthTimers[i].time <= 0f))
{
continue;
}
currentGrowthTimers.Add(growthTimers[i]);
for (int j = 0; j < harvestPotions.Count; j++)
{
if (((object)harvestPotions[j]).Equals((object?)growthTimers[i].potion))
{
harvestPotions.RemoveAt(j);
break;
}
}
Object.Destroy((Object)(object)growthTimers[i].potion);
growthTimers.RemoveAt(i--);
}
if (currentGrowthTimers.Count > 0)
{
GrowingSpotObject.GrowPlants();
}
}
private void LoadConfig()
{
try
{
string[] array = File.ReadAllLines("BepinEx/Plugins/PlentifulHarvestConfig.txt");
foreach (string text in array)
{
if (text.Length == 0 || text[0] == '#')
{
continue;
}
string[] array2 = text.Trim().Split(new char[1] { '=' });
if (array2.Length != 0)
{
if (array2[0].IndexOf("harvestIngredientMultiplier") == 0)
{
harvestIngredientMultiplier = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("harvestExperienceMutliplier") == 0)
{
harvestExperienceMutliplier = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("nigredoCountMultiplier") == 0)
{
nigredoCountMultiplier = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("albedoCountMultiplier") == 0)
{
albedoCountMultiplier = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("citrinitasCountMultiplier") == 0)
{
citrinitasCountMultiplier = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("rubedoCountMultiplier") == 0)
{
rubedoCountMultiplier = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("philosopherStoneCountMultiplier") == 0)
{
philosopherStoneCountMultiplier = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("saltCountMultiplier") == 0)
{
saltCountMultiplier = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("growthDelay") == 0)
{
growthDelay = float.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("growthIncrement") == 0)
{
growthIncrement = int.Parse(array2[1].Trim());
}
else if (array2[0].IndexOf("harvestIncrement ") == 0)
{
harvestIncrement = int.Parse(array2[1].Trim());
}
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Configs loaded");
}
catch (FileNotFoundException ex)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Couldn't find PlentifulHarvestConfig.txt, using default settings instead. Error: " + ex.Message));
}
catch (Exception ex2)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Couldn't read PlentifulHarvestConfig.txt, using default settings instead. Error: " + ex2.Message));
}
}
private void DoPatching()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Expected O, but got Unknown
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Expected O, but got Unknown
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Expected O, but got Unknown
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Expected O, but got Unknown
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Expected O, but got Unknown
//IL_01f2: Expected O, but got Unknown
Harmony val = new Harmony("VIP.TommySoucy.PlentifulHarvest");
MethodInfo method = typeof(SpotPlant).GetMethod("GatherIngredient", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method2 = typeof(HarvestCountPatch).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic);
val.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo method3 = typeof(GrowingSpotObject).GetMethod("InstantiatePlant", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method4 = typeof(SpotPlantIngredientAmountPatch).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic);
val.Patch((MethodBase)method3, (HarmonyMethod)null, new HarmonyMethod(method4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo method5 = typeof(FinishProductButton).GetMethod("OnButtonReleasedPointerInside");
MethodInfo method6 = typeof(AlchemyMachineFinishProductPatch).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic);
val.Patch((MethodBase)method5, new HarmonyMethod(method6), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo method7 = typeof(AlchemyMachineProductItem).GetMethod("PutInInventory");
MethodInfo method8 = typeof(AlchemyMachineProductCountPatch).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic);
val.Patch((MethodBase)method7, new HarmonyMethod(method8), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo method9 = typeof(ItemFromInventory).GetMethod("ReleaseToPlayZone", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method10 = typeof(GardenDropPotionPatch).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic);
val.Patch((MethodBase)method9, (HarmonyMethod)null, new HarmonyMethod(method10), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo method11 = typeof(ItemFromInventory).GetMethod("OnGrabPrimary");
MethodInfo method12 = typeof(GardenGrabPotionPatch).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic);
val.Patch((MethodBase)method11, new HarmonyMethod(method12), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo method13 = typeof(GrowingSpotObject).GetMethod("GrowPlants");
MethodInfo method14 = typeof(GrowPlantsPatch).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo method15 = typeof(GrowPlantsPatch).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic);
val.Patch((MethodBase)method13, new HarmonyMethod(method14), new HarmonyMethod(method15), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
public static void AddGrowth(PotionItem potion, int level)
{
growthTimers.Add(new GrowthTimer(potion, level, growthDelay));
}
public static void RemoveGrowth(PotionItem potion)
{
for (int i = 0; i < growthTimers.Count; i++)
{
if (((object)growthTimers[i].potion).Equals((object?)potion))
{
growthTimers.RemoveAt(i);
break;
}
}
}
}
internal class HarvestCountPatch
{
private static void Prefix(ref int ___experienceOnHarvest, ref Vector2Int ___ingredientAmount)
{
//IL_000c: 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_001b: Unknown result type (might be due to invalid IL or missing references)
___experienceOnHarvest *= PlentifulHarvestMod.harvestExperienceMutliplier;
___ingredientAmount *= PlentifulHarvestMod.harvestIngredientMultiplier;
}
}
internal class SpotPlantIngredientAmountPatch
{
private static void Postfix(ref GameObject ___plantGameObject)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
SpotPlant component = ___plantGameObject.GetComponent<SpotPlant>();
FieldInfo? field = ((object)component).GetType().GetField("ingredientAmount", BindingFlags.Instance | BindingFlags.NonPublic);
Vector2Int val = (Vector2Int)field.GetValue(component);
int num = PlentifulHarvestMod.harvestCount * PlentifulHarvestMod.harvestIncrement;
((Vector2Int)(ref val)).x = ((Vector2Int)(ref val)).x + num;
((Vector2Int)(ref val)).y = ((Vector2Int)(ref val)).y + num;
field.SetValue(component, val);
}
}
internal class AlchemyMachineFinishProductPatch
{
private static void Prefix()
{
PlentifulHarvestMod.alchemicalMachineProductFinish = true;
}
}
internal class AlchemyMachineProductCountPatch
{
private static bool Prefix(AlchemyMachineProductItem __instance, ref Inventory ___inventory, ref ItemsPanel ___itemsPanel)
{
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Expected O, but got Unknown
if (PlentifulHarvestMod.alchemicalMachineProductFinish)
{
PlentifulHarvestMod.alchemicalMachineProductFinish = false;
int num = 1;
InventoryItem inventoryItem = ((ItemFromInventory)__instance).inventoryItem;
LegendarySaltPile val = (LegendarySaltPile)(object)((inventoryItem is LegendarySaltPile) ? inventoryItem : null);
if (((Object)((ItemFromInventory)__instance).inventoryItem).name.Equals("Nigredo"))
{
num = PlentifulHarvestMod.nigredoCountMultiplier;
}
else if (((Object)((ItemFromInventory)__instance).inventoryItem).name.Equals("Albedo"))
{
num = PlentifulHarvestMod.albedoCountMultiplier;
}
else if (((Object)((ItemFromInventory)__instance).inventoryItem).name.Equals("Citrinitas"))
{
num = PlentifulHarvestMod.citrinitasCountMultiplier;
}
else if (((Object)((ItemFromInventory)__instance).inventoryItem).name.Equals("Rubedo"))
{
num = PlentifulHarvestMod.rubedoCountMultiplier;
}
else if (((Object)((ItemFromInventory)__instance).inventoryItem).name.Equals("PhilosophersStone"))
{
num = PlentifulHarvestMod.philosopherStoneCountMultiplier;
}
else
{
if (!((Object)(object)val != (Object)null))
{
return true;
}
num = PlentifulHarvestMod.saltCountMultiplier;
}
if (___inventory == null)
{
MethodInfo method = typeof(ItemFromInventory).GetMethod("GetInventory", BindingFlags.Instance | BindingFlags.NonPublic);
___inventory = (Inventory)method.Invoke(__instance, null);
}
if ((Object)(object)val != (Object)null)
{
___inventory.AddItem((InventoryItem)(object)val.convertToSaltOnPickup, val.amountOfSalt * num, true, true);
((ItemFromInventory)__instance).DestroyItem();
}
else
{
___inventory.AddItem(((ItemFromInventory)__instance).inventoryItem, num, true, true);
((ItemFromInventory)__instance).DestroyItem();
}
typeof(AlchemyMachineProductItem).GetMethod("TryDetachFromAlchemicalMachine", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, null);
return false;
}
return true;
}
}
internal class GardenDropPotionPatch
{
private static void Postfix(ref ItemFromInventory __instance)
{
PotionItem val = null;
int num = 0;
int num2 = 0;
if (Managers.Room.IsCurrentOrTargetRoom((RoomIndex)2))
{
ItemFromInventory obj = __instance;
PotionItem val2 = (PotionItem)(object)((obj is PotionItem) ? obj : null);
if ((Object)(object)val2 != (Object)null)
{
val = val2;
InventoryItem inventoryItem = ((ItemFromInventory)val2).inventoryItem;
Potion val3 = (Potion)(object)((inventoryItem is Potion) ? inventoryItem : null);
if ((Object)(object)val3 != (Object)null)
{
for (int i = 0; i < val3.Effects.Length; i++)
{
if (!((ComparableScriptableObject<PotionEffect>)(object)val3.Effects[i] == (ComparableScriptableObject<PotionEffect>)null))
{
if (((Object)val3.Effects[i]).name.ToLower().Contains("growth"))
{
num++;
}
else if (((Object)val3.Effects[i]).name.ToLower().Contains("crop"))
{
num2++;
}
}
}
}
}
}
if (num > 0)
{
PlentifulHarvestMod.AddGrowth(val, num);
}
if (num2 > 0)
{
PlentifulHarvestMod.harvestCount += num2;
PlentifulHarvestMod.harvestPotions.Add(val);
}
}
}
internal class GardenGrabPotionPatch
{
private static void Prefix(ref ItemFromInventory __instance)
{
PotionItem val = null;
bool flag = false;
bool flag2 = false;
int num = 0;
if (Managers.Room.IsCurrentOrTargetRoom((RoomIndex)2))
{
ItemFromInventory obj = __instance;
PotionItem val2 = (PotionItem)(object)((obj is PotionItem) ? obj : null);
if ((Object)(object)val2 != (Object)null)
{
val = val2;
InventoryItem inventoryItem = ((ItemFromInventory)val2).inventoryItem;
Potion val3 = (Potion)(object)((inventoryItem is Potion) ? inventoryItem : null);
if ((Object)(object)val3 != (Object)null)
{
for (int i = 0; i < val3.Effects.Length; i++)
{
if (!((ComparableScriptableObject<PotionEffect>)(object)val3.Effects[i] == (ComparableScriptableObject<PotionEffect>)null))
{
if (((Object)val3.Effects[i]).name.ToLower().Contains("growth"))
{
flag = true;
}
else if (((Object)val3.Effects[i]).name.ToLower().Contains("crop"))
{
flag2 = true;
num++;
}
}
}
}
}
}
if (flag)
{
PlentifulHarvestMod.RemoveGrowth(val);
}
if (flag2 && PlentifulHarvestMod.harvestPotions.Remove(val))
{
PlentifulHarvestMod.harvestCount -= num;
}
}
}
internal class GrowPlantsPatch
{
private static void Prefix()
{
int minimalSpotPlants = 6;
if (PlentifulHarvestMod.currentGrowthTimers.Count > 0)
{
int num = 0;
foreach (PlentifulHarvestMod.GrowthTimer currentGrowthTimer in PlentifulHarvestMod.currentGrowthTimers)
{
num += currentGrowthTimer.level;
}
PlentifulHarvestMod.currentGrowthTimers.Clear();
minimalSpotPlants = num * PlentifulHarvestMod.growthIncrement;
}
Managers.Ingredient.spotPlantSettings.minimalSpotPlants = minimalSpotPlants;
}
private static void Postfix()
{
PlentifulHarvestMod.harvestCount = 0;
foreach (PotionItem harvestPotion in PlentifulHarvestMod.harvestPotions)
{
Object.Destroy((Object)(object)harvestPotion);
}
PlentifulHarvestMod.harvestPotions.Clear();
}
}