Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
worldother.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 "
./worldother.h
"
24
#include "
../../savefile.h
"
25
#include "
../../savefiletoolset.h
"
26
#include "
../../savefileiterator.h
"
27
#include <
pse-common/random.h
>
28
29
WorldOther::WorldOther
(
SaveFile
* saveFile)
30
{
31
playtime
=
new
Playtime
;
32
load
(saveFile);
33
}
34
35
WorldOther::~WorldOther
() {
36
playtime
->deleteLater();
37
}
38
39
void
WorldOther::load
(
SaveFile
* saveFile)
40
{
41
reset
();
42
43
if
(saveFile ==
nullptr
)
44
return
;
45
46
auto
toolset = saveFile->
toolset
;
47
48
fossilItemGiven
= toolset->getByte(0x29BB);
49
fossilItemGivenChanged
();
50
51
fossilPkmnResult
= toolset->getByte(0x29BC);
52
fossilPkmnResultChanged
();
53
54
debugMode
= toolset->getBit(0x29DE, 1, 1);
55
debugModeChanged
();
56
57
auto
it = saveFile->
iterator
()->
offsetTo
(0x2CED);
58
playtime
->hours = it->getByte();
59
playtime
->hoursChanged();
60
61
playtime
->clockMaxed = (it->getByte() > 0);
62
playtime
->clockMaxedChanged();
63
64
playtime
->minutes = it->getByte();
65
playtime
->minutesChanged();
66
67
playtime
->seconds = it->getByte();
68
playtime
->secondsChanged();
69
70
playtime
->frames = it->getByte();
71
playtime
->framesChanged();
72
delete
it;
73
}
74
75
void
WorldOther::save
(
SaveFile
* saveFile)
76
{
77
auto
toolset = saveFile->
toolset
;
78
79
toolset->
setByte
(0x29BB,
fossilItemGiven
);
80
toolset->setByte(0x29BC,
fossilPkmnResult
);
81
toolset->setBit(0x29DE, 1, 1,
debugMode
);
82
83
auto
it = saveFile->
iterator
()->
offsetTo
(0x2CED);
84
it->
setByte
(
playtime
->hours);
85
it->setByte((
playtime
->clockMaxed) ? 1 : 0);
86
it->setByte(
playtime
->minutes);
87
it->setByte(
playtime
->seconds);
88
it->setByte(
playtime
->frames);
89
delete
it;
90
}
91
92
void
WorldOther::reset
()
93
{
94
debugMode
=
false
;
95
debugModeChanged
();
96
97
playtime
->hours = 0;
98
playtime
->hoursChanged();
99
100
playtime
->minutes = 0;
101
playtime
->minutesChanged();
102
103
playtime
->seconds = 0;
104
playtime
->secondsChanged();
105
106
playtime
->frames = 0;
107
playtime
->framesChanged();
108
109
playtime
->clockMaxed =
false
;
110
playtime
->clockMaxedChanged();
111
112
fossilItemGiven
= 0;
113
fossilItemGivenChanged
();
114
115
fossilPkmnResult
= 0;
116
fossilPkmnResultChanged
();
117
}
118
119
void
WorldOther::randomize
()
120
{
121
reset
();
122
123
// 5% chance of being enabled
124
debugMode
=
Random::inst
()->
chanceSuccess
(5);
125
debugModeChanged
();
126
127
randomizePlaytime
();
128
}
129
130
void
WorldOther::randomizePlaytime
()
131
{
132
playtime
->clockMaxed =
false
;
133
134
playtime
->hours =
Random::inst
()->
rangeInclusive
(0, 255);
135
playtime
->hoursChanged();
136
137
playtime
->minutes =
Random::inst
()->
rangeInclusive
(0, 59);
138
playtime
->minutesChanged();
139
140
playtime
->seconds =
Random::inst
()->
rangeInclusive
(0, 59);
141
playtime
->secondsChanged();
142
143
playtime
->frames =
Random::inst
()->
rangeInclusive
(0, 59);
144
playtime
->framesChanged();
145
}
146
147
void
WorldOther::clearPlaytime
()
148
{
149
playtime
->clockMaxed =
false
;
150
151
playtime
->hours = 0;
152
playtime
->hoursChanged();
153
154
playtime
->minutes = 0;
155
playtime
->minutesChanged();
156
157
playtime
->seconds = 0;
158
playtime
->secondsChanged();
159
160
playtime
->frames = 0;
161
playtime
->framesChanged();
162
}
163
164
int
Playtime::getDays()
165
{
166
return
hours
/ 24;
167
}
168
169
void
Playtime::setDays(
int
val)
170
{
171
int
_days = val;
172
int
_hours =
hours
% 24;
173
174
hours
= (_days * 24) + _hours;
175
hoursChanged();
176
}
177
178
int
Playtime::getHoursAdjusted()
179
{
180
return
hours
% 24;
181
}
182
183
void
Playtime::setHoursAdjusted(
int
val)
184
{
185
int
_days =
hours
/ 24;
186
int
_hours = val;
187
188
hours
= (_days * 24) + _hours;
189
hoursChanged();
190
}
Playtime
The save's playtime clock, surfaced to QML as days/hours/minutes/seconds/frames.
Definition
worldother.h:36
Playtime::hours
int hours
Max 255.
Definition
worldother.h:63
Random::chanceSuccess
bool chanceSuccess(const int percent) const
Did a percent chance succeed?
Definition
random.cpp:73
Random::rangeInclusive
int rangeInclusive(const int start, const int end) const
Random integer in the closed interval [start, end].
Definition
random.cpp:42
Random::inst
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition
random.cpp:31
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
SaveFileToolset::setByte
void setByte(var16 addr, var8 val)
Simply sets a byte.
Definition
savefiletoolset.cpp:237
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
SaveFile::iterator
SaveFileIterator * iterator()
Returns a unique iterator that's setup to iterate over the raw sav file data.
Definition
savefile.cpp:53
WorldOther::fossilItemGiven
int fossilItemGiven
Definition
worldother.h:121
WorldOther::~WorldOther
virtual ~WorldOther()
Definition
worldother.cpp:35
WorldOther::fossilItemGivenChanged
void fossilItemGivenChanged()
WorldOther::fossilPkmnResult
int fossilPkmnResult
Definition
worldother.h:122
WorldOther::load
void load(SaveFile *saveFile=nullptr)
Expand this region from the save.
Definition
worldother.cpp:39
WorldOther::randomize
void randomize()
Randomize this region.
Definition
worldother.cpp:119
WorldOther::debugMode
bool debugMode
Definition
worldother.h:115
WorldOther::WorldOther
WorldOther(SaveFile *saveFile=nullptr)
< In-game debug mode flag (see field note).
Definition
worldother.cpp:29
WorldOther::save
void save(SaveFile *saveFile)
Flatten this region to the save.
Definition
worldother.cpp:75
WorldOther::playtime
Playtime * playtime
Definition
worldother.h:118
WorldOther::debugModeChanged
protected::void debugModeChanged()
WorldOther::reset
void reset()
Blank this region.
Definition
worldother.cpp:92
WorldOther::clearPlaytime
void clearPlaytime()
Zero the playtime clock.
Definition
worldother.cpp:147
WorldOther::randomizePlaytime
void randomizePlaytime()
Randomize just the playtime clock.
Definition
worldother.cpp:130
WorldOther::fossilPkmnResultChanged
void fossilPkmnResultChanged()
random.h
savefile.h
savefileiterator.h
savefiletoolset.h
worldother.h
projects
savefile
src
pse-savefile
expanded
world
worldother.cpp
Generated by
1.17.0