Decompiled source of JSONLoader v0.7.0

JSONLoader.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using ATS_API;
using ATS_API.Ascension;
using ATS_API.Buildings;
using ATS_API.Difficulties;
using ATS_API.Goods;
using ATS_API.Helpers;
using ATS_API.Localization;
using ATS_API.MetaRewards;
using ATS_API.Recipes;
using ATS_API.Recipes.Builders;
using ATS_JSONLoader;
using ATS_JSONLoader.Sounds;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Eremite;
using Eremite.Buildings;
using Eremite.Characters.Villagers;
using Eremite.Controller;
using Eremite.Model;
using Eremite.Model.Meta;
using Eremite.Model.Sound;
using Eremite.Model.Trade;
using HarmonyLib;
using JLPlugin;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Sirenix.Utilities;
using TinyJson;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("JSONLoader")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds new content to Against the Storm using files instead of code")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyInformationalVersion("0.7.0+fc4511e8260721c9b9a12301e2ef1419256ee057")]
[assembly: AssemblyProduct("JSONLoader")]
[assembly: AssemblyTitle("JSONLoader")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.7.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]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[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;
		}
	}
}
public abstract class ABuildingData : IInitializable
{
	[SchemaGuid]
	public string guid;

	[SchemaName]
	public string name;

	[SchemaIcon(/*Could not decode attribute arguments.*/)]
	public string icon;

	[SchemaDisplayName]
	public LocalizableField displayName;

	[SchemaDescription]
	public LocalizableField description;

	[SchemaField(0, "The order of which this will be good will be sorted in some lists.")]
	public int? order;

	[SchemaField(0, "Maximum amount of this building the player can have.")]
	public int? maxAmount;

	[SchemaField(4, "Total builders that can construct this building.")]
	public int? maxBuilders;

	[SchemaField(1f, "The base refund rate for this building.")]
	public float? baseRefundRate;

	[SchemaField(true)]
	public bool? canBePicked;

	[SchemaField(true)]
	public bool? initiallyEssential;

	[SchemaEnum<BuildingCategoriesTypes>(/*Could not decode attribute arguments.*/)]
	public string category;

	[HelperMethods.SchemaBuildingTagTypes(/*Could not decode attribute arguments.*/)]
	public string[] tags;

	[SchemaField(null)]
	public string[] usabilityTags;

	[SchemaField(null)]
	public HelperMethods.GoodRefData movingCost;

	[SchemaField(null)]
	public bool? movable;

	[SchemaField(null)]
	public HelperMethods.GoodRefData[] requiredGoods;

	public virtual void Initialize()
	{
		displayName = new LocalizableField("displayName");
		description = new LocalizableField("description");
	}
}
public abstract class ABuildingLoader<ModelType, DataType> where ModelType : BuildingModel where DataType : ABuildingData
{
	public abstract string FileExtension { get; }

	public abstract string Category { get; }

	public abstract IEnumerable<ModelType> AllModels { get; }

	public abstract ModelType CreateNewModelModel(string guid, string name);

	public abstract bool GetNewData(string name, out string rawName, out string guid);

	public virtual void LoadAll(List<string> files)
	{
		for (int i = 0; i < files.Count; i++)
		{
			string text = files[i];
			if (!text.EndsWith(FileExtension))
			{
				continue;
			}
			ImportExportUtils.SetDebugPath(text);
			files.RemoveAt(i--);
			try
			{
				Logging.VerboseLog("Loading JSON (" + typeof(ModelType).Name + ") " + text);
				DataType data = text.FromFilePath<DataType>();
				if (data == null)
				{
					Plugin.Log.LogError((object)("Failed to load JSON (" + typeof(ModelType).Name + ") " + text));
					continue;
				}
				Logging.VerboseLog("Loaded JSON (" + typeof(ModelType).Name + ") " + text);
				ABuildingData aBuildingData = data;
				if (aBuildingData.guid == null)
				{
					aBuildingData.guid = (AllModels.Any((ModelType a) => ((Object)(object)a).name == data.name) ? "" : "JSONLoader");
				}
				string text2 = ((!string.IsNullOrEmpty(data.guid)) ? (data.guid + "_") : "");
				string fullName = text2 + data.name;
				bool isNewGood = false;
				ModelType val = default(ModelType);
				if (AllModels.Any((ModelType a) => ((Object)(object)a).name == fullName))
				{
					Logging.VerboseLog("Found existing " + typeof(DataType).Name + " " + fullName);
					val = AllModels.First((ModelType a) => ((Object)(object)a).name == fullName);
				}
				else
				{
					Logging.VerboseLog("Creating new " + typeof(DataType).Name + " " + fullName);
					val = CreateNewModelModel(data.guid, data.name);
					isNewGood = true;
				}
				Logging.VerboseLog("Applying JSON (" + typeof(ModelType).Name + ") " + text + " to " + typeof(DataType).Name + " " + fullName);
				Apply(val, data, toModel: true, fullName, isNewGood);
				Logging.VerboseLog("Loaded JSON " + typeof(DataType).Name + " " + fullName);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Error loading JSON ({typeof(ModelType).Name}) {text}\n{arg}");
			}
		}
	}

	public virtual void Apply(ModelType model, DataType data, bool toModel, string modelName, bool isNewGood)
	{
		ImportExportUtils.SetID(modelName);
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).icon, ref data.icon, toModel, Category, "icon");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).order, ref data.order, toModel, Category, "order");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).maxAmount, ref data.maxAmount, toModel, Category, "maxAmount");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).maxBuilders, ref data.maxBuilders, toModel, Category, "maxBuilders");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).baseRefundRate, ref data.baseRefundRate, toModel, Category, "baseRefundRate");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).canBePicked, ref data.canBePicked, toModel, Category, "canBePicked");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).initiallyEssential, ref data.initiallyEssential, toModel, Category, "initiallyEssential");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).movingCost, ref data.movingCost, toModel, Category, "movingCost");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).movable, ref data.movable, toModel, Category, "movable");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).category, ref data.category, toModel, Category, "category");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).tags, ref data.tags, toModel, Category, "tags");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).usabilityTags, ref data.usabilityTags, toModel, Category, "usabilityTags");
		ImportExportUtils.ApplyValueNoNull(ref ((BuildingModel)model).requiredGoods, ref data.requiredGoods, toModel, Category, "requiredGoods");
	}

	public virtual void ExportAll()
	{
		Plugin.Log.LogInfo((object)$"Exporting {AllModels.Count()} {typeof(ModelType).Name}s.");
		foreach (ModelType allModel in AllModels)
		{
			DataType val = Activator.CreateInstance<DataType>();
			val.Initialize();
			if (GetNewData(((Object)(object)allModel).name, out var rawName, out var guid))
			{
				val.guid = guid;
				val.name = rawName;
			}
			else
			{
				val.name = ((Object)(object)allModel).name;
			}
			Apply(allModel, val, toModel: false, ((Object)(object)allModel).name, isNewGood: false);
			string path = ((Object)(object)allModel).name + FileExtension;
			string path2 = Path.Combine(Plugin.ExportDirectory, Category, path);
			if (!Directory.Exists(Path.GetDirectoryName(path2)))
			{
				Directory.CreateDirectory(Path.GetDirectoryName(path2));
			}
			string contents = JSONParser.ToJSON(val);
			File.WriteAllText(path2, contents);
		}
	}
}
public class DecorationBuildingLoader : ABuildingLoader<DecorationModel, DecorationBuildingData>
{
	public const string kFileExtension = "_decorationBuilding.json";

	public override string FileExtension => "_decorationBuilding.json";

	public override string Category => "DecorationBuilding";

	public override IEnumerable<DecorationModel> AllModels => MB.Settings.Buildings.Where((BuildingModel a) => a is DecorationModel).Cast<DecorationModel>();

	public override DecorationModel CreateNewModelModel(string guid, string name)
	{
		return ((GenericBuildingData<DecorationModel>)(object)BuildingManager.CreateDecoration(guid, name)).BuildingModel;
	}

	public override bool GetNewData(string name, out string rawName, out string guid)
	{
		NewHouseBuildingData val = ((IEnumerable<NewHouseBuildingData>)BuildingManager.NewHouses).FirstOrDefault((Func<NewHouseBuildingData, bool>)((NewHouseBuildingData a) => ((Object)((GenericBuildingData<HouseModel>)(object)a).BuildingModel).name == name));
		if (val == null)
		{
			rawName = null;
			guid = null;
			return false;
		}
		rawName = ((GenericBuildingData<HouseModel>)(object)val).Name;
		guid = ((GenericBuildingData<HouseModel>)(object)val).Guid;
		return true;
	}

	public override void Apply(DecorationModel model, DecorationBuildingData data, bool toModel, string modelName, bool isNewGood)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		base.Apply(model, data, toModel, modelName, isNewGood);
		ImportExportUtils.SetID(modelName);
		DecorationBuildingBuilder builder = new DecorationBuildingBuilder(model);
		ImportExportUtils.ApplyLocaText(ref ((BuildingModel)model).displayName, ref data.displayName, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((BuildingBuilder<DecorationModel, NewDecorationBuildingData>)(object)builder).SetDisplayName(a, b);
		}, toModel, "displayName");
		ImportExportUtils.ApplyLocaText(ref ((BuildingModel)model).description, ref data.description, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((BuildingBuilder<DecorationModel, NewDecorationBuildingData>)(object)builder).SetDescription(a, b);
		}, toModel, "description");
		ImportExportUtils.ApplyValueNoNull(ref model.tier, ref data.tier, toModel, Category, "tier");
	}
}
[GenerateSchema("DecorationBuilding", "A decoration building that buffs the hearth. (ie: Anvil, Fox Fence, Harmony Spirit Altar)", "_houseBuilding.json")]
public class DecorationBuildingData : ABuildingData
{
	[SchemaEnum<DecorationTierTypes>(/*Could not decode attribute arguments.*/)]
	public string tier;
}
public class HouseBuildingLoader : ABuildingLoader<HouseModel, HouseBuildingData>
{
	public const string kFileExtension = "_houseBuilding.json";

	public override string FileExtension => "_houseBuilding.json";

	public override string Category => "HouseBuilding";

	public override IEnumerable<HouseModel> AllModels => MB.Settings.Buildings.Where((BuildingModel a) => a is HouseModel).Cast<HouseModel>();

	public override HouseModel CreateNewModelModel(string guid, string name)
	{
		return ((GenericBuildingData<HouseModel>)(object)BuildingManager.CreateHouse(guid, name)).BuildingModel;
	}

	public override bool GetNewData(string name, out string rawName, out string guid)
	{
		NewHouseBuildingData val = ((IEnumerable<NewHouseBuildingData>)BuildingManager.NewHouses).FirstOrDefault((Func<NewHouseBuildingData, bool>)((NewHouseBuildingData a) => ((Object)((GenericBuildingData<HouseModel>)(object)a).BuildingModel).name == name));
		if (val == null)
		{
			rawName = null;
			guid = null;
			return false;
		}
		rawName = ((GenericBuildingData<HouseModel>)(object)val).Name;
		guid = ((GenericBuildingData<HouseModel>)(object)val).Guid;
		return true;
	}

	public override void Apply(HouseModel model, HouseBuildingData data, bool toModel, string modelName, bool isNewGood)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		base.Apply(model, data, toModel, modelName, isNewGood);
		HouseBuildingBuilder builder = new HouseBuildingBuilder(model);
		ImportExportUtils.ApplyLocaText(ref ((BuildingModel)model).displayName, ref data.displayName, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((BuildingBuilder<HouseModel, NewHouseBuildingData>)(object)builder).SetDisplayName(a, b);
		}, toModel, "displayName");
		ImportExportUtils.ApplyLocaText(ref ((BuildingModel)model).description, ref data.description, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((BuildingBuilder<HouseModel, NewHouseBuildingData>)(object)builder).SetDescription(a, b);
		}, toModel, "description");
		ImportExportUtils.ApplyValueNoNull(ref model.housingRaces, ref data.housingRaces, toModel, Category, "housingRaces");
		ImportExportUtils.ApplyValueNoNull(ref model.housingPlaces, ref data.housingPlaces, toModel, Category, "housingPlaces");
		ImportExportUtils.ApplyValueNoNull(ref model.servedNeeds, ref data.servedNeeds, toModel, Category, "servedNeeds");
	}
}
[GenerateSchema("HouseBuilding", "Buildings that server housing needs for Villagers. (ie: Human House, Frog House)", "_houseBuilding.json")]
public class HouseBuildingData : ABuildingData
{
	[SchemaField(null)]
	public string[] housingRaces;

	[SchemaField(null)]
	public int? housingPlaces;

