internal Package(STFSPackage pk, bool readData = true, DJsIO dj = null)
        {
            this.package = pk;
            this.dj = dj;

            ReadData(readData, this);
        }
Пример #2
0
 internal STFSDescriptor(STFSPackage xPackage)
 {
     xPackage.xIO.Position = 0x340;
     xPackage.xIO.IsBigEndian = true;
     int xBlockInfo = xPackage.xIO.ReadInt32();
     xBaseByte = (byte)(((xBlockInfo + 0xFFF) & 0xF000) >> 0xC);
     xPackage.xIO.Position = 0x379;
     if (xPackage.xIO.ReadByte() != 0x24) // Struct Size
         throw STFSExcepts.Type;
     if (xPackage.xIO.ReadByte() != 0) // Reversed
         throw STFSExcepts.Type;
     /* STRUCT OF THE NEXT 6 BYTES:
      * byte for block separation
      * Little Endian File Table block count short (2 bytes)
      * 3 bytes in Little Endian for the starting block of the File Table */
     byte idx = (byte)(xPackage.xIO.ReadByte() & 3);
     xStruct = xPackage.xIO.ReadBytes(5);
     xPackage.xIO.Position = 0x395;
     xBlockCount = xPackage.xIO.ReadUInt32();
     uint xOldBlocks = xPackage.xIO.ReadUInt32();
     // Checks the type of Structure
     if (xBaseByte == 0xB)
     {
         if (idx == 1)
             XSetStructure(STFSType.Type0);
         else throw STFSExcepts.Type;
     }
     else if (xBaseByte == 0xA)
     {
         if (idx == 0 || idx == 2)
             XSetStructure(STFSType.Type1);
         else throw STFSExcepts.Type;
     }
     else throw STFSExcepts.Type;
     if (xBlockCount > SpaceBetween[2])
         throw STFSExcepts.MaxOver;
     TopRecord = new BlockRecord(((uint)((idx >> 1) & 1) << 30 | (uint)xOldBlocks << 15));
     // Grab Real Block Count
     for (uint i = (xBlockCount - 1); i >= 0; i--)
     {
         xBlockCount = (i + 1);
         if (GenerateDataOffset(i) < xPackage.xIO.Length)
             break;
     }
 }
Пример #3
0
 private void buttonX1_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to change these packages?", "WARNING", MessageBoxButtons.YesNo) != DialogResult.Yes)
         return;
     menuStrip1.Enabled = groupPanel1.Enabled = listBox1.Enabled = false;
     progressBarX1.Value = 0;
     progressBarX1.Maximum = listBox1.Items.Count;
     for (int i = 0; i < listBox1.Items.Count; i++)
     {
         STFSPackage x = null;
         try { x = new STFSPackage((string)listBox1.Items[i], null); }
         catch { }
         if (x != null)
             fix(i);
         progressBarX1.Value++;
     }
     menuStrip1.Enabled = groupPanel1.Enabled = listBox1.Enabled = true;
 }
        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 byte[] RebuildPackageInMemory(RSAParams xParams)
        {
            if (!CanRead)
            {
                OpenAgain();
            }
            var cstfs = new CreateSTFS();
            cstfs.HeaderData.Description = xHeader.Description;
            cstfs.HeaderData.DeviceID = xHeader.DeviceID;

            cstfs.HeaderData.ProfileID = xHeader.ProfileID;
            cstfs.HeaderData.Publisher = xHeader.Publisher;
            cstfs.HeaderData.SaveConsoleID = xHeader.SaveConsoleID;
            cstfs.HeaderData.Title_Package = xHeader.Title_Package;
            cstfs.HeaderData.Title_Display = xHeader.Title_Display;
            cstfs.HeaderData.ThisType = xHeader.ThisType;
            cstfs.HeaderData.SaveGameID = xHeader.SaveGameID;
            cstfs.HeaderData.DataFileCount = xHeader.DataFileCount;
            cstfs.HeaderData.DataFileSize = xHeader.DataFileSize;
            cstfs.HeaderData.MediaID = xHeader.MediaID;
            cstfs.HeaderData.TitleID = xHeader.TitleID;
            cstfs.HeaderData.Version_ = xHeader.Version_;
            cstfs.HeaderData.Version_Base = xHeader.Version_Base;

            cstfs.HeaderData.MetaDataVersion = xHeader.MetaDataVersion;
            cstfs.HeaderData.Platform = xHeader.Platform;
            cstfs.HeaderData.SeasonNumber = xHeader.SeasonNumber;

            cstfs.STFSType = xSTFSStruct.ThisType;
            // Populate
            foreach (var y in xFolderDirectory)
                cstfs.AddFolder(y.GetPath());
            foreach (var y in xFileDirectory)
            {
                cstfs.AddFile(y.ExtractBytes(true), y.GetPath());
            }
            byte[] ret;
            var xreturn = new STFSPackage(cstfs, xParams, out ret, xLog);
            if (xreturn.ParseSuccess)
            {

                return ret;
            }
            xreturn.xIO.Close();

            return null;
        }
        ///////////////////////////////////////////
        //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());
        }
