Please disclose if your mod was created primarily 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 BackpackChest v0.3.13
BepInEx/plugins/BackpackChest/BackpackChest.dll
Decompiled a month 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.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("BackpackChest")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("BackpackChest")] [assembly: AssemblyTitle("BackpackChest")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BackpackChest { [BepInPlugin("com.yourname.backpackchest", "BackpackChest", "0.3.12")] public class BackpackChestPlugin : BaseUnityPlugin { private struct ZdoUid { public long userID; public long id; } [CompilerGenerated] private sealed class <DelayedInitialSync>d__76 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public Player player; public BackpackChestPlugin <>4__this; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <DelayedInitialSync>d__76(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(0.6f); <>1__state = 1; return true; case 1: <>1__state = -1; if (!Object.op_Implicit((Object)(object)player)) { return false; } if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && (Object)(object)player == (Object)(object)Player.m_localPlayer) { SyncPlayerCarryState(player); } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class <EnumerateAllZdos>d__70 : IEnumerable<ZDO>, IEnumerable, IEnumerator<ZDO>, IDisposable, IEnumerator { private int <>1__state; private ZDO <>2__current; private int <>l__initialThreadId; private FieldInfo <fiById>5__1; private FieldInfo <fiBySector>5__2; private IDictionary <dict>5__3; private IEnumerator <>s__4; private object <v>5__5; private ZDO <z>5__6; private IDictionary <dict2>5__7; private IEnumerator <>s__8; private object <v>5__9; private IEnumerable <en>5__10; private IEnumerator <>s__11; private object <it>5__12; private ZDO <z>5__13; ZDO IEnumerator<ZDO>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <EnumerateAllZdos>d__70(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; switch (num) { case -3: case 1: try { } finally { <>m__Finally1(); } break; case -5: case -4: case 2: try { if (num == -5 || num == 2) { try { } finally { <>m__Finally3(); } } } finally { <>m__Finally2(); } break; } <fiById>5__1 = null; <fiBySector>5__2 = null; <dict>5__3 = null; <>s__4 = null; <v>5__5 = null; <z>5__6 = null; <dict2>5__7 = null; <>s__8 = null; <v>5__9 = null; <en>5__10 = null; <>s__11 = null; <it>5__12 = null; <z>5__13 = null; <>1__state = -2; } private bool MoveNext() { try { switch (<>1__state) { default: return false; case 0: { <>1__state = -1; if (ZDOMan.instance == null) { return false; } <fiById>5__1 = AccessTools.Field(typeof(ZDOMan), "m_objectsByID"); object value; if (<fiById>5__1 != null) { value = <fiById>5__1.GetValue(ZDOMan.instance); <dict>5__3 = value as IDictionary; if (<dict>5__3 != null) { <>s__4 = <dict>5__3.Values.GetEnumerator(); <>1__state = -3; goto IL_012b; } <dict>5__3 = null; } <fiBySector>5__2 = AccessTools.Field(typeof(ZDOMan), "m_objectsBySector"); if (!(<fiBySector>5__2 != null)) { break; } value = <fiBySector>5__2.GetValue(ZDOMan.instance); <dict2>5__7 = value as IDictionary; if (<dict2>5__7 != null) { <>s__8 = <dict2>5__7.Values.GetEnumerator(); <>1__state = -4; goto IL_02b6; } <dict2>5__7 = null; break; } case 1: <>1__state = -3; goto IL_011d; case 2: { <>1__state = -5; goto IL_027d; } IL_02a7: <en>5__10 = null; <v>5__9 = null; goto IL_02b6; IL_011d: <z>5__6 = null; <v>5__5 = null; goto IL_012b; IL_02b6: if (<>s__8.MoveNext()) { <v>5__9 = <>s__8.Current; <en>5__10 = <v>5__9 as IEnumerable; if (<en>5__10 != null) { <>s__11 = <en>5__10.GetEnumerator(); <>1__state = -5; goto IL_028b; } goto IL_02a7; } <>m__Finally2(); <>s__8 = null; return false; IL_012b: if (<>s__4.MoveNext()) { <v>5__5 = <>s__4.Current; ref ZDO reference = ref <z>5__6; object obj = <v>5__5; reference = (ZDO)((obj is ZDO) ? obj : null); if (<z>5__6 != null) { <>2__current = <z>5__6; <>1__state = 1; return true; } goto IL_011d; } <>m__Finally1(); <>s__4 = null; return false; IL_027d: <z>5__13 = null; <it>5__12 = null; goto IL_028b; IL_028b: if (<>s__11.MoveNext()) { <it>5__12 = <>s__11.Current; ref ZDO reference2 = ref <z>5__13; object obj2 = <it>5__12; reference2 = (ZDO)((obj2 is ZDO) ? obj2 : null); if (<z>5__13 != null) { <>2__current = <z>5__13; <>1__state = 2; return true; } goto IL_027d; } <>m__Finally3(); <>s__11 = null; goto IL_02a7; } return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>s__4 is IDisposable disposable) { disposable.Dispose(); } } private void <>m__Finally2() { <>1__state = -1; if (<>s__8 is IDisposable disposable) { disposable.Dispose(); } } private void <>m__Finally3() { <>1__state = -4; if (<>s__11 is IDisposable disposable) { disposable.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<ZDO> IEnumerable<ZDO>.GetEnumerator() { if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; return this; } return new <EnumerateAllZdos>d__70(0); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<ZDO>)this).GetEnumerator(); } } public const string ModGuid = "com.yourname.backpackchest"; public const string ModName = "BackpackChest"; public const string ModVersion = "0.3.12"; internal static BackpackChestPlugin Instance = null; internal static Harmony Harmony = null; internal static ManualLogSource Log = null; internal static Sprite? CustomIconSprite; internal const string ZdoKeyCarried = "bc_carried"; internal const string ZdoKeyCarrier = "bc_carrier"; internal const string ZdoKeyNonTeleportable = "bc_nontele"; internal const string PlayerKeyHasChest = "bc_haschest"; internal const string PlayerKeyNonTele = "bc_nontele"; internal const string PlayerKeyChestZdoUser = "bc_chest_user"; internal const string PlayerKeyChestZdoId = "bc_chest_id"; internal const string SEName = "SE_BackpackChest"; internal ConfigEntry<KeyCode> EquipKey = null; internal ConfigEntry<KeyCode> DropKey = null; internal ConfigEntry<float> InteractDistance = null; internal ConfigEntry<float> ServerSyncInterval = null; internal ConfigEntry<Vector3> NetworkBackOffset = null; internal ConfigEntry<Vector3> NetworkBackEuler = null; internal ConfigEntry<Vector3> VisualLocalOffset = null; internal ConfigEntry<Vector3> VisualLocalEuler = null; internal ConfigEntry<float> VisualScale = null; internal ConfigEntry<string> VisualBoneFallbackNames = null; internal ConfigEntry<bool> ShowStatus = null; internal ConfigEntry<float> DebuffCarryWeight = null; internal ConfigEntry<float> DebuffRunSlowPercent = null; internal ConfigEntry<string> StatusName = null; internal ConfigEntry<string> StatusTooltip = null; private float _syncTimer; private static bool _rpcsRegistered; private static readonly FieldInfo? FI_Character_m_nview = AccessTools.Field(typeof(Character), "m_nview"); internal static readonly FieldInfo? FI_ZNetView_m_persistent = AccessTools.Field(typeof(ZNetView), "m_persistent"); private static readonly FieldInfo? FI_ZDO_m_uid = AccessTools.Field(typeof(ZDO), "m_uid"); private static readonly FieldInfo? FI_ZNetScene_m_instances = AccessTools.Field(typeof(ZNetScene), "m_instances"); private static readonly Type? T_ZDOID = AccessTools.TypeByName("ZDOID"); private static readonly FieldInfo? FI_ZDOID_userID = T_ZDOID?.GetField("userID"); private static readonly FieldInfo? FI_ZDOID_id = T_ZDOID?.GetField("id"); private static readonly MethodInfo? MI_ZDOMan_GetZDO = AccessTools.Method(typeof(ZDOMan), "GetZDO", new Type[1] { AccessTools.TypeByName("ZDOID") }, (Type[])null); private static readonly MethodInfo? MI_ZDO_SetPosition = AccessTools.Method(typeof(ZDO), "SetPosition", new Type[1] { typeof(Vector3) }, (Type[])null); private static readonly MethodInfo? MI_ZDO_SetRotation = AccessTools.Method(typeof(ZDO), "SetRotation", new Type[1] { typeof(Quaternion) }, (Type[])null); private static int SEHash => StableHash("SE_BackpackChest"); private static void EnsureRpcsRegistered() { if (_rpcsRegistered) { return; } ZRoutedRpc instance = ZRoutedRpc.instance; if (instance == null) { return; } instance.Register<long, long, long>("bc_request_drop_uid", (Action<long, long, long, long>)delegate(long sender, long user, long id, long playerId) { if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer()) { Player val2 = ((IEnumerable<Player>)Player.GetAllPlayers()).FirstOrDefault((Func<Player, bool>)((Player p) => Object.op_Implicit((Object)(object)p) && p.GetPlayerID() == playerId)); if (Object.op_Implicit((Object)(object)val2)) { DoDropServerByUid(user, id, val2); } } }); instance.Register<long>("bc_request_drop_self", (Action<long, long>)delegate(long sender, long playerId) { if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer()) { Player val = ((IEnumerable<Player>)Player.GetAllPlayers()).FirstOrDefault((Func<Player, bool>)((Player p) => Object.op_Implicit((Object)(object)p) && p.GetPlayerID() == playerId)); if (Object.op_Implicit((Object)(object)val)) { DoDropServerByCarrier(val); } } }); _rpcsRegistered = true; ManualLogSource log = Log; if (log != null) { log.LogInfo((object)"[BackpackChest] Routed RPCs registered"); } } internal static bool GetPersistent(ZNetView v) { try { if (FI_ZNetView_m_persistent == null || (Object)(object)v == (Object)null) { return false; } return (bool)FI_ZNetView_m_persistent.GetValue(v); } catch { return false; } } internal static void SetPersistent(ZNetView v, bool value) { try { if (!(FI_ZNetView_m_persistent == null) && !((Object)(object)v == (Object)null)) { FI_ZNetView_m_persistent.SetValue(v, value); } } catch { } } internal static int StableHash(string s) { int num = 0; for (int i = 0; i < s.Length; i++) { num = num * 31 + s[i]; } return num; } internal static ZNetView? GetCharacterNView(Character c) { if (!Object.op_Implicit((Object)(object)c)) { return null; } if (FI_Character_m_nview == null) { return null; } object? value = FI_Character_m_nview.GetValue(c); return (ZNetView?)((value is ZNetView) ? value : null); } internal static ZDO? GetCharacterZDO(Character c) { ZNetView characterNView = GetCharacterNView(c); return ((Object)(object)characterNView != (Object)null && characterNView.IsValid()) ? characterNView.GetZDO() : null; } private static ZdoUid GetZdoUid(ZDO zdo) { try { object obj = FI_ZDO_m_uid?.GetValue(zdo); if (obj == null) { return default(ZdoUid); } Type type = obj.GetType(); FieldInfo field = type.GetField("userID"); FieldInfo field2 = type.GetField("id"); long userID = 0L; long id = 0L; if (field != null) { userID = Convert.ToInt64(field.GetValue(obj)); } if (field2 != null) { id = Convert.ToInt64(field2.GetValue(obj)); } ZdoUid result = default(ZdoUid); result.userID = userID; result.id = id; return result; } catch { return default(ZdoUid); } } private static object? MakeZdoidBox(long user, long id) { try { if (T_ZDOID == null) { return null; } object obj = Activator.CreateInstance(T_ZDOID); if (obj == null) { return null; } FI_ZDOID_userID?.SetValue(obj, user); if (FI_ZDOID_id != null) { Type fieldType = FI_ZDOID_id.FieldType; object value = Convert.ChangeType(id, fieldType); FI_ZDOID_id.SetValue(obj, value); } return obj; } catch { return null; } } private static ZNetView? FindInstanceByZdoUid(long user, long id) { try { if (user == 0L || id == 0) { return null; } if ((Object)(object)ZNetScene.instance == (Object)null) { return null; } object obj = FI_ZNetScene_m_instances?.GetValue(ZNetScene.instance); if (obj is IDictionary dictionary) { object obj2 = MakeZdoidBox(user, id); if (obj2 == null) { return null; } object? obj3 = dictionary[obj2]; return (ZNetView?)((obj3 is ZNetView) ? obj3 : null); } } catch { } return null; } private static ZDO? GetZdoByUid(long user, long id) { try { if (ZDOMan.instance == null) { return null; } object obj = MakeZdoidBox(user, id); if (obj == null) { return null; } object? obj2 = MI_ZDOMan_GetZDO?.Invoke(ZDOMan.instance, new object[1] { obj }); return (ZDO?)((obj2 is ZDO) ? obj2 : null); } catch { return null; } } private static void TryWriteZdoTransformByUid(long user, long id, Vector3 pos, Quaternion rot) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) try { ZDO zdoByUid = GetZdoByUid(user, id); if (zdoByUid != null) { if (MI_ZDO_SetPosition != null) { MI_ZDO_SetPosition.Invoke(zdoByUid, new object[1] { pos }); } if (MI_ZDO_SetRotation != null) { MI_ZDO_SetRotation.Invoke(zdoByUid, new object[1] { rot }); } } } catch { } } internal static void TryWriteZdoTransform(ZNetView view, Vector3 pos, Quaternion rot) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) try { ZDO val = ((view != null) ? view.GetZDO() : null); if (val != null) { if (MI_ZDO_SetPosition != null) { MI_ZDO_SetPosition.Invoke(val, new object[1] { pos }); } if (MI_ZDO_SetRotation != null) { MI_ZDO_SetRotation.Invoke(val, new object[1] { rot }); } } } catch { } } private void Awake() { //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; CustomIconSprite = LoadSpriteNextToDll("backpackchest_icon.png"); EquipKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "EquipKey", (KeyCode)98, "Equip targeted Chest to your back."); DropKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "DropKey", (KeyCode)118, "Drop worn Chest."); InteractDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "InteractDistance", 4f, "Max distance from player body to chest to equip it."); ServerSyncInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Network", "SyncIntervalSeconds", 0.02f, "Server interval (seconds) to update carried chest NETWORK transform (what vanilla clients see)."); NetworkBackOffset = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Network", "BackOffset", new Vector3(0f, 0.1f, -0.45f), "Offset from carrier torso for NETWORK chest."); NetworkBackEuler = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Network", "BackEuler", new Vector3(0f, 180f, 0f), "Euler rotation for NETWORK chest."); VisualLocalOffset = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Visual", "BoneLocalOffset", new Vector3(0f, -0.25f, -0.38f), "Local offset for VISUAL clone relative to chosen bone."); VisualLocalEuler = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Visual", "BoneLocalEuler", new Vector3(0f, 180f, 0f), "Local euler rotation for VISUAL clone relative to chosen bone."); VisualScale = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "VisualScale", 1f, "Extra scale multiplier for VISUAL clone after bone scale compensation."); VisualBoneFallbackNames = ((BaseUnityPlugin)this).Config.Bind<string>("Visual", "FallbackBoneNames", "spine,spine2,Spine,Chest,UpperChest,hips,pelvis", "Bone name fragments (comma-separated) used if Animator bones unavailable."); ShowStatus = ((BaseUnityPlugin)this).Config.Bind<bool>("Debuffs", "ShowStatusEffect", true, "Show a status effect while carrying the chest."); DebuffCarryWeight = ((BaseUnityPlugin)this).Config.Bind<float>("Debuffs", "CarryWeightPenalty", 200f, "Max carry weight reduction while carrying chest."); DebuffRunSlowPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Debuffs", "RunSlowPercent", 0.2f, "Run speed penalty (0.20 = 20%) while carrying chest."); StatusName = ((BaseUnityPlugin)this).Config.Bind<string>("Debuffs", "StatusName", "Сундук на спине", "Status effect name."); StatusTooltip = ((BaseUnityPlugin)this).Config.Bind<string>("Debuffs", "StatusTooltip", "Тяжёлый сундук уменьшает переносимый вес и мешает быстро бегать.\nЕсли внутри есть запрещённые предметы — телепорт блокируется.", "Status tooltip text."); Harmony = new Harmony("com.yourname.backpackchest"); Harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"BackpackChest 0.3.12 loaded"); } private void Update() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) EnsureRpcsRegistered(); Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { return; } EnsureRpcsRegistered(); if (!IsUserTyping()) { if (Input.GetKeyDown(EquipKey.Value)) { TryEquipLookTarget(localPlayer); } if (Input.GetKeyDown(DropKey.Value)) { TryDrop(localPlayer); } } if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer()) { _syncTimer += Time.deltaTime; float num = Mathf.Max(0.005f, ServerSyncInterval.Value); if (!(_syncTimer < num)) { _syncTimer = 0f; SyncAllCarriedChests_Server(); } } } private static bool IsUserTyping() { try { Console instance = Console.instance; if ((Object)(object)instance != (Object)null) { MethodInfo method = ((object)instance).GetType().GetMethod("IsVisible", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null && method.ReturnType == typeof(bool)) { if ((bool)method.Invoke(instance, null)) { return true; } } else { FieldInfo field = ((object)instance).GetType().GetField("m_visible", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool) && (bool)field.GetValue(instance)) { return true; } } } Chat instance2 = Chat.instance; if ((Object)(object)instance2 != (Object)null) { object obj = null; FieldInfo fieldInfo = ((object)instance2).GetType().GetField("m_input", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? ((object)instance2).GetType().GetField("m_inputField", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? ((object)instance2).GetType().GetField("m_inputFieldGamepad", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (fieldInfo != null) { obj = fieldInfo.GetValue(instance2); } if (obj != null) { Type type = obj.GetType(); PropertyInfo property = type.GetProperty("isFocused", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.PropertyType == typeof(bool) && (bool)property.GetValue(obj)) { return true; } MethodInfo methodInfo = type.GetMethod("IsFocused", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? type.GetMethod("HasFocus", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (methodInfo != null && methodInfo.ReturnType == typeof(bool) && methodInfo.GetParameters().Length == 0 && (bool)methodInfo.Invoke(obj, null)) { return true; } FieldInfo fieldInfo2 = type.GetField("m_isFocused", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? type.GetField("isFocused", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (fieldInfo2 != null && fieldInfo2.FieldType == typeof(bool) && (bool)fieldInfo2.GetValue(obj)) { return true; } } FieldInfo field2 = ((object)instance2).GetType().GetField("m_chatWindow", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field2 != null) { object? value = field2.GetValue(instance2); GameObject val = (GameObject)((value is GameObject) ? value : null); if ((Object)(object)val != (Object)null && val.activeInHierarchy) { return true; } } } } catch { } return false; } private void TryEquipLookTarget(Player player) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)BackpackChestState.GetCarriedChestView(player) != (Object)null) { Message(player, "У тебя уже есть сундук на спине."); return; } if ((Object)(object)GameCamera.instance == (Object)null) { Message(player, "Камера не найдена."); return; } RaycastHit val = default(RaycastHit); if (!Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 30f, -1, (QueryTriggerInteraction)1)) { Message(player, "Не вижу сундук."); return; } ZNetView val2 = (Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider) ? ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<ZNetView>() : null); if (!Object.op_Implicit((Object)(object)val2) || !val2.IsValid()) { Message(player, "Это не сетевой объект."); return; } float effectiveInteractDistance = GetEffectiveInteractDistance(player); if ((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) { Message(player, "Не вижу коллайдер сундука."); return; } Vector3 bodyInteractOrigin = GetBodyInteractOrigin(player); Vector3 val3 = ((RaycastHit)(ref val)).collider.ClosestPoint(bodyInteractOrigin); float num = Vector3.Distance(bodyInteractOrigin, val3); if (num > effectiveInteractDistance) { Message(player, "Слишком далеко."); return; } string text = PrefabNameFromInstanceName(((Object)((Component)val2).gameObject).name); if (!string.Equals(text, "Chest", StringComparison.Ordinal)) { Message(player, "Это не Chest, а: " + text); return; } ZDO zDO = val2.GetZDO(); if (zDO == null) { Message(player, "ZDO недоступен."); return; } if (zDO.GetBool("bc_carried", false)) { Message(player, "Этот сундук уже у кого-то на спине."); return; } bool flag = ChestInventoryHasNonTeleportable(val2); val2.ClaimOwnership(); zDO.Set("bc_nontele", flag); zDO.Set("bc_carried", true); zDO.Set("bc_carrier", player.GetPlayerID()); ZDO characterZDO = GetCharacterZDO((Character)(object)player); if (characterZDO != null) { ZdoUid zdoUid = GetZdoUid(zDO); characterZDO.Set("bc_chest_user", zdoUid.userID); characterZDO.Set("bc_chest_id", zdoUid.id); } EnsureFollower(val2); SyncPlayerCarryState(player); Message(player, "Сундук экипирован на спину."); } private void TryDrop(Player player) { if (!Object.op_Implicit((Object)(object)player)) { return; } EnsureRpcsRegistered(); ZDO characterZDO = GetCharacterZDO((Character)(object)player); if (characterZDO == null) { Message(player, "ZDO игрока недоступен."); return; } bool @bool = characterZDO.GetBool("bc_haschest", false); long @long = characterZDO.GetLong("bc_chest_user", 0L); long long2 = characterZDO.GetLong("bc_chest_id", 0L); ZNetView carriedChestView = BackpackChestState.GetCarriedChestView(player); if (Object.op_Implicit((Object)(object)carriedChestView) && carriedChestView.IsValid()) { RemoveChestStatus(player); characterZDO.Set("bc_haschest", false); characterZDO.Set("bc_nontele", false); characterZDO.Set("bc_chest_user", 0); characterZDO.Set("bc_chest_id", 0); SyncPlayerCarryState(player); if (Object.op_Implicit((Object)(object)ZNet.instance) && !ZNet.instance.IsServer()) { carriedChestView.InvokeRPC("bc_request_drop", new object[1] { player.GetPlayerID() }); } else { DoDropServer(carriedChestView, player); } } else if (@bool && @long != 0L && long2 != 0) { RemoveChestStatus(player); characterZDO.Set("bc_haschest", false); characterZDO.Set("bc_nontele", false); characterZDO.Set("bc_chest_user", 0); characterZDO.Set("bc_chest_id", 0); SyncPlayerCarryState(player); if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "bc_request_drop_uid", new object[3] { @long, long2, player.GetPlayerID() }); } } else if (@bool) { RemoveChestStatus(player); characterZDO.Set("bc_haschest", false); characterZDO.Set("bc_nontele", false); characterZDO.Set("bc_chest_user", 0); characterZDO.Set("bc_chest_id", 0); SyncPlayerCarryState(player); if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "bc_request_drop_self", new object[1] { player.GetPlayerID() }); } } else { Message(player, "На спине нет сундука."); } } private void SyncAllCarriedChests_Server() { //IL_00c4: 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_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) List<Player> allPlayers = Player.GetAllPlayers(); if (allPlayers == null || allPlayers.Count == 0) { return; } foreach (Player item in allPlayers) { if (!Object.op_Implicit((Object)(object)item)) { continue; } ZDO characterZDO = GetCharacterZDO((Character)(object)item); if (characterZDO == null || !characterZDO.GetBool("bc_haschest", false)) { continue; } long @long = characterZDO.GetLong("bc_chest_user", 0L); long long2 = characterZDO.GetLong("bc_chest_id", 0L); if (@long == 0L || long2 == 0) { continue; } ComputeNetworkBackTransform(item, out var pos, out var rot); TryWriteZdoTransformByUid(@long, long2, pos, rot); ZNetView val = FindInstanceByZdoUid(@long, long2); if ((Object)(object)val == (Object)null || !val.IsValid()) { continue; } ZDO zDO = val.GetZDO(); if (zDO != null && zDO.GetBool("bc_carried", false) && zDO.GetLong("bc_carrier", 0L) == item.GetPlayerID()) { EnsureFollower(val); ((Component)val).transform.SetPositionAndRotation(pos, rot); TryWriteZdoTransform(val, pos, rot); if (!val.IsOwner()) { val.ClaimOwnership(); } } } } internal void ComputeNetworkBackTransform(Player carrier, out Vector3 pos, out Quaternion rot) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_0022: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) Quaternion rotation = ((Component)carrier).transform.rotation; Vector3 val = ((Component)carrier).transform.position + Vector3.up * 1f; pos = val + rotation * NetworkBackOffset.Value; rot = rotation * Quaternion.Euler(NetworkBackEuler.Value); } internal Transform? FindBackBone(Player carrier) { Animator componentInChildren = ((Component)carrier).GetComponentInChildren<Animator>(); if ((Object)(object)componentInChildren != (Object)null) { Transform boneTransform = componentInChildren.GetBoneTransform((HumanBodyBones)54); if ((Object)(object)boneTransform != (Object)null) { return boneTransform; } boneTransform = componentInChildren.GetBoneTransform((HumanBodyBones)8); if ((Object)(object)boneTransform != (Object)null) { return boneTransform; } boneTransform = componentInChildren.GetBoneTransform((HumanBodyBones)7); if ((Object)(object)boneTransform != (Object)null) { return boneTransform; } boneTransform = componentInChildren.GetBoneTransform((HumanBodyBones)0); if ((Object)(object)boneTransform != (Object)null) { return boneTransform; } } string[] array = (from s in (VisualBoneFallbackNames.Value ?? "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries) select s.Trim() into s where s.Length > 0 select s).ToArray(); if (array.Length == 0) { array = new string[4] { "spine", "chest", "hips", "pelvis" }; } Queue<Transform> queue = new Queue<Transform>(); queue.Enqueue(((Component)carrier).transform); while (queue.Count > 0) { Transform val = queue.Dequeue(); string[] array2 = array; foreach (string value in array2) { if (((Object)val).name.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) { return val; } } for (int j = 0; j < val.childCount; j++) { queue.Enqueue(val.GetChild(j)); } } return null; } private static Player? FindPlayerById(long playerId) { foreach (Player allPlayer in Player.GetAllPlayers()) { if (Object.op_Implicit((Object)(object)allPlayer) && allPlayer.GetPlayerID() == playerId) { return allPlayer; } } return null; } internal static void DoDropServer(ZNetView chestView, Player carrier) { //IL_00cf: 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_00e4: 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_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)chestView) || !chestView.IsValid()) { return; } ZDO zDO = chestView.GetZDO(); if (zDO == null || !zDO.GetBool("bc_carried", false)) { return; } long @long = zDO.GetLong("bc_carrier", 0L); if (@long == carrier.GetPlayerID()) { zDO.Set("bc_carried", false); ZDO characterZDO = GetCharacterZDO((Character)(object)carrier); if (characterZDO != null) { characterZDO.Set("bc_haschest", false); characterZDO.Set("bc_nontele", false); characterZDO.Set("bc_chest_user", 0); characterZDO.Set("bc_chest_id", 0); } Vector3 val = ((Component)carrier).transform.position - ((Component)carrier).transform.forward * 0.8f + Vector3.up * 0.2f; ((Component)chestView).transform.position = val; TryWriteZdoTransform(chestView, val, ((Component)chestView).transform.rotation); EnsureFollower(chestView); } } internal static void DoDropServerByUid(long user, long id, Player carrier) { //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)carrier) || user == 0L || id == 0) { return; } ZDO zdoByUid = GetZdoByUid(user, id); if (zdoByUid == null || !zdoByUid.GetBool("bc_carried", false) || zdoByUid.GetLong("bc_carrier", 0L) != carrier.GetPlayerID()) { return; } zdoByUid.Set("bc_carried", false); zdoByUid.Set("bc_carrier", 0L); ZDO characterZDO = GetCharacterZDO((Character)(object)carrier); if (characterZDO != null) { characterZDO.Set("bc_haschest", false); characterZDO.Set("bc_nontele", false); characterZDO.Set("bc_chest_user", 0); characterZDO.Set("bc_chest_id", 0); } Vector3 val = ((Component)carrier).transform.position - ((Component)carrier).transform.forward * 0.8f + Vector3.up * 0.2f; Quaternion rotation = ((Component)carrier).transform.rotation; TryWriteZdoTransformByUid(user, id, val, rotation); ZNetView val2 = FindInstanceByZdoUid(user, id); if ((Object)(object)val2 != (Object)null && val2.IsValid()) { ((Component)val2).transform.SetPositionAndRotation(val, rotation); TryWriteZdoTransform(val2, val, rotation); EnsureFollower(val2); if (!val2.IsOwner()) { val2.ClaimOwnership(); } } } internal static void DoDropServerByCarrier(Player carrier) { //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)carrier)) { return; } ZDO val = FindCarriedChestZdo(carrier.GetPlayerID()); if (val == null) { return; } ZdoUid zdoUid = GetZdoUid(val); if (zdoUid.userID != 0L && zdoUid.id != 0) { DoDropServerByUid(zdoUid.userID, zdoUid.id, carrier); } else { if (!val.GetBool("bc_carried", false) || val.GetLong("bc_carrier", 0L) != carrier.GetPlayerID()) { return; } val.Set("bc_carried", false); val.Set("bc_carrier", 0L); ZDO characterZDO = GetCharacterZDO((Character)(object)carrier); if (characterZDO != null) { characterZDO.Set("bc_haschest", false); characterZDO.Set("bc_nontele", false); characterZDO.Set("bc_chest_user", 0); characterZDO.Set("bc_chest_id", 0); } Vector3 val2 = ((Component)carrier).transform.position - ((Component)carrier).transform.forward * 0.8f + Vector3.up * 0.2f; Quaternion rotation = ((Component)carrier).transform.rotation; try { if (MI_ZDO_SetPosition != null) { MI_ZDO_SetPosition.Invoke(val, new object[1] { val2 }); } if (MI_ZDO_SetRotation != null) { MI_ZDO_SetRotation.Invoke(val, new object[1] { rotation }); } } catch { } } } private static ZDO? FindCarriedChestZdo(long carrierId) { try { foreach (ZDO item in EnumerateAllZdos()) { if (item == null || !item.GetBool("bc_carried", false) || item.GetLong("bc_carrier", 0L) != carrierId) { continue; } return item; } } catch { } return null; } [IteratorStateMachine(typeof(<EnumerateAllZdos>d__70))] private static IEnumerable<ZDO> EnumerateAllZdos() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <EnumerateAllZdos>d__70(-2); } internal static void Message(Player p, string text) { ((Character)p).Message((MessageType)2, text, 0, (Sprite)null); } internal static bool WorldAllowsTeleportAllItems() { try { ZoneSystem instance = ZoneSystem.instance; if ((Object)(object)instance != (Object)null) { MethodInfo methodInfo = AccessTools.Method(((object)instance).GetType(), "GetGlobalKey", new Type[1] { typeof(string) }, (Type[])null); if (methodInfo != null) { object obj = methodInfo.Invoke(instance, new object[1] { "TeleportAll" }); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } if (((uint)num & (flag ? 1u : 0u)) != 0) { return true; } } FieldInfo fieldInfo = AccessTools.Field(((object)instance).GetType(), "m_globalKeys"); if (fieldInfo != null && fieldInfo.GetValue(instance) is IEnumerable<string> enumerable) { foreach (string item in enumerable) { if (string.Equals(item, "TeleportAll", StringComparison.OrdinalIgnoreCase)) { return true; } } } } } catch { } return false; } internal float GetEffectiveInteractDistance(Player player) { try { FieldInfo fieldInfo = AccessTools.Field(typeof(Player), "m_maxInteractDistance"); if (fieldInfo != null && fieldInfo.FieldType == typeof(float)) { float num = (float)fieldInfo.GetValue(player); if (num > 0.1f) { return num; } } } catch { } return Mathf.Max(0.1f, InteractDistance.Value); } internal static Vector3 GetBodyInteractOrigin(Player player) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) return ((Component)player).transform.position + Vector3.up * 1f; } internal static void SyncPlayerCarryState(Player player) { if (!Object.op_Implicit((Object)(object)player)) { return; } ZDO characterZDO = GetCharacterZDO((Character)(object)player); if (characterZDO == null) { return; } ZNetView carriedChestView = BackpackChestState.GetCarriedChestView(player); if (Object.op_Implicit((Object)(object)carriedChestView) && carriedChestView.IsValid()) { bool flag = false; ZDO zDO = carriedChestView.GetZDO(); if (zDO != null) { flag = zDO.GetBool("bc_nontele", false); } if (zDO != null) { ZdoUid zdoUid = GetZdoUid(zDO); if (zdoUid.userID != 0L && zdoUid.id != 0) { characterZDO.Set("bc_chest_user", zdoUid.userID); characterZDO.Set("bc_chest_id", zdoUid.id); } } characterZDO.Set("bc_haschest", true); characterZDO.Set("bc_nontele", flag); AddChestStatus(player); return; } if (characterZDO.GetBool("bc_haschest", false)) { long @long = characterZDO.GetLong("bc_chest_user", 0L); long long2 = characterZDO.GetLong("bc_chest_id", 0L); if (@long != 0L && long2 != 0) { return; } } characterZDO.Set("bc_haschest", false); characterZDO.Set("bc_nontele", false); RemoveChestStatus(player); } [IteratorStateMachine(typeof(<DelayedInitialSync>d__76))] internal IEnumerator DelayedInitialSync(Player player) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <DelayedInitialSync>d__76(0) { <>4__this = this, player = player }; } private static void EnsureFollower(ZNetView nview) { if (Object.op_Implicit((Object)(object)nview) && !((Object)(object)((Component)nview).GetComponent<BackpackChestFollower>() != (Object)null)) { ((Component)nview).gameObject.AddComponent<BackpackChestFollower>(); } } internal static string PrefabNameFromInstanceName(string instanceName) { return instanceName.EndsWith("(Clone)", StringComparison.Ordinal) ? instanceName.Substring(0, instanceName.Length - "(Clone)".Length) : instanceName; } private static bool ChestInventoryHasNonTeleportable(ZNetView chestView) { if (!Object.op_Implicit((Object)(object)chestView) || !chestView.IsValid()) { return false; } Container componentInChildren = ((Component)chestView).GetComponentInChildren<Container>(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { return false; } Inventory inventory = componentInChildren.GetInventory(); if (inventory == null) { return false; } List<ItemData> allItems = inventory.GetAllItems(); for (int i = 0; i < allItems.Count; i++) { ItemData val = allItems[i]; if (val?.m_shared != null && !val.m_shared.m_teleportable) { return true; } } return false; } internal static void AddChestStatus(Player p) { if (!Instance.ShowStatus.Value || !Object.op_Implicit((Object)(object)p)) { return; } ObjectDB instance = ObjectDB.instance; StatusEffect val = null; if ((Object)(object)instance != (Object)null) { val = instance.GetStatusEffect(SEHash); if ((Object)(object)val == (Object)null && instance.m_StatusEffects != null) { val = ((IEnumerable<StatusEffect>)instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect x) => Object.op_Implicit((Object)(object)x) && ((Object)x).name == "SE_BackpackChest")); } SE_Stats val2 = (SE_Stats)(object)((val is SE_Stats) ? val : null); if (val2 != null) { ((StatusEffect)val2).m_name = Instance.StatusName.Value; ((StatusEffect)val2).m_tooltip = Instance.StatusTooltip.Value; } } SEMan sEMan = ((Character)p).GetSEMan(); if (sEMan == null) { return; } if ((Object)(object)val != (Object)null) { if (!SEManBridge.TryAdd(sEMan, val)) { sEMan.AddStatusEffect(SEHash, true, 0, 0f); } return; } if ((Object)(object)ObjectDB.instance != (Object)null) { BackpackChestStatusRegistrar.Ensure(ObjectDB.instance); } sEMan.AddStatusEffect(SEHash, true, 0, 0f); } internal static void RemoveChestStatus(Player p) { if (!Object.op_Implicit((Object)(object)p)) { return; } SEMan sEMan = ((Character)p).GetSEMan(); if (sEMan == null) { return; } try { ObjectDB instance = ObjectDB.instance; StatusEffect val = null; if ((Object)(object)instance != (Object)null) { val = instance.GetStatusEffect(SEHash); if ((Object)(object)val == (Object)null && instance.m_StatusEffects != null) { val = ((IEnumerable<StatusEffect>)instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect x) => Object.op_Implicit((Object)(object)x) && ((Object)x).name == "SE_BackpackChest")); } } if ((Object)(object)val != (Object)null && SEManBridge.TryRemove(sEMan, val)) { return; } } catch { } sEMan.RemoveStatusEffect(SEHash, true); } internal static Sprite? LoadSpriteNextToDll(string fileName, int pixelsPerUnit = 100) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) try { string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location); if (string.IsNullOrEmpty(directoryName)) { return null; } string text = Path.Combine(directoryName, fileName); if (!File.Exists(text)) { Log.LogWarning((object)("Icon file not found: " + text)); return null; } byte[] data = File.ReadAllBytes(text); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!LoadImageCompat(val, data)) { Log.LogWarning((object)("Failed to decode icon PNG: " + text)); return null; } ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)1; return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), (float)pixelsPerUnit); } catch (Exception arg) { Log.LogWarning((object)$"LoadSpriteNextToDll failed: {arg}"); return null; } } internal static bool LoadImageCompat(Texture2D tex, byte[] data) { try { MethodInfo method = typeof(Texture2D).GetMethod("LoadImage", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(byte[]) }, null); if (method != null) { object obj = method.Invoke(tex, new object[1] { data }); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } MethodInfo methodInfo = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")?.GetMethod("LoadImage", BindingFlags.Static | BindingFlags.Public, null, new Type[2] { typeof(Texture2D), typeof(byte[]) }, null); if (methodInfo != null) { object obj2 = methodInfo.Invoke(null, new object[2] { tex, data }); bool flag2 = default(bool); int num2; if (obj2 is bool) { flag2 = (bool)obj2; num2 = 1; } else { num2 = 0; } return (byte)((uint)num2 & (flag2 ? 1u : 0u)) != 0; } } catch { } return false; } } internal static class BackpackChestState { internal static ZNetView? GetCarriedChestView(Player player) { if (!Object.op_Implicit((Object)(object)player)) { return null; } ZDO characterZDO = BackpackChestPlugin.GetCharacterZDO((Character)(object)player); if (characterZDO != null) { long @long = characterZDO.GetLong("bc_chest_user", 0L); long long2 = characterZDO.GetLong("bc_chest_id", 0L); if (@long != 0L && long2 != 0) { object? obj = AccessTools.Method(typeof(BackpackChestPlugin), "FindInstanceByZdoUid", (Type[])null, (Type[])null)?.Invoke(null, new object[2] { @long, long2 }); ZNetView val = (ZNetView)((obj is ZNetView) ? obj : null); if ((Object)(object)val != (Object)null && val.IsValid()) { ZDO zDO = val.GetZDO(); if (zDO != null && zDO.GetBool("bc_carried", false) && zDO.GetLong("bc_carrier", 0L) == player.GetPlayerID() && BackpackChestPlugin.PrefabNameFromInstanceName(((Object)((Component)val).gameObject).name) == "Chest") { return val; } } } } ZNetView[] array = Object.FindObjectsByType<ZNetView>((FindObjectsSortMode)0); foreach (ZNetView val2 in array) { if (!Object.op_Implicit((Object)(object)val2) || !val2.IsValid()) { continue; } ZDO zDO2 = val2.GetZDO(); if (zDO2 != null && zDO2.GetBool("bc_carried", false) && zDO2.GetLong("bc_carrier", 0L) == player.GetPlayerID()) { string a = BackpackChestPlugin.PrefabNameFromInstanceName(((Object)((Component)val2).gameObject).name); if (string.Equals(a, "Chest", StringComparison.Ordinal)) { return val2; } } } return null; } } [HarmonyPatch(typeof(Container), "Interact")] internal static class ContainerInteractPatch { [HarmonyPrefix] private static bool Prefix(Container __instance, Humanoid character, bool hold, bool alt, ref bool __result) { if ((Object)(object)__instance == (Object)null || (Object)(object)character == (Object)null) { return true; } Player val = (Player)(object)((character is Player) ? character : null); if (val == null) { return true; } ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)component) || !component.IsValid()) { return true; } string a = BackpackChestPlugin.PrefabNameFromInstanceName(((Object)((Component)component).gameObject).name); if (!string.Equals(a, "Chest", StringComparison.Ordinal)) { return true; } ZDO zDO = component.GetZDO(); if (zDO == null) { return true; } if (zDO.GetBool("bc_carried", false)) { BackpackChestPlugin.Message(val, "Нельзя открыть сундук, пока он на спине."); __result = false; return false; } return true; } } [HarmonyPatch(typeof(ZNetView), "Awake")] internal static class ZNetViewAwakePatch { [HarmonyPostfix] private static void Postfix(ZNetView __instance) { ZNetView __instance2 = __instance; if (!Object.op_Implicit((Object)(object)__instance2) || !__instance2.IsValid()) { return; } string a = BackpackChestPlugin.PrefabNameFromInstanceName(((Object)((Component)__instance2).gameObject).name); if (string.Equals(a, "Chest", StringComparison.Ordinal) && (Object)(object)((Component)__instance2).GetComponent<BackpackChestFollower>() == (Object)null) { ((Component)__instance2).gameObject.AddComponent<BackpackChestFollower>(); } __instance2.Register<long>("bc_request_drop", (Action<long, long>)delegate(long sender, long playerId) { if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer()) { Player val = ((IEnumerable<Player>)Player.GetAllPlayers()).FirstOrDefault((Func<Player, bool>)((Player p) => Object.op_Implicit((Object)(object)p) && p.GetPlayerID() == playerId)); if (Object.op_Implicit((Object)(object)val)) { string a2 = BackpackChestPlugin.PrefabNameFromInstanceName(((Object)((Component)__instance2).gameObject).name); if (string.Equals(a2, "Chest", StringComparison.Ordinal)) { BackpackChestPlugin.DoDropServer(__instance2, val); } } } }); } } internal static class BackpackChestStatusRegistrar { private static readonly MethodInfo? MI_UpdateRegisters = AccessTools.Method(typeof(ObjectDB), "UpdateRegisters", (Type[])null, (Type[])null); internal static void Ensure(ObjectDB db) { if (!Object.op_Implicit((Object)(object)db) || db.m_StatusEffects == null) { return; } StatusEffect? obj = ((IEnumerable<StatusEffect>)db.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect se) => Object.op_Implicit((Object)(object)se) && ((Object)se).name == "SE_BackpackChest")); SE_Stats val = (SE_Stats)(object)((obj is SE_Stats) ? obj : null); if ((Object)(object)val == (Object)null) { val = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)val).name = "SE_BackpackChest"; db.m_StatusEffects.Add((StatusEffect)(object)val); } if ((Object)(object)BackpackChestPlugin.Instance != (Object)null) { ((StatusEffect)val).m_name = BackpackChestPlugin.Instance.StatusName.Value; ((StatusEffect)val).m_tooltip = BackpackChestPlugin.Instance.StatusTooltip.Value; if ((Object)(object)BackpackChestPlugin.CustomIconSprite == (Object)null) { BackpackChestPlugin.CustomIconSprite = BackpackChestPlugin.LoadSpriteNextToDll("backpackchest_icon.png"); } if ((Object)(object)BackpackChestPlugin.CustomIconSprite != (Object)null) { ((StatusEffect)val).m_icon = BackpackChestPlugin.CustomIconSprite; } val.m_addMaxCarryWeight = 0f; } try { MI_UpdateRegisters?.Invoke(db, Array.Empty<object>()); } catch { } } } internal static class BackpackChestBuildRegistrar { [CompilerGenerated] private sealed class <EnsureDelayed>d__1 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; private int <i>5__1; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <EnsureDelayed>d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; if (_applied) { return false; } <i>5__1 = 0; break; case 1: <>1__state = -1; <i>5__1++; break; } if (<i>5__1 < 120 && (!Object.op_Implicit((Object)(object)ObjectDB.instance) || !Object.op_Implicit((Object)(object)ZNetScene.instance))) { <>2__current = null; <>1__state = 1; return true; } Apply(); return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static bool _applied; [IteratorStateMachine(typeof(<EnsureDelayed>d__1))] internal static IEnumerator EnsureDelayed() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <EnsureDelayed>d__1(0); } private static void Apply() { //IL_013a: Unknown result type (might be due to invalid IL or missing references) if (_applied) { return; } ObjectDB instance = ObjectDB.instance; ZNetScene instance2 = ZNetScene.instance; if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance2)) { return; } GameObject itemPrefab = instance.GetItemPrefab("Hammer"); if (!Object.op_Implicit((Object)(object)itemPrefab)) { ManualLogSource log = BackpackChestPlugin.Log; if (log != null) { log.LogWarning((object)"Hammer prefab not found in ObjectDB."); } return; } PieceTable val = itemPrefab.GetComponent<ItemDrop>()?.m_itemData?.m_shared?.m_buildPieces; if (!Object.op_Implicit((Object)(object)val)) { ManualLogSource log2 = BackpackChestPlugin.Log; if (log2 != null) { log2.LogWarning((object)"Hammer has no PieceTable (m_buildPieces)."); } return; } GameObject prefab = instance2.GetPrefab("Chest"); if (!Object.op_Implicit((Object)(object)prefab)) { ManualLogSource log3 = BackpackChestPlugin.Log; if (log3 != null) { log3.LogWarning((object)"Prefab 'Chest' not found in ZNetScene."); } return; } Piece val2 = prefab.GetComponent<Piece>() ?? prefab.AddComponent<Piece>(); if (string.IsNullOrEmpty(val2.m_name)) { val2.m_name = "$piece_chest"; } val2.m_category = (PieceCategory)4; GameObject prefab2 = instance2.GetPrefab("forge"); CraftingStation val3 = (Object.op_Implicit((Object)(object)prefab2) ? prefab2.GetComponent<CraftingStation>() : null); if (!Object.op_Implicit((Object)(object)val3)) { ManualLogSource log4 = BackpackChestPlugin.Log; if (log4 != null) { log4.LogWarning((object)"Forge crafting station not found (prefab 'forge')."); } return; } val2.m_craftingStation = val3; GameObject itemPrefab2 = instance.GetItemPrefab("FineWood"); GameObject itemPrefab3 = instance.GetItemPrefab("Tin"); if (!Object.op_Implicit((Object)(object)itemPrefab2) || !Object.op_Implicit((Object)(object)itemPrefab3)) { ManualLogSource log5 = BackpackChestPlugin.Log; if (log5 != null) { log5.LogWarning((object)"FineWood or Tin prefab not found in ObjectDB."); } return; } val2.m_resources = (Requirement[])(object)new Requirement[2] { NewReq(itemPrefab2, 40, recover: true), NewReq(itemPrefab3, 20, recover: true) }; if ((Object)(object)BackpackChestPlugin.CustomIconSprite != (Object)null) { val2.m_icon = BackpackChestPlugin.CustomIconSprite; } if (val.m_pieces == null) { val.m_pieces = new List<GameObject>(); } if (!val.m_pieces.Contains(prefab)) { val.m_pieces.Add(prefab); } ReorderToFirstFurniture(val, prefab); _applied = true; ManualLogSource log6 = BackpackChestPlugin.Log; if (log6 != null) { log6.LogInfo((object)"Added prefab 'Chest' to Hammer/Furniture with Forge requirement and custom cost."); } } private static void ReorderToFirstFurniture(PieceTable pieceTable, GameObject chestPrefab) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Invalid comparison between Unknown and I4 if (pieceTable.m_pieces == null) { return; } pieceTable.m_pieces.Remove(chestPrefab); int index = 0; for (int i = 0; i < pieceTable.m_pieces.Count; i++) { GameObject val = pieceTable.m_pieces[i]; if (Object.op_Implicit((Object)(object)val)) { Piece component = val.GetComponent<Piece>(); if ((Object)(object)component != (Object)null && (int)component.m_category == 4) { index = i; break; } } } pieceTable.m_pieces.Insert(index, chestPrefab); } private static Requirement NewReq(GameObject itemPrefab, int amount, bool recover) { //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_0012: 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_0021: Expected O, but got Unknown return new Requirement { m_resItem = itemPrefab.GetComponent<ItemDrop>(), m_amount = amount, m_recover = recover }; } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class ObjectDBAwake_BackpackChestSE { [HarmonyPostfix] private static void Postfix(ObjectDB __instance) { BackpackChestStatusRegistrar.Ensure(__instance); if ((Object)(object)BackpackChestPlugin.Instance != (Object)null) { ((MonoBehaviour)BackpackChestPlugin.Instance).StartCoroutine(BackpackChestBuildRegistrar.EnsureDelayed()); } } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] internal static class ObjectDBCopyOtherDB_BackpackChestSE { [HarmonyPostfix] private static void Postfix(ObjectDB __instance) { BackpackChestStatusRegistrar.Ensure(__instance); if ((Object)(object)BackpackChestPlugin.Instance != (Object)null) { ((MonoBehaviour)BackpackChestPlugin.Instance).StartCoroutine(BackpackChestBuildRegistrar.EnsureDelayed()); } } } [HarmonyPatch] internal static class CarryWeightPenaltyPatch { [HarmonyTargetMethod] private static MethodBase? TargetMethod() { MethodInfo methodInfo = AccessTools.Method(typeof(Player), "GetMaxCarryWeight", (Type[])null, (Type[])null); if (methodInfo != null && methodInfo.ReturnType == typeof(float)) { return methodInfo; } MethodInfo[] methods = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo2 in methods) { if (methodInfo2.Name == "GetMaxCarryWeight" && methodInfo2.ReturnType == typeof(float)) { return methodInfo2; } } return null; } [HarmonyPostfix] private static void Postfix(Player __instance, ref float __result) { if (Object.op_Implicit((Object)(object)__instance)) { ZDO characterZDO = BackpackChestPlugin.GetCharacterZDO((Character)(object)__instance); if (characterZDO != null && characterZDO.GetBool("bc_haschest", false)) { float num = Mathf.Max(0f, BackpackChestPlugin.Instance.DebuffCarryWeight.Value); __result = Mathf.Max(0f, __result - num); } } } } [HarmonyPatch] internal static class RunSlowOnlyPatch { [CompilerGenerated] private sealed class <TargetMethods>d__0 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator { private int <>1__state; private MethodBase <>2__current; private int <>l__initialThreadId; private Type[] <types>5__1; private Type[] <>s__2; private int <>s__3; private Type <t>5__4; private List<MethodInfo>.Enumerator <>s__5; private MethodInfo <method>5__6; MethodBase IEnumerator<MethodBase>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <TargetMethods>d__0(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <types>5__1 = null; <>s__2 = null; <t>5__4 = null; <>s__5 = default(List<MethodInfo>.Enumerator); <method>5__6 = null; <>1__state = -2; } private bool MoveNext() { try { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -3; goto IL_01a7; } <>1__state = -1; <types>5__1 = new Type[3] { typeof(Character), typeof(Player), typeof(Humanoid) }; <>s__2 = <types>5__1; <>s__3 = 0; goto IL_01e8; IL_01e8: if (<>s__3 < <>s__2.Length) { <t>5__4 = <>s__2[<>s__3]; <>s__5 = AccessTools.GetDeclaredMethods(<t>5__4).GetEnumerator(); <>1__state = -3; goto IL_01af; } <>s__2 = null; return false; IL_010c: if (<method>5__6.Name.IndexOf("RunSpeed", StringComparison.OrdinalIgnoreCase) >= 0 || <method>5__6.Name == "GetRunSpeed" || <method>5__6.Name == "GetRunSpeedFactor" || <method>5__6.Name == "GetRunSpeedModifier" || <method>5__6.Name == "GetRunSpeedFactorInternal") { <>2__current = <method>5__6; <>1__state = 1; return true; } goto IL_01a7; IL_01af: while (<>s__5.MoveNext()) { <method>5__6 = <>s__5.Current; if (<method>5__6 == null || <method>5__6.ReturnType != typeof(float) || <method>5__6.IsSpecialName) { continue; } goto IL_010c; } <>m__Finally1(); <>s__5 = default(List<MethodInfo>.Enumerator); <t>5__4 = null; <>s__3++; goto IL_01e8; IL_01a7: <method>5__6 = null; goto IL_01af; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; ((IDisposable)<>s__5).Dispose(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<MethodBase> IEnumerable<MethodBase>.GetEnumerator() { if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; return this; } return new <TargetMethods>d__0(0); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<MethodBase>)this).GetEnumerator(); } } [IteratorStateMachine(typeof(<TargetMethods>d__0))] [HarmonyTargetMethods] private static IEnumerable<MethodBase> TargetMethods() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <TargetMethods>d__0(-2); } [HarmonyPostfix] private static void Postfix(object __instance, ref float __result) { Player val = (Player)((__instance is Player) ? __instance : null); if (val == null) { return; } ZDO characterZDO = BackpackChestPlugin.GetCharacterZDO((Character)(object)val); if (characterZDO != null && characterZDO.GetBool("bc_haschest", false)) { float num = Mathf.Clamp01(BackpackChestPlugin.Instance.DebuffRunSlowPercent.Value); if (((Character)val).IsRunning()) { __result *= 1f - num; } } } } [HarmonyPatch] internal static class PlayerTeleportHardBlockPatch { [CompilerGenerated] private sealed class <TargetMethods>d__2 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator { private int <>1__state; private MethodBase <>2__current; private int <>l__initialThreadId; private List<MethodInfo> <ms>5__1; private List<MethodInfo>.Enumerator <>s__2; private MethodInfo <m>5__3; private ParameterInfo[] <ps>5__4; MethodBase IEnumerator<MethodBase>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <TargetMethods>d__2(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <ms>5__1 = null; <>s__2 = default(List<MethodInfo>.Enumerator); <m>5__3 = null; <ps>5__4 = null; <>1__state = -2; } private bool MoveNext() { try { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -3; goto IL_012b; } <>1__state = -1; <ms>5__1 = AccessTools.GetDeclaredMethods(typeof(Player)); <>s__2 = <ms>5__1.GetEnumerator(); <>1__state = -3; goto IL_013a; IL_012b: <ps>5__4 = null; <m>5__3 = null; goto IL_013a; IL_013a: while (true) { if (<>s__2.MoveNext()) { <m>5__3 = <>s__2.Current; if (!(<m>5__3.ReturnType != typeof(bool)) && (!(<m>5__3.Name != "TeleportTo") || !(<m>5__3.Name != "Teleport"))) { <ps>5__4 = <m>5__3.GetParameters(); if (<ps>5__4.Length >= 1) { break; } } continue; } <>m__Finally1(); <>s__2 = default(List<MethodInfo>.Enumerator); return false; } if (<ps>5__4[0].ParameterType == typeof(Vector3)) { <>2__current = <m>5__3; <>1__state = 1; return true; } goto IL_012b; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; ((IDisposable)<>s__2).Dispose(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<MethodBase> IEnumerable<MethodBase>.GetEnumerator() { if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; return this; } return new <TargetMethods>d__2(0); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<MethodBase>)this).GetEnumerator(); } } private static float _nextMsgTime; private static bool ShouldBlock(Player p) { if (BackpackChestPlugin.WorldAllowsTeleportAllItems()) { return false; } ZDO characterZDO = BackpackChestPlugin.GetCharacterZDO((Character)(object)p); if (characterZDO == null) { return false; } if (!characterZDO.GetBool("bc_haschest", false)) { return false; } if (!characterZDO.GetBool("bc_nontele", false)) { return false; } return true; } [IteratorStateMachine(typeof(<TargetMethods>d__2))] [HarmonyTargetMethods] private static IEnumerable<MethodBase> TargetMethods() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <TargetMethods>d__2(-2); } [HarmonyPrefix] private static bool Prefix(Player __instance, ref bool __result) { if (!Object.op_Implicit((Object)(object)__instance)) { return true; } if (!ShouldBlock(__instance)) { return true; } if (Time.time >= _nextMsgTime) { _nextMsgTime = Time.time + 1f; BackpackChestPlugin.Message(__instance, "Нельзя телепортироваться: в сундуке есть предметы, запрещённые для порталов."); } __result = false; return false; } } [HarmonyPatch] internal static class PlayerTeleport_MoveCarriedChestPatch { [CompilerGenerated] private sealed class <TargetMethods>d__0 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator { private int <>1__state; private MethodBase <>2__current; private int <>l__initialThreadId; private List<MethodInfo> <ms>5__1; private List<MethodInfo>.Enumerator <>s__2; private MethodInfo <m>5__3; private ParameterInfo[] <ps>5__4; MethodBase IEnumerator<MethodBase>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <TargetMethods>d__0(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <ms>5__1 = null; <>s__2 = default(List<MethodInfo>.Enumerator); <m>5__3 = null; <ps>5__4 = null; <>1__state = -2; } private bool MoveNext() { try { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -3; goto IL_012b; } <>1__state = -1; <ms>5__1 = AccessTools.GetDeclaredMethods(typeof(Player)); <>s__2 = <ms>5__1.GetEnumerator(); <>1__state = -3; goto IL_013a; IL_012b: <ps>5__4 = null; <m>5__3 = null; goto IL_013a; IL_013a: while (true) { if (<>s__2.MoveNext()) { <m>5__3 = <>s__2.Current; if (!(<m>5__3.ReturnType != typeof(bool)) && (!(<m>5__3.Name != "TeleportTo") || !(<m>5__3.Name != "Teleport"))) { <ps>5__4 = <m>5__3.GetParameters(); if (<ps>5__4.Length >= 1) { break; } } continue; } <>m__Finally1(); <>s__2 = default(List<MethodInfo>.Enumerator); return false; } if (<ps>5__4[0].ParameterType == typeof(Vector3)) { <>2__current = <m>5__3; <>1__state = 1; return true; } goto IL_012b; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; ((IDisposable)<>s__2).Dispose(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<MethodBase> IEnumerable<MethodBase>.GetEnumerator() { if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; return this; } return new <TargetMethods>d__0(0); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<MethodBase>)this).GetEnumerator(); } } [IteratorStateMachine(typeof(<TargetMethods>d__0))] [HarmonyTargetMethods] private static IEnumerable<MethodBase> TargetMethods() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <TargetMethods>d__0(-2); } [HarmonyPostfix] private static void Postfix(Player __instance, ref bool __result) { //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)__instance) || !__result || !Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer()) { return; } ZDO characterZDO = BackpackChestPlugin.GetCharacterZDO((Character)(object)__instance); if (characterZDO == null || !characterZDO.GetBool("bc_haschest", false)) { return; } long @long = characterZDO.GetLong("bc_chest_user", 0L); long long2 = characterZDO.GetLong("bc_chest_id", 0L); if (@long == 0L || long2 == 0) { return; } BackpackChestPlugin.Instance.ComputeNetworkBackTransform(__instance, out var pos, out var rot); MethodInfo methodInfo = AccessTools.Method(typeof(BackpackChestPlugin), "TryWriteZdoTransformByUid", new Type[4] { typeof(long), typeof(long), typeof(Vector3), typeof(Quaternion) }, (Type[])null); if (methodInfo != null) { try { methodInfo.Invoke(null, new object[4] { @long, long2, pos, rot }); } catch { } } MethodInfo methodInfo2 = AccessTools.Method(typeof(BackpackChestPlugin), "FindInstanceByZdoUid", new Type[2] { typeof(long), typeof(long) }, (Type[])null); if (!(methodInfo2 != null)) { return; } try { object? obj2 = methodInfo2.Invoke(null, new object[2] { @long, long2 }); ZNetView val = (ZNetView)((obj2 is ZNetView) ? obj2 : null); if ((Object)(object)val != (Object)null && val.IsValid()) { ((Component)val).transform.SetPositionAndRotation(pos, rot); BackpackChestPlugin.TryWriteZdoTransform(val, pos, rot); if (!val.IsOwner()) { val.ClaimOwnership(); } } } catch { } } } [HarmonyPatch(typeof(Player), "Awake")] internal static class PlayerAwakeInitialSyncPatch { [HarmonyPostfix] private static void Postfix(Player __instance) { if (Object.op_Implicit((Object)(object)__instance)) { if ((Object)(object)((Component)__instance).GetComponent<BackpackChestPlayerVisual>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<BackpackChestPlayerVisual>(); } if ((Object)(object)BackpackChestPlugin.Instance != (Object)null) { ((MonoBehaviour)BackpackChestPlugin.Instance).StartCoroutine(BackpackChestPlugin.Instance.DelayedInitialSync(__instance)); } } } } internal class BackpackChestPlayerVisual : MonoBehaviour { private Player? _player; private GameObject? _visualRoot; private Transform? _bone; private void Awake() { _player = ((Component)this).GetComponent<Player>(); } private void OnDestroy() { DestroyVisual(); } private void LateUpdate() { if (!((Object)(object)_player == (Object)null) && Object.op_Implicit((Object)(object)_player)) { ZDO characterZDO = BackpackChestPlugin.GetCharacterZDO((Character)(object)_player); if (characterZDO == null) { DestroyVisual(); return; } if (!characterZDO.GetBool("bc_haschest", false)) { DestroyVisual(); return; } EnsureVisual(); UpdatePose(); } } private void EnsureVisual() { if (!((Object)(object)BackpackChestPlugin.Instance == (Object)null) && !((Object)(object)_visualRoot != (Object)null) && !((Object)(object)ZNetScene.instance == (Object)null)) { GameObject prefab = ZNetScene.instance.GetPrefab("Chest"); if (!((Object)(object)prefab == (Object)null)) { _visualRoot = BuildVisualCloneFromPrefab(prefab.transform); ((Object)_visualRoot).name = "BackpackChestLocalVisual"; _bone = BackpackChestPlugin.Instance.FindBackBone(_player) ?? ((Component)_player).transform; _visualRoot.transform.SetParent(_bone, false); } } } private static Vector3 InverseLossyScale(Transform t) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) Vector3 lossyScale = t.lossyScale; float num = ((Mathf.Abs(lossyScale.x) > 0.0001f) ? (1f / lossyScale.x) : 1f); float num2 = ((Mathf.Abs(lossyScale.y) > 0.0001f) ? (1f / lossyScale.y) : 1f); float num3 = ((Mathf.Abs(lossyScale.z) > 0.0001f) ? (1f / lossyScale.z) : 1f); return new Vector3(num, num2, num3); } private void UpdatePose() { //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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_visualRoot == (Object)null) && !((Object)(object)_player == (Object)null) && Object.op_Implicit((Object)(object)_player) && !((Object)(object)BackpackChestPlugin.Instance == (Object)null)) { Transform val = BackpackChestPlugin.Instance.FindBackBone(_player) ?? ((Component)_player).transform; if ((Object)(object)_bone != (Object)(object)val) { _bone = val; _visualRoot.transform.SetParent(_bone, false); } if (!((Object)(object)_bone == (Object)null)) { Vector3 val2 = InverseLossyScale(_bone); _visualRoot.transform.localPosition = Vector3.Scale(BackpackChestPlugin.Instance.VisualLocalOffset.Value, val2); _visualRoot.transform.localRotation = Quaternion.Euler(BackpackChestPlugin.Instance.VisualLocalEuler.Value); float value = BackpackChestPlugin.Instance.VisualScale.Value; _visualRoot.transform.localScale = Vector3.Scale(val2, Vector3.one * value); } } } private void DestroyVisual() { if ((Object)(object)_visualRoot != (Object)null) { try { Object.Destroy((Object)(object)_visualRoot); } catch { } _visualRoot = null; _bone = null; } } private static GameObject BuildVisualCloneFromPrefab(Transform prefabRoot) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("BackpackChestVisualRoot"); for (int i = 0; i < prefabRoot.childCount; i++) { CopyVisualHierarchy(prefabRoot.GetChild(i), val.transform); } CopyVisualComponents(prefabRoot, val); val.transform.localScale = Vector3.one; return val; } private static void CopyVisualHierarchy(Transform src, Transform dstParent) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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) GameObject val = new GameObject(((Object)src).name); Transform transform = val.transform; transform.SetParent(dstParent, false); transform.localPosition = src.localPosition; transform.localRotation = src.localRotation; transform.localScale = src.localScale; CopyVisualComponents(src, val); for (int i = 0; i < src.childCount; i++) { CopyVisualHierarchy(src.GetChild(i), transform); } } private static void CopyVisualComponents(Transform src, GameObject dstNode) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) MeshRenderer component = ((Component)src).GetComponent<MeshRenderer>(); MeshFilter component2 = ((Component)src).GetComponent<MeshFilter>(); if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null && (Object)(object)component2.sharedMesh != (Object)null) { MeshFilter val = dstNode.AddComponent<MeshFilter>(); val.sharedMesh = component2.sharedMesh; MeshRenderer val2 = dstNode.AddComponent<MeshRenderer>(); ((Renderer)val2).sharedMaterials = ((Renderer)component).sharedMaterials; ((Renderer)val2).shadowCastingMode = ((Renderer)component).shadowCastingMode; ((Renderer)val2).receiveShadows = ((Renderer)component).receiveShadows; ((Renderer)val2).lightProbeUsage = ((Renderer)component).lightProbeUsage; ((Renderer)val2).reflectionProbeUsage = ((Renderer)component).reflectionProbeUsage; } SkinnedMeshRenderer component3 = ((Component)src).GetComponent<SkinnedMeshRenderer>(); if ((Object)(object)component3 != (Object)null && (Object)(object)component3.sharedMesh != (Object)null) { SkinnedMeshRenderer val3 = dstNode.AddComponent<SkinnedMeshRenderer>(); val3.sharedMesh = component3.sharedMesh; ((Renderer)val3).sharedMaterials = ((Renderer)component3).sharedMaterials; ((Renderer)val3).shadowCastingMode = ((Renderer)component3).shadowCastingMode; ((Renderer)val3).receiveShadows = ((Renderer)component3).receiveShadows; ((Renderer)val3).lightProbeUsage = ((Renderer)component3).lightProbeUsage; ((Renderer)val3).reflectionProbeUsage = ((Renderer)component3).reflectionProbeUsage; } } } internal static class SEManBridge { private static readonly MethodInfo? MI_AddSE_2; private static readonly MethodInfo? MI_AddSE_4; private static readonly MethodInfo? MI_RemoveSE_2; static SEManBridge() { MethodInfo[] methods = typeof(SEMan).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name != "AddStatusEffect") { continue; } ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length >= 2 && parameters[0].ParameterType == typeof(StatusEffect) && parameters[1].ParameterType == typeof(bool)) { if (parameters.Length == 2) { MI_AddSE_2 = methodInfo; } if (parameters.Length == 4 && parameters[2].ParameterType == typeof(int) && parameters[3].ParameterType == typeof(float)) { MI_AddSE_4 = methodInfo; } } } MethodInfo[] methods2 = typeof(SEMan).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo2 in methods2) { if (!(methodInfo2.Name != "RemoveStatusEffect")) { ParameterInfo[] parameters2 = methodInfo2.GetParameters(); if (parameters2.Length == 2 && parameters2[0].ParameterType == typeof(StatusEffect) && parameters2[1].ParameterType == typeof(bool)) { MI_RemoveSE_2 = methodInfo2; break; } } } } internal static bool TryAdd(SEMan man, StatusEffect se) { try { if (MI_AddSE_2 != null) { MI_AddSE_2.Invoke(man, new object[2] { se, true }); return true; } if (MI_AddSE_4 != null) { MI_AddSE_4.Invoke(man, new object[4] { se, true, 0, 0f }); return true; } } catch { } return false; } internal static bool TryRemove(SEMan man, StatusEffect se) { try { if (MI_RemoveSE_2 != null) { MI_RemoveSE_2.Invoke(man, new object[2] { se, true }); return true; } } catch { } return false; } } internal class BackpackChestFollower : MonoBehaviour { private ZNetView? _nview; private Rigidbody? _rb; private Collider[] _colliders = Array.Empty<Collider>(); private Renderer[] _renderers = Array.Empty<Renderer>(); private bool _lastCarried; private long _lastCarrierId; private GameObject? _visualRoot; private Transform? _visualParentBone; private bool _origPersistent; private bool _origPersistentCaptured; private void Awake() { _nview = ((Component)this).GetComponent<ZNetView>(); _rb = ((Component)this).GetComponent<Rigidbody>(); _colliders = ((Component)this).GetComponentsInChildren<Collider>(true); _renderers = ((Component)this).GetComponentsInChildren<Renderer>(true); if ((Object)(object)_nview != (Object)null && _nview.IsValid()) { _origPersistent = BackpackChestPlugin.GetPersistent(_nview); _origPersistentCaptured = true; } } private void OnDestroy() { DestroyVisual(); } private void LateUpdate() { if ((Object)(object)_nview == (Object)null || !_nview.IsValid()) { return; } ZDO zDO = _nview.GetZDO(); if (zDO != null) { bool @bool = zDO.GetBool("bc_carried", false); long @long = zDO.GetLong("bc_carrier", 0L); if (@bool != _lastCarried || @long != _lastCarrierId) { ApplyLocalPresentation(@bool); _lastCarried = @bool; _lastCarrierId = @long; } if (!@bool) { DestroyVisual(); } } } private void ApplyLocalPresentation(bool carried) { //IL_0153: 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_00ca: 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) if ((Object)(object)_nview != (Object)null && _nview.IsValid() && _origPersistentCaptured) { BackpackChestPlugin.SetPersistent(_nview, carried || _origPersistent); } if (!carried) { SetRenderersEnabled(enabled: true); Collider[] colliders = _colliders; foreach (Collider val in colliders) { if (Object.op_Implicit((Object)(object)val)) { val.enabled = true; val.isTrigger = false; } } if (Object.op_Implicit((Object)(object)_rb)) { _rb.isKinematic = false; _rb.useGravity = true; _rb.linearVelocity = Vector3.zero; _rb.angularVelocity = Vector3.zero; } DestroyVisual(); return; } SetRenderersEnabled(enabled: false); Collider[] colliders2 = _colliders; foreach (Collider val2 in colliders2) { if (Object.op_Implicit((Object)(object)val2)) { val2.enabled = false; } } if (Object.op_Implicit((Object)(object)_rb)) { _rb.linearVelocity = Vector3.zero; _rb.angularVelocity = Vector3.zero; _rb.isKinematic = true; _rb.useGravity = false; } } private void EnsureVisualForCarrier(long carrierId) { Player val = FindPlayerById(carrierId); if (!Object.op_Implicit((Object)(object)val)) { DestroyVisual(); return; } Transform val2 = BackpackChestPlugin.Instance.FindBackBone(val) ?? ((Component)val).transform; if ((Object)(object)_visualRoot != (Object)null) { if ((Object)(object)_visualParentBone != (Object)(object)val2) { _visualRoot.transform.SetParent(val2, false); _visualParentBone = val2; } ApplyVisualPose(val2); } else { _visualRoot = BuildVisualCloneFromThisChest(); ((Object)_visualRoot).name = "BackpackChestVisual"; _visualRoot.transform.SetParent(val2, false); _visualParentBone = val2; ApplyVisualPose(val2); } } private static Player? FindPlayerById(long playerId) { foreach (Player allPlayer in Player.GetAllPlayers()) { if (Object.op_Implicit((Object)(object)allPlayer) && allPlayer.GetPlayerID() == playerId) { return allPlayer; } } return null; } private static Vector3 InverseLossyScale(Transform t) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) Vector3 lossyScale = t.lossyScale; float num = ((Mathf.Abs(lossyScale.x) > 0.0001f) ? (1f / lossyScale.x) : 1f); float num2 = ((Mathf.Abs(lossyScale.y) > 0.0001f) ? (1f / lossyScale.y) : 1f); float num3 = ((Mathf.Abs(lossyScale.z) > 0.0001f) ? (1f / lossyScale.z) : 1f); return new Vector3(num, num2, num3); } private void ApplyVisualPose(Transform bone) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_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) if (!((Object)(object)_visualRoot == (Object)null)) { Vector3 val = InverseLossyScale(bone); _visualRoot.transform.localPosition = Vector3.Scale(BackpackChestPlugin.Instance.VisualLocalOffset.Value, val); _visualRoot.transform.localRotation = Quaternion.Euler(BackpackChestPlugin.Instance.VisualLocalEuler.Value); float value = BackpackChestPlugin.Instance.VisualScale.Value; _visualRoot.transform.localScale = Vector3.Scale(val, Vector3.one * value); } } private GameObject BuildVisualCloneFromThisChest() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expec