mirror of
https://github.com/kwsch/pk3DS.git
synced 2026-10-02 05:46:47 -05:00
Add GARC shuffler
Currently inaccessible; haven't done any tests on it.
This commit is contained in:
152
pk3DS/Subforms/Shuffler.Designer.cs
generated
Normal file
152
pk3DS/Subforms/Shuffler.Designer.cs
generated
Normal file
@@ -0,0 +1,152 @@
|
||||
namespace pk3DS
|
||||
{
|
||||
partial class Shuffler
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
114
pk3DS/Subforms/Shuffler.cs
Normal file
114
pk3DS/Subforms/Shuffler.cs
Normal file
@@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
120
pk3DS/Subforms/Shuffler.resx
Normal file
120
pk3DS/Subforms/Shuffler.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
Reference in New Issue
Block a user