private static void UnpackXBox360Package(string sourceFileName, string savePath, Platform platform)
        {
            LogRecord   x           = new LogRecord();
            STFSPackage xboxPackage = new STFSPackage(sourceFileName, x);

            if (!xboxPackage.ParseSuccess)
            {
                throw new InvalidDataException("Invalid Rocksmith XBox 360 package!" + Environment.NewLine + x.Log);
            }

            var rootDir = Path.Combine(savePath, Path.GetFileNameWithoutExtension(sourceFileName)) + String.Format("_{0}", platform.platform.ToString());

            xboxPackage.ExtractPayload(rootDir, true, true);

            foreach (var fileName in Directory.EnumerateFiles(Path.Combine(rootDir, ROOT_XBox360)))
            {
                if (Path.GetExtension(fileName) == ".psarc")
                {
                    using (var outputFileStream = File.OpenRead(fileName))
                    {
                        ExtractPSARC(fileName, Path.GetDirectoryName(fileName), outputFileStream, new Platform(GamePlatform.XBox360, GameVersion.None), false);
                    }
                }

                if (File.Exists(fileName) && Path.GetExtension(fileName) == ".psarc")
                {
                    File.Delete(fileName);
                }
            }

            xboxPackage.CloseIO();
        }
Esempio n. 2
0
        private void installGamePackageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.ShowDialog();
            if (File.Exists(ofd.FileName))
            {
                // Open STFS Package
                STFSPackage package = new STFSPackage(ofd.FileName, null);

                // Unpack Archive
                string titleName = package.Header.Title_Display;
                string path      = "Games/" + titleName;
                if (Directory.Exists(path))
                {
                    package.CloseIO();
                    goto CheckXNA;
                }
                Directory.CreateDirectory(path);
                MessageBox.Show("Ex360E will now install the game package, this may take a while\n and may appear to stop responding. Please be patient.");
                package.ExtractPayload(path, true, false);
                package.CloseIO();
CheckXNA:
                path += "/Root/";
                // Check if XNA title
                if (!Directory.Exists(path + "Runtime"))
                {
                    MessageBox.Show("Package not supported\nOnly XBLA games created with XNA Game Studio currently work.");
                    return;
                }

                // Check if supported
                string[] directories = Directory.GetDirectories(path + "Runtime");

                string frameworkVersion = "Unsupported";
                for (int i = 0; i < directories.Length; i++)
                {
                    // Currently only supports XNA 3.1
                    if (directories[i].Contains("v3.1"))
                    {
                        frameworkVersion = "v3.1";
                    }
                }
                if (frameworkVersion == "Unsupported")
                {
                    MessageBox.Show("Sorry, this game uses a currently unsupported version of the XNA Framework.");
                    return;
                }

                // Decrypt XEX Files
                string[] xexFiles = Directory.GetFiles(path, "*.xex", SearchOption.AllDirectories);
                for (int i = 0; i < xexFiles.Length; i++)
                {
                    ProcessStartInfo info = new ProcessStartInfo("xextool.exe", "-b " + xexFiles[i].Replace(".xex", "") + " " + xexFiles[i]);
                    info.CreateNoWindow         = true;
                    info.UseShellExecute        = false;
                    info.RedirectStandardOutput = true;
                    Process proc = new Process();
                    proc.StartInfo = info;
                    proc.Start();
                    proc.WaitForExit();
                }

                // Trim useless PE Headers, leaving .NET assemblies behind
                string[] dllFiles = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);
                string[] exeFiles = Directory.GetFiles(path, "*.exe", SearchOption.AllDirectories);

                for (int i = 0; i < dllFiles.Length; i++)
                {
                    string     tmpFileName = dllFiles[i] + ".tmp";
                    FileStream inStream    = new FileStream(dllFiles[i], FileMode.Open);
                    FileStream outStream;

                    // Set position
                    inStream.Position = 0x30000;

                    // Read Magic Number
                    byte[] magic = new Byte[2];
                    inStream.Read(magic, 0, 2);

                    // Check for MZ Header
                    if (magic[0] == 0x4D && magic[1] == 0x5A)
                    {
                        outStream = new FileStream(tmpFileName, FileMode.Create);
                        // Reset Position
                        inStream.Position = 0x30000;

                        // Copy data to temporary file
                        int    bufferSize = (int)inStream.Length - 0x30000;
                        byte[] outData    = new byte[bufferSize];
                        inStream.Read(outData, 0, bufferSize);
                        inStream.Close();
                        outStream.Write(outData, 0, bufferSize);
                        outStream.Flush();
                        outStream.Close();
                        File.Delete(dllFiles[i]);
                        File.Move(tmpFileName, dllFiles[i]);
                    }
                }

                for (int i = 0; i < exeFiles.Length; i++)
                {
                    string     tmpFileName = dllFiles[i] + ".tmp";
                    FileStream inStream    = new FileStream(exeFiles[i], FileMode.Open);
                    FileStream outStream;

                    // Set position
                    inStream.Position = 0x30000;

                    // Read Magic Number
                    byte[] magic = new Byte[2];
                    inStream.Read(magic, 0, 2);

                    // Check for MZ Header
                    if (magic[0] == 0x4D && magic[1] == 0x5A)
                    {
                        outStream = new FileStream(tmpFileName, FileMode.Create);

                        // Reset Position
                        inStream.Position = 0x30000;

                        // Copy data to temporary file
                        int    bufferSize = (int)inStream.Length - 0x30000;
                        byte[] outData    = new byte[bufferSize];
                        inStream.Read(outData, 0, bufferSize);
                        inStream.Close();
                        outStream.Write(outData, 0, bufferSize);
                        outStream.Flush();
                        outStream.Close();
                        File.Delete(exeFiles[i]);
                        File.Move(tmpFileName, exeFiles[i]);
                    }
                }

                // Patch And Copy Runtime Files
                string[] XNALibs = Directory.GetFiles(path + "Runtime/" + frameworkVersion, "*.dll");
                for (int i = 0; i < XNALibs.Length; i++)
                {
                    // Patch files
                    string patchFile = XNALibs[i].Replace(path, "Patches/") + ".xdelta";
                    string destFile  = XNALibs[i].Replace("Runtime/" + frameworkVersion, "");

                    // If patch exists, apply it
                    if (File.Exists(patchFile))
                    {
                        ProcessStartInfo info = new ProcessStartInfo("xdelta", " -d -f -s " + XNALibs[i] + " " + patchFile + " " + destFile);
                        info.CreateNoWindow         = true;
                        info.UseShellExecute        = false;
                        info.RedirectStandardOutput = true;
                        Process proc = new Process();
                        proc.StartInfo = info;
                        proc.Start();
                        proc.WaitForExit();
                    }

                    // Copy un-patched files
                    if (!File.Exists(destFile))
                    {
                        File.Move(XNALibs[i], XNALibs[i].Replace("Runtime/" + frameworkVersion, ""));
                    }

                    // Patch to remove assembly verification
                    DisableStrongNameSignatures(destFile);
                }

                // Patch Game Files
                string[] GameFiles = Directory.GetFiles(path, "*.*");
                for (int i = 0; i < GameFiles.Length; i++)
                {
                    // Patch files
                    string patchFile = GameFiles[i].Replace(path, "Patches/Games/" + titleName + "/") + ".xdelta";
                    string destFile  = GameFiles[i] + ".patched";

                    // If patch exists, apply it
                    if (File.Exists(patchFile))
                    {
                        ProcessStartInfo info = new ProcessStartInfo("xdelta", " -d -f -s " + GameFiles[i] + " " + patchFile + " " + destFile);
                        info.CreateNoWindow         = true;
                        info.UseShellExecute        = false;
                        info.RedirectStandardOutput = true;
                        Process proc = new Process();
                        proc.StartInfo = info;
                        proc.Start();
                        proc.WaitForExit();
                        File.Delete(GameFiles[i]);
                        File.Move(destFile, GameFiles[i]);
                    }

                    DisableStrongNameSignatures(GameFiles[i]);
                }


                // Copy Xbox 360 Emulation libraries
                string[] X360Libs = Directory.GetFiles("XboxLibs", "*.dll");
                for (int i = 0; i < X360Libs.Length; i++)
                {
                    File.Copy(X360Libs[i], X360Libs[i].Replace("XboxLibs", path), true);
                }

                // Ask to create desktop shortcut to game

                // Ask if game should be launched now
            }
        }
