using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using ItemDataManager;
using ItemManager;
using JetBrains.Annotations;
using Jewelcrafting;
using LocalizationManager;
using Microsoft.CodeAnalysis;
using MonoMod.Utils;
using ServerSync;
using SkillManager;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;
using fastJSON;
[assembly: Guid("2ED4D3E3-D23D-4E36-92E6-C2303E7843E8")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyProduct("Soulcatcher_KG_JC_Additions")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("Soulcatcher_KG_JC_Additions")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyCompany("")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[<68eef2c1-3e2c-4056-ab22-6f77026b64d5>Embedded]
internal sealed class <68eef2c1-3e2c-4056-ab22-6f77026b64d5>EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[<68eef2c1-3e2c-4056-ab22-6f77026b64d5>Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class <f748abfc-69bc-4f09-8901-6581c23f6009>NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public <f748abfc-69bc-4f09-8901-6581c23f6009>NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public <f748abfc-69bc-4f09-8901-6581c23f6009>NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[<68eef2c1-3e2c-4056-ab22-6f77026b64d5>Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class <3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContextAttribute : Attribute
{
public readonly byte Flag;
public <3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
[<68eef2c1-3e2c-4056-ab22-6f77026b64d5>Embedded]
[CompilerGenerated]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ItemDataManager
{
[PublicAPI]
public abstract class ItemData
{
internal static WeakReference<ItemInfo> constructingInfo = null;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0 })]
internal WeakReference<ItemInfo> info;
private static readonly FieldInfo parameterInfoClassImpl = AccessTools.DeclaredField(typeof(ParameterInfo), "ClassImpl");
private static Dictionary<Type, Dictionary<string, FieldInfo>> serializedFields = new Dictionary<Type, Dictionary<string, FieldInfo>>();
public string CustomDataKey { get; internal set; }
protected virtual bool AllowStackingIdenticalValues { get; set; }
public string Value
{
get
{
if (!Item.m_customData.TryGetValue(CustomDataKey, out var value))
{
return "";
}
return value;
}
set
{
Item.m_customData[CustomDataKey] = value;
}
}
public string Key { get; internal set; }
public bool IsCloned => Info.isCloned.Contains(CustomDataKey);
public bool IsAlive
{
get
{
ItemInfo target;
return (info ?? constructingInfo).TryGetTarget(out target);
}
}
public ItemData Item => Info.ItemData;
public ItemInfo Info
{
get
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
if (!(info ?? constructingInfo).TryGetTarget(out var target))
{
return new ItemInfo(new ItemData());
}
return target;
}
}
public virtual void FirstLoad()
{
}
public virtual void Load()
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Expected O, but got Unknown
Dictionary<string, FieldInfo> dictionary = fetchSerializedFields();
if (dictionary == null || dictionary.Count <= 0 || Value == "")
{
return;
}
List<object> list = new List<object>();
string[] array = Value.Split(new char[1] { '|' });
for (int i = 0; i < array.Length; i++)
{
string[] array2 = array[i].Split(new char[1] { ':' });
if (array2.Length == 2 && dictionary.TryGetValue(array2[0], out var value))
{
ZPackage val = new ZPackage(array2[1]);
ParameterInfo parameterInfo = (ParameterInfo)FormatterServices.GetUninitializedObject(typeof(ParameterInfo));
parameterInfoClassImpl.SetValue(parameterInfo, value.FieldType);
list.Clear();
ZRpc.Deserialize(new ParameterInfo[2] { null, parameterInfo }, val, ref list);
if (list.Count > 0)
{
value.SetValue(this, list[0]);
}
}
}
}
public virtual void Save()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
Dictionary<string, FieldInfo> dictionary = fetchSerializedFields();
if (dictionary == null || dictionary.Count <= 0)
{
return;
}
StringBuilder stringBuilder = new StringBuilder();
foreach (FieldInfo value in dictionary.Values)
{
ZPackage val = new ZPackage();
ZRpc.Serialize(new object[1] { value.GetValue(this) }, ref val);
stringBuilder.Append(value.Name);
stringBuilder.Append(':');
stringBuilder.Append(val.GetBase64());
stringBuilder.Append('|');
}
int length = stringBuilder.Length - 1;
stringBuilder.Length = length;
Value = stringBuilder.ToString();
}
public virtual void Unload()
{
}
public virtual void Upgraded()
{
}
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
public virtual string TryStack(ItemData data)
{
if (!AllowStackingIdenticalValues || !(data?.Value == Value))
{
return null;
}
return Value;
}
private Dictionary<string, FieldInfo> fetchSerializedFields()
{
Type type = GetType();
if (serializedFields.TryGetValue(type, out var value))
{
return value;
}
return serializedFields[type] = (from f in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
where f.GetCustomAttributes(typeof(SerializeField), inherit: true).Length != 0
select f).ToDictionary((FieldInfo f) => f.Name, (FieldInfo f) => f);
}
}
public sealed class StringItemData : ItemData
{
}
[PublicAPI]
public class ItemInfo : IEnumerable<ItemData>, IEnumerable
{
public static HashSet<Type> ForceLoadTypes;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
internal static string _modGuid;
private static Dictionary<Type, HashSet<Type>> typeInheritorsCache;
private static HashSet<string> knownTypes;
private Dictionary<string, ItemData> data = new Dictionary<string, ItemData>();
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0 })]
private WeakReference<ItemInfo> selfReference;
internal HashSet<string> isCloned = new HashSet<string>();
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private static ItemData awakeningItem;
private static Assembly primaryAssembly;
private static Dictionary<Assembly, string> assemblyNameCache;
private static Dictionary<Type, string> classKeyCache;
private HashSet<string> fetchedClassKeys = new HashSet<string>();
private static MethodInfo removeMethod;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private static ItemData checkingForStackableItemData;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0, 0 })]
private static Dictionary<string, string> newValuesOnStackable;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private static ItemData currentlyUpgradingItem;
internal static string modGuid => _modGuid ?? (_modGuid = ((Func<string>)delegate
{
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
IEnumerable<TypeInfo> source;
try
{
source = Assembly.GetExecutingAssembly().DefinedTypes.ToList();
}
catch (ReflectionTypeLoadException ex)
{
source = from t in ex.Types
where t != null
select t.GetTypeInfo();
}
return ((BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)))).Info.Metadata.GUID;
})());
public string Mod => modGuid;
public ItemData ItemData { get; private set; }
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public string this[string key]
{
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
get
{
return Get<StringItemData>(key)?.Value;
}
[param: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
set
{
GetOrCreate<StringItemData>(key).Value = value ?? "";
}
}
internal static void addTypeToInheritorsCache(Type type, string typeKey)
{
if (!knownTypes.Contains(typeKey))
{
knownTypes.Add(typeKey);
Type type2 = type;
while ((object)type2 != null)
{
AddInterfaces(type2);
type2 = type2.BaseType;
}
}
void AddInterfaces(Type baseType)
{
if (!typeInheritorsCache.TryGetValue(baseType, out var value))
{
HashSet<Type> hashSet2 = (typeInheritorsCache[baseType] = new HashSet<Type>());
value = hashSet2;
}
value.Add(type);
Type[] interfaces = baseType.GetInterfaces();
for (int i = 0; i < interfaces.Length; i++)
{
AddInterfaces(interfaces[i]);
}
}
}
private static string cachedAssemblyName(Assembly assembly)
{
if (assemblyNameCache.TryGetValue(assembly, out var value))
{
return value;
}
return assemblyNameCache[assembly] = assembly.GetName().Name;
}
internal static string classKey(Type type, string key)
{
if (!classKeyCache.TryGetValue(type, out var value))
{
value = type.FullName + ((type.Assembly != primaryAssembly) ? ("," + cachedAssemblyName(type.Assembly)) : "");
addTypeToInheritorsCache(type, value);
}
if (key == "")
{
return value;
}
return value + "#" + key;
}
internal static string dataKey(string key)
{
return modGuid + "#" + key;
}
internal ItemInfo(ItemData itemData)
{
ItemData = itemData;
string text = dataKey("");
foreach (string item in ItemData.m_customData.Keys.ToList())
{
if (!item.StartsWith(text))
{
continue;
}
string[] array = item.Substring(text.Length).Split(new char[1] { '#' }, 2);
if (!knownTypes.Contains(array[0]))
{
Type type = Type.GetType(array[0]);
if ((object)type != null && typeof(ItemData).IsAssignableFrom(type))
{
addTypeToInheritorsCache(type, array[0]);
}
}
}
}
public T GetOrCreate<T>(string key = "") where T : ItemData, new()
{
return Add<T>(key) ?? Get<T>(key);
}
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public T Add<T>(string key = "") where T : ItemData, new()
{
string text = classKey(typeof(T), key);
if (fetchedClassKeys.Contains(text) && data.ContainsKey(text))
{
return null;
}
string text2 = dataKey(text);
if (ItemData.m_customData.ContainsKey(text2) || (awakeningItem != ItemData && data.ContainsKey(text)))
{
return null;
}
ItemData.m_customData[text2] = "";
ItemDataManager.ItemData.constructingInfo = selfReference ?? (selfReference = new WeakReference<ItemInfo>(this));
T val = new T
{
info = selfReference,
Key = key,
CustomDataKey = text2
};
data[text] = val;
val.Value = "";
val.FirstLoad();
return val;
}
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public T Get<T>(string key = "") where T : class
{
if (!typeInheritorsCache.TryGetValue(typeof(T), out var value))
{
if (!typeof(ItemData).IsAssignableFrom(typeof(T)) || typeof(T) == typeof(ItemData))
{
throw new Exception("Trying to get value from ItemDataManager for class not inheriting from ItemData");
}
return null;
}
foreach (Type item in value)
{
string text = classKey(item, key);
if (data.TryGetValue(text, out var value2))
{
return (T)(object)value2;
}
if (!fetchedClassKeys.Contains(text) && awakeningItem != ItemData)
{
string text2 = dataKey(text);
fetchedClassKeys.Add(text);
if (ItemData.m_customData.ContainsKey(text2))
{
return (T)(object)constructDataObj(text2, text);
}
}
}
return null;
}
public Dictionary<string, T> GetAll<T>() where T : ItemData
{
LoadAll();
return data.Values.Where((ItemData o) => o is T).ToDictionary((ItemData o) => o.Key, (ItemData o) => (T)o);
}
public bool Remove(string key = "")
{
return Remove<StringItemData>(key);
}
public bool Remove<T>(string key = "") where T : ItemData
{
string key2 = classKey(typeof(T), key);
string key3 = dataKey(key2);
if (ItemData.m_customData.Remove(key3))
{
if (data.TryGetValue(key2, out var value))
{
value.Unload();
data.Remove(key2);
}
return true;
}
return false;
}
public bool Remove<T>(T itemData) where T : ItemData
{
if (typeof(T) == itemData.GetType())
{
return Remove<T>(itemData.Key);
}
return (bool)removeMethod.MakeGenericMethod(itemData.GetType()).Invoke(this, new object[1] { itemData.Key });
}
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private ItemData constructDataObj(string fullkey, string key)
{
string[] array = key.Split(new char[1] { '#' }, 2);
Type type = Type.GetType(array[0]);
if ((object)type == null || !typeof(ItemData).IsAssignableFrom(type))
{
return null;
}
ItemDataManager.ItemData.constructingInfo = selfReference ?? (selfReference = new WeakReference<ItemInfo>(this));
ItemData itemData = (ItemData)Activator.CreateInstance(type);
data[key] = itemData;
itemData.info = selfReference;
itemData.Key = ((array.Length > 1) ? array[1] : "");
itemData.CustomDataKey = fullkey;
itemData.Load();
return itemData;
}
public void Save()
{
foreach (ItemData value in data.Values)
{
value.Save();
}
}
public void LoadAll()
{
if (awakeningItem == ItemData)
{
return;
}
string text = dataKey("");
foreach (string item in ItemData.m_customData.Keys.ToList())
{
if (item.StartsWith(text))
{
string key = item.Substring(text.Length);
if (!data.ContainsKey(key))
{
constructDataObj(item, key);
}
}
}
}
public IEnumerator<ItemData> GetEnumerator()
{
LoadAll();
return data.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
private static void SavePrefix(ItemData __instance)
{
SaveItem(__instance);
}
private static void SaveInventoryPrefix(Inventory __instance)
{
foreach (ItemData item in __instance.m_inventory)
{
SaveItem(item);
}
}
private static void SaveItem(ItemData item)
{
if (ItemExtensions.itemInfo.TryGetValue(item, out var value))
{
value.Save();
}
}
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0, 0 })]
public Dictionary<string, string> IsStackableWithOtherInfo(ItemInfo info)
{
LoadAll();
Dictionary<string, string> dictionary = new Dictionary<string, string>();
if (info != null)
{
info.LoadAll();
foreach (string item in new HashSet<string>(info.data.Keys.Intersect(data.Keys)))
{
string text = data[item].TryStack(info.data[item]);
if (text == null)
{
return null;
}
dictionary[item] = text;
}
foreach (KeyValuePair<string, ItemData> datum in info.data)
{
if (!dictionary.ContainsKey(datum.Key))
{
string text2 = info.data[datum.Key].TryStack(null);
if (text2 == null)
{
return null;
}
dictionary[datum.Key] = text2;
}
}
}
foreach (KeyValuePair<string, ItemData> datum2 in data)
{
if (!dictionary.ContainsKey(datum2.Key))
{
string text3 = data[datum2.Key].TryStack(null);
if (text3 == null)
{
return null;
}
dictionary[datum2.Key] = text3;
}
}
return dictionary.ToDictionary((KeyValuePair<string, string> kv) => dataKey(kv.Key), (KeyValuePair<string, string> kv) => kv.Value);
}
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
private static void RegisterForceLoadedTypesAddItem(ItemData __result)
{
awakeningItem = null;
if (__result != null)
{
RegisterForceLoadedTypes(__result);
}
}
private static void RegisterForceLoadedTypes(ItemData itemData)
{
foreach (Type forceLoadType in ForceLoadTypes)
{
string key = classKey(forceLoadType, "");
string text = dataKey(key);
if (itemData.m_customData.ContainsKey(text))
{
itemData.Data().constructDataObj(text, key);
}
}
}
private static void ItemDropAwake(ItemDrop __instance)
{
GameObject dropPrefab = __instance.m_itemData.m_dropPrefab;
if (dropPrefab != null && ItemExtensions.itemInfo.TryGetValue(dropPrefab.GetComponent<ItemDrop>().m_itemData, out var value))
{
__instance.m_itemData.Data().isCloned = new HashSet<string>(value.data.Values.Select((ItemData i) => i.CustomDataKey));
}
}
private static void ItemDropAwakeDelayed(ItemDrop __instance)
{
if (!ZNetView.m_forceDisableInit)
{
RegisterForceLoadedTypes(__instance.m_itemData);
}
}
private static void ItemDataClonePrefix(ItemData __instance, ItemData __result)
{
SaveItem(__instance);
}
private static void ItemDataClonePostfix(ItemData __instance, ItemData __result)
{
if (ItemExtensions.itemInfo.TryGetValue(__instance, out var value))
{
__result.Data().isCloned = new HashSet<string>(value.data.Values.Select((ItemData i) => i.CustomDataKey));
}
}
private static void ItemDataClonePostfixDelayed(ItemData __result)
{
RegisterForceLoadedTypes(__result);
}
private static void RegisterForceLoadedTypesOnPlayerLoaded(Player __instance)
{
foreach (Food food in __instance.m_foods)
{
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(food.m_name);
if (itemPrefab.GetComponent<ItemDrop>().m_itemData == food.m_item)
{
food.m_item = food.m_item.Clone();
food.m_item.m_dropPrefab = itemPrefab;
}
RegisterForceLoadedTypes(food.m_item);
}
}
private static void SaveCheckingForStackableItemData(ItemData item)
{
checkingForStackableItemData = item;
}
private static void ResetCheckingForStackableItemData()
{
checkingForStackableItemData = null;
}
private static IEnumerable<CodeInstruction> CheckStackableInFindFreeStackMethods(IEnumerable<CodeInstruction> instructionsEnumerable)
{
CodeInstruction[] instructions = instructionsEnumerable.ToArray();
Label target = (Label)instructions.First((CodeInstruction i) => i.opcode == OpCodes.Br || i.opcode == OpCodes.Br_S).operand;
CodeInstruction targetedInstr = instructions.First((CodeInstruction i) => i.labels.Contains(target));
Label? label = default(Label?);
CodeInstruction lastBranch = instructions.Reverse().First((CodeInstruction i) => CodeInstructionExtensions.Branches(i, ref label) && targetedInstr.labels.Contains(label.Value));
CodeInstruction loadingInstruction = null;
int j = 0;
while (j < instructions.Length)
{
yield return instructions[j];
if (loadingInstruction == null && instructions[j].opcode == OpCodes.Call && ((MethodInfo)instructions[j].operand).Name == "get_Current")
{
loadingInstruction = instructions[j + 1].Clone();
loadingInstruction.opcode = new Dictionary<OpCode, OpCode>
{
{
OpCodes.Stloc_0,
OpCodes.Ldloc_0
},
{
OpCodes.Stloc_1,
OpCodes.Ldloc_1
},
{
OpCodes.Stloc_2,
OpCodes.Ldloc_2
},
{
OpCodes.Stloc_3,
OpCodes.Ldloc_3
},
{
OpCodes.Stloc_S,
OpCodes.Ldloc_S
}
}[loadingInstruction.opcode];
}
if (instructions[j] == lastBranch)
{
yield return loadingInstruction;
yield return new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.DeclaredField(typeof(ItemInfo), "checkingForStackableItemData"));
yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ItemInfo), "CheckItemDataIsStackableFindFree", (Type[])null, (Type[])null));
yield return new CodeInstruction(OpCodes.Brfalse, (object)target);
}
int num = j + 1;
j = num;
}
}
private static bool CheckItemDataIsStackableFindFree(ItemData item, [<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)] ItemData target)
{
if (target == null)
{
return true;
}
Dictionary<string, string> dictionary = IsStackable(item, target);
if (dictionary != null)
{
newValuesOnStackable = dictionary;
return true;
}
return false;
}
private static void ResetNewValuesOnStackable()
{
newValuesOnStackable = null;
}
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
private static void ApplyNewValuesOnStackable(ItemData __result)
{
if (__result == null || newValuesOnStackable == null)
{
return;
}
foreach (KeyValuePair<string, string> item in newValuesOnStackable)
{
__result.m_customData[item.Key] = item.Value;
}
}
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0, 0 })]
private static Dictionary<string, string> IsStackable(ItemData a, ItemData b)
{
ItemInfo itemInfo = a.Data();
if (itemInfo != null)
{
return itemInfo.IsStackableWithOtherInfo(b.Data());
}
ItemInfo itemInfo2 = b.Data();
if (itemInfo2 != null)
{
return itemInfo2.IsStackableWithOtherInfo(null);
}
return new Dictionary<string, string>();
}
private static bool CheckItemDataStackableAddItem(Inventory __instance, ItemData item, int x, int y, [<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0, 0 })] ref Dictionary<string, string> __state, ref bool __result)
{
ItemData itemAt = __instance.GetItemAt(x, y);
if (itemAt != null)
{
Dictionary<string, string> dictionary = IsStackable(item, itemAt);
if (dictionary == null)
{
__result = false;
return false;
}
__state = dictionary;
}
return true;
}
private static void ApplyCustomItemDataStackableAddItem(Inventory __instance, int x, int y, [<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0, 0 })] Dictionary<string, string> __state, bool __result)
{
if (!__result || __state == null)
{
return;
}
foreach (KeyValuePair<string, string> item in __state)
{
__instance.GetItemAt(x, y).m_customData[item.Key] = item.Value;
}
}
private static void ApplyCustomItemDataStackableAutoStack(ItemDrop item, Dictionary<string, string> customData)
{
item.m_itemData.m_customData = customData;
}
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0, 0 })]
private static Dictionary<string, string> IsStackableItemDrop(ItemDrop drop, ItemData item)
{
return IsStackable(drop.m_itemData, item);
}
private static IEnumerable<CodeInstruction> HandleAutostackableItems(IEnumerable<CodeInstruction> instructionList, ILGenerator ilg)
{
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Expected O, but got Unknown
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Expected O, but got Unknown
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected O, but got Unknown
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Expected O, but got Unknown
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Expected O, but got Unknown
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Expected O, but got Unknown
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Expected O, but got Unknown
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Expected O, but got Unknown
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Expected O, but got Unknown
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Expected O, but got Unknown
List<CodeInstruction> list = instructionList.ToList();
FieldInfo fieldInfo = AccessTools.DeclaredField(typeof(ItemData), "m_stack");
FieldInfo fieldInfo2 = AccessTools.DeclaredField(typeof(ItemDrop), "m_itemData");
Label? label = default(Label?);
for (int i = 0; i < list.Count; i++)
{
if (!CodeInstructionExtensions.StoresField(list[i], fieldInfo))
{
continue;
}
for (int num = i; num > 0; num--)
{
if (CodeInstructionExtensions.Branches(list[num], ref label))
{
for (int num2 = num; num2 > 0; num2--)
{
if (CodeInstructionExtensions.LoadsField(list[num2], fieldInfo2, false))
{
LocalBuilder localBuilder = ilg.DeclareLocal(typeof(Dictionary<string, string>));
LocalBuilder localBuilder2 = ilg.DeclareLocal(typeof(ItemData));
list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ItemInfo), "ApplyCustomItemDataStackableAutoStack", (Type[])null, (Type[])null)));
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldloc, (object)localBuilder.LocalIndex));
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
list.Insert(num + 1, new CodeInstruction(OpCodes.Brfalse, (object)label));
list.Insert(num + 1, new CodeInstruction(OpCodes.Stloc, (object)localBuilder.LocalIndex));
list.Insert(num + 1, new CodeInstruction(OpCodes.Dup, (object)localBuilder.LocalIndex));
list.Insert(num + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ItemInfo), "IsStackableItemDrop", (Type[])null, (Type[])null)));
list.Insert(num + 1, new CodeInstruction(OpCodes.Ldloc, (object)localBuilder2.LocalIndex));
list.Insert(num + 1, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
list.Insert(num2 + 1, new CodeInstruction(OpCodes.Stloc, (object)localBuilder2.LocalIndex));
list.Insert(num2 + 1, new CodeInstruction(OpCodes.Dup, (object)null));
return list;
}
}
}
}
}
throw new Exception("Found no stack store in a branch");
}
private static IEnumerable<CodeInstruction> TransferCustomItemDataOnUpgrade(IEnumerable<CodeInstruction> instructions, ILGenerator ilg)
{
MethodInfo itemDeleter = AccessTools.DeclaredMethod(typeof(Inventory), "RemoveItem", new Type[1] { typeof(ItemData) }, (Type[])null);
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode == OpCodes.Callvirt && CodeInstructionExtensions.OperandIs(instruction, (MemberInfo)itemDeleter))
{
yield return new CodeInstruction(OpCodes.Dup, (object)null);
yield return new CodeInstruction(OpCodes.Stsfld, (object)AccessTools.DeclaredField(typeof(ItemInfo), "currentlyUpgradingItem"));
}
yield return instruction;
}
}
private static void ResetCurrentlyUpgradingItem()
{
currentlyUpgradingItem = null;
}
private static void CopyCustomDataFromUpgradedItem(ItemDrop item)
{
if (currentlyUpgradingItem != null)
{
item.m_itemData.m_customData = currentlyUpgradingItem.m_customData;
ItemInfo itemInfo = currentlyUpgradingItem.Data();
ItemExtensions.itemInfo.Remove(currentlyUpgradingItem);
ItemExtensions.itemInfo.Add(item.m_itemData, itemInfo);
item.m_itemData.m_quality = currentlyUpgradingItem.m_quality + 1;
item.m_itemData.m_variant = currentlyUpgradingItem.m_variant;
itemInfo.ItemData = item.m_itemData;
itemInfo.LoadAll();
foreach (ItemData value in itemInfo.data.Values)
{
value.Upgraded();
}
currentlyUpgradingItem = null;
awakeningItem = null;
return;
}
GameObject dropPrefab = item.m_itemData.m_dropPrefab;
if (dropPrefab == null || item.m_itemData.m_customData.Count != 0)
{
return;
}
ZNetView component = ((Component)item).GetComponent<ZNetView>();
ZDO val = ((Object.op_Implicit((Object)(object)component) && component.IsValid()) ? component.GetZDO() : null);
if (val != null && val.GetInt(ZDOVars.s_dataCount, -1) != -1)
{
return;
}
item.m_itemData.m_customData = new Dictionary<string, string>(dropPrefab.GetComponent<ItemDrop>().m_itemData.m_customData);
if (val == null)
{
return;
}
int num = 0;
val.Set(ZDOVars.s_dataCount, item.m_itemData.m_customData.Count, false);
foreach (KeyValuePair<string, string> customDatum in item.m_itemData.m_customData)
{
val.Set($"data_{num}", customDatum.Key);
val.Set($"data__{num++}", customDatum.Value);
}
}
private static IEnumerable<CodeInstruction> ImportCustomDataOnUpgrade(IEnumerable<CodeInstruction> instructionList)
{
List<CodeInstruction> list = instructionList.ToList();
foreach (CodeInstruction instruction in list)
{
yield return instruction;
if (instruction.opcode == OpCodes.Stfld && CodeInstructionExtensions.OperandIs(instruction, (MemberInfo)AccessTools.DeclaredField(typeof(ItemData), "m_dropPrefab")))
{
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ItemInfo), "CopyCustomDataFromUpgradedItem", (Type[])null, (Type[])null));
}
}
}
private static void TrackAwakeningItem(ItemDrop __instance)
{
if (ZNetView.m_forceDisableInit)
{
awakeningItem = __instance.m_itemData;
}
}
static ItemInfo()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Expected O, but got Unknown
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Expected O, but got Unknown
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Expected O, but got Unknown
//IL_01d0: Expected O, but got Unknown
//IL_021d: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Expected O, but got Unknown
//IL_023f: Expected O, but got Unknown
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Expected O, but got Unknown
//IL_02a1: Expected O, but got Unknown
//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
//IL_02dd: Expected O, but got Unknown
//IL_030b: Unknown result type (might be due to invalid IL or missing references)
//IL_0312: Expected O, but got Unknown
//IL_0328: Unknown result type (might be due to invalid IL or missing references)
//IL_0343: Unknown result type (might be due to invalid IL or missing references)
//IL_0351: Expected O, but got Unknown
//IL_0351: Expected O, but got Unknown
//IL_0381: Unknown result type (might be due to invalid IL or missing references)
//IL_038d: Expected O, but got Unknown
//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
//IL_03e3: Expected O, but got Unknown
//IL_03e3: Expected O, but got Unknown
//IL_0434: Unknown result type (might be due to invalid IL or missing references)
//IL_0441: Expected O, but got Unknown
//IL_0494: Unknown result type (might be due to invalid IL or missing references)
//IL_04a1: Expected O, but got Unknown
//IL_054d: Unknown result type (might be due to invalid IL or missing references)
//IL_055a: Expected O, but got Unknown
//IL_0588: Unknown result type (might be due to invalid IL or missing references)
//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
//IL_05ba: Expected O, but got Unknown
//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
//IL_05ee: Expected O, but got Unknown
//IL_05ee: Expected O, but got Unknown
//IL_062d: Unknown result type (might be due to invalid IL or missing references)
//IL_063a: Expected O, but got Unknown
//IL_0668: Unknown result type (might be due to invalid IL or missing references)
//IL_0693: Unknown result type (might be due to invalid IL or missing references)
//IL_06a0: Expected O, but got Unknown
//IL_06a0: Expected O, but got Unknown
//IL_06df: Unknown result type (might be due to invalid IL or missing references)
//IL_06ec: Expected O, but got Unknown
ForceLoadTypes = new HashSet<Type>();
typeInheritorsCache = new Dictionary<Type, HashSet<Type>>();
knownTypes = new HashSet<string>();
awakeningItem = null;
primaryAssembly = Assembly.GetExecutingAssembly();
assemblyNameCache = new Dictionary<Assembly, string>();
classKeyCache = new Dictionary<Type, string>();
removeMethod = typeof(ItemInfo).GetMethods().Single((MethodInfo m) => m.Name == "Remove" && m.IsGenericMethod && m.GetParameters()[0].ParameterType == typeof(string));
Harmony val = new Harmony("org.bepinex.helpers.ItemDataManager");
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Inventory), "Save", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "SaveInventoryPrefix", (Type[])null, (Type[])null), 800, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
foreach (MethodInfo item in from m in typeof(ItemData).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
where m.Name == "SaveToZDO"
select m)
{
val.Patch((MethodBase)item, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "SavePrefix", (Type[])null, (Type[])null), 800, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Inventory), "AddItem", new Type[4]
{
typeof(ItemData),
typeof(int),
typeof(int),
typeof(int)
}, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "CheckItemDataStackableAddItem", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ApplyCustomItemDataStackableAddItem", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Inventory), "CanAddItem", new Type[2]
{
typeof(ItemData),
typeof(int)
}, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "SaveCheckingForStackableItemData", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ItemInfo), "ResetCheckingForStackableItemData", (Type[])null), (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Inventory), "AddItem", new Type[1] { typeof(ItemData) }, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "SaveCheckingForStackableItemData", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ItemInfo), "ResetCheckingForStackableItemData", (Type[])null), (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Inventory), "FindFreeStackSpace", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "CheckStackableInFindFreeStackMethods", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(Inventory), "FindFreeStackItem", (Type[])null, (Type[])null);
HarmonyMethod val2 = new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "CheckStackableInFindFreeStackMethods", (Type[])null, (Type[])null));
val.Patch((MethodBase)methodInfo, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ResetNewValuesOnStackable", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ApplyNewValuesOnStackable", (Type[])null, (Type[])null)), val2, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ItemDrop), "AutoStackItems", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "HandleAutostackableItems", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(InventoryGui), "DoCrafting", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "TransferCustomItemDataOnUpgrade", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ResetCurrentlyUpgradingItem", (Type[])null, (Type[])null)), (HarmonyMethod)null);
foreach (MethodInfo item2 in from m in typeof(ItemData).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
where m.Name == "LoadFromZDO"
select m)
{
val.Patch((MethodBase)item2, (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "RegisterForceLoadedTypes", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Player), "Load", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "RegisterForceLoadedTypesOnPlayerLoaded", (Type[])null, (Type[])null), 700, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Inventory), "AddItem", new Type[8]
{
typeof(string),
typeof(int),
typeof(int),
typeof(int),
typeof(long),
typeof(string),
typeof(Vector2i),
typeof(bool)
}, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "RegisterForceLoadedTypesAddItem", (Type[])null, (Type[])null), 800, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo methodInfo2 = AccessTools.DeclaredMethod(typeof(ItemDrop), "Awake", (Type[])null, (Type[])null);
HarmonyMethod val3 = new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "TrackAwakeningItem", (Type[])null, (Type[])null));
val2 = new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ImportCustomDataOnUpgrade", (Type[])null, (Type[])null), 800, (string[])null, (string[])null, (bool?)null);
val.Patch((MethodBase)methodInfo2, val3, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ItemDropAwake", (Type[])null, (Type[])null), 800, (string[])null, (string[])null, (bool?)null), val2, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ItemDrop), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ItemDropAwakeDelayed", (Type[])null, (Type[])null), 799, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ItemData), "Clone", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ItemDataClonePrefix", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ItemDataClonePostfix", (Type[])null, (Type[])null), 500, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ItemData), "Clone", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ItemInfo), "ItemDataClonePostfixDelayed", (Type[])null, (Type[])null), 499, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
[PublicAPI]
public class ForeignItemInfo : IEnumerable<object>, IEnumerable
{
private readonly object foreignItemInfo;
public string Mod => ((string)foreignItemInfo.GetType().GetProperty("Mod")?.GetValue(foreignItemInfo)) ?? "";
public ItemData ItemData { get; private set; }
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public string this[string key]
{
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
get
{
object obj = foreignItemInfo.GetType().InvokeMember("Item", BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty, null, foreignItemInfo, new object[1] { key });
if (obj != null)
{
return (string)obj.GetType().GetProperty("Value")?.GetValue(obj);
}
return null;
}
[param: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
set
{
foreignItemInfo.GetType().GetMethod("set_Item", BindingFlags.Instance | BindingFlags.Public)?.Invoke(foreignItemInfo, new object[2] { key, value });
}
}
internal ForeignItemInfo(ItemData itemData, object foreignItemInfo)
{
ItemData = itemData;
this.foreignItemInfo = foreignItemInfo;
}
public T GetOrCreate<T>(string key = "") where T : class, new()
{
return Add<T>(key) ?? Get<T>(key);
}
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
private object call([<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(0)] string name, [<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 0, 2 })] object[] values, [<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 0, 2 })] Type[] args, Type generic = null)
{
MethodInfo[] methods = foreignItemInfo.GetType().GetMethods();
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.Name == name && (from p in methodInfo.GetParameters()
select (!p.ParameterType.IsGenericParameter) ? p.ParameterType : null).SequenceEqual(args) && (object)generic != null == methodInfo.IsGenericMethod)
{
MethodInfo methodInfo2 = methodInfo;
if ((object)generic != null)
{
methodInfo2 = methodInfo2.MakeGenericMethod(generic);
}
return methodInfo2.Invoke(foreignItemInfo, values);
}
}
return null;
}
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public T Add<T>(string key = "") where T : class, new()
{
return call("Add", new object[1] { key }, new Type[1] { typeof(string) }, typeof(T)) as T;
}
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public T Get<T>(string key = "") where T : class
{
return call("Get", new object[1] { key }, new Type[1] { typeof(string) }, typeof(T)) as T;
}
public Dictionary<string, T> GetAll<T>() where T : class
{
return ((call("GetAll", Array.Empty<object>(), Array.Empty<Type>(), typeof(T)) as T) as Dictionary<string, T>) ?? new Dictionary<string, T>();
}
public bool Remove(string key = "")
{
return (call("Add", new object[1] { key }, new Type[1] { typeof(string) }) as bool?).GetValueOrDefault();
}
public bool Remove<T>(string key = "") where T : class
{
return (call("Remove", new object[1] { key }, new Type[1] { typeof(string) }, typeof(T)) as bool?).GetValueOrDefault();
}
public bool Remove<T>(T itemData) where T : class
{
return (call("Remove", new object[1] { itemData }, new Type[1], typeof(T)) as bool?).GetValueOrDefault();
}
public void Save()
{
call("Save", Array.Empty<object>(), Array.Empty<Type>());
}
public void LoadAll()
{
call("LoadAll", Array.Empty<object>(), Array.Empty<Type>());
}
public IEnumerator<object> GetEnumerator()
{
return (IEnumerator<object>)((call("GetEnumerator", Array.Empty<object>(), Array.Empty<Type>()) as IEnumerator<object>) ?? ((object)new List<object>().GetEnumerator()));
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
[PublicAPI]
public static class ItemExtensions
{
private const string className = "ItemDataManager.ItemExtensions";
internal static readonly ConditionalWeakTable<ItemData, ItemInfo> itemInfo = new ConditionalWeakTable<ItemData, ItemInfo>();
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 0, 0, 0, 0, 2 })]
private static readonly ConditionalWeakTable<ItemData, Dictionary<string, ForeignItemInfo>> foreignItemInfo = new ConditionalWeakTable<ItemData, Dictionary<string, ForeignItemInfo>>();
public static ItemInfo Data(this ItemData item)
{
if (itemInfo.TryGetValue(item, out var value))
{
return value;
}
itemInfo.Add(item, value = new ItemInfo(item));
return value;
}
[return: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public static ForeignItemInfo Data(this ItemData item, string mod)
{
Dictionary<string, ForeignItemInfo> orCreateValue = ItemExtensions.foreignItemInfo.GetOrCreateValue(item);
if (orCreateValue.TryGetValue(mod, out var value))
{
return value;
}
if (!Chainloader.PluginInfos.TryGetValue(mod, out var value2))
{
return null;
}
object obj = ((object)value2.Instance).GetType().Assembly.GetType("ItemDataManager.ItemExtensions")?.GetMethod("Data", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(ItemData) }, Array.Empty<ParameterModifier>())?.Invoke(null, new object[1] { item });
if (obj != null)
{
return orCreateValue[mod] = new ForeignItemInfo(item, obj);
}
Debug.LogWarning((object)("Mod " + mod + " has an ItemDataManager.ItemExtensions class, but no Data(ItemDrop.ItemData) method could be called on it."));
return orCreateValue[mod] = null;
}
}
}
namespace SkillManager
{
[PublicAPI]
public class Skill
{
public static class LocalizationCache
{
private static readonly Dictionary<string, Localization> localizations = new Dictionary<string, Localization>();
internal static void LocalizationPostfix(Localization __instance, string language)
{
string key = localizations.FirstOrDefault((KeyValuePair<string, Localization> l) => l.Value == __instance).Key;
if (key != null)
{
localizations.Remove(key);
}
if (!localizations.ContainsKey(language))
{
localizations.Add(language, __instance);
}
}
public static Localization ForLanguage([<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)] string language = null)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
if (localizations.TryGetValue(language ?? PlayerPrefs.GetString("language", "English"), out var value))
{
return value;
}
value = new Localization();
if (language != null)
{
value.SetupLanguage(language);
}
return value;
}
}
[PublicAPI]
public class LocalizeKey
{
private static readonly List<LocalizeKey> keys = new List<LocalizeKey>();
public readonly string Key;
public readonly Dictionary<string, string> Localizations = new Dictionary<string, string>();
public LocalizeKey(string key)
{
Key = key.Replace("$", "");
}
public void Alias(string alias)
{
Localizations.Clear();
if (!alias.Contains("$"))
{
alias = "$" + alias;
}
Localizations["alias"] = alias;
Localization.instance.AddWord(Key, Localization.instance.Localize(alias));
}
public LocalizeKey English(string key)
{
return addForLang("English", key);
}
public LocalizeKey Swedish(string key)
{
return addForLang("Swedish", key);
}
public LocalizeKey French(string key)
{
return addForLang("French", key);
}
public LocalizeKey Italian(string key)
{
return addForLang("Italian", key);
}
public LocalizeKey German(string key)
{
return addForLang("German", key);
}
public LocalizeKey Spanish(string key)
{
return addForLang("Spanish", key);
}
public LocalizeKey Russian(string key)
{
return addForLang("Russian", key);
}
public LocalizeKey Romanian(string key)
{
return addForLang("Romanian", key);
}
public LocalizeKey Bulgarian(string key)
{
return addForLang("Bulgarian", key);
}
public LocalizeKey Macedonian(string key)
{
return addForLang("Macedonian", key);
}
public LocalizeKey Finnish(string key)
{
return addForLang("Finnish", key);
}
public LocalizeKey Danish(string key)
{
return addForLang("Danish", key);
}
public LocalizeKey Norwegian(string key)
{
return addForLang("Norwegian", key);
}
public LocalizeKey Icelandic(string key)
{
return addForLang("Icelandic", key);
}
public LocalizeKey Turkish(string key)
{
return addForLang("Turkish", key);
}
public LocalizeKey Lithuanian(string key)
{
return addForLang("Lithuanian", key);
}
public LocalizeKey Czech(string key)
{
return addForLang("Czech", key);
}
public LocalizeKey Hungarian(string key)
{
return addForLang("Hungarian", key);
}
public LocalizeKey Slovak(string key)
{
return addForLang("Slovak", key);
}
public LocalizeKey Polish(string key)
{
return addForLang("Polish", key);
}
public LocalizeKey Dutch(string key)
{
return addForLang("Dutch", key);
}
public LocalizeKey Portuguese_European(string key)
{
return addForLang("Portuguese_European", key);
}
public LocalizeKey Portuguese_Brazilian(string key)
{
return addForLang("Portuguese_Brazilian", key);
}
public LocalizeKey Chinese(string key)
{
return addForLang("Chinese", key);
}
public LocalizeKey Japanese(string key)
{
return addForLang("Japanese", key);
}
public LocalizeKey Korean(string key)
{
return addForLang("Korean", key);
}
public LocalizeKey Hindi(string key)
{
return addForLang("Hindi", key);
}
public LocalizeKey Thai(string key)
{
return addForLang("Thai", key);
}
public LocalizeKey Abenaki(string key)
{
return addForLang("Abenaki", key);
}
public LocalizeKey Croatian(string key)
{
return addForLang("Croatian", key);
}
public LocalizeKey Georgian(string key)
{
return addForLang("Georgian", key);
}
public LocalizeKey Greek(string key)
{
return addForLang("Greek", key);
}
public LocalizeKey Serbian(string key)
{
return addForLang("Serbian", key);
}
public LocalizeKey Ukrainian(string key)
{
return addForLang("Ukrainian", key);
}
private LocalizeKey addForLang(string lang, string value)
{
Localizations[lang] = value;
if (Localization.instance.GetSelectedLanguage() == lang)
{
Localization.instance.AddWord(Key, value);
}
else if (lang == "English" && !Localization.instance.m_translations.ContainsKey(Key))
{
Localization.instance.AddWord(Key, value);
}
return this;
}
[HarmonyPriority(300)]
internal static void AddLocalizedKeys(Localization __instance, string language)
{
foreach (LocalizeKey key in keys)
{
string value2;
if (key.Localizations.TryGetValue(language, out var value) || key.Localizations.TryGetValue("English", out value))
{
__instance.AddWord(key.Key, value);
}
else if (key.Localizations.TryGetValue("alias", out value2))
{
Localization.instance.AddWord(key.Key, Localization.instance.Localize(value2));
}
}
}
}
private class ConfigurationManagerAttributes
{
[UsedImplicitly]
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public string Category;
}
[HarmonyPatch(typeof(Skills), "IsSkillValid")]
private static class Patch_Skills_IsSkillValid
{
private static void Postfix(SkillType type, ref bool __result)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
if (!__result && skills.ContainsKey(type))
{
__result = true;
}
}
}
private static readonly Dictionary<SkillType, Skill> skills;
internal static readonly Dictionary<string, Skill> skillByName;
private readonly string skillName;
private readonly string internalSkillName;
private readonly SkillDef skillDef;
public readonly LocalizeKey Name;
public readonly LocalizeKey Description;
private float skillEffectFactor = 1f;
private int skillLoss = 5;
public bool Configurable;
private static bool InitializedTerminal;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private static Localization _english;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private static BaseUnityPlugin _plugin;
private static bool hasConfigSync;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private static object _configSync;
public float SkillGainFactor
{
get
{
return skillDef.m_increseStep;
}
set
{
skillDef.m_increseStep = value;
this.SkillGainFactorChanged?.Invoke(value);
}
}
public float SkillEffectFactor
{
get
{
return skillEffectFactor;
}
set
{
skillEffectFactor = value;
this.SkillEffectFactorChanged?.Invoke(value);
}
}
public int SkillLoss
{
get
{
return skillLoss;
}
set
{
skillLoss = value;
this.SkillLossChanged?.Invoke(value);
}
}
private static Localization english => _english ?? (_english = LocalizationCache.ForLanguage("English"));
private static BaseUnityPlugin plugin
{
get
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
object obj = _plugin;
if (obj == null)
{
BaseUnityPlugin val = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)Assembly.GetExecutingAssembly().DefinedTypes.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
_plugin = val;
obj = (object)val;
}
return (BaseUnityPlugin)obj;
}
}
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private static object configSync
{
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
get
{
if (_configSync == null && hasConfigSync)
{
Type type = Assembly.GetExecutingAssembly().GetType("ServerSync.ConfigSync");
if ((object)type != null)
{
_configSync = Activator.CreateInstance(type, plugin.Info.Metadata.GUID + " SkillManager");
type.GetField("CurrentVersion").SetValue(_configSync, plugin.Info.Metadata.Version.ToString());
type.GetProperty("IsLocked").SetValue(_configSync, true);
}
else
{
hasConfigSync = false;
}
}
return _configSync;
}
}
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
[method: <3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
[field: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public event Action<float> SkillGainFactorChanged;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
[method: <3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
[field: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public event Action<float> SkillEffectFactorChanged;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
[method: <3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
[field: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public event Action<float> SkillLossChanged;
public Skill(string englishName, string icon)
: this(englishName, loadSprite(icon, 64, 64))
{
}
public Skill(string englishName, Sprite icon)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: 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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Expected O, but got Unknown
SkillType val = fromName(englishName);
string text = new Regex("[^a-zA-Z]").Replace(englishName, "_");
skills[val] = this;
skillByName[englishName] = this;
skillDef = new SkillDef
{
m_description = "$skilldesc_" + text,
m_icon = icon,
m_increseStep = 1f,
m_skill = val
};
internalSkillName = text;
skillName = englishName;
Name = new LocalizeKey("skill_" + ((object)(SkillType)(ref val)).ToString()).English(englishName);
Description = new LocalizeKey("skilldesc_" + text);
}
public static SkillType fromName(string englishName)
{
return (SkillType)Math.Abs(StringExtensionMethods.GetStableHashCode(englishName));
}
static Skill()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Expected O, but got Unknown
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Expected O, but got Unknown
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Expected O, but got Unknown
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Expected O, but got Unknown
//IL_01ab: Expected O, but got Unknown
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Expected O, but got Unknown
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Expected O, but got Unknown
//IL_023c: Expected O, but got Unknown
skills = new Dictionary<SkillType, Skill>();
skillByName = new Dictionary<string, Skill>();
InitializedTerminal = false;
hasConfigSync = true;
Harmony val = new Harmony("org.bepinex.helpers.skillmanager");
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Skill), "Patch_FejdStartup", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Skills), "GetSkillDef", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Skill), "Patch_Skills_GetSkillDef", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Skills), "CheatRaiseSkill", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Skill), "Patch_Skills_CheatRaiseskill", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Skills), "CheatResetSkill", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Skill), "Patch_Skills_CheatResetSkill", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(LocalizeKey), "AddLocalizedKeys", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Terminal), "InitTerminal", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Skill), "Patch_Terminal_InitTerminal_Prefix", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Skill), "Patch_Terminal_InitTerminal", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "SetupLanguage", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(LocalizationCache), "LocalizationPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Skills), "OnDeath", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Skill), "Patch_Skills_OnDeath_Prefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Skill), "Patch_Skills_OnDeath_Finalizer", (Type[])null, (Type[])null)), (HarmonyMethod)null);
}
private static void Patch_FejdStartup()
{
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Expected O, but got Unknown
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Expected O, but got Unknown
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Expected O, but got Unknown
foreach (Skill skill in skills.Values)
{
if (skill.Configurable)
{
string key = skill.Name.Key;
string group = new Regex("['[\"\\]]").Replace(english.Localize(key), "").Trim();
string category = Localization.instance.Localize(key).Trim();
ConfigEntry<float> skillGain = config(group, "Skill gain factor", skill.SkillGainFactor, new ConfigDescription("The rate at which you gain experience for the skill.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 5f), new object[1]
{
new ConfigurationManagerAttributes
{
Category = category
}
}));
skill.SkillGainFactor = skillGain.Value;
skillGain.SettingChanged += delegate
{
skill.SkillGainFactor = skillGain.Value;
};
ConfigEntry<float> skillEffect = config(group, "Skill effect factor", skill.SkillEffectFactor, new ConfigDescription("The power of the skill, based on the default power.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 5f), new object[1]
{
new ConfigurationManagerAttributes
{
Category = category
}
}));
skill.SkillEffectFactor = skillEffect.Value;
skillEffect.SettingChanged += delegate
{
skill.SkillEffectFactor = skillEffect.Value;
};
ConfigEntry<int> skillLoss = config(group, "Skill loss", skill.skillLoss, new ConfigDescription("How much experience to lose on death.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[1]
{
new ConfigurationManagerAttributes
{
Category = category
}
}));
skill.skillLoss = skillLoss.Value;
skillLoss.SettingChanged += delegate
{
skill.skillLoss = skillLoss.Value;
};
}
}
}
private static void Patch_Skills_GetSkillDef([<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)] ref SkillDef __result, List<SkillDef> ___m_skills, SkillType type)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
if (__result == null)
{
SkillDef val = GetSkillDef(type);
if (val != null)
{
___m_skills.Add(val);
__result = val;
}
}
}
private static bool Patch_Skills_CheatRaiseskill(Skills __instance, string name, float value, Player ___m_player)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
foreach (SkillType key in skills.Keys)
{
SkillType current = key;
Skill skill = skills[current];
if (string.Equals(skill.internalSkillName, name, StringComparison.CurrentCultureIgnoreCase))
{
Skill skill2 = __instance.GetSkill(current);
skill2.m_level += value;
skill2.m_level = Mathf.Clamp(skill2.m_level, 0f, 100f);
((Character)___m_player).Message((MessageType)1, "Skill increased " + Localization.instance.Localize("$skill_" + ((object)(SkillType)(ref current)).ToString()) + ": " + (int)skill2.m_level, 0, skill2.m_info.m_icon);
Console.instance.Print("Skill " + skill.internalSkillName + " = " + skill2.m_level);
return false;
}
}
return true;
}
private static bool Patch_Skills_CheatResetSkill(Skills __instance, string name)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
foreach (SkillType key in skills.Keys)
{
Skill skill = skills[key];
if (string.Equals(skill.internalSkillName, name, StringComparison.CurrentCultureIgnoreCase))
{
__instance.ResetSkill(key);
Console.instance.Print("Skill " + skill.internalSkillName + " reset");
return false;
}
}
return true;
}
private static void Patch_Skills_OnDeath_Prefix(Skills __instance, [<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0 })] ref Dictionary<SkillType, Skill> __state)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
if (__state == null)
{
__state = new Dictionary<SkillType, Skill>();
}
foreach (KeyValuePair<SkillType, Skill> skill in skills)
{
if (__instance.m_skillData.TryGetValue(skill.Key, out var value))
{
__state[skill.Key] = value;
if (skill.Value.skillLoss > 0)
{
Skill obj = value;
obj.m_level -= value.m_level * (float)skill.Value.SkillLoss / 100f;
value.m_accumulator = 0f;
}
__instance.m_skillData.Remove(skill.Key);
}
}
}
private static void Patch_Skills_OnDeath_Finalizer(Skills __instance, [<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0 })] ref Dictionary<SkillType, Skill> __state)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
if (__state == null)
{
return;
}
foreach (KeyValuePair<SkillType, Skill> item in __state)
{
__instance.m_skillData[item.Key] = item.Value;
}
__state = null;
}
private static void Patch_Terminal_InitTerminal_Prefix()
{
InitializedTerminal = Terminal.m_terminalInitialized;
}
private static void Patch_Terminal_InitTerminal()
{
if (!InitializedTerminal)
{
AddSkill(Terminal.commands["raiseskill"]);
AddSkill(Terminal.commands["resetskill"]);
}
static void AddSkill(ConsoleCommand command)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
ConsoleOptionsFetcher fetcher = command.m_tabOptionsFetcher;
command.m_tabOptionsFetcher = (ConsoleOptionsFetcher)delegate
{
List<string> list = fetcher.Invoke();
list.AddRange(skills.Values.Select((Skill skill) => skill.internalSkillName));
return list;
};
}
}
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
private static SkillDef GetSkillDef(SkillType skillType)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (!skills.ContainsKey(skillType))
{
return null;
}
return skills[skillType].skillDef;
}
private static byte[] ReadEmbeddedFileBytes(string name)
{
using MemoryStream memoryStream = new MemoryStream();
Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + "." + name).CopyTo(memoryStream);
return memoryStream.ToArray();
}
private static Texture2D loadTexture(string name)
{
//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_001d: Expected O, but got Unknown
//IL_001f: Expected O, but got Unknown
Texture2D val = new Texture2D(0, 0);
ImageConversion.LoadImage(val, ReadEmbeddedFileBytes("icons." + name));
return val;
}
private static Sprite loadSprite(string name, int width, int height)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
return Sprite.Create(loadTexture(name), new Rect(0f, 0f, (float)width, (float)height), Vector2.zero);
}
private static ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description)
{
ConfigEntry<T> val = plugin.Config.Bind<T>(group, name, value, description);
configSync?.GetType().GetMethod("AddConfigEntry").MakeGenericMethod(typeof(T))
.Invoke(configSync, new object[1] { val });
return val;
}
private static ConfigEntry<T> config<T>(string group, string name, T value, string description)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
}
}
[PublicAPI]
public static class SkillExtensions
{
public static float GetSkillFactor(this Character character, string name)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return character.GetSkillFactor(Skill.fromName(name)) * Skill.skillByName[name].SkillEffectFactor;
}
public static float GetSkillFactor(this Skills skills, string name)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return skills.GetSkillFactor(Skill.fromName(name)) * Skill.skillByName[name].SkillEffectFactor;
}
public static void RaiseSkill(this Character character, string name, float value = 1f)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
character.RaiseSkill(Skill.fromName(name), value);
}
public static void RaiseSkill(this Skills skill, string name, float value = 1f)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
skill.RaiseSkill(Skill.fromName(name), value);
}
public static void LowerSkill(this Character character, string name, float factor = 1f)
{
character.GetSkills().LowerSkill(name, factor);
}
public static void LowerSkill(this Skills skills, string name, float factor)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
if (factor > 0f && skills.m_skillData.TryGetValue(Skill.fromName(name), out var value))
{
Skill obj = value;
obj.m_level -= value.m_level * factor;
value.m_accumulator = 0f;
}
}
}
}
namespace ServerSync
{
[PublicAPI]
public abstract class OwnConfigEntryBase
{
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public object LocalBaseValue;
public bool SynchronizedConfig = true;
public abstract ConfigEntryBase BaseConfig { get; }
}
[PublicAPI]
public class SyncedConfigEntry<T> : OwnConfigEntryBase
{
public readonly ConfigEntry<T> SourceConfig;
public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig;
public T Value
{
get
{
return SourceConfig.Value;
}
set
{
SourceConfig.Value = value;
}
}
public SyncedConfigEntry(ConfigEntry<T> sourceConfig)
{
SourceConfig = sourceConfig;
}
public void AssignLocalValue(T value)
{
if (LocalBaseValue == null)
{
Value = value;
}
else
{
LocalBaseValue = value;
}
}
}
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(0)]
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
public abstract class CustomSyncedValueBase
{
public Action ValueChanged;
public object LocalBaseValue;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(0)]
public readonly string Identifier;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(0)]
public readonly Type Type;
private object boxedValue;
protected bool localIsOwner;
public readonly int Priority;
public object BoxedValue
{
get
{
return boxedValue;
}
set
{
boxedValue = value;
ValueChanged?.Invoke();
}
}
[<3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(0)]
protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority)
{
Priority = priority;
Identifier = identifier;
Type = type;
configSync.AddCustomValue(this);
localIsOwner = configSync.IsSourceOfTruth;
configSync.SourceOfTruthChanged += delegate(bool truth)
{
localIsOwner = truth;
};
}
}
[PublicAPI]
public sealed class CustomSyncedValue<T> : CustomSyncedValueBase
{
public T Value
{
get
{
return (T)base.BoxedValue;
}
set
{
base.BoxedValue = value;
}
}
public void Update()
{
ValueChanged?.Invoke();
}
public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0)
: base(configSync, identifier, typeof(T), priority)
{
Value = value;
}
public void AssignLocalValue(T value)
{
if (localIsOwner)
{
Value = value;
}
else
{
LocalBaseValue = value;
}
}
}
internal class ConfigurationManagerAttributes
{
[UsedImplicitly]
public bool? ReadOnly = false;
}
[PublicAPI]
public class ConfigSync
{
[HarmonyPatch(typeof(ZRpc), "HandlePackage")]
private static class SnatchCurrentlyHandlingRPC
{
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public static ZRpc currentRpc;
[HarmonyPrefix]
private static void Prefix(ZRpc __instance)
{
currentRpc = __instance;
}
}
[HarmonyPatch(typeof(ZNet), "Awake")]
internal static class RegisterRPCPatch
{
[HarmonyPostfix]
private static void Postfix(ZNet __instance)
{
isServer = __instance.IsServer();
foreach (ConfigSync configSync2 in configSyncs)
{
ZRoutedRpc.instance.Register<ZPackage>(configSync2.Name + " ConfigSync", (Action<long, ZPackage>)configSync2.RPC_FromOtherClientConfigSync);
if (isServer)
{
configSync2.InitialSyncDone = true;
Debug.Log((object)("Registered '" + configSync2.Name + " ConfigSync' RPC - waiting for incoming connections"));
}
}
if (isServer)
{
((MonoBehaviour)__instance).StartCoroutine(WatchAdminListChanges());
}
static void SendAdmin(List<ZNetPeer> peers, bool isAdmin)
{
ZPackage package = ConfigsToPackage(null, null, new PackageEntry[1]
{
new PackageEntry
{
section = "Internal",
key = "lockexempt",
type = typeof(bool),
value = isAdmin
}
});
ConfigSync configSync = configSyncs.First();
if (configSync != null)
{
((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package));
}
}
static IEnumerator WatchAdminListChanges()
{
MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null);
SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance);
List<string> CurrentList = new List<string>(adminList.GetList());
while (true)
{
yield return (object)new WaitForSeconds(30f);
if (!adminList.GetList().SequenceEqual(CurrentList))
{
CurrentList = new List<string>(adminList.GetList());
List<ZNetPeer> list = ZNet.instance.GetPeers().Where(delegate(ZNetPeer p)
{
string hostName = p.m_rpc.GetSocket().GetHostName();
return ((object)listContainsId != null) ? ((bool)listContainsId.Invoke(ZNet.instance, new object[2] { adminList, hostName })) : adminList.Contains(hostName);
}).ToList();
SendAdmin(ZNet.instance.GetPeers().Except(list).ToList(), isAdmin: false);
SendAdmin(list, isAdmin: true);
}
}
}
}
}
[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
private static class RegisterClientRPCPatch
{
[HarmonyPostfix]
private static void Postfix(ZNet __instance, ZNetPeer peer)
{
if (__instance.IsServer())
{
return;
}
foreach (ConfigSync configSync in configSyncs)
{
peer.m_rpc.Register<ZPackage>(configSync.Name + " ConfigSync", (Action<ZRpc, ZPackage>)configSync.RPC_FromServerConfigSync);
}
}
}
private class ParsedConfigs
{
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 0, 0, 2 })]
public readonly Dictionary<OwnConfigEntryBase, object> configValues = new Dictionary<OwnConfigEntryBase, object>();
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 0, 0, 2 })]
public readonly Dictionary<CustomSyncedValueBase, object> customValues = new Dictionary<CustomSyncedValueBase, object>();
}
[HarmonyPatch(typeof(ZNet), "Shutdown")]
private class ResetConfigsOnShutdown
{
[HarmonyPostfix]
private static void Postfix()
{
ProcessingServerUpdate = true;
foreach (ConfigSync configSync in configSyncs)
{
configSync.resetConfigsFromServer();
configSync.IsSourceOfTruth = true;
configSync.InitialSyncDone = false;
}
ProcessingServerUpdate = false;
}
}
[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
private class SendConfigsAfterLogin
{
private class BufferingSocket : ISocket
{
public volatile bool finished;
public volatile int versionMatchQueued = -1;
public readonly List<ZPackage> Package = new List<ZPackage>();
public readonly ISocket Original;
public BufferingSocket(ISocket original)
{
Original = original;
}
public bool IsConnected()
{
return Original.IsConnected();
}
public ZPackage Recv()
{
return Original.Recv();
}
public int GetSendQueueSize()
{
return Original.GetSendQueueSize();
}
public int GetCurrentSendRate()
{
return Original.GetCurrentSendRate();
}
public bool IsHost()
{
return Original.IsHost();
}
public void Dispose()
{
Original.Dispose();
}
public bool GotNewData()
{
return Original.GotNewData();
}
public void Close()
{
Original.Close();
}
public string GetEndPointString()
{
return Original.GetEndPointString();
}
public void GetAndResetStats(out int totalSent, out int totalRecv)
{
Original.GetAndResetStats(ref totalSent, ref totalRecv);
}
public void GetConnectionQuality(out float localQuality, out float remoteQuality, out int ping, out float outByteSec, out float inByteSec)
{
Original.GetConnectionQuality(ref localQuality, ref remoteQuality, ref ping, ref outByteSec, ref inByteSec);
}
public ISocket Accept()
{
return Original.Accept();
}
public int GetHostPort()
{
return Original.GetHostPort();
}
public bool Flush()
{
return Original.Flush();
}
public string GetHostName()
{
return Original.GetHostName();
}
public void VersionMatch()
{
if (finished)
{
Original.VersionMatch();
}
else
{
versionMatchQueued = Package.Count;
}
}
public void Send(ZPackage pkg)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
int pos = pkg.GetPos();
pkg.SetPos(0);
int num = pkg.ReadInt();
if ((num == StringExtensionMethods.GetStableHashCode("PeerInfo") || num == StringExtensionMethods.GetStableHashCode("RoutedRPC") || num == StringExtensionMethods.GetStableHashCode("ZDOData")) && !finished)
{
ZPackage val = new ZPackage(pkg.GetArray());
val.SetPos(pos);
Package.Add(val);
}
else
{
pkg.SetPos(pos);
Original.Send(pkg);
}
}
}
[HarmonyPriority(800)]
[HarmonyPrefix]
private static void Prefix([<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(new byte[] { 2, 0, 0 })] ref Dictionary<Assembly, BufferingSocket> __state, ZNet __instance, ZRpc rpc)
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
if (__instance.IsServer())
{
BufferingSocket value = new BufferingSocket(rpc.GetSocket());
AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, value);
object? obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc });
ZNetPeer val = (ZNetPeer)((obj is ZNetPeer) ? obj : null);
if (val != null && (int)ZNet.m_onlineBackend != 0)
{
AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, value);
}
if (__state == null)
{
__state = new Dictionary<Assembly, BufferingSocket>();
}
__state[Assembly.GetExecutingAssembly()] = value;
}
}
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
FieldInfo fieldInfo = AccessTools.Field(typeof(ZNetPeer), "m_socket");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(ZPlayFabSocket), "m_remotePlayerId");
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Ldloc_1, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo, (string)null),
new CodeMatch((OpCode?)OpCodes.Isinst, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo2, (string)null)
});
if (val.IsInvalid)
{
return instructions;
}
val.SetAndAdvance(OpCodes.Ldstr, (object)"none");
val.SetOpcodeAndAdvance(OpCodes.Nop);
val.SetOpcodeAndAdvance(OpCodes.Nop);
val.SetOpcodeAndAdvance(OpCodes.Nop);
return val.InstructionEnumeration();
}
[HarmonyPostfix]
private static void Postfix(Dictionary<Assembly, BufferingSocket> __state, ZNet __instance, ZRpc rpc)
{
ZNetPeer peer;
if (__instance.IsServer())
{
object obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc });
peer = (ZNetPeer)((obj is ZNetPeer) ? obj : null);
if (peer == null)
{
SendBufferedData();
}
else
{
((MonoBehaviour)__instance).StartCoroutine(sendAsync());
}
}
void SendBufferedData()
{
if (rpc.GetSocket() is BufferingSocket bufferingSocket)
{
AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket.Original);
object? obj2 = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc });
ZNetPeer val2 = (ZNetPeer)((obj2 is ZNetPeer) ? obj2 : null);
if (val2 != null)
{
AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val2, bufferingSocket.Original);
}
}
BufferingSocket bufferingSocket2 = __state[Assembly.GetExecutingAssembly()];
bufferingSocket2.finished = true;
for (int i = 0; i < bufferingSocket2.Package.Count; i++)
{
if (i == bufferingSocket2.versionMatchQueued)
{
bufferingSocket2.Original.VersionMatch();
}
bufferingSocket2.Original.Send(bufferingSocket2.Package[i]);
}
if (bufferingSocket2.Package.Count == bufferingSocket2.versionMatchQueued)
{
bufferingSocket2.Original.VersionMatch();
}
}
IEnumerator sendAsync()
{
foreach (ConfigSync configSync in configSyncs)
{
List<PackageEntry> list = new List<PackageEntry>();
if (configSync.CurrentVersion != null)
{
list.Add(new PackageEntry
{
section = "Internal",
key = "serverversion",
type = typeof(string),
value = configSync.CurrentVersion
});
}
MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null);
SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance);
list.Add(new PackageEntry
{
section = "Internal",
key = "lockexempt",
type = typeof(bool),
value = (((object)methodInfo == null) ? ((object)val.Contains(rpc.GetSocket().GetHostName())) : methodInfo.Invoke(ZNet.instance, new object[2]
{
val,
rpc.GetSocket().GetHostName()
}))
});
ZPackage package = ConfigsToPackage(configSync.allConfigs.Select((OwnConfigEntryBase c) => c.BaseConfig), configSync.allCustomValues, list, partial: false);
yield return ((MonoBehaviour)__instance).StartCoroutine(configSync.sendZPackage(new List<ZNetPeer> { peer }, package));
}
SendBufferedData();
}
}
}
private class PackageEntry
{
public string section;
public string key;
public Type type;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public object value;
}
[HarmonyPatch(typeof(ConfigEntryBase), "GetSerializedValue")]
private static class PreventSavingServerInfo
{
[HarmonyPrefix]
private static bool Prefix(ConfigEntryBase __instance, ref string __result)
{
OwnConfigEntryBase ownConfigEntryBase = configData(__instance);
if (ownConfigEntryBase == null || isWritableConfig(ownConfigEntryBase))
{
return true;
}
__result = TomlTypeConverter.ConvertToString(ownConfigEntryBase.LocalBaseValue, __instance.SettingType);
return false;
}
}
[HarmonyPatch(typeof(ConfigEntryBase), "SetSerializedValue")]
private static class PreventConfigRereadChangingValues
{
[HarmonyPrefix]
private static bool Prefix(ConfigEntryBase __instance, string value)
{
OwnConfigEntryBase ownConfigEntryBase = configData(__instance);
if (ownConfigEntryBase == null || ownConfigEntryBase.LocalBaseValue == null)
{
return true;
}
try
{
ownConfigEntryBase.LocalBaseValue = TomlTypeConverter.ConvertToValue(value, __instance.SettingType);
}
catch (Exception ex)
{
Debug.LogWarning((object)$"Config value of setting \"{__instance.Definition}\" could not be parsed and will be ignored. Reason: {ex.Message}; Value: {value}");
}
return false;
}
}
private class InvalidDeserializationTypeException : Exception
{
public string expected;
public string received;
public string field = "";
}
public static bool ProcessingServerUpdate;
public readonly string Name;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public string DisplayName;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public string CurrentVersion;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public string MinimumRequiredVersion;
public bool ModRequired;
private bool? forceConfigLocking;
private bool isSourceOfTruth = true;
private static readonly HashSet<ConfigSync> configSyncs;
private readonly HashSet<OwnConfigEntryBase> allConfigs = new HashSet<OwnConfigEntryBase>();
private HashSet<CustomSyncedValueBase> allCustomValues = new HashSet<CustomSyncedValueBase>();
private static bool isServer;
private static bool lockExempt;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private OwnConfigEntryBase lockedConfig;
private const byte PARTIAL_CONFIGS = 1;
private const byte FRAGMENTED_CONFIG = 2;
private const byte COMPRESSED_CONFIG = 4;
private readonly Dictionary<string, SortedDictionary<int, byte[]>> configValueCache = new Dictionary<string, SortedDictionary<int, byte[]>>();
private readonly List<KeyValuePair<long, string>> cacheExpirations = new List<KeyValuePair<long, string>>();
private static long packageCounter;
public bool IsLocked
{
get
{
bool? flag = forceConfigLocking;
bool num;
if (!flag.HasValue)
{
if (lockedConfig == null)
{
goto IL_0051;
}
num = ((IConvertible)lockedConfig.BaseConfig.BoxedValue).ToInt32(CultureInfo.InvariantCulture) != 0;
}
else
{
num = flag.GetValueOrDefault();
}
if (num)
{
return !lockExempt;
}
goto IL_0051;
IL_0051:
return false;
}
set
{
forceConfigLocking = value;
}
}
public bool IsAdmin
{
get
{
if (!lockExempt)
{
return isSourceOfTruth;
}
return true;
}
}
public bool IsSourceOfTruth
{
get
{
return isSourceOfTruth;
}
private set
{
if (value != isSourceOfTruth)
{
isSourceOfTruth = value;
this.SourceOfTruthChanged?.Invoke(value);
}
}
}
public bool InitialSyncDone { get; private set; }
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
[method: <3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
[field: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
public event Action<bool> SourceOfTruthChanged;
[<f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
[method: <3140a742-0f38-4b13-93e1-fcaf6165851f>NullableContext(2)]
[field: <f748abfc-69bc-4f09-8901-6581c23f6009>Nullable(2)]
private event Action lockedConfigChanged;
static ConfigSync()
{
ProcessingServerUpdate = false;
configSyncs = new HashSet<ConfigSync>();
lockExempt = false;
packageCounter = 0L;
RuntimeHelpers.RunClassConstructor(typeof(VersionCheck).TypeHandle);
}
public ConfigSync(string name)
{
Name = name;
configSyncs.Add(this);
new VersionCheck(this);
}
public SyncedConfigEntry<T> AddConfigEntry<T>(ConfigEntry<T> configEntry)
{
OwnConfigEntryBase ownConfigEntryBase = configData((ConfigEntryBase)(object)configEntry);
SyncedConfigEntry<T> syncedEntry = ownConfigEntryBase as SyncedConfigEntry<T>;
if (syncedEntry == null)
{
syncedEntry = new SyncedConfigEntry<T>(configEntry);
AccessTools.DeclaredField(typeof(ConfigDescription), "<Tags>k__BackingField").SetValue(((ConfigEntryBase)configEntry).Description, new object[1]
{
new ConfigurationManagerAttributes()
}.Concat(((ConfigEntryBase)configEntry).Description.Tags ?? Array.Empty<object>()).Concat(new SyncedConfigEntry<T>[1] { syncedEntry }).ToArray());
configEntry.SettingChanged += delegate
{
if (!ProcessingServerUpdate && syncedEntry.SynchronizedConfig)
{
Broadcast(ZRoutedRpc.Everybody, (ConfigEntryBase)configEntry);
}
};
allConfigs.Add(syncedEntry);
}
return syncedEntry;
}
public SyncedConfigEntry<T> AddLockingConfigEntry<T>(ConfigEntry<T> lockingConfig) where T : IConvertible
{
if (lockedConfig != null)
{
throw new Exception("Cannot initialize locking ConfigEntry twice");
}
lockedConfig = AddConfigEntry<T>(lockingConfig);
lockingConfig.SettingChanged += delegate
{
this.lockedConfigChanged?.Invoke();
};
return (SyncedConfigEntry<T>)lockedConfig;
}
internal void AddCustomValue(CustomSyncedValueBase customValue)
{
if (allCustomValues.Select((CustomSyncedValueBase v) => v.Identifier).Concat(new string[1] { "serverversion" }).Contains(customValue.Identifier))
{
throw new Exception("Cannot have multiple settings with the same name or with a reserved name (serverversion)");
}
allCustomValues.Add(customValue);
allCustomValues = new HashSet<CustomSyncedValueBase>(allCustomValues.OrderByDescending((CustomSyncedValueBase v) => v.Priority));
CustomSyncedValueBase customSyncedValueBase = customValue;
customSyncedValueBase.ValueChanged = (Action)Delegate.Combine(customSyncedValueBase.ValueChanged, (Action)delegate
{
if (!ProcessingServerUpdate)
{
Broadcast(ZRoutedRpc.Everybody, customValue);
}
});
}
private void RPC_FromServerConfigSync(ZRpc rpc, ZPackage package)
{
lockedConfigChanged += serverLockedSettingChanged;
IsSourceOfTruth = false;
if (HandleConfigSyncRPC(0L, package, clientUpdate: false))
{
InitialSyncDone = true;
}
}
private void RPC_FromOtherClientConfigSync(long sender, ZPackage package)
{
HandleConfigSyncRPC(sender, package, clientUpdate: true);
}
private bool HandleConfigSyncRPC(long sender, ZPackage package, bool clientUpdate)
{
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Expected O, but got Unknown
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
try
{
if (isServer && IsLocked)
{
ZRpc currentRpc = SnatchCurrentlyHandlingRPC.currentRpc;
object obj;
if (currentRpc == null)
{
obj = null;
}
else
{
ISocket socket = currentRpc.GetSocket();
obj = ((socket != null) ? socket.GetHostName() : null);
}
string text = (string)obj;
if (text != null)
{
MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null);
SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance);
if (!(((object)methodInfo == null) ? val.Contains(text) : ((bool)methodInfo.Invoke(ZNet.instance, new object[2] { val, text }))))
{
return false;
}
}
}
cacheExpirations.RemoveAll(delegate(KeyValuePair<long, string> kv)
{
if (kv.Key < DateTimeOffset.Now.Ticks)
{
configValueCache.Remove(kv.Value);
return true;
}
return false;
});
byte b = package.ReadByte();
if ((b & 2u) != 0)
{
long num = package.ReadLong();
string text2 = sender.ToString() + num;
if (!configValueCache.TryGetValue(text2, out var value))
{
value = new SortedDictionary<int, byte[]>();
configValueCache[text2] = value;
cacheExpirations.Add(new KeyValuePair<long, string>(DateTimeOffset.Now.AddSeconds(60.0).Ticks, text2));
}
int key = package.ReadInt();
int num2 = package.ReadInt();
value.Add(key, package.ReadByteArray());
if (value.Count < num2)
{
return false;
}
configValueCache.Remove(text2);
package = new ZPackage(value.Values.SelectMany((byte[] a) => a).ToArray());
b = package.ReadByte();
}
ProcessingServerUpdate = true;
if ((b & 4u) != 0)
{
MemoryStream stream = new MemoryStream(package.ReadByteArray());
MemoryStream memoryStream = new MemoryStream();
using (DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress))
{
deflateStream.CopyTo(memoryStream);
}
package = new ZPackage(memoryStream.ToArray());
b = package.ReadByte();
}
if ((b & 1) == 0)
{
resetConfigsFromServer();
}
ParsedConfigs parsedConfigs = ReadConfigsFromPackage(package);
ConfigFile val2 = null;
bool saveOnConfigSet = false;
foreach (KeyValuePair<OwnConfigEntryBase, object> configValue in parsedConfigs.configValues)
{
if (!isServer && configValue.Key.LocalBaseValue == null)
{
configValue.Key.LocalBaseValue = configValue.Key.BaseConfig.BoxedValue;
}
if (val2 == null)
{
val2 = configValue.Key.BaseConfig.ConfigFile;
saveOnConfigSet = val2.SaveOnConfigSet;
val2.SaveOnConfigSet = false;
}
configValue.Key.BaseConfig.BoxedValue = configValue.Value;
}
if (val2 != null)
{
val2.SaveOnConfigSet = saveOnConfigSet;
}
foreach (KeyValuePair<CustomSyncedValueBase, object> customValue in parsedConfigs.customValues)
{
if (!isServer)
{
CustomSyncedValueBase key2 = customValue.Key;
if (key2.LocalBaseValue == null)
{
key2.LocalBaseValue = customValue.Key.BoxedValue;
}
}
customValue.Key.BoxedValue = customValue.Value;
}
Debug.Log((object)string.Format("Received {0} configs and {1} custom values from {2} for mod {3}", parsedConfigs.configValues.Count, parsedCo