BLZ & Code Changes to allow for ExeFS tools

This commit is contained in:
Kurt
2015-01-18 21:45:22 -08:00
parent c2d658c4c8
commit 077e92005e
15 changed files with 958 additions and 186 deletions

527
pk3DS/BLZ.cs Normal file
View File

@@ -0,0 +1,527 @@
/*----------------------------------------------------------------------------*/
/*-- blz.c - Bottom LZ coding for Nintendo GBA/DS --*/
/*-- Copyright (C) 2011 CUE --*/
/*-- --*/
/*-- Ported to C# by Andi Badra, tweaks by Kaphotics --*/
/*-- --*/
/*-- This program is free software: you can redistribute it and/or modify --*/
/*-- it under the terms of the GNU General Public License as published by --*/
/*-- the Free Software Foundation, either version 3 of the License, or --*/
/*-- (at your option) any later version. --*/
/*-- --*/
/*-- This program is distributed in the hope that it will be useful, --*/
/*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/
/*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/
/*-- GNU General Public License for more details. --*/
/*-- --*/
/*-- You should have received a copy of the GNU General Public License --*/
/*-- along with this program. If not, see <http://www.gnu.org/licenses/>. --*/
/*----------------------------------------------------------------------------*/
using System;
using System.IO;
using System.Windows.Forms;
namespace blz
{
public partial class BLZCoder
{
public static void main(String[] args)
{
new BLZCoder(args);
}
private static readonly int CMD_DECODE = 0;
private static readonly int CMD_ENCODE = 1;
static readonly int BLZ_NORMAL = 0;
static readonly int BLZ_BEST = 1;
static readonly int BLZ_SHIFT = 1;
static readonly int BLZ_MASK = 0x80;
static readonly int BLZ_THRESHOLD = 2;
static readonly int BLZ_N = 0x1002;
static readonly int BLZ_F = 0x12;
static readonly int BLZ_MAXIM = 0x01400000;
static readonly int RAW_MAXIM = 0x00FFFFFF;
bool arm9;
int new_len;
static void EXIT(string text)
{
Console.Write(text);
}
private ProgressBar pBar1;
private void initpBar(int max)
{
if (pBar1.InvokeRequired)
pBar1.Invoke((MethodInvoker)delegate { pBar1.Minimum = 0; pBar1.Step = 1; pBar1.Value = 0; pBar1.Maximum = max; });
else { pBar1.Minimum = 0; pBar1.Step = 1; pBar1.Value = 0; pBar1.Maximum = max; }
}
private void setpBarPos(int pos)
{
if (pBar1.InvokeRequired)
pBar1.Invoke((MethodInvoker)delegate { pBar1.Value = pos; });
else { pBar1.Value = pos; }
}
public BLZCoder(string[] args, ProgressBar pBar = null)
{
int cmd, mode = 0, arg;
if (pBar == null) pBar1 = new ProgressBar();
pBar1 = pBar;
// Title();
if (args == null || (args.Length != 2))
throw new Exception("No arguments supplied to BLZ");
if (args[0].Equals("-d"))
cmd = CMD_DECODE;
else if (args[0].Equals("-en") || args[0].Equals("-en9"))
{
cmd = CMD_ENCODE;
mode = BLZ_NORMAL;
}
else if (args[0].Equals("-eo") || args[0].Equals("-eo9"))
{
cmd = CMD_ENCODE;
mode = BLZ_BEST;
}
else { Console.Write("Command not supported" + Environment.NewLine); return; }
if (args.Length < 2)
Console.Write("Filename not specified" + Environment.NewLine);
else
{
switch (cmd)
{
case 0:
for (arg = 1; arg < args.Length; arg++)
BLZ_Decode(args[arg]);
break;
case 1:
arm9 = (args[0].Length > 3 && args[0][3] == '9');
for (arg = 1; arg < args.Length; arg++)
BLZ_Encode(args[arg], mode);
break;
}
}
Console.Write(Environment.NewLine + "Done" + Environment.NewLine);
}
private void Save(String filename, byte[] buffer, int length)
{
Array.Resize(ref buffer, length);
try
{ File.WriteAllBytes(filename, buffer); }
catch (IOException e)
{
Console.Write(Environment.NewLine + "File write error" + Environment.NewLine + e.ToString() + Environment.NewLine);
File.WriteAllBytes("blz.bin", buffer);
Console.Write(Environment.NewLine + "Wrote to 'blz.bin' instead." + Environment.NewLine);
}
}
private void BLZ_Decode(String filename)
{
try
{
Console.Write("- decoding '%s'", filename);
long startTime = System.DateTime.Now.Millisecond;
byte[] buf = File.ReadAllBytes(filename);
BLZResult result = BLZ_Decode(buf);
if (result != null)
Save(filename, result.buffer, result.length);
Console.Write(" - done, time="
+ (DateTime.Now.Millisecond - startTime) + "ms");
Console.Write(Environment.NewLine + "");
}
catch (IOException e)
{ Console.Write(Environment.NewLine + "File read error" + Environment.NewLine + e.ToString()); }
}
private BLZResult BLZ_Decode(byte[] data)
{
byte[] pak_buffer, raw_buffer;
int pak, raw, pak_end, raw_end;
int pak_len, raw_len, len, pos, inc_len, hdr_len, enc_len, dec_len;
int flags = 0, mask;
pak_buffer = prepareData(data);
pak_len = pak_buffer.Length - 3;
inc_len = BitConverter.ToInt32(pak_buffer, pak_len - 4);
if (inc_len < 1)
{
Console.Write(", WARNING: not coded file!");
enc_len = 0;
dec_len = pak_len;
pak_len = 0;
raw_len = dec_len;
}
else
{
if (pak_len < 8)
{
Console.Write(Environment.NewLine + "File has a bad header" + Environment.NewLine);
return null;
}
hdr_len = pak_buffer[pak_len - 5];
if (hdr_len < 8 || hdr_len > 0xB)
{
Console.Write(Environment.NewLine + "Bad header length" + Environment.NewLine);
return null;
}
if (pak_len <= hdr_len)
{
Console.Write(Environment.NewLine + "Bad length" + Environment.NewLine);
return null;
}
enc_len = (int)(BitConverter.ToUInt32(pak_buffer, pak_len - 8) & 0x00FFFFFF);
dec_len = pak_len - enc_len;
pak_len = enc_len - hdr_len;
raw_len = dec_len + enc_len + inc_len;
if (raw_len > RAW_MAXIM)
{
Console.Write(Environment.NewLine + "Bad decoded length" + Environment.NewLine);
return null;
}
}
raw_buffer = new byte[raw_len];
pak = 0;
raw = 0;
pak_end = dec_len + pak_len;
raw_end = raw_len;
for (len = 0; len < dec_len; len++)
raw_buffer[raw++] = pak_buffer[pak++];
BLZ_Invert(pak_buffer, dec_len, pak_len);
mask = 0;
while (raw < raw_end)
{
if ((mask = (int)((uint)mask >> BLZ_SHIFT)) == 0)
{
if (pak == pak_end)
break;
flags = pak_buffer[pak++];
mask = BLZ_MASK;
}
if ((flags & mask) == 0)
{
if (pak == pak_end)
break;
raw_buffer[raw++] = pak_buffer[pak++];
}
else
{
if ((pak + 1) >= pak_end)
break;
pos = pak_buffer[pak++] << 8;
pos |= pak_buffer[pak++];
len = (int)((uint)pos >> 12) + BLZ_THRESHOLD + 1;
if (raw + len > raw_end)
{
Console.Write(", WARNING: wrong decoded length!");
len = raw_end - raw;
}
pos = (pos & 0xFFF) + 3;
while ((len--) > 0)
{
int charHere = raw_buffer[raw - pos];
raw_buffer[raw++] = (byte)charHere;
}
}
}
BLZ_Invert(raw_buffer, dec_len, raw_len - dec_len);
raw_len = raw;
if (raw != raw_end)
Console.Write(", WARNING: unexpected end of encoded file!");
return new BLZResult(raw_buffer, raw_len);
}
private BLZResult BLZ_Encode(byte[] data, int mode)
{
byte[] raw_buffer, pak_buffer, new_buffer;
int raw_len, pak_len;
new_len = 0;
raw_buffer = prepareData(data);
raw_len = raw_buffer.Length - 3;
pak_buffer = null;
pak_len = BLZ_MAXIM + 1;
new_buffer = BLZ_Code(raw_buffer, raw_len, mode);
if (new_len < pak_len)
{
pak_buffer = new_buffer;
pak_len = new_len;
}
return new BLZResult(pak_buffer, pak_len);
}
private byte[] prepareData(byte[] data)
{
int fs = data.Length;
byte[] fb = new byte[fs + 3];
for (int i = 0; i < fs; i++)
fb[i] = data[i];
return fb;
}
private void writeUnsigned(byte[] buffer, int offset, int value)
{
buffer[offset] = (byte)(value & 0xFF);
buffer[offset + 1] = (byte)((value >> 8) & 0xFF);
buffer[offset + 2] = (byte)((value >> 16) & 0xFF);
buffer[offset + 3] = (byte)((value >> 24) & 0x7F);
}
private void BLZ_Encode(String filename, int mode)
{
try
{
Console.Write(String.Format("Now encoding {0}", filename));
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
byte[] buf = File.ReadAllBytes(filename);
BLZResult result = BLZ_Encode(buf, mode);
if (result != null)
Save(filename, result.buffer, result.length);
stopwatch.Stop();
Console.Write(Environment.NewLine + "Done, time elapsed = " + (stopwatch.ElapsedMilliseconds) + "ms" + Environment.NewLine);
}
catch (IOException e)
{ Console.Write(Environment.NewLine + "File read error" + Environment.NewLine + e.ToString() + Environment.NewLine); }
}
private byte[] BLZ_Code(byte[] raw_buffer, int raw_len, int best)
{
byte[] pak_buffer, tmp;
int pak, raw, raw_end, flg = 0;
int pak_len, inc_len, hdr_len, enc_len, len;
int len_best, pos_best = 0, len_next, pos_next = 0, len_post, pos_post = 0;
int pak_tmp, raw_tmp, raw_new;
int mask;
pak_tmp = 0;
raw_tmp = raw_len;
pak_len = raw_len + ((raw_len + 7) / 8) + 11;
pak_buffer = new byte[pak_len];
raw_new = raw_len;
// We don't do any of the checks here
// Presume that we actually are using an arm9
if (arm9)
raw_new -= 0x4000;
BLZ_Invert(raw_buffer, 0, raw_len);
pak = 0;
raw = 0;
raw_end = raw_new;
mask = 0;
initpBar(raw_end);
while (raw < raw_end)
{
setpBarPos(raw);
if ((mask = (int)((uint)mask >> BLZ_SHIFT)) == 0)
{
pak_buffer[(flg = pak++)] = 0;
mask = BLZ_MASK;
}
SearchPair sl1 = SEARCH(pos_best, raw_buffer, raw, raw_end);
len_best = sl1.l;
pos_best = sl1.p;
// LZ-CUE optimization start
if (best == BLZ_BEST)
{
if (len_best > BLZ_THRESHOLD)
{
if (raw + len_best < raw_end)
{
raw += len_best;
SearchPair sl2 = SEARCH(pos_next, raw_buffer, raw,
raw_end);
len_next = sl2.l;
pos_next = sl2.p;
raw -= (len_best - 1);
SearchPair sl3 = SEARCH(pos_post, raw_buffer, raw,
raw_end);
len_post = sl3.l;
pos_post = sl3.p;
raw--;
if (len_next <= BLZ_THRESHOLD)
len_next = 1;
if (len_post <= BLZ_THRESHOLD)
len_post = 1;
if ((len_best + len_next) <= (1 + len_post))
len_best = 1;
}
}
}
// LZ-CUE optimization end
pak_buffer[flg] = (byte)(pak_buffer[flg] << 1);
if (len_best > BLZ_THRESHOLD)
{
raw += len_best;
pak_buffer[flg] |= 1;
pak_buffer[pak++] = (byte)((byte)((len_best - (BLZ_THRESHOLD + 1)) << 4) | ((uint)(pos_best - 3) >> 8));
pak_buffer[pak++] = (byte)((pos_best - 3));
}
else
pak_buffer[pak++] = raw_buffer[raw++];
if (pak + raw_len - raw < pak_tmp + raw_tmp)
{
pak_tmp = pak;
raw_tmp = raw_len - raw;
}
}
while ((mask > 0) && (mask != 1))
{
mask = (int)((uint)mask >> BLZ_SHIFT);
pak_buffer[flg] = (byte)(pak_buffer[flg] << 1);
}
pak_len = pak;
BLZ_Invert(raw_buffer, 0, raw_len);
BLZ_Invert(pak_buffer, 0, pak_len);
if (pak_tmp == 0 || (raw_len + 4 < ((pak_tmp + raw_tmp + 3) & 0xFFFFFFFC) + 8))
{
pak = 0;
raw = 0;
raw_end = raw_len;
while (raw < raw_end)
pak_buffer[pak] = raw_buffer[raw];
while ((pak & 3) > 0)
pak_buffer[pak++] = 0;
pak_buffer[pak++] = 0;
pak_buffer[pak++] = 0;
pak_buffer[pak++] = 0;
pak_buffer[pak++] = 0;
}
else
{
tmp = new byte[raw_tmp + pak_tmp + 11];
for (len = 0; len < raw_tmp; len++)
tmp[len] = raw_buffer[len];
for (len = 0; len < pak_tmp; len++)
tmp[raw_tmp + len] = pak_buffer[len + pak_len - pak_tmp];
pak = 0;
pak_buffer = tmp;
pak = raw_tmp + pak_tmp;
enc_len = pak_tmp;
hdr_len = 8;
inc_len = raw_len - pak_tmp - raw_tmp;
while ((pak & 3) > 0)
{
pak_buffer[pak++] = 0xFF;
hdr_len++;
}
writeUnsigned(pak_buffer, pak, enc_len + hdr_len);
pak += 3;
pak_buffer[pak++] = (byte)hdr_len;
writeUnsigned(pak_buffer, pak, inc_len - hdr_len);
pak += 4;
}
new_len = pak;
return pak_buffer;
}
private class SearchPair
{
public int l;
public int p;
public SearchPair(int l, int p)
{
this.l = l;
this.p = p;
}
}
private SearchPair SEARCH(int p, byte[] raw_buffer, int raw, int raw_end)
{
int l = BLZ_THRESHOLD;
int max = (raw >= BLZ_N) ? BLZ_N : raw;
for (int pos = 3; pos <= max; pos++)
{
int len;
for (len = 0; len < BLZ_F; len++)
{
if (raw + len == raw_end)
break;
if (len >= pos)
break;
if (raw_buffer[raw + len] != raw_buffer[raw + len - pos])
break;
}
if (len > l)
{
p = pos;
if ((l = len) == BLZ_F)
break;
}
}
return new SearchPair(l, p);
}
private class BLZResult
{
public BLZResult(byte[] raw_buffer, int raw_len)
{
this.buffer = raw_buffer;
this.length = raw_len;
}
public byte[] buffer;
public int length;
}
private void BLZ_Invert(byte[] buffer, int offset, int length)
{
int bottom, ch;
bottom = offset + length - 1;
while (offset < bottom)
{
ch = buffer[offset];
buffer[offset++] = buffer[bottom];
buffer[bottom--] = (byte)ch;
}
}
}
}