	[SchemaField(null)]
	public string[] servedNeeds;
}
public class InstitutionBuildingLoader : ABuildingLoader<InstitutionModel, InstitutionBuildingData>
{
	public const string kFileExtension = "_institutionBuilding.json";

	public override string Category => "InstitutionBuilding";

	public override string FileExtension => "_institutionBuilding.json";

	public override IEnumerable<InstitutionModel> AllModels => MB.Settings.Buildings.Where((BuildingModel a) => a is InstitutionModel).Cast<InstitutionModel>();

	public override InstitutionModel CreateNewModelModel(string guid, string name)
	{
		return ((GenericBuildingData<InstitutionModel>)(object)BuildingManager.CreateInstitution(guid, name)).BuildingModel;
	}

	public override bool GetNewData(string name, out string rawName, out string guid)
	{
		NewInstitutionBuildingData val = ((IEnumerable<NewInstitutionBuildingData>)BuildingManager.NewInstitutions).FirstOrDefault((Func<NewInstitutionBuildingData, bool>)((NewInstitutionBuildingData a) => ((Object)((GenericBuildingData<InstitutionModel>)(object)a).BuildingModel).name == name));
		if (val == null)
		{
			rawName = null;
			guid = null;
			return false;
		}
		rawName = ((GenericBuildingData<InstitutionModel>)(object)val).Name;
		guid = ((GenericBuildingData<InstitutionModel>)(object)val).Guid;
		return true;
	}

	public override void Apply(InstitutionModel model, InstitutionBuildingData data, bool toModel, string modelName, bool isNewGood)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		base.Apply(model, data, toModel, modelName, isNewGood);
		InstitutionBuildingBuilder builder = new InstitutionBuildingBuilder(model);
		ImportExportUtils.ApplyLocaText(ref ((BuildingModel)model).displayName, ref data.displayName, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((BuildingBuilder<InstitutionModel, NewInstitutionBuildingData>)(object)builder).SetDisplayName(a, b);
		}, toModel, "displayName");
		ImportExportUtils.ApplyLocaText(ref ((BuildingModel)model).description, ref data.description, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((BuildingBuilder<InstitutionModel, NewInstitutionBuildingData>)(object)builder).SetDescription(a, b);
		}, toModel, "description");
		ImportExportUtils.ApplyValueNoNull(ref model.workplaces, ref data.workplaces, toModel, Category, "workplaces");
		ImportExportUtils.ApplyValueNoNull(ref model.recipes, ref data.institutionRecipes, toModel, Category, "institutionRecipes");
		ImportExportUtils.ApplyValueNoNull(ref model.profession, ref data.profession, toModel, Category, "profession");
		ImportExportUtils.ApplyValueNoNull(ref model.activeEffects, ref data.institutionActiveEffects, toModel, Category, "institutionActiveEffects");
	}
}
[GenerateSchema("InstitutionBuilding", "A building that requires goods to satisfy needs. (ie: Bath House, Clan Hall) ", "_institutionBuilding.json")]
public class InstitutionBuildingData : ABuildingData
{
	[SchemaField(null)]
	public HelperMethods.WorkPlaceData[] workplaces;

	[SchemaField(null)]
	public string[] institutionRecipes;

	[SchemaEnum<ProfessionTypes>(/*Could not decode attribute arguments.*/)]
	public string profession;

	[SchemaField(null)]
	public HelperMethods.InstitutionActiveEffectData[] institutionActiveEffects;
}
public class WorkshopBuildingLoader : ABuildingLoader<WorkshopModel, WorkshopBuildingData>
{
	public const string fileExtension = "_workshopBuilding.json";

	public override string FileExtension => "_workshopBuilding.json";

	public override string Category => "WorkshopBuilding";

	public override IEnumerable<WorkshopModel> AllModels => MB.Settings.workshops;

	public override WorkshopModel CreateNewModelModel(string guid, string name)
	{
		return ((GenericBuildingData<WorkshopModel>)(object)BuildingManager.CreateWorkshop(guid, name)).BuildingModel;
	}

	public override bool GetNewData(string name, out string rawName, out string guid)
	{
		NewWorkshopBuildingData val = ((IEnumerable<NewWorkshopBuildingData>)BuildingManager.NewWorkshops).FirstOrDefault((Func<NewWorkshopBuildingData, bool>)((NewWorkshopBuildingData a) => ((Object)((GenericBuildingData<WorkshopModel>)(object)a).BuildingModel).name == name));
		if (val == null)
		{
			rawName = null;
			guid = null;
			return false;
		}
		rawName = ((GenericBuildingData<WorkshopModel>)(object)val).Name;
		guid = ((GenericBuildingData<WorkshopModel>)(object)val).Guid;
		return true;
	}

	public override void Apply(WorkshopModel model, WorkshopBuildingData data, bool toModel, string modelName, bool isNewGood)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		base.Apply(model, data, toModel, modelName, isNewGood);
		WorkshopBuildingBuilder builder = new WorkshopBuildingBuilder(model);
		ImportExportUtils.ApplyLocaText(ref ((BuildingModel)model).displayName, ref data.displayName, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((BuildingBuilder<WorkshopModel, NewWorkshopBuildingData>)(object)builder).SetDisplayName(a, b);
		}, toModel, "displayName");
		ImportExportUtils.ApplyLocaText(ref ((BuildingModel)model).description, ref data.description, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((BuildingBuilder<WorkshopModel, NewWorkshopBuildingData>)(object)builder).SetDescription(a, b);
		}, toModel, "description");
		ImportExportUtils.ApplyValueNoNull(ref model.profession, ref data.profession, toModel, Category, "profession");
		ImportExportUtils.ApplyValueNoNull(ref model.workplaces, ref data.workplaces, toModel, Category, "workplaces");
		ImportExportUtils.ApplyValueNoNull(ref model.recipes, ref data.workshopRecipes, toModel, Category, "recipes");
	}
}
[GenerateSchema("WorkshopBuilding", "Buildings that turn goods into products. (ie: Bakery, Toolshop)", "_workshopBuilding.json")]
public class WorkshopBuildingData : ABuildingData
{
	[SchemaEnum<ProfessionTypes>(/*Could not decode attribute arguments.*/)]
	public string profession;

	[SchemaField(null)]
	public HelperMethods.WorkPlaceData[] workplaces;

	[SchemaField(null)]
	public string[] workshopRecipes;
}
public class DifficultyLoader
{
	public const string fileExtension = "_difficulty.json";

	public static void LoadAll(List<string> files)
	{
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Expected O, but got Unknown
		for (int i = 0; i < files.Count; i++)
		{
			string text = files[i];
			if (!text.EndsWith("_difficulty.json"))
			{
				continue;
			}
			ImportExportUtils.SetDebugPath(text);
			files.RemoveAt(i--);
			try
			{
				Logging.VerboseLog("Loading JSON (difficulties) " + text);
				DifficultyData data = text.FromFilePath<DifficultyData>();
				if (data == null)
				{
					Plugin.Log.LogError((object)("Failed to load JSON (difficulties) " + text));
					continue;
				}
				Logging.VerboseLog("Loaded JSON (difficulties) " + text);
				DifficultyData difficultyData = data;
				if (difficultyData.guid == null)
				{
					difficultyData.guid = (MB.Settings.difficulties.Any((DifficultyModel a) => ((Object)a).name == data.name) ? "" : "JSONLoader");
				}
				string text2 = ((!string.IsNullOrEmpty(data.guid)) ? (data.guid + "_") : "");
				string fullName = text2 + data.name;
				bool isNewDifficulty = false;
				DifficultyModel val = null;
				if (MB.Settings.difficulties.Any((DifficultyModel a) => ((Object)a).name == fullName))
				{
					Logging.VerboseLog("Found existing difficulty " + fullName);
					val = MB.Settings.difficulties.First((DifficultyModel a) => ((Object)a).name == fullName);
				}
				else
				{
					Logging.VerboseLog("Creating new difficulty " + fullName);
					DifficultyBuilder val2 = new DifficultyBuilder(data.guid, data.name);
					val = val2.Model;
					isNewDifficulty = true;
				}
				Logging.VerboseLog("Applying JSON (difficulties) " + text + " to difficulty " + fullName);
				Apply(val, data, toModel: true, fullName, isNewDifficulty);
				Logging.VerboseLog("Loaded JSON difficulty " + fullName);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Error loading JSON (difficulties) {text}\n{arg}");
			}
		}
	}

	public static void Apply(DifficultyModel model, DifficultyData data, bool toModel, string modelName, bool isNewDifficulty)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_0427: Unknown result type (might be due to invalid IL or missing references)
		ImportExportUtils.SetID(modelName);
		DifficultyBuilder builder = new DifficultyBuilder(model);
		ImportExportUtils.ApplyLocaText(ref model.displayName, ref data.displayName, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			builder.SetDisplayName(a, b);
		}, toModel, "displayName");
		ImportExportUtils.ApplyLocaText(ref model.description, ref data.description, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			builder.SetDescription(a, b);
		}, toModel, "description");
		ImportExportUtils.ApplyValueNoNull(ref model.shortName, ref data.shortName, toModel, "difficulties", "shortName");
		ImportExportUtils.ApplyValueNoNull(ref model.index, ref data.index, toModel, "difficulties", "index");
		ImportExportUtils.ApplyValueNoNull(ref model.ascensionIndex, ref data.ascensionIndex, toModel, "difficulties", "ascensionIndex");
		ImportExportUtils.ApplyValueNoNull(ref model.sealFramentsForWin, ref data.sealFragmentsForWin, toModel, "difficulties", "sealFragmentsForWin");
		ImportExportUtils.ApplyValueNoNull(ref model.isAscension, ref data.isAscension, toModel, "difficulties", "eatable");
		ImportExportUtils.ApplyValueNoNull(ref model.canBePicked, ref data.canBePicked, toModel, "difficulties", "canBePicked");
		ImportExportUtils.ApplyValueNoNull(ref model.isInCustomGame, ref data.isInCustomGame, toModel, "difficulties", "isInCustomGame");
		ImportExportUtils.ApplyValueNoNull(ref model.blightFootprintRate, ref data.blightFootprintRate, toModel, "difficulties", "blightFootprintRate");
		ImportExportUtils.ApplyValueNoNull(ref model.blightCorruptionRate, ref data.blightCorruptionRate, toModel, "difficulties", "blightCorruptionRate");
		ImportExportUtils.ApplyValueNoNull(ref model.rewardsMultiplier, ref data.rewardsMultiplier, toModel, "difficulties", "rewardsMultiplier");
		ImportExportUtils.ApplyValueNoNull(ref model.expMultiplier, ref data.expMultiplier, toModel, "difficulties", "expMultiplier");
		ImportExportUtils.ApplyValueNoNull(ref model.scoreMultiplier, ref data.scoreMultiplier, toModel, "difficulties", "scoreMultiplier");
		ImportExportUtils.ApplyValueNoNull(ref model.difficultyBudget, ref data.difficultyBudget, toModel, "difficulties", "difficultyBudget");
		ImportExportUtils.ApplyValueNoNull(ref model.positiveEffects, ref data.positiveEffects, toModel, "difficulties", "positiveEffects");
		ImportExportUtils.ApplyValueNoNull(ref model.negativeEffects, ref data.negativeEffects, toModel, "difficulties", "negativeEffects");
		ImportExportUtils.ApplyValueNoNull(ref model.minEffectCost, ref data.minEffectCost, toModel, "difficulties", "minEffectCost");
		ImportExportUtils.ApplyValueNoNull(ref model.maxEffectCost, ref data.maxEffectCost, toModel, "difficulties", "maxEffectCost");
		ImportExportUtils.ApplyValueNoNull(ref model.preparationPointsPenalty, ref data.preparationPointsPenalty, toModel, "difficulties", "preparationPointsPenalty");
		ImportExportUtils.ApplyValueNoNull(ref model.portRequirementsRatio, ref data.portRequirementsRatio, toModel, "difficulties", "portRequirementsRatio");
		ImportExportUtils.ApplyValueNoNull(ref model.maxWildcards, ref data.maxWildcards, toModel, "difficulties", "maxWildcards");
		ImportExportUtils.ApplyValueNoNull(ref model.inGameSeal, ref data.inGameSeal, toModel, "difficulties", "inGameSeal");
		ImportExportUtils.ApplyValueNoNull(ref model.modifiers, ref data.modifiers, toModel, "difficulties", "modifiers");
		if (toModel)
		{
			if (data.prestigeLevel.HasValue)
			{
				builder.SetPrestigeLevel(data.prestigeLevel.Value, true);
			}
			if (data.copyModifiersFromPreviousDifficulties.HasValue)
			{
				builder.CopyModifiersFromPreviousDifficulties(data.copyModifiersFromPreviousDifficulties.Value);
			}
			if (data.newModifiers != null)
			{
				for (int i = 0; i < data.newModifiers.Length; i++)
				{
					DifficultyData.NewModifier newModifier = data.newModifiers[i];
					bool valueOrDefault = newModifier.isShown.GetValueOrDefault(true);
					bool valueOrDefault2 = newModifier.isEarlyEffect.GetValueOrDefault();
					bool valueOrDefault3 = newModifier.inCustomMode.GetValueOrDefault(true);
					NewAscensionModifierModel modifier = builder.AddModifier(EffectTypesExtensions.ToEffectTypes(newModifier.effect), valueOrDefault, valueOrDefault2, valueOrDefault3);
					ImportExportUtils.ApplyLocaText(ref modifier.ShortDescription, ref newModifier.shortDescription, delegate(string a, SystemLanguage b)
					{
						//IL_0007: Unknown result type (might be due to invalid IL or missing references)
						modifier.SetShortDescription(a, b);
					}, toModel, $"newModifiers[{i}].shortDescription");
				}
			}
		}
		else
		{
			data.prestigeLevel = model.ascensionIndex + 1;
			data.copyModifiersFromPreviousDifficulties = builder.NewDifficulty.copyModifiersFromPreviousDifficulty;
		}
		if (toModel)
		{
			if (!isNewDifficulty && !string.IsNullOrEmpty(data.icon))
			{
				ImportExportUtils.ApplyProperty(() => model.icon, delegate(Sprite a)
				{
					builder.SetIcon(a);
				}, ref data.icon, toModel, "difficulties", "icon");
			}
		}
		else
		{
			ImportExportUtils.ApplyProperty(() => model.icon, delegate(Sprite a)
			{
				builder.SetIcon(a);
			}, ref data.icon, toModel, "difficulties", "icon");
		}
	}

	public static void ExportAll()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		Plugin.Log.LogInfo((object)$"Exporting {MB.Settings.difficulties.Length} Difficulties.");
		DifficultyModel[] difficulties = MB.Settings.difficulties;
		foreach (DifficultyModel val in difficulties)
		{
			DifficultyTypes key = DifficultyTypesExtensions.ToDifficultyTypes(((Object)val).name);
			DifficultyData difficultyData = new DifficultyData();
			difficultyData.Initialize();
			NewDifficulty value;
			bool flag = DifficultyManager.NewDifficultiesLookup.TryGetValue(key, out value);
			if (flag)
			{
				difficultyData.guid = value.guid;
				difficultyData.name = value.rawName;
			}
			else
			{
				difficultyData.name = ((Object)val).name;
			}
			Apply(val, difficultyData, toModel: false, ((Object)val).name, flag);
			string path = Path.Combine(Plugin.ExportDirectory, "difficulties", ((Object)val).name + "_difficulty.json");
			if (!Directory.Exists(Path.GetDirectoryName(path)))
			{
				Directory.CreateDirectory(Path.GetDirectoryName(path));
			}
			string contents = JSONParser.ToJSON(difficultyData);
			File.WriteAllText(path, contents);
		}
	}
}
[GenerateSchema("Difficulty", "Difficulty when starting a settlement.", "_difficulty.json")]
public class DifficultyData : IInitializable
{
	public class NewModifier : IInitializable
	{
		[SchemaShortDescription]
		public LocalizableField shortDescription;

