Exemple #1
0
        /// <summary>
        /// Gets the available parts for the selected item given a specified race
        /// </summary>
        private void RaceComboBoxChanged()
        {
            if (selectedCategory != "UI")
            {
                PartComboBox = MTRL.GetMTRLParts(selectedItem, SelectedRace.ID, imcVersion, selectedCategory);
            }
            else
            {
                PartComboBox = new ObservableCollection <ComboBoxInfo>()
                {
                    new ComboBoxInfo()
                    {
                        Name = "-", ID = "-", IsNum = false
                    }
                };
            }

            if (PartComboBox.Count > 1)
            {
                PartEnabled = true;
            }
            else
            {
                PartEnabled = false;
            }

            PartIndex = 0;
        }
Exemple #2
0
        protected override void Parse(Stream s)
        {
            BinaryReader r = new BinaryReader(s);

            tag = r.ReadUInt32();
            if (tag != (uint)FOURCC("MATD"))
            {
                throw new InvalidDataException(String.Format("Invalid Tag read: '{0}'; expected: 'MATD'; at 0x{1:X8}", FOURCC(tag), s.Position));
            }
            version          = r.ReadUInt32();
            materialNameHash = r.ReadUInt32();
            shader           = (ShaderType)r.ReadUInt32();
            uint length = r.ReadUInt32();
            long start;

            if (version < 0x00000103)
            {
                start = s.Position;
                mtrl  = new MTRL(OnRCOLChanged, s);
            }
            else
            {
                isVideoSurface    = r.ReadInt32() != 0;
                isPaintingSurface = r.ReadInt32() != 0;
                start             = s.Position;
                mtnf = new MTNF(OnRCOLChanged, s);
            }

            if (start + length != s.Position)
            {
                throw new InvalidDataException(string.Format("Invalid length 0x{0:X8} at 0x{1:X8}", length, s.Position));
            }
        }
        /// <summary>
        /// Updates the displayed image
        /// </summary>
        /// <remarks>
        /// This is called when an image has either been imported or enabled/disabled
        /// </remarks>
        /// <param name="offset">The new offset for the image.</param>
        /// <param name="isColor">Is the image being udpated a color set.</param>
        public void UpdateImage(int offset, bool isColor)
        {
            if (isColor)
            {
                var colorBMP = MTRL.GetColorBitmap(offset);

                TextureType       = "A16B16G16R16F";
                TextureDimensions = "(4 x 16)";

                alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(colorBMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                var removeAlphaBitmap = SetAlpha(colorBMP, 255);

                noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                colorBMP.Dispose();
                removeAlphaBitmap.Dispose();
            }
            else
            {
                if (SelectedMap.ID.Contains("vfx"))
                {
                    texData = TEX.GetVFX(offset);
                }
                else
                {
                    texData = TEX.GetTex(offset);
                }

                TextureType       = texData.TypeString;
                TextureDimensions = "(" + texData.Width + " x " + texData.Height + ")";

                alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                var removeAlphaBitmap = SetAlpha(texData.BMP, 255);

                noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                texData.Dispose();
                removeAlphaBitmap.Dispose();
            }

            if (AlphaChecked)
            {
                ImageSource = alphaBitmap;
            }
            else
            {
                ImageSource = noAlphaBitmap;
            }
        }
        /// <summary>
        /// Gets the available types or maps for the currently selcted item given a specified race and part
        /// Hair, Face, and Mounts that are demihuman, contain types, all others do not.
        /// </summary>
        private void PartComboBoxChanged()
        {
            var info = MTRL.GetMTRLData(selectedItem, selectedRace.ID, selectedCategory, selectedPart.Name, imcVersion, "", "", VFXVersion);

            mtrlData = info.Item1;

            if (selectedItem.ItemName.Equals(Strings.Face) || selectedItem.ItemName.Equals(Strings.Hair))
            {
                TypeComboBox = info.Item2;
                TypeIndex    = 0;
            }
            else if (selectedCategory.Equals(Strings.Mounts))
            {
                bool isDemiHuman = selectedItem.PrimaryMTRLFolder.Contains("demihuman");

                if (isDemiHuman)
                {
                    TypeComboBox = info.Item2;
                    TypeIndex    = 0;
                }
                else
                {
                    MapComboBox = info.Item2;
                    MapIndex    = currMap;
                }
            }
            else
            {
                MapComboBox = info.Item2;
                MapIndex    = currMap;
            }

            if (TypeComboBox.Count > 1)
            {
                TypeEnabled = true;
            }
            else
            {
                TypeEnabled = false;
            }

            if (MapComboBox.Count > 0)
            {
                MapEnabled = true;
            }
            else
            {
                MapEnabled = false;
            }
        }
        /// <summary>
        /// Gets the available parts for the selected item given a specified race
        /// </summary>
        private void RaceComboBoxChanged()
        {
            PartComboBox = MTRL.GetMTRLParts(selectedItem, SelectedRace.ID, imcVersion, selectedCategory);

            if (PartComboBox.Count > 1)
            {
                PartEnabled = true;
            }
            else
            {
                PartEnabled = false;
            }

            PartIndex = 0;
        }
Exemple #6
0
 public MATD(EventHandler handler,
             uint version, uint materialNameHash, ShaderType shader, MTRL mtrl)
     : base(handler, null)
 {
     this.version          = version;
     this.materialNameHash = materialNameHash;
     this.shader           = shader;
     if (version >= 0x00000103)
     {
         throw new ArgumentException("version must be < 0x0103 for MTRLs");
     }
     this.mtrl = mtrl != null
         ? new MTRL(OnRCOLChanged, mtrl)
         : new MTRL(OnRCOLChanged);
 }
Exemple #7
0
        /// <summary>
        /// Gets the available maps for the currently selected item given a specified race, part, and type
        /// </summary>
        private void TypeComboBoxChanged()
        {
            string type;

            if (selectedCategory.Equals(Strings.Mounts))
            {
                bool isDemiHuman = selectedItem.PrimaryMTRLFolder.Contains("demihuman");

                if (isDemiHuman)
                {
                    type = Info.slotAbr[selectedType.Name];
                }
                else
                {
                    type = selectedType.Name;
                }
            }
            else
            {
                type = selectedType.Name;
            }


            var info = MTRL.GetMTRLDatafromType(selectedItem, selectedRace.ID, selectedPart.Name, type, imcVersion, selectedCategory, "a");

            mtrlData = info.Item1;

            MapComboBox = info.Item2;

            if (MapComboBox.Count > 0)
            {
                MapEnabled = true;
            }
            else
            {
                MapEnabled = false;
            }

            if (MapComboBox.Count < (currMap + 1))
            {
                MapIndex = currMap;
            }
            else
            {
                MapIndex = 0;
            }
        }
Exemple #8
0
        public override Stream UnParse()
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter w  = new BinaryWriter(ms);

            w.Write(tag);
            w.Write(version);
            w.Write(materialNameHash);
            w.Write((uint)shader);
            long lenPos = ms.Position;

            w.Write((uint)0);//length
            long pos;

            if (version < 0x00000103)
            {
                pos = ms.Position;
                if (mtrl == null)
                {
                    mtrl = new MTRL(requestedApiVersion, OnRCOLChanged);
                }
                mtrl.UnParse(ms);
            }
            else
            {
                w.Write(isVideoSurface ? 1 : 0);
                w.Write(isPaintingSurface ? 1 : 0);
                pos = ms.Position;
                if (mtnf == null)
                {
                    mtnf = new MTNF(requestedApiVersion, OnRCOLChanged);
                }
                mtnf.UnParse(ms);
            }

            long endPos = ms.Position;

            ms.Position = lenPos;
            w.Write((uint)(endPos - pos));
            ms.Position = endPos;

            return(ms);
        }
 public MATD(int apiVersion, EventHandler handler,
             uint version, uint materialNameHash, ShaderType shader, bool isVideoSurface, bool isPaintingSurface, MTNF mtnf)
     : base(apiVersion, handler, null)
 {
     this.version          = version;
     this.materialNameHash = materialNameHash;
     this.shader           = shader;
     if (checking)
     {
         if (version < 0x00000103)
         {
             throw new ArgumentException("version must be >= 0x0103 for MTNFs");
         }
     }
     this.isVideoSurface    = isVideoSurface;
     this.isPaintingSurface = isPaintingSurface;
     this.mtrl = mtrl != null
         ? new MTRL(requestedApiVersion, OnRCOLChanged, mtrl)
         : new MTRL(requestedApiVersion, OnRCOLChanged);
 }
        /// <summary>
        /// View Model for TextureView
        /// </summary>
        /// <param name="item">The currently selected item</param>
        /// <param name="category">The category of the selected item</param>
        public TextureViewModel(ItemData item, string category)
        {
            selectedItem     = item;
            selectedCategory = category;

            var imcData = IMC.GetVersion(selectedCategory, selectedItem, false);

            imcVersion = imcData.Item1;
            VFXVersion = imcData.Item2;

            RaceComboBox = MTRL.GetMTRLRaces(selectedItem, selectedCategory, imcVersion);

            if (RaceComboBox.Count > 1)
            {
                RaceEnabled = true;
            }
            else
            {
                RaceEnabled = false;
            }
        }
