static void HideSlot(UnitEntityView __instance, ItemSlot slot, ref bool dirty)
        {
            var ee = __instance.ExtractEquipmentEntities(slot).ToList();

            if (ee.Count > 0)
            {
                __instance.CharacterAvatar.RemoveEquipmentEntities(ee);
                dirty = true;
            }
        }
        public static void UpdateModel(UnitEntityView view)
        {
            if (view.CharacterAvatar == null || view.EntityData == null)
            {
                return;
            }
            if (!view.EntityData.IsPlayerFaction)
            {
                return;
            }
            Settings.CharacterSettings characterSettings = Main.settings.GetCharacterSettings(view.EntityData);
            if (characterSettings == null)
            {
                return;
            }
            bool dirty = view.CharacterAvatar.IsDirty;

            if (view.EntityData.Descriptor.Doll == null && characterSettings.classOutfit.Name != "Default")
            {
                ChangeCompanionOutfit(view, characterSettings);
            }
            if (characterSettings.classOutfit.Name == "None")
            {
                NoClassOutfit(view);
            }
            if (characterSettings.hideHelmet)
            {
                HideSlot(view, view.EntityData.Body.Head, ref dirty);
            }

            /* if (characterSettings.hideItemCloak)
             * {
             *   HideSlot(view, view.EntityData.Body.Shoulders, ref dirty);
             * }*/
            if (characterSettings.hideArmor)
            {
                HideSlot(view, view.EntityData.Body.Armor, ref dirty);
            }
            if (characterSettings.hideGloves)
            {
                HideSlot(view, view.EntityData.Body.Gloves, ref dirty);
            }
            if (characterSettings.hideBracers)
            {
                HideSlot(view, view.EntityData.Body.Wrist, ref dirty);
            }
            if (characterSettings.hideBoots)
            {
                HideSlot(view, view.EntityData.Body.Feet, ref dirty);
            }
            if (characterSettings.hideHorns)
            {
                foreach (var ee in view.CharacterAvatar.EquipmentEntities.ToArray())
                {
                    if (ee.BodyParts.Exists((bodypart) => bodypart.Type == BodyPartType.Horns))
                    {
                        view.CharacterAvatar.EquipmentEntities.Remove(ee);
                        dirty = true;
                    }
                }
            }
            if (characterSettings.hideTail)
            {
                foreach (var ee in view.CharacterAvatar.EquipmentEntities.ToArray())
                {
                    if (ee.name.StartsWith("Tail"))
                    {
                        view.CharacterAvatar.EquipmentEntities.Remove(ee);
                        dirty = true;
                    }
                }
            }
            if (characterSettings.hideClassCloak)
            {
                foreach (var ee in view.CharacterAvatar.EquipmentEntities.ToArray())
                {
                    if (ee.OutfitParts.Exists((outfit) => {
                        return(outfit.Special == EquipmentEntity.OutfitPartSpecialType.Backpack ||
                               outfit.Special == EquipmentEntity.OutfitPartSpecialType.Backpack);
                    }) && !view.ExtractEquipmentEntities(view.EntityData.Body.Shoulders).Contains(ee))
                    {
                        view.CharacterAvatar.EquipmentEntities.Remove(ee);
                        dirty = true;
                    }
                }
            }
            if (characterSettings.hideCap)
            {
                foreach (var ee in view.CharacterAvatar.EquipmentEntities.ToArray())
                {
                    if (ee.BodyParts.Exists((bodypart) => bodypart.Type == BodyPartType.Helmet) &&
                        !view.ExtractEquipmentEntities(view.EntityData.Body.Head).Contains(ee))
                    {
                        view.CharacterAvatar.EquipmentEntities.Remove(ee);
                        dirty = true;
                    }
                }
            }
            if (characterSettings.overrideHelm != null && !characterSettings.hideHelmet)
            {
                if (!OverrideEquipment(view, view.EntityData.Body.Head, characterSettings.overrideHelm, ref dirty))
                {
                    characterSettings.overrideHelm = null;
                }
            }

            /*            if (characterSettings.overrideCloak
             *            != null && !characterSettings.hideItemCloak)
             *          {
             *              if (!OverrideEquipment(view, view.EntityData.Body.Shoulders, characterSettings.overrideCloak, ref dirty))
             *              {
             *                  characterSettings.overrideCloak = null;
             *              }
             *          }*/
            if (characterSettings.overrideArmor != null && !characterSettings.hideArmor)
            {
                if (!OverrideEquipment(view, view.EntityData.Body.Armor, characterSettings.overrideArmor, ref dirty))
                {
                    characterSettings.overrideArmor = null;
                }
            }
            if (characterSettings.overrideBracers != null && !characterSettings.hideBracers)
            {
                if (!OverrideEquipment(view, view.EntityData.Body.Wrist, characterSettings.overrideBracers, ref dirty))
                {
                    characterSettings.overrideBracers = null;
                }
            }
            if (characterSettings.overrideGloves != null && !characterSettings.hideGloves)
            {
                if (!OverrideEquipment(view, view.EntityData.Body.Gloves, characterSettings.overrideGloves, ref dirty))
                {
                    characterSettings.overrideGloves = null;
                }
            }
            if (characterSettings.overrideBoots != null && !characterSettings.hideBoots)
            {
                if (!OverrideEquipment(view, view.EntityData.Body.Feet, characterSettings.overrideBoots, ref dirty))
                {
                    characterSettings.overrideBoots = null;
                }
            }
            if (characterSettings.overrideGlasses != null && !characterSettings.hideGlasses)
            {
                if (!OverrideEquipment(view, view.EntityData.Body.Glasses, characterSettings.overrideGlasses, ref dirty))
                {
                    characterSettings.overrideGlasses = null;
                }
            }
            if (characterSettings.overrideShirt != null && !characterSettings.hideShirt)
            {
                if (!OverrideEquipment(view, view.EntityData.Body.Shirt, characterSettings.overrideShirt, ref dirty))
                {
                    characterSettings.overrideShirt = null;
                }
            }
            if (characterSettings.overrideTattoo != null)
            {
                foreach (var assetId in EquipmentResourcesManager.Tattoos.Keys)
                {
                    var ee = ResourcesLibrary.TryGetResource <EquipmentEntity>(assetId);
                    if (ee != null)
                    {
                        view.CharacterAvatar.RemoveEquipmentEntity(ee);
                    }
                }
                var tattoo = ResourcesLibrary.TryGetResource <EquipmentEntity>(characterSettings.overrideTattoo);
                if (tattoo != null)
                {
                    view.CharacterAvatar.AddEquipmentEntity(tattoo);
                }
            }

            /*if (view.EntityData.Descriptor.Progression?.GetEquipmentClass().Name == "Ranger")
             * {
             *  FixRangerCloak(view);
             * }*/
            view.CharacterAvatar.IsDirty = dirty;
        }