		[SchemaEffectType(/*Could not decode attribute arguments.*/)]
		public string effect;

		[SchemaField(true, false, "When set to true will apply the effect to the difficulty.")]
		public bool? isEarlyEffect;

		[SchemaField(true, false, "When set to false will hide the effect from the list of effects in custom games.")]
		public bool? isShown;

		[SchemaField(true, false, "When set to false will hide the effect from the list of effects in custom games.")]
		public bool? inCustomMode;

		public void Initialize()
		{
			shortDescription = new LocalizableField("shortDescription");
		}
	}

	[SchemaGuid]
	public string guid;

	[SchemaName]
	public string name;

	[SchemaIcon(/*Could not decode attribute arguments.*/)]
	public string icon;

	[SchemaDisplayName]
	public LocalizableField displayName;

	[SchemaDescription]
	public LocalizableField description;

	[SchemaShortName]
	public string shortName;

	[SchemaField(0, false, "Position in the list of difficulties. Starts at 0 for the first difficulty.")]
	public int? index;

	[SchemaField(1, false, "Position in the list of ascension difficulties. 0 if not prestige difficulty or first prestige in the list.")]
	public int? ascensionIndex;

	[SchemaField(5, false, "Amount of seal fragments earned when winning the game with this difficulty selected.")]
	public int? sealFragmentsForWin;

	[SchemaField(false, false, "When set to true will set this difficulty to be a prestige difficulty.")]
	public bool? isAscension;

	[SchemaField(true, false, "When set to false will hide this difficulty from the list of difficulties.")]
	public bool? canBePicked;

	[SchemaField(true, false, "When set to false will hide this difficulty from the list of difficulties in custom games.")]
	public bool? isInCustomGame;

	[SchemaField(1f)]
	public float? blightFootprintRate;

	[SchemaField(1f)]
	public float? blightCorruptionRate;

	[SchemaField(5.1f)]
	public float? rewardsMultiplier;

	[SchemaField(5.1f)]
	public float? expMultiplier;

	[SchemaField(2.1f)]
	public float? scoreMultiplier;

	[SchemaField(6)]
	public int? difficultyBudget;

	[SchemaField(1)]
	public int? positiveEffects;

	[SchemaField(4)]
	public int? negativeEffects;

	[SchemaField(-1)]
	public int? minEffectCost;

	[SchemaField(3)]
	public int? maxEffectCost;

	[SchemaField(-4)]
	public int? preparationPointsPenalty;

	[SchemaField(1)]
	public float? portRequirementsRatio;

	[SchemaField(1)]
	public int? maxWildcards;

	[SchemaField("Seal")]
	public string inGameSeal;

	[SchemaAscensionModifierType("List of effects that are applied to this difficulty.")]
	public string[] modifiers;

	[SchemaField(1, false, "Prestige level of the difficulty. Overrides everything in the Difficulty to set the prestige level.")]
	public int? prestigeLevel;

	[SchemaField(true, false, "When set to true will copy the modifiers from the lower level difficulties.")]
	public bool? copyModifiersFromPreviousDifficulties;

	[SchemaField(null, false, "List of new modifiers that are created and applied to this difficulty.")]
	public NewModifier[] newModifiers;

	public void Initialize()
	{
		displayName = new LocalizableField("displayName");
		description = new LocalizableField("description");
	}
}
public class GoodsLoader
{
	public const string fileExtension = "_good.json";

	public static void LoadAll(List<string> files)
	{
		for (int i = 0; i < files.Count; i++)
		{
			string text = files[i];
			if (!text.EndsWith("_good.json"))
			{
				continue;
			}
			ImportExportUtils.SetDebugPath(text);
			files.RemoveAt(i--);
			try
			{
				Logging.VerboseLog("Loading JSON (goods) " + text);
				GoodsData goodsData = text.FromFilePath<GoodsData>();
				if (goodsData == null)
				{
					Plugin.Log.LogError((object)("Failed to load JSON (goods) " + text));
					continue;
				}
				Logging.VerboseLog("Loaded JSON (goods) " + text);
				GoodsData goodsData2 = goodsData;
				if (goodsData2.guid == null)
				{
					goodsData2.guid = (MB.Settings.ContainsGood(goodsData.name) ? "" : "JSONLoader");
				}
				string text2 = ((!string.IsNullOrEmpty(goodsData.guid)) ? (goodsData.guid + "_") : "");
				string text3 = text2 + goodsData.name;
				bool isNewGood = false;
				GoodModel val = null;
				if (MB.Settings.ContainsGood(text3))
				{
					Logging.VerboseLog("Found existing good " + text3);
					val = MB.Settings.GetGood(text3);
				}
				else
				{
					Logging.VerboseLog("Creating new good " + text3);
					val = GoodsManager.New(goodsData.guid, goodsData.name, goodsData.icon).goodModel;
					isNewGood = true;
				}
				Logging.VerboseLog("Applying JSON (goods) " + text + " to good " + text3);
				Apply(val, goodsData, toModel: true, text3, isNewGood);
				Logging.VerboseLog("Loaded JSON good " + text3);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Error loading JSON (goods) {text}\n{arg}");
			}
		}
	}

