2017-01-08 07:54:09 +00:00
|
|
|
|
using System;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
using System.Configuration;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
using System.Diagnostics;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
using System.Drawing;
|
2016-08-31 04:12:47 +00:00
|
|
|
|
using System.Globalization;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
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.Threading;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2015-02-13 04:26:23 +00:00
|
|
|
|
using System.Windows.Forms;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using PKHeX.Core;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
using PKHeX.WinForms.Controls;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
using PKHeX.WinForms.Properties;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
new Task(() => new SplashScreen().ShowDialog()).Start();
|
2017-06-18 20:02:02 +00:00
|
|
|
|
new Task(RefreshMGDB).Start();
|
2014-06-28 21:22:05 +00:00
|
|
|
|
InitializeComponent();
|
2016-08-31 04:12:47 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
FormLoadCheckForUpdates();
|
|
|
|
|
FormLoadAddEvents();
|
|
|
|
|
|
|
|
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
|
|
|
FormLoadInitialSettings(args, out bool showChangelog, out bool BAKprompt);
|
|
|
|
|
FormLoadInitialFiles(args);
|
|
|
|
|
|
|
|
|
|
IsInitialized = true; // Splash Screen closes on its own.
|
2017-06-19 05:27:40 +00:00
|
|
|
|
PKME_Tabs_UpdatePreviewSprite(null, null);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
BringToFront();
|
|
|
|
|
WindowState = FormWindowState.Minimized;
|
|
|
|
|
Show();
|
|
|
|
|
WindowState = FormWindowState.Normal;
|
|
|
|
|
if (HaX)
|
|
|
|
|
WinFormsUtil.Alert("Illegal mode activated.", "Please behave.");
|
|
|
|
|
else if (showChangelog)
|
|
|
|
|
new About().ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (BAKprompt && !Directory.Exists(BackupPath))
|
|
|
|
|
PromptBackup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Important Variables
|
|
|
|
|
public static string CurrentLanguage
|
|
|
|
|
{
|
|
|
|
|
get => GameInfo.CurrentLanguage;
|
|
|
|
|
private set => GameInfo.CurrentLanguage = value;
|
|
|
|
|
}
|
2017-06-19 05:27:40 +00:00
|
|
|
|
private static bool _unicode { get; set; }
|
2017-06-18 20:02:02 +00:00
|
|
|
|
public static bool Unicode
|
|
|
|
|
{
|
|
|
|
|
get => _unicode;
|
|
|
|
|
private set
|
2016-08-31 04:12:47 +00:00
|
|
|
|
{
|
2017-06-18 20:02:02 +00:00
|
|
|
|
_unicode = value;
|
|
|
|
|
GenderSymbols = value ? new[] {"♂", "♀", "-"} : new[] {"M", "F", "-"};
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-31 04:12:47 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
public static string[] GenderSymbols { get; private set; } = { "♂", "♀", "-" };
|
|
|
|
|
public static bool HaX { get; private set; }
|
|
|
|
|
public static bool IsInitialized { get; private set; }
|
|
|
|
|
private readonly string[] main_langlist =
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{
|
|
|
|
|
"日本語", // JPN
|
|
|
|
|
"English", // ENG
|
|
|
|
|
"Français", // FRE
|
|
|
|
|
"Italiano", // ITA
|
|
|
|
|
"Deutsch", // GER
|
|
|
|
|
"Español", // SPA
|
|
|
|
|
"한국어", // KOR
|
|
|
|
|
"中文", // CHN
|
|
|
|
|
"Português", // Portuguese
|
|
|
|
|
};
|
|
|
|
|
#endregion
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
#region Path Variables
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
public static string WorkingDirectory => WinFormsUtil.IsClickonceDeployed ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PKHeX") : Application.StartupPath;
|
|
|
|
|
public static string DatabasePath => Path.Combine(WorkingDirectory, "pkmdb");
|
|
|
|
|
public static string MGDatabasePath => Path.Combine(WorkingDirectory, "mgdb");
|
|
|
|
|
public static string BackupPath => Path.Combine(WorkingDirectory, "bak");
|
|
|
|
|
private static string TemplatePath => Path.Combine(WorkingDirectory, "template");
|
|
|
|
|
private const string ThreadPath = @"https://projectpokemon.org/PKHeX/";
|
|
|
|
|
private const string VersionPath = @"https://raw.githubusercontent.com/kwsch/PKHeX/master/PKHeX.WinForms/Resources/text/version.txt";
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region //// MAIN MENU FUNCTIONS ////
|
|
|
|
|
private void FormLoadInitialSettings(string[] args, out bool showChangelog, out bool BAKprompt)
|
|
|
|
|
{
|
|
|
|
|
showChangelog = false;
|
|
|
|
|
BAKprompt = false;
|
2017-05-23 04:55:05 +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);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
C_SAV.HaX = PKME_Tabs.HaX = HaX = args.Any(x => string.Equals(x.Trim('-'), nameof(HaX), StringComparison.CurrentCultureIgnoreCase));
|
2017-06-18 20:02:02 +00:00
|
|
|
|
PB_Legal.Visible = !HaX;
|
|
|
|
|
|
|
|
|
|
int languageID = 1; // English
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ConfigUtil.CheckConfig();
|
|
|
|
|
FormLoadConfig(out BAKprompt, out showChangelog, out languageID);
|
|
|
|
|
}
|
|
|
|
|
catch (ConfigurationErrorsException e)
|
|
|
|
|
{
|
|
|
|
|
// Delete the settings if they exist
|
|
|
|
|
var settingsFilename = (e.InnerException as ConfigurationErrorsException)?.Filename;
|
|
|
|
|
if (!string.IsNullOrEmpty(settingsFilename) && File.Exists(settingsFilename))
|
|
|
|
|
DeleteConfig(settingsFilename);
|
|
|
|
|
else
|
|
|
|
|
WinFormsUtil.Error("Unable to load settings.", e);
|
|
|
|
|
}
|
|
|
|
|
CB_MainLanguage.SelectedIndex = languageID;
|
|
|
|
|
|
|
|
|
|
PKME_Tabs.InitializeFields();
|
|
|
|
|
PKME_Tabs.TemplateFields(LoadTemplate(C_SAV.SAV));
|
|
|
|
|
}
|
|
|
|
|
private void FormLoadAddEvents()
|
|
|
|
|
{
|
|
|
|
|
C_SAV.PKME_Tabs = PKME_Tabs;
|
|
|
|
|
C_SAV.Menu_Redo = Menu_Redo;
|
|
|
|
|
C_SAV.Menu_Undo = Menu_Undo;
|
2017-07-06 06:05:49 +00:00
|
|
|
|
dragout.GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
|
|
|
|
|
GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
PKME_Tabs.EnableDragDrop(Main_DragEnter, Main_DragDrop);
|
|
|
|
|
C_SAV.EnableDragDrop(Main_DragEnter, Main_DragDrop);
|
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
|
|
|
|
|
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-09-30 05:41:35 +00:00
|
|
|
|
Menu_Options.DropDown.Closing += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
if (!Menu_Unicode.Selected)
|
|
|
|
|
return;
|
|
|
|
|
if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Box to Tabs D&D
|
|
|
|
|
dragout.AllowDrop = true;
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Add ContextMenus
|
|
|
|
|
var mnu = new ContextMenuPKM();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
mnu.RequestEditorLegality += ClickLegality;
|
|
|
|
|
mnu.RequestEditorQR += ClickQR;
|
|
|
|
|
mnu.RequestEditorSaveAs += MainMenuSave;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
dragout.ContextMenuStrip = mnu.mnuL;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
C_SAV.menu.RequestEditorLegality += ShowLegality;
|
2017-06-18 20:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
private void FormLoadInitialFiles(string[] args)
|
|
|
|
|
{
|
2017-02-05 21:24:39 +00:00
|
|
|
|
string pkmArg = null;
|
|
|
|
|
foreach (string arg in args.Skip(1)) // skip .exe
|
2015-09-13 16:10:44 +00:00
|
|
|
|
{
|
2017-02-05 21:24:39 +00:00
|
|
|
|
var fi = new FileInfo(arg);
|
|
|
|
|
if (!fi.Exists)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (PKX.IsPKM(fi.Length))
|
2017-02-05 21:24:39 +00:00
|
|
|
|
pkmArg = arg;
|
|
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
|
OpenQuick(arg, force: true);
|
2015-09-13 16:10:44 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (!C_SAV.SAV.Exportable) // No SAV loaded from exe args
|
2016-04-09 05:14:16 +00:00
|
|
|
|
{
|
2016-08-22 01:05:41 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-06-21 01:16:29 +00:00
|
|
|
|
if (!DetectSaveFile(out string path) && path != null)
|
2017-06-21 01:38:33 +00:00
|
|
|
|
WinFormsUtil.Error(path); // `path` contains the error message
|
2017-06-18 20:02:02 +00:00
|
|
|
|
|
|
|
|
|
if (path != null && File.Exists(path))
|
|
|
|
|
OpenQuick(path, force: true);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OpenSAV(C_SAV.SAV, null);
|
|
|
|
|
C_SAV.SAV.Edited = false; // Prevents form close warning from showing until changes are made
|
|
|
|
|
}
|
2016-08-22 01:05:41 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorWindow.ShowErrorDialog("An error occurred while attempting to auto-load your save file.", ex, true);
|
|
|
|
|
}
|
2016-04-06 03:37:36 +00:00
|
|
|
|
}
|
2017-02-05 21:24:39 +00:00
|
|
|
|
if (pkmArg != null)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
OpenQuick(pkmArg, force: true);
|
2017-05-31 03:50:15 +00:00
|
|
|
|
else
|
2017-06-18 01:37:19 +00:00
|
|
|
|
GetPreview(dragout);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 20:02:02 +00:00
|
|
|
|
private void FormLoadCheckForUpdates()
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-06-18 20:02:02 +00:00
|
|
|
|
L_UpdateAvailable.Click += (sender, e) => Process.Start(ThreadPath);
|
|
|
|
|
new Task(() =>
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-06-18 20:02:02 +00:00
|
|
|
|
string data = NetUtil.GetStringFromURL(VersionPath);
|
|
|
|
|
if (data == null)
|
|
|
|
|
return;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DateTime upd = GetDate(data);
|
|
|
|
|
DateTime cur = GetDate(Resources.ProgramVersion);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
if (upd <= cur)
|
|
|
|
|
return;
|
2014-12-13 22:48:34 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
string message = $"New Update Available! {upd:d}";
|
2016-07-31 21:40:09 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
if (InvokeRequired)
|
|
|
|
|
try { Invoke((MethodInvoker)ToggleUpdateMessage); }
|
|
|
|
|
catch { ToggleUpdateMessage(); }
|
|
|
|
|
else { ToggleUpdateMessage(); }
|
2016-07-31 21:40:09 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
DateTime GetDate(string str) => DateTime.ParseExact(str, "yyyyMMdd", CultureInfo.InvariantCulture,
|
|
|
|
|
DateTimeStyles.None);
|
2016-07-31 21:40:09 +00:00
|
|
|
|
|
2017-06-18 20:02:02 +00:00
|
|
|
|
void ToggleUpdateMessage()
|
|
|
|
|
{
|
|
|
|
|
L_UpdateAvailable.Visible = true;
|
|
|
|
|
L_UpdateAvailable.Text = message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}).Start();
|
|
|
|
|
}
|
|
|
|
|
private void FormLoadConfig(out bool BAKprompt, out bool showChangelog, out int languageID)
|
2016-12-07 07:29:57 +00:00
|
|
|
|
{
|
|
|
|
|
BAKprompt = false;
|
|
|
|
|
showChangelog = false;
|
2017-01-10 03:15:46 +00:00
|
|
|
|
languageID = 1;
|
|
|
|
|
|
|
|
|
|
var Settings = Properties.Settings.Default;
|
|
|
|
|
Settings.Upgrade();
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKME_Tabs.Unicode = Unicode = Menu_Unicode.Checked = Settings.Unicode;
|
|
|
|
|
PKME_Tabs.UpdateUnicode(GenderSymbols);
|
2017-01-10 03:15:46 +00:00
|
|
|
|
SaveFile.SetUpdateDex = Menu_ModifyDex.Checked = Settings.SetUpdateDex;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
SaveFile.SetUpdatePKM = C_SAV.ModifyPKM = PKME_Tabs.ModifyPKM = Menu_ModifyPKM.Checked = Settings.SetUpdatePKM;
|
|
|
|
|
C_SAV.FlagIllegal = Menu_FlagIllegal.Checked = Settings.FlagIllegal;
|
2017-03-23 01:02:05 +00:00
|
|
|
|
Menu_ModifyUnset.Checked = Settings.ModifyUnset;
|
2016-12-07 07:29:57 +00:00
|
|
|
|
|
|
|
|
|
// Select Language
|
2017-01-10 03:15:46 +00:00
|
|
|
|
string l = Settings.Language;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
int lang = GameInfo.Language(l);
|
2017-03-20 07:03:31 +00:00
|
|
|
|
if (lang < 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
lang = GameInfo.Language();
|
2017-01-23 07:05:54 +00:00
|
|
|
|
if (lang > -1)
|
|
|
|
|
languageID = lang;
|
2016-12-07 07:29:57 +00:00
|
|
|
|
|
|
|
|
|
// Version Check
|
2017-01-10 03:15:46 +00:00
|
|
|
|
if (Settings.Version.Length > 0) // already run on system
|
2016-12-07 07:29:57 +00:00
|
|
|
|
{
|
2017-05-13 17:20:25 +00:00
|
|
|
|
int.TryParse(Settings.Version, out int lastrev);
|
|
|
|
|
int.TryParse(Resources.ProgramVersion, out int currrev);
|
2016-12-07 07:29:57 +00:00
|
|
|
|
|
|
|
|
|
showChangelog = lastrev < currrev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BAK Prompt
|
2017-01-10 03:15:46 +00:00
|
|
|
|
if (!Settings.BAKPrompt)
|
|
|
|
|
BAKprompt = Settings.BAKPrompt = true;
|
2016-12-07 07:29:57 +00:00
|
|
|
|
|
2017-01-14 21:10:36 +00:00
|
|
|
|
Settings.Version = Resources.ProgramVersion;
|
2016-12-07 07:29:57 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void DeleteConfig(string settingsFilename)
|
2017-03-05 01:21:33 +00:00
|
|
|
|
{
|
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "PKHeX's settings are corrupt. Would you like to reset the settings?",
|
|
|
|
|
"Yes to delete the settings or No to close the program.");
|
|
|
|
|
|
|
|
|
|
if (dr == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
File.Delete(settingsFilename);
|
|
|
|
|
WinFormsUtil.Alert("The settings have been deleted", "Please restart the program.");
|
|
|
|
|
}
|
|
|
|
|
Process.GetCurrentProcess().Kill();
|
|
|
|
|
}
|
2014-12-13 22:48:34 +00:00
|
|
|
|
// Main Menu Strip UI Functions
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuOpen(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (WinFormsUtil.OpenSAVPKMDialog(C_SAV.SAV.PKMExtensions, out string path))
|
|
|
|
|
OpenQuick(path);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuSave(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!PKME_Tabs.VerifiedPKM()) return;
|
|
|
|
|
PKM pk = PreparePKM();
|
2017-05-18 05:00:06 +00:00
|
|
|
|
WinFormsUtil.SavePKMDialog(pk);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuExit(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2017-06-08 05:19:45 +00:00
|
|
|
|
if (ModifierKeys == Keys.Control) // triggered via hotkey
|
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Quit PKHeX?"))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Close();
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuAbout(object sender, EventArgs e) => new About().ShowDialog();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2016-01-03 04:22:53 +00:00
|
|
|
|
// Sub Menu Options
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBoxReport(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (this.FirstFormOfType<ReportGrid>() is ReportGrid z)
|
2017-05-13 17:20:25 +00:00
|
|
|
|
{ z.CenterToForm(this); z.BringToFront(); return; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ReportGrid report = new ReportGrid();
|
|
|
|
|
report.Show();
|
|
|
|
|
report.PopulateData(C_SAV.SAV.BoxData);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuDatabase(object sender, EventArgs e)
|
2016-01-30 02:02:54 +00:00
|
|
|
|
{
|
2016-11-12 18:19:17 +00:00
|
|
|
|
if (ModifierKeys == Keys.Shift)
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (this.FirstFormOfType<KChart>() is KChart c)
|
2017-05-13 17:20:25 +00:00
|
|
|
|
{ c.CenterToForm(this); c.BringToFront(); }
|
2016-11-12 18:19:17 +00:00
|
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
|
new KChart(C_SAV.SAV).Show();
|
2016-11-12 18:19:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (this.FirstFormOfType<SAV_Database>() is SAV_Database z)
|
2017-05-13 17:20:25 +00:00
|
|
|
|
{ z.CenterToForm(this); z.BringToFront(); return; }
|
2016-01-30 02:02:54 +00:00
|
|
|
|
|
2016-08-11 02:44:47 +00:00
|
|
|
|
if (Directory.Exists(DatabasePath))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
new SAV_Database(PKME_Tabs, C_SAV).Show();
|
2016-01-30 02:02:54 +00:00
|
|
|
|
else
|
2017-01-08 23:27:00 +00:00
|
|
|
|
WinFormsUtil.Alert("PKHeX's database was not found.",
|
2016-08-11 02:44:47 +00:00
|
|
|
|
$"Please dump all boxes from a save file, then ensure the '{DatabasePath}' folder exists.");
|
2016-01-30 02:02:54 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuMysteryDB(object sender, EventArgs e)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (this.FirstFormOfType<SAV_MysteryGiftDB>() is SAV_MysteryGiftDB z)
|
2017-05-13 17:20:25 +00:00
|
|
|
|
{ z.CenterToForm(this); z.BringToFront(); return; }
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
new SAV_MysteryGiftDB(PKME_Tabs, C_SAV).Show();
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuUnicode(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Settings.Default.Unicode = PKME_Tabs.Unicode = Unicode = Menu_Unicode.Checked;
|
|
|
|
|
PKME_Tabs.UpdateUnicode(GenderSymbols);
|
2017-02-05 04:39:42 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuModifyDex(object sender, EventArgs e) => Settings.Default.SetUpdateDex = SaveFile.SetUpdateDex = Menu_ModifyDex.Checked;
|
|
|
|
|
private void MainMenuModifyUnset(object sender, EventArgs e) => Settings.Default.ModifyUnset = Menu_ModifyUnset.Checked;
|
|
|
|
|
private void MainMenuModifyPKM(object sender, EventArgs e) => Settings.Default.SetUpdatePKM = SaveFile.SetUpdatePKM = Menu_ModifyPKM.Checked;
|
|
|
|
|
private void MainMenuFlagIllegal(object sender, EventArgs e) => C_SAV.FlagIllegal = Settings.Default.FlagIllegal = Menu_FlagIllegal.Checked;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBoxLoad(object sender, EventArgs e)
|
2015-10-25 01:16:22 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
string path = null;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
if (Directory.Exists(DatabasePath))
|
2015-10-25 01:16:22 +00:00
|
|
|
|
{
|
2017-05-13 19:51:33 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Load from PKHeX's database?");
|
|
|
|
|
if (dr == DialogResult.Yes)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
path = DatabasePath;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.LoadBoxes(out string result, path))
|
|
|
|
|
WinFormsUtil.Alert(result);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBoxDump(object sender, EventArgs e)
|
2016-01-03 04:22:53 +00:00
|
|
|
|
{
|
|
|
|
|
// Dump all of box content to files.
|
2017-05-23 04:55:05 +00:00
|
|
|
|
string path = null;
|
2017-01-09 01:14:39 +00:00
|
|
|
|
DialogResult ld = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Save to PKHeX's database?");
|
2016-01-03 04:22:53 +00:00
|
|
|
|
if (ld == DialogResult.Yes)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
path = DatabasePath;
|
|
|
|
|
else if (ld != DialogResult.No)
|
|
|
|
|
return;
|
2015-10-25 01:16:22 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.DumpBoxes(out string result, path))
|
2017-05-13 19:51:33 +00:00
|
|
|
|
WinFormsUtil.Alert(result);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBoxDumpSingle(object sender, EventArgs e)
|
2017-03-21 07:21:03 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.DumpBox(out string result))
|
|
|
|
|
WinFormsUtil.Alert(result);
|
2017-03-21 07:21:03 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuBatchEditor(object sender, EventArgs e)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
new BatchEditor(PKME_Tabs.PreparePKM(), C_SAV.SAV).ShowDialog();
|
|
|
|
|
C_SAV.SetPKMBoxes(); // refresh
|
|
|
|
|
C_SAV.UpdateBoxViewers();
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void MainMenuFolder(object sender, EventArgs e) => new SAV_FolderList().ShowDialog();
|
2016-01-03 04:22:53 +00:00
|
|
|
|
// Misc Options
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickShowdownImportPKM(object sender, EventArgs e)
|
2016-01-03 04:22:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (!Clipboard.ContainsText())
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert("Clipboard does not contain text."); return; }
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
|
|
|
|
// 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)
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert("Set data not found in clipboard."); return; }
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
if (Set.Nickname?.Length > C_SAV.SAV.NickLength)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Set.Nickname = Set.Nickname.Substring(0, C_SAV.SAV.NickLength);
|
2016-09-20 02:20:55 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text))
|
|
|
|
|
return;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
2016-09-04 06:14:05 +00:00
|
|
|
|
if (Set.InvalidLines.Any())
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines));
|
2016-09-04 06:14:05 +00:00
|
|
|
|
|
2016-01-03 04:22:53 +00:00
|
|
|
|
// Set Species & Nickname
|
2017-06-19 05:27:40 +00:00
|
|
|
|
PKME_Tabs.LoadShowdownSet(Set);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickShowdownExportPKM(object sender, EventArgs e)
|
2016-01-03 04:22:53 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!PKME_Tabs.VerifiedPKM())
|
2017-06-19 05:27:40 +00:00
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert("Fix data before exporting.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-01-03 04:22:53 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
var text = PreparePKM().ShowdownText;
|
|
|
|
|
Clipboard.SetText(text);
|
|
|
|
|
var clip = Clipboard.GetText();
|
|
|
|
|
if (clip != text)
|
|
|
|
|
WinFormsUtil.Alert("Unable to set to Clipboard.", "Try exporting again.");
|
|
|
|
|
else
|
|
|
|
|
WinFormsUtil.Alert("Exported Showdown Set to Clipboard:", text);
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickShowdownExportParty(object sender, EventArgs e)
|
2016-01-03 04:22:53 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.SAV.PartyData.Length <= 0) return;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Clipboard.SetText(
|
2017-05-23 04:55:05 +00:00
|
|
|
|
C_SAV.SAV.PartyData.Aggregate("", (current, pk) => current + pk.ShowdownText
|
2016-01-03 04:22:53 +00:00
|
|
|
|
+ Environment.NewLine + Environment.NewLine).Trim());
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Alert("Showdown Team (Party) set to Clipboard.");
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickShowdownExportBattleBox(object sender, EventArgs e)
|
2016-01-03 04:22:53 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.SAV.BattleBoxData.Length <= 0) return;
|
2016-01-03 04:22:53 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Clipboard.SetText(
|
2017-05-23 04:55:05 +00:00
|
|
|
|
C_SAV.SAV.BattleBoxData.Aggregate("", (current, pk) => current + pk.ShowdownText
|
2016-01-03 04:22:53 +00:00
|
|
|
|
+ Environment.NewLine + Environment.NewLine).Trim());
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Alert("Showdown Team (Battle Box) set to Clipboard.");
|
2016-01-03 04:22:53 +00:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2014-12-13 22:48:34 +00:00
|
|
|
|
// Main Menu Subfunctions
|
2017-05-23 04:55:05 +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))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{ C_SAV.LoadBoxes(out string _, 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);
|
2017-06-04 07:12:35 +00:00
|
|
|
|
if (!fi.Exists)
|
|
|
|
|
return;
|
2017-04-02 14:53:46 +00:00
|
|
|
|
if (fi.Length > 0x10009C && fi.Length != 0x380000 && ! SAV3GCMemoryCard.IsMemoryCardSize(fi.Length))
|
2017-02-15 16:29:47 +00:00
|
|
|
|
WinFormsUtil.Error("Input file is too large." + Environment.NewLine + $"Size: {fi.Length} bytes", path);
|
|
|
|
|
else if (fi.Length < 32)
|
|
|
|
|
WinFormsUtil.Error("Input file is too small." + Environment.NewLine + $"Size: {fi.Length} bytes", path);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
byte[] input; try { input = File.ReadAllBytes(path); }
|
2017-01-08 07:54:09 +00:00
|
|
|
|
catch (Exception e) { WinFormsUtil.Error("Unable to load file. It could be in use by another program.\nPath: " + path, e); return; }
|
2014-12-13 22:48:34 +00:00
|
|
|
|
|
2017-03-18 23:50:34 +00:00
|
|
|
|
#if DEBUG
|
2017-05-23 04:55:05 +00:00
|
|
|
|
OpenFile(input, path, ext, C_SAV.SAV);
|
2017-03-18 23:50:34 +00:00
|
|
|
|
#else
|
2017-05-23 04:55:05 +00:00
|
|
|
|
try { OpenFile(input, path, ext, C_SAV.SAV); }
|
2017-01-08 07:54:09 +00:00
|
|
|
|
catch (Exception e) { WinFormsUtil.Error("Unable to load file.\nPath: " + path, e); }
|
2017-03-18 23:50:34 +00:00
|
|
|
|
#endif
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void OpenFile(byte[] input, string path, string ext, SaveFile currentSaveFile)
|
|
|
|
|
{
|
|
|
|
|
if (TryLoadXorpadSAV(input, path))
|
|
|
|
|
return;
|
|
|
|
|
if (TryLoadSAV(input, path))
|
|
|
|
|
return;
|
|
|
|
|
if (TryLoadMemoryCard(input, path))
|
|
|
|
|
return;
|
|
|
|
|
if (TryLoadPKM(input, path, ext, currentSaveFile))
|
|
|
|
|
return;
|
|
|
|
|
if (TryLoadPCBoxBin(input))
|
|
|
|
|
return;
|
|
|
|
|
if (TryLoadBattleVideo(input))
|
|
|
|
|
return;
|
|
|
|
|
if (TryLoadMysteryGift(input, path, ext))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
WinFormsUtil.Error("Attempted to load an unsupported file type/size.",
|
|
|
|
|
$"File Loaded:{Environment.NewLine}{path}",
|
|
|
|
|
$"File Size:{Environment.NewLine}{input.Length} bytes (0x{input.Length:X4})");
|
|
|
|
|
}
|
|
|
|
|
private bool TryLoadXorpadSAV(byte[] input, string path)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (input.Length != 0x100000)
|
|
|
|
|
return false;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (OpenXOR(input, path)) // Check if we can load the save via xorpad
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
2014-08-15 04:27:53 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (BitConverter.ToUInt64(input, 0x10) != 0) // encrypted save
|
2016-09-24 01:47:03 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WinFormsUtil.Error("PKHeX only edits decrypted save files." + Environment.NewLine + "This save file is not decrypted.", path);
|
|
|
|
|
return true;
|
2016-09-24 01:47:03 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
DialogResult sdr = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000",
|
|
|
|
|
"Press No for the one at 0x82000");
|
|
|
|
|
if (sdr == DialogResult.Cancel)
|
|
|
|
|
return true;
|
|
|
|
|
int savshift = sdr == DialogResult.Yes ? 0 : 0x7F000;
|
|
|
|
|
byte[] psdata = input.Skip(0x5400 + savshift).Take(SaveUtil.SIZE_G6ORAS).ToArray();
|
|
|
|
|
|
|
|
|
|
if (BitConverter.ToUInt32(psdata, SaveUtil.SIZE_G6ORAS - 0x1F0) == SaveUtil.BEEF)
|
|
|
|
|
Array.Resize(ref psdata, SaveUtil.SIZE_G6ORAS); // set to ORAS size
|
|
|
|
|
else if (BitConverter.ToUInt32(psdata, SaveUtil.SIZE_G6XY - 0x1F0) == SaveUtil.BEEF)
|
|
|
|
|
Array.Resize(ref psdata, SaveUtil.SIZE_G6XY); // set to X/Y size
|
|
|
|
|
else if (BitConverter.ToUInt32(psdata, SaveUtil.SIZE_G7SM - 0x1F0) == SaveUtil.BEEF)
|
|
|
|
|
Array.Resize(ref psdata, SaveUtil.SIZE_G7SM); // set to S/M size
|
|
|
|
|
else
|
2017-04-02 14:53:46 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WinFormsUtil.Error("The data file is not a valid save file", path);
|
|
|
|
|
return true;
|
2017-04-02 14:53:46 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
OpenSAV(SaveUtil.GetVariantSAV(psdata), path);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private bool TryLoadSAV(byte[] input, string path)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var sav = SaveUtil.GetVariantSAV(input);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (sav == null)
|
|
|
|
|
return false;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
OpenSAV(sav, path);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private bool TryLoadMemoryCard(byte[] input, string path)
|
|
|
|
|
{
|
|
|
|
|
if (!SAV3GCMemoryCard.IsMemoryCardSize(input))
|
|
|
|
|
return false;
|
|
|
|
|
SAV3GCMemoryCard MC = CheckGCMemoryCard(input, path);
|
|
|
|
|
if (MC == null)
|
|
|
|
|
return false;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var sav = SaveUtil.GetVariantSAV(MC);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (sav == null)
|
|
|
|
|
return false;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
OpenSAV(sav, path);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private bool TryLoadPKM(byte[] input, string path, string ext, SaveFile SAV)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var temp = PKMConverter.GetPKMfromBytes(input, prefer: ext.Length > 0 ? (ext.Last() - 0x30) & 7 : C_SAV.SAV.Generation);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (temp == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
var type = PKME_Tabs.CurrentPKM.GetType();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM pk = PKMConverter.ConvertToType(temp, type, out string c);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (pk == null)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WinFormsUtil.Alert("Conversion failed.", c);
|
|
|
|
|
return false;
|
2016-05-15 22:35:43 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (SAV.Generation < 3 && ((pk as PK1)?.Japanese ?? ((PK2)pk).Japanese) != SAV.Japanese)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var strs = new[] { "International", "Japanese" };
|
|
|
|
|
var val = SAV.Japanese ? 0 : 1;
|
|
|
|
|
WinFormsUtil.Alert($"Cannot load {strs[val]} {pk.GetType().Name}s to {strs[val ^ 1]} saves.");
|
|
|
|
|
return false;
|
2015-09-18 03:18:22 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(pk);
|
2017-07-02 02:43:51 +00:00
|
|
|
|
Debug.WriteLine(c);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private bool TryLoadPCBoxBin(byte[] input)
|
|
|
|
|
{
|
2017-06-23 00:52:11 +00:00
|
|
|
|
if (!C_SAV.IsPCBoxBin(input.Length))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
if (!C_SAV.OpenPCBoxBin(input, out string c))
|
2015-02-24 07:52:32 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WinFormsUtil.Alert("Binary is not compatible with save file.", c);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-12-16 07:17:17 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WinFormsUtil.Alert(c);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private bool TryLoadBattleVideo(byte[] input)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!BattleVideo.IsValid(input))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return false;
|
2016-10-16 04:28:14 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
BattleVideo b = BattleVideo.GetVariantBattleVideo(input);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
bool result = C_SAV.OpenBattleVideo(b, out string c);
|
|
|
|
|
WinFormsUtil.Alert(c);
|
2017-07-02 02:43:51 +00:00
|
|
|
|
Debug.WriteLine(c);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
private bool TryLoadMysteryGift(byte[] input, string path, string ext)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var tg = MysteryGift.GetMysteryGift(input, ext);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (tg == null)
|
|
|
|
|
return false;
|
|
|
|
|
if (!tg.IsPokémon)
|
2015-12-27 00:05:26 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WinFormsUtil.Alert("Mystery Gift is not a Pokémon.", path);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-10-12 02:11:24 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var temp = tg.ConvertToPKM(C_SAV.SAV);
|
|
|
|
|
PKM pk = PKMConverter.ConvertToType(temp, C_SAV.SAV.PKMType, out string c);
|
2016-10-12 02:11:24 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (pk == null)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert("Conversion failed.", c);
|
|
|
|
|
return true;
|
2015-12-27 00:05:26 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(pk);
|
2017-07-02 02:43:51 +00:00
|
|
|
|
Debug.WriteLine(c);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private bool OpenXOR(byte[] input, string path)
|
2014-12-31 06:18:41 +00:00
|
|
|
|
{
|
2017-02-09 08:44:38 +00:00
|
|
|
|
// try to get a save file via xorpad in same folder
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var folder = new DirectoryInfo(path).Parent.FullName;
|
|
|
|
|
string[] pads = Directory.GetFiles(folder);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var s = SaveUtil.GetSAVfromXORpads(input, pads);
|
2014-12-31 06:18:41 +00:00
|
|
|
|
|
2017-02-09 08:44:38 +00:00
|
|
|
|
if (s == null) // failed to find xorpad in path folder
|
2015-03-11 01:44:51 +00:00
|
|
|
|
{
|
2017-02-09 08:44:38 +00:00
|
|
|
|
// try again
|
|
|
|
|
pads = Directory.GetFiles(WorkingDirectory);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
s = SaveUtil.GetSAVfromXORpads(input, pads);
|
2014-12-31 06:18:41 +00:00
|
|
|
|
}
|
2017-02-09 08:44:38 +00:00
|
|
|
|
|
|
|
|
|
if (s == null)
|
|
|
|
|
return false; // failed
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
OpenSAV(s, s.FileName);
|
2017-02-09 08:44:38 +00:00
|
|
|
|
return true;
|
2014-12-31 06:18:41 +00:00
|
|
|
|
}
|
2017-04-02 20:42:42 +00:00
|
|
|
|
private static GameVersion SelectMemoryCardSaveGame(SAV3GCMemoryCard MC)
|
2017-04-02 14:53:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (MC.SaveGameCount == 1)
|
|
|
|
|
return MC.SelectedGameVersion;
|
|
|
|
|
|
2017-04-02 20:42:42 +00:00
|
|
|
|
var games = new List<ComboItem>();
|
|
|
|
|
if (MC.HasCOLO) games.Add(new ComboItem { Text = "Colosseum", Value = (int)GameVersion.COLO });
|
|
|
|
|
if (MC.HasXD) games.Add(new ComboItem { Text = "XD", Value = (int)GameVersion.XD });
|
|
|
|
|
if (MC.HasRSBOX) games.Add(new ComboItem { Text = "RS Box", Value = (int)GameVersion.RSBOX });
|
2017-04-02 14:53:46 +00:00
|
|
|
|
|
2017-04-02 20:42:42 +00:00
|
|
|
|
WinFormsUtil.Alert("Multiple games detected", "Select a game to edit.");
|
|
|
|
|
var dialog = new SAV_GameSelect(games.ToArray());
|
|
|
|
|
dialog.ShowDialog();
|
|
|
|
|
return dialog.Result;
|
|
|
|
|
}
|
|
|
|
|
private static SAV3GCMemoryCard CheckGCMemoryCard(byte[] Data, string path)
|
2017-04-02 14:53:46 +00:00
|
|
|
|
{
|
|
|
|
|
SAV3GCMemoryCard MC = new SAV3GCMemoryCard();
|
|
|
|
|
GCMemoryCardState MCState = MC.LoadMemoryCardFile(Data);
|
2017-04-02 20:42:42 +00:00
|
|
|
|
switch (MCState)
|
2017-04-02 14:53:46 +00:00
|
|
|
|
{
|
2017-04-02 20:42:42 +00:00
|
|
|
|
default: { WinFormsUtil.Error("Invalid or corrupted GC Memory Card. Aborting.", path); return null; }
|
2017-04-02 14:53:46 +00:00
|
|
|
|
case GCMemoryCardState.NoPkmSaveGame: { WinFormsUtil.Error("GC Memory Card without any Pokémon save file. Aborting.", path); return null; }
|
2017-04-02 20:42:42 +00:00
|
|
|
|
case GCMemoryCardState.DuplicateCOLO:
|
|
|
|
|
case GCMemoryCardState.DuplicateXD:
|
|
|
|
|
case GCMemoryCardState.DuplicateRSBOX: { WinFormsUtil.Error("GC Memory Card with duplicated game save files. Aborting.", path); return null; }
|
2017-04-02 14:53:46 +00:00
|
|
|
|
case GCMemoryCardState.MultipleSaveGame:
|
|
|
|
|
{
|
|
|
|
|
GameVersion Game = SelectMemoryCardSaveGame(MC);
|
2017-04-02 20:42:42 +00:00
|
|
|
|
if (Game == GameVersion.Invalid) //Cancel
|
2017-04-02 14:53:46 +00:00
|
|
|
|
return null;
|
|
|
|
|
MC.SelectSaveGame(Game);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-05-13 19:51:33 +00:00
|
|
|
|
case GCMemoryCardState.SaveGameCOLO: MC.SelectSaveGame(GameVersion.COLO); break;
|
|
|
|
|
case GCMemoryCardState.SaveGameXD: MC.SelectSaveGame(GameVersion.XD); break;
|
|
|
|
|
case GCMemoryCardState.SaveGameRSBOX: MC.SelectSaveGame(GameVersion.RSBOX); break;
|
2017-04-02 14:53:46 +00:00
|
|
|
|
}
|
|
|
|
|
return MC;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 05:00:06 +00:00
|
|
|
|
private static void StoreLegalSaveGameData(SaveFile sav)
|
Encounter Type fix and detection of pokemon that should have evolve on trade (#1105)
* Detect encounter trades that evolve on trade and have not been evolved
Detect generation 1 pokemon with special catch rates : krabby trade and Pokemon Stadium
Detect generation 1 pokemon that evolve on trade and have been traded but not evolved
Detect pokemon with tradeback status any but with only encounters from the other GB generation, that means they are WasTradeback
Detect pokemon with moves from the other GB generation, change tradebackstatus to WasTradeback
* Fix dppt surfing and fishing encounter type, is is surfing because the battle background is the same as other surfingfishing encounters
Fix headbutt encounter type, the encounter type depends on the battle background used when battle a pokemon, for headbutt it changes with the player tile, is the player is in a city it will be building encounter, in a grass tile tall grass, in water it is surfingfishing and cave inside a cave. Some locations have more than one possible encounter type, for example routes with trees near the grass, near the water and near non-combat tiles.
Also added slot type headbutt special for the special trees, those trees are all in routes and are only adjacent to non-combat tiles
* Fix encounter type for missing areas with multiple grass encounters types: Mt Coronet, Mt Silver Cave and Stark Mountain (Issue # 1095)
* Fixes and typos
* Check for non-japanese e-reader pokemon, is unreleased
2017-05-01 15:07:20 +00:00
|
|
|
|
{
|
|
|
|
|
Legal.SavegameJapanese = sav.Japanese;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Legal.EReaderBerryIsEnigma = sav.IsEBerryIsEnigma;
|
|
|
|
|
Legal.EReaderBerryName = sav.EBerryName;
|
Encounter Type fix and detection of pokemon that should have evolve on trade (#1105)
* Detect encounter trades that evolve on trade and have not been evolved
Detect generation 1 pokemon with special catch rates : krabby trade and Pokemon Stadium
Detect generation 1 pokemon that evolve on trade and have been traded but not evolved
Detect pokemon with tradeback status any but with only encounters from the other GB generation, that means they are WasTradeback
Detect pokemon with moves from the other GB generation, change tradebackstatus to WasTradeback
* Fix dppt surfing and fishing encounter type, is is surfing because the battle background is the same as other surfingfishing encounters
Fix headbutt encounter type, the encounter type depends on the battle background used when battle a pokemon, for headbutt it changes with the player tile, is the player is in a city it will be building encounter, in a grass tile tall grass, in water it is surfingfishing and cave inside a cave. Some locations have more than one possible encounter type, for example routes with trees near the grass, near the water and near non-combat tiles.
Also added slot type headbutt special for the special trees, those trees are all in routes and are only adjacent to non-combat tiles
* Fix encounter type for missing areas with multiple grass encounters types: Mt Coronet, Mt Silver Cave and Stark Mountain (Issue # 1095)
* Fixes and typos
* Check for non-japanese e-reader pokemon, is unreleased
2017-05-01 15:07:20 +00:00
|
|
|
|
Legal.Savegame_Gender = sav.Gender;
|
|
|
|
|
Legal.Savegame_TID = sav.TID;
|
|
|
|
|
Legal.Savegame_SID = sav.SID;
|
|
|
|
|
Legal.Savegame_OT = sav.OT;
|
|
|
|
|
Legal.Savegame_Version = sav.Version;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static PKM LoadTemplate(SaveFile sav)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(TemplatePath))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var blank = sav.BlankPKM;
|
|
|
|
|
string path = Path.Combine(TemplatePath, new DirectoryInfo(TemplatePath).Name + "." + blank.Extension);
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!File.Exists(path) || !PKX.IsPKM(new FileInfo(path).Length))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var pk = PKMConverter.GetPKMfromBytes(File.ReadAllBytes(path), prefer: blank.Format);
|
|
|
|
|
return PKMConverter.ConvertToType(pk, sav.BlankPKM.GetType(), out path); // no sneaky plz; reuse string
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void RefreshMGDB()
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
Legal.RefreshMGDB(MGDatabasePath);
|
|
|
|
|
}
|
Encounter Type fix and detection of pokemon that should have evolve on trade (#1105)
* Detect encounter trades that evolve on trade and have not been evolved
Detect generation 1 pokemon with special catch rates : krabby trade and Pokemon Stadium
Detect generation 1 pokemon that evolve on trade and have been traded but not evolved
Detect pokemon with tradeback status any but with only encounters from the other GB generation, that means they are WasTradeback
Detect pokemon with moves from the other GB generation, change tradebackstatus to WasTradeback
* Fix dppt surfing and fishing encounter type, is is surfing because the battle background is the same as other surfingfishing encounters
Fix headbutt encounter type, the encounter type depends on the battle background used when battle a pokemon, for headbutt it changes with the player tile, is the player is in a city it will be building encounter, in a grass tile tall grass, in water it is surfingfishing and cave inside a cave. Some locations have more than one possible encounter type, for example routes with trees near the grass, near the water and near non-combat tiles.
Also added slot type headbutt special for the special trees, those trees are all in routes and are only adjacent to non-combat tiles
* Fix encounter type for missing areas with multiple grass encounters types: Mt Coronet, Mt Silver Cave and Stark Mountain (Issue # 1095)
* Fixes and typos
* Check for non-japanese e-reader pokemon, is unreleased
2017-05-01 15:07:20 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void OpenSAV(SaveFile sav, string path)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2016-06-28 06:03:57 +00:00
|
|
|
|
if (sav == null || sav.Version == GameVersion.Invalid)
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Error("Invalid save file loaded. Aborting.", path); return; }
|
2016-10-12 02:11:24 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!SanityCheckSAV(ref sav, path))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return;
|
|
|
|
|
StoreLegalSaveGameData(sav);
|
2017-07-16 21:05:29 +00:00
|
|
|
|
PKMUtil.Initialize(sav); // refresh sprite generator
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// clean fields
|
|
|
|
|
C_SAV.M.Reset();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Menu_ExportSAV.Enabled = sav.Exportable;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// No changes made yet
|
|
|
|
|
Menu_Undo.Enabled = false;
|
|
|
|
|
Menu_Redo.Enabled = false;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ResetSAVPKMEditors(sav);
|
|
|
|
|
|
|
|
|
|
Text = GetProgramTitle(sav, path);
|
|
|
|
|
TryBackupExportCheck(sav, path);
|
|
|
|
|
|
|
|
|
|
PKMConverter.UpdateConfig(sav.SubRegion, sav.Country, sav.ConsoleRegion, sav.OT, sav.Gender, sav.Language);
|
|
|
|
|
SystemSounds.Beep.Play();
|
|
|
|
|
}
|
|
|
|
|
private void ResetSAVPKMEditors(SaveFile sav)
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
bool WindowToggleRequired = C_SAV.SAV.Generation < 3 && sav.Generation >= 3; // version combobox refresh hack
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM pk = PreparePKM();
|
2017-06-19 05:27:40 +00:00
|
|
|
|
var blank = sav.BlankPKM;
|
|
|
|
|
PKME_Tabs.CurrentPKM = blank;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKME_Tabs.SetPKMFormatMode(sav.Generation);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(blank);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
C_SAV.SAV = sav;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
2017-06-19 05:27:40 +00:00
|
|
|
|
// Initialize Overall Info
|
|
|
|
|
Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_Report.Enabled = Menu_Modify.Enabled = C_SAV.SAV.HasBox;
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Initialize Subviews
|
2017-06-19 05:27:40 +00:00
|
|
|
|
bool WindowTranslationRequired = false;
|
|
|
|
|
WindowTranslationRequired |= PKME_Tabs.ToggleInterface(sav, pk);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WindowTranslationRequired |= C_SAV.ToggleInterface();
|
|
|
|
|
if (WindowTranslationRequired) // force update -- re-added controls may be untranslated
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, CurrentLanguage);
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (WindowToggleRequired) // Version combobox selectedvalue needs a little help, only updates once it is visible
|
|
|
|
|
PKME_Tabs.FlickerInterface();
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKME_Tabs.TemplateFields(LoadTemplate(sav));
|
|
|
|
|
sav.Edited = false;
|
|
|
|
|
}
|
|
|
|
|
private static string GetProgramTitle(SaveFile sav, string path)
|
|
|
|
|
{
|
|
|
|
|
string title = $"PKH{(HaX ? "a" : "e")}X ({Resources.ProgramVersion}) - " + $"{sav.GetType().Name}: ";
|
2017-06-18 02:20:37 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(path)) // Blank save file
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
sav.FilePath = null;
|
|
|
|
|
sav.FileName = "Blank Save File";
|
|
|
|
|
return title + $"{sav.FileName} [{sav.OT} ({sav.Version})]";
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
sav.FilePath = Path.GetDirectoryName(path);
|
|
|
|
|
sav.FileName = Path.GetExtension(path) == ".bak"
|
|
|
|
|
? Path.GetFileName(path).Split(new[] {" ["}, StringSplitOptions.None)[0]
|
|
|
|
|
: Path.GetFileName(path);
|
|
|
|
|
return title + $"{Path.GetFileNameWithoutExtension(Util.CleanFileName(sav.BAKName))}"; // more descriptive
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool TryBackupExportCheck(SaveFile sav, string path)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(path)) // not actual save
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// 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);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
// Check location write protection
|
|
|
|
|
bool locked = true;
|
|
|
|
|
try { locked = File.GetAttributes(path).HasFlag(FileAttributes.ReadOnly); }
|
|
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
|
if (!locked)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
WinFormsUtil.Alert("File's location is write protected:\n" + path,
|
|
|
|
|
"If the path is a removable disk (SD card), please ensure the write protection switch is not set.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
private static bool SanityCheckSAV(ref SaveFile sav, string path)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(path)) // If path is null, this is the default save
|
2016-11-12 15:30:51 +00:00
|
|
|
|
{
|
2016-11-12 15:38:56 +00:00
|
|
|
|
if (sav.RequiresMemeCrypto && !MemeCrypto.CanUseMemeCrypto())
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WinFormsUtil.Error("Your platform does not support the required cryptography components.",
|
|
|
|
|
"In order to be able to save your changes, you must either upgrade to a newer version of Windows or disable FIPS compliance mode.");
|
2016-11-12 15:38:56 +00:00
|
|
|
|
// Don't abort loading; user can still view save and fix checksum on another platform.
|
|
|
|
|
}
|
2017-01-26 04:11:53 +00:00
|
|
|
|
}
|
2016-10-12 02:11:24 +00:00
|
|
|
|
// Finish setting up the save file.
|
2017-03-12 23:36:23 +00:00
|
|
|
|
if (sav.Generation == 1)
|
|
|
|
|
{
|
|
|
|
|
// Ask the user if it is a VC save file or if it is from a physical cartridge.
|
|
|
|
|
// Necessary for legality checking possibilities that are only obtainable on GSC (non VC) or event distributions.
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var drVC = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel,
|
|
|
|
|
$"{sav.Version} Save File detected. Is this a Virtual Console Save File?",
|
2017-03-12 23:36:23 +00:00
|
|
|
|
"Yes: Virtual Console" + Environment.NewLine + "No: Physical Cartridge");
|
|
|
|
|
if (drVC == DialogResult.Cancel)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return false;
|
2017-03-12 23:36:23 +00:00
|
|
|
|
Legal.AllowGBCartEra = drVC == DialogResult.No; // physical cart selected
|
Generation 1 and 2 legal Improvements (#1099)
* Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved.
Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves
Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter.
Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move
* Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible.
If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2.
Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves
Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon
Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves
* Check legal values of generation 1 type and catch rate
Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item)
Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves
* Filter ingame trades and static encounters with catch rate for generation 1 non tradeback
* Fix min moves for generation 1 metapod encounter
* Clean up
* Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up
Clean up type validation
Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch
* Clean-up
* Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array
* Fix generation 1 evolution chains and catch rate as default held item
* Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
|
|
|
|
if (Legal.AllowGBCartEra && sav.Generation == 1)
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var drTradeback = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel,
|
|
|
|
|
$"Generation {sav.Generation} Save File detected. Allow tradebacks from Generation 2 for legality purposes?",
|
|
|
|
|
"Yes: Allow Generation 2 tradeback learnsets" + Environment.NewLine +
|
|
|
|
|
"No: Don't allow Generation 2 tradeback learnsets");
|
2017-07-12 01:01:20 +00:00
|
|
|
|
if (drTradeback == DialogResult.Cancel)
|
|
|
|
|
return false;
|
Generation 1 and 2 legal Improvements (#1099)
* Refactor parseMovesForEncounter to gather valid moves for species encounter, some Pokemon can have valid encounters with different source species from the encounter, the valid moves change if the encounter species change because some preevolutions moves are illegal if pokemon caught already evolved.
Example, generation 1 Pikachu that can have a RBY Pikachu encounter and GSC Pichu encounter, the valid moves for the first encounters should not have any Pichu exclusive evolution moves
Also assign the encounter match from gb when parsing moves like the variable Encounter Match, to store the encounter that is valid for the pokemon moves instead the first encounter.
Store the species encounter, this will be needed to check if the evolution is valid for species that evolve leveling with a given learned move
* Add Tradeback Status to the pokemon, this variable for generations 1 and 2 use data like the catch rate to determine if trade between generations 1 and 2 was possible.
If analysis is for VC games tradeback have value NotTradeback for every gen 1 pokemon, but for cart saves some pokemon can be determine that have not been tradeback, if catch rate match species catch rate but do not match a valid generation 2 held item that means the pokemon habe been never traded to generation 2 games, that allow to discart encounters and moves from generation 2.
Also if is not tradeback catch rate is used to filter encounters, catch rate determine in what species was captured the pokemon discarting some preevolutions moves
Also add option for generation 1 cart save analysis to check legal status not allowing generation 2 games, like VC games but with Stadium allowed, like the generation 1 non tradeback rules from Smogon
Also change evolution chains to included generation 2 preevolutions for gen 1 pokemon if tradeback was possible, it is needed to avoid parsemoves to check illegal pokemon like Hitmonchan with Tyrogue level up moves
* Check legal values of generation 1 type and catch rate
Replace pokemon catch rate after changind pokemon species always if pokemon was not tradeback from generation 2, the catch rate will keep unchanged only if it can be a held item and do not match species catch rate (default item)
Also if catch rate is changed use base species catch rate to avoid legal errors if the catch rate of the evolution species if is not possible with the current moves
* Filter ingame trades and static encounters with catch rate for generation 1 non tradeback
* Fix min moves for generation 1 metapod encounter
* Clean up
* Fix encounter level for generation 1, valid moves are those with one level after the encounter level, pokemon can not learn a new move until level up
Clean up type validation
Fix generation 3 fatefull encounter eggs, the pokemon lost the fatefull mark when it hatch
* Clean-up
* Use new variable EncounterSpecies when it is needed to detect the species of the encounter, the old code wont work if the encounter is a wild slots array
* Fix generation 1 evolution chains and catch rate as default held item
* Fix Generation 1 Yellow Pikachu and Kadabra catch rates
2017-04-27 04:27:59 +00:00
|
|
|
|
Legal.AllowGen1Tradeback = drTradeback == DialogResult.Yes;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Legal.AllowGen1Tradeback = false;
|
2017-03-12 23:36:23 +00:00
|
|
|
|
}
|
2017-03-18 05:27:59 +00:00
|
|
|
|
else
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Legal.AllowGBCartEra = Legal.AllowGen1Tradeback = sav.Generation == 2;
|
2017-03-18 05:27:59 +00:00
|
|
|
|
|
|
|
|
|
if (sav.Generation == 3 && (sav.IndeterminateGame || ModifierKeys == Keys.Control))
|
2016-07-15 03:22:24 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
WinFormsUtil.Alert($"Generation {sav.Generation} Save File detected.", "Select version.");
|
2017-04-10 23:28:44 +00:00
|
|
|
|
var g = new[] {GameVersion.R, GameVersion.S, GameVersion.E, GameVersion.FR, GameVersion.LG};
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int) z));
|
2017-04-02 20:42:42 +00:00
|
|
|
|
var dialog = new SAV_GameSelect(games);
|
|
|
|
|
dialog.ShowDialog();
|
|
|
|
|
|
|
|
|
|
switch (dialog.Result) // Reset save file info
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.R:
|
2017-05-23 04:55:05 +00:00
|
|
|
|
case GameVersion.S:
|
|
|
|
|
sav = new SAV3(sav.BAK, GameVersion.RS);
|
|
|
|
|
break;
|
|
|
|
|
case GameVersion.E:
|
|
|
|
|
sav = new SAV3(sav.BAK, GameVersion.E);
|
|
|
|
|
break;
|
2017-04-02 20:42:42 +00:00
|
|
|
|
case GameVersion.FR:
|
2017-05-23 04:55:05 +00:00
|
|
|
|
case GameVersion.LG:
|
|
|
|
|
sav = new SAV3(sav.BAK, GameVersion.FRLG);
|
|
|
|
|
break;
|
|
|
|
|
default: return false;
|
2016-07-29 05:08:23 +00:00
|
|
|
|
}
|
2017-04-02 20:42:42 +00:00
|
|
|
|
if (sav.Version == GameVersion.FRLG)
|
|
|
|
|
sav.Personal = dialog.Result == GameVersion.FR ? PersonalTable.FR : PersonalTable.LG;
|
2016-10-12 02:11:24 +00:00
|
|
|
|
}
|
2017-04-02 20:42:42 +00:00
|
|
|
|
else if (sav.IndeterminateSubVersion && sav.Version == GameVersion.FRLG)
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
string fr = GameInfo.VersionDataSource.First(r => r.Value == (int) GameVersion.FR).Text;
|
|
|
|
|
string lg = GameInfo.VersionDataSource.First(l => l.Value == (int) GameVersion.LG).Text;
|
2017-04-27 05:05:32 +00:00
|
|
|
|
const string dual = "{0}/{1} Save File Detected.";
|
2017-04-10 23:28:44 +00:00
|
|
|
|
WinFormsUtil.Alert(string.Format(dual, fr, lg), "Select version.");
|
|
|
|
|
var g = new[] {GameVersion.FR, GameVersion.LG};
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var games = g.Select(z => GameInfo.VersionDataSource.First(v => v.Value == (int) z));
|
2017-04-10 23:28:44 +00:00
|
|
|
|
var dialog = new SAV_GameSelect(games);
|
2017-04-02 20:42:42 +00:00
|
|
|
|
dialog.ShowDialog();
|
2017-04-10 23:28:44 +00:00
|
|
|
|
|
2017-07-12 01:01:20 +00:00
|
|
|
|
switch (dialog.Result)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.FR:
|
|
|
|
|
sav.Personal = PersonalTable.FR;
|
|
|
|
|
break;
|
|
|
|
|
case GameVersion.LG:
|
|
|
|
|
sav.Personal = PersonalTable.LG;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-04-02 20:42:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-10-12 02:11:24 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static void SetCountrySubRegion(ComboBox CB, string type)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
int index = CB.SelectedIndex;
|
|
|
|
|
// fix for Korean / Chinese being swapped
|
|
|
|
|
string cl = GameInfo.CurrentLanguage + "";
|
|
|
|
|
cl = cl == "zh" ? "ko" : cl == "ko" ? "zh" : cl;
|
2016-08-11 04:10:21 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
CB.DataSource = Util.GetCBList(type, cl);
|
2017-03-19 23:19:59 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (index > 0 && index < CB.Items.Count)
|
|
|
|
|
CB.SelectedIndex = index;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
}
|
2014-12-13 22:48:34 +00:00
|
|
|
|
|
|
|
|
|
// Language Translation
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeMainLanguage(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-03-24 18:18:14 +00:00
|
|
|
|
if (CB_MainLanguage.SelectedIndex < 8)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
CurrentLanguage = GameInfo.Language2Char((uint)CB_MainLanguage.SelectedIndex);
|
2017-03-24 18:18:14 +00:00
|
|
|
|
|
|
|
|
|
// Set the culture (makes it easy to pass language to other forms)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Settings.Default.Language = CurrentLanguage;
|
|
|
|
|
Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentLanguage.Substring(0, 2));
|
2017-03-24 18:18:14 +00:00
|
|
|
|
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
|
|
|
|
|
|
2014-12-13 22:48:34 +00:00
|
|
|
|
Menu_Options.DropDown.Close();
|
2017-06-19 05:27:40 +00:00
|
|
|
|
|
|
|
|
|
PKM pk = C_SAV.SAV.GetPKM(PKME_Tabs.CurrentPKM.Data);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
InitializeStrings();
|
2017-06-19 05:27:40 +00:00
|
|
|
|
PKME_Tabs.ChangeLanguage(C_SAV.SAV, pk);
|
2016-09-30 05:41:35 +00:00
|
|
|
|
string ProgramTitle = Text;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, CurrentLanguage); // Translate the UI to language.
|
2016-09-30 05:41:35 +00:00
|
|
|
|
Text = ProgramTitle;
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-06-19 05:27:40 +00:00
|
|
|
|
private static void InitializeStrings()
|
2017-03-24 18:18:14 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string l = CurrentLanguage;
|
|
|
|
|
GameInfo.Strings = GameInfo.GetStrings(l);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2017-03-22 04:40:33 +00:00
|
|
|
|
// Update Legality Strings
|
2017-06-18 01:37:19 +00:00
|
|
|
|
// Clipboard.SetText(string.Join(Environment.NewLine, Util.GetLocalization(typeof(LegalityCheckStrings))));
|
2017-06-23 04:56:41 +00:00
|
|
|
|
Task.Run(() => {
|
|
|
|
|
var lang = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Substring(0, 2);
|
|
|
|
|
Util.SetLocalization(typeof(LegalityCheckStrings), lang);
|
|
|
|
|
RibbonStrings.ResetDictionary(GameInfo.Strings.ribbons);
|
|
|
|
|
});
|
2017-03-22 04:40:33 +00:00
|
|
|
|
|
2016-04-07 01:13:43 +00:00
|
|
|
|
// Update Legality Analysis strings
|
2017-06-18 01:37:19 +00:00
|
|
|
|
LegalityAnalysis.MoveStrings = GameInfo.Strings.movelist;
|
|
|
|
|
LegalityAnalysis.SpeciesStrings = GameInfo.Strings.specieslist;
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2014-12-13 22:48:34 +00:00
|
|
|
|
#region //// PKX WINDOW FUNCTIONS ////
|
2017-03-12 23:36:23 +00:00
|
|
|
|
private bool QR6Notified;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickQR(object sender, EventArgs e)
|
2015-02-25 04:10:47 +00:00
|
|
|
|
{
|
2015-02-27 08:40:57 +00:00
|
|
|
|
if (ModifierKeys == Keys.Alt)
|
2017-06-22 04:57:59 +00:00
|
|
|
|
{
|
2017-07-03 04:27:22 +00:00
|
|
|
|
string url = Clipboard.GetText();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(url))
|
|
|
|
|
{
|
|
|
|
|
if (!url.StartsWith("http") || url.Contains('\n'))
|
|
|
|
|
ClickShowdownImportPKM(sender, e);
|
|
|
|
|
else
|
|
|
|
|
ImportQRToTabs(url);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-06-22 04:57:59 +00:00
|
|
|
|
}
|
2017-07-03 04:27:22 +00:00
|
|
|
|
ExportQRFromTabs();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
}
|
2015-03-14 02:59:51 +00:00
|
|
|
|
|
2017-07-03 04:27:22 +00:00
|
|
|
|
private void ImportQRToTabs(string url)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
{
|
|
|
|
|
// Fetch data from QR code...
|
2017-07-03 04:27:22 +00:00
|
|
|
|
byte[] ekx = QR.GetQRData(url);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (ekx == null)
|
|
|
|
|
return;
|
2016-10-12 05:59:19 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM pk = PKMConverter.GetPKMfromBytes(ekx, prefer: C_SAV.SAV.Generation);
|
|
|
|
|
if (pk == null)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert("Decoded data not a valid PKM.", $"QR Data Size: {ekx.Length}");
|
|
|
|
|
return;
|
2015-02-26 06:39:29 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!pk.Valid || pk.Species <= 0)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert("Invalid data detected.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PKM pkz = PKMConverter.ConvertToType(pk, C_SAV.SAV.PKMType, out string c);
|
|
|
|
|
if (pkz == null)
|
2015-02-26 07:12:38 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.Alert(c);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PKME_Tabs.PopulateFields(pkz);
|
|
|
|
|
}
|
2017-06-18 20:02:02 +00:00
|
|
|
|
private void ExportQRFromTabs()
|
2017-06-18 01:37:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (!PKME_Tabs.VerifiedPKM())
|
|
|
|
|
return;
|
|
|
|
|
PKM pkx = PreparePKM();
|
2015-03-14 02:59:51 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Image qr;
|
|
|
|
|
switch (pkx.Format)
|
|
|
|
|
{
|
|
|
|
|
case 7:
|
|
|
|
|
qr = QR.GenerateQRCode7((PK7) pkx);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (pkx.Format == 6 && !QR6Notified) // hint that the user should not be using QR6 injection
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert("QR codes are deprecated in favor of other methods.",
|
|
|
|
|
"Consider utilizing homebrew or on-the-fly RAM editing custom firmware (PKMN-NTR).");
|
|
|
|
|
QR6Notified = true;
|
|
|
|
|
}
|
|
|
|
|
qr = QR.GetQRImage(pkx.EncryptedBoxData, QR.GetQRServer(pkx.Format));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-02-27 08:40:57 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (qr == null)
|
|
|
|
|
return;
|
2017-02-05 20:55:17 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var sprite = dragout.Image;
|
|
|
|
|
var la = new LegalityAnalysis(pkx);
|
|
|
|
|
if (la.Parsed && pkx.Species != 0)
|
|
|
|
|
{
|
|
|
|
|
var img = la.Valid ? Resources.valid : Resources.warn;
|
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, img, 24, 0, 1);
|
2015-02-26 07:12:38 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
|
|
|
|
string[] r = pkx.QRText;
|
|
|
|
|
string refer = $"PKHeX ({Resources.ProgramVersion})";
|
|
|
|
|
new QR(qr, sprite, pkx, r[0], r[1], r[2], $"{refer} ({pkx.GetType().Name})").ShowDialog();
|
2015-02-25 04:10:47 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
|
|
|
|
private void ClickLegality(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!PKME_Tabs.VerifiedPKM())
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{ SystemSounds.Asterisk.Play(); return; }
|
2014-12-13 22:48:34 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var pk = PreparePKM();
|
2014-12-13 22:48:34 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (pk.Species == 0 || !pk.ChecksumValid)
|
|
|
|
|
{ SystemSounds.Asterisk.Play(); return; }
|
2015-08-07 04:16:25 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ShowLegality(sender, e, pk);
|
2017-06-04 20:35:51 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ShowLegality(object sender, EventArgs e, PKM pk)
|
2017-06-04 20:35:51 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
LegalityAnalysis la = new LegalityAnalysis(pk);
|
|
|
|
|
if (pk.Slot < 0)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKME_Tabs.UpdateLegality(la);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
bool verbose = ModifierKeys == Keys.Control;
|
|
|
|
|
var report = la.Report(verbose);
|
|
|
|
|
if (verbose)
|
2016-07-29 05:54:29 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, report, "Copy report to Clipboard?");
|
|
|
|
|
if (dr == DialogResult.Yes)
|
|
|
|
|
Clipboard.SetText(report);
|
2016-07-29 05:54:29 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
else
|
|
|
|
|
WinFormsUtil.Alert(report);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickClone(object sender, EventArgs e)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!PKME_Tabs.VerifiedPKM()) return; // don't copy garbage to the box
|
|
|
|
|
PKM pk = PKME_Tabs.PreparePKM();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
C_SAV.SetClonesToBox(pk);
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void GetPreview(PictureBox pb, PKM pk = null)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2017-06-19 05:27:40 +00:00
|
|
|
|
if (!IsInitialized)
|
|
|
|
|
return;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pk = pk ?? PreparePKM(false); // don't perform control loss click
|
2016-10-31 02:15:48 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (pb == dragout) dragout.ContextMenuStrip.Enabled = pk.Species != 0 || HaX; // Species
|
|
|
|
|
|
|
|
|
|
pb.Image = pk.Sprite(C_SAV.SAV, -1, -1, true);
|
|
|
|
|
if (pb.BackColor == Color.Red)
|
|
|
|
|
pb.BackColor = Color.Transparent;
|
2014-12-13 22:48:34 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void PKME_Tabs_UpdatePreviewSprite(object sender, EventArgs e) => GetPreview(dragout);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void PKME_Tabs_LegalityChanged(object sender, EventArgs e)
|
2015-09-26 04:56:15 +00:00
|
|
|
|
{
|
2017-06-19 05:27:40 +00:00
|
|
|
|
if (sender == null || HaX)
|
2015-09-26 04:56:15 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
PB_Legal.Visible = false;
|
|
|
|
|
return;
|
2015-09-26 04:56:15 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
PB_Legal.Visible = true;
|
2017-06-19 05:27:40 +00:00
|
|
|
|
PB_Legal.Image = sender as bool? == false ? Resources.warn : Resources.valid;
|
2015-09-26 04:56:15 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void PKME_Tabs_RequestShowdownExport(object sender, EventArgs e) => ClickShowdownExportPKM(sender, e);
|
|
|
|
|
private void PKME_Tabs_RequestShowdownImport(object sender, EventArgs e) => ClickShowdownImportPKM(sender, e);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private SaveFile PKME_Tabs_SaveFileRequested(object sender, EventArgs e) => C_SAV.SAV;
|
|
|
|
|
// Open/Save Array Manipulation //
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private PKM PreparePKM(bool click = true) => PKME_Tabs.PreparePKM(click);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// Drag & Drop Events
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void Main_DragEnter(object sender, DragEventArgs e)
|
2015-09-27 17:00:45 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
else if (e.Data != null) // within
|
|
|
|
|
e.Effect = DragDropEffects.Move;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void Main_DragDrop(object sender, DragEventArgs e)
|
2014-12-14 20:15:53 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2017-06-13 01:15:26 +00:00
|
|
|
|
if (files == null || files.Length == 0)
|
|
|
|
|
return;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
OpenQuick(files[0]);
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
2016-12-16 07:17:17 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Cursor = DefaultCursor;
|
2014-12-14 20:15:53 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Decrypted Export
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void Dragout_MouseDown(object sender, MouseEventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (e.Button == MouseButtons.Left && (ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift))
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ClickQR(sender, e);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (e.Button == MouseButtons.Right)
|
2015-10-15 01:33:51 +00:00
|
|
|
|
return;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!PKME_Tabs.VerifiedPKM())
|
2014-08-07 00:10:29 +00:00
|
|
|
|
return;
|
2014-08-17 01:42:51 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Create Temp File to Drag
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM pkx = PreparePKM();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
bool encrypt = ModifierKeys == Keys.Control;
|
|
|
|
|
string fn = pkx.FileName; fn = fn.Substring(0, fn.LastIndexOf('.'));
|
|
|
|
|
string filename = $"{fn}{(encrypt ? ".ek" + pkx.Format : "." + pkx.Extension)}";
|
|
|
|
|
byte[] dragdata = encrypt ? pkx.EncryptedBoxData : pkx.DecryptedBoxData;
|
|
|
|
|
// Make file
|
|
|
|
|
string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename));
|
|
|
|
|
try
|
2016-10-02 23:48:12 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
File.WriteAllBytes(newfile, dragdata);
|
|
|
|
|
PictureBox pb = (PictureBox)sender;
|
|
|
|
|
C_SAV.M.DragInfo.Source.PKM = pkx;
|
|
|
|
|
C_SAV.M.DragInfo.Cursor = Cursor = new Cursor(((Bitmap)pb.Image).GetHicon());
|
|
|
|
|
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
|
2016-10-02 23:48:12 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
catch (Exception x)
|
|
|
|
|
{ WinFormsUtil.Error("Drag & Drop Error", x); }
|
|
|
|
|
C_SAV.M.SetCursor(DefaultCursor, sender);
|
|
|
|
|
File.Delete(newfile);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void Dragout_DragOver(object sender, DragEventArgs e)
|
2014-12-28 21:56:59 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
e.Effect = DragDropEffects.Move;
|
2014-12-28 21:56:59 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Dragout Display
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void DragoutEnter(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
dragout.BackgroundImage = WinFormsUtil.GetIndex(PKME_Tabs.CB_Species) > 0 ? Resources.slotSet : Resources.slotDel;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Cursor = Cursors.Hand;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void DragoutLeave(object sender, EventArgs e)
|
2015-01-24 19:16:20 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
dragout.BackgroundImage = Resources.slotTrans;
|
|
|
|
|
if (Cursor == Cursors.Hand)
|
|
|
|
|
Cursor = Cursors.Default;
|
2015-01-24 19:16:20 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void DragoutDrop(object sender, DragEventArgs e)
|
2016-05-06 01:52:43 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
|
|
OpenQuick(files[0]);
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
2015-10-24 03:13:32 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Cursor = DefaultCursor;
|
2014-07-27 01:00:17 +00:00
|
|
|
|
}
|
2017-04-05 01:58:32 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private void Main_FormClosing(object sender, FormClosingEventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.SAV.Edited || PKME_Tabs.PKMIsUnsaved)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Any unsaved changes will be lost.", "Are you sure you want to close PKHeX?");
|
|
|
|
|
if (prompt != DialogResult.Yes)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
e.Cancel = true;
|
|
|
|
|
return;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
try { Settings.Default.Save(); }
|
|
|
|
|
catch (Exception x) { File.WriteAllLines("config error.txt", new[] { x.ToString() }); }
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region //// SAVE FILE FUNCTIONS ////
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickExportSAVBAK(object sender, EventArgs e)
|
2016-08-08 05:46:07 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (C_SAV.ExportBackup() && !Directory.Exists(BackupPath))
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PromptBackup();
|
2016-08-08 05:46:07 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickExportSAV(object sender, EventArgs e)
|
2014-12-14 19:06:17 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (!Menu_ExportSAV.Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
C_SAV.ExportSaveFile();
|
2014-12-14 19:06:17 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickSaveFileName(object sender, EventArgs e)
|
2017-06-18 20:02:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (!DetectSaveFile(out string path))
|
|
|
|
|
return;
|
|
|
|
|
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Open save file from the following location?", path) == DialogResult.Yes)
|
|
|
|
|
OpenQuick(path); // load save
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool DetectSaveFile(out string path)
|
2014-12-13 22:48:34 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
string cgse = "";
|
|
|
|
|
string pathCache = CyberGadgetUtil.GetCacheFolder();
|
|
|
|
|
if (Directory.Exists(pathCache))
|
|
|
|
|
cgse = Path.Combine(pathCache);
|
2017-06-18 20:02:02 +00:00
|
|
|
|
if (!PathUtilWindows.DetectSaveFile(out path, cgse))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return path != null && File.Exists(path);
|
2017-04-14 06:05:19 +00:00
|
|
|
|
}
|
2017-06-18 20:02:02 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void PromptBackup()
|
2016-08-05 11:04:56 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.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?")) return;
|
2016-08-26 01:50:51 +00:00
|
|
|
|
|
2017-01-26 06:51:52 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
Directory.CreateDirectory(BackupPath); WinFormsUtil.Alert("Backup folder created!",
|
|
|
|
|
$"If you wish to no longer automatically back up save files, delete the \"{BackupPath}\" folder.");
|
2016-09-14 04:17:07 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
catch (Exception ex) { WinFormsUtil.Error($"Unable to create backup folder @ {BackupPath}", ex); }
|
2014-11-26 04:43:02 +00:00
|
|
|
|
}
|
2016-08-26 01:50:51 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickUndo(object sender, EventArgs e) => C_SAV.ClickUndo();
|
|
|
|
|
private void ClickRedo(object sender, EventArgs e) => C_SAV.ClickRedo();
|
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
|
|
|
|
}
|