public void UpdateAttachedWeapon() { Item slot = base.inventory.GetSlot(0); HeldEntity heldEntity = null; if (slot != null && (slot.info.category == ItemCategory.Weapon || slot.info.category == ItemCategory.Fun)) { BaseEntity heldEntity2 = slot.GetHeldEntity(); if (heldEntity2 != null) { HeldEntity component = heldEntity2.GetComponent <HeldEntity>(); if (component != null && component.IsUsableByTurret) { heldEntity = component; } } } SetFlag(Flags.Reserved3, heldEntity != null); if (heldEntity == null) { if ((bool)GetAttachedWeapon()) { GetAttachedWeapon().SetGenericVisible(false); GetAttachedWeapon().SetLightsOn(false); } AttachedWeapon = null; return; } heldEntity.SetLightsOn(true); Transform transform = heldEntity.transform; Transform muzzleTransform = heldEntity.MuzzleTransform; heldEntity.SetParent(null); transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; Quaternion quaternion = transform.rotation * Quaternion.Inverse(muzzleTransform.rotation); heldEntity.limitNetworking = false; heldEntity.SetFlag(Flags.Disabled, false); heldEntity.SetParent(this, StringPool.Get(socketTransform.name)); transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; transform.rotation *= quaternion; Vector3 vector = socketTransform.InverseTransformPoint(muzzleTransform.position); transform.localPosition = Vector3.left * vector.x; float num = Vector3.Distance(muzzleTransform.position, transform.position); transform.localPosition += Vector3.forward * num * attachedWeaponZOffsetScale; heldEntity.SetGenericVisible(true); AttachedWeapon = heldEntity; totalAmmoDirty = true; Reload(); UpdateTotalAmmo(); }