129
pk3DS/Main.Designer.cs generated
View File

@@ -30,7 +30,7 @@ private void InitializeComponent()
{
this.B_Open = new System.Windows.Forms.Button();
this.TB_Path = new System.Windows.Forms.TextBox();
this.GB_Tools = new System.Windows.Forms.GroupBox();
this.GB_RomFS = new System.Windows.Forms.GroupBox();
this.B_Maison = new System.Windows.Forms.Button();
this.B_EggMove = new System.Windows.Forms.Button();
this.B_LevelUp = new System.Windows.Forms.Button();
@@ -48,7 +48,13 @@ private void InitializeComponent()
this.L_Game = new System.Windows.Forms.Label();
this.pBar1 = new System.Windows.Forms.ProgressBar();
this.L_About = new System.Windows.Forms.Label();
this.GB_Tools.SuspendLayout();
this.GB_ExeFS = new System.Windows.Forms.GroupBox();
this.B_Pickup = new System.Windows.Forms.Button();
this.B_Mart = new System.Windows.Forms.Button();
this.B_MoveTutor = new System.Windows.Forms.Button();
this.B_TMHM = new System.Windows.Forms.Button();
this.GB_RomFS.SuspendLayout();
this.GB_ExeFS.SuspendLayout();
this.SuspendLayout();
//
// B_Open
@@ -57,7 +63,7 @@ private void InitializeComponent()
this.B_Open.Name = "B_Open";
this.B_Open.Size = new System.Drawing.Size(75, 23);
this.B_Open.TabIndex = 0;
this.B_Open.Text = "Open \'a\'";
this.B_Open.Text = "Open Dir";
this.B_Open.UseVisualStyleBackColor = true;
this.B_Open.Click += new System.EventHandler(this.B_Open_Click);
//
@@ -71,29 +77,29 @@ private void InitializeComponent()
this.TB_Path.Size = new System.Drawing.Size(349, 20);
this.TB_Path.TabIndex = 1;
//
// GB_Tools
// GB_RomFS
//
this.GB_Tools.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.GB_RomFS.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.GB_Tools.Controls.Add(this.B_Maison);
this.GB_Tools.Controls.Add(this.B_EggMove);
this.GB_Tools.Controls.Add(this.B_LevelUp);
this.GB_Tools.Controls.Add(this.B_StoryText);
this.GB_Tools.Controls.Add(this.B_Item);
this.GB_Tools.Controls.Add(this.B_Move);
this.GB_Tools.Controls.Add(this.B_Evolution);
this.GB_Tools.Controls.Add(this.B_Personal);
this.GB_Tools.Controls.Add(this.B_MegaEvo);
this.GB_Tools.Controls.Add(this.B_Wild);
this.GB_Tools.Controls.Add(this.B_Trainer);
this.GB_Tools.Controls.Add(this.B_GameText);
this.GB_Tools.Enabled = false;
this.GB_Tools.Location = new System.Drawing.Point(12, 67);
this.GB_Tools.Name = "GB_Tools";
this.GB_Tools.Size = new System.Drawing.Size(430, 110);
this.GB_Tools.TabIndex = 2;
this.GB_Tools.TabStop = false;
this.GB_Tools.Text = "ROM Editing Tools";
this.GB_RomFS.Controls.Add(this.B_Maison);
this.GB_RomFS.Controls.Add(this.B_EggMove);
this.GB_RomFS.Controls.Add(this.B_LevelUp);
this.GB_RomFS.Controls.Add(this.B_StoryText);
this.GB_RomFS.Controls.Add(this.B_Item);
this.GB_RomFS.Controls.Add(this.B_Move);
this.GB_RomFS.Controls.Add(this.B_Evolution);
this.GB_RomFS.Controls.Add(this.B_Personal);
this.GB_RomFS.Controls.Add(this.B_MegaEvo);
this.GB_RomFS.Controls.Add(this.B_Wild);
this.GB_RomFS.Controls.Add(this.B_Trainer);
this.GB_RomFS.Controls.Add(this.B_GameText);
this.GB_RomFS.Enabled = false;
this.GB_RomFS.Location = new System.Drawing.Point(12, 67);
this.GB_RomFS.Name = "GB_RomFS";
this.GB_RomFS.Size = new System.Drawing.Size(430, 110);
this.GB_RomFS.TabIndex = 2;
this.GB_RomFS.TabStop = false;
this.GB_RomFS.Text = "RomFS Editing Tools";
//
// B_Maison
//
@@ -259,7 +265,7 @@ private void InitializeComponent()
//
this.pBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pBar1.Location = new System.Drawing.Point(12, 182);
this.pBar1.Location = new System.Drawing.Point(12, 241);
this.pBar1.Name = "pBar1";
this.pBar1.Size = new System.Drawing.Size(430, 14);
this.pBar1.TabIndex = 6;
@@ -274,26 +280,82 @@ private void InitializeComponent()
this.L_About.Text = "[A]";
this.L_About.Click += new System.EventHandler(this.L_About_Click);
//
// GB_ExeFS
//
this.GB_ExeFS.Controls.Add(this.B_Pickup);
this.GB_ExeFS.Controls.Add(this.B_Mart);
this.GB_ExeFS.Controls.Add(this.B_MoveTutor);
this.GB_ExeFS.Controls.Add(this.B_TMHM);
this.GB_ExeFS.Enabled = false;
this.GB_ExeFS.Location = new System.Drawing.Point(12, 184);
this.GB_ExeFS.Name = "GB_ExeFS";
this.GB_ExeFS.Size = new System.Drawing.Size(430, 50);
this.GB_ExeFS.TabIndex = 8;
this.GB_ExeFS.TabStop = false;
this.GB_ExeFS.Text = "ExeFS Editing Tools";
//
// B_Pickup
//
this.B_Pickup.Location = new System.Drawing.Point(6, 19);
this.B_Pickup.Name = "B_Pickup";
this.B_Pickup.Size = new System.Drawing.Size(100, 23);
this.B_Pickup.TabIndex = 3;
this.B_Pickup.Text = "Pickup Editor";
this.B_Pickup.UseVisualStyleBackColor = true;
this.B_Pickup.Click += new System.EventHandler(this.B_Pickup_Click);
//
// B_Mart
//
this.B_Mart.Location = new System.Drawing.Point(218, 19);
this.B_Mart.Name = "B_Mart";
this.B_Mart.Size = new System.Drawing.Size(100, 23);
this.B_Mart.TabIndex = 2;
this.B_Mart.Text = "Mart Editor";
this.B_Mart.UseVisualStyleBackColor = true;
this.B_Mart.Click += new System.EventHandler(this.B_Mart_Click);
//
// B_MoveTutor
//
this.B_MoveTutor.Location = new System.Drawing.Point(324, 19);
this.B_MoveTutor.Name = "B_MoveTutor";
this.B_MoveTutor.Size = new System.Drawing.Size(100, 23);
this.B_MoveTutor.TabIndex = 1;
this.B_MoveTutor.Text = "Move Tutor Editor";
this.B_MoveTutor.UseVisualStyleBackColor = true;
this.B_MoveTutor.Click += new System.EventHandler(this.B_MoveTutor_Click);
//
// B_TMHM
//
this.B_TMHM.Location = new System.Drawing.Point(112, 19);
this.B_TMHM.Name = "B_TMHM";
this.B_TMHM.Size = new System.Drawing.Size(100, 23);
this.B_TMHM.TabIndex = 0;
this.B_TMHM.Text = "TM/HM Editor";
this.B_TMHM.UseVisualStyleBackColor = true;
this.B_TMHM.Click += new System.EventHandler(this.B_TMHM_Click);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(454, 202);
this.ClientSize = new System.Drawing.Size(454, 262);
this.Controls.Add(this.GB_ExeFS);
this.Controls.Add(this.L_About);
this.Controls.Add(this.pBar1);
this.Controls.Add(this.L_Game);
this.Controls.Add(this.L_Lang);
this.Controls.Add(this.CB_Lang);
this.Controls.Add(this.GB_Tools);
this.Controls.Add(this.GB_RomFS);
this.Controls.Add(this.TB_Path);
this.Controls.Add(this.B_Open);
this.MaximumSize = new System.Drawing.Size(470, 240);
this.MinimumSize = new System.Drawing.Size(470, 240);
this.MaximumSize = new System.Drawing.Size(470, 300);
this.MinimumSize = new System.Drawing.Size(470, 300);
this.Name = "Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "pk3DS";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing);
this.GB_Tools.ResumeLayout(false);
this.GB_RomFS.ResumeLayout(false);
this.GB_ExeFS.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -303,7 +365,7 @@ private void InitializeComponent()
private System.Windows.Forms.Button B_Open;
private System.Windows.Forms.TextBox TB_Path;
private System.Windows.Forms.GroupBox GB_Tools;
private System.Windows.Forms.GroupBox GB_RomFS;
private System.Windows.Forms.Button B_Trainer;
private System.Windows.Forms.Button B_GameText;
private System.Windows.Forms.Button B_Wild;
@@ -321,6 +383,11 @@ private void InitializeComponent()
private System.Windows.Forms.Button B_Maison;
private System.Windows.Forms.Button B_EggMove;
private System.Windows.Forms.Button B_LevelUp;
private System.Windows.Forms.GroupBox GB_ExeFS;
private System.Windows.Forms.Button B_Pickup;
private System.Windows.Forms.Button B_Mart;
private System.Windows.Forms.Button B_MoveTutor;
private System.Windows.Forms.Button B_TMHM;
}
}

