|
Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
|
Low-level read/write primitives over a SaveFile's raw 32 KB buffer. More...
#include <savefiletoolset.h>
Public Member Functions | |
| SaveFileToolset (SaveFile *newSaveFile) | |
| var32 | bcd2int (QVector< var8 > val) |
| bcd2number -> takes an array with a BCD and returns the corresponding number. | |
| QVector< var8 > | int2bcd (var32 number, var8 size=2) |
| number2bcd -> takes a number and returns the corresponding BCD in an array input: 16 bit positive number, array size (How many bytes) output: array credit: joaomaia @ https://gist.github.com/joaomaia/3892692 | |
| QVector< var8 > | getRange (var16 from, var16 size, bool reverse=false) |
| Copies a range of bytes to a buffer of size and returns them. | |
| void | copyRange (var16 addr, var16 size, QVector< var8 > data, bool reverse=false) |
| Copies data into the save at a particular place, going no further than the maximum size desired and/or the source array length. | |
| QString | getStr (var16 addr, var16 size, var8 maxLen) |
| Gets a string from the sav file, converted from in-game font encoding to UTF-8 for easy reading and manipulation. | |
| void | setStr (var16 addr, var16 size, var8 maxLen, QString str) |
| Sets a string to the sav file, converted from UTF-8 to in-game font encoding. | |
| QString | getHex (var16 addr, var16 size, bool reverse=false) |
| Gets a value in hex from the save file. | |
| void | setHex (var16 addr, var16 size, QString hex, bool reverse=false) |
| Saves a hex value to bytes in the save file. | |
| var32 | getBCD (var16 addr, var8 size) |
| Get a raw BCD value as a number. | |
| void | setBCD (var16 addr, var8 size, var32 val) |
| Set a raw BCD val from a given number. | |
| bool | getBit (var16 addr, var8 size, var8 bit, bool reverse=false) |
| Get a bit from a value. | |
| void | setBit (var16 addr, var8 size, var8 bit, bool value, bool reverse=false) |
| Set a bit into a value. | |
| var16 | getWord (var16 addr, bool reverse=false) |
| Get a 16-bit value. 0x12,0x34 <=> 0x1234. If you want the reverse then reverse it. | |
| void | setWord (var16 addr, var16 val, bool reverse=false) |
| Set a 16-bit value. 0x12,0x34 <=> 0x1234. If you want the reverse then reverse it. | |
| var8 | getByte (var16 addr) |
| Simply gets a byte. | |
| void | setByte (var16 addr, var8 val) |
| Simply sets a byte. | |
| QVector< bool > | getBitField (var16 addr, var16 size) |
| Gets an entire bitfield as a vector of bools. | |
| void | setBitField (var16 addr, var16 size, QVector< bool > src) |
| Sets an entire bitfield from a vector of bools. | |
| var8 | getChecksum (var16 addr, var16 size) |
| Gets a single checksum from a given range. | |
| void | recalcBoxesChecksums () |
| Recalculates the checksum for all the boxes. | |
| void | recalcChecksums (bool force=false) |
| Recalculates all checksums in all banks, following the strict rule of only calculating what's needed and when. | |
Protected Attributes | |
| SaveFile * | saveFile |
| Owning save; its raw data is what every method here reads/writes. | |
Low-level read/write primitives over a SaveFile's raw 32 KB buffer.
Every byte the editor touches goes through here. The toolset speaks the Game Boy save's actual encodings – BCD numbers, in-game font strings, packed bit-fields, big/little-endian words, and the Gen 1 checksum – so higher layers (the expanded/ objects) can ask for "the money at this address" instead of doing byte math. Addresses are absolute offsets into the raw save.
It holds a back-pointer to its owning SaveFile and reads/writes that file's data directly; it does not own the buffer. For cursor-style sequential access with auto-advancing offsets, see SaveFileIterator, which wraps this.
Definition at line 41 of file savefiletoolset.h.
| SaveFileToolset::SaveFileToolset | ( | SaveFile * | newSaveFile | ) |
| newSaveFile | The save whose raw data this toolset operates on. |
Definition at line 27 of file savefiletoolset.cpp.
References saveFile.
bcd2number -> takes an array with a BCD and returns the corresponding number.
input: array output: number credit: joaomaia @ https://gist.github.com/joaomaia/3892692
| val | Bytes holding a binary-coded-decimal value. |
Definition at line 32 of file savefiletoolset.cpp.
Referenced by getBCD().
| void SaveFileToolset::copyRange | ( | var16 | addr, |
| var16 | size, | ||
| QVector< var8 > | data, | ||
| bool | reverse = false ) |
Copies data into the save at a particular place, going no further than the maximum size desired and/or the source array length.
| addr | index to start copying at, inclusive |
| size | maximum length to copy |
| data | array of data to copy into, will stop at size or data length |
| reverse | reverse copies the data into the specified location |
Definition at line 74 of file savefiletoolset.cpp.
References saveFile.
Referenced by SaveFileIterator::copyRange(), recalcBoxesChecksums(), AreaLoadedSprites::save(), setBCD(), setHex(), setStr(), and setWord().
Get a raw BCD value as a number.
Casino coins are 16-bit BCD meaning the maximum is 9,999. Player money is 24-bit BCD meaning the maximum is 999,999.
Definition at line 154 of file savefiletoolset.cpp.
References bcd2int(), and getRange().
Referenced by SaveFileIterator::getBCD().
Get a bit from a value.
Here for conv. but it's actually simpler just to test it yourself given this is so complicated and expensive for bit testing. This method can only bit test a bit up to 4 bytes.
Definition at line 164 of file savefiletoolset.cpp.
References getRange().
Referenced by getBitField().
Gets an entire bitfield as a vector of bools.
Definition at line 242 of file savefiletoolset.cpp.
References getBit().
Referenced by SaveFileIterator::getBitField(), WorldHidden::load(), WorldMissables::load(), WorldTowns::load(), WorldTrades::load(), and PlayerPokedex::loadPokedex().
Simply gets a byte.
Definition at line 232 of file savefiletoolset.cpp.
References saveFile.
Referenced by SaveFileIterator::getByte().
Gets a single checksum from a given range.
This properly calculates the checksum that Gen 1 games expect.
Definition at line 293 of file savefiletoolset.cpp.
References getRange().
Referenced by recalcBoxesChecksums(), and recalcChecksums().
Gets a value in hex from the save file.
Definition at line 106 of file savefiletoolset.cpp.
References getRange().
Referenced by SaveFileIterator::getHex().
Copies a range of bytes to a buffer of size and returns them.
| from | Start offset (inclusive). |
| size | Byte count. |
| reverse | Read the range in reversed byte order. |
Definition at line 59 of file savefiletoolset.cpp.
References saveFile.
Referenced by getBCD(), getBit(), getChecksum(), getHex(), SaveFileIterator::getRange(), getStr(), getWord(), AreaLoadedSprites::load(), and setBit().
Gets a string from the sav file, converted from in-game font encoding to UTF-8 for easy reading and manipulation.
| addr | Start offset. |
| size | Field byte size. |
| maxLen | Max characters. |
Definition at line 88 of file savefiletoolset.cpp.
References FontsDB::convertFromCode(), getRange(), and FontsDB::inst().
Referenced by SaveFileIterator::getStr().
Get a 16-bit value. 0x12,0x34 <=> 0x1234. If you want the reverse then reverse it.
Definition at line 209 of file savefiletoolset.cpp.
References getRange().
Referenced by SaveFileIterator::getWord().
number2bcd -> takes a number and returns the corresponding BCD in an array input: 16 bit positive number, array size (How many bytes) output: array credit: joaomaia @ https://gist.github.com/joaomaia/3892692
| number | The value to encode. |
| size | Output width in bytes. |
number encoded as binary-coded decimal. Definition at line 44 of file savefiletoolset.cpp.
Referenced by setBCD().
| void SaveFileToolset::recalcBoxesChecksums | ( | ) |
Recalculates the checksum for all the boxes.
This only needs to be called when the boxes checksums are used. The game doesn't always use the box checksums or calculate them. Use recalcChecksums below to have them calculated as appropriate.
Definition at line 315 of file savefiletoolset.cpp.
References copyRange(), getChecksum(), and saveFile.
| void SaveFileToolset::recalcChecksums | ( | bool | force = false | ) |
Recalculates all checksums in all banks, following the strict rule of only calculating what's needed and when.
If the game will never calculate the box checksums then neither will we – there are cases when it won't. This also calculates bank 1, thus covering all checksums in the file. Part of honouring byte-exact fidelity: we don't write checksums the real game wouldn't.
| force | Recalculate even the conditionally-skipped checksums. |
Definition at line 351 of file savefiletoolset.cpp.
References getChecksum(), and saveFile.
Set a raw BCD val from a given number.
Casino coins are 16-bit BCD meaning the maximum is 9,999. Player money is 24-bit BCD meaning the maximum is 999,999.
Definition at line 159 of file savefiletoolset.cpp.
References copyRange(), and int2bcd().
Referenced by SaveFileIterator::setBCD().
Set a bit into a value.
Here for conv. but it's actually simpler just to set it yourself given this is so complicated and expensive for bit setting. This method can only bit set a bit up to 4 bytes.
Definition at line 183 of file savefiletoolset.cpp.
References getRange(), and setHex().
Referenced by AreaNPC::save(), WorldCompleted::save(), and setBitField().
Sets an entire bitfield from a vector of bools.
Definition at line 265 of file savefiletoolset.cpp.
References setBit().
Referenced by WorldHidden::save(), WorldMissables::save(), WorldTowns::save(), WorldTrades::save(), PlayerPokedex::savePokedex(), and SaveFileIterator::setBitField().
Simply sets a byte.
Definition at line 237 of file savefiletoolset.cpp.
References saveFile.
Referenced by AreaAudio::save(), AreaGeneral::save(), AreaMap::save(), AreaPlayer::save(), AreaSign::save(), AreaSprites::save(), AreaTileset::save(), AreaWarps::save(), Daycare::save(), HallOfFame::save(), HoFPokemon::save(), PlayerPokemon::save(), PokemonStorageBox::save(), Storage::save(), WorldGeneral::save(), WorldLocal::save(), WorldOther::save(), and SaveFileIterator::setByte().
Saves a hex value to bytes in the save file.
Definition at line 126 of file savefiletoolset.cpp.
References copyRange().
Referenced by setBit(), and SaveFileIterator::setHex().
Sets a string to the sav file, converted from UTF-8 to in-game font encoding.
| addr | Start offset. |
| size | Field byte size. |
| maxLen | Max characters. |
| str | The UTF-8 text to store. |
Definition at line 97 of file savefiletoolset.cpp.
References FontsDB::convertToCode(), copyRange(), and FontsDB::inst().
Referenced by PlayerBasics::save(), Rival::save(), and SaveFileIterator::setStr().
Set a 16-bit value. 0x12,0x34 <=> 0x1234. If you want the reverse then reverse it.
Definition at line 220 of file savefiletoolset.cpp.
References copyRange().
Referenced by SaveFileIterator::setWord().
|
protected |
Owning save; its raw data is what every method here reads/writes.
Definition at line 161 of file savefiletoolset.h.
Referenced by copyRange(), getByte(), getRange(), recalcBoxesChecksums(), recalcChecksums(), SaveFileToolset(), and setByte().