public static Stream findPattern(patternDetails pattern) { Wrappers.ResourceKey rKey = new MadScience.Wrappers.ResourceKey(0x00B2D882, 0x0, StringHelpers.HashFNV64(pattern.name)); Stream patternThumb = KeyUtils.findKey(rKey); return(patternThumb); }
public static Image makePatternThumb(Stream input) { Wrappers.Database db = new MadScience.Wrappers.Database(input, true); patternDetails pattern = parsePatternComplate(MadScience.Package.Search.getStream(db, 0x0333406C, -1, -1)); Image img = makePatternThumb(pattern, db); return(img); }
public static patternDetails parsePatternComplate(Stream xmlStream) { int level = 0; string curPattern = ""; Patterns.patternDetails pDetail = new patternDetails(); if (xmlStream == null) return pDetail; string patternTexture = ""; XmlTextReader xtr = new XmlTextReader(xmlStream); while (xtr.Read()) { if (xtr.NodeType == XmlNodeType.Element) { switch (xtr.Name) { case "complate": level++; pDetail.name = xtr.GetAttribute("name"); pDetail.category = xtr.GetAttribute("category"); pDetail.key = xtr.GetAttribute("reskey"); break; case "variables": level++; break; case "texturePart": level++; break; case "destination": level++; break; case "param": if (level == 1) { // Normal complate stuff xtr.MoveToNextAttribute(); //Console.WriteLine(xtr.Value); } if (level == 2) { // Inside pattern xtr.MoveToAttribute("name"); //Console.WriteLine(xtr.Value); switch (xtr.Value) { case "assetRoot": pDetail.assetRoot = xtr.GetAttribute("default"); break; case "Color": pDetail.Color = xtr.GetAttribute("default"); break; case "Color 0": pDetail.ColorP[0] = xtr.GetAttribute("default"); break; case "Color 1": pDetail.ColorP[1] = xtr.GetAttribute("default"); break; case "Color 2": pDetail.ColorP[2] = xtr.GetAttribute("default"); break; case "Color 3": pDetail.ColorP[3] = xtr.GetAttribute("default"); break; case "Color 4": pDetail.ColorP[4] = xtr.GetAttribute("default"); break; case "Channel 1": pDetail.Channel[0] = xtr.GetAttribute("default"); break; case "Channel 2": pDetail.Channel[1] = xtr.GetAttribute("default"); break; case "Channel 3": pDetail.Channel[2] = xtr.GetAttribute("default"); break; case "Channel 1 Enabled": pDetail.ChannelEnabled[0] = xtr.GetAttribute("default"); break; case "Channel 2 Enabled": pDetail.ChannelEnabled[1] = xtr.GetAttribute("default"); break; case "Channel 3 Enabled": pDetail.ChannelEnabled[2] = xtr.GetAttribute("default"); break; case "Background Image": pDetail.BackgroundImage = xtr.GetAttribute("default"); if (patternTexture == "") patternTexture = pDetail.BackgroundImage; break; case "H Bg": pDetail.HBg = xtr.GetAttribute("default"); break; case "H 1": pDetail.H[0] = xtr.GetAttribute("default"); break; case "H 2": pDetail.H[1] = xtr.GetAttribute("default"); break; case "H 3": pDetail.H[2] = xtr.GetAttribute("default"); break; case "S Bg": pDetail.SBg = xtr.GetAttribute("default"); break; case "S 1": pDetail.S[0] = xtr.GetAttribute("default"); break; case "S 2": pDetail.S[1] = xtr.GetAttribute("default"); break; case "S 3": pDetail.S[2] = xtr.GetAttribute("default"); break; case "V Bg": pDetail.VBg = xtr.GetAttribute("default"); break; case "V 1": pDetail.V[0] = xtr.GetAttribute("default"); break; case "V 2": pDetail.V[1] = xtr.GetAttribute("default"); break; case "V 3": pDetail.V[2] = xtr.GetAttribute("default"); break; case "Base H Bg": pDetail.BaseHBg = xtr.GetAttribute("default"); break; case "Base H 1": pDetail.BaseH[0] = xtr.GetAttribute("default"); break; case "Base H 2": pDetail.BaseH[1] = xtr.GetAttribute("default"); break; case "Base H 3": pDetail.BaseH[2] = xtr.GetAttribute("default"); break; case "Base S Bg": pDetail.BaseSBg = xtr.GetAttribute("default"); break; case "Base S 1": pDetail.BaseS[0] = xtr.GetAttribute("default"); break; case "Base S 2": pDetail.BaseS[1] = xtr.GetAttribute("default"); break; case "Base S 3": pDetail.BaseS[2] = xtr.GetAttribute("default"); break; case "Base V Bg": pDetail.BaseVBg = xtr.GetAttribute("default"); break; case "Base V 1": pDetail.BaseV[0] = xtr.GetAttribute("default"); break; case "Base V 2": pDetail.BaseV[1] = xtr.GetAttribute("default"); break; case "Base V 3": pDetail.BaseV[2] = xtr.GetAttribute("default"); break; case "HSVShift Bg": pDetail.HSVShiftBg = xtr.GetAttribute("default"); break; case "HSVShift 1": pDetail.HSVShift[0] = xtr.GetAttribute("default"); break; case "HSVShift 2": pDetail.HSVShift[1] = xtr.GetAttribute("default"); break; case "HSVShift 3": pDetail.HSVShift[2] = xtr.GetAttribute("default"); break; case "rgbmask": pDetail.rgbmask = xtr.GetAttribute("default"); if (patternTexture == "") patternTexture = pDetail.rgbmask; break; case "specmap": pDetail.specmap = xtr.GetAttribute("default"); break; case "filename": pDetail.filename = xtr.GetAttribute("default"); pDetail.nameHigh = xtr.GetAttribute("default"); 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; break; case "step": if (level == 3) { // Inside pattern xtr.MoveToAttribute("type"); switch (xtr.Value) { case "ColorFill": if (xtr.AttributeCount == 2) { // Okay here we have to get creative. In-Game patterns often have the params as Color 1 through 4, but custom patterns have them as Color 0 through 3. // What we need to do is to try and detect which this pattern is - in-game or custom, and to shift things accordingly so we can load the background colour in. if (pDetail.ColorP[0] != null) { // We already have a background color... so check to see if we are already filled up if (pDetail.ColorP[4] == null) { pDetail.ColorP[4] = pDetail.ColorP[3]; pDetail.ColorP[3] = pDetail.ColorP[2]; pDetail.ColorP[2] = pDetail.ColorP[1]; pDetail.ColorP[1] = pDetail.ColorP[0]; } xtr.MoveToAttribute("color"); pDetail.ColorP[0] = xtr.Value; } } break; } } break; } } if (xtr.NodeType == XmlNodeType.EndElement) { switch (xtr.Name) { case "variables": level--; break; case "complate": level--; break; case "texturePart": level--; break; case "destination": level--; break; } } } if (patternTexture != "") { //Console.WriteLine(lookupList.Items[i].fullCasPartname); if (!MadScience.KeyUtils.validateKey(patternTexture, false)) { patternTexture = patternTexture.Replace(@"($assetRoot)\InGame\Complates\", ""); patternTexture = patternTexture.Replace(@".tga", ""); patternTexture = patternTexture.Replace(@".dds", ""); } else { // This is a custom pattern so we have to construct up the filename ourselves patternTexture = "Materials\\" + pDetail.category + "\\" + pDetail.name; } pDetail.filename = patternTexture; pDetail.nameHigh = patternTexture; } if (!String.IsNullOrEmpty(pDetail.rgbmask) && !MadScience.KeyUtils.validateKey(pDetail.rgbmask, false)) { // Need to change rgbmask to key format pDetail.rgbmask = "key:00B2D882:00000000:" + MadScience.StringHelpers.HashFNV64(pDetail.rgbmask.Substring(pDetail.rgbmask.LastIndexOf("\\") + 1).Replace(@".tga", "").Replace(@".dds", "")).ToString("X16"); } if (!String.IsNullOrEmpty(pDetail.specmap) && !MadScience.KeyUtils.validateKey(pDetail.specmap, false)) { // Need to change rgbmask to key format pDetail.specmap = "key:00B2D882:00000000:" + MadScience.StringHelpers.HashFNV64(pDetail.specmap.Substring(pDetail.specmap.LastIndexOf("\\") + 1).Replace(@".tga", "").Replace(@".dds", "")).ToString("X16"); } if (!String.IsNullOrEmpty(pDetail.BackgroundImage) && !MadScience.KeyUtils.validateKey(pDetail.BackgroundImage, false)) { pDetail.BackgroundImage = "key:00B2D882:00000000:" + MadScience.StringHelpers.HashFNV64(pDetail.BackgroundImage.Substring(pDetail.BackgroundImage.LastIndexOf("\\") + 1).Replace(@".tga", "").Replace(@".dds", "")).ToString("X16"); } if (pDetail.name.StartsWith("solidColor") || pDetail.name.StartsWith("Flat Color")) { pDetail.type = "solidColor"; } if (!String.IsNullOrEmpty(pDetail.HSVShiftBg) || !String.IsNullOrEmpty(pDetail.HSVShift[0]) || !String.IsNullOrEmpty(pDetail.HBg) || !String.IsNullOrEmpty(pDetail.BaseHBg) || !String.IsNullOrEmpty(pDetail.H[0])) { pDetail.type = "HSV"; } if (pDetail.ColorP[1] != null) { pDetail.type = "Coloured"; } // If we have no type, default to Coloured to be on the safe side if (String.IsNullOrEmpty(pDetail.type)) pDetail.type = "Coloured"; //Console.WriteLine("Pattern " + i + ": " + xcd.pattern[i].name + " - " + xcd.pattern[i].type); //Console.WriteLine(Environment.NewLine); xtr.Close(); return pDetail; }
public static Image makePatternThumb(patternDetails pattern, Wrappers.Database db) { Image temp = null; if (pattern.type == "HSV") { DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile(); Colours.HSVColor channel1Color = new Colours.HSVColor(); Colours.HSVColor channel2Color = new Colours.HSVColor(); Colours.HSVColor channel3Color = new Colours.HSVColor(); Colours.HSVColor backColor = new Colours.HSVColor(Convert.ToDouble(pattern.HBg, CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.SBg, CultureInfo.InvariantCulture), Convert.ToDouble(pattern.VBg, CultureInfo.InvariantCulture)); bool[] channelsEnabled = new bool[3]; if (pattern.ChannelEnabled[0] != null && pattern.ChannelEnabled[0].ToLower() == "true") { channel1Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[0], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[0], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[0], CultureInfo.InvariantCulture)); channelsEnabled[0] = true; } if (pattern.ChannelEnabled[1] != null && pattern.ChannelEnabled[1].ToLower() == "true") { channel2Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[1], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[1], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[1], CultureInfo.InvariantCulture)); channelsEnabled[1] = true; } if (pattern.ChannelEnabled[2] != null && pattern.ChannelEnabled[2].ToLower() == "true") { channel3Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[2], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[2], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[2], CultureInfo.InvariantCulture)); channelsEnabled[2] = true; } if (isEmptyMask(pattern.rgbmask)) { if (db != null) { temp = Patterns.createHSVPattern(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.BackgroundImage), 2, db), backColor); } else { temp = Patterns.createHSVPattern(KeyUtils.findKey(pattern.BackgroundImage), backColor); } } else { if (db != null) { temp = Patterns.createHSVPattern(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.BackgroundImage), 2, db), KeyUtils.findKey(new Wrappers.ResourceKey(pattern.rgbmask), 2, db), backColor, KeyUtils.findKey(new MadScience.Wrappers.ResourceKey(makeKey(pattern.Channel[0])), 0, db), KeyUtils.findKey(new Wrappers.ResourceKey(makeKey(pattern.Channel[1])), 0, db), KeyUtils.findKey(new Wrappers.ResourceKey(makeKey(pattern.Channel[2])), 0, db), channel1Color, channel2Color, channel3Color, channelsEnabled); } else { temp = Patterns.createHSVPattern(KeyUtils.findKey(pattern.BackgroundImage), KeyUtils.findKey(pattern.rgbmask), backColor, KeyUtils.findKey(makeKey(pattern.Channel[0])), KeyUtils.findKey(makeKey(pattern.Channel[1])), KeyUtils.findKey(makeKey(pattern.Channel[2])), channel1Color, channel2Color, channel3Color, channelsEnabled); } } } else if (pattern.type == "Coloured") { DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile(); Color bgColor = Colours.convertColour(pattern.ColorP[0], true); if (bgColor == Color.Empty) { bgColor = Color.Black; } if (pattern.isCustom) { // We need this in here becuase findKey only searches the game files and any local DDS files - it // doesn't search custom packages if (File.Exists(pattern.customFilename)) { Stream patternThumb = KeyUtils.searchForKey(pattern.rgbmask, pattern.customFilename); if (!StreamHelpers.isValidStream(patternThumb)) { patternThumb = KeyUtils.searchForKey(pattern.BackgroundImage, pattern.customFilename); } if (StreamHelpers.isValidStream(patternThumb)) { ddsP.Load(patternThumb); } patternThumb.Close(); } } else { if (db != null) { ddsP.Load(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.rgbmask), 2, db)); } else { ddsP.Load(KeyUtils.findKey(pattern.rgbmask)); } } temp = ddsP.Image(bgColor, Colours.convertColour(pattern.ColorP[1], true), Colours.convertColour(pattern.ColorP[2], true), Colours.convertColour(pattern.ColorP[3], true), Colours.convertColour(pattern.ColorP[4], true)); } else if (pattern.type == "solidColor") { temp = new Bitmap(256,256); using (Graphics g = Graphics.FromImage(temp)) { g.FillRectangle(new SolidBrush(Colours.convertColour(pattern.Color)),0,0,256,256); } } return temp; }
public static Image makePatternThumb(patternDetails pattern) { return makePatternThumb(pattern, null); }
public static Stream findPattern(patternDetails pattern) { Wrappers.ResourceKey rKey = new MadScience.Wrappers.ResourceKey(0x00B2D882, 0x0, StringHelpers.HashFNV64(pattern.name)); Stream patternThumb = KeyUtils.findKey(rKey); return patternThumb; }
public static Image makePatternThumb(patternDetails pattern) { return(makePatternThumb(pattern, null)); }
public static patternDetails parsePatternComplate(Stream xmlStream) { int level = 0; string curPattern = ""; Patterns.patternDetails pDetail = new patternDetails(); if (xmlStream == null) { return(pDetail); } string patternTexture = ""; XmlTextReader xtr = new XmlTextReader(xmlStream); while (xtr.Read()) { if (xtr.NodeType == XmlNodeType.Element) { switch (xtr.Name) { case "complate": level++; pDetail.name = xtr.GetAttribute("name"); pDetail.category = xtr.GetAttribute("category"); pDetail.key = xtr.GetAttribute("reskey"); break; case "variables": level++; break; case "texturePart": level++; break; case "destination": level++; break; case "param": if (level == 1) { // Normal complate stuff xtr.MoveToNextAttribute(); //Console.WriteLine(xtr.Value); } if (level == 2) { // Inside pattern xtr.MoveToAttribute("name"); //Console.WriteLine(xtr.Value); switch (xtr.Value) { case "assetRoot": pDetail.assetRoot = xtr.GetAttribute("default"); break; case "Color": pDetail.Color = xtr.GetAttribute("default"); break; case "Color 0": pDetail.ColorP[0] = xtr.GetAttribute("default"); break; case "Color 1": pDetail.ColorP[1] = xtr.GetAttribute("default"); break; case "Color 2": pDetail.ColorP[2] = xtr.GetAttribute("default"); break; case "Color 3": pDetail.ColorP[3] = xtr.GetAttribute("default"); break; case "Color 4": pDetail.ColorP[4] = xtr.GetAttribute("default"); break; case "Channel 1": pDetail.Channel[0] = xtr.GetAttribute("default"); break; case "Channel 2": pDetail.Channel[1] = xtr.GetAttribute("default"); break; case "Channel 3": pDetail.Channel[2] = xtr.GetAttribute("default"); break; case "Channel 1 Enabled": pDetail.ChannelEnabled[0] = xtr.GetAttribute("default"); break; case "Channel 2 Enabled": pDetail.ChannelEnabled[1] = xtr.GetAttribute("default"); break; case "Channel 3 Enabled": pDetail.ChannelEnabled[2] = xtr.GetAttribute("default"); break; case "Background Image": pDetail.BackgroundImage = xtr.GetAttribute("default"); if (patternTexture == "") { patternTexture = pDetail.BackgroundImage; } break; case "H Bg": pDetail.HBg = xtr.GetAttribute("default"); break; case "H 1": pDetail.H[0] = xtr.GetAttribute("default"); break; case "H 2": pDetail.H[1] = xtr.GetAttribute("default"); break; case "H 3": pDetail.H[2] = xtr.GetAttribute("default"); break; case "S Bg": pDetail.SBg = xtr.GetAttribute("default"); break; case "S 1": pDetail.S[0] = xtr.GetAttribute("default"); break; case "S 2": pDetail.S[1] = xtr.GetAttribute("default"); break; case "S 3": pDetail.S[2] = xtr.GetAttribute("default"); break; case "V Bg": pDetail.VBg = xtr.GetAttribute("default"); break; case "V 1": pDetail.V[0] = xtr.GetAttribute("default"); break; case "V 2": pDetail.V[1] = xtr.GetAttribute("default"); break; case "V 3": pDetail.V[2] = xtr.GetAttribute("default"); break; case "Base H Bg": pDetail.BaseHBg = xtr.GetAttribute("default"); break; case "Base H 1": pDetail.BaseH[0] = xtr.GetAttribute("default"); break; case "Base H 2": pDetail.BaseH[1] = xtr.GetAttribute("default"); break; case "Base H 3": pDetail.BaseH[2] = xtr.GetAttribute("default"); break; case "Base S Bg": pDetail.BaseSBg = xtr.GetAttribute("default"); break; case "Base S 1": pDetail.BaseS[0] = xtr.GetAttribute("default"); break; case "Base S 2": pDetail.BaseS[1] = xtr.GetAttribute("default"); break; case "Base S 3": pDetail.BaseS[2] = xtr.GetAttribute("default"); break; case "Base V Bg": pDetail.BaseVBg = xtr.GetAttribute("default"); break; case "Base V 1": pDetail.BaseV[0] = xtr.GetAttribute("default"); break; case "Base V 2": pDetail.BaseV[1] = xtr.GetAttribute("default"); break; case "Base V 3": pDetail.BaseV[2] = xtr.GetAttribute("default"); break; case "HSVShift Bg": pDetail.HSVShiftBg = xtr.GetAttribute("default"); break; case "HSVShift 1": pDetail.HSVShift[0] = xtr.GetAttribute("default"); break; case "HSVShift 2": pDetail.HSVShift[1] = xtr.GetAttribute("default"); break; case "HSVShift 3": pDetail.HSVShift[2] = xtr.GetAttribute("default"); break; case "rgbmask": pDetail.rgbmask = xtr.GetAttribute("default"); if (patternTexture == "") { patternTexture = pDetail.rgbmask; } break; case "specmap": pDetail.specmap = xtr.GetAttribute("default"); break; case "filename": pDetail.filename = xtr.GetAttribute("default"); pDetail.nameHigh = xtr.GetAttribute("default"); 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; break; case "step": if (level == 3) { // Inside pattern xtr.MoveToAttribute("type"); switch (xtr.Value) { case "ColorFill": if (xtr.AttributeCount == 2) { // Okay here we have to get creative. In-Game patterns often have the params as Color 1 through 4, but custom patterns have them as Color 0 through 3. // What we need to do is to try and detect which this pattern is - in-game or custom, and to shift things accordingly so we can load the background colour in. if (pDetail.ColorP[0] != null) { // We already have a background color... so check to see if we are already filled up if (pDetail.ColorP[4] == null) { pDetail.ColorP[4] = pDetail.ColorP[3]; pDetail.ColorP[3] = pDetail.ColorP[2]; pDetail.ColorP[2] = pDetail.ColorP[1]; pDetail.ColorP[1] = pDetail.ColorP[0]; } xtr.MoveToAttribute("color"); pDetail.ColorP[0] = xtr.Value; } } break; } } break; } } if (xtr.NodeType == XmlNodeType.EndElement) { switch (xtr.Name) { case "variables": level--; break; case "complate": level--; break; case "texturePart": level--; break; case "destination": level--; break; } } } if (patternTexture != "") { //Console.WriteLine(lookupList.Items[i].fullCasPartname); if (!MadScience.KeyUtils.validateKey(patternTexture, false)) { patternTexture = patternTexture.Replace(@"($assetRoot)\InGame\Complates\", ""); patternTexture = patternTexture.Replace(@".tga", ""); patternTexture = patternTexture.Replace(@".dds", ""); } else { // This is a custom pattern so we have to construct up the filename ourselves patternTexture = "Materials\\" + pDetail.category + "\\" + pDetail.name; } pDetail.filename = patternTexture; pDetail.nameHigh = patternTexture; } if (!String.IsNullOrEmpty(pDetail.rgbmask) && !MadScience.KeyUtils.validateKey(pDetail.rgbmask, false)) { // Need to change rgbmask to key format pDetail.rgbmask = "key:00B2D882:00000000:" + MadScience.StringHelpers.HashFNV64(pDetail.rgbmask.Substring(pDetail.rgbmask.LastIndexOf("\\") + 1).Replace(@".tga", "").Replace(@".dds", "")).ToString("X16"); } if (!String.IsNullOrEmpty(pDetail.specmap) && !MadScience.KeyUtils.validateKey(pDetail.specmap, false)) { // Need to change rgbmask to key format pDetail.specmap = "key:00B2D882:00000000:" + MadScience.StringHelpers.HashFNV64(pDetail.specmap.Substring(pDetail.specmap.LastIndexOf("\\") + 1).Replace(@".tga", "").Replace(@".dds", "")).ToString("X16"); } if (!String.IsNullOrEmpty(pDetail.BackgroundImage) && !MadScience.KeyUtils.validateKey(pDetail.BackgroundImage, false)) { pDetail.BackgroundImage = "key:00B2D882:00000000:" + MadScience.StringHelpers.HashFNV64(pDetail.BackgroundImage.Substring(pDetail.BackgroundImage.LastIndexOf("\\") + 1).Replace(@".tga", "").Replace(@".dds", "")).ToString("X16"); } if (pDetail.name.StartsWith("solidColor") || pDetail.name.StartsWith("Flat Color")) { pDetail.type = "solidColor"; } if (!String.IsNullOrEmpty(pDetail.HSVShiftBg) || !String.IsNullOrEmpty(pDetail.HSVShift[0]) || !String.IsNullOrEmpty(pDetail.HBg) || !String.IsNullOrEmpty(pDetail.BaseHBg) || !String.IsNullOrEmpty(pDetail.H[0])) { pDetail.type = "HSV"; } if (pDetail.ColorP[1] != null) { pDetail.type = "Coloured"; } // If we have no type, default to Coloured to be on the safe side if (String.IsNullOrEmpty(pDetail.type)) { pDetail.type = "Coloured"; } //Console.WriteLine("Pattern " + i + ": " + xcd.pattern[i].name + " - " + xcd.pattern[i].type); //Console.WriteLine(Environment.NewLine); xtr.Close(); return(pDetail); }
public static Image makePatternThumb(patternDetails pattern, Wrappers.Database db) { Image temp = null; if (pattern.type == "HSV") { DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile(); Colours.HSVColor channel1Color = new Colours.HSVColor(); Colours.HSVColor channel2Color = new Colours.HSVColor(); Colours.HSVColor channel3Color = new Colours.HSVColor(); Colours.HSVColor backColor = new Colours.HSVColor(Convert.ToDouble(pattern.HBg, CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.SBg, CultureInfo.InvariantCulture), Convert.ToDouble(pattern.VBg, CultureInfo.InvariantCulture)); bool[] channelsEnabled = new bool[3]; if (pattern.ChannelEnabled[0] != null && pattern.ChannelEnabled[0].ToLower() == "true") { channel1Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[0], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[0], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[0], CultureInfo.InvariantCulture)); channelsEnabled[0] = true; } if (pattern.ChannelEnabled[1] != null && pattern.ChannelEnabled[1].ToLower() == "true") { channel2Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[1], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[1], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[1], CultureInfo.InvariantCulture)); channelsEnabled[1] = true; } if (pattern.ChannelEnabled[2] != null && pattern.ChannelEnabled[2].ToLower() == "true") { channel3Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[2], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[2], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[2], CultureInfo.InvariantCulture)); channelsEnabled[2] = true; } if (isEmptyMask(pattern.rgbmask)) { if (db != null) { temp = Patterns.createHSVPattern(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.BackgroundImage), 2, db), backColor); } else { temp = Patterns.createHSVPattern(KeyUtils.findKey(pattern.BackgroundImage), backColor); } } else { if (db != null) { temp = Patterns.createHSVPattern(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.BackgroundImage), 2, db), KeyUtils.findKey(new Wrappers.ResourceKey(pattern.rgbmask), 2, db), backColor, KeyUtils.findKey(new MadScience.Wrappers.ResourceKey(makeKey(pattern.Channel[0])), 0, db), KeyUtils.findKey(new Wrappers.ResourceKey(makeKey(pattern.Channel[1])), 0, db), KeyUtils.findKey(new Wrappers.ResourceKey(makeKey(pattern.Channel[2])), 0, db), channel1Color, channel2Color, channel3Color, channelsEnabled); } else { temp = Patterns.createHSVPattern(KeyUtils.findKey(pattern.BackgroundImage), KeyUtils.findKey(pattern.rgbmask), backColor, KeyUtils.findKey(makeKey(pattern.Channel[0])), KeyUtils.findKey(makeKey(pattern.Channel[1])), KeyUtils.findKey(makeKey(pattern.Channel[2])), channel1Color, channel2Color, channel3Color, channelsEnabled); } } } else if (pattern.type == "Coloured") { DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile(); Color bgColor = Colours.convertColour(pattern.ColorP[0], true); if (bgColor == Color.Empty) { bgColor = Color.Black; } if (pattern.isCustom) { // We need this in here becuase findKey only searches the game files and any local DDS files - it // doesn't search custom packages if (File.Exists(pattern.customFilename)) { Stream patternThumb = KeyUtils.searchForKey(pattern.rgbmask, pattern.customFilename); if (!StreamHelpers.isValidStream(patternThumb)) { patternThumb = KeyUtils.searchForKey(pattern.BackgroundImage, pattern.customFilename); } if (StreamHelpers.isValidStream(patternThumb)) { ddsP.Load(patternThumb); } patternThumb.Close(); } } else { if (db != null) { ddsP.Load(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.rgbmask), 2, db)); } else { ddsP.Load(KeyUtils.findKey(pattern.rgbmask)); } } temp = ddsP.Image(bgColor, Colours.convertColour(pattern.ColorP[1], true), Colours.convertColour(pattern.ColorP[2], true), Colours.convertColour(pattern.ColorP[3], true), Colours.convertColour(pattern.ColorP[4], true)); } else if (pattern.type == "solidColor") { temp = new Bitmap(256, 256); using (Graphics g = Graphics.FromImage(temp)) { g.FillRectangle(new SolidBrush(Colours.convertColour(pattern.Color)), 0, 0, 256, 256); } } return(temp); }