Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
savefileiterator.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 "savefile_autoport.h"
20
21// To prevent cross-include and thus errors
22class SaveFile;
23class SaveFileToolset;
24
42{
43public:
46
52
55
56 SaveFile* file();
58
63
64 // Here are all the specialized functions that auto-use the offset and
65 // auto-increment the offset making things much easier
66
68 QVector<var8> getRange(var16 size, var16 padding = 0, bool reverse = false);
70 void copyRange(
71 var16 size, QVector<var8> data, var16 padding = 0, bool reverse = false);
72 QString getStr(var16 size, var8 maxLen, var16 padding = 0);
73 void setStr(var16 size, var8 maxLen, QString str, var16 padding = 0);
74 QString getHex(var16 size, var16 padding = 0, bool reverse = false);
75 void setHex(var16 size, QString hex, var16 padding = 0, bool reverse = false);
76 var32 getBCD(var8 size, var16 padding = 0);
77 void setBCD(var8 size, var32 val, var16 padding = 0);
78 bool getBit(var8 size, var8 bit, bool reverse = false);
79 void setBit(
80 var8 size, var8 bit, bool value, bool reverse = false);
81 var16 getWord(var16 padding = 0, bool reverse = false);
82 void setWord(var16 val, var16 padding = 0, bool reverse = false);
83 var8 getByte(var16 padding = 0);
84 void setByte(var8 val, var16 padding = 0);
85 QVector<bool> getBitField(var16 size, var16 padding = 0);
86 void setBitField(var16 size, QVector<bool> src, var16 padding = 0);
87
89 var16 offset = 0x0000;
90
91protected:
93 QVector<var16> state;
94
95 SaveFile* saveFile = nullptr;
96};
void setBit(var8 size, var8 bit, bool value, bool reverse=false)
Set a bit at the cursor.
var16 getWord(var16 padding=0, bool reverse=false)
Read a 16-bit word at the cursor; advances.
void setHex(var16 size, QString hex, var16 padding=0, bool reverse=false)
Write hex at the cursor; advances.
var16 offset
Current offset in the save file. Can be freely changed directly.
SaveFileToolset * toolset()
Get the underlying address-based toolset.
void setBCD(var8 size, var32 val, var16 padding=0)
Write a BCD number at the cursor; advances.
SaveFileIterator * push()
Bookmark the current offset (push) ...
SaveFile * saveFile
The save file this cursor walks.
QVector< var8 > getRange(var16 size, var16 padding=0, bool reverse=false)
Copies a range of bytes to a buffer of size and returns them. Reads at the cursor,...
SaveFileIterator(SaveFile *saveFile)
SaveFileIterator * offsetBy(var16 val)
Move the cursor by a relative amount. Returns this for chaining.
void setStr(var16 size, var8 maxLen, QString str, var16 padding=0)
Write a font-encoded string at the cursor; advances.
QString getStr(var16 size, var8 maxLen, var16 padding=0)
Read a font-encoded string at the cursor; advances.
SaveFileIterator * pop()
... and return to the most recent bookmark (pop). Works like a FIFO stack.
QString getHex(var16 size, var16 padding=0, bool reverse=false)
Read hex at the cursor; advances.
void setBitField(var16 size, QVector< bool > src, var16 padding=0)
Write a bitfield at the cursor; advances.
QVector< bool > getBitField(var16 size, var16 padding=0)
Read a bitfield at the cursor; advances.
SaveFileIterator * skipPadding(var16 val)
Alias for code cleanliness (advance past padding).
SaveFile * file()
Get reference back to the save file.
bool getBit(var8 size, var8 bit, bool reverse=false)
Test a bit at the cursor.
QVector< var16 > state
Bookmark stack – saves places in the save file to go back to (push/pop).
SaveFileIterator * inc()
Increment the offset by one byte. Returns this.
void setByte(var8 val, var16 padding=0)
Write a byte at the cursor; advances.
var32 getBCD(var8 size, var16 padding=0)
Read a BCD number at the cursor; advances.
SaveFileIterator * dec()
Decrement the offset by one byte. Returns this.
void setWord(var16 val, var16 padding=0, bool reverse=false)
Write a 16-bit word at the cursor; advances.
void copyRange(var16 size, QVector< var8 > data, var16 padding=0, bool reverse=false)
Writes at the cursor, then advances by size + padding.
SaveFileIterator * offsetTo(var16 val)
Move the cursor to an absolute offset. Returns this for chaining.
var8 getByte(var16 padding=0)
Read a byte at the cursor; advances.
Low-level read/write primitives over a SaveFile's raw 32 KB buffer.
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.