Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Tamed Creature XP LevelUp v0.1.4
BepInEx/plugins/TamedCreatureXP.dll
Decompiled 14 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyCompany("TamedCreatureXP")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("TamedCreatureXP")] [assembly: AssemblyTitle("TamedCreatureXP")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace TamedCreatureXP { [HarmonyPatch(typeof(Character), "Awake")] internal static class CharacterAwakePatch { private static void Postfix(Character __instance) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown try { if (!Plugin.IsAllowedTamedCreature(__instance)) { return; } ZNetView nView = Plugin.GetNView(__instance); if ((Object)nView == (Object)null || !nView.IsValid() || !nView.IsOwner()) { return; } ZDO zDO = nView.GetZDO(); if (zDO == null) { return; } int num = zDO.GetInt("TamedCreatureXP.Level", 0); if (num > 0) { int num2 = Math.Max(1, Math.Min(num, Plugin.GetEffectiveMaxLevel())); if (num2 != __instance.GetLevel()) { __instance.SetLevel(num2); } } else { zDO.Set("TamedCreatureXP.Level", Math.Max(1, __instance.GetLevel())); } if (zDO.GetInt("TamedCreatureXP.XP", -1) < 0) { zDO.Set("TamedCreatureXP.XP", 0); } OfflineProgression.ApplyOnAwake(__instance, zDO); } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Awake XP sync: " + ex.Message)); } } } [HarmonyPatch(typeof(Character), "Damage")] internal static class CharacterDamageAssistPatch { [HarmonyPriority(0)] private static bool Prefix(Character __instance, HitData hit) { if (Plugin.IsLevelUpShieldActive(__instance)) { Plugin.ModLog.LogDebug((object)("LEVEL UP SHIELD BLOCK: " + Plugin.SafeName(__instance))); return false; } try { Plugin.RecordAssistDamage(__instance, hit); } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not record tame damage contribution: " + ex.Message)); } return true; } } [HarmonyPatch(typeof(Character), "OnDeath")] internal static class CharacterOnDeathPatch { private static void Postfix(Character __instance) { try { HitData lastHit = Plugin.GetLastHit(__instance); Character finalAttacker = ((lastHit != null && lastHit.HaveAttacker()) ? lastHit.GetAttacker() : null); List<Character> xPRecipients = Plugin.GetXPRecipients(__instance, finalAttacker); if (xPRecipients.Count == 0) { return; } float rewardShare = 1f / (float)xPRecipients.Count; foreach (Character item in xPRecipients) { Plugin.AddXP(item, __instance, Plugin.XPPerKill.Value, rewardShare); } } catch (Exception ex) { Plugin.ModLog.LogError((object)("[Tamed Creature XP] Error while adding XP: " + ex)); } } } internal static class CreatureBackpack { private sealed class WispVisualState { public Character Creature; public Transform Root; public Vector3 Center; public float Radius; public float Height; public float Phase; public float Speed; } [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class ObjectDbAwakePatch { private static void Postfix() { Initialize(); } } [HarmonyPatch(typeof(Humanoid), "UseItem", new Type[] { typeof(Inventory), typeof(ItemData), typeof(bool) })] private static class UseBackpackItemPatch { private static bool Prefix(Humanoid __instance, Inventory __0, ItemData __1) { try { return UseBackpackItem(__instance, __0, __1); } catch (Exception ex) { Plugin.ModLog.LogError((object)("Could not equip creature backpack: " + ex)); return false; } } } [HarmonyPatch(typeof(Container), "Awake")] private static class VirtualContainerAwakePatch { private static bool Prefix(Container __instance) { return VirtualContainerAwakePrefix(__instance); } } [HarmonyPatch(typeof(Container), "GetInventory")] private static class VirtualGetInventoryPatch { private static bool Prefix(Container __instance, ref Inventory __result) { return GetInventoryPrefix(__instance, ref __result); } } [HarmonyPatch(typeof(Container), "Load")] private static class VirtualContainerLoadPatch { private static bool Prefix(Container __instance, ref bool __result) { return ContainerLoadPrefix(__instance, ref __result); } } [HarmonyPatch(typeof(Container), "Save")] private static class VirtualContainerSavePatch { private static bool Prefix(Container __instance) { return ContainerSavePrefix(__instance); } } [HarmonyPatch(typeof(Container), "SetInUse")] private static class VirtualContainerUsePatch { [HarmonyPriority(800)] private static bool Prefix(Container __instance, bool __0) { return SetInUsePrefix(__instance, __0); } } [HarmonyPatch(typeof(InventoryGui), "Hide")] private static class SaveBackpackOnGuiClosePatch { private static void Prefix() { OnGuiClosing(); } private static void Postfix() { OnGuiClosed(); HideBackpackPanelFrame(); } } [HarmonyPatch(typeof(InventoryGui), "UpdateContainer")] private static class KeepVirtualContainerInRangePatch { private static void Prefix(InventoryGui __instance, Player __0) { try { FollowPlayerWhileOpen(__instance, __0); } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not keep the backpack container within interaction range: " + ex.Message)); } } private static void Postfix(InventoryGui __instance) { try { UpdateBackpackInventoryStyle(__instance); } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not style the backpack inventory panel: " + ex.Message)); } } } [HarmonyPatch(typeof(InventoryGui), "CloseContainer")] private static class HideBackpackPanelFramePatch { private static void Postfix() { HideBackpackPanelFrame(); } } private const string ItemPrefabName = "TamedCreatureXP_CreatureBackpack"; private const string ItemInternalName = "$item_tamedcreaturexp_creaturebackpack"; private const string BackpackFrenchName = "Sac à dos de créature"; private const string BackpackFrenchDescription = "Un sac robuste renforcé d’os, lié à un feu follet violet. À équiper sur une créature apprivoisée de niveau 4 ou plus. Le sac est consommé et reste lié à cette créature. Vise-la et appuie sur la touche configurée pour ouvrir ses 15 emplacements. Appuie sur E pour le fermer."; private const string ContainerObjectName = "TamedCreatureXP_VirtualCreatureBackpack"; private const string VisualObjectName = "TamedCreatureXP_CreatureBackpackVisual_v3"; private const string LegacyVisualObjectName = "TamedCreatureXP_CreatureBackpackVisual"; private const string PreviousVisualObjectName = "TamedCreatureXP_CreatureBackpackVisual_v2"; private const string BackpackPanelFrameName = "TamedCreatureXP_CreatureBackpackPanelFrame"; private const string HasPackKey = "TamedCreatureXP.HasBackpack"; private const string ContentsKey = "TamedCreatureXP.BackpackContents"; private const int UnlockLevel = 4; private const int BackpackWidth = 5; private const int BackpackHeight = 3; private static ObjectDB _registeredObjectDb; private static GameObject _itemPrefab; private static Recipe _recipe; private static bool _recipeUnlocked; private static Container _virtualContainer; private static Inventory _virtualInventory; private static Character _openCreature; private static ZDO _openZdo; private static Sprite _backpackSprite; private static Sprite _panelFrameSprite; private static Transform _panelFrame; private static Material _violetTrailMaterial; private static Material _violetWispOrbMaterial; private static Texture2D _violetWispOrbTexture; private static int _styledTitleInstanceId; private static float _styledTitleOriginalFontSize; private static readonly List<WispVisualState> WispVisuals = new List<WispVisualState>(); private static bool _saving; private static bool _closingVirtualContainer; private static float _nextPeriodicSave; private static bool _warnedRegistration; private static bool _warnedSave; private static bool _warnedVisual; private static bool _warnedJotunn; private static bool _warnedPanelStyle; private static bool _azuAutoStoreCompatibilityPatched; private static bool _warnedAzuAutoStorePatch; private static object _jotunnCustomItem; private static object _jotunnCustomRecipe; private static bool _jotunnItemAdded; internal static void Initialize() { try { EnsureObjectDbRegistration(); } catch (Exception ex) { if (!_warnedRegistration) { _warnedRegistration = true; Plugin.ModLog.LogWarning((object)("Creature backpack registration is waiting for Valheim: " + ex.Message)); } } } private static List<Character> SnapshotLoadedCharacters() { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown List<Character> list = new List<Character>(); FieldInfo fieldInfo = AccessTools.Field(typeof(Character), "s_characters"); IEnumerable enumerable = ((fieldInfo == null) ? null : (fieldInfo.GetValue(null) as IEnumerable)); if (enumerable == null) { return list; } try { foreach (object item in enumerable) { Character val = (Character)((item is Character) ? item : null); if ((Object)val != (Object)null) { list.Add(val); } } } catch (InvalidOperationException ex) { Plugin.ModLog.LogDebug((object)("Creature list changed while being copied for backpack refresh: " + ex.Message)); } return list; } internal static void TryPatchAzuAutoStore(Harmony harmony) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown if (_azuAutoStoreCompatibilityPatched || harmony == null) { return; } Type type = AccessTools.TypeByName("AzuAutoStore.Patches.ContainerSetInUseClearWithoutOwnershipPatch"); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "Prefix", (Type[])null, (Type[])null)); MethodInfo methodInfo2 = AccessTools.Method(typeof(CreatureBackpack), "AzuAutoStoreContainerPrefixGuard", (Type[])null, (Type[])null); if (methodInfo == null || methodInfo2 == null) { return; } try { HarmonyMethod val = new HarmonyMethod(methodInfo2); val.priority = 800; harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _azuAutoStoreCompatibilityPatched = true; Plugin.ModLog.LogInfo((object)"AzuAutoStore compatibility enabled for the virtual creature backpack."); } catch (Exception ex) { if (!_warnedAzuAutoStorePatch) { _warnedAzuAutoStorePatch = true; Plugin.ModLog.LogWarning((object)("Could not isolate the virtual creature backpack from AzuAutoStore: " + ex.Message)); } } } private static bool AzuAutoStoreContainerPrefixGuard(Container __0) { return !IsVirtual(__0); } internal static void RefreshRecipeUnlock() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown Initialize(); if ((Object)_recipe == (Object)null || (Object)ObjectDB.instance == (Object)null) { return; } bool flag = Plugin.BackpackUnlocked != null && Plugin.BackpackUnlocked.Value; try { foreach (Character item in SnapshotLoadedCharacters()) { if (!Plugin.IsAllowedTamedCreature(item) || item.GetLevel() < 4) { continue; } flag = true; if (Plugin.BackpackUnlocked != null && !Plugin.BackpackUnlocked.Value) { Plugin.BackpackUnlocked.Value = true; if ((Object)Plugin.Instance != (Object)null) { ((BaseUnityPlugin)Plugin.Instance).Config.Save(); } } break; } } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not inspect tamed creatures for backpack recipe unlock: " + ex.Message)); } if (_recipeUnlocked == flag && _recipe.m_enabled == flag) { return; } _recipeUnlocked = flag; _recipe.m_enabled = flag; try { AccessTools.Method(typeof(ObjectDB), "UpdateRegisters", (Type[])null, (Type[])null)?.Invoke(ObjectDB.instance, null); } catch (Exception ex2) { Plugin.ModLog.LogDebug((object)("Could not refresh backpack recipe: " + ex2.Message)); } } internal static void RefreshAttachedBackpacks() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown try { foreach (Character item in SnapshotLoadedCharacters()) { if ((Object)item == (Object)null || !item.IsTamed() || item.IsDead()) { continue; } ZNetView nView = Plugin.GetNView(item); ZDO val = (((Object)nView != (Object)null && nView.IsValid()) ? nView.GetZDO() : null); if (val != null) { if (val.GetBool("TamedCreatureXP.HasBackpack", false)) { EnsureBackpackVisual(item); } else { RemoveBackpackVisual(item); } } } } catch (Exception ex) { if (!_warnedVisual) { _warnedVisual = true; Plugin.ModLog.LogWarning((object)("Could not refresh visible creature backpacks: " + ex)); } } } internal static void TickBackpackWisps() { //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_007f: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) for (int num = WispVisuals.Count - 1; num >= 0; num--) { WispVisualState wispVisualState = WispVisuals[num]; if (wispVisualState == null || (Object)wispVisualState.Creature == (Object)null || (Object)wispVisualState.Root == (Object)null || wispVisualState.Creature.IsDead()) { WispVisuals.RemoveAt(num); } else { float num2 = Time.time * wispVisualState.Speed + wispVisualState.Phase; wispVisualState.Root.localPosition = wispVisualState.Center + new Vector3(Mathf.Cos(num2) * wispVisualState.Radius, Mathf.Sin(num2 * 2f) * wispVisualState.Height, Mathf.Sin(num2) * wispVisualState.Radius); wispVisualState.Root.localRotation = Quaternion.Euler(0f, (0f - num2) * 57.29578f, 0f); TickWispSparks(wispVisualState, num2); } } if ((Object)_openCreature != (Object)null && Time.unscaledTime >= _nextPeriodicSave) { _nextPeriodicSave = Time.unscaledTime + 0.75f; SaveIfOpen(); } } internal static void EnsureAttachedBackpack(Character creature) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown if (!((Object)creature == (Object)null) && creature.IsTamed() && !creature.IsDead()) { ZNetView nView = Plugin.GetNView(creature); ZDO val = (((Object)nView != (Object)null && nView.IsValid()) ? nView.GetZDO() : null); if (val != null && val.GetBool("TamedCreatureXP.HasBackpack", false)) { EnsureBackpackVisual(creature); } else { RemoveBackpackVisual(creature); } } } internal static bool HasBackpack(Character creature) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown if ((Object)creature == (Object)null) { return false; } ZNetView nView = Plugin.GetNView(creature); ZDO val = (((Object)nView != (Object)null && nView.IsValid()) ? nView.GetZDO() : null); if (val != null) { return val.GetBool("TamedCreatureXP.HasBackpack", false); } return false; } private static byte[] SerializeInventory(Inventory inventory) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown if (inventory == null) { return null; } ZPackage val = new ZPackage(); inventory.Save(val); return val.GetArray(); } private static void EnsureBackpackVisual(Character creature) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) try { Transform val = FindChild(((Component)creature).transform, "TamedCreatureXP_CreatureBackpackVisual"); if ((Object)val != (Object)null) { Object.Destroy((Object)((Component)val).gameObject); } Transform val2 = FindChild(((Component)creature).transform, "TamedCreatureXP_CreatureBackpackVisual_v2"); if ((Object)val2 != (Object)null) { Object.Destroy((Object)((Component)val2).gameObject); } Transform val3 = FindChild(((Component)creature).transform, "TamedCreatureXP_CreatureBackpackVisual_v3"); if ((Object)val3 == (Object)null) { val3 = new GameObject("TamedCreatureXP_CreatureBackpackVisual_v3").transform; val3.SetParent(((Component)creature).transform, false); BuildBackpackWisp(val3, creature); } FitBackpackWisp(creature, val3); } catch (Exception ex) { if (!_warnedVisual) { _warnedVisual = true; Plugin.ModLog.LogWarning((object)("Could not create visible backpack on " + ((Object)((Component)creature).gameObject).name + ": " + ex)); } } } private static void BuildBackpackWisp(Transform root, Character creature) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Expected O, but got Unknown //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown GameObject val = FindWispVisualSource(); GameObject val2 = null; if ((Object)val != (Object)null) { try { val2 = Object.Instantiate<GameObject>(val, root, false); ((Object)val2).name = "VioletWispTexturedModel"; val2.SetActive(true); val2.transform.localPosition = Vector3.zero; val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one; StripNonVisualComponents(val2); TintWispRenderers(val2, new Color(0.76f, 0.4f, 1f, 1f)); TuneWispEffects(val2); NormalizeWispSize(val2); PlayWispParticles(val2); } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not reuse an in-game wisp visual: " + ex.Message)); if ((Object)val2 != (Object)null) { Object.Destroy((Object)val2); } val2 = null; } } if ((Object)val2 == (Object)null) { BuildTexturedFallbackWisp(root, creature); } AddVioletWispTrails(root); if (!HasParticleVisual(root)) { AddWispSparkMotes(root); } } private static void AddVioletWispTrails(Transform root) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) if (!((Object)root == (Object)null) && !((Object)FindChild(root, "VioletWispTrailGlow") != (Object)null)) { Material violetTrailMaterial = GetVioletTrailMaterial(); if (!((Object)violetTrailMaterial == (Object)null)) { CreateWispTrail(root, "VioletWispTrailGlow", violetTrailMaterial, 0.06f, 0.38f, new Color(0.68f, 0.36f, 1f, 1f), new Color(0.42f, 0.18f, 0.82f, 1f), 0.18f); CreateWispTrail(root, "VioletWispTrailCore", violetTrailMaterial, 0.024f, 0.32f, new Color(0.91f, 0.76f, 1f, 1f), new Color(0.66f, 0.38f, 1f, 1f), 0.68f); } } } private static Material GetVioletTrailMaterial() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) if ((Object)_violetTrailMaterial != (Object)null) { return _violetTrailMaterial; } Shader val = Shader.Find("Particles/Standard Unlit"); if ((Object)val == (Object)null) { val = Shader.Find("Sprites/Default"); } if ((Object)val == (Object)null) { val = Shader.Find("Legacy Shaders/Particles/Alpha Blended"); } if ((Object)val == (Object)null) { if (!_warnedVisual) { _warnedVisual = true; Plugin.ModLog.LogWarning((object)"Could not find a transparent shader for the violet backpack wisp trail."); } return null; } _violetTrailMaterial = new Material(val); string[] array = new string[3] { "_Color", "_BaseColor", "_TintColor" }; foreach (string text in array) { if (_violetTrailMaterial.HasProperty(text)) { _violetTrailMaterial.SetColor(text, Color.white); } } return _violetTrailMaterial; } private static void CreateWispTrail(Transform root, string name, Material material, float width, float duration, Color startColor, Color endColor, float alpha) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: 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_0109: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(root, false); TrailRenderer val2 = val.AddComponent<TrailRenderer>(); ((Renderer)val2).material = material; val2.time = duration; val2.widthMultiplier = width; val2.widthCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[2] { new Keyframe(0f, 1f), new Keyframe(1f, 0.08f) }); val2.minVertexDistance = 0.012f; val2.numCornerVertices = 8; val2.numCapVertices = 8; val2.emitting = true; val2.autodestruct = false; Gradient val3 = new Gradient(); val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(startColor, 0f), new GradientColorKey(endColor, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[3] { new GradientAlphaKey(alpha, 0f), new GradientAlphaKey(alpha * 0.28f, 0.55f), new GradientAlphaKey(0f, 1f) }); val2.colorGradient = val3; } private static GameObject FindWispVisualSource() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_0042: 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_0057: Expected O, but got Unknown //IL_0057: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer != (Object)null) { Transform[] componentsInChildren = ((Component)localPlayer).GetComponentsInChildren<Transform>(true); GameObject val = null; int num = 0; Transform[] array = componentsInChildren; foreach (Transform val2 in array) { if (!((Object)val2 == (Object)null) && !((Object)val2 == (Object)((Component)localPlayer).transform) && ((Object)val2).name.ToLowerInvariant().IndexOf("wisp", StringComparison.Ordinal) >= 0 && ((Component)val2).GetComponentsInChildren<Renderer>(true).Length != 0 && IsVisualOnlyTree(((Component)val2).gameObject)) { int num2 = ScoreWispVisualSource(val2); if (num2 > num) { num = num2; val = ((Component)val2).gameObject; } } } if ((Object)val != (Object)null) { return val; } } return null; } private static int ScoreWispVisualSource(Transform candidate) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown Renderer[] componentsInChildren = ((Component)candidate).GetComponentsInChildren<Renderer>(true); MeshFilter[] componentsInChildren2 = ((Component)candidate).GetComponentsInChildren<MeshFilter>(true); Component[] componentsInChildren3 = ((Component)candidate).GetComponentsInChildren<Component>(true); int num = componentsInChildren.Length * 10 + componentsInChildren2.Length * 4; Component[] array = componentsInChildren3; foreach (Component val in array) { if (!((Object)val == (Object)null)) { switch (((object)val).GetType().Name) { case "ParticleSystem": num += 4; break; case "TrailRenderer": num += 5; break; case "Light": num += 3; break; } } } string text = ((Object)candidate).name.ToLowerInvariant(); if (text.Contains("wisplight")) { num += 80; } else if (text == "wisp") { num += 24; } return num; } private static bool IsVisualOnlyTree(GameObject root) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if (!((Object)val == (Object)null) && !(val is Transform) && !(val is Renderer) && !(val is MeshFilter) && !(((object)val).GetType().Name == "Animator") && !(((object)val).GetType().Name == "Animation") && !(((object)val).GetType().Name == "ParticleSystem") && !(((object)val).GetType().Name == "Light")) { return false; } } return true; } private static void StripNonVisualComponents(GameObject root) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if (!((Object)val == (Object)null) && !(val is Transform) && !(val is Renderer) && !(val is MeshFilter) && !(((object)val).GetType().Name == "Animator") && !(((object)val).GetType().Name == "Animation") && !(((object)val).GetType().Name == "ParticleSystem") && !(((object)val).GetType().Name == "Light")) { Object.Destroy((Object)val); } } } private static void TintWispRenderers(GameObject root, Color tint) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if ((Object)val == (Object)null) { continue; } Material[] materials = val.materials; Material[] array = materials; foreach (Material val2 in array) { if ((Object)val2 == (Object)null) { continue; } string[] array2 = new string[3] { "_Color", "_BaseColor", "_TintColor" }; foreach (string text in array2) { if (val2.HasProperty(text)) { Color color = val2.GetColor(text); val2.SetColor(text, new Color(color.r * tint.r, color.g * tint.g, color.b * tint.b, color.a * tint.a)); } } if (val2.HasProperty("_EmissionColor")) { val2.SetColor("_EmissionColor", tint * 1.6f); val2.EnableKeyword("_EMISSION"); } } val.materials = materials; } } private static void NormalizeWispSize(GameObject root) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true); if (componentsInChildren.Length == 0) { return; } List<Renderer> list = new List<Renderer>(); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if ((Object)val != (Object)null && ((object)val).GetType().Name != "ParticleSystemRenderer" && ((object)val).GetType().Name != "TrailRenderer") { list.Add(val); } } if (list.Count != 0) { Bounds bounds = list[0].bounds; for (int j = 1; j < list.Count; j++) { ((Bounds)(ref bounds)).Encapsulate(list[j].bounds); } float num = Mathf.Max(((Bounds)(ref bounds)).size.x, Mathf.Max(((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z)); if (num > 0.001f) { Transform transform = root.transform; transform.localScale *= 0.82f / num; } } } private static void PlayWispParticles(GameObject root) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if (!((Object)val == (Object)null) && !(((object)val).GetType().Name != "ParticleSystem")) { try { AccessTools.Method(((object)val).GetType(), "Play", new Type[1] { typeof(bool) }, (Type[])null)?.Invoke(val, new object[1] { true }); } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not start a cloned wisp particle system: " + ex.Message)); } } } } private static void TuneWispEffects(GameObject root) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); Type type = AccessTools.TypeByName("UnityEngine.TrailRenderer"); Component[] array = componentsInChildren; foreach (Component val in array) { if ((Object)val == (Object)null) { continue; } try { if (type != null && type.IsInstanceOfType(val)) { SetFloatProperty(val, "time", 0.28f, onlyReduce: true); float floatProperty = GetFloatProperty(val, "widthMultiplier", 0.1f); SetFloatProperty(val, "widthMultiplier", Mathf.Max(0.008f, floatProperty * 0.48f), onlyReduce: false); SetFloatProperty(val, "minVertexDistance", 0.025f, onlyReduce: true); SetIntProperty(val, "numCornerVertices", 5); SetIntProperty(val, "numCapVertices", 5); AccessTools.Method(((object)val).GetType(), "Clear", (Type[])null, (Type[])null)?.Invoke(val, null); } else if (((object)val).GetType().Name == "ParticleSystem") { ReduceParticleCurve(val, "startLifetime", 0.55f, 0.65f); ReduceParticleCurve(val, "startSize", 0.15f, 0.65f); } } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not tune a cloned wisp effect: " + ex.Message)); } } } private static void ReduceParticleCurve(Component particleSystem, string propertyName, float maximum, float factor) { PropertyInfo propertyInfo = AccessTools.Property(((object)particleSystem).GetType(), "main"); if (propertyInfo == null) { return; } object value = propertyInfo.GetValue(particleSystem, null); if (value == null) { return; } PropertyInfo propertyInfo2 = AccessTools.Property(value.GetType(), propertyName); if (!(propertyInfo2 == null) && propertyInfo2.CanWrite) { object value2 = propertyInfo2.GetValue(value, null); PropertyInfo propertyInfo3 = ((value2 == null) ? null : AccessTools.Property(value2.GetType(), "constantMax")); float num = ((propertyInfo3 == null) ? maximum : Convert.ToSingle(propertyInfo3.GetValue(value2, null))); float num2 = Mathf.Min(maximum, num * factor); if (!(num2 <= 0f)) { object value3 = Activator.CreateInstance(propertyInfo2.PropertyType, num2); propertyInfo2.SetValue(value, value3, null); } } } private static float GetFloatProperty(Component component, string name, float fallback) { PropertyInfo propertyInfo = AccessTools.Property(((object)component).GetType(), name); if (propertyInfo == null) { return fallback; } object value = propertyInfo.GetValue(component, null); if (value != null) { return Convert.ToSingle(value); } return fallback; } private static void SetFloatProperty(Component component, string name, float value, bool onlyReduce) { PropertyInfo propertyInfo = AccessTools.Property(((object)component).GetType(), name); if (!(propertyInfo == null) && propertyInfo.CanWrite) { float num = value; if (onlyReduce) { num = Mathf.Min(GetFloatProperty(component, name, value), value); } propertyInfo.SetValue(component, num, null); } } private static void SetIntProperty(Component component, string name, int value) { PropertyInfo propertyInfo = AccessTools.Property(((object)component).GetType(), name); if (propertyInfo != null && propertyInfo.CanWrite) { propertyInfo.SetValue(component, value, null); } } private static bool HasParticleVisual(Transform root) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown Component[] componentsInChildren = ((Component)root).GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if ((Object)val != (Object)null && ((object)val).GetType().Name == "ParticleSystem") { return true; } } return false; } private static void BuildTexturedFallbackWisp(Transform root, Character creature) { //IL_0025: 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_007a: Expected O, but got Unknown //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown GameObject val = GameObject.CreatePrimitive((PrimitiveType)0); ((Object)val).name = "VioletWispTexturedFallback"; val.transform.SetParent(root, false); val.transform.localScale = Vector3.one; Renderer component = val.GetComponent<Renderer>(); Type type = AccessTools.TypeByName("UnityEngine.Collider"); Component val2 = ((type == null) ? null : val.GetComponent(type)); PropertyInfo propertyInfo = ((type == null) ? null : AccessTools.Property(type, "enabled")); if ((Object)val2 != (Object)null && propertyInfo != null) { propertyInfo.SetValue(val2, false, null); } if ((Object)component != (Object)null) { if ((Object)_violetWispOrbMaterial == (Object)null) { _violetWispOrbMaterial = CreateVioletWispOrbMaterial(); } if ((Object)_violetWispOrbMaterial != (Object)null) { component.sharedMaterial = _violetWispOrbMaterial; } } } private static Material CreateVioletWispOrbMaterial() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) Shader val = Shader.Find("Standard"); if ((Object)val == (Object)null) { val = Shader.Find("Unlit/Texture"); } if ((Object)val == (Object)null) { val = Shader.Find("Sprites/Default"); } if ((Object)val == (Object)null) { return null; } _violetWispOrbTexture = CreateVioletWispOrbTexture(); Material val2 = new Material(val); if ((Object)_violetWispOrbTexture != (Object)null) { if (val2.HasProperty("_MainTex")) { val2.SetTexture("_MainTex", (Texture)(object)_violetWispOrbTexture); } if (val2.HasProperty("_BaseMap")) { val2.SetTexture("_BaseMap", (Texture)(object)_violetWispOrbTexture); } } Color val3 = default(Color); ((Color)(ref val3))..ctor(0.82f, 0.58f, 1f, 1f); string[] array = new string[3] { "_Color", "_BaseColor", "_TintColor" }; foreach (string text in array) { if (val2.HasProperty(text)) { val2.SetColor(text, val3); } } if (val2.HasProperty("_EmissionColor")) { val2.SetColor("_EmissionColor", new Color(0.34f, 0.12f, 0.58f, 1f)); val2.EnableKeyword("_EMISSION"); } if (val2.HasProperty("_Glossiness")) { val2.SetFloat("_Glossiness", 0.68f); } return val2; } private static Texture2D CreateVioletWispOrbTexture() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, true); ((Object)val).name = "TamedCreatureXP_VioletWispTexture"; ((Texture)val).wrapMode = (TextureWrapMode)0; ((Texture)val).filterMode = (FilterMode)1; Color32[] array = (Color32[])(object)new Color32[4096]; for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { float num = (float)j / 64f; float num2 = (float)i / 64f; float num3 = 0.5f + 0.5f * Mathf.Sin((num * 5f + Mathf.Sin(num2 * ((float)Math.PI * 4f)) * 0.14f) * ((float)Math.PI * 2f)); float num4 = 0.5f + 0.5f * Mathf.Sin((num * 13f + num2 * 9f) * ((float)Math.PI * 2f)); float num5 = Mathf.Clamp01(0.16f + num3 * 0.55f + num4 * 0.12f); array[i * 64 + j] = new Color32((byte)Mathf.RoundToInt(46f + num5 * 164f), (byte)Mathf.RoundToInt(20f + num5 * 105f), (byte)Mathf.RoundToInt(88f + num5 * 160f), byte.MaxValue); } } val.SetPixels32(array); val.Apply(true, true); return val; } private static Material FindCreatureMaterial(Character creature) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown if ((Object)creature == (Object)null) { return null; } Renderer[] componentsInChildren = ((Component)creature).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if ((Object)val == (Object)null || IsChildOfNamedTransform(((Component)val).transform, "TamedCreatureXP_CreatureBackpackVisual_v3")) { continue; } Material[] sharedMaterials = val.sharedMaterials; if (sharedMaterials == null) { continue; } Material[] array = sharedMaterials; foreach (Material val2 in array) { if ((Object)val2 != (Object)null) { return val2; } } } return null; } private static void AddWispSparkMotes(Transform root) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < 5; i++) { GameObject val = GameObject.CreatePrimitive((PrimitiveType)0); ((Object)val).name = "VioletWispMote_" + i; val.transform.SetParent(root, false); val.transform.localScale = Vector3.one * ((i % 2 == 0) ? 0.11f : 0.075f); val.transform.localPosition = Vector3.zero; Renderer component = val.GetComponent<Renderer>(); Type type = AccessTools.TypeByName("UnityEngine.Collider"); Component val2 = ((type == null) ? null : val.GetComponent(type)); PropertyInfo propertyInfo = ((type == null) ? null : AccessTools.Property(type, "enabled")); if ((Object)val2 != (Object)null && propertyInfo != null) { propertyInfo.SetValue(val2, false, null); } if ((Object)component != (Object)null) { Material material = component.material; if ((Object)material != (Object)null && material.HasProperty("_Color")) { material.SetColor("_Color", (i % 2 == 0) ? new Color(0.9f, 0.72f, 1f, 1f) : new Color(0.55f, 0.18f, 0.95f, 1f)); } if ((Object)material != (Object)null && material.HasProperty("_EmissionColor")) { material.SetColor("_EmissionColor", new Color(0.65f, 0.2f, 1f, 1f) * 1.7f); material.EnableKeyword("_EMISSION"); } } } } private static void TickWispSparks(WispVisualState state, float angle) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < state.Root.childCount; i++) { Transform child = state.Root.GetChild(i); if (!((Object)child == (Object)null) && ((Object)child).name.IndexOf("VioletWispMote_", StringComparison.Ordinal) == 0) { float num = (float)i * (float)Math.PI * 0.4f; float num2 = 1f + (float)(i % 2) * 0.25f; child.localPosition = new Vector3(Mathf.Cos(angle * num2 + num) * 0.72f, Mathf.Sin(angle * 1.7f + num) * 0.55f, Mathf.Sin(angle * num2 + num) * 0.72f); } } } private static void FitBackpackWisp(Character creature, Transform visual) { //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) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_0044: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //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_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: 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_0197: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) try { Renderer[] componentsInChildren = ((Component)creature).GetComponentsInChildren<Renderer>(); Bounds bounds = default(Bounds); ((Bounds)(ref bounds))..ctor(((Component)creature).transform.position + Vector3.up, Vector3.one); bool flag = false; Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if (!((Object)val == (Object)null) && !IsChildOfNamedTransform(((Component)val).transform, "TamedCreatureXP_CreatureBackpackVisual_v3") && (val is SkinnedMeshRenderer || val is MeshRenderer)) { if (!flag) { bounds = val.bounds; flag = true; } else { ((Bounds)(ref bounds)).Encapsulate(val.bounds); } } } float num = (flag ? Mathf.Max(0.5f, ((Bounds)(ref bounds)).size.y) : 1.5f); Vector3 val2 = ((Component)creature).transform.InverseTransformPoint(flag ? ((Bounds)(ref bounds)).center : (((Component)creature).transform.position + Vector3.up * num * 0.5f)); float num2 = Mathf.Max(0.1f, Mathf.Abs(((Component)creature).transform.lossyScale.y)); float num3 = num / num2; float num4 = Mathf.Clamp(num3 * 0.04f, 0.09f, 0.15f); WispVisualState wispVisualState = FindWispState(visual); if (wispVisualState == null) { wispVisualState = new WispVisualState { Creature = creature, Root = visual, Phase = (float)(((Object)creature).GetInstanceID() % 1000) * 0.013f, Speed = 2f }; WispVisuals.Add(wispVisualState); } wispVisualState.Creature = creature; wispVisualState.Root = visual; wispVisualState.Center = val2 + Vector3.up * (num3 * 0.16f); wispVisualState.Radius = Mathf.Clamp(num3 * 0.35f, 0.38f, 1.05f); wispVisualState.Height = Mathf.Clamp(num3 * 0.055f, 0.045f, 0.16f); visual.localScale = Vector3.one * num4; TickSingleWisp(wispVisualState); } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not position backpack wisp on " + ((Object)((Component)creature).gameObject).name + ": " + ex.Message)); } } private static WispVisualState FindWispState(Transform visual) { //IL_0021: 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_0031: Expected O, but got Unknown //IL_0031: Expected O, but got Unknown for (int i = 0; i < WispVisuals.Count; i++) { if (WispVisuals[i] != null && (Object)WispVisuals[i].Root == (Object)visual) { return WispVisuals[i]; } } return null; } private static void TickSingleWisp(WispVisualState state) { //IL_001b: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) float num = Time.time * state.Speed + state.Phase; state.Root.localPosition = state.Center + new Vector3(Mathf.Cos(num) * state.Radius, Mathf.Sin(num * 2f) * state.Height, Mathf.Sin(num) * state.Radius); state.Root.localRotation = Quaternion.Euler(0f, (0f - num) * 57.29578f, 0f); } private static bool IsChildOfNamedTransform(Transform transform, string name) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown while ((Object)transform != (Object)null) { if (((Object)transform).name == name) { return true; } transform = transform.parent; } return false; } private static Transform FindChild(Transform parent, string name) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown if ((Object)parent == (Object)null) { return null; } if (((Object)parent).name == name) { return parent; } for (int i = 0; i < parent.childCount; i++) { Transform val = FindChild(parent.GetChild(i), name); if ((Object)val != (Object)null) { return val; } } return null; } private static void RemoveBackpackVisual(Character creature) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_006c: Expected O, but got Unknown //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown Transform val = (((Object)creature == (Object)null) ? null : FindChild(((Component)creature).transform, "TamedCreatureXP_CreatureBackpackVisual_v3")); if ((Object)val != (Object)null) { for (int num = WispVisuals.Count - 1; num >= 0; num--) { if (WispVisuals[num] != null && (Object)WispVisuals[num].Root == (Object)val) { WispVisuals.RemoveAt(num); } } } if ((Object)val != (Object)null) { Object.Destroy((Object)((Component)val).gameObject); } Transform val2 = (((Object)creature == (Object)null) ? null : FindChild(((Component)creature).transform, "TamedCreatureXP_CreatureBackpackVisual")); if ((Object)val2 != (Object)null) { Object.Destroy((Object)((Component)val2).gameObject); } Transform val3 = (((Object)creature == (Object)null) ? null : FindChild(((Component)creature).transform, "TamedCreatureXP_CreatureBackpackVisual_v2")); if ((Object)val3 != (Object)null) { Object.Destroy((Object)((Component)val3).gameObject); } } internal static void SaveForPortablePals(Character creature) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_000f: 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_0023: Expected O, but got Unknown //IL_0023: Expected O, but got Unknown if ((Object)creature != (Object)null && (Object)creature == (Object)_openCreature) { SaveIfOpen(); } } internal static void WritePortablePalsData(ZDO zdo, IDictionary<string, string> customData) { if (zdo != null && customData != null) { customData["TamedCreatureXP.HasBackpack"] = zdo.GetBool("TamedCreatureXP.HasBackpack", false).ToString(); byte[] byteArray = zdo.GetByteArray("TamedCreatureXP.BackpackContents", (byte[])null); customData["TamedCreatureXP.BackpackContents"] = ((byteArray == null) ? string.Empty : Convert.ToBase64String(byteArray)); } } internal static void RestoreFromPortablePals(ZDO zdo, IDictionary<string, string> customData) { if (zdo == null || customData == null) { return; } if (customData.TryGetValue("TamedCreatureXP.HasBackpack", out var value) && bool.TryParse(value, out var result)) { zdo.Set("TamedCreatureXP.HasBackpack", result); } if (!customData.TryGetValue("TamedCreatureXP.BackpackContents", out var value2)) { return; } try { zdo.Set("TamedCreatureXP.BackpackContents", string.IsNullOrEmpty(value2) ? new byte[0] : Convert.FromBase64String(value2)); } catch (Exception ex) { Plugin.ModLog.LogWarning((object)("Could not restore Pal Stone backpack contents: " + ex.Message)); } } private static void EnsureObjectDbRegistration() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Expected O, but got Unknown //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Expected O, but got Unknown //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Expected O, but got Unknown ObjectDB instance = ObjectDB.instance; if ((Object)instance == (Object)null) { return; } if ((Object)(object)_registeredObjectDb == (Object)(object)instance) { EnsureRecipe(instance); return; } _registeredObjectDb = instance; _itemPrefab = null; _recipe = null; _recipeUnlocked = false; RegisterLocalization(); GameObject itemPrefab = instance.GetItemPrefab("TamedCreatureXP_CreatureBackpack"); if ((Object)itemPrefab != (Object)null) { _itemPrefab = itemPrefab; if ((Object)_backpackSprite == (Object)null) { _backpackSprite = CreateBackpackSprite(instance); } ItemDrop component = itemPrefab.GetComponent<ItemDrop>(); if ((Object)component != (Object)null && component.m_itemData != null && component.m_itemData.m_shared != null) { component.m_itemData.m_shared.m_name = "Sac à dos de créature"; component.m_itemData.m_shared.m_description = "Un sac robuste renforcé d’os, lié à un feu follet violet. À équiper sur une créature apprivoisée de niveau 4 ou plus. Le sac est consommé et reste lié à cette créature. Vise-la et appuie sur la touche configurée pour ouvrir ses 15 emplacements. Appuie sur E pour le fermer."; component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { _backpackSprite }; } RegisterItemWithJotunn(instance, itemPrefab); EnsureRecipe(instance); return; } GameObject itemPrefab2 = instance.GetItemPrefab("TrophyWolf"); if ((Object)itemPrefab2 == (Object)null) { _registeredObjectDb = null; return; } _itemPrefab = Object.Instantiate<GameObject>(itemPrefab2); ((Object)_itemPrefab).name = "TamedCreatureXP_CreatureBackpack"; _itemPrefab.SetActive(false); ItemDrop component2 = _itemPrefab.GetComponent<ItemDrop>(); if ((Object)component2 == (Object)null || component2.m_itemData == null || component2.m_itemData.m_shared == null) { Object.Destroy((Object)_itemPrefab); _itemPrefab = null; _registeredObjectDb = null; throw new InvalidOperationException("TrophyWolf template has no usable ItemDrop component."); } component2.m_itemData.m_dropPrefab = _itemPrefab; SharedData shared = component2.m_itemData.m_shared; shared.m_name = "Sac à dos de créature"; shared.m_description = "Un sac robuste renforcé d’os, lié à un feu follet violet. À équiper sur une créature apprivoisée de niveau 4 ou plus. Le sac est consommé et reste lié à cette créature. Vise-la et appuie sur la touche configurée pour ouvrir ses 15 emplacements. Appuie sur E pour le fermer."; shared.m_itemType = (ItemType)19; shared.m_maxStackSize = 1; shared.m_weight = 1f; shared.m_teleportable = true; shared.m_useDurability = false; _backpackSprite = CreateBackpackSprite(instance); shared.m_icons = (Sprite[])(object)new Sprite[1] { _backpackSprite }; RegisterLocalization(); RegisterItemWithJotunn(instance, _itemPrefab); EnsureRecipe(instance); Plugin.ModLog.LogInfo((object)(((Object)_recipe == (Object)null) ? "Registered creature backpack item; recipe is waiting for its crafting station and materials." : "Registered universal creature backpack item and Black Forge recipe.")); } internal static void RegisterLocalization() { try { Type type = AccessTools.TypeByName("Jotunn.Managers.LocalizationManager"); object obj = ((type == null) ? null : AccessTools.Property(type, "Instance")?.GetValue(null, null)); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "GetLocalization", Type.EmptyTypes, (Type[])null)); object obj2 = ((obj == null || methodInfo == null) ? null : methodInfo.Invoke(obj, null)); if (obj2 == null) { return; } MethodInfo methodInfo2 = null; MethodInfo[] methods = obj2.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo3 in methods) { if (methodInfo3.Name == "AddTranslation") { ParameterInfo[] parameters = methodInfo3.GetParameters(); if (parameters.Length == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType.IsAssignableFrom(typeof(Dictionary<string, string>))) { methodInfo2 = methodInfo3; break; } } } if (!(methodInfo2 == null)) { methodInfo2.Invoke(obj2, new object[2] { "English", new Dictionary<string, string> { { "item_tamedcreaturexp_creaturebackpack", "Creature Backpack" }, { "item_tamedcreaturexp_creaturebackpack_desc", "Equip on a level 4 or higher tamed creature. Press the configured key while targeting it to open its 15-slot backpack." } } }); methodInfo2.Invoke(obj2, new object[2] { "French", new Dictionary<string, string> { { "item_tamedcreaturexp_creaturebackpack", "Sac à dos de créature" }, { "item_tamedcreaturexp_creaturebackpack_desc", "Un sac robuste renforcé d’os, lié à un feu follet violet. À équiper sur une créature apprivoisée de niveau 4 ou plus. Le sac est consommé et reste lié à cette créature. Vise-la et appuie sur la touche configurée pour ouvrir ses 15 emplacements. Appuie sur E pour le fermer." } } }); } } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not register backpack translations through Jotunn: " + ex.Message)); } } private static bool IsStringParameter(ParameterInfo parameter) { if (!(parameter.ParameterType == typeof(string))) { if (parameter.ParameterType.IsByRef) { return parameter.ParameterType.GetElementType() == typeof(string); } return false; } return true; } private static void RegisterItemWithJotunn(ObjectDB database, GameObject prefab) { //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown Type type = AccessTools.TypeByName("Jotunn.Managers.ItemManager"); object obj = ((type == null) ? null : AccessTools.Property(type, "Instance")?.GetValue(null, null)); if (obj == null) { if (!_warnedJotunn) { _warnedJotunn = true; Plugin.ModLog.LogWarning((object)"Jotunn ItemManager is unavailable; the creature backpack is disabled because it cannot be registered safely."); } return; } try { if (_jotunnCustomItem == null) { Type type2 = AccessTools.TypeByName("Jotunn.Entities.CustomItem"); ConstructorInfo constructorInfo = ((type2 == null) ? null : type2.GetConstructor(new Type[2] { typeof(GameObject), typeof(bool) })); MethodInfo methodInfo = ((type2 == null) ? null : AccessTools.Method(type, "AddItem", new Type[1] { type2 }, (Type[])null)); if (constructorInfo != null && methodInfo != null) { _jotunnCustomItem = constructorInfo.Invoke(new object[2] { prefab, false }); _jotunnItemAdded = Convert.ToBoolean(methodInfo.Invoke(obj, new object[1] { _jotunnCustomItem })); } } if (_jotunnCustomItem == null || !_jotunnItemAdded) { if (!_warnedJotunn) { _warnedJotunn = true; Plugin.ModLog.LogWarning((object)"Jotunn did not accept the creature backpack item; it will not be inserted into Valheim's prefab lists directly."); } } else if ((Object)database != (Object)null) { MethodInfo methodInfo2 = AccessTools.Method(type, "RegisterItemInObjectDB", new Type[1] { typeof(GameObject) }, (Type[])null); if (methodInfo2 == null) { throw new MissingMethodException(type.FullName, "RegisterItemInObjectDB(GameObject)"); } methodInfo2.Invoke(obj, new object[1] { prefab }); } } catch (Exception ex) { if (!_warnedJotunn) { _warnedJotunn = true; Plugin.ModLog.LogWarning((object)("Could not register the creature backpack through Jotunn: " + ex)); } } } private static void EnsureRecipe(ObjectDB database) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Expected O, but got Unknown //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Expected O, but got Unknown //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Expected O, but got Unknown //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Expected O, but got Unknown //IL_03e2: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Expected O, but got Unknown if ((Object)_recipe != (Object)null || (Object)database == (Object)null || (Object)_itemPrefab == (Object)null || !(AccessTools.Field(typeof(ObjectDB), "m_recipes")?.GetValue(database) is IList list)) { return; } foreach (object item in list) { Recipe val = (Recipe)((item is Recipe) ? item : null); if ((Object)val != (Object)null && (Object)val.m_item != (Object)null && (Object)((Component)val.m_item).gameObject != (Object)null && ((Object)((Component)val.m_item).gameObject).name == "TamedCreatureXP_CreatureBackpack") { _recipe = val; return; } } ZNetScene instance = ZNetScene.instance; GameObject val2 = (((Object)instance == (Object)null) ? null : instance.GetPrefab("blackforge")); CraftingStation val3 = (((Object)val2 == (Object)null) ? null : val2.GetComponent<CraftingStation>()); ItemDrop component = _itemPrefab.GetComponent<ItemDrop>(); if ((Object)val3 == (Object)null || (Object)component == (Object)null) { Plugin.ModLog.LogDebug((object)"Black Forge or backpack item is not registered yet; will retry."); return; } Requirement[] array = (Requirement[])(object)new Requirement[3]; string[] array2 = new string[3] { "BlackMetal", "LinenThread", "FineWood" }; int[] array3 = new int[3] { 4, 4, 4 }; for (int i = 0; i < array.Length; i++) { GameObject itemPrefab = database.GetItemPrefab(array2[i]); ItemDrop val4 = (((Object)itemPrefab == (Object)null) ? null : itemPrefab.GetComponent<ItemDrop>()); if ((Object)val4 == (Object)null) { Plugin.ModLog.LogWarning((object)("Black Forge backpack recipe ingredient is missing: " + array2[i])); return; } array[i] = new Requirement { m_resItem = val4, m_amount = array3[i], m_amountPerLevel = 0 }; } Recipe val5 = ScriptableObject.CreateInstance<Recipe>(); ((Object)val5).name = "Recipe_TamedCreatureXP_CreatureBackpack"; val5.m_item = component; val5.m_amount = 1; val5.m_enabled = false; val5.m_craftingStation = val3; val5.m_resources = array; Type type = AccessTools.TypeByName("Jotunn.Managers.ItemManager"); object obj = ((type == null) ? null : AccessTools.Property(type, "Instance")?.GetValue(null, null)); Type type2 = AccessTools.TypeByName("Jotunn.Entities.CustomRecipe"); ConstructorInfo constructorInfo = ((type2 == null) ? null : type2.GetConstructor(new Type[3] { typeof(Recipe), typeof(bool), typeof(bool) })); MethodInfo methodInfo = ((type == null || type2 == null) ? null : AccessTools.Method(type, "AddRecipe", new Type[1] { type2 }, (Type[])null)); if (obj == null || constructorInfo == null || methodInfo == null) { Plugin.ModLog.LogWarning((object)"Jotunn recipe registration is unavailable; the creature backpack recipe was not added."); return; } _jotunnCustomRecipe = constructorInfo.Invoke(new object[3] { val5, false, false }); bool flag = Convert.ToBoolean(methodInfo.Invoke(obj, new object[1] { _jotunnCustomRecipe })); if (!list.Contains(val5)) { list.Add(val5); } _recipe = val5; try { MethodInfo methodInfo2 = AccessTools.Method(typeof(Player), "UpdateKnownRecipesList", (Type[])null, (Type[])null); if ((Object)Player.m_localPlayer != (Object)null && methodInfo2 != null) { methodInfo2.Invoke(Player.m_localPlayer, null); } } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not refresh the local player's recipe list for the creature backpack: " + ex.Message)); } Plugin.ModLog.LogInfo((object)(flag ? "Registered creature backpack recipe at Black Forge (4 Black Metal, 4 Linen Thread, 4 Fine Wood)." : "Creature backpack recipe was already registered with Jotunn.")); } internal static bool UseBackpackItem(Humanoid user, Inventory inventory, ItemData item) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown if (!IsBackpackItem(item)) { return true; } Player val = (Player)((user is Player) ? user : null); Character val2 = (((Object)val == (Object)null) ? null : val.GetHoverCreature()); if (!Plugin.IsAllowedTamedCreature(val2) || val2.GetLevel() < 4) { Plugin.ShowMessage(Plugin.IsFrench ? "Cible une créature apprivoisée de niveau 4 ou plus pour lui donner le sac." : "Target a level 4 or higher tamed creature to give it the backpack.", levelUp: false); return false; } ZNetView nView = Plugin.GetNView(val2); ZDO val3 = (((Object)nView != (Object)null && nView.IsValid()) ? nView.GetZDO() : null); if (val3 == null || !ClaimOwnership(nView)) { Plugin.ShowMessage(Plugin.IsFrench ? "Impossible d'accéder aux données de cette créature." : "Could not access this creature's data.", levelUp: false); return false; } if (val3.GetBool("TamedCreatureXP.HasBackpack", false)) { Plugin.ShowMessage(Plugin.IsFrench ? "Cette créature a déjà un sac." : "This creature already has a backpack.", levelUp: false); return false; } val3.Set("TamedCreatureXP.HasBackpack", true); EnsureBackpackVisual(val2); if (inventory != null && item != null) { inventory.RemoveItem(item, 1); } Plugin.ShowMessage(Plugin.IsFrench ? "Sac de bât équipé. Utilise la touche configurée en ciblant la créature pour l'ouvrir." : "Backpack equipped. Use the configured key while targeting the creature to open it.", levelUp: false); Plugin.ModLog.LogInfo((object)("Backpack equipped on " + ((Object)((Component)val2).gameObject).name + ".")); return false; } private static bool IsBackpackItem(ItemData item) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown if (item == null || item.m_shared == null) { return false; } if (!string.Equals(item.m_shared.m_name, "$item_tamedcreaturexp_creaturebackpack", StringComparison.Ordinal)) { if ((Object)item.m_dropPrefab != (Object)null) { return ((Object)item.m_dropPrefab).name == "TamedCreatureXP_CreatureBackpack"; } return false; } return true; } internal static void TryOpenTargetedCreature() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Expected O, but got Unknown //IL_00fe: 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_010e: Expected O, but got Unknown //IL_010e: Expected O, but got Unknown //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Expected O, but got Unknown //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Expected O, but got Unknown //IL_026a: Expected O, but got Unknown //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown //IL_016e: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)InventoryGui.instance == (Object)null) { return; } Character hoverCreature = localPlayer.GetHoverCreature(); if ((Object)hoverCreature == (Object)null) { Plugin.ShowMessage(Plugin.IsFrench ? "Vise le compagnon portant le sac, puis appuie sur la touche configurée." : "Aim at the creature wearing the backpack, then press the configured key.", levelUp: false); } else { if (!Plugin.IsAllowedTamedCreature(hoverCreature)) { return; } if (hoverCreature.GetLevel() < 4) { Plugin.ShowMessage(Plugin.IsFrench ? "Le sac est disponible à partir du niveau 4." : "The backpack unlocks at level 4.", levelUp: false); return; } ZNetView nView = Plugin.GetNView(hoverCreature); ZDO val = (((Object)nView != (Object)null && nView.IsValid()) ? nView.GetZDO() : null); if (val == null || !val.GetBool("TamedCreatureXP.HasBackpack", false)) { Plugin.ShowMessage(Plugin.IsFrench ? "Cette créature n'a pas de sac de bât." : "This creature has no backpack.", levelUp: false); return; } if (ClaimOwnership(nView)) { try { SaveIfOpen(); if ((Object)_openCreature != (Object)null && (Object)_openCreature != (Object)hoverCreature && (Object)_virtualContainer != (Object)null) { object obj = AccessTools.Field(typeof(InventoryGui), "m_currentContainer")?.GetValue(InventoryGui.instance); if ((Object)((obj is Container) ? obj : null) == (Object)_virtualContainer) { AccessTools.Method(typeof(InventoryGui), "CloseContainer", (Type[])null, (Type[])null)?.Invoke(InventoryGui.instance, null); } } EnsureVirtualContainer(); _virtualInventory = new Inventory(Plugin.IsFrench ? "Sac de bât" : "Creature Backpack", _backpackSprite, 5, 3); SetField(_virtualContainer, "m_inventory", _virtualInventory); ((Component)_virtualContainer).transform.position = ((Component)localPlayer).transform.position; _openCreature = hoverCreature; _openZdo = val; LoadFromZdo(val); InventoryGui.instance.Show(_virtualContainer, 0); _nextPeriodicSave = Time.unscaledTime + 0.75f; object obj2 = AccessTools.Field(typeof(InventoryGui), "m_currentContainer")?.GetValue(InventoryGui.instance); if ((Object)((obj2 is Container) ? obj2 : null) == (Object)_virtualContainer) { Plugin.ModLog.LogInfo((object)("Opened the backpack inventory for " + Plugin.SafeName(hoverCreature) + ".")); } else { Plugin.ModLog.LogWarning((object)"Valheim's inventory window did not select the virtual creature backpack after Show()."); Plugin.ShowMessage(Plugin.IsFrench ? "Le sac ne s'est pas affiché. Ferme l'inventaire, vise le compagnon et réessaie." : "The backpack did not appear. Close the inventory, target the creature and try again.", levelUp: false); } return; } catch (Exception ex) { _openCreature = null; _openZdo = null; Plugin.ModLog.LogError((object)("Could not open creature backpack: " + ex)); Plugin.ShowMessage(Plugin.IsFrench ? "Erreur lors de l'ouverture du sac." : "Could not open the backpack.", levelUp: false); return; } } Plugin.ShowMessage(Plugin.IsFrench ? "Impossible d'ouvrir le sac pour le moment." : "Could not open the backpack right now.", levelUp: false); } } private static bool ClaimOwnership(ZNetView nview) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown if ((Object)nview == (Object)null || !nview.IsValid()) { return false; } if (!nview.IsOwner()) { try { nview.ClaimOwnership(); } catch (Exception ex) { Plugin.ModLog.LogDebug((object)("Could not claim backpack owner: " + ex.Message)); } } return nview.IsOwner(); } private static void EnsureVirtualContainer() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //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_002c: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown if (!((Object)_virtualContainer != (Object)null) || _virtualInventory == null) { GameObject val = new GameObject("TamedCreatureXP_VirtualCreatureBackpack"); Object.DontDestroyOnLoad((Object)val); _virtualContainer = val.AddComponent<Container>(); _virtualInventory = new Inventory("Creature Backpack", _backpackSprite, 5, 3); SetField(_virtualContainer, "m_name", Plugin.IsFrench ? "Sac de bât" : "Creature Backpack"); SetField(_virtualContainer, "m_width", 5); SetField(_virtualContainer, "m_height", 3); SetField(_virtualContainer, "m_inventory", _virtualInventory); ((Behaviour)_virtualContainer).enabled = false; } } private static void LoadFromZdo(ZDO zdo) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown if (zdo == null || _virtualInventory == null) { return; } byte[] byteArray = zdo.GetByteArray("TamedCreatureXP.BackpackContents", (byte[])null); if (byteArray == null || byteArray.Length == 0) { return; } try { ZPackage val = new ZPackage(byteArray); _virtualInventory.Load(val); } catch (Exception ex) { Plugin.ModLog.LogWarning((object)("Could not load creature backpack contents; the stored data was left untouched: " + ex.Message)); } } internal static void SaveIfOpen() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown //IL_006a: 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_007e: Expected O, but got Unknown //IL_007e: Expected O, but got Unknown if (_saving || (Object)_virtualContainer == (Object)null || _virtualInventory == null || _openZdo == null) { return; } InventoryGui instance = InventoryGui.instance; if ((Object)instance != (Object)null) { object obj = AccessTools.Field(typeof(InventoryGui), "m_currentContainer")?.GetValue(instance); if ((Object)((obj is Container) ? obj : null) != (Object)_virtualContainer) { return; } } try { _saving = true; ZPackage val = new ZPackage(); _virtualInventory.Save(val); _openZdo.Set("TamedCreatureXP.BackpackContents", val.GetArray()); } catch (Exception ex) { if (!_warnedSave) { _warnedSave = true; Plugin.ModLog.LogWarning((object)("Could not save creature backpack contents: " + ex.Message)); } } finally { _saving = false; } } private static void OnGuiClosed() { if (_closingVirtualContainer) { _closingVirtualContainer = false; _openCreature = null; _openZdo = null; } } private static void OnGuiClosing() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown //IL_0070: Expected O, but got Unknown _closingVirtualContainer = false; if (!((Object)_virtualContainer == (Object)null) && !((Object)InventoryGui.instance == (Object)null)) { object obj = AccessTools.Field(typeof(InventoryGui), "m_currentContainer")?.GetValue(InventoryGui.instance); if (!((Object)((obj is Container) ? obj : null) != (Object)_virtualContainer)) { SaveIfOpen(); _closingVirtualContainer = true; } } } private static bool IsVirtual(Container container) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_000f: 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_0023: Expected O, but got Unknown //IL_0023: Expected O, but got Unknown if ((Object)container != (Object)null) { return (Object)container == (Object)_virtualContainer; } return false; } internal static bool IsVirtualContainerName(string name) { return string.Equals(name, "TamedCreatureXP_VirtualCreatureBackpack", StringComparison.Ordinal); } internal static bool VirtualContainerAwakePrefix(Container instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown return !IsVirtualContainerName(((Object)instance != (Object)null && (Object)((Component)instance).gameObject != (Object)null) ? ((Object)((Component)instance).gameObject).name : string.Empty); } internal static bool GetInventoryPrefix(Container __instance, ref Inventory __result) { if (!IsVirtual(__instance)) { return true; } __result = _virtualInventory; return false; } internal static bool ContainerLoadPrefix(Container __instance, ref bool __result) { if (!IsVirtual(__instance)) { return true; } __result = true; return false; } internal static bool ContainerSavePrefix(Container __instance) { if (!IsVirtual(__instance)) { return true; } SaveIfOpen(); return false; } internal static bool SetInUsePrefix(Container __instance, bool inUse) { if (!IsVirtual(__instance)) { return true; } SetField(__instance, "m_inUse", inUse); if (!inUse) { SaveIfOpen(); } return false; } internal static void FollowPlayerWhileOpen(InventoryGui gui, Player player) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0063: Expected O, but got Unknown //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) if ((Object)_virtualContainer == (Object)null || (Object)gui == (Object)null) { return; } object obj = AccessTools.Field(typeof(InventoryGui), "m_currentContainer")?.GetValue(gui); if (!((Object)((obj is Container) ? obj : null) != (Object)_virtualContainer)) { Player val = (((Object)player != (Object)null) ? player : Player.m_localPlayer); if ((Object)val != (Object)null) { ((Component)_virtualContainer).transform.position = ((Component)val).transform.position; } } } private static void SetField(object instance, string name, object value) { FieldInfo fieldInfo = AccessTools.Field(instance.GetType(), name); if (fieldInfo != null) { fieldInfo.SetValue(instance, value); } } private static void SetProperty(object instance, string name, object value) { if (instance != null) { PropertyInfo propertyInfo = AccessTools.Property(instance.GetType(), name); if (propertyInfo != null && propertyInfo.CanWrite) { propertyInfo.SetValue(instance, value, null); } } } internal static void UpdateBackpackInventoryStyle(InventoryGui gui) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_00b3: Expected O, but got Unknown //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Expected O, but got Unknown //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Expected O, but got Unknown if ((Object)gui == (Object)null) { return; } object obj = AccessTools.Field(typeof(InventoryGui), "m_currentContainer")?.GetValue(gui); Container val = (Container)((obj is Container) ? obj : null); object obj2 = AccessTools.Field(typeof(InventoryGui), "m_container")?.GetValue(gui); RectTransform val2 = (RectTransform)((obj2 is RectTransform) ? obj2 : null); if ((Object)val2 == (Object)null) { return; } Transform val3 = EnsureBackpackPanelFrame(val2); if ((Object)val3 == (Object)null) { return; } bool flag = (Object)val == (Object)_virtualContainer; if (((Component)val3).gameObject.activeSelf != flag) { ((Component)val3).gameObject.SetActive(flag); } object obj3 = AccessTools.Field(typeof(InventoryGui), "m_containerName")?.GetValue(gui); Component val4 = (Component)((obj3 is Component) ? obj3 : null); if (!flag) { RestoreBackpackPanelTitle(val4); } if (!flag) { return; } val3.SetAsLastSibling(); PropertyInfo propertyInfo = (((Object)val4 == (Object)null) ? null : AccessTools.Property(((object)val4).GetType(), "text")); if (!(propertyInfo == null) && propertyInfo.CanWrite) { string text = (Plugin.IsFrench ? "SAC À DOS DE CRÉATURE" : "CREATURE BACKPACK"); propertyInfo.SetValue(val4, "<color=#B87BEE>★</color> <color=#F3D7FF>" + text + "</color> <color=#B87BEE>★</color>", null); } PropertyInfo propertyInfo2 = (((Object)val4 == (Object)null) ? null : AccessTools.Property(((object)val4).GetType(), "fontSize")); if (!(propertyInfo2 == null) && propertyInfo2.CanRead && propertyInfo2.CanWrite) { if (_styledTitleInstanceId != ((Object)val4).GetInstanceID()) { _styledTitleInstanceId = ((Object)val4).GetInstanceID(); _styledTitleOriginalFontSize = Convert.ToSingle(propertyInfo2.GetValue(val4, null)); } propertyInfo2.SetValue(val4, _styledTitleOriginalFontSize * 0.78f, null); } } private static void RestoreBackpackPanelTitle(Component title) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown if (!((Object)title == (Object)null) && _styledTitleInstanceId == ((Object)title).GetInstanceID()) { PropertyInfo propertyInfo = AccessTools.Property(((object)title).GetType(), "fontSize"); if (propertyInfo != null && propertyInfo.CanWrite && _styledTitleOriginalFontSize > 0f) { propertyInfo.SetValue(title, _styledTitleOriginalFontSize, null); } _styledTitleInstanceId = 0; _styledTitleOriginalFontSize = 0f; } } private static Transform EnsureBackpackPanelFrame(RectTransform panel) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_002c: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: 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_014a: Unknown result type (might be due to invalid IL or missing references) if ((Object)_panelFrame != (Object)null && (Object)_panelFrame.parent == (Object)panel) { return _panelFrame; } _panelFrame = FindChild((Transform)panel, "TamedCreatureXP_CreatureBackpackPanelFrame"); if ((Object)_panelFrame != (Object)null) { return _panelFrame; } Type type = AccessTools.TypeByName("UnityEngine.UI.Image"); if (type == null) { if (!_warnedPanelStyle) { _warnedPanelStyle = true; Plugin.ModLog.LogWarning((object)"Could not style the backpack panel because Unity UI Image is unavailable."); } return null; } Sprite backpackPanelFrameSprite = GetBackpackPanelFrameSprite(); if ((Object)backpackPanelFrameSprite == (Object)null) { return null; } GameObject val = new GameObject("TamedCreatureXP_CreatureBackpackPanelFrame", new Type[1] { typeof(RectTransform) }); RectTransform component = val.GetComponent<RectTransform>(); ((Transform)component).SetParent((Transform)panel, false); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = Vector2.zero; component.offsetMax = Vector2.zero; Component instance = val.AddComponent(type); SetProperty(instance, "sprite", backpackPanelFrameSprite); PropertyInfo propertyInfo = AccessTools.Property(type, "type"); if (propertyInfo != null) { SetProperty(instance, "type", Enum.ToObject(propertyInfo.PropertyType, 1)); } SetProperty(instance, "color", Color.white); SetProperty(instance, "raycastTarget", false); _panelFrame = val.transform; ((Component)_panelFrame).gameObject.SetActive(false); return _panelFrame; } private static Sprite GetBackpackPanelFrameSprite() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_001c: 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) //IL_0061: Unknow