Decompiled source of AzuExtendedPlayerInventory v2.1.0
AzuExtendedPlayerInventory.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; 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.Threading; using System.Timers; using APIManager; using AzuEPI; using AzuEPI.Core.Input; using AzuEPI.Core.InventoryHandlers; using AzuEPI.Core.Slots; using AzuEPI.Core.Text; using AzuEPI.Core.Utilities.Extensions; using AzuEPI.EPI; using AzuEPI.Game.Compatibility; using AzuEPI.Game.Compatibility.AdvBackpacks; using AzuEPI.Game.Loadout; using AzuEPI.Game.Panels; using AzuEPI.Game.Panels.Stats; using AzuEPI.Game.Panels.Vanity; using AzuEPI.Game.Patches; using AzuEPI.Game.PlayerPreview; using AzuEPI.Game.Slots.QAB; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using BepInEx.Preloader; using BepInEx.Preloader.Patching; using HarmonyLib; using JetBrains.Annotations; using LocalizationManager; using Microsoft.CodeAnalysis; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Collections.Generic; using ServerSync; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Core.ObjectPool; using YamlDotNet.Core.Tokens; using YamlDotNet.Helpers; using YamlDotNet.Serialization; using YamlDotNet.Serialization.BufferedDeserialization; using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators; using YamlDotNet.Serialization.Callbacks; 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; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("AzuExtendedPlayerInventory")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Azumatt")] [assembly: AssemblyProduct("AzuExtendedPlayerInventory")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")] [assembly: AssemblyFileVersion("2.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } public static class ToggleExtensions { public static bool isOn(this AzuExtendedPlayerInventoryPlugin.Toggle toggle) { return toggle == AzuExtendedPlayerInventoryPlugin.Toggle.On; } public static bool isOff(this AzuExtendedPlayerInventoryPlugin.Toggle toggle) { return toggle == AzuExtendedPlayerInventoryPlugin.Toggle.Off; } } namespace AzuExtendedPlayerInventory { [PublicAPI] public class API { public delegate void SlotAddedHandler(string slotName); public delegate void SlotRemovedHandler(string slotName); private static readonly Dictionary<SlotAddedHandler, AzuEPI.API.SlotAddedHandler> _slotAddedMap = new Dictionary<SlotAddedHandler, AzuEPI.API.SlotAddedHandler>(); private static readonly Dictionary<SlotRemovedHandler, AzuEPI.API.SlotRemovedHandler> _slotRemovedMap = new Dictionary<SlotRemovedHandler, AzuEPI.API.SlotRemovedHandler>(); private static readonly Dictionary<Action<Hud>, Action<Hud>> _hudAwakeMap = new Dictionary<Action<Hud>, Action<Hud>>(); private static readonly Dictionary<Action<Hud>, Action<Hud>> _hudAwakeCompleteMap = new Dictionary<Action<Hud>, Action<Hud>>(); private static readonly Dictionary<Action<Hud>, Action<Hud>> _hudUpdateMap = new Dictionary<Action<Hud>, Action<Hud>>(); private static readonly Dictionary<Action<Hud>, Action<Hud>> _hudUpdateCompleteMap = new Dictionary<Action<Hud>, Action<Hud>>(); public static event SlotAddedHandler? SlotAdded { add { SlotAddedHandler value2 = value; if (value2 == null || _slotAddedMap.ContainsKey(value2)) { return; } AzuEPI.API.SlotAddedHandler value3 = delegate(string s) { try { value2(s); } catch { } }; _slotAddedMap[value2] = value3; AzuEPI.API.SlotAdded += value3; } remove { if (value != null && _slotAddedMap.TryGetValue(value, out AzuEPI.API.SlotAddedHandler value2)) { AzuEPI.API.SlotAdded -= value2; _slotAddedMap.Remove(value); } } } public static event SlotRemovedHandler? SlotRemoved { add { SlotRemovedHandler value2 = value; if (value2 == null || _slotRemovedMap.ContainsKey(value2)) { return; } AzuEPI.API.SlotRemovedHandler value3 = delegate(string s) { try { value2(s); } catch { } }; _slotRemovedMap[value2] = value3; AzuEPI.API.SlotRemoved += value3; } remove { if (value != null && _slotRemovedMap.TryGetValue(value, out AzuEPI.API.SlotRemovedHandler value2)) { AzuEPI.API.SlotRemoved -= value2; _slotRemovedMap.Remove(value); } } } public static event Action<Hud>? OnHudAwake { add { AddHudEvent(value, _hudAwakeMap, delegate(Action<Hud> h) { AzuEPI.API.OnHudAwake += h; }); } remove { RemoveHudEvent(value, _hudAwakeMap, delegate(Action<Hud> h) { AzuEPI.API.OnHudAwake -= h; }); } } public static event Action<Hud>? OnHudAwakeComplete { add { AddHudEvent(value, _hudAwakeCompleteMap, delegate(Action<Hud> h) { AzuEPI.API.OnHudAwakeComplete += h; }); } remove { RemoveHudEvent(value, _hudAwakeCompleteMap, delegate(Action<Hud> h) { AzuEPI.API.OnHudAwakeComplete -= h; }); } } public static event Action<Hud>? OnHudUpdate { add { AddHudEvent(value, _hudUpdateMap, delegate(Action<Hud> h) { AzuEPI.API.OnHudUpdate += h; }); } remove { RemoveHudEvent(value, _hudUpdateMap, delegate(Action<Hud> h) { AzuEPI.API.OnHudUpdate -= h; }); } } public static event Action<Hud>? OnHudUpdateComplete { add { AddHudEvent(value, _hudUpdateCompleteMap, delegate(Action<Hud> h) { AzuEPI.API.OnHudUpdateComplete += h; }); } remove { RemoveHudEvent(value, _hudUpdateCompleteMap, delegate(Action<Hud> h) { AzuEPI.API.OnHudUpdateComplete -= h; }); } } private static void AddHudEvent(Action<Hud>? handler, Dictionary<Action<Hud>, Action<Hud>> map, Action<Action<Hud>> subscribe) { Action<Hud> handler2 = handler; if (handler2 == null || map.ContainsKey(handler2)) { return; } Action<Hud> action = delegate(Hud h) { try { handler2(h); } catch { } }; map[handler2] = action; subscribe(action); } private static void RemoveHudEvent(Action<Hud>? handler, Dictionary<Action<Hud>, Action<Hud>> map, Action<Action<Hud>> unsubscribe) { if (handler != null && map.TryGetValue(handler, out Action<Hud> value)) { unsubscribe(value); map.Remove(handler); } } public static bool IsLoaded() { return AzuEPI.API.IsLoaded(); } public static bool AddSlot(string slotName, Func<Player, ItemData?> getItem, Func<ItemData, bool> isValid, int index = -1) { string slotName2 = slotName; Func<Player, ItemData?> getItem2 = getItem; Func<ItemData, bool> isValid2 = isValid; if (Localization.instance.Localize(slotName2).Contains("[")) { Localizer.OnLocalizationComplete += delegate { AzuEPI.API.AddSlot(slotName2, getItem2, isValid2, index); }; } else { AzuEPI.API.AddSlot(slotName2, getItem2, isValid2, index); } return true; } public static bool RemoveSlot(string slotName) { return AzuEPI.API.RemoveSlot(slotName); } public static SlotInfo GetSlots() { AzuEPI.SlotInfo slots = AzuEPI.API.GetSlots(); return new SlotInfo { SlotNames = (slots.SlotNames ?? Array.Empty<string>()), SlotPositions = (slots.SlotPositions ?? Array.Empty<Vector2>()), GetItemFuncs = (slots.GetItemFuncs ?? Array.Empty<Func<Player, ItemData>>()), IsValidFuncs = (slots.IsValidFuncs ?? Array.Empty<Func<ItemData, bool>>()) }; } public static SlotInfo GetQuickSlots() { AzuEPI.SlotInfo quickSlots = AzuEPI.API.GetQuickSlots(); return new SlotInfo { SlotNames = (quickSlots.SlotNames ?? Array.Empty<string>()), SlotPositions = (quickSlots.SlotPositions ?? Array.Empty<Vector2>()), GetItemFuncs = (quickSlots.GetItemFuncs ?? Array.Empty<Func<Player, ItemData>>()), IsValidFuncs = (quickSlots.IsValidFuncs ?? Array.Empty<Func<ItemData, bool>>()) }; } public static List<ItemData> GetQuickSlotsItems() { return AzuEPI.API.GetQuickSlotsItems(); } public static int GetAddedRows(int width) { return AzuEPI.API.GetAddedRows(width); } public static void HudAwake(Hud h) { Hud h2 = h; SafeInvoke(delegate { AzuEPI.API.HudAwake(h2); }); } public static void HudAwakeComplete(Hud h) { Hud h2 = h; SafeInvoke(delegate { AzuEPI.API.HudAwakeComplete(h2); }); } public static void HudUpdate(Hud h) { Hud h2 = h; SafeInvoke(delegate { AzuEPI.API.HudUpdate(h2); }); } public static void HudUpdateComplete(Hud h) { Hud h2 = h; SafeInvoke(delegate { AzuEPI.API.HudUpdateComplete(h2); }); } private static void SafeInvoke(Action a) { try { a(); } catch { } } } [PublicAPI] public class SlotInfo { public string[] SlotNames { get; set; } = Array.Empty<string>(); public Vector2[] SlotPositions { get; set; } = Array.Empty<Vector2>(); public Func<Player, ItemData?>?[] GetItemFuncs { get; set; } = Array.Empty<Func<Player, ItemData>>(); public Func<ItemData, bool>?[] IsValidFuncs { get; set; } = Array.Empty<Func<ItemData, bool>>(); } } namespace APIManager { public static class Patcher { private class MonoAssemblyResolver : IAssemblyResolver, IDisposable { public AssemblyDefinition Resolve(AssemblyNameReference name) { return AssemblyDefinition.ReadAssembly(AppDomain.CurrentDomain.Load(name.FullName).Location); } public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) { return Resolve(name); } public void Dispose() { } } private class AssemblyLoadInterceptor { private static string? assemblyPath; private static MethodInfo TargetMethod() { return AccessTools.DeclaredMethod(typeof(Assembly), "Load", new Type[1] { typeof(byte[]) }, (Type[])null); } private static bool Prefix(ref byte[] __0, ref Assembly? __result) { //IL_001d: 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_0032: Expected O, but got Unknown //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Expected O, but got Unknown //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) assemblyPath = null; if (modifyNextLoad) { modifyNextLoad = false; try { AssemblyDefinition val = AssemblyDefinition.ReadAssembly((Stream)new MemoryStream(__0), new ReaderParameters { AssemblyResolver = (IAssemblyResolver)(object)new MonoAssemblyResolver() }); try { ((Dictionary<string, string>)typeof(EnvVars).Assembly.GetType("BepInEx.Preloader.RuntimeFixes.UnityPatches").GetProperty("AssemblyLocations").GetValue(null))[val.FullName] = currentAssemblyPath; FixupModuleReferences(val.MainModule); TypeDefinition val2 = val.MainModule.GetType("APIManager", "PatchedAttribute"); if (val2 == null) { val2 = new TypeDefinition("APIManager", "PatchedAttribute", (TypeAttributes)3) { BaseType = val.MainModule.ImportReference(typeof(Attribute)) }; MethodDefinition val3 = new MethodDefinition(".ctor", (MethodAttributes)6278, val.MainModule.TypeSystem.Void); ((MethodReference)val3).Parameters.Add(new ParameterDefinition(val.MainModule.TypeSystem.String)); ((MethodReference)val3).Parameters.Add(new ParameterDefinition(val.MainModule.TypeSystem.String)); val3.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); val2.Methods.Add(val3); val.MainModule.Types.Add(val2); CustomAttribute val4 = new CustomAttribute((MethodReference)(object)val3); val4.ConstructorArguments.Add(new CustomAttributeArgument(val.MainModule.TypeSystem.String, (object)"")); val4.ConstructorArguments.Add(new CustomAttributeArgument(val.MainModule.TypeSystem.String, (object)val.MainModule.Mvid.ToString())); val.CustomAttributes.Add(val4); } CustomAttribute val5 = new CustomAttribute((MethodReference)(object)((IEnumerable<MethodDefinition>)val2.Methods).First((MethodDefinition m) => ((MemberReference)m).Name == ".ctor")); val5.ConstructorArguments.Add(new CustomAttributeArgument(val.MainModule.TypeSystem.String, (object)modGUID)); val5.ConstructorArguments.Add(new CustomAttributeArgument(val.MainModule.TypeSystem.String, (object)patchingAssembly.ManifestModule.ModuleVersionId.ToString())); val.CustomAttributes.Add(val5); using MemoryStream memoryStream = new MemoryStream(); val.Write((Stream)memoryStream); __0 = memoryStream.ToArray(); string dumpedAssembliesPath = Patcher.dumpedAssembliesPath; char directorySeparatorChar = Path.DirectorySeparatorChar; string path = dumpedAssembliesPath + directorySeparatorChar + ((AssemblyNameReference)val.Name).Name + ".dll"; Directory.CreateDirectory(Patcher.dumpedAssembliesPath); File.WriteAllBytes(path, __0); assemblyPath = path; __result = null; return false; } finally { ((IDisposable)val)?.Dispose(); } } catch (BadImageFormatException) { } catch (Exception ex2) { Debug.LogError((object)("Failed patching ... " + ex2)); } } return true; } private static void Postfix(ref Assembly? __result) { if (assemblyPath != null && __result == null) { __result = Assembly.LoadFrom(assemblyPath); assemblyPath = null; } } } private static PluginInfo? lastPluginInfo; private static bool modifyNextLoad = false; private static string modGUID = null; private static HashSet<string> redirectedNamespaces = null; private static readonly Assembly patchingAssembly = Assembly.GetExecutingAssembly(); private static string currentAssemblyPath = null; private static readonly string dumpedAssembliesPath = (string)AccessTools.DeclaredField(typeof(AssemblyPatcher), "DumpedAssembliesPath").GetValue(null); private static void GrabPluginInfo(PluginInfo __instance) { lastPluginInfo = __instance; } [HarmonyPriority(700)] private static void CheckAssemblyLoadFile(string __0) { PluginInfo? obj = lastPluginInfo; if (__0 == ((obj != null) ? obj.Location : null) && lastPluginInfo.Dependencies.Any((BepInDependency d) => d.DependencyGUID == modGUID)) { modifyNextLoad = true; currentAssemblyPath = __0; } lastPluginInfo = null; } [HarmonyPriority(500)] private static bool InterceptAssemblyLoadFile(string __0, ref Assembly? __result) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) if (modifyNextLoad && (object)__result == null) { string text = dumpedAssembliesPath; char directorySeparatorChar = Path.DirectorySeparatorChar; string text2 = text + directorySeparatorChar + Path.GetFileName(__0); if (File.Exists(text2)) { AssemblyDefinition val = AssemblyDefinition.ReadAssembly(text2, new ReaderParameters { AssemblyResolver = (IAssemblyResolver)(object)new MonoAssemblyResolver() }); try { bool flag = false; Enumerator<CustomAttribute> enumerator = val.CustomAttributes.GetEnumerator(); try { while (enumerator.MoveNext()) { CustomAttribute current = enumerator.Current; TypeReference declaringType = ((MemberReference)current.Constructor).DeclaringType; if (declaringType.Namespace == "APIManager" && ((MemberReference)declaringType).Name == "PatchedAttribute") { CustomAttributeArgument val2 = current.ConstructorArguments[0]; if ((string)((CustomAttributeArgument)(ref val2)).Value == modGUID) { val2 = current.ConstructorArguments[1]; flag = (string)((CustomAttributeArgument)(ref val2)).Value == patchingAssembly.ManifestModule.ModuleVersionId.ToString(); break; } } } } finally { ((IDisposable)enumerator).Dispose(); } if (flag) { return true; } } finally { ((IDisposable)val)?.Dispose(); } } __result = Assembly.Load(File.ReadAllBytes(__0)); return false; } return true; } [HarmonyPriority(499)] private static bool ReplaceAssemblyLoadWithCache(ref string __0, ref Assembly? __result) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) if (modifyNextLoad && (object)__result == null && !__0.StartsWith(dumpedAssembliesPath)) { string text = dumpedAssembliesPath; char directorySeparatorChar = Path.DirectorySeparatorChar; string text2 = text + directorySeparatorChar + Path.GetFileName(__0); AssemblyDefinition val = AssemblyDefinition.ReadAssembly(text2, new ReaderParameters { AssemblyResolver = (IAssemblyResolver)(object)new MonoAssemblyResolver() }); AssemblyDefinition val2 = AssemblyDefinition.ReadAssembly(__0, new ReaderParameters { AssemblyResolver = (IAssemblyResolver)(object)new MonoAssemblyResolver() }); Enumerator<CustomAttribute> enumerator = val.CustomAttributes.GetEnumerator(); try { while (enumerator.MoveNext()) { CustomAttribute current = enumerator.Current; TypeReference declaringType = ((MemberReference)current.Constructor).DeclaringType; if (declaringType.Namespace == "APIManager" && ((MemberReference)declaringType).Name == "PatchedAttribute") { CustomAttributeArgument val3 = current.ConstructorArguments[0]; string text3 = (string)((CustomAttributeArgument)(ref val3)).Value; bool num; if (!(text3 == "")) { num = !Chainloader.PluginInfos.ContainsKey(text3); } else { val3 = current.ConstructorArguments[1]; num = (string)((CustomAttributeArgument)(ref val3)).Value != val2.MainModule.Mvid.ToString(); } if (num) { val2.Dispose(); val.Dispose(); __result = Assembly.Load(File.ReadAllBytes(__0)); return false; } } } } finally { ((IDisposable)enumerator).Dispose(); } ((Dictionary<string, string>)typeof(EnvVars).Assembly.GetType("BepInEx.Preloader.RuntimeFixes.UnityPatches").GetProperty("AssemblyLocations").GetValue(null))[val.FullName] = __0; val2.Dispose(); val.Dispose(); __0 = text2; } modifyNextLoad = false; return true; } private static void FixupModuleReferences(ModuleDefinition module) { ModuleDefinition module2 = module; foreach (TypeDefinition type4 in module2.GetTypes()) { if ((object)patchingAssembly.GetType(((MemberReference)type4).FullName) == null) { Dispatch(type4); } } static bool AreSame(TypeReference a, TypeReference b) { return (bool)typeof(MetadataResolver).Assembly.GetType("Mono.Cecil.MetadataResolver").GetMethod("AreSame", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[2] { typeof(TypeReference), typeof(TypeReference) }, null).Invoke(null, new object[2] { a, b }); } void Dispatch(TypeDefinition type) { if (type.BaseType != null && type.BaseType.Scope == module2 && redirectedNamespaces.Contains(baseDeclaringType(type.BaseType).Namespace)) { Type type3 = patchingAssembly.GetType(((MemberReference)type.BaseType).FullName); if ((object)type3 != null) { type.BaseType = module2.ImportReference(type3); } } DispatchGenericParameters((IGenericParameterProvider)(object)type, ((MemberReference)type).FullName); DispatchInterfaces(type, ((MemberReference)type).FullName); DispatchAttributes((ICustomAttributeProvider)(object)type, ((MemberReference)type).FullName); DispatchFields(type, ((MemberReference)type).FullName); DispatchProperties(type, ((MemberReference)type).FullName); DispatchEvents(type, ((MemberReference)type).FullName); DispatchMethods(type); } void DispatchAttributes(ICustomAttributeProvider provider, string referencingEntityName) { //IL_000f: 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) //IL_0053: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) if (!provider.HasCustomAttributes) { return; } Enumerator<CustomAttribute> enumerator11 = provider.CustomAttributes.GetEnumerator(); try { while (enumerator11.MoveNext()) { CustomAttribute current11 = enumerator11.Current; MethodReference val12 = importMethodReference(current11.Constructor); if (val12 != null) { current11.Constructor = val12; } else { VisitMethod(current11.Constructor, referencingEntityName); } for (int n = 0; n < current11.ConstructorArguments.Count; n++) { CustomAttributeArgument val13 = current11.ConstructorArguments[n]; current11.ConstructorArguments[n] = new CustomAttributeArgument(VisitType(((CustomAttributeArgument)(ref val13)).Type, referencingEntityName), ((CustomAttributeArgument)(ref val13)).Value); } CustomAttributeArgument argument; for (int num = 0; num < current11.Properties.Count; num++) { CustomAttributeNamedArgument val14 = current11.Properties[num]; Collection<CustomAttributeNamedArgument> properties = current11.Properties; int num2 = num; string name = ((CustomAttributeNamedArgument)(ref val14)).Name; argument = ((CustomAttributeNamedArgument)(ref val14)).Argument; TypeReference? obj2 = VisitType(((CustomAttributeArgument)(ref argument)).Type, referencingEntityName); argument = ((CustomAttributeNamedArgument)(ref val14)).Argument; properties[num2] = new CustomAttributeNamedArgument(name, new CustomAttributeArgument(obj2, ((CustomAttributeArgument)(ref argument)).Value)); } for (int num3 = 0; num3 < current11.Fields.Count; num3++) { CustomAttributeNamedArgument val15 = current11.Fields[num3]; Collection<CustomAttributeNamedArgument> fields = current11.Fields; int num4 = num3; string name2 = ((CustomAttributeNamedArgument)(ref val15)).Name; argument = ((CustomAttributeNamedArgument)(ref val15)).Argument; TypeReference? obj3 = VisitType(((CustomAttributeArgument)(ref argument)).Type, referencingEntityName); argument = ((CustomAttributeNamedArgument)(ref val15)).Argument; fields[num4] = new CustomAttributeNamedArgument(name2, new CustomAttributeArgument(obj3, ((CustomAttributeArgument)(ref argument)).Value)); } } } finally { ((IDisposable)enumerator11).Dispose(); } } void DispatchEvents(TypeDefinition type, string referencingEntityName) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) Enumerator<EventDefinition> enumerator6 = type.Events.GetEnumerator(); try { while (enumerator6.MoveNext()) { EventDefinition current6 = enumerator6.Current; ((EventReference)current6).EventType = VisitType(((EventReference)current6).EventType, referencingEntityName); DispatchAttributes((ICustomAttributeProvider)(object)current6, referencingEntityName); } } finally { ((IDisposable)enumerator6).Dispose(); } } void DispatchFields(TypeDefinition type, string referencingEntityName) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) Enumerator<FieldDefinition> enumerator8 = type.Fields.GetEnumerator(); try { while (enumerator8.MoveNext()) { FieldDefinition current8 = enumerator8.Current; ((FieldReference)current8).FieldType = VisitType(((FieldReference)current8).FieldType, referencingEntityName); DispatchAttributes((ICustomAttributeProvider)(object)current8, referencingEntityName); } } finally { ((IDisposable)enumerator8).Dispose(); } } void DispatchGenericArguments(IGenericInstance genericInstance, string referencingEntityName) { for (int j = 0; j < genericInstance.GenericArguments.Count; j++) { genericInstance.GenericArguments[j] = VisitType(genericInstance.GenericArguments[j], referencingEntityName); } } void DispatchGenericParameters(IGenericParameterProvider provider, string referencingEntityName) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) Enumerator<GenericParameter> enumerator12 = provider.GenericParameters.GetEnumerator(); try { while (enumerator12.MoveNext()) { GenericParameter current12 = enumerator12.Current; DispatchAttributes((ICustomAttributeProvider)(object)current12, referencingEntityName); for (int num5 = 0; num5 < current12.Constraints.Count; num5++) { current12.Constraints[num5] = VisitType(current12.Constraints[num5], referencingEntityName); } } } finally { ((IDisposable)enumerator12).Dispose(); } } void DispatchInterfaces(TypeDefinition type, string referencingEntityName) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) Enumerator<InterfaceImplementation> enumerator9 = type.Interfaces.GetEnumerator(); try { while (enumerator9.MoveNext()) { InterfaceImplementation current9 = enumerator9.Current; current9.InterfaceType = VisitType(current9.InterfaceType, referencingEntityName); } } finally { ((IDisposable)enumerator9).Dispose(); } } void DispatchMethod(MethodDefinition method) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) ((MethodReference)method).ReturnType = VisitType(((MethodReference)method).ReturnType, ((MemberReference)method).FullName); DispatchAttributes((ICustomAttributeProvider)(object)((MethodReference)method).MethodReturnType, ((MemberReference)method).FullName); DispatchGenericParameters((IGenericParameterProvider)(object)method, ((MemberReference)method).FullName); Enumerator<ParameterDefinition> enumerator4 = ((MethodReference)method).Parameters.GetEnumerator(); try { while (enumerator4.MoveNext()) { ParameterDefinition current4 = enumerator4.Current; ((ParameterReference)current4).ParameterType = VisitType(((ParameterReference)current4).ParameterType, ((MemberReference)method).FullName); DispatchAttributes((ICustomAttributeProvider)(object)current4, ((MemberReference)method).FullName); } } finally { ((IDisposable)enumerator4).Dispose(); } for (int i = 0; i < method.Overrides.Count; i++) { MethodReference val6 = importMethodReference(method.Overrides[i]); if (val6 != null) { method.Overrides[i] = val6; } else { VisitMethod(method.Overrides[i], ((MemberReference)method).FullName); } } if (method.HasBody) { DispatchMethodBody(method.Body); } } void DispatchMethodBody(MethodBody body) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) Enumerator<VariableDefinition> enumerator2 = body.Variables.GetEnumerator(); try { while (enumerator2.MoveNext()) { VariableDefinition current2 = enumerator2.Current; ((VariableReference)current2).VariableType = VisitType(((VariableReference)current2).VariableType, ((MemberReference)body.Method).FullName); } } finally { ((IDisposable)enumerator2).Dispose(); } Enumerator<Instruction> enumerator3 = body.Instructions.GetEnumerator(); try { while (enumerator3.MoveNext()) { Instruction current3 = enumerator3.Current; object operand = current3.Operand; FieldReference val = (FieldReference)((operand is FieldReference) ? operand : null); if (val == null) { MethodReference val2 = (MethodReference)((operand is MethodReference) ? operand : null); if (val2 == null) { TypeReference val3 = (TypeReference)((operand is TypeReference) ? operand : null); if (val3 != null) { current3.Operand = VisitType(val3, ((MemberReference)body.Method).FullName); } } else { MethodReference val4 = importMethodReference(val2); if (val4 != null) { current3.Operand = val4; } else { VisitMethod(val2, ((MemberReference)body.Method).FullName); } } } else { FieldReference val5 = importFieldReference(val); if (val5 != null) { current3.Operand = val5; } else { VisitField(val, ((MemberReference)body.Method).FullName); } } } } finally { ((IDisposable)enumerator3).Dispose(); } } void DispatchMethods(TypeDefinition type) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) Enumerator<MethodDefinition> enumerator5 = type.Methods.GetEnumerator(); try { while (enumerator5.MoveNext()) { MethodDefinition current5 = enumerator5.Current; DispatchMethod(current5); } } finally { ((IDisposable)enumerator5).Dispose(); } } void DispatchProperties(TypeDefinition type, string referencingEntityName) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) Enumerator<PropertyDefinition> enumerator7 = type.Properties.GetEnumerator(); try { while (enumerator7.MoveNext()) { PropertyDefinition current7 = enumerator7.Current; ((PropertyReference)current7).PropertyType = VisitType(((PropertyReference)current7).PropertyType, referencingEntityName); DispatchAttributes((ICustomAttributeProvider)(object)current7, referencingEntityName); } } finally { ((IDisposable)enumerator7).Dispose(); } } TypeReference FixupType(TypeReference type) { if (type.Scope == module2 && redirectedNamespaces.Contains(baseDeclaringType(type).Namespace)) { if (type.IsNested) { return FixupType(((MemberReference)type).DeclaringType); } Type type2 = patchingAssembly.GetType(((MemberReference)type).FullName); if ((object)type2 != null) { return module2.ImportReference(type2); } } return type; } void VisitField(FieldReference? field, string referencingEntityName) { if (field != null) { field.FieldType = VisitType(field.FieldType, referencingEntityName); if (!(field is FieldDefinition)) { ((MemberReference)field).DeclaringType = VisitType(((MemberReference)field).DeclaringType, referencingEntityName); } } } void VisitMethod(MethodReference? method, string referencingEntityName) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (method != null) { GenericInstanceMethod val7 = (GenericInstanceMethod)(object)((method is GenericInstanceMethod) ? method : null); if (val7 != null) { DispatchGenericArguments((IGenericInstance)(object)val7, referencingEntityName); } method.ReturnType = VisitType(method.ReturnType, referencingEntityName); Enumerator<ParameterDefinition> enumerator10 = method.Parameters.GetEnumerator(); try { while (enumerator10.MoveNext()) { ParameterDefinition current10 = enumerator10.Current; ((ParameterReference)current10).ParameterType = VisitType(((ParameterReference)current10).ParameterType, referencingEntityName); } } finally { ((IDisposable)enumerator10).Dispose(); } if (!(method is MethodSpecification)) { ((MemberReference)method).DeclaringType = VisitType(((MemberReference)method).DeclaringType, referencingEntityName); } } } TypeReference? VisitType(TypeReference? type, string referencingEntityName) { if (type == null) { return type; } if (type.GetElementType().IsGenericParameter) { return type; } GenericInstanceType val8 = (GenericInstanceType)(object)((type is GenericInstanceType) ? type : null); if (val8 != null) { DispatchGenericArguments((IGenericInstance)(object)val8, referencingEntityName); } return FixupType(type); } static TypeReference baseDeclaringType(TypeReference type) { while (((MemberReference)type).DeclaringType != null) { type = ((MemberReference)type).DeclaringType; } return type; } FieldReference? importFieldReference(FieldReference field) { if (((MemberReference)field).DeclaringType.Scope == module2 && redirectedNamespaces.Contains(baseDeclaringType(((MemberReference)field).DeclaringType).Namespace)) { FieldInfo fieldInfo = patchingAssembly.GetType(((MemberReference)((MemberReference)field).DeclaringType).FullName)?.GetField(((MemberReference)field).Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if ((object)fieldInfo != null) { return module2.ImportReference(fieldInfo); } } return null; } MethodReference? importMethodReference(MethodReference method) { //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown MethodReference method2 = method; if (((MemberReference)method2).DeclaringType.Scope == module2 && redirectedNamespaces.Contains(baseDeclaringType(((MemberReference)method2).DeclaringType).Namespace)) { if (((MemberReference)method2).Name == ".cctor") { ConstructorInfo[] array = patchingAssembly.GetType(((MemberReference)((MemberReference)method2).DeclaringType).FullName)?.GetConstructors(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (array != null && array.Length == 1) { return module2.ImportReference((MethodBase)array[0]); } } else if (((MemberReference)method2).Name == ".ctor") { ConstructorInfo constructorInfo = patchingAssembly.GetType(((MemberReference)((MemberReference)method2).DeclaringType).FullName)?.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault(CompareMethods); if ((object)constructorInfo != null) { return module2.ImportReference((MethodBase)constructorInfo); } } else { MethodInfo methodInfo = patchingAssembly.GetType(((MemberReference)((MemberReference)method2).DeclaringType).FullName)?.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault(delegate(MethodInfo m) { if (m.Name != ((MemberReference)method2).Name) { return false; } return (((MemberReference)method2.ReturnType).ContainsGenericParameter == m.ReturnType.IsGenericParameter || AreSame(method2.ReturnType, module2.ImportReference(m.ReturnType))) && CompareMethods(m); }); if ((object)methodInfo != null) { MethodReference val9 = module2.ImportReference((MethodBase)methodInfo); MethodReference obj = method2; GenericInstanceMethod val10 = (GenericInstanceMethod)(object)((obj is GenericInstanceMethod) ? obj : null); if (val10 != null) { GenericInstanceMethod val11 = new GenericInstanceMethod(val9); for (int k = 0; k < val10.GenericArguments.Count; k++) { val10.GenericArguments[k] = VisitType(val10.GenericArguments[k], ((MemberReference)method2).FullName); val11.GenericArguments.Add(val10.GenericArguments[k]); } val9 = (MethodReference)(object)val11; } return val9; } } } return null; bool CompareMethods(MethodBase m) { ParameterInfo[] parameters = m.GetParameters(); if (method2.IsGenericInstance != m.IsGenericMethodDefinition || parameters.Length != 0 != method2.HasParameters) { return false; } if (method2.HasParameters) { if (method2.Parameters.Count != parameters.Length) { return false; } for (int l = 0; l < method2.Parameters.Count; l++) { if (parameters[l].ParameterType.IsGenericParameter ? (!((ParameterReference)method2.Parameters[l]).ParameterType.IsGenericParameter) : (!AreSame(((ParameterReference)method2.Parameters[l]).ParameterType, module2.ImportReference(parameters[l].ParameterType)))) { return false; } } } return true; } } } public static bool PreventHarmonyInteropFixLoad(Assembly? __0) { return __0 == null; } public static void Patch(IEnumerable<string>? extraNamespaces = null) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Expected O, but got Unknown //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Expected O, but got Unknown Harmony val = new Harmony("org.bepinex.plugins.APIManager"); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(PluginInfo), "ToString", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Patcher), "GrabPluginInfo", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Assembly), "LoadFile", new Type[1] { typeof(string) }, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Patcher), "InterceptAssemblyLoadFile", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Assembly), "LoadFile", new Type[1] { typeof(string) }, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Patcher), "CheckAssemblyLoadFile", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Assembly), "LoadFile", new Type[1] { typeof(string) }, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Patcher), "ReplaceAssemblyLoadWithCache", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); new PatchClassProcessor(val, typeof(AssemblyLoadInterceptor), true).Patch(); Type type = typeof(AssemblyPatcher).Assembly.GetType("BepInEx.Preloader.RuntimeFixes.HarmonyInteropFix"); if ((object)type != null) { val.Patch((MethodBase)AccessTools.DeclaredMethod(type, "OnAssemblyLoad", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Patcher), "PreventHarmonyInteropFixLoad", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } IEnumerable<TypeInfo> source; try { source = patchingAssembly.DefinedTypes.ToList(); } catch (ReflectionTypeLoadException ex) { source = from t in ex.Types where t != null select t.GetTypeInfo(); } BaseUnityPlugin val2 = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); redirectedNamespaces = new HashSet<string>(extraNamespaces ?? Array.Empty<string>()) { ((object)val2).GetType().Namespace }; modGUID = val2.Info.Metadata.GUID; } } } namespace LocalizationManager { [PublicAPI] public class Localizer { private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors; private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts; private static readonly ConditionalWeakTable<Localization, string> localizationLanguage; private static readonly List<WeakReference<Localization>> localizationObjects; private static BaseUnityPlugin? _plugin; private static readonly List<string> fileExtensions; private static BaseUnityPlugin plugin { get { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown if (_plugin == null) { IEnumerable<TypeInfo> source; try { source = Assembly.GetExecutingAssembly().DefinedTypes.ToList(); } catch (ReflectionTypeLoadException ex) { source = from t in ex.Types where t != null select t.GetTypeInfo(); } _plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); } return _plugin; } } public static event Action? OnLocalizationComplete; private static void UpdatePlaceholderText(Localization localization, string key) { localizationLanguage.TryGetValue(localization, out string value); string text = loadedTexts[value][key]; if (PlaceholderProcessors.TryGetValue(key, out Dictionary<string, Func<string>> value2)) { text = value2.Aggregate(text, (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value())); } localization.AddWord(key, text); } public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, Func<T, string>? convertConfigValue = null) where T : notnull { string key2 = key; string placeholder2 = placeholder; Func<T, string> convertConfigValue2 = convertConfigValue; ConfigEntry<T> config2 = config; if (convertConfigValue2 == null) { convertConfigValue2 = (T val) => val.ToString(); } if (!PlaceholderProcessors.ContainsKey(key2)) { PlaceholderProcessors[key2] = new Dictionary<string, Func<string>>(); } config2.SettingChanged += delegate { UpdatePlaceholder(); }; if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage())) { UpdatePlaceholder(); } void UpdatePlaceholder() { PlaceholderProcessors[key2][placeholder2] = () => convertConfigValue2(config2.Value); UpdatePlaceholderText(Localization.instance, key2); } } public static void AddText(string key, string text) { List<WeakReference<Localization>> list = new List<WeakReference<Localization>>(); foreach (WeakReference<Localization> localizationObject in localizationObjects) { if (localizationObject.TryGetTarget(out var target)) { Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)]; if (!target.m_translations.ContainsKey(key)) { dictionary[key] = text; target.AddWord(key, text); } } else { list.Add(localizationObject); } } foreach (WeakReference<Localization> item in list) { localizationObjects.Remove(item); } } public static void Load() { _ = plugin; } public static void LoadLocalizationLater(Localization __instance) { LoadLocalization(Localization.instance, __instance.GetSelectedLanguage()); } public static void SafeCallLocalizeComplete() { Localizer.OnLocalizationComplete?.Invoke(); } private static void LoadLocalization(Localization __instance, string language) { if (!localizationLanguage.Remove(__instance)) { localizationObjects.Add(new WeakReference<Localization>(__instance)); } localizationLanguage.Add(__instance, language); Dictionary<string, string> dictionary = new Dictionary<string, string>(); foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories) where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0 select f) { string text = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' })[1]; if (dictionary.ContainsKey(text)) { Debug.LogWarning((object)("Duplicate key " + text + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped.")); } else { dictionary[text] = item; } } byte[] array = LoadTranslationFromAssembly("English"); if (array == null) { throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml."); } Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array)); if (dictionary2 == null) { throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty."); } string text2 = null; if (language != "English") { if (dictionary.TryGetValue(language, out var value)) { text2 = File.ReadAllText(value); } else { byte[] array2 = LoadTranslationFromAssembly(language); if (array2 != null) { text2 = Encoding.UTF8.GetString(array2); } } } if (text2 == null && dictionary.TryGetValue("English", out var value2)) { text2 = File.ReadAllText(value2); } if (text2 != null) { foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text2) ?? new Dictionary<string, string>()) { dictionary2[item2.Key] = item2.Value; } } loadedTexts[language] = dictionary2; foreach (KeyValuePair<string, string> item3 in dictionary2) { UpdatePlaceholderText(__instance, item3.Key); } } static Localizer() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>(); loadedTexts = new Dictionary<string, Dictionary<string, string>>(); localizationLanguage = new ConditionalWeakTable<Localization, string>(); localizationObjects = new List<WeakReference<Localization>>(); fileExtensions = new List<string> { ".json", ".yml" }; Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager"); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "SetupLanguage", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "SetupGui", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalizationLater", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "SafeCallLocalizeComplete", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static byte[]? LoadTranslationFromAssembly(string language) { foreach (string fileExtension in fileExtensions) { byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension); if (array != null) { return array; } } return null; } public static byte[]? ReadEmbeddedFileBytes(string resourceFileName, Assembly? containingAssembly = null) { string resourceFileName2 = resourceFileName; using MemoryStream memoryStream = new MemoryStream(); if ((object)containingAssembly == null) { containingAssembly = Assembly.GetCallingAssembly(); } string text = containingAssembly.GetManifestResourceNames().FirstOrDefault((string str) => str.EndsWith(resourceFileName2, StringComparison.Ordinal)); if (text != null) { containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream); } return (memoryStream.Length == 0L) ? null : memoryStream.ToArray(); } } } namespace ItemDataManager { [PublicAPI] public abstract class ItemData { internal static WeakReference<ItemInfo> constructingInfo = null; 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 ItemInfo 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() { } 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 Dictionary<string, FieldInfo> 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 { [CompilerGenerated] private sealed class <>c__DisplayClass57_0 { public Label target; public CodeInstruction targetedInstr; internal bool <CheckStackableInFindFreeStackMethods>b__1(CodeInstruction i) { return i.labels.Contains(target); } internal bool <CheckStackableInFindFreeStackMethods>b__2(CodeInstruction i) { Label? label = default(Label?); if (CodeInstructionExtensions.Branches(i, ref label)) { return targetedInstr.labels.Contains(label.Value); } return false; } } [CompilerGenerated] private sealed class <CheckStackableInFindFreeStackMethods>d__57 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private IEnumerable<CodeInstruction> instructionsEnumerable; public IEnumerable<CodeInstruction> <>3__instructionsEnumerable; private <>c__DisplayClass57_0 <>8__1; private CodeInstruction[] <instructions>5__2; private CodeInstruction <lastBranch>5__3; private CodeInstruction <loadingInstruction>5__4; private int <i>5__5; CodeInstruction IEnumerator<CodeInstruction>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <CheckStackableInFindFreeStackMethods>d__57(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { <>8__1 = null; <instructions>5__2 = null; <lastBranch>5__3 = null; <loadingInstruction>5__4 = null; <>1__state = -2; } private bool MoveNext() { //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Expected O, but got Unknown //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Expected O, but got Unknown //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Expected O, but got Unknown int num; switch (<>1__state) { default: return false; case 0: { <>1__state = -1; <>8__1 = new <>c__DisplayClass57_0(); <instructions>5__2 = instructionsEnumerable.ToArray(); <>8__1.target = (Label)<instructions>5__2.First((CodeInstruction i) => i.opcode == OpCodes.Br || i.opcode == OpCodes.Br_S).operand; <>8__1.targetedInstr = <instructions>5__2.First((CodeInstruction i) => i.labels.Contains(<>8__1.target)); Label? label = default(Label?); <lastBranch>5__3 = <instructions>5__2.Reverse().First((CodeInstruction i) => CodeInstructionExtensions.Branches(i, ref label) && <>8__1.targetedInstr.labels.Contains(label.Value)); <loadingInstruction>5__4 = null; <i>5__5 = 0; break; } case 1: <>1__state = -1; if (<loadingInstruction>5__4 == null && <instructions>5__2[<i>5__5].opcode == OpCodes.Call && ((MethodInfo)<instructions>5__2[<i>5__5].operand).Name == "get_Current") { <loadingInstruction>5__4 = <instructions>5__2[<i>5__5 + 1].Clone(); <loadingInstruction>5__4.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>5__4.opcode]; } if (<instructions>5__2[<i>5__5] == <lastBranch>5__3) { <>2__current = <loadingInstruction>5__4; <>1__state = 2; return true; } goto IL_02bc; case 2: <>1__state = -1; <>2__current = new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.DeclaredField(typeof(ItemInfo), "checkingForStackableItemData")); <>1__state = 3; return true; case 3: <>1__state = -1; <>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ItemInfo), "CheckItemDataIsStackableFindFree", (Type[])null, (Type[])null)); <>1__state = 4; return true; case 4: <>1__state = -1; <>2__current = new CodeInstruction(OpCodes.Brfalse, (object)<>8__1.target); <>1__state = 5; return true; case 5: { <>1__state = -1; goto IL_02bc; } IL_02bc: num = <i>5__5 + 1; <i>5__5 = num; break; } if (<i>5__5 < <instructions>5__2.Length) { <>2__current = <instructions>5__2[<i>5__5]; <>1__state = 1; return true; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator() { <CheckStackableInFindFreeStackMethods>d__57 <CheckStackableInFindFreeStackMethods>d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; <CheckStackableInFindFreeStackMethods>d__ = this; } else { <CheckStackableInFindFreeStackMethods>d__ = new <CheckStackableInFindFreeStackMethods>d__57(0); } <CheckStackableInFindFreeStackMethods>d__.instructionsEnumerable = <>3__instructionsEnumerable; return <CheckStackableInFindFreeStackMethods>d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<CodeInstruction>)this).GetEnumerator(); } } [CompilerGenerated] private sealed class <ImportCustomDataOnUpgrade>d__71 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private IEnumerable<CodeInstruction> instructionList; public IEnumerable<CodeInstruction> <>3__instructionList; private List<CodeInstruction>.Enumerator <>7__wrap1; private CodeInstruction <instruction>5__3; CodeInstruction IEnumerator<CodeInstruction>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <ImportCustomDataOnUpgrade>d__71(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 1) <= 2u) { try { } finally { <>m__Finally1(); } } <>7__wrap1 = default(List<CodeInstruction>.Enumerator); <instruction>5__3 = null; <>1__state = -2; } private bool MoveNext() { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Expected O, but got Unknown try { switch (<>1__state) { default: return false; case 0: { <>1__state = -1; List<CodeInstruction> list = instructionList.ToList(); <>7__wrap1 = list.GetEnumerator(); <>1__state = -3; break; } case 1: <>1__state = -3; if (<instruction>5__3.opcode == OpCodes.Stfld && CodeInstructionExtensions.OperandIs(<instruction>5__3, (MemberInfo)AccessTools.DeclaredField(typeof(ItemData), "m_dropPrefab"))) { <>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null); <>1__state = 2; return true; } goto IL_0118; case 2: <>1__state = -3; <>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ItemInfo), "CopyCustomDataFromUpgradedItem", (Type[])null, (Type[])null)); <>1__state = 3; return true; case 3: { <>1__state = -3; goto IL_0118; } IL_0118: <instruction>5__3 = null; break; } if (<>7__wrap1.MoveNext()) { <instruction>5__3 = <>7__wrap1.Current; <>2__current = <instruction>5__3; <>1__state = 1; return true; } <>m__Finally1(); <>7__wrap1 = default(List<CodeInstruction>.Enumerator); return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; ((IDisposable)<>7__wrap1).Dispose(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator() { <ImportCustomDataOnUpgrade>d__71 <ImportCustomDataOnUpgrade>d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; <ImportCustomDataOnUpgrade>d__ = this; } else { <ImportCustomDataOnUpgrade>d__ = new <ImportCustomDataOnUpgrade>d__71(0); } <ImportCustomDataOnUpgrade>d__.instructionList = <>3__instructionList; return <ImportCustomDataOnUpgrade>d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<CodeInstruction>)this).GetEnumerator(); } } [CompilerGenerated] private sealed class <TransferCustomItemDataOnUpgrade>d__68 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private IEnumerable<CodeInstruction> instructions; public IEnumerable<CodeInstruction> <>3__instructions; private MethodInfo <itemDeleter>5__2; private IEnumerator<CodeInstruction> <>7__wrap2; private CodeInstruction <instruction>5__4; CodeInstruction IEnumerator<CodeInstruction>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <TransferCustomItemDataOnUpgrade>d__68(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 1) <= 2u) { try { } finally { <>m__Finally1(); } } <itemDeleter>5__2 = null; <>7__wrap2 = null; <instruction>5__4 = null; <>1__state = -2; } private bool MoveNext() { //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <itemDeleter>5__2 = AccessTools.DeclaredMethod(typeof(Inventory), "RemoveItem", new Type[1] { typeof(ItemData) }, (Type[])null); <>7__wrap2 = instructions.GetEnumerator(); <>1__state = -3; goto IL_0136; case 1: <>1__state = -3; <>2__current = new CodeInstruction(OpCodes.Stsfld, (object)AccessTools.DeclaredField(typeof(ItemInfo), "currentlyUpgradingItem")); <>1__state = 2; return true; case 2: <>1__state = -3; goto IL_0110; case 3: { <>1__state = -3; <instruction>5__4 = null; goto IL_0136; } IL_0136: if (<>7__wrap2.MoveNext()) { <instruction>5__4 = <>7__wrap2.Current; if (<instruction>5__4.opcode == OpCodes.Callvirt && CodeInstructionExtensions.OperandIs(<instruction>5__4, (MemberInfo)<itemDeleter>5__2)) { <>2__current = new CodeInstruction(OpCodes.Dup, (object)null); <>1__state = 1; return true; } goto IL_0110; } <>m__Finally1(); <>7__wrap2 = null; return false; IL_0110: <>2__current = <instruction>5__4; <>1__state = 3; return true; } } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap2 != null) { <>7__wrap2.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator() { <TransferCustomItemDataOnUpgrade>d__68 <TransferCustomItemDataOnUpgrade>d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; <TransferCustomItemDataOnUpgrade>d__ = this; } else { <TransferCustomItemDataOnUpgrade>d__ = new <TransferCustomItemDataOnUpgrade>d__68(0); } <TransferCustomItemDataOnUpgrade>d__.instructions = <>3__instructions; return <TransferCustomItemDataOnUpgrade>d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<CodeInstruction>)this).GetEnumerator(); } } public static HashSet<Type> ForceLoadTypes; 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>(); private WeakReference<ItemInfo>? selfReference; internal HashSet<string> isCloned = new HashSet<string>(); 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; private static ItemData? checkingForStackableItemData; private static Dictionary<string, string>? newValuesOnStackable; 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; } public string? this[string key] { get { return Get<StringItemData>(key)?.Value; } set { GetOrCreate<StringItemData>(key).Value = value ?? ""; } } internal static void addTypeToInheritorsCache(Type type, string typeKey) { Type type2 = type; if (!knownTypes.Contains(typeKey)) { knownTypes.Add(typeKey); Type type3 = type2; while ((object)type3 != null) { AddInterfaces(type3); type3 = type3.BaseType; } } void AddInterfaces(Type baseType) { if (!typeInheritorsCache.TryGetValue(baseType, out HashSet<Type> value)) { HashSet<Type> hashSet2 = (typeInheritorsCache[baseType] = new HashSet<Type>()); value = hashSet2; } value.Add(type2); 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 string value)) { return value; } return assemblyNameCache[assembly] = assembly.GetName().Name; } internal static string classKey(Type type, string key) { if (!classKeyCache.TryGetValue(type, out string 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); } 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; } public T? Get<T>(string key = "") where T : class { if (!typeInheritorsCache.TryGetValue(typeof(T), out HashSet<Type> 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 ItemData 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 ItemData 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 }); } 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 ItemInfo value)) { value.Save(); } } 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); } 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)) { ItemInfo itemInfo = itemData.Data(); if (!itemInfo.data.ContainsKey(key)) { itemInfo.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 ItemInfo 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 ItemInfo 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) { if (item == awakeningItem) { awakeningItem = null; } checkingForStackableItemData = item; } private static void ResetCheckingForStackableItemData() { checkingForStackableItemData = null; } [IteratorStateMachine(typeof(<CheckStackableInFindFreeStackMethods>d__57))] private static IEnumerable<CodeInstruction> CheckStackableInFindFreeStackMethods(IEnumerable<CodeInstruction> instructionsEnumerable) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <CheckStackableInFindFreeStackMethods>d__57(-2) { <>3__instructionsEnumerable = instructionsEnumerable }; } private static bool CheckItemDataIsStackableFindFree(ItemData item, 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; } 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; } } 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, 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, 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; } 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"); } [IteratorStateMachine(typeof(<TransferCustomItemDataOnUpgrade>d__68))] private static IEnumerable<CodeInstruction> TransferCustomItemDataOnUpgrade(IEnumerable<CodeInstruction> instructions, ILGenerator ilg) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <TransferCustomItemDataOnUpgrade>d__68(-2) { <>3__instructions = instructions }; } 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); } } [IteratorStateMachine(typeof(<ImportCustomDataOnUpgrade>d__71))] private static IEnumerable<CodeInstruction> ImportCustomDataOnUpgrade(IEnumerable<CodeInstruction> instructionList) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <ImportCustomDataOnUpgrade>d__71(-2) { <>3__instructionList = instructionList }; } 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_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Expected O, but got Unknown //IL_0310: Expected O, but got Unknown //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Expected O, but got Unknown //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Expected O, but got Unknown //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Expected O, but got Unknown //IL_03c0: Expected O, but got Unknown //IL_03f0: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Expected O, but got Unknown //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_0447: Unknown result type (might be due to invalid IL or missing references) //IL_0452: Expected O, but got Unknown //IL_0452: Expected O, but got Unknown //IL_04a3: Unknown result type (might be due to invalid IL or missing references) //IL_04b0: Expected O, but got Unknown //IL_0503: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Expected O, but got Unknown //IL_05bc: Unknown result type (might be due to invalid IL or missing references) //IL_05c9: Expected O, but got Unknown //IL_05f7: Unknown result type (might be due to invalid IL or missing references) //IL_0622: Unknown result type (might be due to invalid IL or missing references) //IL_0629: Expected O, but got Unknown //IL_064f: Unknown result type (might be due to invalid IL or missing references) //IL_065d: Expected O, but got Unknown //IL_065d: Expected O, but got Unknown //IL_069c: Unknown result type (might be due to invalid IL or missing references) //IL_06a9: Expected O, but got Unknown //IL_06d7: Unknown result type (might be due to invalid IL or missing references) //IL_0702: Unknown result type (might be due to invalid IL or missing references) //IL_070f: Expected O, but got Unknown //IL_070f: Expected O, but got Unknown //IL_074e: Unknown result type (might be due to invalid IL or missing references) //IL_075b: 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.Declare