Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
pokemonstorageset.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 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
22
23#include <QRandomGenerator>
24
25#include "./pokemonstorageset.h"
26#include "./pokemonstoragebox.h"
27#include "../../savefile.h"
30
32{
33 for(var8 i = 0; i < setMaxBoxes; i++)
34 boxes[i] = new PokemonStorageBox;
35
36 load(saveFile, boxesOffset, skipInd);
37}
38
40{
41 for(var8 i = 0; i < setMaxBoxes; i++)
42 boxes[i]->deleteLater();
43}
44
45void PokemonStorageSet::load(SaveFile* saveFile, var16 boxesOffset, svar8 skipInd)
46{
47 reset();
48
49 if(saveFile == nullptr)
50 return;
51
52 for (var8 i = 0; i < setMaxBoxes; i++) {
53
54 // skipInd is signed (svar8, -1 == "skip nothing"); i is unsigned (var8). The
55 // `skipInd >= 0` guard means the cast is safe -- it just makes the signed/
56 // unsigned comparison explicit (clang-tidy bugprone-signed-char-misuse).
57 if(skipInd >= 0 && i == static_cast<var8>(skipInd))
58 continue;
59
60 boxes[i]->load(
61 saveFile,
62 (i * 0x462) + boxesOffset);
63 }
64}
65
66void PokemonStorageSet::save(SaveFile* saveFile, var16 boxesOffset, svar8 skipInd)
67{
68 for (var8 i = 0; i < setMaxBoxes; i++) {
69
70 // skipInd is signed (svar8, -1 == "skip nothing"); i is unsigned (var8). The
71 // `skipInd >= 0` guard means the cast is safe -- it just makes the signed/
72 // unsigned comparison explicit (clang-tidy bugprone-signed-char-misuse).
73 if(skipInd >= 0 && i == static_cast<var8>(skipInd))
74 continue;
75
76 boxes[i]->save(
77 saveFile,
78 (i * 0x462) + boxesOffset);
79 }
80}
81
83{
84 for(var8 i = 0; i < setMaxBoxes; i++)
85 boxes[i]->reset();
86}
87
89{
90 reset();
91
92 for(var8 i = 0; i < setMaxBoxes; i++)
93 boxes[i]->randomize(basics);
94}
95
96void PokemonStorageSet::loadSpecific(SaveFile* saveFile, var16 offset, var8 toBox)
97{
98 boxes[toBox]->load(
99 saveFile,
100 offset);
101}
102
103void PokemonStorageSet::saveSpecific(SaveFile* saveFile, var16 offset, var8 fromBox)
104{
105 boxes[fromBox]->save(
106 saveFile,
107 offset);
108}
109
111{
112 return boxes[ind];
113}
The trainer's headline values: name, ID, money, coins, badges, starter.
Holds contents of a single Pokemon storage box.
PokemonStorageBox * boxAt(int ind)
Box at ind within this set.
void reset()
Empty all six boxes.
void randomize(PlayerBasics *basics)
Fill the set with constrained random mons.
void loadSpecific(SaveFile *saveFile=nullptr, var16 offset=0, var8 toBox=0)
Load a specific box at a specific address into box toBox, overwriting it.
void save(SaveFile *saveFile, var16 boxesOffset, svar8 skipInd=-1)
Auto load or save boxes 1-6 from a single address and skip a box if it's the current box.
void load(SaveFile *saveFile=nullptr, var16 boxesOffset=0, svar8 skipInd=-1)
Auto load or save boxes 1-6 from a single address and skip a box if it's the current box.
PokemonStorageSet(SaveFile *saveFile=nullptr, var16 boxesOffset=0, svar8 skipInd=-1)
PokemonStorageBox * boxes[setMaxBoxes]
The six boxes (fixed-size; never grows/shrinks).
void saveSpecific(SaveFile *saveFile=nullptr, var16 offset=0, var8 fromBox=0)
Save box fromBox out to a specific address.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
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
svar8e svar8
Smaller Shorthand with most default assumptions.
Definition types.h:109
constexpr var8 setMaxBoxes
Boxes per storage set (a save has two sets = 12 boxes).