PDA

View Full Version : File Editing (Binary/Hex) with Qt 4.6.2



RH-00
24th September 2010, 23:12
What I'm basically trying to do is create a save game editor for Dynasty Warriors 6 using Qt. The save file itself is about 700kb large (might be a bit more, don't have a sample w/ me). I know the exact offsets of the different values I'm looking for (say experience), and I know how big they are (32-bit unsigned integer in big endian format). However, every time I try to extract these values and place them into a SpinBox control, I get nothing.

Basically what I do is this:

1) Establish QFile object as normal (use a QString with the QFileDialog::getOpenFileName() function).

2) Create a temporary QByteArray to store the values (the array is flushed for each value).

3) Make sure everything is ok with the QFile object, checking the isOpen() and isReadable() properties and so on.

4) Seek to the offset (ie 0x1240).

5) Use the Read() function to read 4 bytes into the temporary array.

6) Set the SpinBox's current value to the array's toUInt() function. (Considering there's no toQInt32() function, pity.)

7) Display a message confirming completion of the process.

It seems to get through all the steps just fine, and even shows the confirmation message, but the SpinBox doesn't go from 0 to 99,999 like it would from my save game, because the value at offset 0x1240 is 99,999; I can crack it open in my hex editor and stare it right in the face.

I've also tried using the readAll() function to read the file into a QByteArray serving as a buffer (inefficient and expensive, I know), but even that doesn't work.

I've looked into the temporary array during debugging, and it shows the proper value (0x0001869F), but it doesn't show on the SpinBox, it doesn't show on a TextBox, or a QMessageBox.

In short, what in Petraeus' name is going on here? I swear, Qt has it out for me... :mad:

RH-00
1st October 2010, 22:49
Quick addendum to my above post. The save file isn't 700+ kb, its only 206kb (208kb on disk). I've tried using a QDataStream, as well, with the same results as if I were using the above method. The only thing I haven't tried is using the i/fstreams in <iostream>. I'll test that and post my results, if any...

squidge
1st October 2010, 22:57
If you call toUint on the text "1234", it will return the number 1234.

Your 32-bit unsigned number stored in a QByteArray clearly isn't text, so toUint clearly isn't going to do the job.

The question is, why not just do it yourself? For example, uint32 = array[0] << 24 | array[1] << 16 | array[2] << 8 | array[3] for example?

RH-00
8th October 2010, 21:58
Didn't think about that...I'll give it a shot.

I found a weird solution, but it requires going around the QFile class with the Standard Library equivalent, but its a bit...clunky. So, I'll try your idea.