Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
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
"
28
#include "
../../savefiletoolset.h
"
29
#include "
../../savefileiterator.h
"
30
31
WorldHidden::WorldHidden
(
SaveFile
* saveFile)
32
{
33
load
(saveFile);
34
}
35
36
WorldHidden::~WorldHidden
() {}
37
38
void
WorldHidden::load
(
SaveFile
* saveFile)
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
53
hiddenItemsChanged
();
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
61
hiddenCoinsChanged
();
62
}
63
64
void
WorldHidden::save
(
SaveFile
* saveFile)
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
84
int
WorldHidden::hItemsCount
()
85
{
86
return
hiddenItemCount
;
87
}
88
89
bool
WorldHidden::hItemsAt
(
int
ind)
90
{
91
return
hiddenItems
[ind];
92
}
93
94
void
WorldHidden::hItemsSet
(
int
ind,
bool
val)
95
{
96
hiddenItems
[ind] = val;
97
hiddenItemsChanged
();
98
}
99
100
int
WorldHidden::hCoinsCount
()
101
{
102
return
hiddenCoinCount
;
103
}
104
105
bool
WorldHidden::hCoinsAt
(
int
ind)
106
{
107
return
hiddenCoins
[ind];
108
}
109
110
void
WorldHidden::hCoinsSet
(
int
ind,
bool
val)
111
{
112
hiddenCoins
[ind] = val;
113
hiddenCoinsChanged
();
114
}
115
116
void
WorldHidden::reset
()
117
{
118
memset(
hiddenItems
, 0,
hiddenItemCount
);
119
hiddenItemsChanged
();
120
121
memset(
hiddenCoins
, 0,
hiddenCoinCount
);
122
hiddenCoinsChanged
();
123
}
124
125
// I want the player to collect the hidden items and coins
126
void
WorldHidden::randomize
()
127
{
128
reset
();
129
}
SaveFileToolset::setBitField
void setBitField(var16 addr, var16 size, QVector< bool > src)
Sets an entire bitfield from a vector of bools.
Definition
savefiletoolset.cpp:265
SaveFileToolset::getBitField
QVector< bool > getBitField(var16 addr, var16 size)
Gets an entire bitfield as a vector of bools.
Definition
savefiletoolset.cpp:242
SaveFile
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition
savefile.h:46
SaveFile::toolset
SaveFileToolset * toolset
Tools to operate directly on the raw sav file data.
Definition
savefile.h:117
WorldHidden::reset
void reset()
Clear all hidden flags.
Definition
worldhidden.cpp:116
WorldHidden::~WorldHidden
virtual ~WorldHidden()
Definition
worldhidden.cpp:36
WorldHidden::hItemsCount
int hItemsCount()
Number of hidden-item flags.
Definition
worldhidden.cpp:84
WorldHidden::hiddenCoins
bool hiddenCoins[hiddenCoinCount]
Hidden-coin collected flags.
Definition
worldhidden.h:70
WorldHidden::randomize
void randomize()
Randomize the hidden flags.
Definition
worldhidden.cpp:126
WorldHidden::hiddenItemsChanged
protected::void hiddenItemsChanged()
WorldHidden::load
void load(SaveFile *saveFile=nullptr)
Expand the hidden-item/coin flags from the save.
Definition
worldhidden.cpp:38
WorldHidden::hCoinsCount
int hCoinsCount()
Number of hidden-coin flags.
Definition
worldhidden.cpp:100
WorldHidden::hItemsSet
void hItemsSet(int ind, bool val)
Set/clear hidden item ind.
Definition
worldhidden.cpp:94
WorldHidden::hiddenItems
bool hiddenItems[hiddenItemCount]
Hidden-item collected flags.
Definition
worldhidden.h:69
WorldHidden::hCoinsAt
bool hCoinsAt(int ind)
Is hidden coin ind collected?
Definition
worldhidden.cpp:105
WorldHidden::hItemsAt
bool hItemsAt(int ind)
Is hidden item ind collected?
Definition
worldhidden.cpp:89
WorldHidden::WorldHidden
WorldHidden(SaveFile *saveFile=nullptr)
Definition
worldhidden.cpp:31
WorldHidden::hCoinsSet
void hCoinsSet(int ind, bool val)
Set/clear hidden coin ind.
Definition
worldhidden.cpp:110
WorldHidden::hiddenCoinsChanged
void hiddenCoinsChanged()
WorldHidden::save
void save(SaveFile *saveFile)
Flatten the hidden-item/coin flags to the save.
Definition
worldhidden.cpp:64
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
savefile.h
savefileiterator.h
savefiletoolset.h
worldhidden.h
hiddenCoinCount
constexpr var8 hiddenCoinCount
Hidden-coin collected flags actually used.
Definition
worldhidden.h:27
hiddenCoinByteCount
constexpr var8 hiddenCoinByteCount
4 Bits of 16 unused
Definition
worldhidden.h:29
hiddenItemByteCount
constexpr var8 hiddenItemByteCount
2 Bits of 56 unused
Definition
worldhidden.h:28
hiddenItemCount
constexpr var8 hiddenItemCount
Hidden-item collected flags actually used.
Definition
worldhidden.h:26
projects
savefile
src
pse-savefile
expanded
world
worldhidden.cpp
Generated by
1.17.0