Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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"
28#include <pse-db/scripts.h>
29
31{
32 load(saveFile);
33}
34
36
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
59
60 delete it;
61}
62
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
83{
84 return scriptCount;
85}
86
88{
89 return curScripts[ind];
90}
91
92void WorldScripts::scriptsSet(int ind, int val)
93{
94 curScripts[ind] = val;
96}
97
99{
100 memset(curScripts, 0, static_cast<size_t>(scriptCount) * 2); // 2 * 8-bit widths
102}
103
104// We want the player to start from the beginning
106{
107 reset();
108}
SaveFileIterator * offsetTo(var16 val)
Move the cursor to an absolute offset. Returns this for chaining.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
SaveFileIterator * iterator()
Returns a unique iterator that's setup to iterate over the raw sav file data.
Definition savefile.cpp:53
static ScriptsDB * inst()
< Number of scripts.
Definition scripts.cpp:67
int scriptsAt(int ind)
Script value for map index ind.
protected::void curScriptsChanged()
void reset()
Zero all script values.
var16 curScripts[scriptCount]
Per-map script-progress values.
virtual ~WorldScripts()
void load(SaveFile *saveFile=nullptr)
Expand the script values from the save.
void randomize()
Randomize the script values.
void save(SaveFile *saveFile)
Flatten the script values to the save.
int scriptsCount()
Number of script values (scriptCount).
void scriptsSet(int ind, int val)
Set the script value for ind.
WorldScripts(SaveFile *saveFile=nullptr)
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition types.h:125
constexpr var8 scriptCount
Number of per-map script-progress values.