	public static void Apply(GoodModel model, GoodsData data, bool toModel, string modelName, bool isNewGood)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_0576: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Expected O, but got Unknown
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Expected O, but got Unknown
		ImportExportUtils.SetID(modelName);
		GoodsBuilder builder = new GoodsBuilder(model);
		ImportExportUtils.ApplyLocaText(ref model.displayName, ref data.displayName, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			builder.SetDisplayName(a, b);
		}, toModel, "displayName");
		ImportExportUtils.ApplyLocaText(ref model.description, ref data.description, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			builder.SetDescription(a, b);
		}, toModel, "description");
		ImportExportUtils.ApplyLocaText(ref model.shortDescription, ref data.shortDescription, delegate(string a, SystemLanguage b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			builder.SetShortDescription(a, b);
		}, toModel, "shortDescription");
		ImportExportUtils.ApplyProperty(() => ((Object)model.category).name, delegate(string a)
		{
			builder.SetCategory(a);
		}, ref data.category, toModel, "goods", "category");
		ApplyTraderSellingFields(builder, data, toModel, modelName);
		ApplyTraderBuyingFields(builder, data, toModel, modelName);
		ImportExportUtils.ApplyValueNoNull(ref model.eatable, ref data.eatable, toModel, "goods", "eatable");
		ImportExportUtils.ApplyValueNoNull(ref model.order, ref data.order, toModel, "goods", "order");
		ImportExportUtils.ApplyValueNoNull(ref model.burningTime, ref data.burningTime, toModel, "goods", "burningTime");
		ImportExportUtils.ApplyValueNoNull(ref model.eatingFullness, ref data.eatingFullness, toModel, "goods", "eatingFullness");
		ImportExportUtils.ApplyValueNoNull(ref model.canBeBurned, ref data.canBeBurned, toModel, "goods", "canBeBurned");
		ImportExportUtils.ApplyValueNoNull(ref model.showStorageAmount, ref data.showStorageAmount, toModel, "goods", "showStorageAmount");
		ImportExportUtils.ApplyValueNoNull(ref model.tradingBuyValue, ref data.tradingBuyValue, toModel, "goods", "tradingBuyValue");
		ImportExportUtils.ApplyValueNoNull(ref model.tradingSellValue, ref data.tradingSellValue, toModel, "goods", "tradingSellValue");
		ImportExportUtils.ApplyValueNoNull(ref model.isOnHUD, ref data.isOnHUD, toModel, "goods", "isOnHUD");
		ImportExportUtils.ApplyValueNoNull(ref model.consoleId, ref data.consoleId, toModel, "goods", "consoleId");
		ImportExportUtils.ApplyValueNoNull(ref model.tags, ref data.tags, toModel, "goods", "tags");
		if (toModel)
		{
			if (!isNewGood && !string.IsNullOrEmpty(data.icon))
			{
				ImportExportUtils.ApplyProperty(() => model.icon, delegate(Sprite a)
				{
					builder.SetIcon(a);
				}, ref data.icon, toModel, "goods", "icon");
			}
			if (data.embarkGoodMetaRewards == null)
			{
				return;
			}
			List<EmbarkGoodMetaRewardModel> list = (from a in SO.Settings.metaRewards.Where(delegate(MetaRewardModel a)
				{
					EmbarkGoodMetaRewardModel val4 = (EmbarkGoodMetaRewardModel)(object)((a is EmbarkGoodMetaRewardModel) ? a : null);
					return val4 != null && (Object)(object)val4.good.good == (Object)(object)model;
				})
				select (EmbarkGoodMetaRewardModel)(object)((a is EmbarkGoodMetaRewardModel) ? a : null)).ToList();
			GoodMetaRewardData[] embarkGoodMetaRewards = data.embarkGoodMetaRewards;
			foreach (GoodMetaRewardData goodMetaRewardData in embarkGoodMetaRewards)
			{
				string expectedName = ((!string.IsNullOrEmpty(goodMetaRewardData.guid)) ? (goodMetaRewardData.guid + "_" + goodMetaRewardData.name) : goodMetaRewardData.name);
				EmbarkGoodMetaRewardModel val = ((IEnumerable<EmbarkGoodMetaRewardModel>)list).FirstOrDefault((Func<EmbarkGoodMetaRewardModel, bool>)((EmbarkGoodMetaRewardModel a) => ((Object)a).name == expectedName));
				if ((Object)(object)val == (Object)null)
				{
					MetaRewardModel model2 = MetaRewardManager.New<EmbarkGoodMetaRewardModel>(goodMetaRewardData.guid, goodMetaRewardData.name).Model;
					val = (EmbarkGoodMetaRewardModel)(object)((model2 is EmbarkGoodMetaRewardModel) ? model2 : null);
					val.good = new GoodRef();
					val.good.good = model;
				}
				else
				{
					list.Remove(val);
				}
				EmbarkGoodMetaRewardBuilder goodBuilder = new EmbarkGoodMetaRewardBuilder((MetaRewardModel)(object)val);
				EmbarkGoodMetaRewardModel model3 = ((MetaRewardBuilder<EmbarkGoodMetaRewardModel>)(object)goodBuilder).Model;
				ImportExportUtils.ApplyValue(ref model3.good.amount, ref goodMetaRewardData.goodAmount, toModel, "metaReward", "goodAmount");
				ImportExportUtils.ApplyLocaText(ref model3.displayName, ref goodMetaRewardData.displayName, delegate(string a, SystemLanguage b)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					goodBuilder.SetDisplayName(a, b);
				}, toModel, "displayName");
				ImportExportUtils.ApplyLocaText(ref model3.description, ref goodMetaRewardData.description, delegate(string a, SystemLanguage b)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					goodBuilder.SetDescription(a, b);
				}, toModel, "description");
				ImportExportUtils.ApplyVector2Int(ref model3.costRange, ref goodMetaRewardData.minCost, ref goodMetaRewardData.maxCost, toModel, "metaReward", "costRange");
			}
			return;
		}
		ImportExportUtils.ApplyProperty(() => model.icon, delegate(Sprite a)
		{
			builder.SetIcon(a);
		}, ref data.icon, toModel, "goods", "icon");
		EmbarkGoodMetaRewardModel[] array = (from a in SO.Settings.metaRewards.Where(delegate(MetaRewardModel a)
			{
				EmbarkGoodMetaRewardModel val3 = (EmbarkGoodMetaRewardModel)(object)((a is EmbarkGoodMetaRewardModel) ? a : null);
				return val3 != null && (Object)(object)val3.good.good == (Object)(object)model;
			})
			select (EmbarkGoodMetaRewardModel)(object)((a is EmbarkGoodMetaRewardModel) ? a : null)).ToArray();
		if (array.Length == 0)
		{
			return;
		}
		data.embarkGoodMetaRewards = new GoodMetaRewardData[array.Length];
		for (int j = 0; j < array.Length; j++)
		{
			EmbarkGoodMetaRewardModel val2 = array[j];
			GoodMetaRewardData goodMetaRewardData2 = new GoodMetaRewardData();
			goodMetaRewardData2.Initialize();
			string text = "";
			string a2 = "";
			if (MetaRewardManager.NewMetaRewardsLookup.TryGetValue(MetaRewardTypesExtensions.ToMetaRewardTypes(((Object)val2).name), out var value))
			{
				text = value.rawName;
				a2 = value.guid;
			}
			else
			{
				text = ((Object)val2).name;
			}
			ImportExportUtils.ApplyValue(ref a2, ref goodMetaRewardData2.guid, toModel, "metaReward", "guid");
			ImportExportUtils.ApplyValue(ref text, ref goodMetaRewardData2.name, toModel, "metaReward", "name");
			ImportExportUtils.ApplyLocaText(ref val2.displayName, ref goodMetaRewardData2.displayName, delegate(string a, SystemLanguage b)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				builder.SetDisplayName(a, b);
			}, toModel: false, "displayName");
			ImportExportUtils.ApplyLocaText(ref val2.description, ref goodMetaRewardData2.description, delegate(string a, SystemLanguage b)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				builder.SetDescription(a, b);
			}, toModel: false, "description");
			goodMetaRewardData2.goodAmount = val2.good.amount;
			goodMetaRewardData2.minCost = ((Vector2Int)(ref val2.costRange)).x;
			goodMetaRewardData2.maxCost = ((Vector2Int)(ref val2.costRange)).y;
			data.embarkGoodMetaRewards[j] = goodMetaRewardData2;
		}
	}

	private static void ApplyTraderBuyingFields(GoodsBuilder builder, GoodsData data, bool toModel, string modelName)
	{
		TraderModel[] allTraders = MB.Settings.traders;
		IEnumerable<string> tradersBuyingThisGood = from a in MB.Settings.traders
			where a.desiredGoods.Any((GoodModel b) => ((Object)b).name == modelName)
			select ((Object)a).name;
		ImportExportUtils.ApplyProperty(() => allTraders.Length == tradersBuyingThisGood.Count(), delegate(bool a)
		{
			if (a)
			{
				builder.CanBeSoldToAllTraders();
			}
		}, ref data.allTradersBuyThisGood, !toModel, "goods", "allTradersBuyThisGood");
		ImportExportUtils.ApplyProperty(() => tradersBuyingThisGood.ToArray(), delegate(string[] a)
		{
			if (a != null)
			{
				foreach (string canBeSoldToTrader in a)
				{
					builder.SetCanBeSoldToTrader(canBeSoldToTrader);
				}
			}
		}, ref data.tradersBuyingThisGood, toModel, "goods", "tradersBuyingThisGood");
	}

	private static void ApplyTraderSellingFields(GoodsBuilder model, GoodsData data, bool toModel, string modelName)
	{
		TraderModel[] allTraders = MB.Settings.traders;
		IEnumerable<string> tradersSellingThisGood = from a in MB.Settings.traders
			where a.guaranteedOfferedGoods.Any((GoodRef b) => ((Object)b.good).name == modelName) || a.offeredGoods.Any((GoodRefWeight b) => b.Value.name == modelName)
			select ((Object)a).name;
		ImportExportUtils.ApplyProperty(() => allTraders.Length == tradersSellingThisGood.Count(), delegate(bool a)
		{
			if (a)
			{
				model.SetSoldByAllTraders();
			}
		}, ref data.allTradersSellThisGood, toModel, "goods", "allTradersSellThisGood");
		ImportExportUtils.ApplyProperty(() => tradersSellingThisGood.ToArray(), delegate(string[] a)
		{
			if (a != null)
			{
				foreach (string text in a)
				{
					model.AddTraderSellingGood(text);
				}
			}
		}, ref data.tradersSellingThisGood, toModel, "goods", "tradersSellingThisGood");
	}

	public static void ExportAll()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		Plugin.Log.LogInfo((object)$"Exporting {MB.Settings.Goods.Length} Goods.");
		GoodModel[] goods = MB.Settings.Goods;
		foreach (GoodModel val in goods)
		{
			GoodsTypes key = GoodsTypesExtensions.ToGoodsTypes(((Object)val).name);
			GoodsData goodsData = new GoodsData();
			goodsData.Initialize();
			if (GoodsManager.NewGoodsLookup.TryGetValue(key, out var value))
			{
				goodsData.guid = value.guid;
				goodsData.name = value.rawName;
			}
			else
			{
				goodsData.name = ((Object)val).name;
			}
			Apply(val, goodsData, toModel: false, ((Object)val).name, isNewGood: false);
			string path = Path.Combine(Plugin.ExportDirectory, "goods", ((Object)val).name + "_good.json");
			if (!Directory.Exists(Path.GetDirectoryName(path)))
			{
				Directory.CreateDirectory(Path.GetDirectoryName(path));
			}
			string contents = JSONParser.ToJSON(goodsData);
			File.WriteAllText(path, contents);
		}
	}
}
[GenerateSchema("Goods", "Fuel/Eatable/Tradeable items/Amber/etc.", "_good.json")]
public class GoodsData : IInitializable
{
	[SchemaGuid]
	public string guid;

	[SchemaName]
	public string name;

	[SchemaIcon(/*Could not decode attribute arguments.*/)]
	public string icon;

	[SchemaDisplayName]
	public LocalizableField displayName;

	[SchemaDescription]
	public LocalizableField description;

	[SchemaShortDescription]
	public LocalizableField shortDescription;

	[SchemaField(false, "If set to true will allow villagers to eat it. Use eatingFullness to set how full villagers get.")]
	public bool? eatable;

	[SchemaField(0, "The order of which this will be good will be sorted in some lists.")]
	public int? order;

	[SchemaField(40f, "How long this good will burn at the hearth if canBeBurned is set to true.")]
	public float? burningTime;

	[SchemaField(1f, "How full villagers get when they eat this good if eatable is set to true.")]
	public float? eatingFullness;

	[SchemaField(false, "If set to true then this good can be burnt at the hearth. Use burningTime to set how long it will burn.")]
	public bool? canBeBurned;

	[SchemaField(true)]
	public bool? showStorageAmount;

	[SchemaField(true)]
	public bool? isOnHUD;

	[SchemaEnum<GoodsCategoriesTypes>(/*Could not decode attribute arguments.*/)]
	public string category;

	[SchemaField(null)]
	public string[] tags;

	[SchemaField("", "Identifier to be used by the console??")]
	public string consoleId;

	[SchemaField(4.5f, "How much the player will receive for selling this.")]
	public float? tradingBuyValue;

	[SchemaField(true, "If set to true then this good will be sold by all traders.")]
	public bool? allTradersSellThisGood;

	[SchemaTraderType(/*Could not decode attribute arguments.*/)]
	public string[] tradersSellingThisGood;

	[SchemaField(2.25f, "How much traders will sell this good for.")]
	public float? tradingSellValue;

	[SchemaField(true, "If set to true then the player can sell this good to all traders.")]
	public bool? allTradersBuyThisGood;

	[SchemaTraderType(/*Could not decode attribute arguments.*/)]
	public string[] tradersBuyingThisGood;

	[SchemaField(null, "Rewards the player can choose when starting a new settlement. If not included then will not affect existing meta rewards.")]
	public GoodMetaRewardData[] embarkGoodMetaRewards;

	public void Initialize()
	{
		displayName = new LocalizableField("displayName");
		description = new LocalizableField("description");
		shortDescription = new LocalizableField("shortDescription");
	}
}
public class GoodMetaRewardData : IInitializable
{
	[SchemaGuid]
	public string guid;

	[SchemaGuid]
	public string name;

	[SchemaDisplayName]
	public LocalizableField displayName;

	[SchemaDescription]
	public LocalizableField description;

	[SchemaField("How much of this good you will get when selecting this reward.")]
	public int goodAmount;

	[SchemaField("Minimum cost required to get this meta reward.")]
	public int minCost;

	[SchemaField("Maximum cost required to get this meta reward.")]
	public int maxCost;

	public void Initialize()
	{
		displayName = new LocalizableField("displayName");
		description = new LocalizableField("description");
	}
}
public class HelperMethods
{
	public class GoodRefData : JSONSerializer<GoodRef, GoodRefData>, JSONSerializer<GoodRefData, GoodRef>
	{
		public string goodName;

		public int? amount;

		public GoodRef Convert(GoodRefData data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GoodRef val = new GoodRef();
			val.good = GoodsTypesExtensions.ToGoodModel(data.goodName);
			val.amount = data.amount.GetValueOrDefault();
			return val;
		}

		public GoodRefData Convert(GoodRef goodRef)
		{
			GoodRefData goodRefData = new GoodRefData();
			GoodModel good = goodRef.good;
			goodRefData.goodName = ((good != null) ? ((SO)good).Name : null);
			goodRefData.amount = goodRef.amount;
			return goodRefData;
		}
	}

	public class WorkPlaceData : JSONSerializer<WorkplaceModel, WorkPlaceData>, JSONSerializer<WorkPlaceData, WorkplaceModel>
	{
		public string[] races;

		public WorkplaceModel Convert(WorkPlaceData data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			WorkplaceModel val = new WorkplaceModel();
			val.allowedRaces = RaceTypesExtensions.ToRaceModelArray((IEnumerable<string>)data.races);
			return val;
		}

		public WorkPlaceData Convert(WorkplaceModel value)
		{
			WorkPlaceData workPlaceData = new WorkPlaceData();
			workPlaceData.races = value.allowedRaces.Select((RaceModel a) => (a != null) ? ((SO)a).Name : null).ToArray();
			return workPlaceData;
		}
	}

	public class NeedData : JSONSerializer<string, NeedModel>, JSONSerializer<NeedModel, string>
	{
		public NeedModel Convert(string name)
		{
			return NeedTypesExtensions.ToNeedModel(name);
		}

		public string Convert(NeedModel value)
		{
			return ((Object)value).name;
		}
	}

