private void btnLoadCustom_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Sims 3 Package|*.package"; if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName != "") { Stream cast = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); MadScience.Wrappers.Database castdb = new MadScience.Wrappers.Database(cast, true); // Open XML file //patternsFile cPattern = new patternsFile(); Patterns.patternDetails pDetails = new Patterns.patternDetails(); foreach (MadScience.Wrappers.ResourceKey key in castdb._Entries.Keys) { if ((key.groupId == 0x00000000) && (key.typeId == 0x0333406C)) { pDetails = Patterns.parsePatternComplate(castdb.GetResourceStream(key)); patternsFile cPattern = new patternsFile(); //MadScience.Wrappers.ResourceKey rKey = new MadScience.Wrappers.ResourceKey(pDetails.key); //cPattern.typeid = rKey.typeId.ToString("X8"); //cPattern.groupid = rKey.groupId.ToString("X8"); //cPattern.instanceid = rKey.instanceId.ToString("X16"); cPattern.key = pDetails.key; if (!StreamHelpers.isValidStream(KeyUtils.findKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1)).ToString("X16")))) { if (String.IsNullOrEmpty(pDetails.BackgroundImage)) { cPattern.texturename = pDetails.rgbmask; } else { cPattern.texturename = pDetails.BackgroundImage; } } else { cPattern.texturename = "key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1)).ToString("X16"); } cPattern.casPart = pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1); cPattern.subcategory = openFileDialog1.FileName; pDetails.customFilename = openFileDialog1.FileName; cPattern.isCustom = true; pDetails.isCustom = true; customPatterns.Items.Add(cPattern); TextWriter r = new StreamWriter(Path.Combine(Application.StartupPath, Path.Combine("xml", "customPatterns.xml"))); XmlSerializer s = new XmlSerializer(typeof(patterns)); s.Serialize(r, customPatterns); r.Close(); break; } } //Stream patternThumb = KeyUtils.searchForKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name), openFileDialog1.FileName); //if (!Helpers.isValidStream(patternThumb)) //{ // patternThumb = KeyUtils.searchForKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.BackgroundImage), openFileDialog1.FileName); //} //if (Helpers.isValidStream(patternThumb)) //{ //Stream patternDDS = File.OpenWrite(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pDetails.name + ".dds"))); //Helpers.CopyStream(patternThumb, patternDDS, true); //patternDDS.Close(); //patternThumb.Seek(0, SeekOrigin.Begin); PictureBox picBox = new PictureBox(); picBox.BackColor = System.Drawing.Color.White; //picBox.Location = new System.Drawing.Point(horizontal, vertical); picBox.Name = pDetails.name; string toolTip = pDetails.category + "\\"; ToolTip tt = new ToolTip(); toolTip += pDetails.name; tt.SetToolTip(picBox, toolTip); picBox.Image = Patterns.makePatternThumb(pDetails, castdb); //picBox.Image = castdb.GetResourceStream(entry.Key); try { picBox.Image.Save(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pDetails.name + ".png")), System.Drawing.Imaging.ImageFormat.Png); } catch (Exception) { } addToPanel(picBox); cast.Close(); //picBox.Dispose(); //} comboBox1.SelectedIndex = 15; } }
public void parseRawXML(int index) { index--; int level = 0; string curPattern = ""; MemoryStream mem = new MemoryStream(Encoding.ASCII.GetBytes((string)cFile.xmlChunkRaw[index])); XmlTextReader xtr = new XmlTextReader(mem); xmlChunkDetails xcd = new xmlChunkDetails(); for (int i = 0; i < 4; i++) { xcd.pattern[i] = new Patterns.patternDetails(); } while (xtr.Read()) { if (xtr.NodeType == XmlNodeType.Element) { switch (xtr.Name) { case "complate": level++; xtr.MoveToAttribute(0); xcd.name = xtr.Value; xtr.MoveToAttribute(1); xcd.reskey = xtr.Value; break; case "value": if (level == 1) { // Normal complate stuff xtr.MoveToNextAttribute(); //Console.WriteLine(xtr.Value); switch (xtr.Value) { case "assetRoot": xtr.MoveToNextAttribute(); xcd.assetRoot = xtr.Value; break; case "IsHat": xtr.MoveToNextAttribute(); xcd.IsHat = xtr.Value; break; case "DrawsOnFace": xtr.MoveToNextAttribute(); xcd.DrawsOnFace = xtr.Value; break; case "DrawsOnScalp": xtr.MoveToNextAttribute(); xcd.DrawsOnScalp = xtr.Value; break; case "Control Map": xtr.MoveToNextAttribute(); xcd.ControlMap = xtr.Value; break; case "Diffuse Map": xtr.MoveToNextAttribute(); xcd.DiffuseMap = xtr.Value; break; case "Overlay": xtr.MoveToNextAttribute(); xcd.Overlay = xtr.Value; break; case "Mask": xtr.MoveToNextAttribute(); xcd.Mask = xtr.Value; break; case "MaskHeight": xtr.MoveToNextAttribute(); xcd.MaskHeight = xtr.Value; break; case "MaskWidth": xtr.MoveToNextAttribute(); xcd.MaskWidth = xtr.Value; break; case "Multiplier": xtr.MoveToNextAttribute(); xcd.Multiplier = xtr.Value; break; case "Stencil A": xtr.MoveToNextAttribute(); xcd.stencil.A.key = xtr.Value; break; case "Stencil A Tiling": xtr.MoveToNextAttribute(); xcd.stencil.A.Tiling = xtr.Value; break; case "Stencil A Rotation": xtr.MoveToNextAttribute(); xcd.stencil.A.Rotation = xtr.Value; break; case "Stencil A Enabled": xtr.MoveToNextAttribute(); xcd.stencil.A.Enabled = xtr.Value; break; case "Stencil B": xtr.MoveToNextAttribute(); xcd.stencil.B.key = xtr.Value; break; case "Stencil B Tiling": xtr.MoveToNextAttribute(); xcd.stencil.B.Tiling = xtr.Value; break; case "Stencil B Rotation": xtr.MoveToNextAttribute(); xcd.stencil.B.Rotation = xtr.Value; break; case "Stencil B Enabled": xtr.MoveToNextAttribute(); xcd.stencil.B.Enabled = xtr.Value; break; case "Stencil C": xtr.MoveToNextAttribute(); xcd.stencil.C.key = xtr.Value; break; case "Stencil C Tiling": xtr.MoveToNextAttribute(); xcd.stencil.C.Tiling = xtr.Value; break; case "Stencil C Rotation": xtr.MoveToNextAttribute(); xcd.stencil.C.Rotation = xtr.Value; break; case "Stencil C Enabled": xtr.MoveToNextAttribute(); xcd.stencil.C.Enabled = xtr.Value; break; case "Stencil D": xtr.MoveToNextAttribute(); xcd.stencil.D.key = xtr.Value; break; case "Stencil D Tiling": xtr.MoveToNextAttribute(); xcd.stencil.D.Tiling = xtr.Value; break; case "Stencil D Rotation": xtr.MoveToNextAttribute(); xcd.stencil.D.Rotation = xtr.Value; break; case "Stencil D Enabled": xtr.MoveToNextAttribute(); xcd.stencil.D.Enabled = xtr.Value; break; case "Stencil E": xtr.MoveToNextAttribute(); xcd.stencil.E.key = xtr.Value; break; case "Stencil E Tiling": xtr.MoveToNextAttribute(); xcd.stencil.E.Tiling = xtr.Value; break; case "Stencil E Rotation": xtr.MoveToNextAttribute(); xcd.stencil.E.Rotation = xtr.Value; break; case "Stencil E Enabled": xtr.MoveToNextAttribute(); xcd.stencil.E.Enabled = xtr.Value; break; case "Stencil F": xtr.MoveToNextAttribute(); xcd.stencil.F.key = xtr.Value; break; case "Stencil F Tiling": xtr.MoveToNextAttribute(); xcd.stencil.F.Tiling = xtr.Value; break; case "Stencil F Rotation": xtr.MoveToNextAttribute(); xcd.stencil.F.Rotation = xtr.Value; break; case "Stencil F Enabled": xtr.MoveToNextAttribute(); xcd.stencil.F.Enabled = xtr.Value; break; case "Pattern A": xtr.MoveToNextAttribute(); xcd.pattern[0].nameHigh = xtr.Value; break; case "Pattern A Enabled": xtr.MoveToNextAttribute(); xcd.pattern[0].Enabled = xtr.Value; break; case "Pattern A Linked": xtr.MoveToNextAttribute(); xcd.pattern[0].Linked = xtr.Value; break; case "Pattern A Tiling": xtr.MoveToNextAttribute(); xcd.pattern[0].Tiling = xtr.Value; break; case "Pattern B": xtr.MoveToNextAttribute(); xcd.pattern[1].nameHigh = xtr.Value; break; case "Pattern B Enabled": xtr.MoveToNextAttribute(); xcd.pattern[1].Enabled = xtr.Value; break; case "Pattern B Linked": xtr.MoveToNextAttribute(); xcd.pattern[1].Linked = xtr.Value; break; case "Pattern B Tiling": xtr.MoveToNextAttribute(); xcd.pattern[1].Tiling = xtr.Value; break; case "Pattern C": xtr.MoveToNextAttribute(); xcd.pattern[2].nameHigh = xtr.Value; break; case "Pattern C Enabled": xtr.MoveToNextAttribute(); xcd.pattern[2].Enabled = xtr.Value; break; case "Pattern C Linked": xtr.MoveToNextAttribute(); xcd.pattern[2].Linked = xtr.Value; break; case "Pattern C Tiling": xtr.MoveToNextAttribute(); xcd.pattern[2].Tiling = xtr.Value; break; case "Pattern D": xtr.MoveToNextAttribute(); xcd.pattern[3].nameHigh = xtr.Value; break; case "Pattern D Enabled": xtr.MoveToNextAttribute(); xcd.pattern[3].Enabled = xtr.Value; break; case "Pattern D Linked": xtr.MoveToNextAttribute(); xcd.pattern[3].Linked = xtr.Value; break; case "Pattern D Tiling": xtr.MoveToNextAttribute(); xcd.pattern[3].Tiling = xtr.Value; break; case "IsNaked": xtr.MoveToNextAttribute(); xcd.IsNaked = xtr.Value; break; case "IsNotNaked": xtr.MoveToNextAttribute(); xcd.IsNotNaked = xtr.Value; break; case "Skin Specular": xtr.MoveToNextAttribute(); xcd.SkinSpecular = xtr.Value; break; case "Skin Ambient": xtr.MoveToNextAttribute(); xcd.SkinAmbient = xtr.Value; break; case "Clothing Specular": xtr.MoveToNextAttribute(); xcd.ClothingSpecular = xtr.Value; break; case "Clothing Ambient": xtr.MoveToNextAttribute(); xcd.ClothingAmbient = xtr.Value; break; case "Rotation": xtr.MoveToNextAttribute(); xcd.Rotation = xtr.Value; break; case "Logo UpperLeft": xtr.MoveToNextAttribute(); xcd.logo.upperLeft = xtr.Value; break; case "Logo LowerRight": xtr.MoveToNextAttribute(); xcd.logo.lowerRight = xtr.Value; break; case "Logo Enabled": xtr.MoveToNextAttribute(); xcd.logo.enabled = xtr.Value; break; case "Logo": xtr.MoveToNextAttribute(); xcd.logo.value = xtr.Value; break; case "Part Mask": xtr.MoveToNextAttribute(); xcd.PartMask = xtr.Value; break; case "partType": xtr.MoveToNextAttribute(); xcd.partType = xtr.Value; break; case "age": xtr.MoveToNextAttribute(); xcd.age = xtr.Value; break; case "gender": xtr.MoveToNextAttribute(); xcd.gender = xtr.Value; break; case "bodyType": xtr.MoveToNextAttribute(); xcd.bodyType = xtr.Value; break; case "daeFileName": xtr.MoveToNextAttribute(); xcd.daeFileName = xtr.Value; break; case "filename": xtr.MoveToNextAttribute(); xcd.filename = xtr.Value; break; case "Root Color": xtr.MoveToNextAttribute(); xcd.hair.RootColor = xtr.Value; break; case "Diffuse Color": xtr.MoveToNextAttribute(); xcd.hair.DiffuseColor = xtr.Value; break; case "Highlight Color": xtr.MoveToNextAttribute(); xcd.hair.HighlightColor = xtr.Value; break; case "Tip Color": xtr.MoveToNextAttribute(); xcd.hair.TipColor = xtr.Value; break; case "Scalp Diffuse Map": xtr.MoveToNextAttribute(); xcd.hair.ScalpDiffuseMap = xtr.Value; break; case "Scalp Specular Map": xtr.MoveToNextAttribute(); xcd.hair.ScalpSpecularMap = xtr.Value; break; case "Scalp Control Map": xtr.MoveToNextAttribute(); xcd.hair.ScalpControlMap = xtr.Value; break; case "Scalp AO": xtr.MoveToNextAttribute(); xcd.hair.ScalpAO = xtr.Value; break; case "Face Diffuse Map": xtr.MoveToNextAttribute(); xcd.hair.FaceDiffuseMap = xtr.Value; break; case "Face Specular Map": xtr.MoveToNextAttribute(); xcd.hair.FaceSpecularMap = xtr.Value; break; case "Face Control Map": xtr.MoveToNextAttribute(); xcd.hair.FaceControlMap = xtr.Value; break; case "Face AO": xtr.MoveToNextAttribute(); xcd.hair.FaceAO = xtr.Value; break; case "Tint Color": xtr.MoveToNextAttribute(); xcd.TintColor = xtr.Value; break; case "Tint Color A": xtr.MoveToNextAttribute(); xcd.tint.A.color = xtr.Value; break; case "Tint Color B": xtr.MoveToNextAttribute(); xcd.tint.B.color = xtr.Value; break; case "Tint Color C": xtr.MoveToNextAttribute(); xcd.tint.C.color = xtr.Value; break; case "Tint Color D": xtr.MoveToNextAttribute(); xcd.tint.D.color = xtr.Value; break; case "Tint Color A Enabled": xtr.MoveToNextAttribute(); xcd.tint.A.enabled = xtr.Value; break; case "Tint Color B Enabled": xtr.MoveToNextAttribute(); xcd.tint.B.enabled = xtr.Value; break; case "Tint Color C Enabled": xtr.MoveToNextAttribute(); xcd.tint.C.enabled = xtr.Value; break; case "Tint Color D Enabled": xtr.MoveToNextAttribute(); xcd.tint.D.enabled = xtr.Value; break; case "Face Overlay": xtr.MoveToNextAttribute(); xcd.faceOverlay = xtr.Value; break; case "Face Specular": xtr.MoveToNextAttribute(); xcd.faceSpecular = xtr.Value; break; } } if (level == 2) { // Inside pattern xtr.MoveToNextAttribute(); bool isLogo = false; Patterns.patternDetails pDetail = new Patterns.patternDetails(); logoDetails lDetail = new logoDetails(); switch (curPattern) { case "Pattern A": pDetail = xcd.pattern[0]; break; case "Pattern B": pDetail = xcd.pattern[1]; break; case "Pattern C": pDetail = xcd.pattern[2]; break; case "Pattern D": pDetail = xcd.pattern[3]; break; case "Logo": lDetail = xcd.logo; isLogo = true; break; } //Console.WriteLine(xtr.Value); switch (xtr.Value) { case "assetRoot": xtr.MoveToNextAttribute(); pDetail.assetRoot = xtr.Value; break; case "Color": xtr.MoveToNextAttribute(); pDetail.Color = xtr.Value; break; case "Color 0": xtr.MoveToNextAttribute(); pDetail.ColorP[0] = xtr.Value; break; case "Color 1": xtr.MoveToNextAttribute(); pDetail.ColorP[1] = xtr.Value; break; case "Color 2": xtr.MoveToNextAttribute(); pDetail.ColorP[2] = xtr.Value; break; case "Color 3": xtr.MoveToNextAttribute(); pDetail.ColorP[3] = xtr.Value; break; case "Color 4": xtr.MoveToNextAttribute(); pDetail.ColorP[4] = xtr.Value; break; case "Channel 1": xtr.MoveToNextAttribute(); pDetail.Channel[0] = xtr.Value; break; case "Channel 2": xtr.MoveToNextAttribute(); pDetail.Channel[1] = xtr.Value; break; case "Channel 3": xtr.MoveToNextAttribute(); pDetail.Channel[2] = xtr.Value; break; case "Channel 1 Enabled": xtr.MoveToNextAttribute(); pDetail.ChannelEnabled[0] = xtr.Value; break; case "Channel 2 Enabled": xtr.MoveToNextAttribute(); pDetail.ChannelEnabled[1] = xtr.Value; break; case "Channel 3 Enabled": xtr.MoveToNextAttribute(); pDetail.ChannelEnabled[2] = xtr.Value; break; case "Background Image": xtr.MoveToNextAttribute(); pDetail.BackgroundImage = xtr.Value; break; case "H Bg": xtr.MoveToNextAttribute(); pDetail.HBg = xtr.Value; break; case "H 1": xtr.MoveToNextAttribute(); pDetail.H[0] = xtr.Value; break; case "H 2": xtr.MoveToNextAttribute(); pDetail.H[1] = xtr.Value; break; case "H 3": xtr.MoveToNextAttribute(); pDetail.H[2] = xtr.Value; break; case "S Bg": xtr.MoveToNextAttribute(); pDetail.SBg = xtr.Value; break; case "S 1": xtr.MoveToNextAttribute(); pDetail.S[0] = xtr.Value; break; case "S 2": xtr.MoveToNextAttribute(); pDetail.S[1] = xtr.Value; break; case "S 3": xtr.MoveToNextAttribute(); pDetail.S[2] = xtr.Value; break; case "V Bg": xtr.MoveToNextAttribute(); pDetail.VBg = xtr.Value; break; case "V 1": xtr.MoveToNextAttribute(); pDetail.V[0] = xtr.Value; break; case "V 2": xtr.MoveToNextAttribute(); pDetail.V[1] = xtr.Value; break; case "V 3": xtr.MoveToNextAttribute(); pDetail.V[2] = xtr.Value; break; case "Base H Bg": xtr.MoveToNextAttribute(); pDetail.BaseHBg = xtr.Value; break; case "Base H 1": xtr.MoveToNextAttribute(); pDetail.BaseH[0] = xtr.Value; break; case "Base H 2": xtr.MoveToNextAttribute(); pDetail.BaseH[1] = xtr.Value; break; case "Base H 3": xtr.MoveToNextAttribute(); pDetail.BaseH[2] = xtr.Value; break; case "Base S Bg": xtr.MoveToNextAttribute(); pDetail.BaseSBg = xtr.Value; break; case "Base S 1": xtr.MoveToNextAttribute(); pDetail.BaseS[0] = xtr.Value; break; case "Base S 2": xtr.MoveToNextAttribute(); pDetail.BaseS[1] = xtr.Value; break; case "Base S 3": xtr.MoveToNextAttribute(); pDetail.BaseS[2] = xtr.Value; break; case "Base V Bg": xtr.MoveToNextAttribute(); pDetail.BaseVBg = xtr.Value; break; case "Base V 1": xtr.MoveToNextAttribute(); pDetail.BaseV[0] = xtr.Value; break; case "Base V 2": xtr.MoveToNextAttribute(); pDetail.BaseV[1] = xtr.Value; break; case "Base V 3": xtr.MoveToNextAttribute(); pDetail.BaseV[2] = xtr.Value; break; case "HSVShift Bg": xtr.MoveToNextAttribute(); pDetail.HSVShiftBg = xtr.Value; break; case "HSVShift 1": xtr.MoveToNextAttribute(); pDetail.HSVShift[0] = xtr.Value; break; case "HSVShift 2": xtr.MoveToNextAttribute(); pDetail.HSVShift[1] = xtr.Value; break; case "HSVShift 3": xtr.MoveToNextAttribute(); pDetail.HSVShift[2] = xtr.Value; break; case "rgbmask": xtr.MoveToNextAttribute(); pDetail.rgbmask = xtr.Value; break; case "specmap": xtr.MoveToNextAttribute(); pDetail.specmap = xtr.Value; break; case "filename": xtr.MoveToNextAttribute(); if (isLogo) { lDetail.filename = xtr.Value; } else { pDetail.filename = xtr.Value; } break; } } break; case "pattern": level++; string a1 = ""; string a2 = ""; string a3 = ""; xtr.MoveToNextAttribute(); a1 = xtr.Value; xtr.MoveToNextAttribute(); a2 = xtr.Value; xtr.MoveToNextAttribute(); a3 = xtr.Value; curPattern = a3; switch (a3) { case "Pattern A": xcd.pattern[0].key = a2; xcd.pattern[0].name = a1; break; case "Pattern B": xcd.pattern[1].key = a2; xcd.pattern[1].name = a1; break; case "Pattern C": xcd.pattern[2].key = a2; xcd.pattern[2].name = a1; break; case "Pattern D": xcd.pattern[3].key = a2; xcd.pattern[3].name = a1; break; case "Logo": xcd.logo.key = a2; xcd.logo.name = a1; break; } break; } } if (xtr.NodeType == XmlNodeType.EndElement) { level--; } } for (int i = 0; i < 4; i++) { if (xcd.pattern[i].name.StartsWith("solidColor") || xcd.pattern[i].name.StartsWith("Flat Color") ) { xcd.pattern[i].type = "solidColor"; } if (xcd.pattern[i].HSVShiftBg != "" || xcd.pattern[i].HSVShift[0] != null) { xcd.pattern[i].type = "HSV"; } if (xcd.pattern[i].ColorP[0] != null || xcd.pattern[i].ColorP[1] != null) { xcd.pattern[i].type = "Coloured"; } //Console.WriteLine("Pattern " + i + ": " + xcd.pattern[i].name + " - " + xcd.pattern[i].type); } cFile.xmlChunk.Add(xcd); //Console.WriteLine(Environment.NewLine); xtr.Close(); }