using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 Microsoft.CodeAnalysis;
using RoR2;
using RoR2.ContentManagement;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ConfigurableCrafting")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+07ec65656d515ec8afd82f69b54f6a2e9c345b45")]
[assembly: AssemblyProduct("ConfigurableCrafting")]
[assembly: AssemblyTitle("ConfigurableCrafting")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ConfigurableCrafting
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("swuff.ConfigurableCrafting", "ConfigurableCrafting", "1.0.0")]
public class ConfigurableCraftingPlugin : BaseUnityPlugin
{
private class PendingRecipe
{
public CraftableDef craftableDef;
public string pickupNameA;
public string pickupNameB;
public string pickupNameC;
public int amount;
}
public const string PluginGUID = "swuff.ConfigurableCrafting";
public const string PluginAuthor = "swuff";
public const string PluginName = "ConfigurableCrafting";
public const string PluginVersion = "1.0.0";
private readonly List<PendingRecipe> _pendingRecipes = new List<PendingRecipe>();
public static ConfigEntry<string> CraftingList { get; set; }
public void Awake()
{
MakeConfig();
CreateCraftableDefsFromConfig();
new PluginContentPack().Initialize();
((ResourceAvailability)(ref PickupCatalog.availability)).CallWhenAvailable((Action)DefineRecipes);
}
public void MakeConfig()
{
CraftingList = ((BaseUnityPlugin)this).Config.Bind<string>("Configurable Crafting", "Crafting List", "(IncreaseHealing,DeathMark,NovaOnHeal,1),(NovaOnHeal,TPHealingNova,IncreaseHealing,1)", "A list of all crafting recipes to be added. Should be formatted as such, with recipes separated by commas:\n(InputPickupNameA,InputPickupNameA,OutputPickupName,OutputAmount)");
}
private void CreateCraftableDefsFromConfig()
{
_pendingRecipes.Clear();
string[] array = CraftingList.Value.Trim().TrimEnd(',').Split(new string[1] { "),(" }, StringSplitOptions.None);
string[] array2 = array;
foreach (string text in array2)
{
string text2 = text.Trim('(', ')');
string[] array3 = text2.Split(',');
if (array3.Length == 4)
{
string pickupNameA = array3[0];
string pickupNameB = array3[1];
string pickupNameC = array3[2];
int amount = int.Parse(array3[3]);
CraftableDef val = ScriptableObject.CreateInstance<CraftableDef>();
PluginContentPack.craftableDefs.Add(val);
_pendingRecipes.Add(new PendingRecipe
{
craftableDef = val,
pickupNameA = pickupNameA,
pickupNameB = pickupNameB,
pickupNameC = pickupNameC,
amount = amount
});
Debug.Log((object)("PRE-REGISTERED RECIPE : " + text));
}
else
{
Debug.LogWarning((object)("FAILED TO PRE-REGISTER RECIPE : " + text));
}
}
}
public void DefineRecipes()
{
foreach (PendingRecipe pendingRecipe in _pendingRecipes)
{
if (TryGetPickupData(pendingRecipe.pickupNameA, out var _, out var itemDef, out var equipmentDef) && TryGetPickupData(pendingRecipe.pickupNameB, out var _, out var itemDef2, out var equipmentDef2) && TryGetPickupData(pendingRecipe.pickupNameC, out var _, out var itemDef3, out var equipmentDef3))
{
FillCraftableDef(pendingRecipe.craftableDef, itemDef, equipmentDef, itemDef2, equipmentDef2, itemDef3, equipmentDef3, pendingRecipe.amount);
Debug.Log((object)("ADDED RECIPE : " + pendingRecipe.pickupNameA + " + " + pendingRecipe.pickupNameB + " = " + pendingRecipe.amount + "x " + pendingRecipe.pickupNameC));
}
else
{
Debug.LogError((object)("FAILED TO ADD RECIPE : " + pendingRecipe.pickupNameA + " + " + pendingRecipe.pickupNameB + " = " + pendingRecipe.amount + "x " + pendingRecipe.pickupNameC));
}
}
_pendingRecipes.Clear();
}
private void FillCraftableDef(CraftableDef craftableDef, ItemDef itemA, EquipmentDef equipmentA, ItemDef itemB, EquipmentDef equipmentB, ItemDef itemC, EquipmentDef equipmentC, int amount)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
craftableDef.pickup = (Object)(((Object)(object)itemC != (Object)null) ? ((object)itemC) : ((object)equipmentC));
Recipe[] array = new Recipe[1];
Recipe val = new Recipe();
val.amountToDrop = amount;
val.ingredients = (RecipeIngredient[])(object)new RecipeIngredient[2]
{
new RecipeIngredient
{
pickup = (Object)(((Object)(object)itemA != (Object)null) ? ((object)itemA) : ((object)equipmentA))
},
new RecipeIngredient
{
pickup = (Object)(((Object)(object)itemB != (Object)null) ? ((object)itemB) : ((object)equipmentB))
}
};
array[0] = val;
craftableDef.recipes = (Recipe[])(object)array;
}
public bool TryGetPickupData(string pickupName, out PickupDef pickupDef, out ItemDef itemDef, out EquipmentDef equipmentDef)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Invalid comparison between Unknown and I4
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Invalid comparison between Unknown and I4
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
pickupDef = null;
itemDef = null;
equipmentDef = null;
ItemIndex val = ItemCatalog.FindItemIndex(pickupName);
EquipmentIndex val2 = EquipmentCatalog.FindEquipmentIndex(pickupName);
if ((int)val != -1)
{
itemDef = ItemCatalog.GetItemDef(val);
return true;
}
if ((int)val2 != -1)
{
equipmentDef = EquipmentCatalog.GetEquipmentDef(val2);
return true;
}
Debug.LogWarning((object)("Failed to find any pickup-related index for " + pickupName));
return false;
}
}
public class PluginContentPack : IContentPackProvider
{
internal ContentPack contentPack = new ContentPack();
public static List<CraftableDef> craftableDefs = new List<CraftableDef>();
public string identifier => "swuff.ConfigurableCrafting";
public void Initialize()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(ContentManager_collectContentpackProviders);
}
private void ContentManager_collectContentpackProviders(AddContentPackProviderDelegate addContentPackProvider)
{
addContentPackProvider.Invoke((IContentPackProvider)(object)this);
}
public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
{
contentPack.identifier = identifier;
contentPack.craftableDefs.Add(craftableDefs.ToArray());
args.ReportProgress(1f);
yield break;
}
public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
{
ContentPack.Copy(contentPack, args.output);
args.ReportProgress(1f);
yield break;
}
public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
{
args.ReportProgress(1f);
yield break;
}
}
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
}