2014-06-28 21:22:05 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Drawing ;
using System.IO ;
2015-02-13 04:26:23 +00:00
using System.Linq ;
2014-06-28 21:22:05 +00:00
using System.Security.Cryptography ;
2015-02-13 04:26:23 +00:00
using System.Text ;
using System.Threading ;
using System.Windows.Forms ;
2014-06-28 21:22:05 +00:00
namespace PKHeX
{
public partial class Form1 : Form
{
public Form1 ( )
{
#region Pop open a splash screen while we load up .
Thread SplashSCR = new Thread ( ( ) = > new SplashScreen ( this ) . ShowDialog ( ) ) ;
SplashSCR . Start ( ) ;
#endregion
#region Initialize Form
InitializeComponent ( ) ;
2014-12-20 04:22:15 +00:00
defaultControlWhite = CB_Species . BackColor ;
defaultControlText = Label_Species . ForeColor ;
2014-06-28 21:22:05 +00:00
CB_ExtraBytes . SelectedIndex = 0 ;
2015-01-01 19:38:37 +00:00
2014-06-28 21:22:05 +00:00
// Resize Main Window to PKX Editing Mode
2015-03-11 01:44:51 +00:00
largeWidth = Width ;
2014-07-31 22:06:48 +00:00
shortWidth = ( Width * ( 30500 / 620 ) ) / 100 + 1 ;
2014-07-29 22:33:22 +00:00
Width = shortWidth ;
2015-01-25 01:57:42 +00:00
// Initialize Boxes
byte [ ] ezeros = PKX . encryptArray ( new byte [ 232 ] ) ;
for ( int i = 0 ; i < 30 * 31 ; i + + )
Array . Copy ( ezeros , 0 , savefile , SaveGame . Box + i * 0xE8 , 0xE8 ) ;
2014-06-28 21:22:05 +00:00
#endregion
#region Language Detection before loading
// Set up Language Selection
2014-12-14 18:31:53 +00:00
foreach ( var cbItem in main_langlist )
CB_MainLanguage . Items . Add ( cbItem ) ;
2014-06-28 21:22:05 +00:00
// Try and detect the language
2015-04-05 17:48:18 +00:00
int [ ] main_langnum = { 1 , 2 , 3 , 4 , 5 , 7 , 8 , 9 } ;
2015-03-12 05:51:56 +00:00
main_langnum = main_langnum . Concat ( Enumerable . Range ( 10 , lang_val . Length ) . Select ( i = > i ) . ToArray ( ) ) . ToArray ( ) ;
2014-06-28 21:22:05 +00:00
string filename = Path . GetFileNameWithoutExtension ( System . Diagnostics . Process . GetCurrentProcess ( ) . MainModule . FileName ) ;
string lastTwoChars = filename . Substring ( filename . Length - 2 ) ;
2015-04-05 17:48:18 +00:00
int lang = Array . IndexOf ( lang_val , lastTwoChars ) ;
2015-03-12 05:51:56 +00:00
CB_MainLanguage . SelectedIndex = lang > = 0 ? main_langnum [ lang ] - 1 : ( ( lastTwoChars = = "jp" ) ? 1 : 0 ) ;
2014-08-17 01:42:51 +00:00
2014-08-15 22:28:33 +00:00
#region HaX
2015-03-11 01:44:51 +00:00
HaX = ( filename . IndexOf ( "HaX" , StringComparison . Ordinal ) > = 0 ) ;
2014-08-15 04:27:53 +00:00
{
CHK_HackedStats . Enabled = CHK_HackedStats . Visible =
DEV_Ability . Enabled = DEV_Ability . Visible =
MT_Level . Enabled = MT_Level . Visible =
TB_AbilityNumber . Visible =
2015-01-01 19:38:37 +00:00
MT_Form . Enabled = MT_Form . Visible = HaX ;
2014-06-28 21:22:05 +00:00
2014-08-15 04:27:53 +00:00
TB_Level . Visible =
2015-01-01 19:38:37 +00:00
CB_Ability . Visible = ! HaX ;
2014-08-15 04:27:53 +00:00
}
2014-08-15 22:28:33 +00:00
#endregion
2015-01-31 18:36:06 +00:00
Status = "Language set up" ;
2014-06-28 21:22:05 +00:00
#endregion
#region Localize & Populate
2015-01-31 18:36:06 +00:00
InitializeFields ( ) ; Status = "Fields set up" ;
2015-03-12 05:51:56 +00:00
CB_Language . SelectedIndex = ( lang > = 0 & & lang < 7 ) ? main_langnum [ lang ] : 1 ;
2014-06-28 21:22:05 +00:00
#endregion
2014-11-05 06:55:44 +00:00
#region Add ContextMenus to the PictureBoxes ( PKX slots )
2015-01-01 19:38:37 +00:00
2014-06-28 21:22:05 +00:00
ContextMenuStrip mnu = new ContextMenuStrip ( ) ;
2014-11-05 06:55:44 +00:00
ToolStripMenuItem mnuView = new ToolStripMenuItem ( "View" ) ;
2014-06-28 21:22:05 +00:00
ToolStripMenuItem mnuSet = new ToolStripMenuItem ( "Set" ) ;
ToolStripMenuItem mnuDelete = new ToolStripMenuItem ( "Delete" ) ;
2014-12-13 22:48:34 +00:00
// Assign event handlers
2015-01-02 02:05:47 +00:00
mnuView . Click + = clickView ;
mnuSet . Click + = clickSet ;
mnuDelete . Click + = clickDelete ;
2014-12-13 22:48:34 +00:00
// Add to main context menu
2014-06-28 21:22:05 +00:00
mnu . Items . AddRange ( new ToolStripItem [ ] { mnuView , mnuSet , mnuDelete } ) ;
2014-12-13 22:48:34 +00:00
// Assign to datagridview for Box Pokemon and Party Pokemon
foreach ( PictureBox pb in PAN_Box . Controls )
pb . ContextMenuStrip = mnu ;
foreach ( PictureBox pb in PAN_Party . Controls )
pb . ContextMenuStrip = mnu ;
2014-08-17 01:42:51 +00:00
2014-06-28 21:22:05 +00:00
// Add ContextMenus to the PictureBoxes that are read only
PictureBox [ ] pba2 = {
bbpkx1 , bbpkx2 , bbpkx3 , bbpkx4 , bbpkx5 , bbpkx6 ,
2015-03-11 01:44:51 +00:00
dcpkx1 , dcpkx2 , gtspkx , fusedpkx , subepkx1 , subepkx2 , subepkx3
2014-06-28 21:22:05 +00:00
} ;
ContextMenuStrip mnu2 = new ContextMenuStrip ( ) ;
ToolStripMenuItem mnu2View = new ToolStripMenuItem ( "View" ) ;
2014-12-13 22:48:34 +00:00
// Assign event handlers
2015-03-11 01:44:51 +00:00
mnu2View . Click + = clickView ;
2014-12-13 22:48:34 +00:00
// Add to main context menu
2014-06-28 21:22:05 +00:00
mnu2 . Items . AddRange ( new ToolStripItem [ ] { mnu2View } ) ;
2014-12-13 22:48:34 +00:00
// Assign to datagridview
2015-03-11 01:44:51 +00:00
foreach ( PictureBox p in pba2 )
p . ContextMenuStrip = mnu2 ;
2014-06-28 21:22:05 +00:00
#endregion
#region Enable Drag and Drop on the form & tab control .
2015-03-11 01:44:51 +00:00
AllowDrop = true ;
DragEnter + = tabMain_DragEnter ;
DragDrop + = tabMain_DragDrop ;
2014-06-28 21:22:05 +00:00
// Enable Drag and Drop on each tab.
2014-12-14 18:31:53 +00:00
tabMain . AllowDrop = true ;
2015-03-11 01:44:51 +00:00
tabMain . DragEnter + = tabMain_DragEnter ;
tabMain . DragDrop + = tabMain_DragDrop ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
foreach ( TabPage tab in tabMain . Controls )
2014-06-28 21:22:05 +00:00
{
2014-12-14 18:31:53 +00:00
tab . AllowDrop = true ;
2014-12-13 22:48:34 +00:00
tab . DragEnter + = tabMain_DragEnter ;
tab . DragDrop + = tabMain_DragDrop ;
}
2014-06-28 21:22:05 +00:00
// ToolTips for Drag&Drop
ToolTip dragoutTip1 = new ToolTip ( ) ;
dragoutTip1 . SetToolTip ( dragout , "PK6 QuickSave" ) ;
2014-11-26 04:43:02 +00:00
// Box Drag & Drop
2014-12-13 22:48:34 +00:00
foreach ( PictureBox pb in PAN_Box . Controls )
pb . AllowDrop = true ;
2014-11-26 04:43:02 +00:00
2014-12-14 20:15:53 +00:00
// Box to Tabs D&D
dragout . AllowDrop = true ;
2014-06-28 21:22:05 +00:00
#endregion
#region Finish Up
2014-11-28 03:26:42 +00:00
// Load the arguments
2015-01-31 18:36:06 +00:00
Status = "Checking load args." ;
2014-08-31 20:32:04 +00:00
string [ ] args = Environment . GetCommandLineArgs ( ) ;
2015-01-27 06:05:04 +00:00
pathSDF = Util . GetSDFLocation ( ) ;
2015-01-31 23:59:23 +00:00
path3DS = Util . get3DSLocation ( ) ;
2014-08-31 20:32:04 +00:00
if ( args . Length > 1 )
2014-11-28 03:26:42 +00:00
openQuick ( args [ 1 ] ) ;
2015-09-05 01:50:14 +00:00
else if ( path3DS ! = null & & File . Exists ( Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" , "main" ) ) )
openQuick ( Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" , "main" ) ) ;
2015-01-27 06:05:04 +00:00
else if ( pathSDF ! = null )
openQuick ( Path . Combine ( pathSDF , "main" ) ) ;
2015-01-01 19:38:37 +00:00
else if ( File . Exists ( Util . NormalizePath ( Path . Combine ( Util . GetTempFolder ( ) , "root" + Path . DirectorySeparatorChar + "main" ) ) ) )
openQuick ( Util . NormalizePath ( Path . Combine ( Util . GetTempFolder ( ) , "root" + Path . DirectorySeparatorChar + "main" ) ) ) ;
2014-08-31 20:32:04 +00:00
2014-12-20 19:27:29 +00:00
GB_OT . Click + = clickGT ;
GB_nOT . Click + = clickGT ;
2014-12-28 21:56:59 +00:00
GB_Daycare . Click + = switchDaycare ;
2015-06-28 21:34:38 +00:00
GB_RelearnMoves . Click + = clickMoves ;
2015-01-31 06:37:38 +00:00
2015-01-31 18:36:06 +00:00
Status = "Setting game font." ;
2015-01-31 06:37:38 +00:00
TB_Nickname . Font = PKX . getPKXFont ( 11 ) ;
TB_OT . Font = ( Font ) TB_Nickname . Font . Clone ( ) ;
TB_OTt2 . Font = ( Font ) TB_Nickname . Font . Clone ( ) ;
2015-01-31 18:36:06 +00:00
Status = "Initialized!" ;
2015-03-12 05:51:56 +00:00
CB_Species . SelectedIndex = 1 ;
2015-01-31 06:37:38 +00:00
2015-01-01 19:38:37 +00:00
init = true ;
2015-02-28 03:03:36 +00:00
// Splash Screen closes on its own.
2015-03-11 01:44:51 +00:00
BringToFront ( ) ;
WindowState = FormWindowState . Minimized ;
Show ( ) ;
WindowState = FormWindowState . Normal ;
2015-02-28 03:03:36 +00:00
if ( HaX ) Util . Alert ( "Illegal mode activated." , "Please behave." ) ;
2014-06-28 21:22:05 +00:00
#endregion
}
#region Global Variables : Always Visible !
2015-01-03 01:07:29 +00:00
public byte [ ] buff = new byte [ 260 ] ; // Tab Pokemon Data Storage
2014-12-12 05:44:05 +00:00
public byte [ ] savefile = new byte [ 0x100000 ] ;
public byte [ ] cyberSAV = new byte [ 0x65600 ] ;
2015-03-11 01:44:51 +00:00
public static byte [ ] ramsav ;
public static bool ramsavloaded ;
2015-01-25 01:57:42 +00:00
public bool savegame_oras = true ;
2015-03-11 01:44:51 +00:00
public bool cybergadget ;
public bool savLoaded ;
2014-06-28 21:22:05 +00:00
public int savindex ;
public bool savedited ;
2015-03-11 01:44:51 +00:00
public string pathSDF ;
public string path3DS ;
2015-02-01 04:40:35 +00:00
2015-01-31 18:36:06 +00:00
public static string Status = "Starting up PKHeX..." ;
2015-03-11 01:44:51 +00:00
public static bool HaX ;
public static bool specialChars ; // Open Form Tracking
2014-12-20 04:22:15 +00:00
public static Color defaultControlWhite ;
public static Color defaultControlText ;
2014-10-10 02:59:57 +00:00
public static int colorizedbox = 32 ;
2014-12-20 19:27:29 +00:00
public static Image mixedHighlight = Util . LayerImage ( Properties . Resources . slotSet , Properties . Resources . slotView , 0 , 0 , 0.5 ) ;
2015-03-11 01:44:51 +00:00
public static Image colorizedcolor ;
public static int colorizedslot ;
public static int largeWidth , shortWidth ;
2014-10-10 02:59:57 +00:00
public static string eggname = "" ;
2015-03-12 05:51:56 +00:00
public static string [ ] lang_val = { "en" , "ja" , "fr" , "it" , "de" , "es" , "ko" , "zh" , "pt" } ;
public static string [ ] main_langlist =
{
"English" , // ENG
"日本語" , // JPN
"Français" , // FRE
"Italiano" , // ITA
"Deutsch" , // GER
"Español" , // SPA
"한국어" , // KOR
"中文" , // CHN
"Português" , // Portuguese
} ;
2014-12-04 01:26:12 +00:00
public static string [ ] gendersymbols = { "♂" , "♀" , "-" } ;
2014-10-10 02:59:57 +00:00
public static string [ ] specieslist = { } ;
public static string [ ] movelist = { } ;
public static string [ ] itemlist = { } ;
public static string [ ] abilitylist = { } ;
public static string [ ] types = { } ;
public static string [ ] natures = { } ;
public static string [ ] characteristics = { } ;
public static string [ ] memories = { } ;
public static string [ ] genloc = { } ;
public static string [ ] forms = { } ;
public static string [ ] metHGSS_00000 = { } ;
public static string [ ] metHGSS_02000 = { } ;
public static string [ ] metHGSS_03000 = { } ;
public static string [ ] metBW2_00000 = { } ;
public static string [ ] metBW2_30000 = { } ;
public static string [ ] metBW2_40000 = { } ;
public static string [ ] metBW2_60000 = { } ;
public static string [ ] metXY_00000 = { } ;
public static string [ ] metXY_30000 = { } ;
public static string [ ] metXY_40000 = { } ;
public static string [ ] metXY_60000 = { } ;
public static string [ ] trainingbags = { } ;
public static string [ ] trainingstage = { } ;
public static string [ ] wallpapernames = { } ;
2014-12-14 07:18:27 +00:00
public static string [ ] encountertypelist = { } ;
2014-12-26 18:46:18 +00:00
public static string [ ] gamelanguages = { } ;
public static string [ ] consoleregions = { } ;
public static string [ ] balllist = { } ;
2014-12-14 07:18:27 +00:00
public static string [ ] gamelist = { } ;
2014-10-10 02:59:57 +00:00
public static string [ ] puffs = { } ;
public static string [ ] itempouch = { } ;
public static string origintrack ;
2015-03-12 05:51:56 +00:00
public static string curlanguage = "en" ;
2015-03-11 01:44:51 +00:00
public volatile bool init ;
public static bool unicode ;
2014-06-28 21:22:05 +00:00
public ToolTip Tip1 = new ToolTip ( ) ;
public ToolTip Tip2 = new ToolTip ( ) ;
public ToolTip Tip3 = new ToolTip ( ) ;
2015-02-21 20:59:22 +00:00
public ToolTip NatureTip = new ToolTip ( ) ;
2015-01-25 01:57:42 +00:00
public PKX . Structures . SaveGame SaveGame = new PKX . Structures . SaveGame ( "ORAS" ) ;
2014-06-28 21:22:05 +00:00
#endregion
2014-12-13 22:48:34 +00:00
#region //// MAIN MENU FUNCTIONS ////
// Main Menu Strip UI Functions
2014-12-14 07:18:27 +00:00
private void mainMenuOpen ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
string cyberpath = Util . GetTempFolder ( ) ;
2015-01-27 06:05:04 +00:00
pathSDF = Util . GetSDFLocation ( ) ;
path3DS = Util . get3DSLocation ( ) ;
2015-09-11 02:59:44 +00:00
if ( path3DS ! = null & & File . Exists ( Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" , "main" ) ) )
{
OpenPKX . InitialDirectory = Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" ) ;
OpenPKX . RestoreDirectory = true ;
OpenPKX . FilterIndex = 4 ;
}
else if ( pathSDF ! = null )
2014-06-28 21:22:05 +00:00
{
2015-01-27 06:05:04 +00:00
OpenPKX . InitialDirectory = pathSDF ;
OpenPKX . RestoreDirectory = true ;
OpenPKX . FilterIndex = 4 ;
}
else if ( path3DS ! = null )
{
2015-09-11 02:59:44 +00:00
OpenPKX . InitialDirectory = Path . GetPathRoot ( path3DS ) ;
2014-12-13 22:48:34 +00:00
OpenPKX . RestoreDirectory = true ;
OpenPKX . FilterIndex = 4 ;
}
else if ( Directory . Exists ( Path . Combine ( cyberpath , "root" ) ) )
{
OpenPKX . InitialDirectory = Path . Combine ( cyberpath , "root" ) ;
OpenPKX . RestoreDirectory = true ;
OpenPKX . FilterIndex = 4 ;
}
else if ( Directory . Exists ( cyberpath ) )
{
OpenPKX . InitialDirectory = cyberpath ;
OpenPKX . RestoreDirectory = true ;
OpenPKX . FilterIndex = 4 ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
DialogResult result = OpenPKX . ShowDialog ( ) ;
2015-03-12 04:44:12 +00:00
if ( result ! = DialogResult . OK ) return ;
string path = OpenPKX . FileName ;
openQuick ( path ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-14 07:18:27 +00:00
private void mainMenuSave ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-24 07:29:57 +00:00
if ( ! verifiedPKX ( ) ) { return ; }
2014-12-13 22:48:34 +00:00
SavePKX . FileName = TB_Nickname . Text + " - " + TB_PID . Text ;
DialogResult result = SavePKX . ShowDialog ( ) ;
2015-03-11 01:44:51 +00:00
if ( result ! = DialogResult . OK ) return ;
string path = SavePKX . FileName ;
// Injection Dummy Override
if ( path . Contains ( "pokemon.ekx" ) ) path = Path . GetDirectoryName ( path ) + Path . DirectorySeparatorChar + "pokemon.ekx" ;
string ext = Path . GetExtension ( path ) ;
2014-06-28 21:22:05 +00:00
2015-03-11 01:44:51 +00:00
if ( File . Exists ( path ) & & ! path . Contains ( "pokemon.ekx" ) )
{
// File already exists, save a .bak
byte [ ] backupfile = File . ReadAllBytes ( path ) ;
File . WriteAllBytes ( path + ".bak" , backupfile ) ;
}
2015-03-14 02:59:51 +00:00
byte [ ] pkx = preparepkx ( ) ;
2014-06-28 21:22:05 +00:00
2015-03-11 01:44:51 +00:00
if ( ( ext = = ".ekx" ) | | ( ext = = ".bin" ) | | ( ext = = ".pkx" ) | | ( ext = = ".ek6" ) | | ( ext = = ".pk6" ) )
{
if ( ( ext = = ".ekx" ) | | ( ext = = ".bin" ) | | ( ext = = ".ek6" ) ) // User Requested Encrypted File
2014-12-13 22:48:34 +00:00
pkx = PKX . encryptArray ( pkx ) ;
2015-03-11 01:44:51 +00:00
File . WriteAllBytes ( path , pkx . ToArray ( ) ) ;
}
else
{
Util . Error ( String . Format ( "Foreign File Extension: {0}" , ext ) , "Exporting as encrypted." ) ;
pkx = PKX . encryptArray ( pkx ) ;
File . WriteAllBytes ( path , pkx ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
}
2014-12-14 07:18:27 +00:00
private void mainMenuExit ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
2015-02-22 21:04:12 +00:00
if ( ModifierKeys = = ( Keys . Control | Keys . E ) ) // Hotkey Triggered
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Quit PKHeX?" ) ) return ;
2015-03-11 01:44:51 +00:00
Close ( ) ;
2014-12-13 22:48:34 +00:00
}
2014-12-14 07:18:27 +00:00
private void mainMenuAbout ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
// Open a new form with the About details.
new About ( ) . ShowDialog ( ) ;
}
2014-12-14 07:18:27 +00:00
private void mainMenuWiden ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
int newwidth ;
if ( Width < Height )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
newwidth = largeWidth ;
tabBoxMulti . SelectedIndex = 0 ;
}
else
newwidth = shortWidth ;
2014-11-15 05:08:00 +00:00
2014-12-13 22:48:34 +00:00
Width = newwidth ;
}
2014-12-14 07:18:27 +00:00
private void mainMenuCodeGen ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
// Open Code Generator
2014-12-24 07:29:57 +00:00
byte [ ] formdata = null ;
2015-03-14 02:59:51 +00:00
if ( verifiedPKX ( ) ) formdata = preparepkx ( ) ;
2015-03-11 01:44:51 +00:00
CodeGenerator CodeGen = new CodeGenerator ( this , formdata ) ;
2014-12-13 22:48:34 +00:00
CodeGen . ShowDialog ( ) ;
byte [ ] data = CodeGen . returnArray ;
2015-03-11 01:44:51 +00:00
if ( data = = null ) return ;
byte [ ] decdata = PKX . decryptArray ( data ) ;
Array . Copy ( decdata , buff , 232 ) ;
try { populateFields ( buff ) ; }
catch
2014-12-13 22:48:34 +00:00
{
2015-03-11 01:44:51 +00:00
Array . Copy ( new byte [ 232 ] , buff , 232 ) ;
populateFields ( buff ) ;
Util . Error ( "Imported code did not decrypt properly" , "Please verify that what you imported was correct." ) ;
2014-12-13 22:48:34 +00:00
}
}
2014-12-14 07:18:27 +00:00
private void mainMenuBoxReport ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
frmReport ReportForm = new frmReport ( ) ;
int offset = 0x27A00 ; if ( savegame_oras ) offset = 0x33000 + 0x5400 ;
2015-02-11 22:47:59 +00:00
ReportForm . Show ( ) ;
2014-12-13 22:48:34 +00:00
ReportForm . PopulateData ( savefile , savindex , offset ) ;
}
private void mainMenuUnicode ( object sender , EventArgs e )
{
unicode = ( gendersymbols [ 0 ] = = "♂" ) ;
if ( unicode )
{
2015-03-11 01:44:51 +00:00
gendersymbols = new [ ] { "M" , "F" , "-" } ;
2014-12-13 22:48:34 +00:00
BTN_Shinytize . Text = "*" ;
2015-02-27 05:07:18 +00:00
TB_Nickname . Font = TB_OT . Font = TB_OTt2 . Font = Label_TID . Font ;
2014-12-13 22:48:34 +00:00
}
else
{
2015-03-11 01:44:51 +00:00
gendersymbols = new [ ] { "♂" , "♀" , "-" } ;
2014-12-13 22:48:34 +00:00
BTN_Shinytize . Text = "☆" ;
2015-02-27 05:07:18 +00:00
TB_Nickname . Font = TB_OT . Font = TB_OTt2 . Font = PKX . getPKXFont ( 11 ) ;
2014-12-13 22:48:34 +00:00
}
2014-12-16 02:12:48 +00:00
// Switch active gender labels to new if they are active.
if ( PKX . getGender ( Label_Gender . Text ) < 2 )
Label_Gender . Text = gendersymbols [ PKX . getGender ( Label_Gender . Text ) ] ;
if ( PKX . getGender ( Label_OTGender . Text ) < 2 )
Label_OTGender . Text = gendersymbols [ PKX . getGender ( Label_OTGender . Text ) ] ;
if ( PKX . getGender ( Label_CTGender . Text ) < 2 )
Label_CTGender . Text = gendersymbols [ PKX . getGender ( Label_CTGender . Text ) ] ;
2014-12-13 22:48:34 +00:00
}
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Main Menu Subfunctions
private void openQuick ( string path )
{
// detect if it is a folder (load into boxes or not)
if ( Directory . Exists ( path ) )
{ loadBoxesFromDB ( path ) ; return ; }
2014-08-17 01:42:51 +00:00
2014-12-13 22:48:34 +00:00
string ext = Path . GetExtension ( path ) ;
FileInfo fi = new FileInfo ( path ) ;
if ( fi . Length > 0x10009C )
Util . Error ( "Input file is too large." , path ) ;
else
{
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
byte [ ] input ; try { input = File . ReadAllBytes ( path ) ; }
catch { Util . Error ( "File is in use by another program!" , path ) ; return ; }
try { openFile ( input , path , ext ) ; }
catch
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
try
{
byte [ ] blank = PKX . encryptArray ( new byte [ 260 ] ) ;
for ( int i = 0 ; i < 232 ; i + + )
2015-01-15 04:48:46 +00:00
blank [ i ] ^ = input [ i ] ;
2014-12-13 22:48:34 +00:00
openFile ( blank , path , ext ) ;
}
catch { openFile ( input , path , ext ) ; }
2014-06-28 21:22:05 +00:00
}
}
2014-12-13 22:48:34 +00:00
}
private void openFile ( byte [ ] input , string path , string ext )
{
#region Powersaves Read - Only Conversion
if ( input . Length = = 0x10009C ) // Resize to 1MB
{
Array . Copy ( input , 0x9C , input , 0 , 0x100000 ) ;
Array . Resize ( ref input , 0x100000 ) ;
2014-06-28 21:22:05 +00:00
}
#endregion
2015-01-01 19:38:37 +00:00
2014-12-13 22:48:34 +00:00
#region Saves
2014-12-31 06:18:41 +00:00
if ( ( input . Length = = 0x76000 ) & & BitConverter . ToUInt32 ( input , 0x75E10 ) = = 0x42454546 ) // ORAS
2014-12-13 22:48:34 +00:00
openMAIN ( input , path , "ORAS" , true ) ;
else if ( ( input . Length = = 0x65600 ) & & BitConverter . ToUInt32 ( input , 0x65410 ) = = 0x42454546 ) // XY
openMAIN ( input , path , "XY" , false ) ;
// Verify the Data Input Size is Proper
else if ( input . Length = = 0x100000 )
{
2014-12-31 06:18:41 +00:00
if ( openXOR ( input , path ) ) // Check if we can load the save via xorpad
return ; // only if a save is loaded we abort
2015-03-11 01:44:51 +00:00
if ( BitConverter . ToUInt64 ( input , 0x10 ) ! = 0 ) // encrypted save
2014-12-13 22:48:34 +00:00
{ Util . Error ( "PKHeX only edits decrypted save files." , "This save file is not decrypted." ) ; return ; }
2014-08-15 04:27:53 +00:00
2014-12-13 22:48:34 +00:00
string GameType = "XY" ; // Default Game Type to load.
if ( BitConverter . ToUInt32 ( input , 0x7B210 ) = = 0x42454546 ) GameType = "ORAS" ; // BEEF magic in checksum block
if ( ( BitConverter . ToUInt32 ( input , 0x100 ) ! = 0x41534944 ) & & ( BitConverter . ToUInt32 ( input , 0x5234 ) ! = 0x6E69616D ) )
2014-08-15 04:27:53 +00:00
{
2014-12-13 22:48:34 +00:00
DialogResult dialogResult = Util . Prompt ( MessageBoxButtons . YesNo , "Save file is not decrypted." , "Press Yes to ignore this warning and continue loading the save file." ) ;
2015-03-12 04:44:12 +00:00
if ( dialogResult ! = DialogResult . Yes ) return ;
DialogResult sdr = Util . Prompt ( MessageBoxButtons . YesNoCancel , "Press Yes to load the sav at 0x3000" , "Press No for the one at 0x82000" ) ;
if ( sdr = = DialogResult . Cancel ) return ;
savindex = ( sdr = = DialogResult . Yes ) ? 0 : 1 ;
B_SwitchSAV . Enabled = true ;
open1MB ( input , path , GameType , false ) ;
2014-08-15 04:27:53 +00:00
}
2014-12-13 22:48:34 +00:00
else if ( PKX . detectSAVIndex ( input , ref savindex ) = = 2 )
{
DialogResult dialogResult = Util . Prompt ( MessageBoxButtons . YesNo , "Hash verification failed." , "Press Yes to ignore this warning and continue loading the save file." ) ;
2015-03-12 04:44:12 +00:00
if ( dialogResult ! = DialogResult . Yes ) return ;
DialogResult sdr = Util . Prompt ( MessageBoxButtons . YesNoCancel , "Press Yes to load the sav at 0x3000" , "Press No for the one at 0x82000" ) ;
if ( sdr = = DialogResult . Cancel )
2014-12-13 22:48:34 +00:00
{
2015-03-12 04:44:12 +00:00
savindex = 0 ;
return ; // abort load
2014-12-13 22:48:34 +00:00
}
2015-03-12 04:44:12 +00:00
savindex = ( sdr = = DialogResult . Yes ) ? 0 : 1 ;
B_SwitchSAV . Enabled = true ;
open1MB ( input , path , GameType , false ) ;
2014-12-13 22:48:34 +00:00
}
else
{
B_ExportSAV . Enabled = true ;
B_SwitchSAV . Enabled = true ;
PKX . detectSAVIndex ( input , ref savindex ) ;
open1MB ( input , path , GameType , false ) ;
}
2014-08-15 04:27:53 +00:00
}
#endregion
2014-12-13 22:48:34 +00:00
#region PK6 / EK6
else if ( ( input . Length = = 260 ) | | ( input . Length = = 232 ) )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
// Check if Input is PKX
if ( ( ext = = ".pk6" ) | | ( ext = = ".ek6" ) | | ( ext = = ".pkx" ) | | ( ext = = ".ekx" ) | | ( ext = = ".bin" ) | | ( ext = = "" ) )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
// Check if Encrypted before Loading
buff = ( BitConverter . ToUInt16 ( input , 0xC8 ) = = 0 & & BitConverter . ToUInt16 ( input , 0x58 ) = = 0 ) ? input : PKX . decryptArray ( input ) ;
populateFields ( buff ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
else
2015-02-24 07:23:29 +00:00
Util . Error ( "Unable to recognize file." + Environment . NewLine + "Only valid .pk* .ek* .bin supported." , String . Format ( "File Loaded:{0}{1}" , Environment . NewLine , path ) ) ;
2014-06-28 21:22:05 +00:00
}
#endregion
2014-12-13 22:48:34 +00:00
#region PK3 / PK4 / PK5
else if ( ( input . Length = = 136 ) | | ( input . Length = = 220 ) | | ( input . Length = = 236 ) | | ( input . Length = = 100 ) | | ( input . Length = = 80 ) ) // to convert g5pkm
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
var Converter = new pk2pk ( ) ;
if ( ! PKX . verifychk ( input ) ) Util . Error ( "Invalid File (Checksum Error)" ) ;
try // to convert g5pkm
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
byte [ ] data = Converter . ConvertPKM ( input , savefile , savindex ) ;
Array . Copy ( data , buff , 232 ) ;
populateFields ( buff ) ;
}
catch
{
Array . Copy ( new byte [ 232 ] , buff , 232 ) ;
populateFields ( buff ) ;
Util . Error ( "Attempted to load previous generation PKM." , "Conversion failed." ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
}
#endregion
2014-12-31 06:18:41 +00:00
#region Trade Packets
else if ( input . Length = = 363 & & BitConverter . ToUInt16 ( input , 0x6B ) = = 0 )
{
// EAD Packet of 363 length
byte [ ] c = new byte [ 260 ] ;
Array . Copy ( input , 0x67 , c , 0 , 260 ) ;
}
else if ( input . Length = = 407 & & BitConverter . ToUInt16 ( input , 0x98 ) = = 0 )
{
// EAD Packet of 407 length
byte [ ] c = new byte [ 260 ] ;
Array . Copy ( input , 0x93 , c , 0 , 260 ) ;
}
#endregion
2015-01-24 18:45:32 +00:00
#region Box Data
2015-01-25 19:24:00 +00:00
else if ( ( input . Length = = 0xE8 * 30 | | input . Length = = 0xE8 * 30 * 31 ) & & BitConverter . ToUInt16 ( input , 4 ) = = 0 & & BitConverter . ToUInt32 ( input , 8 ) > 0 )
2015-01-27 06:05:04 +00:00
{
2015-05-07 02:30:31 +00:00
Array . Copy ( input , 0 , savefile , SaveGame . Box + 0xE8 * 30 * ( ( input . Length = = 0xE8 * 30 ) ? CB_BoxSelect . SelectedIndex : 0 ) , input . Length ) ;
2015-01-27 06:05:04 +00:00
setPKXBoxes ( ) ;
2015-02-24 07:23:29 +00:00
Width = largeWidth ;
2015-01-27 06:05:04 +00:00
Util . Alert ( "Box Binary loaded." ) ; }
2015-01-24 18:45:32 +00:00
#endregion
2015-01-25 07:03:46 +00:00
#region injectiondebug
2015-01-25 19:24:00 +00:00
else if ( input . Length = = 0x10000 )
2015-01-25 07:03:46 +00:00
{
2015-01-27 06:05:04 +00:00
int offset = - 1 ; // Seek to find data start
2015-01-25 19:24:00 +00:00
for ( int i = 0 ; i < 0x800 ; i + + )
2015-01-25 07:03:46 +00:00
{
byte [ ] data = PKX . decryptArray ( input . Skip ( i ) . Take ( 0xE8 ) . ToArray ( ) ) ;
2015-03-11 01:44:51 +00:00
if ( PKX . getCHK ( data ) ! = BitConverter . ToUInt16 ( data , 6 ) ) continue ;
offset = i ; break ;
2015-01-25 07:03:46 +00:00
}
2015-01-25 19:24:00 +00:00
if ( offset < 0 ) { Util . Alert ( path , "Unable to read the input file; not an expected injectiondebug.bin." ) ; return ; }
2015-05-07 02:30:31 +00:00
CB_BoxSelect . SelectedIndex = 0 ;
Array . Copy ( input , offset , savefile , SaveGame . Box + 0xE8 * 30 * CB_BoxSelect . SelectedIndex , 9 * 30 * 0xE8 ) ;
2015-01-27 06:05:04 +00:00
setPKXBoxes ( ) ;
2015-03-11 01:44:51 +00:00
Width = largeWidth ;
2015-01-25 07:03:46 +00:00
Util . Alert ( "Injection Binary loaded." ) ; }
#endregion
2015-01-27 06:05:04 +00:00
#region RAMSAV
2015-01-28 06:59:53 +00:00
else if ( ( /*XY*/ input . Length = = 0x70000 | | /*ORAS*/ input . Length = = 0x80000 ) & & Path . GetFileName ( path ) . Contains ( "ram" ) )
2015-01-27 06:05:04 +00:00
{
2015-01-28 06:59:53 +00:00
if ( input . Length = = 0x80000 )
// Scan for FEEB in XY location, 3DS only overwrites data if file already exists.
for ( int i = 0x60000 ; i < 0x64000 ; i + = 4 )
if ( BitConverter . ToUInt32 ( input , i ) = = 0x42454546 ) { Array . Resize ( ref input , 0x70000 ) ; break ; }
2015-01-27 06:05:04 +00:00
bool o = ( input . Length = = 0x80000 ) ;
2015-03-11 01:44:51 +00:00
try { openMAIN ( ram2sav . getMAIN ( input ) , path , ( o ) ? "ORAS" : "XY" , o , true ) ; } catch { return ; }
2015-01-27 06:41:13 +00:00
ramsav = ( byte [ ] ) input . Clone ( ) ;
2015-01-27 06:05:04 +00:00
}
#endregion
2015-02-24 07:52:32 +00:00
#region Battle Video
2015-02-25 04:10:47 +00:00
else if ( input . Length = = 0x2E60 & & BitConverter . ToUInt64 ( input , 0xE18 ) ! = 0 & & BitConverter . ToUInt16 ( input , 0xE12 ) = = 0 )
2015-02-24 07:52:32 +00:00
{
2015-05-07 02:30:31 +00:00
if ( Util . Prompt ( MessageBoxButtons . YesNo , "Load Batte Video Pokémon data to " + CB_BoxSelect . Text + "?" , "The first 24 slots will be overwritten." ) ! = DialogResult . Yes ) return ;
2015-02-24 07:52:32 +00:00
for ( int i = 0 ; i < 24 ; i + + )
2015-05-07 02:30:31 +00:00
Array . Copy ( input , 0xE18 + 260 * i + ( i / 6 ) * 8 , savefile , SaveGame . Box + i * 0xE8 + CB_BoxSelect . SelectedIndex * 30 * 0xE8 , 0xE8 ) ;
2015-02-24 07:52:32 +00:00
setPKXBoxes ( ) ;
}
#endregion
2015-04-01 00:58:23 +00:00
#region Wondercard
else if ( input . Length = = 0x108 & & ext = = ".wc6" )
new SAV_Wondercard ( this , input ) . Show ( ) ;
#endregion
2014-12-13 22:48:34 +00:00
else
2015-02-18 03:23:17 +00:00
Util . Error ( "Attempted to load an unsupported file type/size." , "File Loaded:" + Environment . NewLine + path , "File Size:" + Environment . NewLine + new FileInfo ( path ) . Length . ToString ( "X8" ) ) ;
2014-12-13 22:48:34 +00:00
}
2015-01-27 06:14:50 +00:00
private void openMAIN ( byte [ ] input , string path , string GameType , bool oras , bool ram = false )
2014-12-13 22:48:34 +00:00
{
2015-01-27 06:14:50 +00:00
ramsavloaded = ram ;
2014-12-13 22:48:34 +00:00
L_Save . Text = "SAV: " + Path . GetFileName ( path ) ;
2014-12-25 00:20:39 +00:00
SaveGame = new PKX . Structures . SaveGame ( GameType ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Load CyberGadget
2015-01-01 19:38:37 +00:00
savindex = 0 ;
savefile = new byte [ 0x100000 ] ;
cyberSAV = input ;
2014-12-13 22:48:34 +00:00
cybergadget = true ;
B_ExportSAV . Enabled = true ;
2015-01-01 19:38:37 +00:00
B_SwitchSAV . Enabled = false ;
2014-12-13 22:48:34 +00:00
Array . Copy ( input , 0 , savefile , 0x5400 , input . Length ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
openSave ( oras ) ;
}
private void open1MB ( byte [ ] input , string path , string GameType , bool oras )
{
2015-01-27 06:14:50 +00:00
ramsavloaded = false ;
2014-12-13 22:48:34 +00:00
L_Save . Text = "SAV: " + Path . GetFileName ( path ) ;
2014-12-25 00:20:39 +00:00
SaveGame = new PKX . Structures . SaveGame ( GameType ) ;
2014-12-13 22:48:34 +00:00
savegame_oras = oras ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
savefile = input ;
cybergadget = false ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Logic to allow unlocking of Switch SAV
// Setup SHA
2015-03-11 01:44:51 +00:00
SHA256 mySHA256 = SHA256 . Create ( ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Check both IVFC Hashes
byte [ ] zeroarray = new byte [ 0x200 ] ;
Array . Copy ( savefile , 0x2000 + 0 * 0x7F000 , zeroarray , 0 , 0x20 ) ;
byte [ ] hashValue1 = mySHA256 . ComputeHash ( zeroarray ) ;
Array . Copy ( savefile , 0x2000 + 1 * 0x7F000 , zeroarray , 0 , 0x20 ) ;
byte [ ] hashValue2 = mySHA256 . ComputeHash ( zeroarray ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
byte [ ] realHash1 = new byte [ 0x20 ] ;
byte [ ] realHash2 = new byte [ 0x20 ] ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
Array . Copy ( savefile , 0x43C - 0 * 0x130 , realHash1 , 0 , 0x20 ) ;
Array . Copy ( savefile , 0x43C - 1 * 0x130 , realHash2 , 0 , 0x20 ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
B_SwitchSAV . Enabled = ( hashValue1 . SequenceEqual ( realHash1 ) & & hashValue2 . SequenceEqual ( realHash2 ) ) ;
2014-12-28 21:56:59 +00:00
getSAVOffsets ( ref oras ) ; // to detect if we are ORAS or not
2014-12-13 22:48:34 +00:00
Array . Copy ( savefile , 0x5400 + 0x7F000 * savindex , cyberSAV , 0 , cyberSAV . Length ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
openSave ( oras ) ;
}
2014-12-31 06:18:41 +00:00
private bool openXOR ( byte [ ] input , string path )
{
// Detection of stored Decryption XORpads:
2015-03-11 01:44:51 +00:00
if ( ModifierKeys = = Keys . Control ) return false ; // no xorpad compatible
byte [ ] savID = new byte [ 0x10 ] ; Array . Copy ( input , 0x10 , savID , 0 , 0x10 ) ;
string exepath = Application . StartupPath ;
string xorpath = exepath . Clone ( ) . ToString ( ) ;
string [ ] XORpads = Directory . GetFiles ( xorpath ) ;
2014-12-31 06:18:41 +00:00
2015-01-01 19:38:37 +00:00
check :
2015-03-11 01:44:51 +00:00
foreach ( byte [ ] data in from file in XORpads let fi = new FileInfo ( file ) where ( fi . Name . ToLower ( ) . Contains ( "xorpad" ) | | fi . Name . ToLower ( ) . Contains ( "key" ) ) & & ( fi . Length = = 0x10009C | | fi . Length = = 0x100000 ) select File . ReadAllBytes ( file ) )
{
// Fix xorpad alignment
byte [ ] xorpad = data ;
if ( xorpad . Length = = 0x10009C )
2014-12-31 06:18:41 +00:00
{
2015-03-11 01:44:51 +00:00
Array . Copy ( xorpad , 0x9C , xorpad , 0 , 0x100000 ) ;
Array . Resize ( ref xorpad , 0x100000 ) ;
2014-12-31 06:18:41 +00:00
}
2015-03-11 01:44:51 +00:00
byte [ ] xorID = new byte [ 0x10 ] ; Array . Copy ( xorpad , 0x10 , xorID , 0 , 0x10 ) ;
if ( ! xorID . SequenceEqual ( savID ) ) continue ;
// Set up Decrypted File
byte [ ] decryptedPS = new byte [ 0x76000 ] ;
Array . Copy ( input , 0x5400 , decryptedPS , 0 , 0x76000 ) ;
// xor through and decrypt
for ( int z = 0 ; z < 0x76000 ; z + + )
decryptedPS [ z ] ^ = xorpad [ 0x5400 + z ] ;
// Weakly check the validity of the decrypted content
if ( BitConverter . ToUInt32 ( decryptedPS , 0x76000 - 0x1F0 ) ! = 0x42454546 ) // Not OR/AS
if ( BitConverter . ToUInt32 ( decryptedPS , 0x65600 - 0x1F0 ) ! = 0x42454546 )
continue ; // Not X/Y, so continue.
else
Array . Resize ( ref decryptedPS , 0x65600 ) ; // set to X/Y size
else Array . Resize ( ref decryptedPS , 0x76000 ) ; // set to ORAS size just in case
// Save file is now decrypted! Reset the loading variables.
bool oras = ( decryptedPS . Length = = 0x76000 ) ;
string GameType = oras ? "ORAS" : "XY" ;
// Trigger Loading of the decrypted save file.
openMAIN ( decryptedPS , path , GameType , oras ) ;
// Abort the opening of a non-cyber file.
return true ;
2014-12-31 06:18:41 +00:00
}
2015-03-11 01:44:51 +00:00
// End file check loop, check the input path for xorpads too if it isn't the same as the EXE (quite common).
if ( xorpath ! = exepath ) return false ; // no xorpad compatible
xorpath = Path . GetDirectoryName ( path ) ; goto check ;
2014-12-31 06:18:41 +00:00
}
2014-12-13 22:48:34 +00:00
private void openSave ( bool oras )
{
savegame_oras = oras ;
// Enable Secondary Tools
GB_SAVtools . Enabled =
2015-02-07 02:34:01 +00:00
B_JPEG . Enabled = true ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
savedited = false ;
Menu_ToggleBoxUI . Visible = false ;
2014-06-28 21:22:05 +00:00
2015-01-01 19:38:37 +00:00
B_VerifySHA . Enabled = ! cybergadget ;
2015-02-07 02:34:01 +00:00
B_VerifyCHK . Enabled = ! ramsavloaded ;
2015-05-07 02:30:31 +00:00
2014-12-13 22:48:34 +00:00
setBoxNames ( ) ; // Display the Box Names
setPKXBoxes ( ) ; // Reload all of the PKX Windows
setSAVLabel ( ) ; // Reload the label indicating current save
// Version Exclusive Editors
GB_SUBE . Visible = ! oras ;
B_OpenSecretBase . Visible = oras ;
2015-08-07 05:32:12 +00:00
int startBox = savefile [ SaveGame . PCLayout + savindex * 0x7FFFF + 0x43F ] & 0x1F ;
if ( startBox > 30 ) { tabBoxMulti . SelectedIndex = 1 ; CB_BoxSelect . SelectedIndex = 0 ; }
2015-05-07 02:30:31 +00:00
else { tabBoxMulti . SelectedIndex = 0 ; CB_BoxSelect . SelectedIndex = startBox ; }
2015-03-11 01:44:51 +00:00
Width = largeWidth ;
2014-12-13 22:48:34 +00:00
savLoaded = true ;
// Indicate audibly the save is loaded
System . Media . SystemSounds . Beep . Play ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
// Language Translation
private void changeMainLanguage ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2015-03-14 02:59:51 +00:00
if ( init ) buff = preparepkx ( ) ; // get data currently in form
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
Menu_Options . DropDown . Close ( ) ;
InitializeStrings ( ) ;
InitializeLanguage ( ) ;
2015-03-12 05:51:56 +00:00
Util . TranslateInterface ( this , lang_val [ CB_MainLanguage . SelectedIndex ] , menuStrip1 ) ; // Translate the UI to language.
2014-12-13 22:48:34 +00:00
populateFields ( buff ) ; // put data back in form
}
private void InitializeStrings ( )
{
2015-03-12 05:51:56 +00:00
if ( CB_MainLanguage . SelectedIndex < 8 )
curlanguage = lang_val [ CB_MainLanguage . SelectedIndex ] ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
string l = curlanguage ;
natures = Util . getStringList ( "Natures" , l ) ;
types = Util . getStringList ( "Types" , l ) ;
abilitylist = Util . getStringList ( "Abilities" , l ) ;
movelist = Util . getStringList ( "Moves" , l ) ;
itemlist = Util . getStringList ( "Items" , l ) ;
characteristics = Util . getStringList ( "Character" , l ) ;
specieslist = Util . getStringList ( "Species" , l ) ;
wallpapernames = Util . getStringList ( "Wallpaper" , l ) ;
itempouch = Util . getStringList ( "ItemPouch" , l ) ;
2014-12-14 07:18:27 +00:00
encountertypelist = Util . getStringList ( "EncounterType" , l ) ;
gamelist = Util . getStringList ( "Games" , l ) ;
2015-02-03 05:51:08 +00:00
gamelanguages = Util . getNulledStringArray ( Util . getSimpleStringList ( "languages" ) ) ;
consoleregions = Util . getNulledStringArray ( Util . getSimpleStringList ( "regions3ds" ) ) ;
2015-01-01 19:38:37 +00:00
2014-12-26 18:46:18 +00:00
balllist = new string [ Legal . Items_Ball . Length ] ;
for ( int i = 0 ; i < balllist . Length ; i + + )
balllist [ i ] = itemlist [ Legal . Items_Ball [ i ] ] ;
2015-01-01 19:38:37 +00:00
2014-12-13 22:48:34 +00:00
if ( ( l ! = "zh" ) | | ( l = = "zh" & & ! init ) ) // load initial binaries
{
forms = Util . getStringList ( "Forms" , l ) ;
memories = Util . getStringList ( "Memories" , l ) ;
genloc = Util . getStringList ( "GenLoc" , l ) ;
trainingbags = Util . getStringList ( "TrainingBag" , l ) ;
trainingstage = Util . getStringList ( "SuperTraining" , l ) ;
puffs = Util . getStringList ( "Puff" , l ) ;
}
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Fix Item Names (Duplicate entries)
itemlist [ 456 ] + = " (OLD)" ; // S.S. Ticket
itemlist [ 463 ] + = " (OLD)" ; // Storage Key
itemlist [ 478 ] + = " (OLD)" ; // Basement Key
itemlist [ 626 ] + = " (2)" ; // Xtransceiver
itemlist [ 629 ] + = " (2)" ; // DNA Splicers
itemlist [ 637 ] + = " (2)" ; // Dropped Item
itemlist [ 707 ] + = " (2)" ; // Travel Trunk
itemlist [ 713 ] + = " (2)" ; // Alt Bike
itemlist [ 714 ] + = " (2)" ; // Holo Caster
itemlist [ 729 ] + = " (1)" ; // Meteorite
itemlist [ 740 ] + = " (2)" ; // Contest Costume
itemlist [ 751 ] + = " (2)" ; // Meteorite
itemlist [ 771 ] + = " (3)" ; // Meteorite
itemlist [ 772 ] + = " (4)" ; // Meteorite
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Get the Egg Name and then replace it with --- for the comboboxes.
eggname = specieslist [ 0 ] ;
specieslist [ 0 ] = "---" ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Get the met locations... for all of the games...
metHGSS_00000 = Util . getStringList ( "hgss_00000" , l ) ;
metHGSS_02000 = Util . getStringList ( "hgss_02000" , l ) ;
metHGSS_03000 = Util . getStringList ( "hgss_03000" , l ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
metBW2_00000 = Util . getStringList ( "bw2_00000" , l ) ;
metBW2_30000 = Util . getStringList ( "bw2_30000" , l ) ;
metBW2_40000 = Util . getStringList ( "bw2_40000" , l ) ;
metBW2_60000 = Util . getStringList ( "bw2_60000" , l ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
metXY_00000 = Util . getStringList ( "xy_00000" , l ) ;
metXY_30000 = Util . getStringList ( "xy_30000" , l ) ;
metXY_40000 = Util . getStringList ( "xy_40000" , l ) ;
metXY_60000 = Util . getStringList ( "xy_60000" , l ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Fix up some of the Location strings to make them more descriptive:
metHGSS_02000 [ 1 ] + = " (NPC)" ; // Anything from an NPC
metHGSS_02000 [ 2 ] + = " (" + eggname + ")" ; // Egg From Link Trade
metBW2_00000 [ 36 ] = metBW2_00000 [ 84 ] + "/" + metBW2_00000 [ 36 ] ; // Cold Storage in BW = PWT in BW2
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// BW2 Entries from 76 to 105 are for Entralink in BW
for ( int i = 76 ; i < 106 ; i + + )
metBW2_00000 [ i ] = metBW2_00000 [ i ] + "●" ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Localize the Poketransfer to the language (30001)
string [ ] ptransp = { "Poké Transfer" , "ポケシフター" , "Poké Fret" , "Pokétrasporto" , "Poképorter" , "Pokétransfer" , "포케시프터" , "ポケシフター" } ;
2015-03-12 05:51:56 +00:00
metBW2_30000 [ 1 - 1 ] = ptransp [ Array . IndexOf ( lang_val , curlanguage ) ] ;
2014-12-13 22:48:34 +00:00
metBW2_30000 [ 2 - 1 ] + = " (NPC)" ; // Anything from an NPC
metBW2_30000 [ 3 - 1 ] + = " (" + eggname + ")" ; // Egg From Link Trade
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Zorua/Zoroark events
metBW2_30000 [ 10 - 1 ] = specieslist [ 251 ] + " (" + specieslist [ 570 ] + " 1)" ; // Celebi's Zorua Event
metBW2_30000 [ 11 - 1 ] = specieslist [ 251 ] + " (" + specieslist [ 570 ] + " 2)" ; // Celebi's Zorua Event
metBW2_30000 [ 12 - 1 ] = specieslist [ 571 ] + " (" + "1)" ; // Zoroark
metBW2_30000 [ 13 - 1 ] = specieslist [ 571 ] + " (" + "2)" ; // Zoroark
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
metBW2_60000 [ 3 - 1 ] + = " (" + eggname + ")" ; // Egg Treasure Hunter/Breeder, whatever...
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
metXY_00000 [ 104 ] + = " (X/Y)" ; // Victory Road
metXY_00000 [ 298 ] + = " (OR/AS)" ; // Victory Road
metXY_30000 [ 0 ] + = " (NPC)" ; // Anything from an NPC
metXY_30000 [ 1 ] + = " (" + eggname + ")" ; // Egg From Link Trade
2014-11-30 01:47:17 +00:00
2014-12-13 22:48:34 +00:00
// Set the first entry of a met location to "" (nothing)
// Fix (None) tags
abilitylist [ 0 ] = itemlist [ 0 ] = movelist [ 0 ] = metXY_00000 [ 0 ] = metBW2_00000 [ 0 ] = metHGSS_00000 [ 0 ] = "(" + itemlist [ 0 ] + ")" ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Force an update to the met locations
origintrack = "" ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
if ( init )
updateIVs ( null , null ) ; // Prompt an update for the characteristics
}
#endregion
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
#region //// PKX WINDOW FUNCTIONS ////
private void InitializeFields ( )
{
// Now that the ComboBoxes are ready, load the data.
populateFields ( buff ) ;
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
TB_OT . Text = "PKHeX" ;
TB_TID . Text = 12345. ToString ( ) ;
TB_SID . Text = 54321. ToString ( ) ;
2015-02-28 18:35:35 +00:00
CB_Species . SelectedIndex = 1 ;
2014-12-14 04:39:31 +00:00
CB_GameOrigin . SelectedIndex = 0 ;
CB_Language . SelectedIndex = 0 ;
2015-05-07 02:30:31 +00:00
CB_BoxSelect . SelectedIndex = 0 ;
2014-12-14 07:18:27 +00:00
CB_GameOrigin . SelectedIndex = 0 ;
2014-12-13 22:48:34 +00:00
CB_PPu1 . SelectedIndex = CB_PPu2 . SelectedIndex = CB_PPu3 . SelectedIndex = CB_PPu4 . SelectedIndex = 0 ;
CB_Ball . SelectedIndex = 0 ;
CB_Country . SelectedIndex = 0 ;
2014-12-24 07:29:57 +00:00
setAbilityList ( TB_AbilityNumber , Util . getIndex ( CB_Species ) , CB_Ability , CB_Form ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
}
private void InitializeLanguage ( )
{
2014-12-14 07:18:27 +00:00
// Set the Display
2015-01-31 18:36:06 +00:00
CB_Country . DisplayMember =
CB_SubRegion . DisplayMember =
CB_3DSReg . DisplayMember =
2015-01-01 19:38:37 +00:00
CB_Language . DisplayMember =
CB_Ball . DisplayMember =
CB_HeldItem . DisplayMember =
CB_Species . DisplayMember =
2014-12-14 07:18:27 +00:00
DEV_Ability . DisplayMember =
CB_Nature . DisplayMember =
2014-12-14 07:22:07 +00:00
CB_EncounterType . DisplayMember =
2015-03-09 00:41:13 +00:00
CB_GameOrigin . DisplayMember =
CB_HPType . DisplayMember = "Text" ;
2014-12-14 07:18:27 +00:00
// Set the Value
2015-01-31 18:36:06 +00:00
CB_Country . ValueMember =
CB_SubRegion . ValueMember =
CB_3DSReg . ValueMember =
2015-01-01 19:38:37 +00:00
CB_Language . ValueMember =
CB_Ball . ValueMember =
CB_HeldItem . ValueMember =
2014-12-14 07:18:27 +00:00
CB_Species . ValueMember =
DEV_Ability . ValueMember =
2014-12-14 07:22:07 +00:00
CB_Nature . ValueMember =
CB_EncounterType . ValueMember =
2015-03-09 00:41:13 +00:00
CB_GameOrigin . ValueMember =
CB_HPType . ValueMember = "Value" ;
2014-12-14 07:18:27 +00:00
2014-12-14 18:31:53 +00:00
// Set the various ComboBox DataSources up with their allowed entries
2015-01-31 18:36:06 +00:00
setCountrySubRegion ( CB_Country , "countries" ) ;
2014-12-14 18:31:53 +00:00
CB_3DSReg . DataSource = Util . getUnsortedCBList ( "regions3ds" ) ;
CB_Language . DataSource = Util . getUnsortedCBList ( "languages" ) ;
2015-03-11 01:44:51 +00:00
int [ ] ball_nums = { 7 , 576 , 13 , 492 , 497 , 14 , 495 , 493 , 496 , 494 , 11 , 498 , 8 , 6 , 12 , 15 , 9 , 5 , 499 , 10 , 1 , 16 } ;
int [ ] ball_vals = { 7 , 25 , 13 , 17 , 22 , 14 , 20 , 18 , 21 , 19 , 11 , 23 , 8 , 6 , 12 , 15 , 9 , 5 , 24 , 10 , 1 , 16 } ;
CB_Ball . DataSource = Util . getVariedCBList ( Util . getCBList ( itemlist , new [ ] { 4 } , new [ ] { 3 } , new [ ] { 2 } , new [ ] { 1 } ) , itemlist , ball_nums , ball_vals ) ;
2014-12-14 18:31:53 +00:00
CB_HeldItem . DataSource = Util . getCBList ( itemlist , ( DEV_Ability . Enabled ) ? null : Legal . Items_Held ) ;
CB_Species . DataSource = Util . getCBList ( specieslist , null ) ;
DEV_Ability . DataSource = Util . getCBList ( abilitylist , null ) ;
CB_Nature . DataSource = Util . getCBList ( natures , null ) ;
2015-03-11 01:44:51 +00:00
CB_EncounterType . DataSource = Util . getCBList ( encountertypelist , new [ ] { 0 } , Legal . Gen4EncounterTypes ) ;
2014-12-14 18:31:53 +00:00
CB_GameOrigin . DataSource = Util . getCBList ( gamelist , Legal . Games_6oras , Legal . Games_6xy , Legal . Games_5 , Legal . Games_4 , Legal . Games_4e , Legal . Games_4r , Legal . Games_3 , Legal . Games_3e , Legal . Games_3r , Legal . Games_3s ) ;
2015-01-01 19:38:37 +00:00
2015-03-09 00:41:13 +00:00
string [ ] hptypes = new string [ types . Length - 2 ] ; Array . Copy ( types , 1 , hptypes , 0 , hptypes . Length ) ;
CB_HPType . DataSource = Util . getCBList ( hptypes , null ) ;
2014-12-14 07:18:27 +00:00
// Set the Move ComboBoxes too..
2014-06-28 21:22:05 +00:00
{
2014-12-14 18:31:53 +00:00
var moves = Util . getCBList ( movelist , null ) ;
2015-03-11 01:44:51 +00:00
foreach ( ComboBox cb in new [ ] { CB_Move1 , CB_Move2 , CB_Move3 , CB_Move4 , CB_RelearnMove1 , CB_RelearnMove2 , CB_RelearnMove3 , CB_RelearnMove4 } )
2014-12-13 22:48:34 +00:00
{
2014-12-14 07:18:27 +00:00
cb . DisplayMember = "Text" ; cb . ValueMember = "Value" ;
2014-12-14 18:31:53 +00:00
cb . DataSource = new BindingSource ( moves , null ) ;
2014-12-13 22:48:34 +00:00
}
2014-08-07 00:10:29 +00:00
}
2014-06-28 21:22:05 +00:00
}
2015-03-14 02:59:51 +00:00
private void populateFields ( byte [ ] data )
2014-06-28 21:22:05 +00:00
{
2015-03-14 02:59:51 +00:00
// Store all loaded data in a persistent buffer for easy access.
Array . Resize ( ref buff , data . Length ) ;
Array . Copy ( data , buff , data . Length ) ;
2014-12-17 02:56:08 +00:00
init = false ;
2014-12-13 22:48:34 +00:00
CAL_EggDate . Value = new DateTime ( 2000 , 01 , 01 ) ;
Tab_Main . Focus ( ) ;
// Encryption Constant
TB_EC . Text = BitConverter . ToUInt32 ( buff , 0 ) . ToString ( "X8" ) ;
// Block A
int species = BitConverter . ToInt16 ( buff , 0x08 ) ;
int helditem = BitConverter . ToUInt16 ( buff , 0x0A ) ;
uint TID = BitConverter . ToUInt16 ( buff , 0x0C ) ;
uint SID = BitConverter . ToUInt16 ( buff , 0x0E ) ;
uint exp = BitConverter . ToUInt32 ( buff , 0x10 ) ;
int ability = buff [ 0x14 ] ;
int abilitynum = buff [ 0x15 ] ;
// 0x16, 0x17 - Training Bags handled by the Ribbon Editor
uint PID = BitConverter . ToUInt32 ( buff , 0x18 ) ;
int nature = buff [ 0x1C ] ;
int feflag = buff [ 0x1D ] % 2 ;
2015-01-03 01:07:29 +00:00
int genderflag = ( buff [ 0x1D ] > > 1 ) & 0x3 ;
2014-12-13 22:48:34 +00:00
int altforms = ( buff [ 0x1D ] > > 3 ) ;
int HP_EV = buff [ 0x1E ] ;
int ATK_EV = buff [ 0x1F ] ;
int DEF_EV = buff [ 0x20 ] ;
int SPA_EV = buff [ 0x22 ] ;
int SPD_EV = buff [ 0x23 ] ;
int SPE_EV = buff [ 0x21 ] ;
int cnt_cool = buff [ 0x24 ] ;
int cnt_beauty = buff [ 0x25 ] ;
int cnt_cute = buff [ 0x26 ] ;
int cnt_smart = buff [ 0x27 ] ;
int cnt_tough = buff [ 0x28 ] ;
int cnt_sheen = buff [ 0x29 ] ;
int markings = buff [ 0x2A ] ;
int PKRS_Strain = buff [ 0x2B ] > > 4 ;
int PKRS_Duration = buff [ 0x2B ] % 0x10 ;
// Medals and Ribbons, passed with buff to new form
// 0x2C, 0x2D, 0x2E, 0x2F
// 0x33, 0x34, 0x35, 0x36
// 0x34, 0x35, 0x36, 0x37
2015-02-26 04:22:53 +00:00
// 0x38, 0x39, 0x3A
2014-12-13 22:48:34 +00:00
2015-02-26 04:22:53 +00:00
// 0x3B, 0x3C, 0x3D, 0x3E, 0x3F - Unused/Unknown
2014-12-13 22:48:34 +00:00
// Block B
string nicknamestr = Util . TrimFromZero ( Encoding . Unicode . GetString ( buff , 0x40 , 24 ) ) ;
// 0x58, 0x59 - unused
int move1 = BitConverter . ToInt16 ( buff , 0x5A ) ;
int move2 = BitConverter . ToInt16 ( buff , 0x5C ) ;
int move3 = BitConverter . ToInt16 ( buff , 0x5E ) ;
int move4 = BitConverter . ToInt16 ( buff , 0x60 ) ;
int move1_pp = buff [ 0x62 ] ;
int move2_pp = buff [ 0x63 ] ;
int move3_pp = buff [ 0x64 ] ;
int move4_pp = buff [ 0x65 ] ;
int move1_ppu = buff [ 0x66 ] ;
int move2_ppu = buff [ 0x67 ] ;
int move3_ppu = buff [ 0x68 ] ;
int move4_ppu = buff [ 0x69 ] ;
int eggmove1 = BitConverter . ToInt16 ( buff , 0x6A ) ;
int eggmove2 = BitConverter . ToInt16 ( buff , 0x6C ) ;
int eggmove3 = BitConverter . ToInt16 ( buff , 0x6E ) ;
int eggmove4 = BitConverter . ToInt16 ( buff , 0x70 ) ;
// 0x72 - Super Training Flag - Passed with buff to new form
2015-02-26 04:22:53 +00:00
// 0x73 - Unused/Unknown
2014-12-13 22:48:34 +00:00
uint IV32 = BitConverter . ToUInt32 ( buff , 0x74 ) ;
uint HP_IV = IV32 & 0x1F ;
uint ATK_IV = ( IV32 > > 5 ) & 0x1F ;
uint DEF_IV = ( IV32 > > 10 ) & 0x1F ;
uint SPE_IV = ( IV32 > > 15 ) & 0x1F ;
uint SPA_IV = ( IV32 > > 20 ) & 0x1F ;
uint SPD_IV = ( IV32 > > 25 ) & 0x1F ;
uint isegg = ( IV32 > > 30 ) & 1 ;
uint isnick = ( IV32 > > 31 ) ;
// Block C
string notOT = Util . TrimFromZero ( Encoding . Unicode . GetString ( buff , 0x78 , 24 ) ) ;
bool notOTG = Convert . ToBoolean ( buff [ 0x92 ] ) ;
// Memory Editor edits everything else with buff in a new form
// Block D
string ot = Util . TrimFromZero ( Encoding . Unicode . GetString ( buff , 0xB0 , 24 ) ) ;
// 0xC8, 0xC9 - unused
int OTfriendship = buff [ 0xCA ] ;
2015-03-11 01:44:51 +00:00
// int OTaffection = buff[0xCB]; // Handled by Memory Editor
2014-12-13 22:48:34 +00:00
// 0xCC, 0xCD, 0xCE, 0xCF, 0xD0
int egg_year = buff [ 0xD1 ] ;
int egg_month = buff [ 0xD2 ] ;
int egg_day = buff [ 0xD3 ] ;
int met_year = buff [ 0xD4 ] ;
int met_month = buff [ 0xD5 ] ;
int met_day = buff [ 0xD6 ] ;
// 0xD7 - unused
int eggloc = BitConverter . ToUInt16 ( buff , 0xD8 ) ;
int metloc = BitConverter . ToUInt16 ( buff , 0xDA ) ;
int ball = buff [ 0xDC ] ;
int metlevel = buff [ 0xDD ] & 0x7F ;
int otgender = ( buff [ 0xDD ] ) > > 7 ;
int encountertype = buff [ 0xDE ] ;
int gamevers = buff [ 0xDF ] ;
int countryID = buff [ 0xE0 ] ;
int regionID = buff [ 0xE1 ] ;
int dsregID = buff [ 0xE2 ] ;
int otlang = buff [ 0xE3 ] ;
// 0xE4, 0xE5, 0xE6, 0xE7 - unused
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
//
// Populate Fields
//
2014-10-10 02:59:57 +00:00
2014-12-13 22:48:34 +00:00
CHK_Fateful . Checked = Convert . ToBoolean ( feflag ) ;
CHK_IsEgg . Checked = Convert . ToBoolean ( isegg ) ;
CHK_Nicknamed . Checked = Convert . ToBoolean ( isnick ) ;
Label_OTGender . Text = gendersymbols [ otgender ] ;
2015-08-07 04:16:25 +00:00
Label_OTGender . ForeColor = ( ( otgender = = 1 ) ? Color . Red : Color . Blue ) ;
2015-01-01 19:38:37 +00:00
2014-12-13 22:48:34 +00:00
// Private Use Character Fixing Text
2014-08-15 04:27:53 +00:00
{
2015-02-16 06:03:42 +00:00
nicknamestr = nicknamestr . Replace ( "\uE08F" , "\u2640" ) ;
nicknamestr = nicknamestr . Replace ( "\uE08E" , "\u2642" ) ;
2014-08-15 04:27:53 +00:00
}
2014-12-24 07:29:57 +00:00
// Set Markings
CHK_Circle . Checked = ( ( markings > > 0 ) & 1 ) = = 1 ;
CHK_Triangle . Checked = ( ( markings > > 1 ) & 1 ) = = 1 ;
CHK_Square . Checked = ( ( markings > > 2 ) & 1 ) = = 1 ;
CHK_Heart . Checked = ( ( markings > > 3 ) & 1 ) = = 1 ;
CHK_Star . Checked = ( ( markings > > 4 ) & 1 ) = = 1 ;
CHK_Diamond . Checked = ( ( markings > > 5 ) & 1 ) = = 1 ;
// Set Generic Identification Data
2014-12-13 22:48:34 +00:00
TB_PID . Text = PID . ToString ( "X8" ) ;
CB_Species . SelectedValue = species ;
CB_HeldItem . SelectedValue = helditem ;
2014-12-24 07:29:57 +00:00
setAbilityList ( TB_AbilityNumber , species , CB_Ability , CB_Form ) ;
2014-12-13 22:48:34 +00:00
TB_AbilityNumber . Text = abilitynum . ToString ( ) ;
2014-12-24 07:29:57 +00:00
CB_Ability . SelectedIndex = ( abilitynum < 6 ) ? abilitynum > > 1 : 0 ; // with some simple error handling
2014-12-13 22:48:34 +00:00
CB_Nature . SelectedValue = nature ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
TB_EXP . Text = exp . ToString ( ) ;
2015-02-26 04:22:53 +00:00
TB_TID . Text = TID . ToString ( "00000" ) ;
TB_SID . Text = SID . ToString ( "00000" ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
TB_OT . Text = ot ;
TB_Nickname . Text = nicknamestr ;
TB_OTt2 . Text = notOT ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
if ( buff [ 0x93 ] = = 1 ) // = 1
2014-12-04 01:26:12 +00:00
{
2014-12-13 22:48:34 +00:00
TB_Friendship . Text = buff [ 0xA2 ] . ToString ( ) ;
2015-02-26 04:22:53 +00:00
GB_nOT . BackgroundImage = mixedHighlight ;
GB_OT . BackgroundImage = null ;
2014-12-04 01:26:12 +00:00
}
2015-02-26 04:22:53 +00:00
else // = 0
2014-12-04 01:26:12 +00:00
{
2014-12-13 22:48:34 +00:00
TB_Friendship . Text = OTfriendship . ToString ( ) ;
2015-02-26 04:22:53 +00:00
GB_OT . BackgroundImage = mixedHighlight ;
2015-02-26 06:39:29 +00:00
GB_nOT . BackgroundImage = null ;
2014-12-04 01:26:12 +00:00
}
2015-01-01 19:38:37 +00:00
2014-12-13 22:48:34 +00:00
CB_Language . SelectedValue = otlang ;
CB_Country . SelectedValue = countryID ;
CB_SubRegion . SelectedValue = regionID ;
CB_3DSReg . SelectedValue = dsregID ;
CB_GameOrigin . SelectedValue = gamevers ;
CB_EncounterType . SelectedValue = encountertype ;
CB_Ball . SelectedValue = ball ;
2014-06-28 21:22:05 +00:00
2014-12-24 07:29:57 +00:00
if ( met_month = = 0 ) { met_month = 1 ; }
if ( met_day = = 0 ) { met_day = 1 ; }
try { CAL_MetDate . Value = new DateTime ( met_year + 2000 , met_month , met_day ) ; }
2014-12-13 22:48:34 +00:00
catch { CAL_MetDate . Value = new DateTime ( 2000 , 1 , 1 ) ; }
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
if ( eggloc ! = 0 )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
// Was obtained initially as an egg.
CHK_AsEgg . Checked = true ;
GB_EggConditions . Enabled = true ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
CB_EggLocation . SelectedValue = eggloc ;
2014-12-24 07:29:57 +00:00
try { CAL_EggDate . Value = new DateTime ( egg_year + 2000 , egg_month , egg_day ) ; }
2014-12-13 22:48:34 +00:00
catch { CAL_MetDate . Value = new DateTime ( 2000 , 1 , 1 ) ; }
}
else { CHK_AsEgg . Checked = GB_EggConditions . Enabled = false ; CB_EggLocation . SelectedValue = 0 ; }
2014-12-11 06:50:40 +00:00
2014-12-13 22:48:34 +00:00
CB_MetLocation . SelectedValue = metloc ;
2014-06-28 21:22:05 +00:00
2014-12-27 17:43:38 +00:00
// Set CT Gender to None if no CT, else set to gender symbol.
Label_CTGender . Text = ( ( TB_OTt2 . Text = = "" ) | | ( notOT = = "" ) ) ? "" : ( notOTG ) ? gendersymbols [ 1 ] : gendersymbols [ 0 ] ;
2015-08-07 04:16:25 +00:00
Label_CTGender . ForeColor = ( ( notOTG ) ? Color . Red : Color . Blue ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
TB_MetLevel . Text = metlevel . ToString ( ) ;
2014-06-28 21:22:05 +00:00
2014-12-27 17:43:38 +00:00
// Reset Label and ComboBox visibility, as well as non-data checked status.
2015-03-11 01:44:51 +00:00
Label_PKRS . Visible = CB_PKRSStrain . Visible = CHK_Infected . Checked = PKRS_Strain ! = 0 ;
Label_PKRSdays . Visible = CB_PKRSDays . Visible = PKRS_Duration ! = 0 ;
2014-12-27 17:43:38 +00:00
// Set SelectedIndexes for PKRS
2014-12-13 22:48:34 +00:00
CB_PKRSStrain . SelectedIndex = PKRS_Strain ;
2015-04-03 01:44:03 +00:00
CHK_Cured . Checked = ( PKRS_Strain > 0 & & PKRS_Duration = = 0 ) ;
2015-04-05 03:45:29 +00:00
CB_PKRSDays . SelectedIndex = Math . Min ( CB_PKRSDays . Items . Count - 1 , PKRS_Duration ) ; // to strip out bad hacked 'rus
2014-12-13 22:48:34 +00:00
TB_Cool . Text = cnt_cool . ToString ( ) ;
TB_Beauty . Text = cnt_beauty . ToString ( ) ;
TB_Cute . Text = cnt_cute . ToString ( ) ;
TB_Smart . Text = cnt_smart . ToString ( ) ;
TB_Tough . Text = cnt_tough . ToString ( ) ;
TB_Sheen . Text = cnt_sheen . ToString ( ) ;
TB_HPIV . Text = HP_IV . ToString ( ) ;
TB_ATKIV . Text = ATK_IV . ToString ( ) ;
TB_DEFIV . Text = DEF_IV . ToString ( ) ;
TB_SPAIV . Text = SPA_IV . ToString ( ) ;
TB_SPDIV . Text = SPD_IV . ToString ( ) ;
TB_SPEIV . Text = SPE_IV . ToString ( ) ;
TB_HPEV . Text = HP_EV . ToString ( ) ;
TB_ATKEV . Text = ATK_EV . ToString ( ) ;
TB_DEFEV . Text = DEF_EV . ToString ( ) ;
TB_SPAEV . Text = SPA_EV . ToString ( ) ;
TB_SPDEV . Text = SPD_EV . ToString ( ) ;
TB_SPEEV . Text = SPE_EV . ToString ( ) ;
CB_Move1 . SelectedValue = move1 ;
CB_Move2 . SelectedValue = move2 ;
CB_Move3 . SelectedValue = move3 ;
CB_Move4 . SelectedValue = move4 ;
CB_RelearnMove1 . SelectedValue = eggmove1 ;
CB_RelearnMove2 . SelectedValue = eggmove2 ;
CB_RelearnMove3 . SelectedValue = eggmove3 ;
CB_RelearnMove4 . SelectedValue = eggmove4 ;
CB_PPu1 . SelectedIndex = move1_ppu ;
CB_PPu2 . SelectedIndex = move2_ppu ;
CB_PPu3 . SelectedIndex = move3_ppu ;
CB_PPu4 . SelectedIndex = move4_ppu ;
2015-03-11 01:44:51 +00:00
TB_PP1 . Text = move1_pp . ToString ( ) ;
TB_PP2 . Text = move2_pp . ToString ( ) ;
TB_PP3 . Text = move3_pp . ToString ( ) ;
TB_PP4 . Text = move4_pp . ToString ( ) ;
2014-12-13 22:48:34 +00:00
int level = PKX . getLevel ( species , ref exp ) ;
TB_Level . Text = level . ToString ( ) ;
2014-12-27 17:43:38 +00:00
// Set Form if count is enough, else if count is more than 1 set equal to max else zero.
CB_Form . SelectedIndex = ( CB_Form . Items . Count > altforms ) ? altforms : ( CB_Form . Items . Count > 1 ) ? CB_Form . Items . Count - 1 : 0 ;
2014-12-13 22:48:34 +00:00
// Load Extrabyte Value
TB_ExtraByte . Text = buff [ Convert . ToInt32 ( CB_ExtraBytes . Text , 16 ) ] . ToString ( ) ;
2015-01-01 19:38:37 +00:00
2015-01-03 01:07:29 +00:00
// Load Gender Flag
2014-12-13 22:48:34 +00:00
Label_Gender . Text = gendersymbols [ genderflag ] ;
2015-08-07 04:16:25 +00:00
Label_Gender . ForeColor = ( genderflag = = 2 ) ? Label_Species . ForeColor : ( ( genderflag = = 1 ) ? Color . Red : Color . Blue ) ;
2014-06-28 21:22:05 +00:00
updateStats ( ) ;
2014-12-13 22:48:34 +00:00
setIsShiny ( ) ;
2014-12-17 02:56:08 +00:00
CB_EncounterType . Visible = Label_EncounterType . Visible = ! ( gamevers > 12 | | gamevers < 7 ) ;
if ( gamevers > 12 | | gamevers < 7 )
CB_EncounterType . SelectedValue = 0 ;
2014-12-13 22:48:34 +00:00
init = true ;
2014-12-26 18:46:18 +00:00
updatePKRSInfected ( null , null ) ;
updatePKRSCured ( null , null ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
if ( HaX ) // DEV Illegality
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
DEV_Ability . SelectedValue = ability ;
MT_Level . Text = level . ToString ( ) ;
MT_Form . Text = altforms . ToString ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-27 17:43:38 +00:00
// Set the Preview Box
2014-12-17 19:29:26 +00:00
getQuickFiller ( dragout ) ;
2014-12-27 17:43:38 +00:00
2015-02-07 20:22:09 +00:00
// Highlight the Current Handler
clickGT ( ( buff [ 0x93 ] = = 1 ) ? GB_nOT : GB_OT , null ) ;
2014-12-27 17:43:38 +00:00
if ( ! PKX . verifychk ( buff ) )
Util . Alert ( "PKX File has an invalid checksum." ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-25 00:20:39 +00:00
// General Use Functions shared by other Forms //
2015-03-11 01:44:51 +00:00
public void setCountrySubRegion ( ComboBox CB , string type )
2014-06-28 21:22:05 +00:00
{
2015-01-31 23:59:23 +00:00
int index = CB . SelectedIndex ;
2014-12-24 07:29:57 +00:00
// fix for Korean / Chinese being swapped
string cl = curlanguage + "" ;
cl = ( cl = = "zh" ) ? "ko" : ( cl = = "ko" ) ? "zh" : cl ;
2014-06-28 21:22:05 +00:00
2014-12-24 07:29:57 +00:00
CB . DataSource = Util . getCBList ( type , cl ) ;
2015-03-03 17:11:21 +00:00
if ( index > 0 & & index < CB . Items . Count & & init )
2015-01-31 23:59:23 +00:00
CB . SelectedIndex = index ;
2014-12-13 22:48:34 +00:00
}
2015-03-08 08:48:57 +00:00
public void setForms ( int species , ComboBox cb , Label l = null )
2014-12-13 22:48:34 +00:00
{
// Form Tables
2015-01-26 00:30:44 +00:00
cb . DisplayMember = "Text" ;
cb . ValueMember = "Value" ;
2015-03-08 08:48:57 +00:00
PKX . PersonalParser . Personal MonData = PKX . PersonalGetter . GetPersonal ( species ) ;
2015-03-17 02:25:59 +00:00
bool hasForms = ! ( MonData . AltFormCount = = 0 & & species ! = 664 & & species ! = 665 ) ; // If no forms & not Scatterbug / Spewpa...
2015-03-08 08:48:57 +00:00
cb . Enabled = cb . Visible = hasForms ;
if ( l ! = null ) l . Visible = hasForms ;
2015-03-17 02:25:59 +00:00
cb . DataSource = PKX . getFormList ( species , types , forms , gendersymbols ) . ToList ( ) ;
2014-12-13 22:48:34 +00:00
}
2014-12-24 07:29:57 +00:00
public void setAbilityList ( MaskedTextBox tb_abil , int species , ComboBox cb_abil , ComboBox cb_forme )
{
if ( ! init & & tb_abil . Text = = "" )
return ;
int newabil = Convert . ToInt16 ( tb_abil . Text ) > > 1 ;
int form = cb_forme . SelectedIndex ;
byte [ ] abils = PKX . getAbilities ( species , form ) ;
// Build Ability List
2015-03-11 01:44:51 +00:00
List < string > ability_list = new List < string >
{
abilitylist [ abils [ 0 ] ] + " (1)" ,
abilitylist [ abils [ 1 ] ] + " (2)" ,
abilitylist [ abils [ 2 ] ] + " (H)"
} ;
2014-12-24 07:29:57 +00:00
cb_abil . DataSource = ability_list ;
2015-03-11 01:44:51 +00:00
cb_abil . SelectedIndex = newabil < 3 ? newabil : 0 ;
2014-12-24 07:29:57 +00:00
}
// PKX Data Calculation Functions //
private void setIsShiny ( )
{
2015-01-01 19:38:37 +00:00
bool isShiny = PKX . getIsShiny ( Util . getHEXval ( TB_PID ) , Util . ToUInt32 ( TB_TID . Text ) , Util . ToUInt32 ( TB_SID . Text ) ) ;
2014-12-24 07:29:57 +00:00
// Set the Controls
BTN_Shinytize . Visible = BTN_Shinytize . Enabled = ! isShiny ;
Label_IsShiny . Visible = isShiny ;
// Refresh Markings (for Shiny Star if applicable)
setMarkings ( ) ;
}
2014-12-13 22:48:34 +00:00
private void setMarkings ( )
{
PictureBox [ ] pba = { PB_Mark1 , PB_Mark2 , PB_Mark3 , PB_Mark4 , PB_Mark5 , PB_Mark6 } ;
CheckBox [ ] cba = { CHK_Circle , CHK_Triangle , CHK_Square , CHK_Heart , CHK_Star , CHK_Diamond } ;
for ( int i = 0 ; i < 6 ; i + + )
2015-03-11 01:44:51 +00:00
pba [ i ] . Image = Util . ChangeOpacity ( pba [ i ] . InitialImage , ( Convert . ToUInt16 ( cba [ i ] . Checked ) ) * 0.9 + 0.1 ) ;
2014-06-28 21:22:05 +00:00
2015-03-11 01:44:51 +00:00
PB_MarkShiny . Image = Util . ChangeOpacity ( PB_MarkShiny . InitialImage , ( Convert . ToUInt16 ( ! BTN_Shinytize . Enabled ) ) * 0.9 + 0.1 ) ;
PB_MarkCured . Image = Util . ChangeOpacity ( PB_MarkCured . InitialImage , ( Convert . ToUInt16 ( CHK_Cured . Checked ) ) * 0.9 + 0.1 ) ;
2014-12-13 22:48:34 +00:00
int gameindex = Util . getIndex ( CB_GameOrigin ) ;
2015-03-11 01:44:51 +00:00
PB_MarkPentagon . Image = Util . ChangeOpacity ( PB_MarkPentagon . InitialImage , ( Convert . ToUInt16 ( gameindex = = 24 | | gameindex = = 25 | | gameindex = = 26 | | gameindex = = 27 ) ) * 0.9 + 0.1 ) ;
2014-12-13 22:48:34 +00:00
}
2015-02-25 04:10:47 +00:00
// Clicked Label Shortcuts //
private void clickQR ( object sender , EventArgs e )
{
2015-02-27 08:40:57 +00:00
if ( ModifierKeys = = Keys . Alt )
{
// Fetch data from QR code...
2015-03-14 02:59:51 +00:00
byte [ ] ekx = Util . getQRData ( ) ;
if ( ekx = = null ) return ;
if ( ekx . Length ! = 232 ) { Util . Alert ( "Decoded data not 232 bytes." , String . Format ( "QR Data Size: {0}" , ekx . Length ) ) ; }
else try
{
2015-02-27 08:40:57 +00:00
byte [ ] pkx = PKX . decryptArray ( ekx ) ;
2015-03-01 19:04:06 +00:00
if ( PKX . verifychk ( pkx ) ) { Array . Copy ( pkx , buff , 0xE8 ) ; populateFields ( buff ) ; }
2015-02-27 08:40:57 +00:00
else Util . Alert ( "Invalid checksum in QR data." ) ;
2015-03-14 02:59:51 +00:00
}
catch { Util . Alert ( "Error loading decrypted data." ) ; }
2015-02-26 06:39:29 +00:00
}
2015-02-27 08:40:57 +00:00
else
2015-02-26 07:12:38 +00:00
{
2015-02-27 08:40:57 +00:00
if ( ! verifiedPKX ( ) ) return ;
2015-03-14 02:59:51 +00:00
byte [ ] pkx = preparepkx ( ) ;
2015-02-27 08:40:57 +00:00
byte [ ] ekx = PKX . encryptArray ( pkx ) ;
Array . Resize ( ref ekx , 232 ) ;
2015-03-11 01:44:51 +00:00
const string server = "http://loadcode.projectpokemon.org/b1s1.html#" ; // Rehosted with permission from LC/MS -- massive thanks!
2015-03-14 02:59:51 +00:00
Image qr = Util . getQRImage ( ekx , server ) ;
if ( qr = = null ) return ;
2015-02-27 08:40:57 +00:00
PKX data = new PKX ( pkx , "Tabs" ) ;
2015-03-14 02:59:51 +00:00
string [ ] r = PKX . getPKXSummary ( data ) ;
new QR ( qr , dragout . Image , r [ 0 ] , r [ 1 ] , r [ 2 ] , "PKHeX @ ProjectPokemon.org" ) . ShowDialog ( ) ;
2015-02-26 07:12:38 +00:00
}
2015-02-25 04:10:47 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickFriendship ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
if ( ModifierKeys = = Keys . Control ) // prompt to reset
2015-03-11 01:44:51 +00:00
TB_Friendship . Text = buff [ 0x93 ] = = 0 ? buff [ 0xCA ] . ToString ( ) : buff [ 0xA2 ] . ToString ( ) ;
else
TB_Friendship . Text = TB_Friendship . Text = = "255" ? PKX . getBaseFriendship ( Util . getIndex ( CB_Species ) ) . ToString ( ) : "255" ;
2014-12-13 22:48:34 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickGender ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
// Get Gender Threshold
2015-01-03 01:07:29 +00:00
PKX . PersonalParser . Personal MonData = PKX . PersonalGetter . GetPersonal ( Util . getIndex ( CB_Species ) ) ;
int gt = MonData . GenderRatio ;
2014-12-13 22:48:34 +00:00
if ( gt = = 255 | | gt = = 0 | | gt = = 254 ) // Single gender/genderless
return ;
2015-03-11 01:44:51 +00:00
if ( gt > = 255 ) return ;
2015-08-07 04:16:25 +00:00
// If not a single gender(less) species: (should be <254 but whatever, 255 never happens)
int gender = PKX . getGender ( Label_Gender . Text ) ^ 1 ;
Label_Gender . Text = gendersymbols [ gender ] ;
Label_Gender . ForeColor = ( gender = = 2 ) ? Label_Species . ForeColor : ( ( gender = = 1 ) ? Color . Red : Color . Blue ) ;
2014-12-13 22:48:34 +00:00
2015-03-11 01:44:51 +00:00
if ( PKX . getGender ( CB_Form . Text ) < 2 ) // Gendered Forms
CB_Form . SelectedIndex = PKX . getGender ( Label_Gender . Text ) ;
2015-02-28 05:51:19 +00:00
2015-03-11 01:44:51 +00:00
getQuickFiller ( dragout ) ;
2014-12-13 22:48:34 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickPPUps ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
CB_PPu1 . SelectedIndex = ( ModifierKeys ! = Keys . Control & & Util . getIndex ( CB_Move1 ) > 0 ) ? 3 : 0 ;
CB_PPu2 . SelectedIndex = ( ModifierKeys ! = Keys . Control & & Util . getIndex ( CB_Move2 ) > 0 ) ? 3 : 0 ;
CB_PPu3 . SelectedIndex = ( ModifierKeys ! = Keys . Control & & Util . getIndex ( CB_Move3 ) > 0 ) ? 3 : 0 ;
CB_PPu4 . SelectedIndex = ( ModifierKeys ! = Keys . Control & & Util . getIndex ( CB_Move4 ) > 0 ) ? 3 : 0 ;
}
2014-12-14 19:06:17 +00:00
private void clickMarking ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
PictureBox [ ] pba = { PB_Mark1 , PB_Mark2 , PB_Mark3 , PB_Mark4 , PB_Mark5 , PB_Mark6 } ;
CheckBox [ ] cba = { CHK_Circle , CHK_Triangle , CHK_Square , CHK_Heart , CHK_Star , CHK_Diamond } ;
CheckBox cb = cba [ Array . IndexOf ( pba , sender as PictureBox ) ] ;
cb . Checked = ! cb . Checked ;
setMarkings ( ) ;
}
2014-12-14 19:06:17 +00:00
private void clickOT ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
string OT = Util . TrimFromZero ( Encoding . Unicode . GetString ( savefile , SaveGame . TrainerCard + 0x48 + savindex * 0x7F000 , 0x1A ) ) ;
2015-03-11 01:44:51 +00:00
if ( OT . Length < = 0 ) return ;
TB_OT . Text = OT ;
int savshift = 0x7F000 * savindex ;
// Set Gender Label
int g6trgend = savefile [ SaveGame . TrainerCard + 0x5 + savshift ] ;
Label_OTGender . Text = g6trgend = = 1 ? gendersymbols [ 1 ] : gendersymbols [ 0 ] ;
// Get TID/SID
TB_TID . Text = BitConverter . ToUInt16 ( savefile , SaveGame . TrainerCard + 0 + savshift ) . ToString ( ) ;
TB_SID . Text = BitConverter . ToUInt16 ( savefile , SaveGame . TrainerCard + 2 + savshift ) . ToString ( ) ;
int game = savefile [ SaveGame . TrainerCard + 0x4 + savshift ] ;
int subreg = savefile [ SaveGame . TrainerCard + 0x26 + savshift ] ;
int country = savefile [ SaveGame . TrainerCard + 0x27 + savshift ] ;
int _3DSreg = savefile [ SaveGame . TrainerCard + 0x2C + savshift ] ;
int lang = savefile [ SaveGame . TrainerCard + 0x2D + savshift ] ;
// CB_GameOrigin.SelectedValue = game;
CB_GameOrigin . SelectedValue = game ;
CB_SubRegion . SelectedValue = subreg ;
CB_Country . SelectedValue = country ;
CB_3DSReg . SelectedValue = _3DSreg ;
CB_Language . SelectedValue = lang ;
updateNickname ( null , null ) ;
2014-12-13 22:48:34 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickCT ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
2014-12-20 19:27:29 +00:00
if ( TB_OTt2 . Text . Length > 0 )
Label_CTGender . Text = gendersymbols [ savefile [ 0x19405 + savindex * 0x7F000 ] ] ;
}
private void clickGT ( object sender , EventArgs e )
{
if ( sender as GroupBox = = GB_OT )
{
buff [ 0x93 ] = 0 ;
TB_Friendship . Text = buff [ 0xCA ] . ToString ( ) ;
GB_OT . BackgroundImage = mixedHighlight ;
GB_nOT . BackgroundImage = null ;
}
else if ( TB_OTt2 . Text . Length > 0 )
{
buff [ 0x93 ] = 1 ;
TB_Friendship . Text = buff [ 0xA2 ] . ToString ( ) ;
GB_OT . BackgroundImage = null ;
GB_nOT . BackgroundImage = mixedHighlight ;
}
2014-12-13 22:48:34 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickTRGender ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
Label lbl = sender as Label ;
2015-03-11 01:44:51 +00:00
if ( lbl . Text ! = "" ) // set gender label (toggle M/F)
2015-08-07 04:16:25 +00:00
{
int gender = PKX . getGender ( lbl . Text ) ^ 1 ;
lbl . Text = gendersymbols [ gender ] ;
lbl . ForeColor = ( ( gender = = 1 ) ? Color . Red : Color . Blue ) ;
}
2014-12-13 22:48:34 +00:00
}
2015-06-28 21:34:38 +00:00
private void clickMoves ( object sender , EventArgs e )
{
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Copy current moves to Relearn Moves?" ) )
return ;
CB_RelearnMove1 . SelectedIndex = CB_Move1 . SelectedIndex > 0 ? CB_Move1 . SelectedIndex : 0 ;
CB_RelearnMove2 . SelectedIndex = CB_Move2 . SelectedIndex > 0 ? CB_Move2 . SelectedIndex : 0 ;
CB_RelearnMove3 . SelectedIndex = CB_Move3 . SelectedIndex > 0 ? CB_Move3 . SelectedIndex : 0 ;
CB_RelearnMove4 . SelectedIndex = CB_Move4 . SelectedIndex > 0 ? CB_Move4 . SelectedIndex : 0 ;
}
2014-12-13 22:48:34 +00:00
// Prompted Updates of PKX Functions //
2015-03-11 01:44:51 +00:00
private bool changingFields ;
2014-12-13 22:48:34 +00:00
private void updateEXPLevel ( object sender , EventArgs e )
{
2015-03-09 00:41:13 +00:00
if ( changingFields ) return ;
2014-12-20 04:22:15 +00:00
if ( sender as MaskedTextBox = = TB_EXP )
2014-12-13 22:48:34 +00:00
{
2015-03-09 00:41:13 +00:00
changingFields = true ;
2014-12-13 22:48:34 +00:00
// Change the Level
uint exp = Util . ToUInt32 ( TB_EXP ) ;
2014-12-20 04:22:15 +00:00
int level = ( Util . ToInt32 ( TB_EXP . Text ) = = 0 ) ? 1 : PKX . getLevel ( Util . getIndex ( CB_Species ) , ref exp ) ;
2014-12-13 22:48:34 +00:00
TB_Level . Text = level . ToString ( ) ;
2014-12-20 04:22:15 +00:00
if ( ! MT_Level . Visible )
2014-12-13 22:48:34 +00:00
TB_EXP . Text = exp . ToString ( ) ;
2014-12-20 04:22:15 +00:00
else
2014-12-13 22:48:34 +00:00
MT_Level . Text = level . ToString ( ) ;
}
2014-12-20 04:22:15 +00:00
else
2014-12-13 22:48:34 +00:00
{
2015-03-09 00:41:13 +00:00
changingFields = true ;
2014-12-13 22:48:34 +00:00
// Change the XP
2014-12-20 04:22:15 +00:00
int level = Util . ToInt32 ( ( MT_Level . Focused ? MT_Level : TB_Level ) . Text ) ;
if ( level > 100 ) TB_Level . Text = "100" ;
if ( level > 255 ) MT_Level . Text = "255" ;
2014-12-13 22:48:34 +00:00
TB_EXP . Text = PKX . getEXP ( level , Util . getIndex ( CB_Species ) ) . ToString ( ) ;
}
2015-03-09 00:41:13 +00:00
changingFields = false ;
2014-12-13 22:48:34 +00:00
updateStats ( ) ;
}
2015-03-09 00:41:13 +00:00
private void updateHPType ( object sender , EventArgs e )
{
if ( changingFields ) return ;
changingFields = true ;
2015-03-11 01:44:51 +00:00
int [ ] ivs =
{
2015-03-09 00:41:13 +00:00
Util . ToInt32 ( TB_HPIV . Text ) , Util . ToInt32 ( TB_ATKIV . Text ) , Util . ToInt32 ( TB_DEFIV . Text ) ,
2015-03-11 01:44:51 +00:00
Util . ToInt32 ( TB_SPAIV . Text ) , Util . ToInt32 ( TB_SPDIV . Text ) , Util . ToInt32 ( TB_SPEIV . Text )
} ;
2015-03-09 00:41:13 +00:00
// Change IVs to match the new Hidden Power
int [ ] newIVs = PKX . setHPIVs ( Util . getIndex ( CB_HPType ) , ivs ) ;
TB_HPIV . Text = newIVs [ 0 ] . ToString ( ) ;
TB_ATKIV . Text = newIVs [ 1 ] . ToString ( ) ;
TB_DEFIV . Text = newIVs [ 2 ] . ToString ( ) ;
TB_SPAIV . Text = newIVs [ 3 ] . ToString ( ) ;
TB_SPDIV . Text = newIVs [ 4 ] . ToString ( ) ;
TB_SPEIV . Text = newIVs [ 5 ] . ToString ( ) ;
// Refresh View
changingFields = false ;
updateIVs ( null , null ) ;
}
2014-12-13 22:48:34 +00:00
private void updateIVs ( object sender , EventArgs e )
{
2015-03-09 00:41:13 +00:00
if ( changingFields ) return ;
2014-12-13 22:48:34 +00:00
if ( sender ! = null )
if ( Util . ToInt32 ( ( sender as MaskedTextBox ) . Text ) > 31 )
( sender as MaskedTextBox ) . Text = "31" ;
2014-06-28 21:22:05 +00:00
2015-03-11 01:44:51 +00:00
int [ ] ivs =
{
2015-03-04 02:57:08 +00:00
Util . ToInt32 ( TB_HPIV . Text ) , Util . ToInt32 ( TB_ATKIV . Text ) , Util . ToInt32 ( TB_DEFIV . Text ) ,
2015-09-05 20:56:46 +00:00
Util . ToInt32 ( TB_SPEIV . Text ) , Util . ToInt32 ( TB_SPAIV . Text ) , Util . ToInt32 ( TB_SPDIV . Text )
2015-03-11 01:44:51 +00:00
} ;
2015-03-09 00:41:13 +00:00
changingFields = true ;
CB_HPType . SelectedValue = PKX . getHPType ( ivs ) ;
changingFields = false ;
2014-06-28 21:22:05 +00:00
2015-03-04 02:57:08 +00:00
int ivtotal = ivs . Sum ( ) ;
2014-12-13 22:48:34 +00:00
TB_IVTotal . Text = ivtotal . ToString ( ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Potential Reading
if ( ! unicode )
{
if ( ivtotal < = 90 )
L_Potential . Text = "★☆☆☆" ;
else if ( ivtotal < = 120 )
L_Potential . Text = "★★☆☆" ;
else if ( ivtotal < = 150 )
L_Potential . Text = "★★★☆" ;
else
L_Potential . Text = "★★★★" ;
}
else
{
if ( ivtotal < = 90 )
L_Potential . Text = "+" ;
else if ( ivtotal < = 120 )
L_Potential . Text = "++" ;
else if ( ivtotal < = 150 )
L_Potential . Text = "+++" ;
else
L_Potential . Text = "++++" ;
}
2014-06-28 21:22:05 +00:00
2015-01-31 23:59:23 +00:00
// Characteristic with EC%6
int pm6 = ( int ) ( Util . getHEXval ( TB_EC ) % 6 ) ; // EC MOD 6
2015-03-04 02:57:08 +00:00
int maxIV = ivs . Max ( ) ;
2014-12-13 22:48:34 +00:00
int pm6stat = 0 ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
for ( int i = 0 ; i < 6 ; i + + )
{
pm6stat = ( pm6 + i ) % 6 ;
2015-03-04 02:57:08 +00:00
if ( ivs [ pm6stat ] = = maxIV )
2015-01-31 23:59:23 +00:00
break ; // P%6 is this stat
2014-12-13 22:48:34 +00:00
}
2014-06-28 21:22:05 +00:00
2015-09-05 20:56:46 +00:00
L_Characteristic . Text = characteristics [ pm6stat * 5 + maxIV % 5 ] ;
2014-12-13 22:48:34 +00:00
updateStats ( ) ;
}
private void updateEVs ( object sender , EventArgs e )
{
if ( sender ! = null )
if ( Util . ToInt32 ( ( sender as MaskedTextBox ) . Text ) > 252 )
( sender as MaskedTextBox ) . Text = "252" ;
2015-03-11 01:44:51 +00:00
int HP_EV = Util . ToInt32 ( TB_HPEV . Text ) ;
int ATK_EV = Util . ToInt32 ( TB_ATKEV . Text ) ;
int DEF_EV = Util . ToInt32 ( TB_DEFEV . Text ) ;
int SPA_EV = Util . ToInt32 ( TB_SPAEV . Text ) ;
int SPD_EV = Util . ToInt32 ( TB_SPDEV . Text ) ;
int SPE_EV = Util . ToInt32 ( TB_SPEEV . Text ) ;
2014-12-13 22:48:34 +00:00
2015-03-11 01:44:51 +00:00
int evtotal = HP_EV + ATK_EV + DEF_EV + SPA_EV + SPD_EV + SPE_EV ;
2014-12-13 22:48:34 +00:00
if ( evtotal > 510 ) // Background turns Red
2015-01-01 19:38:37 +00:00
TB_EVTotal . BackColor = Color . Red ;
2014-12-13 22:48:34 +00:00
else if ( evtotal = = 510 ) // Maximum EVs
2015-01-01 19:38:37 +00:00
TB_EVTotal . BackColor = Color . Honeydew ;
2014-12-13 22:48:34 +00:00
else TB_EVTotal . BackColor = Color . WhiteSmoke ;
TB_EVTotal . Text = evtotal . ToString ( ) ;
updateStats ( ) ;
}
private void updateRandomIVs ( object sender , EventArgs e )
{
2015-03-12 15:25:27 +00:00
if ( ModifierKeys = = Keys . Control | | ModifierKeys = = Keys . Shift )
2014-12-13 22:48:34 +00:00
{
// Max IVs
TB_HPIV . Text = 31. ToString ( ) ;
TB_ATKIV . Text = 31. ToString ( ) ;
TB_DEFIV . Text = 31. ToString ( ) ;
TB_SPAIV . Text = 31. ToString ( ) ;
TB_SPDIV . Text = 31. ToString ( ) ;
TB_SPEIV . Text = 31. ToString ( ) ;
}
else
{
TB_HPIV . Text = ( Util . rnd32 ( ) & 0x1F ) . ToString ( ) ;
TB_ATKIV . Text = ( Util . rnd32 ( ) & 0x1F ) . ToString ( ) ;
TB_DEFIV . Text = ( Util . rnd32 ( ) & 0x1F ) . ToString ( ) ;
TB_SPAIV . Text = ( Util . rnd32 ( ) & 0x1F ) . ToString ( ) ;
TB_SPDIV . Text = ( Util . rnd32 ( ) & 0x1F ) . ToString ( ) ;
TB_SPEIV . Text = ( Util . rnd32 ( ) & 0x1F ) . ToString ( ) ;
}
}
private void updateRandomEVs ( object sender , EventArgs e )
{
2015-03-12 15:25:27 +00:00
if ( ModifierKeys = = Keys . Control | | ModifierKeys = = Keys . Shift )
2014-12-13 22:48:34 +00:00
{
// Max IVs
TB_HPEV . Text = 0. ToString ( ) ;
TB_ATKEV . Text = 0. ToString ( ) ;
TB_DEFEV . Text = 0. ToString ( ) ;
TB_SPAEV . Text = 0. ToString ( ) ;
TB_SPDEV . Text = 0. ToString ( ) ;
TB_SPEEV . Text = 0. ToString ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
else
{
byte [ ] evs = PKX . getRandomEVs ( ) ;
TB_HPEV . Text = evs [ 0 ] . ToString ( ) ;
TB_ATKEV . Text = evs [ 1 ] . ToString ( ) ;
TB_DEFEV . Text = evs [ 2 ] . ToString ( ) ;
TB_SPAEV . Text = evs [ 3 ] . ToString ( ) ;
TB_SPDEV . Text = evs [ 4 ] . ToString ( ) ;
TB_SPEEV . Text = evs [ 5 ] . ToString ( ) ;
}
}
private void updateRandomPID ( object sender , EventArgs e )
{
2014-12-14 20:15:53 +00:00
TB_PID . Text = PKX . getRandomPID ( Util . getIndex ( CB_Species ) , PKX . getGender ( Label_Gender . Text ) ) . ToString ( "X8" ) ;
getQuickFiller ( dragout ) ;
2014-12-13 22:48:34 +00:00
}
private void updateRandomEC ( object sender , EventArgs e )
{
TB_EC . Text = Util . rnd32 ( ) . ToString ( "X8" ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateHackedStats ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
Stat_HP . Enabled =
Stat_ATK . Enabled =
Stat_DEF . Enabled =
Stat_SPA . Enabled =
Stat_SPD . Enabled =
Stat_SPE . Enabled = CHK_HackedStats . Checked ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
private void update255_MTB ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
MaskedTextBox mtb = sender as MaskedTextBox ;
try
{
if ( Util . ToInt32 ( ( sender as MaskedTextBox ) . Text ) > 255 )
( sender as MaskedTextBox ) . Text = "255" ;
}
catch { mtb . Text = "0" ; }
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
private void update255_TB ( object sender , EventArgs e )
2014-07-12 01:39:24 +00:00
{
2014-12-13 22:48:34 +00:00
TextBox tb = sender as TextBox ;
try
2014-07-12 01:39:24 +00:00
{
2014-12-13 22:48:34 +00:00
if ( Util . ToInt32 ( ( sender as TextBox ) . Text ) > 255 )
( sender as TextBox ) . Text = "255" ;
2014-07-12 01:39:24 +00:00
}
2014-12-13 22:48:34 +00:00
catch { tb . Text = "0" ; }
2014-07-12 01:39:24 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateForm ( object sender , EventArgs e )
2014-12-12 05:44:05 +00:00
{
2014-12-13 22:48:34 +00:00
updateStats ( ) ;
// Repopulate Abilities if Species Form has different abilities
2014-12-24 07:29:57 +00:00
setAbilityList ( TB_AbilityNumber , Util . getIndex ( CB_Species ) , CB_Ability , CB_Form ) ;
2014-12-13 22:48:34 +00:00
// Gender Forms
2015-01-28 06:59:53 +00:00
if ( PKX . getGender ( CB_Form . Text ) < 2 & & Util . getIndex ( CB_Species ) ! = 201 ) // don't do this for Unown
2014-12-13 22:48:34 +00:00
Label_Gender . Text = CB_Form . Text ;
2014-12-12 05:44:05 +00:00
}
2014-12-13 22:48:34 +00:00
private void updatePP ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
TB_PP1 . Text = ( PKX . getMovePP ( Util . getIndex ( CB_Move1 ) , CB_PPu1 . SelectedIndex ) ) . ToString ( ) ;
TB_PP2 . Text = ( PKX . getMovePP ( Util . getIndex ( CB_Move2 ) , CB_PPu2 . SelectedIndex ) ) . ToString ( ) ;
TB_PP3 . Text = ( PKX . getMovePP ( Util . getIndex ( CB_Move3 ) , CB_PPu3 . SelectedIndex ) ) . ToString ( ) ;
TB_PP4 . Text = ( PKX . getMovePP ( Util . getIndex ( CB_Move4 ) , CB_PPu4 . SelectedIndex ) ) . ToString ( ) ;
}
private void updatePKRSstrain ( object sender , EventArgs e )
{
2015-03-14 02:59:51 +00:00
// Change the PKRS Days to the legal bounds.
int currentDuration = CB_PKRSDays . SelectedIndex ;
CB_PKRSDays . Items . Clear ( ) ;
2015-04-03 01:44:03 +00:00
int [ ] days = Enumerable . Range ( 0 , CB_PKRSStrain . SelectedIndex % 4 + 2 ) . Select ( i = > i ) . ToArray ( ) ;
2015-03-14 02:59:51 +00:00
foreach ( int day in days ) CB_PKRSDays . Items . Add ( day ) ;
// Set the days back if they're legal, else set it to 1. (0 always passes).
CB_PKRSDays . SelectedIndex = ( currentDuration < CB_PKRSDays . Items . Count ) ? currentDuration : 1 ;
2015-03-12 04:44:12 +00:00
if ( CB_PKRSStrain . SelectedIndex ! = 0 ) return ;
2015-03-14 02:59:51 +00:00
2015-03-12 04:44:12 +00:00
// Never Infected
2015-04-03 01:44:03 +00:00
CB_PKRSDays . SelectedIndex = 0 ;
2015-03-12 04:44:12 +00:00
CHK_Cured . Checked = false ;
CHK_Infected . Checked = false ;
}
private void updatePKRSdays ( object sender , EventArgs e )
{
if ( CB_PKRSDays . SelectedIndex ! = 0 ) return ;
// If no days are selected
2014-12-13 22:48:34 +00:00
if ( CB_PKRSStrain . SelectedIndex = = 0 )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
// Never Infected
CHK_Cured . Checked = false ;
CHK_Infected . Checked = false ;
2014-06-28 21:22:05 +00:00
}
2015-03-12 04:44:12 +00:00
else CHK_Cured . Checked = true ;
2014-06-28 21:22:05 +00:00
}
2014-12-26 18:46:18 +00:00
private void updatePKRSCured ( object sender , EventArgs e )
{
if ( ! init ) return ;
// Cured PokeRus is toggled
if ( CHK_Cured . Checked )
{
// Has Had PokeRus
Label_PKRSdays . Visible = CB_PKRSDays . Visible = false ;
CB_PKRSDays . SelectedIndex = 0 ;
Label_PKRS . Visible = CB_PKRSStrain . Visible = true ;
CHK_Infected . Checked = true ;
// If we're cured we have to have a strain infection.
if ( CB_PKRSStrain . SelectedIndex = = 0 )
CB_PKRSStrain . SelectedIndex = 1 ;
}
else if ( ! CHK_Infected . Checked )
{
// Not Infected, Disable the other
Label_PKRS . Visible = CB_PKRSStrain . Visible = false ;
CB_PKRSStrain . SelectedIndex = 0 ;
}
else
{
// Still Infected for a duration
Label_PKRSdays . Visible = CB_PKRSDays . Visible = true ;
CB_PKRSDays . SelectedValue = 1 ;
}
// if not cured yet, days > 0
if ( ! CHK_Cured . Checked & & CHK_Infected . Checked & & CB_PKRSDays . SelectedIndex = = 0 )
CB_PKRSDays . SelectedIndex + + ;
setMarkings ( ) ;
}
private void updatePKRSInfected ( object sender , EventArgs e )
{
if ( ! init ) return ;
2015-01-27 06:05:04 +00:00
if ( CHK_Cured . Checked & & ! CHK_Infected . Checked ) { CHK_Cured . Checked = false ; return ; }
2015-03-11 01:44:51 +00:00
if ( CHK_Cured . Checked ) return ;
2014-12-26 18:46:18 +00:00
Label_PKRS . Visible = CB_PKRSStrain . Visible = CHK_Infected . Checked ;
if ( ! CHK_Infected . Checked ) { CB_PKRSStrain . SelectedIndex = 0 ; CB_PKRSDays . SelectedIndex = 0 ; Label_PKRSdays . Visible = CB_PKRSDays . Visible = false ; }
2015-06-30 03:09:34 +00:00
else if ( CB_PKRSStrain . SelectedIndex = = 0 ) { CB_PKRSStrain . SelectedIndex = 1 ; Label_PKRSdays . Visible = CB_PKRSDays . Visible = true ; updatePKRSCured ( sender , e ) ; }
2014-12-26 18:46:18 +00:00
// if not cured yet, days > 0
2015-03-11 01:44:51 +00:00
if ( CHK_Infected . Checked & & CB_PKRSDays . SelectedIndex = = 0 ) CB_PKRSDays . SelectedIndex + + ;
2014-12-26 18:46:18 +00:00
}
2014-12-24 07:29:57 +00:00
private void updateCountry ( object sender , EventArgs e )
{
if ( Util . getIndex ( sender as ComboBox ) > 0 )
setCountrySubRegion ( CB_SubRegion , "sr_" + Util . getIndex ( sender as ComboBox ) . ToString ( "000" ) ) ;
}
2014-12-13 22:48:34 +00:00
private void updateSpecies ( object sender , EventArgs e )
{
// Change Species Prompted
int species = Util . getIndex ( CB_Species ) ;
int level = Util . ToInt32 ( TB_Level . Text ) ;
if ( MT_Level . Visible ) level = Util . ToInt32 ( MT_Level . Text ) ;
// Get Forms for Given Species
2015-03-08 08:48:57 +00:00
setForms ( species , CB_Form , Label_Form ) ;
2014-12-13 22:48:34 +00:00
// Recalculate EXP for Given Level
uint exp = PKX . getEXP ( level , species ) ;
TB_EXP . Text = exp . ToString ( ) ;
// Check for Gender Changes
// Get Gender Threshold
species = Util . getIndex ( CB_Species ) ;
PKX . PersonalParser . Personal MonData = PKX . PersonalGetter . GetPersonal ( species ) ;
2015-01-03 01:07:29 +00:00
int gt = MonData . GenderRatio ;
int genderflag ;
2014-12-13 22:48:34 +00:00
if ( gt = = 255 ) // Genderless
genderflag = 2 ;
else if ( gt = = 254 ) // Female Only
genderflag = 1 ;
else if ( gt = = 0 ) // Male Only
genderflag = 0 ;
else // get gender from old PID correlation
genderflag = ( ( Util . getHEXval ( TB_PID ) & 0xFF ) < = gt ) ? 1 : 0 ;
Label_Gender . Text = gendersymbols [ genderflag ] ;
2015-08-07 04:16:25 +00:00
Label_Gender . ForeColor = ( genderflag = = 2 ) ? Label_Species . ForeColor : ( ( genderflag = = 1 ) ? Color . Red : Color . Blue ) ;
2014-12-24 07:29:57 +00:00
setAbilityList ( TB_AbilityNumber , Util . getIndex ( CB_Species ) , CB_Ability , CB_Form ) ;
2014-12-13 22:48:34 +00:00
updateForm ( null , null ) ;
// If species changes and no nickname, set the new name == speciesName.
if ( ! CHK_Nicknamed . Checked )
updateNickname ( sender , e ) ;
}
private void updateOriginGame ( object sender , EventArgs e )
{
int gameorigin = Util . getIndex ( CB_GameOrigin ) ;
2015-01-01 19:38:37 +00:00
if ( gameorigin < 24 & & origintrack ! = "Past" )
2014-06-28 21:22:05 +00:00
{
2014-12-24 07:29:57 +00:00
// Load Past Gen Locations
#region B2W2 Met Locations
2014-12-13 22:48:34 +00:00
{
2014-12-14 18:31:53 +00:00
// Build up our met list
2015-03-11 01:44:51 +00:00
var met_list = Util . getCBList ( metBW2_00000 , new [ ] { 0 } ) ;
met_list = Util . getOffsetCBList ( met_list , metBW2_60000 , 60001 , new [ ] { 60002 } ) ;
met_list = Util . getOffsetCBList ( met_list , metBW2_30000 , 30001 , new [ ] { 30003 } ) ;
2014-12-14 18:31:53 +00:00
met_list = Util . getOffsetCBList ( met_list , metBW2_00000 , 00000 , Legal . Met_BW2_0 ) ;
met_list = Util . getOffsetCBList ( met_list , metBW2_30000 , 30001 , Legal . Met_BW2_3 ) ;
met_list = Util . getOffsetCBList ( met_list , metBW2_40000 , 40001 , Legal . Met_BW2_4 ) ;
met_list = Util . getOffsetCBList ( met_list , metBW2_60000 , 60001 , Legal . Met_BW2_6 ) ;
2014-12-13 22:48:34 +00:00
CB_MetLocation . DisplayMember = "Text" ;
CB_MetLocation . ValueMember = "Value" ;
2015-01-31 18:36:06 +00:00
CB_MetLocation . DataSource = met_list ;
2014-12-13 22:48:34 +00:00
CB_EggLocation . DisplayMember = "Text" ;
CB_EggLocation . ValueMember = "Value" ;
2015-01-31 18:36:06 +00:00
CB_EggLocation . DataSource = new BindingSource ( met_list , null ) ;
2014-12-13 22:48:34 +00:00
CB_EggLocation . SelectedValue = 0 ;
2015-03-11 01:44:51 +00:00
CB_MetLocation . SelectedValue = gameorigin < 20 ? 30001 : 60001 ;
2014-12-14 18:31:53 +00:00
origintrack = "Past" ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
#endregion
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
else if ( gameorigin > 23 & & ( origintrack ! = "XY" ) )
2014-06-28 21:22:05 +00:00
{
2014-12-24 07:29:57 +00:00
// Load X/Y/OR/AS locations
#region ORAS Met Locations
2014-12-13 22:48:34 +00:00
{
2014-12-14 18:31:53 +00:00
// Build up our met list
2015-03-11 01:44:51 +00:00
var met_list = Util . getCBList ( metXY_00000 , new [ ] { 0 } ) ;
met_list = Util . getOffsetCBList ( met_list , metXY_60000 , 60001 , new [ ] { 60002 } ) ;
met_list = Util . getOffsetCBList ( met_list , metXY_30000 , 30001 , new [ ] { 30002 } ) ;
2014-12-14 18:31:53 +00:00
met_list = Util . getOffsetCBList ( met_list , metXY_00000 , 00000 , Legal . Met_XY_0 ) ;
met_list = Util . getOffsetCBList ( met_list , metXY_30000 , 30001 , Legal . Met_XY_3 ) ;
met_list = Util . getOffsetCBList ( met_list , metXY_40000 , 40001 , Legal . Met_XY_4 ) ;
met_list = Util . getOffsetCBList ( met_list , metXY_60000 , 60001 , Legal . Met_XY_6 ) ;
2014-12-13 22:48:34 +00:00
CB_MetLocation . DisplayMember = "Text" ;
CB_MetLocation . ValueMember = "Value" ;
2015-01-31 18:36:06 +00:00
CB_MetLocation . DataSource = met_list ;
2014-12-13 22:48:34 +00:00
CB_EggLocation . DisplayMember = "Text" ;
CB_EggLocation . ValueMember = "Value" ;
2015-01-31 18:36:06 +00:00
CB_EggLocation . DataSource = new BindingSource ( met_list , null ) ;
2014-12-13 22:48:34 +00:00
CB_EggLocation . SelectedValue = 0 ;
CB_MetLocation . SelectedValue = 0 ;
2014-12-14 18:31:53 +00:00
origintrack = "XY" ;
2014-12-13 22:48:34 +00:00
}
#endregion
}
2015-01-28 07:12:18 +00:00
if ( gameorigin < 0x10 & & origintrack ! = "Gen4" )
2014-12-24 07:29:57 +00:00
{
// Load Gen 4 egg locations if Gen 4 Origin.
2014-12-13 22:48:34 +00:00
#region HGSS Met Locations
2015-03-11 01:44:51 +00:00
var met_list = Util . getCBList ( metHGSS_00000 , new [ ] { 0 } ) ;
met_list = Util . getOffsetCBList ( met_list , metHGSS_02000 , 2000 , new [ ] { 2000 } ) ;
met_list = Util . getOffsetCBList ( met_list , metHGSS_02000 , 2000 , new [ ] { 2002 } ) ;
met_list = Util . getOffsetCBList ( met_list , metHGSS_03000 , 3000 , new [ ] { 3001 } ) ;
2014-12-14 18:31:53 +00:00
met_list = Util . getOffsetCBList ( met_list , metHGSS_00000 , 0000 , Legal . Met_HGSS_0 ) ;
met_list = Util . getOffsetCBList ( met_list , metHGSS_02000 , 2000 , Legal . Met_HGSS_2 ) ;
met_list = Util . getOffsetCBList ( met_list , metHGSS_03000 , 3000 , Legal . Met_HGSS_3 ) ;
2014-12-13 22:48:34 +00:00
CB_EggLocation . DisplayMember = "Text" ;
CB_EggLocation . ValueMember = "Value" ;
2015-01-31 18:36:06 +00:00
CB_EggLocation . DataSource = met_list ;
2014-12-13 22:48:34 +00:00
CB_EggLocation . SelectedValue = 0 ;
2014-12-14 18:31:53 +00:00
origintrack = "Gen4" ;
2014-12-13 22:48:34 +00:00
#endregion
2014-06-28 21:22:05 +00:00
}
2014-12-17 02:56:08 +00:00
2014-12-24 07:29:57 +00:00
// Visibility logic for Gen 4 encounter type; only show for Gen 4 Pokemon.
2014-12-17 02:56:08 +00:00
CB_EncounterType . Visible = Label_EncounterType . Visible = ! ( gameorigin > 12 | | gameorigin < 7 ) ;
2014-12-24 07:29:57 +00:00
// If not Gen 4, set Encounter Type to 0 after it set !visible.
2014-12-17 02:56:08 +00:00
if ( gameorigin > 12 | | gameorigin < 7 )
CB_EncounterType . SelectedValue = 0 ;
2014-12-24 07:29:57 +00:00
setMarkings ( ) ; // Set/Remove KB marking
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateExtraByteValue ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
// Changed Extra Byte's Value
if ( Util . ToInt32 ( ( sender as MaskedTextBox ) . Text ) > 255 )
( sender as MaskedTextBox ) . Text = "255" ;
int value = Util . ToInt32 ( TB_ExtraByte . Text ) ;
int offset = Convert . ToInt32 ( CB_ExtraBytes . Text , 16 ) ;
buff [ offset ] = ( byte ) value ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateExtraByteIndex ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
// Byte changed, need to refresh the Text box for the byte's value.
TB_ExtraByte . Text = buff [ Convert . ToInt32 ( CB_ExtraBytes . Text , 16 ) ] . ToString ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateNickname ( object sender , EventArgs e )
2014-08-15 22:28:33 +00:00
{
2015-03-17 02:25:59 +00:00
if ( init & & ModifierKeys = = Keys . Control ) { getShowdownSet ( ) ; return ; }
2015-03-11 01:44:51 +00:00
if ( ! init | | ( CHK_Nicknamed . Checked ) ) return ;
// Fetch Current Species and set it as Nickname Text
int species = Util . getIndex ( CB_Species ) ;
if ( species = = 0 | | species > 721 )
TB_Nickname . Text = "" ;
else
2014-08-15 22:28:33 +00:00
{
2015-03-11 01:44:51 +00:00
// get language
int lang = Util . getIndex ( CB_Language ) ;
2014-12-13 22:48:34 +00:00
2015-03-11 01:44:51 +00:00
string l ;
switch ( lang )
{
case 1 : l = "ja" ; break ;
case 2 : l = "en" ; break ;
case 3 : l = "fr" ; break ;
case 4 : l = "it" ; break ;
case 5 : l = "de" ; break ;
case 7 : l = "es" ; break ;
case 8 : l = "ko" ; break ;
default : l = curlanguage ; break ;
2014-08-15 22:28:33 +00:00
}
2015-03-11 01:44:51 +00:00
if ( CHK_IsEgg . Checked ) species = 0 ; // Set species to 0 to get the egg name.
TB_Nickname . Text = Util . getStringList ( "Species" , l ) [ ( CHK_IsEgg . Checked ) ? 0 : species ] ;
2014-08-15 22:28:33 +00:00
}
}
2014-12-13 22:48:34 +00:00
private void updateNicknameClick ( object sender , MouseEventArgs e )
2014-08-15 22:28:33 +00:00
{
2015-01-28 07:28:44 +00:00
TextBox tb = ( ! ( sender is TextBox ) ) ? TB_Nickname : ( sender as TextBox ) ;
2014-12-13 22:48:34 +00:00
// Special Character Form
2015-01-28 07:28:44 +00:00
if ( ModifierKeys = = Keys . Control & & ! specialChars )
( new f2_Text ( tb ) ) . Show ( ) ;
2014-08-15 22:28:33 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateNotOT ( object sender , EventArgs e )
2014-08-31 20:32:04 +00:00
{
2014-12-13 22:48:34 +00:00
if ( TB_OTt2 . Text = = "" )
2014-08-31 20:32:04 +00:00
{
2015-02-07 20:22:09 +00:00
clickGT ( GB_OT , null ) ; // Switch CT over to OT.
2014-12-13 22:48:34 +00:00
Label_CTGender . Text = "" ;
TB_Friendship . Text = buff [ 0xCA ] . ToString ( ) ;
2014-08-31 20:32:04 +00:00
}
2014-12-13 22:48:34 +00:00
else if ( Label_CTGender . Text = = "" )
Label_CTGender . Text = gendersymbols [ 0 ] ;
2014-08-31 20:32:04 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateIsEgg ( object sender , EventArgs e )
{
if ( CHK_IsEgg . Checked )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
CHK_Nicknamed . Checked = false ;
TB_Friendship . Text = "1" ;
2014-12-12 05:44:05 +00:00
2014-12-13 22:48:34 +00:00
// If we are an egg, it won't have a met location.
CHK_AsEgg . Checked = true ;
GB_EggConditions . Enabled = true ;
CAL_MetDate . Value = new DateTime ( 2000 , 01 , 01 ) ;
CB_MetLocation . SelectedIndex = 2 ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
else // Not Egg
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
if ( ! CHK_Nicknamed . Checked )
updateNickname ( null , null ) ;
TB_Friendship . Text = PKX . getBaseFriendship ( Util . getIndex ( CB_Species ) ) . ToString ( ) ;
2015-01-01 19:38:37 +00:00
2014-12-13 22:48:34 +00:00
if ( CB_EggLocation . SelectedIndex = = 0 )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
CAL_EggDate . Value = new DateTime ( 2000 , 01 , 01 ) ;
CHK_AsEgg . Checked = false ;
GB_EggConditions . Enabled = false ;
2014-06-28 21:22:05 +00:00
}
}
2014-12-13 22:48:34 +00:00
// Display hatch counter if it is an egg, Display Friendship if it is not.
Label_HatchCounter . Visible = CHK_IsEgg . Checked ;
Label_Friendship . Visible = ! CHK_IsEgg . Checked ;
2014-12-20 19:27:29 +00:00
// Update image to (not) show egg.
2015-03-11 01:44:51 +00:00
if ( ! init ) return ;
updateNickname ( null , null ) ;
getQuickFiller ( dragout ) ;
2014-12-13 22:48:34 +00:00
}
private void updateMetAsEgg ( object sender , EventArgs e )
{
GB_EggConditions . Enabled = CHK_AsEgg . Checked ;
2015-03-11 01:44:51 +00:00
if ( CHK_AsEgg . Checked ) return ;
// Remove egg met data
CHK_IsEgg . Checked = false ;
CAL_EggDate . Value = new DateTime ( 2000 , 01 , 01 ) ;
CB_EggLocation . SelectedValue = 0 ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateShinyPID ( object sender , EventArgs e )
2014-11-15 05:08:00 +00:00
{
2014-12-13 22:48:34 +00:00
uint PID = Util . getHEXval ( TB_PID ) ;
uint UID = ( PID > > 16 ) ;
uint LID = ( PID & 0xFFFF ) ;
uint PSV = UID ^ LID ;
uint TID = Util . ToUInt32 ( TB_TID ) ;
uint SID = Util . ToUInt32 ( TB_SID ) ;
uint TSV = TID ^ SID ;
uint XOR = TSV ^ PSV ;
2014-11-15 05:08:00 +00:00
2014-12-13 22:48:34 +00:00
// Preserve Gen5 Origin Ability bit just in case
XOR & = 0xFFFE ; XOR | = UID & 1 ;
2014-11-15 05:08:00 +00:00
2014-12-13 22:48:34 +00:00
// New XOR should be 0 or 1.
if ( XOR > 16 )
TB_PID . Text = ( ( ( UID ^ XOR ) < < 16 ) + LID ) . ToString ( "X8" ) ;
setIsShiny ( ) ;
2014-12-14 20:15:53 +00:00
getQuickFiller ( dragout ) ;
2014-11-15 05:08:00 +00:00
}
2014-12-13 22:48:34 +00:00
private void update_ID ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-13 22:48:34 +00:00
// Trim out nonhex characters
TB_PID . Text = Util . getHEXval ( TB_PID ) . ToString ( "X8" ) ;
TB_EC . Text = Util . getHEXval ( TB_EC ) . ToString ( "X8" ) ;
2015-02-26 04:19:43 +00:00
// Max TID/SID is 65535
if ( Util . ToUInt32 ( TB_TID . Text ) > 65535 ) TB_TID . Text = "65535" ;
if ( Util . ToUInt32 ( TB_SID . Text ) > 65535 ) TB_SID . Text = "65535" ;
2015-01-01 19:38:37 +00:00
2014-12-13 22:48:34 +00:00
setIsShiny ( ) ;
2015-02-28 05:51:19 +00:00
getQuickFiller ( dragout ) ;
2014-12-13 22:48:34 +00:00
updateIVs ( null , null ) ; // If the PID is changed, PID%6 (Characteristic) might be changed.
TB_PID . Select ( 60 , 0 ) ; // position cursor at end of field
}
private void validateComboBox ( object sender , CancelEventArgs e )
{
if ( ! ( sender is ComboBox ) ) { return ; }
ComboBox cb = sender as ComboBox ;
cb . SelectionLength = 0 ;
2015-03-11 01:44:51 +00:00
cb . BackColor = cb . SelectedValue = = null ? Color . DarkSalmon : defaultControlWhite ;
2014-12-14 20:15:53 +00:00
if ( init )
2015-02-25 04:10:47 +00:00
{ getQuickFiller ( dragout ) ; }
2014-12-13 22:48:34 +00:00
}
private void validateComboBox2 ( object sender , EventArgs e )
{
ComboBox cb = sender as ComboBox ;
validateComboBox ( sender , e as CancelEventArgs ) ;
if ( cb = = CB_Ability )
TB_AbilityNumber . Text = ( 1 < < CB_Ability . SelectedIndex ) . ToString ( ) ;
else if ( ( cb = = CB_Move1 ) | | ( cb = = CB_Move2 ) | | ( cb = = CB_Move3 ) | | ( cb = = CB_Move4 ) )
updatePP ( sender , e ) ;
2015-02-21 20:59:22 +00:00
getNatureModification ( sender , null ) ;
2014-12-13 22:48:34 +00:00
updateIVs ( null , null ) ; // updating Nature will trigger stats to update as well
}
private void removedropCB ( object sender , KeyEventArgs e )
{
( ( ComboBox ) sender ) . DroppedDown = false ;
}
private void updateStats ( )
{
// Gather the needed information.
2015-01-03 01:07:29 +00:00
int species = Util . getIndex ( CB_Species ) ;
2014-12-13 22:48:34 +00:00
int level = Util . ToInt32 ( ( MT_Level . Enabled ) ? MT_Level . Text : TB_Level . Text ) ;
if ( level = = 0 ) { level = 1 ; }
int form = CB_Form . SelectedIndex ;
int HP_IV = Util . ToInt32 ( TB_HPIV . Text ) ;
int ATK_IV = Util . ToInt32 ( TB_ATKIV . Text ) ;
int DEF_IV = Util . ToInt32 ( TB_DEFIV . Text ) ;
int SPA_IV = Util . ToInt32 ( TB_SPAIV . Text ) ;
int SPD_IV = Util . ToInt32 ( TB_SPDIV . Text ) ;
int SPE_IV = Util . ToInt32 ( TB_SPEIV . Text ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
int HP_EV = Util . ToInt32 ( TB_HPEV . Text ) ;
int ATK_EV = Util . ToInt32 ( TB_ATKEV . Text ) ;
int DEF_EV = Util . ToInt32 ( TB_DEFEV . Text ) ;
int SPA_EV = Util . ToInt32 ( TB_SPAEV . Text ) ;
int SPD_EV = Util . ToInt32 ( TB_SPDEV . Text ) ;
int SPE_EV = Util . ToInt32 ( TB_SPEEV . Text ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
int nature = Util . getIndex ( CB_Nature ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Generate the stats.
ushort [ ] stats = PKX . getStats ( species , level , nature , form ,
HP_EV , ATK_EV , DEF_EV , SPA_EV , SPD_EV , SPE_EV ,
HP_IV , ATK_IV , DEF_IV , SPA_IV , SPD_IV , SPE_IV ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
Stat_HP . Text = stats [ 0 ] . ToString ( ) ;
Stat_ATK . Text = stats [ 1 ] . ToString ( ) ;
Stat_DEF . Text = stats [ 2 ] . ToString ( ) ;
Stat_SPA . Text = stats [ 4 ] . ToString ( ) ;
Stat_SPD . Text = stats [ 5 ] . ToString ( ) ;
Stat_SPE . Text = stats [ 3 ] . ToString ( ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Recolor the Stat Labels based on boosted stats.
{
int incr = nature / 5 ;
int decr = nature % 5 ;
2014-06-28 21:22:05 +00:00
2015-03-11 01:44:51 +00:00
Label [ ] labarray = { Label_ATK , Label_DEF , Label_SPE , Label_SPA , Label_SPD } ;
2014-12-13 22:48:34 +00:00
// Reset Label Colors
foreach ( Label label in labarray )
2014-12-20 04:22:15 +00:00
label . ForeColor = defaultControlText ;
2014-11-19 06:35:39 +00:00
2014-12-13 22:48:34 +00:00
// Set Colored StatLabels only if Nature isn't Neutral
2015-03-11 01:44:51 +00:00
if ( incr = = decr ) return ;
labarray [ incr ] . ForeColor = Color . Red ;
labarray [ decr ] . ForeColor = Color . Blue ;
2014-12-13 22:48:34 +00:00
}
2014-11-19 06:35:39 +00:00
}
2015-03-17 02:25:59 +00:00
private void getShowdownSet ( )
{
if ( ! Clipboard . ContainsText ( ) ) return ;
// Get Simulator Data
PKX . Simulator . Set Set = new PKX . Simulator . Set (
Clipboard . GetText ( ) , // Input Set
Util . getStringList ( "Species" , "en" ) ,
Util . getStringList ( "Items" , "en" ) ,
Util . getStringList ( "Natures" , "en" ) ,
Util . getStringList ( "Moves" , "en" ) ,
Util . getStringList ( "Abilities" , "en" ) ) ;
if ( Set . Species < 0 ) return ;
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Import this set?" , Clipboard . GetText ( ) ) ) return ;
// Set Species & Nickname
CB_Species . SelectedValue = Set . Species ;
2015-03-19 03:45:06 +00:00
CHK_Nicknamed . Checked = ( Set . Nickname ! = null ) ;
if ( Set . Nickname ! = null )
TB_Nickname . Text = Set . Nickname ;
if ( Set . Gender ! = null & & PKX . getGender ( Label_Gender . Text ) ! = 2 & & PKX . getGender ( Set . Gender ) ! = 2 )
Label_Gender . Text = Set . Gender ;
2015-03-17 02:25:59 +00:00
// Set Form
string [ ] formStrings = PKX . getFormList ( Set . Species ,
Util . getStringList ( "Types" , "en" ) ,
Util . getStringList ( "Forms" , "en" ) , gendersymbols ) ;
int form = 0 ;
for ( int i = 0 ; i < formStrings . Length ; i + + )
if ( formStrings [ i ] . Contains ( Set . Form ? ? "" ) )
{ form = i ; break ; }
CB_Form . SelectedIndex = form ;
// Set Ability
byte [ ] abilities = PKX . getAbilities ( Set . Species , form ) ;
int ability = Array . IndexOf ( abilities , ( byte ) Set . Ability ) ;
if ( ability < 0 ) ability = 0 ;
CB_Ability . SelectedIndex = ability ;
ComboBox [ ] m = { CB_Move1 , CB_Move2 , CB_Move3 , CB_Move4 , } ;
for ( int i = 0 ; i < 4 ; i + + ) m [ i ] . SelectedValue = Set . Moves [ i ] ;
// Set Item and Nature
CB_HeldItem . SelectedValue = ( Set . Item < 0 ) ? 0 : Set . Item ;
CB_Nature . SelectedValue = ( Set . Nature < 0 ) ? 0 : Set . Nature ;
// Set IVs
TB_HPIV . Text = Set . IVs [ 0 ] . ToString ( ) ;
TB_ATKIV . Text = Set . IVs [ 1 ] . ToString ( ) ;
TB_DEFIV . Text = Set . IVs [ 2 ] . ToString ( ) ;
TB_SPAIV . Text = Set . IVs [ 3 ] . ToString ( ) ;
TB_SPDIV . Text = Set . IVs [ 4 ] . ToString ( ) ;
TB_SPEIV . Text = Set . IVs [ 5 ] . ToString ( ) ;
// Set EVs
TB_HPEV . Text = Set . EVs [ 0 ] . ToString ( ) ;
TB_ATKEV . Text = Set . EVs [ 1 ] . ToString ( ) ;
TB_DEFEV . Text = Set . EVs [ 2 ] . ToString ( ) ;
TB_SPAEV . Text = Set . EVs [ 3 ] . ToString ( ) ;
TB_SPDEV . Text = Set . EVs [ 4 ] . ToString ( ) ;
TB_SPEEV . Text = Set . EVs [ 5 ] . ToString ( ) ;
// Set Level and Friendship
TB_Level . Text = Set . Level . ToString ( ) ;
TB_Friendship . Text = Set . Friendship . ToString ( ) ;
// Reset IV/EVs
BTN_RerollPID . PerformClick ( ) ;
BTN_RerollEC . PerformClick ( ) ;
if ( Set . Shiny ) BTN_Shinytize . PerformClick ( ) ;
}
2014-06-28 21:22:05 +00:00
// Secondary Windows for Ribbons/Amie/Memories
2014-12-24 07:29:57 +00:00
private void openRibbons ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-06 02:14:04 +00:00
new RibbMedal ( this ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-24 07:29:57 +00:00
private void openHistory ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-06 02:14:04 +00:00
new MemoryAmie ( this ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-22 04:07:04 +00:00
// Open/Save Array Manipulation //
2014-12-24 07:29:57 +00:00
private bool verifiedPKX ( )
2014-06-28 21:22:05 +00:00
{
2014-11-29 19:07:01 +00:00
if ( ModifierKeys = = ( Keys . Control | Keys . Shift | Keys . Alt ) )
2014-11-15 05:08:00 +00:00
return true ; // Override
2014-06-28 21:22:05 +00:00
// Make sure the PKX Fields are filled out properly (color check)
2014-12-24 07:29:57 +00:00
#region ComboBoxes to verify they are set .
2014-06-28 21:22:05 +00:00
ComboBox [ ] cba = {
2014-12-13 22:48:34 +00:00
CB_Species , CB_Nature , CB_HeldItem , CB_Ability , // Main Tab
2014-06-28 21:22:05 +00:00
CB_MetLocation , CB_EggLocation , CB_Ball , // Met Tab
CB_Move1 , CB_Move2 , CB_Move3 , CB_Move4 , // Moves
2014-07-16 19:16:16 +00:00
CB_RelearnMove1 , CB_RelearnMove2 , CB_RelearnMove3 , CB_RelearnMove4 // Moves
2014-06-28 21:22:05 +00:00
} ;
for ( int i = 0 ; i < cba . Length ; i + + )
{
2014-11-28 04:47:50 +00:00
int back = cba [ i ] . BackColor . ToArgb ( ) ;
2015-03-11 01:44:51 +00:00
if ( back = = SystemColors . Control . ToArgb ( ) | | back = = 0 | |
! ( back ! = - 1 & back ! = defaultControlWhite . ToArgb ( ) ) ) continue ;
if ( i < 6 ) // Main Tab
tabMain . SelectedIndex = 0 ;
else if ( i < 9 ) // Met Tab
tabMain . SelectedIndex = 1 ;
else // Moves
tabMain . SelectedIndex = 3 ;
goto invalid ;
2014-06-28 21:22:05 +00:00
}
2014-07-16 19:16:16 +00:00
#endregion
2014-07-12 01:39:24 +00:00
// Further logic checking
2014-08-15 04:27:53 +00:00
if ( Convert . ToUInt32 ( TB_EVTotal . Text ) > 510 & & ! CHK_HackedStats . Checked )
2014-12-06 02:14:04 +00:00
{ tabMain . SelectedIndex = 2 ; goto invalid ; }
2014-07-16 19:16:16 +00:00
// If no errors detected...
2015-03-14 02:59:51 +00:00
if ( Util . getIndex ( CB_Species ) ! = 0 ) return true ;
// Else
tabMain . SelectedIndex = 0 ;
// else...
2015-01-01 19:38:37 +00:00
invalid :
2014-11-28 10:14:15 +00:00
{ System . Media . SystemSounds . Exclamation . Play ( ) ; return false ; }
2014-06-28 21:22:05 +00:00
}
2015-03-14 02:59:51 +00:00
private byte [ ] preparepkx ( bool click = true )
2014-06-28 21:22:05 +00:00
{
2014-12-14 20:15:53 +00:00
if ( click )
tabMain . Select ( ) ; // hack to make sure comboboxes are set (users scrolling through and immediately setting causes this)
2014-12-11 06:50:40 +00:00
// Stuff the global byte array with our PKX form data
2014-06-28 21:22:05 +00:00
// Create a new storage so we don't muck up things with the original
2014-12-14 20:15:53 +00:00
if ( buff . Length = = 232 ) Array . Resize ( ref buff , 260 ) ;
2014-12-11 06:50:40 +00:00
byte [ ] pkx = new byte [ 0x104 ] ;
Array . Copy ( buff , pkx , 0x104 ) ;
2014-06-28 21:22:05 +00:00
// Repopulate PKX with Edited Stuff
2014-10-10 02:59:57 +00:00
if ( Util . getIndex ( CB_GameOrigin ) < 24 )
2014-08-03 05:15:47 +00:00
{
2014-10-10 02:59:57 +00:00
uint EC = Util . getHEXval ( TB_EC ) ;
uint PID = Util . getHEXval ( TB_PID ) ;
uint SID = Util . ToUInt32 ( TB_TID . Text ) ;
uint TID = Util . ToUInt32 ( TB_TID . Text ) ;
2014-08-03 05:15:47 +00:00
uint LID = PID & 0xFFFF ;
uint HID = PID > > 16 ;
uint XOR = ( TID ^ LID ^ SID ^ HID ) ;
// Ensure we don't have a shiny.
2014-12-30 05:43:38 +00:00
if ( XOR > > 3 = = 1 ) // Illegal, fix. (not 16<XOR>=8)
2014-08-03 05:15:47 +00:00
{
// Keep as shiny, so we have to mod the PID
2014-12-30 05:43:38 +00:00
PID ^ = XOR ;
2014-08-03 05:15:47 +00:00
TB_PID . Text = PID . ToString ( "X8" ) ;
TB_EC . Text = PID . ToString ( "X8" ) ;
}
2014-12-30 05:43:38 +00:00
else if ( ( XOR ^ 0x8000 ) > > 3 = = 1 & & PID ! = EC )
2014-08-03 05:15:47 +00:00
TB_EC . Text = ( PID ^ 0x80000000 ) . ToString ( "X8" ) ;
else // Not Illegal, no fix.
TB_EC . Text = PID . ToString ( "X8" ) ;
}
2014-06-28 21:22:05 +00:00
2014-10-10 02:59:57 +00:00
Array . Copy ( BitConverter . GetBytes ( Util . getHEXval ( TB_EC ) ) , 0 , pkx , 0 , 4 ) ; // EC
2014-06-28 21:22:05 +00:00
Array . Copy ( BitConverter . GetBytes ( 0 ) , 0 , pkx , 0x4 , 4 ) ; // 0 CHK for now
// Block A
2014-12-04 01:26:12 +00:00
int species = Util . getIndex ( CB_Species ) ;
Array . Copy ( BitConverter . GetBytes ( species ) , 0 , pkx , 0x08 , 2 ) ; // Species
2014-10-11 07:22:22 +00:00
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_HeldItem ) ) , 0 , pkx , 0x0A , 2 ) ; // Held Item
Array . Copy ( BitConverter . GetBytes ( Util . ToUInt32 ( TB_TID . Text ) ) , 0 , pkx , 0x0C , 2 ) ; // TID
Array . Copy ( BitConverter . GetBytes ( Util . ToUInt32 ( TB_SID . Text ) ) , 0 , pkx , 0x0E , 2 ) ; // SID
2014-06-28 21:22:05 +00:00
Array . Copy ( BitConverter . GetBytes ( Convert . ToUInt32 ( TB_EXP . Text ) ) , 0 , pkx , 0x10 , 4 ) ; // EXP
2014-10-11 07:22:22 +00:00
pkx [ 0x14 ] = ( byte ) Array . IndexOf ( abilitylist , ( CB_Ability . Text ) . Remove ( ( CB_Ability . Text ) . Length - 4 ) ) ; // Ability
2014-10-10 02:59:57 +00:00
pkx [ 0x15 ] = ( byte ) ( Util . ToInt32 ( ( TB_AbilityNumber . Text ) ) ) ; // Number
2014-08-17 01:42:51 +00:00
// pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag)
2014-10-11 07:22:22 +00:00
Array . Copy ( BitConverter . GetBytes ( Util . getHEXval ( TB_PID ) ) , 0 , pkx , 0x18 , 4 ) ; // PID
pkx [ 0x1C ] = ( byte ) ( ( Util . getIndex ( CB_Nature ) ) ) ; // Nature
2015-03-11 01:44:51 +00:00
int fegform = Convert . ToInt32 ( CHK_Fateful . Checked ) ; // Fateful
2014-12-11 06:50:40 +00:00
fegform | = ( PKX . getGender ( Label_Gender . Text ) < < 1 ) ; // Gender
2015-03-17 02:25:59 +00:00
fegform | = ( Math . Min ( ( MT_Form . Enabled ) ? Convert . ToInt32 ( MT_Form . Text ) : CB_Form . SelectedIndex , 32 ) < < 3 ) ; // Form
2014-06-28 21:22:05 +00:00
pkx [ 0x1D ] = ( byte ) fegform ;
2014-12-30 05:43:38 +00:00
pkx [ 0x1E ] = ( byte ) Util . ToInt32 ( TB_HPEV . Text ) ; // EVs
pkx [ 0x1F ] = ( byte ) Util . ToInt32 ( TB_ATKEV . Text ) ;
pkx [ 0x20 ] = ( byte ) Util . ToInt32 ( TB_DEFEV . Text ) ;
pkx [ 0x21 ] = ( byte ) Util . ToInt32 ( TB_SPEEV . Text ) ;
pkx [ 0x22 ] = ( byte ) Util . ToInt32 ( TB_SPAEV . Text ) ;
pkx [ 0x23 ] = ( byte ) Util . ToInt32 ( TB_SPDEV . Text ) ;
pkx [ 0x24 ] = ( byte ) Util . ToInt32 ( TB_Cool . Text ) ; // CNT
pkx [ 0x25 ] = ( byte ) Util . ToInt32 ( TB_Beauty . Text ) ;
pkx [ 0x26 ] = ( byte ) Util . ToInt32 ( TB_Cute . Text ) ;
pkx [ 0x27 ] = ( byte ) Util . ToInt32 ( TB_Smart . Text ) ;
pkx [ 0x28 ] = ( byte ) Util . ToInt32 ( TB_Tough . Text ) ;
pkx [ 0x29 ] = ( byte ) Util . ToInt32 ( TB_Sheen . Text ) ;
int markings = CHK_Circle . Checked ? ( 1 < < 0 ) : 0 ;
markings | = CHK_Triangle . Checked ? ( 1 < < 1 ) : 0 ;
markings | = CHK_Square . Checked ? ( 1 < < 2 ) : 0 ;
markings | = CHK_Heart . Checked ? ( 1 < < 3 ) : 0 ;
markings | = CHK_Star . Checked ? ( 1 < < 4 ) : 0 ;
markings | = CHK_Diamond . Checked ? ( 1 < < 5 ) : 0 ;
2014-06-28 21:22:05 +00:00
pkx [ 0x2A ] = ( byte ) markings ;
2014-12-30 05:43:38 +00:00
pkx [ 0x2B ] = ( byte ) ( CB_PKRSStrain . SelectedIndex < < 4 | CB_PKRSDays . SelectedIndex ) ;
2014-06-28 21:22:05 +00:00
// Already in buff (then transferred to new pkx)
// 0x2C, 0x2D, 0x2E, 0x2F
// 0x30, 0x31, 0x32, 0x33
// 0x34, 0x35, 0x36, 0x37
// 0x38, 0x39
// Unused
// 0x3A, 0x3B
// 0x3C, 0x3D, 0x3E, 0x3F
2014-07-26 21:56:06 +00:00
// Block B
2014-06-28 21:22:05 +00:00
// Convert Nickname field back to bytes
string nicknamestr = TB_Nickname . Text ;
{
2015-02-16 06:03:42 +00:00
nicknamestr = nicknamestr . Replace ( "\u2640" , "\uE08F" ) ;
nicknamestr = nicknamestr . Replace ( "\u2642" , "\uE08E" ) ;
nicknamestr = nicknamestr . Replace ( "\u0027" , "\u2019" ) ; // ' to ’
2014-06-28 21:22:05 +00:00
}
byte [ ] nicknamebytes = Encoding . Unicode . GetBytes ( nicknamestr ) ;
2015-03-24 02:35:46 +00:00
Array . Resize ( ref nicknamebytes , nicknamebytes . Length + 2 ) ; // pad with zero byte terminator
2014-06-28 21:22:05 +00:00
Array . Copy ( nicknamebytes , 0 , pkx , 0x40 , nicknamebytes . Length ) ;
2014-07-26 21:56:06 +00:00
// 0x58, 0x59 unused
2014-10-10 02:59:57 +00:00
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_Move1 ) ) , 0 , pkx , 0x5A , 2 ) ; // Move 1
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_Move2 ) ) , 0 , pkx , 0x5C , 2 ) ; // Move 2
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_Move3 ) ) , 0 , pkx , 0x5E , 2 ) ; // Move 3
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_Move4 ) ) , 0 , pkx , 0x60 , 2 ) ; // Move 4
2014-06-28 21:22:05 +00:00
2014-12-30 05:43:38 +00:00
pkx [ 0x62 ] = ( byte ) ( Util . getIndex ( CB_Move1 ) > 0 ? Util . ToInt32 ( TB_PP1 . Text ) : 0 ) ; // Max PP
pkx [ 0x63 ] = ( byte ) ( Util . getIndex ( CB_Move2 ) > 0 ? Util . ToInt32 ( TB_PP2 . Text ) : 0 ) ;
pkx [ 0x64 ] = ( byte ) ( Util . getIndex ( CB_Move3 ) > 0 ? Util . ToInt32 ( TB_PP3 . Text ) : 0 ) ;
pkx [ 0x65 ] = ( byte ) ( Util . getIndex ( CB_Move4 ) > 0 ? Util . ToInt32 ( TB_PP4 . Text ) : 0 ) ;
2014-07-29 22:33:22 +00:00
2014-12-30 05:43:38 +00:00
pkx [ 0x66 ] = ( byte ) ( Util . getIndex ( CB_Move1 ) > 0 ? CB_PPu1 . SelectedIndex : 0 ) ; // PP Ups
pkx [ 0x67 ] = ( byte ) ( Util . getIndex ( CB_Move2 ) > 0 ? CB_PPu2 . SelectedIndex : 0 ) ;
pkx [ 0x68 ] = ( byte ) ( Util . getIndex ( CB_Move3 ) > 0 ? CB_PPu3 . SelectedIndex : 0 ) ;
pkx [ 0x69 ] = ( byte ) ( Util . getIndex ( CB_Move4 ) > 0 ? CB_PPu4 . SelectedIndex : 0 ) ;
2015-01-01 19:38:37 +00:00
2014-10-10 02:59:57 +00:00
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_RelearnMove1 ) ) , 0 , pkx , 0x6A , 2 ) ; // EggMove 1
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_RelearnMove2 ) ) , 0 , pkx , 0x6C , 2 ) ; // EggMove 2
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_RelearnMove3 ) ) , 0 , pkx , 0x6E , 2 ) ; // EggMove 3
Array . Copy ( BitConverter . GetBytes ( Util . getIndex ( CB_RelearnMove4 ) ) , 0 , pkx , 0x70 , 2 ) ; // EggMove 4
2014-06-28 21:22:05 +00:00
// 0x72 - Ribbon editor sets this flag (Secret Super Training)
// 0x73
2014-10-10 02:59:57 +00:00
uint IV32 = Util . ToUInt32 ( TB_HPIV . Text ) & 0x1F ;
2014-12-30 05:43:38 +00:00
IV32 | = ( ( Util . ToUInt32 ( TB_ATKIV . Text ) & 0x1F ) < < 5 ) ;
IV32 | = ( ( Util . ToUInt32 ( TB_DEFIV . Text ) & 0x1F ) < < 10 ) ;
IV32 | = ( ( Util . ToUInt32 ( TB_SPEIV . Text ) & 0x1F ) < < 15 ) ;
IV32 | = ( ( Util . ToUInt32 ( TB_SPAIV . Text ) & 0x1F ) < < 20 ) ;
IV32 | = ( ( Util . ToUInt32 ( TB_SPDIV . Text ) & 0x1F ) < < 25 ) ;
IV32 | = ( Convert . ToUInt32 ( CHK_IsEgg . Checked ) < < 30 ) ;
IV32 | = ( Convert . ToUInt32 ( CHK_Nicknamed . Checked ) < < 31 ) ;
Array . Copy ( BitConverter . GetBytes ( IV32 ) , 0 , pkx , 0x74 , 4 ) ; // Copy in IVs
2014-06-28 21:22:05 +00:00
2014-07-26 21:56:06 +00:00
// Block C
2015-03-19 03:45:06 +00:00
// Convert Latest OT field back to bytes
byte [ ] OT2 = Encoding . Unicode . GetBytes ( Util . TrimFromZero ( TB_OTt2 . Text ) . Replace ( "\u0027" , "\u2019" ) ) ;
Array . Resize ( ref OT2 , OT2 . Length + 2 ) ; // Allow Trash
2014-06-28 21:22:05 +00:00
Array . Copy ( OT2 , 0 , pkx , 0x78 , OT2 . Length ) ;
2015-03-19 03:45:06 +00:00
// 0x90-0xAF
2014-12-04 01:26:12 +00:00
pkx [ 0x92 ] = Convert . ToByte ( PKX . getGender ( Label_CTGender . Text ) = = 1 ) ;
2015-03-19 03:45:06 +00:00
// Plus more, set by MemoryAmie (already in buff)
2014-06-28 21:22:05 +00:00
2014-07-26 21:56:06 +00:00
// Block D
2014-06-28 21:22:05 +00:00
// Convert OT field back to bytes
2015-02-16 06:03:42 +00:00
byte [ ] OT = Encoding . Unicode . GetBytes ( TB_OT . Text . Replace ( "\u0027" , "\u2019" ) ) ;
2015-03-24 05:51:04 +00:00
Array . Resize ( ref OT , OT . Length + 2 ) ; // Pad with \0000 to terminate
2014-06-28 21:22:05 +00:00
Array . Copy ( OT , 0 , pkx , 0xB0 , OT . Length ) ;
if ( pkx [ 0x93 ] = = 0 )
2014-10-10 02:59:57 +00:00
pkx [ 0xCA ] = ( byte ) ( Util . ToInt32 ( TB_Friendship . Text ) & 0xFF ) ;
2014-07-26 21:56:06 +00:00
else // 1
2014-10-10 02:59:57 +00:00
pkx [ 0xA2 ] = ( byte ) ( Util . ToInt32 ( TB_Friendship . Text ) & 0xFF ) ;
2014-06-28 21:22:05 +00:00
int egg_year = 2000 ; // Dates
int egg_month = 0 ;
int egg_day = 0 ;
int egg_location = 0 ;
if ( CHK_AsEgg . Checked ) // If encountered as an egg, load the Egg Met data from fields.
{
egg_year = CAL_EggDate . Value . Year ;
egg_month = CAL_EggDate . Value . Month ;
egg_day = CAL_EggDate . Value . Day ;
2014-10-10 02:59:57 +00:00
egg_location = Util . getIndex ( CB_EggLocation ) ;
2014-06-28 21:22:05 +00:00
}
// Egg Met Data
pkx [ 0xD1 ] = ( byte ) ( egg_year - 2000 ) ;
pkx [ 0xD2 ] = ( byte ) egg_month ;
pkx [ 0xD3 ] = ( byte ) egg_day ;
// Met Data
pkx [ 0xD4 ] = ( byte ) ( CAL_MetDate . Value . Year - 2000 ) ;
pkx [ 0xD5 ] = ( byte ) CAL_MetDate . Value . Month ;
pkx [ 0xD6 ] = ( byte ) CAL_MetDate . Value . Day ;
2014-09-23 04:05:27 +00:00
if ( CHK_IsEgg . Checked & & CB_MetLocation . SelectedIndex = = 0 ) // If still an egg, it has no hatch location/date. Zero it!
2014-06-28 21:22:05 +00:00
{
pkx [ 0xD4 ] = 0 ;
pkx [ 0xD5 ] = 0 ;
pkx [ 0xD6 ] = 0 ;
}
// 0xD7 Unknown
2014-10-10 02:59:57 +00:00
int met_location = Util . getIndex ( CB_MetLocation ) ; // Locations
2014-06-28 21:22:05 +00:00
Array . Copy ( BitConverter . GetBytes ( egg_location ) , 0 , pkx , 0xD8 , 2 ) ; // Egg Location
Array . Copy ( BitConverter . GetBytes ( met_location ) , 0 , pkx , 0xDA , 2 ) ; // Met Location
2014-10-10 02:59:57 +00:00
pkx [ 0xDC ] = ( byte ) Util . getIndex ( CB_Ball ) ;
2014-12-30 05:43:38 +00:00
pkx [ 0xDD ] = ( byte ) ( ( ( Util . ToInt32 ( TB_MetLevel . Text ) & 0x7F ) | ( Convert . ToInt32 ( PKX . getGender ( Label_OTGender . Text ) = = 1 ) < < 7 ) ) ) ;
2014-10-10 02:59:57 +00:00
pkx [ 0xDE ] = ( byte ) ( Util . ToInt32 ( CB_EncounterType . SelectedValue . ToString ( ) ) ) ;
pkx [ 0xDF ] = ( byte ) Util . getIndex ( CB_GameOrigin ) ;
pkx [ 0xE0 ] = ( byte ) Util . getIndex ( CB_Country ) ;
pkx [ 0xE1 ] = ( byte ) Util . getIndex ( CB_SubRegion ) ;
pkx [ 0xE2 ] = ( byte ) Util . getIndex ( CB_3DSReg ) ;
pkx [ 0xE3 ] = ( byte ) Util . getIndex ( CB_Language ) ;
2014-06-28 21:22:05 +00:00
// 0xE4-0xE7
Array . Resize ( ref pkx , 260 ) ;
// Party Stats
pkx [ 0xE8 ] = 0 ; pkx [ 0xE9 ] = 0 ;
pkx [ 0xEA ] = 0 ; pkx [ 0xEB ] = 0 ;
2014-11-26 03:55:46 +00:00
pkx [ 0xEC ] = ( byte ) Util . ToInt32 ( TB_Level . Text ) ; // Level
2014-06-28 21:22:05 +00:00
pkx [ 0xED ] = 0 ; pkx [ 0xEE ] = 0 ; pkx [ 0xEF ] = 0 ;
2014-10-10 02:59:57 +00:00
Array . Copy ( BitConverter . GetBytes ( Math . Min ( Util . ToInt32 ( Stat_HP . Text ) , 65535 ) ) , 0 , pkx , 0xF0 , 2 ) ; // Current HP
Array . Copy ( BitConverter . GetBytes ( Math . Min ( Util . ToInt32 ( Stat_HP . Text ) , 65535 ) ) , 0 , pkx , 0xF2 , 2 ) ; // Max HP
Array . Copy ( BitConverter . GetBytes ( Math . Min ( Util . ToInt32 ( Stat_ATK . Text ) , 65535 ) ) , 0 , pkx , 0xF4 , 2 ) ; // ATK
Array . Copy ( BitConverter . GetBytes ( Math . Min ( Util . ToInt32 ( Stat_DEF . Text ) , 65535 ) ) , 0 , pkx , 0xF6 , 2 ) ; // DEF
Array . Copy ( BitConverter . GetBytes ( Math . Min ( Util . ToInt32 ( Stat_SPE . Text ) , 65535 ) ) , 0 , pkx , 0xF8 , 2 ) ; // SPE
Array . Copy ( BitConverter . GetBytes ( Math . Min ( Util . ToInt32 ( Stat_SPA . Text ) , 65535 ) ) , 0 , pkx , 0xFA , 2 ) ; // SPA
Array . Copy ( BitConverter . GetBytes ( Math . Min ( Util . ToInt32 ( Stat_SPD . Text ) , 65535 ) ) , 0 , pkx , 0xFC , 2 ) ; // SPD
2015-01-01 19:38:37 +00:00
pkx [ 0xFE ] = 0 ; pkx [ 0xFF ] = 0 ;
2014-06-28 21:22:05 +00:00
pkx [ 0x100 ] = 0 ; pkx [ 0x101 ] = 0 ; pkx [ 0x102 ] = 0 ; pkx [ 0x103 ] = 0 ;
2014-08-17 01:42:51 +00:00
// Hax Illegality
2014-12-13 22:48:34 +00:00
if ( HaX )
2014-08-15 04:27:53 +00:00
{
2014-11-26 03:55:46 +00:00
pkx [ 0x14 ] = ( byte ) Util . getIndex ( DEV_Ability ) ; // Ability
pkx [ 0xEC ] = ( byte ) Math . Min ( Convert . ToInt32 ( MT_Level . Text ) , 255 ) ; // Level
2014-10-11 07:22:22 +00:00
}
// Fix Moves if a slot is empty
for ( int i = 0 ; i < 3 ; i + + )
{
2015-03-11 01:44:51 +00:00
if ( BitConverter . ToUInt16 ( pkx , 0x5A + 2 * i ) ! = 0 ) continue ;
Array . Copy ( pkx , 0x5C + 2 * i , pkx , 0x5A + 2 * i , 2 ) ; // Shift moves down
Array . Copy ( new byte [ 2 ] , 0 , pkx , 0x5C + 2 * i , 2 ) ; // Clear next move (error shifted down)
2014-10-11 07:22:22 +00:00
2015-03-11 01:44:51 +00:00
// Move PP and PP Ups down one byte.
pkx [ 0x62 + i ] = pkx [ 0x63 + i ] ; pkx [ 0x63 + i ] = 0 ; // PP
pkx [ 0x66 + i ] = pkx [ 0x67 + i ] ; pkx [ 0x67 + i ] = 0 ; // PP Ups
2014-10-11 07:22:22 +00:00
}
// Fix Relearn moves if a slot is empty
for ( int i = 0 ; i < 3 ; i + + )
{
2015-03-11 01:44:51 +00:00
if ( BitConverter . ToUInt16 ( pkx , 0x6A + 2 * i ) ! = 0 ) continue ;
Array . Copy ( pkx , 0x6C + 2 * i , pkx , 0x6A + 2 * i , 2 ) ; // Shift moves down
Array . Copy ( new byte [ 2 ] , 0 , pkx , 0x6C + 2 * i , 2 ) ; // Clear next move (error shifted down)
2014-10-11 07:22:22 +00:00
}
// No foreign memories for Pokemon without a foreign trainer
if ( BitConverter . ToUInt16 ( pkx , 0x78 ) = = 0 )
{
pkx [ 0xA2 ] = pkx [ 0xA3 ] = // No Friendship/Affection
pkx [ 0xA8 ] = pkx [ 0xA9 ] = // No Memory Var
pkx [ 0xA4 ] = pkx [ 0xA5 ] = pkx [ 0xA6 ] = 0 ; // No Memory Types
2014-08-15 04:27:53 +00:00
}
2014-06-28 21:22:05 +00:00
// Now we fix the checksum!
2014-08-17 01:42:51 +00:00
ushort chk = 0 ;
2014-06-28 21:22:05 +00:00
for ( int i = 8 ; i < 232 ; i + = 2 ) // Loop through the entire PKX
2014-12-11 06:50:40 +00:00
chk + = BitConverter . ToUInt16 ( pkx , i ) ;
2014-06-28 21:22:05 +00:00
// Apply New Checksum
2014-12-30 05:43:38 +00:00
Array . Copy ( BitConverter . GetBytes ( chk ) , 0 , pkx , 6 , 2 ) ;
2014-06-28 21:22:05 +00:00
// PKX is now filled
return pkx ;
}
2014-10-11 07:22:22 +00:00
// Drag & Drop Events
2014-06-28 21:22:05 +00:00
private void tabMain_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) ) e . Effect = DragDropEffects . Copy ;
}
private void tabMain_DragDrop ( object sender , DragEventArgs e )
{
string [ ] files = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
string path = files [ 0 ] ; // open first D&D
2014-08-31 20:32:04 +00:00
openQuick ( path ) ;
2014-06-28 21:22:05 +00:00
}
// Decrypted Export
private void dragout_MouseDown ( object sender , MouseEventArgs e )
{
2014-12-24 07:29:57 +00:00
if ( ! verifiedPKX ( ) ) { return ; }
2014-06-28 21:22:05 +00:00
{
// Create Temp File to Drag
2015-03-11 01:44:51 +00:00
string basepath = Application . StartupPath ;
2014-06-28 21:22:05 +00:00
Cursor . Current = Cursors . Hand ;
2014-11-30 18:59:10 +00:00
// Make a new file name
2015-03-14 02:59:51 +00:00
byte [ ] dragdata = preparepkx ( ) ;
2014-12-14 03:32:51 +00:00
PKX pkx = new PKX ( dragdata , "Tabs" ) ;
2014-11-30 18:59:10 +00:00
string filename = pkx . Nickname ;
if ( filename ! = pkx . Species )
filename + = " (" + pkx . Species + ")" ;
2014-12-14 20:15:53 +00:00
filename + = " - " + pkx . PID ;
2014-12-16 02:12:48 +00:00
filename + = ( e . Button = = MouseButtons . Right ) ? ".ek6" : ".pk6" ;
2015-03-14 02:59:51 +00:00
dragdata = ( e . Button = = MouseButtons . Right ) ? PKX . encryptArray ( preparepkx ( ) ) : preparepkx ( ) ;
2014-06-28 21:22:05 +00:00
// Strip out party stats (if they are there)
Array . Resize ( ref dragdata , 232 ) ;
// Make file
2014-11-28 23:46:09 +00:00
string newfile = Path . Combine ( basepath , Util . CleanFileName ( filename ) ) ;
2014-06-28 21:22:05 +00:00
try
{
2014-07-14 18:44:40 +00:00
File . WriteAllBytes ( newfile , dragdata ) ;
2014-06-28 21:22:05 +00:00
2014-07-14 18:44:40 +00:00
string [ ] filesToDrag = { newfile } ;
2014-06-28 21:22:05 +00:00
dragout . DoDragDrop ( new DataObject ( DataFormats . FileDrop , filesToDrag ) , DragDropEffects . Move ) ;
2014-07-14 18:44:40 +00:00
File . Delete ( newfile ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-11 06:50:40 +00:00
catch ( Exception x )
{ Util . Error ( "Drag & Drop Error" , x . ToString ( ) ) ; }
2014-07-14 18:44:40 +00:00
File . Delete ( newfile ) ;
2014-06-28 21:22:05 +00:00
}
}
2014-12-14 20:15:53 +00:00
private void dragout_DragOver ( object sender , DragEventArgs e )
2014-06-28 21:22:05 +00:00
{
e . Effect = DragDropEffects . Move ;
}
2014-12-14 20:15:53 +00:00
// Dragout Display
2014-06-28 21:22:05 +00:00
private void dragoutHover ( object sender , EventArgs e )
{
2015-01-03 01:07:29 +00:00
dragout . BackgroundImage = ( Util . getIndex ( CB_Species ) > 0 ) ? Properties . Resources . slotSet : Properties . Resources . slotDel ;
2014-06-28 21:22:05 +00:00
}
private void dragoutLeave ( object sender , EventArgs e )
{
2014-12-14 20:15:53 +00:00
dragout . BackgroundImage = Properties . Resources . slotTrans ;
}
private void dragoutDrop ( object sender , DragEventArgs e )
{
openQuick ( ( ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ) [ 0 ] ) ;
2014-06-28 21:22:05 +00:00
}
#endregion
2014-12-22 04:07:04 +00:00
2014-06-28 21:22:05 +00:00
#region //// SAVE FILE FUNCTIONS ////
// Integrity Checks //
2014-12-14 19:06:17 +00:00
private void clickVerifyCHK ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2015-04-28 14:39:50 +00:00
if ( savedited ) { Util . Alert ( "Save has been edited. Cannot integrity check." ) ; return ; }
2014-06-28 21:22:05 +00:00
2015-04-28 14:39:50 +00:00
int [ ] ctr = { 0 , 0 } ;
RTB_S . Text + = PKX . verifyG6CHK ( savefile , savegame_oras , 0 , ref ctr ) ;
2014-11-22 07:23:48 +00:00
if ( cybergadget ) return ;
2015-04-28 14:39:50 +00:00
RTB_S . Text + = PKX . verifyG6CHK ( savefile , savegame_oras , 1 , ref ctr ) ;
2014-11-22 07:23:48 +00:00
2015-04-28 14:39:50 +00:00
if ( ctr [ 0 ] = = ctr [ 1 ] ) RTB_S . Text = "No checksums are valid." ;
2014-06-28 21:22:05 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickVerifySHA ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2015-04-28 14:39:50 +00:00
if ( savedited ) { Util . Alert ( "Save has been edited. Cannot integrity check." ) ; return ; }
2014-06-28 21:22:05 +00:00
2015-04-28 14:39:50 +00:00
RTB_S . Text + = PKX . verifyG6SHA ( savefile , savegame_oras ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickExportSAV ( object sender , EventArgs e )
2015-08-07 05:32:12 +00:00
{
// Set the current box to the save
savefile [ SaveGame . PCLayout + savindex * 0x7FFFF + 0x43F ] = ( byte )
( tabBoxMulti . SelectedIndex = = 1 ? 0xFF // If Battle/Party selected
: CB_BoxSelect . SelectedIndex ) ; // Box
2014-06-28 21:22:05 +00:00
// Create another version of the save file.
2014-12-12 05:44:05 +00:00
byte [ ] editedsav = new byte [ 0x100000 ] ;
2014-06-28 21:22:05 +00:00
Array . Copy ( savefile , editedsav , savefile . Length ) ;
// Since we only edited one of the save files, we only have to fix half of the chk/hashes!
// Fix Checksums
2015-04-28 14:39:50 +00:00
editedsav = PKX . writeG6CHK ( editedsav , savegame_oras , savindex ) ;
if ( ! cybergadget ) // Fix Hashes
editedsav = PKX . writeG6SHA ( editedsav , savegame_oras , savindex ) ;
2014-06-28 21:22:05 +00:00
// Write the active save index
2014-11-21 23:34:10 +00:00
editedsav [ 0x168 ] = ( byte ) ( savindex ^ 1 ) ;
// File Integrity has been restored as well as it can. Export!
2014-07-26 21:56:06 +00:00
2014-11-21 23:34:10 +00:00
if ( cybergadget )
2015-04-28 14:39:50 +00:00
#region Saving CyberGadget / RAMSAV
2014-07-26 21:56:06 +00:00
{
2015-04-28 14:39:50 +00:00
byte [ ] cybersav = new byte [ savegame_oras ? 0x76000 : 0x65600 ] ;
2014-11-21 23:34:10 +00:00
Array . Copy ( editedsav , 0x5400 , cybersav , 0 , cybersav . Length ) ;
2015-01-27 06:05:04 +00:00
if ( ramsav = = null )
2014-08-31 20:32:04 +00:00
{
2015-01-27 06:05:04 +00:00
// Chunk Error Checking
byte [ ] FFFF = new byte [ 0x200 ] ;
byte [ ] section = new byte [ 0x200 ] ;
for ( int i = 0 ; i < 0x200 ; i + + )
FFFF [ i ] = 0xFF ;
2014-08-31 20:32:04 +00:00
2015-01-27 06:05:04 +00:00
for ( int i = 0 ; i < cybersav . Length / 0x200 ; i + + )
{
Array . Copy ( cybersav , i * 0x200 , section , 0 , 0x200 ) ;
2015-03-11 01:44:51 +00:00
if ( ! section . SequenceEqual ( FFFF ) ) continue ;
string problem = String . Format ( "0x200 chunk @ 0x{0} is FF'd." , ( i * 0x200 ) . ToString ( "X5" ) )
+ Environment . NewLine + "Cyber will screw up (as of August 31st)." + Environment . NewLine + Environment . NewLine ;
// Check to see if it is in the Pokedex
if ( i * 0x200 > 0x14E00 & & i * 0x200 < 0x15700 )
2014-08-31 20:32:04 +00:00
{
2015-03-11 01:44:51 +00:00
problem + = "Problem lies in the Pokedex. " ;
if ( i * 0x200 = = 0x15400 )
problem + = "Remove a language flag for a species ~ ex " + specieslist [ 548 ] ;
2015-01-27 06:05:04 +00:00
}
2015-03-11 01:44:51 +00:00
if ( Util . Prompt ( MessageBoxButtons . YesNo , problem , "Continue saving?" ) ! = DialogResult . Yes )
return ;
2014-08-31 20:32:04 +00:00
}
2015-01-01 19:38:37 +00:00
}
2014-07-26 21:56:06 +00:00
SaveFileDialog cySAV = new SaveFileDialog ( ) ;
2014-08-01 07:55:28 +00:00
// Try for file path
string cyberpath = Util . GetTempFolder ( ) ;
2015-01-27 06:05:04 +00:00
if ( ramsav ! = null & & Directory . Exists ( path3DS ) )
2014-11-28 03:26:42 +00:00
{
2015-01-27 06:05:04 +00:00
cySAV . InitialDirectory = path3DS ;
cySAV . RestoreDirectory = true ;
}
2015-09-05 01:50:14 +00:00
else if ( path3DS ! = null & & File . Exists ( Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" , "main" ) ) )
{
cySAV . InitialDirectory = Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" ) ;
cySAV . RestoreDirectory = true ;
}
2015-01-27 06:05:04 +00:00
else if ( pathSDF ! = null & & Directory . Exists ( pathSDF ) )
{
cySAV . InitialDirectory = pathSDF ;
cySAV . RestoreDirectory = true ;
2014-11-28 03:26:42 +00:00
}
2014-11-28 23:46:09 +00:00
else if ( Directory . Exists ( Path . Combine ( cyberpath , "root" ) ) )
2014-08-02 00:24:22 +00:00
{
2014-11-28 23:46:09 +00:00
cySAV . InitialDirectory = Path . Combine ( cyberpath , "root" ) ;
2014-08-02 00:24:22 +00:00
cySAV . RestoreDirectory = true ;
}
2014-08-01 07:55:28 +00:00
else if ( Directory . Exists ( cyberpath ) )
2014-08-02 00:24:22 +00:00
{
2014-08-01 07:55:28 +00:00
cySAV . InitialDirectory = cyberpath ;
2014-08-02 00:24:22 +00:00
cySAV . RestoreDirectory = true ;
}
2015-01-27 07:14:08 +00:00
if ( ramsavloaded & & ModifierKeys = = Keys . Shift ) // Export RAM SAV to another.
{
Util . Alert ( "Please specify the target cart/console-RAM save." ) ;
OpenFileDialog ofd = new OpenFileDialog ( ) ;
2015-03-11 01:44:51 +00:00
if ( ofd . ShowDialog ( ) ! = DialogResult . OK ) return ;
string target = ofd . FileName ;
byte [ ] targetRAM = File . ReadAllBytes ( target ) ;
byte [ ] newRAM = ram2sav . getRAM ( targetRAM , cybersav ) ;
cySAV . Filter = "ramsav|*.bin" ;
cySAV . FileName = "ramsav.bin" ;
DialogResult sdr = cySAV . ShowDialog ( ) ;
if ( sdr ! = DialogResult . OK ) return ;
string path = cySAV . FileName ;
File . WriteAllBytes ( path , newRAM ) ;
Util . Alert ( "Saved RAM SAV to:" + Environment . NewLine + path , "Target RAM:" + Environment . NewLine + target ) ;
2015-01-27 07:14:08 +00:00
}
else if ( ramsavloaded & & ModifierKeys ! = Keys . Control ) // Export RAM SAV if it is the currently loaded one.
2015-01-27 06:05:04 +00:00
{
cySAV . Filter = "ramsav|*.bin" ;
cySAV . FileName = "ramsav.bin" ;
DialogResult sdr = cySAV . ShowDialog ( ) ;
2015-03-11 01:44:51 +00:00
if ( sdr ! = DialogResult . OK ) return ;
string path = cySAV . FileName ;
File . WriteAllBytes ( path , ram2sav . getRAM ( ramsav , cybersav ) ) ;
Util . Alert ( "Saved RAM SAV to:" , path ) ;
2015-01-27 06:05:04 +00:00
}
else
2014-07-26 21:56:06 +00:00
{
2015-01-27 06:05:04 +00:00
cySAV . Filter = "Cyber SAV|*.*" ;
2015-03-11 01:44:51 +00:00
cySAV . FileName = L_Save . Text . Split ( new [ ] { ": " } , StringSplitOptions . None ) [ 1 ] ;
2015-01-27 06:05:04 +00:00
DialogResult sdr = cySAV . ShowDialog ( ) ;
2015-03-11 01:44:51 +00:00
if ( sdr ! = DialogResult . OK ) return ;
string path = cySAV . FileName ;
File . WriteAllBytes ( path , cybersav ) ;
Util . Alert ( "Saved Cyber SAV to:" , path ) ;
2014-07-26 21:56:06 +00:00
}
}
2015-04-28 14:39:50 +00:00
#endregion
2014-08-01 19:37:30 +00:00
else
2015-04-28 14:39:50 +00:00
#region Saving Full Save File
2014-06-28 21:22:05 +00:00
{
2014-08-01 19:37:30 +00:00
// Save Full Save File
2015-03-11 01:44:51 +00:00
SaveFileDialog savesav = new SaveFileDialog
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
Filter = "SAV|*.bin;*.sav" ,
FileName = L_Save . Text . Split ( new [ ] { ": " } , StringSplitOptions . None ) [ 1 ]
} ;
DialogResult result = savesav . ShowDialog ( ) ;
if ( result ! = DialogResult . OK ) return ;
string path = savesav . FileName ;
2014-06-28 21:22:05 +00:00
2015-03-11 01:44:51 +00:00
if ( File . Exists ( path ) )
{
// File already exists, save a .bak
byte [ ] backupfile = File . ReadAllBytes ( path ) ;
File . WriteAllBytes ( path + ".bak" , backupfile ) ;
2014-08-01 19:37:30 +00:00
}
2015-03-11 01:44:51 +00:00
File . WriteAllBytes ( path , editedsav ) ;
Util . Alert ( "Saved 1MB SAV to:" , path ) ;
2014-06-28 21:22:05 +00:00
}
2015-04-28 14:39:50 +00:00
#endregion
2014-06-28 21:22:05 +00:00
}
2014-12-28 21:56:59 +00:00
// Box/SAV Functions //
2014-12-14 19:06:17 +00:00
private void clickBoxRight ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2015-05-07 02:30:31 +00:00
CB_BoxSelect . SelectedIndex = ( CB_BoxSelect . SelectedIndex + 1 ) % 31 ;
2014-06-28 21:22:05 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickBoxLeft ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2015-05-07 02:30:31 +00:00
CB_BoxSelect . SelectedIndex = ( CB_BoxSelect . SelectedIndex + 30 ) % 31 ;
2014-06-28 21:22:05 +00:00
}
2014-12-24 07:29:57 +00:00
private void clickSlot ( object sender , EventArgs e )
{
2015-03-11 01:44:51 +00:00
switch ( ModifierKeys )
{
case ( Keys . Control | Keys . Alt ) : clickClone ( sender , e ) ; break ;
case Keys . Control : clickView ( sender , e ) ; break ;
case Keys . Shift : clickSet ( sender , e ) ; break ;
case Keys . Alt : clickDelete ( sender , e ) ; break ;
}
2014-12-24 07:29:57 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickView ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
int slot = getSlot ( sender ) ;
int offset = getPKXOffset ( slot ) ;
PictureBox [ ] pba = {
bpkx1 , bpkx2 , bpkx3 , bpkx4 , bpkx5 , bpkx6 ,
bpkx7 , bpkx8 , bpkx9 , bpkx10 , bpkx11 , bpkx12 ,
bpkx13 , bpkx14 , bpkx15 , bpkx16 , bpkx17 , bpkx18 ,
bpkx19 , bpkx20 , bpkx21 , bpkx22 , bpkx23 , bpkx24 ,
bpkx25 , bpkx26 , bpkx27 , bpkx28 , bpkx29 , bpkx30 ,
ppkx1 , ppkx2 , ppkx3 , ppkx4 , ppkx5 , ppkx6 ,
bbpkx1 , bbpkx2 , bbpkx3 , bbpkx4 , bbpkx5 , bbpkx6 ,
dcpkx1 , dcpkx2 , gtspkx , fusedpkx , subepkx1 , subepkx2 , subepkx3 ,
} ;
PictureBox picturebox = pba [ slot ] ;
if ( picturebox . Image = = null )
2014-11-28 10:14:15 +00:00
{ System . Media . SystemSounds . Exclamation . Play ( ) ; return ; }
2014-06-28 21:22:05 +00:00
// Load the PKX file
if ( BitConverter . ToUInt64 ( savefile , offset + 8 ) ! = 0 )
{
2014-12-12 05:44:05 +00:00
byte [ ] ekxdata = new byte [ 0xE8 ] ;
2014-06-28 21:22:05 +00:00
Array . Copy ( savefile , offset , ekxdata , 0 , 0xE8 ) ;
2014-10-10 02:59:57 +00:00
byte [ ] pkxdata = PKX . decryptArray ( ekxdata ) ;
2014-06-28 21:22:05 +00:00
int species = BitConverter . ToInt16 ( pkxdata , 0x08 ) ; // Get Species
if ( species = = 0 )
{
2014-07-31 22:06:48 +00:00
System . Media . SystemSounds . Exclamation . Play ( ) ;
2014-06-28 21:22:05 +00:00
return ;
}
2014-07-31 22:06:48 +00:00
try
2014-06-28 21:22:05 +00:00
{
Array . Copy ( pkxdata , buff , 0xE8 ) ;
2014-10-10 02:59:57 +00:00
populateFields ( buff ) ;
2014-06-28 21:22:05 +00:00
}
catch // If it fails, try XORing encrypted zeroes
{
try
{
2014-12-12 05:44:05 +00:00
byte [ ] blank = PKX . encryptArray ( new byte [ 0xE8 ] ) ;
2014-08-17 01:42:51 +00:00
2014-06-28 21:22:05 +00:00
for ( int i = 0 ; i < 0xE8 ; i + + )
blank [ i ] = ( byte ) ( buff [ i ] ^ blank [ i ] ) ;
2014-08-17 01:42:51 +00:00
2014-10-10 02:59:57 +00:00
populateFields ( blank ) ;
2014-06-28 21:22:05 +00:00
}
catch // Still fails, just let the original errors occur.
2014-11-28 10:14:15 +00:00
{ populateFields ( buff ) ; }
2014-06-28 21:22:05 +00:00
}
// Visual to display what slot is currently loaded.
2014-08-01 23:53:09 +00:00
getSlotColor ( slot , Properties . Resources . slotView ) ;
2014-06-28 21:22:05 +00:00
}
2014-07-31 22:06:48 +00:00
else
System . Media . SystemSounds . Exclamation . Play ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickSet ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-24 07:29:57 +00:00
if ( ! verifiedPKX ( ) ) { return ; }
2014-06-28 21:22:05 +00:00
int slot = getSlot ( sender ) ;
2014-12-11 06:50:40 +00:00
if ( slot = = 30 & & ( CB_Species . SelectedIndex = = 0 | | CHK_IsEgg . Checked ) ) { Util . Alert ( "Can't have empty/egg first slot." ) ; return ; }
2014-10-11 07:22:22 +00:00
int offset = getPKXOffset ( slot ) ;
2015-03-14 02:59:51 +00:00
byte [ ] pkxdata = preparepkx ( ) ;
2014-10-11 07:22:22 +00:00
byte [ ] ekxdata = PKX . encryptArray ( pkxdata ) ;
2014-07-26 21:56:06 +00:00
2014-11-22 07:23:48 +00:00
if ( ! savegame_oras )
{
// User Protection
2015-04-28 14:39:50 +00:00
bool move1 = BitConverter . ToInt16 ( pkxdata , 0x5A ) > 617 ;
bool move2 = BitConverter . ToInt16 ( pkxdata , 0x5C ) > 617 ;
bool move3 = BitConverter . ToInt16 ( pkxdata , 0x5E ) > 617 ;
bool move4 = BitConverter . ToInt16 ( pkxdata , 0x60 ) > 617 ;
bool ability = pkxdata [ 0x14 ] > 188 ;
bool item = BitConverter . ToInt16 ( pkxdata , 0x0A ) > 717 ;
2014-12-11 06:50:40 +00:00
string err = "" ;
2014-11-22 07:23:48 +00:00
2015-04-28 14:39:50 +00:00
if ( move1 | | move2 | | move3 | | move4 )
2014-12-11 06:50:40 +00:00
err = "Move does not exist in X/Y." ;
2015-04-28 14:39:50 +00:00
else if ( ability )
2014-12-11 06:50:40 +00:00
err = "Ability does not exist in X/Y." ;
2015-04-28 14:39:50 +00:00
else if ( item )
2014-12-11 06:50:40 +00:00
err = "Item does not exist in X/Y." ;
2015-01-02 02:05:47 +00:00
if ( ( err ! = "" ) & & Util . Prompt ( MessageBoxButtons . YesNo , err , "Continue?" ) ! = DialogResult . Yes )
2014-11-22 07:23:48 +00:00
return ;
}
2014-07-26 21:56:06 +00:00
if ( slot > = 30 & & slot < 36 ) // Party
Array . Copy ( ekxdata , 0 , savefile , offset , 0x104 ) ;
2014-10-11 07:22:22 +00:00
else if ( slot < 30 | | ( slot > = 36 & & slot < 42 & & DEV_Ability . Enabled ) )
2014-07-26 21:56:06 +00:00
Array . Copy ( ekxdata , 0 , savefile , offset , 0xE8 ) ;
2014-10-11 07:22:22 +00:00
else return ;
setParty ( ) ;
setPokedex ( pkxdata ) ;
2014-12-20 19:27:29 +00:00
getQuickFiller ( getPictureBox ( slot ) , pkxdata ) ;
2014-06-28 21:22:05 +00:00
savedited = true ;
2014-08-01 23:53:09 +00:00
getSlotColor ( slot , Properties . Resources . slotSet ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickDelete ( object sender , EventArgs e )
2014-10-11 07:22:22 +00:00
{
int slot = getSlot ( sender ) ;
2015-01-31 18:36:06 +00:00
if ( slot = = 30 & & setParty ( ) = = 1 & & ! DEV_Ability . Enabled ) { Util . Alert ( "Can't delete first slot." ) ; return ; }
2014-10-11 07:22:22 +00:00
int offset = getPKXOffset ( slot ) ;
2014-12-12 05:44:05 +00:00
byte [ ] pkxdata = new byte [ 0x104 ] ;
2014-10-11 07:22:22 +00:00
byte [ ] ekxdata = PKX . encryptArray ( pkxdata ) ;
2015-02-27 16:18:32 +00:00
savedited = true ;
2014-10-11 07:22:22 +00:00
if ( slot > = 30 & & slot < 36 ) // Party
2015-02-27 16:18:32 +00:00
{ Array . Copy ( ekxdata , 0 , savefile , offset , 0x104 ) ; setParty ( ) ; return ; }
2015-03-11 01:44:51 +00:00
if ( slot < 30 | | ( slot > = 36 & & slot < 42 & & DEV_Ability . Enabled ) )
2015-01-31 18:36:06 +00:00
{ Array . Copy ( ekxdata , 0 , savefile , offset , 0xE8 ) ; }
2014-10-11 07:22:22 +00:00
else return ;
2014-12-20 19:27:29 +00:00
getQuickFiller ( getPictureBox ( slot ) , pkxdata ) ;
2014-10-11 07:22:22 +00:00
getSlotColor ( slot , Properties . Resources . slotDel ) ;
}
2014-12-14 19:06:17 +00:00
private void clickClone ( object sender , EventArgs e )
2014-11-29 19:07:01 +00:00
{
2014-12-06 02:14:04 +00:00
if ( getSlot ( sender ) > 30 ) return ; // only perform action if cloning to boxes
2014-12-24 07:29:57 +00:00
if ( ! verifiedPKX ( ) ) { return ; } // don't copy garbage to the box
2014-11-29 19:07:01 +00:00
2014-12-20 19:27:29 +00:00
byte [ ] pkxdata ;
2015-05-07 02:30:31 +00:00
int box = CB_BoxSelect . SelectedIndex + 1 ; // get box we're cloning to
2014-11-30 01:47:17 +00:00
{
2014-12-20 19:27:29 +00:00
if ( Util . Prompt ( MessageBoxButtons . YesNo , String . Format ( "Clone Pokemon from Editing Tabs to all slots in Box {0}?" , box ) ) = = DialogResult . Yes )
{
2015-03-14 02:59:51 +00:00
pkxdata = preparepkx ( ) ;
2014-12-20 19:27:29 +00:00
setPokedex ( pkxdata ) ;
}
else if ( Util . Prompt ( MessageBoxButtons . YesNo , String . Format ( "Delete Pokemon from all slots in Box {0}?" , box ) ) = = DialogResult . Yes )
pkxdata = new Byte [ 0xE8 ] ;
else
return ; // abort clone/delete
2014-11-30 01:47:17 +00:00
}
2015-01-01 19:38:37 +00:00
2014-11-29 19:07:01 +00:00
byte [ ] ekxdata = PKX . encryptArray ( pkxdata ) ;
2014-12-06 02:14:04 +00:00
for ( int i = 0 ; i < 30 ; i + + ) // write encrypted array to all box slots
2014-11-29 19:07:01 +00:00
Array . Copy ( ekxdata , 0 , savefile , getPKXOffset ( i ) , 0xE8 ) ;
2014-12-20 19:27:29 +00:00
for ( int i = 0 ; i < 30 ; i + + )
getQuickFiller ( getPictureBox ( i ) , pkxdata ) ;
2014-11-29 19:07:01 +00:00
savedited = true ;
}
2014-12-24 07:29:57 +00:00
// Generic Subfunctions //
2014-08-16 04:40:58 +00:00
private void setPokedex ( byte [ ] pkxdata )
2014-08-10 03:56:26 +00:00
{
if ( savindex > 1 ) return ;
int species = BitConverter . ToUInt16 ( pkxdata , 0x8 ) ; // Species
int lang = pkxdata [ 0xE3 ] - 1 ; if ( lang > 5 ) lang - - ; // 0-6 language vals
int origin = pkxdata [ 0xDF ] ; // Native / Non Native
int gender = ( pkxdata [ 0x1D ] & 2 ) > > 1 ; // Gender
uint pid = BitConverter . ToUInt32 ( pkxdata , 0x18 ) ;
ushort TID = BitConverter . ToUInt16 ( pkxdata , 0xC ) ;
ushort SID = BitConverter . ToUInt16 ( pkxdata , 0xE ) ;
2014-12-31 06:18:41 +00:00
int shiny = ( PKX . getPSV ( pid ) ^ PKX . getTSV ( TID , SID ) ) > > 4 = = 0 ? 1 : 0 ;
2014-11-30 01:47:17 +00:00
int dexoff = savindex * 0x7F000 + SaveGame . PokeDex ; // Same offset for XY-ORAS
int langoff = 0x3C8 ; if ( savegame_oras ) langoff = 0x400 ; // Not the same offset for language bools
2014-11-30 05:28:48 +00:00
int shiftoff = ( shiny * 0x60 * 2 ) + ( gender * 0x60 ) + 0x60 ;
2014-08-10 03:56:26 +00:00
2014-11-30 01:47:17 +00:00
// Set the [Species/Gender/Shiny] Owned Flag
2014-11-30 05:28:48 +00:00
savefile [ dexoff + shiftoff + ( species - 1 ) / 8 + 0x8 ] | = ( byte ) ( 1 < < ( ( species - 1 ) % 8 ) ) ;
2014-08-10 03:56:26 +00:00
2014-11-30 01:47:17 +00:00
// Owned quality flag
if ( origin < 0x18 & & species < 650 & & ! savegame_oras ) // Pre 650 for X/Y, and not for ORAS; Set the Foreign Owned Flag
2014-08-10 03:56:26 +00:00
savefile [ 0x1AA4C + 0x7F000 * savindex + ( species - 1 ) / 8 ] | = ( byte ) ( 1 < < ( ( species - 1 ) % 8 ) ) ;
2014-11-30 01:47:17 +00:00
else if ( origin > = 0x18 | | savegame_oras ) // Set Native Owned Flag (should always happen)
savefile [ dexoff + ( species - 1 ) / 8 + 0x8 ] | = ( byte ) ( 1 < < ( ( species - 1 ) % 8 ) ) ;
2014-08-10 10:50:20 +00:00
// Set the Language
2014-08-31 20:32:04 +00:00
if ( lang < 0 ) lang = 1 ;
2014-12-24 07:29:57 +00:00
savefile [ dexoff + langoff + ( ( species - 1 ) * 7 + lang ) / 8 ] | = ( byte ) ( 1 < < ( ( ( ( species - 1 ) * 7 ) + lang ) % 8 ) ) ;
2014-08-10 03:56:26 +00:00
}
2014-10-11 07:22:22 +00:00
private byte setParty ( )
2014-07-26 21:56:06 +00:00
{
2014-12-06 02:14:04 +00:00
byte partymembers = 0 ; // start off with a ctr of 0
2014-07-26 21:56:06 +00:00
int offset = SaveGame . Party + 0x7F000 * savindex ;
for ( int i = 0 ; i < 6 ; i + + )
{
// Gather all the species
2014-12-12 05:44:05 +00:00
byte [ ] data = new byte [ 0x104 ] ;
2014-07-26 21:56:06 +00:00
Array . Copy ( savefile , offset + i * 0x104 , data , 0 , 0x104 ) ;
2014-10-10 02:59:57 +00:00
byte [ ] decdata = PKX . decryptArray ( data ) ;
2014-12-24 07:29:57 +00:00
int species = BitConverter . ToInt16 ( decdata , 8 ) ;
2014-07-26 21:56:06 +00:00
if ( ( species ! = 0 ) & & ( species < 722 ) )
2015-02-27 16:18:32 +00:00
Array . Copy ( data , 0 , savefile , offset + ( partymembers + + ) * 0x104 , 0x104 ) ;
2014-07-26 21:56:06 +00:00
}
2014-12-06 02:14:04 +00:00
2014-07-26 21:56:06 +00:00
// Write in the current party count
2014-10-11 07:22:22 +00:00
savefile [ offset + 6 * 0x104 + savindex * 0x7F000 ] = partymembers ;
2014-07-26 21:56:06 +00:00
// Zero out the party slots that are empty.
for ( int i = 0 ; i < 6 ; i + + )
if ( i > = partymembers )
2014-12-12 05:44:05 +00:00
Array . Copy ( PKX . encryptArray ( new byte [ 0x104 ] ) , 0 , savefile , offset + ( i * 0x104 ) , 0x104 ) ;
2014-10-11 07:22:22 +00:00
// Repeat for Battle Box.
byte battlemem = 0 ;
int offset2 = SaveGame . BattleBox + 0x7F000 * savindex ;
for ( int i = 0 ; i < 6 ; i + + )
2014-07-26 21:56:06 +00:00
{
2014-10-11 07:22:22 +00:00
// Gather all the species
2014-12-12 05:44:05 +00:00
byte [ ] data = new byte [ 0x104 ] ;
2014-10-11 07:22:22 +00:00
Array . Copy ( savefile , offset2 + i * 0xE8 , data , 0 , 0xE8 ) ;
byte [ ] decdata = PKX . decryptArray ( data ) ;
int species = BitConverter . ToInt16 ( decdata , 8 ) ;
if ( ( species ! = 0 ) & & ( species < 722 ) )
2015-02-27 16:18:32 +00:00
Array . Copy ( data , 0 , savefile , offset2 + ( battlemem + + ) * 0xE8 , 0xE8 ) ;
2014-07-26 21:56:06 +00:00
}
2014-10-11 07:22:22 +00:00
// Zero out the party slots that are empty.
for ( int i = 0 ; i < 6 ; i + + )
if ( i > = battlemem )
2014-12-12 05:44:05 +00:00
Array . Copy ( PKX . encryptArray ( new byte [ 0x104 ] ) , 0 , savefile , offset2 + ( i * 0xE8 ) , 0xE8 ) ;
2014-11-28 10:14:15 +00:00
2014-10-11 07:22:22 +00:00
if ( battlemem = = 0 )
savefile [ offset2 + 6 * 0xE8 + savindex * 0x7F000 ] = 0 ;
2014-06-28 21:22:05 +00:00
2015-02-27 16:18:32 +00:00
// Refresh slots
for ( int i = 0 ; i < 6 ; i + + )
{
getQuickFiller ( getPictureBox ( i + 30 ) , PKX . decryptArray ( savefile . Skip ( SaveGame . Party + 0x7F000 * savindex + 260 * i ) . Take ( 232 ) . ToArray ( ) ) ) ;
getQuickFiller ( getPictureBox ( i + 36 ) , PKX . decryptArray ( savefile . Skip ( SaveGame . BattleBox + 0x7F000 * savindex + 232 * i ) . Take ( 232 ) . ToArray ( ) ) ) ;
}
2014-10-11 07:22:22 +00:00
return partymembers ;
2014-06-28 21:22:05 +00:00
}
private int getPKXOffset ( int slot )
{
2015-05-07 02:30:31 +00:00
int offset = SaveGame . Box + CB_BoxSelect . SelectedIndex * ( 0xE8 * 30 ) + slot * 0xE8 ;
2014-06-28 21:22:05 +00:00
if ( slot > 29 ) // Not a party
{
if ( slot < 36 ) // Party Slot
offset = SaveGame . Party + ( slot - 30 ) * 0x104 ;
else if ( slot < 42 ) // Battle Box Slot
offset = SaveGame . BattleBox + ( slot - 36 ) * 0xE8 ;
else if ( slot < 44 ) // Daycare
offset = SaveGame . Daycare + 8 + ( slot - 42 ) * 0xF0 ;
else if ( slot < 45 ) // GTS
offset = SaveGame . GTS ;
else if ( slot < 46 ) // Fused
offset = SaveGame . Fused ;
else // SUBE
offset = SaveGame . SUBE + ( slot - 46 ) * 0xEC ;
}
offset + = 0x7F000 * savindex ;
return offset ;
}
private int getSlot ( object sender )
{
2015-01-31 18:36:06 +00:00
string name = ( sender is ToolStripItem )
?
( ( sender as ToolStripItem ) . Owner as ContextMenuStrip ) . SourceControl . Name
:
( sender as PictureBox ) . Name ;
2014-06-28 21:22:05 +00:00
2014-10-11 07:22:22 +00:00
string [ ] pba = {
"bpkx1" , "bpkx2" , "bpkx3" , "bpkx4" , "bpkx5" , "bpkx6" ,
"bpkx7" , "bpkx8" , "bpkx9" , "bpkx10" , "bpkx11" , "bpkx12" ,
"bpkx13" , "bpkx14" , "bpkx15" , "bpkx16" , "bpkx17" , "bpkx18" ,
"bpkx19" , "bpkx20" , "bpkx21" , "bpkx22" , "bpkx23" , "bpkx24" ,
"bpkx25" , "bpkx26" , "bpkx27" , "bpkx28" , "bpkx29" , "bpkx30" ,
2014-06-28 21:22:05 +00:00
2014-10-11 07:22:22 +00:00
"ppkx1" , "ppkx2" , "ppkx3" , "ppkx4" , "ppkx5" , "ppkx6" ,
"bbpkx1" , "bbpkx2" , "bbpkx3" , "bbpkx4" , "bbpkx5" , "bbpkx6" ,
2014-06-28 21:22:05 +00:00
2014-10-11 07:22:22 +00:00
"dcpkx1" , "dcpkx2" , "gtspkx" , "fusedpkx" , "subepkx1" , "subepkx2" , "subepkx3" ,
} ;
2015-01-31 18:36:06 +00:00
int slot = Array . IndexOf ( pba , name ) ;
2014-10-11 07:22:22 +00:00
return slot ;
2014-06-28 21:22:05 +00:00
}
2014-12-24 07:29:57 +00:00
private void setPKXBoxes ( )
2014-06-28 21:22:05 +00:00
{
2015-05-07 02:30:31 +00:00
int boxoffset = SaveGame . Box + 0x7F000 * savindex + CB_BoxSelect . SelectedIndex * ( 0xE8 * 30 ) ;
2014-06-28 21:22:05 +00:00
2015-05-07 02:30:31 +00:00
int boxbgofst = ( 0x7F000 * savindex ) + 0x9C1E + CB_BoxSelect . SelectedIndex ;
2014-08-01 23:53:09 +00:00
int boxbgval = 1 + savefile [ boxbgofst ] ;
2014-11-22 03:26:16 +00:00
string imagename = "box_wp" + boxbgval . ToString ( "00" ) ; if ( savegame_oras & & boxbgval > 16 ) imagename + = "o" ;
PAN_Box . BackgroundImage = ( Image ) Properties . Resources . ResourceManager . GetObject ( imagename ) ;
2014-12-20 19:27:29 +00:00
2014-06-28 21:22:05 +00:00
PictureBox [ ] pba = {
bpkx1 , bpkx2 , bpkx3 , bpkx4 , bpkx5 , bpkx6 ,
bpkx7 , bpkx8 , bpkx9 , bpkx10 , bpkx11 , bpkx12 ,
bpkx13 , bpkx14 , bpkx15 , bpkx16 , bpkx17 , bpkx18 ,
bpkx19 , bpkx20 , bpkx21 , bpkx22 , bpkx23 , bpkx24 ,
bpkx25 , bpkx26 , bpkx27 , bpkx28 , bpkx29 , bpkx30 ,
ppkx1 , ppkx2 , ppkx3 , ppkx4 , ppkx5 , ppkx6 ,
bbpkx1 , bbpkx2 , bbpkx3 , bbpkx4 , bbpkx5 , bbpkx6 ,
dcpkx1 , dcpkx2 , gtspkx , fusedpkx , subepkx1 , subepkx2 , subepkx3 ,
} ;
for ( int i = 0 ; i < 30 ; i + + )
2015-01-03 01:07:29 +00:00
getSlotFiller ( boxoffset + 0xE8 * i , pba [ i ] ) ;
2014-06-28 21:22:05 +00:00
// Reload Party
for ( int i = 0 ; i < 6 ; i + + )
2015-01-03 01:07:29 +00:00
getSlotFiller ( SaveGame . Party + ( 0x7F000 * savindex ) + 0x104 * i , pba [ i + 30 ] ) ;
2014-12-06 02:14:04 +00:00
2014-06-28 21:22:05 +00:00
// Reload Battle Box
for ( int i = 0 ; i < 6 ; i + + )
2015-01-03 01:07:29 +00:00
getSlotFiller ( SaveGame . BattleBox + ( 0x7F000 * savindex ) + 0xE8 * i , pba [ i + 36 ] ) ;
2014-12-06 02:14:04 +00:00
2014-06-28 21:22:05 +00:00
// Reload Daycare
2014-12-06 02:14:04 +00:00
Label [ ] dclabela = { L_DC1 , L_DC2 , } ;
TextBox [ ] dctexta = { TB_Daycare1XP , TB_Daycare2XP } ;
2014-06-28 21:22:05 +00:00
for ( int i = 0 ; i < 2 ; i + + )
{
2015-01-03 01:07:29 +00:00
getSlotFiller ( SaveGame . Daycare + ( 0x7F000 * savindex ) + 0xE8 * i + 8 * ( i + 1 ) , pba [ i + 42 ] ) ;
2014-11-22 03:26:16 +00:00
dctexta [ i ] . Text = BitConverter . ToUInt32 ( savefile , SaveGame . Daycare + ( 0x7F000 * savindex ) + 0xF0 * i + 4 ) . ToString ( ) ;
if ( Convert . ToBoolean ( savefile [ SaveGame . Daycare + ( 0x7F000 * savindex ) + 0xF0 * i ] ) ) // If Occupied
2015-01-02 02:05:47 +00:00
dclabela [ i ] . Text = ( i + 1 ) + ": ✓" ;
2014-06-28 21:22:05 +00:00
else
{
2015-01-02 02:05:47 +00:00
dclabela [ i ] . Text = ( i + 1 ) + ": ✘" ;
2014-10-11 07:22:22 +00:00
pba [ i + 42 ] . Image = Util . ChangeOpacity ( pba [ i + 42 ] . Image , 0.6 ) ;
2014-06-28 21:22:05 +00:00
}
}
2014-11-22 03:26:16 +00:00
DayCare_HasEgg . Checked = Convert . ToBoolean ( savefile [ SaveGame . Daycare + ( 0x7F000 * savindex ) + 0x1E0 ] ) ;
TB_RNGSeed . Text = BitConverter . ToUInt64 ( savefile , SaveGame . Daycare + ( 0x7F000 * savindex ) + 0x1E8 ) . ToString ( "X16" ) ;
2014-06-28 21:22:05 +00:00
// GTS
2014-11-22 03:26:16 +00:00
getSlotFiller ( SaveGame . GTS + ( 0x7F000 * savindex ) , pba [ 44 ] ) ;
2014-06-28 21:22:05 +00:00
// Fused
2014-11-22 03:26:16 +00:00
getSlotFiller ( SaveGame . Fused + ( 0x7F000 * savindex ) , pba [ 45 ] ) ;
2014-06-28 21:22:05 +00:00
// SUBE
for ( int i = 0 ; i < 3 ; i + + )
{
int offset = 0x22C90 + i * 0xEC + ( 0x7F000 * savindex ) ;
if ( BitConverter . ToUInt64 ( savefile , offset ) ! = 0 )
getSlotFiller ( offset , pba [ 46 + i ] ) ;
else pba [ 46 + i ] . Image = null ;
}
// Recoloring of a storage box slot (to not show for other storage boxes)
if ( colorizedslot < 32 )
2015-05-07 02:30:31 +00:00
pba [ colorizedslot ] . BackgroundImage = ( colorizedbox = = CB_BoxSelect . SelectedIndex ) ? colorizedcolor : null ;
2014-06-28 21:22:05 +00:00
}
2014-12-24 07:29:57 +00:00
private void setBoxNames ( )
2014-06-28 21:22:05 +00:00
{
2015-05-07 02:30:31 +00:00
int selectedbox = CB_BoxSelect . SelectedIndex ; // precache selected box
2014-06-28 21:22:05 +00:00
// Build ComboBox Dropdown Items
try
{
2015-05-07 02:30:31 +00:00
CB_BoxSelect . Items . Clear ( ) ;
2014-06-28 21:22:05 +00:00
for ( int i = 0 ; i < 31 ; i + + )
2015-05-07 02:30:31 +00:00
CB_BoxSelect . Items . Add ( Encoding . Unicode . GetString ( savefile , SaveGame . PCLayout + ( 0x7F000 * savindex ) + 0x22 * i , 0x22 ) ) ;
2014-06-28 21:22:05 +00:00
}
catch
{
2015-05-07 02:30:31 +00:00
CB_BoxSelect . Items . Clear ( ) ;
2015-01-01 19:38:37 +00:00
for ( int i = 1 ; i < 32 ; i + + )
2015-05-07 02:30:31 +00:00
CB_BoxSelect . Items . Add ( "Box " + i ) ;
2014-06-28 21:22:05 +00:00
}
2015-05-07 02:30:31 +00:00
CB_BoxSelect . SelectedIndex = selectedbox ; // restore selected box
2014-06-28 21:22:05 +00:00
}
2014-10-10 02:59:57 +00:00
private void setSAVLabel ( )
2014-06-28 21:22:05 +00:00
{
L_SAVINDEX . Text = ( savindex + 1 ) . ToString ( ) ;
2015-03-12 04:44:12 +00:00
RTB_S . AppendText ( "Loaded Save File " + ( savindex + 1 ) + Environment . NewLine ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-28 21:56:59 +00:00
private void getSAVOffsets ( ref bool oras )
2014-06-28 21:22:05 +00:00
{
// Get the save file offsets for the input game
bool enableInterface = false ;
if ( BitConverter . ToUInt32 ( savefile , 0x6A810 + 0x7F000 * savindex ) = = 0x42454546 )
2014-12-28 21:56:59 +00:00
{
2014-06-28 21:22:05 +00:00
enableInterface = true ;
2014-12-25 00:20:39 +00:00
SaveGame = new PKX . Structures . SaveGame ( "XY" ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-28 19:28:13 +00:00
else if ( BitConverter . ToUInt32 ( savefile , 0x7B210 + 0x7F000 * savindex ) = = 0x42454546 )
{
enableInterface = true ;
SaveGame = new PKX . Structures . SaveGame ( "ORAS" ) ;
2014-12-28 21:56:59 +00:00
oras = true ;
2014-12-28 19:28:13 +00:00
}
2014-06-28 21:22:05 +00:00
else
{
2014-12-11 06:50:40 +00:00
Util . Error ( "Unrecognized Save File loaded." ) ;
2014-12-25 00:20:39 +00:00
SaveGame = new PKX . Structures . SaveGame ( "Error" ) ;
2014-06-28 21:22:05 +00:00
}
// Enable Buttons
2014-12-15 00:50:15 +00:00
GB_SAVtools . Enabled = B_JPEG . Enabled = B_VerifyCHK . Enabled = B_VerifySHA . Enabled = B_SwitchSAV . Enabled
2014-06-28 21:22:05 +00:00
= enableInterface ;
}
2014-12-20 19:27:29 +00:00
private PictureBox getPictureBox ( int slot )
{
PictureBox [ ] pba = {
bpkx1 , bpkx2 , bpkx3 , bpkx4 , bpkx5 , bpkx6 ,
bpkx7 , bpkx8 , bpkx9 , bpkx10 , bpkx11 , bpkx12 ,
bpkx13 , bpkx14 , bpkx15 , bpkx16 , bpkx17 , bpkx18 ,
bpkx19 , bpkx20 , bpkx21 , bpkx22 , bpkx23 , bpkx24 ,
bpkx25 , bpkx26 , bpkx27 , bpkx28 , bpkx29 , bpkx30 ,
ppkx1 , ppkx2 , ppkx3 , ppkx4 , ppkx5 , ppkx6 ,
bbpkx1 , bbpkx2 , bbpkx3 , bbpkx4 , bbpkx5 , bbpkx6 ,
dcpkx1 , dcpkx2 , gtspkx , fusedpkx , subepkx1 , subepkx2 , subepkx3 ,
} ;
return pba [ slot ] ;
}
private void getQuickFiller ( PictureBox pb , byte [ ] dslotdata = null )
2014-12-14 20:15:53 +00:00
{
2014-12-17 02:56:08 +00:00
if ( ! init ) return ;
2015-03-14 02:59:51 +00:00
dslotdata = dslotdata ? ? preparepkx ( false ) ; // don't perform control loss click
2014-12-14 20:15:53 +00:00
2015-04-28 14:39:50 +00:00
if ( pb = = dragout ) L_QR . Visible = ( BitConverter . ToInt16 ( dslotdata , 0x08 ) ! = 0 ) ; // Species
pb . Image = PKX . getSprite ( dslotdata ) ;
2014-12-14 20:15:53 +00:00
}
2014-06-28 21:22:05 +00:00
private void getSlotFiller ( int offset , PictureBox pb )
{
2014-12-12 05:44:05 +00:00
byte [ ] slotdata = new byte [ 0xE8 ] ;
2014-06-28 21:22:05 +00:00
Array . Copy ( savefile , offset , slotdata , 0 , 0xE8 ) ; // Fill Our EKX Slot
2014-10-10 02:59:57 +00:00
byte [ ] dslotdata = PKX . decryptArray ( slotdata ) ;
2014-06-28 21:22:05 +00:00
2015-04-28 14:39:50 +00:00
if ( PKX . getCHK ( dslotdata ) ! = BitConverter . ToUInt16 ( dslotdata , 6 ) // Invalid Checksum
& & ( ! savLoaded & & ! slotdata . SequenceEqual ( new byte [ 0xE8 ] ) ) ) // And Save Loaded
2014-08-07 00:10:29 +00:00
{
2015-04-28 14:39:50 +00:00
// Bad Egg present in slot.
2014-08-07 00:10:29 +00:00
pb . Image = null ;
pb . BackColor = Color . Red ;
return ;
}
2015-03-11 01:44:51 +00:00
pb . BackColor = Color . Transparent ;
2015-04-28 14:39:50 +00:00
pb . Image = PKX . getSprite ( dslotdata ) ;
2014-06-28 21:22:05 +00:00
}
2014-08-01 23:53:09 +00:00
private void getSlotColor ( int slot , Image color )
2014-06-28 21:22:05 +00:00
{
PictureBox [ ] pba = {
bpkx1 , bpkx2 , bpkx3 , bpkx4 , bpkx5 , bpkx6 ,
bpkx7 , bpkx8 , bpkx9 , bpkx10 , bpkx11 , bpkx12 ,
bpkx13 , bpkx14 , bpkx15 , bpkx16 , bpkx17 , bpkx18 ,
bpkx19 , bpkx20 , bpkx21 , bpkx22 , bpkx23 , bpkx24 ,
bpkx25 , bpkx26 , bpkx27 , bpkx28 , bpkx29 , bpkx30 ,
ppkx1 , ppkx2 , ppkx3 , ppkx4 , ppkx5 , ppkx6 ,
bbpkx1 , bbpkx2 , bbpkx3 , bbpkx4 , bbpkx5 , bbpkx6 ,
dcpkx1 , dcpkx2 , gtspkx , fusedpkx , subepkx1 , subepkx2 , subepkx3 ,
} ;
2014-08-17 01:42:51 +00:00
2015-03-11 01:44:51 +00:00
foreach ( PictureBox t in pba )
t . BackgroundImage = null ;
2014-08-17 01:42:51 +00:00
2014-06-28 21:22:05 +00:00
if ( slot < 32 )
2015-05-07 02:30:31 +00:00
colorizedbox = CB_BoxSelect . SelectedIndex ;
2014-08-17 01:42:51 +00:00
2014-08-01 23:53:09 +00:00
pba [ slot ] . BackgroundImage = color ;
2014-06-28 21:22:05 +00:00
colorizedcolor = color ;
colorizedslot = slot ;
}
private void getBox ( object sender , EventArgs e )
{
2014-10-10 02:59:57 +00:00
setPKXBoxes ( ) ;
2014-06-28 21:22:05 +00:00
}
private void getTSV ( object sender , EventArgs e )
{
2014-12-13 22:48:34 +00:00
uint tsv = PKX . getTSV ( Util . ToUInt32 ( TB_TID . Text ) , Util . ToUInt32 ( TB_SID . Text ) ) ;
2015-02-21 20:59:22 +00:00
Tip1 . SetToolTip ( TB_TID , "TSV: " + tsv . ToString ( "0000" ) ) ;
Tip2 . SetToolTip ( TB_SID , "TSV: " + tsv . ToString ( "0000" ) ) ;
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
uint psv = PKX . getPSV ( Util . getHEXval ( TB_PID ) ) ;
2015-02-21 20:59:22 +00:00
Tip3 . SetToolTip ( TB_PID , "PSV: " + psv . ToString ( "0000" ) ) ;
}
private void getNatureModification ( object sender , EventArgs e )
{
if ( sender is ComboBox & & ( sender as ComboBox ) . Name ! = CB_Nature . Name ) return ;
int nature = Util . getIndex ( CB_Nature ) ;
int incr = nature / 5 ;
int decr = nature % 5 ;
2015-03-11 01:44:51 +00:00
Label [ ] labarray = { Label_ATK , Label_DEF , Label_SPE , Label_SPA , Label_SPD } ;
2015-02-21 20:59:22 +00:00
// Reset Label Colors
foreach ( Label label in labarray )
label . ForeColor = defaultControlText ;
// Set Colored StatLabels only if Nature isn't Neutral
2015-03-11 01:44:51 +00:00
NatureTip . SetToolTip ( CB_Nature ,
incr ! = decr
? String . Format ( "+{0} / -{1}" , labarray [ incr ] . Text , labarray [ decr ] . Text ) . Replace ( ":" , "" )
: "-/-" ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-28 21:56:59 +00:00
private void switchDaycare ( object sender , EventArgs e )
{
if ( ! savegame_oras ) return ;
2015-01-01 19:38:37 +00:00
if ( DialogResult . Yes = = Util . Prompt ( MessageBoxButtons . YesNo , "Would you like to switch the view to the other Daycare?" , String . Format ( "Currently viewing daycare {0}." , SaveGame . Daycare / 0x211F0 + 1 ) ) )
// If ORAS, alter the daycare offset via toggle.
SaveGame . Daycare = ( SaveGame . Daycare = = 0x21000 ) ? 0x211F0 : 0x21000 ;
2014-12-28 21:56:59 +00:00
// Refresh Boxes
setPKXBoxes ( ) ;
}
2014-12-14 19:06:17 +00:00
private void mainMenuBoxDumpLoad ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2014-12-11 07:00:25 +00:00
DialogResult dr = Util . Prompt ( MessageBoxButtons . YesNoCancel , "Press Yes to Import All from Folder." + Environment . NewLine + "Press No to Dump All to Folder." , "Press Cancel to Abort." ) ;
2015-03-11 01:44:51 +00:00
if ( dr = = DialogResult . Cancel ) return ;
string exepath = Application . StartupPath ;
string path = "" ;
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
int offset = SaveGame . Box ;
const int size = 232 ;
if ( dr = = DialogResult . Yes ) // Import
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
if ( Directory . Exists ( Path . Combine ( exepath , "db" ) ) )
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
DialogResult ld = Util . Prompt ( MessageBoxButtons . YesNo , "Load from PKHeX's database?" ) ;
if ( ld = = DialogResult . Yes )
path = Path . Combine ( exepath , "db" ) ;
else if ( ld = = DialogResult . No )
2014-06-28 21:22:05 +00:00
{
// open folder dialog
FolderBrowserDialog fbd = new FolderBrowserDialog ( ) ;
if ( fbd . ShowDialog ( ) = = DialogResult . OK )
path = fbd . SelectedPath ;
}
2015-03-11 01:44:51 +00:00
else return ;
}
else
{
// open folder dialog
FolderBrowserDialog fbd = new FolderBrowserDialog ( ) ;
if ( fbd . ShowDialog ( ) = = DialogResult . OK )
path = fbd . SelectedPath ;
2014-06-28 21:22:05 +00:00
}
2015-03-11 01:44:51 +00:00
loadBoxesFromDB ( path ) ;
}
else if ( dr = = DialogResult . No )
{
// Dump all of box content to files.
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
DialogResult ld = Util . Prompt ( MessageBoxButtons . YesNo , "Save to PKHeX's database?" ) ;
if ( ld = = DialogResult . Yes )
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
path = Path . Combine ( exepath , "db" ) ;
if ( ! Directory . Exists ( path ) )
Directory . CreateDirectory ( path ) ;
2014-06-28 21:22:05 +00:00
}
2015-03-11 01:44:51 +00:00
else if ( ld = = DialogResult . No )
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
// open folder dialog
FolderBrowserDialog fbd = new FolderBrowserDialog ( ) ;
if ( fbd . ShowDialog ( ) = = DialogResult . OK )
path = fbd . SelectedPath ;
2014-06-28 21:22:05 +00:00
}
2015-03-11 01:44:51 +00:00
else return ;
}
for ( int i = 0 ; i < 31 * 30 * size ; i + = size )
{
byte [ ] ekxdata = new byte [ size ] ;
Array . Copy ( savefile , offset + i , ekxdata , 0 , size ) ;
byte [ ] pkxdata = PKX . decryptArray ( ekxdata ) ;
int species = BitConverter . ToInt16 ( pkxdata , 0x08 ) ;
if ( species = = 0 ) continue ;
uint chk = BitConverter . ToUInt16 ( pkxdata , 0x06 ) ;
uint EC = BitConverter . ToUInt32 ( pkxdata , 0 ) ;
uint IV32 = BitConverter . ToUInt32 ( pkxdata , 0x74 ) ;
string nick ;
if ( Convert . ToBoolean ( ( IV32 > > 31 ) & 1 ) )
nick = Util . TrimFromZero ( Encoding . Unicode . GetString ( pkxdata , 0x40 , 24 ) ) + " (" + specieslist [ species ] + ")" ;
else
nick = specieslist [ species ] ;
if ( Convert . ToBoolean ( ( IV32 > > 30 ) & 1 ) )
nick + = " (" + eggname + ")" ;
string isshiny = "" ;
// Is Shiny
if ( PKX . getIsShiny ( BitConverter . ToUInt32 ( pkxdata , 0x18 ) , Util . ToUInt32 ( TB_TID . Text ) , Util . ToUInt32 ( TB_SID . Text ) ) )
isshiny = " ★" ;
string savedname =
species . ToString ( "000" ) + isshiny + " - "
+ nick + " - "
+ chk . ToString ( "X4" ) + EC . ToString ( "X8" )
+ ".pk6" ;
Array . Resize ( ref pkxdata , 232 ) ;
if ( ! File . Exists ( Path . Combine ( path , savedname ) ) )
File . WriteAllBytes ( Path . Combine ( path , Util . CleanFileName ( savedname ) ) , pkxdata ) ;
2014-06-28 21:22:05 +00:00
}
}
}
}
private void loadBoxesFromDB ( string path )
{
if ( path = = "" ) return ;
int offset = SaveGame . Box ;
2015-05-07 02:30:31 +00:00
int ctr = CB_BoxSelect . SelectedIndex * 30 ;
2014-09-05 06:23:05 +00:00
int pastctr = 0 ;
2014-08-31 20:32:04 +00:00
// Clear out the box data array.
2014-09-05 06:23:05 +00:00
// Array.Clear(savefile, offset, size * 30 * 31);
2014-12-14 04:39:31 +00:00
DialogResult dr = Util . Prompt ( MessageBoxButtons . YesNoCancel , "Clear subsequent boxes when importing data?" , "If you only want to overwrite for new data, press no." ) ;
if ( dr = = DialogResult . Cancel ) return ;
2015-03-11 01:44:51 +00:00
if ( dr = = DialogResult . Yes )
2014-09-06 19:52:36 +00:00
{
2014-12-12 05:44:05 +00:00
byte [ ] ezeros = PKX . encryptArray ( new byte [ 232 ] ) ;
2014-09-06 19:52:36 +00:00
for ( int i = ctr ; i < 30 * 31 ; i + + )
Array . Copy ( ezeros , 0 , savefile , offset + i * 232 , 232 ) ;
}
2014-08-15 04:27:53 +00:00
string [ ] filepaths = Directory . GetFiles ( path , "*.*" , SearchOption . TopDirectoryOnly ) ;
2014-10-11 07:22:22 +00:00
var Converter = new pk2pk ( ) ;
2014-08-17 01:42:51 +00:00
2015-03-11 01:44:51 +00:00
foreach ( string t in filepaths )
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
long len = new FileInfo ( t ) . Length ;
2015-01-01 19:38:37 +00:00
if ( len > 260 )
2014-12-13 22:48:34 +00:00
continue ;
2015-03-11 01:44:51 +00:00
if (
len ! = 232 & & len ! = 260 // 6th Gen
2014-08-15 22:28:33 +00:00
& & len ! = 136 & & len ! = 220 & & len ! = 236 // 5th Gen
& & len ! = 100 & & len ! = 80 ) // 4th Gen
2014-06-28 21:22:05 +00:00
continue ;
2014-12-12 05:44:05 +00:00
byte [ ] data = new byte [ 232 ] ;
2015-04-28 14:39:50 +00:00
switch ( Path . GetExtension ( t ) ) // Filter all files by extension
2014-08-15 04:27:53 +00:00
{
2015-03-11 01:44:51 +00:00
case ".pk5" :
case ".pk4" :
case ".pk3" :
case ".3gpkm" :
case ".pkm" :
2014-08-15 04:27:53 +00:00
{
2015-03-11 01:44:51 +00:00
// Verify PKM (decrypted)
byte [ ] input = File . ReadAllBytes ( t ) ;
2015-04-28 14:39:50 +00:00
if ( ! PKX . verifychk ( input ) ) continue ;
2015-03-11 01:44:51 +00:00
{
try // to convert g5pkm
{ data = PKX . encryptArray ( Converter . ConvertPKM ( input , savefile , savindex ) ) ; pastctr + + ; }
2015-04-28 14:39:50 +00:00
catch { continue ; }
2015-03-11 01:44:51 +00:00
}
2014-08-15 04:27:53 +00:00
}
2015-03-11 01:44:51 +00:00
break ;
case ".pk6" :
case ".pkx" :
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
byte [ ] input = File . ReadAllBytes ( t ) ;
if ( ( BitConverter . ToUInt16 ( input , 0xC8 ) = = 0 ) & & ( BitConverter . ToUInt16 ( input , 0x58 ) = = 0 ) )
{
if ( BitConverter . ToUInt16 ( input , 0x8 ) = = 0 ) // if species = 0
continue ;
Array . Resize ( ref input , 232 ) ;
2015-04-28 14:39:50 +00:00
if ( PKX . getCHK ( input ) ! = BitConverter . ToUInt16 ( input , 0x6 ) ) continue ;
2015-03-11 01:44:51 +00:00
data = PKX . encryptArray ( input ) ;
}
}
break ;
case ".ek6" :
case ".ekx" :
{
byte [ ] input = File . ReadAllBytes ( t ) ;
2014-06-28 21:22:05 +00:00
Array . Resize ( ref input , 232 ) ;
2015-03-11 01:44:51 +00:00
Array . Copy ( input , data , 232 ) ;
// check if it is good data
byte [ ] decrypteddata = PKX . decryptArray ( input ) ;
if ( BitConverter . ToUInt16 ( decrypteddata , 0xC8 ) ! = 0 & & BitConverter . ToUInt16 ( decrypteddata , 0x58 ) ! = 0 )
continue ; // don't allow improperly encrypted files. they must be encrypted properly.
//else if (BitConverter.ToUInt16(decrypteddata, 0x8) == 0) // if species = 0
// continue;
2015-04-28 14:39:50 +00:00
// We'll allow blank ekx files for those wanting to see the decrypted data.
if ( PKX . getCHK ( input ) ! = BitConverter . ToUInt16 ( decrypteddata , 0x6 ) ) continue ;
2014-06-28 21:22:05 +00:00
}
2015-03-11 01:44:51 +00:00
break ;
default :
continue ;
2014-06-28 21:22:05 +00:00
}
2015-04-28 14:39:50 +00:00
Array . Copy ( data , 0 , savefile , offset + ctr + + * 232 , 232 ) ;
2014-10-10 02:59:57 +00:00
setPokedex ( PKX . decryptArray ( data ) ) ; // Set the Pokedex data
2014-06-28 21:22:05 +00:00
if ( ctr = = 30 * 31 ) break ; // break out if we have written all 31 boxes
}
2015-03-11 01:44:51 +00:00
if ( ctr < = 0 ) return ;
// if we've written at least one pk6 in, go ahead and make sure the window is stretched.
if ( Width < Height ) // expand if boxes aren't visible
2014-06-28 21:22:05 +00:00
{
2015-03-11 01:44:51 +00:00
Width = largeWidth ;
tabBoxMulti . SelectedIndex = 0 ;
2014-06-28 21:22:05 +00:00
}
2015-03-11 01:44:51 +00:00
setPKXBoxes ( ) ;
string result = String . Format ( "Loaded {0} files to boxes." , ctr ) ;
if ( pastctr > 0 )
Util . Alert ( result , String . Format ( "Conversion successful for {0} past generation files." , pastctr ) ) ;
else
Util . Alert ( result ) ;
2014-06-28 21:22:05 +00:00
}
2015-01-25 19:24:00 +00:00
private void B_SaveBoxBin_Click ( object sender , EventArgs e )
2015-01-24 19:16:20 +00:00
{
2015-05-07 02:30:31 +00:00
DialogResult dr = Util . Prompt ( MessageBoxButtons . YesNoCancel , "Yes: Export All Boxes" + Environment . NewLine + String . Format ( "No: Export {1} (Box {0})" , CB_BoxSelect . SelectedIndex + 1 , CB_BoxSelect . Text ) + Environment . NewLine + "Cancel: Abort" ) ;
2015-01-25 19:24:00 +00:00
if ( dr = = DialogResult . Yes )
{
2015-03-11 01:44:51 +00:00
SaveFileDialog sfd = new SaveFileDialog { Filter = "Box Data|*.bin" , FileName = "pcdata.bin" } ;
if ( sfd . ShowDialog ( ) = = DialogResult . OK )
2015-01-25 19:24:00 +00:00
File . WriteAllBytes ( sfd . FileName , savefile . Skip ( SaveGame . Box ) . Take ( 0xE8 * 30 * 31 ) . ToArray ( ) ) ;
}
2015-02-01 04:40:35 +00:00
else if ( dr = = DialogResult . No )
2015-01-24 19:16:20 +00:00
{
2015-03-11 01:44:51 +00:00
SaveFileDialog sfd = new SaveFileDialog { Filter = "Box Data|*.bin" , FileName = "boxdata.bin" } ;
if ( sfd . ShowDialog ( ) = = DialogResult . OK )
2015-05-07 02:30:31 +00:00
File . WriteAllBytes ( sfd . FileName , savefile . Skip ( SaveGame . Box + 0xE8 * 30 * CB_BoxSelect . SelectedIndex ) . Take ( 0xE8 * 30 ) . ToArray ( ) ) ;
2015-01-24 19:16:20 +00:00
}
}
2014-12-14 19:06:17 +00:00
// Subfunction Save Buttons //
2014-06-28 21:22:05 +00:00
private void B_OpenWondercards_Click ( object sender , EventArgs e )
{
// Open Wondercard Menu
2014-12-06 02:14:04 +00:00
new SAV_Wondercard ( this ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenBoxLayout_Click ( object sender , EventArgs e )
{
// Open Box Layout Menu
2014-12-06 02:14:04 +00:00
new SAV_BoxLayout ( this ) . ShowDialog ( ) ;
setBoxNames ( ) ; // fix box names
setPKXBoxes ( ) ; // refresh box background
2014-06-28 21:22:05 +00:00
}
private void B_OpenTrainerInfo_Click ( object sender , EventArgs e )
{
2014-12-06 02:14:04 +00:00
new SAV_Trainer ( this ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenPokepuffs_Click ( object sender , EventArgs e )
{
2014-12-06 02:14:04 +00:00
new SAV_Pokepuff ( this ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenItemPouch_Click ( object sender , EventArgs e )
{
2014-12-06 02:14:04 +00:00
new SAV_Inventory ( this ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenBerryField_Click ( object sender , EventArgs e )
{
2014-11-26 06:24:32 +00:00
if ( savegame_oras )
{
2014-12-11 06:50:40 +00:00
DialogResult dr = Util . Prompt ( MessageBoxButtons . YesNo , "No editing support for ORAS :(" , "Repopulate all with random berries?" ) ;
2015-03-11 01:44:51 +00:00
if ( dr ! = DialogResult . Yes ) return ; // abort
// Randomize the trees.
int offset = 0x1C400 + 0x5400 + savindex * 0x7F000 ;
byte [ ] ready = { 0x05 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xFF , 0xFF , 0x00 , 0x00 , 0x80 , 0x40 , 0x01 , 0x00 , 0x00 , 0x00 , } ;
int [ ] berrylist =
2014-11-26 06:24:32 +00:00
{
2015-03-11 01:44:51 +00:00
0 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 ,
163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 ,
178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 ,
193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 ,
208 , 209 , 210 , 211 , 212 , 686 , 687 , 688 ,
} ;
for ( int i = 0 ; i < 90 ; i + + )
{
Array . Copy ( ready , 0 , savefile , offset + 0x10 * i , 0x10 ) ; // prep the berry template tree (which we replace offset 0x6 for the Tree Item)
int randberry = ( int ) ( Util . rnd32 ( ) % berrylist . Length ) ; // generate a random berry that will go into the tree
int index = berrylist [ randberry ] ; // get berry item ID from list
Array . Copy ( BitConverter . GetBytes ( index ) , 0 , savefile , offset + 0x10 * i + 6 , 2 ) ; // put berry into tree.
2014-11-26 06:24:32 +00:00
}
}
2015-01-01 19:38:37 +00:00
else
2014-12-06 02:14:04 +00:00
new SAV_BerryField ( this , SaveGame . BerryField ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenEventFlags_Click ( object sender , EventArgs e )
{
// Open Flag Menu
2015-01-01 19:38:37 +00:00
if ( savegame_oras )
2014-12-06 02:14:04 +00:00
new SAV_EventFlagsORAS ( this ) . ShowDialog ( ) ;
2015-01-01 19:38:37 +00:00
else
2014-12-06 02:14:04 +00:00
new SAV_EventFlagsXY ( this ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-07-31 22:06:48 +00:00
private void B_OpenSuperTraining_Click ( object sender , EventArgs e )
{
// Open ST Menu
2014-12-06 02:14:04 +00:00
new SAV_SuperTrain ( this ) . ShowDialog ( ) ;
2014-07-31 22:06:48 +00:00
}
2014-07-27 01:00:17 +00:00
private void B_OpenOPowers_Click ( object sender , EventArgs e )
{
// Open O-Power Menu
2014-11-25 03:53:10 +00:00
if ( savegame_oras )
{
2014-12-11 06:50:40 +00:00
DialogResult dr = Util . Prompt ( MessageBoxButtons . YesNo , "No editing support for ORAS :(" , "Max O-Powers with a working code?" ) ;
2015-03-11 01:44:51 +00:00
if ( dr ! = DialogResult . Yes ) return ;
byte [ ] maxoras =
{
0x00 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x00 , 0x01 , 0x01 ,
0x01 , 0x01 , 0x00 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x00 ,
0x01 , 0x01 , 0x01 , 0x01 ,
0x00 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x00 , 0x01 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x01 , 0x00 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x00 ,
0x01 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x01 , 0x01 , 0x01 ,
0x01 , 0x00 , 0x00 , 0x00 ,
} ;
Array . Copy ( maxoras , 0 , savefile , 0x17400 + 0x5400 + 0x7F000 * savindex , 0x44 ) ;
2014-11-25 03:53:10 +00:00
}
2015-01-01 19:38:37 +00:00
else
2014-12-06 02:14:04 +00:00
new SAV_OPower ( this ) . ShowDialog ( ) ;
2014-07-27 01:00:17 +00:00
}
2014-07-28 01:30:54 +00:00
private void B_OpenPokedex_Click ( object sender , EventArgs e )
{
// Open Pokedex Menu
2015-01-01 19:38:37 +00:00
if ( savegame_oras )
2014-12-06 02:14:04 +00:00
new SAV_PokedexORAS ( this ) . ShowDialog ( ) ;
2015-01-01 19:38:37 +00:00
else
2014-12-06 02:14:04 +00:00
new SAV_PokedexXY ( this ) . ShowDialog ( ) ;
2014-07-28 01:30:54 +00:00
}
2014-06-28 21:22:05 +00:00
private void B_OUTPasserby_Click ( object sender , EventArgs e )
{
2014-07-31 22:06:48 +00:00
string result = "" ;
2015-01-03 01:07:29 +00:00
result + = "PSS List" + Environment . NewLine ;
2014-06-28 21:22:05 +00:00
string [ ] headers = {
"PSS Data - Friends" ,
"PSS Data - Acquaintances" ,
"PSS Data - Passerby" ,
} ;
int offset = savindex * 0x7F000 + SaveGame . PSS ;
for ( int g = 0 ; g < 3 ; g + + )
{
2015-01-03 01:07:29 +00:00
result + = Environment . NewLine
+ "----" + Environment . NewLine
+ headers [ g ] + Environment . NewLine
+ "----" + Environment . NewLine ;
2015-03-11 01:44:51 +00:00
// uint count = BitConverter.ToUInt32(savefile, offset + 0x4E20);
2014-06-28 21:22:05 +00:00
int r_offset = offset ;
for ( int i = 0 ; i < 100 ; i + + )
{
ulong unkn = BitConverter . ToUInt64 ( savefile , r_offset ) ;
2015-01-03 01:07:29 +00:00
if ( unkn = = 0 ) break ; // No data present here
if ( i > 0 ) result + = Environment . NewLine + Environment . NewLine ;
2014-06-28 21:22:05 +00:00
2014-08-31 20:32:04 +00:00
string otname = Util . TrimFromZero ( Encoding . Unicode . GetString ( savefile , r_offset + 8 , 0x1A ) ) ;
string message = Util . TrimFromZero ( Encoding . Unicode . GetString ( savefile , r_offset + 0x22 , 0x22 ) ) ;
2014-06-28 21:22:05 +00:00
// Trim terminated
2015-03-11 01:44:51 +00:00
// uint unk1 = BitConverter.ToUInt32(savefile, r_offset + 0x44);
// ulong unk2 = BitConverter.ToUInt64(savefile, r_offset + 0x48);
// uint unk3 = BitConverter.ToUInt32(savefile, r_offset + 0x50);
// uint unk4 = BitConverter.ToUInt16(savefile, r_offset + 0x54);
2014-06-28 21:22:05 +00:00
byte region = savefile [ r_offset + 0x56 ] ;
byte country = savefile [ r_offset + 0x57 ] ;
byte game = savefile [ r_offset + 0x5A ] ;
2015-03-11 01:44:51 +00:00
// ulong outfit = BitConverter.ToUInt64(savefile, r_offset + 0x5C);
2014-06-28 21:22:05 +00:00
int favpkm = BitConverter . ToUInt16 ( savefile , r_offset + 0x9C ) & 0x7FF ;
2015-03-11 01:44:51 +00:00
string gamename ;
try { gamename = gamelist [ game ] ; }
catch { gamename = "UNKNOWN GAME" ; }
2014-12-17 03:12:16 +00:00
string [ ] cr = PKX . getCountryRegionText ( country , region , curlanguage ) ;
2015-01-01 19:38:37 +00:00
result + =
2014-12-11 07:00:25 +00:00
"OT: " + otname + Environment . NewLine +
"Message: " + message + Environment . NewLine +
"Game: " + gamename + Environment . NewLine +
2014-12-26 18:46:18 +00:00
"Country: " + cr [ 0 ] + Environment . NewLine +
"Region: " + cr [ 1 ] + Environment . NewLine +
2015-01-03 01:07:29 +00:00
"Favorite: " + specieslist [ favpkm ] ;
2014-12-11 07:00:25 +00:00
2015-01-03 01:07:29 +00:00
r_offset + = 0xC8 ; // Advance to next entry
2014-06-28 21:22:05 +00:00
}
2015-01-03 01:07:29 +00:00
offset + = 0x5000 ; // Advance to next block
2014-06-28 21:22:05 +00:00
}
2014-07-31 22:06:48 +00:00
RTB_T . Text = result ;
2014-06-28 21:22:05 +00:00
RTB_T . Font = new Font ( "Courier New" , 8 ) ;
2014-07-31 22:06:48 +00:00
tabBoxMulti . SelectedIndex = 3 ;
2014-06-28 21:22:05 +00:00
}
private void B_OUTHallofFame_Click ( object sender , EventArgs e )
{
// Open HoF Menu
2014-12-06 02:14:04 +00:00
new SAV_HallOfFame ( this ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-11-23 22:23:40 +00:00
private void B_OpenSecretBase_Click ( object sender , EventArgs e )
{
// Open Secret Base Menu
2015-01-01 19:38:37 +00:00
new SAV_SecretBase ( this ) . ShowDialog ( ) ;
2014-11-23 22:23:40 +00:00
}
2014-12-14 19:06:17 +00:00
private void B_JPEG_Click ( object sender , EventArgs e )
{
int offset = 0x7F000 * savindex + SaveGame . JPEG ;
string filename = Encoding . Unicode . GetString ( savefile , offset + 0 , 0x1A ) . Replace ( "\0" , string . Empty ) ;
filename + = "'s picture" ;
offset + = 0x54 ;
if ( savefile [ offset ] ! = 0xFF )
{
Util . Alert ( "No PGL picture data found in the save file!" ) ;
return ;
}
2015-03-11 01:44:51 +00:00
const int length = 0xE004 ;
2014-12-14 19:06:17 +00:00
byte [ ] jpeg = new byte [ length ] ;
Array . Copy ( savefile , offset , jpeg , 0 , length ) ;
2015-03-11 01:44:51 +00:00
SaveFileDialog savejpeg = new SaveFileDialog { FileName = filename , Filter = "JPEG|*.jpeg" } ;
if ( savejpeg . ShowDialog ( ) ! = DialogResult . OK ) return ;
string path = savejpeg . FileName ;
if ( File . Exists ( path ) )
2014-12-14 19:06:17 +00:00
{
2015-03-11 01:44:51 +00:00
// File already exists, save a .bak
byte [ ] backupfile = File . ReadAllBytes ( path ) ;
File . WriteAllBytes ( path + ".bak" , backupfile ) ;
2014-12-14 19:06:17 +00:00
}
2015-03-11 01:44:51 +00:00
File . WriteAllBytes ( path , jpeg ) ;
2014-12-14 19:06:17 +00:00
}
2014-12-24 07:29:57 +00:00
// Save Folder Related
2014-12-14 19:06:17 +00:00
private void clickSaveFileName ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
// Get latest SaveDataFiler save location
2015-01-27 06:05:04 +00:00
pathSDF = Util . GetSDFLocation ( ) ;
2014-12-13 22:48:34 +00:00
string path = null ;
2015-09-05 01:50:14 +00:00
bool sdbPath = File . Exists ( Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" , "main" ) ) ;
2014-12-13 22:48:34 +00:00
2015-09-05 01:50:14 +00:00
if ( sdbPath & & ModifierKeys ! = Keys . Control )
path = Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" , "main" ) ;
else if ( pathSDF ! = null & & ModifierKeys ! = Keys . Shift ) // if we have a result
2015-01-27 06:05:04 +00:00
path = Path . Combine ( pathSDF , "main" ) ;
2014-12-13 22:48:34 +00:00
else if ( File . Exists ( Util . NormalizePath ( Path . Combine ( Util . GetTempFolder ( ) , "root" + Path . DirectorySeparatorChar + "main" ) ) ) ) // else if cgse exists
path = Util . NormalizePath ( Path . Combine ( Util . GetTempFolder ( ) , "root" + Path . DirectorySeparatorChar + "main" ) ) ;
2015-03-11 01:44:51 +00:00
if ( path = = null ) return ;
if ( Util . Prompt ( MessageBoxButtons . YesNo , "Open save file from the following location?" , path ) = = DialogResult . Yes )
openQuick ( path ) ; // load save
2014-12-13 22:48:34 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickOpenTempFolder ( object sender , EventArgs e )
2014-07-31 22:06:48 +00:00
{
2014-08-12 23:37:26 +00:00
string path ;
2015-03-11 01:44:51 +00:00
switch ( ModifierKeys )
{
case Keys . Control : // Cache
path = Util . GetCacheFolder ( ) ;
if ( Directory . Exists ( path ) ) System . Diagnostics . Process . Start ( "explorer.exe" , @path ) ; else Util . Alert ( "Can't find the cache folder." ) ;
break ;
2015-09-05 01:50:14 +00:00
case Keys . Shift : // SaveDataBackup
Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" , "main" ) ;
if ( path3DS ! = null & & File . Exists ( path = Path . Combine ( Path . GetDirectoryName ( path3DS ) , "SaveDataBackup" , "main" ) ) )
System . Diagnostics . Process . Start ( "explorer.exe" , @Path . GetDirectoryName ( path ) ) ; else Util . Alert ( "Can't find the SaveDataBackup folder." ) ;
break ;
2015-03-11 01:44:51 +00:00
case Keys . Alt : // SaveDataFiler
path = Util . GetSDFLocation ( ) ;
if ( Directory . Exists ( path ) ) System . Diagnostics . Process . Start ( "explorer.exe" , @path ) ; else Util . Alert ( "Can't find the SDF folder." ) ;
break ;
default : // Root
path = Util . GetTempFolder ( ) ;
if ( Directory . Exists ( Path . Combine ( path , "root" ) ) ) System . Diagnostics . Process . Start ( "explorer.exe" , @Path . Combine ( path , "root" ) ) ;
else if ( Directory . Exists ( path ) ) System . Diagnostics . Process . Start ( "explorer.exe" , @path ) ;
else { Util . Error ( "Can't find the temporary file." , "Make sure the Cyber Gadget software is paused." ) ; }
break ;
2014-08-12 23:37:26 +00:00
}
2014-07-31 22:06:48 +00:00
}
2015-03-11 01:44:51 +00:00
2014-12-14 19:06:17 +00:00
private void clickSwitchSAV ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2015-01-01 19:38:37 +00:00
DialogResult switchsav = Util . Prompt ( MessageBoxButtons . YesNo , String . Format ( "Current Savefile is Save {0}." , ( savindex + 1 ) ) , String . Format ( "Would you like to switch to Save {0}?" , ( ( savindex + 1 ) % 2 + 1 ) ) ) ;
2015-03-11 01:44:51 +00:00
if ( switchsav ! = DialogResult . Yes ) return ;
savindex = ( savindex + 1 ) % 2 ;
setBoxNames ( ) ;
setPKXBoxes ( ) ;
setSAVLabel ( ) ;
2015-08-07 05:32:12 +00:00
int startBox = savefile [ SaveGame . PCLayout + savindex * 0x7FFFF + 0x43F ] & 0x1F ;
if ( startBox > 30 ) { tabBoxMulti . SelectedIndex = 1 ; CB_BoxSelect . SelectedIndex = 0 ; }
else { tabBoxMulti . SelectedIndex = 0 ; CB_BoxSelect . SelectedIndex = startBox ; }
2014-06-28 21:22:05 +00:00
}
2014-11-26 04:43:02 +00:00
2014-11-26 06:24:32 +00:00
// Drag & Drop within Box
2014-11-26 04:43:02 +00:00
private void pbBoxSlot_MouseDown ( object sender , MouseEventArgs e )
{
2014-11-29 19:07:01 +00:00
if ( ModifierKeys = = Keys . Control | | ModifierKeys = = Keys . Alt | | ModifierKeys = = Keys . Shift | | ModifierKeys = = ( Keys . Control | Keys . Alt ) )
2015-03-11 01:44:51 +00:00
{ clickSlot ( sender , e ) ; return ; }
2014-11-26 04:43:02 +00:00
PictureBox pb = ( PictureBox ) ( sender ) ;
if ( pb . Image = = null )
return ;
2014-12-20 19:27:29 +00:00
pkm_from_slot = getSlot ( sender ) ;
int offset = getPKXOffset ( pkm_from_slot ) ;
2015-03-11 01:44:51 +00:00
if ( e . Button ! = MouseButtons . Left | | e . Clicks ! = 1 ) return ;
// Create Temp File to Drag
string basepath = Application . StartupPath ;
Cursor . Current = Cursors . Hand ;
// Prepare Data
Array . Copy ( savefile , offset , pkm_from , 0 , 0xE8 ) ;
pkm_from_offset = offset ;
// Make a new file name based off the PID
byte [ ] dragdata = PKX . decryptArray ( pkm_from ) ;
Array . Resize ( ref dragdata , 0xE8 ) ;
PKX pkx = new PKX ( dragdata , "Boxes" ) ;
string filename = pkx . Nickname ;
if ( filename ! = pkx . Species )
filename + = " (" + pkx . Species + ")" ;
filename + = " - " + pkx . PID + ".pk6" ;
// Make File
string newfile = Path . Combine ( basepath , Util . CleanFileName ( filename ) ) ;
try
2014-11-26 04:43:02 +00:00
{
2015-03-11 01:44:51 +00:00
File . WriteAllBytes ( newfile , dragdata ) ;
2014-11-30 18:59:10 +00:00
2015-03-11 01:44:51 +00:00
string [ ] filesToDrag = { newfile } ;
DoDragDrop ( new DataObject ( DataFormats . FileDrop , filesToDrag ) , DragDropEffects . Move ) ;
File . Delete ( newfile ) ; // after drop, delete the temporary file
2014-11-26 04:43:02 +00:00
}
2015-03-11 01:44:51 +00:00
catch ( ArgumentException x )
{ Util . Error ( "Drag & Drop Error:" , x . ToString ( ) ) ; }
File . Delete ( newfile ) ;
pkm_from_offset = 0 ;
2014-11-26 04:43:02 +00:00
}
private void pbBoxSlot_DragDrop ( object sender , DragEventArgs e )
{
int slot = getSlot ( sender ) ;
int offset = getPKXOffset ( slot ) ;
2014-11-30 18:59:10 +00:00
// Check for In-Dropped files (PKX,SAV,ETC)
string [ ] files = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
2014-12-14 04:39:31 +00:00
if ( Directory . Exists ( files [ 0 ] ) ) { loadBoxesFromDB ( files [ 0 ] ) ; return ; }
2015-03-11 01:44:51 +00:00
if ( pkm_from_offset = = 0 )
2014-11-30 18:59:10 +00:00
{
if ( files . Length > 0 )
{
FileInfo fi = new FileInfo ( files [ 0 ] ) ;
// Detect if PKM/PKX
if ( ( fi . Length = = 136 ) | | ( fi . Length = = 220 ) | | ( fi . Length = = 236 ) | | ( fi . Length = = 100 ) | | ( fi . Length = = 80 ) )
{
byte [ ] input = File . ReadAllBytes ( files [ 0 ] ) ;
var Converter = new pk2pk ( ) ;
2014-12-11 06:50:40 +00:00
if ( ! PKX . verifychk ( input ) ) Util . Alert ( "Invalid File Loaded." , "Checksum is not valid." ) ;
2014-11-30 18:59:10 +00:00
try // to convert past gen pkm
{
byte [ ] data = Converter . ConvertPKM ( input , savefile , savindex ) ;
Array . Copy ( PKX . encryptArray ( data ) , 0 , savefile , offset , 0xE8 ) ;
}
catch
2014-12-11 06:50:40 +00:00
{ Util . Error ( "Attempted to load previous generation PKM." , "Conversion failed." ) ; }
2014-11-30 18:59:10 +00:00
}
else if ( fi . Length = = 232 | | fi . Length = = 260 )
{
byte [ ] data = File . ReadAllBytes ( files [ 0 ] ) ;
if ( fi . Extension = = ".pkx" | | fi . Extension = = ".pk6" )
data = PKX . encryptArray ( data ) ;
2014-12-14 20:15:53 +00:00
else if ( fi . Extension ! = ".ekx" & & fi . Extension ! = ".ek6" )
2014-12-06 02:14:04 +00:00
{ openQuick ( files [ 0 ] ) ; return ; } // lazy way of aborting
2014-11-30 18:59:10 +00:00
2014-12-14 20:15:53 +00:00
byte [ ] decdata = PKX . decryptArray ( data ) ;
2014-12-20 19:27:29 +00:00
if ( ! PKX . verifychk ( decdata ) )
Util . Alert ( "Attempted to load Invalid File." , "Checksum is not valid." ) ;
else
{
Array . Copy ( data , 0 , savefile , offset , 0xE8 ) ;
setPokedex ( decdata ) ;
getQuickFiller ( getPictureBox ( slot ) , decdata ) ;
getSlotColor ( slot , Properties . Resources . slotSet ) ;
}
2014-11-30 18:59:10 +00:00
}
else // not PKX/EKX, so load with the general function
{ openQuick ( files [ 0 ] ) ; }
}
}
else
{
2014-12-20 19:27:29 +00:00
if ( ModifierKeys = = Keys . Alt & & slot > - 1 ) // overwrite delete old slot
{
byte [ ] cleardata = new Byte [ 0xE8 ] ;
// Clear from slot picture
getQuickFiller ( getPictureBox ( pkm_from_slot ) , cleardata ) ;
// Clear from slot data
2015-01-01 19:38:37 +00:00
Array . Copy ( PKX . encryptArray ( cleardata ) , 0 , savefile , pkm_from_offset , 0xE8 ) ;
2014-12-20 19:27:29 +00:00
}
else if ( ModifierKeys ! = Keys . Control & & slot > - 1 )
{
2014-12-20 22:44:17 +00:00
// Load data from destination
2014-12-20 19:27:29 +00:00
byte [ ] swapdata = new Byte [ 0xE8 ] ;
2014-12-20 22:44:17 +00:00
Array . Copy ( savefile , offset , swapdata , 0 , 0xE8 ) ;
2014-12-20 19:27:29 +00:00
// Swap slot picture
getQuickFiller ( getPictureBox ( pkm_from_slot ) , PKX . decryptArray ( swapdata ) ) ;
2014-12-20 22:44:17 +00:00
// Swap slot data to source
Array . Copy ( swapdata , 0 , savefile , pkm_from_offset , 0xE8 ) ;
2014-12-20 19:27:29 +00:00
}
2014-12-20 22:44:17 +00:00
// Copy from temp slot to new.
Array . Copy ( pkm_from , 0 , savefile , offset , 0xE8 ) ;
2014-12-20 19:27:29 +00:00
getQuickFiller ( getPictureBox ( slot ) , PKX . decryptArray ( pkm_from ) ) ;
2014-12-20 22:44:17 +00:00
2014-11-30 18:59:10 +00:00
pkm_from_offset = 0 ; // Clear offset value
}
2014-12-20 19:27:29 +00:00
2014-12-14 20:15:53 +00:00
savedited = true ;
2014-11-26 04:43:02 +00:00
}
private void pbBoxSlot_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data ! = null )
e . Effect = DragDropEffects . Move ;
}
2014-12-12 05:44:05 +00:00
private byte [ ] pkm_from = PKX . encryptArray ( new byte [ 0xE8 ] ) ;
2015-03-11 01:44:51 +00:00
private int pkm_from_offset ;
2014-12-20 19:27:29 +00:00
private int pkm_from_slot = - 1 ;
2014-12-13 22:48:34 +00:00
#endregion
2014-06-28 21:22:05 +00:00
}
2015-03-03 17:11:21 +00:00
}