Danny0317

Untitled

Jul 18th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Xml;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14. public partial class Form1 : Form
  15. {
  16. String abiltiesS;
  17. String BS;
  18. int BaseStats;
  19. int choose;
  20.  
  21. public Form1()
  22. {
  23. InitializeComponent();
  24. }
  25.  
  26. private void fileToolStripMenuItem_Click(object sender, EventArgs e)
  27. {
  28.  
  29. }
  30. OpenFileDialog ofd = new OpenFileDialog();
  31. string path;
  32.  
  33.  
  34.  
  35. private void loadROMToolStripMenuItem_Click(object sender, EventArgs e)
  36. {
  37. string HP = string.Empty;
  38. ofd.Filter = "GBA File(*.gba)|*.gba";
  39. if (ofd.ShowDialog() == DialogResult.OK)
  40. {
  41. BinaryReader br = new BinaryReader(File.OpenRead(ofd.FileName));
  42. br.BaseStream.Seek(0xAC, SeekOrigin.Begin);
  43. String Gamecode = Encoding.UTF8.GetString(br.ReadBytes(4));
  44. if (Gamecode != "BPEE")
  45. {
  46. MessageBox.Show("Unsupported ROM", "Error.");
  47. System.Windows.Forms.Application.Exit();
  48. }
  49. else
  50. {
  51. HPl.Enabled = true;
  52. HPtb.Enabled = true;
  53. Atl.Enabled = true;
  54. Attb.Enabled = true;
  55. Defl.Enabled = true;
  56. Deftb.Enabled = true;
  57. SpAl.Enabled = true;
  58. SpAtb.Enabled = true;
  59. SpDl.Enabled = true;
  60. SpDtb.Enabled = true;
  61. Spl.Enabled = true;
  62. Sptb.Enabled = true;
  63. Names.Enabled = true;
  64. Loaded.Text = "You have loaded: Pokemon Emerald BPEE";
  65. Loaded.Enabled = true;
  66. Loaded.Visible = true;
  67. saveROMToolStripMenuItem.Enabled = true;
  68. XmlDocument config = new XmlDocument();
  69. string directory = System.IO.Directory.GetCurrentDirectory() + "/config.xml";
  70. config.Load(directory);
  71. String pokesS = (config.SelectSingleNode("root/numberofpokes").InnerText);
  72. int PokeAmount = Int32.Parse(pokesS);
  73. abiltiesS = (config.SelectSingleNode("root/numberofabilities").InnerText);
  74. int abilities = Int32.Parse(abiltiesS);
  75. BS = (config.SelectSingleNode("root/pokebasestats").InnerText);
  76. BaseStats = Int32.Parse(BS) + 28;
  77. path = ofd.FileName;
  78. for (int i = 1; i < Int32.Parse((config.SelectSingleNode("root/numberofpokes")).InnerText) + 1; i++)
  79. {
  80. Names.Items.Add(i);
  81. }
  82. }
  83. }
  84. else
  85. {
  86. MessageBox.Show("File load cancelled.", "Error.");
  87. }
  88.  
  89. }
  90.  
  91. private void Names_SelectedIndexChanged(object sender, EventArgs e)
  92. {
  93.  
  94. }
  95.  
  96. private void HPtb_TextChanged(object sender, EventArgs e)
  97. {
  98.  
  99. }
  100.  
  101. private void Atl_Click(object sender, EventArgs e)
  102. {
  103.  
  104. }
  105.  
  106. private void Sptb_TextChanged(object sender, EventArgs e)
  107. {
  108.  
  109. }
  110.  
  111. private void textBox1_TextChanged(object sender, EventArgs e)
  112. {
  113. }
  114. String HP;
  115.  
  116. private int load (int have)
  117. {
  118. choose = Names.Items.IndexOf(Names.SelectedItem);
  119. BinaryReader br = new BinaryReader(File.OpenRead(ofd.FileName));
  120. br.BaseStream.Seek(BaseStats + (28 * choose), SeekOrigin.Begin);
  121. HPtb.Text = br.ReadBytes(1)[0].ToString();
  122. br.BaseStream.Seek(BaseStats + (28 * choose) + 1, SeekOrigin.Begin);
  123. Attb.Text = br.ReadBytes(1)[0].ToString();
  124. br.BaseStream.Seek(BaseStats + (28 * choose) + 2, SeekOrigin.Begin);
  125. Deftb.Text = br.ReadBytes(1)[0].ToString();
  126. br.BaseStream.Seek(BaseStats + (28 * choose) + 3, SeekOrigin.Begin);
  127. Sptb.Text = br.ReadBytes(1)[0].ToString();
  128. br.BaseStream.Seek(BaseStats + (28 * choose) + 4, SeekOrigin.Begin);
  129. SpAtb.Text = br.ReadBytes(1)[0].ToString();
  130. br.BaseStream.Seek(BaseStats + (28 * choose) + 5, SeekOrigin.Begin);
  131. SpDtb.Text = br.ReadBytes(1)[0].ToString();
  132. br.Close();
  133. 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);
  134. BSTl.Enabled = true;
  135. BSTl.Text = "Base Stat Total: " + BST;
  136. return have;
  137. }
  138.  
  139. private void button1_Click(object sender, EventArgs e)
  140. {
  141. int have = 0;
  142. load(have);
  143. }
  144.  
  145. private int save (int have)
  146. {
  147. choose = Names.Items.IndexOf(Names.SelectedItem);
  148. BinaryWriter black = new BinaryWriter(File.OpenWrite(ofd.FileName));
  149. //black.BaseStream.Position = BaseStats + ((Int32.Parse(textBox1.Text) - 1) * 0x1C);
  150. black.BaseStream.Position = BaseStats + (choose * 0x1C);
  151. String[] statbox = new String[] { HPtb.Text, Attb.Text, Deftb.Text, Sptb.Text, SpAtb.Text, SpDtb.Text };
  152. foreach (String element in statbox)
  153. {
  154. black.Write((byte)int.Parse(element));
  155. }
  156. black.Close();
  157. return have;
  158. }
  159.  
  160.  
  161. private void button2_Click(object sender, EventArgs e)
  162. {
  163. int have = 0;
  164. save(have);
  165. }
  166. private void label1_Click(object sender, EventArgs e)
  167. {
  168.  
  169.  
  170. }
  171.  
  172. private void saveROMToolStripMenuItem_Click(object sender, EventArgs e)
  173. {
  174. int have = 0;
  175. save(have);
  176. }
  177.  
  178. private void Form1_Load(object sender, EventArgs e)
  179. {
  180.  
  181. }
  182.  
  183. private void Names_SelectedIndexChanged_1(object sender, EventArgs e)
  184. {
  185. int have = 0;
  186. load(have);
  187. }
  188.  
  189. private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  190. {
  191. //br.Close();
  192. //black.Close();
  193. }
  194.  
  195. }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment