Beispiel #1
0
        public static Package Load(string fileName, bool readData = false)
        {
            Package ret = null;
            try
            {

                DJsIO dj = new DJsIO(fileName, DJFileMode.Open, true);
                STFSPackage pk = null;
                try
                {

                    pk = new STFSPackage(dj, null);
                }
                catch
                {
                    if (pk != null)
                        pk.CloseIO();
                }
                if (pk != null)
                {
                    if (pk.ParseSuccess == true)
                    {
                        ret = new Package(pk, readData);

                    }
                    pk.CloseIO();
                }


            }
            catch { }
            return ret;
        }
Beispiel #2
0
        public static Package Load(byte[] fileBytes, bool loadBytes=false)
        {
            Package ret = null;
            try
            {
                STFSPackage pk = null;
                try
                {
                    pk = new STFSPackage(fileBytes, null);
                }
                catch
                {
                    if (pk != null)
                        pk.CloseIO();
                }
                if (pk != null)
                {
                    if (pk.ParseSuccess == true)
                    {
                        ret = new Package(pk);

                    }
                    pk.CloseIO();
                }

            }
            catch { }
            return ret;
        }
Beispiel #3
0
        public static Package Load(DJsIO dj, bool readData = false)
        {
            Package ret = null;
            try
            {

                STFSPackage pk = null;
                try
                {

                    pk = new STFSPackage(dj, null);
                }
                catch
                {
                    if (pk != null)
                        pk.CloseIO();
                }
                if (pk != null)
                {
                    if (pk.ParseSuccess == true)
                    {
                        ret = new Package(pk, readData, dj);

                    }
                    pk.CloseIO();
                }


            }
            catch { }
            return ret;
        }
Beispiel #4
0
        public bool ExtractDecryptMogg(string CON_file, bool bypass, NemoTools tools, DTAParser parser)
        {
            Initialize();
            Tools  = tools;
            Parser = parser;
            Tools.ReleaseStreamHandle();
            if (!Parser.ExtractDTA(CON_file))
            {
                ErrorLog.Add("Couldn't extract songs.dta file from that CON file");
                return(false);
            }
            if (!Parser.ReadDTA(Parser.DTA) || !Parser.Songs.Any())
            {
                ErrorLog.Add("Couldn't read that songs.dta file");
                return(false);
            }
            if (Parser.Songs.Count > 1)
            {
                ErrorLog.Add("This feature does not support packs, only single songs\nUse the dePACK feature in C3 CON Tools' Quick Pack Editor to split this pack into single songs and try again");
                return(false);
            }
            var internal_name = Parser.Songs[0].InternalName;
            var xCON          = new STFSPackage(CON_file);

            if (!xCON.ParseSuccess)
            {
                ErrorLog.Add("Couldn't parse that CON file");
                xCON.CloseIO();
                return(false);
            }
            var xMogg = xCON.GetFile("songs/" + internal_name + "/" + internal_name + ".mogg");

            if (xMogg == null)
            {
                ErrorLog.Add("Couldn't find the mogg file inside that CON file");
                xCON.CloseIO();
                return(false);
            }
            var mData = xMogg.Extract();

            xCON.CloseIO();
            if (mData == null || mData.Length == 0)
            {
                ErrorLog.Add("Couldn't extract the mogg file from that CON file");
                return(false);
            }
            LoadLibraries();
            if (Tools.DecM(mData, bypass, false, DecryptMode.ToMemory))
            {
                return(true);
            }
            ErrorLog.Add("Mogg file is encrypted and I could not decrypt it, can't split it");
            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// Loads the save data from an STFS package.
        /// </summary>
        /// <param name="path">The path to the STFS package to load.</param>
        /// <param name="extractDir">The directory to extract the STFS package to.</param>
        public void LoadSTFS(string path, string rawFileName, string extractDir)
        {
            STFSPackage package = new STFSPackage(path, null);

            LoadSTFS(package, rawFileName, extractDir);
            package.CloseIO();
        }
Beispiel #6
0
        void fix(int i)
        {
            STFSPackage x = null;

            try { x = new STFSPackage((string)listBox1.Items[i], null); }
            catch { }
            if (x != null)
            {
                if (x.ParseSuccess)
                {
                    if (checkBoxX1.Checked)
                    {
                        x.Header.MakeAnonymous();
                    }
                    if (checkBoxX2.Checked)
                    {
                        x.FlushPackage(par.PublicKV);
                    }
                    else
                    {
                        x.UpdateHeader(par.PublicKV);
                    }
                }
                x.CloseIO();
            }
        }
Beispiel #7
0
        public void importfromprofile()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Title  = "Open a xbox 360 profile";
            dialog.Filter = "Xbox 360 profile|*.*";
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                try
                {
                    DJsIO io = new DJsIO(dialog.FileName, DJFileMode.Open, true);


                    io.Position    = 0x371;
                    this.Profileid = io.ReadHexString(8);
                    io.Close();

                    //xPackage3.STFS.Package sts = new xPackage3.STFS.Package(dialog.FileName);

                    STFSPackage    stfs     = new STFSPackage(dialog.FileName, null);
                    ProfilePackage xFile    = new ProfilePackage(ref stfs);
                    string         gamertag = xFile.UserFile.GetGamertag();
                    this.ProfileName = gamertag;
                    xFile.CloseIO();
                    stfs.CloseIO();
                    //this.Profileid = stfs.Header.Title_Package;
                }
                catch (Exception e) { }
            }
        }
        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();
        }
Beispiel #9
0
        private void backgroundWorker2_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            var counter = 0;

            foreach (var file in FilesToConvert.TakeWhile(file => !backgroundWorker2.CancellationPending))
            {
                Log("Converting STFS file '" + Path.GetFileName(file) + "'");
                try
                {
                    var xFile = new STFSPackage(file);
                    if (!xFile.ParseSuccess)
                    {
                        Log("Couldn't parse that file, skipping...");
                        continue;
                    }
                    xFile.Header.MakeAnonymous();
                    xFile.Header.ThisType = doLIVE ? PackageType.MarketPlace : PackageType.SavedGame;
                    var signature = doLIVE ? new RSAParams(StrongSigned.LIVE) : new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                    xFile.RebuildPackage(signature);
                    xFile.FlushPackage(signature);
                    xFile.CloseIO();
                    Tools.UnlockCON(file);
                    if (!doLIVE)
                    {
                        Tools.SignCON(file);
                    }
                    Log("Successfully converted '" + Path.GetFileName(file) + "' to " + (doLIVE ? "LIVE" : "CON..."));
                    counter++;
                    xFile.CloseIO();
                }
                catch (Exception ex)
                {
                    Log("There was an error converting that file");
                    Log("The error says: " + ex.Message);
                }
            }
            Log("Finished converting " + (counter == 1 ? "file" : "files"));
            Log("Ready");
        }
Beispiel #10
0
        private void updateSaveFile()
        {
            // FIXME: This is hax, you have to invoke the dispatcher from a STA thread so that showQuestion will work -_-
            Thread backupThread = new Thread(() =>
            {
                Dispatcher.Invoke(new Action(makeBackup));
            });

            backupThread.SetApartmentState(ApartmentState.STA);
            backupThread.Start();
            backupThread.Join();

            STFSPackage package = new STFSPackage(_packagePath, null);

            _saveManager.SaveChanges(package, Properties.Resources.KV);
            package.CloseIO();
        }
