Esempio n. 1
0
        public static bool UsesImc(IItemModel item)
        {
            var root = item.GetRoot();

            if (root == null)
            {
                return(false);
            }
            return(UsesImc(root));
        }
Esempio n. 2
0
        /// <summary>
        /// A simple function that retrieves the material set ID of an item,
        /// whether via IMC or default value.
        ///
        /// A value of -1 indicates that material sets are not used at all on this item.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public async Task <int> GetMaterialSetId(IItemModel item)
        {
            var root = item.GetRoot();

            if (root == null)
            {
                return(-1);
            }

            if (root.Info.PrimaryType == XivItemType.human)
            {
                if (root.Info.SecondaryType == XivItemType.hair ||
                    root.Info.SecondaryType == XivItemType.tail ||
                    root.Info.SecondaryType == XivItemType.body)
                {
                    // These use material sets (always set 1), but have no IMC file.
                    return(1);
                }
                else
                {
                    return(-1);
                }
            }
            else if (root.Info.PrimaryType == XivItemType.indoor || root.Info.PrimaryType == XivItemType.outdoor)
            {
                return(-1);
            }
            else
            {
                try
                {
                    var entry = await GetImcInfo(item);

                    return(entry.MaterialSet);
                } catch
                {
                    return(-1);
                }
            }
        }
Esempio n. 3
0
        public async Task <List <string> > GetDemiHumanMountModelEquipPartList(IItemModel itemModel)
        {
            var equipPartList = new List <string>();

            var index = new Index(_gameDirectory);

            var id      = itemModel.ModelInfo.PrimaryID.ToString().PadLeft(4, '0');
            var bodyVer = itemModel.ModelInfo.SecondaryID.ToString().PadLeft(4, '0');
            var root    = itemModel.GetRoot();


            var mdlFolder = $"chara/demihuman/d{id}/obj/equipment/e{bodyVer}/model";

            var files = await index.GetAllHashedFilesInFolder(HashGenerator.GetHash(mdlFolder), XivDataFile._04_Chara);

            if (root == null || root.Info.Slot == null)
            {
                foreach (var slotAbr in SlotAbbreviationDictionary)
                {
                    var mdlFile = $"d{id}e{bodyVer}_{slotAbr.Value}.mdl";

                    if (files.Contains(HashGenerator.GetHash(mdlFile)))
                    {
                        equipPartList.Add(slotAbr.Key);
                    }
                }
            }
            else
            {
                var niceSlotName = SlotAbbreviationDictionary.FirstOrDefault(x => x.Value == root.Info.Slot).Key;
                if (!string.IsNullOrEmpty(niceSlotName))
                {
                    equipPartList.Add(niceSlotName);
                }
            }

            return(equipPartList);
        }