	public class TagData : JSONSerializer<string, ModelTag>, JSONSerializer<ModelTag, string>
	{
		public ModelTag Convert(string name)
		{
			return TagTypesExtensions.ToModelTag(name);
		}

		public string Convert(ModelTag value)
		{
			return ((Object)value).name;
		}
	}

	public class DecorationTierData : JSONSerializer<string, DecorationTier>, JSONSerializer<DecorationTier, string>
	{
		public DecorationTier Convert(string name)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (Enum.TryParse<DecorationTierTypes>(name, out DecorationTierTypes result) && (int)result > 0)
			{
				return DecorationTierTypesExtensions.ToDecorationTier(result);
			}
			DecorationTier val = ((IEnumerable<DecorationTier>)SO.Settings.decorationsTiers).FirstOrDefault((Func<DecorationTier, bool>)((DecorationTier a) => ((Object)a).name == name));
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)("Decoration tier not found: " + name));
			}
			return val;
		}

		public string Convert(DecorationTier value)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			DecorationTierTypes val = DecorationTierTypesExtensions.ToDecorationTierTypes(((Object)value).name);
			return ((object)(DecorationTierTypes)(ref val)).ToString();
		}
	}

	public class WorkshopRecipeModelData : JSONSerializer<string, WorkshopRecipeModel>, JSONSerializer<WorkshopRecipeModel, string>
	{
		public WorkshopRecipeModel Convert(string name)
		{
			return WorkshopsRecipeTypesExtensions.ToWorkshopRecipeModel(name);
		}

		public string Convert(WorkshopRecipeModel value)
		{
			return ((Object)value).name;
		}
	}

	public class InstitutionRecipeModelData : JSONSerializer<string, InstitutionRecipeModel>, JSONSerializer<InstitutionRecipeModel, string>
	{
		public InstitutionRecipeModel Convert(string name)
		{
			return InstitutionRecipeTypesExtensions.ToInstitutionRecipeModel(name);
		}

		public string Convert(InstitutionRecipeModel value)
		{
			return ((Object)value).name;
		}
	}

	public class InstitutionActiveEffectData : JSONSerializer<InstitutionEffectModel, InstitutionActiveEffectData>, JSONSerializer<InstitutionActiveEffectData, InstitutionEffectModel>
	{
		public int MinWorkers;

		public string Effect;

		public InstitutionActiveEffectData Convert(InstitutionEffectModel model)
		{
			InstitutionActiveEffectData institutionActiveEffectData = new InstitutionActiveEffectData();
			institutionActiveEffectData.MinWorkers = model.minWorkers;
			institutionActiveEffectData.Effect = ((Object)model.effect).name;
			return institutionActiveEffectData;
		}

		public InstitutionEffectModel Convert(InstitutionActiveEffectData value)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			InstitutionEffectModel val = new InstitutionEffectModel();
			val.minWorkers = value.MinWorkers;
			val.effect = EffectTypesExtensions.ToEffectModel(value.Effect);
			return val;
		}
	}

	public class BuildingCategoryModelData : JSONSerializer<string, BuildingCategoryModel>, JSONSerializer<BuildingCategoryModel, string>
	{
		public string Convert(BuildingCategoryModel model)
		{
			return ((Object)model).name;
		}

		public BuildingCategoryModel Convert(string value)
		{
			return BuildingCategoriesTypesExtensions.ToBuildingCategoryModel(value);
		}
	}

	public class BuildingTagModelData : JSONSerializer<string, BuildingTagModel>, JSONSerializer<BuildingTagModel, string>
	{
		public string Convert(BuildingTagModel model)
		{
			return ((Object)model).name;
		}

		public BuildingTagModel Convert(string value)
		{
			return BuildingTagTypesExtensions.ToBuildingTagModel(value);
		}
	}

	public class ProfessionModelData : JSONSerializer<string, ProfessionModel>, JSONSerializer<ProfessionModel, string>
	{
		public string Convert(ProfessionModel model)
		{
			return ((Object)model).name;
		}

		public ProfessionModel Convert(string value)
		{
			return ProfessionTypesExtensions.ToProfessionModel(value);
		}
	}

	public class RaceModelData : JSONSerializer<string, RaceModel>, JSONSerializer<RaceModel, string>
	{
		public string Convert(RaceModel model)
		{
			return ((Object)model).name;
		}

		public RaceModel Convert(string value)
		{
			return RaceTypesExtensions.ToRaceModel(value);
		}
	}

	[SchemaHelpURL("https://github.com/JamesVeug/AgainstTheStormAPI/blob/master/ATS_API/Scripts/Helpers/Enums/BuildingTagTypes.cs", "https://hoodedhorse.com/wiki/Against_the_Storm/Trading")]
	public class SchemaBuildingTagTypesAttribute : SchemaEnumAttribute<BuildingTagTypes>
	{
		public SchemaBuildingTagTypesAttribute(BuildingTagTypes defaultValue, string description)
			: base(defaultValue, description)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)

	}

	public class GoodSetData : IInitializable, JSONSerializer<GoodSetData, GoodsSet>, JSONSerializer<GoodsSet, GoodSetData>
	{
		[SchemaField(null, "Rewards the player can choose when starting a new settlement. If not included then will not affect existing meta rewards.")]
		public RequiredGood[] goods;

		public GoodsSet Convert(GoodSetData from)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GoodsSet val = new GoodsSet();
			val.goods = ((IEnumerable<RequiredGood>)from.goods).Select((Func<RequiredGood, GoodRef>)((RequiredGood g) => new GoodRef
			{
				good = ((g != null) ? GoodsTypesExtensions.ToGoodModel(g.good) : null),
				amount = g.amount
			})).ToArray();
			return val;
		}

		public GoodSetData Convert(GoodsSet from)
		{
			GoodSetData goodSetData = new GoodSetData();
			goodSetData.goods = from.goods.Select(delegate(GoodRef g)
			{
				RequiredGood requiredGood = new RequiredGood();
				GoodModel good = g.good;
				requiredGood.good = ((good != null) ? ((SO)good).Name : null);
				requiredGood.amount = g.amount;
				return requiredGood;
			}).ToArray();
			return goodSetData;
		}

		public void Initialize()
		{
		}
	}

	public class GoodRefChanceData : IInitializable, JSONSerializer<GoodRefChance, GoodRefChanceData>, JSONSerializer<GoodRefChanceData, GoodRefChance>
	{
		[SchemaEnum<GoodsTypes>(/*Could not decode attribute arguments.*/)]
		public string good;

		[SchemaField(0, "The amount of the good produced")]
		public int? amount;

		[SchemaField(0, "The chance of the good being produced. 0 never, 0.5 is 50% of the time, 1 is always")]
		public float? chance;

		public GoodRefChance Convert(GoodRefChanceData from)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GoodRefChance val = new GoodRefChance();
			object obj;
			if (from == null)
			{
				obj = null;
			}
			else
			{
				string text = from.good;
				obj = ((text != null) ? GoodsTypesExtensions.ToGoodModel(text) : null);
			}
			val.good = (GoodModel)obj;
			val.amount = (from?.amount).GetValueOrDefault();
			val.chance = (from?.chance).GetValueOrDefault();
			return val;
		}

		public GoodRefChanceData Convert(GoodRefChance from)
		{
			GoodRefChanceData goodRefChanceData = new GoodRefChanceData();
			object obj;
			if (from == null)
			{
				obj = null;
			}
			else
			{
				GoodModel obj2 = from.good;
				obj = ((obj2 != null) ? ((SO)obj2).Name : null);
			}
			goodRefChanceData.good = (string)obj;
			goodRefChanceData.amount = from?.amount;
			goodRefChanceData.chance = from?.chance;
			return goodRefChanceData;
		}

		public void Initialize()
		{
		}
	}

	public class RequiredGood : IInitializable
	{
		[SchemaEnum<GoodsTypes>(/*Could not decode attribute arguments.*/)]
		public string good;

		[SchemaField(0, "The amount of the good required")]
		public int amount;

		public void Initialize()
		{
		}
	}

	public class WaterData : JSONSerializer<string, WaterModel>, JSONSerializer<WaterModel, string>
	{
		public WaterModel Convert(string from)
		{
			return WaterTypesExtensions.ToWaterModel(from);
		}

		public string Convert(WaterModel from)
		{
			return ((Object)from).name;
		}
	}
}
public static class ImportExportUtils
{
	private static string ID;

	private static string DebugPath;

	private static string LoggingSuffix;

	private static readonly Type[] AllSerializers = (from a in Assembly.GetAssembly(typeof(Plugin)).GetTypes()
		where a.GetInterfaces().Any((Type i) => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(JSONSerializer<, >))
		select a).ToArray();

	public static void SetID(string id)
	{
		ID = id;
	}

	public static void SetDebugPath(string path)
	{
		if (string.IsNullOrEmpty(path))
		{
			DebugPath = "";
		}
		else
		{
			DebugPath = path.Substring(Plugin.BepInExDirectory.Length);
		}
		LoggingSuffix = "";
	}

	public static T ParseEnum<T>(string value) where T : unmanaged, Enum
	{
		if (Enum.TryParse<T>(value, out var result))
		{
			return result;
		}
		int num = Math.Max(value.LastIndexOf('_'), value.LastIndexOf('.'));
		if (num < 0)
		{
			throw new InvalidCastException("Cannot parse " + value + " as " + typeof(T).FullName);
		}
		string text = value.Substring(0, num);
		string text2 = value.Substring(num + 1);
		return GUIDManager.Get<T>(text, text2);
	}

	public static void ApplyMethod<T, Y>(Func<T> getter, Action<T> setter, ref Y serializeInfoValue, bool toModel, string category, string suffix)
	{
		if (toModel)
		{
			T a = default(T);
			ApplyValue(ref a, ref serializeInfoValue, toA: true, category, suffix);
			setter(a);
		}
		else
		{
			T a2 = getter();
			ApplyValue(ref a2, ref serializeInfoValue, toA: false, category, suffix);
		}
	}

	public static void ApplyProperty<T, Y>(Func<T> modelGetter, Action<T> modelSetter, ref Y serializeInfoValue, bool toModel, string category, string suffix)
	{
		if (toModel)
		{
			T a = default(T);
			ApplyValue(ref a, ref serializeInfoValue, toA: true, category, suffix);
			modelSetter(a);
		}
		else
		{
			T a2 = modelGetter();
			ApplyValue(ref a2, ref serializeInfoValue, toA: false, category, suffix);
		}
	}

	public static void ApplyProperty<T, Y>(ref T aSerializeInfoValue, Func<Y> bGetter, Action<Y> bSetter, bool toModel, string category, string suffix)
	{
		if (toModel)
		{
			Y b = bGetter();
			ApplyValue(ref aSerializeInfoValue, ref b, toA: true, category, suffix);
		}
		else
		{
			Y b2 = default(Y);
			ApplyValue(ref aSerializeInfoValue, ref b2, toA: false, category, suffix);
			bSetter(b2);
		}
	}

	public static void ApplyValue<T, Y>(ref T a, ref Y b, bool toA, string category, string suffix)
	{
		if (toA)
		{
			ConvertValue(ref b, ref a, category, suffix);
		}
		else
		{
			ConvertValue(ref a, ref b, category, suffix);
		}
	}

	public static void ApplyVector2<T>(ref Vector2 a, ref T bX, ref T bY, bool toA, string category, string suffix)
	{
		if (toA)
		{
			ConvertValue(ref bX, ref a.x, category, suffix);
			ConvertValue(ref bY, ref a.y, category, suffix);
		}
		else
		{
			ConvertValue(ref a.x, ref bX, category, suffix);
			ConvertValue(ref a.y, ref bY, category, suffix);
		}
	}

