Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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"
27#include <pse-common/random.h>
28
30{
31 playtime = new Playtime;
32 load(saveFile);
33}
34
36 playtime->deleteLater();
37}
38
40{
41 reset();
42
43 if(saveFile == nullptr)
44 return;
45
46 auto toolset = saveFile->toolset;
47
48 fossilItemGiven = toolset->getByte(0x29BB);
50
51 fossilPkmnResult = toolset->getByte(0x29BC);
53
54 debugMode = toolset->getBit(0x29DE, 1, 1);
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
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
93{
94 debugMode = false;
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;
114
117}
118
120{
121 reset();
122
123 // 5% chance of being enabled
126
128}
129
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
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
164int Playtime::getDays()
165{
166 return hours / 24;
167}
168
169void Playtime::setDays(int val)
170{
171 int _days = val;
172 int _hours = hours % 24;
173
174 hours = (_days * 24) + _hours;
175 hoursChanged();
176}
177
178int Playtime::getHoursAdjusted()
179{
180 return hours % 24;
181}
182
183void Playtime::setHoursAdjusted(int val)
184{
185 int _days = hours / 24;
186 int _hours = val;
187
188 hours = (_days * 24) + _hours;
189 hoursChanged();
190}
The save's playtime clock, surfaced to QML as days/hours/minutes/seconds/frames.
Definition worldother.h:36
int hours
Max 255.
Definition worldother.h:63
bool chanceSuccess(const int percent) const
Did a percent chance succeed?
Definition random.cpp:73
int rangeInclusive(const int start, const int end) const
Random integer in the closed interval [start, end].
Definition random.cpp:42
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition random.cpp:31
void setByte(var8 val, var16 padding=0)
Write a byte at the cursor; advances.
SaveFileIterator * offsetTo(var16 val)
Move the cursor to an absolute offset. Returns this for chaining.
void setByte(var16 addr, var8 val)
Simply sets a byte.
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
SaveFileIterator * iterator()
Returns a unique iterator that's setup to iterate over the raw sav file data.
Definition savefile.cpp:53
int fossilItemGiven
Definition worldother.h:121
virtual ~WorldOther()
void fossilItemGivenChanged()
int fossilPkmnResult
Definition worldother.h:122
void load(SaveFile *saveFile=nullptr)
Expand this region from the save.
void randomize()
Randomize this region.
bool debugMode
Definition worldother.h:115
WorldOther(SaveFile *saveFile=nullptr)
< In-game debug mode flag (see field note).
void save(SaveFile *saveFile)
Flatten this region to the save.
Playtime * playtime
Definition worldother.h:118
protected::void debugModeChanged()
void reset()
Blank this region.
void clearPlaytime()
Zero the playtime clock.
void randomizePlaytime()
Randomize just the playtime clock.
void fossilPkmnResultChanged()