Esempio n. 4
0
        public async Task DisableMod()
        {
            _view.SaveButton.IsEnabled    = false;
            _view.CancelButton.IsEnabled  = false;
            _view.DisableButton.IsEnabled = false;
            _view.DisableButton.Content   = UIStrings.Working_Ellipsis;
            var files = new HashSet <string>();

            var root = _item.GetRoot();

            if (root == null || !Imc.UsesImc(root))
            {
                // This is the only copy of the material we know how to find.
                files.Add(_material.MTRLPath);
            }
            else
            {
                var imc  = new Imc(XivCache.GameInfo.GameDirectory);
                var info = await imc.GetFullImcInfo(_item);

                var entries      = info.GetAllEntries(root.Info.Slot);
                var materialSets = entries.Select(x => x.MaterialSet).ToHashSet();

                var extract = new Regex("(v[0-9]{4})");
                var rep     = extract.Match(_material.MTRLPath).Groups[1].Value;

                // Remove the material in all of the referenced material sets.
                foreach (var setId in materialSets)
                {
                    var newPath = _material.MTRLPath.Replace(rep, "v" + setId.ToString().PadLeft(4, '0'));
                    files.Add(newPath);
                }
            }

            try
            {
                foreach (var file in files)
                {
                    var modEntry = await _modding.TryGetModEntry(file);

                    if (modEntry == null)
                    {
                        continue;
                    }

                    // If the file is a custom addition, and not a modification.
                    if (modEntry.IsCustomFile())
                    {
                        await _modding.DeleteMod(file);
                    }
                    else
                    {
                        await _modding.ToggleModStatus(file, false);
                    }
                }
            } catch (Exception ex)
            {
                FlexibleMessageBox.Show("Unable to delete Mod.\n\nError: " + ex.Message, "Mod Delete Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            _view.Close(false);
        }
Esempio n. 5
0
        public async Task AsyncInit()
        {
            var root = _item.GetRoot();

            if (root == null)
            {
                return;
            }

            var gd   = XivCache.GameInfo.GameDirectory;
            var lang = XivCache.GameInfo.GameLanguage;
            var df   = IOUtil.GetDataFileFromPath(root.Info.GetRootFile());

            var _index    = new Index(gd);
            var _mtrl     = new Mtrl(XivCache.GameInfo.GameDirectory);
            var _mdl      = new Mdl(gd, df);
            var _imc      = new Imc(gd);
            var raceRegex = new Regex("c([0-9]{4})[^b]");

            ItemNameBox.Text = _item.Name;

            var setName = root.Info.GetBaseFileName(false);

            SetLabel.Text = "Set: " + setName;

            if (!String.IsNullOrWhiteSpace(root.Info.Slot))
            {
                var niceSlot = Mdl.SlotAbbreviationDictionary.FirstOrDefault(x => x.Value == root.Info.Slot);
                if (niceSlot.Key != null)
                {
                    SlotLabel.Text = "Slot: " + niceSlot.Key + " (" + root.Info.Slot + ")";
                }
                else
                {
                    SlotLabel.Text = "Slot: Unknown (" + root.Info.Slot + ")";
                }
            }
            else
            {
                SlotLabel.Text = "Slot: --";
            }

            var usesImc = Imc.UsesImc(_item);

            if (usesImc)
            {
                VariantLabel.Text = "Variant: " + _item.ModelInfo.ImcSubsetID;
            }
            else
            {
                VariantLabel.Text = "Variant: --";
            }

            var mSet = await _imc.GetMaterialSetId(_item);

            if (mSet > 0)
            {
                MaterialSetLabel.Text = "Material Set: " + mSet;
            }
            else
            {
                MaterialSetLabel.Text = "Material Set: --";
            }

            var races = XivRaces.PlayableRaces;

            var models = await root.GetModelFiles();

            var materials = await root.GetMaterialFiles(mSet);

            #region Race Chart
            var rowIdx = 1;
            foreach (var race in races)
            {
                var rCode = race.GetRaceCode();

                var row = new RowDefinition();
                row.Height = new GridLength(30);
                RacialGrid.RowDefinitions.Add(row);

                var lBase = new Label();
                lBase.Content = race.GetDisplayName();
                lBase.SetValue(Grid.RowProperty, rowIdx);

                RacialGrid.Children.Add(lBase);

                XivRace?usedMdlRace = race;

                string usedMdl = null;;
                if (race != XivRace.All_Races)
                {
                    // Check if the race has a model.
                    var mdl = models.FirstOrDefault(x => x.Contains("c" + rCode));
                    if (mdl == null)
                    {
                        // Gotta see which race they're shared from.
                        var node   = XivRaceTree.GetNode(race);
                        var parent = node.Parent;

                        while (parent != null)
                        {
                            var code = parent.Race.GetRaceCode();
                            mdl = models.FirstOrDefault(x => x.Contains("c" + code));
                            if (mdl != null)
                            {
                                usedMdlRace = parent.Race;
                                usedMdl     = mdl;
                                break;
                            }
                            parent = parent.Parent;
                        }

                        if (mdl == null)
                        {
                            // No model exists for this item.
                            usedMdlRace = null;
                        }
                    }
                    else
                    {
                        usedMdl = mdl;
                    }
                }

                var mdlRaceString = "None";
                if (usedMdlRace == race)
                {
                    mdlRaceString = "Own";
                }
                else
                {
                    if (usedMdlRace != null)
                    {
                        mdlRaceString = ((XivRace)usedMdlRace).GetDisplayName();
                    }
                }

                XivRace?usedMtrlRace = usedMdlRace;
                if (race != XivRace.All_Races)
                {
                    if (usedMdlRace == null)
                    {
                        usedMtrlRace = null;
                    }
                    else
                    {
                        // Get the materials used by this racial's model.
                        var mdl          = usedMdl;
                        var mdlMaterials = await XivCache.GetChildFiles(mdl);

                        var mtrl = mdlMaterials.FirstOrDefault(x => raceRegex.IsMatch(x));

                        if (mtrl == null)
                        {
                            usedMtrlRace = null;
                        }
                        else
                        {
                            var code = raceRegex.Match(mtrl).Groups[1].Value;
                            usedMtrlRace = XivRaces.GetXivRace(code);
                            if (usedMtrlRace == XivRace.All_Races)
                            {
                                usedMtrlRace = null;
                            }
                        }
                    }
                }

                var mtrlRaceString = "None";
                if (usedMtrlRace == race)
                {
                    mtrlRaceString = "Own";
                }
                else
                {
                    if (usedMtrlRace != null)
                    {
                        mtrlRaceString = ((XivRace)usedMtrlRace).GetDisplayName();
                    }
                }

                var lMdl = new Label();
                lMdl.Content = mdlRaceString;
                lMdl.SetValue(Grid.RowProperty, rowIdx);
                lMdl.SetValue(Grid.ColumnProperty, 1);
                RacialGrid.Children.Add(lMdl);

                var lMtrl = new Label();
                lMtrl.Content = mtrlRaceString;
                lMtrl.SetValue(Grid.RowProperty, rowIdx);
                lMtrl.SetValue(Grid.ColumnProperty, 2);
                RacialGrid.Children.Add(lMtrl);


                rowIdx++;
            }
            #endregion


            if (Imc.UsesImc(_item) && _item.ModelInfo != null)
            {
                var myImcSubsetId = _item.ModelInfo.ImcSubsetID;
                var allItems      = await root.GetAllItems();

                var fInfo = await _imc.GetFullImcInfo(_item);

                var entries = fInfo.GetAllEntries(_item.GetItemSlotAbbreviation(), true);

                foreach (var item in allItems)
                {
                    SameModelItems.Add(new KeyValuePair <string, IItem>(item.Name, item));
                    if (entries.Count > item.ModelInfo.ImcSubsetID)
                    {
                        var imSet = entries[item.ModelInfo.ImcSubsetID].MaterialSet;

                        if (mSet == imSet)
                        {
                            SameMSetItems.Add(new KeyValuePair <string, IItem>(item.Name, item));
                        }
                    }
                    if (item.ModelInfo.ImcSubsetID == myImcSubsetId)
                    {
                        SameVariantItems.Add(new KeyValuePair <string, IItem>(item.Name, item));
                    }
                }
            }
        }