Example #1
0
        private void openTattooPackageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter          = PackageFilter;
            openFileDialog1.Title           = "Select Tattoo Package File";
            openFileDialog1.FilterIndex     = 1;
            openFileDialog1.CheckFileExists = true;
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Package myPack;

            try
            {
                myPack = (Package)Package.OpenPackage(0, openFileDialog1.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot open package: " + openFileDialog1.FileName + " - Error is:" + System.Environment.NewLine +
                                ex.Message + System.Environment.NewLine + ex.InnerException);
                return;
            }

            Predicate <IResourceIndexEntry> isCASP   = r => r.ResourceType == (uint)ResourceTypes.CASP;
            List <IResourceIndexEntry>      CASPlist = myPack.FindAll(isCASP);

            if (CASPlist.Count == 0)
            {
                MessageBox.Show("No CASP files found in package!");
                Package.ClosePackage(0, (IPackage)myPack);
                return;
            }

            Predicate <IResourceIndexEntry> isKEY = r => r.ResourceType == (uint)ResourceTypes.KEY;
            IResourceIndexEntry             irKey = myPack.Find(isKEY);

            NameMapResource.NameMapResource nMap = null;
            if (irKey != null)
            {
                Stream n = myPack.GetResource(irKey);
                nMap = new NameMapResource.NameMapResource(0, n);
            }

            int numTattoos = 0;

            foreach (IResourceIndexEntry r in CASPlist)
            {
                Stream s = myPack.GetResource(r);
                s.Position = 0;
                CASPartResource.CASPartResource casp = new CASPartResource.CASPartResource(0, s);
                if (casp.Clothing == ClothingType.TattooTemplate)
                {
                    numTattoos++;
                    string tatName = "";
                    if (casp.Presets.Count > 0)
                    {
                        XmlDocument imp = new XmlDocument();
                        imp.LoadXml(casp.Presets[0].XmlFile.ReadToEnd());
                        XmlNodeList nodes = imp.GetElementsByTagName("value");
                        foreach (XmlNode n in nodes)
                        {
                            if (n.Attributes["key"].InnerXml.Contains("daeFileName"))
                            {
                                tatName = n.Attributes["value"].InnerXml;
                                break;
                            }
                        }
                    }
                    string tmp;
                    if (nMap != null && nMap.TryGetValue(r.Instance, out tmp))
                    {
                        tatName = tmp;
                    }
                    DialogResult res = MessageBox.Show("Open tattoo: " + tatName + "?", "Select Tattoo", MessageBoxButtons.YesNoCancel);
                    if (res == DialogResult.Yes)
                    {
                        bool gotImage = false;
                        for (int i = 0; i < Math.Min(casp.Presets.Count, 3); i++)
                        {
                            XmlDocument imp = new XmlDocument();
                            imp.LoadXml(casp.Presets[i].XmlFile.ReadToEnd());
                            XmlNodeList nodes = imp.GetElementsByTagName("value");
                            foreach (XmlNode n in nodes)
                            {
                                if (n.Attributes["key"].InnerXml.Contains("Layer1ColorR"))
                                {
                                    presets[i].rChannelColor = new Color(n.Attributes["value"].InnerXml);
                                }
                                else if (n.Attributes["key"].InnerXml.Contains("Layer1ColorG"))
                                {
                                    presets[i].gChannelColor = new Color(n.Attributes["value"].InnerXml);
                                }
                                else if (n.Attributes["key"].InnerXml.Contains("Layer1ColorB"))
                                {
                                    presets[i].bChannelColor = new Color(n.Attributes["value"].InnerXml);
                                }
                                else if (n.Attributes["key"].InnerXml.Contains("Layer1ColorA"))
                                {
                                    presets[i].aChannelColor = new Color(n.Attributes["value"].InnerXml);
                                }
                                else if (n.Attributes["key"].InnerXml.Contains("Layer1Mask") && !gotImage)
                                {
                                    string[] imgTgi = n.Attributes["value"].InnerXml.Split(':');
                                    Predicate <IResourceIndexEntry> isIMG;
                                    try
                                    {
                                        isIMG = ri => ri.ResourceType == UInt32.Parse(imgTgi[1], System.Globalization.NumberStyles.HexNumber) &
                                                ri.ResourceGroup == UInt32.Parse(imgTgi[2], System.Globalization.NumberStyles.HexNumber) &
                                                ri.Instance == UInt64.Parse(imgTgi[3], System.Globalization.NumberStyles.HexNumber);
                                    }
                                    catch
                                    {
                                        MessageBox.Show("Could not parse TGI of tattoo image!");
                                        return;
                                    }
                                    IResourceIndexEntry img = myPack.Find(isIMG);
                                    if (img != null)
                                    {
                                        Stream d = myPack.GetResource(img);
                                        d.Position = 0;
                                        dds        = new DdsFile();
                                        dds.Load(d, false);
                                        ddsOriginal = new DdsFile();
                                        ddsOriginal.CreateImage(dds, false);
                                        gotImage = true;
                                    }
                                }
                            }
                        }
                        if (!gotImage)
                        {
                            MessageBox.Show("Could not find tattoo image!");
                        }
                        bgColor = new Color(0x00D2B48Cu);
                        BGcolor_panel.BackColor = System.Drawing.Color.FromArgb(bgColor.Red, bgColor.Green, bgColor.Blue);
                        currentPreset           = 0;
                        PresetPrep();
                        Update_DDSdisplay();
                        TattooImageFile.Text = "";
                        Predicate <IResourceIndexEntry> isTHUM = ri => ri.ResourceType == (uint)ResourceTypes.THUM &
                                                                 ri.ResourceGroup == 1U & ri.Instance == r.Instance;
                        IResourceIndexEntry irThum = myPack.Find(isTHUM);
                        if (irThum != null)
                        {
                            Stream t = myPack.GetResource(irThum);
                            thumbNail = new Bitmap(t);
                        }
                        else
                        {
                            thumbNail = null;
                        }
                        TattooName.Text     = tatName;
                        TattooInstance.Text = r.Instance.ToString("X16");
                        AgeGenderFlags ag = casp.AgeGender;
                        CASPtodder_checkBox.Checked = ((ag.Age & AgeFlags.Toddler) > 0);
                        CASPchild_checkBox.Checked  = ((ag.Age & AgeFlags.Child) > 0);
                        CASPteen_checkBox.Checked   = ((ag.Age & AgeFlags.Teen) > 0);
                        CASPadult_checkBox.Checked  = ((ag.Age & AgeFlags.Adult) > 0);
                        CASPelder_checkBox.Checked  = ((ag.Age & AgeFlags.Elder) > 0);
                        CASPmale_checkBox.Checked   = ((ag.Gender & GenderFlags.Male) > 0);
                        CASPfemale_checkBox.Checked = ((ag.Gender & GenderFlags.Female) > 0);
                        CASPsortOrder.Text          = casp.SortPriority.ToString();
                        saveOptionsDDS = new DdsSaveOptions("DXT5", true, 90);
                        PhotoConvert_radioButton.Checked = false;
                        Black2Red_radioButton.Checked    = false;
                        Resize_checkBox.Checked          = false;
                        ReplaceAlpha_checkBox.Checked    = false;
                        Black2Alpha_radioButton.Checked  = true;
                        White2Alpha_radioButton.Checked  = false;
                        BlankAlpha_radioButton.Checked   = false;
                        invertAlpha_radioButton.Checked  = false;
                        White2Back_checkBox.Checked      = false;
                        break;
                    }
                    else if (res == DialogResult.No)
                    {
                        continue;
                    }
                    else
                    {
                        Package.ClosePackage(0, (IPackage)myPack);
                        return;
                    }
                }
            }

            if (numTattoos == 0)
            {
                MessageBox.Show("No tattoos found in package!");
            }
            Package.ClosePackage(0, (IPackage)myPack);
            // CASPartResource.CASPartResource casp =
        }
