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.Goods;
using ATS_API.Helpers;
using ATS_API.Localization;
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.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.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0+f60578f769e2a4cac513b9dbe94af74e0f342663")]
[assembly: AssemblyProduct("JSONLoader")]
[assembly: AssemblyTitle("JSONLoader")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.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 class GoodsLoader
{
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
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 || !isNewGood)
{
ImportExportUtils.ApplyProperty(() => model.icon, delegate(Sprite a)
{
builder.SetIcon(a);
}, ref data.icon, toModel, "goods", "icon");
}
}
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_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
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");
string contents = JSONParser.ToJSON(goodsData);
File.WriteAllText(path, contents);
}
}
}
public class GoodsData : IInitializable
{
public string guid;
public string name;
public string icon;
public LocalizableField displayName;
public LocalizableField description;
public LocalizableField shortDescription;
public bool? eatable;
public int? order;
public float? burningTime;
public float? eatingFullness;
public bool? canBeBurned;
public bool? showStorageAmount;
public bool? isOnHUD;
public string category;
public string[] tags;
public string consoleId;
public float? tradingBuyValue;
public bool? allTradersSellThisGood;
public string[] tradersSellingThisGood;
public float? tradingSellValue;
public bool? allTradersBuyThisGood;
public string[] tradersBuyingThisGood;
public void Initialize()
{
displayName = new LocalizableField("displayName");
description = new LocalizableField("description");
shortDescription = new LocalizableField("shortDescription");
}
}
public static class ImportExportUtils
{
private static string ID;
private static string DebugPath;
private static string LoggingSuffix;
public static void SetID(string id)
{
ID = id;
}
public static void SetDebugPath(string path)
{
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 serializeInfoValue, Func<Y> getter, Action<Y> setter, bool toModel, string category, string suffix)
{
if (toModel)
{
Y b = getter();
ApplyValue(ref serializeInfoValue, ref b, toA: false, category, suffix);
}
else
{
Y b2 = default(Y);
ApplyValue(ref serializeInfoValue, ref b2, toA: true, category, suffix);
setter(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 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_076f: Unknown result type (might be due to invalid IL or missing references)
//IL_0776: Expected O, but got Unknown
//IL_0887: Unknown result type (might be due to invalid IL or missing references)
//IL_088e: Expected O, but got Unknown
//IL_09aa: Unknown result type (might be due to invalid IL or missing references)
//IL_09af: Unknown result type (might be due to invalid IL or missing references)
//IL_0b08: Unknown result type (might be due to invalid IL or missing references)
//IL_0b0d: Unknown result type (might be due to invalid IL or missing references)
//IL_0b1d: Unknown result type (might be due to invalid IL or missing references)
//IL_0b32: Unknown result type (might be due to invalid IL or missing references)
//IL_0b47: Unknown result type (might be due to invalid IL or missing references)
//IL_0b5c: Unknown result type (might be due to invalid IL or missing references)
//IL_0ab8: Unknown result type (might be due to invalid IL or missing references)
//IL_0bf6: Unknown result type (might be due to invalid IL or missing references)
//IL_0c62: Unknown result type (might be due to invalid IL or missing references)
//IL_0c67: Unknown result type (might be due to invalid IL or missing references)
//IL_0c6f: Unknown result type (might be due to invalid IL or missing references)
//IL_0c7b: Unknown result type (might be due to invalid IL or missing references)
//IL_0cd2: Unknown result type (might be due to invalid IL or missing references)
//IL_0cd9: Expected O, but got Unknown
//IL_0d27: Unknown result type (might be due to invalid IL or missing references)
//IL_0d2e: Expected O, but got Unknown
//IL_0f4f: Unknown result type (might be due to invalid IL or missing references)
//IL_0f56: Expected O, but got Unknown
//IL_10c9: Unknown result type (might be due to invalid IL or missing references)
//IL_10d0: Expected O, but got Unknown
//IL_122c: Unknown result type (might be due to invalid IL or missing references)
//IL_1233: 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 (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 obj2 = typeof(ImportExportUtils).GetMethod("ParseEnum", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(typeFromHandle2).Invoke(null, new object[1] { from });
to = (ToType)obj2;
}
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 path = Path.Combine(Plugin.ExportDirectory, category, "Assets", ID + "_" + suffix + ".png");
to = (ToType)(object)ExportTexture(val, path);
}
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 path2 = Path.Combine(Plugin.ExportDirectory, category, "Assets", ID + "_" + suffix + ".png");
to = (ToType)(object)ExportTexture(val2.texture, path2);
}
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;
}
}
}
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 Texture2D GetTextureFromString(string path)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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);
((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 ExportTexture(Texture2D texture, string path)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
if (!((Texture)texture).isReadable)
{
RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)1);
Graphics.Blit((Texture)(object)texture, temporary);
RenderTexture active = RenderTexture.active;
RenderTexture.active = temporary;
Texture2D val = new Texture2D(((Texture)texture).width, ((Texture)texture).height);
val.ReadPixels(new Rect(0f, 0f, (float)((Texture)temporary).width, (float)((Texture)temporary).height), 0, 0);
val.Apply();
RenderTexture.active = active;
RenderTexture.ReleaseTemporary(temporary);
texture = val;
}
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);
}
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 class RaceLoader
{
public class RaceCharacteristicData
{
public string buildingTag;
public string villagerPerkEffect;
public string globalEffect;
public string buildingPerk;
}
public class RaceData : IInitializable
{
public string guid;
public string name;
public string icon;
public string roundIcon;
public string widePortrait;
public string tag;
public bool? isEssential;
public int? order;
public float? baseSpeed;
public float? initialResolve;
public float? minResolve;
public float? maxResolve;
public float? resolvePositveChangePerSec;
public float? resolveNegativeChangePerSec;
public float? resolveNegativeChangeDiffFactor;
public float? reputationPerSec;
public int? minPopulationToGainReputation;
public float? maxReputationFromResolvePerSec;
public float? minResolveForReputationTreshold;
public float? maxResolveForReputationTreshold;
public float? reputationTresholdIncreasePerReputation;
public float? resolveToReputationRatio;
public float? populationToReputationRatio;
public int? hungerTolerance;
public string racialHousingNeed;
public float? needsInterval;
public string[] needs;
public RaceCharacteristicData[] characteristics;
public RacialSounds avatarClickSounds;
public RacialSounds femalePickSounds;
public RacialSounds malePickSounds;
public RacialSounds femaleChangeProfessionSounds;
public RacialSounds maleChangeProfessionSounds;
public string[] maleNames;
public string[] femaleNames;
public void Initialize()
{
}
}
public static void LoadAll(List<string> files)
{
for (int i = 0; i < files.Count; i++)
{
string text = files[i];
if (!text.EndsWith("_race.json"))
{
continue;
}
ImportExportUtils.SetDebugPath(text);
files.RemoveAt(i--);
try
{
Logging.VerboseLog("Loading JSON (goods) " + text);
RaceData raceData = text.FromFilePath<RaceData>();
if (raceData == null)
{
Plugin.Log.LogError((object)("Failed to load JSON (race) " + text));
continue;
}
Logging.VerboseLog("Loaded JSON (race) " + text);
RaceData raceData2 = raceData;
if (raceData2.guid == null)
{
raceData2.guid = (MB.Settings.ContainsRace(raceData.name) ? "" : "JSONLoader");
}
string text2 = ((!string.IsNullOrEmpty(raceData.guid)) ? (raceData.guid + "_") : "");
string text3 = text2 + raceData.name;
RaceModel val = null;
if (MB.Settings.ContainsRace(text3))
{
Logging.VerboseLog("Found existing race " + text3);
val = MB.Settings.GetRace(text3);
Logging.VerboseLog("Applying JSON (race) " + text + " to race " + text3);
Apply(val, raceData, toModel: true, text3);
Logging.VerboseLog("Loaded JSON race " + text3);
}
else
{
Plugin.Log.LogError((object)("Custom races not yet supported! for name " + text3));
}
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"Error loading JSON (race) {text}\n{arg}");
}
}
}
public static void Apply(RaceModel model, RaceData data, bool toModel, string modelName)
{
//IL_045b: Unknown result type (might be due to invalid IL or missing references)
//IL_0462: Expected O, but got Unknown
ImportExportUtils.SetID(modelName);
ImportExportUtils.ApplyValueNoNull(ref model.icon, ref data.icon, toModel, "races", "icon");
ImportExportUtils.ApplyValueNoNull(ref model.roundIcon, ref data.roundIcon, toModel, "races", "roundIcon");
ImportExportUtils.ApplyValueNoNull(ref model.widePortrait, ref data.widePortrait, toModel, "races", "widePortrait");
ImportExportUtils.ApplyValueNoNull(ref model.isEssential, ref data.isEssential, toModel, "races", "isEssential");
ImportExportUtils.ApplyValueNoNull(ref model.maleNames, ref data.maleNames, toModel, "races", "maleNames");
ImportExportUtils.ApplyValueNoNull(ref model.femaleNames, ref data.femaleNames, toModel, "races", "femaleNames");
ImportExportUtils.ApplyValueNoNull(ref model.order, ref data.order, toModel, "races", "order");
ImportExportUtils.ApplyValueNoNull(ref model.tag, ref data.tag, toModel, "races", "widePortrait");
ImportExportUtils.ApplyValueNoNull(ref model.baseSpeed, ref data.baseSpeed, toModel, "races", "baseSpeed");
ImportExportUtils.ApplyValueNoNull(ref model.initialResolve, ref data.initialResolve, toModel, "races", "initialResolve");
ImportExportUtils.ApplyValueNoNull(ref model.minResolve, ref data.minResolve, toModel, "races", "minResolve");
ImportExportUtils.ApplyValueNoNull(ref model.maxResolve, ref data.maxResolve, toModel, "races", "maxResolve");
ImportExportUtils.ApplyValueNoNull(ref model.resolvePositveChangePerSec, ref data.resolvePositveChangePerSec, toModel, "races", "resolvePositveChangePerSec");
ImportExportUtils.ApplyValueNoNull(ref model.resolveNegativeChangePerSec, ref data.resolveNegativeChangePerSec, toModel, "races", "resolveNegativeChangePerSec");
ImportExportUtils.ApplyValueNoNull(ref model.resolveNegativeChangeDiffFactor, ref data.resolveNegativeChangeDiffFactor, toModel, "races", "resolveNegativeChangeDiffFactor");
ImportExportUtils.ApplyValueNoNull(ref model.reputationPerSec, ref data.reputationPerSec, toModel, "races", "reputationPerSec");
ImportExportUtils.ApplyValueNoNull(ref model.minPopulationToGainReputation, ref data.minPopulationToGainReputation, toModel, "races", "minPopulationToGainReputation");
ImportExportUtils.ApplyValueNoNull(ref model.maxReputationFromResolvePerSec, ref data.maxReputationFromResolvePerSec, toModel, "races", "maxReputationFromResolvePerSec");
ImportExportUtils.ApplyVector2(ref model.resolveForReputationTreshold, ref data.minResolveForReputationTreshold, ref data.maxResolveForReputationTreshold, toModel, "races", "resolveForReputationTreshold");
ImportExportUtils.ApplyValueNoNull(ref model.reputationTresholdIncreasePerReputation, ref data.reputationTresholdIncreasePerReputation, toModel, "races", "reputationTresholdIncreasePerReputation");
ImportExportUtils.ApplyValueNoNull(ref model.resolveToReputationRatio, ref data.resolveToReputationRatio, toModel, "races", "resolveToReputationRatio");
ImportExportUtils.ApplyValueNoNull(ref model.populationToReputationRatio, ref data.populationToReputationRatio, toModel, "races", "populationToReputationRatio");
ImportExportUtils.ApplyValueNoNull(ref model.hungerTolerance, ref data.hungerTolerance, toModel, "races", "hungerTolerance");
ImportExportUtils.ApplyValueNoNull(ref model.needs, ref data.needs, toModel, "races", "needs");
ImportExportUtils.ApplyValueNoNull(ref model.racialHousingNeed, ref data.racialHousingNeed, toModel, "races", "racialHousingNeed");
ImportExportUtils.ApplyValueNoNull(ref model.needsInterval, ref data.needsInterval, toModel, "races", "needsInterval");
ImportExportUtils.ApplyValueNoNull(ref model.avatarClickSound, ref data.avatarClickSounds, toModel, "races", "avatarClickSounds");
ImportExportUtils.ApplyValueNoNull(ref model.femalePrefab.view.pickSound, ref data.femalePickSounds, toModel, "races", "femalePickSounds");
ImportExportUtils.ApplyValueNoNull(ref model.femalePrefab.view.professionChangeSound, ref data.femaleChangeProfessionSounds, toModel, "races", "femaleChangeProfessionSounds");
ImportExportUtils.ApplyValueNoNull(ref model.malePrefab.view.pickSound, ref data.malePickSounds, toModel, "races", "malePickSounds");
ImportExportUtils.ApplyValueNoNull(ref model.malePrefab.view.professionChangeSound, ref data.maleChangeProfessionSounds, toModel, "races", "maleChangeProfessionSounds");
if (toModel)
{
model.avatarClickSound.race = model;
model.femalePrefab.view.pickSound.race = model;
model.femalePrefab.view.professionChangeSound.race = model;
model.malePrefab.view.pickSound.race = model;
model.malePrefab.view.professionChangeSound.race = model;
if (data.characteristics == null)
{
return;
}
model.characteristics = (RaceCharacteristicModel[])(object)new RaceCharacteristicModel[data.characteristics.Length];
for (int i = 0; i < data.characteristics.Length; i++)
{
RaceCharacteristicData raceCharacteristicData = data.characteristics[i];
RaceCharacteristicModel val = new RaceCharacteristicModel();
val.tag = BuildingTagTypesExtensions.ToBuildingTagModel(raceCharacteristicData.buildingTag);
if (!string.IsNullOrEmpty(raceCharacteristicData.villagerPerkEffect))
{
val.effect = VillagerPerkTypesExtensions.ToVillagerPerkModel(raceCharacteristicData.villagerPerkEffect);
}
if (!string.IsNullOrEmpty(raceCharacteristicData.globalEffect))
{
val.globalEffect = EffectTypesExtensions.ToEffectModel(raceCharacteristicData.globalEffect);
}
if (!string.IsNullOrEmpty(raceCharacteristicData.buildingPerk))
{
val.buildingPerk = BuildingPerkTypesExtensions.ToBuildingPerkModel(raceCharacteristicData.buildingPerk);
}
model.characteristics[i] = val;
}
}
else
{
data.characteristics = new RaceCharacteristicData[model.characteristics.Length];
Plugin.Log.LogInfo((object)$"{modelName} Characteristics: {model.characteristics.Length}");
for (int j = 0; j < model.characteristics.Length; j++)
{
RaceCharacteristicModel val2 = model.characteristics[j];
RaceCharacteristicData raceCharacteristicData2 = new RaceCharacteristicData();
BuildingTagModel tag = val2.tag;
raceCharacteristicData2.buildingTag = ((tag != null) ? ((Object)tag).name : null);
VillagerPerkModel effect = val2.effect;
raceCharacteristicData2.villagerPerkEffect = ((effect != null) ? ((Object)effect).name : null);
EffectModel globalEffect = val2.globalEffect;
raceCharacteristicData2.globalEffect = ((globalEffect != null) ? ((Object)globalEffect).name : null);
BuildingPerkModel buildingPerk = val2.buildingPerk;
raceCharacteristicData2.buildingPerk = ((buildingPerk != null) ? ((Object)buildingPerk).name : null);
data.characteristics[j] = raceCharacteristicData2;
}
}
}
public static void ExportAll()
{
RaceModel[] races = MB.Settings.Races;
foreach (RaceModel val in races)
{
RaceData raceData = new RaceData();
raceData.name = ((Object)val).name;
raceData.Initialize();
Apply(val, raceData, toModel: false, ((Object)val).name);
string path = Path.Combine(Plugin.ExportDirectory, "races", ((Object)val).name + "_race.json");
string contents = JSONParser.ToJSON(raceData);
File.WriteAllText(path, contents);
}
}
}
namespace TinyJson
{
public interface IFlexibleField
{
bool ContainsKey(string key);
void SetValueWithKey(string key, string value);
string ToJSON(string prefix);
}
public interface IInitializable
{
void Initialize();
}
public static class JSONParser
{
[ThreadStatic]
private static Stack<List<string>> splitArrayPool;
[ThreadStatic]
private static StringBuilder stringBuilder;
[ThreadStatic]
private static Dictionary<Type, Dictionary<string, FieldInfo>> fieldInfoCache;
[ThreadStatic]
private static Dictionary<Type, Dictionary<string, PropertyInfo>> propertyInfoCache;
[ThreadStatic]
private static Dictionary<Type, FieldInfo[]> publicFieldInfoCache;
[ThreadStatic]
private static Dictionary<Type, PropertyInfo[]> publicPropertyInfoCache;
private static string LogPrefix = "";
public static T FromFilePath<T>(this string filePath)
{
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
LogPrefix = filePath.Replace(Paths.PluginPath, "");
if (LogPrefix.StartsWith("/") || LogPrefix.StartsWith("\\"))
{
LogPrefix = LogPrefix.Substring(1);
}
string text = File.ReadAllText(filePath);
if (string.IsNullOrEmpty(text))
{
throw new JsonException("File is empty! " + filePath);
}
Logging.VerboseLog("Loading JSON from " + filePath + "\n" + text);
return text.FromJsonInternal<T>();
}
public static T FromJson<T>(this string json)
{
LogPrefix = "Unspecified Path";
return json.FromJsonInternal<T>();
}
private static T FromJsonInternal<T>(this string json)
{
Initialize();
stringBuilder.Length = 0;
for (int i = 0; i < json.Length; i++)
{
char c = json[i];
switch (c)
{
case '"':
i = AppendUntilStringEnd(appendEscapeCharacter: true, i, json);
continue;
case '/':
if (i + 1 != json.Length && json[i + 1] == '/')
{
i = SkipUntilLineEnd(i, json);
continue;
}
break;
}
if (!char.IsWhiteSpace(c))
{
stringBuilder.Append(c);
}
}
return (T)ParseValue(typeof(T), stringBuilder.ToString());
}
private static void Initialize()
{
if (propertyInfoCache == null)
{
propertyInfoCache = new Dictionary<Type, Dictionary<string, PropertyInfo>>();
}
if (fieldInfoCache == null)
{
fieldInfoCache = new Dictionary<Type, Dictionary<string, FieldInfo>>();
}
if (stringBuilder == null)
{
stringBuilder = new StringBuilder();
}
if (splitArrayPool == null)
{
splitArrayPool = new Stack<List<string>>();
}
if (publicFieldInfoCache == null)
{
publicFieldInfoCache = new Dictionary<Type, FieldInfo[]>();
}
if (publicPropertyInfoCache == null)
{
publicPropertyInfoCache = new Dictionary<Type, PropertyInfo[]>();
}
}
private static int SkipUntilLineEnd(int startIdx, string json)
{
for (int i = startIdx + 2; i < json.Length; i++)
{
if (json[i] == '\n')
{
return i + 1;
}
}
return json.Length - 1;
}
private static int AppendUntilStringEnd(bool appendEscapeCharacter, int startIdx, string json)
{
stringBuilder.Append(json[startIdx]);
for (int i = startIdx + 1; i < json.Length; i++)
{
if (json[i] == '\\')
{
if (appendEscapeCharacter)
{
stringBuilder.Append(json[i]);
}
stringBuilder.Append(json[i + 1]);
i++;
}
else
{
if (json[i] == '"')
{
stringBuilder.Append(json[i]);
return i;
}
stringBuilder.Append(json[i]);
}
}
return json.Length - 1;
}
private static List<string> Split(string json, out int lastIndex)
{
List<string> list = ((splitArrayPool.Count > 0) ? splitArrayPool.Pop() : new List<string>());
list.Clear();
if (json.Length == 2)
{
lastIndex = -1;
return list;
}
int num = 0;
stringBuilder.Length = 0;
lastIndex = 1;
for (int i = 1; i < json.Length - 1; i++)
{
switch (json[i])
{
case '[':
case '{':
num++;
break;
case ']':
case '}':
num--;
break;
case '"':
i = AppendUntilStringEnd(appendEscapeCharacter: true, i, json);
continue;
case ',':
case ':':
lastIndex = i;
if (num == 0)
{
list.Add(stringBuilder.ToString());
stringBuilder.Length = 0;
continue;
}
break;
}
stringBuilder.Append(json[i]);
}
list.Add(stringBuilder.ToString());
return list;
}
internal static object ParseValue(Type type, string json)
{
if (type == typeof(string))
{
if (json.Length <= 2)
{
return null;
}
StringBuilder stringBuilder = new StringBuilder(json.Length);
for (int i = 1; i < json.Length - 1; i++)
{
if (json[i] == '\\' && i + 1 < json.Length - 1)
{
int num = "\"\\nrtbf/".IndexOf(json[i + 1]);
if (num >= 0)
{
stringBuilder.Append("\"\\\n\r\t\b\f/"[num]);
i++;
continue;
}
if (json[i + 1] == 'u' && i + 5 < json.Length - 1)
{
uint result = 0u;
if (uint.TryParse(json.Substring(i + 2, 4), NumberStyles.AllowHexSpecifier, null, out result))
{
stringBuilder.Append((char)result);
i += 5;
continue;
}
}
}
stringBuilder.Append(json[i]);
}
return stringBuilder.ToString();
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return Convert.ChangeType(json, type.GetGenericArguments().First(), CultureInfo.InvariantCulture);
}
if (type.IsPrimitive)
{
return Convert.ChangeType(json, type, CultureInfo.InvariantCulture);
}
if (type == typeof(decimal))
{
decimal.TryParse(json, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2);
return result2;
}
if (type == typeof(DateTime))
{
DateTime.TryParse(json.Replace("\"", ""), CultureInfo.InvariantCulture, DateTimeStyles.None, out var result3);
return result3;
}
if (json == "null")
{
return null;
}
if (type.IsEnum)
{
if (json[0] == '"')
{
json = json.Substring(1, json.Length - 2);
}
try
{
return Enum.Parse(type, json, ignoreCase: false);
}
catch (Exception exception)
{
LogError(exception);
return 0;
}
}
int lastIndex;
if (type.IsArray)
{
Type elementType = type.GetElementType();
if (json[0] != '[' || json[json.Length - 1] != ']')
{
return null;
}
List<string> list = Split(json, out lastIndex);
Array array = Array.CreateInstance(elementType, list.Count);
for (int j = 0; j < list.Count; j++)
{
array.SetValue(ParseValue(elementType, list[j]), j);
}
splitArrayPool.Push(list);
return array;
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
{
Type type2 = type.GetGenericArguments()[0];
if (json[0] != '[' || json[json.Length - 1] != ']')
{
return null;
}
List<string> list2 = Split(json, out lastIndex);
IList list3 = (IList)type.GetConstructor(new Type[1] { typeof(int) }).Invoke(new object[1] { list2.Count });
for (int k = 0; k < list2.Count; k++)
{
list3.Add(ParseValue(type2, list2[k]));
}
splitArrayPool.Push(list2);
return list3;
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<, >))
{
Type[] genericArguments = type.GetGenericArguments();
Type type3 = genericArguments[0];
Type type4 = genericArguments[1];
if (type3 != typeof(string))
{
return null;
}
if (json[0] != '{' || json[json.Length - 1] != '}')
{
return null;
}
List<string> list4 = Split(json, out lastIndex);
if (list4.Count % 2 != 0)
{
return null;
}
IDictionary dictionary = (IDictionary)type.GetConstructor(new Type[1] { typeof(int) }).Invoke(new object[1] { list4.Count / 2 });
for (int l = 0; l < list4.Count; l += 2)
{
if (list4[l].Length > 2)
{
string key = list4[l].Substring(1, list4[l].Length - 2);
object value = ParseValue(type4, list4[l + 1]);
dictionary[key] = value;
}
}
return dictionary;
}
if (type == typeof(object))
{
return ParseAnonymousValue(json);
}
if (json[0] == '{' && json[json.Length - 1] == '}')
{
return ParseObject(type, json);
}
return null;
}
private static object ParseAnonymousValue(string json)
{
if (json.Length == 0)
{
return null;
}
int lastIndex;
if (json[0] == '{' && json[json.Length - 1] == '}')
{
List<string> list = Split(json, out lastIndex);
if (list.Count % 2 != 0)
{
return null;
}
Dictionary<string, object> dictionary = new Dictionary<string, object>(list.Count / 2);
for (int i = 0; i < list.Count; i += 2)
{
dictionary[list[i].Substring(1, list[i].Length - 2)] = ParseAnonymousValue(list[i + 1]);
}
return dictionary;
}
if (json[0] == '[' && json[json.Length - 1] == ']')
{
List<string> list2 = Split(json, out lastIndex);
List<object> list3 = new List<object>(list2.Count);
for (int j = 0; j < list2.Count; j++)
{
list3.Add(ParseAnonymousValue(list2[j]));
}
return list3;
}
if (json[0] == '"' && json[json.Length - 1] == '"')
{
string text = json.Substring(1, json.Length - 2);
return text.Replace("\\", string.Empty);
}
if (char.IsDigit(json[0]) || json[0] == '-')
{
if (json.Contains("."))
{
double.TryParse(json, NumberStyles.Float, CultureInfo.InvariantCulture, out var result);
return result;
}
int.TryParse(json, out var result2);
return result2;
}
if (json == "true")
{
return true;
}
if (json == "false")
{
return false;
}
return null;
}
private static Dictionary<string, T> CreateMemberNameDictionary<T>(T[] members) where T : MemberInfo
{
Dictionary<string, T> dictionary = new Dictionary<string, T>(StringComparer.OrdinalIgnoreCase);
foreach (T val in members)
{
if (val.IsDefined(typeof(IgnoreDataMemberAttribute), inherit: true))
{
continue;
}
string name = val.Name;
if (val.IsDefined(typeof(DataMemberAttribute), inherit: true))
{
DataMemberAttribute dataMemberAttribute = (DataMemberAttribute)Attribute.GetCustomAttribute(val, typeof(DataMemberAttribute), inherit: true);
if (!string.IsNullOrEmpty(dataMemberAttribute.Name))
{
name = dataMemberAttribute.Name;
}
}
dictionary.Add(name.ToLower(), val);
}
return dictionary;
}
private static object ParseObject(Type type, string json)
{
object uninitializedObject = FormatterServices.GetUninitializedObject(type);
if (uninitializedObject is IInitializable initializable)
{
initializable.Initialize();
}
int lastIndex;
List<string> list = Split(json, out lastIndex);
if (list.Count % 2 != 0)
{
char[] array = new char[5] { '{', '}', '[', ']', ',' };
int num = lastIndex - 1;
while (num >= 0 && !ArrayExtension.Contains<char>(array, json[num]))
{
num--;
}
string text = "";
if (num < 0)
{
int num2 = Math.Max(0, lastIndex - 20);
int length = Math.Min(json.Length - num2, 40);
text = json.Substring(num2, length);
}
else
{
int num3 = num + 1;
int length2 = Math.Min(json.Length - num3, lastIndex);
text = json.Substring(num3, length2);
}
LogError($"Invalid JSON. Unexpected extra character found {json[lastIndex]} => {text}");
return uninitializedObject;
}
if (!fieldInfoCache.TryGetValue(type, out var value))
{
value = CreateMemberNameDictionary(type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy));
fieldInfoCache.Add(type, value);
}
if (!propertyInfoCache.TryGetValue(type, out var value2))
{
value2 = CreateMemberNameDictionary(type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy));
propertyInfoCache.Add(type, value2);
}
List<MemberInfo> allMembers = null;
for (int i = 0; i < list.Count; i += 2)
{
if (list[i].Length <= 2)
{
continue;
}
string text2 = list[i].Substring(1, list[i].Length - 2);
string key = text2.ToLower();
string text3 = list[i + 1];
if (value.TryGetValue(key, out var value3) && (!value3.IsPrivate || ((MemberInfo)value3).GetCustomAttribute<SerializeField>() != null))
{
SetField(value3, uninitializedObject, text3);
continue;
}
if (value2.TryGetValue(key, out var value4))
{
SetProperty(value4, uninitializedObject, text3);
continue;
}
bool flag = false;
foreach (KeyValuePair<string, FieldInfo> item in value)
{
FieldInfo value5 = item.Value;
if (ArrayExtension.Contains<Type>(value5.FieldType.GetInterfaces(), typeof(IFlexibleField)))
{
object value6 = value5.GetValue(uninitializedObject);
if (value6 is IFlexibleField flexibleField && flexibleField.ContainsKey(key))
{
flexibleField.SetValueWithKey(key, (string)ParseValue(typeof(string), text3));
flag = true;
break;
}
}
}
if (flag)
{
continue;
}
string[] array2 = FindSimilarFields(key, value, value2);
if (array2 != null && array2.Length != 0)
{
if (allMembers == null)
{
allMembers = new List<MemberInfo>();
allMembers.AddRange(value.Values);
allMembers.AddRange(value2.Values);
}
string[] source = array2.Select((string a) => allMembers.Find((MemberInfo b) => b.Name.ToLower() == a).Name).ToArray();
string arg = string.Join(" or ", source.Select((string a) => "'" + a + "'"));
LogError($"{text2} field not found for {type}. Did you mean {arg}?");
}
else
{
LogWarning($"{text2} field not found for {type}. Could not find a field with a similar name. Are you sure you need this field?");
}
}
return uninitializedObject;
}
private static void LogWarning(string message)
{
Plugin.Log.LogWarning((object)("[" + LogPrefix + "] " + message));
}
private static void LogError(string message)
{
Plugin.Log.LogError((object)("[" + LogPrefix + "] " + message));
}
private static void LogError(Exception exception)
{
Plugin.Log.LogError((object)$"[{LogPrefix}] {exception}");
}
private static string[] FindSimilarFields(string key, Dictionary<string, FieldInfo> nameToField, Dictionary<string, PropertyInfo> nameToProperty)
{
HashSet<string> hashSet = new HashSet<string>();
LinqExtensions.AddRange<string>(hashSet, (IEnumerable<string>)nameToField.Keys);
LinqExtensions.AddRange<string>(hashSet, (IEnumerable<string>)nameToProperty.Keys);
return ImportExportUtils.FindSimilarStrings(key, hashSet);
}
private static void SetField(FieldInfo info, object o, string v)
{
if (ArrayExtension.Contains<Type>(info.FieldType.GetInterfaces(), typeof(IFlexibleField)))
{
object value = info.GetValue(o);
if (value == null)
{
LogError($"{info.Name} field is null! Type: {info.FieldType} o:{o} instance:{o}");
}
else if (value is IFlexibleField flexibleField)
{
flexibleField.SetValueWithKey(info.Name, (string)ParseValue(typeof(string), v));
}
}
else
{
info.SetValue(o, ParseValue(info.FieldType, v));
}
}
private static void SetProperty(PropertyInfo info, object o, string v)
{
info.SetValue(o, ParseValue(info.PropertyType, v), null);
}
public static string ToJSON<T>(T t)
{
Initialize();
return ToJSONInternal(typeof(T), t, "");
}
private static string ToJSONInternal(Type type, object t, string prefix)
{
try
{
if (type == typeof(string))
{
string text = (string)t;
if (text != null)
{
return "\"" + text + "\"";
}
return "\"\"";
}
if (type.IsArray)
{
if (t == null)
{
return "null";
}
return JsonInternalArray(t, prefix);
}
if (type == typeof(int?))
{
int? num = (int?)t;
if (num.HasValue)
{
return num.Value.ToString();
}
return "0";
}
if (type == typeof(bool?))
{
bool? flag = (bool?)t;
if (flag.HasValue)
{
return flag.Value ? "true" : "false";
}
return "false";
}
if (type == typeof(bool))
{
return ((bool)t) ? "true" : "false";
}
if (type == typeof(int) || type == typeof(long))
{
return t.ToString();
}
if (type == typeof(float))
{
return $"{t}";
}
if (type == typeof(float?))
{
float? num2 = (float?)t;
if (num2.HasValue)
{
return num2.Value.ToString();
}
return "0.0";
}
if (type == typeof(Dictionary<string, string>))
{
Dictionary<string, string> dictionary = (Dictionary<string, string>)t;
if (dictionary != null && dictionary.Count > 0)
{
string text2 = "{";
int num3 = 0;
foreach (KeyValuePair<string, string> item in dictionary)
{
text2 = ((num3++ <= 0) ? (text2 + "\n\t" + prefix + "\"" + item.Key + "\": \"" + item.Value + "\"") : (text2 + ",\n\t" + prefix + "\"" + item.Key + "\": \"" + item.Value + "\""));
}
if (num3 > 0)
{
return text2 + "\n" + prefix + "}";
}
return text2 + "}";
}
return "{}";
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
{
IList list = (IList)t;
if (list != null && list.Count > 0)
{
Type type2 = list.GetType().GetGenericArguments().Single();
string text3 = "";
string text4 = prefix + "\t";
for (int i = 0; i < list.Count; i++)
{
object t2 = list[i];
text3 = text3 + "\n" + text4 + ToJSONInternal(type2, t2, text4);
if (i < list.Count - 1)
{
text3 += ",";
}
}
return "[" + text3 + "\n" + prefix + "]";
}
return "[]";
}
if (!type.IsValueType)
{
if (t == null)
{
return "null";
}
if (!publicFieldInfoCache.TryGetValue(type, out var value))
{
value = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
publicFieldInfoCache[type] = value;
}
if (!publicPropertyInfoCache.TryGetValue(type, out var value2))
{
value2 = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);
publicPropertyInfoCache[type] = value2;
}
string text5 = "{";
int num4 = 0;
string text6 = prefix + "\t";
FieldInfo[] array = value;
foreach (FieldInfo fieldInfo in array)
{
if (fieldInfo.IsPrivate && MemberInfoExtensions.GetAttribute<SerializeField>((ICustomAttributeProvider)fieldInfo) == null)
{
continue;
}
if (ArrayExtension.Contains<Type>(fieldInfo.FieldType.GetInterfaces(), typeof(IFlexibleField)))
{
if (num4 > 0)
{
text5 += ",";
}
text5 += ((IFlexibleField)fieldInfo.GetValue(t)).ToJSON(text6);
num4++;
continue;
}
string text7 = ToJSONInternal(fieldInfo.FieldType, fieldInfo.GetValue(t), text6);
if (num4++ > 0)
{
text5 += ",";
}
text5 = text5 + "\n" + text6 + "\"" + fieldInfo.Name + "\": " + text7;
}
PropertyInfo[] array2 = value2;
foreach (PropertyInfo propertyInfo in array2)
{
LogWarning("Property " + propertyInfo.Name);
string text8 = ToJSONInternal(propertyInfo.PropertyType, propertyInfo.GetValue(t), text6);
if (num4++ > 0)
{
text5 += ",";
}
text5 = text5 + "\n" + text6 + "\"" + propertyInfo.Name + "\": " + text8;
}
if (num4 > 0)
{
return text5 + "\n" + prefix + "}";
}
return text5 + prefix + "}";
}
}
catch (Exception exception)
{
LogError($"Something went wrong while serializing JSON type: {type} value: {t}");
LogError(exception);
throw;
}
throw new NotImplementedException($"Type not supported for JSON serialization {type}");
}
private static string JsonInternalArray(object t, string prefix)
{
Array array = (Array)t;
if (array != null)
{
Type elementType = array.GetType().GetElementType();
string text = "";
text += "[";
for (int i = 0; i < array.Length; i++)
{
text += ToJSONInternal(elementType, array.GetValue(i), prefix + "\t");
if (i < array.Length - 1)
{
text = text + ",\n" + prefix + "\t";
}
}
if (array.Length > 1)
{
text = text + "\n" + prefix;
}
return text + "]";
}
return "[]";
}
}
[Serializable]
public class LocalizableField : IFlexibleField
{
public Dictionary<SystemLanguage, string> rows;
public string englishFieldName;
public string englishFieldNameLower;
public string EnglishValue
{
get
{
if (rows.TryGetValue((SystemLanguage)10, out var value))
{
return value;
}
Plugin.Log.LogError((object)("Field has not been initialized " + englishFieldName + "!"));
return englishFieldName;
}
}
public LocalizableField(string EnglishFieldName)
{
rows = new Dictionary<SystemLanguage, string>();
englishFieldName = EnglishFieldName;
englishFieldNameLower = EnglishFieldName.ToLower();
}
public void Initialize(string englishValue)
{
rows[(SystemLanguage)10] = englishValue;
}
public bool ContainsKey(string key)
{
return key.StartsWith(englishFieldNameLower);
}
public void SetValueWithKey(string key, string value)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
if (key == englishFieldName)
{
rows[(SystemLanguage)10] = value;
return;
}
int num = englishFieldName.LastIndexOf("_");
string languageCode = key.Substring(num + 1);
SystemLanguage languageFromKey = GetLanguageFromKey(languageCode);
rows[languageFromKey] = value;
}
public void SetValue(SystemLanguage language, string value)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
rows[language] = value;
}
public void SetValueWithLanguageCode(string languageCode, string value)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
SystemLanguage languageFromKey = GetLanguageFromKey(languageCode);
rows[languageFromKey] = value;
}
private SystemLanguage GetLanguageFromKey(string languageCode)
{
//IL_065b: Unknown result type (might be due to invalid IL or missing references)
//IL_0643: Unknown result type (might be due to invalid IL or missing references)
//IL_06c3: Unknown result type (might be due to invalid IL or missing references)
//IL_069b: Unknown result type (might be due to invalid IL or missing references)
//IL_06be: Unknown result type (might be due to invalid IL or missing references)
//IL_066a: Unknown result type (might be due to invalid IL or missing references)
//IL_0679: Unknown result type (might be due to invalid IL or missing references)
//IL_069f: Unknown result type (might be due to invalid IL or missing references)
//IL_0674: Unknown result type (might be due to invalid IL or missing references)
//IL_067d: Unknown result type (might be due to invalid IL or missing references)
//IL_0663: Unknown result type (might be due to invalid IL or missing references)
//IL_0634: Unknown result type (might be due to invalid IL or missing references)
//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
//IL_06ab: Unknown result type (might be due to invalid IL or missing references)
//IL_0696: Unknown result type (might be due to invalid IL or missing references)
//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
//IL_0682: Unknown result type (might be due to invalid IL or missing references)
//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
//IL_0624: Unknown result type (might be due to invalid IL or missing references)
//IL_063b: Unknown result type (might be due to invalid IL or missing references)
//IL_0614: Unknown result type (might be due to invalid IL or missing references)
//IL_06af: Unknown result type (might be due to invalid IL or missing references)
//IL_06b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0653: Unknown result type (might be due to invalid IL or missing references)
//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
//IL_061c: Unknown result type (might be due to invalid IL or missing references)
//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
//IL_066f: Unknown result type (might be due to invalid IL or missing references)
//IL_068c: Unknown result type (might be due to invalid IL or missing references)
//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
//IL_062c: Unknown result type (might be due to invalid IL or missing references)
//IL_0691: Unknown result type (might be due to invalid IL or missing references)
//IL_064b: Unknown result type (might be due to invalid IL or missing references)
//IL_060c: Unknown result type (might be due to invalid IL or missing references)
//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0604: Unknown result type (might be due to invalid IL or missing references)
//IL_0687: Unknown result type (might be due to invalid IL or missing references)
return (SystemLanguage)(languageCode switch
{
"en" => 10,
"ru" => 30,
"zh" => 6,
"es" => 34,
"fr" => 14,
"de" => 15,
"it" => 21,
"pt" => 28,
"ja" => 22,
"ko" => 23,
"ar" => 1,
"nl" => 9,
"fi" => 13,
"sv" => 35,
"no" => 26,
"pl" => 27,
"da" => 8,
"el" => 16,
"tr" => 37,
"hu" => 18,
"cs" => 7,
"ro" => 29,
"th" => 36,
"vi" => 39,
"uk" => 38,
"id" => 20,
"he" => 17,
"af" => 0,
"eu" => 2,
"be" => 3,
"bg" => 4,
"ca" => 5,
"fo" => 12,
"is" => 19,
"lv" => 24,
"lt" => 25,
"sh" => 31,
"sk" => 32,
"sl" => 33,
_ => throw new NotImplementedException("Language code " + languageCode + " is not supported"),
});
}
private string GetKeyFromLanguage(SystemLanguage language)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Expected I4, but got Unknown
//IL_0240: Unknown result type (might be due to invalid IL or missing references)
switch ((int)language)
{
case 10:
return "en";
case 30:
return "ru";
case 6:
case 40:
case 41:
return "zh";
case 34:
return "es";
case 14:
return "fr";
case 15:
return "de";
case 21:
return "it";
case 28:
return "pt";
case 22:
return "ja";
case 23:
return "ko";
case 1:
return "ar";
case 9:
return "nl";
case 13:
return "fi";
case 35:
return "sv";
case 26:
return "no";
case 27:
return "pl";
case 8:
return "da";
case 16:
return "el";
case 37:
return "tr";
case 18:
return "hu";
case 7:
return "cs";
case 29:
return "ro";
case 36:
return "th";
case 39:
return "vi";
case 38:
return "uk";
case 20:
return "id";
case 17:
return "he";
case 0:
return "af";
case 2:
return "eu";
case 3:
return "be";
case 4:
return "bg";
case 5:
return "ca";
case 12:
return "fo";
case 19:
return "is";
case 24:
return "lv";
case 25:
return "lt";
case 31:
return "sh";
case 32:
return "sk";
case 33:
return "sl";
default:
throw new NotImplementedException($"Language {language} is not supported");
}
}
public string ToJSON(string prefix)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
string text = "";
int num = 0;
foreach (KeyValuePair<SystemLanguage, string> row in rows)
{
string keyFromLanguage = GetKeyFromLanguage(row.Key);
string text2 = englishFieldName + "_" + keyFromLanguage;
text = text + "\n" + prefix + "\"" + text2 + "\": \"" + row.Value + "\"";
if (num++ < rows.Count - 1)
{
text += ",";
}
}
if (num == 0)
{
text = text + "\n" + prefix + "\"" + englishFieldName + "\": \"\"";
}
return text;
}
public override string ToString()
{
return rows.ToString();
}
public IEnumerable<KeyValuePair<SystemLanguage, string>> GetTranslations()
{
return rows;
}
public string GetFieldKey(SystemLanguage language)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
return englishFieldName + "_" + GetKeyFromLanguage(language);
}
}
}
namespace ATS_JSONLoader
{
internal class Logging
{
internal static void VerboseLog(string s)
{
if (Configs.VerboseLogging)
{
Plugin.Log.LogInfo((object)s);
}
}
internal static void VerboseWarning(string s)
{
if (Configs.VerboseLogging)
{
Plugin.Log.LogWarning((object)s);
}
}
internal static void VerboseError(string s)
{
if (Configs.VerboseLogging)
{
Plugin.Log.LogError((object)s);
}
}
}
[HarmonyPatch]
[BepInPlugin("JSONLoader", "JSONLoader", "0.4.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public static string PluginDirectory;
public static Plugin Instance;
public static ManualLogSource Log;
public static string JSONLoaderDirectory = "";
public static string BepInExDirectory = "";
private Harmony harmony;
public static string ExportDirectory => Path.Combine(Application.dataPath, "JSONLoader", "Exported");
private static List<string> GetAllJLDRFiles()
{
string exportedFolder = Path.Combine(JSONLoaderDirectory, "Exported");
string examplesFolder = Path.Combine(JSONLoaderDirectory, "Examples");
return (from a in Directory.GetFiles(Paths.PluginPath, "*.json", SearchOption.AllDirectories)
where !a.Contains(exportedFolder) && !a.Contains(examplesFolder)
select a).ToList();
}
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading JSONLoader!");
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
JSONLoaderDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
harmony = Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, "JSONLoader");
int num = ((BaseUnityPlugin)this).Info.Location.LastIndexOf("BepInEx");
if (num > 0)
{
BepInExDirectory = ((BaseUnityPlugin)this).Info.Location.Substring(0, num);
}
else
{
BepInExDirectory = Directory.GetParent(JSONLoaderDirectory)?.FullName ?? "";
}
Configs.InitializeConfigs(((BaseUnityPlugin)this).Config);
Hotkeys.RegisterKey("JSONLoader", "reload", "Reload all JSON Files", new List<KeyCode>(1) { (KeyCode)286 }, (Action)delegate
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Reloading JSONLoader!");
LoadAllFiles();
}, (Action)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded JSONLoader!");
}
[HarmonyPatch(typeof(MainController), "OnServicesReady")]
[HarmonyPostfix]
private static void HookMainControllerSetup()
{
bool flag = MB.GameSaveService.IsNewGame();
((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"Entered a game. Is this a new game: {flag}.");
((MonoBehaviour)Instance).StartCoroutine(GameLoaded());
}
private static IEnumerator GameLoaded()
{
yield return (object)new WaitForEndOfFrame();
LoadAllFiles();
if (Configs.Export)
{
ExportAllFiles();
}
}
private static void LoadAllFiles()
{
List<string> allJLDRFiles = GetAllJLDRFiles();
GoodsLoader.LoadAll(allJLDRFiles);
RaceLoader.LoadAll(allJLDRFiles);
}
private static void ExportAllFiles()
{
if (!Directory.Exists(ExportDirectory))
{
Directory.CreateDirectory(ExportDirectory);
}
GoodsLoader.ExportAll();
RaceLoader.ExportAll();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "JSONLoader";
public const string PLUGIN_NAME = "JSONLoader";
public const string PLUGIN_VERSION = "0.4.0";
}
}
namespace ATS_JSONLoader.Sounds
{
public class SoundCollection : IInitializable
{
public List<Sound> sounds = new List<Sound>();
public void Initialize()
{
sounds = new List<Sound>();
}
}
public class RacialSounds : IInitializable
{
public SoundCollection PositiveSounds = new SoundCollection();
public SoundCollection NegativeSounds = new SoundCollection();
public SoundCollection NeutralSounds = new SoundCollection();
public void Initialize()
{
PositiveSounds = new SoundCollection();
NegativeSounds = new SoundCollection();
NeutralSounds = new SoundCollection();
}
}
public class Sound
{
public string soundPath;
public float? volume = 1f;
}
}
namespace JLPlugin
{
internal static class Configs
{
private static ConfigEntry<bool> export;
private static ConfigEntry<bool> verboseLogging;
private static ConfigFile configFile;
internal static bool VerboseLogging => verboseLogging.Value;
internal static bool Export => export.Value;
public static void InitializeConfigs(ConfigFile config)
{
configFile = config;
verboseLogging = config.Bind<bool>("Debugging", "Verbose Logging", false, "When set to true JSONLoader will produce a lot more logs to assist with debugging why something isn't working.");
export = config.Bind<bool>("Exporting", "Export On Game Load", false, "When set to true JSONLoader will export as much data as it can to '" + Plugin.ExportDirectory + "'.");
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}