Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
worldhidden.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
25#include <QVector>
26#include "./worldhidden.h"
27#include "../../savefile.h"
30
32{
33 load(saveFile);
34}
35
37
39{
40 reset();
41
42 if(saveFile == nullptr)
43 return;
44
45 auto toolset = saveFile->toolset;
46
47 // Load hidden items
48 auto bits = toolset->getBitField(0x299C, hiddenItemByteCount);
49
50 for(var8 i = 0; i < bits.size() && i < hiddenItemCount; i++)
51 hiddenItems[i] = bits.at(i);
52
54
55 // Load hidden coins
56 bits = toolset->getBitField(0x29AA, hiddenCoinByteCount);
57
58 for(var8 i = 0; i < bits.size() && i < hiddenCoinCount; i++)
59 hiddenCoins[i] = bits.at(i);
60
62}
63
65{
66 auto toolset = saveFile->toolset;
67
68 QVector<bool> bits;
69
70 // Save Hidden Items
71 for(var8 i = 0; i < hiddenItemCount; i++)
72 bits.append(hiddenItems[i]);
73
74 toolset->setBitField(0x299C, hiddenItemByteCount, bits);
75 bits.clear();
76
77 // Save hidden coins
78 for(var8 i = 0; i < hiddenCoinCount; i++)
79 bits.append(hiddenCoins[i]);
80
81 toolset->setBitField(0x29AA, hiddenCoinByteCount, bits);
82}
83
88
90{
91 return hiddenItems[ind];
92}
93
94void WorldHidden::hItemsSet(int ind, bool val)
95{
96 hiddenItems[ind] = val;
98}
99
101{
102 return hiddenCoinCount;
103}
104
106{
107 return hiddenCoins[ind];
108}
109
110void WorldHidden::hCoinsSet(int ind, bool val)
111{
112 hiddenCoins[ind] = val;
114}
115
117{
118 memset(hiddenItems, 0, hiddenItemCount);
120
121 memset(hiddenCoins, 0, hiddenCoinCount);
123}
124
125// I want the player to collect the hidden items and coins
127{
128 reset();
129}
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 hidden flags.
virtual ~WorldHidden()
int hItemsCount()
Number of hidden-item flags.
bool hiddenCoins[hiddenCoinCount]
Hidden-coin collected flags.
Definition worldhidden.h:70
void randomize()
Randomize the hidden flags.
protected::void hiddenItemsChanged()
void load(SaveFile *saveFile=nullptr)
Expand the hidden-item/coin flags from the save.
int hCoinsCount()
Number of hidden-coin flags.
void hItemsSet(int ind, bool val)
Set/clear hidden item ind.
bool hiddenItems[hiddenItemCount]
Hidden-item collected flags.
Definition worldhidden.h:69
bool hCoinsAt(int ind)
Is hidden coin ind collected?
bool hItemsAt(int ind)
Is hidden item ind collected?
WorldHidden(SaveFile *saveFile=nullptr)
void hCoinsSet(int ind, bool val)
Set/clear hidden coin ind.
void hiddenCoinsChanged()
void save(SaveFile *saveFile)
Flatten the hidden-item/coin flags to the save.
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
constexpr var8 hiddenCoinCount
Hidden-coin collected flags actually used.
Definition worldhidden.h:27
constexpr var8 hiddenCoinByteCount
4 Bits of 16 unused
Definition worldhidden.h:29
constexpr var8 hiddenItemByteCount
2 Bits of 56 unused
Definition worldhidden.h:28
constexpr var8 hiddenItemCount
Hidden-item collected flags actually used.
Definition worldhidden.h:26