using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EasyThreshing.Patches;
using EquinoxsModUtils;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("EasyThreshing")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EasyThreshing")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2178634c-144e-453a-9e3b-fbf993b8c308")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace EasyThreshing
{
[BepInPlugin("com.equinox.EasyThreshing", "EasyThreshing", "1.0.0")]
public class EasyThreshingPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.equinox.EasyThreshing";
private const string PluginName = "EasyThreshing";
private const string VersionString = "1.0.0";
private static readonly Harmony Harmony = new Harmony("com.equinox.EasyThreshing");
public static ManualLogSource Log = new ManualLogSource("EasyThreshing");
public static ConfigEntry<bool> duplicateSeeds;
public static ConfigEntry<bool> voidExcessOutput;
public static ConfigEntry<bool> pauseIfBothFull;
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: EasyThreshing, VersionString: 1.0.0 is loading...");
Harmony.PatchAll();
ApplyPatches();
CreateConfigEntries();
Events.GameDefinesLoaded += OnGameDefinesLoaded;
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: EasyThreshing, VersionString: 1.0.0 is loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void OnGameDefinesLoaded()
{
if (duplicateSeeds.Value)
{
int resourceIDByName = Resources.GetResourceIDByName("Kindlevine", false);
int resourceIDByName2 = Resources.GetResourceIDByName("Shiverthorn", false);
SchematicsRecipeData val = Recipes.TryFindThresherRecipe(resourceIDByName, false);
SchematicsRecipeData val2 = Recipes.TryFindThresherRecipe(resourceIDByName2, false);
val.outputQuantities[0] = 2;
val2.outputQuantities[0] = 2;
}
}
private void ApplyPatches()
{
Harmony.CreateAndPatchAll(typeof(ThresherInstancePatch), (string)null);
}
private void CreateConfigEntries()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Expected O, but got Unknown
duplicateSeeds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Duplicate Seeds", true, new ConfigDescription("When true, each threshed plant will produce two seeds.", (AcceptableValueBase)null, Array.Empty<object>()));
voidExcessOutput = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Void Excess Output", true, new ConfigDescription("When true, if one thresher output fills up, items are voided from it instead of the thresher pausing.", (AcceptableValueBase)null, Array.Empty<object>()));
pauseIfBothFull = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Pause If Both Full", true, new ConfigDescription("When true, threshers will pause crafting when both outputs are full instead of voiding both.", (AcceptableValueBase)null, Array.Empty<object>()));
}
}
}
namespace EasyThreshing.Patches
{
internal class ThresherInstancePatch
{
[HarmonyPatch(typeof(ThresherInstance), "UpdateCrafting")]
[HarmonyPrefix]
private static void ClearOutputsForCrafting(ThresherInstance __instance)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
if (!EasyThreshingPlugin.voidExcessOutput.Value)
{
return;
}
Inventory inputInventory = ((ThresherInstance)(ref __instance)).GetInputInventory();
if (((ResourceStack)(ref inputInventory.myStacks[0])).isEmpty)
{
return;
}
Inventory outputInventory = ((ThresherInstance)(ref __instance)).GetOutputInventory();
SchematicsRecipeData val = Recipes.TryFindThresherRecipe(inputInventory.myStacks[0].id, false);
if (IsSlotFull(__instance, 0) && IsSlotFull(__instance, 1) && EasyThreshingPlugin.pauseIfBothFull.Value)
{
return;
}
for (int i = 0; i < outputInventory.myStacks.Count(); i++)
{
if (IsSlotFull(__instance, i))
{
((Inventory)(ref outputInventory)).RemoveResourcesFromSlot(i, val.outputQuantities[i]);
}
}
}
private static bool IsSlotFull(ThresherInstance __instance, int index)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: 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_001a: 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)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
Inventory inputInventory = ((ThresherInstance)(ref __instance)).GetInputInventory();
Inventory outputInventory = ((ThresherInstance)(ref __instance)).GetOutputInventory();
SchematicsRecipeData val = Recipes.TryFindThresherRecipe(inputInventory.myStacks[0].id, false);
if (((ResourceStack)(ref outputInventory.myStacks[index])).isEmpty)
{
return false;
}
int num = val.outputQuantities[index];
int num2 = outputInventory.myStacks[index].maxStack - num;
return outputInventory.myStacks[index].count >= num2;
}
}
}