2014-06-28 21:22:05 +00:00
|
|
|
|
using System;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
using System.Drawing;
|
2015-03-11 01:44:51 +00:00
|
|
|
|
using System.IO;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
using System.Linq;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX
|
|
|
|
|
{
|
|
|
|
|
public partial class SAV_Wondercard : Form
|
|
|
|
|
{
|
2015-09-21 03:34:09 +00:00
|
|
|
|
public SAV_Wondercard(byte[] wcdata = null)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2015-09-21 03:34:09 +00:00
|
|
|
|
Util.TranslateInterface(this, Main.curlanguage);
|
2015-12-18 05:15:40 +00:00
|
|
|
|
pba = new[]
|
|
|
|
|
{
|
|
|
|
|
PB_Card01, PB_Card02, PB_Card03, PB_Card04, PB_Card05, PB_Card06,
|
|
|
|
|
PB_Card07, PB_Card08, PB_Card09, PB_Card10, PB_Card11, PB_Card12,
|
|
|
|
|
PB_Card13, PB_Card14, PB_Card15, PB_Card16, PB_Card17, PB_Card18,
|
|
|
|
|
PB_Card19, PB_Card20, PB_Card21, PB_Card22, PB_Card23, PB_Card24,
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
foreach (PictureBox pb in pba)
|
|
|
|
|
{
|
|
|
|
|
pb.AllowDrop = true;
|
|
|
|
|
// The PictureBoxes have their own drag&drop event handlers.
|
|
|
|
|
}
|
2014-06-28 21:22:05 +00:00
|
|
|
|
populateWClist();
|
|
|
|
|
populateReceived();
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
2014-06-28 21:22:05 +00:00
|
|
|
|
if (LB_Received.Items.Count > 0)
|
2014-12-10 23:24:34 +00:00
|
|
|
|
LB_Received.SelectedIndex = 0;
|
|
|
|
|
|
2015-03-11 01:44:51 +00:00
|
|
|
|
DragEnter += tabMain_DragEnter;
|
|
|
|
|
DragDrop += tabMain_DragDrop;
|
2015-04-01 00:58:23 +00:00
|
|
|
|
|
2015-12-20 00:25:32 +00:00
|
|
|
|
if (wcdata == null || wcdata.Length != WC6.Size)
|
2015-12-19 06:04:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-04-01 00:58:23 +00:00
|
|
|
|
Array.Copy(wcdata, wondercard_data, wcdata.Length);
|
|
|
|
|
loadwcdata();
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2016-02-11 08:43:44 +00:00
|
|
|
|
private readonly byte[] sav = (byte[])Main.SAV.Data.Clone();
|
2016-02-10 08:33:42 +00:00
|
|
|
|
private byte[] wondercard_data = new byte[WC6.Size];
|
2015-09-21 03:34:09 +00:00
|
|
|
|
private const uint EonTicketConst = 0x225D73C2;
|
2016-01-17 21:27:24 +00:00
|
|
|
|
private readonly PictureBox[] pba;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
|
|
|
|
// Repopulation Functions
|
2015-12-19 06:04:01 +00:00
|
|
|
|
private int currentSlot;
|
2015-12-19 04:48:47 +00:00
|
|
|
|
private void setBackground(int index, Image bg)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 24; i++)
|
|
|
|
|
pba[i].BackgroundImage = index == i ? bg : null;
|
2015-12-19 06:04:01 +00:00
|
|
|
|
currentSlot = index;
|
2015-12-19 04:48:47 +00:00
|
|
|
|
}
|
|
|
|
|
private void removeEmptyWC6s()
|
|
|
|
|
{
|
|
|
|
|
byte[][] ca = new byte[24][];
|
|
|
|
|
for (int i = 0; i < ca.Length; i++)
|
|
|
|
|
ca[i] = sav.Skip(Main.SAV.WondercardData + WC6.Size*i).Take(WC6.Size).ToArray();
|
|
|
|
|
|
|
|
|
|
ca = ca.Where(c => BitConverter.ToUInt16(c, 0) > 0).ToArray();
|
|
|
|
|
for (int i = 0; i < ca.Length; i++)
|
|
|
|
|
ca[i].CopyTo(sav, Main.SAV.WondercardData + WC6.Size * i);
|
|
|
|
|
for (int i = ca.Length; i < 24; i++)
|
|
|
|
|
new byte[WC6.Size].CopyTo(sav, Main.SAV.WondercardData + WC6.Size * i);
|
|
|
|
|
}
|
2014-06-28 21:22:05 +00:00
|
|
|
|
private void populateWClist()
|
|
|
|
|
{
|
2015-12-19 04:48:47 +00:00
|
|
|
|
removeEmptyWC6s();
|
2014-06-28 21:22:05 +00:00
|
|
|
|
for (int i = 0; i < 24; i++)
|
|
|
|
|
{
|
2015-12-20 00:25:32 +00:00
|
|
|
|
int offset = Main.SAV.WondercardData + i * WC6.Size;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
int cardID = BitConverter.ToUInt16(sav, offset);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
pba[i].Image = cardID == 0 ? null : getWCPreviewImage(sav.Skip(Main.SAV.WondercardData + WC6.Size * i).Take(WC6.Size).ToArray());
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void loadwcdata()
|
|
|
|
|
{
|
2014-12-11 06:50:40 +00:00
|
|
|
|
try
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-01-24 18:19:30 +00:00
|
|
|
|
if ((wondercard_data[0x52] & 2) != 0 && DialogResult.Yes ==
|
2015-09-13 04:32:30 +00:00
|
|
|
|
Util.Prompt(MessageBoxButtons.YesNo,
|
2015-12-18 05:15:40 +00:00
|
|
|
|
"Wonder Card is marked as USED and will not be able to be picked up in-game.",
|
2015-09-13 04:32:30 +00:00
|
|
|
|
"Do you want to remove the USED flag so that it is UNUSED?"))
|
|
|
|
|
wondercard_data[0x52] &= 0xFD; // keep all bits but bit1 (11111101)
|
2016-01-24 18:19:30 +00:00
|
|
|
|
|
2015-03-11 04:18:35 +00:00
|
|
|
|
RTB.Text = getWCDescriptionString(wondercard_data);
|
|
|
|
|
PB_Preview.Image = getWCPreviewImage(wondercard_data);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2015-01-11 07:31:51 +00:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2015-12-18 05:15:40 +00:00
|
|
|
|
Util.Error("Loading of data failed... is this really a Wonder Card?", e.ToString());
|
2016-01-24 18:19:30 +00:00
|
|
|
|
wondercard_data = new byte[WC6.Size];
|
2015-01-11 07:31:51 +00:00
|
|
|
|
RTB.Clear();
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void populateReceived()
|
|
|
|
|
{
|
|
|
|
|
LB_Received.Items.Clear();
|
|
|
|
|
for (int i = 1; i < 2048; i++)
|
2016-01-24 18:19:30 +00:00
|
|
|
|
if ((sav[Main.SAV.WondercardFlags + i / 8]>>i%8 & 0x1) == 1)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
LB_Received.Items.Add(i.ToString("0000"));
|
2015-12-19 06:04:01 +00:00
|
|
|
|
if (LB_Received.Items.Count > 0)
|
|
|
|
|
LB_Received.SelectedIndex = 0;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2015-12-19 06:04:01 +00:00
|
|
|
|
private void setCardID(int cardID)
|
|
|
|
|
{
|
|
|
|
|
if (cardID <= 0 || cardID >= 0x100 * 8) return;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
string card = cardID.ToString("0000");
|
|
|
|
|
if (!LB_Received.Items.Contains(card))
|
|
|
|
|
LB_Received.Items.Add(card);
|
|
|
|
|
LB_Received.SelectedIndex = LB_Received.Items.IndexOf(card);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wonder Card IO (.wc6<->window)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
private void B_Import_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-12-18 05:15:40 +00:00
|
|
|
|
OpenFileDialog importwc6 = new OpenFileDialog {Filter = "Wonder Card|*.wc6"};
|
2015-03-12 04:44:12 +00:00
|
|
|
|
if (importwc6.ShowDialog() != DialogResult.OK) return;
|
|
|
|
|
|
|
|
|
|
string path = importwc6.FileName;
|
2015-12-20 00:25:32 +00:00
|
|
|
|
if (new FileInfo(path).Length != WC6.Size)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2015-12-18 05:15:40 +00:00
|
|
|
|
Util.Error("File is not a Wonder Card:", path);
|
2015-03-12 04:44:12 +00:00
|
|
|
|
return;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2015-03-12 04:44:12 +00:00
|
|
|
|
byte[] newwc6 = File.ReadAllBytes(path);
|
|
|
|
|
Array.Copy(newwc6, wondercard_data, newwc6.Length);
|
|
|
|
|
loadwcdata();
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
private void B_Output_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SaveFileDialog outputwc6 = new SaveFileDialog();
|
|
|
|
|
int cardID = BitConverter.ToUInt16(wondercard_data, 0);
|
|
|
|
|
string cardname = Encoding.Unicode.GetString(wondercard_data, 0x2, 0x48);
|
2016-02-01 07:15:54 +00:00
|
|
|
|
outputwc6.FileName = Util.CleanFileName($"{cardID} - {cardname}.wc6");
|
2015-12-18 05:15:40 +00:00
|
|
|
|
outputwc6.Filter = "Wonder Card|*.wc6";
|
2015-03-12 04:44:12 +00:00
|
|
|
|
if (outputwc6.ShowDialog() != DialogResult.OK) return;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2015-03-12 04:44:12 +00:00
|
|
|
|
string path = outputwc6.FileName;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2016-02-01 07:15:54 +00:00
|
|
|
|
if (File.Exists(path)) // File already exists, save a .bak
|
|
|
|
|
File.WriteAllBytes(path + ".bak", File.ReadAllBytes(path));
|
2015-03-12 04:44:12 +00:00
|
|
|
|
|
|
|
|
|
File.WriteAllBytes(path, wondercard_data);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
// Wonder Card RW (window<->sav)
|
|
|
|
|
private void clickView(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
|
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-20 00:25:32 +00:00
|
|
|
|
|
2015-12-19 04:48:47 +00:00
|
|
|
|
setBackground(index, Properties.Resources.slotView);
|
2015-12-20 00:25:32 +00:00
|
|
|
|
int offset = Main.SAV.WondercardData + index * WC6.Size;
|
|
|
|
|
Array.Copy(sav, offset, wondercard_data, 0, WC6.Size);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
loadwcdata();
|
|
|
|
|
}
|
2015-12-19 06:04:01 +00:00
|
|
|
|
private void clickSet(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
|
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-20 00:25:32 +00:00
|
|
|
|
|
|
|
|
|
// Hijack to the latest unfilled slot if index creates interstitial empty slots.
|
|
|
|
|
int lastUnfilled = Array.FindIndex(pba, p => p.Image == null);
|
|
|
|
|
if (lastUnfilled < index)
|
|
|
|
|
index = lastUnfilled;
|
|
|
|
|
|
2015-12-19 04:48:47 +00:00
|
|
|
|
setBackground(index, Properties.Resources.slotSet);
|
2015-12-20 00:25:32 +00:00
|
|
|
|
int offset = Main.SAV.WondercardData + index * WC6.Size;
|
2015-10-24 03:13:32 +00:00
|
|
|
|
if (Main.SAV.ORAS) // ORAS Only
|
2014-11-29 04:43:00 +00:00
|
|
|
|
if (BitConverter.ToUInt16(wondercard_data, 0) == 0x800) // Eon Ticket #
|
|
|
|
|
if (BitConverter.ToUInt16(wondercard_data, 0x68) == 0x2D6) // Eon Ticket
|
2016-02-11 08:43:44 +00:00
|
|
|
|
{ BitConverter.GetBytes(EonTicketConst).CopyTo(sav, Main.SAV.EonTicket); }
|
|
|
|
|
else
|
|
|
|
|
{ Util.Alert("Cannot set Eon Ticket to non OR/AS games."); return; }
|
2016-02-01 07:15:54 +00:00
|
|
|
|
|
2015-12-20 00:25:32 +00:00
|
|
|
|
Array.Copy(wondercard_data, 0, sav, offset, WC6.Size);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
populateWClist();
|
2015-12-19 06:04:01 +00:00
|
|
|
|
setCardID(BitConverter.ToUInt16(wondercard_data, 0));
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2015-12-19 06:04:01 +00:00
|
|
|
|
private void clickDelete(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
|
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
2015-12-20 00:25:32 +00:00
|
|
|
|
setBackground(index, Properties.Resources.slotDel);
|
|
|
|
|
int offset = Main.SAV.WondercardData + index * WC6.Size;
|
|
|
|
|
new byte[WC6.Size].CopyTo(sav, offset);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
populateWClist();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close Window
|
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-10-24 03:13:32 +00:00
|
|
|
|
int offset = Main.SAV.WondercardFlags;
|
2015-01-11 07:31:51 +00:00
|
|
|
|
|
2014-06-28 21:22:05 +00:00
|
|
|
|
// Make sure all of the Received Flags are flipped!
|
2015-01-11 07:31:51 +00:00
|
|
|
|
byte[] wcflags = new byte[0x100];
|
2015-03-11 04:18:35 +00:00
|
|
|
|
foreach (uint cardnum in from object card in LB_Received.Items
|
|
|
|
|
select card.ToString() into cardID
|
|
|
|
|
select Util.ToUInt32(cardID))
|
2016-01-18 01:07:19 +00:00
|
|
|
|
wcflags[(cardnum / 8) & 0xFF] |= (byte)(1 << (byte)(cardnum & 0x7));
|
2015-03-11 04:18:35 +00:00
|
|
|
|
|
2015-01-11 07:31:51 +00:00
|
|
|
|
Array.Copy(wcflags, 0, sav, offset, 0x100);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2015-01-11 07:31:51 +00:00
|
|
|
|
offset += 0x100;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
// Make sure there's no space between wondercards
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 24; i++)
|
2015-12-20 00:25:32 +00:00
|
|
|
|
if (BitConverter.ToUInt16(sav, offset + i * WC6.Size) == 0)
|
2015-01-11 07:31:51 +00:00
|
|
|
|
for (int j = i + 1; j < 24 - i; j++) // Shift everything down
|
2015-12-20 00:25:32 +00:00
|
|
|
|
Array.Copy(sav, offset + j * WC6.Size, sav, offset + (j - 1) * WC6.Size, WC6.Size);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-24 03:13:32 +00:00
|
|
|
|
Array.Copy(sav, Main.SAV.Data, sav.Length);
|
2015-10-24 23:33:44 +00:00
|
|
|
|
Main.SAV.Edited = true;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-11 06:50:40 +00:00
|
|
|
|
// Delete WC Flag
|
2015-12-19 06:04:01 +00:00
|
|
|
|
private void clearRecievedFlag(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
if (LB_Received.SelectedIndex < 0) return;
|
2015-03-12 04:44:12 +00:00
|
|
|
|
|
|
|
|
|
if (LB_Received.Items.Count > 0)
|
|
|
|
|
LB_Received.Items.Remove(LB_Received.Items[LB_Received.SelectedIndex]);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
if (LB_Received.Items.Count > 0)
|
|
|
|
|
LB_Received.SelectedIndex = 0;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2014-12-10 23:24:34 +00:00
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
// Drag & Drop Wonder Cards
|
2014-12-10 23:24:34 +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);
|
2015-01-11 07:31:51 +00:00
|
|
|
|
|
2015-01-31 23:59:23 +00:00
|
|
|
|
// Check for multiple wondercards
|
2015-12-19 06:04:01 +00:00
|
|
|
|
int ctr = currentSlot;
|
2015-01-31 23:59:23 +00:00
|
|
|
|
|
|
|
|
|
if (files.Length == 1)
|
2014-12-10 23:24:34 +00:00
|
|
|
|
{
|
2015-01-31 23:59:23 +00:00
|
|
|
|
string path = files[0]; // open first D&D
|
2015-12-20 00:25:32 +00:00
|
|
|
|
if (new FileInfo(path).Length != WC6.Size)
|
2015-01-31 23:59:23 +00:00
|
|
|
|
{
|
2015-12-19 06:04:01 +00:00
|
|
|
|
Util.Error("File is not a Wonder Card:", path);
|
2015-01-31 23:59:23 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
byte[] newwc6 = File.ReadAllBytes(path);
|
|
|
|
|
Array.Copy(newwc6, wondercard_data, newwc6.Length);
|
|
|
|
|
loadwcdata();
|
|
|
|
|
}
|
2016-02-01 07:15:54 +00:00
|
|
|
|
else if (DialogResult.Yes == Util.Prompt(MessageBoxButtons.YesNo, $"Try to load {files.Length} Wonder Cards starting at Card {ctr + 1}?"))
|
2015-12-19 06:04:01 +00:00
|
|
|
|
foreach (string file in files)
|
2015-01-31 23:59:23 +00:00
|
|
|
|
{
|
2015-12-20 00:25:32 +00:00
|
|
|
|
if (new FileInfo(file).Length != WC6.Size)
|
2015-12-19 06:04:01 +00:00
|
|
|
|
{ Util.Error("File is not a Wonder Card:", file); continue; }
|
2015-01-31 23:59:23 +00:00
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
// Load in WC
|
2016-02-01 07:15:54 +00:00
|
|
|
|
File.ReadAllBytes(file).CopyTo(sav, Main.SAV.WondercardData + WC6.Size*ctr++);
|
|
|
|
|
if (ctr >= 24)
|
|
|
|
|
break;
|
2015-01-31 23:59:23 +00:00
|
|
|
|
}
|
2014-12-10 23:24:34 +00:00
|
|
|
|
}
|
2015-03-11 04:18:35 +00:00
|
|
|
|
|
|
|
|
|
// String Creation
|
|
|
|
|
private string getWCDescriptionString(byte[] data)
|
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
WC6 wc = new WC6(data);
|
|
|
|
|
if (wc.CardID == 0)
|
|
|
|
|
return "Empty Slot. No data!";
|
2015-03-11 04:18:35 +00:00
|
|
|
|
|
2016-02-01 07:15:54 +00:00
|
|
|
|
string s = $"Card #: {wc.CardID.ToString("0000")} - {wc.CardTitle.Trim()}" + Environment.NewLine;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
|
2016-02-01 07:15:54 +00:00
|
|
|
|
switch (wc.CardType)
|
2015-03-11 04:18:35 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
case 1:
|
|
|
|
|
s += "Item: " + Main.itemlist[wc.Item] + Environment.NewLine + "Quantity: " + wc.Quantity;
|
|
|
|
|
return s;
|
|
|
|
|
case 0:
|
|
|
|
|
s +=
|
|
|
|
|
$"{Main.specieslist[wc.Species]} @ {Main.itemlist[wc.HeldItem]} --- {wc.OT} - {wc.TID.ToString("00000")}/{wc.SID.ToString("00000")}" + Environment.NewLine +
|
|
|
|
|
$"{Main.movelist[wc.Move1]} / {Main.movelist[wc.Move2]} / {Main.movelist[wc.Move3]} / {Main.movelist[wc.Move4]}" + Environment.NewLine;
|
|
|
|
|
return s;
|
|
|
|
|
default:
|
|
|
|
|
s += "Unknown Wonder Card Type!";
|
|
|
|
|
return s;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Image getWCPreviewImage(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
Image img;
|
2016-01-23 18:16:07 +00:00
|
|
|
|
WC6 wc = new WC6(data);
|
|
|
|
|
if (wc.IsPokémon)
|
|
|
|
|
img = PKX.getSprite(wc.Species, wc.Form, wc.Gender, wc.HeldItem, wc.IsEgg, wc.PIDType == 2);
|
|
|
|
|
else if (wc.IsItem)
|
|
|
|
|
img = (Image)(Properties.Resources.ResourceManager.GetObject("item_" + BitConverter.ToUInt16(data, 0x68)) ?? Properties.Resources.unknown);
|
|
|
|
|
else
|
|
|
|
|
img = Properties.Resources.unknown;
|
|
|
|
|
|
|
|
|
|
if (wc.GiftUsed)
|
|
|
|
|
img = Util.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3);
|
2015-03-11 04:18:35 +00:00
|
|
|
|
return img;
|
|
|
|
|
}
|
|
|
|
|
private void L_QR_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (ModifierKeys == Keys.Alt)
|
|
|
|
|
{
|
2015-03-14 02:59:51 +00:00
|
|
|
|
byte[] wc = Util.getQRData();
|
2016-01-02 06:03:41 +00:00
|
|
|
|
if (wc == null) return;
|
2016-01-17 21:27:24 +00:00
|
|
|
|
if (wc.Length != WC6.Size) { Util.Alert("Decoded data not 0x108 bytes.",
|
|
|
|
|
$"QR Data Size: 0x{wc.Length.ToString("X")}"); }
|
2015-03-14 02:59:51 +00:00
|
|
|
|
else try
|
2015-03-11 04:18:35 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
wc.CopyTo(wondercard_data, 0);
|
2015-03-14 02:59:51 +00:00
|
|
|
|
loadwcdata();
|
2015-03-11 04:18:35 +00:00
|
|
|
|
}
|
|
|
|
|
catch { Util.Alert("Error loading wondercard data."); }
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-01-18 01:07:19 +00:00
|
|
|
|
if (wondercard_data.SequenceEqual(new byte[wondercard_data.Length]))
|
2015-09-21 03:34:09 +00:00
|
|
|
|
{ Util.Alert("No wondercard data found in loaded slot!"); return; }
|
2015-04-05 17:48:18 +00:00
|
|
|
|
if (BitConverter.ToUInt16(wondercard_data, 0x68) == 726 && wondercard_data[0x51] == 1)
|
2015-12-19 06:04:01 +00:00
|
|
|
|
{ Util.Alert("Eon Ticket Wonder Cards will not function properly", "Inject to the save file instead."); return; }
|
2015-03-11 04:18:35 +00:00
|
|
|
|
// Prep data
|
|
|
|
|
byte[] wcdata = wondercard_data;
|
|
|
|
|
// Ensure size
|
2015-12-20 00:25:32 +00:00
|
|
|
|
Array.Resize(ref wcdata, WC6.Size);
|
2015-03-11 04:18:35 +00:00
|
|
|
|
// Setup QR
|
|
|
|
|
const string server = "http://lunarcookies.github.io/wc.html#";
|
2015-03-14 02:59:51 +00:00
|
|
|
|
Image qr = Util.getQRImage(wcdata, server);
|
|
|
|
|
if (qr == null) return;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
|
|
|
|
|
string desc = getWCDescriptionString(wondercard_data);
|
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
new QR(qr, PB_Preview.Image, desc, "", "", "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog();
|
2015-03-11 04:18:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-18 05:15:40 +00:00
|
|
|
|
|
|
|
|
|
private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2015-12-19 06:04:01 +00:00
|
|
|
|
if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift ||
|
|
|
|
|
ModifierKeys == (Keys.Control | Keys.Alt))
|
2015-12-18 05:15:40 +00:00
|
|
|
|
{
|
2015-12-19 06:04:01 +00:00
|
|
|
|
switch (ModifierKeys)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Control: clickView(sender, e); break;
|
|
|
|
|
case Keys.Shift: clickSet(sender, e); break;
|
|
|
|
|
case Keys.Alt: clickDelete(sender, e); break;
|
|
|
|
|
}
|
|
|
|
|
return;
|
2015-12-18 05:15:40 +00:00
|
|
|
|
}
|
2016-01-06 02:16:58 +00:00
|
|
|
|
PictureBox pb = (PictureBox)sender;
|
2015-12-19 06:04:01 +00:00
|
|
|
|
if (pb.Image == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (e.Button != MouseButtons.Left || e.Clicks != 1) return;
|
|
|
|
|
|
2016-02-01 07:15:54 +00:00
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-19 06:17:01 +00:00
|
|
|
|
wc_slot = index;
|
2015-12-19 06:04:01 +00:00
|
|
|
|
// Create Temp File to Drag
|
|
|
|
|
Cursor.Current = Cursors.Hand;
|
|
|
|
|
|
|
|
|
|
// Prepare Data
|
|
|
|
|
byte[] dragdata = sav.Skip(Main.SAV.WondercardData + WC6.Size * index).Take(WC6.Size).ToArray();
|
|
|
|
|
WC6 card = new WC6(dragdata);
|
2016-02-01 07:15:54 +00:00
|
|
|
|
string filename = Util.CleanFileName($"{card.CardID.ToString("0000")} - {card.CardTitle}.wc6");
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException x)
|
|
|
|
|
{ Util.Error("Drag & Drop Error:", x.ToString()); }
|
|
|
|
|
File.Delete(newfile);
|
2015-12-19 06:17:01 +00:00
|
|
|
|
wc_slot = -1;
|
2015-12-18 05:15:40 +00:00
|
|
|
|
}
|
2015-12-19 06:04:01 +00:00
|
|
|
|
private void pbBoxSlot_DragDrop(object sender, DragEventArgs e)
|
2015-12-18 05:15:40 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
|
|
|
|
// Hijack to the latest unfilled slot if index creates interstitial empty slots.
|
|
|
|
|
int lastUnfilled = Array.FindIndex(pba, p => p.Image == null);
|
|
|
|
|
if (lastUnfilled < index)
|
|
|
|
|
index = lastUnfilled;
|
|
|
|
|
|
|
|
|
|
// Check for In-Dropped files (PKX,SAV,ETC)
|
|
|
|
|
|
2015-12-19 06:17:01 +00:00
|
|
|
|
if (wc_slot == -1)
|
|
|
|
|
{
|
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
2015-12-19 06:17:01 +00:00
|
|
|
|
if (files.Length < 1 || new FileInfo(files[0]).Length != WC6.Size)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
byte[] wcdata = File.ReadAllBytes(files[0]);
|
|
|
|
|
wcdata.CopyTo(sav, Main.SAV.WondercardData + WC6.Size * index);
|
|
|
|
|
wcdata.CopyTo(wondercard_data, 0);
|
|
|
|
|
loadwcdata();
|
|
|
|
|
setCardID(BitConverter.ToUInt16(wcdata, 0));
|
|
|
|
|
}
|
|
|
|
|
else // Swap Data
|
|
|
|
|
{
|
|
|
|
|
// Check to see if they copied beyond blank slots.
|
|
|
|
|
if (index > Math.Max(wc_slot, lastUnfilled - 1))
|
|
|
|
|
index = Math.Max(wc_slot, lastUnfilled - 1);
|
|
|
|
|
byte[] s1 = sav.Skip(Main.SAV.WondercardData + WC6.Size * index).Take(WC6.Size).ToArray();
|
|
|
|
|
byte[] s2 = sav.Skip(Main.SAV.WondercardData + WC6.Size * wc_slot).Take(WC6.Size).ToArray();
|
|
|
|
|
s1.CopyTo(sav, Main.SAV.WondercardData + WC6.Size * wc_slot);
|
|
|
|
|
s2.CopyTo(sav, Main.SAV.WondercardData + WC6.Size * index);
|
|
|
|
|
}
|
2015-12-19 06:04:01 +00:00
|
|
|
|
setBackground(index, Properties.Resources.slotView);
|
2015-12-19 06:17:01 +00:00
|
|
|
|
populateWClist();
|
2015-12-18 05:15:40 +00:00
|
|
|
|
}
|
2015-12-19 06:04:01 +00:00
|
|
|
|
private void pbBoxSlot_DragEnter(object sender, DragEventArgs e)
|
2015-12-18 05:15:40 +00:00
|
|
|
|
{
|
2015-12-19 06:04:01 +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;
|
2015-12-18 05:15:40 +00:00
|
|
|
|
}
|
2015-12-19 06:17:01 +00:00
|
|
|
|
private int wc_slot = -1;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2014-12-15 00:50:15 +00:00
|
|
|
|
}
|