	public static void ApplyVector2Int(ref Vector2Int a, ref int bX, ref int bY, bool toA, string category, string suffix)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		if (toA)
		{
			int to = ((Vector2Int)(ref a)).x;
			int to2 = ((Vector2Int)(ref a)).y;
			ConvertValue(ref bX, ref to, category, suffix);
			ConvertValue(ref bY, ref to2, category, suffix);
			a = new Vector2Int(to, to2);
		}
		else
		{
			int from = ((Vector2Int)(ref a)).x;
			int from2 = ((Vector2Int)(ref a)).x;
			ConvertValue(ref from, ref bX, category, suffix);
			ConvertValue(ref from2, ref bY, category, suffix);
			bX = from;
			bY = from2;
		}
	}

	public static void ApplyValueNoNull<T, Y>(ref T a, ref Y b, bool toA, string category, string suffix)
	{
		if (toA)
		{
			if ((object)b != GetDefault(typeof(Y)))
			{
				ConvertValue(ref b, ref a, category, suffix);
				return;
			}
			VerboseLog("Skipping " + category + "." + suffix + " as it is null");
		}
		else if ((object)a != GetDefault(typeof(T)))
		{
			ConvertValue(ref a, ref b, category, suffix);
		}
		else
		{
			VerboseLog("Skipping " + category + "." + suffix + " as it is null");
		}
	}

	private static void ConvertValue<FromType, ToType>(ref FromType from, ref ToType to, string category, string suffix)
	{
		//IL_07be: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c5: Expected O, but got Unknown
		//IL_08d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_08dd: Expected O, but got Unknown
		//IL_09f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_09f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b52: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b57: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b67: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b7c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b91: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ba6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b02: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c40: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cb1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cb9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d1c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d23: Expected O, but got Unknown
		//IL_0d71: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d78: Expected O, but got Unknown
		//IL_0f99: Unknown result type (might be due to invalid IL or missing references)
		//IL_0fa0: Expected O, but got Unknown
		//IL_1113: Unknown result type (might be due to invalid IL or missing references)
		//IL_111a: Expected O, but got Unknown
		//IL_1276: Unknown result type (might be due to invalid IL or missing references)
		//IL_127d: Expected O, but got Unknown
		//IL_13eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_13f2: Expected O, but got Unknown
		//IL_150d: Unknown result type (might be due to invalid IL or missing references)
		//IL_1514: Expected O, but got Unknown
		//IL_1608: Unknown result type (might be due to invalid IL or missing references)
		//IL_160f: Expected O, but got Unknown
		LoggingSuffix = suffix;
		Type typeFromHandle = typeof(FromType);
		Type typeFromHandle2 = typeof(ToType);
		try
		{
			if (typeFromHandle == typeFromHandle2)
			{
				to = (ToType)(object)from;
				return;
			}
			if (AreNullableTypesEqual(from, to, out var a2, out var _, out var aHasValue, out var _))
			{
				if (aHasValue)
				{
					to = (ToType)a2;
				}
				return;
			}
			if (typeFromHandle.IsGenericType && typeFromHandle.GetGenericTypeDefinition() == typeof(List<>) && typeFromHandle2.IsGenericType && typeFromHandle2.GetGenericTypeDefinition() == typeof(List<>))
			{
				if (from != null)
				{
					IList list = (IList)Activator.CreateInstance(typeFromHandle2);
					to = (ToType)list;
					IList list2 = (IList)(object)from;
					for (int i = 0; i < list2.Count; i++)
					{
						object o = list2[i];
						object @default = GetDefault(typeFromHandle2.GetGenericArguments().Single());
						object value = ConvertType(typeFromHandle, typeFromHandle2, o, @default, category, $"{suffix}_{i + 1}");
						list.Add(value);
					}
				}
				return;
			}
			if (typeFromHandle.IsGenericType && typeFromHandle.GetGenericTypeDefinition() == typeof(List<>) && typeFromHandle2.IsArray)
			{
				if (from != null)
				{
					IList list3 = (IList)(object)from;
					int length = ((from != null) ? list3.Count : 0);
					Array array = Array.CreateInstance(typeFromHandle2.GetElementType(), length);
					to = (ToType)(object)array;
					for (int j = 0; j < list3.Count; j++)
					{
						object obj = list3[j];
						object default2 = GetDefault(typeFromHandle2.GetElementType());
						object[] array2 = new object[4]
						{
							obj,
							default2,
							category,
							$"{suffix}_{j + 1}"
						};
						MethodInfo methodInfo = typeof(ImportExportUtils).GetMethod("ConvertValue", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(typeFromHandle.GetGenericArguments().Single(), typeFromHandle2.GetElementType());
						methodInfo.Invoke(null, array2);
						array.SetValue(array2[1], j);
					}
				}
				return;
			}
			if (typeFromHandle.IsArray && typeFromHandle2.IsGenericType && typeFromHandle2.GetGenericTypeDefinition() == typeof(List<>))
			{
				if (from != null)
				{
					IList list4 = (IList)Activator.CreateInstance(typeFromHandle2);
					to = (ToType)list4;
					Array array3 = (Array)(object)from;
					for (int k = 0; k < array3.Length; k++)
					{
						object value2 = array3.GetValue(k);
						object default3 = GetDefault(typeFromHandle2.GetGenericArguments().Single());
						object[] array4 = new object[4]
						{
							value2,
							default3,
							category,
							$"{suffix}_{k + 1}"
						};
						MethodInfo methodInfo2 = typeof(ImportExportUtils).GetMethod("ConvertValue", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(typeFromHandle.GetElementType(), typeFromHandle2.GetGenericArguments().Single());
						methodInfo2.Invoke(null, array4);
						list4.Add(array4[1]);
					}
				}
				return;
			}
			if (typeFromHandle.IsArray && typeFromHandle2.IsArray)
			{
				if (from != null)
				{
					Array array5 = (Array)(object)from;
					int length2 = ((from != null) ? array5.Length : 0);
					Array array6 = Array.CreateInstance(typeFromHandle2.GetElementType(), length2);
					to = (ToType)(object)array6;
					for (int l = 0; l < array5.Length; l++)
					{
						object value3 = array5.GetValue(l);
						object default4 = GetDefault(typeFromHandle2.GetElementType());
						object[] array7 = new object[4]
						{
							value3,
							default4,
							category,
							$"{suffix}_{l + 1}"
						};
						MethodInfo methodInfo3 = typeof(ImportExportUtils).GetMethod("ConvertValue", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(typeFromHandle.GetElementType(), typeFromHandle2.GetElementType());
						methodInfo3.Invoke(null, array7);
						array6.SetValue(array7[1], l);
					}
				}
				return;
			}
			if (TryGetJSONSerializer(typeFromHandle2, typeFromHandle, out var serializer))
			{
				Type reflectedType = serializer.ReflectedType;
				object obj2 = Activator.CreateInstance(reflectedType);
				to = (ToType)serializer.Invoke(obj2, new object[1] { from });
				return;
			}
			if (typeFromHandle.IsEnum && typeFromHandle2 == typeof(string))
			{
				string text = from.ToString();
				if (int.TryParse(text, out var result))
				{
					if (Enum.GetValues(typeFromHandle).Cast<int>().Contains(result))
					{
						to = (ToType)(object)text;
						return;
					}
					Error($"Failed to convert enum to string! '{from}' int '{result}'");
					to = (ToType)(object)text;
				}
				else
				{
					to = (ToType)(object)text;
				}
				return;
			}
			if (typeFromHandle == typeof(string) && typeFromHandle2.IsEnum)
			{
				if (!string.IsNullOrEmpty((string)(object)from))
				{
					object obj3 = typeof(ImportExportUtils).GetMethod("ParseEnum", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(typeFromHandle2).Invoke(null, new object[1] { from });
					to = (ToType)obj3;
				}
				return;
			}
			if (typeFromHandle == typeof(string) && (typeFromHandle2 == typeof(Texture) || typeFromHandle2.IsSubclassOf(typeof(Texture))))
			{
				string text2 = (string)(object)from;
				if (!string.IsNullOrEmpty(text2))
				{
					try
					{
						to = (ToType)(object)GetTextureFromString(text2);
						return;
					}
					catch (FileNotFoundException)
					{
						Error("Failed to find texture " + text2 + "!");
						return;
					}
				}
				return;
			}
			if ((typeFromHandle == typeof(Texture) || typeFromHandle.IsSubclassOf(typeof(Texture))) && typeFromHandle2 == typeof(string))
			{
				Texture val = (Texture)(object)from;
				if ((Object)(object)val != (Object)null)
				{
					string path4 = Path.Combine(Plugin.ExportDirectory, category, "Assets", ID + "_" + suffix + ".png");
					to = (ToType)(object)ExportTexture(val, path4);
				}
				return;
			}
			if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(Sprite))
			{
				string text3 = (string)(object)from;
				if (!string.IsNullOrEmpty(text3))
				{
					Texture2D textureFromString = GetTextureFromString(text3);
					if ((Object)(object)textureFromString != (Object)null)
					{
						to = (ToType)(object)TextureHelper.ConvertTexture(textureFromString, (Vector2?)null);
					}
				}
				return;
			}
			if (typeFromHandle == typeof(Sprite) && typeFromHandle2 == typeof(string))
			{
				Sprite val2 = (Sprite)(object)from;
				if ((Object)(object)val2 != (Object)null)
				{
					string path5 = Path.Combine(Plugin.ExportDirectory, category, "Assets", ID + "_" + suffix + ".png");
					to = (ToType)(object)ExportSprite(val2, path5);
				}
				return;
			}
			if (ArrayExtension.Contains<Type>(typeFromHandle.GetInterfaces(), typeof(IConvertible)) && ArrayExtension.Contains<Type>(typeFromHandle2.GetInterfaces(), typeof(IConvertible)))
			{
				IConvertible convertible = from as IConvertible;
				IConvertible convertible2 = to as IConvertible;
				if (convertible != null && convertible2 != null)
				{
					to = (ToType)Convert.ChangeType(convertible, typeFromHandle2);
				}
				return;
			}
			if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(Color))
			{
				string text4 = (string)(object)from;
				Color white = Color.white;
				if (text4.StartsWith("#"))
				{
					if (!ColorUtility.TryParseHtmlString(text4, ref white))
					{
						Error("Could not convert " + text4 + " to color!");
					}
				}
				else
				{
					int[] array8 = (from a in text4.Split(new char[1] { ',' })
						select int.Parse(a.Trim())).ToArray();
					if (array8.Length != 0)
					{
						white.r = (float)array8[0] / 255f;
					}
					if (array8.Length > 1)
					{
						white.g = (float)array8[1] / 255f;
					}
					if (array8.Length > 2)
					{
						white.b = (float)array8[2] / 255f;
					}
					if (array8.Length > 3)
					{
						white.a = (float)array8[3] / 255f;
					}
				}
				to = (ToType)(object)white;
				return;
			}
			if (typeFromHandle == typeof(Color) && typeFromHandle2 == typeof(string))
			{
				Color val3 = (Color)(object)from;
				to = (ToType)(object)$"{val3.r * 255f:F0},{val3.g * 255f:F0},{val3.b * 255f:F0},{val3.a * 255f:F0}";
				return;
			}
			if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(Vector2))
			{
				string text5 = (string)(object)from;
				string[] array9 = text5.Split(new char[1] { ',' });
				if (array9.Length == 2)
				{
					to = (ToType)(object)new Vector2(float.Parse(array9[0]), float.Parse(array9[1]));
				}
				else
				{
					Error("Could not convert " + text5 + " to Vector2!");
				}
				return;
			}
			if (typeFromHandle == typeof(Vector2) && typeFromHandle2 == typeof(string))
			{
				Vector2 val4 = (Vector2)(object)from;
				to = (ToType)(object)$"{val4.x},{val4.y}";
				return;
			}
			if (typeFromHandle.IsSubclassOf(typeof(ScriptableObject)) && typeFromHandle2 == typeof(string))
			{
				ScriptableObject val5 = (ScriptableObject)(object)from;
				to = (ToType)(object)((Object)val5).name;
				return;
			}
			if (typeFromHandle == typeof(AudioClip) && typeFromHandle2 == typeof(string))
			{
				AudioClip val6 = (AudioClip)(object)from;
				if ((Object)(object)val6 != (Object)null)
				{
					string text6 = Path.Combine(Plugin.ExportDirectory, category, "Audio", ID + "_" + suffix + ".wav");
					to = (ToType)(object)AudioHelpers.ExportAudioClip(val6, text6);
				}
				to = (ToType)(object)((Object)val6).name;
				return;
			}
			if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(AudioClip))
			{
				string text7 = (string)(object)from;
				AudioClip val7 = AudioHelpers.LoadAudioClip(text7);
				to = (ToType)(object)val7;
				return;
			}
			if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(NeedModel))
			{
				string text8 = (string)(object)from;
				NeedModel val8 = NeedTypesExtensions.ToNeedModel(text8);
				to = (ToType)(object)val8;
				return;
			}
			if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(ModelTag))
			{
				string text9 = (string)(object)from;
				ModelTag val9 = TagTypesExtensions.ToModelTag(text9);
				to = (ToType)(object)val9;
				return;
			}
			if (typeFromHandle == typeof(LocalizableField) && typeFromHandle2 == typeof(string))
			{
				Error("Use ApplyLocaleField when converted from LocalizableField to string!");
			}
			else if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(LocalizableField))
			{
				Error("Use ApplyLocaleField when converted from string to LocalizableField!");
			}
			else
			{
				if (typeFromHandle == typeof(RacialSound) && typeFromHandle2 == typeof(RacialSounds))
				{
					RacialSound val10 = (RacialSound)(object)from;
					RacialSounds racialSounds = new RacialSounds();
					ApplyValue(ref val10.positiveSound, ref racialSounds.PositiveSounds, toA: false, category, suffix + "_PositiveSounds");
					ApplyValue(ref val10.neutralSound, ref racialSounds.NeutralSounds, toA: false, category, suffix + "_NeutralSounds");
					ApplyValue(ref val10.negativeSound, ref racialSounds.NegativeSounds, toA: false, category, suffix + "_NegativeSounds");
					to = (ToType)(object)racialSounds;
					return;
				}
				if (typeFromHandle == typeof(RacialSounds) && typeFromHandle2 == typeof(RacialSound))
				{
					RacialSounds racialSounds2 = (RacialSounds)(object)from;
					RacialSound val11 = ScriptableObject.CreateInstance<RacialSound>();
					ApplyValue(ref racialSounds2.PositiveSounds, ref val11.positiveSound, toA: false, category, suffix + "_PositiveSounds");
					ApplyValue(ref racialSounds2.NeutralSounds, ref val11.neutralSound, toA: false, category, suffix + "_NeutralSounds");
					ApplyValue(ref racialSounds2.NegativeSounds, ref val11.negativeSound, toA: false, category, suffix + "_NegativeSounds");
					to = (ToType)(object)val11;
					return;
				}
				if (typeFromHandle == typeof(SoundRef) && typeFromHandle2 == typeof(SoundCollection))
				{
					SoundRef val12 = (SoundRef)(object)from;
					SoundCollection soundCollection = new SoundCollection();
					soundCollection.Initialize();
					if ((Object)(object)val12 != (Object)null && val12.sounds != null)
					{
						SoundModel[] sounds = val12.sounds;
						foreach (SoundModel val13 in sounds)
						{
							if (val13 != null && !((Object)(object)val13.audioClip == (Object)null))
							{
								Sound sound = new Sound();
								ApplyValue(ref sound.soundPath, ref val13.audioClip, toA: true, category, suffix + "_audioClip");
								ApplyValue(ref sound.volume, ref val13.volume, toA: true, category, suffix + "_volume");
								soundCollection.sounds.Add(sound);
							}
						}
					}
					to = (ToType)(object)soundCollection;
					return;
				}
				if (typeFromHandle == typeof(SoundCollection) && typeFromHandle2 == typeof(SoundRef))
				{
					SoundCollection soundCollection2 = (SoundCollection)(object)from;
					SoundRef val14 = ScriptableObject.CreateInstance<SoundRef>();
					if ((Object)(object)val14 != (Object)null)
					{
						val14.sounds = (SoundModel[])(object)new SoundModel[soundCollection2.sounds.Count];
						for (int n = 0; n < soundCollection2.sounds.Count; n++)
						{
							SoundModel val15 = new SoundModel();
							Sound sound2 = soundCollection2.sounds[n];
							ApplyValue(ref sound2.soundPath, ref val15.audioClip, toA: false, suffix, suffix + "_audioClip");
							ApplyValue(ref sound2.volume, ref val15.volume, toA: false, suffix, suffix + "_volume");
							val14.sounds[n] = val15;
						}
					}
					to = (ToType)(object)val14;
					return;
				}
				if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(AscensionModifierModel))
				{
					string path3 = (string)(object)from;
					AscensionModifierModel val16 = ((IEnumerable<AscensionModifierModel>)SO.Settings.ascensionModifiers).FirstOrDefault((Func<AscensionModifierModel, bool>)((AscensionModifierModel a) => ((Object)a).name == path3));
					if ((Object)(object)val16 == (Object)null)
					{
						Error("Could not find AscensionModifierModel with name '" + path3 + "'!");
					}
					to = (ToType)(object)val16;
					return;
				}
				if (typeFromHandle == typeof(AscensionModifierModel) && typeFromHandle2 == typeof(string))
				{
					AscensionModifierModel val17 = (AscensionModifierModel)(object)from;
					to = (ToType)(object)((Object)val17).name;
					return;
				}
				if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(RecipeGradeModel))
				{
					string path2 = (string)(object)from;
					RecipeGradeModel val18 = SO.Settings.recipes.Select((RecipeModel a) => a.grade).FirstOrDefault((Func<RecipeGradeModel, bool>)((RecipeGradeModel a) => ((Object)a).name == path2));
					if ((Object)(object)val18 == (Object)null)
					{
						Error("Could not find RecipeGradeModel with name '" + path2 + "'!");
					}
					to = (ToType)(object)val18;
					return;
				}
				if (typeFromHandle == typeof(RecipeGradeModel) && typeFromHandle2 == typeof(string))
				{
					RecipeGradeModel val19 = (RecipeGradeModel)(object)from;
					to = (ToType)(object)((Object)val19).name;
					return;
				}
				if (typeFromHandle == typeof(string) && typeFromHandle2 == typeof(GoodModel))
				{
					string path = (string)(object)from;
					GoodModel val20 = ((IEnumerable<GoodModel>)SO.Settings.Goods).FirstOrDefault((Func<GoodModel, bool>)((GoodModel a) => ((Object)a).name == path));
					if ((Object)(object)val20 == (Object)null)
					{
						Error("Could not find GoodModel with name '" + path + "'!");
					}
					to = (ToType)(object)val20;
					return;
				}
				if (typeFromHandle == typeof(GoodModel) && typeFromHandle2 == typeof(string))
				{
					GoodModel val21 = (GoodModel)(object)from;
					to = (ToType)(object)((Object)val21).name;
					return;
				}
			}
		}
		catch (Exception e)
		{
			Error($"Failed to convert: {typeFromHandle} to {typeFromHandle2}");
			Exception(e);
			return;
		}
		Error($"Unsupported conversion type: {typeFromHandle} to {typeFromHandle2}\n{Environment.StackTrace}");
	}

	private static bool TryGetJSONSerializer(Type toType, Type fromType, out MethodInfo serializer)
	{
		Type[] allSerializers = AllSerializers;
		foreach (Type type in allSerializers)
		{
			Type[] interfaces = type.GetInterfaces();
			foreach (Type type2 in interfaces)
			{
				if (type2.IsGenericType && !(type2.GetGenericTypeDefinition() != typeof(JSONSerializer<, >)) && !(type2.GetGenericArguments()[0] != fromType) && !(type2.GetGenericArguments()[1] != toType))
				{
					serializer = (from a in type.GetMethods(BindingFlags.Instance | BindingFlags.Public)
						where a.Name == "Convert"
						select a).FirstOrDefault((MethodInfo a) => a.GetParameters().Length == 1 && a.GetParameters()[0].ParameterType == fromType && a.ReturnType == toType);
					return true;
				}
			}
		}
		serializer = null;
		return false;
	}

	private static Texture2D GetTextureFromString(string path)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		if (path.StartsWith("base64:"))
		{
			try
			{
				string s = path.Substring("base64:".Length);
				byte[] array = Convert.FromBase64String(s);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false, true);
				((Texture)val).filterMode = (FilterMode)0;
				ImageConversion.LoadImage(val, array);
				return val;
			}
			catch (Exception ex)
			{
				Error("Failed to convert base64 to texture: " + path);
				throw ex;
			}
		}
		return TextureHelper.GetImageAsTexture(path, (FilterMode)0);
	}

	public static string[] FindSimilarStrings(string misspelledCardName, IEnumerable<string> collection)
	{
		return FindSimilar(misspelledCardName, collection, (string a) => a);
	}

	public static T[] FindSimilar<T>(string misspelledCardName, IEnumerable<T> allElements, Func<T, string> getter)
	{
		List<Tuple<int, T>> list = new List<Tuple<int, T>>();
		string text = misspelledCardName.ToLower().Replace("-", "").Replace("_", "");
		int num = Mathf.Clamp(text.Length - 1, 1, 4);
		foreach (T allElement in allElements)
		{
			string text2 = getter(allElement).ToLower().Replace("-", "").Replace("_", "");
			if (Mathf.Abs(text.Length - text2.Length) > num)
			{
				continue;
			}
			int num2 = 0;
			int num3 = Mathf.Max(0, text.Length - text2.Length);
			int num4 = text2.Length - 1;
			int num5 = text.Length - 1;
			while (num5 >= 0 && num4 >= 0)
			{
				if (text2[num4] == text[num5])
				{
					num2++;
				}
				else
				{
					num3++;
					if (num3 > num)
					{
						break;
					}
					if (num4 > 0 && text2[num4 - 1] == text[num5])
					{
						num4--;
						num2++;
					}
					else if (num5 > 0 && text2[num4] == text[num5 - 1])
					{
						num5--;
						num2++;
					}
				}
				num5--;
				num4--;
			}
			if (num2 > 0 && num3 < num)
			{
				list.Add(new Tuple<int, T>(num2, allElement));
			}
		}
		list.Sort((Tuple<int, T> a, Tuple<int, T> b) => b.Item1 - a.Item1);
		return list.Select((Tuple<int, T> a) => a.Item2).ToArray();
	}

	private static object ConvertType(Type fromType, Type toType, object o1, object o2, string category, string suffix)
	{
		object[] array = new object[4] { o1, o2, category, suffix };
		MethodInfo methodInfo = typeof(ImportExportUtils).GetMethod("ConvertValue", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(fromType.GetGenericArguments().Single(), toType.GetGenericArguments().Single());
		methodInfo.Invoke(null, array);
		return array[1];
	}

	private static bool AreNullableTypesEqual<T, Y>(T t, Y y, out object a, out object b, out bool aHasValue, out bool bHasValue)
	{
		aHasValue = false;
		bHasValue = false;
		a = null;
		b = null;
		bool flag = typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Nullable<>);
		bool flag2 = typeof(Y).IsGenericType && typeof(Y).GetGenericTypeDefinition() == typeof(Nullable<>);
		if (!flag && !flag2)
		{
			return false;
		}
		Type type = (flag ? Nullable.GetUnderlyingType(typeof(T)) : typeof(T));
		Type type2 = (flag2 ? Nullable.GetUnderlyingType(typeof(Y)) : typeof(Y));
		if (type == type2)
		{
			if (flag)
			{
				a = GetValueFromNullable(t, out aHasValue);
			}
			else
			{
				a = t;
				aHasValue = true;
			}
			if (flag2)
			{
				b = GetValueFromNullable(y, out bHasValue);
			}
			else
			{
				b = y;
				bHasValue = true;
			}
			return true;
		}
		Error($"Not same types {typeof(T)} {typeof(Y)}");
		return false;
	}

	private static string ExportTexture(Texture texture, string path)
	{
		Texture2D val = (Texture2D)(object)((texture is Texture2D) ? texture : null);
		if (val != null)
		{
			return ExportTexture(val, path);
		}
		Texture2D texture2 = Texture2D.CreateExternalTexture(texture.width, texture.height, (TextureFormat)4, false, false, texture.GetNativeTexturePtr());
		return ExportTexture(texture2, path);
	}

	private static string ExportSprite(Sprite sprite, string path)
	{
		//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_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		Texture2D val = sprite.texture;
		if (!((Texture)val).isReadable)
		{
			val = GetReadableTexture2D(val);
		}
		Rect textureRect = sprite.textureRect;
		Texture2D val2 = new Texture2D((int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height, (TextureFormat)4, false, false);
		Color[] pixels = val.GetPixels((int)((Rect)(ref textureRect)).xMin, (int)((Rect)(ref textureRect)).yMin, (int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height);
		val2.SetPixels(pixels);
		val2.Apply();
		return ExportTexture(val2, path);
	}

	private static string ExportTexture(Texture2D texture, string path)
	{
		if (!((Texture)texture).isReadable)
		{
			texture = GetReadableTexture2D(texture);
		}
		byte[] array = ImageConversion.EncodeToPNG(texture);
		if (array == null)
		{
			Error("Failed to turn into bytes??");
		}
		if (string.IsNullOrEmpty(path))
		{
			Error("path is empty????");
		}
		string directoryName = Path.GetDirectoryName(path);
		if (!Directory.Exists(directoryName))
		{
			Directory.CreateDirectory(directoryName);
		}
		File.WriteAllBytes(path, array);
		return Path.GetFileName(path);
	}

	private static Texture2D GetReadableTexture2D(Texture2D texture)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)2);
		Graphics.Blit((Texture)(object)texture, temporary);
		RenderTexture active = RenderTexture.active;
		RenderTexture.active = temporary;
		Texture2D val = new Texture2D(((Texture)texture).width, ((Texture)texture).height, (TextureFormat)4, false, false);
		val.ReadPixels(new Rect(0f, 0f, (float)((Texture)temporary).width, (float)((Texture)temporary).height), 0, 0);
		val.Apply();
		RenderTexture.active = active;
		RenderTexture.ReleaseTemporary(temporary);
		return val;
	}

	public static string[] ExportTextures(IEnumerable<Texture2D> texture, string type, string fileName)
	{
		int num = 0;
		List<string> list = new List<string>();
		foreach (Texture2D item in texture)
		{
			num++;
			string path = Path.Combine(Plugin.ExportDirectory, type, "Assets", $"{fileName}_{num}.png");
			list.Add(ExportTexture(item, path));
		}
		return list.ToArray();
	}

	public static void ApplyLocaleField(string field, ref LocaText model, ref LocalizableField data, bool toModel)
	{
		if (toModel)
		{
			string modelKey = "";
			ApplyLocaleField(field, data, ref modelKey);
			model = LocalizationManager.ToLocaText(modelKey);
		}
	}

	public static void ApplyLocaText(ref LocaText model, ref LocalizableField data, Action<string, SystemLanguage> setModel, bool toModel, string fieldName)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		if (toModel)
		{
			foreach (KeyValuePair<SystemLanguage, string> translation in data.GetTranslations())
			{
				setModel(translation.Value, translation.Key);
			}
			return;
		}
		data = new LocalizableField(fieldName);
		string currentLocaCode = MB.TextsService.CurrentLocaCode;
		string text = model.GetText();
		string value = text.Replace("\n", "\\n");
		data.SetValueWithLanguageCode(currentLocaCode, value);
	}

	private static void ApplyLocaleField(string field, LocalizableField rows, ref string modelKey)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		modelKey = ID + "_" + field;
		VerboseLog("ApplyLocaleField " + field + " english " + modelKey);
		foreach (KeyValuePair<SystemLanguage, string> row in rows.rows)
		{
			SystemLanguage key = row.Key;
			LocalizationManager.AddString(modelKey, row.Value, key);
			VerboseLog($"Translation {modelKey} to {key} = {row.Value}");
		}
	}

	private static object GetValueFromNullable<U>(U u, out bool hasValue)
	{
		Type typeFromHandle = typeof(U);
		if (u != null && (bool)typeFromHandle.GetProperty("HasValue", BindingFlags.Instance | BindingFlags.Public).GetValue(u))
		{
			hasValue = true;
			return typeFromHandle.GetProperty("Value", BindingFlags.Instance | BindingFlags.Public).GetValue(u);
		}
		hasValue = false;
		Type underlyingType = Nullable.GetUnderlyingType(typeFromHandle);
		if (underlyingType.IsValueType)
		{
			return Activator.CreateInstance(underlyingType);
		}
		return null;
	}

	private static object GetDefault(Type type)
	{
		if (type.IsValueType)
		{
			return Activator.CreateInstance(type);
		}
		return null;
	}

	private static void VerboseLog(string message)
	{
		Logging.VerboseLog("[" + DebugPath + "][" + ID + "][" + LoggingSuffix + "] " + message);
	}

	private static void VerboseWarning(string message)
	{
		if (Configs.VerboseLogging)
		{
			Logging.VerboseWarning("[" + DebugPath + "][" + ID + "][" + LoggingSuffix + "] " + message);
		}
	}

	private static void VerboseError(string message)
	{
		if (Configs.VerboseLogging)
		{
			Logging.VerboseError("[" + DebugPath + "][" + ID + "][" + LoggingSuffix + "] " + message);
		}
	}

	private static void Log(string message)
	{
		Plugin.Log.LogInfo((object)("[" + ID + "][" + LoggingSuffix + "] " + message));
	}

	private static void Warning(string message)
	{
		if (Configs.VerboseLogging)
		{
			VerboseWarning(message);
			return;
		}
		Plugin.Log.LogWarning((object)("[" + ID + "][" + LoggingSuffix + "] " + message));
	}

	private static void Error(string message)
	{
		if (Configs.VerboseLogging)
		{
			VerboseError(message);
			return;
		}
		Plugin.Log.LogError((object)("[" + ID + "][" + LoggingSuffix + "] " + message));
	}

	private static void Exception(Exception e)
	{
		Plugin.Log.LogError((object)("[" + DebugPath + "][" + ID + "][" + LoggingSuffix + "] " + e.Message + "\n" + e.StackTrace));
	}
}
public interface JSONSerializer<FromType, ToType>
{
	ToType Convert(FromType from);
}
public class GenerateSchemaAttribute : Attribute
{
	private readonly string Title;

