/// <summary>
        /// reads the pattern package bytes from the sims3pack file
        /// saves read bytes to a .package.tmp file
        /// </summary>
        /// <param name="patternPackage"></param>
        public void createTmpPackageFile(PatternPackage patternPackage)
        {
            BinaryReader binaryReader = new BinaryReader(new FileStream(patternPackage.Sims3PackPath, FileMode.Open, FileAccess.Read));
            binaryReader.BaseStream.Position = patternPackage.BinaryStartPosition + patternPackage.Offset;

            byte[] packageBytes = binaryReader.ReadBytes(patternPackage.Length);

            FileInfo packageSims3PackFileInfo = new FileInfo(patternPackage.Sims3PackPath);
            string fullname = packageSims3PackFileInfo.FullName;
            fullname = fullname.Replace(packageSims3PackFileInfo.Extension, "_tmp.package");

            writeBytesToFile(fullname, packageBytes);
            patternPackage.TmpPackagePath = fullname;
        }
        /// <summary>
        /// decodes main package offset and length from sims3pack xml
        /// </summary>
        /// <param name="patternPackage"></param>
        public void decode(PatternPackage patternPackage)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(patternPackage.Xml);

            XmlNode sims3packNode = xmlDocument.DocumentElement;

            string packageID = "";
            string guid = "";
            int length = -1;
            int offset = -1;

            foreach (XmlNode sims3packChildNode in sims3packNode.ChildNodes)
            {
                if (sims3packChildNode.Name == xmlPackageIdNodeName)
                {
                    packageID = sims3packChildNode.InnerText;
                }
                else if (sims3packChildNode.Name == xmlPackageFileNodeName)
                {
                    foreach (XmlNode packageNode in sims3packChildNode.ChildNodes)
                    {
                        if (packageNode.Name == xmlPackageGuidNodeName)
                        {
                            guid = packageNode.InnerText;
                        }
                        else if (packageNode.Name == xmlPackageLengthNodeName)
                        {
                            length = Convert.ToInt32(packageNode.InnerText);
                        }
                        else if (packageNode.Name == xmlPackageOffsetNodeName)
                        {
                            offset = Convert.ToInt32(packageNode.InnerText);
                        }
                    }

                    //if package is main package get length and offset
                    if (packageID.ToLower() == guid.ToLower())
                    {
                        patternPackage.Length = length;
                        patternPackage.Offset = offset;
                    }

                }
            }
        }
        /// <summary>
        /// reads xml part and start position of the binary part from a Sims3Pack file
        /// </summary>
        /// <param name="path">path of the sims3pack file</param>
        /// <returns></returns>
        public PatternPackage read(string path)
        {
            PatternPackage patternPackage = new PatternPackage(path);

            // Sims3Pack:
            // DWORD length of the following string
            // String
            // WORD
            // DWORD length of the following xml part

            int DWORD = 4;
            int WORD = 2;

            string XMLPart = "";

            BinaryReader binaryReader = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read));

            //read 1. DWORD
            byte[] DWordLength = binaryReader.ReadBytes(DWORD);
            int stringLength = getLengthFromDWord(DWordLength);

            //skip string part and WORD
            binaryReader.BaseStream.Position += stringLength + WORD;

            //read 2. DWORD
            DWordLength = binaryReader.ReadBytes(DWORD);
            int xmlLength = getLengthFromDWord(DWordLength);

            // read XML part and convert it
            byte[] XMLBytes = binaryReader.ReadBytes(xmlLength);
            XMLPart = System.Text.UTF8Encoding.UTF8.GetString(XMLBytes);

            binaryReader.Close();

            patternPackage.BinaryStartPosition = DWORD + stringLength + WORD + DWORD + xmlLength;
            patternPackage.Xml = XMLPart;

            return patternPackage;
        }