Example #2
0
        private void TattooGo_button_Click(object sender, EventArgs e)
        {
            float sortOrder;

            try
            {
                sortOrder = float.Parse(CASPsortOrder.Text);
            }
            catch
            {
                MessageBox.Show("Please enter a valid number for Sort Order in CAS");
                return;
            }
            if (String.CompareOrdinal(TattooName.Text, " ") <= 0)
            {
                MessageBox.Show("Please enter a name for the tattoo");
                return;
            }
            if (dds == null)
            {
                MessageBox.Show("Please select an image for the tattoo");
                return;
            }
            ulong  tatInstance;
            string tatName;

            if (TattooName.Text.IndexOf("uutattoo") < 0)
            {
                tatName = "uutattoo" + TattooName.Text;
            }
            else
            {
                tatName = TattooName.Text;
            }
            if (String.CompareOrdinal(TattooInstance.Text, " ") > 0)
            {
                if (!UInt64.TryParse(TattooInstance.Text, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out tatInstance))
                {
                    MessageBox.Show("Please enter a valid Tattoo Instance number in hexidecimal, or leave it blank");
                    return;
                }
            }
            else
            {
                tatInstance = FNVhash.FNV64(tatName);
            }

            PleaseWait_label.Visible = true;
            this.Refresh();

            uint  tatGroup     = FNVhash.FNV24(tatName);
            ulong txtcInstance = FNVhash.FNV64(tatName + "TattooTemplate_Top_diffuse");

            Package myPack;

            myPack = (Package)Package.NewPackage(0);

            NameMapResource.NameMapResource myMap = new NameMapResource.NameMapResource(0, null);
            myMap.Add(tatInstance, tatName);
            myMap.Add(tatGroup, tatName);
            myMap.Add(txtcInstance, tatName + "TattooTemplate_Top_diffuse");

            XmlDocument doc1 = PresetBuilder.presetXML(tatName, tatInstance, presets[0],
                                                       ChannelR_checkBox.Checked, ChannelG_checkBox.Checked, ChannelB_checkBox.Checked, ChannelA_checkBox.Checked);
            XmlDocument doc2 = PresetBuilder.presetXML(tatName, tatInstance, presets[1],
                                                       ChannelR_checkBox.Checked, ChannelG_checkBox.Checked, ChannelB_checkBox.Checked, ChannelA_checkBox.Checked);
            XmlDocument doc3 = PresetBuilder.presetXML(tatName, tatInstance, presets[2],
                                                       ChannelR_checkBox.Checked, ChannelG_checkBox.Checked, ChannelB_checkBox.Checked, ChannelA_checkBox.Checked);

            CASPartResource.CASPartResource myCasp;
            myCasp = new CASPartResource.CASPartResource(0, null);
            CASPartResource.CASPartResource.Preset pre1 = new CASPartResource.CASPartResource.Preset(0, null, doc1.OuterXml, 1);
            CASPartResource.CASPartResource.Preset pre2 = new CASPartResource.CASPartResource.Preset(0, null, doc2.OuterXml, 2);
            CASPartResource.CASPartResource.Preset pre3 = new CASPartResource.CASPartResource.Preset(0, null, doc3.OuterXml, 3);
            myCasp.Presets = new CASPartResource.CASPartResource.PresetList(null);
            myCasp.Presets.Add(pre1);
            myCasp.Presets.Add(pre2);
            myCasp.Presets.Add(pre3);
            myCasp.Unknown1     = tatName;
            myCasp.SortPriority = sortOrder;
            myCasp.Clothing     = ClothingType.TattooTemplate;
            myCasp.DataType     = DataTypeFlags.Body;
            myCasp.AgeGender    = new AgeGenderFlags(0, null, (CASPtodder_checkBox.Checked ? AgeFlags.Toddler : 0) |
                                                     (CASPchild_checkBox.Checked ? AgeFlags.Child : 0) | (CASPteen_checkBox.Checked ? AgeFlags.Teen : 0) |
                                                     (CASPadult_checkBox.Checked ? AgeFlags.YoungAdult | AgeFlags.Adult : 0) |
                                                     (CASPelder_checkBox.Checked ? AgeFlags.Elder : 0),
                                                     (CASPfemale_checkBox.Checked ? GenderFlags.Female : 0) | (CASPmale_checkBox.Checked ? GenderFlags.Male : 0),
                                                     0, 0);
            myCasp.ClothingCategory = ClothingCategoryFlags.Athletic | ClothingCategoryFlags.Career | ClothingCategoryFlags.Everyday |
                                      ClothingCategoryFlags.FireFighting | ClothingCategoryFlags.Formalwear | ClothingCategoryFlags.Makeover |
                                      ClothingCategoryFlags.MartialArts | ClothingCategoryFlags.Naked | ClothingCategoryFlags.Outerwear |
                                      ClothingCategoryFlags.SkinnyDippingTowel | ClothingCategoryFlags.Sleepwear | ClothingCategoryFlags.Swimwear |
                                      ClothingCategoryFlags.Singed | ClothingCategoryFlags.ValidForMaternity;
            myCasp.CasPart1Index         = 2;
            myCasp.CasPart2Index         = 2;
            myCasp.BlendInfoFatIndex     = 3;
            myCasp.BlendInfoFitIndex     = 4;
            myCasp.BlendInfoThinIndex    = 5;
            myCasp.BlendInfoSpecialIndex = 6;
            myCasp.OverlayPriority       = 2u;
            myCasp.VPXYIndexes           = new ByteIndexList(null);
            myCasp.VPXYIndexes.Add(7);
            myCasp.Diffuse1Indexes = new ByteIndexList(null);
            myCasp.Diffuse1Indexes.Add(8);
            myCasp.Specular1Indexes = new ByteIndexList(null);
            myCasp.Specular1Indexes.Add(9);
            myCasp.BONDIndexes = new ByteIndexList(null);
            myCasp.BONDIndexes.AddRange(new List <byte> {
                2, 2, 2, 2, 2
            });
            myCasp.Unknown4  = "bare";
            myCasp.TGIBlocks = new CountedTGIBlockList(null);
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.DDS, 0, tatInstance));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.XML, 0, 0xF7FC14B9EA85B390));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, 0, 0, 0));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.BBLN, 0, 0xCBE03A305F80FF50));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.BBLN, 0, 0xCBE032305F80F1F8));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.BBLN, 0, 0x540F4B31F0B42342));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.BBLN, 0, 0x82F02E48897E22B4));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.VPXY, 1, tatGroup));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.TXTC, tatGroup, txtcInstance));
            myCasp.TGIBlocks.Add(new TGIBlock(0, null, (uint)ResourceTypes.TXTC, tatGroup, 0xCBF29CE484222325));

            uint  fakeType     = (uint)tatInstance;
            uint  fakeGroup    = (uint)(tatInstance >> 32);
            ulong fakeInstance = (ulong)ResourceTypes.DDS << 32;

            TxtcResource.TxtcResource txtc = TattooTextureCompositor.TattooTxtc(new TGIBlock(0, null, fakeType, fakeGroup, fakeInstance));

            VPXY vpxy = new VPXY(0, null, 4, null, 2,
                                 new BoundingBox(0, null, new Vertex(0, null, -.0060f, 1.7157f, -.0060f), new Vertex(0, null, .0060f, 1.7277f, .0060f)),
                                 new byte[] { 0, 0, 0, 0 }, 0, 0, new TGIBlockList(null));
            GenericRCOLResource vpxyRcol = new GenericRCOLResource(0, null);

            vpxyRcol.Version      = 3;
            vpxyRcol.PublicChunks = 1;
            vpxyRcol.ChunkEntries = new GenericRCOLResource.ChunkEntryList(null);
            GenericRCOLResource.ChunkEntry vpxyChunk = new GenericRCOLResource.ChunkEntry(0, null, new TGIBlock(0, null, "ITG", (uint)ResourceTypes.VPXY, 1, tatGroup), vpxy);
            vpxyRcol.ChunkEntries.Add(vpxyChunk);
            IResourceIndexEntry rs = myPack.AddResource(new TGIBlock(0, null, (uint)ResourceTypes.KEY, 0, tatInstance), myMap.Stream, true);

            rs.Compressed = (ushort)0xFFFF;
            rs            = myPack.AddResource(new TGIBlock(0, null, (uint)ResourceTypes.CASP, 0, tatInstance), myCasp.Stream, true);
            rs.Compressed = (ushort)0xFFFF;
            rs            = myPack.AddResource(new TGIBlock(0, null, (uint)ResourceTypes.TXTC, tatGroup, txtcInstance), txtc.Stream, true);
            rs.Compressed = (ushort)0xFFFF;
            rs            = myPack.AddResource(new TGIBlock(0, null, (uint)ResourceTypes.VPXY, 1, tatGroup), vpxyRcol.Stream, true);
            rs.Compressed = (ushort)0xFFFF;
            MemoryStream ms = new MemoryStream();

            doc1.Save(ms);
            rs            = myPack.AddResource(new TGIBlock(0, null, (uint)ResourceTypes.XML, 0, tatInstance), ms, true);
            rs.Compressed = (ushort)0xFFFF;
            MemoryStream ms2 = new MemoryStream();

            dds.UseDXT          = false;
            dds.AlphaDepth      = 8;
            dds.GenerateMipmaps = true;
            dds.Save(ms2);
            rs            = myPack.AddResource(new TGIBlock(0, null, (uint)ResourceTypes.DDS, 0, tatInstance), ms2, true);
            rs.Compressed = (ushort)0xFFFF;
            if (thumbNail != null)
            {
                MemoryStream ms3 = new MemoryStream();
                thumbNail.Save(ms3, System.Drawing.Imaging.ImageFormat.Png);
                rs            = myPack.AddResource(new TGIBlock(0, null, (uint)ResourceTypes.THUM, 1, tatInstance), ms3, true);
                rs.Compressed = (ushort)0xFFFF;
            }

            PleaseWait_label.Visible = false;

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter          = PackageFilter;
            saveFileDialog1.Title           = "Save as a new package";
            saveFileDialog1.FileName        = TattooName.Text + ".package";
            saveFileDialog1.FilterIndex     = 1;
            saveFileDialog1.CheckFileExists = false;
            saveFileDialog1.CheckPathExists = true;
            saveFileDialog1.OverwritePrompt = true;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                myPack.SaveAs(saveFileDialog1.FileName);
            }
            ms.Dispose();
            ms2.Dispose();
        }