	private readonly string Description;

	private readonly string FileExtension;

	public GenerateSchemaAttribute(string title, string description, string fileExtension)
	{
		Title = title;
		Description = description;
		FileExtension = fileExtension;
	}

	public string GetTitle()
	{
		return Title;
	}

	public string GetDescription()
	{
		string text = Description;
		if (!string.IsNullOrEmpty(FileExtension))
		{
			text = text + "\n\nFor JSONLoader to load this file into Against the Storm create a file on your computer ending with " + FileExtension + " and paste the contents of the JSON inside. Example: \"MyFile" + FileExtension + "\"";
		}
		return text;
	}

	public string GetFileExtension()
	{
		return FileExtension;
	}
}
[SchemaHelpURL("https://github.com/JamesVeug/AgainstTheStormAPI/blob/master/ATS_API/Scripts/Helpers/Enums/AscensionModifierTypes.cs", "https://hoodedhorse.com/wiki/Against_the_Storm/Difficulty")]
public class SchemaAscensionModifierTypeAttribute : SchemaEnumAttribute<AscensionModifierTypes>
{
	public SchemaAscensionModifierTypeAttribute(string description)
		: base((AscensionModifierTypes)21, description)
	{
	}
}
[SchemaHelpURL("https://github.com/JamesVeug/AgainstTheStormAPI/blob/master/ATS_API/Scripts/Helpers/Enums/BuildingPerkTypes.cs")]
public class SchemaBuildingPerkTypeAttribute : SchemaEnumAttribute<BuildingPerkTypes>
{
	public SchemaBuildingPerkTypeAttribute(string description)
		: base((BuildingPerkTypes)7, description)
	{
	}
}
[SchemaHelpURL("https://github.com/JamesVeug/AgainstTheStormAPI/blob/master/ATS_API/Scripts/Helpers/Enums/BuildingTagTypes.cs")]
public class SchemaBuildingTagTypeAttribute : SchemaEnumAttribute<BuildingTagTypes>
{
	public SchemaBuildingTagTypeAttribute(string description)
		: base((BuildingTagTypes)1, description)
	{
	}
}
public class SchemaDescriptionAttribute : SchemaLocalizedAttribute
{
	public SchemaDescriptionAttribute()
		: base("Long Description describing what it does.")
	{
	}
}
public class SchemaDisplayNameAttribute : SchemaLocalizedAttribute
{
	public SchemaDisplayNameAttribute()
		: base("Name that will appear in the game.")
	{
	}
}
[SchemaHelpURL("https://github.com/JamesVeug/AgainstTheStormAPI/blob/master/ATS_API/Scripts/Helpers/Enums/EffectTypes.cs", "https://hoodedhorse.com/wiki/Against_the_Storm/Perks")]
public class SchemaEffectTypeAttribute : SchemaEnumAttribute<EffectTypes>
{
	public SchemaEffectTypeAttribute(EffectTypes defaultValue, string description)
		: base(defaultValue, description)
	{
	}//IL_0001: Unknown result type (might be due to invalid IL or missing references)

}
public class SchemaEnumAttribute<T> : SchemaFieldAttribute where T : Enum
{
	private static readonly string[] IgnoreEnumNames = new string[3] { "None", "Unknown", "MAX" };