Пример #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();
     }
 }
 void read(DJsIO xIO, STFSPackage xPackage, PackageMagic MagicType)
 {
     xMagic = MagicType;
     xIO.Position = 0x22C;
     if (xPackage != null)
         xPackage.AddToLog("Reading Liscenses");
     xLisc = new List<STFSLicense>();
     for (int i = 0; i < 0x10; i++)
         xLisc.Add(new STFSLicense(xIO.ReadInt64(), xIO.ReadInt32(), xIO.ReadInt32(), i == 0));
     if (xPackage != null)
         xPackage.AddToLog("Reading Package locks");
     xIO.Position = 0x344;
     if (xPackage != null)
         xPackage.AddToLog("Reading Header Values");
     xThisType = (PackageType)xIO.ReadUInt32(); ;
     MetaDataVersion = xIO.ReadUInt32();
     xContentSize = xIO.ReadInt64();
     MediaID = xIO.ReadUInt32();
     Version_ = xIO.ReadUInt32();
     Version_Base = xIO.ReadUInt32();
     TitleID = xIO.ReadUInt32();
     Platform = xIO.ReadByte();
     ExecutableType = xIO.ReadByte();
     DiscNumber = xIO.ReadByte();
     DiscInSet = xIO.ReadByte();
     SaveGameID = xIO.ReadUInt32();
     SaveConsoleID = (long)xIO.ReadUInt40();
     ProfileID = xIO.ReadInt64();
     xIO.Position = 0x39D;
     DataFileCount = xIO.ReadUInt32();
     DataFileSize = xIO.ReadInt64();
     Reserved = xIO.ReadInt64();
     xSeriesID = xIO.ReadBytes(0x10);
     xSeasonID = xIO.ReadBytes(0x10);
     SeasonNumber = xIO.ReadUInt16();
     EpidsodeNumber = xIO.ReadUInt16();
     xIO.Position += 0x28;
     xDeviceID = xIO.ReadBytes(0x14);
     for (int i = 0; i < 9; i++)
         xTitles[i] = xIO.ReadString(StringForm.Unicode, 0x80).Replace("\0", "");
     for (int i = 0; i < 9; i++)
         xDescriptions[i] = xIO.ReadString(StringForm.Unicode, 0x80).Replace("\0", "");
     xPublisher = xIO.ReadString(StringForm.Unicode, 0x40).Replace("\0", "");
     xTitle = xIO.ReadString(StringForm.Unicode, 0x40).Replace("\0", "");
     IDTransferByte = xIO.ReadByte();
     // Package Image
     int xSize = xIO.ReadInt32();
     xIO.Position = 0x171A;
     if (xSize < 0x4000)
         xPackageImage = xIO.ReadBytes(xSize);
     else xPackageImage = xIO.ReadBytes(0x4000);
     // Content Image
     xIO.Position = 0x1716;
     xSize = xIO.ReadInt32();
     xIO.Position = 0x571A;
     if (xSize < 0x4000)
         xContentImage = xIO.ReadBytes(xSize);
     else xContentImage = xIO.ReadBytes(0x4000);
     xLoaded = true;
 }
        public IEnumerable<IResult> ReadSave()
        {
            string fileName = null;

            MyOpenFileResult ofr;

            ofr = new MyOpenFileResult()
                .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;
            }

            ///////////////////////////////////////////
            //SPITFIRE1337 MODS
            ///////////////////////////////////////////

            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            //using (FileStream fs = File.Create(path)) { }
            File.Delete(path + "/mytempsave.sav");
            File.Delete(path + "/savegame.sav");
            File.Copy(fileName, path + "/mytempsave.sav");
            string profileid = "";
            string deviceid = "";
            string consoleid = "";


            Stream input1 = new FileStream(fileName, FileMode.Open);

            // Ensure that the target does not exist.



            //Stream input = new Stream(fs);
            var check = input1.ReadValueU32(Endian.Big);

            input1.Close();

            if (check == 0x434F4E20)
            {
                //MessageBox.Show("This is a xbox save");

                yield return new DelegateResult(() =>
                {
                    DJsIO io = new DJsIO(fileName, DJFileMode.Open, true);

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


                STFSPackage xPackage = new STFSPackage(fileName, null);
                FileEntry xent = (FileEntry)xPackage.GetFile("savegame.sav");

                if (!xent.Extract(path + "/savegame.sav"))
                {
                    //MessageBoxEx.Show("Extraction Failed!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.[Error])
                    //xboxextract.ReportProgress(200, "Extraction Failed");
                    //Thread.Sleep(2000);
                    //Return
                    MessageBox.Show("Could not extract savegame.sav. Please use a program like modio or horizon to extract your savegame.sav");
                }
                else
                {


                    fileName = path + "/savegame.sav";
                    //MessageBox.Show("File extracted");
                    //Thread.Sleep(2000);
                    //MessageBoxEx.Show("Extraction Complete!", "Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                }

            }
            else
            {
                profileid = "0";
                deviceid = "0";
                consoleid = "0";
            }

            yield return new DelegateResult(() =>
            {
                FileFormats.SaveFile saveFile;
                using (var input = File.OpenRead(fileName))
                {
                    saveFile = FileFormats.SaveFile.Deserialize(input, FileFormats.SaveFile.DeserializeSettings.None);
                }

                this.SaveFile = saveFile;
                this.General.ImportData(saveFile.SaveGame, saveFile.Endian, profileid, deviceid, consoleid);
                this.CurrencyOnHand.ImportData(saveFile.SaveGame);
                this.Backpack.ImportData(saveFile.SaveGame);
                this.Bank.ImportData(saveFile.SaveGame);
            })
                .Rescue<DllNotFoundException>().Execute(
                    x => new MyMessageBox("Failed to load save: " + x.Message, "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine())
                .Rescue<FileFormats.SaveFormatException>().Execute(
                    x => new MyMessageBox("Failed to load save: " + x.Message, "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine())
                .Rescue<FileFormats.SaveCorruptionException>().Execute(
                    x => new MyMessageBox("Failed to load save: " + x.Message, "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine())
                .Rescue().Execute(
                    x =>
                    new MyMessageBox("An exception was thrown (press Ctrl+C to copy):\n\n" + x.ToString(),
                                     "Error")
                        .WithIcon(MessageBoxImage.Error).AsCoroutine());
            ///////////////////////////////////////////
            //END SPITFIRE1337 MODS
            ///////////////////////////////////////////
        }
Пример #11
0
 private void button1_Click(object sender, EventArgs e)
 {
     RSAParams xParams;
     string xOut = null;
     if (xtype == PackType.STFS)
     {
         xOut = VariousFunctions.GetUserFileLocale("Save to where?", "", false);
         if (xOut == null)
             return;
     }
     else
     {
         if (ximg == null)
         {
             MessageBox.Show("Please select an image");
             return;
         }
         string y = VariousFunctions.GetUserFolderLocale("Select a save location");
         if (y == null)
             return;
         xOut = y;
     }
     if (radioButton1.Checked)
         xParams = xparent.PublicKV;
     else if (radioButton2.Checked)
         xParams = new RSAParams(StrongSigned.LIVE);
     else xParams = new RSAParams(StrongSigned.PIRS);
     if (xtype == PackType.STFS)
     {
         LogRecord rec = new LogRecord();
         STFSPackage xy = new STFSPackage(xsession, xParams, xOut, rec);
         PackageExplorer z = new PackageExplorer(xparent);
         z.set(ref xy);
         z.listBox4.Items.AddRange(rec.Log);
         this.Close();
         z.Show();
     }
     else
     {
         CreateSVOD z = new CreateSVOD(ximg, xOut, xhead);
         if (z.Create(xParams, (PackageType)comboBoxEx2.SelectedItem))
             MessageBox.Show("Completed successfully");
         else MessageBox.Show("Unsuccessful build");
     }
     this.Dispose();
 }
 /// <summary>
 /// Initializes an instance
 /// </summary>
 /// <param name="x"></param>
 public ProfilePackage(ref STFSPackage x)
     : base(ref x)
 {
     if (Header.ThisType == PackageType.Profile)
         LoadProfile(true);
 }
 /// <summary>
 /// Sets a package comming in to this package
 /// </summary>
 /// <param name="xIn"></param>
 void SetSamePackage(ref STFSPackage xIn)
 {
     xLog = xIn.xLog;
     AddToLog("Setting Package");
     xIO = xIn.xIO;
     xSTFSStruct = xIn.STFSStruct;
     xFolderDirectory = xIn.xFolderDirectory;
     xFileDirectory = xIn.xFileDirectory;
     xHeader = xIn.xHeader;
     xFileBlocks = xIn.xFileBlocks;
     xActive = xIn.xActive;
     xroot = xIn.xroot;
     xIn = null;
     foreach (FileEntry x in xFileDirectory)
         x.xPackage = this;
     foreach (FolderEntry x in xFolderDirectory)
         x.xPackage = this;
 }
Пример #14
0
 public void set(ref STFSPackage x)
 {
     xpack = x;
     Log("Package parsed");
     node1.NodeClick += new EventHandler(xReturn_NodeClick);
     SetNodes();
     node1.SetChecked(true, eTreeAction.Expand);
     Log("Contents loaded");
     if (xPackage.FileNameShort.Length < 30)
         this.Text = "Package - " + xPackage.FileNameShort;
     else this.Text = "Package - " + xPackage.FileNameShort.Substring(0, 30) + "...";
     textBoxX1.Text = xPackage.FileNameLong;
     textBoxX2.Text = xPackage.Header.Title_Display;
     textBoxX3.Text = xPackage.Header.Description;
     try { pictureBox1.Image = xPackage.Header.ContentImage; }
     catch { pictureBox1.Enabled = false; }
     try { pictureBox2.Image = xPackage.Header.PackageImage; }
     catch { pictureBox2.Enabled = false; }
     comboBoxEx1.SelectedIndex = 0;
     numericUpDown5.Value = xPackage.Header.SaveConsoleID;
     numericUpDown6.Value = xPackage.Header.ProfileID;
     textBoxX17.Text = xPackage.Header.DeviceID.HexString();
     numericUpDown9_ValueChanged(null, null);
     if (xPackage.Header.IDTransfer == TransferLock.NoTransfer)
         checkBoxX1.Checked = false;
     else
     {
         checkBoxX2.Checked = ((byte)xPackage.Header.IDTransfer & 1) == 1;
         checkBoxX3.Checked = (((byte)xPackage.Header.IDTransfer >> 1) & 1) == 1;
     }
     labelX8.Text = "Title ID: " + xpack.Header.TitleID.ToString("X");
     if (xPackage.Header.ThisType != PackageType.Profile)
     {
         tabItem4.Visible = false;
         return;
     }
     xprof = new ProfilePackage(ref x);
     xpack = null;
     xprof.RemovePhDAT();
     if (xprof.HasValidAccount)
     {
         if (xprof.UserFile.IsLiveEnabled)
         {
             textBoxX9.Text = VariousFunctions.EndianConvert(BitConverter.GetBytes(xprof.UserFile.XUID)).HexString();
             textBoxX9.Enabled =
             buttonX4.Enabled =
             checkBoxX5.Enabled = true;
             PassCode[] xPass = xprof.UserFile.GetPassCode();
             if (xPass.Length > 0)
             {
                 checkBoxX5.Checked = true;
                 comboBoxEx3.SelectedItem = xPass[0];
                 comboBoxEx4.SelectedItem = xPass[1];
                 comboBoxEx5.SelectedItem = xPass[2];
                 comboBoxEx6.SelectedItem = xPass[3];
             }
         }
         textBoxX8.Text = xprof.UserFile.GetGamertag();
         buttonX5.Enabled = true;
         Log("Account loaded");
     }
     if (xprof.HasDashGPD)
     {
         UserInfo xInfo = xprof.GetUserStrings();
         if (xInfo.Bio != null)
             textBoxX10.Text = xInfo.Bio;
         if (xInfo.Motto != null)
             textBoxX11.Text = xInfo.Motto;
         if (xInfo.Name != null)
             textBoxX12.Text = xInfo.Name;
         if (xInfo.Location != null)
             textBoxX13.Text = xInfo.Location;
         Setting temp = xprof.UserGPD.GetSetting(GPDIDs.GCardZone);
         if (temp != null)
         {
             comboBoxEx7.Enabled = true;
             GamerZone[] zones = (GamerZone[])Enum.GetValues(typeof(GamerZone));
             comboBoxEx7.DataSource = zones;
             if (Enum.IsDefined(typeof(GamerZone), temp.Data))
                 comboBoxEx7.SelectedItem = (GamerZone)((uint)temp.Data);
             else comboBoxEx7.SelectedItem = GamerZone.Unknown;
             has1 = buttonX16.Enabled = true;
         }
         temp = xprof.UserGPD.GetSetting(GPDIDs.GCardRep, SettingType.Float);
         if (temp != null)
         {
             numericUpDown1.Enabled = true;
             numericUpDown1.Value = (decimal)((float)temp.Data);
             has2 = buttonX16.Enabled = true;
         }
         SetList();
         buttonX15.Enabled =
         listBox3.Enabled = true;
         // groupPanel2.Enabled = true;
         SetNmric(GPDIDs.GCardCredit, textBoxX15);
         Log("Profile loaded");
     }
     if (!xprof.IsValidProfile)
     {
         if (xprof.HasValidAccount && !xprof.HasDashGPD)
             MessageBox.Show("This file does not have valid Dash information, therefore achievement modding is disabled");
         else if (!xprof.HasValidAccount && xprof.HasDashGPD)
             MessageBox.Show("This file does not have a valid user account, therefore, account block editing is disabled");
         else
         {
             tabItem4.Visible = false;
             MessageBox.Show("This file has no valid user information, profile - specific editing is disabled");
         }
     }
 }
 /// <summary>
 /// Function for partial classes, importing packages
 /// </summary>
 /// <param name="xIn"></param>
 protected STFSPackage(ref STFSPackage xIn)
 {
     xActive = true; SetSamePackage(ref xIn); xActive = false;
 }
 /// <summary>
 /// Rebuilds the package using package creation
 /// </summary>
 /// <param name="xParams"></param>
 /// <returns></returns>
 public bool RebuildPackage(RSAParams xParams)
 {
     if (!ActiveCheck())
         return false;
     if (!xParams.Valid)
         return (xActive = false);
     CreateSTFS x = new CreateSTFS();
     x.HeaderData = xHeader;
     x.STFSType = xSTFSStruct.ThisType;
     // Populate
     foreach (FolderEntry y in xFolderDirectory)
         x.AddFolder(y.GetPath());
     foreach (FileEntry y in xFileDirectory)
     {
         DJsIO io = y.xGetTempIO(true);
         if (io != null && io.Accessed)
         {
             io.Close();
             x.AddFile(io.FileNameLong, y.GetPath());
         }
     }
     STFSPackage xreturn = new STFSPackage(x, xParams, VariousFunctions.GetTempFileLocale(), xLog);
     if (xreturn.ParseSuccess)
     {
         xIO.Close();
         xreturn.xIO.Close();
         if (!VariousFunctions.MoveFile(xreturn.xIO.FileNameLong, xIO.FileNameLong))
             return (xActive = false);
         xreturn.xIO = xIO;
         SetSamePackage(ref xreturn);
         xIO.OpenAgain();
         return !(xActive = false);
     }
     xreturn.xIO.Close();
     VariousFunctions.DeleteFile(xreturn.xIO.FileNameLong);
     return (xActive = false);
 }
 internal ItemEntry(ItemEntry x)
 {
     xName = x.xName;
     xAccessed = x.xAccessed;
     xCreated = x.xCreated;
     xBlockCount = x.xBlockCount;
     xDirectoryOffset = x.xDirectoryOffset;
     xFlag = x.xFlag;
     xEntryID = x.xEntryID;
     xFolderPointer = x.xFolderPointer;
     xSize = x.xSize;
     xStartBlock = x.xStartBlock;
     xFlag = (byte)((x.FolderFlag ? 1 : 0) << 7 | (x.UnknownFlag ? 1 : 0) << 6 | xName.Length);
     xPackage = x.xPackage;
 }
 internal ItemEntry(string NameIn, int SizeIn, bool xIsFolder, ushort xID, ushort xFolder, STFSPackage xPackageIn)
 {
     xPackage = xPackageIn;
     xEntryID = xID;
     xFolderPointer = xFolder;
     if (NameIn.Length >= 0x28)
         xName = NameIn.Substring(0, 0x28);
     else xName = NameIn;
     xFlag = (byte)(((xIsFolder ? 1 : 0) << 7) | xName.Length);
     DateTime x = DateTime.Now;
     xCreated = TimeStamps.FatTimeInt(x);
     xAccessed = xCreated;
     if (xIsFolder)
     {
         xSize = 0;
         xStartBlock = 0;
         xBlockCount = 0;
     }
     else
     {
         xSize = SizeIn;
         if (xSize != 0)
             xBlockCount = (uint)(((xSize - 1) / 0x1000) + 1);
     }
 }
 internal ItemEntry(byte[] xDataIn, long DirectOffset, ushort xID, STFSPackage xPackageIn)
 {
     try
     {
         xPackage = xPackageIn;
         DJsIO xFileIO = new DJsIO(xDataIn, true);
         xFileIO.Position = 0;
         xEntryID = xID;
         xFileIO.Position = 0x28;
         xFlag = xFileIO.ReadByte();
         if (xNameLength > 0x28)
             xNameLength = 0x28;
         xFileIO.Position = 0;
         if (xNameLength == 0)
             return;
         xName = xFileIO.ReadString(StringForm.ASCII, xNameLength);
         xName.IsValidXboxName();
         xFileIO.Position = 0x2F;
         xStartBlock = xFileIO.ReadUInt24(false);
         xFolderPointer = xFileIO.ReadUInt16();
         xSize = xFileIO.ReadInt32();
         xBlockCount = (uint)(((xSize - 1) / 0x1000) + 1);
         xCreated = xFileIO.ReadInt32();
         xAccessed = xFileIO.ReadInt32();
         xDirectoryOffset = DirectOffset;
     }
     catch { xNameLength = 0; }
 }
Пример #20
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
            }
        }
Пример #21
0
 /// <summary>
 /// Saves any changes made to the save data without resigning the container package (if any).
 /// </summary>
 public void SaveChanges(X360.STFS.STFSPackage package)
 {
     _saveData.Update(_rawPath);
     UpdateSTFS(package, null);
 }
Пример #22
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();
        }
Пример #23
0
 /// <summary>
 /// Saves any changes made to the save data, resigning the container package with the specified KV file.
 /// </summary>
 /// <param name="kvPath">The path to the KV file to resign with.</param>
 public void SaveChanges(X360.STFS.STFSPackage package, string kvPath)
 {
     SaveChanges(package, File.ReadAllBytes(kvPath));
 }
Пример #24
0
 static STFSPackage LoadSTFS(byte[] data)
 {
     DJsIO dj = new DJsIO(data, true);
     var ret = new STFSPackage(dj, null);
     if (ret.ParseSuccess == false)
         ret = null;
     return ret;
 }
Пример #25
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); }
 }
 internal FolderEntry(string NameIn, int SizeIn, ushort xID, ushort xFolder, STFSPackage xPackageIn)
     : base(NameIn, SizeIn, true, xID, xFolder, xPackageIn)
 {
 }
Пример #27
0
        void ReadFile(string file)
        {
            try
            {
                switch (VariousFunctions.ReadFileType(file))
                {
                    case XboxFileType.STFS:
                        {
                            LogRecord x = new LogRecord();
                            STFSPackage xPackage = new STFSPackage(file, x);
                            if (!xPackage.ParseSuccess)
                                return;
                            PackageExplorer xExplorer = new PackageExplorer(this);
                            xExplorer.listBox4.Items.AddRange(x.Log);
                            x.WhenLogged += new LogRecord.OnLog(xExplorer.xAddLog);
                            xExplorer.set(ref xPackage);
                            xExplorer.Show();
                        }
                        break;

                    case XboxFileType.SVOD:
                        {
                            SVODPackage hd = new SVODPackage(file, null);
                            if (!hd.IsValid)
                                return;
                            HDDGameForm frm = new HDDGameForm(hd, file, this);
                            frm.MdiParent = this;
                            frm.Show();
                        }
                        break;

                    case XboxFileType.Music:
                        {
                            MusicFile xfile = new MusicFile(file);
                            MusicView xview = new MusicView(this, file, xfile);
                            xview.MdiParent = this;
                            xview.Show();
                        }
                        break;

                    case XboxFileType.GPD:
                        {
                            GameGPD y = new GameGPD(file, 0xFFFFFFFF);
                            GPDViewer z = new GPDViewer(y, file, this);
                            z.MdiParent = this;
                            z.Show();
                        }
                        break;

                    case XboxFileType.FATX:
                        {
                            FATXDrive xdrive = new FATXDrive(file);
                            Files.Add(file);
                            FATXBrowser y = new FATXBrowser(xdrive, file, this);
                            y.MdiParent = this;
                            y.Show();
                        }
                        break;

                    case XboxFileType.GDF:
                        {
                            StatsForm x = new StatsForm(0);
                            x.Text = "Select Deviation";
                            if (x.ShowDialog() != DialogResult.OK)
                                return;
                            GDFImage ximg = new GDFImage(file, x.ChosenID);
                            if (!ximg.Valid)
                                throw new Exception("Invalid package");
                            GDFViewer xViewer = new GDFViewer(ximg, this);
                            xViewer.MdiParent = this;
                            xViewer.Show();
                        }
                        break;

                    default: MessageBox.Show("Error: Unknown file"); return;
                }
                Files.Add(file);
            }
            catch (Exception x) { MessageBox.Show(x.Message); }
        }
        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();
        }
 internal FileEntry(string NameIn, int SizeIn, bool xIsFolder, ushort xID, ushort xFolder, STFSPackage xPackageIn)
     : base(NameIn, SizeIn, xIsFolder, xID, xFolder, xPackageIn)
 {
 }
Пример #30
0
 /// <summary>
 /// Saves any changes made to the save data, resigning the container package with the specified KV.
 /// </summary>
 /// <param name="kvData">The KV data to resign with</param>
 public void SaveChanges(X360.STFS.STFSPackage package, byte[] kvData)
 {
     _saveData.Update(_rawPath);
     UpdateSTFS(package, kvData);
 }
 internal HeaderData(STFSPackage xPackage, PackageMagic MagicType)
 {
     read(xPackage.xIO, xPackage, MagicType);
 }
        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) { }
            }
        }
Пример #33
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();
        }