Exemple #11
0
 public MATD(int APIversion, EventHandler handler, MATD basis)
     : base(APIversion, handler, null)
 {
     this.version          = basis.version;
     this.materialNameHash = basis.materialNameHash;
     this.shader           = basis.shader;
     if (version < 0x00000103)
     {
         this.mtrl = basis.mtrl != null
             ? new MTRL(requestedApiVersion, OnRCOLChanged, basis.mtrl)
             : new MTRL(requestedApiVersion, OnRCOLChanged);
     }
     else
     {
         this.isVideoSurface    = basis.isVideoSurface;
         this.isPaintingSurface = basis.isPaintingSurface;
         this.mtnf = basis.mtnf != null
             ? new MTNF(requestedApiVersion, OnRCOLChanged, basis.mtnf)
             : new MTNF(requestedApiVersion, OnRCOLChanged);
     }
 }
Exemple #12
0
        /// <summary>
        /// View Model for TextureView
        /// </summary>
        /// <param name="item">The currently selected item</param>
        /// <param name="category">The category of the selected item</param>
        public void UpdateTexture(ItemData item, string category)
        {
            selectedItem     = item;
            selectedCategory = category;

            if (!category.Equals("UI"))
            {
                var imcData = IMC.GetVersion(selectedCategory, selectedItem, false);

                imcVersion = imcData.Item1;
                VFXVersion = imcData.Item2;

                RaceComboBox = MTRL.GetMTRLRaces(selectedItem, selectedCategory, imcVersion);
            }
            else
            {
                RaceComboBox = new ObservableCollection <ComboBoxInfo>()
                {
                    new ComboBoxInfo()
                    {
                        Name = "-", ID = "-", IsNum = false
                    }
                };
            }


            if (RaceComboBox.Count > 1)
            {
                RaceEnabled = true;
            }
            else
            {
                RaceEnabled = false;
            }

            RaceIndex = 0;
        }
