Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
worldscripts.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 <string.h>
23
24
#include "
./worldscripts.h
"
25
#include "
../../savefile.h
"
26
#include "
../../savefiletoolset.h
"
27
#include "
../../savefileiterator.h
"
28
#include <
pse-db/scripts.h
>
29
30
WorldScripts::WorldScripts
(
SaveFile
* saveFile)
31
{
32
load
(saveFile);
33
}
34
35
WorldScripts::~WorldScripts
() {}
36
37
void
WorldScripts::load
(
SaveFile
* saveFile)
38
{
39
if
(saveFile ==
nullptr
)
40
return
reset
();
41
42
auto
it = saveFile->
iterator
()->
offsetTo
(0x289C);
43
44
for
(
auto
scriptEntry :
ScriptsDB::inst
()->getStore()) {
45
var16
val;
46
47
if
(scriptEntry->size == 1)
48
val = it->getByte();
49
else
50
val = it->getWord();
51
52
curScripts
[scriptEntry->ind] = val;
53
54
if
(scriptEntry->skip)
55
it->skipPadding(*scriptEntry->skip);
56
}
57
58
curScriptsChanged
();
59
60
delete
it;
61
}
62
63
void
WorldScripts::save
(
SaveFile
* saveFile)
64
{
65
auto
it = saveFile->
iterator
()->
offsetTo
(0x289C);
66
67
for
(
auto
scriptEntry :
ScriptsDB::inst
()->getStore()) {
68
var16
val =
curScripts
[scriptEntry->ind];
69
70
if
(scriptEntry->size == 1)
71
it->setByte(val);
72
else
73
it->setWord(val);
74
75
if
(scriptEntry->skip)
76
it->skipPadding(*scriptEntry->skip);
77
}
78
79
delete
it;
80
}
81
82
int
WorldScripts::scriptsCount
()
83
{
84
return
scriptCount
;
85
}
86
87
int
WorldScripts::scriptsAt
(
int
ind)
88
{
89
return
curScripts
[ind];
90
}
91
92
void
WorldScripts::scriptsSet
(
int
ind,
int
val)
93
{
94
curScripts
[ind] = val;
95
curScriptsChanged
();
96
}
97
98
void
WorldScripts::reset
()
99
{
100
memset(
curScripts
, 0,
static_cast<
size_t
>
(
scriptCount
) * 2);
// 2 * 8-bit widths
101
curScriptsChanged
();
102
}
103
104
// We want the player to start from the beginning
105
void
WorldScripts::randomize
()
106
{
107
reset
();
108
}
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
ScriptsDB::inst
static ScriptsDB * inst()
< Number of scripts.
Definition
scripts.cpp:67
WorldScripts::scriptsAt
int scriptsAt(int ind)
Script value for map index ind.
Definition
worldscripts.cpp:87
WorldScripts::curScriptsChanged
protected::void curScriptsChanged()
WorldScripts::reset
void reset()
Zero all script values.
Definition
worldscripts.cpp:98
WorldScripts::curScripts
var16 curScripts[scriptCount]
Per-map script-progress values.
Definition
worldscripts.h:60
WorldScripts::~WorldScripts
virtual ~WorldScripts()
Definition
worldscripts.cpp:35
WorldScripts::load
void load(SaveFile *saveFile=nullptr)
Expand the script values from the save.
Definition
worldscripts.cpp:37
WorldScripts::randomize
void randomize()
Randomize the script values.
Definition
worldscripts.cpp:105
WorldScripts::save
void save(SaveFile *saveFile)
Flatten the script values to the save.
Definition
worldscripts.cpp:63
WorldScripts::scriptsCount
int scriptsCount()
Number of script values (scriptCount).
Definition
worldscripts.cpp:82
WorldScripts::scriptsSet
void scriptsSet(int ind, int val)
Set the script value for ind.
Definition
worldscripts.cpp:92
WorldScripts::WorldScripts
WorldScripts(SaveFile *saveFile=nullptr)
Definition
worldscripts.cpp:30
var16
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition
types.h:125
savefile.h
savefileiterator.h
savefiletoolset.h
scripts.h
worldscripts.h
scriptCount
constexpr var8 scriptCount
Number of per-map script-progress values.
Definition
worldscripts.h:25
projects
savefile
src
pse-savefile
expanded
world
worldscripts.cpp
Generated by
1.17.0