public PackageCreatez(MainForm xParent, PackType xThisType) { this.MdiParent = xParent; xparent = xParent; InitializeComponent(); List<PackageType> y = new List<PackageType>(); if (xThisType == PackType.STFS) { xsession = new CreateSTFS(); PackageType[] x = (PackageType[])Enum.GetValues(typeof(PackageType)); y.AddRange(x); y.RemoveAll(new Predicate<PackageType>(ptcheck)); node1.DataKey = (ushort)0xFFFF; node1.NodeClick += new EventHandler(xReturn_NodeClick); comboBoxEx1.SelectedIndex = 0; comboBoxEx4.DataSource = Enum.GetValues(typeof(SphereColor)); comboBoxEx4.SelectedIndex = 0; comboBoxEx5.DataSource = Enum.GetValues(typeof(DashStyle)); comboBoxEx5.SelectedIndex = 0; numericUpDown4.Value = xsession.ThemeSettings.AvatarLightingAmbient; numericUpDown7.Value = xsession.ThemeSettings.AvatarLightingDirectional3; numericUpDown8.Value = xsession.ThemeSettings.AvatarLightingDirectional0; numericUpDown9.Value = xsession.ThemeSettings.AvatarLightingDirectional1; numericUpDown10.Value = xsession.ThemeSettings.AvatarLightingDirectional2; advTree1.SelectedIndex = 0; tabItem7.Visible = false; } else { y.Add(PackageType.OriginalXboxGame); y.Add(PackageType.HDDInstalledGame); y.Add(PackageType.GamesOnDemand); y.Add(PackageType.SocialTitle); tabItem6.Visible = false; xhead = new HeaderData(); tabItem5.Visible = false; tabItem4.Visible = false; comboBoxEx1.Visible = false; } xtype = xThisType; comboBoxEx2.DataSource = y.ToArray(); comboBoxEx2.SelectedIndex = 0; comboBoxEx3.DataSource = Enum.GetValues(typeof(Languages)); comboBoxEx3.SelectedIndex = 0; SetText(); }
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*/ } }
internal CItemEntry(string path, ref CreateSTFS xCreate) { xthispath = path; create = xCreate; }
internal CFolderEntry(string path, ref CreateSTFS xCreate) : base(path, ref xCreate) { }
internal CFileEntry(string xFile, string path, ref CreateSTFS xCreate) : base(path, ref xCreate) { filelocale = xFile; }
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(); }
/// <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); }
/// <summary> /// Create an STFS Package /// </summary> /// <param name="xSession"></param> /// <param name="xSigning"></param> /// <param name="xOutPath"></param> /// <param name="LogIn"></param> public STFSPackage(CreateSTFS xSession, RSAParams xSigning, string xOutPath, LogRecord LogIn) { xActive = true; if (!xSigning.Valid) throw CryptoExcepts.ParamError; if (xSession.xFileDirectory.Count == 0) throw new Exception(); try { AddToLog("Setting Package variables"); new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(System.DLLIdentify.PrivilegeCheck)).Start(System.Threading.Thread.CurrentThread); xroot = new FolderEntry("", 0, 0xFFFF, 0xFFFF, this); if (xSession.HeaderData.ThisType == PackageType.ThematicSkin) { DJsIO x1 = new DJsIO(true); DJsIO x2 = new DJsIO(true); x1.Write((int)xSession.ThemeSettings.StyleType); x1.Flush(); x1.Close(); if (!xSession.AddFile(x1.FileNameLong, "DashStyle")) throw STFSExcepts.ThemeError; x2.Write("SphereColor=" + ((byte)xSession.ThemeSettings.Sphere).ToString().PadRight(2, '\0')); x2.Write(new byte[] { 0xD, 0xA }); x2.Write("AvatarLightingDirectional=" + xSession.ThemeSettings.AvatarLightingDirectional0.ToString("#0.0") + "," + xSession.ThemeSettings.AvatarLightingDirectional1.ToString("#0.0000") + "," + xSession.ThemeSettings.AvatarLightingDirectional2.ToString("#0.0") + ",0x" + xSession.ThemeSettings.AvatarLightingDirectional3.ToString("X")); x2.Write(new byte[] { 0xD, 0xA }); x2.Write("AvatarLightingAmbient=0x" + xSession.ThemeSettings.AvatarLightingAmbient.ToString("X")); x2.Write(new byte[] { 0xD, 0xA }); x2.Flush(); x2.Close(); if (!xSession.AddFile(x2.FileNameLong, "parameters.ini")) throw STFSExcepts.ThemeError; } else if (xSession.HeaderData.ThisType == PackageType.GamesOnDemand || xSession.HeaderData.ThisType == PackageType.HDDInstalledGame || xSession.HeaderData.ThisType == PackageType.OriginalXboxGame || xSession.HeaderData.ThisType == PackageType.SocialTitle) throw STFSExcepts.Game; xLog = LogIn; xHeader = xSession.HeaderData; xSTFSStruct = new STFSDescriptor(xSession.STFSType, 0); xIO = new DJsIO(true); List<BlockRecord> DirectoryBlockz = new List<BlockRecord>(); // switched2 = true; uint xcurblock = 0; for (ushort i = 0; i < xSession.GetDirectoryCount; i++) { DirectoryBlockz.Add(new BlockRecord()); DirectoryBlockz[DirectoryBlockz.Count - 1].ThisBlock = xcurblock++; /*if (!switched0.Contains((int)(xcurblock / Constants.BlockLevel[0]))) switched0.Add((int)(xcurblock / Constants.BlockLevel[0])); if (!switched1.Contains((int)(xcurblock / Constants.BlockLevel[1]))) switched1.Add((int)(xcurblock / Constants.BlockLevel[1]));*/ } xFileBlocks = DirectoryBlockz.ToArray(); xWriteChain(xFileBlocks); xSTFSStruct.xDirectoryBlockCount = (ushort)xFileBlocks.Length; ushort xCurID = 0; xSession.xFolderDirectory.Sort(new Comparison<CFolderEntry>(sortpathct)); foreach (CFolderEntry x in xSession.xFolderDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFolderDirectory.Add(new FolderEntry(x.Name, 0, xCurID++, pointer, this)); xFolderDirectory[xFolderDirectory.Count - 1].xFixOffset(); } foreach (CFileEntry x in xSession.xFileDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFileDirectory.Add(new FileEntry(x.Name, (int)x.GetLength(), false,xCurID++, pointer, this)); List<BlockRecord> xAlloc = new List<BlockRecord>(); for (uint i = 0; i < x.BlockCount(); i++) { xAlloc.Add(new BlockRecord()); xAlloc[xAlloc.Count - 1].ThisBlock = xcurblock++; /*if (!switched0.Contains((int)(xcurblock / Constants.BlockLevel[0]))) switched0.Add((int)(xcurblock / Constants.BlockLevel[0])); if (!switched1.Contains((int)(xcurblock / Constants.BlockLevel[1]))) switched1.Add((int)(xcurblock / Constants.BlockLevel[1]));*/ } xFileDirectory[xFileDirectory.Count - 1].xBlockCount = (uint)xAlloc.Count; xFileDirectory[xFileDirectory.Count - 1].xStartBlock = xAlloc[0].ThisBlock; xFileDirectory[xFileDirectory.Count - 1].xPackage = this; xFileDirectory[xFileDirectory.Count - 1].xFixOffset(); xWriteChain(xAlloc.ToArray()); } AddToLog("Writing Entry Table"); DJsIO xent; if (!xEntriesToFile(out xent)) throw new Exception(); xWriteTo(ref xent, xFileBlocks); xent.Close(); VariousFunctions.DeleteFile(xent.FileNameLong); AddToLog("Writing Files"); uint curblck = xSession.GetDirectoryCount; foreach (CFileEntry z in xSession.xFileDirectory) { List<BlockRecord> w = new List<BlockRecord>(); uint ct = z.BlockCount(); for (uint y = 0; y < ct; y++) { w.Add(new BlockRecord()); w[w.Count - 1].ThisBlock = curblck++; } DJsIO x = null; try { x = new DJsIO(z.FileLocale, DJFileMode.Open, true); xWriteTo(ref x, w.ToArray()); } catch { } if (x != null) x.Dispose(); } xWriteTables(); xWriteHeader(xSigning); xIO.Close(); VariousFunctions.MoveFile(xIO.FileNameLong, xOutPath); xIO = new DJsIO(xOutPath, DJFileMode.Open, true); xActive = false; } catch (Exception x) { xFileDirectory = null; xFolderDirectory = null; xIO.Dispose(); throw x; } }
internal CFileEntry(byte[] xFile, string path, CreateSTFS xCreate) : base(path, ref xCreate) { filelocale = null; FileData = xFile; }
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; }
/// <summary> /// Create an STFS Package /// </summary> /// <param name="xSession"></param> /// <param name="xSigning"></param> /// <param name="xOutPath"></param> /// <param name="LogIn"></param> public STFSPackage(CreateSTFS xSession, RSAParams xSigning, out byte[] ret, LogRecord LogIn) { ret = null; xActive = true; if (!xSigning.Valid) throw CryptoExcepts.ParamError; if (xSession.xFileDirectory.Count == 0) throw new Exception(); ////try { //AddToLog("Setting Package variables"); xroot = new FolderEntry("", 0, 0xFFFF, 0xFFFF, this); if (xSession.HeaderData.ThisType == PackageType.GamesOnDemand || xSession.HeaderData.ThisType == PackageType.HDDInstalledGame || xSession.HeaderData.ThisType == PackageType.OriginalXboxGame || xSession.HeaderData.ThisType == PackageType.SocialTitle) throw STFSExcepts.Game; xLog = LogIn; xHeader = xSession.HeaderData; xSTFSStruct = new STFSDescriptor(xSession.STFSType, 0); xIO = new DJsIO(); var DirectoryBlockz = new List<BlockRecord>(); // switched2 = true; uint xcurblock = 0; for (ushort i = 0; i < xSession.GetDirectoryCount; i++) { DirectoryBlockz.Add(new BlockRecord()); DirectoryBlockz[DirectoryBlockz.Count - 1].ThisBlock = xcurblock++; } xFileBlocks = DirectoryBlockz.ToArray(); xWriteChain(xFileBlocks); xSTFSStruct.xDirectoryBlockCount = (ushort)xFileBlocks.Length; ushort xCurID = 0; xSession.xFolderDirectory.Sort(new Comparison<CFolderEntry>(sortpathct)); foreach (var x in xSession.xFolderDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFolderDirectory.Add(new FolderEntry(x.Name, 0, xCurID++, pointer, this)); xFolderDirectory[xFolderDirectory.Count - 1].xFixOffset(); } foreach (CFileEntry x in xSession.xFileDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFileDirectory.Add(new FileEntry(x.Name, (int)x.GetLength(), false, xCurID++, pointer, this)); var xAlloc = new List<BlockRecord>(); for (uint i = 0; i < x.BlockCount(); i++) { xAlloc.Add(new BlockRecord()); xAlloc[xAlloc.Count - 1].ThisBlock = xcurblock++; } xFileDirectory[xFileDirectory.Count - 1].xBlockCount = (uint)xAlloc.Count; xFileDirectory[xFileDirectory.Count - 1].xStartBlock = xAlloc[0].ThisBlock; xFileDirectory[xFileDirectory.Count - 1].xPackage = this; xFileDirectory[xFileDirectory.Count - 1].xFixOffset(); xWriteChain(xAlloc.ToArray()); } //AddToLog("Writing Entry Table"); DJsIO xent; if (!xEntriesToFile(out xent)) throw new Exception(); xWriteTo(ref xent, xFileBlocks); xent.Close(); //VariousFunctions.DeleteFile(xent.FileNameLong); //AddToLog("Writing Files"); uint curblck = xSession.GetDirectoryCount; foreach (var z in xSession.xFileDirectory) { var w = new List<BlockRecord>(); uint ct = z.BlockCount(); for (uint y = 0; y < ct; y++) { w.Add(new BlockRecord()); w[w.Count - 1].ThisBlock = curblck++; } DJsIO x = null; //try { x = new DJsIO(z.FileData, true); xWriteTo(ref x, w.ToArray()); } //catch { } if (x != null) x.Dispose(); } xWriteTables(); xWriteHeader(xSigning); ret = xIO.GetBytes(); xIO.Close(); //VariousFunctions.MoveFile(xIO.FileNameLong, xOutPath); xActive = false; } ////catch (Exception x) { xFileDirectory = null; xFolderDirectory = null; xIO.Dispose(); throw x; } }