Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Xml;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- String abiltiesS;
- String BS;
- int BaseStats;
- int choose;
- public Form1()
- {
- InitializeComponent();
- }
- private void fileToolStripMenuItem_Click(object sender, EventArgs e)
- {
- }
- OpenFileDialog ofd = new OpenFileDialog();
- string path;
- private void loadROMToolStripMenuItem_Click(object sender, EventArgs e)
- {
- string HP = string.Empty;
- ofd.Filter = "GBA File(*.gba)|*.gba";
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- BinaryReader br = new BinaryReader(File.OpenRead(ofd.FileName));
- br.BaseStream.Seek(0xAC, SeekOrigin.Begin);
- String Gamecode = Encoding.UTF8.GetString(br.ReadBytes(4));
- if (Gamecode != "BPEE")
- {
- MessageBox.Show("Unsupported ROM", "Error.");
- System.Windows.Forms.Application.Exit();
- }
- else
- {
- HPl.Enabled = true;
- HPtb.Enabled = true;
- Atl.Enabled = true;
- Attb.Enabled = true;
- Defl.Enabled = true;
- Deftb.Enabled = true;
- SpAl.Enabled = true;
- SpAtb.Enabled = true;
- SpDl.Enabled = true;
- SpDtb.Enabled = true;
- Spl.Enabled = true;
- Sptb.Enabled = true;
- Names.Enabled = true;
- Loaded.Text = "You have loaded: Pokemon Emerald BPEE";
- Loaded.Enabled = true;
- Loaded.Visible = true;
- saveROMToolStripMenuItem.Enabled = true;
- XmlDocument config = new XmlDocument();
- string directory = System.IO.Directory.GetCurrentDirectory() + "/config.xml";
- config.Load(directory);
- String pokesS = (config.SelectSingleNode("root/numberofpokes").InnerText);
- int PokeAmount = Int32.Parse(pokesS);
- abiltiesS = (config.SelectSingleNode("root/numberofabilities").InnerText);
- int abilities = Int32.Parse(abiltiesS);
- BS = (config.SelectSingleNode("root/pokebasestats").InnerText);
- BaseStats = Int32.Parse(BS) + 28;
- path = ofd.FileName;
- for (int i = 1; i < Int32.Parse((config.SelectSingleNode("root/numberofpokes")).InnerText) + 1; i++)
- {
- Names.Items.Add(i);
- }
- }
- }
- else
- {
- MessageBox.Show("File load cancelled.", "Error.");
- }
- }
- private void Names_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void HPtb_TextChanged(object sender, EventArgs e)
- {
- }
- private void Atl_Click(object sender, EventArgs e)
- {
- }
- private void Sptb_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- String HP;
- private int load (int have)
- {
- choose = Names.Items.IndexOf(Names.SelectedItem);
- BinaryReader br = new BinaryReader(File.OpenRead(ofd.FileName));
- br.BaseStream.Seek(BaseStats + (28 * choose), SeekOrigin.Begin);
- HPtb.Text = br.ReadBytes(1)[0].ToString();
- br.BaseStream.Seek(BaseStats + (28 * choose) + 1, SeekOrigin.Begin);
- Attb.Text = br.ReadBytes(1)[0].ToString();
- br.BaseStream.Seek(BaseStats + (28 * choose) + 2, SeekOrigin.Begin);
- Deftb.Text = br.ReadBytes(1)[0].ToString();
- br.BaseStream.Seek(BaseStats + (28 * choose) + 3, SeekOrigin.Begin);
- Sptb.Text = br.ReadBytes(1)[0].ToString();
- br.BaseStream.Seek(BaseStats + (28 * choose) + 4, SeekOrigin.Begin);
- SpAtb.Text = br.ReadBytes(1)[0].ToString();
- br.BaseStream.Seek(BaseStats + (28 * choose) + 5, SeekOrigin.Begin);
- SpDtb.Text = br.ReadBytes(1)[0].ToString();
- br.Close();
- int BST = Int32.Parse(HPtb.Text) + Int32.Parse(Attb.Text) + Int32.Parse(Deftb.Text) + Int32.Parse(Sptb.Text) + Int32.Parse(SpAtb.Text) + Int32.Parse(SpDtb.Text);
- BSTl.Enabled = true;
- BSTl.Text = "Base Stat Total: " + BST;
- return have;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- int have = 0;
- load(have);
- }
- private int save (int have)
- {
- choose = Names.Items.IndexOf(Names.SelectedItem);
- BinaryWriter black = new BinaryWriter(File.OpenWrite(ofd.FileName));
- //black.BaseStream.Position = BaseStats + ((Int32.Parse(textBox1.Text) - 1) * 0x1C);
- black.BaseStream.Position = BaseStats + (choose * 0x1C);
- String[] statbox = new String[] { HPtb.Text, Attb.Text, Deftb.Text, Sptb.Text, SpAtb.Text, SpDtb.Text };
- foreach (String element in statbox)
- {
- black.Write((byte)int.Parse(element));
- }
- black.Close();
- return have;
- }
- private void button2_Click(object sender, EventArgs e)
- {
- int have = 0;
- save(have);
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void saveROMToolStripMenuItem_Click(object sender, EventArgs e)
- {
- int have = 0;
- save(have);
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void Names_SelectedIndexChanged_1(object sender, EventArgs e)
- {
- int have = 0;
- load(have);
- }
- private void exitToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //br.Close();
- //black.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment