E
E
Eugene Chefranov2020-05-21 12:24:21
hex
Eugene Chefranov, 2020-05-21 12:24:21

How to read and edit HEX value?

There is a file (game save) and there is a known location (offset) of the value I need.
5ec6476d88174318124279.png
And it seems like there is a code for reading and writing the value:

short skill = 0;

            using (BinaryReader br = new BinaryReader(File.OpenRead("Player.chr")))
            {
                br.BaseStream.Position = 0x6F0; 
                label1.Text = br.ReadInt32().ToString();
            }

            using (BinaryWriter bw = new BinaryWriter(File.OpenWrite("Player.chr")))
            {
                bw.Seek(0x6F0, SeekOrigin.Begin); 

                bw.Write(skill + 10); // добавим 10 очков умений
            }


The question is, do I have the correct code for working with offset and how to work with offset (on the screen in integer format, but in the code as hex and I don’t see the range)? If you can give an example, but based on the screen data (offset 4863-4866. Length 4, Int)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2020-05-22
@Chefranov

The shift when reading is indicated in your code by - Here you can also write in decimal system
br.BaseStream.Position = 0x6F0;

using (var file = File.Open("Player.chr", FileMode.Open, FileAccess.ReadWrite))
{
    int skillPoints;
    using (var br = new BinaryReader(file))
    {
        br.BaseStream.Position = 4863; //0x12FF
        skillPoints = br.ReadInt32();
    }

    using (var bw = new BinaryWriter(file))
    {
        bw.BaseStream.Position = 4863; //0x12FF
        bw.Write(skillPoints + 10);
    }
}

N
Nikolai Vasilchuk, 2014-03-06
@ERAFY

The code is executed in onLoad. Did you forget to wrap it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question