public static void BuildXBox360Package(string songFileName, DLCPackageData info, IEnumerable<string> xboxFiles, GameVersion gameVersion, DLCPackageType dlcType = DLCPackageType.Song)
        {
            LogRecord x = new LogRecord();
            RSAParams xboxRSA = info.SignatureType == PackageMagic.CON ? new RSAParams(new DJsIO(Resources.XBox360_KV, true)) : new RSAParams(StrongSigned.LIVE);
            CreateSTFS xboxSTFS = new CreateSTFS();
            xboxSTFS.HeaderData = info.GetSTFSHeader(gameVersion, dlcType);
            foreach (string file in xboxFiles)
                xboxSTFS.AddFile(file, Path.GetFileName(file));

            STFSPackage xboxPackage = new STFSPackage(xboxSTFS, xboxRSA, songFileName, x);
            var generated = xboxPackage.RebuildPackage(xboxRSA);
            if (!generated)
                throw new InvalidOperationException("Error on create XBox360 package, details: \n" + x.Log);

            xboxPackage.FlushPackage(xboxRSA);
            xboxPackage.CloseIO();

            DirectoryExtension.SafeDelete(XBOX_WORKDIR);
        }
        public static void BuildXBox360Package(string packagePath, DLCPackageData info, IEnumerable<string> xboxFiles, PackageMagic? xboxPackageType)
        {
            LogRecord x = new LogRecord();
            RSAParams xboxRSA = xboxPackageType == PackageMagic.CON ? new RSAParams(new DJsIO(Resources.XBox360_KV, true)) : new RSAParams(StrongSigned.LIVE);
            CreateSTFS xboxSTFS = new CreateSTFS();
            xboxSTFS.HeaderData = info.GetSTFSHeader();
            foreach (string file in xboxFiles)
                xboxSTFS.AddFile(file, Path.GetFileName(file));

            STFSPackage xboxPackage = new STFSPackage(xboxSTFS, xboxRSA, packagePath, x);
            var generated = xboxPackage.RebuildPackage(xboxRSA);
            if (!generated)
                throw new InvalidOperationException("Error on create XBox360 package, details: \n\r" + x.Log);

            xboxPackage.FlushPackage(xboxRSA);
            xboxPackage.CloseIO();

            try
            {
                if (Directory.Exists(xboxWorkDir))
                    Directory.Delete(xboxWorkDir, true);
            }
            catch { /*Have no problem if don't delete*/ }
        }
        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();
        }
Ejemplo n.º 5
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
            }
        }
Ejemplo n.º 6
0
        private void BuildXboxPackage(string packageFileName, string saveFileName)
        {
            CreateSTFS Package = new CreateSTFS();

            Package.STFSType = STFSType.Type1;
            Package.HeaderData.ProfileID = CurrentWSG.ProfileID;
            Package.HeaderData.DeviceID = CurrentWSG.DeviceID;

            Assembly newAssembly = Assembly.GetExecutingAssembly();
            Stream WT_Icon = newAssembly.GetManifestResourceStream("WillowTree.Resources.WT_CON.png");

            Package.HeaderData.ContentImage = System.Drawing.Image.FromStream(WT_Icon);
            Package.HeaderData.Title_Display = CurrentWSG.CharacterName + " - Level " + CurrentWSG.Level + " - " + CurrentLocation.Text;
            Package.HeaderData.Title_Package = "Borderlands";
            Package.HeaderData.TitleID = 1414793191;
            Package.AddFile(saveFileName, "SaveGame.sav");

            STFSPackage CON = new STFSPackage(Package, new RSAParams(AppDir + "\\Data\\KV.bin"), packageFileName, new X360.Other.LogRecord());

            CON.FlushPackage(new RSAParams(AppDir + "\\Data\\KV.bin"));
            CON.CloseIO();
            WT_Icon.Close();
        }
        ///////////////////////////////////////////
        //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());
        }
Ejemplo n.º 8
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();
     }
 }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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); }
 }
Ejemplo n.º 11
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;
        }
Ejemplo n.º 12
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;
        }
Ejemplo n.º 13
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;
        }