PKHeX/SAV/SAV_EventFlagsORAS.cs

223 lines
7.5 KiB
C#
Raw Normal View History

2014-06-28 21:22:05 +00:00
using System;
2014-07-31 22:06:48 +00:00
using System.Collections;
2014-06-28 21:22:05 +00:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
2014-07-31 22:06:48 +00:00
using System.IO;
2014-06-28 21:22:05 +00:00
namespace PKHeX
{
2014-11-22 03:47:30 +00:00
public partial class SAV_EventFlagsORAS : Form
2014-06-28 21:22:05 +00:00
{
2014-11-22 03:47:30 +00:00
public SAV_EventFlagsORAS(Form1 frm1)
2014-06-28 21:22:05 +00:00
{
InitializeComponent();
m_parent = frm1;
2014-07-31 22:06:48 +00:00
savshift = 0x7F000 * m_parent.savindex;
Setup();
nud.Text = "0"; // Prompts an update for flag 0.
2014-11-27 07:06:25 +00:00
MT_Ash.Text = BitConverter.ToUInt16(m_parent.savefile, savshift + 0x14A78 + 0x5400).ToString();
2014-06-28 21:22:05 +00:00
}
Form1 m_parent;
2014-07-31 22:06:48 +00:00
public int savshift;
bool setup = true;
public CheckBox[] chka;
public bool[] flags = new bool[3072];
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();
}
private void B_Save_Click(object sender, EventArgs e)
{
// Gather Updated Flags
for (int i = 0; i < chka.Length; i++)
flags[getFlagNum(chka[i])] = chka[i].Checked;
byte[] data = new byte[flags.Length / 8];
for (int i = 0; i < flags.Length; i++)
if (flags[i])
data[i/8] |= (byte)(1 << i%8);
2014-11-22 03:47:30 +00:00
2014-07-31 22:06:48 +00:00
Array.Copy(data, 0, m_parent.savefile, 0x1A0FC + savshift, 0x180);
2014-11-27 07:06:25 +00:00
// Copy back Volcanic Ash counter
Array.Copy(BitConverter.GetBytes(Util.ToUInt32(MT_Ash)), 0, m_parent.savefile, 0x14A78 + 0x5400 + savshift, 2);
2014-07-31 22:06:48 +00:00
this.Close();
}
private void Setup()
{
// Fill Bit arrays
chka = new CheckBox[] {
2014-11-25 03:53:10 +00:00
flag_0173,flag_2811, // Raikou
flag_0174,flag_2812, // Entei
flag_0175,flag_2813, // Suicune
2014-11-25 07:19:58 +00:00
flag_0209,flag_2814, // Lugia
flag_0208,flag_2815, // Ho-Oh
2014-11-25 03:53:10 +00:00
flag_0179,flag_2816, // Uxie
flag_0180,flag_2817, // Mesprit
flag_0181,flag_2818, // Azelf
2014-11-25 07:19:58 +00:00
flag_2819, // Dialga
flag_2820, // Palkia
flag_0260,flag_2821, // Heatran
2014-11-26 00:17:46 +00:00
flag_0252,flag_2822, // Regigigas
2014-11-25 07:19:58 +00:00
flag_2823, // Giratina
2014-11-26 04:46:42 +00:00
flag_0172,flag_2824, // Cresselia
2014-11-22 07:27:30 +00:00
flag_0176,flag_2825, // Cobalion
2014-11-26 03:55:46 +00:00
flag_0177,flag_2826, // Terrakion
2014-11-25 07:19:58 +00:00
// Trio 2827?
flag_2828, // Tornadus
flag_2829, // Thundurus
flag_0182,flag_2830, // Reshiram
flag_0183,flag_2831, // Zekrom
flag_2832, // Landorus
2014-11-25 03:53:10 +00:00
flag_0184,flag_2833, // Kyurem
2014-11-25 07:19:58 +00:00
// ?? 2834
// ?? 2835
flag_0956,flag_2836, // Regirock
flag_0957,flag_2837, // Regice
flag_0958,flag_2838, // Registeel
flag_0648,flag_2839, // Groudon
flag_0647,flag_2840, // Kyogre
// Lati@southern
flag_0945,flag_2842, // Deoxys
// Cresselia, Regigigas
// Terrakion, Virizion
2014-11-25 03:53:10 +00:00
2014-11-26 03:55:46 +00:00
// Maison
flag_0284,flag_0285,flag_0286,flag_0287,flag_0288, // Statuettes
flag_0289,flag_0290,flag_0291,flag_0292,flag_0293, // Super Unlocks
//flag_0675, // Chatelaine 50
//flag_2546, // Pokedex
2014-07-31 22:06:48 +00:00
};
int offset = 0x1A0FC + savshift;
byte[] data = new Byte[0x180];
Array.Copy(m_parent.savefile, offset, data, 0, 0x180);
BitArray BitRegion = new BitArray(data);
BitRegion.CopyTo(flags, 0);
2014-06-28 21:22:05 +00:00
2014-07-31 22:06:48 +00:00
// Populate Flags
setup = true;
popFlags();
}
private void popFlags()
{
if (setup)
{
for (int i = 0; i < chka.Length; i++)
chka[i].Checked = flags[getFlagNum(chka[i])];
changeCustomFlag(null, null);
}
}
2014-08-05 01:48:22 +00:00
2014-07-31 22:06:48 +00:00
private int getFlagNum(CheckBox chk)
{
try
{
string source = chk.Name;
return Convert.ToInt32(source.Substring(Math.Max(0, source.Length - 4)));
}
catch { return 0; }
}
private void changeCustomBool(object sender, EventArgs e)
{
flags[(int)nud.Value] = CHK_CustomFlag.Checked;
popFlags();
}
private void changeCustomFlag(object sender, EventArgs e)
2014-06-28 21:22:05 +00:00
{
int flag = (int)nud.Value;
2014-07-31 22:06:48 +00:00
if (flag >= 3072)
2014-06-28 21:22:05 +00:00
{
CHK_CustomFlag.Checked = false;
2014-07-31 22:06:48 +00:00
CHK_CustomFlag.Enabled = false;
2014-06-28 21:22:05 +00:00
nud.BackColor = Color.Red;
}
else
{
2014-07-31 22:06:48 +00:00
CHK_CustomFlag.Enabled = true;
2014-06-28 21:22:05 +00:00
nud.BackColor = Color.White;
2014-07-31 22:06:48 +00:00
CHK_CustomFlag.Checked = flags[flag];
2014-06-28 21:22:05 +00:00
}
}
2014-08-05 01:48:22 +00:00
private void changeCustomFlag(object sender, KeyEventArgs e)
{
changeCustomFlag(null, (EventArgs)e);
}
2014-07-31 22:06:48 +00:00
private void toggleFlag(object sender, EventArgs e)
2014-06-28 21:22:05 +00:00
{
2014-07-31 22:06:48 +00:00
flags[getFlagNum((CheckBox)(sender))] = ((CheckBox)(sender)).Checked;
changeCustomFlag(sender, e);
2014-06-28 21:22:05 +00:00
}
2014-07-31 22:06:48 +00:00
private void changeSAV(object sender, EventArgs e)
{
if (TB_NewSAV.Text.Length > 0 && TB_OldSAV.Text.Length > 0)
diffSaves();
}
private void diffSaves()
{
BitArray oldBits = new BitArray(olddata);
BitArray newBits = new BitArray(newdata);
2014-06-28 21:22:05 +00:00
2014-07-31 22:06:48 +00:00
for (int i = 0; i < oldBits.Length; i++)
if (oldBits[i] != newBits[i])
if (newBits[i])
TB_IsSet.AppendText(i.ToString("0000") + ",");
else
TB_UnSet.AppendText(i.ToString("0000") + ",");
2014-06-28 21:22:05 +00:00
}
2014-07-31 22:06:48 +00:00
private byte[] olddata = new Byte[0x180];
private byte[] newdata = new Byte[0x180];
private void openSAV(object sender, EventArgs e)
2014-06-28 21:22:05 +00:00
{
2014-07-31 22:06:48 +00:00
byte[] eventflags = new byte[0x180];
string path = "";
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
path = ofd.FileName;
FileInfo fi = new FileInfo(path);
if (fi.Length == 0x100000)
{
byte[] data = File.ReadAllBytes(path);
Array.Copy(data, 0x1A0FC, eventflags, 0, 0x180);
}
2014-11-22 03:47:30 +00:00
else if (fi.Length == 0x76000)
2014-07-31 22:06:48 +00:00
{
byte[] data = File.ReadAllBytes(path);
Array.Copy(data, 0x1A0FC - 0x5400, eventflags, 0, 0x180);
}
else
{ MessageBox.Show("Invalid SAV Size", "Error"); return; }
2014-07-31 22:06:48 +00:00
}
else
return;
2014-07-31 22:06:48 +00:00
Button bs = (Button)sender;
if (bs.Name == "B_LoadOld")
{
Array.Copy(eventflags, olddata, 0x180);
TB_OldSAV.Text = path;
}
else
{
Array.Copy(eventflags, newdata, 0x180);
TB_NewSAV.Text = path;
}
2014-06-28 21:22:05 +00:00
}
}
}