Decompiled source of PortablePals v0.1.0
PortablePals.dll
Decompiled 2 weeks 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.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 AllTameable; using AllTameable.DNA; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using CompatPatches; using CreatureLevelControl; using HarmonyLib; using JetBrains.Annotations; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using LocalizationManager; using Microsoft.CodeAnalysis; using MonsterModifiers.Custom_Components; using PortablePals; using UnityEngine; using UnityEngine.SceneManagement; 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: Guid("db3f13a2-a323-4902-ad30-87a28b8836b6")] [assembly: ComVisible(false)] [assembly: AssemblyTrademark("")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyProduct("PortablePals")] [assembly: AssemblyCompany("")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyDescription("")] [assembly: AssemblyTitle("PortablePals")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyConfiguration("")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace CompatPatches { internal class MonsterMod { public static void SetModifiers(Character character, string MonMod) { MonsterModifier val = default(MonsterModifier); if (((Component)character).TryGetComponent<MonsterModifier>(ref val)) { if (Object.op_Implicit((Object)(object)val.character)) { DBG.blogDebug("MonMod has started"); } character.m_nview.GetZDO().Set("modifiers", MonMod); DBG.blogDebug("MonMod has been set"); DBG.blogDebug("MonMod is:" + character.m_nview.GetZDO().GetString("modifiers", string.Empty)); } } public static string getModifiers(Character character) { MonsterModifier val = default(MonsterModifier); string text; if (((Component)character).TryGetComponent<MonsterModifier>(ref val)) { text = string.Join(",", val.Modifiers); DBG.blogDebug("got modifiers from component: " + text); } else { text = character.m_nview.GetZDO().GetString("modifiers", string.Empty) ?? ""; DBG.blogDebug("got modifiers from zdo: " + text); } return text; } } internal class VikingNPC { [HarmonyPatch(typeof(Humanoid), "GiveDefaultItems")] [HarmonyPostfix] private static void GiveDefaultItems(Humanoid __instance) { TimedScaleAndFreeze timedScaleAndFreeze = default(TimedScaleAndFreeze); if (((Component)__instance).TryGetComponent<TimedScaleAndFreeze>(ref timedScaleAndFreeze) && timedScaleAndFreeze.clearInv) { Inventory inventory = __instance.GetInventory(); if (inventory.m_inventory.Count() > 0) { timedScaleAndFreeze.clearInv = false; inventory.RemoveAll(); inventory.Changed(); } } } } [HarmonyPatch(typeof(CreatureLevelControl), "PatchSize")] internal class CLLC_Patches { private static bool Prefix(CreatureLevelControl __instance, EnemyLevelData originalData, out Vector3 __state) { //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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) GameObject gameObject = ((Component)originalData).gameObject; __state = gameObject.transform.localScale; TimedScaleAndFreeze timedScaleAndFreeze = default(TimedScaleAndFreeze); if ((((Object)(object)gameObject != (Object)null) & gameObject.TryGetComponent<TimedScaleAndFreeze>(ref timedScaleAndFreeze)) && timedScaleAndFreeze.CLLC_Scale != 1f) { DBG.blogDebug("Already Scaled by CLLC"); __state = Vector3.zero; return false; } return true; } private static void Postfix(CreatureLevelControl __instance, EnemyLevelData originalData, Vector3 __state) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) if (!(__state == Vector3.zero)) { GameObject gameObject = ((Component)originalData).gameObject; TimedScaleAndFreeze tsf = default(TimedScaleAndFreeze); if ((Object)(object)gameObject != (Object)null && gameObject.TryGetComponent<TimedScaleAndFreeze>(ref tsf)) { float scale = gameObject.transform.localScale.x / __state.x; DBG.blogDebug("In CLLC Patch with scale=" + scale); CatchPal.checkScales(gameObject, isCLLC: true, tsf, scale); } } } } internal class AllTame_API { [HarmonyPatch(typeof(DNA), "setTraits")] public class AT_DNA_Patches { private static void Prefix(DNA __instance, out Vector3 __state) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) __state = ((Component)__instance).gameObject.transform.localScale; } private static void Postfix(DNA __instance, Vector3 __state) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) GameObject gameObject = ((Component)__instance).gameObject; TimedScaleAndFreeze tsf = default(TimedScaleAndFreeze); if ((Object)(object)gameObject != (Object)null && gameObject.TryGetComponent<TimedScaleAndFreeze>(ref tsf)) { float scale = gameObject.transform.localScale.x / __state.x; DBG.blogDebug((object)("In setTraits Patch with scale=" + scale)); CatchPal.checkScales(gameObject, isCLLC: false, tsf, scale); } } } public static string GetDNA(Character character) { DNA component = ((Component)character).GetComponent<DNA>(); if ((Object)(object)component == (Object)null) { return ""; } return component.DNA_hash.ToString(); } public static void setDNAHash(GameObject go, ZNetView znv) { DNA component = go.GetComponent<DNA>(); if (Object.op_Implicit((Object)(object)component)) { DBG.blogDebug((object)("DNA hash=" + component.DNA_hash)); component.DNA_hash = znv.GetZDO().GetLong("AT_DNA", 0L); DBG.blogDebug((object)("DNA hash2=" + component.DNA_hash)); component.ParseMSG(); } } public static void setDNA(GameObject go, long dna_hash) { DNA val = default(DNA); if (go.TryGetComponent<DNA>(ref val)) { val.DNA_hash = dna_hash; val.ParseMSG(); val.restoreColor(); val.setAttributes(); val.SetZDO(); DBG.blogDebug((object)("PP hash=" + dna_hash)); } else { DBG.blogDebug((object)"No DNA"); } } } internal class CLLC { public static void SetInfusionCreature(Character character, string infusion) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (!Enum.TryParse<CreatureInfusion>(infusion, out CreatureInfusion result)) { DBG.blogDebug("Failed to parse infusion from string " + infusion); } else { API.SetInfusionCreature(character, result); } } public static void SetExtraEffectCreature(Character character, string effect) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (!Enum.TryParse<CreatureExtraEffect>(effect, out CreatureExtraEffect result)) { DBG.blogDebug("Failed to parse extra effect from string " + effect); } else { API.SetExtraEffectCreature(character, result); } } public static string CLLC_getInfusion(Character character) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) CreatureInfusion infusionCreature = API.GetInfusionCreature(character); return ((object)(CreatureInfusion)(ref infusionCreature)).ToString(); } public static string CLLC_getEffect(Character character) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) CreatureExtraEffect extraEffectCreature = API.GetExtraEffectCreature(character); return ((object)(CreatureExtraEffect)(ref extraEffectCreature)).ToString(); } } } namespace PortablePals { internal class CatchPal { public static string releaseZDOKey = "PP_Release"; public static float tsf_startScale = 0.1f; public static float tsf_startTime = 0.6f; public static float tsf_duration = 1.1f; public static GameObject Staging; public const int maxCatchDist = 15; public static Vector3 throwforce = new Vector3(-50f, 450f, 200f); public static ForceMode forceMode = (ForceMode)0; public static Vector3 throwLoc = new Vector3(0.4f, 0.9f, -0.04f); public static int catcherHash = StringExtensionMethods.GetStableHashCode("PP_Catcher"); [HarmonyPatch(typeof(Character), "Awake")] [HarmonyPostfix] private static void RegisterRPCs(Character __instance) { ZNetView nview = __instance.m_nview; nview.Register<ZDOID>("RPC_RequestCatch", (Action<long, ZDOID>)RPC_RequestCatch); nview.Register<ZDOID, ZDOID>("RPC_CatchEffect", (Action<long, ZDOID, ZDOID>)RPC_CatchEffect); if (nview.GetZDO() != null && nview.GetZDO().GetBool(releaseZDOKey, false)) { DBG.blogDebug("Has Release ZDO"); ReleaseCreatureEffect(__instance); nview.GetZDO().Set(releaseZDOKey, false); } } public static int attemptCatch(Player plr, ItemData item) { //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) if (((Character)plr).InAttack()) { DBG.blogDebug("In Attack"); return 0; } if (item.m_customData.TryGetValue("PP_Prefab", out var value) && (value ?? "") != "") { ReleaseCreature(plr, item); if (item.m_shared.m_useDurability) { float maxDurability = item.GetMaxDurability(); if (item.m_durability > maxDurability) { item.m_durability = maxDurability; } item.m_durability -= 1f; } return 1; } item.m_shared.m_movementModifier = -0.05f; if (float.TryParse(GeneralExtensions.GetValueSafe<string, string>(item.m_customData, "PP_LastCatch"), out var result)) { float num = Math.Abs(result - Time.time); if (num < 0.3f) { DBG.blogDebug("Catch already in Progress"); return 0; } if (num < Plugin.cooldown.Value) { DBG.blogDebug("In Cooldown:" + result); ((Character)plr).Message((MessageType)2, "Item in cooldown, try again in " + (int)(Plugin.cooldown.Value - num + 1f) + "s", 0, (Sprite)null); return 0; } } Character val = null; GameObject val2 = null; plr.FindHoverObject(ref val2, ref val); if ((Object)(object)val != (Object)null) { if (Vector3.Distance(((Character)plr).m_eye.position, ((Component)val).transform.position) < 15f) { DBG.blogDebug("hovering=" + val.m_name); if (CatchCreature(plr, item, val)) { return 2; } DBG.blogDebug("Failed to attempt catch=" + ((Object)val).name); return 0; } DBG.blogDebug("to far away from=" + ((Object)val).name); return 0; } DBG.blogDebug("no creature to catch"); return 0; } private static bool CatchCreature(Player plr, ItemData item, Character hovCreature) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) if (!hovCreature.m_nview.IsValid() || !hovCreature.IsTamed()) { return false; } item.m_shared.m_movementModifier = -0.9f; ZDO zDO = hovCreature.m_nview.GetZDO(); long @long = zDO.GetLong(catcherHash, 0L); DBG.blogDebug("Catcher uid=" + @long); ZDOID zDOID = zDO.GetZDOID("PP_Catcher"); if (((ZDOID)(ref zDOID)).UserID != 0) { DBG.blogDebug("Already has Catcher ZDOID"); if (Time.time - zDO.GetFloat("PP_CatcherTime", 0f) < 5f) { return false; } DBG.blogDebug("Time has passed, attempting Catch"); } if (@long != 0) { DBG.blogDebug("Already has Catcher"); } Utils2.addOrUpdateCustomData(item.m_customData, "PP_LastCatch", Time.time.ToString()); DBG.blogDebug("Set lastCatch to: " + Time.time); zDO.Set("PP_Catcher", ((Character)plr).m_nview.GetZDO().m_uid); zDO.Set("PP_CatcherTime", Time.time); DBG.blogDebug("Set ZDOID"); ZDOID zDOID2 = zDO.GetZDOID("PP_Catcher"); ZDOID uid = zDO.m_uid; DBG.blogDebug("found ZDOID"); GameObject val = ZNetScene.instance.FindInstance(zDOID2); DBG.blogDebug("got go"); DBG.blogDebug("go name=" + ((Object)val).name); hovCreature.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_RequestCatch", new object[1] { uid }); ((MonoBehaviour)hovCreature).StartCoroutine(CatchUpdate(hovCreature)); return true; } private static bool SaveCreatureToItem(Player plr, Character hovCreature) { //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) if (!hovCreature.m_nview.IsValid() || !hovCreature.IsTamed()) { return false; } ItemData rightItem = ((Humanoid)plr).m_rightItem; if (rightItem == null || !((Object)rightItem.m_dropPrefab).name.Contains("PalStone")) { return false; } Dictionary<string, string> customData = rightItem.m_customData; Utils2.addOrUpdateCustomData(customData, "PP_Prefab", hovCreature.m_nview.GetPrefabName()); Utils2.addOrUpdateCustomData(customData, "PP_Name", hovCreature.m_nview.GetZDO().GetString(StringExtensionMethods.GetStableHashCode("TamedName"), "")); Utils2.addOrUpdateCustomData(customData, "PP_Lvl", hovCreature.m_level.ToString()); Utils2.addOrUpdateCustomData(customData, "PP_Health", hovCreature.GetHealth().ToString()); float num = (float)hovCreature.m_nview.GetZDO().GetLong(ZDOVars.s_tameLastFeeding, 0L) / 10000000f; Utils2.addOrUpdateCustomData(customData, "PP_LastFed", ((int)(ZNet.instance.m_netTime - (double)num)).ToString()); Growup component = ((Component)hovCreature).gameObject.GetComponent<Growup>(); if (Object.op_Implicit((Object)(object)component)) { float num2 = (float)hovCreature.m_nview.GetZDO().GetLong(ZDOVars.s_spawnTime, 0L) / 10000000f; int num3 = (int)(ZNet.instance.m_netTime - (double)num2); DBG.blogDebug("growTime " + num3); Utils2.addOrUpdateCustomData(customData, "PP_growTime", num3.ToString()); } Utils2.addOrUpdateCustomData(customData, "PP_HealStart", ((int)ZNet.instance.m_netTime).ToString()); Humanoid val = (Humanoid)(object)((hovCreature is Humanoid) ? hovCreature : null); if (Object.op_Implicit((Object)(object)val)) { Utils2.addOrUpdateCustomData(customData, "PP_Seed", val.m_seed.ToString()); if (((object)hovCreature).GetType().Name.Contains("Companion")) { dropInventory(val.GetInventory(), ((Component)hovCreature).transform.position); } } DBG.blogDebug("Health=" + hovCreature.GetHealth()); if (Plugin.hasCLLC) { Utils2.addOrUpdateCustomData(customData, "PP_CLLC", CLLC.CLLC_getInfusion(hovCreature) + "," + CLLC.CLLC_getEffect(hovCreature)); } if (Plugin.hasAT) { Utils2.addOrUpdateCustomData(customData, "PP_DNA", AllTame_API.GetDNA(hovCreature)); } if (Plugin.hasMonMod) { Utils2.addOrUpdateCustomData(customData, "PP_MonMod", MonsterMod.getModifiers(hovCreature)); } Tameable tamable = hovCreature.m_baseAI.m_tamable; if ((Object)(object)tamable != (Object)null && tamable.HaveSaddle()) { DBG.blogDebug("Has Saddle"); Utils2.addOrUpdateCustomData(customData, "PP_Saddle", "true"); Sadle saddle = tamable.m_saddle; if ((Object)(object)saddle != (Object)null) { Container componentInChildren = ((Component)saddle).GetComponentInChildren<Container>(); if ((Object)(object)componentInChildren != (Object)null) { dropInventory(componentInChildren.m_inventory, ((Component)hovCreature).transform.position); } } } else { Utils2.addOrUpdateCustomData(customData, "PP_Saddle", "false"); } return true; } public static void dropInventory(Inventory inv, Vector3 pos) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) List<ItemData> allItems = inv.GetAllItems(); DBG.blogDebug("Dropping Inventory"); foreach (ItemData item in allItems) { ItemDrop.DropItem(item, item.m_stack, pos, Quaternion.Euler(0f, 0f, (float)Random.Range(0, 360))); } } private static void ReleaseCreatureEffect(Character character) { //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: 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) DBG.blogDebug("Releasing Creature Effect"); GameObject gameObject = ((Component)character).gameObject; TimedScaleAndFreeze timedScaleAndFreeze = gameObject.AddComponent<TimedScaleAndFreeze>(); timedScaleAndFreeze.ZNetDestroy = false; timedScaleAndFreeze.startScale = tsf_startScale; timedScaleAndFreeze.startimeScale = tsf_startTime; timedScaleAndFreeze.duration = tsf_duration; timedScaleAndFreeze.roughness = 0.02f; timedScaleAndFreeze.breakChild = -1; ZNetView nview = character.m_nview; if (Object.op_Implicit((Object)(object)nview) && nview.IsValid()) { timedScaleAndFreeze.ogScale = nview.GetZDO().GetVec3("PP_Scale", Vector3.one); } else { DBG.blogWarning("Failed to grab zdo scale for " + ((Object)character).name); timedScaleAndFreeze.ogScale = gameObject.transform.localScale; } ((Component)character).transform.localScale = timedScaleAndFreeze.ogScale * tsf_startScale; if (!Object.op_Implicit((Object)(object)gameObject)) { DBG.blogWarning("Failed to release " + ((Object)character).name); return; } VisEquipment component = gameObject.GetComponent<VisEquipment>(); if (Plugin.hasAT) { AllTame_API.setDNAHash(gameObject, nview); } if ((Object)(object)component != (Object)null) { DBG.blogDebug("has visequ"); ((Component)component.m_rightHand).gameObject.SetActive(false); ((Component)component.m_leftHand).gameObject.SetActive(false); ((Behaviour)component).enabled = false; Humanoid val = (Humanoid)(object)((character is Humanoid) ? character : null); if ((Object)(object)val != (Object)null) { val.GiveDefaultItems(); } } else { DBG.blogDebug("no visequ"); } gameObject.SetActive(true); ((Behaviour)character).enabled = false; } public static void checkScales(GameObject go, bool isCLLC, TimedScaleAndFreeze tsf, float scale) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: 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_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) if (scale == 1f || scale > 5f || Math.Abs(tsf.DNA_Scale - scale) < 0.001f || Math.Abs(tsf.CLLC_Scale - scale) < 0.001f) { DBG.blogDebug("Seems like duplicate Scale=" + scale); Transform transform = go.transform; transform.localScale /= scale; } else if (isCLLC) { if (tsf.CLLC_Scale != 1f) { DBG.blogDebug("Postfix Already Scaled by CLLC "); return; } tsf.CLLC_Scale = scale; DBG.blogDebug("CLLC Scale Modified by " + scale + ": lvl=" + go.GetComponent<Character>().GetLevel() + ": tamed=" + go.GetComponent<Character>().m_tamed); tsf.exteriorScale *= scale; } else if (tsf.DNA_Scale != 1f) { DBG.blogDebug("Postfix Already Scaled by DNA "); } else { DBG.blogDebug("DNA Scale Modified by " + scale); tsf.DNA_Scale = scale; tsf.exteriorScale *= scale; } } private static bool ReleaseCreature(Player plr, ItemData item) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_05da: Unknown result type (might be due to invalid IL or missing references) //IL_05df: Unknown result type (might be due to invalid IL or missing references) //IL_063a: Unknown result type (might be due to invalid IL or missing references) //IL_063f: Unknown result type (might be due to invalid IL or missing references) //IL_0671: Unknown result type (might be due to invalid IL or missing references) //IL_09c3: Unknown result type (might be due to invalid IL or missing references) //IL_09c8: Unknown result type (might be due to invalid IL or missing references) //IL_09e9: Unknown result type (might be due to invalid IL or missing references) //IL_09ee: Unknown result type (might be due to invalid IL or missing references) //IL_09ff: Unknown result type (might be due to invalid IL or missing references) //IL_0a01: Unknown result type (might be due to invalid IL or missing references) //IL_0a5c: Unknown result type (might be due to invalid IL or missing references) //IL_0a9d: Unknown result type (might be due to invalid IL or missing references) //IL_0aa2: Unknown result type (might be due to invalid IL or missing references) //IL_0aaf: Unknown result type (might be due to invalid IL or missing references) //IL_0ab4: Unknown result type (might be due to invalid IL or missing references) DBG.blogDebug("Releasing Creature local"); Dictionary<string, string> customData = item.m_customData; customData.TryGetValue("PP_Prefab", out var value); GameObject prefab = ZNetScene.instance.GetPrefab(StringExtensionMethods.GetStableHashCode(value)); if (!Object.op_Implicit((Object)(object)prefab)) { return true; } Vector3 val = ((Component)plr).transform.position + ((Component)plr).transform.rotation * throwLoc; Vector3 localScale = prefab.transform.localScale; Vector3 val2 = localScale; DBG.blogDebug("StartScale=" + ((object)(Vector3)(ref val2)).ToString()); GameObject val3 = Object.Instantiate<GameObject>(prefab, val, Quaternion.Euler(0f, (float)Random.Range(0, 360), 0f)); string valueSafe = GeneralExtensions.GetValueSafe<string, string>(item.m_customData, "PP_LastCatch"); Utils2.addOrUpdateCustomData(((Humanoid)plr).RightItem.m_customData, "PP_Prefab", ""); Utils2.addOrUpdateCustomData(item.m_customData, "PP_LastCatch", Time.time.ToString()); val2 = val3.transform.localScale; DBG.blogDebug("Scale=" + ((object)(Vector3)(ref val2)).ToString()); val3.transform.localScale = localScale; val2 = val3.transform.localScale; DBG.blogDebug("locaScale post Set Scale=" + ((object)(Vector3)(ref val2)).ToString()); DBG.blogDebug("Created Creature"); Character component = val3.GetComponent<Character>(); component.m_nview.GetZDO().Set(releaseZDOKey, true); if (customData.TryGetValue("PP_Saddle", out var value2) && value2 == "true") { DBG.blogDebug("Attempting Saddle"); component.m_nview.GetZDO().Set(ZDOVars.s_haveSaddleHash, true); if ((Object)(object)component.m_baseAI != (Object)null && (Object)(object)component.m_baseAI.m_tamable != (Object)null) { DBG.blogDebug("Attempting Set Saddle"); component.m_baseAI.m_tamable.SetSaddle(true); } } Humanoid val4 = (Humanoid)(object)((component is Humanoid) ? component : null); if (Object.op_Implicit((Object)(object)val4) && int.TryParse(GeneralExtensions.GetValueSafe<string, string>(customData, "PP_Seed"), out var result)) { val4.m_seed = result; component.m_nview.GetZDO().Set(ZDOVars.s_seed, result, true); DBG.blogDebug("Set Seed"); } component.SetTamed(true); val2 = val3.transform.localScale; DBG.blogDebug("locaScale post Set Tame=" + ((object)(Vector3)(ref val2)).ToString()); if (customData.TryGetValue("PP_Name", out var value3) && value3 != "") { Tameable val5 = default(Tameable); if (val3.TryGetComponent<Tameable>(ref val5)) { val5.SetText(value3); } else { List<Component> list = val3.GetComponents(typeof(Component)).ToList(); foreach (Component item2 in list) { if (!((object)item2).GetType().Name.Contains("Tameable")) { continue; } DBG.blogDebug("found alt Tameable with: " + ((object)item2).GetType()); MethodInfo method = ((object)item2).GetType().GetMethod("SetText"); if (method != null) { try { object[] parameters = new object[1] { value3 }; method.Invoke(item2, parameters); } catch { DBG.blogDebug("Failed SetText in " + ((object)item2).GetType()); continue; } break; } DBG.blogDebug("no method SetText found in " + ((object)item2).GetType()); } } } else { DBG.blogDebug("No Specific Name"); } if (Plugin.hasCLLC && customData.TryGetValue("PP_CLLC", out var value4)) { string[] array = value4.Split(new char[1] { ',' }); CLLC.SetInfusionCreature(component, array[0]); if (array.Length > 1) { CLLC.SetExtraEffectCreature(component, array[1]); } } if (Plugin.hasMonMod && customData.TryGetValue("PP_MonMod", out var value5)) { MonsterMod.SetModifiers(component, value5); } string name = ((Object)item.m_dropPrefab).name; bool flag = false; if (name.Contains("Speed")) { DBG.blogDebug("Speed PalStone"); component.GetSEMan().AddStatusEffect((StatusEffect)(object)Plugin.prefabManager.SE_SpeedBuff, false, 0, 0f); } else if (name.Contains("Armour")) { DBG.blogDebug("Armour PalStone"); component.GetSEMan().AddStatusEffect((StatusEffect)(object)Plugin.prefabManager.SE_ArmorBuff, false, 0, 0f); } else if (name.Contains("Heal")) { DBG.blogDebug("Heal PalStone"); flag = true; component.GetSEMan().AddStatusEffect((StatusEffect)(object)Plugin.prefabManager.SE_HealBuff, false, 0, 0f); } bool flag2 = false; if (int.TryParse(GeneralExtensions.GetValueSafe<string, string>(customData, "PP_Lvl"), out var result2)) { component.SetLevel(result2); } else { flag2 = true; DBG.blogDebug("Failed to get lvl"); } val2 = val3.transform.localScale; DBG.blogDebug("localScale post set lvl Set=" + ((object)(Vector3)(ref val2)).ToString()); if (flag2 || !component.IsTamed()) { DBG.blogDebug("Error Occured, Destryoing Creature"); Object.Destroy((Object)(object)val3); } val3.SetActive(true); val2 = val3.transform.localScale; DBG.blogDebug("localScale pre DNA Set=" + ((object)(Vector3)(ref val2)).ToString()); component.m_nview.GetZDO().Set("PP_Scale", val3.transform.localScale); if (Plugin.hasAT && long.TryParse(GeneralExtensions.GetValueSafe<string, string>(customData, "PP_DNA"), out var result3)) { AllTame_API.setDNA(val3, result3); } if (customData.TryGetValue("PP_Health", out var value6)) { DBG.blogDebug("Attempting Health"); float.TryParse(value6, out var result4); if (result4 > 0f) { component.SetHealth(result4); DBG.blogDebug("Health Read=" + component.GetHealth()); } } if (customData.TryGetValue("PP_HealStart", out var value7)) { float.TryParse(value7, out var result5); if (flag && result5 > 0f) { DBG.blogDebug("healStartTimeStr=" + result5); DBG.blogDebug("ZNet.instance.m_netTime=" + (int)ZNet.instance.m_netTime); float num = (float)(ZNet.instance.m_netTime - (double)result5); DBG.blogDebug("seconds=" + num); if (num > 0f) { float val6 = Plugin.percentHealPerMin.Value * num / 60f; DBG.blogDebug("healPercent=" + val6); float val7 = 1f - component.GetHealthPercentage(); DBG.blogDebug("maxHealPercent=" + val7); component.SetHealth(component.GetHealth() + component.GetMaxHealth() * Math.Min(val6, val7)); DBG.blogDebug("Health healed=" + component.GetHealth()); } } } if (customData.TryGetValue("PP_LastFed", out var value8)) { DBG.blogDebug("Attempting LastFed"); float.TryParse(value8, out var result6); if (result6 != 0f) { long num2 = Math.Max(ZNet.instance.GetTime().Ticks - Convert.ToInt64(result6 * 10000000f), 0L); DBG.blogDebug("lastFed =" + result6 + ", ticks=" + num2); component.m_nview.GetZDO().Set(ZDOVars.s_tameLastFeeding, num2); } } Growup val8 = default(Growup); if (((Component)component).gameObject.TryGetComponent<Growup>(ref val8) && customData.TryGetValue("PP_growTime", out var value9)) { DBG.blogDebug("Attempting GrowTime"); float.TryParse(value9, out var result7); if (result7 != 0f) { long num3 = Math.Max(ZNet.instance.GetTime().Ticks - Convert.ToInt64(result7 * 10000000f), 0L); DBG.blogDebug("grow =" + result7 + ", ticks=" + num3); component.m_nview.GetZDO().Set(ZDOVars.s_spawnTime, num3); } } val2 = val3.transform.localScale; DBG.blogDebug("localScale post DNA Set=" + ((object)(Vector3)(ref val2)).ToString()); localScale = val3.transform.localScale; ReleaseCreatureEffect(component); val3.GetComponent<TimedScaleAndFreeze>().ogScale = localScale; if (((object)component).GetType().Name.Contains("Companion")) { val3.GetComponent<TimedScaleAndFreeze>().clearInv = true; } float num4 = Math.Min(val3.GetComponent<Rigidbody>().mass, 110f) - 10f; val3.GetComponent<Rigidbody>().AddForce(((Component)plr).transform.rotation * new Vector3(throwforce.x, throwforce.y - 100f * num4 / 110f, throwforce.z + 220f * num4 / 110f) * (num4 + 10f), forceMode); Utils2.addOrUpdateCustomData(item.m_customData, "PP_LastCatch", valueSafe); return true; } private static void RPC_RequestCatch(long uid, ZDOID creature) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) GameObject val = ZNetScene.instance.FindInstance(creature); ZLog.Log((object)("Player " + uid + " wants to catch " + ((Object)val).name + " im: " + ZDOMan.GetSessionID())); ZNetView nview = val.GetComponent<Character>().m_nview; if (nview.IsOwner()) { nview.GetZDO().SetOwner(uid); ZLog.Log((object)(" Setting Owner to " + uid)); } else if (nview.GetZDO().GetOwner() == uid) { ZLog.Log((object)" but they are already the owner PP"); } else { ZLog.Log((object)" but neither I nor the requesting player are the owners PP"); } } private static IEnumerator CatchUpdate(Character creature) { yield return (object)new WaitForSeconds(0.1f); CatchUpdate_Repeat(creature); } private static IEnumerator regainControl(Player plr, float time) { yield return (object)new WaitForSeconds(time); regainControl_Repeat(plr, repeat: true); } private static void regainControl_Repeat(Player plr, bool repeat = false) { ItemData rightItem = ((Humanoid)plr).RightItem; if (rightItem == null || !((Object)rightItem.m_dropPrefab).name.Contains("PalStone")) { DBG.blogDebug("Invalid Item to regain control from"); return; } DBG.blogDebug("Forcing Movement"); ((Character)plr).m_animator.CrossFade("Base Layer.Movement", 0.25f, 0); if (rightItem.m_shared.m_movementModifier + 0.2f >= -0.05f) { DBG.blogDebug("Regained control"); rightItem.m_shared.m_movementModifier = -0.05f; return; } DBG.blogDebug("decreasing movement penalty"); SharedData shared = rightItem.m_shared; shared.m_movementModifier += 0.2f; if (repeat) { ((MonoBehaviour)plr).StartCoroutine(regainControl(plr, 0.1f)); } } private static void CatchUpdate_Repeat(Character creature) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) ZNetView nview = creature.m_nview; if (!nview.IsValid()) { return; } ZDOID zDOID = nview.GetZDO().GetZDOID("PP_Catcher"); long userID = ((ZDOID)(ref zDOID)).UserID; long owner = nview.GetZDO().GetOwner(); DBG.blogDebug("found UID=" + userID); DBG.blogDebug("owner=" + owner); if (userID == owner) { ZLog.Log((object)"I can finally Catch"); if (SaveCreatureToItem(Player.m_localPlayer, creature)) { creature.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_CatchEffect", new object[2] { nview.GetZDO().m_uid, zDOID }); } else { DBG.blogWarning("Failed to save creature data to Item"); } ((MonoBehaviour)Player.m_localPlayer).StartCoroutine(regainControl(Player.m_localPlayer, 1.1f)); } else { regainControl_Repeat(Player.m_localPlayer); ZLog.Log((object)"Im still not the owner"); ((MonoBehaviour)creature).StartCoroutine(CatchUpdate(creature)); } } private static void RPC_CatchEffect(long uid, ZDOID creature, ZDOID catcher) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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) GameObject val = ZNetScene.instance.FindInstance(creature); Character component = val.GetComponent<Character>(); GameObject val2 = ZNetScene.instance.FindInstance(catcher); if (component.m_nview.IsValid()) { GameObject val3 = new GameObject("holder"); val3.SetActive(false); val3.transform.position = ((Component)component).transform.position; ((Component)component).transform.parent = val3.transform; val3.AddComponent<TimedColor>(); TimedDestruction val4 = val3.AddComponent<TimedDestruction>(); val4.Trigger(2f); TimedScaleAndFreeze timedScaleAndFreeze = ((Component)component).gameObject.AddComponent<TimedScaleAndFreeze>().SetRB(((Component)component).GetComponent<Rigidbody>()); Vector3 endPos = val2.transform.position + val2.transform.rotation * new Vector3(0.288f, 1.8141f, 0.91f); timedScaleAndFreeze.SetEndPos(endPos); timedScaleAndFreeze.startScale = 1f; timedScaleAndFreeze.endScale = 0.01f; timedScaleAndFreeze.startimeMove = 0.3f; timedScaleAndFreeze.startimeScale = 0f; timedScaleAndFreeze.roughness = 0f; timedScaleAndFreeze.breakChild = -1; timedScaleAndFreeze.setFinalScale = false; val3.SetActive(true); } } } internal class Patches { [HarmonyPatch(typeof(InventoryGui), "CanRepair")] public static class FixMaxRepairLevel { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { bool skipped = false; foreach (CodeInstruction instruction in instructions) { if (!skipped && instruction.opcode == OpCodes.Ldc_I4_4) { skipped = true; yield return new CodeInstruction(OpCodes.Ldc_I4_8, (object)null); } else { yield return instruction; } } } } public static string catch_anim = "emote_point"; public static string release_anim = "knife_stab"; [HarmonyPostfix] [HarmonyPatch(typeof(ObjectDB), "Awake")] private static void AddItems(ObjectDB __instance) { //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) Scene activeScene = SceneManager.GetActiveScene(); if (((Scene)(ref activeScene)).name == "main" && ZNet.instance.IsServer()) { DBG.blogDebug("Updating Pal Stones as Server"); PrefabManager.UpdateItems(); } } [HarmonyPatch(typeof(Attack), "Start")] [HarmonyPrefix] private static bool Attack_Start(Attack __instance, Humanoid character, ZSyncAnimation zanim, ItemData weapon, ref float timeSinceLastAttack) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown if (weapon == null) { return true; } if ((Object)(object)weapon.m_dropPrefab == (Object)null || !((Object)weapon.m_dropPrefab).name.Contains("PalStone")) { return true; } if (Math.Abs(Time.time - weapon.m_lastAttackTime) < 1.1f) { return false; } weapon.m_shared.m_movementModifier = -0.05f; DBG.blogDebug("inPalStoneAttackAwake"); int num = CatchPal.attemptCatch((Player)character, weapon); if (((Character)character).IsPlayer() && num <= 0) { weapon.m_lastAttackTime = Time.time; ((Character)character).m_attack = true; return false; } if (num == 2) { __instance.m_attackAnimation = catch_anim; __instance.m_attackChainLevels = 1; zanim.SetSpeed(4f); zanim.m_animator.speed = 3f; } else { __instance.m_attackAnimation = release_anim; __instance.m_attackChainLevels = 3; zanim.SetSpeed(0.5f); zanim.m_animator.speed = 0.5f; } weapon.m_lastAttackTime = Time.time; DBG.blogDebug("animation=" + __instance.m_attackAnimation); return true; } [HarmonyPostfix] [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int) })] private static void Postfix(ItemData item, bool crafting, int qualityLevel, ref string __result) { if (Object.op_Implicit((Object)(object)item.m_dropPrefab) && ((Object)item.m_dropPrefab).name.Contains("PalStone")) { __result = Build_PalStone_Description(item, crafting, qualityLevel); } } private static string Build_PalStone_Description(ItemData item, bool crafting, int quality) { Player localPlayer = Player.m_localPlayer; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(item.m_shared.m_description); stringBuilder.Append("\n"); if (item.m_crafterID != 0) { stringBuilder.AppendFormat("\n$item_crafter: <color=orange>{0}\n</color>", CensorShittyWords.FilterUGC(item.m_crafterName, (UGCType)2, (string)null, item.m_crafterID)); } string name = ((Object)item.m_dropPrefab).name; if (name.Contains("Speed")) { stringBuilder.AppendFormat("<color=yellow>{0}$pp_speedEffect_desc\n$pp_duration</color>{1}s\n", Plugin.speedIncrease.Value * 100f, Plugin.Speed_buffLength.Value); } else if (name.Contains("Armour")) { stringBuilder.AppendFormat("<color=#04a6da>$pp_armourEffect_desc\n$pp_duration</color>{0}s\n", Plugin.Armor_buffLength.Value); } else if (name.Contains("Heal")) { stringBuilder.AppendFormat("<color=green>$pp_healEffect_desc {0}%</color>\n", Plugin.percentHealPerMin.Value * 100f); } if (item.m_shared.m_useDurability) { if (crafting) { float maxDurability = item.GetMaxDurability(quality); stringBuilder.AppendFormat("\n$item_durability: <color=orange>{0}</color>", maxDurability); } else { float maxDurability2 = item.GetMaxDurability(quality); float durability = item.m_durability; stringBuilder.AppendFormat("\n$item_durability: <color=orange>{0}%</color> <color=yellow>({1}/{2})</color>", (item.GetDurabilityPercentage() * 100f).ToString("0"), durability.ToString("0"), maxDurability2.ToString("0")); } if (item.m_shared.m_canBeReparied && !crafting) { Recipe recipe = ObjectDB.instance.GetRecipe(item); if ((Object)(object)recipe != (Object)null) { int minStationLevel = recipe.m_minStationLevel; stringBuilder.AppendFormat("\n$item_repairlevel: <color=orange>{0}</color>", minStationLevel.ToString()); } } } stringBuilder.Append("\n"); Dictionary<string, string> customData = item.m_customData; if (!customData.TryGetValue("PP_Prefab", out var value) || (value ?? "") == "") { stringBuilder.Append("<color=red>$pp_empty</color>\n"); localPlayer.AppendEquipmentModifierTooltips(item, stringBuilder); return stringBuilder.ToString(); } GameObject prefab = ZNetScene.instance.GetPrefab(value); Character val = default(Character); if (Object.op_Implicit((Object)(object)prefab) && prefab.TryGetComponent<Character>(ref val)) { value = val.m_name; } stringBuilder.Append("$pp_stored_creature<color=green>" + value + "</color>\n"); if (customData.TryGetValue("PP_Name", out var value2) && (value2 ?? "") != "") { stringBuilder.Append("$pp_name<color=orange>" + value2 + "</color>\n"); } stringBuilder.Append("$pp_lvl<color=orange>" + GeneralExtensions.GetValueSafe<string, string>(customData, "PP_Lvl") + "</color>\n"); if (Plugin.hasCLLC) { string[] array = GeneralExtensions.GetValueSafe<string, string>(customData, "PP_CLLC").Split(new char[1] { ',' }); if ((array[0] ?? "") != "" && array[0] != "None") { stringBuilder.Append("$pp_infusion<color=orange>" + array[0] + "</color>\n"); } if (array.Length > 1 && array[1] + "None" != "" && array[1] != "None") { stringBuilder.Append("$pp_effect<color=orange>" + array[1] + "</color>\n"); } } if (customData.TryGetValue("PP_Saddle", out var value3) && value3 == "true") { stringBuilder.Append("- <color=orange>$pp_has_saddle</color>\n"); } localPlayer.AppendEquipmentModifierTooltips(item, stringBuilder); return stringBuilder.ToString(); } } public static class DBG { public static void cprt(string s) { Console.instance.Print(s); } public static void InfoTL(string s) { ((Character)Player.m_localPlayer).Message((MessageType)1, s, 0, (Sprite)null); } public static void InfoCT(string s) { ((Character)Player.m_localPlayer).Message((MessageType)2, s, 0, (Sprite)null); } public static void blogInfo(object o) { Plugin.logger.LogInfo(o); } public static void blogWarning(object o) { Plugin.logger.LogWarning(o); } public static void blogDebug(object o) { if (Plugin.debugout.Value) { Plugin.logger.LogWarning(o); } } public static void tryblogDebug(object o, object o_backup) { try { if (Plugin.debugout.Value) { Plugin.logger.LogWarning(o); } } catch { Plugin.logger.LogWarning(o_backup); } } } [BepInPlugin("meldurson.valheim.PortablePals", "PortablePals", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public static ConfigEntry<int> nexusID; public static ConfigEntry<string> cfg; public static ConfigEntry<int> durability; public static ConfigEntry<bool> repairable; public static ConfigEntry<bool> destroyOnBreak; public static ConfigEntry<string> recipe; public static ConfigEntry<string> craftingStation; public static ConfigEntry<float> cooldown; public static ConfigEntry<bool> debugout; public static ConfigEntry<string> recipe_Heal; public static ConfigEntry<float> percentHealPerMin; public static ConfigEntry<string> recipe_Speed; public static ConfigEntry<float> speedIncrease; public static ConfigEntry<int> Speed_buffLength; public static ConfigEntry<string> recipe_Armor; public static ConfigEntry<int> Armor_buffLength; public static string assetPath = "Assets/PortablePals/"; public static ManualLogSource logger; public static GameObject Root; public static PrefabManager prefabManager; public const string CLLCGUID = "org.bepinex.plugins.creaturelevelcontrol"; public const string AllTameableGUID = "meldurson.valheim.AllTameable"; public const string MonModGUID = "warpalicious.MonsterModifiers"; public static bool hasCLLC = false; public static bool hasAT = false; public static bool hasMonMod = false; [HarmonyPostfix] [HarmonyPatch(typeof(ZNetScene), "Shutdown")] private static void Postfix() { DBG.blogInfo("Reseting PortablePals"); } private void Awake() { //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) //IL_003d: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00e8: 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_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Expected O, but got Unknown //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Expected O, but got Unknown //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Expected O, but got Unknown //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Expected O, but got Unknown //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Expected O, but got Unknown //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Expected O, but got Unknown //IL_0244: 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_0252: Expected O, but got Unknown //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Expected O, but got Unknown //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Expected O, but got Unknown //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Expected O, but got Unknown //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Expected O, but got Unknown //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Expected O, but got Unknown //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0312: Expected O, but got Unknown //IL_0312: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Expected O, but got Unknown //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Expected O, but got Unknown //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_035c: Expected O, but got Unknown //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Expected O, but got Unknown //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_0390: Expected O, but got Unknown logger = ((BaseUnityPlugin)this).Logger; recipe = ((BaseUnityPlugin)this).Config.Bind<string>("2: Crafting", "Crafting Recipe", "DragonTear:3,Crystal:5,WolfClaw:5,Obsidian:3", new ConfigDescription("What is the recipe for craft, separate amount with : and different items with ,", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); craftingStation = ((BaseUnityPlugin)this).Config.Bind<string>("2: Crafting", "Crafting Station", "piece_workbench:3", new ConfigDescription("What is the required Crafting Station and Level, separated by a : such as piece_workbench:3 would be lvl 3 Workbench (vanilla stations are: piece_workbench, forge, piece_cauldron, piece_stonecutter, piece_artisanstation, blackforge, piece_magetable", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); durability = ((BaseUnityPlugin)this).Config.Bind<int>("2: Crafting", "Durability", 15, new ConfigDescription("Durability of PalStone, 0 is indestuctable", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); repairable = ((BaseUnityPlugin)this).Config.Bind<bool>("2: Crafting", "Repairable", true, new ConfigDescription("If durability is used, can stone be repaired?", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); destroyOnBreak = ((BaseUnityPlugin)this).Config.Bind<bool>("2: Crafting", "destroyOnBreak", false, new ConfigDescription("If durability is used, will the stone be destroyed when out of durability (sets repairable to false)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); cooldown = ((BaseUnityPlugin)this).Config.Bind<float>("2: Crafting", "Cooldown", 20f, new ConfigDescription("Cooldown between uses in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); debugout = ((BaseUnityPlugin)this).Config.Bind<bool>("1: General", "Debug Output", false, "Determines if debug is output to bepinex log"); recipe_Heal = ((BaseUnityPlugin)this).Config.Bind<string>("3: Healing Stone", "Crafting Recipe", "PalStone:1,LinenThread:10,Obsidian:5,MeadHealthMinor:5", new ConfigDescription("What is the recipe for crafting the Healing Pal Stone, separate amount with : and different items with ,", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); percentHealPerMin = ((BaseUnityPlugin)this).Config.Bind<float>("3: Healing Stone", "Healing Per Minute", 0.05f, new ConfigDescription("What percent does a creature trapped in a healing pal stone gain per minute as a decimal (0.05 is 5% per minute)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); recipe_Speed = ((BaseUnityPlugin)this).Config.Bind<string>("4: Speed Stone", "Crafting Recipe", "PalStone:1,LinenThread:10,Obsidian:5,MeadStaminaMinor:5", new ConfigDescription("What is the recipe for crafting the Speed Pal Stone, separate amount with : and different items with ,", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); speedIncrease = ((BaseUnityPlugin)this).Config.Bind<float>("4: Speed Stone", "Percent Speed Increase", 0.2f, new ConfigDescription("What percent does a creature released from a speed stone gain as a decimal (0.2 is 20% speed increase)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); Speed_buffLength = ((BaseUnityPlugin)this).Config.Bind<int>("4: Speed Stone", "Buff Length", 180, new ConfigDescription("How long does the speed buff last in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); recipe_Armor = ((BaseUnityPlugin)this).Config.Bind<string>("5: Armour Stone", "Crafting Recipe", "PalStone:1,LinenThread:10,Obsidian:5,LoxPelt:15", new ConfigDescription("What is the recipe for crafting the Speed Pal Stone, separate amount with : and different items with ,", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); Armor_buffLength = ((BaseUnityPlugin)this).Config.Bind<int>("5: Armour Stone", "Buff Length", 180, new ConfigDescription("How long does the armour buff last in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); Localizer.Load(); Root = new GameObject("PortablePals Root"); Object.DontDestroyOnLoad((Object)(object)Root); CatchPal.Staging = new GameObject("Staging Area"); CatchPal.Staging.transform.SetParent(Root.transform); CatchPal.Staging.SetActive(false); if (Chainloader.PluginInfos.ContainsKey("org.bepinex.plugins.creaturelevelcontrol")) { DBG.blogDebug("Has CLLC"); hasCLLC = true; } if (Chainloader.PluginInfos.ContainsKey("meldurson.valheim.AllTameable")) { DBG.blogDebug("Has AllTameable"); hasAT = true; } if (Chainloader.PluginInfos.ContainsKey("warpalicious.MonsterModifiers")) { DBG.blogDebug("Has MonsterModifiers"); hasMonMod = true; } PerformPatches(); prefabManager = Root.AddComponent<PrefabManager>(); DBG.blogInfo("PortablePals Loaded"); PrefabManager.OnVanillaPrefabsAvailable += PrefabManager.ItemReg; SynchronizationManager.OnConfigurationSynchronized += delegate(object obj, ConfigurationSynchronizationEventArgs attr) { if (attr.InitialSynchronization) { Logger.LogMessage((object)"Initial Config sync event received"); } else { Logger.LogMessage((object)"Config sync event received"); } PrefabManager.ItemRegFromServer(); }; } public void PerformPatches() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown Harmony val = new Harmony("meldurson.valheim.PortablePals"); DBG.blogInfo("Patching Select"); val.PatchAll(typeof(Patches)); val.PatchAll(typeof(CatchPal)); if (hasCLLC) { val.PatchAll(typeof(CLLC_Patches)); DBG.blogDebug("Patched CLLCPatches"); } if (hasAT) { val.PatchAll(typeof(AllTame_API.AT_DNA_Patches)); DBG.blogDebug("Patched ATPatches"); } if (Chainloader.PluginInfos.ContainsKey("RustyMods.VikingNPC")) { DBG.blogInfo("Patching RustyMods.VikingNPC"); val.PatchAll(typeof(VikingNPC)); } IEnumerable<MethodBase> patchedMethods = val.GetPatchedMethods(); val.PatchAll(typeof(Patches.FixMaxRepairLevel)); foreach (MethodBase item in patchedMethods) { DBG.blogDebug(item.ReflectedType?.ToString() + ":" + item.Name + " is patched"); } } } public class TimedScaleAndFreeze : MonoBehaviour { public float roughness = 0.05f; public float startimeScale = 1f; public float startimeMove = 0.4f; private float lastTimeScale = 0f; private float lastTimeMove = 0f; public float duration = 1f; public int breakChild = 0; public float startScale = 0.01f; public float endScale = 1f; public float maxMovePercent = 0.1f; public Vector3 endLoc = Vector3.zero; private float timeMulti; public Vector3 ogScale; private float endTime; public bool ZNetDestroy = true; private bool firstUpdate = true; public float CLLC_Scale = 1f; public float DNA_Scale = 1f; public bool setFinalScale = true; public bool clearInv = false; public bool pastStart = false; private Vector3 previousScale; public Vector3 exteriorScale = Vector3.one; public Rigidbody rb; private RigidbodyConstraints constraints = (RigidbodyConstraints)0; public ZNetView m_nview; private void Start() { //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: 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_00e7: 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_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: 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 ((Object)(object)m_nview == (Object)null) { m_nview = ((Component)this).GetComponent<ZNetView>(); } if ((Object)(object)m_nview == (Object)null) { m_nview = ((Component)this).GetComponentInParent<ZNetView>(); } lastTimeScale = Time.time + startimeScale; startimeScale = lastTimeScale; lastTimeMove = Time.time + startimeMove; startimeMove = lastTimeMove; DBG.blogDebug("Start Time Scale =" + startimeScale); timeMulti = (endScale - startScale) / duration; _ = ogScale; if (ogScale == Vector3.zero) { ogScale = ((Component)this).transform.localScale; } Vector3 val = ogScale; DBG.blogDebug("ogScale =" + ((object)(Vector3)(ref val)).ToString()); ((Component)this).transform.localScale = ogScale * startScale; previousScale = ((Component)this).transform.localScale; endTime = startimeScale + duration; } private void Update() { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_0202: 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_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0332: Unknown result type (might be due to invalid IL or missing references) float time = Time.time; Vector3 val; if (time > endTime) { if (setFinalScale) { ((Component)this).transform.localScale = Vector3.Scale(exteriorScale, ogScale); val = ((Component)this).transform.localScale; DBG.blogDebug("finalScale=" + ((object)(Vector3)(ref val)).ToString()); } removeSelf(); return; } if (time - lastTimeScale > roughness) { Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(((Component)this).transform.localScale.x / previousScale.x, ((Component)this).transform.localScale.y / previousScale.y, ((Component)this).transform.localScale.z / previousScale.z); if (((Vector3)(ref val2)).magnitude < 5f) { exteriorScale = Vector3.Scale(exteriorScale, val2); } else { val = val2; string? text = ((object)(Vector3)(ref val)).ToString(); val = ((Component)this).transform.localScale; DBG.blogDebug("scaler Scale too high =" + text + ", scale=" + ((object)(Vector3)(ref val)).ToString()); } if (((Component)this).transform.localScale.x / previousScale.x != 1f) { val = exteriorScale; string? text2 = ((object)(Vector3)(ref val)).ToString(); val = ((Component)this).transform.localScale; DBG.blogDebug("exterior Scale =" + text2 + ", scale=" + ((object)(Vector3)(ref val)).ToString()); } ((Component)this).transform.localScale = Vector3.Scale(exteriorScale, ogScale) * (startScale + timeMulti * (time - startimeScale)); previousScale = ((Component)this).transform.localScale; lastTimeScale = time; if (firstUpdate) { Character component = ((Component)this).gameObject.GetComponent<Character>(); if ((Object)(object)component != (Object)null && !((Behaviour)component).enabled) { ((Behaviour)component).enabled = true; } firstUpdate = false; } Humanoid val3 = default(Humanoid); if (clearInv && pastStart && ((Component)this).gameObject.TryGetComponent<Humanoid>(ref val3)) { Inventory inventory = val3.GetInventory(); if (inventory.m_inventory.Count() > 0) { clearInv = false; } inventory.RemoveAll(); inventory.Changed(); } } if (time - lastTimeMove > roughness && endLoc != Vector3.zero) { if (endLoc != Vector3.zero) { ((Component)this).transform.position = Vector3.MoveTowards(((Component)this).transform.position, endLoc, maxMovePercent * Vector3.Distance(((Component)this).transform.position, endLoc)); } lastTimeMove = time; } } public void SetEndPos(Vector3 location) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) endLoc = location; Vector3 val = endLoc; DBG.blogDebug("End loc =" + ((object)(Vector3)(ref val)).ToString()); } public TimedScaleAndFreeze SetRB(Rigidbody freeze_rb) { //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) rb = freeze_rb; constraints = rb.constraints; rb.constraints = (RigidbodyConstraints)126; return this; } public void removeSelf() { //IL_01ba: Unknown result type (might be due to invalid IL or missing references) Humanoid component = ((Component)this).gameObject.GetComponent<Humanoid>(); if (clearInv && (Object)(object)component != (Object)null) { Inventory inventory = component.GetInventory(); DBG.blogDebug("inv pre size=" + inventory.m_inventory.Count()); DBG.blogDebug("Clearing Inventory"); inventory.RemoveAll(); DBG.blogDebug("inv post size=" + inventory.m_inventory.Count()); inventory.Changed(); } try { VisEquipment componentInChildren = ((Component)this).gameObject.GetComponentInChildren<VisEquipment>(); if ((Object)(object)componentInChildren != (Object)null && !((Behaviour)componentInChildren).enabled) { ((Behaviour)componentInChildren).enabled = true; ((Component)componentInChildren.m_rightHand).gameObject.SetActive(true); ((Component)componentInChildren.m_leftHand).gameObject.SetActive(true); if ((Object)(object)component != (Object)null) { component.EquipItem(component.RightItem, true); DBG.blogDebug("Equipped right Item:" + ((object)component.RightItem).ToString()); } } } catch { DBG.blogWarning("Failed VisEquip"); } try { if (breakChild >= 0 && breakChild < ((Component)this).transform.childCount) { DBG.blogDebug("Breaking Child " + ((Object)((Component)this).gameObject).name); Transform child = ((Component)this).transform.GetChild(breakChild); if (Object.op_Implicit((Object)(object)child)) { child.parent = null; if ((Object)(object)rb != (Object)null) { rb.constraints = constraints; } } } } catch { DBG.blogWarning("Failed Break Child"); } try { ZNetView component2 = ((Component)this).gameObject.GetComponent<ZNetView>(); if ((Object)(object)component2 != (Object)null && component2.IsValid() && component2.GetZDO().GetBool(CatchPal.releaseZDOKey, false)) { DBG.blogDebug("Removing Release ZDO"); component2.GetZDO().Set(CatchPal.releaseZDOKey, false); } } catch { DBG.blogWarning("Failed reset releaseZDO"); } DestroyNow(); } public void DestroyNow() { if (!ZNetDestroy) { DBG.blogDebug("Destroying tsf component in " + ((Object)((Component)this).gameObject).name); Object.Destroy((Object)(object)this); } else if (Object.op_Implicit((Object)(object)m_nview)) { if (m_nview.IsValid()) { if (!m_nview.HasOwner()) { m_nview.ClaimOwnership(); } if (m_nview.IsOwner()) { DBG.blogDebug("Destroying Znet in " + ((Object)((Component)this).gameObject).name); ZNetScene.instance.Destroy(((Component)this).gameObject); } } } else { DBG.blogDebug("Not Owner, waiting for owner to destroy " + ((Object)((Component)this).gameObject).name); } } } public class TimedColor : MonoBehaviour { public float roughness = 0.01f; public float startime = 0f; private float lastTime = 0f; public float duration = 0.7f; public int breakChild = 0; public Color endColorMulti = new Color(25f, 25f, 25f); private Color colMulti; private float endTime; private List<Material> materials = new List<Material>(); private int actualCyles = 0; private bool hasEnded = false; public Rigidbody rb; private void Start() { //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) lastTime = Time.time + startime; startime = lastTime; DBG.blogDebug("Start Color time =" + startime); int num = (int)(duration / Math.Max(roughness, 1f / 59f)); DBG.blogDebug("Expected num cycles=" + num); colMulti = new Color(Mathf.Pow(endColorMulti.r, 1f / (float)num), Mathf.Pow(endColorMulti.g, 1f / (float)num), Mathf.Pow(endColorMulti.b, 1f / (float)num)); endTime = startime + duration; Renderer[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<Renderer>(); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { DBG.blogDebug("material added: " + ((Object)val.material).name); materials.Add(val.material); } } private void Update() { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) if (hasEnded) { return; } float time = Time.time; if (time > endTime) { DBG.blogDebug("ActualCycles =" + actualCyles); hasEnded = true; } else { if (!(time - lastTime > roughness)) { return; } actualCyles++; foreach (Material material in materials) { Color color = material.color; material.color = new Color(color.r * colMulti.r, color.g * colMulti.g, color.b * colMulti.b); } lastTime = time; } } } public class PP_SE : StatusEffect { private ZNetView m_nview; public string ZDO_key = ""; public float m_lvl = 1f; public float m_length = 600f; public float m_damageMod = 0.6f; public SkillType[] modifySkills = (SkillType[])(object)new SkillType[0]; public override void Setup(Character character) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) base.m_character = character; if (!string.IsNullOrEmpty(base.m_startMessage)) { base.m_character.Message(base.m_startMessageType, base.m_startMessage, 0, (Sprite)null); } m_nview = base.m_character.m_nview; if (m_nview.IsValid()) { if (base.m_repeatInterval > 0f) { m_length = base.m_repeatInterval; } DBG.blogDebug("Setting " + ZDO_key + " to time " + (Time.time + m_length)); m_nview.GetZDO().Set(ZDO_key, Time.time + m_length); } ((StatusEffect)this).TriggerStartEffects(); } public override void UpdateStatusEffect(float dt) { base.m_time += dt; if (base.m_repeatInterval > 0f) { base.m_msgTimer += dt; if (base.m_msgTimer > base.m_repeatInterval) { DBG.blogDebug("resetting timer for " + ZDO_key + " to time " + (Time.time + base.m_repeatInterval)); base.m_msgTimer = 0f; m_nview.GetZDO().Set(ZDO_key, Time.time + base.m_repeatInterval); } } } public override void ModifyAttack(SkillType skill, ref HitData hitData) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (modifySkills.Length != 0 && (modifySkills.Contains(skill) || (int)modifySkills[0] == 999)) { ((DamageTypes)(ref hitData.m_damage)).Modify(m_damageMod); } } public override void Stop() { ((StatusEffect)this).Stop(); m_nview.GetZDO().Set(ZDO_key, 0f); } } public class PrefabManager : MonoBehaviour { public SE_Stats SE_SpeedBuff = ScriptableObject.CreateInstance<SE_Stats>(); public SE_Stats SE_ArmorBuff = ScriptableObject.CreateInstance<SE_Stats>(); public SE_Stats SE_HealBuff = ScriptableObject.CreateInstance<SE_Stats>(); public GameObject Root; private static AssetBundle PP_Assets; private void Awake() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown Root = new GameObject("PrefabList"); Root.transform.SetParent(Plugin.Root.transform); Root.SetActive(false); PP_Assets = AssetUtils.LoadAssetBundleFromResources("portablepals", Assembly.GetExecutingAssembly()); } public static AssetBundle getAssetBundle() { return PP_Assets; } public static void ItemReg() { DBG.blogDebug("ItemReg"); AddItems(); PrefabManager.OnVanillaPrefabsAvailable -= ItemReg; } public static void ItemRegFromServer() { UpdateItems(); } public static void AddItems() { addPortablePalStone(); addSpeedPalStone(); addArmourPalStone(); addHealPalStone(); Plugin.prefabManager.addEffects(); } public static void UpdateItems() { DBG.blogDebug("Updating recipes for palstones"); if ((Object)(object)ZNetScene.instance == (Object)null) { DBG.blogDebug("zns is null"); return; } ResetPalStoneRecipe(Plugin.recipe.Value, "PalStone"); ResetPalStoneRecipe(Plugin.recipe_Armor.Value, "PalStoneArmour"); ResetPalStoneRecipe(Plugin.recipe_Heal.Value, "PalStoneHeal"); ResetPalStoneRecipe(Plugin.recipe_Speed.Value, "PalStoneSpeed"); } private static Recipe ResetPalStoneRecipe(string recipeConfig, string item) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item); ItemDrop val = default(ItemDrop); if ((Object)(object)itemPrefab == (Object)null || !itemPrefab.TryGetComponent<ItemDrop>(ref val)) { DBG.blogWarning(item + " is null or does not have itemDrop"); return null; } Recipe val2 = ScriptableObject.CreateInstance<Recipe>(); ((Object)val2).name = "Recipe_" + item; val2.m_item = val; string[] array = Plugin.craftingStation.Value.Split(new char[1] { ':' }); GameObject prefab = ZNetScene.instance.GetPrefab(array[0]); CraftingStation val3 = default(CraftingStation); if ((Object)(object)prefab == (Object)null || !prefab.TryGetComponent<CraftingStation>(ref val3)) { DBG.blogWarning("invalid crafting station: " + array[0]); return null; } val2.m_craftingStation = val3; val2.m_repairStation = val3; if (array.Length > 1 && int.TryParse(array[1], out var result)) { val2.m_minStationLevel = result; } else { val2.m_minStationLevel = 5; } string[] array2 = recipeConfig.Split(new char[1] { ',' }); int amt = 1; List<Requirement> list = new List<Requirement>(); for (int i = 0; i < array2.Length; i++) { string[] array3 = array2[i].Split(new char[1] { ':' }); if (array3.Length == 2 && int.TryParse(array3[1], out var result2)) { amt = result2; } Requirement val4 = makeRequirment(array3[0], amt); if (val4 == null) { return null; } list.Add(val4); } val2.m_resources = list.ToArray(); if (ItemManager.Instance.GetRecipe(((Object)val2).name) != null) { ItemManager.Instance.RemoveRecipe(((Object)val2).name); } ObjectDB.instance.m_recipes.Add(val2); SetDurability(ref val.m_itemData); return val2; } private static Requirement makeRequirment(string itemStr, int amt) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown Requirement val = new Requirement(); GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemStr); ItemDrop resItem = default(ItemDrop); if (!Object.op_Implicit((Object)(object)itemPrefab) || !itemPrefab.TryGetComponent<ItemDrop>(ref resItem)) { DBG.blogDebug("Ingredient: " + itemStr + " is not found"); return null; } val.m_amount = amt; val.m_amountPerLevel = Mathf.RoundToInt((float)amt * 0.75f); val.m_resItem = resItem; return val; } private static ItemConfig makePalStoneRecipe(string recipeConfig) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown ItemConfig val = new ItemConfig(); string[] array = recipeConfig.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { ':' }); if (array2.Length == 2 && int.TryParse(array2[1], out var result)) { val.AddRequirement(new RequirementConfig(array2[0], result, 0, false)); } else { val.AddRequirement(new RequirementConfig(array2[0], 1, 0, false)); } } string[] array3 = Plugin.craftingStation.Value.Split(new char[1] { ':' }); if (array3.Length == 2 && int.TryParse(array3[1], out var result2)) { val.CraftingStation = array3[0]; val.MinStationLevel = result2; val.RepairStation = array3[0]; } else { val.CraftingStation = array3[0]; val.RepairStation = array3[0]; val.MinStationLevel = 5; } return val; } public static void addPortablePalStone() { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown CustomItem val = ItemManager.Instance.GetItem("PalStone"); if (val == null) { DBG.blogDebug("Adding recipe for Pal Stone"); GameObject val2 = PP_Assets.LoadAsset<GameObject>(Plugin.assetPath + "Palstone.prefab"); DBG.blogDebug("Loaded from assets"); PrefabExtension.FixReferences(val2, true); val = new CustomItem(val2, true, makePalStoneRecipe(Plugin.recipe.Value)); ItemManager.Instance.AddItem(val); } SetDurability(ref val.ItemDrop.m_itemData); } public static void addSpeedPalStone() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown CustomItem val = ItemManager.Instance.GetItem("PalStoneSpeed"); if (val == null) { DBG.blogDebug("Adding recipe for Pal Stone Speed"); GameObject val2 = PP_Assets.LoadAsset<GameObject>(Plugin.assetPath + "PalStoneSpeed.prefab"); PrefabExtension.FixReferences(val2, true); DBG.blogDebug("Loaded from assets"); DBG.blogDebug("Set Name"); val = new CustomItem(val2, true, makePalStoneRecipe(Plugin.recipe_Speed.Value)); ItemManager.Instance.AddItem(val); DBG.blogDebug("Added Item"); } SetDurability(ref val.ItemDrop.m_itemData); } public static void addArmourPalStone() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown CustomItem val = ItemManager.Instance.GetItem("PalStoneArmour"); if (val == null) { DBG.blogDebug("Adding recipe for Pal Stone Armour"); GameObject val2 = PP_Assets.LoadAsset<GameObject>(Plugin.assetPath + "PalStoneArmour.prefab"); PrefabExtension.FixReferences(val2, true); val = new CustomItem(val2, true, makePalStoneRecipe(Plugin.recipe_Armor.Value)); ItemManager.Instance.AddItem(val); } SetDurability(ref val.ItemDrop.m_itemData); } public static void addHealPalStone() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown CustomItem val = ItemManager.Instance.GetItem("PalStoneHeal"); if (val == null) { DBG.blogDebug("Adding recipe for Pal Stone Heal"); GameObject val2 = PP_Assets.LoadAsset<GameObject>(Plugin.assetPath + "PalStoneHeal.prefab"); PrefabExtension.FixReferences(val2, true); val = new CustomItem(val2, true, makePalStoneRecipe(Plugin.recipe_Heal.Value)); ItemManager.Instance.AddItem(val); } SetDurability(ref val.ItemDrop.m_itemData); } public static void SetDurability(ref ItemData id2) { //IL_00ac: Unknown result type (might be due to invalid IL or missing references) if (Plugin.durability.Value > 0) { id2.m_shared.m_maxDurability = Plugin.durability.Value; id2.m_shared.m_useDurability = true; } else { id2.m_shared.m_useDurability = false; } if (Plugin.destroyOnBreak.Value) { id2.m_shared.m_canBeReparied = false; id2.m_shared.m_destroyBroken = true; } else if (Plugin.repairable.Value) { id2.m_shared.m_canBeReparied = true; } else { id2.m_shared.m_canBeReparied = false; } id2.m_shared.m_attachOverride = (ItemType)19; } private void addEffects() { //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) Transform transform = PP_Assets.LoadAsset<GameObject>(Plugin.assetPath + "vfx_ReleaseEffects.prefab").transform; GameObject val = Object.Instantiate<GameObject>(((Component)transform.Find("vfx_SpeedRelease")).gameObject, Root.transform); ((StatusEffect)SE_SpeedBuff).m_startEffects.m_effectPrefabs = NewStickyEffect(); ((StatusEffect)SE_SpeedBuff).m_startEffects.m_effectPrefabs[0].m_prefab = val; ((Object)SE_SpeedBuff).name = "SE_PPSpeed"; ((StatusEffect)SE_SpeedBuff).m_ttl = Plugin.Speed_buffLength.Value; SE_SpeedBuff.m_speedModifier = 1f + Plugin.speedIncrease.Value; GameObject val2 = Object.Instantiate<GameObject>(((Component)transform.Find("vfx_HealRelease")).gameObject, Root.transform); ((StatusEffect)SE_HealBuff).m_startEffects.m_effectPrefabs = NewStickyEffect(); ((StatusEffect)SE_HealBuff).m_startEffects.m_effectPrefabs[0].m_prefab = val2; ((Object)SE_HealBuff).name = "SE_PPHeal"; ((StatusEffect)SE_HealBuff).m_ttl = 10f; GameObject val3 = Object.Instantiate<GameObject>(((Component)transform.Find("vfx_ArmourRelease")).gameObject, Root.transform); ((StatusEffect)SE_ArmorBuff).m_startEffects.m_effectPrefabs = NewStickyEffect(); ((StatusEffect)SE_ArmorBuff).m_startEffects.m_effectPrefabs[0].m_prefab = val3; ((Object)SE_ArmorBuff).name = "SE_PPArmour"; ((StatusEffect)SE_ArmorBuff).m_ttl = Plugin.Armor_buffLength.Value; SE_ArmorBuff.m_mods = new List<DamageModPair>(); DamageModPair item = default(DamageModPair); item.m_type = (DamageType)1024; item.m_modifier = (DamageModifier)5; SE_ArmorBuff.m_mods.Add(item); PrefabManager.Instance.AddPrefab(val); PrefabManager.Instance.AddPrefab(val2); PrefabManager.Instance.AddPrefab(val3); } private EffectData[] NewStickyEffect() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown EffectData[] array = (EffectData[])(object)new EffectData[1] { new EffectData() }; EffectData val = array[0]; val.m_attach = true; val.m_inheritParentRotation = true; val.m_inheritParentScale = true; val.m_scale = true; return array; } } public static class Utils2 { private const BindingFlags bindingFlags = BindingFlags.Public; public static T GetCopyOf<T>(this Component comp, T other) where T : Component { Type type = ((object)comp).GetType(); if (type != ((object)other).GetType()) { return default(T); } List<Type> list = new List<Type>(); Type baseType = type.BaseType; while (baseType != null && !(baseType == typeof(MonoBehaviour))) { list.Add(baseType); baseType = baseType.BaseType; } IEnumerable<PropertyInfo> enumerable = type.GetProperties(BindingFlags.Public); foreach (Type item in list) { enumerable = enumerable.Concat(item.GetProperties(BindingFlags.Public)); } enumerable = from property in enumerable where !(type == typeof(Rigidbody)) || !(property.Name == "inertiaTensor") where !property.CustomAttributes.Any((CustomAttributeData attribute) => attribute.AttributeType == typeof(ObsoleteAttribute)) select property; foreach (PropertyInfo pinfo in enumerable) { if (pinfo.CanWrite && !enumerable.Any((PropertyInfo e) => e.Name == $"shared{char.ToUpper(pinfo.Name[0])}{pinfo.Name.Substring(1)}")) { try { pinfo.SetValue(comp, pinfo.GetValue(other, null), null); } catch { } } } IEnumerable<FieldInfo> enumerable2 = type.GetFields(BindingFlags.Public); foreach (FieldInfo finfo in enumerable2) { foreach (Type item2 in list) { if (!enumerable2.Any((FieldInfo e) => e.Name == $"shared{char.ToUpper(finfo.Name[0])}{finfo.Name.Substring(1)}")) { enumerable2 = enumerable2.Concat(item2.GetFields(BindingFlags.Public)); } } } foreach (FieldInfo item3 in enumerable2) { item3.SetValue(comp, item3.GetValue(other)); } enumerable2 = enumerable2.Where((FieldInfo field) => field.CustomAttributes.Any((CustomAttributeData attribute) => attribute.AttributeType == typeof(ObsoleteAttribute))); foreach (FieldInfo item4 in enumerable2) { item4.SetValue(comp, item4.GetValue(other)); } return (T)(object)((comp is T) ? comp : null); } public static T AddComponent<T>(this GameObject go, T toAdd) where T : Component { return go.AddComponent(((object)toAdd).GetType()).GetCopyOf(toAdd); } public static T CopyBroComponet<T, TU>(this Component comp, TU other) where T : Component { Type baseType = ((object)comp).GetType().BaseType; IEnumerable<FieldInfo> fields = baseType.GetFields(BindingFlags.Public); foreach (FieldInfo item in fields) { item.SetValue(comp, item.GetValue(other)); DBG.blogWarning(item?.ToString() + " , " + item.GetType()?.ToString() + " , " + item.Name); } return (T)(object)((comp is T) ? comp : null); } public static void addOrUpdateCustomData(Dictionary<string, string> dic, string key, string newValue) { if (dic.ContainsKey(key)) { dic[key] = newValue; return; } DBG.blogDebug("Added " + key + " to dictionary"); dic.Add(key, newValue); } } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<cea1c596-2509-4fde-b6a7-fc4de9b2fc99>Embedded] internal sealed class <cea1c596-2509-4fde-b6a7-fc4de9b2fc99>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [<cea1c596-2509-4fde-b6a7-fc4de9b2fc99>Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } [CompilerGenerated] [<cea1c596-2509-4fde-b6a7-fc4de9b2fc99>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [<cea1c596-2509-4fde-b6a7-fc4de9b2fc99>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class <a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContextAttribute : Attribute { public readonly byte Flag; public <a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContextAttribute(byte P_0) { Flag = P_0; } } [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] [CompilerGenerated] [<cea1c596-2509-4fde-b6a7-fc4de9b2fc99>Embedded] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace YamlDotNet { [<a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContext(1)] [<5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(0)] internal sealed class <942d5ce3-3418-4ff1-93cf-aa5e09d27064>CultureInfoAdapter : CultureInfo { private readonly IFormatProvider provider; public <942d5ce3-3418-4ff1-93cf-aa5e09d27064>CultureInfoAdapter(CultureInfo baseCulture, IFormatProvider provider) : base(baseCulture.Name) { this.provider = provider; } [return: <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(2)] public override object GetFormat(Type formatType) { return provider.GetFormat(formatType); } } [<5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(0)] [<a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContext(1)] internal static class Polyfills { [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool Contains(this string source, char c) { return source.IndexOf(c) != -1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool EndsWith(this string source, char c) { if (source.Length > 0) { return source[source.Length - 1] == c; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool StartsWith(this string source, char c) { if (source.Length > 0) { return source[0] == c; } return false; } } internal static class <7f1a0e8b-676e-4e34-a739-fc8359a06f5d>PropertyInfoExtensions { [<a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContext(1)] [return: <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(2)] public static object ReadValue(this PropertyInfo property, object target) { return property.GetValue(target, null); } } [<5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(0)] [<a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContext(1)] internal static class <c9085104-bbab-4c59-9ced-ebd0068193aa>ReflectionExtensions { private static readonly Func<PropertyInfo, bool> IsInstance = (PropertyInfo property) => !(property.GetMethod ?? property.SetMethod).IsStatic; private static readonly Func<PropertyInfo, bool> IsInstancePublic = (PropertyInfo property) => IsInstance(property) && (property.GetMethod ?? property.SetMethod).IsPublic; private static readonly ConcurrentDictionary<Type, bool> TypesHaveNullContext = new ConcurrentDictionary<Type, bool>(); [return: <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(2)] public static Type BaseType(this Type type) { return type.GetTypeInfo().BaseType; } public static bool IsValueType(this Type type) { return type.GetTypeInfo().IsValueType; } public static bool IsGenericType(this Type type) { return type.GetTypeInfo().IsGenericType; } public static bool IsGenericTypeDefinition(this Type type) { return type.GetTypeInfo().IsGenericTypeDefinition; } [return: <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(2)] public static Type GetImplementationOfOpenGenericInterface(this Type type, Type openGenericType) { if (!openGenericType.IsGenericType || !openGenericType.IsInterface) { throw new ArgumentException("The type must be a generic type definition and an interface", "openGenericType"); } if (IsGenericDefinitionOfType(type, openGenericType)) { return type; } return type.FindInterfaces([<a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContext(0)] (Type t, object context) => IsGenericDefinitionOfType(t, context), openGenericType).FirstOrDefault(); static bool IsGenericDefinitionOfType(Type t, [<5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(2)] object context) { if (t.IsGenericType) { return t.GetGenericTypeDefinition() == (Type)context; } return false; } } public static bool IsInterface(this Type type) { return type.GetTypeInfo().IsInterface; } public static bool IsEnum(this Type type) { return type.GetTypeInfo().IsEnum; } public static bool IsRequired(this MemberInfo member) { return member.GetCustomAttributes(inherit: true).Any([<a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContext(0)] (object x) => x.GetType().FullName == "System.Runtime.CompilerServices.RequiredMemberAttribute"); } public static bool HasDefaultConstructor(this Type type, bool allowPrivateConstructors) { BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public; if (allowPrivateConstructors) { bindingFlags |= BindingFlags.NonPublic; } if (!type.IsValueType) { return type.GetConstructor(bindingFlags, null, Type.EmptyTypes, null) != null; } return true; } public static bool IsAssignableFrom(this Type type, Type source) { return type.IsAssignableFrom(source.GetTypeInfo()); } public static bool IsAssignableFrom(this Type type, TypeInfo source) { return type.GetTypeInfo().IsAssignableFrom(source); } public static TypeCode GetTypeCode(this Type type) { if (IsEnum(type)) { type = Enum.GetUnderlyingType(type); } if (type == typeof(bool)) { return TypeCode.Boolean; } if (type == typeof(char)) { return TypeCode.Char; } if (type == typeof(sbyte)) { return TypeCode.SByte; } if (type == typeof(byte)) { return TypeCode.Byte; } if (type == typeof(short)) { return TypeCode.Int16; } if (type == typeof(ushort)) { return TypeCode.UInt16; } if (type == typeof(int)) { return TypeCode.Int32; } if (type == typeof(uint)) { return TypeCode.UInt32; } if (type == typeof(long)) { return TypeCode.Int64; } if (type == typeof(ulong)) { return TypeCode.UInt64; } if (type == typeof(float)) { return TypeCode.Single; } if (type == typeof(double)) { return TypeCode.Double; } if (type == typeof(decimal)) { return TypeCode.Decimal; } if (type == typeof(DateTime)) { return TypeCode.DateTime; } if (type == typeof(string)) { return TypeCode.String; } return TypeCode.Object; } public static bool IsDbNull(this object value) { return value?.GetType()?.FullName == "System.DBNull"; } public static Type[] GetGenericArguments(this Type type) { return type.GetTypeInfo().GenericTypeArguments; } [return: <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(2)] public static PropertyInfo GetPublicProperty(this Type type, string name) { return type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public).FirstOrDefault([<a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContext(0)] (PropertyInfo p) => p.Name == name); } [return: <5b7a07ea-374d-4e94-969f-eecfc1ed4d9b>Nullable(2)] public static FieldInfo GetPublicStaticField(this Type type, string name) { return type.GetRuntimeField(name); } public static IEnumerable<PropertyInfo> GetProperties(this Type type, bool includeNonPublic) { Func<PropertyInfo, bool> predicate = (includeNonPublic ? IsInstance : IsInstancePublic); if (!IsInterface(type)) { return type.GetRuntimeProperties().Where(predicate); } return new Type[1] { type }.Concat(type.GetInterfaces()).SelectMany([<a46c7842-adf9-4b22-99b1-12fca02b60a9>NullableContext(0)] (Type i) => i.GetRuntimeProperties().Where(predicate)); } public static IEnumerable<PropertyInfo> GetPublicProperties(this Type type) { return GetProperties(type, includeNonPublic: false); } public static IEnumerable<FieldInfo> GetPublicFields(this Type type) { return from f in type.GetRuntimeFields() where !f.IsStatic && f.IsPubl