View File

@@ -18,23 +18,25 @@ public Main()
InitializeComponent();
CB_Lang.SelectedIndex = 2;
// restoreGARCs(true, "gametext", "storytext", "personal", "trpoke", "trdata", "evolution", "megaevo", "levelup", "eggmove", "item", "move", "maisonpkS", "maisontrS", "maisonpkN", "maisontrN");
this.AllowDrop = GB_Tools.AllowDrop = TB_Path.AllowDrop = true;
this.AllowDrop = GB_RomFS.AllowDrop = TB_Path.AllowDrop = true;
this.DragEnter += tabMain_DragEnter;
this.DragDrop += tabMain_DragDrop;
GB_Tools.DragEnter += tabMain_DragEnter;
GB_Tools.DragDrop += tabMain_DragDrop;
GB_RomFS.DragEnter += tabMain_DragEnter;
GB_RomFS.DragDrop += tabMain_DragDrop;
TB_Path.DragEnter += tabMain_DragEnter;
TB_Path.DragDrop += tabMain_DragDrop;
if (File.Exists("config.ini"))
{
string path = File.ReadAllText("config.ini");
if (path.Length > 0) openQuick(path);
if (path.Length > 0) openQuick(path);
}
}
public bool oras = false;
public string ExeFS = null;
public static bool oras = false;
public static string RomFS = null;
public static string ExeFS = null;
public volatile int threads = 0;
private static string[] allGARCs = { "gametext", "storytext", "personal", "trpoke", "trdata", "evolution", "megaevo", "levelup", "eggmove", "item", "move", "maisonpkS", "maisontrS", "maisonpkN", "maisontrN" };
private void B_Open_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
@@ -43,12 +45,54 @@ private void B_Open_Click(object sender, EventArgs e)
}
private void openQuick(string path)
{
// Check to see if the folder is romfs
FileInfo fi = new FileInfo(path);
if (fi.Name.Contains("a"))
if (!Directory.Exists(path)) return;
if (threads > 0) { Util.Alert("Please wait for all operations to finish first."); return; }
if (fi.Name.Contains("code.bin"))
{
if (fi.Length % 0x200 == 0 && (Util.Prompt(MessageBoxButtons.YesNo, "Detected Decompressed code.bin.", "Compress? File will be replaced.") == DialogResult.Yes))
new Thread(() => { threads++; new blz.BLZCoder(new string[] { "-en", path }, pBar1); threads--; Util.Alert("Compressed!"); }).Start();
else if (Util.Prompt(MessageBoxButtons.YesNo, "Detected Compressed code.bin.", "Decompress? File will be replaced.") == DialogResult.Yes)
new Thread(() => { threads++; new blz.BLZCoder(new string[] { "-d", path }, pBar1); threads--; Util.Alert("Decompressed!"); }).Start();
return;
}
else
{
// Check for ROMFS/EXEFS
string[] files = Directory.GetDirectories(path);
int count = files.Length;
if (count > 2 && count > 0) return; // Only want exefs & romfs
{
// first file should be 'exe'
if (new FileInfo(files[0]).Name.Contains("exe") && Directory.Exists(files[0]))
checkIfExeFS(files[0]);
if (new FileInfo(files[count - 1]).Name.Contains("rom") && Directory.Exists(files[count - 1]))
checkIfRomFS(files[count - 1]);
GB_RomFS.Enabled = (RomFS != null);
GB_ExeFS.Enabled = (ExeFS != null);
B_MoveTutor.Enabled = oras; // default false unless loaded
if (RomFS != null)
{ L_Game.Text = (oras) ? "Game Loaded: ORAS" : "Game Loaded: XY"; TB_Path.Text = path; }
else if (ExeFS != null)
{ L_Game.Text = "ExeFS loaded - no RomFS"; TB_Path.Text = path; }
else
{ L_Game.Text = "No Game Loaded"; TB_Path.Text = ""; }
changeLanguage(null, null); // Trigger Text Loading
System.Media.SystemSounds.Asterisk.Play();
}
}
}
private bool checkIfRomFS(string path)
{
string[] top = Directory.GetDirectories(path);
FileInfo fi = new FileInfo(top[(top.Length > 1) ? 1 : 0]);
// Check to see if the folder is romfs
if (fi.Name == "a")
{
string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
System.Media.SystemSounds.Asterisk.Play();
if (files.Length == 299) // ORAS
oras = true;
else if (files.Length == 301) // ORAS demo
@@ -57,18 +101,34 @@ private void openQuick(string path)
oras = false;
else
{
TB_Path.Text = ""; GB_Tools.Enabled = false;
L_Game.Text = "No Game Loaded";
return;
RomFS = null;
oras = false;
return false;
}
TB_Path.Text = path; GB_Tools.Enabled = true;
backupGARCs(false, "gametext", "storytext", "personal", "trpoke", "trdata", "evolution", "megaevo", "levelup", "eggmove", "item", "move", "maisonpkS", "maisontrS", "maisonpkN", "maisontrN");
L_Game.Text = (oras) ? "Game Loaded: ORAS" : "Game Loaded: XY";
string exefs = Util.getExeFSFolder(path);
changeLanguage(null, null); // Trigger Text Loading
RomFS = path;
backupGARCs(false, allGARCs);
return true;
}
RomFS = null;
oras = false;
return false;
}
private bool checkIfExeFS(string path)
{
string[] files = Directory.GetFiles(path);
if (files.Length != 3) return false;
FileInfo fi = new FileInfo(files[0]);
if (fi.Name.Contains("code.bin"))
{
if (fi.Length % 0x200 != 0 && (Util.Prompt(MessageBoxButtons.YesNo, "Detected Compressed code.bin.", "Decompress? File will be replaced.") == DialogResult.Yes))
new Thread(() => { threads++; new blz.BLZCoder(new string[] { "-d", path }, pBar1); threads--; Util.Alert("Decompressed!"); }).Start();
ExeFS = path;
return true;
}
return false;
}
private void tabMain_DragEnter(object sender, DragEventArgs e)
{
@@ -81,18 +141,18 @@ private void tabMain_DragDrop(object sender, DragEventArgs e)
openQuick(path);
}
// Subform Items
// RomFS Subform Items
private void B_GameText_Click(object sender, EventArgs e)
{
new Thread(() =>
{
string toEdit = "gametext";
string GARC = getGARCFileName(toEdit);
// threadGet(TB_Path.Text + getGARCFileName(toEdit), toEdit); // We don't need this because loading and changing language does it for us.
// threadGet(RomFS + getGARCFileName(toEdit), toEdit); // We don't need this because loading and changing language does it for us.
Invoke((Action)(() => { new xytext(Directory.GetFiles(toEdit)).ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + GARC, toEdit);
threadSet(RomFS + GARC, toEdit);
}).Start();
}
private void B_StoryText_Click(object sender, EventArgs e)
@@ -102,13 +162,13 @@ private void B_StoryText_Click(object sender, EventArgs e)
{
string toEdit = "storytext";
string GARC = getGARCFileName(toEdit);
threadGet(TB_Path.Text + GARC, toEdit, true, true);
threadGet(RomFS + GARC, toEdit, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
Invoke((Action)(() => { new xytext(Directory.GetFiles(toEdit)).ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + GARC, toEdit);
threadSet(RomFS + GARC, toEdit);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(toEdit)) Directory.Delete(toEdit, true);
@@ -125,24 +185,24 @@ private void B_Maison_Click(object sender, EventArgs e)
bool super = (dr == DialogResult.Yes);
string mtr = (super) ? "maisontrS" : "maisontrN";
string mtrGARC = getGARCFileName(mtr);
threadGet(TB_Path.Text + mtrGARC, mtr, true, true);
threadGet(RomFS + mtrGARC, mtr, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(50);
string mpk = (super) ? "maisonpkS" : "maisonpkN";
string mpkGARC = getGARCFileName(mpk);
threadGet(TB_Path.Text + mpkGARC, mpk, true, true);
threadGet(RomFS + mpkGARC, mpk, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(50);
Invoke((Action)(() => { new Maison(oras, super).ShowDialog(); }));
Invoke((Action)(() => { new Maison(super).ShowDialog(); }));
threadSet(TB_Path.Text + mtrGARC, mtr);
threadSet(RomFS + mtrGARC, mtr);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(mtr)) Directory.Delete(mtr, true);
threadSet(TB_Path.Text + mpkGARC, mpk);
threadSet(RomFS + mpkGARC, mpk);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(mpk)) Directory.Delete(mpk, true);
@@ -156,13 +216,13 @@ private void B_Personal_Click(object sender, EventArgs e)
{
string toEdit = "personal";
string GARC = getGARCFileName(toEdit);
threadGet(TB_Path.Text + GARC, toEdit, true, true);
threadGet(RomFS + GARC, toEdit, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
Invoke((Action)(() => { new Personal(oras).ShowDialog(); }));
Invoke((Action)(() => { new Personal().ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + GARC, toEdit);
threadSet(RomFS + GARC, toEdit);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(toEdit)) Directory.Delete(toEdit, true);
@@ -175,31 +235,31 @@ private void B_Trainer_Click(object sender, EventArgs e)
{
string trdata = "trdata";
string trdataGARC = getGARCFileName(trdata);
threadGet(TB_Path.Text + trdataGARC, trdata, true, true);
threadGet(RomFS + trdataGARC, trdata, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(50);
string trpoke = "trpoke";
string trpokeGARC = getGARCFileName(trpoke);
threadGet(TB_Path.Text + trpokeGARC, trpoke, true, true);
threadGet(RomFS + trpokeGARC, trpoke, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(50);
string personal = "personal";
string personalGARC = getGARCFileName(personal);
threadGet(TB_Path.Text + personalGARC, personal, true, true);
threadGet(RomFS + personalGARC, personal, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
Invoke((Action)(() => { new RSTE(oras).ShowDialog(); }));
Invoke((Action)(() => { new RSTE().ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + trdataGARC, trdata);
threadSet(RomFS + trdataGARC, trdata);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(trdata)) Directory.Delete(trdata, true);
threadSet(TB_Path.Text + trpokeGARC, trpoke);
threadSet(RomFS + trpokeGARC, trpoke);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(trpoke)) Directory.Delete(trpoke, true);
@@ -212,17 +272,17 @@ private void B_Wild_Click(object sender, EventArgs e)
{
string encdata = "encdata";
string encdataGARC = getGARCFileName(encdata);
threadGet(TB_Path.Text + encdataGARC, encdata, true, false);
threadGet(RomFS + encdataGARC, encdata, true, false);
while (threads > 0) // Let threads complete
Thread.Sleep(50);
if (oras)
{ Invoke((Action)(() => { new RSWE(oras).ShowDialog(); })); }
{ Invoke((Action)(() => { new RSWE().ShowDialog(); })); }
else
{ Invoke((Action)(() => { new XYWE(oras).ShowDialog(); })); }
{ Invoke((Action)(() => { new XYWE().ShowDialog(); })); }
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + encdataGARC, encdata);
threadSet(RomFS + encdataGARC, encdata);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(encdata)) Directory.Delete(encdata, true);
@@ -235,13 +295,13 @@ private void B_Evolution_Click(object sender, EventArgs e)
{
string toEdit = "evolution";
string GARC = getGARCFileName(toEdit);
threadGet(TB_Path.Text + GARC, toEdit, true, true);
threadGet(RomFS + GARC, toEdit, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
Invoke((Action)(() => { new Evolution(oras).ShowDialog(); }));
Invoke((Action)(() => { new Evolution().ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + GARC, toEdit);
threadSet(RomFS + GARC, toEdit);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(toEdit)) Directory.Delete(toEdit, true);
@@ -254,20 +314,20 @@ private void B_MegaEvo_Click(object sender, EventArgs e)
{
string megaevo = "megaevo";
string GARC = getGARCFileName(megaevo);
threadGet(TB_Path.Text + GARC, megaevo, true, true);
threadGet(RomFS + GARC, megaevo, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(50);
string personal = "personal";
string personalGARC = getGARCFileName(personal);
threadGet(TB_Path.Text + personalGARC, personal, true, true);
threadGet(RomFS + personalGARC, personal, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(50);
Invoke((Action)(() => { new MEE(oras).ShowDialog(); }));
Invoke((Action)(() => { new MEE().ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + GARC, megaevo);
threadSet(RomFS + GARC, megaevo);
while (threads > 0) // Let threads complete
Thread.Sleep(50);
if (Directory.Exists(megaevo)) Directory.Delete(megaevo, true);
@@ -284,14 +344,14 @@ private void B_Move_Click(object sender, EventArgs e)
{
string toEdit = "move";
string GARC = getGARCFileName(toEdit);
threadGet(TB_Path.Text + GARC, toEdit, true, true);
threadGet(RomFS + GARC, toEdit, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
Invoke((Action)(() => { new Moves(oras).ShowDialog(); }));
Invoke((Action)(() => { new Moves().ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + GARC, toEdit);
threadSet(RomFS + GARC, toEdit);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(toEdit)) Directory.Delete(toEdit, true);
@@ -304,13 +364,13 @@ private void B_LevelUp_Click(object sender, EventArgs e)
{
string toEdit = "levelup";
string GARC = getGARCFileName(toEdit);
threadGet(TB_Path.Text + GARC, toEdit, true, true);
threadGet(RomFS + GARC, toEdit, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
Invoke((Action)(() => { new LevelUp(oras).ShowDialog(); }));
Invoke((Action)(() => { new LevelUp().ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + GARC, toEdit);
threadSet(RomFS + GARC, toEdit);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(toEdit)) Directory.Delete(toEdit, true);
@@ -323,19 +383,37 @@ private void B_EggMove_Click(object sender, EventArgs e)
{
string toEdit = "eggmove";
string GARC = getGARCFileName(toEdit);
threadGet(TB_Path.Text + GARC, toEdit, true, true);
threadGet(RomFS + GARC, toEdit, true, true);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
Invoke((Action)(() => { new EggMove(oras).ShowDialog(); }));
Invoke((Action)(() => { new EggMove().ShowDialog(); }));
// When closed, create a new thread to set the GARC back.
threadSet(TB_Path.Text + GARC, toEdit);
threadSet(RomFS + GARC, toEdit);
while (threads > 0) // Let threads complete
Thread.Sleep(100);
if (Directory.Exists(toEdit)) Directory.Delete(toEdit, true);
}).Start();
}
// ExeFS Subform Items
private void B_Pickup_Click(object sender, EventArgs e)
{
Util.Alert("Not implemented yet.");
}
private void B_TMHM_Click(object sender, EventArgs e)
{
Util.Alert("Not implemented yet.");
}
private void B_Mart_Click(object sender, EventArgs e)
{
Util.Alert("Not implemented yet.");
}
private void B_MoveTutor_Click(object sender, EventArgs e)
{
Util.Alert("Not implemented yet.");
}
// GARC Requests
public bool getGARC(string infile, string outfolder, bool PB, bool bypassExt = false)
{
@@ -371,7 +449,7 @@ public void threadSet(string outfile, string infolder, bool PB = true)
Thread thread = new Thread(() => setGARC(outfile, infolder, PB));
thread.Start(); threads++;
}
public string getGARCFileName(string request)
public string getGARCFileName(string requestedGARC)
{
int lang = 0;
if (CB_Lang.InvokeRequired)
@@ -379,7 +457,7 @@ public string getGARCFileName(string request)
else lang = CB_Lang.SelectedIndex;
string ans = "";
switch (request)
switch (requestedGARC)
{
case "encdata": ans = (oras) ? getFileName(0, 1, 3) : getFileName(0, 1, 2); break;
case "gametext": ans = (oras) ? getFileName(0, 7, 1 + lang) : getFileName(0, 7, 2 + lang); break;
@@ -406,15 +484,15 @@ public void backupGARCs(bool overwrite, params string[] g)
foreach (string s in g)
{
string GARC = getGARCFileName(s);
string dest = "backup" + Path.DirectorySeparatorChar + s + String.Format(" (a{0})", GARC.Replace(Path.DirectorySeparatorChar.ToString(), ""));
string dest = "backup" + Path.DirectorySeparatorChar + s + String.Format(" ({0})", GARC.Replace(Path.DirectorySeparatorChar.ToString(), ""));
if (overwrite || !File.Exists(dest))
File.Copy(TB_Path.Text + GARC, dest);
File.Copy(RomFS + GARC, dest);
}
}
public void restoreGARCs(bool ggg, params string[] g)
public void restoreGARCs(bool oras_define, params string[] g)
{
oras = ggg;
GB_Tools.Enabled = false;
oras = oras_define;
GB_RomFS.Enabled = false;
foreach (string s in g)
{
string dest = File.ReadAllText("config.ini") + getGARCFileName(s);
@@ -438,25 +516,25 @@ public bool setText(int file, string[] strings)
private void changeLanguage(object sender, EventArgs e)
{
if (!GB_Tools.Enabled) return;
if (!GB_RomFS.Enabled) return;
// Gather the Text Language Strings
threadGet(TB_Path.Text + getGARCFileName("gametext"), "gametext", true, true);
threadGet(RomFS + getGARCFileName("gametext"), "gametext", true, true);
}
private string getFileName(int A, int B, int C)
{
return Path.DirectorySeparatorChar + A.ToString() + Path.DirectorySeparatorChar + B.ToString() + Path.DirectorySeparatorChar + C.ToString();
return Path.DirectorySeparatorChar + "a" + Path.DirectorySeparatorChar + A.ToString() + Path.DirectorySeparatorChar + B.ToString() + Path.DirectorySeparatorChar + C.ToString();
}
private void formClosing(object sender, FormClosingEventArgs e)
{
this.Hide();
if (TB_Path.Text.Length > 0) File.WriteAllText("config.ini", TB_Path.Text);
if (!GB_Tools.Enabled) return; // No data/threads need to be addressed if we haven't loaded anything.
if (!GB_RomFS.Enabled) return; // No data/threads need to be addressed if we haven't loaded anything.
// Set the GameText back as other forms may have edited it.
try
{
threadSet(TB_Path.Text + getGARCFileName("gametext"), "gametext", false);
if (Directory.Exists("personal")) threadSet(TB_Path.Text + getGARCFileName("personal"), "personal", false);
threadSet(RomFS + getGARCFileName("gametext"), "gametext", false);
if (Directory.Exists("personal")) threadSet(RomFS + getGARCFileName("personal"), "personal", false);
int timeout = 0; // Time out after 7 seconds.
while (threads > 0 && timeout++ < 70)
Thread.Sleep(100);

View File

@@ -117,4 +117,118 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="B_Open.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="TB_Path.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="GB_RomFS.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Maison.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_EggMove.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_LevelUp.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_StoryText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Item.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Move.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Evolution.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Personal.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_MegaEvo.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Wild.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Trainer.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_GameText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Maison.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_EggMove.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_LevelUp.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_StoryText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Item.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Move.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Evolution.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Personal.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_MegaEvo.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Wild.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Trainer.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_GameText.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="CB_Lang.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="L_Lang.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="L_Game.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="pBar1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="L_About.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="GB_ExeFS.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Pickup.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_Mart.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_MoveTutor.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="B_TMHM.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@@ -12,13 +12,13 @@ namespace pk3DS
{
public partial class EggMove : Form
{
public EggMove(bool oras)
public EggMove()
{
InitializeComponent();
files = Directory.GetFiles("eggmove");
movelist = Main.getText((oras) ? 14 : 13);
specieslist = Main.getText((oras) ? 98 : 80);
movelist = Main.getText((Main.oras) ? 14 : 13);
specieslist = Main.getText((Main.oras) ? 98 : 80);
specieslist[0] = movelist[0] = "";
Array.Resize(ref specieslist, 722);

View File

@@ -12,15 +12,15 @@ namespace pk3DS
{
public partial class Evolution : Form
{
public Evolution(bool oras)
public Evolution()
{
InitializeComponent();
files = Directory.GetFiles("evolution");
specieslist = Main.getText((oras) ? 98 : 80);
movelist = Main.getText((oras) ? 14 : 13);
itemlist = Main.getText((oras) ? 114 : 96);
typelist = Main.getText((oras) ? 18 : 17);
specieslist = Main.getText((Main.oras) ? 98 : 80);
movelist = Main.getText((Main.oras) ? 14 : 13);
itemlist = Main.getText((Main.oras) ? 114 : 96);
typelist = Main.getText((Main.oras) ? 18 : 17);
specieslist[0] = movelist[0] = itemlist[0] = "";
Array.Resize(ref specieslist, 722);

View File

@@ -12,13 +12,13 @@ namespace pk3DS
{
public partial class LevelUp : Form
{
public LevelUp(bool oras)
public LevelUp()
{
InitializeComponent();
files = Directory.GetFiles("levelup");
movelist = Main.getText((oras) ? 14 : 13);
specieslist = Main.getText((oras) ? 98 : 80);
movelist = Main.getText((Main.oras) ? 14 : 13);
specieslist = Main.getText((Main.oras) ? 98 : 80);
specieslist[0] = movelist[0] = "";
Array.Resize(ref specieslist, 722);

View File

@@ -18,7 +18,6 @@ public partial class MEE : Form
private string[] types;
string[] specieslist;
string[] itemlist;
bool oras = false;
byte[] personalData;
private GroupBox[] groupbox_spec = { };
private ComboBox[] forme_spec = { };
@@ -31,24 +30,23 @@ public partial class MEE : Form
private string[][] AltForms;
int entry = -1;
public MEE(bool rom_oras) //All the initial settings
public MEE() //All the initial settings
{
oras = rom_oras;
InitializeComponent();
CB_Species.DisplayMember = "Text";
CB_Species.ValueMember = "Value";
#region Intializations
forms = Main.getText((oras) ? 5 : 5);
itemlist = Main.getText((oras) ? 114 : 96);
specieslist = Main.getText((oras) ? 98 : 80);
forms = Main.getText((Main.oras) ? 5 : 5);
itemlist = Main.getText((Main.oras) ? 114 : 96);
specieslist = Main.getText((Main.oras) ? 98 : 80);
Array.Resize(ref specieslist, 722); specieslist[0] = itemlist[0] = "";
specieslist[32] += "♂"; specieslist[29] += "♀";
types = Main.getText((oras) ? 18 : 17);
types = Main.getText((Main.oras) ? 18 : 17);
files = Directory.GetFiles("megaevo");
string[] personalList = Directory.GetFiles("personal");
personalData = File.ReadAllBytes(personalList[personalList.Length - 1]);
AltForms = Personal.getFormList(personalData, oras, specieslist, forms, types, itemlist);
AltForms = Personal.getFormList(personalData, Main.oras, specieslist, forms, types, itemlist);
groupbox_spec = new GroupBox[] {GB_MEvo1,GB_MEvo2,GB_MEvo3};
item_spec = new ComboBox[] { CB_Item1, CB_Item2, CB_Item3 };
@@ -124,7 +122,7 @@ private void getEntry()
{
if (loaded)
{
if (oras && entry == 384 && !dumping) // Current Mon is Rayquaza
if (Main.oras && entry == 384 && !dumping) // Current Mon is Rayquaza
Util.Alert("Rayquaza is special and uses a different activator for its evolution. If it knows Dragon Ascent, it can Mega Evolve", "Don't edit its evolution table if you want to keep this functionality.");
byte[] data = File.ReadAllBytes(files[entry]);

View File

@@ -12,22 +12,20 @@ namespace pk3DS
{
public partial class Maison : Form
{
public Maison(bool rom_oras, bool super)
public Maison(bool super)
{
oras = rom_oras;
movelist = Main.getText((oras) ? 14 : 13);
itemlist = Main.getText((oras) ? 114 : 96);
specieslist = Main.getText((oras) ? 98 : 80); Array.Resize(ref specieslist, 722);
movelist = Main.getText((Main.oras) ? 14 : 13);
itemlist = Main.getText((Main.oras) ? 114 : 96);
specieslist = Main.getText((Main.oras) ? 98 : 80); Array.Resize(ref specieslist, 722);
movelist[0] = specieslist[0] = itemlist[0] = "";
trClass = Main.getText((oras) ? 21 : 20);
natures = Main.getText((oras) ? 51 : 47);
trClass = Main.getText((Main.oras) ? 21 : 20);
natures = Main.getText((Main.oras) ? 51 : 47);
trFiles = Directory.GetFiles((super) ? "maisontrS" : "maisontrN");
pkFiles = Directory.GetFiles((super) ? "maisonpkS" : "maisonpkN");
int trTXTFile = (oras) ? 153 : 130;
int trTXTFile = (Main.oras) ? 153 : 130;
trNames = Main.getText((super) ? trTXTFile : trTXTFile + 1); Array.Resize(ref trNames, trFiles.Length);
InitializeComponent();
@@ -36,7 +34,6 @@ public Maison(bool rom_oras, bool super)
string[] trFiles;
string[] trNames;
string[] pkFiles;
bool oras = false;
string[] natures;
string[] movelist;
string[] specieslist;

View File

@@ -12,23 +12,21 @@ namespace pk3DS
{
public partial class Moves : Form
{
public Moves(bool rom_oras)
public Moves()
{
oras = rom_oras;
Util.unpackMini(Directory.GetFiles("move")[0], "WD");
files = Directory.GetFiles("move");
movelist = Main.getText((oras) ? 14 : 13);
moveflavor = Main.getText((oras) ? 16 : 15);
movelist = Main.getText((Main.oras) ? 14 : 13);
moveflavor = Main.getText((Main.oras) ? 16 : 15);
movelist[0] = "";
types = Main.getText((oras) ? 18 : 17);
types = Main.getText((Main.oras) ? 18 : 17);
sortedmoves = (string[])movelist.Clone();
Array.Sort(sortedmoves);
InitializeComponent();
Setup();
}
bool oras;
string[] types;
string[] moveflavor;
string[] movelist;

View File

@@ -12,10 +12,9 @@ namespace pk3DS
{
public partial class Personal : Form
{
public Personal(bool rom_oras)
public Personal()
{
oras = rom_oras;
entrysize = (oras) ? 0x50 : 0x40;
entrysize = (Main.oras) ? 0x50 : 0x40;
InitializeComponent();
helditem_boxes = new ComboBox[] { CB_HeldItem1, CB_HeldItem2, CB_HeldItem3 };
ability_boxes = new ComboBox[] { CB_Ability1, CB_Ability2, CB_Ability3 };
@@ -25,14 +24,13 @@ public Personal(bool rom_oras)
ev_boxes = new MaskedTextBox[] { TB_HPEVs, TB_ATKEVs, TB_DEFEVs, TB_SPEEVs, TB_SPAEVs, TB_SPDEVs };
paths = Directory.GetFiles("personal", "*.*", SearchOption.TopDirectoryOnly);
mode = (oras) ? "ORAS" : "XY";
mode = (Main.oras) ? "ORAS" : "XY";
data = File.ReadAllBytes(paths[paths.Length - 1]); // Load last to data.
L_Mode.Text = "Mode: " + mode;
Setup(); //Turn string resources into arrays
CB_Species.SelectedIndex = 1;
}
#region Global Variables
bool oras = false;
private string[] paths = { };
private string mode = "";
@@ -78,17 +76,17 @@ public Personal(bool rom_oras)
#endregion
private void Setup()
{
abilities = Main.getText((oras) ? 37 : 34);
moves = Main.getText((oras) ? 14 : 13);
items = Main.getText((oras) ? 114 : 96);
species = Main.getText((oras) ? 98 : 80);
natures = Main.getText((oras) ? 51 : 47);
types = Main.getText((oras) ? 18 : 17);
forms = Main.getText((oras) ? 5 : 5);
abilities = Main.getText((Main.oras) ? 37 : 34);
moves = Main.getText((Main.oras) ? 14 : 13);
items = Main.getText((Main.oras) ? 114 : 96);
species = Main.getText((Main.oras) ? 98 : 80);
natures = Main.getText((Main.oras) ? 51 : 47);
types = Main.getText((Main.oras) ? 18 : 17);
forms = Main.getText((Main.oras) ? 5 : 5);
species[0] = "---";
abilities[0] = items[0] = moves[0] = "";
AltForms = Personal.getFormList(data, oras, species, forms, types, items);
species = getPersonalEntryList(data, oras, AltForms, species);
AltForms = Personal.getFormList(data, Main.oras, species, forms, types, items);
species = getPersonalEntryList(data, Main.oras, AltForms, species);
for (int i = 1; i <= 100; i++)
CLB_TMHM.Items.Add("TM" + i.ToString("00"));
for (int i = 1; i <= 7; i++)
@@ -270,7 +268,7 @@ private void readEntry()
}
if (!dumping)
{
int[] specForm = Personal.getSpecies(data, oras, CB_Species.SelectedIndex);
int[] specForm = Personal.getSpecies(data, Main.oras, CB_Species.SelectedIndex);
string filename = "_" + specForm[0] + ((CB_Species.SelectedIndex > 721) ? "_" + (specForm[1] + 1) : "");
Bitmap rawImg = (Bitmap)Properties.Resources.ResourceManager.GetObject(filename);
Bitmap bigImg = new Bitmap(rawImg.Width * 2, rawImg.Height * 2);
@@ -412,7 +410,7 @@ private void B_Difficulty_Click(object sender, EventArgs e)
private void B_Randomize_Click(object sender, EventArgs e)
{
Random rnd = new Random();
ushort[] itemlist = (oras) ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY;
ushort[] itemlist = (Main.oras) ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY;
ushort[] berrylist = Legal.Pouch_Berry_XY;
Array.Resize(ref itemlist, itemlist.Length + berrylist.Length);
Array.Copy(berrylist, 0, itemlist, itemlist.Length - berrylist.Length, berrylist.Length);

View File

@@ -12,20 +12,19 @@ namespace pk3DS
{
public partial class RSTE : Form
{
public RSTE(bool rom_oras)
public RSTE()
{
oras = rom_oras;
trdatapaths = Directory.GetFiles("trdata");
trpokepaths = Directory.GetFiles("trpoke");
abilitylist = Main.getText((oras) ? 37 : 34);
movelist = Main.getText((oras) ? 14 : 13);
itemlist = Main.getText((oras) ? 114 : 96);
specieslist = Main.getText((oras) ? 98 : 80);
abilitylist = Main.getText((Main.oras) ? 37 : 34);
movelist = Main.getText((Main.oras) ? 14 : 13);
itemlist = Main.getText((Main.oras) ? 114 : 96);
specieslist = Main.getText((Main.oras) ? 98 : 80);
Array.Resize(ref specieslist, 722);
types = Main.getText((oras) ? 18 : 17);
forms = Main.getText((oras) ? 5 : 5);
trName = Main.getText((oras) ? 22 : 21);
trClass = Main.getText((oras) ? 21 : 20);
types = Main.getText((Main.oras) ? 18 : 17);
forms = Main.getText((Main.oras) ? 5 : 5);
trName = Main.getText((Main.oras) ? 22 : 21);
trClass = Main.getText((Main.oras) ? 21 : 20);
InitializeComponent();
// String Fetching
#region Combo Box Arrays
@@ -137,7 +136,6 @@ internal static uint rnd32()
{
return (uint)(rand.Next(1 << 30)) << 2 | (uint)(rand.Next(1 << 2));
}
bool oras = false;
bool start = true;
bool loading = true;
byte[][] personal;
@@ -180,7 +178,7 @@ private void refreshPKMSlotAbility(int slot)
species = (indexList[species] > 0) ? indexList[species] + formnum - 1 : species;
byte[] abilities = new byte[3];
Array.Copy(personalData, ((oras) ? 0x50 : 0x40) * species + 0x18, abilities, 0, 3);
Array.Copy(personalData, ((Main.oras) ? 0x50 : 0x40) * species + 0x18, abilities, 0, 3);
trpk_abil[slot].Items.Clear();
trpk_abil[slot].Items.Add("Any (1 or 2)");
trpk_abil[slot].Items.Add(abilitylist[abilities[0]] + " (1)");
@@ -318,9 +316,9 @@ private void readFile()
// load trainer data
tabControl1.Enabled = true;
{
format = (oras) ? br.ReadUInt16() : br.ReadByte();
CB_Trainer_Class.SelectedIndex = (oras) ? br.ReadUInt16() : br.ReadByte();
if (oras) br.ReadUInt16();
format = (Main.oras) ? br.ReadUInt16() : br.ReadByte();
CB_Trainer_Class.SelectedIndex = (Main.oras) ? br.ReadUInt16() : br.ReadByte();
if (Main.oras) br.ReadUInt16();
checkBox_Item.Checked = ((format >> 1) & 1) == 1;
checkBox_Moves.Checked = ((format) & 1) == 1;
@@ -384,7 +382,7 @@ private void writeFile()
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter bw = new BinaryWriter(ms))
{
if (oras)
if (Main.oras)
{ bw.Write((ushort)format); bw.Write((ushort)CB_Trainer_Class.SelectedIndex); bw.Write((ushort)0); }
else
{ bw.Write((byte)format); bw.Write((byte)CB_Trainer_Class.SelectedIndex); }
@@ -441,11 +439,11 @@ private void Setup()
start = true;
string[] personalList = Directory.GetFiles("personal");
personalData = File.ReadAllBytes(personalList[personalList.Length - 1]);
indexList = Personal.getPersonalIndexList(personalData, oras);
indexList = Personal.getPersonalIndexList(personalData, Main.oras);
personal = new byte[personalList.Length][];
for (int i = 0; i < personalList.Length; i++)
personal[i] = File.ReadAllBytes("personal" + Path.DirectorySeparatorChar + i.ToString("000") + ".bin");
AltForms = Personal.getFormList(personalData, oras, specieslist, forms, types, itemlist);
AltForms = Personal.getFormList(personalData, Main.oras, specieslist, forms, types, itemlist);
Array.Resize(ref trName, trdatapaths.Length);
CB_TrainerID.Items.Clear();
@@ -561,9 +559,9 @@ private void Randomize()
ushort[] items;
uint rand = rnd32() % 10;
if (rand < 2) // held item
items = (oras) ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY;
items = (Main.oras) ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY;
else if (rand < 5) // medicine
items = (oras) ? Legal.Pouch_Medicine_ORAS : Legal.Pouch_Medicine_XY;
items = (Main.oras) ? Legal.Pouch_Medicine_ORAS : Legal.Pouch_Medicine_XY;
else // berry
items = Legal.Pouch_Berry_XY;
CB_Prize.SelectedIndex = items[(rnd32() % items.Length)];
@@ -572,7 +570,7 @@ private void Randomize()
else if (rGift)
CB_Prize.SelectedIndex = 0;
ushort[] itemlist = (oras) ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY;
ushort[] itemlist = (Main.oras) ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY;
itemlist = itemlist.Concat(Legal.Pouch_Berry_XY).ToArray();
int moves = trpk_m1[0].Items.Count;
int itemC = itemlist.Length;

View File

@@ -14,12 +14,10 @@ namespace pk3DS
{
public partial class RSWE : Form
{
private bool oras;
public RSWE(bool rom_oras)
public RSWE()
{
InitializeComponent();
Console.WriteLine("Started RSWE");
oras = rom_oras;
spec = new ComboBox[]
{
CB_Grass1, CB_Grass2, CB_Grass3, CB_Grass4, CB_Grass5, CB_Grass6, CB_Grass7, CB_Grass8, CB_Grass9, CB_Grass10, CB_Grass11, CB_Grass12,
@@ -288,7 +286,7 @@ public RSWE(bool rom_oras)
private void RSWE_Load(object sender, EventArgs e)
{
specieslist = Main.getText((oras) ? 98 : 80);
specieslist = Main.getText((Main.oras) ? 98 : 80);
specieslist[0] = "---";
foreach (string s in formlist)
@@ -318,7 +316,7 @@ private void openQuick(string[] encdata)
Array.Sort(encdatapaths);
this.filepaths = new string[this.encdatapaths.Length - 2];
Array.Copy(this.encdatapaths, 2, this.filepaths, 0, this.filepaths.Length);
metRS_00000 = Main.getText((oras) ? 90 : 72);
metRS_00000 = Main.getText((Main.oras) ? 90 : 72);
zonedata = File.ReadAllBytes(encdatapaths[0]);
decStorage = File.ReadAllBytes(encdatapaths[1]);
LocationNames = new string[this.filepaths.Length];

View File

@@ -14,11 +14,9 @@ namespace pk3DS
{
public partial class XYWE : Form
{
private bool oras = false;
public XYWE(bool rom_oras)
public XYWE()
{
InitializeComponent();
oras = rom_oras;
InitializeComponent();
spec = new ComboBox[]
{
CB_Grass1, CB_Grass2, CB_Grass3, CB_Grass4, CB_Grass5, CB_Grass6, CB_Grass7, CB_Grass8, CB_Grass9, CB_Grass10, CB_Grass11, CB_Grass12,
@@ -292,7 +290,7 @@ public XYWE(bool rom_oras)
private void Load_XYWE(object sender, EventArgs e)
{
specieslist = Main.getText((oras) ? 98 : 80);
specieslist = Main.getText((Main.oras) ? 98 : 80);
specieslist[0] = "---";
CB_FormeList.Items.AddRange(formlist);
@@ -313,7 +311,7 @@ private void openQuick(string[] encdata)
Array.Sort(encdatapaths);
this.filepaths = new string[this.encdatapaths.Length - 1];
Array.Copy(this.encdatapaths, 1, this.filepaths, 0, this.filepaths.Length);
metXY_00000 = Main.getText((oras) ? 90 : 72);
metXY_00000 = Main.getText((Main.oras) ? 90 : 72);
zonedata = File.ReadAllBytes(encdatapaths[0]);
LocationNames = new string[this.filepaths.Length];
for (int f = 0; f < filepaths.Length; f++)

View File

@@ -50,6 +50,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BLZ.cs" />
<Compile Include="Subforms\Maison.cs">
<SubType>Form</SubType>
</Compile>