Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
worldmissables.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 <string.h>
24#include <QVector>
25
26#include "./worldmissables.h"
27#include "../../savefile.h"
30#include <pse-db/missablesdb.h>
32
34{
35 load(saveFile);
36}
37
39
41{
42 reset();
43
44 if(saveFile == nullptr)
45 return;
46
47 auto toolset = saveFile->toolset;
48
49 // Load missables
50 auto bits = toolset->getBitField(0x2852, missableByteCount);
51
52 for(var8 i = 0; i < bits.size() && i < missableCount; i++)
53 missables[i] = bits.at(i);
54
56}
57
59{
60 auto toolset = saveFile->toolset;
61
62 QVector<bool> bits;
63
64 // Save Missables
65 for(var8 i = 0; i < missableCount; i++)
66 bits.append(missables[i]);
67
68 toolset->setBitField(0x2852, missableByteCount, bits);
69}
70
75
77{
78 return missables[ind];
79}
80
81void WorldMissables::missablesSet(int ind, bool val)
82{
83 missables[ind] = val;
85}
86
88{
89 // Missables can't be zeroed out whimsically, reset back to game start
90 // defaults. Missables can crash the game if mis-handled
91 // 1 = Hide, 0 = Show, ensure it's marked one if it's hidden
92 for(auto missable : MissablesDB::inst()->getStore())
93 missables[missable->getInd()] = !missable->getDefShow();
94
96}
97
98// Missables is not something you can blantly randomize, the game will likely
99// crash. Also we want the player to progress through the game normaly.
101 reset();
102}
static MissablesDB * inst()
< Number of missable definitions.
void setBitField(var16 addr, var16 size, QVector< bool > src)
Sets an entire bitfield from a vector of bools.
QVector< bool > getBitField(var16 addr, var16 size)
Gets an entire bitfield as a vector of bools.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
SaveFileToolset * toolset
Tools to operate directly on the raw sav file data.
Definition savefile.h:117
void reset()
Clear all missable flags.
void missablesSet(int ind, bool val)
Set/clear missable ind.
WorldMissables(SaveFile *saveFile=nullptr)
protected::void missablesChanged()
int missablesCount()
Number of missable flags.
bool missablesAt(int ind)
Is missable ind set (shown/hidden)?
bool missables[missableCount]
Per-missable visibility flags.
void save(SaveFile *saveFile)
Flatten the missable flags to the save.
void load(SaveFile *saveFile=nullptr)
Expand the missable flags from the save.
virtual ~WorldMissables()
void randomize()
Randomize the missable flags.
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
constexpr var8 missableCount
Missable-sprite flags actually used.
constexpr var8 missableByteCount
4 bits unused of 232