Firstly, here is my method to write to my specified offsets, I've went through the debugging process and everything is getting set accordingly.
Example, I've set the pokemonValue to 190
it is then converted to 0xBE
and then written to the offset at offsetArray[i] == 0x1D104
The expected behavior is that it will simply write 0xBE at this offset. It does not do that. instead it writes 0x02 0x42 0x45
at 0x1D104 0x1D105 0x1D106
respectively.
public void writeStarterPokemon(long[] offsetArray, BinaryWriter writer, int pokemonValue)
{
string hexVal = "";
for (int i = 0; i < offsetArray.Length; i++)
{
writer.BaseStream.Position = offsetArray[i];
hexVal = string.Format("{0:X}", pokemonValue); // pokemonValue is a decimal ranging from 0-255;
MessageBox.Show(string.Format("Hex val: 0x{0:1X}, Offset: 0x{1:X5}", hexVal, offsetArray[i])); // to see if the values are correct
writer.Write(hexVal);
writer.Flush();
}
}
Here is an example of the array used and the how the method is called
private long[] squirtleOffsets = new long[] { 0x1D104, 0x1D11F, 0x24BA5, 0x26FBC};
writeStarterPokemon(sqrtlOffsets, writer, NameList.SelectedIndex);
// NameList is the name of my comboBox populated with pokemon data, 0-255
I've checked my offsets and they are correct and earlier in the program I read from them which works as it is intended. So I'm unsure why this isn't working correctly or rather setting the data to be incorrect.
If you want to write specific bytes you need to use the byte[]
etc APIs. If you use the Write(string)
API, it encodes extra data for the string length etc, which you presumably don't want. Frankly, BinaryWriter
is not very useful in most scenarios - you're better off writing to a Stream
etc, which will limit you to APIs that do what you expect.