Decompiled source of Atos Arrows JVL v1.0.30
plugins/AtosArrowsJVL.dll
Decompiled 3 months 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.Generic; using System.Collections.Specialized; using System.Data; using System.Diagnostics; using System.Dynamic; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Resources; 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.Threading; using System.Xml.Serialization; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Digitalroot.Valheim.Common; using Digitalroot.Valheim.Common.Json; using JetBrains.Annotations; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; using fastJSON; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("Digitalroot Technologies")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright © Digitalroot Technologies 2021 - 2024")] [assembly: AssemblyDescription("Port of AtosArrows to JvL.")] [assembly: AssemblyFileVersion("1.0.30.0")] [assembly: AssemblyInformationalVersion("1.0.30+71e1471e8147486122b29f475f2c6d62081fcf98")] [assembly: AssemblyProduct("AtosArrowsJvL")] [assembly: AssemblyTitle("AtosArrowsJVL")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Digitalroot-Valheim/Atokal-AtosArrowsJVL")] [assembly: NeutralResourcesLanguage("en-US")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.30.0")] [module: UnverifiableCode] namespace AtosArrowsJVL { [BepInPlugin("digitalroot.valheim.mods.atosarrows.jvl", "AtosArrowsJVL", "1.0.30")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("com.bepinex.plugins.atosarrows")] public class Main : BaseUnityPlugin, ITraceableLogging { public static Main Instance; private AssetBundle _assetBundle; public static ConfigEntry<int> NexusId; public const string Version = "1.0.30"; private const string Name = "AtosArrowsJVL"; public const string Guid = "digitalroot.valheim.mods.atosarrows.jvl"; public const string Namespace = "AtosArrowsJVL"; public string Source => "AtosArrowsJVL"; public bool EnableTrace { get; } public Main() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0054: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown try { EnableTrace = false; Instance = this; NexusId = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 1301, new ConfigDescription("Nexus mod ID for updates", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { Browsable = false, ReadOnly = true } })); Log.RegisterSource(Instance); Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); } catch (Exception ex) { ZLog.LogError((object)ex); } } [UsedImplicitly] public void Awake() { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); PrefabManager.OnVanillaPrefabsAvailable += AddClonedItems; } private void AddClonedItems() { try { Log.Trace(Instance, "AtosArrowsJVL." + MethodBase.GetCurrentMethod()?.DeclaringType?.Name + "." + MethodBase.GetCurrentMethod()?.Name); _assetBundle = AssetUtils.LoadAssetBundleFromResources("atoarrows", typeof(Main).Assembly); AddStoneArrows(); AddBluntedArrows(); AddBoneArrows(); AddFlintArrows(); AddObsidianArrows(); AddNeedleArrows(); AddFireArrows(); AddIceArrows(); AddPoisonArrows(); AddBombs(); AddXbow(); _assetBundle.Unload(false); PrefabManager.OnVanillaPrefabsAvailable -= AddClonedItems; } catch (Exception e) { Log.Error(Instance, e); } } private void AddBombs() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00db: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Expected O, but got Unknown //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Expected O, but got Unknown //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Expected O, but got Unknown //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Expected O, but got Unknown //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Expected O, but got Unknown //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Expected O, but got Unknown //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/items/firebomb.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 5; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 3; val.Name = "FireBomb"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Coal", Amount = 10 }, new RequirementConfig { Item = "Resin", Amount = 8 }, new RequirementConfig { Item = "LeatherScraps", Amount = 8 }, new RequirementConfig { Item = "Entrails", Amount = 2 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_ato_firebomb"; ItemManager.Instance.AddItem(val2); GameObject obj2 = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/items/icebomb.prefab"); val = new ItemConfig(); val.Amount = 5; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 3; val.Name = "IceBomb"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "FreezeGland", Amount = 10 }, new RequirementConfig { Item = "Resin", Amount = 8 }, new RequirementConfig { Item = "LeatherScraps", Amount = 8 }, new RequirementConfig { Item = "Entrails", Amount = 2 } }; CustomItem val3 = new CustomItem(obj2, false, val); val3.ItemDrop.m_itemData.m_shared.m_name = "$item_ato_icebomb"; ItemManager.Instance.AddItem(val3); } catch (Exception e) { Log.Error(Instance, e); } } private void AddBoneArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00db: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Expected O, but got Unknown //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Expected O, but got Unknown //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Expected O, but got Unknown //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Expected O, but got Unknown //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Expected O, but got Unknown //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/arrowbone.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 20; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 3; val.Name = "BoneArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "BoneFragments", Amount = 4 }, new RequirementConfig { Item = "Wood", Amount = 8 }, new RequirementConfig { Item = "Feathers", Amount = 2 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_bone"; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val2); GameObject obj2 = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/heavy/arrowheavybone.prefab"); val = new ItemConfig(); val.Amount = 10; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 3; val.Name = "Heavy Bone Arrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "BoneFragments", Amount = 6 }, new RequirementConfig { Item = "RoundLog", Amount = 10 }, new RequirementConfig { Item = "Feathers", Amount = 5 } }; CustomItem val3 = new CustomItem(obj2, false, val); val3.ItemDrop.m_itemData.m_shared.m_description = "$item_atoarrow_heavy_bone_description"; val3.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_heavy_bone"; val3.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; val3.ItemDrop.m_itemData.m_shared.m_damages.m_pierce = 32f; val3.ItemDrop.m_itemData.m_shared.m_damages.m_slash = 32f; val3.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 10f; ItemManager.Instance.AddItem(val3); } catch (Exception e) { Log.Error(Instance, e); } } private void AddBluntedArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00db: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Expected O, but got Unknown //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Expected O, but got Unknown //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Expected O, but got Unknown //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Expected O, but got Unknown //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Expected O, but got Unknown //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/arrowcore.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 20; val.CraftingStation = "forge"; val.Enabled = true; val.MinStationLevel = 2; val.Name = "CoreArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Bronze", Amount = 1 }, new RequirementConfig { Item = "Stone", Amount = 2 }, new RequirementConfig { Item = "RoundLog", Amount = 8 }, new RequirementConfig { Item = "Feathers", Amount = 2 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_core"; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val2); GameObject obj2 = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/heavy/arrowheavycore.prefab"); val = new ItemConfig(); val.Amount = 10; val.CraftingStation = "forge"; val.Enabled = true; val.MinStationLevel = 3; val.Name = "HeavyCoreArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Bronze", Amount = 2 }, new RequirementConfig { Item = "Stone", Amount = 4 }, new RequirementConfig { Item = "RoundLog", Amount = 12 }, new RequirementConfig { Item = "Feathers", Amount = 2 } }; CustomItem val3 = new CustomItem(obj2, false, val); val3.ItemDrop.m_itemData.m_shared.m_description = "$item_atoarrow_heavy_core_description"; val3.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_heavy_core"; val3.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; val3.ItemDrop.m_itemData.m_shared.m_damages.m_blunt = 64f; val3.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 10f; ItemManager.Instance.AddItem(val3); } catch (Exception e) { Log.Error(Instance, e); } } private void AddFireArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00db: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Expected O, but got Unknown //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Expected O, but got Unknown //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Expected O, but got Unknown //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Expected O, but got Unknown //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Expected O, but got Unknown //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Expected O, but got Unknown //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Expected O, but got Unknown //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_032d: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Expected O, but got Unknown //IL_0337: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Expected O, but got Unknown //IL_0351: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_0369: Expected O, but got Unknown //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_037b: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Expected O, but got Unknown //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/arrowobsidianfire.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 20; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 4; val.Name = "BigFireArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Obsidian", Amount = 4 }, new RequirementConfig { Item = "Resin", Amount = 8 }, new RequirementConfig { Item = "Wood", Amount = 8 }, new RequirementConfig { Item = "Feathers", Amount = 2 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_arrow_obsidianfire"; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val2); GameObject obj2 = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/heavy/arrowheavyfire.prefab"); val = new ItemConfig(); val.Amount = 10; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 4; val.Name = "HeavyFireArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Obsidian", Amount = 6 }, new RequirementConfig { Item = "Resin", Amount = 10 }, new RequirementConfig { Item = "FineWood", Amount = 10 }, new RequirementConfig { Item = "Feathers", Amount = 5 } }; CustomItem val3 = new CustomItem(obj2, false, val); val3.ItemDrop.m_itemData.m_shared.m_description = "$item_arrow_heavyfire_description"; val3.ItemDrop.m_itemData.m_shared.m_name = "$item_arrow_heavyfire"; val3.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; val3.ItemDrop.m_itemData.m_shared.m_damages.m_pierce = 32f; val3.ItemDrop.m_itemData.m_shared.m_damages.m_fire = 72f; val3.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 10f; ItemManager.Instance.AddItem(val3); GameObject obj3 = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/arrowfireaoe.prefab"); val = new ItemConfig(); val.Amount = 5; val.CraftingStation = "forge"; val.Enabled = true; val.MinStationLevel = 6; val.Name = "FireAoeArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Crystal", Amount = 4 }, new RequirementConfig { Item = "FireBomb", Amount = 1 }, new RequirementConfig { Item = "FineWood", Amount = 8 }, new RequirementConfig { Item = "Feathers", Amount = 2 } }; CustomItem val4 = new CustomItem(obj3, false, val); val4.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_bigfire"; val4.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val4); } catch (Exception e) { Log.Error(Instance, e); } } private void AddFlintArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/heavy/arrowheavyflint.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 10; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 3; val.Name = "HeavyFlintArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "Flint", Amount = 6 }, new RequirementConfig { Item = "RoundLog", Amount = 12 }, new RequirementConfig { Item = "Feathers", Amount = 5 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_description = "$item_atoarrow_heavy_flint_description"; val2.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_heavy_flint"; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; val2.ItemDrop.m_itemData.m_shared.m_damages.m_pierce = 47f; val2.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 10f; ItemManager.Instance.AddItem(val2); } catch (Exception e) { Log.Error(Instance, e); } } private void AddIceArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: 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_0111: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Expected O, but got Unknown //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Expected O, but got Unknown //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Expected O, but got Unknown //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Expected O, but got Unknown //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Expected O, but got Unknown //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Expected O, but got Unknown //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/heavy/arrowheavyfrost.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 10; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 4; val.Name = "HeavyIceArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Obsidian", Amount = 6 }, new RequirementConfig { Item = "FreezeGland", Amount = 10 }, new RequirementConfig { Item = "FineWood", Amount = 10 }, new RequirementConfig { Item = "Feathers", Amount = 5 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_arrow_heavy_frost"; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; val2.ItemDrop.m_itemData.m_shared.m_damages.m_pierce = 32f; val2.ItemDrop.m_itemData.m_shared.m_damages.m_frost = 72f; val2.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 10f; ItemManager.Instance.AddItem(val2); GameObject obj2 = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/arrowiceaoe.prefab"); val = new ItemConfig(); val.Amount = 5; val.CraftingStation = "forge"; val.Enabled = true; val.MinStationLevel = 6; val.Name = "IceAoeArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Crystal", Amount = 4 }, new RequirementConfig { Item = "IceBomb", Amount = 1 }, new RequirementConfig { Item = "FineWood", Amount = 8 }, new RequirementConfig { Item = "Feathers", Amount = 2 } }; CustomItem val3 = new CustomItem(obj2, false, val); val3.ItemDrop.m_itemData.m_shared.m_description = "$item_atoarrow_bigice_description"; val3.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_bigice"; val3.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val3); } catch (Exception e) { Log.Error(Instance, e); } } private void AddNeedleArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/heavy/arrowheavyneedle.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 10; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 4; val.Name = "HeavyNeedleArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "Needle", Amount = 10 }, new RequirementConfig { Item = "FineWood", Amount = 10 }, new RequirementConfig { Item = "Feathers", Amount = 5 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_arrow_heavyneedle"; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; val2.ItemDrop.m_itemData.m_shared.m_damages.m_pierce = 72f; val2.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 10f; ItemManager.Instance.AddItem(val2); } catch (Exception e) { Log.Error(Instance, e); } } private void AddObsidianArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/heavy/arrowheavyobsidian.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 10; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 4; val.Name = "HeavyObsidianArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "Obsidian", Amount = 6 }, new RequirementConfig { Item = "FineWood", Amount = 12 }, new RequirementConfig { Item = "Feathers", Amount = 5 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_arrow_heavyobsidian"; val2.ItemDrop.m_itemData.m_shared.m_damages.m_pierce = 67f; val2.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 10f; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val2); } catch (Exception e) { Log.Error(Instance, e); } } private void AddPoisonArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: 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_0111: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Expected O, but got Unknown //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Expected O, but got Unknown //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Expected O, but got Unknown //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Expected O, but got Unknown //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Expected O, but got Unknown //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Expected O, but got Unknown //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/heavy/arrowheavypoison.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 10; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 4; val.Name = "HeavyPoisonArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Obsidian", Amount = 6 }, new RequirementConfig { Item = "Ooze", Amount = 10 }, new RequirementConfig { Item = "FineWood", Amount = 10 }, new RequirementConfig { Item = "Feathers", Amount = 5 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_arrow_heavy_poison"; val2.ItemDrop.m_itemData.m_shared.m_damages.m_pierce = 32f; val2.ItemDrop.m_itemData.m_shared.m_damages.m_poison = 72f; val2.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 10f; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val2); GameObject obj2 = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/arrowpoisonaoe.prefab"); val = new ItemConfig(); val.Amount = 5; val.CraftingStation = "forge"; val.Enabled = true; val.MinStationLevel = 6; val.Name = "PoisonAoeArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Crystal", Amount = 4 }, new RequirementConfig { Item = "BombOoze", Amount = 1 }, new RequirementConfig { Item = "FineWood", Amount = 8 }, new RequirementConfig { Item = "Feathers", Amount = 2 } }; CustomItem val3 = new CustomItem(obj2, false, val); val3.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_aoepoison"; val3.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val3); } catch (Exception e) { Log.Error(Instance, e); } } private void AddStoneArrows() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00db: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/arrows/arrowstone.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 20; val.CraftingStation = "piece_workbench"; val.Enabled = true; val.MinStationLevel = 1; val.Name = "StoneArrow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "Stone", Amount = 2 }, new RequirementConfig { Item = "Wood", Amount = 8 }, new RequirementConfig { Item = "Feathers", Amount = 2 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_atoarrow_stone"; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val2); } catch (Exception e) { Log.Error(Instance, e); } } private void AddXbow() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00b3: 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_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Expected O, but got Unknown //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown try { Log.Trace(Instance, ((object)this).GetType().Namespace + "." + ((object)this).GetType().Name + "." + MethodBase.GetCurrentMethod()?.Name + "()"); GameObject obj = _assetBundle.LoadAsset<GameObject>("assets/atosarrows/bows/xbow.prefab"); ItemConfig val = new ItemConfig(); val.Amount = 1; val.CraftingStation = "forge"; val.RepairStation = "forge"; val.Enabled = true; val.MinStationLevel = 1; val.Name = "XBow"; val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4] { new RequirementConfig { Item = "Crystal", Amount = 10, AmountPerLevel = 2 }, new RequirementConfig { Item = "BlackMetal", Amount = 60, AmountPerLevel = 10 }, new RequirementConfig { Item = "FineWood", Amount = 8 }, new RequirementConfig { Item = "LinenThread", Amount = 20, AmountPerLevel = 2 } }; CustomItem val2 = new CustomItem(obj, false, val); val2.ItemDrop.m_itemData.m_shared.m_name = "$item_xbow"; val2.ItemDrop.m_itemData.m_shared.m_attackForce = 0f; val2.ItemDrop.m_itemData.m_shared.m_attack.m_projectileVel = 65f; val2.ItemDrop.m_itemData.m_shared.m_maxDurability = 600f; val2.ItemDrop.m_itemData.m_shared.m_blockPower = 10f; val2.ItemDrop.m_itemData.m_shared.m_maxStackSize = 1; val2.ItemDrop.m_itemData.m_shared.m_ammoType = "$ammo_arrows"; ItemManager.Instance.AddItem(val2); } catch (Exception e) { Log.Error(Instance, e); } } } } namespace Digitalroot.Valheim.Common { internal interface ITraceableLogging { string Source { get; } bool EnableTrace { get; } } internal sealed class Log { private static readonly Dictionary<string, TraceLogger> TraceLoggers; [UsedImplicitly] private static Log Instance { get; } static Log() { TraceLoggers = new Dictionary<string, TraceLogger>(); Instance = new Log(); } private Log() { TraceLoggers.Add("Digitalroot", new TraceLogger("Digitalroot", enableTrace: false)); } public static void RegisterSource(ITraceableLogging sender) { if ((!TraceLoggers.ContainsKey(sender.Source) || TraceLoggers[sender.Source].IsTraceEnabled != sender.EnableTrace) && (!TraceLoggers.ContainsKey(sender.Source) || sender.EnableTrace)) { if (TraceLoggers.ContainsKey(sender.Source) && sender.EnableTrace) { TraceLoggers[sender.Source].EnableTrace(); } else { TraceLoggers.Add(sender.Source, new TraceLogger(sender.Source, sender.EnableTrace)); } } } private static TraceLogger GetTraceLogger(ITraceableLogging sender) { if (!TraceLoggers.ContainsKey(sender.Source)) { return TraceLoggers["Digitalroot"]; } return TraceLoggers[sender.Source]; } [UsedImplicitly] public static void SetEnableTrace(ITraceableLogging sender, bool value) { if (value) { GetTraceLogger(sender).EnableTrace(); } else { GetTraceLogger(sender).DisableTrace(); } } [UsedImplicitly] public static void SetEnableTraceForAllLoggers(bool value) { foreach (TraceLogger value2 in TraceLoggers.Values) { if (value) { value2.EnableTrace(); } else { value2.DisableTrace(); } } } [UsedImplicitly] public static void Debug(ITraceableLogging sender, object value) { GetTraceLogger(sender).LoggerRef.LogDebug(value); } [UsedImplicitly] public static void Error(ITraceableLogging sender, Exception e, int i = 1) { Error(sender, "Message: " + e.Message); Error(sender, $"TargetSite: {e.TargetSite}"); Error(sender, "StackTrace: " + e.StackTrace); Error(sender, "Source: " + e.Source); if (e.Data.Count > 0) { foreach (object key in e.Data.Keys) { Error(sender, $"key: {key}, value: {e.Data[key]}"); } } if (e.InnerException != null) { Error(sender, $"--- InnerException [{i}][Start] ---"); Error(sender, e.InnerException, ++i); } } [UsedImplicitly] public static void Error(ITraceableLogging sender, object value) { GetTraceLogger(sender).LoggerRef.LogError(value); } [UsedImplicitly] public static void Info(ITraceableLogging sender, object value) { GetTraceLogger(sender).LoggerRef.LogInfo(value); } [UsedImplicitly] public static void Fatal(ITraceableLogging sender, Exception e, int i = 1) { Fatal(sender, "Message: " + e.Message); Fatal(sender, $"TargetSite: {e.TargetSite}"); Fatal(sender, "StackTrace: " + e.StackTrace); Fatal(sender, "Source: " + e.Source); if (e.Data.Count > 0) { foreach (object key in e.Data.Keys) { Fatal(sender, $"key: {key}, value: {e.Data[key]}"); } } if (e.InnerException != null) { Fatal(sender, $"--- InnerException [{i}][Start] ---"); Fatal(sender, e.InnerException, ++i); } } [UsedImplicitly] public static void Fatal(ITraceableLogging sender, object value) { GetTraceLogger(sender).LoggerRef.LogFatal(value); } [UsedImplicitly] public static void Message(ITraceableLogging sender, object value) { GetTraceLogger(sender).LoggerRef.LogMessage(value); } [UsedImplicitly] public static void Trace(ITraceableLogging sender, object value) { if (GetTraceLogger(sender).IsTraceEnabled || sender.EnableTrace) { GetTraceLogger(sender).LoggerRef.Log((LogLevel)63, value); } } [UsedImplicitly] public static void Warning(ITraceableLogging sender, object value) { GetTraceLogger(sender).LoggerRef.LogWarning(value); } } internal class TraceLogger { internal readonly ManualLogSource LoggerRef; private readonly string _source; private readonly FileInfo _traceFileInfo; public bool IsTraceEnabled { get; private set; } private DirectoryInfo AssemblyDirectory => new FileInfo(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)).Directory; public TraceLogger(string source, bool enableTrace) { _source = source; IsTraceEnabled = enableTrace; LoggerRef = Logger.CreateLogSource(_source); _traceFileInfo = new FileInfo(Path.Combine(Paths.BepInExRootPath ?? AssemblyDirectory.FullName, "logs", _source + ".Trace.log")); if (_traceFileInfo.DirectoryName != null) { Directory.CreateDirectory(_traceFileInfo.DirectoryName); } if (_traceFileInfo.Exists) { _traceFileInfo.Delete(); _traceFileInfo.Refresh(); } LoggerRef.LogEvent += OnLogEvent; } public void EnableTrace() { IsTraceEnabled = true; } public void DisableTrace() { IsTraceEnabled = false; } private void StopTrace() { LoggerRef.LogEvent -= OnLogEvent; } private void OnLogEvent(object sender, LogEventArgs e) { //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) if (e.Source.SourceName != _source || !IsTraceEnabled) { return; } using Mutex mutex = new Mutex(initiallyOwned: false, "Digitalroot.Valheim.Common.TraceLogger." + _source); mutex.WaitOne(); try { if (e.Data is string) { string contents = $"[{e.Level,-7}:{e.Source.SourceName,10}] {e.Data}{Environment.NewLine}"; File.AppendAllText(_traceFileInfo.FullName, contents, Encoding.UTF8); } else { string contents2 = $"[{e.Level,-7}:{e.Source.SourceName,10}] {JsonSerializationProvider.ToJson(e.Data)}{Environment.NewLine}"; File.AppendAllText(_traceFileInfo.FullName, contents2, Encoding.UTF8); } } finally { mutex.ReleaseMutex(); } } } } namespace Digitalroot.Valheim.Common.Json { [UsedImplicitly] internal static class JsonSerializationProvider { private static readonly JSONParameters JsonParameters = new JSONParameters { SerializeNullValues = false, SerializeToLowerCaseNames = false, BadListTypeChecking = true, ShowReadOnlyProperties = true, KVStyleStringDictionary = false, UseEscapedUnicode = true, InlineCircularReferences = true }; private static bool _customTypeLoaded; private static void Init() { if (!_customTypeLoaded) { JSON.RegisterCustomType(typeof(Vector3), delegate(object x) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) Vector3 val2 = (Vector3)x; return JSON.ToJSON(new float[3] { val2.x, val2.y, val2.z }); }, delegate(string x) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) float[] array2 = JSON.ToObject<float[]>(x); return (object)new Vector3(array2[0], array2[1], array2[2]); }); JSON.RegisterCustomType(typeof(Quaternion), delegate(object x) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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) Quaternion val = (Quaternion)x; return JSON.ToJSON(new float[4] { val.x, val.y, val.z, val.w }); }, delegate(string x) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) float[] array = JSON.ToObject<float[]>(x); return (object)new Quaternion(array[0], array[1], array[2], array[3]); }); _customTypeLoaded = true; } } public static T FromJson<T>(string json) { Init(); return JSON.ToObject<T>(json, JsonParameters); } public static string ToJson(object obj, bool pretty = false) { Init(); if (pretty) { return JSON.ToNiceJSON(obj, JsonParameters); } return JSON.ToJSON(obj, JsonParameters); } } } namespace fastJSON { internal sealed class JSONParameters { public bool UseOptimizedDatasetSchema = true; public bool UseFastGuid = true; public bool SerializeNullValues = true; public bool UseUTCDateTime = true; public bool ShowReadOnlyProperties; public bool UsingGlobalTypes = true; [Obsolete("Not needed anymore and will always match")] public bool IgnoreCaseOnDeserialize; public bool EnableAnonymousTypes; public bool UseExtensions = true; public bool UseEscapedUnicode = true; public bool KVStyleStringDictionary; public bool UseValuesOfEnums; public List<Type> IgnoreAttributes = new List<Type> { typeof(XmlIgnoreAttribute), typeof(NonSerializedAttribute) }; public bool ParametricConstructorOverride; public bool DateTimeMilliseconds; public byte SerializerMaxDepth = 20; public bool InlineCircularReferences; public bool SerializeToLowerCaseNames; public byte FormatterIndentSpaces = 3; public bool AllowNonQuotedKeys; public bool AutoConvertStringToNumbers = true; public bool OverrideObjectHashCodeChecking; [Obsolete("Racist term removed, please use BadListTypeChecking")] public bool BlackListTypeChecking = true; public bool BadListTypeChecking = true; public bool FullyQualifiedDataSetSchema; public void FixValues() { if (!UseExtensions) { UsingGlobalTypes = false; InlineCircularReferences = true; } if (EnableAnonymousTypes) { ShowReadOnlyProperties = true; } } public JSONParameters MakeCopy() { return new JSONParameters { AllowNonQuotedKeys = AllowNonQuotedKeys, DateTimeMilliseconds = DateTimeMilliseconds, EnableAnonymousTypes = EnableAnonymousTypes, FormatterIndentSpaces = FormatterIndentSpaces, IgnoreAttributes = new List<Type>(IgnoreAttributes), InlineCircularReferences = InlineCircularReferences, KVStyleStringDictionary = KVStyleStringDictionary, ParametricConstructorOverride = ParametricConstructorOverride, SerializeNullValues = SerializeNullValues, SerializerMaxDepth = SerializerMaxDepth, SerializeToLowerCaseNames = SerializeToLowerCaseNames, ShowReadOnlyProperties = ShowReadOnlyProperties, UseEscapedUnicode = UseEscapedUnicode, UseExtensions = UseExtensions, UseFastGuid = UseFastGuid, UseOptimizedDatasetSchema = UseOptimizedDatasetSchema, UseUTCDateTime = UseUTCDateTime, UseValuesOfEnums = UseValuesOfEnums, UsingGlobalTypes = UsingGlobalTypes, AutoConvertStringToNumbers = AutoConvertStringToNumbers, OverrideObjectHashCodeChecking = OverrideObjectHashCodeChecking, FullyQualifiedDataSetSchema = FullyQualifiedDataSetSchema, BadListTypeChecking = BadListTypeChecking }; } } internal sealed class Reflection { private delegate object CreateObject(); private delegate object CreateList(int capacity); public delegate object GenericGetter(object obj); public delegate object GenericSetter(object target, object value); public delegate object Deserialize(string data); public delegate string Serialize(object data); private static readonly Reflection instance; public static bool RDBMode; private SafeDictionary<Type, string> _tyname = new SafeDictionary<Type, string>(10); private SafeDictionary<string, Type> _typecache = new SafeDictionary<string, Type>(10); private SafeDictionary<Type, CreateObject> _constrcache = new SafeDictionary<Type, CreateObject>(10); private SafeDictionary<Type, CreateList> _conlistcache = new SafeDictionary<Type, CreateList>(10); private SafeDictionary<Type, Getters[]> _getterscache = new SafeDictionary<Type, Getters[]>(10); private SafeDictionary<string, Dictionary<string, myPropInfo>> _propertycache = new SafeDictionary<string, Dictionary<string, myPropInfo>>(10); private SafeDictionary<Type, Type[]> _genericTypes = new SafeDictionary<Type, Type[]>(10); private SafeDictionary<Type, Type> _genericTypeDef = new SafeDictionary<Type, Type>(10); private static SafeDictionary<short, OpCode> _opCodes; private static List<string> _badlistTypes; private static UTF8Encoding utf8; internal SafeDictionary<Type, Serialize> _customSerializer = new SafeDictionary<Type, Serialize>(); internal SafeDictionary<Type, Deserialize> _customDeserializer = new SafeDictionary<Type, Deserialize>(); public static Reflection Instance => instance; static Reflection() { instance = new Reflection(); RDBMode = false; _badlistTypes = new List<string> { "system.configuration.install.assemblyinstaller", "system.activities.presentation.workflowdesigner", "system.windows.resourcedictionary", "system.windows.data.objectdataprovider", "system.windows.forms.bindingsource", "microsoft.exchange.management.systemmanager.winforms.exchangesettingsprovider" }; utf8 = new UTF8Encoding(); } private Reflection() { } private static bool TryGetOpCode(short code, out OpCode opCode) { if (_opCodes != null) { return _opCodes.TryGetValue(code, out opCode); } SafeDictionary<short, OpCode> safeDictionary = new SafeDictionary<short, OpCode>(); FieldInfo[] fields = typeof(OpCodes).GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo fieldInfo in fields) { if (typeof(OpCode).IsAssignableFrom(fieldInfo.FieldType)) { OpCode value = (OpCode)fieldInfo.GetValue(null); if (value.OpCodeType != OpCodeType.Nternal) { safeDictionary.Add(value.Value, value); } } } _opCodes = safeDictionary; return _opCodes.TryGetValue(code, out opCode); } public static byte[] UTF8GetBytes(string str) { return utf8.GetBytes(str); } public static string UTF8GetString(byte[] bytes, int offset, int len) { return utf8.GetString(bytes, offset, len); } public unsafe static byte[] UnicodeGetBytes(string str) { int num = str.Length * 2; byte[] array = new byte[num]; fixed (void* value = str) { Marshal.Copy(new IntPtr(value), array, 0, num); } return array; } public static string UnicodeGetString(byte[] b) { return UnicodeGetString(b, 0, b.Length); } public unsafe static string UnicodeGetString(byte[] bytes, int offset, int buflen) { string text = ""; fixed (byte* ptr = bytes) { char* value = (char*)(ptr + offset); text = new string(value, 0, buflen / 2); } return text; } internal object CreateCustom(string v, Type type) { _customDeserializer.TryGetValue(type, out var value); return value(v); } internal void RegisterCustomType(Type type, Serialize serializer, Deserialize deserializer) { if (type != null && serializer != null && deserializer != null) { _customSerializer.Add(type, serializer); _customDeserializer.Add(type, deserializer); Instance.ResetPropertyCache(); } } internal bool IsTypeRegistered(Type t) { if (_customSerializer.Count() == 0) { return false; } Serialize value; return _customSerializer.TryGetValue(t, out value); } public Type GetGenericTypeDefinition(Type t) { Type value = null; if (_genericTypeDef.TryGetValue(t, out value)) { return value; } value = t.GetGenericTypeDefinition(); _genericTypeDef.Add(t, value); return value; } public Type[] GetGenericArguments(Type t) { Type[] value = null; if (_genericTypes.TryGetValue(t, out value)) { return value; } value = t.GetGenericArguments(); _genericTypes.Add(t, value); return value; } public Dictionary<string, myPropInfo> Getproperties(Type type, string typename, bool ShowReadOnlyProperties) { Dictionary<string, myPropInfo> value = null; if (_propertycache.TryGetValue(typename, out value)) { return value; } value = new Dictionary<string, myPropInfo>(10); BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; PropertyInfo[] properties = type.GetProperties(bindingAttr); PropertyInfo[] array = properties; foreach (PropertyInfo propertyInfo in array) { if (propertyInfo.GetIndexParameters().Length != 0) { continue; } myPropInfo myPropInfo2 = CreateMyProp(propertyInfo.PropertyType, propertyInfo.Name); myPropInfo2.setter = CreateSetMethod(type, propertyInfo, ShowReadOnlyProperties); if (myPropInfo2.setter != null) { myPropInfo2.CanWrite = true; } myPropInfo2.getter = CreateGetMethod(type, propertyInfo); object[] customAttributes = propertyInfo.GetCustomAttributes(inherit: true); object[] array2 = customAttributes; foreach (object obj in array2) { if (obj is System.Runtime.Serialization.DataMemberAttribute) { System.Runtime.Serialization.DataMemberAttribute dataMemberAttribute = (System.Runtime.Serialization.DataMemberAttribute)obj; if (dataMemberAttribute.Name != "") { myPropInfo2.memberName = dataMemberAttribute.Name; } } if (obj is DataMemberAttribute) { DataMemberAttribute dataMemberAttribute2 = (DataMemberAttribute)obj; if (dataMemberAttribute2.Name != "") { myPropInfo2.memberName = dataMemberAttribute2.Name; } } } if (myPropInfo2.memberName != null) { value.Add(myPropInfo2.memberName, myPropInfo2); } else { value.Add(propertyInfo.Name.ToLowerInvariant(), myPropInfo2); } } FieldInfo[] fields = type.GetFields(bindingAttr); FieldInfo[] array3 = fields; foreach (FieldInfo fieldInfo in array3) { myPropInfo myPropInfo3 = CreateMyProp(fieldInfo.FieldType, fieldInfo.Name); if (fieldInfo.IsLiteral) { continue; } if (!fieldInfo.IsInitOnly) { myPropInfo3.setter = CreateSetField(type, fieldInfo); } if (myPropInfo3.setter != null) { myPropInfo3.CanWrite = true; } myPropInfo3.getter = CreateGetField(type, fieldInfo); object[] customAttributes2 = fieldInfo.GetCustomAttributes(inherit: true); object[] array4 = customAttributes2; foreach (object obj2 in array4) { if (obj2 is System.Runtime.Serialization.DataMemberAttribute) { System.Runtime.Serialization.DataMemberAttribute dataMemberAttribute3 = (System.Runtime.Serialization.DataMemberAttribute)obj2; if (dataMemberAttribute3.Name != "") { myPropInfo3.memberName = dataMemberAttribute3.Name; } } if (obj2 is DataMemberAttribute) { DataMemberAttribute dataMemberAttribute4 = (DataMemberAttribute)obj2; if (dataMemberAttribute4.Name != "") { myPropInfo3.memberName = dataMemberAttribute4.Name; } } } if (myPropInfo3.memberName != null) { value.Add(myPropInfo3.memberName, myPropInfo3); } else { value.Add(fieldInfo.Name.ToLowerInvariant(), myPropInfo3); } } _propertycache.Add(typename, value); return value; } private myPropInfo CreateMyProp(Type t, string name) { myPropInfo myPropInfo2 = new myPropInfo(); myPropInfoType type = myPropInfoType.Unknown; if (t == typeof(int) || t == typeof(int?)) { type = myPropInfoType.Int; } else if (t == typeof(long) || t == typeof(long?)) { type = myPropInfoType.Long; } else if (t == typeof(string)) { type = myPropInfoType.String; } else if (t == typeof(bool) || t == typeof(bool?)) { type = myPropInfoType.Bool; } else if (t == typeof(DateTime) || t == typeof(DateTime?)) { type = myPropInfoType.DateTime; } else if (t.IsEnum) { type = myPropInfoType.Enum; } else if (t == typeof(Guid) || t == typeof(Guid?)) { type = myPropInfoType.Guid; } else if (t == typeof(StringDictionary)) { type = myPropInfoType.StringDictionary; } else if (t == typeof(NameValueCollection)) { type = myPropInfoType.NameValue; } else if (t.IsArray) { myPropInfo2.bt = t.GetElementType(); type = ((!(t == typeof(byte[]))) ? myPropInfoType.Array : myPropInfoType.ByteArray); } else if (t.Name.Contains("Dictionary")) { myPropInfo2.GenericTypes = Instance.GetGenericArguments(t); type = ((myPropInfo2.GenericTypes.Length == 0 || !(myPropInfo2.GenericTypes[0] == typeof(string))) ? myPropInfoType.Dictionary : myPropInfoType.StringKeyDictionary); } else if (t == typeof(Hashtable)) { type = myPropInfoType.Hashtable; } else if (t == typeof(DataSet)) { type = myPropInfoType.DataSet; } else if (t == typeof(DataTable)) { type = myPropInfoType.DataTable; } else if (IsTypeRegistered(t)) { type = myPropInfoType.Custom; } if (t.IsValueType && !t.IsPrimitive && !t.IsEnum && t != typeof(decimal)) { myPropInfo2.IsStruct = true; } myPropInfo2.IsInterface = t.IsInterface; myPropInfo2.IsClass = t.IsClass; myPropInfo2.IsValueType = t.IsValueType; if (t.IsGenericType) { myPropInfo2.IsGenericType = true; myPropInfo2.bt = Instance.GetGenericArguments(t)[0]; } myPropInfo2.pt = t; myPropInfo2.Name = name; myPropInfo2.changeType = GetChangeType(t); myPropInfo2.Type = type; return myPropInfo2; } private Type GetChangeType(Type conversionType) { if (conversionType.IsGenericType && conversionType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))) { return Instance.GetGenericArguments(conversionType)[0]; } return conversionType; } public string GetTypeAssemblyName(Type t) { string value = ""; if (_tyname.TryGetValue(t, out value)) { return value; } string assemblyQualifiedName = t.AssemblyQualifiedName; _tyname.Add(t, assemblyQualifiedName); return assemblyQualifiedName; } internal Type GetTypeFromCache(string typename, bool badlistChecking) { Type value = null; if (_typecache.TryGetValue(typename, out value)) { return value; } if (badlistChecking) { string text = typename.Trim().ToLowerInvariant(); foreach (string badlistType in _badlistTypes) { if (text.StartsWith(badlistType, StringComparison.Ordinal)) { throw new Exception("Black list type encountered, possible attack vector when using $type : " + typename); } } } Type type = Type.GetType(typename); if (RDBMode && type == null) { type = Type.GetType(typename, (AssemblyName name) => (from z in AppDomain.CurrentDomain.GetAssemblies() where z.FullName == name.FullName select z).FirstOrDefault(), null, throwOnError: true); } _typecache.Add(typename, type); return type; } internal object FastCreateList(Type objtype, int capacity) { try { int capacity2 = 10; if (capacity > 10) { capacity2 = capacity; } CreateList value = null; if (_conlistcache.TryGetValue(objtype, out value)) { if (value != null) { return value(capacity2); } return FastCreateInstance(objtype); } ConstructorInfo constructor = objtype.GetConstructor(new Type[1] { typeof(int) }); if (constructor != null) { DynamicMethod dynamicMethod = new DynamicMethod("_fcil", objtype, new Type[1] { typeof(int) }, restrictedSkipVisibility: true); ILGenerator iLGenerator = dynamicMethod.GetILGenerator(); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Newobj, objtype.GetConstructor(new Type[1] { typeof(int) })); iLGenerator.Emit(OpCodes.Ret); value = (CreateList)dynamicMethod.CreateDelegate(typeof(CreateList)); _conlistcache.Add(objtype, value); return value(capacity2); } _conlistcache.Add(objtype, null); return FastCreateInstance(objtype); } catch (Exception innerException) { throw new Exception($"Failed to fast create instance for type '{objtype.FullName}' from assembly '{objtype.AssemblyQualifiedName}'", innerException); } } internal object FastCreateInstance(Type objtype) { try { CreateObject value = null; if (_constrcache.TryGetValue(objtype, out value)) { return value(); } if (objtype.IsClass) { DynamicMethod dynamicMethod = new DynamicMethod("_fcic", objtype, null, restrictedSkipVisibility: true); ILGenerator iLGenerator = dynamicMethod.GetILGenerator(); iLGenerator.Emit(OpCodes.Newobj, objtype.GetConstructor(Type.EmptyTypes)); iLGenerator.Emit(OpCodes.Ret); value = (CreateObject)dynamicMethod.CreateDelegate(typeof(CreateObject)); _constrcache.Add(objtype, value); } else { DynamicMethod dynamicMethod2 = new DynamicMethod("_fcis", typeof(object), null, restrictedSkipVisibility: true); ILGenerator iLGenerator2 = dynamicMethod2.GetILGenerator(); LocalBuilder local = iLGenerator2.DeclareLocal(objtype); iLGenerator2.Emit(OpCodes.Ldloca_S, local); iLGenerator2.Emit(OpCodes.Initobj, objtype); iLGenerator2.Emit(OpCodes.Ldloc_0); iLGenerator2.Emit(OpCodes.Box, objtype); iLGenerator2.Emit(OpCodes.Ret); value = (CreateObject)dynamicMethod2.CreateDelegate(typeof(CreateObject)); _constrcache.Add(objtype, value); } return value(); } catch (Exception innerException) { throw new Exception($"Failed to fast create instance for type '{objtype.FullName}' from assembly '{objtype.AssemblyQualifiedName}'", innerException); } } internal static GenericSetter CreateSetField(Type type, FieldInfo fieldInfo) { Type[] array = new Type[2]; array[0] = (array[1] = typeof(object)); DynamicMethod dynamicMethod = new DynamicMethod("_csf", typeof(object), array, type, skipVisibility: true); ILGenerator iLGenerator = dynamicMethod.GetILGenerator(); if (!type.IsClass) { LocalBuilder local = iLGenerator.DeclareLocal(type); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Unbox_Any, type); iLGenerator.Emit(OpCodes.Stloc_0); iLGenerator.Emit(OpCodes.Ldloca_S, local); iLGenerator.Emit(OpCodes.Ldarg_1); if (fieldInfo.FieldType.IsClass) { iLGenerator.Emit(OpCodes.Castclass, fieldInfo.FieldType); } else { iLGenerator.Emit(OpCodes.Unbox_Any, fieldInfo.FieldType); } iLGenerator.Emit(OpCodes.Stfld, fieldInfo); iLGenerator.Emit(OpCodes.Ldloc_0); iLGenerator.Emit(OpCodes.Box, type); iLGenerator.Emit(OpCodes.Ret); } else { iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); if (fieldInfo.FieldType.IsValueType) { iLGenerator.Emit(OpCodes.Unbox_Any, fieldInfo.FieldType); } iLGenerator.Emit(OpCodes.Stfld, fieldInfo); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ret); } return (GenericSetter)dynamicMethod.CreateDelegate(typeof(GenericSetter)); } internal static FieldInfo GetGetterBackingField(PropertyInfo autoProperty) { MethodInfo getMethod = autoProperty.GetGetMethod(); if (!getMethod.IsDefined(typeof(CompilerGeneratedAttribute), inherit: false)) { return null; } byte[] array = getMethod.GetMethodBody()?.GetILAsByteArray() ?? new byte[0]; OpCode opCode; for (int i = 0; i < array.Length; i += ((opCode.OperandType != OperandType.InlineNone) ? ((opCode.OperandType == OperandType.ShortInlineBrTarget || opCode.OperandType == OperandType.ShortInlineI || opCode.OperandType == OperandType.ShortInlineVar) ? 1 : ((opCode.OperandType == OperandType.InlineVar) ? 2 : ((opCode.OperandType == OperandType.InlineI8 || opCode.OperandType == OperandType.InlineR) ? 8 : ((opCode.OperandType == OperandType.InlineSwitch) ? (4 * (BitConverter.ToInt32(array, i) + 1)) : 4)))) : 0)) { byte b = array[i++]; if (!TryGetOpCode(b, out opCode) && (i >= array.Length || !TryGetOpCode((short)(b * 256 + array[i++]), out opCode))) { throw new NotSupportedException("Unknown IL code detected."); } if (opCode == OpCodes.Ldfld && opCode.OperandType == OperandType.InlineField && i + 4 <= array.Length) { return getMethod.Module.ResolveMember(BitConverter.ToInt32(array, i), getMethod.DeclaringType?.GetGenericArguments(), null) as FieldInfo; } } return null; } internal static GenericSetter CreateSetMethod(Type type, PropertyInfo propertyInfo, bool ShowReadOnlyProperties) { MethodInfo setMethod = propertyInfo.GetSetMethod(ShowReadOnlyProperties); if (setMethod == null) { if (!ShowReadOnlyProperties) { return null; } FieldInfo getterBackingField = GetGetterBackingField(propertyInfo); if (!(getterBackingField != null)) { return null; } return CreateSetField(type, getterBackingField); } Type[] array = new Type[2]; array[0] = (array[1] = typeof(object)); DynamicMethod dynamicMethod = new DynamicMethod("_csm", typeof(object), array, restrictedSkipVisibility: true); ILGenerator iLGenerator = dynamicMethod.GetILGenerator(); if (!type.IsClass) { LocalBuilder local = iLGenerator.DeclareLocal(type); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Unbox_Any, type); iLGenerator.Emit(OpCodes.Stloc_0); iLGenerator.Emit(OpCodes.Ldloca_S, local); iLGenerator.Emit(OpCodes.Ldarg_1); if (propertyInfo.PropertyType.IsClass) { iLGenerator.Emit(OpCodes.Castclass, propertyInfo.PropertyType); } else { iLGenerator.Emit(OpCodes.Unbox_Any, propertyInfo.PropertyType); } iLGenerator.EmitCall(OpCodes.Call, setMethod, null); iLGenerator.Emit(OpCodes.Ldloc_0); iLGenerator.Emit(OpCodes.Box, type); } else if (!setMethod.IsStatic) { iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Castclass, propertyInfo.DeclaringType); iLGenerator.Emit(OpCodes.Ldarg_1); if (propertyInfo.PropertyType.IsClass) { iLGenerator.Emit(OpCodes.Castclass, propertyInfo.PropertyType); } else { iLGenerator.Emit(OpCodes.Unbox_Any, propertyInfo.PropertyType); } iLGenerator.EmitCall(OpCodes.Callvirt, setMethod, null); iLGenerator.Emit(OpCodes.Ldarg_0); } else { iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); if (propertyInfo.PropertyType.IsClass) { iLGenerator.Emit(OpCodes.Castclass, propertyInfo.PropertyType); } else { iLGenerator.Emit(OpCodes.Unbox_Any, propertyInfo.PropertyType); } iLGenerator.Emit(OpCodes.Call, setMethod); } iLGenerator.Emit(OpCodes.Ret); return (GenericSetter)dynamicMethod.CreateDelegate(typeof(GenericSetter)); } internal static GenericGetter CreateGetField(Type type, FieldInfo fieldInfo) { DynamicMethod dynamicMethod = new DynamicMethod("_cgf", typeof(object), new Type[1] { typeof(object) }, type, skipVisibility: true); ILGenerator iLGenerator = dynamicMethod.GetILGenerator(); if (!type.IsClass) { LocalBuilder local = iLGenerator.DeclareLocal(type); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Unbox_Any, type); iLGenerator.Emit(OpCodes.Stloc_0); iLGenerator.Emit(OpCodes.Ldloca_S, local); iLGenerator.Emit(OpCodes.Ldfld, fieldInfo); if (fieldInfo.FieldType.IsValueType) { iLGenerator.Emit(OpCodes.Box, fieldInfo.FieldType); } } else { iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldfld, fieldInfo); if (fieldInfo.FieldType.IsValueType) { iLGenerator.Emit(OpCodes.Box, fieldInfo.FieldType); } } iLGenerator.Emit(OpCodes.Ret); return (GenericGetter)dynamicMethod.CreateDelegate(typeof(GenericGetter)); } internal static GenericGetter CreateGetMethod(Type type, PropertyInfo propertyInfo) { MethodInfo getMethod = propertyInfo.GetGetMethod(); if (getMethod == null) { return null; } DynamicMethod dynamicMethod = new DynamicMethod("_cgm", typeof(object), new Type[1] { typeof(object) }, type, skipVisibility: true); ILGenerator iLGenerator = dynamicMethod.GetILGenerator(); if (!type.IsClass) { LocalBuilder local = iLGenerator.DeclareLocal(type); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Unbox_Any, type); iLGenerator.Emit(OpCodes.Stloc_0); iLGenerator.Emit(OpCodes.Ldloca_S, local); iLGenerator.EmitCall(OpCodes.Call, getMethod, null); if (propertyInfo.PropertyType.IsValueType) { iLGenerator.Emit(OpCodes.Box, propertyInfo.PropertyType); } } else { if (!getMethod.IsStatic) { iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Castclass, propertyInfo.DeclaringType); iLGenerator.EmitCall(OpCodes.Callvirt, getMethod, null); } else { iLGenerator.Emit(OpCodes.Call, getMethod); } if (propertyInfo.PropertyType.IsValueType) { iLGenerator.Emit(OpCodes.Box, propertyInfo.PropertyType); } } iLGenerator.Emit(OpCodes.Ret); return (GenericGetter)dynamicMethod.CreateDelegate(typeof(GenericGetter)); } public Getters[] GetGetters(Type type, List<Type> IgnoreAttributes) { Getters[] value = null; if (_getterscache.TryGetValue(type, out value)) { return value; } BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; if (!type.IsClass) { bindingAttr = BindingFlags.Instance | BindingFlags.Public; } PropertyInfo[] properties = type.GetProperties(bindingAttr); List<Getters> list = new List<Getters>(); PropertyInfo[] array = properties; foreach (PropertyInfo propertyInfo in array) { bool readOnly = false; if (propertyInfo.GetIndexParameters().Length != 0) { continue; } if (!propertyInfo.CanWrite) { readOnly = true; } if (IgnoreAttributes != null) { bool flag = false; foreach (Type IgnoreAttribute in IgnoreAttributes) { if (propertyInfo.IsDefined(IgnoreAttribute, inherit: false)) { flag = true; break; } } if (flag) { continue; } } string memberName = null; object[] customAttributes = propertyInfo.GetCustomAttributes(inherit: true); object[] array2 = customAttributes; foreach (object obj in array2) { if (obj is System.Runtime.Serialization.DataMemberAttribute) { System.Runtime.Serialization.DataMemberAttribute dataMemberAttribute = (System.Runtime.Serialization.DataMemberAttribute)obj; if (dataMemberAttribute.Name != "") { memberName = dataMemberAttribute.Name; } } if (obj is DataMemberAttribute) { DataMemberAttribute dataMemberAttribute2 = (DataMemberAttribute)obj; if (dataMemberAttribute2.Name != "") { memberName = dataMemberAttribute2.Name; } } } GenericGetter genericGetter = CreateGetMethod(type, propertyInfo); if (genericGetter != null) { list.Add(new Getters { Getter = genericGetter, Name = propertyInfo.Name, lcName = propertyInfo.Name.ToLowerInvariant(), memberName = memberName, ReadOnly = readOnly }); } } FieldInfo[] fields = type.GetFields(bindingAttr); FieldInfo[] array3 = fields; foreach (FieldInfo fieldInfo in array3) { bool readOnly2 = false; if (fieldInfo.IsInitOnly) { readOnly2 = true; } if (IgnoreAttributes != null) { bool flag2 = false; foreach (Type IgnoreAttribute2 in IgnoreAttributes) { if (fieldInfo.IsDefined(IgnoreAttribute2, inherit: false)) { flag2 = true; break; } } if (flag2) { continue; } } string memberName2 = null; object[] customAttributes2 = fieldInfo.GetCustomAttributes(inherit: true); object[] array4 = customAttributes2; foreach (object obj2 in array4) { if (obj2 is System.Runtime.Serialization.DataMemberAttribute) { System.Runtime.Serialization.DataMemberAttribute dataMemberAttribute3 = (System.Runtime.Serialization.DataMemberAttribute)obj2; if (dataMemberAttribute3.Name != "") { memberName2 = dataMemberAttribute3.Name; } } if (obj2 is DataMemberAttribute) { DataMemberAttribute dataMemberAttribute4 = (DataMemberAttribute)obj2; if (dataMemberAttribute4.Name != "") { memberName2 = dataMemberAttribute4.Name; } } } if (!fieldInfo.IsLiteral) { GenericGetter genericGetter2 = CreateGetField(type, fieldInfo); if (genericGetter2 != null) { list.Add(new Getters { Getter = genericGetter2, Name = fieldInfo.Name, lcName = fieldInfo.Name.ToLowerInvariant(), memberName = memberName2, ReadOnly = readOnly2 }); } } } value = list.ToArray(); _getterscache.Add(type, value); return value; } internal void ResetPropertyCache() { _propertycache = new SafeDictionary<string, Dictionary<string, myPropInfo>>(); } internal void ClearReflectionCache() { _tyname = new SafeDictionary<Type, string>(10); _typecache = new SafeDictionary<string, Type>(10); _constrcache = new SafeDictionary<Type, CreateObject>(10); _getterscache = new SafeDictionary<Type, Getters[]>(10); _propertycache = new SafeDictionary<string, Dictionary<string, myPropInfo>>(10); _genericTypes = new SafeDictionary<Type, Type[]>(10); _genericTypeDef = new SafeDictionary<Type, Type>(10); } } internal sealed class SafeDictionary<TKey, TValue> { private readonly object _Padlock = new object(); private readonly Dictionary<TKey, TValue> _Dictionary; public TValue this[TKey key] { get { lock (_Padlock) { return _Dictionary[key]; } } set { lock (_Padlock) { _Dictionary[key] = value; } } } public SafeDictionary(int capacity) { _Dictionary = new Dictionary<TKey, TValue>(capacity); } public SafeDictionary() { _Dictionary = new Dictionary<TKey, TValue>(); } public bool TryGetValue(TKey key, out TValue value) { lock (_Padlock) { return _Dictionary.TryGetValue(key, out value); } } public int Count() { lock (_Padlock) { return _Dictionary.Count; } } public void Add(TKey key, TValue value) { lock (_Padlock) { if (!_Dictionary.ContainsKey(key)) { _Dictionary.Add(key, value); } } } } internal struct Getters { public string Name; public string lcName; public string memberName; public Reflection.GenericGetter Getter; public bool ReadOnly; } internal class myPropInfo { public Type pt; public Type bt; public Type changeType; public Reflection.GenericSetter setter; public Reflection.GenericGetter getter; public Type[] GenericTypes; public string Name; public string memberName; public myPropInfoType Type; public bool CanWrite; public bool IsClass; public bool IsValueType; public bool IsGenericType; public bool IsStruct; public bool IsInterface; } internal enum myPropInfoType { Int, Long, String, Bool, DateTime, Enum, Guid, Array, ByteArray, Dictionary, StringKeyDictionary, NameValue, StringDictionary, Hashtable, DataSet, DataTable, Custom, Unknown } internal class DataMemberAttribute : Attribute { public string Name { get; set; } } internal static class JSON { public static JSONParameters Parameters = new JSONParameters(); public static string ToNiceJSON(object obj) { string input = ToJSON(obj, Parameters); return Beautify(input); } public static string ToNiceJSON(object obj, JSONParameters param) { string input = ToJSON(obj, param); return Beautify(input, param.FormatterIndentSpaces); } public static string ToJSON(object obj) { return ToJSON(obj, Parameters); } public static string ToJSON(object obj, JSONParameters param) { param.FixValues(); param = param.MakeCopy(); Type c = null; if (obj == null) { return "null"; } if (obj.GetType().IsGenericType) { c = Reflection.Instance.GetGenericTypeDefinition(obj.GetType()); } if (typeof(IDictionary).IsAssignableFrom(c) || typeof(List<>).IsAssignableFrom(c)) { param.UsingGlobalTypes = false; } if (param.EnableAnonymousTypes) { param.UseExtensions = false; param.UsingGlobalTypes = false; } return new JSONSerializer(param).ConvertToJSON(obj); } public static object Parse(string json) { return new JsonParser(json, Parameters.AllowNonQuotedKeys).Decode(null); } public static dynamic ToDynamic(string json) { return new DynamicJson(json); } public static T ToObject<T>(string json) { return new deserializer(Parameters).ToObject<T>(json); } public static T ToObject<T>(string json, JSONParameters param) { return new deserializer(param).ToObject<T>(json); } public static object ToObject(string json) { return new deserializer(Parameters).ToObject(json, null); } public static object ToObject(string json, JSONParameters param) { return new deserializer(param).ToObject(json, null); } public static object ToObject(string json, Type type) { return new deserializer(Parameters).ToObject(json, type); } public static object ToObject(string json, Type type, JSONParameters par) { return new deserializer(par).ToObject(json, type); } public static object FillObject(object input, string json) { if (!(new JsonParser(json, Parameters.AllowNonQuotedKeys).Decode(input.GetType()) is Dictionary<string, object> d)) { return null; } return new deserializer(Parameters).ParseDictionary(d, null, input.GetType(), input); } public static object DeepCopy(object obj) { return new deserializer(Parameters).ToObject(ToJSON(obj)); } public static T DeepCopy<T>(T obj) { return new deserializer(Parameters).ToObject<T>(ToJSON(obj)); } public static string Beautify(string input) { string spaces = new string(' ', Parameters.FormatterIndentSpaces); return Formatter.PrettyPrint(input, spaces); } public static string Beautify(string input, byte spaces) { string spaces2 = new string(' ', spaces); return Formatter.PrettyPrint(input, spaces2); } public static void RegisterCustomType(Type type, Reflection.Serialize serializer, Reflection.Deserialize deserializer) { Reflection.Instance.RegisterCustomType(type, serializer, deserializer); } public static void ClearReflectionCache() { Reflection.Instance.ClearReflectionCache(); } } internal static class Formatter { private static void AppendIndent(StringBuilder sb, int count, string indent) { while (count > 0) { sb.Append(indent); count--; } } public static string PrettyPrint(string input) { return PrettyPrint(input, new string(' ', JSON.Parameters.FormatterIndentSpaces)); } public static string PrettyPrint(string input, string spaces) { StringBuilder stringBuilder = new StringBuilder(); int num = 0; int length = input.Length; char[] array = input.ToCharArray(); for (int i = 0; i < length; i++) { char c = array[i]; if (c == '"') { bool flag = true; while (flag) { stringBuilder.Append(c); c = array[++i]; switch (c) { case '\\': stringBuilder.Append(c); c = array[++i]; break; case '"': flag = false; break; } } } switch (c) { case '[': case '{': stringBuilder.Append(c); stringBuilder.AppendLine(); AppendIndent(stringBuilder, ++num, spaces); break; case ']': case '}': stringBuilder.AppendLine(); AppendIndent(stringBuilder, --num, spaces); stringBuilder.Append(c); break; case ',': stringBuilder.Append(c); stringBuilder.AppendLine(); AppendIndent(stringBuilder, num, spaces); break; case ':': stringBuilder.Append(" : "); break; default: if (!char.IsWhiteSpace(c)) { stringBuilder.Append(c); } break; } } return stringBuilder.ToString(); } } internal class deserializer { private JSONParameters _params; private bool _usingglobals; private Dictionary<object, int> _circobj; private Dictionary<int, object> _cirrev = new Dictionary<int, object>(); public deserializer(JSONParameters param) { if (param.OverrideObjectHashCodeChecking) { _circobj = new Dictionary<object, int>(10, ReferenceEqualityComparer.Default); } else { _circobj = new Dictionary<object, int>(); } param.FixValues(); _params = param.MakeCopy(); } public T ToObject<T>(string json) { Type typeFromHandle = typeof(T); object obj = ToObject(json, typeFromHandle); if (typeFromHandle.IsArray) { if ((obj as ICollection).Count == 0) { Type elementType = typeFromHandle.GetElementType(); object obj2 = Array.CreateInstance(elementType, 0); return (T)obj2; } return (T)obj; } return (T)obj; } public object ToObject(string json) { return ToObject(json, null); } public object ToObject(string json, Type type) { Type type2 = null; if (type != null && type.IsGenericType) { type2 = Reflection.Instance.GetGenericTypeDefinition(type); } _usingglobals = _params.UsingGlobalTypes; if (typeof(IDictionary).IsAssignableFrom(type2) || typeof(List<>).IsAssignableFrom(type2)) { _usingglobals = false; } object obj = new JsonParser(json, _params.AllowNonQuotedKeys).Decode(type); if (obj == null) { return null; } if (type != null) { if (type == typeof(DataSet)) { return CreateDataset(obj as Dictionary<string, object>, null); } if (type == typeof(DataTable)) { return CreateDataTable(obj as Dictionary<string, object>, null); } } if (obj is IDictionary) { if (type != null && typeof(Dictionary<, >).IsAssignableFrom(type2)) { return RootDictionary(obj, type); } return ParseDictionary(obj as Dictionary<string, object>, null, type, null); } if (obj is List<object>) { if (!(type != null)) { List<object> list = (List<object>)obj; if (list.Count > 0 && list[0].GetType() == typeof(Dictionary<string, object>)) { Dictionary<string, object> globaltypes = new Dictionary<string, object>(); List<object> list2 = new List<object>(); { foreach (object item in list) { list2.Add(ParseDictionary((Dictionary<string, object>)item, globaltypes, null, null)); } return list2; } } return list.ToArray(); } if (typeof(Dictionary<, >).IsAssignableFrom(type2)) { return RootDictionary(obj, type); } if (type2 == typeof(List<>)) { return RootList(obj, type); } if (type.IsArray) { return RootArray(obj, type); } if (type == typeof(Hashtable)) { return RootHashTable((List<object>)obj); } } else if (type != null && obj.GetType() != type) { return ChangeType(obj, type); } return obj; } private object RootHashTable(List<object> o) { Hashtable hashtable = new Hashtable(); foreach (Dictionary<string, object> item in o) { object obj = item["k"]; object obj2 = item["v"]; if (obj is Dictionary<string, object>) { obj = ParseDictionary((Dictionary<string, object>)obj, null, typeof(object), null); } if (obj2 is Dictionary<string, object>) { obj2 = ParseDictionary((Dictionary<string, object>)obj2, null, typeof(object), null); } hashtable.Add(obj, obj2); } return hashtable; } private object ChangeType(object value, Type conversionType) { if (conversionType == typeof(object)) { return value; } if (conversionType == typeof(int)) { if (!(value is string text)) { return (int)(long)value; } if (_params.AutoConvertStringToNumbers) { return Helper.CreateInteger(text, 0, text.Length); } throw new Exception("AutoConvertStringToNumbers is disabled for converting string : " + value); } if (conversionType == typeof(long)) { if (!(value is string text2)) { return (long)value; } if (_params.AutoConvertStringToNumbers) { return Helper.CreateLong(text2, 0, text2.Length); } throw new Exception("AutoConvertStringToNumbers is disabled for converting string : " + value); } if (conversionType == typeof(string)) { return (string)value; } if (conversionType.IsEnum) { return Helper.CreateEnum(conversionType, value); } if (conversionType == typeof(DateTime)) { return Helper.CreateDateTime((string)value, _params.UseUTCDateTime); } if (conversionType == typeof(DateTimeOffset)) { return Helper.CreateDateTimeOffset((string)value); } if (Reflection.Instance.IsTypeRegistered(conversionType)) { return Reflection.Instance.CreateCustom((string)value, conversionType); } if (Helper.IsNullable(conversionType)) { if (value == null) { return value; } conversionType = Helper.UnderlyingTypeOf(conversionType); } if (conversionType == typeof(Guid)) { return Helper.CreateGuid((string)value); } if (conversionType == typeof(byte[])) { return Convert.FromBase64String((string)value); } if (conversionType == typeof(TimeSpan)) { return new TimeSpan((long)value); } return Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture); } private object RootList(object parse, Type type) { Type[] genericArguments = Reflection.Instance.GetGenericArguments(type); IList list = (IList)Reflection.Instance.FastCreateList(type, ((IList)parse).Count); DoParseList((IList)parse, genericArguments[0], list); return list; } private void DoParseList(IList parse, Type it, IList o) { Dictionary<string, object> globaltypes = new Dictionary<string, object>(); foreach (object item in parse) { _usingglobals = false; object obj = item; obj = ((!(item is Dictionary<string, object> d)) ? ChangeType(item, it) : ParseDictionary(d, globaltypes, it, null)); o.Add(obj); } } private object RootArray(object parse, Type type) { Type elementType = type.GetElementType(); IList list = (IList)Reflection.Instance.FastCreateInstance(typeof(List<>).MakeGenericType(elementType)); DoParseList((IList)parse, elementType, list); Array array = Array.CreateInstance(elementType, list.Count); list.CopyTo(array, 0); return array; } private object RootDictionary(object parse, Type type) { Type[] genericArguments = Reflection.Instance.GetGenericArguments(type); Type type2 = null; Type type3 = null; bool fl