using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;
using xiaoye97;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("CrazyRecipes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin. Multiplies the output number of items for all recipes")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CrazyRecipes")]
[assembly: AssemblyTitle("CrazyRecipes")]
[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 CrazyRecipes
{
public class EditRecipes
{
private static readonly string Dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
private readonly string FilePathRecipes = Path.Combine(Dir, "Recipes.xml");
private const int MaxItemCount = 1000000;
public void Run()
{
List<Recipe> recipesFromGame = GetRecipesFromGame();
List<Recipe> list = GetRecipesFromFile();
if (list == null)
{
list = recipesFromGame;
}
RemoveDuplicates(list);
AddRecipesFromFile(list, recipesFromGame);
SetRecipesToGame(list);
SetRecipesToFile(list);
}
private void RemoveDuplicates(List<Recipe> fromFile)
{
fromFile = (from recipe in fromFile
group recipe by recipe.ID into @group
select @group.First()).ToList();
}
private void AddRecipesFromFile(List<Recipe> fromFile, List<Recipe> fromGame)
{
foreach (Recipe gameRecipe in fromGame)
{
if (!fromFile.Any((Recipe fileRecipe) => fileRecipe.ID == gameRecipe.ID))
{
fromFile.Add(gameRecipe);
}
}
}
private List<Recipe> GetRecipesFromGame()
{
List<Recipe> list = new List<Recipe>();
RecipeProto[] dataArray = ((ProtoSet<RecipeProto>)(object)LDB.recipes).dataArray;
foreach (RecipeProto val in dataArray)
{
List<Item> itemRecipes = GetItemRecipes(val.Items, val.ItemCounts);
List<Item> itemRecipes2 = GetItemRecipes(val.Results, val.ResultCounts);
list.Add(new Recipe
{
name = ((Proto)val).name,
ID = ((Proto)val).ID,
inItem = itemRecipes,
outItem = itemRecipes2
});
}
if (list.Count <= 0)
{
return null;
}
return list;
}
private List<Recipe> GetRecipesFromFile()
{
if (!File.Exists(FilePathRecipes))
{
return null;
}
XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Recipe>));
try
{
using FileStream stream = new FileStream(FilePathRecipes, FileMode.Open);
List<Recipe> list = (List<Recipe>)xmlSerializer.Deserialize(stream);
return (list.Count > 0) ? list : null;
}
catch
{
return null;
}
}
private void SetRecipesToGame(List<Recipe> recipes)
{
foreach (Recipe recipe in recipes)
{
RecipeProto val = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(recipe.ID);
int[] source = new int[6] { 9, 18, 27, 55, 75, 102 };
if (val == null || source.Contains(((Proto)val).ID))
{
continue;
}
List<int> list = new List<int>();
List<int> list2 = new List<int>();
foreach (Item item in recipe.inItem)
{
if (((ProtoSet<ItemProto>)(object)LDB.items).Select(item.ID) != null)
{
list.Add(item.ID);
list2.Add(Mathf.Clamp(item.count, 0, 1000000));
}
}
List<int> list3 = new List<int>();
List<int> list4 = new List<int>();
foreach (Item item2 in recipe.outItem)
{
if (((ProtoSet<ItemProto>)(object)LDB.items).Select(item2.ID) != null)
{
list3.Add(item2.ID);
list4.Add(Mathf.Clamp(item2.count, 0, 1000000));
}
}
val.Items = list.ToArray();
val.ItemCounts = list2.ToArray();
val.Results = list3.ToArray();
val.ResultCounts = list4.ToArray();
}
}
private void SetRecipesToFile(List<Recipe> recipes)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Recipe>));
try
{
using FileStream stream = new FileStream(FilePathRecipes, FileMode.Create);
xmlSerializer.Serialize(stream, recipes);
}
catch
{
}
}
private List<Item> GetItemRecipes(int[] itemIds, int[] itemCounts)
{
List<Item> list = new List<Item>();
for (int i = 0; i < itemIds.Length; i++)
{
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(itemIds[i]);
list.Add(new Item
{
name = ((Proto)val).name,
ID = ((Proto)val).ID,
count = itemCounts[i]
});
}
return list;
}
}
[Serializable]
public class Recipe
{
public string name;
public int ID;
public List<Item> inItem;
public List<Item> outItem;
}
[Serializable]
public class Item
{
public string name;
public int ID;
public int count;
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.MeredithRodneyMackay.CrazyRecipes", "CrazyRecipes", "1.1.0")]
[BepInProcess("DSPGAME.exe")]
public class Plugin : BaseUnityPlugin
{
public const string NAME = "CrazyRecipes";
public const string GUID = "com.MeredithRodneyMackay.CrazyRecipes";
public const string VERSION = "1.1.0";
private static ConfigEntry<bool> getRecipesFromFile;
public EditRecipes EditRecipes { get; } = new EditRecipes();
private void Start()
{
getRecipesFromFile = ((BaseUnityPlugin)this).Config.Bind<bool>("", "getRecipesFromFile", false, "Apply settings for recipes from the Recipes.xml file");
if (getRecipesFromFile.Value)
{
LDBTool.PostAddDataAction = (Action)Delegate.Combine(LDBTool.PostAddDataAction, new Action(EditRecipes.Run));
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "CrazyRecipes";
public const string PLUGIN_NAME = "CrazyRecipes";
public const string PLUGIN_VERSION = "1.0.0";
}
}