using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EquinoxsModUtils;
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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace KindKindlevineMod;
public interface IRecipePatcher
{
IRecipePatcher SetInputCount(ResourceInfo input, int count);
IRecipePatcher SetOutputCount(ResourceInfo output, int count);
IRecipePatcher SetDuration(float duration);
IRecipePatcher SetRecipe(SchematicsRecipeData schematicsRecipeData);
}
public class RecipePatcher : IRecipePatcher
{
public SchematicsRecipeData Recipe { get; private set; }
public IRecipePatcher SetRecipe(SchematicsRecipeData schematicsRecipeData)
{
Recipe = schematicsRecipeData;
return this;
}
public IRecipePatcher SetInputCount(ResourceInfo input, int count)
{
for (int i = 0; i < Recipe.ingTypes.Length; i++)
{
ResourceInfo val = Recipe.ingTypes[i];
if ((Object)(object)val == (Object)(object)input)
{
Recipe.ingQuantities[i] = count;
}
}
return this;
}
public IRecipePatcher SetOutputCount(ResourceInfo output, int count)
{
for (int i = 0; i < Recipe.outputTypes.Length; i++)
{
ResourceInfo val = Recipe.outputTypes[i];
if ((Object)(object)val == (Object)(object)output)
{
Recipe.outputQuantities[i] = count;
}
}
return this;
}
public IRecipePatcher SetDuration(float duration)
{
Recipe.duration = duration;
return this;
}
}
[BepInPlugin("com.Jarl.KindKindlevine", "KindKindlevine", "1.0.1")]
public class KindKindlevinePlugin : BaseUnityPlugin
{
private const string MyGUID = "com.Jarl.KindKindlevine";
private const string PluginName = "KindKindlevine";
private const string VersionString = "1.0.1";
private static readonly Harmony Harmony = new Harmony("com.Jarl.KindKindlevine");
public static ManualLogSource Log = new ManualLogSource("KindKindlevine");
public static string KeyboardShortcutExampleKey = "Recall Keyboard Shortcut";
public static ConfigEntry<KeyboardShortcut> KeyboardShortcutExample;
private KindKindlevinePatch patcher = new KindKindlevinePatch();
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: KindKindlevine, 1.0.1 is loading...");
Harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: KindKindlevine, 1.0.1 is loaded.");
}
private void Update()
{
patcher.KeepPatched();
}
}
public class KindKindlevinePatch : MonoBehaviour
{
private bool _definesAreLoaded;
public void KeepPatched()
{
bool flag = AreDefinesLoaded();
if (flag != _definesAreLoaded)
{
_definesAreLoaded = flag;
if (_definesAreLoaded)
{
Patch();
}
}
}
private bool AreDefinesLoaded()
{
return (Object)(object)GameLogic.instance != (Object)null && (Object)(object)GameDefines.instance != (Object)null;
}
private void Patch()
{
ResourceInfo resourceInfoByNameUnsafe = ModUtils.GetResourceInfoByNameUnsafe("Kindlevine Extract", false);
ResourceInfo resourceInfoByNameUnsafe2 = ModUtils.GetResourceInfoByNameUnsafe("Atlantum Powder", false);
ResourceInfo resourceInfoByNameUnsafe3 = ModUtils.GetResourceInfoByNameUnsafe("Kindlevine Extract Brick", false);
ResourceInfo resourceInfoByNameUnsafe4 = ModUtils.GetResourceInfoByNameUnsafe("Shiverthorn Extract Gel", false);
ResourceInfo resourceInfoByNameUnsafe5 = ModUtils.GetResourceInfoByNameUnsafe("Atlantum Powder Brick", false);
ResourceInfo resourceInfoByNameUnsafe6 = ModUtils.GetResourceInfoByNameUnsafe("Atlantum Mixture Brick", false);
ResourceInfo resourceInfoByNameUnsafe7 = ModUtils.GetResourceInfoByNameUnsafe("Mining Charge", false);
List<SchematicsRecipeData> list = new List<SchematicsRecipeData>();
RecipePatcher patcher = new RecipePatcher();
RecipeQuery recipeQuery = new RecipeQuery();
recipeQuery.SetOutputs(resourceInfoByNameUnsafe3).QueryTo(patcher, (CraftingMethod)0)?.SetInputCount(resourceInfoByNameUnsafe, 100).SetDuration(10f);
recipeQuery.SetOutputs(resourceInfoByNameUnsafe4).QueryTo(patcher, (CraftingMethod)0)?.SetDuration(10f);
recipeQuery.SetInputs(resourceInfoByNameUnsafe3).QueryTo(patcher, (CraftingMethod)3)?.SetOutputCount(resourceInfoByNameUnsafe, 50);
recipeQuery.SetOutputs(resourceInfoByNameUnsafe5).QueryTo(patcher, (CraftingMethod)0)?.SetInputCount(resourceInfoByNameUnsafe2, 100);
recipeQuery.SetOutputs(resourceInfoByNameUnsafe6).QueryTo(patcher, (CraftingMethod)0)?.SetInputCount(resourceInfoByNameUnsafe3, 10).SetInputCount(resourceInfoByNameUnsafe4, 10).SetInputCount(resourceInfoByNameUnsafe5, 10)
.SetDuration(60f);
recipeQuery.SetInputs(resourceInfoByNameUnsafe3, resourceInfoByNameUnsafe4).SetOutputs(resourceInfoByNameUnsafe7).QueryTo(patcher, (CraftingMethod)0)?.SetInputCount(resourceInfoByNameUnsafe4, 2).SetDuration(30f);
}
}
public interface IRecipeQuery
{
IRecipeQuery Clear();
IRecipeQuery SetInputs(params ResourceInfo[] items);
IRecipeQuery SetOutputs(params ResourceInfo[] items);
SchematicsRecipeData Query(CraftingMethod method);
string ToLogName();
}
public static class IRecipeQuerierExtensions
{
public static IRecipePatcher QueryTo(this IRecipeQuery query, IRecipePatcher patcher, CraftingMethod method, bool logWarning = true)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
SchematicsRecipeData val = query.Query(method);
if ((Object)(object)val == (Object)null)
{
if (logWarning)
{
KindKindlevinePlugin.Log.LogWarning((object)("Not found recipe: " + query.ToLogName()));
}
return null;
}
query.Clear();
return patcher.SetRecipe(val);
}
}
public class RecipeQuery : IRecipeQuery
{
private List<ResourceInfo> _inputs = new List<ResourceInfo>();
private List<ResourceInfo> _outputs = new List<ResourceInfo>();
public IRecipeQuery Clear()
{
_inputs.Clear();
_outputs.Clear();
return this;
}
public SchematicsRecipeData Query(CraftingMethod method = 0)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
TryFindRecipe(method, _inputs, _outputs, out var recipeDefine);
return recipeDefine;
}
public string ToLogName()
{
string text = string.Join(", ", _inputs.Select((ResourceInfo i) => i.displayName));
string text2 = string.Join(", ", _outputs.Select((ResourceInfo i) => i.displayName));
return "({" + text + "}, {" + text2 + "})";
}
public static bool TryFindRecipe(CraftingMethod method, List<ResourceInfo> inputs, List<ResourceInfo> outputs, out SchematicsRecipeData recipeDefine)
{
//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)
recipeDefine = null;
foreach (SchematicsRecipeData schematicsRecipeEntry in GameDefines.instance.schematicsRecipeEntries)
{
if (schematicsRecipeEntry.craftingMethod == method && Compare(inputs, schematicsRecipeEntry.ingTypes) && Compare(outputs, schematicsRecipeEntry.outputTypes))
{
if ((Object)(object)recipeDefine != (Object)null)
{
recipeDefine = null;
return false;
}
recipeDefine = schematicsRecipeEntry;
}
}
return (Object)(object)recipeDefine != (Object)null;
static bool Compare(List<ResourceInfo> quiried, ResourceInfo[] items)
{
return quiried.All(((IEnumerable<ResourceInfo>)items).Contains<ResourceInfo>);
}
}
public IRecipeQuery SetInputs(params ResourceInfo[] items)
{
_inputs.Clear();
foreach (ResourceInfo item in items)
{
_inputs.Add(item);
}
return this;
}
public IRecipeQuery SetOutputs(params ResourceInfo[] items)
{
_outputs.Clear();
foreach (ResourceInfo item in items)
{
_outputs.Add(item);
}
return this;
}
}