Beispiel #11
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            xsession.HeaderData.ContentImageBinary = picContent.Image.ImageToBytes(ImageFormat.Png);
            xsession.HeaderData.PackageImageBinary = picPackage.Image.ImageToBytes(ImageFormat.Png);
            switch (GameIndex)
            {
            case 0:
                xsession.HeaderData.TitleID = 0x45410829;
                break;

            case 1:
                xsession.HeaderData.TitleID = 0x45410869;
                break;

            case 2:
                xsession.HeaderData.TitleID = 0x45410914;
                break;
            }
            xsession.HeaderData.Publisher     = "";
            xsession.HeaderData.Title_Package = "Rock Band " + (GameIndex + 1);
            xsession.HeaderData.SetLanguage(Languages.English);
            xsession.HeaderData.Title_Display = Title;
            xsession.HeaderData.Description   = Description;
            xsession.STFSType = STFSType.Type0;
            xsession.HeaderData.MakeAnonymous();
            xsession.HeaderData.ThisType = radioCON.Checked ? PackageType.SavedGame : PackageType.MarketPlace;
            signature = radioCON.Checked ? new RSAParams(Application.StartupPath + "\\bin\\KV.bin") : new RSAParams(StrongSigned.LIVE);
            var xy = new STFSPackage(xsession, signature, xOut);

            xy.CloseIO();
            //now open and unlock
            if (!Tools.UnlockCON(xOut))
            {
                MessageBox.Show("There was an error unlocking CON file\nCan't finish", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //convert to CON if button checked, if not, leave as LIVE
            if (!radioCON.Checked)
            {
                return;
            }
            if (!Tools.SignCON(xOut))
            {
                MessageBox.Show("There was an error signing CON file\nCan't finish", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #12
0
        private bool PackageCreate(string con, CreateSTFS xsession)
        {
            var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin");

            try
            {
                xsession.HeaderData.Title_Display = artistSongTool.Checked ? (SongArtist + " - " + SongTitle) : ("\"" + SongTitle + "\"" + (songByArtistTool.Checked ? " by " + SongArtist : ""));
                xsession.HeaderData.Description   = "Converted to CON using C3 CON Tools";
                var xy = new STFSPackage(xsession, signature, con);
                xy.CloseIO();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #13
0
        void plugclick(object sender, EventArgs e)
        {
            string locale = VariousFunctions.GetUserFileLocale("Open a File", "", true);

            if (locale == null)
            {
                return;
            }
            // Integrate log choice
            STFSPackage x = new STFSPackage(locale, null);

            if (!x.ParseSuccess)
            {
                return;
            }
            try { ((LFPlugIn)((ToolStripItem)sender).Tag).xConst.Invoke(new object[] { x, (Form)this }); }
            catch (Exception z) { x.CloseIO(); MessageBox.Show(z.Message); }
        }
Beispiel #14
0
        public XBoxUniqueID(string FileName)
        {
            BinaryReader br    = new BinaryReader(File.Open(FileName, FileMode.Open), Encoding.ASCII);
            string       Magic = new string(br.ReadChars(3));

            if (Magic != "CON")
            {
                throw new FileFormatException();
            }
            br.Close();
            br = null;

            STFSPackage CON = new STFSPackage(new DJsIO(FileName, DJFileMode.Open, true), new X360.Other.LogRecord());

            ProfileID = CON.Header.ProfileID;
            DeviceID  = CON.Header.DeviceID;
            CON.CloseIO();
        }
Beispiel #15
0
        private bool buildPackage()
        {
            bool success;

            try
            {
                var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                var bigpack   = new STFSPackage(packfiles, signature, xOut);
                var count1    = bigpack.xFileDirectory.Count;
                bigpack.CloseIO();

                var pack   = new STFSPackage(xOut);
                var count2 = pack.xFileDirectory.Count;
                pack.CloseIO();

                if (count1 == count2)
                {
                    Log("Awesome ... looks like everything went smoothly");
                    success = true;
                }
                else
                {
                    MessageBox.Show("Sorry, it looks like there was a problem creating your pack\nThere should be a total of " +
                                    count1 + " files but the pack is only reporting " + count2 + " files\n\nThis is caused by a nasty bug in the X360 library " +
                                    "we thought we had fixed!\n\nClick 'View Package' to open pack in CON Explorer and start checking each song's folder, " +
                                    "whenever you find the first song that has only a .mid file in its folder, that's likely the file causing the problem\nRemove that " +
                                    "file and try building the pack again\n\nDO NOT PUT THIS PACK IN YOUR GAME", Text + " - Big Bad Bug", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    sOpenPackage = xOut;
                    Log("Pack creation failed ... remove problem file and try again");
                    success = false;
                }
            }
            catch
            {
                Log("There was an error building CON file");
                success = false;
            }
            return(success);
        }
Beispiel #16
0
        private void HandleDragDrop(object sender, DragEventArgs e)
        {
            if (picWorking.Visible)
            {
                return;
            }
            var files = (string[])e.Data.GetData(DataFormats.FileDrop);

            if (VariousFunctions.ReadFileType(files[0]) == XboxFileType.STFS)
            {
                var xFile = new STFSPackage(files[0]);
                if (xFile.ParseSuccess)
                {
                    doLIVE = xFile.Header.ThisType != PackageType.MarketPlace;
                    xFile.CloseIO();
                    SelectFilesToConvert(Path.GetDirectoryName(files[0]));
                    return;
                }
            }
            txtFolder.Text      = Path.GetDirectoryName(files[0]);
            Tools.CurrentFolder = txtFolder.Text;
        }
Beispiel #17
0
        private void FileExtractor_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            var dtafolder  = txtFolder.Text + "\\" + (organizeFilesByType.Checked ? "dta_files\\" : "");
            var dtacount   = 0;
            var midicount  = 0;
            var moggcount  = 0;
            var milocount  = 0;
            var pngcount   = 0;
            var thumbcount = 0;
            var hasdta     = false;
            var rename     = "";
            var counter    = 0;

            foreach (var file in inputFiles.Where(File.Exists).TakeWhile(file => !FileExtractor.CancellationPending))
            {
                try
                {
                    if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS)
                    {
                        continue;
                    }
                    if (!Parser.ExtractDTA(file))
                    {
                        Log("Error extracting songs.dta from file: '" + Path.GetFileName(file) + "' ... skipping");
                        continue;
                    }
                    if (!Parser.ReadDTA(Parser.DTA) || !Parser.Songs.Any())
                    {
                        Log("Error reading that songs.dta file ... skipping");
                        continue;
                    }

                    try
                    {
                        xPackage = new STFSPackage(file);
                        if (!xPackage.ParseSuccess)
                        {
                            Log("Error opening file '" + Path.GetFileName(file) + "' ... skipping");
                            xPackage.CloseIO();
                        }
                        else
                        {
                            hasdta = true;

                            Log("CON file '" + Path.GetFileNameWithoutExtension(file) + "' contains " + Parser.Songs.Count + " " + (Parser.Songs.Count == 1 ? "song" : "songs"));
                            for (var i = 0; i < Parser.Songs.Count; i++)
                            {
                                if (FileExtractor.CancellationPending)
                                {
                                    xPackage.CloseIO();
                                    break;
                                }
                                var song = Parser.Songs[i];
                                counter++;
                                Log("Extracting files for song #" + (counter) + ": '" + song.Artist + " - " + song.Name + "'");
                                var songid = song.InternalName;

                                var name   = Tools.CleanString(song.Name, true);
                                var artist = Tools.CleanString(song.Artist, true);
                                songid = Tools.CleanString(songid, true);

                                rename = arrangeName(name, artist, songid).Replace("!", "").Replace("'", "");
                                rename = Tools.CleanString(rename, false);

                                if (chkMIDI.Checked && !FileExtractor.CancellationPending)
                                {
                                    if (ExtractFile("mid", false, songid, rename))
                                    {
                                        midicount++;
                                    }
                                }
                                if (chkMOGG.Checked && !FileExtractor.CancellationPending)
                                {
                                    if (ExtractFile("mogg", false, songid, rename))
                                    {
                                        moggcount++;
                                    }
                                }
                                if (chkPNG.Checked && !FileExtractor.CancellationPending)
                                {
                                    if (ExtractFile("png_xbox", true, songid, rename, true))
                                    {
                                        pngcount++;
                                    }
                                }
                                if (!chkMILO.Checked)
                                {
                                    continue;
                                }
                                if (ExtractFile("milo_xbox", true, songid, rename))
                                {
                                    milocount++;
                                }
                            }

                            if (FileExtractor.CancellationPending)
                            {
                                xPackage.CloseIO();
                                break;
                            }
                            var xUpgrade = xPackage.GetFile("songs_upgrades/upgrades.dta");
                            if (xUpgrade != null)
                            {
                                var temp_upg = Path.GetTempPath() + "upg.dta";
                                Tools.DeleteFile(temp_upg);

                                if (xUpgrade.ExtractToFile(temp_upg))
                                {
                                    var upg_midi = "";
                                    var sr       = new StreamReader(temp_upg);
                                    while (sr.Peek() >= 0)
                                    {
                                        var line = sr.ReadLine();
                                        if (string.IsNullOrWhiteSpace(line))
                                        {
                                            continue;
                                        }

                                        if (line.Contains("midi_file"))
                                        {
                                            upg_midi = line.Replace("midi_file", "").Replace("songs_upgrades", "")
                                                       .Replace("(", "").Replace(")", "").Replace("\"", "")
                                                       .Replace("/", "").Replace("'", "").Trim();
                                        }

                                        if (string.IsNullOrWhiteSpace(upg_midi))
                                        {
                                            continue;
                                        }
                                        if (chkMIDI.Checked)
                                        {
                                            var xmidi = xPackage.GetFile("songs_upgrades/" + upg_midi);
                                            if (xmidi != null)
                                            {
                                                var outputfolder = txtFolder.Text + "\\" + (organizeFilesByType.Checked ? "midi_files\\" : "");
                                                if (!Directory.Exists(outputfolder))
                                                {
                                                    Directory.CreateDirectory(outputfolder);
                                                }
                                                var out_midi = outputfolder + upg_midi;
                                                Log("Extracting MIDI file " + Path.GetFileName(out_midi));
                                                Tools.DeleteFile(out_midi);
                                                if (xmidi.ExtractToFile(out_midi))
                                                {
                                                    Log("Extracted " + Path.GetFileName(out_midi) + " successfully");
                                                    midicount++;
                                                }
                                                else
                                                {
                                                    Log("There was an error extracting upgrade MIDI file " + upg_midi);
                                                }
                                            }
                                            else
                                            {
                                                Log("Could not find upgrade MIDI file " + upg_midi + " in that file");
                                            }
                                        }
                                        upg_midi = "";
                                    }
                                    sr.Dispose();

                                    if (chkDTA.Checked)
                                    {
                                        if (!Directory.Exists(dtafolder))
                                        {
                                            Directory.CreateDirectory(dtafolder);
                                        }
                                        var upgdta = (string.IsNullOrWhiteSpace(xPackage.Header.Title_Display) ? Path.GetFileName(file) : xPackage.Header.Title_Display).Replace("!", "")
                                                     .Replace("'", "").Replace(" ", replaceSpacesWithUnderscores.Checked ? "_" : (removeSpacesFromFileName.Checked ? "" : " "));
                                        var upg_out = dtafolder + "\\" + Tools.CleanString(upgdta, false) + "_upgrade.dta";
                                        Tools.DeleteFile(upg_out);
                                        if (Tools.MoveFile(temp_upg, upg_out))
                                        {
                                            Log("Extracted " + Path.GetFileName(upg_out) + " successfully");
                                            dtacount++;
                                        }
                                        else
                                        {
                                            Log("There was an error extracting the upgrades.dta for " + Path.GetFileName(file));
                                        }
                                    }
                                }
                                else
                                {
                                    Log("There was an error extracting the upgrades.dta for " + Path.GetFileName(file));
                                }
                            }
                            else if (!hasdta)
                            {
                                Log("Could not find songs.dta or upgrades.dta inside '" + Path.GetFileName(file) + "'");
                            }
                        }

                        var packname = (string.IsNullOrWhiteSpace(xPackage.Header.Title_Display) ? Path.GetFileName(file) : xPackage.Header.Title_Display).Replace("!", "")
                                       .Replace("'", "").Replace(" ", replaceSpacesWithUnderscores.Checked ? "_" : (removeSpacesFromFileName.Checked ? "" : " "));
                        packname = Parser.Songs.Count == 1 && !string.IsNullOrWhiteSpace(rename) ? rename : Tools.CleanString(packname, false);

                        if (chkDTA.Checked && hasdta)
                        {
                            try
                            {
                                var newDTA = dtafolder + packname + (appendsongsToFiles.Checked ? "_songs" : "") + ".dta";
                                Log("Extracting DTA file " + Path.GetFileName(newDTA));
                                if (!Directory.Exists(dtafolder))
                                {
                                    Directory.CreateDirectory(dtafolder);
                                }
                                if (Parser.WriteDTAToFile(newDTA))
                                {
                                    Log(Path.GetFileName(newDTA) + " extracted successfully");
                                    dtacount++;
                                }
                                else
                                {
                                    Log("Looks like extracting the DTA file for " + Path.GetFileName(file) + " failed. Sorry.");
                                }
                            }
                            catch (Exception ex)
                            {
                                Log("Error extracting DTA file for " + Path.GetFileName(file));
                                Log("The error says: " + ex.Message);
                            }
                        }

                        if (chkThumbs.Checked && !FileExtractor.CancellationPending)
                        {
                            var thumbfolder = txtFolder.Text + "\\" + (organizeFilesByType.Checked ? "thumbnails\\" : "");
                            var package     = thumbfolder + packname + " Package.png";
                            var content     = thumbfolder + packname + " Content.png";
                            if (!Directory.Exists(thumbfolder))
                            {
                                Directory.CreateDirectory(thumbfolder);
                            }
                            try
                            {
                                Tools.DeleteFile(content);
                                var img = xPackage.Header.ContentImage;
                                img.Save(content, ImageFormat.Png);
                                img.Dispose();
                                thumbcount++;

                                Tools.DeleteFile(package);
                                img = xPackage.Header.PackageImage;
                                img.Save(package, ImageFormat.Png);
                                img.Dispose();
                                thumbcount++;

                                Log("Extracted thumbnails successfully");
                            }
                            catch (Exception ex)
                            {
                                Log("There was an error extracting the thumbnails");
                                Log("The error says: " + ex.Message);
                            }
                        }
                        xPackage.CloseIO();
                    }
                    catch (Exception ex)
                    {
                        Log("Error processing file '" + Path.GetFileName(file) + "'");
                        Log("The error says: " + ex.Message);
                        xPackage.CloseIO();
                    }
                }
                catch (Exception ex)
                {
                    Log("There was a problem accessing that file");
                    Log("The error says: " + ex.Message);
                    xPackage.CloseIO();
                }
            }

            if (dtacount + midicount + moggcount + milocount + pngcount + thumbcount == 0)
            {
                Log("Nothing was extracted ... please see the log for any failure reports");
            }
            else
            {
                if (dtacount > 0)
                {
                    Log("Extracted " + dtacount + " DTA " + (dtacount > 1 ? "files" : "file"));
                }
                if (pngcount > 0)
                {
                    Log("Extracted " + pngcount + " PNG_XBOX " + (pngcount > 1 ? "files" : "file"));
                    btnConverter.Invoke(new MethodInvoker(() => btnConverter.Visible = true));
                }
                if (midicount > 0)
                {
                    Log("Extracted " + midicount + " MIDI " + (midicount > 1 ? "files" : "file"));
                }
                if (moggcount > 0)
                {
                    Log("Extracted " + moggcount + " MOGG " + (moggcount > 1 ? "files" : "file"));
                }
                if (milocount > 0)
                {
                    Log("Extracted " + milocount + " MILO_XBOX " + (milocount > 1 ? "files" : "file"));
                }
                if (thumbcount > 0)
                {
                    Log("Extracted " + thumbcount + " " + (thumbcount > 1 ? "thumbnails" : "thumbnail"));
                }
            }
            xPackage.CloseIO();
        }
Beispiel #18
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
            }
        }
Beispiel #19
0
        private string ExtractMIDI(string con, bool isUpgrade)
        {
            var midi = "";

            var xPackage = new STFSPackage(con);

            if (!xPackage.ParseSuccess)
            {
                MessageBox.Show("There was an error parsing CON file, can't extract MIDI", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log("Can't work with this CON file, try again");
                return("");
            }

            try
            {
                var xent = xPackage.GetFolder("songs");
                if (xent == null && !isUpgrade)
                {
                    xent = xPackage.GetFolder("songs_upgrades");
                    MessageBox.Show(xent != null ? "This looks like a pro upgrade, only song files are valid here" :
                                    "I can't find a 'songs' folder in that CON file, make sure sure it's a Rock Band song file",
                                    Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    xPackage.CloseIO();
                    Log("Can't work with this CON file, try again");
                    return("");
                }

                //we can't work with packs or pro upgrades, so check and skip
                xent = xPackage.GetFolder("songs_upgrades");
                if (xent != null && !isUpgrade)
                {
                    xent = xPackage.GetFolder("songs");
                    MessageBox.Show(xent != null ? "It looks like this is a pack, only individual song files are valid here"
                            : "This looks like a pro upgrade, only song files are valid here",
                                    Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    xPackage.CloseIO();
                    Log("Can't work with this CON file, try again");
                    return("");
                }

                var folder  = isUpgrade ? "songs_upgrades/" : "songs/";
                var dtaFile = isUpgrade ? "upgrades.dta" : "songs.dta";
                var dta     = temp_folder + dtaFile;

                if (Parser.ExtractDTA(xPackage, false, isUpgrade))
                {
                    if (Parser.ReadDTA(Parser.DTA) && Parser.Songs.Count > 1)
                    {
                        MessageBox.Show("It looks like this is a pack, only individual song files are valid here",
                                        Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        xPackage.CloseIO();
                        Log("Can't work with this CON file, try again");
                        return("");
                    }
                }

                var xFile = xPackage.GetFile(folder + dtaFile);
                if (xFile == null)
                {
                    MessageBox.Show("Can't find " + dtaFile + " inside this CON file\nI can't work without it", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    xPackage.CloseIO();
                    Log("Can't work with this CON file, try again");
                    return("");
                }

                var fileName = Path.GetFileName(con);
                if (fileName != null)
                {
                    if (!Parser.WriteDTAToFile(dta))
                    {
                        MessageBox.Show("Something went wrong in extracting the " + dtaFile + " file\nI can't work without it", Text,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        xPackage.CloseIO();
                        Log("Can't work with this CON file, try again");
                        return("");
                    }
                }

                var artists  = 0;
                var songname = "";

                var sr = new StreamReader(dta, Parser.GetDTAEncoding(Parser.DTA));
                // read one line at a time until the end
                while (sr.Peek() >= 0)
                {
                    var line = sr.ReadLine();
                    if (string.IsNullOrWhiteSpace(line.Trim()))
                    {
                        continue;
                    }

                    if (line.ToLowerInvariant().Contains("artist") && !line.ToLowerInvariant().Contains(";") && !isUpgrade)
                    {
                        artists++;
                    }
                    else if (line.ToLowerInvariant().Contains("songs/") && !line.Contains("midi_file") && !isUpgrade)
                    {
                        songname      = Parser.GetInternalName(line);
                        song_int_name = songname;
                    }
                    else if (line.Contains("song_id"))
                    {
                        if (isUpgrade)
                        {
                            upgradeID = Parser.GetSongID(line);
                        }
                        else
                        {
                            songID = Parser.GetSongID(line);
                            CheckIDMatch();
                        }
                    }
                    else if (line.Contains("midi_file") && isUpgrade)
                    {
                        var midipath = line.Replace("(", "");
                        midipath         = midipath.Replace(")", "");
                        midipath         = midipath.Replace("midi_file", "");
                        midipath         = midipath.Replace("songs_upgrades", "");
                        midipath         = midipath.Replace("\"", "");
                        midipath         = midipath.Replace("/", "");
                        songname         = midipath.Trim();
                        upgrade_int_name = songname.Replace(".mid", "");
                    }
                }
                sr.Dispose();

                if (artists > 1) //if single song, packs will have values > 1
                {
                    MessageBox.Show("It looks like this is a pack, only individual song files are valid here",
                                    Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    xPackage.CloseIO();
                    Log("Can't work with this CON file, try again");
                    return("");
                }

                xFile = xPackage.GetFile(folder + songname + (isUpgrade ? "" : "/" + songname + ".mid"));
                if (xFile != null)
                {
                    midi = temp_folder + songname + (isUpgrade? "" : ".mid");
                    Tools.DeleteFile(midi);
                    if (!xFile.ExtractToFile(midi))
                    {
                        MessageBox.Show("Can't find a MIDI file inside this CON file\nI can't work without it", Text,
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        xPackage.CloseIO();
                        Log("Can't work with this CON file, try again");
                        return("");
                    }
                }
                xPackage.CloseIO();

                if (isUpgrade)
                {
                    newupgdta = dta;
                    ReadUpgDTA(newupgdta);
                }
                else
                {
                    orig_dta = dta;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was an error:\n" + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                xPackage.CloseIO();
            }
            return(midi);
        }
Beispiel #20
0
        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            if (!File.Exists(orig_con))
            {
                Log("CON file " + Path.GetFileName(orig_con) + " seems to have been deleted, can't continue without it");
                return;
            }

            var BundleFile = orig_con + " (bundled)";

            Tools.DeleteFile(BundleFile);
            File.Copy(orig_con, BundleFile);


            var xPackage = new STFSPackage(BundleFile);

            if (!xPackage.ParseSuccess)
            {
                Log("There was an error parsing CON file to bundle");
                xPackage.CloseIO();
                return;
            }

            var xent = xPackage.GetFile("/songs/songs.dta");

            if (xent != null)
            {
                if (xent.Replace(newDTA))
                {
                    Log("Bundled DTA file successfully");
                }
            }

            xent = xPackage.GetFile("/songs/" + Path.GetFileNameWithoutExtension(orig_midi) + "/" + Path.GetFileName(orig_midi));
            if (xent != null)
            {
                if (xent.Replace(newMIDI))
                {
                    Log("Bundled MIDI file successfully");
                }
            }

            xPackage.Header.MakeAnonymous();
            xPackage.Header.ThisType = PackageType.SavedGame;

            var success = false;

            try
            {
                Log("Rebuilding CON file ... this might take a little while");
                signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                if (ChangeGameID.Checked)
                {
                    xPackage.Header.TitleID            = 0x45410914;
                    xPackage.Header.Title_Package      = "Rock Band 3";
                    xPackage.Header.ContentImageBinary = Resources.RB3.ImageToBytes(ImageFormat.Png);
                }
                xPackage.RebuildPackage(signature);
                xPackage.FlushPackage(signature);
                xPackage.CloseIO();
                success = true;
            }
            catch (Exception ex)
            {
                Log("There was an error: " + ex.Message);
                xPackage.CloseIO();
            }

            if (success)
            {
                Log("Trying to unlock CON file");
                if (Tools.UnlockCON(BundleFile))
                {
                    Log("Unlocked CON file successfully");
                }
                else
                {
                    Log("Error unlocking CON file");
                    success = false;
                }
            }

            if (success)
            {
                Log("Trying to sign CON file");
                if (Tools.SignCON(BundleFile))
                {
                    Log("CON file signed successfully");
                }
                else
                {
                    Log("Error signing CON file");
                    success = false;
                }
            }

            Log(success ? "Your files were bundled successfully!" : "Something went wrong along the way, sorry!");

            if (!cleanUpAfterBundlingFiles.Checked)
            {
                return;
            }
            Log("Cleaning up");
            CleanUp();
        }
Beispiel #21
0
        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Tools.CurrentFolder = Path.GetDirectoryName(con);
            Log("Reading CON file " + Path.GetFileName(con));

            var dta    = Path.GetTempPath() + "temp_dta.txt";
            var backup = con + "_backup";

            Tools.DeleteFile(backup);

            if (!Parser.ExtractDTA(con))//grab byte[] content of DTA
            {
                Log("Error extracting DTA file");
                ErrorOut();
                return;
            }
            if (!Parser.WriteDTAToFile(dta)) //write it out to file
            {
                Log("Error extracting DTA file");
                ErrorOut();
                return;
            }

            var song = new STFSPackage(con);

            if (backUpCONFile.Checked)
            {
                Log("Found songs.dta file, making a backup of your file before starting");
                Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!");

                song.CloseIO();
                File.Copy(con, backup);
                song = new STFSPackage(con);
            }

            var xDTA = song.GetFile("/songs/songs.dta");

            Log("Opening DTA file...");

            var process = Process.Start(dta);

            Log("DTA file is being edited by the user ... waiting...");

            do
            {
                //wait while user has DTA file opened
            } while (!process.HasExited);

            process.Dispose();

            Log("DTA file closed by user, continuing...");
            Log("Replacing old DTA file with modified DTA file");
            Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!");

            if (!xDTA.Replace(dta))
            {
                Log("Error replacing DTA file with modified one");
                Tools.DeleteFile(backup);
                ErrorOut();
                return;
            }

            Log("Replaced DTA file successfully");
            song.Header.MakeAnonymous();
            song.Header.ThisType = PackageType.SavedGame;

            var success = false;

            try
            {
                Log("Saving changes to pack ... sit tight");
                Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!");

                signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                song.RebuildPackage(signature);
                song.FlushPackage(signature);
                song.CloseIO();
                success = true;
            }
            catch (Exception ex)
            {
                Log("There was an error: " + ex.Message);
                song.CloseIO();
            }

            if (success)
            {
                Log("Trying to unlock CON file");
                if (Tools.UnlockCON(con))
                {
                    Log("Unlocked CON file successfully");
                }
                else
                {
                    Log("Error unlocking CON file");
                    success = false;
                }
            }

            if (success)
            {
                if (Tools.SignCON(con))
                {
                    Log("CON file signed successfully");
                }
                else
                {
                    Log("Error signing CON file");
                    success = false;
                }
            }

            Tools.DeleteFile(dta);

            Log(success ? "Process completed successfully!" : "Something went wrong along the way, sorry!");
            if (success)
            {
                return;
            }
            if (!backUpCONFile.Checked)
            {
                return;
            }
            Log("Restoring backup file");
            Tools.DeleteFile(con);
            Log(Tools.MoveFile(backup, con) ? "Backup file restored successfully, nothing was lost" : "Sorry, there was an error restoring the backup file");
        }
Beispiel #22
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            foreach (var file in FilesToConvert)
            {
                if (backgroundWorker1.CancellationPending)
                {
                    return;
                }
                var replaced = 0;
                try
                {
                    var xFile = new STFSPackage(file);
                    if (!xFile.ParseSuccess)
                    {
                        ProblemFiles.Add(file);
                        continue;
                    }

                    var xent = xFile.GetFile("/songs/songs.dta");
                    if (xent == null)
                    {
                        xFile.CloseIO();
                        ProblemFiles.Add(file);
                        continue;
                    }

                    var dta1 = Application.StartupPath + "\\bin\\dta1.txt";
                    Tools.DeleteFile(dta1);

                    if (!xent.Extract(dta1))
                    {
                        xFile.CloseIO();
                        ProblemFiles.Add(file);
                        continue;
                    }

                    var dta2 = Application.StartupPath + "\\bin\\dta2.txt";
                    Tools.DeleteFile(dta2);

                    var sr = new StreamReader(dta1, Encoding.Default);
                    var sw = new StreamWriter(dta2, false, Encoding.Default);
                    while (sr.Peek() >= 0)
                    {
                        var line = sr.ReadLine();
                        if (string.IsNullOrEmpty(line.Trim()))
                        {
                            continue;
                        }

                        if (line.Contains(";ORIG_ID="))
                        {
                            if (DoReverseBatch)
                            {
                                var id = line.Replace(";", "").Replace("ORIG_ID=", "").Trim();
                                sw.WriteLine("   ('song_id' " + id + ")");
                                sr.ReadLine();//skip the old song_id line
                                line = sr.ReadLine();
                                TotalSongs++;
                                replaced++;
                            }
                            else
                            {
                                sw.WriteLine(line);
                                line = sr.ReadLine();
                                sw.WriteLine(line);
                                line = sr.ReadLine();
                            }
                        }
                        else if (line.Contains("song_id") && !DoReverseBatch)
                        {
                            if (!Parser.IsNumericID(line))
                            {
                                line = ";ORIG_ID=" + Parser.GetSongID(line);
                                sw.WriteLine(line);
                                line = "   ('song_id' " + mMainForm.GetNumericID() + ")";
                                TotalSongs++;
                                replaced++;
                            }
                            else
                            {
                                SkippedFiles.Add(file);
                            }
                        }

                        if (!string.IsNullOrEmpty(line.Trim()))
                        {
                            sw.WriteLine(line);
                        }
                    }
                    sr.Dispose();
                    sw.Dispose();

                    if (replaced == 0) //don't modify this CON file if nothing is edited in this DTA file
                    {
                        if (!SkippedFiles.Contains(file))
                        {
                            SkippedFiles.Add(file);
                        }
                        xFile.CloseIO();
                        continue;
                    }

                    if (backgroundWorker1.CancellationPending)
                    {
                        xFile.CloseIO();
                        return;
                    }
                    if (!xent.Replace(dta2))
                    {
                        xFile.CloseIO();
                        ProblemFiles.Add(file);
                        continue;
                    }

                    Tools.DeleteFile(dta1);
                    Tools.DeleteFile(dta2);

                    xFile.Header.MakeAnonymous();
                    xFile.Header.ThisType = PackageType.SavedGame;
                    var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin");
                    xFile.RebuildPackage(signature);
                    xFile.FlushPackage(signature);
                    xFile.CloseIO();
                    Tools.UnlockCON(file);
                    Tools.SignCON(file);
                    xFile.CloseIO();
                }
                catch (Exception)
                {
                    ProblemFiles.Add(file);
                }
            }
        }
Beispiel #23
0
        private void ExtractFromSaveFile(string file)
        {
            ClearAll();
            isWorking(true);
            var savefile = file;
            var isXbox   = Path.GetFileName(file).ToLowerInvariant().Contains("xbox") || Path.GetFileName(file) == "band3";

            isWii = Path.GetFileName(file).ToLowerInvariant().Contains("wii");
            isPS3 = Path.GetFileName(file).ToLowerInvariant().Contains("ps3");
            Tools.CurrentFolder = Path.GetDirectoryName(file);
            UserSaveFile        = file;

            if (VariousFunctions.ReadFileType(file) == XboxFileType.STFS)
            {
                isXbox = true;
                isPS3  = false;
                isWii  = false;

                Log("Received save CON file, extracting save.dat file");
                var package = new STFSPackage(file);
                if (!package.ParseSuccess)
                {
                    isWorking(false);
                    package.CloseIO();
                    Log("Couldn't read that CON file, aborting");
                    Log("Ready");
                    return;
                }
                var xent = package.GetFile("save.dat");
                if (xent == null)
                {
                    isWorking(false);
                    package.CloseIO();
                    Log("Couldn't find save.dat in that CON file, aborting");
                    Log("Ready");
                    return;
                }
                var tempdat = EditorFolder + "\\temp.dat";
                Tools.DeleteFile(tempdat);
                if (!xent.ExtractToFile(tempdat))
                {
                    isWorking(false);
                    package.CloseIO();
                    Log("Couldn't extract save.dat from that CON file, aborting");
                    Log("Ready");
                    return;
                }
                savefile = tempdat;
                package.CloseIO();
            }
            Log("Received save file, extracting images...");

            ImageFolder = EditorFolder + Path.GetFileNameWithoutExtension(file) + "_extracted\\";
            Tools.DeleteFolder(ImageFolder, true);

            var success = false;

            if (isXbox)
            {
                success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file));
            }
            else if (isWii)
            {
                success = Tools.ExtractWiiSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file));
            }
            else if (isPS3)
            {
                success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file), true);
            }
            else
            {
                switch (MessageBox.Show("Click Yes if this is a *decrypted* PS3 save file\nClick No if this is a Wii save file\nXbox 360 users must use the 'band3' save file\nPress Cancel to go back",
                                        Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                {
                case DialogResult.Yes:
                    isPS3   = true;
                    isWii   = false;
                    success = Tools.ExtractSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file), true);
                    break;

                case DialogResult.No:
                    isWii   = true;
                    isPS3   = false;
                    success = Tools.ExtractWiiSaveImages(savefile, EditorFolder + Path.GetFileNameWithoutExtension(file));
                    break;

                case DialogResult.Cancel:
                    Log("Extracting cancelled by user");
                    isWorking(false);
                    Log("Ready");
                    return;
                }
            }

            if (!success)
            {
                Log("Extracting from save game file failed");
                isWorking(false);
                Log("Ready");
                return;
            }
            Log("Extracted images from save file successfully");

            if (savefile != file) //i.e. extracted from con
            {
                Tools.DeleteFile(savefile);
            }

            lblFileName.Text = Path.GetFileName(file);
            lblConsole.Text  = isPS3 ? "Playstation 3" : (isWii ? "Wii" : "Xbox 360");
            ChangeImagePadding();
            LoadExtractedImages();
            exportAllImagesToolStripMenuItem.Enabled = true;
            closeFileToolStripMenuItem.Enabled       = true;

            txtBand.Enabled  = true;
            txtBand.Text     = !string.IsNullOrWhiteSpace(Tools.SaveFileBandName) ? Tools.SaveFileBandName : "Unknown";
            txtBand.ReadOnly = isWii;

            isWorking(false);
            Log("Ready");
        }
Beispiel #24
0
        private Util.SaveType loadSaveFile(string stfsPath)
        {
            // lolmultithreading

            _reachTaglists.RemoveMapSpecificTaglists();
            if (_saveManager != null)
            {
                _saveManager.Close();
            }

            STFSPackage package = null;

            try
            {
                // Open the STFS package
                string rawFileName;
                try
                {
                    package = new STFSPackage(stfsPath, null);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("The selected file is not a valid STFS package.", ex);
                }

                // Before detecting the save's game, check if it's a "Halo 4 Data" package
                // These packages aren't actually saved games, but a lot of users are getting this confused
                if (package.GetFile("data.cache") != null)
                {
                    Action wrongFileAction = new Action(() =>
                    {
                        showMessage("Packages named \"Halo 3 Data\" or \"Halo 4 Data\" aren't actual save files. You need to copy the ~11 MB file named after your gamertag instead. If you don't see anything, make sure to get to a checkpoint first.", "OOPS");
                    }
                                                        );
                    Dispatcher.Invoke(wrongFileAction);
                    return(Util.SaveType.Unknown);
                }

                // Detect the save's game
                _currentGame = detectGame(package, out rawFileName);
                classInfo.storage.settings.applicationSettings.gameIdent.gameID = _currentGame;

                if (_currentGame == Util.SaveType.Unknown)
                {
                    Action notSupportedAction = new Action(() =>
                    {
                        showMessage(package.Header.Title_Display + " saves are not supported yet. Currently, only Halo 3, Halo 3: ODST, Halo: Reach, Halo: CE Anniversary, and Halo 4 saves are supported. Please select a different file.", "GAME NOT SUPPORTED");
                    }
                                                           );
                    Dispatcher.Invoke(notSupportedAction);
                    return(Util.SaveType.Unknown);
                }
                else if (_currentGame == Util.SaveType.SomeGame)
                {
                    Action eggAction = new Action(() =>
                    {
                        eggData.egg3Dialog dialog = new eggData.egg3Dialog();
                        dialog.Owner = this;
                        dialog.ShowDialog();
                    }
                                                  );
                    Dispatcher.Invoke(eggAction);
                    return(Util.SaveType.Unknown);
                }

                _saveManager.LoadSTFS(package, rawFileName, classInfo.extraIO.makeTempSaveDir());
                _packagePath = stfsPath;

                // Update some UI controls with package info
                Dispatcher.Invoke(new Action <string, uint, string, long>(setPackageInfo),
                                  new object[] { package.Header.Title_Package,
                                                 package.Header.TitleID,
                                                 package.Header.Title_Display,
                                                 package.Header.ProfileID });
            }
            catch (ArgumentException ex)
            {
                Dispatcher.Invoke(new Action <string, string>(showMessage), new object[] { ex.Message, "ERROR" });
                return(Util.SaveType.Unknown);
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(new Action <string, bool>(showException), new object[] { ex.ToString(), true });
                return(Util.SaveType.Unknown);
            }
            finally
            {
                if (package != null)
                {
                    package.CloseIO();
                }
            }

            return(_currentGame);
        }
Beispiel #25
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);
        }
Beispiel #26
0
        public static byte[] CreateRB3Pro(CreateProConfig config)
        {
            STFSPackage pk = null;
            bool loadedExisting = false;
            if (config.existingCONFile != null)
            {
                try
                {
                    pk = LoadSTFS(config.existingCONFile);
                }
                catch { }
                if (pk == null)
                {
                    pk = LoadSTFS(Resources.proconfile);
                }
                else
                {
                    loadedExisting = true;
                }
            }
            else
            {
                pk = LoadSTFS(Resources.proconfile);
            }
            bool loadedOK = false;
            if (pk != null)
            {

                //pk.Header.ContentImage = Resources.rockband;
                //pk.Header.PackageImage = Resources.rockband2;
                
                pk.Header.TitleID = config.TitleID;
                //pk.Header.MediaID = 4FC9256F;

                pk.Header.Description = config.description;
                pk.Header.Title_Display = config.displayTitle;

                var folder = pk.GetFolder("songs_upgrades");
                if (loadedExisting)
                {


                    var files = folder.GetSubFiles();

                    bool foundDTA = false;
                    bool foundMID = false;
                    foreach (var f in files)
                    {

                        if (string.Compare(f.Name, "upgrades.dta", StringComparison.OrdinalIgnoreCase) == 0)
                        {

                            string upgradeFile = Encoding.ASCII.GetString(Resources.upgrades);

                            upgradeFile = upgradeFile.Replace("##songshortname##", config.songShortName);
                            upgradeFile = upgradeFile.Replace("##profilename##", config.proMidiFileName);
                            upgradeFile = upgradeFile.Replace("##songid##", config.song_id);
                            upgradeFile = upgradeFile.Replace("##guitardifficulty##", config.guitarDifficulty);
                            upgradeFile = upgradeFile.Replace("##bassdifficulty##", config.bassDifficulty);

                            f.Replace(Encoding.ASCII.GetBytes(upgradeFile));
                            foundDTA = true;
                        }
                        else if (string.Compare(f.Name, config.proMidiFileName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            f.Replace(config.midFileContents);
                            foundMID = true;
                        }
                    }
                    loadedOK = foundDTA && foundMID;

                    if (!loadedOK)
                    {
                        pk.CloseIO();
                        config.existingCONFile = null;
                        return CreateRB3Pro(config);
                    }
                }
                else
                {
                    foreach (var f in folder.GetSubFiles())
                    {
                        if (f.Name.EndsWith(".mid", StringComparison.OrdinalIgnoreCase) ||
                            f.Name.EndsWith(".midi", StringComparison.OrdinalIgnoreCase))
                        {
                            f.Name = config.proMidiFileName;

                            f.Replace(config.midFileContents);
                        }
                        else if (f.Name.EndsWith(".dta", StringComparison.OrdinalIgnoreCase))
                        {
                            string upgradeFile = Encoding.ASCII.GetString(Resources.upgrades);

                            f.Name = "upgrades.dta";

                            upgradeFile = upgradeFile.Replace("##songshortname##", config.songShortName);
                            upgradeFile = upgradeFile.Replace("##profilename##", config.proMidiFileName);
                            upgradeFile = upgradeFile.Replace("##songid##", config.song_id);
                            upgradeFile = upgradeFile.Replace("##guitardifficulty##", config.guitarDifficulty);
                            upgradeFile = upgradeFile.Replace("##bassdifficulty##", config.bassDifficulty);

                            f.Replace(Encoding.ASCII.GetBytes(upgradeFile));
                        }
                    }
                }
            }


            var bytes = pk.RebuildPackageInMemory(
                new RSAParams(new DJsIO(Resources.KV, true)));

            pk.CloseIO();

            return bytes;
        }
Beispiel #27
0
        private bool ProcessFiles()
        {
            var counter = 0;
            var success = 0;

            foreach (var file in inputFiles.Where(File.Exists).TakeWhile(file => !backgroundWorker1.CancellationPending))
            {
                try
                {
                    if (VariousFunctions.ReadFileType(file) != XboxFileType.STFS)
                    {
                        continue;
                    }
                    Song.NewSong();
                    Song.ReplaceGenreWithSub = useSubgenreInsteadOfGenreToolStripMenuItem.Checked;

                    try
                    {
                        if (!Directory.Exists(PSFolder))
                        {
                            Directory.CreateDirectory(PSFolder);
                        }
                        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;
                        }
                        if (!Parser.Songs.Any())
                        {
                            Log("There was an error processing the songs.dta file");
                            continue;
                        }
                        if (loadDTA())
                        {
                            Log("Loaded and processed songs.dta file for song #" + counter + " successfully");
                            Log("Song #" + counter + " is " + Song.Artist + " - " + Song.Name);
                        }
                        else
                        {
                            return(false);
                        }

                        var songfolder = PSFolder + Tools.CleanString(Song.Artist, false) + " - " + Tools.CleanString(Song.Name, false) + "\\";
                        if (!Directory.Exists(songfolder))
                        {
                            Directory.CreateDirectory(songfolder);
                        }
                        var internal_name = Parser.Songs[0].InternalName;

                        var xPackage = new STFSPackage(file);
                        if (!xPackage.ParseSuccess)
                        {
                            Log("Failed to parse '" + Path.GetFileName(file) + "'");
                            Log("Skipping this file");
                            continue;
                        }
                        var xArt = xPackage.GetFile("songs/" + internal_name + "/gen/" + internal_name + "_keep.png_xbox");
                        if (xArt != null)
                        {
                            var newart = songfolder + "album.png_xbox";
                            if (xArt.ExtractToFile(newart))
                            {
                                Log("Extracted album art file " + internal_name + "_keep.png_xbox successfully");
                                fromXbox(newart);
                            }
                            else
                            {
                                Log("There was a problem extracting the album art file");
                            }
                        }
                        else
                        {
                            Log("WARNING: Did not find album art file in that CON file");
                        }
                        var xMIDI = xPackage.GetFile("songs/" + internal_name + "/" + internal_name + ".mid");
                        if (xMIDI != null)
                        {
                            var newmidi = songfolder + "notes.mid";
                            if (xMIDI.ExtractToFile(newmidi))
                            {
                                Log("Extracted MIDI file " + internal_name + ".mid successfully");
                                ProcessMidi(newmidi);
                            }
                            else
                            {
                                Log("There was a problem extracting the MIDI file");
                                Log("Skipping this song...");
                                xPackage.CloseIO();
                                continue;
                            }
                        }
                        else
                        {
                            Log("ERROR: Did not find a MIDI file in that CON file!");
                            Log("Skipping this song...");
                            xPackage.CloseIO();
                            continue;
                        }
                        var xMOGG = xPackage.GetFile("songs/" + internal_name + "/" + internal_name + ".mogg");
                        if (xMOGG != null)
                        {
                            var newmogg = songfolder + internal_name + ".mogg";
                            if (radioSeparate.Checked)
                            {
                                xPackage.CloseIO();
                                SeparateAudio(file, newmogg, songfolder);
                            }
                            else if (radioDownmix.Checked)
                            {
                                xPackage.CloseIO();
                                DownMixAudio(file, songfolder);
                            }
                            else
                            {
                                var msg = "Extracting audio file " + (radioAudacity.Checked ? "to send to Audacity" : "and leaving it as is");
                                Log(msg);
                                var mData = xMOGG.Extract();
                                if (mData != null && mData.Length > 0)
                                {
                                    Log("Successfully extracted audio file '" + Path.GetFileName(newmogg) + "'");
                                    if (radioAudacity.Checked)
                                    {
                                        Log("Sending audio file to Audacity now");
                                        Tools.DecM(mData, false, false, DecryptMode.ToFile, newmogg);
                                        Log(Tools.SendtoAudacity(newmogg));
                                    }
                                    else
                                    {
                                        Tools.WriteOutData(Tools.ObfM(mData), newmogg);
                                    }
                                }
                                else
                                {
                                    Log("There was a problem extracting the audio file");
                                    Log("Skipping this song...");
                                    xPackage.CloseIO();
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            Log("ERROR: Did not find an audio file in that CON file!");
                            Log("Skipping this song...");
                            xPackage.CloseIO();
                            continue;
                        }
                        xPackage.CloseIO();

                        if (!Directory.Exists(songfolder))
                        {
                            Directory.CreateDirectory(songfolder);
                        }
                        Song.WriteINIFile(songfolder, !chkNoC3.Checked);

                        var banner = Application.StartupPath + "\\res\\phaseshift\\banner.png";
                        if (File.Exists(banner) && !chkNoC3.Checked)
                        {
                            Tools.DeleteFile(songfolder + "banner.png");
                            File.Copy(banner, songfolder + "banner.png");
                        }
                        var icon = Application.StartupPath + "\\res\\phaseshift\\c3.png";
                        if (File.Exists(icon) && !chkNoC3.Checked)
                        {
                            Tools.DeleteFile(songfolder + "ccc.png");
                            File.Copy(icon, songfolder + "ccc.png");
                        }

                        success++;
                        if (!chkRAR.Checked || backgroundWorker1.CancellationPending)
                        {
                            continue;
                        }
                        var archive = Path.GetFileName(file);
                        archive = archive.Replace(" ", "").Replace("-", "_").Replace("\\", "").Replace("'", "").Replace(",", "").Replace("_rb3con", "");
                        archive = Tools.CleanString(archive, false);
                        archive = PSFolder + archive + "_ps.rar";

                        var arg = "a -m5 -ep1 -r \"" + archive + "\" \"" + songfolder.Substring(0, songfolder.Length - 1) + "\"";
                        Log("Creating RAR archive");

                        Log(Tools.CreateRAR(rar, archive, arg)? "Created RAR archive successfully" : "RAR archive creation failed");
                    }
                    catch (Exception ex)
                    {
                        Log("There was an error: " + ex.Message);
                        Log("Attempting to continue with the next file");
                    }
                }
                catch (Exception ex)
                {
                    Log("There was a problem accessing that file");
                    Log("The error says: " + ex.Message);
                }
            }
            Log("Successfully processed " + success + " of " + counter + " files");
            return(true);
        }
Beispiel #28
0
        ///////////////////////////////////////////
        //SPITFIRE1337 MODS
        ///////////////////////////////////////////
        public IEnumerable <IResult> WriteSaveXbox()
        {
            if (this.SaveFile == null)
            {
                yield break;
            }

            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            File.Delete(path + "/savegame.sav");

            //MessageBox.Show("A save file box will now appear, please select a EXISTING XBOX SAVE to overwrite. I can not emphasize this enough, ALWAYS KEEP A WORKING BACKUP. Once you have a backup press ok to continue");

            var saveFile = this.SaveFile;

            yield return(new DelegateResult(() =>
            {
                Endian endian;
                this.General.ExportData(saveFile.SaveGame, out endian);
                this.CurrencyOnHand.ExportData(saveFile.SaveGame);
                this.Backpack.ExportData(saveFile.SaveGame);
                this.Bank.ExportData(saveFile.SaveGame);


                using (var output = File.Create(path + "/savegame.sav"))
                {
                    saveFile.Endian = endian;
                    saveFile.Serialize(output);
                }
            }).Rescue().Execute(
                             x =>
                             new MyMessageBox("An exception was thrown (press Ctrl+C to copy this text):\n\n" + x.ToString(), "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine()));

            string fileName = null;

            MySaveFileResult ofr;

            ofr = new MySaveFileResult()
                  .PromptForOverwrite()
                  .FilterFiles(
                ffc => ffc.AddFilter("sav", true)
                .WithDescription("Borderlands 2 Save Files")
                .AddAllFilesFilter())
                  .WithFileDo(s => fileName = s);

            if (string.IsNullOrEmpty(this._SavePath) == false &&
                Directory.Exists(this._SavePath) == true)
            {
                ofr = ofr.In(this._SavePath);
            }

            yield return(ofr);

            if (fileName == null)
            {
                yield break;
            }
            if (File.Exists(fileName))
            {
                File.WriteAllBytes(fileName, Properties.Resources.Save0001);
            }
            else
            {
                File.Delete(fileName);
                File.WriteAllBytes(fileName, Properties.Resources.Save0001);
            }
            yield return(new DelegateResult(() =>
            {
                string profileid = this.General.Profileid;
                DJsIO io = new DJsIO(fileName, DJFileMode.Open, true);

                io.Position = 0x371;
                io.WriteHexString(profileid);
                io.Close();
            }).Rescue().Execute(
                             x =>
                             new MyMessageBox("An exception was thrown (press Ctrl+C to copy this text):\n\n" + x.ToString(), "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine()));

            yield return(new DelegateResult(() =>
            {
                STFSPackage stfs = new STFSPackage(fileName, null);
                FileEntry item = stfs.GetFile("savegame.sav"); //Get's the account file



                if (!item.Replace(path + "\\savegame.sav"))
                {
                    //If Not xent.Extract(Application.StartupPath + "\" + "savegame.sav") Then
                    //MessageBoxEx.Show("Extraction Failed!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.[Error])
                    throw new Exception("Failed to insert save file to xbox save. Please use a program like modio or horizon to insert your save");
                }
                else
                {
                    //MessageBox.Show("File Inserted");

                    //If Not  Then

                    //End If
                    //MessageBoxEx.Show("Extraction Complete!", "Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                }
                if (!File.Exists(path + "/kv.bin"))
                {
                    File.WriteAllBytes(path + "/kv.bin", Properties.Resources.KV);
                }



                stfs.FlushPackage(new RSAParams(path + "/kv.bin"));
                stfs.CloseIO();
            }).Rescue().Execute(
                             x =>
                             new MyMessageBox("An exception was thrown (press Ctrl+C to copy this text):\n\n" + x.ToString(), "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine()));
        }