Exemple #13
0
        /// <summary>
        /// View Model for TextureView from ID
        /// </summary>
        /// <param name="item">The currently selected item</param>
        /// <param name="category">The category of the selected item</param>
        public void UpdateTextureFromID(ItemData item, string raceID, string category, string part, string variant)
        {
            selectedItem     = item;
            selectedCategory = category;
            imcVersion       = variant;
            VFXVersion       = "0000";

            RaceComboBox = MTRL.GetMTRLRaces(selectedItem, selectedCategory, imcVersion);

            if (RaceComboBox.Count > 1)
            {
                RaceEnabled = true;
            }
            else
            {
                RaceEnabled = false;
            }

            RaceIndex = 0;

            //var info = MTRL.GetMTRLData(item, raceID, category, part, variant, "", "", "0000");
            //MapComboBox = info.Item2;
            //MapIndex = 0;
        }
        public ModListModel ParseEntry(JsonEntry entry)
        {
            ModListModel mlm = new ModListModel();
            string       race, map, part, type;

            if (entry.fullPath.Contains("weapon") || entry.fullPath.Contains("accessory") || entry.fullPath.Contains("decal") || entry.fullPath.Contains("vfx") || entry.fullPath.Contains("ui/"))
            {
                race = Strings.All;
            }
            else if (entry.fullPath.Contains("monster") || entry.fullPath.Contains("demihuman"))
            {
                race = Strings.Monster;
            }
            else
            {
                race = entry.fullPath.Substring(entry.fullPath.LastIndexOf('/'));

                if ((entry.fullPath.Contains("_fac_") || entry.fullPath.Contains("_etc_") || entry.fullPath.Contains("_acc_")) && Properties.Settings.Default.DX_Ver.Equals(Strings.DX11))
                {
                    race = race.Substring(race.LastIndexOf("--c") + 3, 4);
                }
                else if (entry.fullPath.Contains("_fac_") || entry.fullPath.Contains("_etc_") || entry.fullPath.Contains("_acc_"))
                {
                    race = race.Substring(race.LastIndexOf("/c") + 2, 4);
                }
                else if (entry.fullPath.Contains("_c_"))
                {
                    race = race.Substring(race.IndexOf("_c") + 2, 4);
                }
                else
                {
                    race = race.Substring(race.LastIndexOf('c') + 1, 4);
                }
                race = Info.IDRace[race];
            }

            mlm.Race = race;


            if (entry.fullPath.Contains("_d."))
            {
                map = Strings.Diffuse;
            }
            else if (entry.fullPath.Contains("_n."))
            {
                map = Strings.Normal;
            }
            else if (entry.fullPath.Contains("_s."))
            {
                map = Strings.Specular;
            }
            else if (entry.fullPath.Contains("material"))
            {
                map = Strings.ColorSet;
            }
            else if (entry.fullPath.Contains("model"))
            {
                map = "3D";
            }
            else if (entry.fullPath.Contains("ui/"))
            {
                map = "UI";
            }
            else
            {
                map = Strings.Mask;
            }

            mlm.Map = map;


            if (entry.fullPath.Contains("_b_"))
            {
                part = "b";
            }
            else if (entry.fullPath.Contains("_c_"))
            {
                part = "c";
            }
            else if (entry.fullPath.Contains("_d_"))
            {
                part = "d";
            }
            else if (entry.fullPath.Contains("decal"))
            {
                part = entry.fullPath.Substring(entry.fullPath.LastIndexOf('_') + 1, entry.fullPath.LastIndexOf('.') - (entry.fullPath.LastIndexOf('_') + 1));
            }
            else
            {
                part = "a";
            }

            mlm.Part = part;


            if (entry.fullPath.Contains("_iri_"))
            {
                type = "Iris";
            }
            else if (entry.fullPath.Contains("_etc_"))
            {
                type = "Etc.";
            }
            else if (entry.fullPath.Contains("_fac_"))
            {
                type = "Face";
            }
            else if (entry.fullPath.Contains("_hir_"))
            {
                type = "Hair";
            }
            else if (entry.fullPath.Contains("_acc_"))
            {
                type = "Accessory";
            }
            else if (entry.fullPath.Contains("demihuman"))
            {
                type = entry.fullPath.Substring(entry.fullPath.LastIndexOf('_') - 3, 3);
                type = (Info.slotAbr).FirstOrDefault(x => x.Value == type).Key;
            }
            else
            {
                type = "-";
            }

            mlm.Type = type;

            if (entry.fullPath.Contains("material"))
            {
                var info = MTRL.GetMTRLInfo(entry.modOffset, false);

                var bitmap = TEX.TextureToBitmap(info.ColorData, 9312, 4, 16);

                mlm.BMP = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            }
            else if (entry.fullPath.Contains("model"))
            {
                mlm.BMP = new BitmapImage(new Uri("pack://application:,,,/FFXIV TexTools 2;component/Resources/3DModel.png"));
            }
            else
            {
                TEXData texData;

                if (entry.fullPath.Contains("vfx"))
                {
                    texData = TEX.GetVFX(entry.modOffset, entry.datFile);
                }
                else
                {
                    if (entry.fullPath.Contains("icon"))
                    {
                        texData = TEX.GetTex(entry.modOffset, entry.datFile);
                    }
                    else
                    {
                        texData = TEX.GetTex(entry.modOffset, entry.datFile);
                    }
                }

                mlm.BMP = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            }

            var offset = Helper.GetDataOffset(FFCRC.GetHash(entry.fullPath.Substring(0, entry.fullPath.LastIndexOf("/"))), FFCRC.GetHash(Path.GetFileName(entry.fullPath)), entry.datFile);

            if (offset == entry.modOffset)
            {
                mlm.ActiveBorder  = Brushes.Green;
                mlm.Active        = Brushes.Transparent;
                mlm.ActiveOpacity = 1;
            }
            else if (offset == entry.originalOffset)
            {
                mlm.ActiveBorder  = Brushes.Red;
                mlm.Active        = Brushes.Gray;
                mlm.ActiveOpacity = 0.5f;
            }
            else
            {
                mlm.ActiveBorder  = Brushes.Red;
                mlm.Active        = Brushes.Red;
                mlm.ActiveOpacity = 1;
            }

            mlm.Entry = entry;

            return(mlm);
        }
