diff --git a/pk3DS/Subforms/Shuffler.Designer.cs b/pk3DS/Subforms/Shuffler.Designer.cs new file mode 100644 index 0000000..d4f21cf --- /dev/null +++ b/pk3DS/Subforms/Shuffler.Designer.cs @@ -0,0 +1,152 @@ +namespace pk3DS +{ + partial class Shuffler + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.CB_a = new System.Windows.Forms.ComboBox(); + this.CB_b = new System.Windows.Forms.ComboBox(); + this.CB_c = new System.Windows.Forms.ComboBox(); + this.L_a = new System.Windows.Forms.Label(); + this.L_File = new System.Windows.Forms.Label(); + this.B_Shuffle = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // CB_a + // + this.CB_a.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_a.FormattingEnabled = true; + this.CB_a.Items.AddRange(new object[] { + "0", + "1", + "2", + "3"}); + this.CB_a.Location = new System.Drawing.Point(36, 11); + this.CB_a.Name = "CB_a"; + this.CB_a.Size = new System.Drawing.Size(34, 21); + this.CB_a.TabIndex = 0; + this.CB_a.TextChanged += new System.EventHandler(this.updateLabel); + // + // CB_b + // + this.CB_b.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_b.FormattingEnabled = true; + this.CB_b.Items.AddRange(new object[] { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9"}); + this.CB_b.Location = new System.Drawing.Point(76, 11); + this.CB_b.Name = "CB_b"; + this.CB_b.Size = new System.Drawing.Size(34, 21); + this.CB_b.TabIndex = 1; + this.CB_b.TextChanged += new System.EventHandler(this.updateLabel); + // + // CB_c + // + this.CB_c.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_c.FormattingEnabled = true; + this.CB_c.Items.AddRange(new object[] { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9"}); + this.CB_c.Location = new System.Drawing.Point(116, 11); + this.CB_c.Name = "CB_c"; + this.CB_c.Size = new System.Drawing.Size(34, 21); + this.CB_c.TabIndex = 2; + this.CB_c.TextChanged += new System.EventHandler(this.updateLabel); + // + // L_a + // + this.L_a.Location = new System.Drawing.Point(12, 9); + this.L_a.Name = "L_a"; + this.L_a.Size = new System.Drawing.Size(18, 23); + this.L_a.TabIndex = 3; + this.L_a.Text = "a"; + this.L_a.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // L_File + // + this.L_File.Location = new System.Drawing.Point(109, 35); + this.L_File.Name = "L_File"; + this.L_File.Size = new System.Drawing.Size(41, 23); + this.L_File.TabIndex = 4; + this.L_File.Text = "FILENAME HERE"; + this.L_File.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // B_Shuffle + // + this.B_Shuffle.Location = new System.Drawing.Point(76, 67); + this.B_Shuffle.Name = "B_Shuffle"; + this.B_Shuffle.Size = new System.Drawing.Size(75, 23); + this.B_Shuffle.TabIndex = 5; + this.B_Shuffle.Text = "Shuffle!"; + this.B_Shuffle.UseVisualStyleBackColor = true; + this.B_Shuffle.Click += new System.EventHandler(this.B_Shuffle_Click); + // + // Shuffler + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(164, 102); + this.Controls.Add(this.B_Shuffle); + this.Controls.Add(this.L_File); + this.Controls.Add(this.L_a); + this.Controls.Add(this.CB_c); + this.Controls.Add(this.CB_b); + this.Controls.Add(this.CB_a); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "Shuffler"; + this.Text = "Shuffler"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ComboBox CB_a; + private System.Windows.Forms.ComboBox CB_b; + private System.Windows.Forms.ComboBox CB_c; + private System.Windows.Forms.Label L_a; + private System.Windows.Forms.Label L_File; + private System.Windows.Forms.Button B_Shuffle; + } +} \ No newline at end of file diff --git a/pk3DS/Subforms/Shuffler.cs b/pk3DS/Subforms/Shuffler.cs new file mode 100644 index 0000000..dd71f04 --- /dev/null +++ b/pk3DS/Subforms/Shuffler.cs @@ -0,0 +1,114 @@ +using System; +using System.IO; +using System.Linq; +using System.Windows.Forms; + +namespace pk3DS +{ + /* GARC File Shuffler + * Shuffles the FATB table references around (Start/End/Length) + * Only shuffles nonfoldered files around. + * Backs up the original file incase the user shuffles a file with ill-effect. + */ + public partial class Shuffler : Form + { + public Shuffler() + { + InitializeComponent(); + CB_a.SelectedIndex = CB_b.SelectedIndex = CB_c.SelectedIndex = 0; + } + private string garc; + + private void updateLabel(object sender, EventArgs e) + { + garc = Path.Combine(Main.RomFSPath, "a", + CB_a.SelectedIndex.ToString(), CB_a.SelectedIndex.ToString(), CB_a.SelectedIndex.ToString()); + + if (File.Exists(garc)) + { + L_File.Text = String.Format("File: a\\{0}\\{1}\\{2}", + CB_a.SelectedIndex, CB_b.SelectedIndex, CB_c.SelectedIndex); + B_Shuffle.Enabled = true; + } + else + { + L_File.Text = "File does not exist!"; + B_Shuffle.Enabled = false; + garc = null; + } + } + + private void B_Shuffle_Click(object sender, EventArgs e) + { + if (garc == null) + return; + + var g = CTR.GARC.unpackGARC(garc); + + // Build a list of all the files we can relocate. + int[] randFiles = new int[g.fatb.FileCount]; + int ctr = 0; + for (int i = 0; i < randFiles.Length; i++) + if (!g.fatb.Entries[i].IsFolder) + randFiles[ctr++] = i; + + Array.Resize(ref randFiles, ctr); + + if (ctr == 0) { Util.Alert("No files to shuffle...?"); return; } + + // Create backup + string dest = "backup" + Path.DirectorySeparatorChar + String.Format("PreShuffle {0}", L_File.Text.Split(':')[1].Replace("\\", "")); + if (!File.Exists(dest)) + File.Copy(garc, dest); + + var g2 = CTR.GARC.unpackGARC(garc); + int[] newFileOffset = (int[])randFiles.Clone(); + Util.Shuffle(newFileOffset); + + for (int i = 0; i < randFiles.Length; i++) + g.fatb.Entries[randFiles[i]] = g2.fatb.Entries[newFileOffset[i]]; + + #region Re-write GARC Header information! + using (var newGARC = File.OpenWrite(garc)) + using (BinaryWriter gw = new BinaryWriter(newGARC)) + { + gw.Seek(7*4, SeekOrigin.Begin); // Skip GARC Header + // Write GARC + // gw.Write((uint)0x47415243); // GARC + // gw.Write((uint)0x0000001C); // Header Length + // gw.Write((ushort)0xFEFF); // Endianness BOM + // gw.Write((ushort)0x0400); // Const (4) + // gw.Write((uint)0x00000004); // Section Count (4) + // gw.Write((uint)0x00000000); // Data Offset (temp) + // gw.Write((uint)0x00000000); // File Length (temp) + // gw.Write((uint)0x00000000); // Largest File Size (temp) + + // Write FATO + gw.Write((uint)0x4641544F); // FATO + gw.Write(g.fato.HeaderSize); // Header Size + gw.Write(g.fato.EntryCount); // Entry Count + gw.Write(g.fato.Padding); // Padding + for (int i = 0; i < g.fato.Entries.Length; i++) + gw.Write((uint)g.fato.Entries[i].Offset); + + // Write FATB + gw.Write((uint)0x46415442); // FATB + gw.Write(g.fatb.HeaderSize); // Header Size + gw.Write(g.fatb.FileCount); // File Count + foreach (var fe in g.fatb.Entries) + { + gw.Write(fe.Vector); + foreach (var s in fe.SubEntries.Where(s => s.Exists)) + { + gw.Write((uint)s.Start); + gw.Write((uint)s.End); + gw.Write((uint)s.Length); + } + } + } + #endregion + + Util.Alert("GARC Shuffled!"); + } + } +} diff --git a/pk3DS/Subforms/Shuffler.resx b/pk3DS/Subforms/Shuffler.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/pk3DS/Subforms/Shuffler.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file