	public SchemaEnumAttribute(T defaultValue, string description)
		: base(defaultValue, required: false, description)
	{
		Enum = (from a in System.Enum.GetNames(typeof(T))
			where !ArrayExtension.Contains<string>(IgnoreEnumNames, a)
			select a).ToArray();
	}

	public SchemaEnumAttribute(T defaultValue, bool required, string description)
		: base(defaultValue, required, description)
	{
		Enum = (from a in System.Enum.GetNames(typeof(T))
			where !ArrayExtension.Contains<string>(IgnoreEnumNames, a)
			select a).ToArray();
	}
}
public class SchemaFieldAttribute : Attribute
{
	protected object DefaultValue;

	protected bool Required;

	protected string Description;

	protected string Pattern;

	protected int MinLength;

	protected string[] Enum = Array.Empty<string>();

	public SchemaFieldAttribute(object defaultValue, bool required, string description)
	{
		DefaultValue = defaultValue;
		Required = required;
		Description = description;
	}

	public SchemaFieldAttribute(object defaultValue, string description)
	{
		DefaultValue = defaultValue;
		Required = false;
		Description = description;
	}

	public SchemaFieldAttribute(object defaultValue)
	{
		DefaultValue = defaultValue;
		Required = false;
		Description = "";
	}

	public virtual object GetDefaultValue()
	{
		return DefaultValue;
	}

	public virtual bool IsRequired()
	{
		return Required;
	}

	public virtual string GetDescription()
	{
		return Description;
	}

	public virtual string GetPattern()
	{
		return Pattern;
	}

	public virtual int GetMinLength()
	{
		return MinLength;
	}

	public virtual string[] GetEnum()
	{
		return Enum;
	}
}
[SchemaHelpURL("https://github.com/JamesVeug/AgainstTheStormAPI/blob/master/ATS_API/Scripts/Helpers/Enums/GoodsTypes.cs", "https://hoodedhorse.com/wiki/Against_the_Storm/Resources")]
public class SchemaGoodTypeAttribute : SchemaEnumAttribute<GoodsTypes>
{
	public SchemaGoodTypeAttribute(string description)
		: base((GoodsTypes)64, description)
	{
	}
}
public class SchemaGuidAttribute : SchemaFieldAttribute
{
	public SchemaGuidAttribute()
		: base(null, required: true, "Unique identifier for the mod that added this. Blank if it's added as part of the base game.")
	{
		Pattern = "^[a-zA-Z\\d]+$";
	}
}
public class SchemaHelpURLAttribute : Attribute
{
	public string URL;

	public SchemaHelpURLAttribute(string url)
	{
		URL = url;
	}

	public SchemaHelpURLAttribute(string urlA, string urlB)
	{
		URL = urlA + "\n" + urlB;
	}
}
public class SchemaIconAttribute : SchemaFieldAttribute
{
	private SpriteType spriteType;

	public SchemaIconAttribute(SpriteType spriteType)
		: base("", required: false, "Name of the file containing the icon for this object. Example: MyCustomGood.png")
	{
		//IL_0014: 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)
		this.spriteType = spriteType;
	}

	public SchemaIconAttribute(SpriteType spriteType, string description)
		: base("", required: false, "Name of the file containing the icon for this object. Example: MyCustomGood.png\n" + description)
	{
		//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)
		this.spriteType = spriteType;
	}

	public override string GetDescription()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		Vector2 spriteSize = TextureHelper.GetSpriteSize(spriteType);
		return base.GetDescription() + "\n" + $"Icon size: {(int)spriteSize.x}x{(int)spriteSize.y} pixels";
	}
}
public class SchemaLocalizedAttribute : SchemaFieldAttribute
{
	private const string LocalizedSubtext = "Defaults to english. To include more languages, add a new field with the language code to the end of the key. For example, 'displayName' => 'displayName_pl' for polish.";

	public SchemaLocalizedAttribute(string description)
		: base(null, description + "\nDefaults to english. To include more languages, add a new field with the language code to the end of the key. For example, 'displayName' => 'displayName_pl' for polish.")
	{
	}
}
[SchemaHelpURL("https://github.com/JamesVeug/AgainstTheStormAPI/blob/master/ATS_API/Scripts/Helpers/Enums/MetaRewardTypes.cs")]
public class SchemaMetaRewardTypeAttribute : SchemaEnumAttribute<MetaRewardTypes>
{
	public SchemaMetaRewardTypeAttribute(MetaRewardTypes defaultValue, string description)
		: base(defaultValue, description)
	{
	}//IL_0001: Unknown result type (might be due to invalid IL or missing references)

}
public class SchemaNameAttribute : SchemaFieldAttribute
{
	public SchemaNameAttribute()
		: base(null, required: true, "Unique identifier")
	{
		Pattern = "^[a-zA-Z\\d_]+$";
		MinLength = 1;
	}
}
[SchemaHelpURL("https://github.com/JamesVeug/AgainstTheStormAPI/blob/master/ATS_API/Scripts/Helpers/Enums/NeedTypes.cs", "https://hoodedhorse.co