示例#1
0
        public static Stream searchForKey(string keyString, string filename)
        {
            // Validate keystring
            if (validateKey(keyString) == false)
            {
                return(null);
            }

            if (!File.Exists(filename))
            {
                return(null);
            }

            keyName tKey    = new keyName(keyString);
            Stream  tStream = null;

            Stream input = File.OpenRead(filename);

            MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(input, true);

            try
            {
                tStream = db.GetResourceStream(tKey.ToResourceKey());
            }
            catch (System.Collections.Generic.KeyNotFoundException ex)
            {
                Helpers.logMessageToFile(ex.Message);
            }
            catch (Exception ex)
            {
                Helpers.logMessageToFile(ex.Message);
            }

            input.Close();

            return(tStream);
        }
        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;
            }
        }
示例#3
0
        public static List <Stream> findKey(List <MadScience.Wrappers.ResourceKey> resourceKeys, int fullBuildNum, MadScience.Wrappers.Database db)
        {
            List <Stream> tempChunks = new List <Stream>();

            // Add one Stream per keyName, even if null
            for (int i = 0; i < resourceKeys.Count; i++)
            {
                tempChunks.Add(new MemoryStream());
            }

            // Check local files first
            if (Helpers.localFiles.Count > 0)
            {
                for (int i = 0; i < resourceKeys.Count; i++)
                {
                    if (Helpers.localFiles.ContainsKey(resourceKeys[i].ToString()))
                    {
                        Stream blah = File.OpenRead((string)Helpers.localFiles[resourceKeys[i].ToString()]);
                        StreamHelpers.CopyStream(blah, tempChunks[i]);
                        tempChunks[i].Seek(0, SeekOrigin.Begin);
                        blah.Close();
                    }
                }
            }

            //check current package
            if (!String.IsNullOrEmpty(Helpers.currentPackageFile))
            {
                Stream localPackage = File.Open(Helpers.currentPackageFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database localDb = new MadScience.Wrappers.Database(localPackage, true);

                for (int i = 0; i < resourceKeys.Count; i++)
                {
                    if (tempChunks[i].Length == 0)
                    {
                        try
                        {
                            tempChunks[i] = localDb.GetResourceStream(resourceKeys[i]);
                        }
                        catch (System.Collections.Generic.KeyNotFoundException)
                        {
                            //Helpers.logMessageToFile(ex.Message);
                        }
                        catch (Exception)
                        {
                            //Helpers.logMessageToFile(ex.Message);
                        }
                    }
                }

                localPackage.Close();
            }

            //check global packages
            foreach (string filename in Helpers.globalPackageFiles)
            {
                if (!String.IsNullOrEmpty(filename))
                {
                    using (Stream localPackage = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        MadScience.Wrappers.Database localDb = new MadScience.Wrappers.Database(localPackage, true);

                        for (int i = 0; i < resourceKeys.Count; i++)
                        {
                            if (tempChunks[i].Length == 0)
                            {
                                try
                                {
                                    tempChunks[i] = localDb.GetResourceStream(resourceKeys[i]);
                                }
                                catch (System.Collections.Generic.KeyNotFoundException)
                                {
                                    //Helpers.logMessageToFile(ex.Message);
                                }
                                catch (Exception)
                                {
                                    //Helpers.logMessageToFile(ex.Message);
                                }
                            }
                        }

                        localPackage.Close();
                    }
                }
            }

            // If input stream isn't null then we use that, otherwise open the fullbuild we want...
            Stream input   = Stream.Null;
            bool   closeDb = false;

            if (db == null)
            {
                closeDb = true;
                try
                {
                    input = File.OpenRead(Path.Combine(Helpers.findSims3Root(), Helpers.getGameSubPath("\\GameData\\Shared\\Packages\\FullBuild" + fullBuildNum.ToString() + ".package")));
                    db    = new MadScience.Wrappers.Database(input, true);
                }
                catch (Exception)
                {
                    return(tempChunks);
                }
            }

            for (int i = 0; i < resourceKeys.Count; i++)
            {
                if (tempChunks[i].Length == 0)
                {
                    //keyName tKey = new keyName(resourceKeys[i]);
                    try
                    {
                        tempChunks[i] = db.GetResourceStream(resourceKeys[i]);
                    }
                    catch (System.Collections.Generic.KeyNotFoundException)
                    {
                        //Helpers.logMessageToFile(ex.Message);
                    }
                    catch (Exception)
                    {
                        //Helpers.logMessageToFile(ex.Message);
                    }
                }
            }
            if (closeDb)
            {
                input.Close();
            }

            return(tempChunks);
        }
        public static Stream searchForKey(string keyString, string filename)
        {
            // Validate keystring
            if (validateKey(keyString) == false)
            {
                return null;
            }

            if (!File.Exists(filename))
            {
                return null;
            }

            keyName tKey = new keyName(keyString);
            Stream tStream = null;

            Stream input = File.OpenRead(filename);
            MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(input, true);

            try
            {

                tStream = db.GetResourceStream(tKey.ToResourceKey());
            }
            catch (System.Collections.Generic.KeyNotFoundException ex)
            {
                Helpers.logMessageToFile(ex.Message);
            }
            catch (Exception ex)
            {
                Helpers.logMessageToFile(ex.Message);
            }

            input.Close();

            return tStream;
        }
        public static List<Stream> findKey(List<MadScience.Wrappers.ResourceKey> resourceKeys, int fullBuildNum, MadScience.Wrappers.Database db)
        {
            List<Stream> tempChunks = new List<Stream>();

            // Add one Stream per keyName, even if null
            for (int i = 0; i < resourceKeys.Count; i++)
            {
                tempChunks.Add(new MemoryStream());
            }

            // Check local files first
            if (Helpers.localFiles.Count > 0)
            {

                for (int i = 0; i < resourceKeys.Count; i++)
                {
                    if (Helpers.localFiles.ContainsKey(resourceKeys[i].ToString()))
                    {
                        Stream blah = File.OpenRead((string)Helpers.localFiles[resourceKeys[i].ToString()]);
                        StreamHelpers.CopyStream(blah, tempChunks[i]);
                        tempChunks[i].Seek(0, SeekOrigin.Begin);
                        blah.Close();
                    }
                }

            }

            //check current package
            if (!String.IsNullOrEmpty(Helpers.currentPackageFile))
            {
                Stream localPackage = File.Open(Helpers.currentPackageFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database localDb = new MadScience.Wrappers.Database(localPackage, true);

                for (int i = 0; i < resourceKeys.Count; i++)
                {
                    if (tempChunks[i].Length == 0)
                    {
                        try
                        {
                            tempChunks[i] = localDb.GetResourceStream(resourceKeys[i]);
                        }
                        catch (System.Collections.Generic.KeyNotFoundException)
                        {
                            //Helpers.logMessageToFile(ex.Message);
                        }
                        catch (Exception)
                        {
                            //Helpers.logMessageToFile(ex.Message);
                        }
                    }
                }

                localPackage.Close();
            }

            //check global packages
            foreach (string filename in Helpers.globalPackageFiles)
            {
                if (!String.IsNullOrEmpty(filename))
                {
                    using (Stream localPackage = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        MadScience.Wrappers.Database localDb = new MadScience.Wrappers.Database(localPackage, true);

                        for (int i = 0; i < resourceKeys.Count; i++)
                        {
                            if (tempChunks[i].Length == 0)
                            {
                                try
                                {
                                    tempChunks[i] = localDb.GetResourceStream(resourceKeys[i]);
                                }
                                catch (System.Collections.Generic.KeyNotFoundException)
                                {
                                    //Helpers.logMessageToFile(ex.Message);
                                }
                                catch (Exception)
                                {
                                    //Helpers.logMessageToFile(ex.Message);
                                }
                            }
                        }

                        localPackage.Close();
                    }
                }
            }

            // If input stream isn't null then we use that, otherwise open the fullbuild we want...
            Stream input = Stream.Null;
            bool closeDb = false;
            if (db == null)
            {
                closeDb = true;
                try
                {
                    input = File.OpenRead(Path.Combine(Helpers.findSims3Root(), Helpers.getGameSubPath("\\GameData\\Shared\\Packages\\FullBuild" + fullBuildNum.ToString() + ".package")));
                    db = new MadScience.Wrappers.Database(input, true);
                }
                catch (Exception)
                {
                    return tempChunks;
                }
            }

            for (int i = 0; i < resourceKeys.Count; i++)
            {
                if (tempChunks[i].Length == 0)
                {

                    //keyName tKey = new keyName(resourceKeys[i]);
                    try
                    {
                        tempChunks[i] = db.GetResourceStream(resourceKeys[i]);
                    }
                    catch (System.Collections.Generic.KeyNotFoundException)
                    {
                        //Helpers.logMessageToFile(ex.Message);
                    }
                    catch (Exception)
                    {
                        //Helpers.logMessageToFile(ex.Message);
                    }
                }
            }
            if (closeDb)
            {
                input.Close();
            }

            return tempChunks;
        }
        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;
            }
        }