2014-06-28 21:22:05 +00:00
using System ;
using System.Collections.Generic ;
2016-07-31 21:40:09 +00:00
using System.Deployment.Application ;
2016-01-03 04:22:53 +00:00
using System.Diagnostics ;
2014-06-28 21:22:05 +00:00
using System.Drawing ;
using System.IO ;
2015-02-13 04:26:23 +00:00
using System.Linq ;
2016-01-03 18:47:44 +00:00
using System.Media ;
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
{
2015-09-21 03:34:09 +00:00
public partial class Main : Form
2014-06-28 21:22:05 +00:00
{
2015-09-21 03:34:09 +00:00
public Main ( )
2014-06-28 21:22:05 +00:00
{
#region Initialize Form
2016-01-24 18:19:30 +00:00
new Thread ( ( ) = > new SplashScreen ( ) . ShowDialog ( ) ) . Start ( ) ;
2016-06-20 04:22:43 +00:00
pkm_from = SAV . BlankPKM . EncryptedPartyData ;
2014-06-28 21:22:05 +00:00
InitializeComponent ( ) ;
2016-06-20 04:22:43 +00:00
CB_ExtraBytes . SelectedIndex = 0 ;
SaveFile . SetUpdateDex = Menu_ModifyDex . Checked ;
2016-07-10 17:32:51 +00:00
SaveFile . SetUpdatePKM = Menu_ModifyPKM . Checked ;
2016-07-09 21:01:31 +00:00
getFieldsfromPKM = populateFieldsPK6 ;
getPKMfromFields = preparePK6 ;
2016-06-20 04:22:43 +00:00
// Set up form properties and arrays.
2015-09-21 03:34:09 +00:00
SlotPictureBoxes = new [ ] {
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 ,
} ;
2016-03-15 06:26:29 +00:00
relearnPB = new [ ] { PB_WarnRelearn1 , PB_WarnRelearn2 , PB_WarnRelearn3 , PB_WarnRelearn4 } ;
movePB = new [ ] { PB_WarnMove1 , PB_WarnMove2 , PB_WarnMove3 , PB_WarnMove4 } ;
2014-12-20 04:22:15 +00:00
defaultControlWhite = CB_Species . BackColor ;
defaultControlText = Label_Species . ForeColor ;
2015-11-19 05:37:30 +00:00
2014-06-28 21:22:05 +00:00
// 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
2015-11-19 05:37:30 +00:00
// ToolTips for Drag&Drop
2016-06-20 04:22:43 +00:00
new ToolTip ( ) . SetToolTip ( dragout , "PKM QuickSave" ) ;
2015-11-19 05:37:30 +00:00
// Box Drag & Drop
foreach ( PictureBox pb in PAN_Box . Controls )
2015-11-22 18:45:44 +00:00
{
2016-06-20 04:22:43 +00:00
pb . AllowDrop = true ; // The PictureBoxes have their own drag&drop event handlers (pbBoxSlot)
2015-11-22 18:45:44 +00:00
}
foreach ( TabPage tab in tabMain . TabPages )
{
tab . AllowDrop = true ;
tab . DragDrop + = tabMain_DragDrop ;
tab . DragEnter + = tabMain_DragEnter ;
}
foreach ( TabPage tab in tabBoxMulti . TabPages )
{
tab . AllowDrop = true ;
tab . DragDrop + = tabMain_DragDrop ;
tab . DragEnter + = tabMain_DragEnter ;
}
2015-11-19 05:37:30 +00:00
2016-06-20 04:22:43 +00:00
GB_OT . Click + = clickGT ;
GB_nOT . Click + = clickGT ;
GB_Daycare . Click + = switchDaycare ;
GB_RelearnMoves . Click + = clickMoves ;
TB_Nickname . Font = PKX . getPKXFont ( 11 ) ;
TB_OT . Font = ( Font ) TB_Nickname . Font . Clone ( ) ;
TB_OTt2 . Font = ( Font ) TB_Nickname . Font . Clone ( ) ;
2016-03-23 03:14:11 +00:00
2016-03-23 03:30:48 +00:00
Menu_Modify . DropDown . Closing + = ( sender , e ) = >
2016-03-23 03:14:11 +00:00
{
if ( e . CloseReason = = ToolStripDropDownCloseReason . ItemClicked )
e . Cancel = true ;
} ;
2016-06-20 04:22:43 +00:00
// Box to Tabs D&D
dragout . AllowDrop = true ;
2016-07-31 03:57:45 +00:00
FLP_SAVtools . Scroll + = Util . PanelScroll ;
2016-07-29 23:00:56 +00:00
2016-06-20 04:22:43 +00:00
// Load WC6 folder to legality
refreshWC6DB ( ) ;
2015-11-19 05:37:30 +00:00
#endregion
#region Localize & Populate Fields
2016-06-20 04:22:43 +00:00
string [ ] args = Environment . GetCommandLineArgs ( ) ;
2016-07-18 18:51:26 +00:00
string filename = args . Length > 0 ? Path . GetFileNameWithoutExtension ( args [ 0 ] ) ? . ToLower ( ) : "" ;
2016-06-20 04:22:43 +00:00
HaX = filename . IndexOf ( "hax" , StringComparison . Ordinal ) > = 0 ;
2014-06-28 21:22:05 +00:00
// Try and detect the language
2016-01-05 06:42:38 +00:00
string lastTwoChars = filename . Length > 2 ? filename . Substring ( filename . Length - 2 ) : "" ;
2016-04-10 16:33:38 +00:00
if ( lastTwoChars = = "jp" ) lastTwoChars = "ja" ;
int lang = Array . IndexOf ( lang_val , lastTwoChars ) ;
CB_MainLanguage . SelectedIndex = lang < 0 ? 1 : lang ;
2014-08-17 01:42:51 +00:00
2015-09-25 02:54:50 +00:00
InitializeFields ( ) ;
2016-06-20 04:22:43 +00:00
formInitialized = true ;
2014-06-28 21:22:05 +00:00
#endregion
2015-11-19 05:37:30 +00:00
#region Load Initial File ( s )
2016-06-20 04:22:43 +00:00
if ( args . Length > 1 ) // Load the arguments
2015-09-13 16:10:44 +00:00
{
foreach ( string arg in args . Skip ( 1 ) . Where ( a = > a . Length > 4 ) )
2016-06-20 04:22:43 +00:00
openQuick ( arg , force : true ) ;
2015-09-13 16:10:44 +00:00
}
2016-07-04 23:16:34 +00:00
if ( ! SAV . Exportable ) // No SAV loaded from exe args
2016-04-09 05:14:16 +00:00
{
2016-06-20 04:22:43 +00:00
string path = detectSaveFile ( ) ;
if ( path ! = null )
openQuick ( path , force : true ) ;
2016-07-04 23:16:34 +00:00
else
GB_SAVtools . Visible = false ;
2016-04-06 03:37:36 +00:00
}
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
}
2016-02-17 15:54:59 +00:00
#region Important Variables
2016-06-20 04:22:43 +00:00
public static PKM pkm = new PK6 ( ) ; // Tab Pokemon Data Storage
2016-07-04 23:16:34 +00:00
public static SaveFile SAV = new SAV6 { Game = ( int ) GameVersion . AS , OT = "PKHeX" , TID = 12345 , SID = 54321 , Language = 2 , Country = 49 , SubRegion = 7 , ConsoleRegion = 1 } ; // Save File
2016-06-20 04:22:43 +00:00
public static Color defaultControlWhite , defaultControlText ;
2014-10-10 02:59:57 +00:00
public static string eggname = "" ;
2016-07-31 21:40:09 +00:00
2016-06-20 04:22:43 +00:00
public static string curlanguage = "en" ;
2016-02-17 15:54:59 +00:00
public static string [ ] gendersymbols = { "♂" , "♀" , "-" } ;
public static string [ ] specieslist , movelist , itemlist , abilitylist , types , natures , forms ,
memories , genloc , trainingbags , trainingstage , characteristics ,
2016-07-09 01:38:40 +00:00
encountertypelist , gamelanguages , balllist , gamelist , pokeblocks , g3items = { } ;
2016-07-17 04:31:49 +00:00
public static string [ ] metRSEFRLG_00000 = { } ;
2016-02-17 15:54:59 +00:00
public static string [ ] metHGSS_00000 , metHGSS_02000 , metHGSS_03000 = { } ;
public static string [ ] metBW2_00000 , metBW2_30000 , metBW2_40000 , metBW2_60000 = { } ;
public static string [ ] metXY_00000 , metXY_30000 , metXY_40000 , metXY_60000 = { } ;
2016-06-29 00:54:07 +00:00
public static string [ ] wallpapernames , puffs = { } ;
2016-02-17 15:54:59 +00:00
public static bool unicode ;
2016-07-09 22:34:38 +00:00
public static List < ComboItem > MoveDataSource , ItemDataSource , SpeciesDataSource , BallDataSource , NatureDataSource , AbilityDataSource , VersionDataSource ;
2016-02-17 15:54:59 +00:00
public static volatile bool formInitialized , fieldsInitialized , fieldsLoaded ;
2016-06-20 04:22:43 +00:00
private static int colorizedbox = - 1 ;
2016-02-17 15:54:59 +00:00
private static Image colorizedcolor ;
private static int colorizedslot ;
private static bool HaX ;
2016-06-20 04:22:43 +00:00
private LegalityAnalysis Legality = new LegalityAnalysis ( new PK3 ( ) ) ;
2016-02-17 15:54:59 +00:00
private static readonly Image mixedHighlight = Util . ChangeOpacity ( Properties . Resources . slotSet , 0.5 ) ;
2016-04-10 16:33:38 +00:00
private static readonly string [ ] lang_val = { "ja" , "en" , "fr" , "it" , "de" , "es" , "ko" , "zh" , "pt" } ;
private static readonly string [ ] main_langlist =
2015-03-12 05:51:56 +00:00
{
"日本語" , // JPN
2016-04-10 16:33:38 +00:00
"English" , // ENG
2015-03-12 05:51:56 +00:00
"Français" , // FRE
"Italiano" , // ITA
"Deutsch" , // GER
"Español" , // SPA
"한국어" , // KOR
"中文" , // CHN
"Português" , // Portuguese
} ;
2016-02-17 15:54:59 +00:00
private static string origintrack ;
2016-03-15 06:26:29 +00:00
private readonly PictureBox [ ] SlotPictureBoxes , movePB , relearnPB ;
2016-02-17 15:54:59 +00:00
private readonly ToolTip Tip1 = new ToolTip ( ) , Tip2 = new ToolTip ( ) , Tip3 = new ToolTip ( ) , NatureTip = new ToolTip ( ) ;
2014-06-28 21:22:05 +00:00
#endregion
2014-12-13 22:48:34 +00:00
2016-07-31 21:40:09 +00:00
#region Path Variables
public static string WorkingDirectory {
get
{
if ( ApplicationDeployment . IsNetworkDeployed )
{
return Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , "PKHeX" ) ;
}
else
{
return Environment . CurrentDirectory ;
}
}
}
public static string DatabasePath
{
get
{
return Path . Combine ( WorkingDirectory , "db" ) ;
}
}
private static string WC6DatabasePath
{
get
{
return Path . Combine ( WorkingDirectory , "wc6" ) ;
}
}
private static string BackupPath
{
get
{
return Path . Combine ( WorkingDirectory , "bak" ) ;
}
}
#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
{
2015-09-27 17:00:45 +00:00
OpenFileDialog ofd = new OpenFileDialog
{
Filter = "PKX File|*.pk6;*.pkx" +
"|EKX File|*.ek6;*.ekx" +
"|BIN File|*.bin" +
"|All Files|*.*" ,
2016-02-01 07:15:54 +00:00
RestoreDirectory = true ,
FilterIndex = 4 ,
FileName = "main" ,
2015-09-27 17:00:45 +00:00
} ;
2016-02-01 07:15:54 +00:00
2016-03-30 17:14:32 +00:00
// Reset file dialog path if it no longer exists
if ( ! Directory . Exists ( ofd . InitialDirectory ) )
ofd . InitialDirectory = Environment . CurrentDirectory ;
2016-02-01 07:15:54 +00:00
// Detect main
2016-06-20 04:22:43 +00:00
string path = detectSaveFile ( ) ;
if ( path ! = null )
{ ofd . InitialDirectory = Path . GetDirectoryName ( path ) ; }
else if ( File . Exists ( Path . Combine ( ofd . InitialDirectory , "main" ) ) )
{ }
else if ( ! Directory . Exists ( ofd . InitialDirectory ) )
{ ofd . RestoreDirectory = false ; ofd . FilterIndex = 1 ; ofd . FileName = "" ; }
2015-03-12 04:44:12 +00:00
2016-02-01 07:15:54 +00:00
if ( ofd . ShowDialog ( ) = = DialogResult . OK )
openQuick ( ofd . FileName ) ;
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
{
2016-06-21 06:02:26 +00:00
if ( ! verifiedPKM ( ) ) return ;
2016-06-20 04:22:43 +00:00
PKM pk = preparePKM ( ) ;
2015-09-27 17:00:45 +00:00
SaveFileDialog sfd = new SaveFileDialog
{
Filter = "PKX File|*.pk6;*.pkx" +
"|EKX File|*.ek6;*.ekx" +
"|BIN File|*.bin" +
"|All Files|*.*" ,
DefaultExt = "pk6" ,
2016-04-22 01:47:51 +00:00
FileName = Util . CleanFileName ( pk . FileName )
2015-09-27 17:00:45 +00:00
} ;
if ( sfd . ShowDialog ( ) ! = DialogResult . OK ) return ;
string path = sfd . FileName ;
2015-03-11 01:44:51 +00:00
// Injection Dummy Override
2015-12-14 15:52:25 +00:00
if ( path . Contains ( "pokemon.ekx" ) ) path = Path . Combine ( Path . GetDirectoryName ( path ) , "pokemon.ekx" ) ;
2015-03-11 01:44:51 +00:00
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 ) ;
}
2014-06-28 21:22:05 +00:00
2016-01-24 18:19:30 +00:00
if ( new [ ] { ".ekx" , ".ek6" , ".bin" } . Contains ( ext ) )
File . WriteAllBytes ( path , pk . EncryptedPartyData ) ;
else if ( new [ ] { ".pkx" , ".pk6" } . Contains ( ext ) )
File . WriteAllBytes ( path , pk . Data ) ;
2015-03-11 01:44:51 +00:00
else
{
2016-01-17 21:27:24 +00:00
Util . Error ( $"Foreign File Extension: {ext}" , "Exporting as encrypted." ) ;
2016-06-20 04:22:43 +00:00
File . WriteAllBytes ( path , pkm . EncryptedPartyData ) ;
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
{
2016-04-13 01:40:37 +00:00
if ( ModifierKeys = = ( Keys . Control | Keys . Q ) ) // Hotkey Triggered
2015-02-22 21:04:12 +00:00
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 ( ) ;
}
2016-01-03 04:22:53 +00:00
// Sub Menu Options
2014-12-14 07:18:27 +00:00
private void mainMenuBoxReport ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
2016-04-15 23:11:46 +00:00
var z = Application . OpenForms . Cast < Form > ( ) . FirstOrDefault ( form = > form . GetType ( ) = = typeof ( frmReport ) ) as frmReport ;
2016-04-08 05:16:08 +00:00
if ( z ! = null )
2016-04-15 23:11:46 +00:00
{ Util . CenterToForm ( z , this ) ; z . BringToFront ( ) ; return ; }
2016-06-20 04:22:43 +00:00
2014-12-13 22:48:34 +00:00
frmReport ReportForm = new frmReport ( ) ;
2015-02-11 22:47:59 +00:00
ReportForm . Show ( ) ;
2016-06-20 04:22:43 +00:00
ReportForm . PopulateData ( SAV . BoxData ) ;
2014-12-13 22:48:34 +00:00
}
2016-01-30 02:02:54 +00:00
private void mainMenuDatabase ( object sender , EventArgs e )
{
2016-04-15 23:11:46 +00:00
var z = Application . OpenForms . Cast < Form > ( ) . FirstOrDefault ( form = > form . GetType ( ) = = typeof ( SAV_Database ) ) as SAV_Database ;
2016-04-08 05:16:08 +00:00
if ( z ! = null )
2016-04-15 23:11:46 +00:00
{ Util . CenterToForm ( z , this ) ; z . BringToFront ( ) ; return ; }
2016-01-30 02:02:54 +00:00
if ( Directory . Exists ( "db" ) )
new SAV_Database ( this ) . Show ( ) ;
else
Util . Alert ( "PKHeX's database was not found" ,
"Please dump all boxes from a save file, then ensure the 'db' folder exists." ) ;
}
2014-12-13 22:48:34 +00:00
private void mainMenuUnicode ( object sender , EventArgs e )
{
2016-01-30 01:27:20 +00:00
unicode = Menu_Unicode . Checked ;
updateUnicode ( ) ;
2014-12-13 22:48:34 +00:00
}
2015-10-25 01:16:22 +00:00
private void mainMenuModifyDex ( object sender , EventArgs e )
2015-10-24 03:13:32 +00:00
{
2016-06-20 04:22:43 +00:00
SaveFile . SetUpdateDex = Menu_ModifyDex . Checked ;
2015-10-24 03:13:32 +00:00
}
2016-06-20 04:22:43 +00:00
private void mainMenuModifyPKM ( object sender , EventArgs e )
2015-10-24 03:13:32 +00:00
{
2016-07-10 17:32:51 +00:00
SaveFile . SetUpdatePKM = Menu_ModifyPKM . Checked ;
2015-10-24 03:13:32 +00:00
}
2016-01-03 04:22:53 +00:00
private void mainMenuBoxLoad ( object sender , EventArgs e )
2015-10-25 01:16:22 +00:00
{
string path = "" ;
2016-01-03 04:22:53 +00:00
if ( Directory . Exists ( DatabasePath ) )
2015-10-25 01:16:22 +00:00
{
2016-01-03 04:22:53 +00:00
DialogResult ld = Util . Prompt ( MessageBoxButtons . YesNo , "Load from PKHeX's database?" ) ;
if ( ld = = DialogResult . Yes )
path = DatabasePath ;
else if ( ld = = DialogResult . No )
2015-10-25 01:16:22 +00:00
{
2016-01-03 04:22:53 +00:00
// open folder dialog
FolderBrowserDialog fbd = new FolderBrowserDialog ( ) ;
if ( fbd . ShowDialog ( ) = = DialogResult . OK )
path = fbd . SelectedPath ;
2015-10-25 01:16:22 +00:00
}
2016-01-03 04:22:53 +00:00
else return ;
}
else
{
// open folder dialog
FolderBrowserDialog fbd = new FolderBrowserDialog ( ) ;
if ( fbd . ShowDialog ( ) = = DialogResult . OK )
path = fbd . SelectedPath ;
}
loadBoxesFromDB ( path ) ;
}
private void mainMenuBoxDump ( object sender , EventArgs e )
{
string path ;
bool dumptoboxes = false ;
// Dump all of box content to files.
DialogResult ld = Util . Prompt ( MessageBoxButtons . YesNo , "Save to PKHeX's database?" ) ;
if ( ld = = DialogResult . Yes )
{
path = DatabasePath ;
if ( ! Directory . Exists ( path ) )
Directory . CreateDirectory ( path ) ;
}
else if ( ld = = DialogResult . No )
{
dumptoboxes = DialogResult . Yes = = Util . Prompt ( MessageBoxButtons . YesNo , "Save each box separately?" ) ;
2015-10-25 01:16:22 +00:00
2016-01-03 04:22:53 +00:00
// open folder dialog
FolderBrowserDialog fbd = new FolderBrowserDialog ( ) ;
if ( fbd . ShowDialog ( ) ! = DialogResult . OK )
return ;
2015-10-25 01:16:22 +00:00
2016-01-03 04:22:53 +00:00
path = fbd . SelectedPath ;
}
else return ;
2015-10-25 01:16:22 +00:00
2016-01-03 04:22:53 +00:00
dumpBoxesToDB ( path , dumptoboxes ) ;
}
2016-07-13 05:19:51 +00:00
private void manMenuBatchEditor ( object sender , EventArgs e )
{
new BatchEditor ( ) . ShowDialog ( ) ;
setPKXBoxes ( ) ; // refresh
}
2016-01-03 04:22:53 +00:00
// Misc Options
private void clickShowdownImportPK6 ( object sender , EventArgs e )
{
2016-04-05 03:39:11 +00:00
if ( ! formInitialized )
return ;
2016-01-03 04:22:53 +00:00
if ( ! Clipboard . ContainsText ( ) )
{ Util . Alert ( "Clipboard does not contain text." ) ; return ; }
// Get Simulator Data
2016-06-20 04:22:43 +00:00
ShowdownSet Set = new ShowdownSet ( Clipboard . GetText ( ) ) ;
2016-01-03 04:22:53 +00:00
if ( Set . Species < 0 )
{ Util . Alert ( "Set data not found in clipboard." ) ; return ; }
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Import this set?" , Clipboard . GetText ( ) ) )
{ return ; }
// Set Species & Nickname
CB_Species . SelectedValue = Set . Species ;
2016-01-05 06:42:38 +00:00
CHK_Nicknamed . Checked = Set . Nickname ! = null ;
2016-01-03 04:22:53 +00:00
if ( Set . Nickname ! = null )
TB_Nickname . Text = Set . Nickname ;
if ( Set . Gender ! = null & & PKX . getGender ( Set . Gender ) ! = 2 & & PKX . getGender ( Set . Gender ) ! = 2 )
{
int Gender = PKX . getGender ( Set . Gender ) ;
Label_Gender . Text = gendersymbols [ Gender ] ;
Label_Gender . ForeColor = Gender = = 2 ? Label_Species . ForeColor : ( Gender = = 1 ? Color . Red : Color . Blue ) ;
2015-10-25 01:16:22 +00:00
}
2016-01-03 04:22:53 +00:00
// Set Form
string [ ] formStrings = PKX . getFormList ( Set . Species ,
2016-03-15 00:54:30 +00:00
Util . getStringList ( "types" , "en" ) ,
Util . getStringList ( "forms" , "en" ) , gendersymbols ) ;
2016-01-03 04:22:53 +00:00
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
2016-07-18 06:40:40 +00:00
int [ ] abilities = SAV . Personal . getAbilities ( Set . Species , form ) ;
2016-07-03 03:24:17 +00:00
int ability = Array . IndexOf ( abilities , Set . Ability ) ;
2016-01-03 04:22:53 +00:00
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
2016-01-05 06:42:38 +00:00
CB_HeldItem . SelectedValue = Set . Item < 0 ? 0 : Set . Item ;
CB_Nature . SelectedValue = Set . Nature < 0 ? 0 : Set . Nature ;
2016-01-03 04:22:53 +00:00
// 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 ( ) ;
2016-06-20 04:22:43 +00:00
pkm = preparePKM ( ) ;
2016-03-18 01:58:30 +00:00
updateLegality ( ) ;
2016-01-03 04:22:53 +00:00
}
private void clickShowdownExportPK6 ( object sender , EventArgs e )
{
2016-06-20 04:22:43 +00:00
if ( ! formInitialized )
return ;
2016-06-21 06:02:26 +00:00
if ( ! verifiedPKM ( ) )
2016-01-03 04:22:53 +00:00
{ Util . Alert ( "Fix data before exporting." ) ; return ; }
2016-06-20 04:22:43 +00:00
Clipboard . SetText ( preparePKM ( ) . ShowdownText ) ;
2016-01-03 04:22:53 +00:00
Util . Alert ( "Exported Showdown Set to Clipboard:" , Clipboard . GetText ( ) ) ;
}
private void clickShowdownExportParty ( object sender , EventArgs e )
{
2016-01-27 02:52:08 +00:00
if ( SAV . PartyData . Length < = 0 ) return ;
2016-01-03 04:22:53 +00:00
try
{
Clipboard . SetText (
SAV . PartyData . Aggregate ( "" , ( current , pk ) = > current + pk . ShowdownText
+ Environment . NewLine + Environment . NewLine ) . Trim ( ) ) ;
Util . Alert ( "Showdown Team (Party) set to Clipboard." ) ;
}
catch { }
}
private void clickShowdownExportBattleBox ( object sender , EventArgs e )
{
2016-01-27 02:52:08 +00:00
if ( SAV . BattleBoxData . Length < = 0 ) return ;
2016-01-03 04:22:53 +00:00
try
{
Clipboard . SetText (
SAV . BattleBoxData . Aggregate ( "" , ( current , pk ) = > current + pk . ShowdownText
+ Environment . NewLine + Environment . NewLine ) . Trim ( ) ) ;
Util . Alert ( "Showdown Team (Battle Box) set to Clipboard." ) ;
}
catch { }
}
private void clickOpenTempFolder ( object sender , EventArgs e )
{
string path = Util . GetTempFolder ( ) ;
if ( Directory . Exists ( Path . Combine ( path , "root" ) ) )
2016-07-17 17:06:52 +00:00
Process . Start ( "explorer.exe" , Path . Combine ( path , "root" ) ) ;
2016-01-03 04:22:53 +00:00
else if ( Directory . Exists ( path ) )
2016-07-17 17:06:52 +00:00
Process . Start ( "explorer.exe" , path ) ;
2016-01-03 04:22:53 +00:00
else
Util . Alert ( "Can't find the temporary file." , "Make sure the Cyber Gadget software is paused." ) ;
}
private void clickOpenCacheFolder ( object sender , EventArgs e )
{
string path = Util . GetCacheFolder ( ) ;
if ( Directory . Exists ( path ) )
2016-07-17 17:06:52 +00:00
Process . Start ( "explorer.exe" , path ) ;
2016-01-03 04:22:53 +00:00
else
Util . Alert ( "Can't find the cache folder." ) ;
}
private void clickOpenSDFFolder ( object sender , EventArgs e )
{
string path ;
2016-06-20 04:22:43 +00:00
if ( Util . get3DSLocation ( ) ! = null & & Directory . Exists ( path = Util . GetSDFLocation ( ) ) )
2016-07-17 17:06:52 +00:00
Process . Start ( "explorer.exe" , path ) ;
2016-01-03 04:22:53 +00:00
else
Util . Alert ( "Can't find the SaveDataFiler folder." ) ;
}
private void clickOpenSDBFolder ( object sender , EventArgs e )
{
2016-06-20 04:22:43 +00:00
string path3DS = Util . get3DSLocation ( ) ;
2016-01-03 04:22:53 +00:00
string path ;
if ( path3DS ! = null & & Directory . Exists ( path = Path . Combine ( Path . GetPathRoot ( path3DS ) , "SaveDataBackup" ) ) )
2016-07-17 17:06:52 +00:00
Process . Start ( "explorer.exe" , path ) ;
2016-01-03 04:22:53 +00:00
else
Util . Alert ( "Can't find the SaveDataBackup folder." ) ;
2015-10-25 01:16:22 +00:00
}
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Main Menu Subfunctions
2016-06-20 04:22:43 +00:00
private void openQuick ( string path , bool force = false )
2014-12-13 22:48:34 +00:00
{
2016-06-20 04:22:43 +00:00
if ( ! ( CanFocus | | force ) )
{
SystemSounds . Asterisk . Play ( ) ;
return ;
}
2014-12-13 22:48:34 +00:00
// 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
{
byte [ ] input ; try { input = File . ReadAllBytes ( path ) ; }
2016-06-20 04:22:43 +00:00
catch ( Exception e ) { Util . Error ( "File is in use by another program!" , path , e . ToString ( ) ) ; return ; }
2014-12-13 22:48:34 +00:00
try { openFile ( input , path , ext ) ; }
2016-06-20 04:22:43 +00:00
catch ( Exception e ) { Util . Error ( "Unable to load file." , e . ToString ( ) ) ; }
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 )
{
2016-06-20 04:22:43 +00:00
MysteryGift tg ; PKM temp ; string c ;
2016-06-20 05:11:53 +00:00
byte [ ] footer = new byte [ 0 ] ;
#region DeSmuME . dsv detect
if ( input . Length > SaveUtil . SIZE_G4RAW )
{
2016-06-20 05:13:57 +00:00
bool dsv = SaveUtil . FOOTER_DSV . SequenceEqual ( input . Skip ( input . Length - SaveUtil . FOOTER_DSV . Length ) ) ;
2016-06-20 05:11:53 +00:00
if ( dsv )
{
footer = input . Skip ( SaveUtil . SIZE_G4RAW ) . ToArray ( ) ;
input = input . Take ( SaveUtil . SIZE_G4RAW ) . ToArray ( ) ;
}
}
#endregion
2014-12-13 22:48:34 +00:00
#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
}
2014-12-13 22:48:34 +00:00
// Verify the Data Input Size is Proper
2016-06-20 04:22:43 +00:00
if ( input . Length = = 0x100000 )
2014-12-13 22:48:34 +00:00
{
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
2016-02-09 23:44:59 +00:00
{ Util . Error ( "PKHeX only edits decrypted save files." + Environment . NewLine + "This save file is not decrypted." , path ) ; return ; }
2015-10-24 03:13:32 +00:00
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 ;
2016-02-09 23:37:12 +00:00
int savshift = sdr = = DialogResult . Yes ? 0 : 0x7F000 ;
2016-06-20 04:22:43 +00:00
byte [ ] psdata = input . Skip ( 0x5400 + savshift ) . Take ( SaveUtil . SIZE_G6ORAS ) . ToArray ( ) ;
if ( BitConverter . ToUInt32 ( psdata , psdata . Length - 0x1F0 ) ! = SaveUtil . BEEF )
Array . Resize ( ref psdata , SaveUtil . SIZE_G6XY ) ;
if ( BitConverter . ToUInt32 ( psdata , psdata . Length - 0x1F0 ) ! = SaveUtil . BEEF )
2016-02-09 23:44:59 +00:00
{ Util . Error ( "The data file is not a valid save file" , path ) ; return ; }
2014-08-15 04:27:53 +00:00
2016-06-20 04:22:43 +00:00
openSAV ( psdata , path ) ;
2014-08-15 04:27:53 +00:00
}
2016-06-20 04:22:43 +00:00
#endregion
#region SAV / PKM
else if ( SaveUtil . getSAVGeneration ( input ) > - 1 ) // Supports Gen4/5/6
2016-06-20 05:11:53 +00:00
{ openSAV ( input , path ) ; SAV . Footer = footer ; }
2016-06-20 04:22:43 +00:00
else if ( ( temp = PKMConverter . getPKMfromBytes ( input ) ) ! = null )
{
PKM pk = PKMConverter . convertToFormat ( temp , SAV . Generation , out c ) ;
if ( pk = = null )
Util . Alert ( "Conversion failed." , c ) ;
2016-05-15 22:35:43 +00:00
else
2016-06-20 04:22:43 +00:00
populateFields ( pk ) ;
Console . WriteLine ( c ) ;
2016-05-15 22:35:43 +00:00
}
2014-08-15 04:27:53 +00:00
#endregion
2016-06-20 04:22:43 +00:00
#region PC / Box Data
else if ( BitConverter . ToUInt16 ( input , 4 ) = = 0 & & BitConverter . ToUInt32 ( input , 8 ) > 0 & & PKX . getIsPKM ( input . Length / 30 / SAV . BoxCount ) | | PKX . getIsPKM ( input . Length / 30 ) )
2014-06-28 21:22:05 +00:00
{
2016-06-20 04:22:43 +00:00
if ( SAV . setPCBin ( input ) )
Util . Alert ( "PC Binary loaded." ) ;
else if ( SAV . setBoxBin ( input , CB_BoxSelect . SelectedIndex ) )
Util . Alert ( "Box Binary loaded." ) ;
2014-12-13 22:48:34 +00:00
else
2015-09-18 03:18:22 +00:00
{
2016-06-20 04:22:43 +00:00
Util . Alert ( "Binary is not compatible with save file." , "Current SAV Generation: " + SAV . Generation ) ;
return ;
2015-10-24 03:13:32 +00:00
}
2015-01-27 06:05:04 +00:00
setPKXBoxes ( ) ;
2015-09-18 03:18:22 +00:00
}
2015-01-24 18:45:32 +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
{
2016-06-20 04:22:43 +00:00
if ( SAV . Generation < 6 )
{ Util . Alert ( "Cannot load a Gen6 Battle Video to a past generation save file." ) ; return ; }
2016-04-15 00:10:06 +00:00
2016-06-20 04:22:43 +00:00
if ( Util . Prompt ( MessageBoxButtons . YesNo , "Load Batte Video Pokémon data to " + CB_BoxSelect . Text + "?" , "The box will be overwritten." ) ! = DialogResult . Yes )
return ;
2016-04-15 00:10:06 +00:00
2016-06-20 04:22:43 +00:00
bool? noSetb = getPKMSetOverride ( ) ;
int offset = SAV . getBoxOffset ( CB_BoxSelect . SelectedIndex ) ;
2015-02-24 07:52:32 +00:00
for ( int i = 0 ; i < 24 ; i + + )
2015-09-18 03:18:22 +00:00
{
2016-06-20 04:22:43 +00:00
byte [ ] data = input . Skip ( 0xE18 + PKX . SIZE_6PARTY * i + i / 6 * 8 ) . Take ( PKX . SIZE_6STORED ) . ToArray ( ) ;
SAV . setStoredSlot ( data , offset + i * SAV . SIZE_STORED , noSetb ) ;
2015-09-18 03:18:22 +00:00
}
2015-02-24 07:52:32 +00:00
setPKXBoxes ( ) ;
}
#endregion
2016-06-20 04:22:43 +00:00
#region Mystery Gift ( Templates )
else if ( ( tg = MysteryGift . getMysteryGift ( input , ext ) ) ! = null )
2015-12-27 00:05:26 +00:00
{
2016-06-20 04:22:43 +00:00
if ( ! tg . IsPokémon )
2015-12-27 00:05:26 +00:00
{
2016-06-20 04:22:43 +00:00
Util . Alert ( "Mystery Gift is not a Pokémon." , path ) ;
2015-12-27 00:05:26 +00:00
return ;
}
2016-06-20 04:22:43 +00:00
temp = tg . convertToPKM ( SAV ) ;
if ( temp . Format = = SAV . Generation & & ModifierKeys = = Keys . Control & & SAV . HasWondercards )
2015-12-27 00:05:26 +00:00
{
2016-06-20 04:22:43 +00:00
B_OpenWondercards_Click ( tg , null ) ;
2015-12-27 00:05:26 +00:00
return ;
}
2016-06-20 04:22:43 +00:00
PKM pk = PKMConverter . convertToFormat ( temp , SAV . Generation , out c ) ;
if ( pk = = null )
Util . Alert ( "Conversion failed." , c ) ;
else
populateFields ( pk ) ;
Console . WriteLine ( c ) ;
2015-12-27 00:05:26 +00:00
}
2015-04-01 00:58:23 +00:00
#endregion
2014-12-13 22:48:34 +00:00
else
2016-01-17 21:27:24 +00:00
Util . Error ( "Attempted to load an unsupported file type/size." ,
$"File Loaded:{Environment.NewLine}{path}" ,
$"File Size:{Environment.NewLine}{input.Length} bytes (0x{input.Length.ToString(" X4 ")})" ) ;
2014-12-13 22:48:34 +00:00
}
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
2015-11-29 20:59:13 +00:00
byte [ ] savID = input . Take ( 0x10 ) . ToArray ( ) ;
2015-03-11 01:44:51 +00:00
string exepath = Application . StartupPath ;
string xorpath = exepath . Clone ( ) . ToString ( ) ;
string [ ] XORpads = Directory . GetFiles ( xorpath ) ;
2014-12-31 06:18:41 +00:00
2015-12-13 07:39:43 +00:00
int loop = 0 ;
2016-01-03 06:31:04 +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 ;
2015-11-29 20:59:13 +00:00
if ( xorpad . Length = = 0x10009C ) // Trim off Powersaves' header
xorpad = xorpad . Skip ( 0x9C ) . ToArray ( ) ; // returns 0x100000
if ( ! xorpad . Take ( 0x10 ) . SequenceEqual ( savID ) ) continue ;
2015-03-11 01:44:51 +00:00
// Set up Decrypted File
2016-06-20 04:22:43 +00:00
byte [ ] decryptedPS = input . Skip ( 0x5400 ) . Take ( SaveUtil . SIZE_G6ORAS ) . ToArray ( ) ;
2015-03-11 01:44:51 +00:00
// xor through and decrypt
2015-11-29 20:59:13 +00:00
for ( int z = 0 ; z < decryptedPS . Length ; z + + )
2015-03-11 01:44:51 +00:00
decryptedPS [ z ] ^ = xorpad [ 0x5400 + z ] ;
// Weakly check the validity of the decrypted content
2016-06-20 04:22:43 +00:00
if ( BitConverter . ToUInt32 ( decryptedPS , SaveUtil . SIZE_G6ORAS - 0x1F0 ) ! = SaveUtil . BEEF ) // Not OR/AS
if ( BitConverter . ToUInt32 ( decryptedPS , SaveUtil . SIZE_G6XY - 0x1F0 ) ! = SaveUtil . BEEF ) // Not X/Y
2015-11-29 20:59:13 +00:00
continue ;
2015-03-11 01:44:51 +00:00
else
2016-06-20 04:22:43 +00:00
Array . Resize ( ref decryptedPS , SaveUtil . SIZE_G6XY ) ; // set to X/Y size
else Array . Resize ( ref decryptedPS , SaveUtil . SIZE_G6ORAS ) ; // set to ORAS size just in case
2015-03-11 01:44:51 +00:00
2015-10-24 03:13:32 +00:00
// Save file is now decrypted!
2015-03-11 01:44:51 +00:00
// Trigger Loading of the decrypted save file.
2016-06-20 04:22:43 +00:00
openSAV ( decryptedPS , path ) ;
2015-03-11 01:44:51 +00:00
// 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).
2015-12-13 07:39:43 +00:00
if ( xorpath ! = exepath | | loop + + > 0 ) return false ; // no xorpad compatible
2015-03-11 01:44:51 +00:00
xorpath = Path . GetDirectoryName ( path ) ; goto check ;
2014-12-31 06:18:41 +00:00
}
2016-06-20 04:22:43 +00:00
private void openSAV ( byte [ ] input , string path )
2014-12-13 22:48:34 +00:00
{
2016-06-20 04:22:43 +00:00
SaveFile sav = SaveUtil . getVariantSAV ( input ) ;
2016-06-28 06:03:57 +00:00
if ( sav = = null | | sav . Version = = GameVersion . Invalid )
2016-06-20 04:22:43 +00:00
{ Util . Error ( "Invalid save file loaded. Aborting." , path ) ; return ; }
2016-07-15 03:22:24 +00:00
if ( sav . Generation < = 3 ) // Japanese Save files are different. Get isJapanese
{
2016-07-29 05:08:23 +00:00
if ( sav . Version = = GameVersion . Unknown )
{
// Hacky cheats invalidated the Game Code value.
var drGame = Util . Prompt ( MessageBoxButtons . YesNoCancel ,
"Unknown Gen3 Game Detected. Select Origins:" ,
"Yes: Ruby / Sapphire" + Environment . NewLine +
"No: Emerald" + Environment . NewLine +
"Cancel: FireRed / LeafGreen" ) ;
if ( drGame = = DialogResult . Yes )
sav = new SAV3 ( sav . Data , GameVersion . RS ) ;
else if ( drGame = = DialogResult . No )
sav = new SAV3 ( sav . Data , GameVersion . E ) ;
else
sav = new SAV3 ( sav . Data , GameVersion . FRLG ) ;
}
2016-07-30 04:14:08 +00:00
var drJP = Util . Prompt ( MessageBoxButtons . YesNoCancel , $"Generation 3 ({sav.Version}) Save File detected. Select Origins:" , "Yes: International" + Environment . NewLine + "No: Japanese" ) ;
2016-07-28 01:59:10 +00:00
if ( drJP = = DialogResult . Cancel )
2016-07-15 03:22:24 +00:00
return ;
2016-07-28 01:59:10 +00:00
sav . Japanese = drJP = = DialogResult . No ;
if ( sav . Version = = GameVersion . FRLG )
{
2016-07-30 04:14:08 +00:00
var drFRLG = Util . Prompt ( MessageBoxButtons . YesNoCancel , $"{sav.Version} detected. Select version..." , "Yes: FireRed" + Environment . NewLine + "No: LeafGreen" ) ;
2016-07-28 01:59:10 +00:00
if ( drFRLG = = DialogResult . Cancel )
return ;
sav . Personal = drFRLG = = DialogResult . Yes ? PersonalTable . FR : PersonalTable . LG ;
}
2016-07-15 03:22:24 +00:00
}
2016-07-29 05:33:16 +00:00
PKM pk = preparePKM ( ) ;
2016-06-20 04:22:43 +00:00
SAV = sav ;
2016-01-03 06:31:04 +00:00
2016-06-20 04:22:43 +00:00
SAV . FilePath = Path . GetDirectoryName ( path ) ;
SAV . FileName = Path . GetExtension ( path ) = = ".bak"
2016-07-18 18:51:26 +00:00
? Path . GetFileName ( path ) ? . Split ( new [ ] { " [" } , StringSplitOptions . None ) [ 0 ]
2016-06-20 04:22:43 +00:00
: Path . GetFileName ( path ) ;
L_Save . Text = $"SAV{SAV.Generation}: {Path.GetFileNameWithoutExtension(Util.CleanFileName(SAV.BAKName))}" ; // more descriptive
2016-01-28 04:24:32 +00:00
Menu_ExportSAV . Enabled = B_VerifyCHK . Enabled = SAV . Exportable ;
2016-04-19 01:21:50 +00:00
2014-12-13 22:48:34 +00:00
setBoxNames ( ) ; // Display the Box Names
2016-06-20 04:22:43 +00:00
if ( SAV . HasBox )
2015-12-30 06:03:27 +00:00
{
int startBox = SAV . CurrentBox ; // FF if BattleBox
2016-06-20 04:22:43 +00:00
if ( startBox > SAV . BoxCount - 1 ) { tabBoxMulti . SelectedIndex = 1 ; CB_BoxSelect . SelectedIndex = 0 ; }
2015-12-30 06:03:27 +00:00
else { tabBoxMulti . SelectedIndex = 0 ; CB_BoxSelect . SelectedIndex = startBox ; }
}
2016-06-20 04:22:43 +00:00
setPKXBoxes ( ) ; // Reload all of the PKX Windows
2015-12-17 03:33:58 +00:00
2015-12-30 06:03:27 +00:00
// Hide content if not present in game.
2016-07-04 23:16:34 +00:00
GB_SAVtools . Visible = true ;
2016-06-20 04:22:43 +00:00
GB_SUBE . Visible = SAV . HasSUBE ;
PB_Locked . Visible = SAV . HasBattleBox & & SAV . BattleBoxLocked ;
PAN_Box . Visible = CB_BoxSelect . Visible = B_BoxLeft . Visible = B_BoxRight . Visible = SAV . HasBox ;
Menu_LoadBoxes . Enabled = Menu_DumpBoxes . Enabled = Menu_Report . Enabled = Menu_Modify . Enabled = B_SaveBoxBin . Enabled = SAV . HasBox ;
PAN_BattleBox . Visible = L_BattleBox . Visible = L_ReadOnlyPBB . Visible = SAV . HasBattleBox ;
GB_Daycare . Visible = SAV . HasDaycare ;
GB_Fused . Visible = SAV . HasFused ;
GB_GTS . Visible = SAV . HasGTS ;
B_OpenSecretBase . Visible = SAV . HasSecretBase ;
B_OpenPokepuffs . Visible = SAV . HasPuff ;
B_OUTPasserby . Visible = SAV . HasPSS ;
B_OpenBoxLayout . Visible = SAV . HasBoxWallpapers ;
B_OpenWondercards . Visible = SAV . HasWondercards ;
B_OpenSuperTraining . Visible = SAV . HasSuperTrain ;
B_OpenHallofFame . Visible = SAV . HasHoF ;
B_OpenOPowers . Visible = SAV . HasOPower ;
B_OpenPokedex . Visible = SAV . HasPokeDex ;
B_OpenBerryField . Visible = SAV . HasBerryField ;
B_Pokeblocks . Visible = SAV . HasPokeBlock ;
B_JPEG . Visible = SAV . HasJPEG ;
B_OpenEventFlags . Visible = SAV . HasEvents ;
2016-07-27 03:18:48 +00:00
B_LinkInfo . Visible = SAV . HasLink ;
2016-06-20 04:22:43 +00:00
// Generational Interface
byte [ ] extraBytes = new byte [ 1 ] ;
2016-06-21 04:11:48 +00:00
Tip1 . RemoveAll ( ) ; Tip2 . RemoveAll ( ) ; Tip3 . RemoveAll ( ) ; // TSV/PSV
2016-06-26 21:23:41 +00:00
CB_Country . Visible = CB_SubRegion . Visible = CB_3DSReg . Visible =
Label_Country . Visible = Label_SubRegion . Visible = Label_3DSRegion . Visible = SAV . Generation > = 6 ;
Label_EncryptionConstant . Visible = BTN_RerollEC . Visible = TB_EC . Visible = SAV . Generation > = 6 ;
2016-07-17 00:19:26 +00:00
GB_nOT . Visible = GB_RelearnMoves . Visible = BTN_Medals . Visible = BTN_History . Visible = SAV . Generation > = 6 ;
2016-06-26 21:23:41 +00:00
PB_Legal . Visible = PB_WarnMove1 . Visible = PB_WarnMove2 . Visible = PB_WarnMove3 . Visible = PB_WarnMove4 . Visible = SAV . Generation > = 6 ;
PB_MarkPentagon . Visible = SAV . Generation = = 6 ;
PB_Legal . Visible = PB_WarnMove1 . Visible = PB_WarnMove2 . Visible = PB_WarnMove3 . Visible = PB_WarnMove4 . Visible = SAV . Generation = = 6 ;
TB_GameSync . Visible = TB_Secure1 . Visible = TB_Secure2 . Visible = L_GameSync . Visible = L_Secure1 . Visible = L_Secure2 . Visible = SAV . Generation = = 6 ;
CB_Form . Visible = Label_Form . Visible = CHK_AsEgg . Visible = GB_EggConditions . Visible =
Label_MetDate . Visible = CAL_MetDate . Visible = PB_Mark5 . Visible = PB_Mark6 . Visible = SAV . Generation > = 4 ;
2016-07-17 00:19:26 +00:00
BTN_Ribbons . Visible = SAV . Generation > = 3 ;
2016-07-15 03:15:05 +00:00
DEV_Ability . Enabled = DEV_Ability . Visible = SAV . Generation > 3 & & HaX ;
2016-06-28 06:03:57 +00:00
TB_AbilityNumber . Visible = SAV . Generation > = 6 & & DEV_Ability . Enabled ;
2016-07-15 03:15:05 +00:00
CB_Ability . Visible = ! DEV_Ability . Enabled & & SAV . Generation > = 3 ;
2016-06-26 21:23:41 +00:00
2016-07-17 00:19:26 +00:00
// Recenter PKM SubEditors
FLP_PKMEditors . Location = new Point ( ( tabMain . TabPages [ 4 ] . Width - FLP_PKMEditors . Width ) / 2 , FLP_PKMEditors . Location . Y ) ;
2016-06-20 04:22:43 +00:00
switch ( SAV . Generation )
{
2016-06-26 21:23:41 +00:00
case 3 :
2016-07-09 21:01:31 +00:00
getFieldsfromPKM = populateFieldsPK3 ;
getPKMfromFields = preparePK3 ;
2016-06-26 21:23:41 +00:00
extraBytes = PK3 . ExtraBytes ;
break ;
2016-06-20 04:22:43 +00:00
case 4 :
2016-07-09 21:01:31 +00:00
getFieldsfromPKM = populateFieldsPK4 ;
getPKMfromFields = preparePK4 ;
2016-06-20 04:22:43 +00:00
extraBytes = PK4 . ExtraBytes ;
break ;
case 5 :
2016-07-09 21:01:31 +00:00
getFieldsfromPKM = populateFieldsPK5 ;
getPKMfromFields = preparePK5 ;
2016-06-20 04:22:43 +00:00
extraBytes = PK5 . ExtraBytes ;
break ;
case 6 :
2016-07-09 21:01:31 +00:00
getFieldsfromPKM = populateFieldsPK6 ;
getPKMfromFields = preparePK6 ;
2016-06-20 04:22:43 +00:00
extraBytes = PK6 . ExtraBytes ;
2016-07-19 04:39:43 +00:00
SAV6 sav6 = ( SAV6 ) SAV ;
TB_GameSync . Enabled = sav6 . GameSyncID ! = 0 ;
TB_GameSync . Text = sav6 . GameSyncID . ToString ( "X16" ) ;
TB_Secure1 . Text = sav6 . Secure1 . ToString ( "X16" ) ;
TB_Secure2 . Text = sav6 . Secure2 . ToString ( "X16" ) ;
2016-06-20 04:22:43 +00:00
break ;
}
2016-07-03 22:05:15 +00:00
bool init = fieldsInitialized ;
fieldsInitialized = false ;
2016-06-21 01:58:06 +00:00
populateFilteredDataSources ( ) ;
2016-06-22 05:19:26 +00:00
populateFields ( pkm . Format ! = SAV . Generation ? SAV . BlankPKM : pk ) ;
2016-07-03 22:05:15 +00:00
fieldsInitialized | = init ;
2016-06-20 04:22:43 +00:00
// SAV Specific Limits
TB_OT . MaxLength = SAV . OTLength ;
TB_OTt2 . MaxLength = SAV . OTLength ;
TB_Nickname . MaxLength = SAV . NickLength ;
// Common HaX Interface
CHK_HackedStats . Enabled = CHK_HackedStats . Visible = MT_Level . Enabled = MT_Level . Visible = MT_Form . Enabled = MT_Form . Visible = HaX ;
2016-06-21 01:58:06 +00:00
PB_Legal . Visible = PB_WarnMove1 . Visible = PB_WarnMove2 . Visible = PB_WarnMove3 . Visible = PB_WarnMove4 . Visible & = ! HaX ;
2016-06-20 04:22:43 +00:00
TB_Level . Visible = ! HaX ;
// Load Extra Byte List
CB_ExtraBytes . Items . Clear ( ) ;
foreach ( byte b in extraBytes )
CB_ExtraBytes . Items . Add ( "0x" + b . ToString ( "X2" ) ) ;
CB_ExtraBytes . SelectedIndex = 0 ;
2015-12-30 06:03:27 +00:00
2016-01-03 04:22:53 +00:00
// Refresh PK#->PK6 conversion info
2016-06-20 04:22:43 +00:00
PKMConverter . updateConfig ( SAV . SubRegion , SAV . Country , SAV . ConsoleRegion , SAV . OT , SAV . Gender ) ;
2016-02-12 05:41:31 +00:00
// If backup folder exists, save a backup.
string backupName = Path . Combine ( BackupPath , Util . CleanFileName ( SAV . BAKName ) ) ;
if ( SAV . Exportable & & Directory . Exists ( BackupPath ) & & ! File . Exists ( backupName ) )
File . WriteAllBytes ( backupName , SAV . BAK ) ;
2016-06-20 04:22:43 +00:00
// Indicate audibly the save is loaded
SystemSounds . Beep . Play ( ) ;
2014-06-28 21:22:05 +00:00
}
2016-05-15 22:35:43 +00:00
private static void refreshWC6DB ( )
2016-02-29 01:05:38 +00:00
{
List < WC6 > wc6db = new List < WC6 > ( ) ;
byte [ ] wc6bin = Properties . Resources . wc6 ;
for ( int i = 0 ; i < wc6bin . Length ; i + = WC6 . Size )
wc6db . Add ( new WC6 ( wc6bin . Skip ( i ) . Take ( WC6 . Size ) . ToArray ( ) ) ) ;
2016-04-30 06:24:23 +00:00
byte [ ] wc6full = Properties . Resources . wc6full ;
for ( int i = 0 ; i < wc6full . Length ; i + = WC6 . SizeFull )
wc6db . Add ( new WC6 ( wc6full . Skip ( i ) . Take ( WC6 . SizeFull ) . ToArray ( ) ) ) ;
2016-02-29 01:05:38 +00:00
if ( Directory . Exists ( WC6DatabasePath ) )
wc6db . AddRange ( from file in Directory . GetFiles ( WC6DatabasePath , "*" , SearchOption . AllDirectories )
let fi = new FileInfo ( file )
2016-04-22 01:47:51 +00:00
where new [ ] { ".wc6full" , ".wc6" } . Contains ( fi . Extension ) & & new [ ] { WC6 . Size , WC6 . SizeFull } . Contains ( ( int ) fi . Length )
2016-02-29 01:05:38 +00:00
select new WC6 ( File . ReadAllBytes ( file ) ) ) ;
Legal . WC6DB = wc6db . Distinct ( ) . ToArray ( ) ;
}
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
{
2016-06-20 04:22:43 +00:00
PKM pk = SAV . getPKM ( ( fieldsInitialized ? preparePKM ( ) : pkm ) . Data ) ;
2015-12-26 18:26:42 +00:00
bool alreadyInit = fieldsInitialized ;
2015-11-06 06:59:55 +00:00
fieldsInitialized = false ;
2014-12-13 22:48:34 +00:00
Menu_Options . DropDown . Close ( ) ;
InitializeStrings ( ) ;
InitializeLanguage ( ) ;
2016-01-17 23:35:02 +00:00
Util . TranslateInterface ( this , lang_val [ CB_MainLanguage . SelectedIndex ] ) ; // Translate the UI to language.
2016-07-17 00:19:26 +00:00
// Recenter PKM SubEditors
FLP_PKMEditors . Location = new Point ( ( tabMain . TabPages [ 4 ] . Width - FLP_PKMEditors . Width ) / 2 , FLP_PKMEditors . Location . Y ) ;
2016-01-24 18:19:30 +00:00
populateFields ( pk ) ; // put data back in form
2015-12-27 05:17:23 +00:00
fieldsInitialized | = alreadyInit ;
2014-12-13 22:48:34 +00:00
}
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
2016-07-09 01:38:40 +00:00
// Past Generation strings
g3items = Util . getStringList ( "ItemsG3" , "en" ) ;
2016-07-17 04:31:49 +00:00
metRSEFRLG_00000 = Util . getStringList ( "rsefrlg_00000" , "en" ) ;
2016-07-09 01:38:40 +00:00
// Current Generation strings
2014-12-13 22:48:34 +00:00
string l = curlanguage ;
2016-03-15 00:54:30 +00:00
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 ) ;
encountertypelist = Util . getStringList ( "encountertype" , l ) ;
gamelist = Util . getStringList ( "games" , l ) ;
2016-02-09 23:27:24 +00:00
gamelanguages = Util . getNulledStringArray ( Util . getStringList ( "languages" ) ) ;
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
2016-04-29 04:43:16 +00:00
if ( l ! = "pt" | | ( l = = "pt" & & ! fieldsInitialized ) ) // load initial binaries
2014-12-13 22:48:34 +00:00
{
2016-03-15 00:54:30 +00:00
pokeblocks = Util . getStringList ( "pokeblock" , l ) ;
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-12-13 22:48:34 +00:00
}
2014-06-28 21:22:05 +00:00
2014-12-13 22:48:34 +00:00
// Fix Item Names (Duplicate entries)
2016-06-21 01:58:06 +00:00
itemlist [ 456 ] + = " (HG/SS)" ; // S.S. Ticket
itemlist [ 736 ] + = " (OR/AS)" ; // S.S. Ticket
itemlist [ 463 ] + = " (DPPt)" ; // Storage Key
itemlist [ 734 ] + = " (OR/AS)" ; // Storage Key
itemlist [ 478 ] + = " (HG/SS)" ; // Basement Key
itemlist [ 478 ] + = " (OR/AS)" ; // Basement Key
itemlist [ 621 ] + = " (M)" ; // Xtransceiver
itemlist [ 626 ] + = " (F)" ; // Xtransceiver
2014-12-13 22:48:34 +00:00
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)
2016-04-14 09:36:40 +00:00
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
2016-05-08 10:47:22 +00:00
metXY_00000 [ 106 ] + = " (X/Y)" ; // Pokémon League
metXY_00000 [ 202 ] + = " (OR/AS)" ; // Pokémon League
2014-12-13 22:48:34 +00:00
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
2016-04-07 01:13:43 +00:00
// Update Legality Analysis strings
LegalityAnalysis . movelist = movelist ;
2015-11-06 06:59:55 +00:00
if ( fieldsInitialized )
2014-12-13 22:48:34 +00:00
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.
2015-11-06 06:59:55 +00:00
fieldsInitialized = true ;
2016-06-20 04:22:43 +00:00
pkm . RefreshChecksum ( ) ;
2015-11-06 06:59:55 +00:00
// Load Data
2016-06-20 04:22:43 +00:00
populateFields ( pkm ) ;
2014-06-28 21:22:05 +00:00
{
2016-04-02 21:03:04 +00:00
CB_Species . SelectedValue = 493 ;
CB_Move1 . SelectedValue = 1 ;
2014-12-13 22:48:34 +00:00
TB_OT . Text = "PKHeX" ;
TB_TID . Text = 12345. ToString ( ) ;
TB_SID . Text = 54321. ToString ( ) ;
2014-12-14 04:39:31 +00:00
CB_GameOrigin . SelectedIndex = 0 ;
2016-04-10 16:33:38 +00:00
int curlang = Array . IndexOf ( lang_val , curlanguage ) ;
CB_Language . SelectedIndex = curlang > CB_Language . Items . Count - 1 ? 1 : curlang ;
2015-05-07 02:30:31 +00:00
CB_BoxSelect . SelectedIndex = 0 ;
2014-12-13 22:48:34 +00:00
CB_Ball . SelectedIndex = 0 ;
CB_Country . SelectedIndex = 0 ;
2016-03-14 01:38:11 +00:00
CAL_MetDate . Value = CAL_EggDate . Value = DateTime . Today ;
2014-06-28 21:22:05 +00:00
}
2014-12-13 22:48:34 +00:00
}
private void InitializeLanguage ( )
{
2016-06-20 04:22:43 +00:00
ComboBox [ ] cbs =
{
CB_Country , CB_SubRegion , CB_3DSReg , CB_Language , CB_Ball , CB_HeldItem , CB_Species , DEV_Ability ,
CB_Nature , CB_EncounterType , CB_GameOrigin , CB_HPType
} ;
foreach ( var cb in cbs ) { cb . DisplayMember = "Text" ; cb . 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 } ;
2016-02-10 08:33:42 +00:00
BallDataSource = Util . getVariedCBList ( itemlist , ball_nums , ball_vals ) ;
2015-09-21 03:34:09 +00:00
SpeciesDataSource = Util . getCBList ( specieslist , null ) ;
NatureDataSource = Util . getCBList ( natures , null ) ;
2015-10-08 03:19:34 +00:00
AbilityDataSource = Util . getCBList ( abilitylist , null ) ;
VersionDataSource = 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-09-21 03:34:09 +00:00
2016-06-21 01:58:06 +00:00
MoveDataSource = Util . getCBList ( movelist , null ) ;
2015-09-21 03:34:09 +00:00
2015-03-11 01:44:51 +00:00
CB_EncounterType . DataSource = Util . getCBList ( encountertypelist , new [ ] { 0 } , Legal . Gen4EncounterTypes ) ;
2015-12-14 15:52:25 +00:00
CB_HPType . DataSource = Util . getCBList ( types . Skip ( 1 ) . Take ( 16 ) . ToArray ( ) , null ) ;
2016-06-21 01:58:06 +00:00
CB_Nature . DataSource = new BindingSource ( NatureDataSource , null ) ;
populateFilteredDataSources ( ) ;
}
private void populateFilteredDataSources ( )
{
2016-07-09 01:38:40 +00:00
string [ ] items = itemlist ;
if ( SAV . Generation = = 3 )
items = g3items ;
ItemDataSource = Util . getCBList ( items , ( HaX ? Enumerable . Range ( 0 , SAV . MaxItemID ) : SAV . HeldItems . Select ( i = > ( int ) i ) ) . ToArray ( ) ) ;
2016-07-30 17:47:28 +00:00
CB_HeldItem . DataSource = new BindingSource ( ItemDataSource . Where ( i = > i . Value < = SAV . MaxItemID ) . ToList ( ) , null ) ;
2016-06-21 01:58:06 +00:00
2016-07-30 17:47:28 +00:00
CB_Ball . DataSource = new BindingSource ( BallDataSource . Where ( b = > b . Value < = SAV . MaxBallID ) . ToList ( ) , null ) ;
CB_Species . DataSource = new BindingSource ( SpeciesDataSource . Where ( s = > s . Value < = SAV . MaxSpeciesID ) . ToList ( ) , null ) ;
DEV_Ability . DataSource = new BindingSource ( AbilityDataSource . Where ( a = > a . Value < = SAV . MaxAbilityID ) . ToList ( ) , null ) ;
CB_GameOrigin . DataSource = new BindingSource ( VersionDataSource . Where ( g = > g . Value < = SAV . MaxGameID | | SAV . Generation > = 3 & & g . Value = = 15 ) . ToList ( ) , null ) ;
2015-03-09 00:41:13 +00:00
2014-12-14 07:18:27 +00:00
// Set the Move ComboBoxes too..
2016-07-30 17:47:28 +00:00
var moves = MoveDataSource . Where ( m = > m . Value < = SAV . MaxMoveID ) . ToList ( ) ;
2016-04-10 16:33:38 +00:00
foreach ( ComboBox cb in new [ ] { CB_Move1 , CB_Move2 , CB_Move3 , CB_Move4 , CB_RelearnMove1 , CB_RelearnMove2 , CB_RelearnMove3 , CB_RelearnMove4 } )
2014-06-28 21:22:05 +00:00
{
2016-04-10 16:33:38 +00:00
cb . DisplayMember = "Text" ; cb . ValueMember = "Value" ;
2016-07-29 01:36:02 +00:00
cb . DataSource = new BindingSource ( moves , null ) ;
2014-08-07 00:10:29 +00:00
}
2014-06-28 21:22:05 +00:00
}
2016-07-09 21:01:31 +00:00
private Action getFieldsfromPKM ;
private Func < PKM > getPKMfromFields ;
2016-06-20 04:22:43 +00:00
public void populateFields ( PKM pk , bool focus = true )
2014-06-28 21:22:05 +00:00
{
2016-06-20 04:22:43 +00:00
if ( pk = = null ) { Util . Error ( "Attempted to load a null file." ) ; return ; }
2015-03-14 02:59:51 +00:00
2016-07-23 21:16:23 +00:00
if ( pk . Format > SAV . Generation )
2016-06-28 06:03:57 +00:00
{ Util . Alert ( "Can't load future generation files." ) ; return ; }
2015-11-06 06:59:55 +00:00
bool oldInit = fieldsInitialized ;
2016-02-17 15:54:59 +00:00
fieldsInitialized = fieldsLoaded = false ;
2015-10-12 06:36:20 +00:00
if ( focus )
Tab_Main . Focus ( ) ;
2014-12-13 22:48:34 +00:00
2016-06-30 05:58:02 +00:00
pkm = pk . Clone ( ) ;
2016-07-09 21:01:31 +00:00
2016-06-20 04:22:43 +00:00
if ( fieldsInitialized & ! pkm . ChecksumValid )
Util . Alert ( "PKX File has an invalid checksum." ) ;
2016-07-09 21:01:31 +00:00
if ( pkm . Format ! = SAV . Generation ) // past gen format
2016-06-20 04:22:43 +00:00
{
2016-07-09 21:01:31 +00:00
string c ;
pkm = PKMConverter . convertToFormat ( pkm , SAV . Generation , out c ) ;
2016-07-23 21:16:23 +00:00
if ( pk . Format ! = pkm . Format & & focus ) // converted
2016-07-09 21:01:31 +00:00
Util . Alert ( "Converted File." ) ;
2016-06-20 04:22:43 +00:00
}
2016-07-09 21:01:31 +00:00
getFieldsfromPKM ( ) ;
2016-06-20 04:22:43 +00:00
CB_EncounterType . Visible = Label_EncounterType . Visible = pkm . Gen4 ;
fieldsInitialized = oldInit ;
updateIVs ( null , null ) ;
updatePKRSInfected ( null , null ) ;
updatePKRSCured ( null , null ) ;
if ( HaX )
{
MT_Level . Text = pkm . Stat_Level . ToString ( ) ;
MT_Form . Text = pkm . AltForm . ToString ( ) ;
if ( pkm . Stat_HPMax ! = 0 ) // stats present
{
Stat_HP . Text = pkm . Stat_HPCurrent . ToString ( ) ;
Stat_ATK . Text = pkm . Stat_ATK . ToString ( ) ;
Stat_DEF . Text = pkm . Stat_DEF . ToString ( ) ;
Stat_SPA . Text = pkm . Stat_SPA . ToString ( ) ;
Stat_SPD . Text = pkm . Stat_SPD . ToString ( ) ;
Stat_SPE . Text = pkm . Stat_SPE . ToString ( ) ;
}
}
fieldsLoaded = true ;
// Set the Preview Box
dragout . Image = pk . Sprite ;
updateLegality ( ) ;
}
2014-12-25 00:20:39 +00:00
// General Use Functions shared by other Forms //
2015-09-21 03:34:09 +00:00
internal static 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 + "" ;
2016-01-05 06:42:38 +00:00
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-11-06 06:59:55 +00:00
if ( index > 0 & & index < CB . Items . Count & & fieldsInitialized )
2015-01-31 23:59:23 +00:00
CB . SelectedIndex = index ;
2014-12-13 22:48:34 +00:00
}
2016-06-30 05:58:02 +00:00
private void setForms ( )
2014-12-13 22:48:34 +00:00
{
2016-07-28 01:20:15 +00:00
int species = Util . getIndex ( CB_Species ) ;
if ( SAV . Generation < 4 & & species ! = 201 )
2016-06-30 05:58:02 +00:00
{
Label_Form . Visible = CB_Form . Visible = CB_Form . Enabled = false ;
return ;
}
2016-07-28 01:08:08 +00:00
bool hasForms = SAV . Personal [ species ] . HasFormes | | new [ ] { 201 , 664 , 665 , 414 } . Contains ( species ) ;
2016-06-30 05:58:02 +00:00
CB_Form . Enabled = CB_Form . Visible = Label_Form . Visible = hasForms ;
if ( ! hasForms )
return ;
CB_Form . DataSource = PKX . getFormList ( species , types , forms , gendersymbols ) . ToList ( ) ;
2014-12-13 22:48:34 +00:00
}
2016-06-28 06:03:57 +00:00
private void setAbilityList ( )
2014-12-24 07:29:57 +00:00
{
2016-06-28 06:03:57 +00:00
if ( SAV . Generation < 3 ) // no abilities
2014-12-24 07:29:57 +00:00
return ;
2016-06-28 06:03:57 +00:00
int formnum = 0 ;
int species = Util . getIndex ( CB_Species ) ;
if ( SAV . Generation > 3 ) // has forms
formnum = CB_Form . SelectedIndex ;
2016-06-26 21:23:41 +00:00
2016-07-18 06:04:39 +00:00
int [ ] abils = SAV . Personal . getAbilities ( species , formnum ) ;
2016-07-03 03:24:17 +00:00
string [ ] abilIdentifier = { " (1)" , " (2)" , " (H)" } ;
2016-07-09 21:21:28 +00:00
List < string > ability_list = abils . Where ( a = > a ! = 0 ) . Select ( ( t , i ) = > abilitylist [ t ] + abilIdentifier [ i ] ) . ToList ( ) ;
2016-07-05 06:53:35 +00:00
if ( ! ability_list . Any ( ) )
ability_list . Add ( abilitylist [ 0 ] + abilIdentifier [ 0 ] ) ;
2016-06-26 21:23:41 +00:00
2016-07-09 21:21:28 +00:00
int abil = CB_Ability . SelectedIndex ;
2016-06-28 06:03:57 +00:00
CB_Ability . DataSource = ability_list ;
2016-07-09 21:21:28 +00:00
CB_Ability . SelectedIndex = abil < 0 | | abil > = CB_Ability . Items . Count ? 0 : abil ;
2016-06-26 21:23:41 +00:00
}
2014-12-24 07:29:57 +00:00
// PKX Data Calculation Functions //
2016-07-19 03:25:54 +00:00
private void setIsShiny ( object sender )
2014-12-24 07:29:57 +00:00
{
2016-07-19 03:25:54 +00:00
if ( sender = = TB_PID )
pkm . PID = Util . getHEXval ( TB_PID . Text ) ;
else if ( sender = = TB_TID )
pkm . TID = ( int ) Util . ToUInt32 ( TB_TID . Text ) ;
else if ( sender = = TB_SID )
pkm . SID = ( int ) Util . ToUInt32 ( TB_SID . Text ) ;
2016-07-18 06:40:40 +00:00
bool isShiny = pkm . IsShiny ;
2015-01-01 19:38:37 +00:00
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 } ;
for ( int i = 0 ; i < 6 ; i + + )
2016-06-20 04:22:43 +00:00
pba [ i ] . Image = Util . ChangeOpacity ( pba [ i ] . InitialImage , ( pkm . Markings [ i ] ? 1 : 0 ) * 0.9 + 0.1 ) ;
2015-09-24 03:29:31 +00:00
PB_MarkShiny . Image = Util . ChangeOpacity ( PB_MarkShiny . InitialImage , ( ! BTN_Shinytize . Enabled ? 1 : 0 ) * 0.9 + 0.1 ) ;
PB_MarkCured . Image = Util . ChangeOpacity ( PB_MarkCured . InitialImage , ( CHK_Cured . Checked ? 1 : 0 ) * 0.9 + 0.1 ) ;
2014-06-28 21:22:05 +00:00
2015-10-10 17:01:52 +00:00
int Version = Util . getIndex ( CB_GameOrigin ) ; // 24,25 = XY, 26,27 = ORAS, 28,29 = ???
2016-01-18 01:07:19 +00:00
PB_MarkPentagon . Image = Util . ChangeOpacity ( PB_MarkPentagon . InitialImage , ( Version > = 24 & & Version < = 29 ? 1 : 0 ) * 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 )
{
2016-06-20 04:22:43 +00:00
if ( SAV . Generation ! = 6 )
{
Util . Alert ( "QR feature only available for 6th Gen Games." ) ;
return ;
}
2015-02-27 08:40:57 +00:00
if ( ModifierKeys = = Keys . Alt )
{
// Fetch data from QR code...
2016-06-20 04:22:43 +00:00
byte [ ] ekx = QR . getQRData ( ) ;
2015-03-14 02:59:51 +00:00
if ( ekx = = null ) return ;
2016-06-20 04:22:43 +00:00
if ( ekx . Length ! = PKX . SIZE_6STORED ) { Util . Alert ( $"Decoded data not {PKX.SIZE_6STORED} bytes." , $"QR Data Size: {ekx.Length}" ) ; }
2015-03-14 02:59:51 +00:00
else try
{
2016-01-24 18:19:30 +00:00
PK6 pk = new PK6 ( PKX . decryptArray ( ekx ) ) ;
if ( pk . ChecksumValid ) { populateFields ( pk ) ; }
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
{
2016-06-21 06:02:26 +00:00
if ( ! verifiedPKM ( ) ) return ;
2016-06-20 04:22:43 +00:00
PKM pkx = preparePKM ( ) ;
2016-01-24 18:19:30 +00:00
byte [ ] ekx = pkx . EncryptedBoxData ;
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!
2016-06-20 04:22:43 +00:00
Image qr = QR . getQRImage ( ekx , server ) ;
2015-03-14 02:59:51 +00:00
if ( qr = = null ) return ;
2015-02-27 08:40:57 +00:00
2016-01-24 18:19:30 +00:00
string [ ] r = pkx . QRText ;
2015-03-14 02:59:51 +00:00
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
2016-06-20 04:22:43 +00:00
TB_Friendship . Text = pkm . CurrentFriendship . ToString ( ) ;
2015-03-11 01:44:51 +00:00
else
2016-07-18 06:40:40 +00:00
TB_Friendship . Text = TB_Friendship . Text = = "255" ? SAV . Personal [ pkm . Species ] . BaseFriendship . 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
2016-07-18 06:04:39 +00:00
int gt = SAV . Personal [ Util . getIndex ( CB_Species ) ] . Gender ;
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)
2016-07-29 05:54:29 +00:00
int newGender = PKX . getGender ( Label_Gender . Text ) ^ 1 ;
if ( SAV . Generation < = 4 )
{
pkm . Species = Util . getIndex ( CB_Species ) ;
pkm . Version = Util . getIndex ( CB_GameOrigin ) ;
2016-07-30 05:30:06 +00:00
pkm . Nature = Util . getIndex ( CB_Nature ) ;
2016-07-29 05:54:29 +00:00
pkm . AltForm = CB_Form . SelectedIndex ;
pkm . setPIDGender ( newGender ) ;
TB_PID . Text = pkm . PID . ToString ( "X8" ) ;
}
pkm . Gender = newGender ;
2016-06-20 04:22:43 +00:00
Label_Gender . Text = gendersymbols [ pkm . Gender ] ;
Label_Gender . ForeColor = pkm . Gender = = 2 ? Label_Species . ForeColor : ( pkm . 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
{
2016-01-05 06:42:38 +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-13 22:48:34 +00:00
}
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 } ;
2016-06-20 04:22:43 +00:00
int index = Array . IndexOf ( pba , sender ) ;
bool [ ] markings = pkm . Markings ;
markings [ index ] ^ = true ;
pkm . Markings = markings ;
2014-12-13 22:48:34 +00:00
setMarkings ( ) ;
}
2015-09-27 17:00:45 +00:00
private void clickStatLabel ( object sender , MouseEventArgs e )
2015-09-26 04:56:15 +00:00
{
if ( ! ( ModifierKeys = = Keys . Control | | ModifierKeys = = Keys . Alt ) )
return ;
2016-02-24 22:59:03 +00:00
int index = Array . IndexOf ( new [ ] { Label_HP , Label_ATK , Label_DEF , Label_SPA , Label_SPD , Label_SPE } , sender ) ;
2015-09-26 04:56:15 +00:00
if ( ModifierKeys = = Keys . Alt ) // EV
{
var arrayEV = new [ ] { TB_HPEV , TB_ATKEV , TB_DEFEV , TB_SPAEV , TB_SPDEV , TB_SPEEV } ;
2016-01-05 06:42:38 +00:00
arrayEV [ index ] . Text = ( e . Button = = MouseButtons . Left
2016-01-09 20:39:18 +00:00
? Math . Min ( Math . Max ( 510 - Util . ToInt32 ( TB_EVTotal . Text ) + Util . ToInt32 ( arrayEV [ index ] . Text ) , 0 ) , 252 )
2015-09-26 04:56:15 +00:00
: 0 ) . ToString ( ) ;
}
else
2015-10-24 23:33:44 +00:00
new [ ] { TB_HPIV , TB_ATKIV , TB_DEFIV , TB_SPAIV , TB_SPDIV , TB_SPEIV } [ index ] . Text =
2016-01-18 01:07:19 +00:00
( e . Button = = MouseButtons . Left ? 31 : 0 ) . ToString ( ) ;
2015-09-26 04:56:15 +00:00
}
2015-09-27 17:00:45 +00:00
private void clickIV ( object sender , EventArgs e )
{
if ( ModifierKeys = = Keys . Control )
2016-07-18 18:51:26 +00:00
( ( MaskedTextBox ) sender ) . Text = 31. ToString ( ) ;
2015-09-27 17:00:45 +00:00
else if ( ModifierKeys = = Keys . Alt )
2016-07-18 18:51:26 +00:00
( ( MaskedTextBox ) sender ) . Text = 0. ToString ( ) ;
2015-09-27 17:00:45 +00:00
}
private void clickEV ( object sender , EventArgs e )
{
if ( ModifierKeys = = Keys . Control ) // EV
2016-07-18 18:51:26 +00:00
( ( MaskedTextBox ) sender ) . Text = Math . Min ( Math . Max ( 510 - Util . ToInt32 ( TB_EVTotal . Text ) + Util . ToInt32 ( ( sender as MaskedTextBox ) . Text ) , 0 ) , 252 ) . ToString ( ) ;
2015-09-27 17:00:45 +00:00
else if ( ModifierKeys = = Keys . Alt )
2016-07-18 18:51:26 +00:00
( ( MaskedTextBox ) sender ) . Text = 0. ToString ( ) ;
2015-09-27 17:00:45 +00:00
}
2014-12-14 19:06:17 +00:00
private void clickOT ( object sender , EventArgs e )
2014-12-13 22:48:34 +00:00
{
2016-01-31 07:03:43 +00:00
if ( ! SAV . Exportable )
return ;
2015-10-24 03:13:32 +00:00
// Get Save Information
2016-01-31 07:03:43 +00:00
TB_OT . Text = SAV . OT ;
Label_OTGender . Text = gendersymbols [ SAV . Gender % 2 ] ;
2016-05-06 01:47:40 +00:00
Label_OTGender . ForeColor = SAV . Gender = = 1 ? Color . Red : Color . Blue ;
2015-10-24 03:13:32 +00:00
TB_TID . Text = SAV . TID . ToString ( ) ;
TB_SID . Text = SAV . SID . ToString ( ) ;
2016-06-20 04:22:43 +00:00
if ( SAV . Game > = 0 )
CB_GameOrigin . SelectedValue = SAV . Game ;
if ( SAV . Language > = 0 )
CB_Language . SelectedValue = SAV . Language ;
if ( SAV . HasGeolocation )
{
CB_SubRegion . SelectedValue = SAV . SubRegion ;
CB_Country . SelectedValue = SAV . Country ;
CB_3DSReg . SelectedValue = SAV . ConsoleRegion ;
}
2015-03-11 01:44:51 +00:00
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 )
2016-01-31 07:03:43 +00:00
Label_CTGender . Text = gendersymbols [ SAV . Gender % 2 ] ;
2014-12-20 19:27:29 +00:00
}
private void clickGT ( object sender , EventArgs e )
{
2016-06-20 04:22:43 +00:00
if ( ! GB_nOT . Visible )
return ;
2016-01-24 18:19:30 +00:00
if ( sender = = GB_OT )
2014-12-20 19:27:29 +00:00
{
2016-06-20 04:22:43 +00:00
pkm . CurrentHandler = 0 ;
2014-12-20 19:27:29 +00:00
GB_OT . BackgroundImage = mixedHighlight ;
GB_nOT . BackgroundImage = null ;
}
else if ( TB_OTt2 . Text . Length > 0 )
{
2016-06-20 04:22:43 +00:00
pkm . CurrentHandler = 1 ;
2014-12-20 19:27:29 +00:00
GB_OT . BackgroundImage = null ;
GB_nOT . BackgroundImage = mixedHighlight ;
}
2016-06-20 04:22:43 +00:00
TB_Friendship . Text = pkm . CurrentFriendship . ToString ( ) ;
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 ;
2016-02-03 04:05:46 +00:00
if ( ! string . IsNullOrWhiteSpace ( 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 ] ;
2016-01-05 06:42:38 +00:00
lbl . ForeColor = gender = = 1 ? Color . Red : Color . Blue ;
2015-08-07 04:16:25 +00:00
}
2014-12-13 22:48:34 +00:00
}
2015-06-28 21:34:38 +00:00
private void clickMoves ( object sender , EventArgs e )
{
2016-03-25 07:10:11 +00:00
updateLegality ( ) ;
int [ ] m = Legality . getSuggestedRelearn ( ) ;
2016-04-08 00:42:53 +00:00
string r = string . Join ( Environment . NewLine , m . Select ( v = > v > = movelist . Length ? "ERROR" : movelist [ v ] ) ) ;
2016-03-25 07:10:11 +00:00
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Apply suggested relearn moves?" , r ) )
2015-06-28 21:34:38 +00:00
return ;
2016-03-25 07:10:11 +00:00
CB_RelearnMove1 . SelectedValue = m [ 0 ] ;
CB_RelearnMove2 . SelectedValue = m [ 1 ] ;
CB_RelearnMove3 . SelectedValue = m [ 2 ] ;
CB_RelearnMove4 . SelectedValue = m [ 3 ] ;
updateLegality ( ) ;
2015-06-28 21:34:38 +00:00
}
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
2016-02-01 04:44:30 +00:00
changingFields = true ;
2016-01-31 07:03:43 +00:00
if ( sender = = TB_EXP )
2014-12-13 22:48:34 +00:00
{
// Change the Level
2016-01-09 20:39:18 +00:00
uint EXP = Util . ToUInt32 ( TB_EXP . Text ) ;
2015-09-25 02:54:50 +00:00
int Species = Util . getIndex ( CB_Species ) ;
2016-02-01 04:44:30 +00:00
int Level = PKX . getLevel ( Species , EXP ) ;
2015-09-25 02:54:50 +00:00
if ( Level = = 100 )
2016-02-01 04:44:30 +00:00
EXP = PKX . getEXP ( 100 , Species ) ;
2014-12-20 04:22:15 +00:00
2015-09-25 02:54:50 +00:00
TB_Level . Text = Level . ToString ( ) ;
2014-12-20 04:22:15 +00:00
if ( ! MT_Level . Visible )
2015-09-25 02:54:50 +00:00
TB_EXP . Text = EXP . ToString ( ) ;
2014-12-20 04:22:15 +00:00
else
2015-09-25 02:54:50 +00:00
MT_Level . Text = Level . ToString ( ) ;
2014-12-13 22:48:34 +00:00
}
2014-12-20 04:22:15 +00:00
else
2014-12-13 22:48:34 +00:00
{
// Change the XP
2015-09-25 02:54:50 +00:00
int Level = Util . ToInt32 ( ( MT_Level . Focused ? MT_Level : TB_Level ) . Text ) ;
if ( Level > 100 ) TB_Level . Text = "100" ;
2016-01-03 04:22:53 +00:00
if ( Level > byte . MaxValue ) MT_Level . Text = "255" ;
2014-12-13 22:48:34 +00:00
2015-09-25 02:54:50 +00:00
TB_EXP . Text = PKX . getEXP ( Level , Util . getIndex ( CB_Species ) ) . ToString ( ) ;
2014-12-13 22:48:34 +00:00
}
2015-03-09 00:41:13 +00:00
changingFields = false ;
2016-07-30 02:38:16 +00:00
if ( fieldsLoaded )
pkm . EXP = Util . ToUInt32 ( TB_EXP . Text ) ;
2014-12-13 22:48:34 +00:00
updateStats ( ) ;
2016-02-28 02:10:02 +00:00
updateLegality ( ) ;
2014-12-13 22:48:34 +00:00
}
2015-03-09 00:41:13 +00:00
private void updateHPType ( object sender , EventArgs e )
{
2015-11-06 06:59:55 +00:00
if ( changingFields | | ! fieldsInitialized ) return ;
2015-03-09 00:41:13 +00:00
changingFields = true ;
2015-09-25 02:54:50 +00:00
int [ ] ivs =
{
Util . ToInt32 ( TB_HPIV . Text ) , Util . ToInt32 ( TB_ATKIV . Text ) , Util . ToInt32 ( TB_DEFIV . Text ) ,
Util . ToInt32 ( TB_SPAIV . Text ) , Util . ToInt32 ( TB_SPDIV . Text ) , Util . ToInt32 ( TB_SPEIV . Text )
} ;
2015-03-09 00:41:13 +00:00
2015-09-25 02:54:50 +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
2015-03-09 00:41:13 +00:00
changingFields = false ;
updateIVs ( null , null ) ;
}
2014-12-13 22:48:34 +00:00
private void updateIVs ( object sender , EventArgs e )
{
2015-11-06 06:59:55 +00:00
if ( changingFields | | ! fieldsInitialized ) return ;
2016-07-18 18:51:26 +00:00
if ( sender ! = null & & Util . ToInt32 ( ( ( MaskedTextBox ) sender ) . Text ) > 31 )
( ( MaskedTextBox ) sender ) . Text = "31" ;
2014-06-28 21:22:05 +00:00
2015-03-09 00:41:13 +00:00
changingFields = true ;
2014-06-28 21:22:05 +00:00
2015-09-24 03:29:31 +00:00
// Update IVs
2016-06-20 04:22:43 +00:00
pkm . IV_HP = Util . ToInt32 ( TB_HPIV . Text ) ;
pkm . IV_ATK = Util . ToInt32 ( TB_ATKIV . Text ) ;
pkm . IV_DEF = Util . ToInt32 ( TB_DEFIV . Text ) ;
pkm . IV_SPE = Util . ToInt32 ( TB_SPEIV . Text ) ;
pkm . IV_SPA = Util . ToInt32 ( TB_SPAIV . Text ) ;
pkm . IV_SPD = Util . ToInt32 ( TB_SPDIV . Text ) ;
2015-09-25 02:54:50 +00:00
2016-06-20 04:22:43 +00:00
CB_HPType . SelectedValue = pkm . HPType ;
2015-09-24 03:29:31 +00:00
changingFields = false ;
2014-06-28 21:22:05 +00:00
2015-09-24 03:29:31 +00:00
// Potential Reading
2016-01-05 06:42:38 +00:00
L_Potential . Text = ( ! unicode
2015-09-24 03:29:31 +00:00
? new [ ] { "★☆☆☆" , "★★☆☆" , "★★★☆" , "★★★★" }
: new [ ] { "+" , "++" , "+++" , "++++" }
2016-06-20 04:22:43 +00:00
) [ pkm . PotentialRating ] ;
2015-09-24 03:29:31 +00:00
2016-06-20 04:22:43 +00:00
TB_IVTotal . Text = pkm . IVs . Sum ( ) . ToString ( ) ;
2014-06-28 21:22:05 +00:00
2016-06-26 21:23:41 +00:00
int characteristic = pkm . Characteristic ;
2016-06-28 06:03:57 +00:00
L_Characteristic . Visible = Label_CharacteristicPrefix . Visible = characteristic > - 1 ;
2016-06-26 21:23:41 +00:00
if ( characteristic > - 1 )
L_Characteristic . Text = characteristics [ pkm . Characteristic ] ;
2014-12-13 22:48:34 +00:00
updateStats ( ) ;
}
private void updateEVs ( object sender , EventArgs e )
{
2016-07-21 03:40:03 +00:00
if ( sender is MaskedTextBox )
{
MaskedTextBox m = ( MaskedTextBox ) sender ;
if ( Util . ToInt32 ( m . Text ) > SAV . MaxEV )
{ m . Text = SAV . MaxEV . ToString ( ) ; return ; } // recursive on text set
}
2014-12-13 22:48:34 +00:00
2015-09-24 03:29:31 +00:00
changingFields = true ;
2016-07-21 03:40:03 +00:00
if ( sender = = TB_HPEV ) pkm . EV_HP = Util . ToInt32 ( TB_HPEV . Text ) ;
else if ( sender = = TB_ATKEV ) pkm . EV_ATK = Util . ToInt32 ( TB_ATKEV . Text ) ;
else if ( sender = = TB_DEFEV ) pkm . EV_DEF = Util . ToInt32 ( TB_DEFEV . Text ) ;
else if ( sender = = TB_SPEEV ) pkm . EV_SPE = Util . ToInt32 ( TB_SPEEV . Text ) ;
else if ( sender = = TB_SPAEV ) pkm . EV_SPA = Util . ToInt32 ( TB_SPAEV . Text ) ;
else if ( sender = = TB_SPDEV ) pkm . EV_SPD = Util . ToInt32 ( TB_SPDEV . Text ) ;
2014-12-13 22:48:34 +00:00
2016-07-21 03:40:03 +00:00
int evtotal = pkm . EVs . Sum ( ) ;
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 ;
2015-09-24 03:29:31 +00:00
else if ( evtotal = = 508 ) // Fishy EVs
TB_EVTotal . BackColor = Color . LightYellow ;
2016-04-29 04:43:16 +00:00
else TB_EVTotal . BackColor = TB_IVTotal . BackColor ;
2014-12-13 22:48:34 +00:00
TB_EVTotal . Text = evtotal . ToString ( ) ;
2015-09-24 03:29:31 +00:00
changingFields = false ;
2014-12-13 22:48:34 +00:00
updateStats ( ) ;
}
private void updateRandomIVs ( object sender , EventArgs e )
{
2015-09-24 03:29:31 +00:00
changingFields = true ;
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 ( ) ;
}
2015-09-24 03:29:31 +00:00
changingFields = false ;
2016-01-27 05:06:53 +00:00
updateIVs ( null , null ) ;
2014-12-13 22:48:34 +00:00
}
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 )
{
2016-07-30 05:30:06 +00:00
if ( fieldsLoaded )
{
pkm . Version = Util . getIndex ( CB_GameOrigin ) ;
pkm . PID = Util . getHEXval ( TB_PID . Text ) ;
pkm . Species = Util . getIndex ( CB_Species ) ;
pkm . Nature = Util . getIndex ( CB_Nature ) ;
pkm . AltForm = CB_Form . SelectedIndex ;
}
if ( sender = = Label_Gender )
pkm . setPIDGender ( pkm . Gender ) ;
else if ( sender = = CB_Nature & & pkm . Nature ! = Util . getIndex ( CB_Nature ) )
pkm . setPIDNature ( Util . getIndex ( CB_Nature ) ) ;
else if ( sender = = BTN_RerollPID )
pkm . setPIDGender ( pkm . Gender ) ;
TB_PID . Text = pkm . PID . ToString ( "X8" ) ;
2014-12-14 20:15:53 +00:00
getQuickFiller ( dragout ) ;
2016-07-30 05:30:06 +00:00
if ( pkm . Format > = 6 )
TB_EC . Text = pkm . EncryptionConstant . ToString ( "X8" ) ;
2014-12-13 22:48:34 +00:00
}
private void updateRandomEC ( object sender , EventArgs e )
{
2016-04-22 02:44:22 +00:00
int origin = Util . getIndex ( CB_GameOrigin ) ;
if ( origin < 24 )
{
TB_EC . Text = TB_PID . Text ;
Util . Alert ( "EC should match PID." ) ;
}
int wIndex = Array . IndexOf ( Legal . WurmpleFamily , Util . getIndex ( CB_Species ) ) ;
if ( wIndex < 0 )
{
TB_EC . Text = Util . rnd32 ( ) . ToString ( "X8" ) ;
}
else
{
uint EC ;
do { EC = Util . rnd32 ( ) ; } while ( ( EC > > 16 ) % 10 / 5 ! = wIndex / 2 ) ;
TB_EC . Text = EC . 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
}
2016-01-03 04:22:53 +00:00
private void updateHackedStatText ( object sender , EventArgs e )
{
2016-01-17 21:27:24 +00:00
if ( ! CHK_HackedStats . Checked | | ! ( sender is TextBox ) )
2016-01-03 04:22:53 +00:00
return ;
2016-01-17 21:27:24 +00:00
string text = ( ( TextBox ) sender ) . Text ;
2016-01-27 05:04:17 +00:00
if ( string . IsNullOrWhiteSpace ( text ) )
2016-01-17 21:27:24 +00:00
( ( TextBox ) sender ) . Text = "0" ;
2016-01-03 04:22:53 +00:00
if ( Convert . ToUInt32 ( text ) > ushort . MaxValue )
2016-01-17 21:27:24 +00:00
( ( TextBox ) sender ) . Text = "65535" ;
2016-01-03 04:22:53 +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
{
2016-07-18 18:51:26 +00:00
if ( Util . ToInt32 ( ( ( MaskedTextBox ) sender ) . Text ) > byte . MaxValue )
( ( MaskedTextBox ) sender ) . Text = "255" ;
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
{
2016-07-28 02:25:36 +00:00
if ( CB_Form = = sender & & fieldsLoaded )
pkm . AltForm = CB_Form . SelectedIndex ;
2014-12-13 22:48:34 +00:00
updateStats ( ) ;
// Repopulate Abilities if Species Form has different abilities
2016-06-28 06:03:57 +00:00
setAbilityList ( ) ;
2014-12-13 22:48:34 +00:00
// Gender Forms
2016-07-28 01:20:15 +00:00
if ( Util . getIndex ( CB_Species ) = = 201 )
{
if ( fieldsLoaded & & SAV . Generation = = 3 )
updateRandomPID ( sender , e ) ; // Fix AltForm
}
else if ( PKX . getGender ( CB_Form . Text ) < 2 )
2014-12-13 22:48:34 +00:00
Label_Gender . Text = CB_Form . Text ;
2016-01-12 05:19:01 +00:00
if ( changingFields )
return ;
changingFields = true ;
2016-01-22 06:55:20 +00:00
MT_Form . Text = CB_Form . SelectedIndex . ToString ( ) ;
2016-01-12 05:19:01 +00:00
changingFields = false ;
}
private void updateHaXForm ( object sender , EventArgs e )
{
if ( changingFields )
return ;
changingFields = true ;
2016-07-21 03:40:03 +00:00
int form = pkm . AltForm = Util . ToInt32 ( MT_Form . Text ) ;
2016-01-12 05:19:01 +00:00
CB_Form . SelectedIndex = CB_Form . Items . Count > form ? form : - 1 ;
changingFields = false ;
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
{
2016-07-22 06:49:52 +00:00
TB_PP1 . Text = pkm . getMovePP ( Util . getIndex ( CB_Move1 ) , CB_PPu1 . SelectedIndex ) . ToString ( ) ;
TB_PP2 . Text = pkm . getMovePP ( Util . getIndex ( CB_Move2 ) , CB_PPu2 . SelectedIndex ) . ToString ( ) ;
TB_PP3 . Text = pkm . getMovePP ( Util . getIndex ( CB_Move3 ) , CB_PPu3 . SelectedIndex ) . ToString ( ) ;
TB_PP4 . Text = pkm . getMovePP ( Util . getIndex ( CB_Move4 ) , CB_PPu4 . SelectedIndex ) . ToString ( ) ;
2014-12-13 22:48:34 +00:00
}
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-12-02 07:08:16 +00:00
foreach ( int day in Enumerable . Range ( 0 , CB_PKRSStrain . SelectedIndex % 4 + 2 ) ) CB_PKRSDays . Items . Add ( day ) ;
2015-03-14 02:59:51 +00:00
// Set the days back if they're legal, else set it to 1. (0 always passes).
2016-01-05 06:42:38 +00:00
CB_PKRSDays . SelectedIndex = currentDuration < CB_PKRSDays . Items . Count ? currentDuration : 1 ;
2015-03-14 02:59:51 +00:00
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 )
{
2015-11-06 06:59:55 +00:00
if ( ! fieldsInitialized ) return ;
2014-12-26 18:46:18 +00:00
// 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 )
{
2015-11-06 06:59:55 +00:00
if ( ! fieldsInitialized ) 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
2015-09-25 02:54:50 +00:00
int Species = Util . getIndex ( CB_Species ) ;
int Level = Util . ToInt32 ( TB_Level . Text ) ;
if ( MT_Level . Visible ) Level = Util . ToInt32 ( MT_Level . Text ) ;
2014-12-13 22:48:34 +00:00
// Get Forms for Given Species
2016-06-30 05:58:02 +00:00
setForms ( ) ;
2014-12-13 22:48:34 +00:00
// Recalculate EXP for Given Level
2015-09-25 02:54:50 +00:00
uint EXP = PKX . getEXP ( Level , Species ) ;
TB_EXP . Text = EXP . ToString ( ) ;
2014-12-13 22:48:34 +00:00
// Check for Gender Changes
// Get Gender Threshold
2016-07-18 06:04:39 +00:00
int gt = SAV . Personal [ Species ] . Gender ;
2016-05-01 03:25:12 +00:00
int cg = Array . IndexOf ( gendersymbols , Label_Gender . Text ) ;
int Gender ;
2014-12-13 22:48:34 +00:00
if ( gt = = 255 ) // Genderless
2016-04-30 21:43:47 +00:00
Gender = 2 ;
2014-12-13 22:48:34 +00:00
else if ( gt = = 254 ) // Female Only
2016-04-30 21:43:47 +00:00
Gender = 1 ;
else if ( gt = = 0 ) // Male Only
Gender = 0 ;
2016-05-01 03:25:12 +00:00
else if ( cg = = 2 | | Util . getIndex ( CB_GameOrigin ) < 24 )
2016-04-30 21:43:47 +00:00
Gender = ( Util . getHEXval ( TB_PID . Text ) & 0xFF ) < = gt ? 1 : 0 ;
else
Gender = cg ;
2015-09-25 02:54:50 +00:00
Label_Gender . Text = gendersymbols [ Gender ] ;
2015-12-02 07:08:16 +00:00
Label_Gender . ForeColor = Gender = = 2 ? Label_Species . ForeColor : ( Gender = = 1 ? Color . Red : Color . Blue ) ;
2016-06-28 06:03:57 +00:00
setAbilityList ( ) ;
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 ) ;
2016-02-17 15:54:59 +00:00
2016-02-28 02:10:02 +00:00
updateLegality ( ) ;
2014-12-13 22:48:34 +00:00
}
private void updateOriginGame ( object sender , EventArgs e )
{
2015-09-25 02:54:50 +00:00
int Version = Util . getIndex ( CB_GameOrigin ) ;
2016-07-17 04:31:49 +00:00
if ( SAV . Generation = = 3 & & origintrack ! = "Gen3" )
{
var met_list = Util . getCBList ( metRSEFRLG_00000 , Enumerable . Range ( 0 , 213 ) . ToArray ( ) ) ;
2016-07-23 21:55:12 +00:00
met_list = Util . getOffsetCBList ( met_list , metRSEFRLG_00000 , 00000 , new [ ] { 253 , 254 , 255 } ) ;
2016-07-17 04:31:49 +00:00
origintrack = "Gen3" ;
CB_MetLocation . DisplayMember = "Text" ;
CB_MetLocation . ValueMember = "Value" ;
CB_MetLocation . DataSource = met_list ;
CB_MetLocation . SelectedValue = 0 ;
}
2016-07-29 04:46:30 +00:00
else if ( SAV . Generation = = 4 & & origintrack ! = "Gen4" )
{
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 } ) ;
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 ) ;
CB_MetLocation . DisplayMember = "Text" ;
CB_MetLocation . ValueMember = "Value" ;
CB_MetLocation . DataSource = met_list ;
CB_EggLocation . DisplayMember = "Text" ;
CB_EggLocation . ValueMember = "Value" ;
CB_EggLocation . DataSource = new BindingSource ( met_list , null ) ;
CB_EggLocation . SelectedValue = 0 ;
CB_MetLocation . SelectedValue = 0 ;
origintrack = "Gen4" ;
}
else if ( Version < 24 & & origintrack ! = "Past" & & SAV . Generation > = 5 )
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-09-25 02:54:50 +00:00
CB_MetLocation . SelectedValue = Version < 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
}
2016-04-29 04:43:16 +00:00
else if ( Version > 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
}
2016-06-20 04:22:43 +00:00
2016-07-29 04:46:30 +00:00
if ( SAV . Generation > = 4 & & Version < 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.
2016-07-17 04:31:49 +00:00
if ( SAV . Generation > = 4 )
{
bool g4 = Version > = 7 & & Version < = 12 & & Version ! = 9 ;
CB_EncounterType . Visible = Label_EncounterType . Visible = g4 ;
if ( ! g4 )
CB_EncounterType . SelectedValue = 0 ;
}
2014-12-24 07:29:57 +00:00
setMarkings ( ) ; // Set/Remove KB marking
2016-02-27 04:33:18 +00:00
if ( ! fieldsLoaded )
return ;
2016-06-20 04:22:43 +00:00
pkm . Version = Version ;
2016-02-28 02:10:02 +00:00
updateLegality ( ) ;
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
{
2016-06-20 04:22:43 +00:00
if ( CB_ExtraBytes . Items . Count = = 0 )
return ;
2014-12-13 22:48:34 +00:00
// Changed Extra Byte's Value
2016-07-18 18:51:26 +00:00
if ( Util . ToInt32 ( ( ( MaskedTextBox ) sender ) . Text ) > byte . MaxValue )
( ( MaskedTextBox ) sender ) . Text = "255" ;
2014-12-13 22:48:34 +00:00
int value = Util . ToInt32 ( TB_ExtraByte . Text ) ;
int offset = Convert . ToInt32 ( CB_ExtraBytes . Text , 16 ) ;
2016-06-20 04:22:43 +00:00
pkm . Data [ 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
{
2016-06-20 04:22:43 +00:00
if ( CB_ExtraBytes . Items . Count = = 0 )
return ;
2014-12-13 22:48:34 +00:00
// Byte changed, need to refresh the Text box for the byte's value.
2016-06-20 04:22:43 +00:00
TB_ExtraByte . Text = pkm . Data [ Convert . ToInt32 ( CB_ExtraBytes . Text , 16 ) ] . ToString ( ) ;
2014-06-28 21:22:05 +00:00
}
2015-09-21 03:34:09 +00:00
private void updateNatureModification ( object sender , EventArgs e )
{
2016-01-31 07:03:43 +00:00
if ( sender ! = CB_Nature ) return ;
2015-09-21 03:34:09 +00:00
int nature = Util . getIndex ( CB_Nature ) ;
int incr = nature / 5 ;
int decr = nature % 5 ;
Label [ ] labarray = { Label_ATK , Label_DEF , Label_SPE , Label_SPA , Label_SPD } ;
// Reset Label Colors
foreach ( Label label in labarray )
label . ForeColor = defaultControlText ;
// Set Colored StatLabels only if Nature isn't Neutral
NatureTip . SetToolTip ( CB_Nature ,
incr ! = decr
2016-01-17 21:27:24 +00:00
? $"+{labarray[incr].Text} / -{labarray[decr].Text}" . Replace ( ":" , "" )
2015-09-21 03:34:09 +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
{
2016-01-15 05:05:05 +00:00
if ( fieldsInitialized & & ModifierKeys = = Keys . Control & & sender ! = null ) // Import Showdown
2016-06-26 21:23:41 +00:00
{ clickShowdownImportPK6 ( sender , e ) ; return ; }
2016-01-15 05:05:05 +00:00
if ( fieldsInitialized & & ModifierKeys = = Keys . Alt & & sender ! = null ) // Export Showdown
2016-06-26 21:23:41 +00:00
{ clickShowdownExportPK6 ( sender , e ) ; return ; }
if ( ! fieldsInitialized | | CHK_Nicknamed . Checked )
return ;
2015-03-11 01:44:51 +00:00
// Fetch Current Species and set it as Nickname Text
int species = Util . getIndex ( CB_Species ) ;
2016-06-26 21:23:41 +00:00
if ( species < 1 | | species > SAV . MaxSpeciesID )
2015-03-11 01:44:51 +00:00
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 ) ;
if ( CHK_IsEgg . Checked ) species = 0 ; // Set species to 0 to get the egg name.
2016-06-26 21:23:41 +00:00
string nick = PKX . getSpeciesName ( CHK_IsEgg . Checked ? 0 : species , lang ) ;
if ( SAV . Generation < 5 ) // All caps GenIV and previous
nick = nick . ToUpper ( ) ;
TB_Nickname . Text = nick ;
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
{
2016-07-17 17:06:52 +00:00
TextBox tb = ! ( sender is TextBox ) ? TB_Nickname : ( TextBox ) sender ;
2014-12-13 22:48:34 +00:00
// Special Character Form
2016-01-31 07:03:43 +00:00
if ( ModifierKeys ! = Keys . Control )
return ;
2016-04-15 23:11:46 +00:00
var z = Application . OpenForms . Cast < Form > ( ) . FirstOrDefault ( form = > form . GetType ( ) = = typeof ( f2_Text ) ) as f2_Text ;
2016-04-08 05:16:08 +00:00
if ( z ! = null )
2016-04-15 23:11:46 +00:00
{ Util . CenterToForm ( z , this ) ; z . BringToFront ( ) ; return ; }
2016-01-31 07:03:43 +00:00
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
{
2016-02-03 04:05:46 +00:00
if ( string . IsNullOrWhiteSpace ( 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 = "" ;
2016-06-20 04:22:43 +00:00
TB_Friendship . Text = pkm . CurrentFriendship . ToString ( ) ;
2014-08-31 20:32:04 +00:00
}
2016-02-03 04:05:46 +00:00
else if ( string . IsNullOrWhiteSpace ( Label_CTGender . Text ) )
2014-12-13 22:48:34 +00:00
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 ) ;
2016-07-18 06:40:40 +00:00
TB_Friendship . Text = SAV . Personal [ Util . getIndex ( CB_Species ) ] . BaseFriendship . 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-11-06 06:59:55 +00:00
if ( ! fieldsInitialized ) return ;
2015-03-11 01:44:51 +00:00
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 ;
2016-02-17 15:54:59 +00:00
2016-02-28 02:10:02 +00:00
updateLegality ( ) ;
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
{
2016-07-29 05:33:16 +00:00
pkm . TID = Util . ToInt32 ( TB_TID . Text ) ;
pkm . SID = Util . ToInt32 ( TB_SID . Text ) ;
pkm . PID = Util . getHEXval ( TB_PID . Text ) ;
pkm . Nature = Util . getIndex ( CB_Nature ) ;
pkm . Gender = PKX . getGender ( Label_Gender . Text ) ;
pkm . AltForm = CB_Form . SelectedIndex ;
2014-11-15 05:08:00 +00:00
2016-07-29 05:33:16 +00:00
pkm . setShinyPID ( ) ;
TB_PID . Text = pkm . PID . ToString ( "X8" ) ;
2014-11-15 05:08:00 +00:00
2016-07-29 05:33:16 +00:00
if ( pkm . Format > = 6 )
2016-03-07 06:21:54 +00:00
TB_EC . Text = TB_PID . Text ;
2014-12-13 22:48:34 +00:00
2014-12-14 20:15:53 +00:00
getQuickFiller ( dragout ) ;
2016-07-29 05:33:16 +00:00
updateLegality ( ) ;
2014-11-15 05:08:00 +00:00
}
2015-09-21 03:34:09 +00:00
private void updateTSV ( object sender , EventArgs e )
{
2016-06-21 04:11:48 +00:00
if ( SAV . Generation < 6 )
return ;
2016-07-18 06:40:40 +00:00
var TSV = pkm . TSV ;
2015-09-25 02:54:50 +00:00
Tip1 . SetToolTip ( TB_TID , "TSV: " + TSV . ToString ( "0000" ) ) ;
Tip2 . SetToolTip ( TB_SID , "TSV: " + TSV . ToString ( "0000" ) ) ;
2015-09-21 03:34:09 +00:00
2016-07-18 06:40:40 +00:00
pkm . PID = Util . getHEXval ( TB_PID . Text ) ;
var PSV = pkm . PSV ;
2015-09-25 02:54:50 +00:00
Tip3 . SetToolTip ( TB_PID , "PSV: " + PSV . ToString ( "0000" ) ) ;
2015-09-21 03:34:09 +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
2016-01-09 20:39:18 +00:00
TB_PID . Text = Util . getHEXval ( TB_PID . Text ) . ToString ( "X8" ) ;
TB_EC . Text = Util . getHEXval ( TB_EC . Text ) . ToString ( "X8" ) ;
2014-12-13 22:48:34 +00:00
2015-02-26 04:19:43 +00:00
// Max TID/SID is 65535
2016-01-03 04:22:53 +00:00
if ( Util . ToUInt32 ( TB_TID . Text ) > ushort . MaxValue ) TB_TID . Text = "65535" ;
if ( Util . ToUInt32 ( TB_SID . Text ) > ushort . MaxValue ) TB_SID . Text = "65535" ;
2015-01-01 19:38:37 +00:00
2016-07-19 03:25:54 +00:00
setIsShiny ( sender ) ;
2015-02-28 05:51:19 +00:00
getQuickFiller ( dragout ) ;
2016-03-07 06:21:54 +00:00
updateIVs ( null , null ) ; // If the EC is changed, EC%6 (Characteristic) might be changed.
2014-12-13 22:48:34 +00:00
TB_PID . Select ( 60 , 0 ) ; // position cursor at end of field
2016-07-30 05:30:06 +00:00
if ( SAV . Generation < = 4 & & fieldsLoaded )
2016-06-20 04:22:43 +00:00
{
2016-07-30 05:30:06 +00:00
fieldsLoaded = false ;
2016-06-20 04:22:43 +00:00
pkm . PID = Util . getHEXval ( TB_PID . Text ) ;
CB_Nature . SelectedValue = pkm . Nature ;
2016-07-30 05:30:06 +00:00
Label_Gender . Text = gendersymbols [ pkm . Gender ] ;
Label_Gender . ForeColor = pkm . Gender = = 2 ? Label_Species . ForeColor : ( pkm . Gender = = 1 ? Color . Red : Color . Blue ) ;
fieldsLoaded = true ;
2016-06-20 04:22:43 +00:00
}
2014-12-13 22:48:34 +00:00
}
2016-02-28 02:10:02 +00:00
private void validateComboBox ( object sender )
2014-12-13 22:48:34 +00:00
{
2016-03-12 04:57:55 +00:00
if ( ! formInitialized )
return ;
2016-03-06 22:42:20 +00:00
ComboBox cb = sender as ComboBox ;
if ( cb = = null )
2016-02-01 07:15:54 +00:00
return ;
2016-03-06 22:42:20 +00:00
2014-12-13 22:48:34 +00:00
cb . SelectionLength = 0 ;
2016-03-06 00:59:16 +00:00
if ( cb . Text = = "" )
{ cb . SelectedIndex = 0 ; return ; }
2015-03-11 01:44:51 +00:00
cb . BackColor = cb . SelectedValue = = null ? Color . DarkSalmon : defaultControlWhite ;
2016-02-28 02:10:02 +00:00
}
private void validateComboBox ( object sender , EventArgs e )
{
if ( ! ( sender is ComboBox ) )
return ;
2014-12-14 20:15:53 +00:00
2016-02-28 02:10:02 +00:00
validateComboBox ( sender ) ;
if ( fieldsLoaded )
2016-02-01 07:15:54 +00:00
getQuickFiller ( dragout ) ;
2014-12-13 22:48:34 +00:00
}
private void validateComboBox2 ( object sender , EventArgs e )
{
2016-01-03 04:22:53 +00:00
validateComboBox ( sender , e ) ;
2016-02-17 15:54:59 +00:00
if ( sender = = CB_Ability )
2014-12-13 22:48:34 +00:00
TB_AbilityNumber . Text = ( 1 < < CB_Ability . SelectedIndex ) . ToString ( ) ;
2016-07-31 16:20:06 +00:00
if ( fieldsLoaded & & sender = = CB_Nature & & SAV . Generation < = 4 )
updateRandomPID ( sender , e ) ;
2015-09-21 03:34:09 +00:00
updateNatureModification ( sender , null ) ;
2014-12-13 22:48:34 +00:00
updateIVs ( null , null ) ; // updating Nature will trigger stats to update as well
}
2016-02-17 15:54:59 +00:00
private void validateMove ( object sender , EventArgs e )
{
2016-03-06 22:42:20 +00:00
validateComboBox ( sender ) ;
2016-02-24 03:19:25 +00:00
if ( ! fieldsLoaded )
return ;
2016-02-17 15:54:59 +00:00
2016-02-24 03:19:25 +00:00
if ( new [ ] { CB_Move1 , CB_Move2 , CB_Move3 , CB_Move4 } . Contains ( sender ) ) // Move
2016-02-17 15:54:59 +00:00
updatePP ( sender , e ) ;
2016-03-12 04:56:40 +00:00
2016-03-06 22:42:20 +00:00
// Refresh Relearn if...
if ( new [ ] { CB_RelearnMove1 , CB_RelearnMove2 , CB_RelearnMove3 , CB_RelearnMove4 } . Contains ( sender ) )
2016-02-17 15:54:59 +00:00
{
2016-06-20 04:22:43 +00:00
if ( pkm . Format < 6 )
return ;
2016-07-18 18:51:26 +00:00
( ( PK6 ) pkm ) . RelearnMoves = new [ ] { Util . getIndex ( CB_RelearnMove1 ) , Util . getIndex ( CB_RelearnMove2 ) , Util . getIndex ( CB_RelearnMove3 ) , Util . getIndex ( CB_RelearnMove4 ) } ;
2016-03-12 04:56:40 +00:00
Legality . updateRelearnLegality ( ) ;
2016-02-24 03:19:25 +00:00
for ( int i = 0 ; i < 4 ; i + + )
2016-03-12 17:16:41 +00:00
movePB [ i ] . Visible = ! Legality . vRelearn [ i ] . Valid ;
2016-03-06 22:42:20 +00:00
}
2016-03-12 04:56:40 +00:00
// else, Refresh Moves
2016-03-06 22:42:20 +00:00
{
2016-06-20 04:22:43 +00:00
pkm . Moves = new [ ] { Util . getIndex ( CB_Move1 ) , Util . getIndex ( CB_Move2 ) , Util . getIndex ( CB_Move3 ) , Util . getIndex ( CB_Move4 ) } ;
2016-03-12 04:56:40 +00:00
Legality . updateMoveLegality ( ) ;
2016-03-06 22:42:20 +00:00
for ( int i = 0 ; i < 4 ; i + + )
2016-03-12 17:16:41 +00:00
movePB [ i ] . Visible = ! Legality . vMoves [ i ] . Valid ;
2016-02-17 15:54:59 +00:00
}
2016-03-15 06:26:29 +00:00
if ( relearnPB . Any ( p = > p . Visible ) | | movePB . Any ( p = > p . Visible ) )
{
Legality . Valid = false ;
PB_Legal . Image = Properties . Resources . warn ;
}
2016-02-17 15:54:59 +00:00
}
2016-02-28 02:10:02 +00:00
private void validateLocation ( object sender , EventArgs e )
{
validateComboBox ( sender ) ;
if ( ! fieldsLoaded )
return ;
2016-06-20 04:22:43 +00:00
pkm . Met_Location = Util . getIndex ( CB_MetLocation ) ;
pkm . Egg_Location = Util . getIndex ( CB_EggLocation ) ;
2016-02-28 02:10:02 +00:00
updateLegality ( ) ;
}
2014-12-13 22:48:34 +00:00
private void removedropCB ( object sender , KeyEventArgs e )
{
( ( ComboBox ) sender ) . DroppedDown = false ;
}
2016-04-04 00:11:58 +00:00
private void showLegality ( PK6 pk , bool tabs , bool verbose )
2016-03-09 03:20:26 +00:00
{
LegalityAnalysis la = new LegalityAnalysis ( pk ) ;
2016-03-14 01:09:12 +00:00
if ( tabs )
2016-03-18 01:58:30 +00:00
updateLegality ( la ) ;
2016-04-04 00:11:58 +00:00
Util . Alert ( verbose ? la . VerboseReport : la . Report ) ;
2016-03-09 03:20:26 +00:00
}
2016-03-18 01:58:30 +00:00
private void updateLegality ( LegalityAnalysis la = null )
2016-02-17 15:54:59 +00:00
{
if ( ! fieldsLoaded )
return ;
2016-06-20 04:22:43 +00:00
if ( ! ( pkm is PK6 ) )
return ;
2016-07-17 17:06:52 +00:00
Legality = la ? ? new LegalityAnalysis ( ( PK6 ) pkm ) ;
2016-03-14 01:09:12 +00:00
PB_Legal . Image = Legality . Valid ? Properties . Resources . valid : Properties . Resources . warn ;
2016-06-20 04:22:43 +00:00
PB_Legal . Visible = pkm . Gen6 /*&& pkm is PK6*/ ;
2016-02-17 15:54:59 +00:00
2016-03-06 22:42:20 +00:00
// Refresh Move Legality
2016-03-12 04:56:40 +00:00
for ( int i = 0 ; i < 4 ; i + + )
2016-03-12 17:16:41 +00:00
movePB [ i ] . Visible = ! Legality . vMoves [ i ] . Valid ;
2016-03-12 04:56:40 +00:00
for ( int i = 0 ; i < 4 ; i + + )
2016-03-15 06:26:29 +00:00
relearnPB [ i ] . Visible = ! Legality . vRelearn [ i ] . Valid ;
2016-02-17 15:54:59 +00:00
}
2014-12-13 22:48:34 +00:00
private void updateStats ( )
{
// Generate the stats.
2016-07-21 03:40:03 +00:00
ushort [ ] stats = pkm . getStats ( SAV . Personal . getFormeEntry ( pkm . Species , pkm . AltForm ) ) ;
2014-06-28 21:22:05 +00:00
2015-09-25 02:54:50 +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.
{
2016-07-21 03:40:03 +00:00
int incr = pkm . Nature / 5 ;
int decr = pkm . 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
}
2016-01-30 01:27:20 +00:00
private void updateUnicode ( )
{
if ( ! unicode )
{
gendersymbols = new [ ] { "M" , "F" , "-" } ;
BTN_Shinytize . Text = "*" ;
TB_Nickname . Font = TB_OT . Font = TB_OTt2 . Font = Label_TID . Font ;
}
else
{
gendersymbols = new [ ] { "♂" , "♀" , "-" } ;
BTN_Shinytize . Text = "☆" ;
TB_Nickname . Font = TB_OT . Font = TB_OTt2 . Font = PKX . getPKXFont ( 11 ) ;
}
// 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-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
{
2016-07-17 00:19:26 +00:00
new RibbonEditor ( ) . ShowDialog ( ) ;
}
private void openMedals ( object sender , EventArgs e )
{
new SuperTrainingEditor ( ) . 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
{
2016-06-20 04:22:43 +00:00
if ( pkm . Format < 6 ) return ;
2015-09-29 04:11:03 +00:00
// Write back current values
2016-06-20 04:22:43 +00:00
PK6 pk6 = pkm as PK6 ;
2015-09-29 04:11:03 +00:00
pk6 . Version = Util . getIndex ( CB_GameOrigin ) ;
pk6 . HT_Name = TB_OTt2 . Text ;
pk6 . OT_Name = TB_OT . Text ;
pk6 . IsEgg = CHK_IsEgg . Checked ;
2016-06-20 04:22:43 +00:00
pk6 . CurrentFriendship = Util . ToInt32 ( TB_Friendship . Text ) ;
2015-09-29 04:11:03 +00:00
new MemoryAmie ( ) . ShowDialog ( ) ;
2016-06-20 04:22:43 +00:00
TB_Friendship . Text = pk6 . CurrentFriendship . ToString ( ) ;
2014-06-28 21:22:05 +00:00
}
2014-12-22 04:07:04 +00:00
// Open/Save Array Manipulation //
2016-06-21 06:02:26 +00:00
public bool verifiedPKM ( )
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 :
2016-01-03 18:47:44 +00:00
{ SystemSounds . Exclamation . Play ( ) ; return false ; }
2014-06-28 21:22:05 +00:00
}
2016-06-21 06:02:26 +00:00
private static string [ ] verifyPKMtoSAV ( PKM pk )
{
// Check if PKM properties are outside of the valid range
List < string > errata = new List < string > ( ) ;
if ( pk . HeldItem > itemlist . Length )
errata . Add ( $"Item Index beyond range: {pk.HeldItem}" ) ;
else
{
if ( pk . HeldItem > SAV . MaxItemID )
errata . Add ( $"Game can't obtain item: {itemlist[pk.HeldItem]}" ) ;
2016-07-09 01:38:40 +00:00
if ( ! pk . CanHoldItem ( SAV . HeldItems ) )
2016-06-21 06:02:26 +00:00
errata . Add ( $"Game can't hold item: {itemlist[pk.HeldItem]}" ) ;
}
if ( pk . Species > specieslist . Length )
errata . Add ( $"Species Index beyond range: {pk.HeldItem}" ) ;
else if ( SAV . MaxSpeciesID < pk . Species )
errata . Add ( $"Game can't obtain species: {specieslist[pk.Species]}" ) ;
if ( pk . Moves . Any ( m = > m > movelist . Length ) )
errata . Add ( $"Item Index beyond range: {string.Join(" , ", pk.Moves.Where(m => m > movelist.Length).Select(m => m.ToString()))}" ) ;
else if ( pk . Moves . Any ( m = > m > SAV . MaxMoveID ) )
errata . Add ( $"Game can't have move: {string.Join(" , ", pk.Moves.Where(m => m > SAV.MaxMoveID).Select(m => movelist[m]))}" ) ;
if ( pk . Ability > abilitylist . Length )
errata . Add ( $"Ability Index beyond range: {pk.Ability}" ) ;
else if ( pk . Ability > SAV . MaxAbilityID )
errata . Add ( $"Game can't have ability: {abilitylist[pk.Ability]}" ) ;
return errata . ToArray ( ) ;
}
2016-06-20 04:22:43 +00:00
public PKM preparePKM ( 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)
2015-09-28 02:56:17 +00:00
2016-07-09 21:01:31 +00:00
PKM pk = getPKMfromFields ( ) ;
2016-06-22 05:19:26 +00:00
return pk ? . Clone ( ) ;
2016-06-20 04:22:43 +00:00
}
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 ) ;
2016-02-01 07:15:54 +00:00
openQuick ( files [ 0 ] ) ;
2014-06-28 21:22:05 +00:00
}
// Decrypted Export
private void dragout_MouseDown ( object sender , MouseEventArgs e )
{
2016-03-12 02:40:08 +00:00
if ( e . Button = = MouseButtons . Left & & ( ModifierKeys = = Keys . Alt | | ModifierKeys = = Keys . Shift ) )
clickQR ( sender , e ) ;
2016-03-09 03:20:26 +00:00
if ( e . Button = = MouseButtons . Right )
return ;
2016-06-21 06:02:26 +00:00
if ( ! verifiedPKM ( ) )
2016-03-09 03:20:26 +00:00
return ;
2014-06-28 21:22:05 +00:00
2016-03-09 03:20:26 +00:00
// Create Temp File to Drag
2016-06-20 04:22:43 +00:00
PKM pkx = preparePKM ( ) ;
2016-03-09 03:20:26 +00:00
bool encrypt = ModifierKeys = = Keys . Control ;
2016-06-20 04:22:43 +00:00
string filename = $"{Path.GetFileNameWithoutExtension(pkx.FileName)}{(encrypt ? " . ek " : " . pk ") + pkx.Format}" ;
2016-03-09 03:20:26 +00:00
byte [ ] dragdata = encrypt ? pkx . EncryptedBoxData : pkx . DecryptedBoxData ;
// Make file
string newfile = Path . Combine ( Path . GetTempPath ( ) , Util . CleanFileName ( filename ) ) ;
try
{
File . WriteAllBytes ( newfile , dragdata ) ;
DoDragDrop ( new DataObject ( DataFormats . FileDrop , new [ ] { newfile } ) , DragDropEffects . Move ) ;
2014-06-28 21:22:05 +00:00
}
2016-03-09 03:20:26 +00:00
catch ( Exception x )
{ Util . Error ( "Drag & Drop Error" , x . ToString ( ) ) ; }
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 )
{
2016-01-05 06:42:38 +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 ////
2014-12-14 19:06:17 +00:00
private void clickVerifyCHK ( object sender , EventArgs e )
2014-06-28 21:22:05 +00:00
{
2015-10-24 23:33:44 +00:00
if ( SAV . Edited ) { Util . Alert ( "Save has been edited. Cannot integrity check." ) ; return ; }
2014-06-28 21:22:05 +00:00
2016-02-09 23:30:10 +00:00
if ( SAV . ChecksumsValid ) { Util . Alert ( "Checksums are valid." ) ; return ; }
if ( DialogResult . Yes = = Util . Prompt ( MessageBoxButtons . YesNo , "Export Checksum Info to Clipboard?" ) )
Clipboard . SetText ( SAV . ChecksumInfo ) ;
2014-06-28 21:22:05 +00:00
}
2016-01-03 06:31:04 +00:00
private void clickExportSAVBAK ( object sender , EventArgs e )
2015-08-07 05:32:12 +00:00
{
2016-04-07 01:36:10 +00:00
if ( ! SAV . Exportable )
return ;
2016-01-03 06:31:04 +00:00
SaveFileDialog sfd = new SaveFileDialog
2016-02-12 05:41:31 +00:00
{ FileName = Util . CleanFileName ( SAV . BAKName ) } ;
2016-01-03 06:31:04 +00:00
if ( sfd . ShowDialog ( ) ! = DialogResult . OK )
return ;
2015-12-18 02:55:59 +00:00
2016-01-03 06:31:04 +00:00
string path = sfd . FileName ;
2016-01-28 04:24:32 +00:00
File . WriteAllBytes ( path , SAV . BAK ) ;
2016-01-03 06:31:04 +00:00
Util . Alert ( "Saved Backup of current SAV to:" , path ) ;
2016-02-12 05:41:31 +00:00
2016-03-05 04:48:27 +00:00
if ( Directory . Exists ( BackupPath ) ) return ;
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo ,
$"PKHeX can perform automatic backups if you create a folder with the name \" { BackupPath } \ " in the same folder as PKHeX's executable." ,
"Would you like to create the backup folder now and save backup of current save?" ) ) return ;
try { Directory . CreateDirectory ( BackupPath ) ; Util . Alert ( "Backup folder created!" ,
$"If you wish to no longer automatically back up save files, delete the \" { BackupPath } \ " folder." ) ; }
catch { Util . Error ( $"Unable to create backup folder @ {BackupPath}" ) ; }
2016-01-03 06:31:04 +00:00
}
private void clickExportSAV ( object sender , EventArgs e )
{
if ( ! Menu_ExportSAV . Enabled )
return ;
2015-12-18 02:55:59 +00:00
2015-09-21 03:34:09 +00:00
// Chunk Error Checking
2016-06-20 04:22:43 +00:00
string err = SAV . MiscSaveChecks ( ) ;
2015-10-24 23:52:25 +00:00
if ( err . Length > 0 & & Util . Prompt ( MessageBoxButtons . YesNo , err , "Continue saving?" ) ! = DialogResult . Yes )
return ;
2015-03-11 01:44:51 +00:00
2016-02-01 07:15:54 +00:00
SaveFileDialog main = new SaveFileDialog
{
2016-06-20 05:11:53 +00:00
Filter = SAV . Filter ,
2016-02-11 08:56:10 +00:00
FileName = SAV . FileName ,
2016-02-01 07:15:54 +00:00
RestoreDirectory = true
} ;
2016-02-11 08:56:10 +00:00
if ( Directory . Exists ( SAV . FilePath ) )
main . InitialDirectory = SAV . FilePath ;
2015-03-11 01:44:51 +00:00
2015-09-21 03:34:09 +00:00
// Export
2016-02-01 07:15:54 +00:00
if ( main . ShowDialog ( ) ! = DialogResult . OK ) return ;
2016-02-11 08:56:10 +00:00
2016-06-20 04:22:43 +00:00
if ( SAV . HasBox )
2016-02-11 08:56:10 +00:00
SAV . CurrentBox = CB_BoxSelect . SelectedIndex ;
2016-06-20 05:11:53 +00:00
2016-07-18 18:51:26 +00:00
bool dsv = Path . GetExtension ( main . FileName ) ? . ToLower ( ) = = ".dsv" ;
2016-06-20 05:11:53 +00:00
File . WriteAllBytes ( main . FileName , SAV . Write ( dsv ) ) ;
2016-02-11 08:56:10 +00:00
Util . Alert ( "SAV exported to:" , main . FileName ) ;
2014-06-28 21:22:05 +00:00
}
2016-01-28 04:24:32 +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
{
2016-06-20 04:22:43 +00:00
CB_BoxSelect . SelectedIndex = ( CB_BoxSelect . SelectedIndex + 1 ) % SAV . BoxCount ;
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
{
2016-06-20 04:22:43 +00:00
CB_BoxSelect . SelectedIndex = ( CB_BoxSelect . SelectedIndex + SAV . BoxCount - 1 ) % SAV . BoxCount ;
2014-06-28 21:22:05 +00:00
}
2016-02-09 07:57:25 +00:00
private void clickBoxSort ( object sender , EventArgs e )
{
2016-06-20 04:22:43 +00:00
if ( tabBoxMulti . SelectedIndex ! = 0 )
2016-02-09 07:57:25 +00:00
return ;
2016-07-15 03:37:18 +00:00
if ( ! SAV . HasBox )
return ;
2016-06-20 04:22:43 +00:00
if ( ModifierKeys = = ( Keys . Alt | Keys . Shift ) )
{
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Clear ALL Boxes?!" ) )
return ;
2016-02-09 07:57:25 +00:00
2016-06-20 04:22:43 +00:00
SAV . resetBoxes ( ) ;
CB_BoxSelect . SelectedIndex = 0 ;
Util . Alert ( "Boxes cleared!" ) ;
}
else if ( ModifierKeys = = Keys . Alt )
{
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Clear Current Box?" ) )
return ;
2016-02-09 07:57:25 +00:00
2016-06-20 04:22:43 +00:00
SAV . resetBoxes ( CB_BoxSelect . SelectedIndex , CB_BoxSelect . SelectedIndex + 1 ) ;
setPKXBoxes ( ) ;
Util . Alert ( "Current Box cleared!" ) ;
}
else if ( ModifierKeys = = ( Keys . Control | Keys . Shift ) )
{
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Sort ALL Boxes?!" ) )
return ;
SAV . sortBoxes ( ) ;
CB_BoxSelect . SelectedIndex = 0 ;
Util . Alert ( "Boxes sorted!" ) ;
}
else if ( ModifierKeys = = Keys . Control )
{
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Sort Current Box?" ) )
return ;
SAV . sortBoxes ( CB_BoxSelect . SelectedIndex , CB_BoxSelect . SelectedIndex + 1 ) ;
setPKXBoxes ( ) ;
Util . Alert ( "Current Box sorted!" ) ;
}
2016-02-09 07:57:25 +00:00
}
2016-06-20 04:22:43 +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 )
{
2016-01-18 01:07:19 +00:00
case Keys . Control | Keys . Alt : clickClone ( sender , e ) ; break ;
2015-03-11 01:44:51 +00:00
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 ) ;
2015-10-15 03:10:09 +00:00
if ( SlotPictureBoxes [ slot ] . Image = = null )
2016-01-03 18:47:44 +00:00
{ SystemSounds . Exclamation . Play ( ) ; return ; }
2016-06-20 04:22:43 +00:00
int offset = getPKXOffset ( slot ) ;
if ( offset < 0 )
{
Util . Error ( $"Slot read error @ slot {slot}." ) ;
return ;
}
2014-06-28 21:22:05 +00:00
// Load the PKX file
2016-06-20 04:22:43 +00:00
PKM pk = 30 < = slot & & slot < 36 ? SAV . getPartySlot ( offset ) : SAV . getStoredSlot ( offset ) ;
2015-10-24 03:13:32 +00:00
if ( pk . Sanity = = 0 & & pk . Species ! = 0 )
2014-06-28 21:22:05 +00:00
{
2016-01-28 04:24:32 +00:00
try { populateFields ( pk ) ; }
2016-06-20 04:22:43 +00:00
catch { }
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
2016-01-03 18:47:44 +00:00
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
{
2016-06-21 06:02:26 +00:00
if ( ! verifiedPKM ( ) ) return ;
2014-06-28 21:22:05 +00:00
int slot = getSlot ( sender ) ;
2016-01-28 04:24:32 +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
2016-01-28 04:24:32 +00:00
int offset = getPKXOffset ( slot ) ;
2016-06-20 04:22:43 +00:00
if ( offset < 0 )
{
Util . Error ( $"Slot read error @ slot {slot}." ) ;
2016-04-24 19:40:46 +00:00
return ;
2016-06-20 04:22:43 +00:00
}
PKM pk = preparePKM ( ) ;
2016-06-21 06:02:26 +00:00
string [ ] errata = verifyPKMtoSAV ( pk ) ;
if ( errata . Length > 0 & & DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , string . Join ( Environment . NewLine , errata ) , "Continue?" ) )
return ;
2014-07-26 21:56:06 +00:00
if ( slot > = 30 & & slot < 36 ) // Party
2016-07-05 03:04:43 +00:00
{
2016-07-05 03:11:28 +00:00
// If slot isn't overwriting existing PKM, make it write to the lowest empty PKM slot
2016-07-05 03:04:43 +00:00
if ( SAV . PartyCount < slot + 1 - 30 )
{ slot = SAV . PartyCount + 30 ; offset = getPKXOffset ( slot ) ; }
2016-06-20 04:22:43 +00:00
SAV . setPartySlot ( pk , offset ) ;
2016-07-05 03:04:43 +00:00
setParty ( ) ;
getSlotColor ( slot , Properties . Resources . slotSet ) ;
}
2016-07-05 03:11:28 +00:00
else if ( slot < 30 | | HaX & & slot > = 36 & & slot < 42 )
2016-07-05 03:04:43 +00:00
{
2016-06-20 04:22:43 +00:00
SAV . setStoredSlot ( pk , offset ) ;
2016-01-24 18:19:30 +00:00
getQuickFiller ( SlotPictureBoxes [ slot ] , pk ) ;
2016-07-05 03:04:43 +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 ) ;
2016-07-05 03:11:28 +00:00
if ( slot = = 30 & & SAV . PartyCount = = 1 & & ! HaX ) { Util . Alert ( "Can't delete first slot." ) ; return ; }
2016-06-20 04:22:43 +00:00
int offset = getPKXOffset ( slot ) ;
if ( offset < 0 )
{
Util . Error ( $"Slot read error @ slot {slot}." ) ;
return ;
}
2014-10-11 07:22:22 +00:00
if ( slot > = 30 & & slot < 36 ) // Party
2016-07-05 03:04:43 +00:00
{
SAV . deletePartySlot ( slot - 30 ) ;
setParty ( ) ;
getSlotColor ( slot , Properties . Resources . slotDel ) ;
return ;
}
2016-07-05 03:11:28 +00:00
if ( slot < 30 | | HaX & & slot > = 36 & & slot < 42 )
2016-06-20 04:22:43 +00:00
{ SAV . setStoredSlot ( SAV . BlankPKM , getPKXOffset ( slot ) ) ; }
2014-10-11 07:22:22 +00:00
else return ;
2015-10-15 03:10:09 +00:00
SlotPictureBoxes [ slot ] . Image = null ;
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
2016-06-21 06:02:26 +00:00
if ( ! verifiedPKM ( ) ) return ; // don't copy garbage to the box
2016-07-03 03:30:20 +00:00
PKM pk ;
if ( Util . Prompt ( MessageBoxButtons . YesNo , $"Clone Pokemon from Editing Tabs to all slots in {CB_BoxSelect.Text}?" ) = = DialogResult . Yes )
pk = preparePKM ( ) ;
else if ( Util . Prompt ( MessageBoxButtons . YesNo , $"Delete all Pokemon in {CB_BoxSelect.Text}?" ) = = DialogResult . Yes )
pk = SAV . BlankPKM ;
else
2016-06-20 04:22:43 +00:00
return ;
2014-11-29 19:07:01 +00:00
2016-06-20 04:22:43 +00:00
for ( int i = 0 ; i < 30 ; i + + ) // set to every slot in box
2015-10-24 03:13:32 +00:00
{
2016-06-20 04:22:43 +00:00
SAV . setStoredSlot ( pk , getPKXOffset ( i ) ) ;
2016-01-24 18:19:30 +00:00
getQuickFiller ( SlotPictureBoxes [ i ] , pk ) ;
2015-10-24 03:13:32 +00:00
}
2014-11-29 19:07:01 +00:00
}
2016-03-09 03:20:26 +00:00
private void clickLegality ( object sender , EventArgs e )
{
int slot = getSlot ( sender ) ;
2016-06-20 04:22:43 +00:00
PKM pk ;
2016-03-09 03:20:26 +00:00
if ( slot > = 0 )
2016-06-20 04:22:43 +00:00
pk = SAV . getStoredSlot ( getPKXOffset ( slot ) ) ;
2016-06-21 06:02:26 +00:00
else if ( verifiedPKM ( ) )
2016-06-20 04:22:43 +00:00
pk = preparePKM ( ) ;
2016-03-09 03:20:26 +00:00
else
return ;
if ( pk . Species = = 0 | | ! pk . ChecksumValid )
{ SystemSounds . Asterisk . Play ( ) ; return ; }
2016-06-20 04:22:43 +00:00
if ( typeof ( PK6 ) ! = pk . GetType ( ) )
{
Util . Alert ( $"Checking legality of {pk.GetType()} files is not supported." ) ;
return ;
}
showLegality ( pk as PK6 , slot < 0 , ModifierKeys = = Keys . Control ) ;
2016-03-09 03:20:26 +00:00
}
2016-06-20 04:22:43 +00:00
2015-09-16 06:33:02 +00:00
private void updateEggRNGSeed ( object sender , EventArgs e )
{
2016-04-15 23:11:46 +00:00
if ( TB_RNGSeed . Text . Length = = 0 )
2015-09-16 06:33:02 +00:00
{
2016-04-15 23:11:46 +00:00
// Reset to 0
2016-06-20 04:22:43 +00:00
TB_RNGSeed . Text = 0. ToString ( "X" + SAV . DaycareSeedSize ) ;
2015-09-16 06:33:02 +00:00
return ; // recursively triggers this method, no need to continue
}
2016-04-15 23:11:46 +00:00
string filterText = Util . getOnlyHex ( TB_RNGSeed . Text ) ;
if ( filterText . Length ! = TB_RNGSeed . Text . Length )
2015-09-16 06:33:02 +00:00
{
2016-04-15 23:11:46 +00:00
Util . Alert ( "Expected HEX (0-9, A-F)." , "Received: " + Environment . NewLine + TB_RNGSeed . Text ) ;
// Reset to Stored Value
2016-06-20 04:22:43 +00:00
var seed = SAV . getDaycareRNGSeed ( SAV . DaycareIndex ) ;
if ( seed ! = null )
TB_RNGSeed . Text = ( ( ulong ) seed ) . ToString ( "X" + SAV . DaycareSeedSize ) ;
2015-09-16 06:33:02 +00:00
return ; // recursively triggers this method, no need to continue
}
// Write final value back to the save
2016-04-15 23:11:46 +00:00
ulong value = Convert . ToUInt64 ( filterText , 16 ) ;
2016-06-20 04:22:43 +00:00
if ( value ! = SAV . getDaycareRNGSeed ( SAV . DaycareIndex ) )
2015-10-24 23:33:44 +00:00
{
2016-06-20 04:22:43 +00:00
SAV . setDaycareRNGSeed ( SAV . DaycareIndex , value ) ;
2015-10-24 23:33:44 +00:00
SAV . Edited = true ;
}
2015-09-21 03:34:09 +00:00
}
2016-06-20 04:22:43 +00:00
private void updateU64 ( object sender , EventArgs e )
2015-12-17 03:33:58 +00:00
{
2016-06-20 04:22:43 +00:00
TextBox tb = sender as TextBox ;
if ( tb . Text . Length = = 0 )
2015-12-17 03:33:58 +00:00
{
2016-04-15 23:11:46 +00:00
// Reset to 0
2016-06-20 04:22:43 +00:00
tb . Text = 0. ToString ( "X16" ) ;
2015-12-17 03:33:58 +00:00
return ; // recursively triggers this method, no need to continue
}
2016-06-20 04:22:43 +00:00
// Currently saved Value
ulong oldval = 0 ;
2016-07-19 03:36:52 +00:00
if ( SAV . Generation = = 6 )
{
SAV6 sav6 = ( SAV6 ) SAV ;
if ( tb = = TB_GameSync )
oldval = sav6 . GameSyncID ;
else if ( tb = = TB_Secure1 )
oldval = sav6 . Secure1 ;
else if ( tb = = TB_Secure2 )
oldval = sav6 . Secure2 ;
}
2015-12-28 21:52:08 +00:00
2016-06-20 04:22:43 +00:00
string filterText = Util . getOnlyHex ( tb . Text ) ;
2015-12-28 21:52:08 +00:00
2016-06-20 04:22:43 +00:00
if ( filterText . Length ! = tb . Text . Length )
2015-12-28 21:52:08 +00:00
{
2016-06-20 04:22:43 +00:00
Util . Alert ( "Expected HEX (0-9, A-F)." , "Received: " + Environment . NewLine + tb . Text ) ;
2015-12-28 21:52:08 +00:00
// Reset to Stored Value
2016-06-20 04:22:43 +00:00
tb . Text = oldval . ToString ( "X16" ) ;
2015-12-28 21:52:08 +00:00
return ; // recursively triggers this method, no need to continue
}
// Write final value back to the save
2016-06-20 04:22:43 +00:00
ulong newval = Convert . ToUInt64 ( filterText , 16 ) ;
2016-07-19 03:36:52 +00:00
if ( newval = = oldval ) return ;
if ( SAV . Generation = = 6 )
2016-06-20 04:22:43 +00:00
{
2016-07-19 03:36:52 +00:00
SAV6 sav6 = ( SAV6 ) SAV ;
2016-06-20 04:22:43 +00:00
if ( tb = = TB_GameSync )
2016-07-19 03:36:52 +00:00
sav6 . GameSyncID = newval ;
2016-06-20 04:22:43 +00:00
else if ( tb = = TB_Secure1 )
2016-07-19 03:36:52 +00:00
sav6 . Secure1 = newval ;
2016-06-20 04:22:43 +00:00
else if ( tb = = TB_Secure2 )
2016-07-19 03:36:52 +00:00
sav6 . Secure2 = newval ;
2015-12-28 21:52:08 +00:00
SAV . Edited = true ;
}
}
2015-10-24 03:13:32 +00:00
// Generic Subfunctions //
private void setParty ( )
2014-07-26 21:56:06 +00:00
{
2016-06-20 04:22:43 +00:00
PKM [ ] party = SAV . PartyData ;
PKM [ ] battle = SAV . BattleBoxData ;
2015-02-27 16:18:32 +00:00
// Refresh slots
2016-06-20 04:22:43 +00:00
if ( SAV . HasParty )
2016-07-05 03:04:43 +00:00
{
for ( int i = 0 ; i < party . Length ; i + + )
2016-06-20 04:22:43 +00:00
getQuickFiller ( SlotPictureBoxes [ i + 30 ] , party [ i ] ) ;
2016-07-05 03:04:43 +00:00
for ( int i = party . Length ; i < 6 ; i + + )
SlotPictureBoxes [ i + 30 ] . Image = null ;
}
2016-06-20 04:22:43 +00:00
if ( SAV . HasBattleBox )
2016-07-05 03:04:43 +00:00
{
for ( int i = 0 ; i < battle . Length ; i + + )
2016-06-20 04:22:43 +00:00
getQuickFiller ( SlotPictureBoxes [ i + 36 ] , battle [ i ] ) ;
2016-07-05 03:04:43 +00:00
for ( int i = battle . Length ; i < 6 ; i + + )
SlotPictureBoxes [ i + 30 ] . Image = null ;
}
2014-06-28 21:22:05 +00:00
}
private int getPKXOffset ( int slot )
{
2016-04-26 05:03:16 +00:00
if ( slot < 30 ) // Box Slot
2016-06-20 04:22:43 +00:00
return SAV . getBoxOffset ( CB_BoxSelect . SelectedIndex ) + slot * SAV . SIZE_STORED ;
slot - = 30 ;
if ( slot < 6 ) // Party Slot
return SAV . getPartyOffset ( slot ) ;
slot - = 6 ;
if ( slot < 6 ) // Battle Box Slot
return SAV . BattleBox + slot * SAV . SIZE_STORED ;
slot - = 6 ;
if ( slot < 2 ) // Daycare
return SAV . getDaycareSlotOffset ( SAV . DaycareIndex , slot ) ;
slot - = 2 ;
if ( slot = = 0 ) // GTS
2016-01-31 07:03:43 +00:00
return SAV . GTS ;
2016-06-20 04:22:43 +00:00
slot - = 1 ;
if ( slot = = 0 ) // Fused
2016-01-31 07:03:43 +00:00
return SAV . Fused ;
2016-06-20 04:22:43 +00:00
slot - = 1 ;
if ( slot < 3 ) // SUBE
return SAV . SUBE + slot * ( SAV . SIZE_STORED + 4 ) ;
2016-01-31 07:03:43 +00:00
return - 1 ;
2014-06-28 21:22:05 +00:00
}
private int getSlot ( object sender )
{
2016-02-01 07:15:54 +00:00
sender = ( ( sender as ToolStripItem ) ? . Owner as ContextMenuStrip ) ? . SourceControl ? ? sender as PictureBox ;
2016-01-31 07:03:43 +00:00
return Array . IndexOf ( SlotPictureBoxes , sender ) ;
2014-06-28 21:22:05 +00:00
}
2015-11-15 02:17:54 +00:00
public void setPKXBoxes ( )
2014-06-28 21:22:05 +00:00
{
2016-06-20 04:22:43 +00:00
if ( SAV . HasBox )
2015-12-30 06:03:27 +00:00
{
2016-06-20 04:22:43 +00:00
int boxoffset = SAV . getBoxOffset ( CB_BoxSelect . SelectedIndex ) ;
2016-07-25 04:11:11 +00:00
int boxbgval = SAV . getBoxWallpaper ( CB_BoxSelect . SelectedIndex ) ;
PAN_Box . BackgroundImage = BoxWallpaper . getWallpaper ( SAV , boxbgval ) ;
2014-12-20 19:27:29 +00:00
2015-12-30 06:03:27 +00:00
for ( int i = 0 ; i < 30 ; i + + )
2016-06-20 04:22:43 +00:00
getSlotFiller ( boxoffset + SAV . SIZE_STORED * i , SlotPictureBoxes [ i ] ) ;
2015-12-30 06:03:27 +00:00
}
2014-06-28 21:22:05 +00:00
// Reload Party
2016-06-20 04:22:43 +00:00
if ( SAV . HasParty )
{
for ( int i = 0 ; i < 6 ; i + + )
getSlotFiller ( SAV . getPartyOffset ( i ) , SlotPictureBoxes [ i + 30 ] ) ;
}
2014-12-06 02:14:04 +00:00
2014-06-28 21:22:05 +00:00
// Reload Battle Box
2016-06-20 04:22:43 +00:00
if ( SAV . HasBattleBox )
{
for ( int i = 0 ; i < 6 ; i + + )
getSlotFiller ( SAV . BattleBox + SAV . SIZE_STORED * i , SlotPictureBoxes [ i + 36 ] ) ;
}
2014-12-06 02:14:04 +00:00
2014-06-28 21:22:05 +00:00
// Reload Daycare
2016-06-20 04:22:43 +00:00
if ( SAV . HasDaycare )
2014-06-28 21:22:05 +00:00
{
2016-06-20 04:22:43 +00:00
Label [ ] L_SlotOccupied = { L_DC1 , L_DC2 } ;
TextBox [ ] TB_SlotEXP = { TB_Daycare1XP , TB_Daycare2XP } ;
Label [ ] L_SlotEXP = { L_XP1 , L_XP2 } ;
2015-12-30 06:03:27 +00:00
for ( int i = 0 ; i < 2 ; i + + )
2014-06-28 21:22:05 +00:00
{
2016-06-20 04:22:43 +00:00
getSlotFiller ( SAV . getDaycareSlotOffset ( SAV . DaycareIndex , i ) , SlotPictureBoxes [ i + 42 ] ) ;
uint? exp = SAV . getDaycareEXP ( SAV . DaycareIndex , i ) ;
TB_SlotEXP [ i ] . Visible = L_SlotEXP [ i ] . Visible = exp ! = null ;
TB_SlotEXP [ i ] . Text = exp . ToString ( ) ;
bool? occ = SAV . getDaycareOccupied ( SAV . DaycareIndex , i ) ;
L_SlotOccupied [ i ] . Visible = occ ! = null ;
if ( occ = = true ) // If Occupied
L_SlotOccupied [ i ] . Text = $"{i + 1}: ✓" ;
2015-12-30 06:03:27 +00:00
else
{
2016-06-20 04:22:43 +00:00
L_SlotOccupied [ i ] . Text = $"{i + 1}: ✘" ;
2015-12-30 06:03:27 +00:00
SlotPictureBoxes [ i + 42 ] . Image = Util . ChangeOpacity ( SlotPictureBoxes [ i + 42 ] . Image , 0.6 ) ;
}
2014-06-28 21:22:05 +00:00
}
2016-06-20 04:22:43 +00:00
bool? egg = SAV . getDaycareHasEgg ( SAV . DaycareIndex ) ;
DayCare_HasEgg . Visible = egg ! = null ;
DayCare_HasEgg . Checked = egg = = true ;
ulong? seed = SAV . getDaycareRNGSeed ( SAV . DaycareIndex ) ;
L_DaycareSeed . Visible = TB_RNGSeed . Visible = seed ! = null ;
if ( seed ! = null )
{
TB_RNGSeed . MaxLength = SAV . DaycareSeedSize ;
TB_RNGSeed . Text = ( ( ulong ) seed ) . ToString ( "X" + SAV . DaycareSeedSize ) ;
}
2014-06-28 21:22:05 +00:00
}
// GTS
2016-06-20 04:22:43 +00:00
if ( SAV . HasGTS )
2015-10-24 03:13:32 +00:00
getSlotFiller ( SAV . GTS , SlotPictureBoxes [ 44 ] ) ;
2014-06-28 21:22:05 +00:00
// Fused
2016-06-20 04:22:43 +00:00
if ( SAV . HasFused )
2015-10-24 03:13:32 +00:00
getSlotFiller ( SAV . Fused , SlotPictureBoxes [ 45 ] ) ;
2014-06-28 21:22:05 +00:00
// SUBE
2016-06-20 04:22:43 +00:00
if ( SAV . HasSUBE )
2014-06-28 21:22:05 +00:00
for ( int i = 0 ; i < 3 ; i + + )
{
2016-06-20 04:22:43 +00:00
int offset = SAV . SUBE + i * ( SAV . SIZE_STORED + 4 ) ;
2015-10-24 03:13:32 +00:00
if ( BitConverter . ToUInt64 ( SAV . Data , offset ) ! = 0 )
2015-09-21 03:34:09 +00:00
getSlotFiller ( offset , SlotPictureBoxes [ 46 + i ] ) ;
else SlotPictureBoxes [ 46 + i ] . Image = null ;
2014-06-28 21:22:05 +00:00
}
// Recoloring of a storage box slot (to not show for other storage boxes)
2016-06-20 04:22:43 +00:00
if ( colorizedslot < = SAV . BoxCount )
2016-01-05 06:42:38 +00:00
SlotPictureBoxes [ 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
{
2016-06-20 04:22:43 +00:00
if ( ! SAV . HasBox )
2015-12-30 06:03:27 +00:00
return ;
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 ( ) ;
2016-06-20 04:22:43 +00:00
for ( int i = 0 ; i < SAV . BoxCount ; i + + )
2015-10-24 23:33:44 +00:00
CB_BoxSelect . Items . Add ( SAV . getBoxName ( i ) ) ;
2014-06-28 21:22:05 +00:00
}
catch
{
2015-05-07 02:30:31 +00:00
CB_BoxSelect . Items . Clear ( ) ;
2016-06-20 04:22:43 +00:00
for ( int i = 0 ; i < SAV . BoxCount ; i + + )
2015-12-18 02:59:54 +00:00
CB_BoxSelect . Items . Add ( "BOX " + ( i + 1 ) ) ;
2014-06-28 21:22:05 +00:00
}
2016-06-20 04:22:43 +00:00
if ( selectedbox < CB_BoxSelect . Items . Count )
CB_BoxSelect . SelectedIndex = selectedbox ; // restore selected box
2014-06-28 21:22:05 +00:00
}
2016-06-20 04:22:43 +00:00
private void getQuickFiller ( PictureBox pb , PKM pk = null )
2014-12-14 20:15:53 +00:00
{
2015-11-06 06:59:55 +00:00
if ( ! fieldsInitialized ) return ;
2016-06-20 04:22:43 +00:00
pk = pk ? ? preparePKM ( false ) ; // don't perform control loss click
2014-12-14 20:15:53 +00:00
2016-03-12 02:40:08 +00:00
if ( pb = = dragout ) mnuLQR . Enabled = pk . Species ! = 0 ; // Species
2016-01-24 18:19:30 +00:00
pb . Image = pk . Sprite ;
2016-03-24 04:35:36 +00:00
if ( pb . BackColor = = Color . Red )
pb . BackColor = Color . Transparent ;
2014-12-14 20:15:53 +00:00
}
2014-06-28 21:22:05 +00:00
private void getSlotFiller ( int offset , PictureBox pb )
{
2016-06-20 04:22:43 +00:00
if ( SAV . getData ( offset , SAV . SIZE_STORED ) . SequenceEqual ( new byte [ SAV . SIZE_STORED ] ) )
2015-10-15 01:33:51 +00:00
{
2015-12-02 07:08:16 +00:00
// 00s present in slot.
2015-10-15 01:33:51 +00:00
pb . Image = null ;
pb . BackColor = Color . Transparent ;
return ;
}
2016-06-20 04:22:43 +00:00
PKM p = SAV . getStoredSlot ( offset ) ;
2016-01-24 18:19:30 +00:00
if ( p . Sanity ! = 0 | | ! p . ChecksumValid ) // Invalid
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-12-02 07:08:16 +00:00
// Something stored in slot. Only display if species is valid.
2015-10-15 03:10:09 +00:00
pb . Image = p . Species = = 0 ? null : p . Sprite ;
2015-12-02 07:08:16 +00:00
pb . BackColor = Color . Transparent ;
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
{
2015-10-25 01:16:22 +00:00
foreach ( PictureBox t in SlotPictureBoxes )
2015-03-11 01:44:51 +00:00
t . BackgroundImage = null ;
2014-08-17 01:42:51 +00:00
2016-01-31 07:03:43 +00:00
if ( slot < 30 )
2015-05-07 02:30:31 +00:00
colorizedbox = CB_BoxSelect . SelectedIndex ;
2014-08-17 01:42:51 +00:00
2015-10-25 01:16:22 +00:00
SlotPictureBoxes [ 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
}
2014-12-28 21:56:59 +00:00
private void switchDaycare ( object sender , EventArgs e )
{
2015-10-24 03:13:32 +00:00
if ( ! SAV . ORAS ) return ;
2016-01-17 21:27:24 +00:00
if ( DialogResult . Yes = = Util . Prompt ( MessageBoxButtons . YesNo , "Would you like to switch the view to the other Daycare?" ,
2016-03-29 09:58:14 +00:00
$"Currently viewing daycare {SAV.DaycareIndex + 1}." ) )
2015-01-01 19:38:37 +00:00
// If ORAS, alter the daycare offset via toggle.
2016-03-29 09:58:14 +00:00
SAV . DaycareIndex ^ = 1 ;
2014-12-28 21:56:59 +00:00
// Refresh Boxes
setPKXBoxes ( ) ;
}
2015-10-13 00:06:30 +00:00
private void dumpBoxesToDB ( string path , bool individualBoxFolders )
{
2016-06-20 04:22:43 +00:00
PKM [ ] boxdata = SAV . BoxData ;
if ( boxdata = = null ) { Util . Error ( "Null argument when dumping boxes." ) ; return ; }
2015-11-20 06:44:16 +00:00
for ( int i = 0 ; i < boxdata . Length ; i + + )
2015-10-13 00:06:30 +00:00
{
2016-06-20 04:22:43 +00:00
PKM pk = boxdata [ i ] ;
2015-11-14 02:29:59 +00:00
if ( pk . Species = = 0 | | pk . Sanity ! = 0 )
continue ;
2015-10-13 00:06:30 +00:00
string fileName = Util . CleanFileName ( pk . FileName ) ;
string boxfolder = "" ;
if ( individualBoxFolders )
{
2016-04-26 05:03:16 +00:00
boxfolder = SAV . getBoxName ( i / 30 ) ;
2015-10-13 00:06:30 +00:00
Directory . CreateDirectory ( Path . Combine ( path , boxfolder ) ) ;
2014-06-28 21:22:05 +00:00
}
2015-10-13 00:06:30 +00:00
if ( ! File . Exists ( Path . Combine ( Path . Combine ( path , boxfolder ) , fileName ) ) )
2016-06-20 04:22:43 +00:00
File . WriteAllBytes ( Path . Combine ( Path . Combine ( path , boxfolder ) , fileName ) , pk . Data . Take ( SAV . SIZE_STORED ) . ToArray ( ) ) ;
2014-06-28 21:22:05 +00:00
}
}
private void loadBoxesFromDB ( string path )
{
2016-02-03 04:05:46 +00:00
if ( string . IsNullOrWhiteSpace ( path ) ) return ;
2016-06-20 04:22:43 +00:00
if ( ! SAV . HasBox ) return ;
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." ) ;
2016-06-20 04:22:43 +00:00
if ( dr = = DialogResult . Cancel )
return ;
2015-03-11 01:44:51 +00:00
if ( dr = = DialogResult . Yes )
2016-06-20 04:22:43 +00:00
SAV . resetBoxes ( CB_BoxSelect . SelectedIndex ) ;
2016-05-06 01:52:43 +00:00
2016-06-20 04:22:43 +00:00
bool? noSetb = getPKMSetOverride ( ) ;
int ctr = CB_BoxSelect . SelectedIndex * 30 ;
int pastctr = 0 ;
2014-08-15 04:27:53 +00:00
string [ ] filepaths = Directory . GetFiles ( path , "*.*" , SearchOption . TopDirectoryOnly ) ;
2014-08-17 01:42:51 +00:00
2016-06-20 04:22:43 +00:00
foreach ( byte [ ] data in from file in filepaths where PKX . getIsPKM ( new FileInfo ( file ) . Length ) select File . ReadAllBytes ( file ) )
2014-06-28 21:22:05 +00:00
{
2016-06-20 04:22:43 +00:00
string c ;
PKM temp = PKMConverter . getPKMfromBytes ( data ) ;
PKM pk = PKMConverter . convertToFormat ( temp , SAV . Generation , out c ) ;
2015-10-25 01:16:22 +00:00
2016-06-20 04:22:43 +00:00
if ( pk ! = null ) // Write to save
2014-08-15 04:27:53 +00:00
{
2016-06-21 06:02:26 +00:00
if ( verifyPKMtoSAV ( pk ) . Length > 0 )
continue ;
2016-06-20 04:22:43 +00:00
SAV . setStoredSlot ( pk , SAV . getBoxOffset ( ctr / 30 ) + ctr % 30 * SAV . SIZE_STORED , noSetb ) ;
if ( pk . Format ! = temp . Format ) // Transferred
pastctr + + ;
if ( + + ctr = = SAV . BoxCount * 30 ) // Boxes full!
break ;
2014-06-28 21:22:05 +00:00
}
2016-06-20 04:22:43 +00:00
Console . WriteLine ( c ) ;
2014-06-28 21:22:05 +00:00
}
2016-02-12 08:01:15 +00:00
ctr - = 30 * CB_BoxSelect . SelectedIndex ; // actual imported count
2016-06-20 04:22:43 +00:00
if ( ctr < = 0 )
return ;
2016-01-03 04:22:53 +00:00
2015-03-11 01:44:51 +00:00
setPKXBoxes ( ) ;
2016-01-17 21:27:24 +00:00
string result = $"Loaded {ctr} files to boxes." ;
2015-03-11 01:44:51 +00:00
if ( pastctr > 0 )
2016-01-17 21:27:24 +00:00
Util . Alert ( result , $"Conversion successful for {pastctr} past generation files." ) ;
2015-03-11 01:44:51 +00:00
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
{
2016-06-20 04:22:43 +00:00
if ( ! SAV . HasBox )
{ Util . Alert ( "Save file does not have boxes to dump!" ) ; return ; }
DialogResult dr = Util . Prompt ( MessageBoxButtons . YesNoCancel ,
"Yes: Export All Boxes" + Environment . NewLine +
$"No: Export {CB_BoxSelect.Text} (Box {CB_BoxSelect.SelectedIndex + 1})" + 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" } ;
2016-06-20 04:22:43 +00:00
if ( sfd . ShowDialog ( ) ! = DialogResult . OK )
return ;
File . WriteAllBytes ( sfd . FileName , SAV . getPCBin ( ) ) ;
2015-01-25 19:24:00 +00:00
}
2015-02-01 04:40:35 +00:00
else if ( dr = = DialogResult . No )
2015-01-24 19:16:20 +00:00
{
2016-06-20 04:22:43 +00:00
SaveFileDialog sfd = new SaveFileDialog { Filter = "Box Data|*.bin" , FileName = $"boxdata {CB_BoxSelect.Text}.bin" } ;
if ( sfd . ShowDialog ( ) ! = DialogResult . OK )
return ;
File . WriteAllBytes ( sfd . FileName , SAV . getBoxBin ( CB_BoxSelect . SelectedIndex ) ) ;
2015-01-24 19:16:20 +00:00
}
}
2016-06-20 04:22:43 +00:00
private bool? getPKMSetOverride ( )
2016-05-06 01:52:43 +00:00
{
2016-07-10 17:32:51 +00:00
var yn = Menu_ModifyPKM . Checked ? "Yes" : "No" ;
2016-06-20 04:22:43 +00:00
DialogResult noSet = Util . Prompt ( MessageBoxButtons . YesNoCancel ,
"Loading overrides:" ,
"Yes - Modify .pk* when set to SAV" + Environment . NewLine +
"No - Don't modify .pk*" + Environment . NewLine +
$"Cancel - Use current settings ({yn})" ) ;
2016-05-06 01:52:43 +00:00
return noSet = = DialogResult . Yes ? true : ( noSet = = DialogResult . No ? ( bool? ) false : null ) ;
}
2015-10-24 03:13:32 +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 )
{
2016-06-20 04:22:43 +00:00
new SAV_Wondercard ( sender as MysteryGift ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenBoxLayout_Click ( object sender , EventArgs e )
{
2015-09-21 03:34:09 +00:00
new SAV_BoxLayout ( CB_BoxSelect . SelectedIndex ) . ShowDialog ( ) ;
2014-12-06 02:14:04 +00:00
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 )
{
2016-06-22 00:35:12 +00:00
if ( SAV . Generation < 6 )
new SAV_SimpleTrainer ( ) . ShowDialog ( ) ;
else if ( SAV . Generation = = 6 )
new SAV_Trainer ( ) . ShowDialog ( ) ;
2016-06-20 04:22:43 +00:00
// Refresh conversion info
PKMConverter . updateConfig ( SAV . SubRegion , SAV . Country , SAV . ConsoleRegion , SAV . OT , SAV . Gender ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenPokepuffs_Click ( object sender , EventArgs e )
{
2015-09-21 03:34:09 +00:00
new SAV_Pokepuff ( ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenItemPouch_Click ( object sender , EventArgs e )
{
2015-09-21 03:34:09 +00:00
new SAV_Inventory ( ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenBerryField_Click ( object sender , EventArgs e )
{
2016-06-20 04:22:43 +00:00
new SAV_BerryFieldXY ( ) . ShowDialog ( ) ;
}
private void B_OpenPokeblocks_Click ( object sender , EventArgs e )
{
new SAV_PokeBlockORAS ( ) . ShowDialog ( ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OpenEventFlags_Click ( object sender , EventArgs e )
{
2016-06-20 04:22:43 +00:00
new SAV_EventFlags ( ) . 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 )
{
2016-01-24 18:19:30 +00:00
new SAV_SuperTrain ( ) . 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 )
{
2016-06-20 04:22:43 +00:00
if ( SAV . Generation ! = 6 )
return ;
2015-10-24 03:13:32 +00:00
if ( SAV . ORAS )
2014-11-25 03:53:10 +00:00
{
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 ;
2016-02-03 04:05:46 +00:00
new byte [ ]
2015-03-11 01:44:51 +00:00
{
2016-02-03 04:05:46 +00:00
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 ,
2016-06-20 04:22:43 +00:00
0x01 , 0x00 , 0x00 , 0x00 ,
2016-07-18 18:51:26 +00:00
} . CopyTo ( SAV . Data , ( ( SAV6 ) SAV ) . OPower ) ;
2014-11-25 03:53:10 +00:00
}
2016-04-26 05:03:16 +00:00
else if ( SAV . XY )
2015-09-21 03:34:09 +00:00
new SAV_OPower ( ) . 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 )
{
2015-10-24 03:13:32 +00:00
if ( SAV . ORAS )
2015-09-21 03:34:09 +00:00
new SAV_PokedexORAS ( ) . ShowDialog ( ) ;
2016-04-26 05:03:16 +00:00
else if ( SAV . XY )
2015-09-21 03:34:09 +00:00
new SAV_PokedexXY ( ) . 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 )
{
2016-06-20 04:22:43 +00:00
if ( SAV . Generation ! = 6 )
return ;
2016-02-09 23:35:56 +00:00
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , "Export Passerby Info to Clipboard?" ) )
2015-12-18 02:55:59 +00:00
return ;
string result = "PSS List" + Environment . NewLine ;
string [ ] headers = { "PSS Data - Friends" , "PSS Data - Acquaintances" , "PSS Data - Passerby" , } ;
2016-07-18 18:51:26 +00:00
int offset = ( ( SAV6 ) SAV ) . PSS ;
2014-06-28 21:22:05 +00:00
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 + + )
{
2015-10-24 03:13:32 +00:00
ulong unkn = BitConverter . ToUInt64 ( SAV . Data , 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
2015-10-24 03:13:32 +00:00
string otname = Util . TrimFromZero ( Encoding . Unicode . GetString ( SAV . Data , r_offset + 8 , 0x1A ) ) ;
string message = Util . TrimFromZero ( Encoding . Unicode . GetString ( SAV . Data , 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);
2015-10-24 03:13:32 +00:00
byte region = SAV . Data [ r_offset + 0x56 ] ;
byte country = SAV . Data [ r_offset + 0x57 ] ;
byte game = SAV . Data [ r_offset + 0x5A ] ;
2015-03-11 01:44:51 +00:00
// ulong outfit = BitConverter.ToUInt64(savefile, r_offset + 0x5C);
2015-10-24 03:13:32 +00:00
int favpkm = BitConverter . ToUInt16 ( SAV . Data , 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
}
2015-12-18 02:55:59 +00:00
Clipboard . SetText ( result ) ;
2014-06-28 21:22:05 +00:00
}
private void B_OUTHallofFame_Click ( object sender , EventArgs e )
{
2015-09-21 03:34:09 +00:00
new SAV_HallOfFame ( ) . 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 )
{
2015-09-21 03:34:09 +00:00
new SAV_SecretBase ( ) . ShowDialog ( ) ;
2014-11-23 22:23:40 +00:00
}
2016-07-27 03:18:48 +00:00
private void B_LinkInfo_Click ( object sender , EventArgs e )
{
new SAV_Link6 ( ) . ShowDialog ( ) ;
}
2014-12-14 19:06:17 +00:00
private void B_JPEG_Click ( object sender , EventArgs e )
{
2016-03-05 06:09:54 +00:00
byte [ ] jpeg = SAV . JPEGData ;
if ( SAV . JPEGData = = null )
{ Util . Alert ( "No PGL picture data found in the save file!" ) ; return ; }
string filename = SAV . JPEGTitle + "'s picture" ;
SaveFileDialog sfd = new SaveFileDialog { FileName = filename , Filter = "JPEG|*.jpeg" } ;
if ( sfd . ShowDialog ( ) ! = DialogResult . OK ) return ;
File . WriteAllBytes ( sfd . FileName , 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
{
2016-06-20 04:22:43 +00:00
string path = detectSaveFile ( ) ;
if ( path = = null | | ! File . Exists ( path ) ) return ;
if ( Util . Prompt ( MessageBoxButtons . YesNo , "Open save file from the following location?" , path ) = = DialogResult . Yes )
openQuick ( path ) ; // load save
}
private static string detectSaveFile ( )
{
string pathSDF = Util . GetSDFLocation ( ) ;
string path3DS = Util . get3DSLocation ( ) ;
2016-04-06 03:37:36 +00:00
string pathCache = Util . GetCacheFolder ( ) ;
2016-03-25 07:10:57 +00:00
2015-10-03 00:41:55 +00:00
if ( path3DS ! = null & & Directory . Exists ( Path . Combine ( path3DS , "SaveDataBackup" ) ) & & ModifierKeys ! = Keys . Control )
2016-06-20 04:22:43 +00:00
return Path . Combine ( Path . GetPathRoot ( path3DS ) , "SaveDataBackup" , "main" ) ;
if ( pathSDF ! = null & & ModifierKeys ! = Keys . Shift ) // if we have a result
return Path . Combine ( pathSDF , "main" ) ;
if ( path3DS ! = null & & Directory . Exists ( Path . Combine ( Path . GetPathRoot ( path3DS ) , "JKSV" , "Saves" ) ) )
return Directory . GetFiles ( Path . Combine ( Path . GetPathRoot ( path3DS ) , "JKSV" , "Saves" ) , "main" , SearchOption . AllDirectories )
. Where ( f = > SaveUtil . SizeValidSAV6 ( ( int ) new FileInfo ( f ) . Length ) ) // filter
. OrderByDescending ( f = > new FileInfo ( f ) . LastWriteTime ) . FirstOrDefault ( ) ;
if ( Directory . Exists ( pathCache ) )
return Directory . GetFiles ( pathCache ) . Where ( f = > SaveUtil . SizeValidSAV6 ( ( int ) new FileInfo ( f ) . Length ) ) // filter
2016-04-09 05:14:16 +00:00
. OrderByDescending ( f = > new FileInfo ( f ) . LastWriteTime ) . FirstOrDefault ( ) ;
2016-07-30 18:25:45 +00:00
try
{
if ( File . Exists ( Util . NormalizePath ( Path . Combine ( Util . GetTempFolder ( ) , "root" , "main" ) ) ) ) // if cgse exists
return Util . NormalizePath ( Path . Combine ( Util . GetTempFolder ( ) , "root" , "main" ) ) ;
} catch { }
2014-12-13 22:48:34 +00:00
2016-06-20 04:22:43 +00:00
return null ;
2014-12-13 22:48:34 +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 )
{
2015-12-26 18:26:42 +00:00
if ( e . Button ! = MouseButtons . Left | | e . Clicks ! = 1 ) return ;
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 ; }
2016-01-18 01:07:19 +00:00
PictureBox pb = ( PictureBox ) sender ;
2014-11-26 04:43:02 +00:00
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
// Create Temp File to Drag
Cursor . Current = Cursors . Hand ;
// Prepare Data
2016-06-20 04:22:43 +00:00
pkm_from = SAV . getData ( offset , SAV . SIZE_STORED ) ;
2015-03-11 01:44:51 +00:00
pkm_from_offset = offset ;
// Make a new file name based off the PID
2016-06-20 04:22:43 +00:00
byte [ ] dragdata = SAV . decryptPKM ( pkm_from ) ;
Array . Resize ( ref dragdata , SAV . SIZE_STORED ) ;
PKM pkx = SAV . getPKM ( dragdata ) ;
2015-11-22 18:51:09 +00:00
string filename = pkx . FileName ;
2015-03-11 01:44:51 +00:00
// Make File
2015-11-14 22:19:40 +00:00
string newfile = Path . Combine ( Path . GetTempPath ( ) , Util . CleanFileName ( filename ) ) ;
2015-03-11 01:44:51 +00:00
try
2014-11-26 04:43:02 +00:00
{
2015-03-11 01:44:51 +00:00
File . WriteAllBytes ( newfile , dragdata ) ;
2015-11-14 22:19:40 +00:00
DoDragDrop ( new DataObject ( DataFormats . FileDrop , new [ ] { newfile } ) , DragDropEffects . Move ) ;
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 ( ) ) ; }
pkm_from_offset = 0 ;
2016-07-10 17:35:44 +00:00
// Browser apps need time to load data since the file isn't moved to a location on the user's local storage.
// Tested 10ms -> too quick, 100ms was fine. 500ms should be safe?
new Thread ( ( ) = >
{
Thread . Sleep ( 500 ) ;
2016-07-26 05:40:05 +00:00
if ( File . Exists ( newfile ) )
File . Delete ( newfile ) ;
2016-07-10 17:35:44 +00:00
} ) . Start ( ) ;
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
{
2016-06-21 06:02:26 +00:00
if ( files . Length < = 0 )
return ;
string file = files [ 0 ] ;
if ( ! PKX . getIsPKM ( new FileInfo ( file ) . Length ) )
2016-06-30 00:36:03 +00:00
{ openQuick ( file ) ; return ; }
2016-06-21 06:02:26 +00:00
byte [ ] data = File . ReadAllBytes ( file ) ;
PKM temp = PKMConverter . getPKMfromBytes ( data ) ;
string c ;
2016-06-20 04:22:43 +00:00
2016-06-21 06:02:26 +00:00
PKM pk = PKMConverter . convertToFormat ( temp , SAV . Generation , out c ) ;
if ( pk = = null )
{ Util . Error ( c ) ; Console . WriteLine ( c ) ; return ; }
string [ ] errata = verifyPKMtoSAV ( pk ) ;
if ( errata . Length > 0 )
{
string concat = string . Join ( Environment . NewLine , errata ) ;
if ( DialogResult . Yes ! = Util . Prompt ( MessageBoxButtons . YesNo , concat , "Continue?" ) )
{ Console . WriteLine ( c ) ; Console . WriteLine ( concat ) ; return ; }
2014-11-30 18:59:10 +00:00
}
2016-06-21 06:02:26 +00:00
SAV . setStoredSlot ( pk , offset ) ;
getQuickFiller ( SlotPictureBoxes [ slot ] , pk ) ;
getSlotColor ( slot , Properties . Resources . slotSet ) ;
Console . WriteLine ( c ) ;
2014-11-30 18:59:10 +00:00
}
else
{
2016-07-31 03:47:28 +00:00
PKM pkz = SAV . getStoredSlot ( pkm_from_offset ) ;
2014-12-20 19:27:29 +00:00
if ( ModifierKeys = = Keys . Alt & & slot > - 1 ) // overwrite delete old slot
{
2016-06-20 04:22:43 +00:00
// Clear from slot
getQuickFiller ( SlotPictureBoxes [ pkm_from_slot ] , SAV . BlankPKM ) ; // picturebox
SAV . setStoredSlot ( SAV . BlankPKM , pkm_from_offset ) ; // savefile
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
2016-06-20 04:22:43 +00:00
PKM pk = SAV . getStoredSlot ( offset ) ;
2014-12-20 19:27:29 +00:00
// Swap slot picture
2016-01-24 18:19:30 +00:00
getQuickFiller ( SlotPictureBoxes [ pkm_from_slot ] , pk ) ;
2014-12-20 19:27:29 +00:00
2014-12-20 22:44:17 +00:00
// Swap slot data to source
2016-06-20 04:22:43 +00:00
SAV . setStoredSlot ( pk , pkm_from_offset ) ;
2014-12-20 19:27:29 +00:00
}
2014-12-20 22:44:17 +00:00
// Copy from temp slot to new.
2016-07-31 03:47:28 +00:00
SAV . setStoredSlot ( pkz , offset ) ;
2016-06-20 04:22:43 +00:00
getQuickFiller ( SlotPictureBoxes [ slot ] , pkz ) ;
2014-12-20 22:44:17 +00:00
2014-11-30 18:59:10 +00:00
pkm_from_offset = 0 ; // Clear offset value
}
2014-11-26 04:43:02 +00:00
}
private void pbBoxSlot_DragEnter ( object sender , DragEventArgs e )
{
2015-11-22 19:03:38 +00:00
if ( e . AllowedEffect = = ( DragDropEffects . Copy | DragDropEffects . Link ) ) // external file
e . Effect = DragDropEffects . Copy ;
else if ( e . Data ! = null ) // within
2014-11-26 04:43:02 +00:00
e . Effect = DragDropEffects . Move ;
}
2016-06-20 04:22:43 +00:00
private byte [ ] pkm_from ;
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
}