Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
warpdata.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
#include "
warpdata.h
"
23
#include "
../../savefile.h
"
24
#include "
../../savefiletoolset.h
"
25
#include "
../../savefileiterator.h
"
26
#include <
pse-db/mapsdb.h
>
27
#include <
pse-db/entries/mapdbentry.h
>
28
#include <
pse-db/entries/mapdbentrywarpout.h
>
29
#include <
pse-db/entries/mapdbentrywarpin.h
>
30
#include <
pse-db/util/mapsearch.h
>
31
#include <
pse-common/random.h
>
32
33
WarpData::WarpData
(
SaveFile
* saveFile,
var8
index)
34
{
35
load
(saveFile, index);
36
}
37
38
WarpData::WarpData
(
MapDBEntryWarpOut
* warp)
39
{
40
load
(warp);
41
}
42
43
WarpData::~WarpData
() {}
44
45
void
WarpData::load
(
SaveFile
* saveFile,
var8
index)
46
{
47
reset
();
48
49
if
(saveFile ==
nullptr
)
50
return
;
51
52
auto
it = saveFile->
iterator
()->
offsetTo
((0x4 * index) + 0x265B);
53
54
y
= it->getByte();
55
yChanged
();
56
57
x
= it->getByte();
58
xChanged
();
59
60
destWarp
= it->getByte();
61
destWarpChanged
();
62
63
destMap
= it->getByte();
64
destMapChanged
();
65
66
delete
it;
67
}
68
69
void
WarpData::load
(
MapDBEntryWarpOut
* warp)
70
{
71
x
= warp->
getX
();
72
xChanged
();
73
74
y
= warp->
getY
();
75
yChanged
();
76
77
destMap
= warp->
getToMap
()->
getInd
();
78
destMapChanged
();
79
80
destWarp
= warp->
getWarp
();
81
destWarpChanged
();
82
}
83
84
void
WarpData::save
(
SaveFile
* saveFile,
var8
index)
85
{
86
auto
it = saveFile->
iterator
()->
offsetTo
((0x4 * index) + 0x265B);
87
88
it->
setByte
(
y
);
89
it->setByte(
x
);
90
it->setByte(
destWarp
);
91
it->setByte(
destMap
);
92
93
delete
it;
94
}
95
96
void
WarpData::reset
()
97
{
98
y
= 0;
99
yChanged
();
100
101
x
= 0;
102
xChanged
();
103
104
destWarp
= 0;
105
destWarpChanged
();
106
107
destMap
= 0;
108
destMapChanged
();
109
}
110
111
void
WarpData::randomize
() {
112
reset
();
113
114
// Grab a non-outdoor map
115
// The game can get kind of weird and crash if you warp to an outdoor map
116
// directly instead of "returning" outdoors using "Last Map"
117
auto
map =
MapsDB::inst
()->
search
()->isGood()->notType(
"Outdoor"
)->pickRandom();
118
auto
mapWarps = map->getWarpIn();
119
120
// Switch out warp to a random non-outdoor warp
121
destMap
= map->getInd();
122
destMapChanged
();
123
124
destWarp
=
Random::inst
()->
rangeExclusive
(0, mapWarps.size());
125
destWarpChanged
();
126
127
y
= mapWarps[
destWarp
]->getY();
128
yChanged
();
129
130
x
= mapWarps[
destWarp
]->getX();
131
xChanged
();
132
}
133
134
MapDBEntry
*
WarpData::toMap
()
135
{
136
return
MapsDB::inst
()->
getIndAt
(QString::number(
destMap
));
137
}
MapsDB::inst
static MapsDB * inst()
< Number of maps.
Definition
mapsdb.cpp:35
MapsDB::search
QScopedPointer< MapSearch, QScopedPointerDeleteLater > search() const
C++-owned finder (smart pointer).
Definition
mapsdb.cpp:141
MapsDB::getIndAt
MapDBEntry * getIndAt(const QString val) const
Map by name key (for QML).
Definition
mapsdb.cpp:155
Random::inst
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition
random.cpp:31
Random::rangeExclusive
int rangeExclusive(const int start, const int end) const
Random integer in the half-open interval [start, end).
Definition
random.cpp:53
SaveFileIterator::setByte
void setByte(var8 val, var16 padding=0)
Write a byte at the cursor; advances.
Definition
savefileiterator.cpp:173
SaveFileIterator::offsetTo
SaveFileIterator * offsetTo(var16 val)
Move the cursor to an absolute offset. Returns this for chaining.
Definition
savefileiterator.cpp:31
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::iterator
SaveFileIterator * iterator()
Returns a unique iterator that's setup to iterate over the raw sav file data.
Definition
savefile.cpp:53
WarpData::load
void load(SaveFile *saveFile=nullptr, var8 index=0)
Expand warp index from the save.
Definition
warpdata.cpp:45
WarpData::WarpData
WarpData(SaveFile *saveFile=nullptr, var8 index=0)
< Warp tile Y.
Definition
warpdata.cpp:33
WarpData::destMap
int destMap
Definition
warpdata.h:69
WarpData::x
int x
Definition
warpdata.h:67
WarpData::reset
void reset()
Blank this warp.
Definition
warpdata.cpp:96
WarpData::~WarpData
virtual ~WarpData()
Definition
warpdata.cpp:43
WarpData::randomize
void randomize()
Randomize this warp.
Definition
warpdata.cpp:111
WarpData::save
void save(SaveFile *saveFile, var8 index)
Flatten warp index to the save.
Definition
warpdata.cpp:84
WarpData::destMapChanged
void destMapChanged()
WarpData::xChanged
void xChanged()
WarpData::toMap
MapDBEntry * toMap()
The destination map's DB entry.
Definition
warpdata.cpp:134
WarpData::destWarpChanged
void destWarpChanged()
WarpData::y
int y
Definition
warpdata.h:66
WarpData::destWarp
int destWarp
Definition
warpdata.h:68
WarpData::yChanged
protected::void yChanged()
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
mapdbentry.h
mapdbentrywarpin.h
mapdbentrywarpout.h
mapsdb.h
mapsearch.h
random.h
savefile.h
savefileiterator.h
savefiletoolset.h
MapDBEntryWarpOut
A warp-out point: a tile that warps the player to another map.
Definition
mapdbentrywarpout.h:37
MapDBEntryWarpOut::getX
int getX() const
< Warp-out tile X.
Definition
mapdbentrywarpout.cpp:123
MapDBEntryWarpOut::getWarp
int getWarp() const
Definition
mapdbentrywarpout.cpp:113
MapDBEntryWarpOut::getY
int getY() const
Definition
mapdbentrywarpout.cpp:118
MapDBEntryWarpOut::getToMap
MapDBEntry * getToMap() const
Definition
mapdbentrywarpout.cpp:98
MapDBEntry
One map's complete static definition – the root of the MapDBEntry family.
Definition
mapdbentry.h:56
MapDBEntry::getInd
int getInd() const
Definition
mapdbentry.cpp:582
warpdata.h
projects
savefile
src
pse-savefile
expanded
fragments
warpdata.cpp
Generated by
1.17.0