Esempio n. 3
0
        private bool extractRBFiles()
        {
            var counter = 0;
            var success = 0;

            foreach (var file in inputFiles)
            {
                if (backgroundWorker1.CancellationPending)
                {
                    return(false);
                }
                try
                {
                    if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS)
                    {
                        continue;
                    }
                    try
                    {
                        counter++;
                        Parser.ExtractDTA(file);
                        Parser.ReadDTA(Parser.DTA);
                        if (Parser.Songs.Count > 1)
                        {
                            Log("File " + Path.GetFileName(file) + " is a pack, try dePACKing first, skipping...");
                            continue;
                        }

                        var xPackage = new STFSPackage(file);
                        if (!xPackage.ParseSuccess)
                        {
                            Log("Failed to extract '" + Path.GetFileName(file) + "'");
                            Log("Skipping this file");
                        }

                        //if working inner temp folder exists, delete to start clean
                        var temptempFile = tempFolder + "temp\\";
                        Tools.DeleteFolder(temptempFile, true);

                        if (backgroundWorker1.CancellationPending)
                        {
                            xPackage.CloseIO();
                            return(false);
                        }

                        //extract songs folder, subfolders and all files into a combined directory
                        xPackage.ExtractPayload(temptempFile, true, false);
                        xPackage.CloseIO();
                        temptempFile = temptempFile + "root\\";
                        if (Directory.Exists(temptempFile + "songs\\"))
                        {
                            var subFolders   = Directory.GetDirectories(temptempFile + "songs\\");
                            var tempFileName = subFolders[0].Substring((temptempFile + "songs\\").Length,
                                                                       subFolders[0].Length -
                                                                       (temptempFile + "songs\\").Length);

                            if (subFolders.Count() != 0)
                            //upgrades won't have subdirectories, skip this step in that case
                            {
                                if (File.Exists(temptempFile + "songs\\songs.dta"))
                                {
                                    //move songs.dta to the song's folder for sorting later
                                    //allows to skip duplicates
                                    Tools.MoveFile(temptempFile + "songs\\songs.dta",
                                                   temptempFile + "songs\\" + tempFileName + "\\songs.dta");
                                }
                                foreach (var foldertoMove in subFolders)
                                {
                                    tempFileName = foldertoMove.Substring((temptempFile + "songs\\").Length,
                                                                          foldertoMove.Length -
                                                                          (temptempFile + "songs\\").Length);

                                    var folderpath = tempFolder + "songs\\";

                                    //let's make sure songs folder is there, if not, create it
                                    if (!(Directory.Exists(folderpath)))
                                    {
                                        Directory.CreateDirectory(tempFolder + "songs\\");
                                    }

                                    //if this song already exists in the working directory, delete it
                                    //copy this one instead
                                    Tools.DeleteFolder(folderpath + tempFileName + "\\", true);

                                    if (Path.GetPathRoot(temptempFile) == Path.GetPathRoot(songsFolder))
                                    {
                                        Directory.Move(temptempFile + "songs\\" + tempFileName + "\\",
                                                       folderpath + tempFileName + "\\");
                                    }
                                    else
                                    {
                                        FileSystem.CopyDirectory(temptempFile + "songs\\" + tempFileName + "\\",
                                                                 folderpath + tempFileName + "\\");
                                    }
                                }
                            }

                            Log("Extracting file " + counter + " of " + inputFiles.Count);
                            success++;
                        }

                        //move other root files but no spa.bin files to root directory
                        var rootFiles = Directory.GetFiles(temptempFile);
                        if (rootFiles.Count() != 0)
                        {
                            foreach (var rootFile in rootFiles.Where(rootFile => rootFile.Substring(rootFile.Length - 7, 7) != "spa.bin"))
                            {
                                Tools.MoveFile(rootFile, tempFolder + Path.GetFileName(rootFile));
                            }
                        }

                        //delete folder to get rid of useless files
                        Tools.DeleteFolder(temptempFile, true);
                    }
                    catch (Exception ex)
                    {
                        Log("There was an error: " + ex.Message);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Log("There was a problem accessing that file");
                    Log("The error says: " + ex.Message);
                }
            }
            Log("Successfully extracted " + success + " of " + counter + " files");

            return(true);
        }