Exemple #15
0
        /// <summary>
        /// Gets the texture data and displays it for the currently selected item given a specified race, part, type(if applicable), and map
        /// </summary>
        private void MapComboBoxChanged()
        {
            if (saveClone != null)
            {
                //saveClone.UnlockBits(cloneLock);
                saveClone.Dispose();
            }

            Bitmap colorBmp = null;
            int    offset   = 0;
            bool   isVFX    = false;
            bool   isUI     = false;

            if (selectedMap.Name.Equals(Strings.Normal))
            {
                fullPath       = mtrlData.NormalPath;
                offset         = mtrlData.NormalOffset;
                FullPathString = fullPath;
            }
            else if (selectedMap.Name.Equals(Strings.Specular))
            {
                fullPath       = mtrlData.SpecularPath;
                offset         = mtrlData.SpecularOffset;
                FullPathString = fullPath;
            }
            else if (selectedMap.Name.Equals(Strings.Diffuse))
            {
                fullPath       = mtrlData.DiffusePath;
                offset         = mtrlData.DiffuseOffset;
                FullPathString = fullPath;
            }
            else if (selectedMap.Name.Equals(Strings.Mask) || selectedMap.Name.Equals(Strings.Skin))
            {
                if (selectedItem.ItemName.Equals(Strings.Face_Paint) || selectedItem.ItemName.Equals(Strings.Equipment_Decals))
                {
                    string part;
                    if (selectedItem.ItemName.Equals(Strings.Equipment_Decals))
                    {
                        if (!SelectedPart.Name.Contains("stigma"))
                        {
                            part = selectedPart.Name.PadLeft(3, '0');
                        }
                        else
                        {
                            part = SelectedPart.Name;
                        }
                    }
                    else
                    {
                        part = selectedPart.Name;
                    }

                    fullPath = String.Format(mtrlData.MaskPath, part);
                    offset   = MTRL.GetDecalOffset(selectedItem.ItemName, selectedPart.Name);
                }
                else
                {
                    fullPath = mtrlData.MaskPath;
                    offset   = mtrlData.MaskOffset;
                }
                FullPathString = fullPath;
            }
            else if (selectedMap.Name.Equals(Strings.ColorSet))
            {
                colorBmp       = TEX.TextureToBitmap(mtrlData.ColorData, 9312, 4, 16);
                fullPath       = mtrlData.MTRLPath;
                FullPathString = fullPath;
            }
            else if (SelectedMap.Name.Contains("Icon"))
            {
                if (SelectedMap.Name.Contains("HQ"))
                {
                    fullPath = mtrlData.UIHQPath;
                    offset   = mtrlData.UIHQOffset;
                }
                else
                {
                    fullPath = mtrlData.UIPath;
                    offset   = mtrlData.UIOffset;
                }
                FullPathString = fullPath;
                isUI           = true;
            }
            else if (selectedItem.ItemCategory.Equals(Strings.Maps))
            {
                if (selectedMap.Name.Contains("HighRes Map"))
                {
                    fullPath = string.Format(mtrlData.UIPath, "_m");
                    offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                }
                else if (selectedMap.Name.Contains("LowRes Map"))
                {
                    fullPath = string.Format(mtrlData.UIPath, "_s");
                    offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                }
                else if (selectedMap.Name.Contains("PoI"))
                {
                    fullPath = string.Format(mtrlData.UIPath, "d");
                    offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                }
                else if (selectedMap.Name.Contains("HighRes Mask"))
                {
                    fullPath = string.Format(mtrlData.UIPath, "m_m");
                    offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                }
                else if (selectedMap.Name.Contains("LowRes Mask"))
                {
                    fullPath = string.Format(mtrlData.UIPath, "m_s");
                    offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                }
                FullPathString = fullPath;
                isUI           = true;
            }
            else if (selectedItem.ItemCategory.Equals("HUD") || selectedItem.ItemCategory.Equals("LoadingImage"))
            {
                fullPath       = mtrlData.UIPath;
                offset         = mtrlData.UIOffset;
                FullPathString = fullPath;

                isUI = true;
            }
            else
            {
                fullPath = SelectedMap.ID;
                var VFXFolder = fullPath.Substring(0, fullPath.LastIndexOf("/"));
                var VFXFile   = fullPath.Substring(fullPath.LastIndexOf("/") + 1);

                offset = Helper.GetDataOffset(FFCRC.GetHash(VFXFolder), FFCRC.GetHash(VFXFile), Strings.ItemsDat);

                FullPathString = fullPath;

                isVFX = true;
            }

            string    line;
            JsonEntry modEntry  = null;
            bool      inModList = false;

            try
            {
                using (StreamReader sr = new StreamReader(Properties.Settings.Default.Modlist_Directory))
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        modEntry = JsonConvert.DeserializeObject <JsonEntry>(line);
                        if (modEntry.fullPath.Equals(fullPath))
                        {
                            inModList = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("[TVM] Error Accessing .modlist File \n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (inModList)
            {
                var currOffset = Helper.GetDataOffset(FFCRC.GetHash(modEntry.fullPath.Substring(0, modEntry.fullPath.LastIndexOf("/"))), FFCRC.GetHash(Path.GetFileName(modEntry.fullPath)), modEntry.datFile);

                if (currOffset == modEntry.modOffset)
                {
                    ActiveToggle = "Disable";
                }
                else if (currOffset == modEntry.originalOffset)
                {
                    ActiveToggle = "Enable";
                }
                else
                {
                    ActiveToggle = "Error";
                }

                ActiveEnabled = true;
            }
            else
            {
                ActiveEnabled = false;
                ActiveToggle  = "Enable/Disable";
            }

            if (offset == 0)
            {
                TextureType = "Type: 16.16.16.16f ABGR\nMipMaps: None";

                TextureDimensions = "(4 x 16)";

                alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(colorBmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                alphaBitmap.Freeze();

                var removeAlphaBitmap = SetAlpha(colorBmp, 255);

                noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                noAlphaBitmap.Freeze();

                colorBmp.Dispose();
                removeAlphaBitmap.Dispose();
            }
            else
            {
                if (!isVFX)
                {
                    if (!isUI)
                    {
                        texData = TEX.GetTex(offset, Strings.ItemsDat);
                    }
                    else
                    {
                        texData = TEX.GetTex(offset, Strings.UIDat);
                    }
                }
                else
                {
                    texData = TEX.GetVFX(offset, Strings.ItemsDat);
                }

                string mipMaps = "Yes (" + texData.MipCount + ")";
                if (texData.MipCount < 1)
                {
                    mipMaps = "None";
                }
                TextureType = "Type: " + texData.TypeString + "\nMipMaps: " + mipMaps;

                TextureDimensions = "(" + texData.Width + " x " + texData.Height + ")";

                var clonerect = new Rectangle(0, 0, texData.Width, texData.Height);
                saveClone = texData.BMP.Clone(new Rectangle(0, 0, texData.Width, texData.Height), PixelFormat.Format32bppArgb);

                alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                alphaBitmap.Freeze();

                if (!isUI)
                {
                    var removeAlphaBitmap = SetAlpha(texData.BMP, 255);

                    noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    noAlphaBitmap.Freeze();

                    removeAlphaBitmap.Dispose();
                }
            }


            try
            {
                ImageEffect = new ColorChannels()
                {
                    Channel = new System.Windows.Media.Media3D.Point4D(1.0f, 1.0f, 1.0f, 0.0f)
                };
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
            }

            if (!isUI)
            {
                ImageSource = noAlphaBitmap;

                SetColorChannelFilter(imageEffect);

                ChannelsEnabled = true;
            }
            else
            {
                ImageSource = alphaBitmap;

                SetColorChannelFilter(imageEffect);

                ChannelsEnabled = true;
            }

            SaveEnabled = true;

            texData.Dispose();

            string dxPath = Path.GetFileNameWithoutExtension(fullPath);

            string savePath = Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemName + "/" + dxPath + ".dds";

            if (selectedCategory.Equals("UI"))
            {
                savePath = Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemCategory + "/" + dxPath + ".dds";
            }

            if (File.Exists(savePath))
            {
                ImportEnabled = true;
            }
            else
            {
                ImportEnabled = false;
            }

            string folderPath = Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemName;

            if (selectedCategory.Equals("UI"))
            {
                folderPath = Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemCategory;
            }

            if (Directory.Exists(folderPath))
            {
                OpenEnabled = true;
            }
            else
            {
                OpenEnabled = false;
            }
        }
Exemple #16
0
        /// <summary>
        /// Gets the available types or maps for the currently selcted item given a specified race and part
        /// Hair, Face, and Mounts that are demihuman, contain types, all others do not.
        /// </summary>
        private void PartComboBoxChanged()
        {
            if (selectedCategory != "UI")
            {
                var body    = "";
                var modelID = selectedItem.PrimaryModelID;
                var imc     = imcVersion;
                var vfx     = VFXVersion;
                var part    = selectedPart.Name;

                if (selectedItem.PrimaryMTRLFolder != null)
                {
                    if (selectedItem.PrimaryMTRLFolder.Contains("weapon"))
                    {
                        var imcData = IMC.GetVersion(selectedCategory, selectedItem, false);

                        imc = imcData.Item1;
                        vfx = imcData.Item2;

                        modelID = selectedItem.PrimaryModelID;
                        body    = selectedItem.PrimaryModelBody;
                        part    = selectedPart.Name;
                    }
                }


                if (SelectedPart.Name.Equals("s"))
                {
                    var imcData = IMC.GetVersion(selectedCategory, selectedItem, true);

                    imc = imcData.Item1;
                    vfx = imcData.Item2;

                    modelID = selectedItem.SecondaryModelID;
                    body    = selectedItem.SecondaryModelBody;
                    part    = "a";

                    if (body == null)
                    {
                        body = "0001";
                    }
                }

                if (selectedCategory.Equals(Strings.Pets))
                {
                    body = "a";
                }
                var info = MTRL.GetMTRLData(selectedItem, selectedRace.ID, selectedCategory, part, imc, body, modelID, vfx);
                mtrlData = info.Item1;

                if (selectedItem.ItemName.Equals(Strings.Face) || selectedItem.ItemName.Equals(Strings.Hair))
                {
                    TypeComboBox = info.Item2;
                    TypeIndex    = 0;
                }
                else if (selectedCategory.Equals(Strings.Mounts))
                {
                    bool isDemiHuman = selectedItem.PrimaryMTRLFolder.Contains("demihuman");

                    if (isDemiHuman)
                    {
                        TypeComboBox = info.Item2;
                        TypeIndex    = 0;
                    }
                    else
                    {
                        MapComboBox = info.Item2;
                        if (MapComboBox.Count < (currMap + 1))
                        {
                            MapIndex = 0;
                        }
                        else
                        {
                            MapIndex = currMap;
                        }
                        TypeComboBox.Clear();
                    }
                }
                else
                {
                    MapComboBox = info.Item2;
                    if (MapComboBox.Count < (currMap + 1))
                    {
                        MapIndex = 0;
                    }
                    else
                    {
                        MapIndex = currMap;
                    }
                    TypeComboBox.Clear();
                }
            }
            else
            {
                var info = MTRL.GetUIData(selectedItem);
                mtrlData    = info.Item1;
                MapComboBox = info.Item2;
                if (MapComboBox.Count < (currMap + 1))
                {
                    MapIndex = 0;
                }
                else
                {
                    MapIndex = currMap;
                }
                TypeComboBox.Clear();
            }


            if (TypeComboBox.Count > 1)
            {
                TypeEnabled = true;
            }
            else
            {
                TypeEnabled = false;
            }

            if (MapComboBox.Count > 0)
            {
                MapEnabled = true;
            }
            else
            {
                MapEnabled = false;
            }
        }
        /// <summary>
        /// Gets the texture data and displays it for the currently selected item given a specified race, part, type(if applicable), and map
        /// </summary>
        private void MapComboBoxChanged()
        {
            Bitmap colorBmp = null;
            int    offset   = 0;
            bool   isVFX    = false;

            if (selectedMap.Name.Equals(Strings.Normal))
            {
                fullPath       = mtrlData.NormalPath;
                offset         = mtrlData.NormalOffset;
                FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]";
            }
            else if (selectedMap.Name.Equals(Strings.Specular))
            {
                fullPath       = mtrlData.SpecularPath;
                offset         = mtrlData.SpecularOffset;
                FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]";
            }
            else if (selectedMap.Name.Equals(Strings.Diffuse))
            {
                fullPath       = mtrlData.DiffusePath;
                offset         = mtrlData.DiffuseOffset;
                FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]";
            }
            else if (selectedMap.Name.Equals(Strings.Mask) || selectedMap.Name.Equals(Strings.Skin))
            {
                if (selectedItem.ItemName.Equals(Strings.Face_Paint) || selectedItem.ItemName.Equals(Strings.Equipment_Decals))
                {
                    string part;
                    if (selectedItem.ItemName.Equals(Strings.Equipment_Decals))
                    {
                        part = selectedPart.Name.PadLeft(3, '0');
                    }
                    else
                    {
                        part = selectedPart.Name;
                    }

                    fullPath       = String.Format(mtrlData.MaskPath, part);
                    offset         = MTRL.GetDecalOffset(selectedItem.ItemName, selectedPart.Name);
                    FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]";
                }
                else
                {
                    fullPath       = mtrlData.MaskPath;
                    offset         = mtrlData.MaskOffset;
                    FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]";
                }
            }
            else if (selectedMap.Name.Equals(Strings.ColorSet))
            {
                colorBmp       = TEX.TextureToBitmap(mtrlData.ColorData, 9312, 4, 16);
                fullPath       = mtrlData.MTRLPath;
                FullPathString = fullPath + " [" + FFCRC.GetHash(fullPath) + "]";
            }
            else
            {
                fullPath = SelectedMap.ID;
                var VFXFolder = fullPath.Substring(0, fullPath.LastIndexOf("/"));
                var VFXFile   = fullPath.Substring(fullPath.LastIndexOf("/") + 1);

                offset = Helper.GetItemOffset(FFCRC.GetHash(VFXFolder), FFCRC.GetHash(VFXFile));

                FullPathString = fullPath;

                isVFX = true;
            }

            if (Properties.Settings.Default.Mod_List == 0)
            {
                string    line;
                JsonEntry modEntry  = null;
                bool      inModList = false;
                try
                {
                    using (StreamReader sr = new StreamReader(Info.modListDir))
                    {
                        while ((line = sr.ReadLine()) != null)
                        {
                            modEntry = JsonConvert.DeserializeObject <JsonEntry>(line);
                            if (modEntry.fullPath.Equals(fullPath))
                            {
                                inModList = true;
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("[Main] Error Accessing .modlist File \n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (inModList)
                {
                    var currOffset = Helper.GetItemOffset(FFCRC.GetHash(modEntry.fullPath.Substring(0, modEntry.fullPath.LastIndexOf("/"))), FFCRC.GetHash(Path.GetFileName(modEntry.fullPath)));

                    if (currOffset == modEntry.modOffset)
                    {
                        ActiveToggle = "Disable";
                    }
                    else if (currOffset == modEntry.originalOffset)
                    {
                        ActiveToggle = "Enable";
                    }
                    else
                    {
                        ActiveToggle = "Error";
                    }

                    ActiveEnabled = true;
                }
                else
                {
                    ActiveEnabled = false;
                    ActiveToggle  = "Enable/Disable";
                }
            }
            else
            {
                ActiveEnabled = false;
                ActiveToggle  = "Enable/Disable";
            }

            if (offset == 0)
            {
                TextureType = "A16B16G16R16F";
                textureType = "A16B16G16R16F";

                TextureDimensions = "(4 x 16)";
                textureDimensions = "(4 x 16)";


                alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(colorBmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                var removeAlphaBitmap = SetAlpha(colorBmp, 255);

                noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                colorBmp.Dispose();
                removeAlphaBitmap.Dispose();
            }
            else
            {
                if (!isVFX)
                {
                    texData = TEX.GetTex(offset);
                }
                else
                {
                    texData = TEX.GetVFX(offset);
                }

                TextureType = texData.TypeString;

                TextureDimensions = "(" + texData.Width + " x " + texData.Height + ")";

                alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                var removeAlphaBitmap = SetAlpha(texData.BMP, 255);

                noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                removeAlphaBitmap.Dispose();
            }

            try
            {
                ImageEffect = new ColorChannels()
                {
                    Channel = new System.Windows.Media.Media3D.Point4D(1.0f, 1.0f, 1.0f, 0.0f)
                };
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
            }

            ImageSource = noAlphaBitmap;

            SetColorChannelFilter();

            SaveEnabled = true;

            texData.Dispose();

            string dxPath = Path.GetFileNameWithoutExtension(fullPath);

            if (File.Exists(Properties.Settings.Default.Save_Directory + "/" + selectedCategory + "/" + selectedItem.ItemName + "/" + dxPath + ".dds"))
            {
                ImportEnabled = true;
            }
            else
            {
                ImportEnabled = false;
            }
        }
Exemple #18
0
        public void SaveAllDDS()
        {
            foreach (var m in MapComboBox)
            {
                int offset = 0;

                if (m.Name.Equals(Strings.Normal))
                {
                    fullPath = mtrlData.NormalPath;
                    offset   = mtrlData.NormalOffset;
                }
                else if (m.Name.Equals(Strings.Specular))
                {
                    fullPath = mtrlData.SpecularPath;
                    offset   = mtrlData.SpecularOffset;
                }
                else if (m.Name.Equals(Strings.Diffuse))
                {
                    fullPath = mtrlData.DiffusePath;
                    offset   = mtrlData.DiffuseOffset;
                }
                else if (m.Name.Equals(Strings.Mask) || m.Name.Equals(Strings.Skin))
                {
                    if (selectedItem.ItemName.Equals(Strings.Face_Paint) || selectedItem.ItemName.Equals(Strings.Equipment_Decals))
                    {
                        string part;
                        if (selectedItem.ItemName.Equals(Strings.Equipment_Decals))
                        {
                            if (!SelectedPart.Name.Contains("stigma"))
                            {
                                part = selectedPart.Name.PadLeft(3, '0');
                            }
                            else
                            {
                                part = SelectedPart.Name;
                            }
                        }
                        else
                        {
                            part = selectedPart.Name;
                        }

                        fullPath = String.Format(mtrlData.MaskPath, part);
                        offset   = MTRL.GetDecalOffset(selectedItem.ItemName, selectedPart.Name);
                    }
                    else
                    {
                        fullPath = mtrlData.MaskPath;
                        offset   = mtrlData.MaskOffset;
                    }
                }
                else if (m.Name.Equals(Strings.ColorSet))
                {
                    fullPath = mtrlData.MTRLPath;
                }
                else if (m.Name.Contains("Icon"))
                {
                    if (m.Name.Contains("HQ"))
                    {
                        fullPath = mtrlData.UIHQPath;
                        offset   = mtrlData.UIHQOffset;
                    }
                    else
                    {
                        fullPath = mtrlData.UIPath;
                        offset   = mtrlData.UIOffset;
                    }
                }
                else if (selectedItem.ItemCategory.Equals(Strings.Maps))
                {
                    if (selectedMap.Name.Contains("HighRes Map"))
                    {
                        fullPath = string.Format(mtrlData.UIPath, "_m");
                        offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                    }
                    else if (selectedMap.Name.Contains("LowRes Map"))
                    {
                        fullPath = string.Format(mtrlData.UIPath, "_s");
                        offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                    }
                    else if (selectedMap.Name.Contains("PoI"))
                    {
                        fullPath = string.Format(mtrlData.UIPath, "d");
                        offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                    }
                    else if (selectedMap.Name.Contains("HighRes Mask"))
                    {
                        fullPath = string.Format(mtrlData.UIPath, "m_m");
                        offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                    }
                    else if (selectedMap.Name.Contains("LowRes Mask"))
                    {
                        fullPath = string.Format(mtrlData.UIPath, "m_s");
                        offset   = mtrlData.UIOffset = int.Parse(selectedMap.ID);
                    }
                }
                else if (selectedItem.ItemCategory.Equals("HUD"))
                {
                    fullPath = mtrlData.UIPath;
                    offset   = mtrlData.UIOffset;
                }
                else
                {
                    fullPath = SelectedMap.ID;
                    var VFXFolder = fullPath.Substring(0, fullPath.LastIndexOf("/"));
                    var VFXFile   = fullPath.Substring(fullPath.LastIndexOf("/") + 1);

                    offset = Helper.GetDataOffset(FFCRC.GetHash(VFXFolder), FFCRC.GetHash(VFXFile), Strings.ItemsDat);
                }

                if (offset != 0)
                {
                    if (m.ID.Contains("vfx"))
                    {
                        texData = TEX.GetVFX(offset, Strings.ItemsDat);
                    }
                    else
                    {
                        if (selectedCategory.Equals("UI"))
                        {
                            texData = TEX.GetTex(offset, Strings.UIDat);
                        }
                        else
                        {
                            texData = TEX.GetTex(offset, Strings.ItemsDat);
                        }
                    }
                }


                SaveTex.SaveDDS(selectedCategory, selectedItem.ItemName, fullPath, m.Name, mtrlData, texData, selectedItem.ItemCategory);
            }
        }
Exemple #19
0
        /// <summary>
        /// Updates the displayed image
        /// </summary>
        /// <remarks>
        /// This is called when an image has either been imported or enabled/disabled
        /// </remarks>
        /// <param name="offset">The new offset for the image.</param>
        /// <param name="isColor">Is the image being udpated a color set.</param>
        public void UpdateImage(int offset, bool isColor)
        {
            try
            {
                if (isColor)
                {
                    var colorBMP = MTRL.GetColorBitmap(offset);

                    TextureType       = "Type: 16.16.16.16f ABGR\nMipMaps: 0";
                    TextureDimensions = "(4 x 16)";

                    alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(colorBMP.Item1.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    alphaBitmap.Freeze();

                    var removeAlphaBitmap = SetAlpha(colorBMP.Item1, 255);

                    noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    noAlphaBitmap.Freeze();

                    mtrlData.ColorData = colorBMP.Item2;

                    colorBMP.Item1.Dispose();
                    removeAlphaBitmap.Dispose();
                }
                else
                {
                    if (SelectedMap.ID.Contains("vfx"))
                    {
                        texData = TEX.GetVFX(offset, Strings.ItemsDat);
                    }
                    else
                    {
                        if (selectedCategory.Equals("UI"))
                        {
                            texData = TEX.GetTex(offset, Strings.UIDat);
                        }
                        else
                        {
                            texData = TEX.GetTex(offset, Strings.ItemsDat);
                        }
                    }

                    string mipMaps = "Yes (" + texData.MipCount + ")";
                    if (texData.MipCount < 1)
                    {
                        mipMaps = "None";
                    }
                    TextureType       = "Type: " + texData.TypeString + "\nMipMaps: " + mipMaps;
                    TextureDimensions = "(" + texData.Width + " x " + texData.Height + ")";

                    alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                    var removeAlphaBitmap = SetAlpha(texData.BMP, 255);

                    noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                    texData.Dispose();
                    removeAlphaBitmap.Dispose();
                }

                if (AlphaChecked)
                {
                    ImageSource = alphaBitmap;
                }
                else
                {
                    ImageSource = noAlphaBitmap;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("[TVM] There was an error updating the image.\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #20
0
        /// <summary>
        /// Gets the MTRL data of the given mesh
        /// </summary>
        /// <param name="mesh">The mesh to obtain the data from</param>
        /// <returns>The MTRLData of the given mesh</returns>
        public MTRLData MTRL3D(int mesh)
        {
            MTRLData mtrlData    = null;
            bool     isDemiHuman = false;

            if (selectedItem.PrimaryMTRLFolder != null)
            {
                isDemiHuman = selectedItem.PrimaryMTRLFolder.Contains("demihuman");
            }

            var itemVersion = IMC.GetVersion(selectedCategory, selectedItem, false).Item1;
            var itemType    = Helper.GetCategoryType(selectedCategory);

            try
            {
                if (selectedItem.ItemName.Equals(Strings.Face) || selectedItem.ItemName.Equals(Strings.Hair) || isDemiHuman)
                {
                    string slotAbr;

                    if (isDemiHuman)
                    {
                        slotAbr = Info.slotAbr[SelectedPart.Name];
                    }
                    else if (selectedCategory.Equals(Strings.Character))
                    {
                        var race = materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("c") + 1, 4);

                        if (materialStrings[mesh].Contains("h00"))
                        {
                            var hairNum    = materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("h00") + 1, 4);
                            var mtrlFolder = string.Format(Strings.HairMtrlFolder, race, hairNum);
                            slotAbr = materialStrings[mesh].Substring(materialStrings[mesh].LastIndexOf("_") - 3, 3);
                            slotAbr = Info.HairTypes.FirstOrDefault(x => x.Value == slotAbr).Key;

                            var hairInfo = MTRL.GetMTRLDatafromType(selectedItem, SelectedRace, hairNum, slotAbr, itemVersion, selectedCategory);
                            return(hairInfo.Item1);
                        }
                        else if (materialStrings[mesh].Contains("f00"))
                        {
                            var faceNum    = materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("f00") + 1, 4);
                            var mtrlFolder = string.Format(Strings.FaceMtrlFolder, race, faceNum);
                            slotAbr = materialStrings[mesh].Substring(materialStrings[mesh].LastIndexOf("_") - 3, 3);
                            slotAbr = Info.FaceTypes.FirstOrDefault(x => x.Value == slotAbr).Key;

                            var faceInfo = MTRL.GetMTRLDatafromType(selectedItem, SelectedRace, faceNum, slotAbr, itemVersion, selectedCategory);
                            return(faceInfo.Item1);
                        }
                        else
                        {
                            slotAbr = selectedPart.Name;
                        }
                    }
                    else
                    {
                        slotAbr = selectedPart.Name;
                    }

                    var info = MTRL.GetMTRLDatafromType(selectedItem, SelectedRace, selectedPart.Name, slotAbr, itemVersion, selectedCategory);
                    mtrlData = info.Item1;
                }
                else
                {
                    Tuple <MTRLData, ObservableCollection <ComboBoxInfo> > info;

                    if (itemType.Equals("character") || itemType.Equals("equipment"))
                    {
                        try
                        {
                            if (materialStrings[mesh].Contains("b00") || materialStrings[mesh].Contains("t00") || materialStrings[mesh].Contains("h00"))
                            {
                                if (materialStrings[mesh].Contains("mt_c"))
                                {
                                    var mtrlFolder = "";
                                    var race       = materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("c") + 1, 4);

                                    if (materialStrings[mesh].Contains("b00"))
                                    {
                                        mtrlFolder = string.Format(Strings.BodyMtrlFolder, race, materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("b00") + 1, 4));
                                    }
                                    else if (materialStrings[mesh].Contains("t00"))
                                    {
                                        mtrlFolder = string.Format(Strings.TailMtrlFolder, race, materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("t00") + 1, 4));
                                    }
                                    else if (materialStrings[mesh].Contains("h00"))
                                    {
                                        mtrlFolder = string.Format(Strings.HairMtrlFolder, race, materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("h00") + 1, 4));
                                    }

                                    var mtrlFile = materialStrings[mesh].Substring(1);

                                    return(MTRL.GetMTRLInfo(Helper.GetItemOffset(FFCRC.GetHash(mtrlFolder), FFCRC.GetHash(mtrlFile)), true));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                            Debug.WriteLine(ex.StackTrace);
                        }
                    }
                    else
                    {
                        info = MTRL.GetMTRLData(selectedItem, SelectedRace.ID, selectedCategory, SelectedPart.Name, itemVersion, "", "", "0000");
                    }

                    if (SelectedPart.Name.Equals("Secondary"))
                    {
                        info = MTRL.GetMTRLData(selectedItem, SelectedRace.ID, selectedCategory, SelectedPart.Name, itemVersion, "Secondary", "", "0000");
                    }
                    else
                    {
                        string part   = "a";
                        string itemID = selectedItem.PrimaryModelID;

                        if (materialStrings.Count > 1)
                        {
                            try
                            {
                                part   = materialStrings[mesh].Substring(materialStrings[mesh].LastIndexOf("_") + 1, 1);
                                itemID = materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("_") + 2, 4);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                                Debug.WriteLine(ex.StackTrace);
                            }
                        }

                        if (selectedCategory.Equals(Strings.Pets))
                        {
                            part = "1";
                        }

                        info = MTRL.GetMTRLData(selectedItem, SelectedRace.ID, selectedCategory, part, itemVersion, "", itemID, "0000");
                    }

                    if (info != null)
                    {
                        mtrlData = info.Item1;
                    }
                    else
                    {
                        var combo = new ComboBoxInfo()
                        {
                            Name = "Default", ID = materialStrings[mesh].Substring(materialStrings[mesh].IndexOf("c") + 1, 4), IsNum = false
                        };

                        if (SelectedPart.Name.Equals("-"))
                        {
                            info = MTRL.GetMTRLData(selectedItem, combo.ID, selectedCategory, "a", itemVersion, "", "", "0000");
                        }
                        else
                        {
                            info = MTRL.GetMTRLData(selectedItem, combo.ID, selectedCategory, SelectedPart.Name, itemVersion, "", "", "0000");
                        }

                        mtrlData = info.Item1;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                return(null);
            }

            return(mtrlData);
        }
Exemple #21
0
        public ModListModel ParseEntry(JsonEntry entry)
        {
            ModListModel mlm = new ModListModel();
            string       race, map, part, type;

            if (entry.fullPath.Contains("mt_"))
            {
                Debug.WriteLine(entry.fullPath);
            }

            if (entry.fullPath.Contains("weapon") || entry.fullPath.Contains("accessory") || entry.fullPath.Contains("decal") || entry.fullPath.Contains("vfx") || entry.fullPath.Contains("ui/"))
            {
                race = Strings.All;
            }
            else if (entry.fullPath.Contains("monster") || entry.fullPath.Contains("demihuman"))
            {
                race = Strings.Monster;
            }
            else
            {
                race = entry.fullPath.Substring(entry.fullPath.LastIndexOf('/'));
                if (entry.fullPath.Contains("mt_") && entry.fullPath.Contains("_acc_"))
                {
                    race = race.Substring(race.IndexOf("_") + 2, 4);
                }
                else if ((entry.fullPath.Contains("_fac_") || entry.fullPath.Contains("_etc_") || entry.fullPath.Contains("_acc_")) && Properties.Settings.Default.DX_Ver.Equals(Strings.DX11))
                {
                    race = race.Substring(race.LastIndexOf("--c") + 3, 4);
                }
                else if (entry.fullPath.Contains("_fac_") || entry.fullPath.Contains("_etc_") || entry.fullPath.Contains("_acc_"))
                {
                    race = race.Substring(race.LastIndexOf("/c") + 2, 4);
                }
                else if (entry.fullPath.Contains("_c_"))
                {
                    race = race.Substring(race.IndexOf("_c") + 2, 4);
                }
                else
                {
                    if (entry.fullPath.Contains(".mdl") && entry.fullPath.Contains("_fac"))
                    {
                        race = race.Substring(race.IndexOf('c') + 1, 4);
                    }
                    else
                    {
                        race = race.Substring(race.LastIndexOf('c') + 1, 4);
                    }
                }

                if (entry.fullPath.Contains("mt_"))
                {
                    Debug.WriteLine(race + "\n");
                }

                race = Info.IDRace[race];
            }

            mlm.Race = race;


            if (entry.fullPath.Contains("_d."))
            {
                map = Strings.Diffuse;
            }
            else if (entry.fullPath.Contains("_n."))
            {
                map = Strings.Normal;
            }
            else if (entry.fullPath.Contains("_s."))
            {
                map = Strings.Specular;
            }
            else if (entry.fullPath.Contains("material"))
            {
                map = Strings.ColorSet;
            }
            else if (entry.fullPath.Contains("model"))
            {
                map = "3D";
            }
            else if (entry.fullPath.Contains("ui/"))
            {
                map = "UI";
            }
            else
            {
                map = Strings.Mask;
            }

            mlm.Map = map;


            if (entry.fullPath.Contains("_b_"))
            {
                part = "b";
            }
            else if (entry.fullPath.Contains("_c_"))
            {
                part = "c";
            }
            else if (entry.fullPath.Contains("_d_"))
            {
                part = "d";
            }
            else if (entry.fullPath.Contains("decal"))
            {
                part = entry.fullPath.Substring(entry.fullPath.LastIndexOf('_') + 1, entry.fullPath.LastIndexOf('.') - (entry.fullPath.LastIndexOf('_') + 1));
            }
            else
            {
                part = "a";
            }

            mlm.Part = part;


            if (entry.fullPath.Contains("_iri_"))
            {
                type = "Iris";
            }
            else if (entry.fullPath.Contains("_etc_"))
            {
                type = "Etc.";
            }
            else if (entry.fullPath.Contains("_fac_"))
            {
                type = "Face";
            }
            else if (entry.fullPath.Contains("_hir_"))
            {
                type = "Hair";
            }
            else if (entry.fullPath.Contains("_acc_"))
            {
                type = "Accessory";
            }
            else if (entry.fullPath.Contains("demihuman"))
            {
                type = entry.fullPath.Substring(entry.fullPath.LastIndexOf('_') - 3, 3);
                type = (Info.slotAbr).FirstOrDefault(x => x.Value == type).Key;
            }
            else
            {
                type = "-";
            }

            mlm.Type = type;

            if (entry.fullPath.Contains("material"))
            {
                var info = MTRL.GetMTRLInfo(entry.modOffset, false);

                using (var bitmap = TEX.ColorSetToBitmap(info.ColorData))
                    mlm.BMP = TexHelper.CreateBitmapSource(bitmap);
                mlm.BMP.Freeze();
            }
            else if (entry.fullPath.Contains("model"))
            {
                mlm.BMP = new BitmapImage(new Uri("pack://application:,,,/FFXIV TexTools 2;component/Resources/3DModel.png"));
            }
            else
            {
                TEXData texData;

                if (entry.fullPath.Contains("vfx"))
                {
                    texData = TEX.GetVFX(entry.modOffset, entry.datFile);
                }
                else
                {
                    if (entry.fullPath.Contains("icon"))
                    {
                        texData = TEX.GetTex(entry.modOffset, entry.datFile);
                    }
                    else
                    {
                        texData = TEX.GetTex(entry.modOffset, entry.datFile);
                    }
                }

                var scale = 1;

                if (texData.Width >= 4096 || texData.Height >= 4096)
                {
                    scale = 16;
                }
                else if (texData.Width >= 2048 || texData.Height >= 2048)
                {
                    scale = 8;
                }
                else if (texData.Width >= 1024 || texData.Height >= 1024)
                {
                    scale = 4;
                }

                var nWidth  = texData.Width / scale;
                var nHeight = texData.Height / scale;

                var resizedImage = TexHelper.CreateResizedImage(texData.BMPSouceNoAlpha, nWidth, nHeight);
                mlm.BMP = (BitmapSource)resizedImage;
                mlm.BMP.Freeze();
            }

            var offset = Helper.GetDataOffset(FFCRC.GetHash(entry.fullPath.Substring(0, entry.fullPath.LastIndexOf("/"))), FFCRC.GetHash(Path.GetFileName(entry.fullPath)), entry.datFile);

            if (offset == entry.modOffset)
            {
                mlm.ActiveBorder  = Brushes.Green;
                mlm.Active        = Brushes.Transparent;
                mlm.ActiveOpacity = 1;
            }
            else if (offset == entry.originalOffset)
            {
                mlm.ActiveBorder  = Brushes.Red;
                mlm.Active        = Brushes.Gray;
                mlm.ActiveOpacity = 0.5f;
            }
            else
            {
                mlm.ActiveBorder  = Brushes.Red;
                mlm.Active        = Brushes.Red;
                mlm.ActiveOpacity = 1;
            }

            mlm.Entry = entry;

            return(mlm);
        }