Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
savefiletoolset.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16#pragma once
17#include <pse-common/types.h>
18#include <QVector>
19#include <QString>
20#include "savefile_autoport.h"
21
22class SaveFile;
23
40// Tools to operate on raw save file data
42{
43public:
45 SaveFileToolset(SaveFile* newSaveFile);
46
56 var32 bcd2int(QVector<var8> val);
57
68 QVector<var8> int2bcd(var32 number, var8 size = 2);
69
73 QVector<var8> getRange(var16 from, var16 size, bool reverse = false);
74
83 void copyRange(var16 addr, var16 size, QVector<var8> data, bool reverse = false);
84
88 QString getStr(var16 addr, var16 size, var8 maxLen);
89
93 void setStr(var16 addr, var16 size, var8 maxLen, QString str);
94
96 QString getHex(var16 addr, var16 size, bool reverse = false);
97
99 void setHex(var16 addr, var16 size, QString hex, bool reverse = false);
100
104 var32 getBCD(var16 addr, var8 size);
105
109 void setBCD(var16 addr, var8 size, var32 val);
110
115 bool getBit(var16 addr, var8 size, var8 bit, bool reverse = false);
116
121 void setBit(var16 addr, var8 size, var8 bit, bool value, bool reverse = false);
122
124 var16 getWord(var16 addr, bool reverse = false);
126 void setWord(var16 addr, var16 val, bool reverse = false);
127
129 var8 getByte(var16 addr);
131 void setByte(var16 addr, var8 val);
132
134 QVector<bool> getBitField(var16 addr, var16 size);
136 void setBitField(var16 addr, var16 size, QVector<bool> src);
137
140 var8 getChecksum(var16 addr, var16 size);
141
147
158 void recalcChecksums(bool force = false);
159
160protected:
162};
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/o...
QString getHex(var16 addr, var16 size, bool reverse=false)
Gets a value in hex from the save file.
QVector< var8 > int2bcd(var32 number, var8 size=2)
number2bcd -> takes a number and returns the corresponding BCD in an array input: 16 bit positive num...
SaveFile * saveFile
Owning save; its raw data is what every method here reads/writes.
void setHex(var16 addr, var16 size, QString hex, bool reverse=false)
Saves a hex value to bytes in the save file.
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.
void recalcChecksums(bool force=false)
Recalculates all checksums in all banks, following the strict rule of only calculating what's needed ...
var32 bcd2int(QVector< var8 > val)
bcd2number -> takes an array with a BCD and returns the corresponding number.
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 m...
QVector< var8 > getRange(var16 from, var16 size, bool reverse=false)
Copies a range of bytes to a buffer of size and returns them.
bool getBit(var16 addr, var8 size, var8 bit, bool reverse=false)
Get a bit from a value.
void setBitField(var16 addr, var16 size, QVector< bool > src)
Sets an entire bitfield from a vector of bools.
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.
void recalcBoxesChecksums()
Recalculates the checksum for all the boxes.
QVector< bool > getBitField(var16 addr, var16 size)
Gets an entire bitfield as a vector of bools.
var16 getWord(var16 addr, bool reverse=false)
Get a 16-bit value. 0x12,0x34 <=> 0x1234. If you want the reverse then reverse it.
SaveFileToolset(SaveFile *newSaveFile)
void setByte(var16 addr, var8 val)
Simply sets a byte.
var8 getChecksum(var16 addr, var16 size)
Gets a single checksum from a given range.
void setBit(var16 addr, var8 size, var8 bit, bool value, bool reverse=false)
Set a bit into a value.
var8 getByte(var16 addr)
Simply gets a byte.
void setBCD(var16 addr, var8 size, var32 val)
Set a raw BCD val from a given number.
var32 getBCD(var16 addr, var8 size)
Get a raw BCD value as a number.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
Project-wide fixed-width integer aliases (var8, var16, ...).
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition types.h:125
var32e var32
Everyday 32-bit alias. Exact width to avoid the "fastest" widening bug.
Definition types.h:126
Import/export macro for the savefile library, plus the central list of QObject types kept deliberatel...
#define SAVEFILE_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.