-
Notifications
You must be signed in to change notification settings - Fork 15
/
JsmData.cpp
176 lines (151 loc) · 4.3 KB
/
JsmData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/****************************************************************************
** Deling Final Fantasy VIII Field Editor
** Copyright (C) 2009-2012 Arzel Jérôme <[email protected]>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "JsmData.h"
JsmData::JsmData() :
_demo(false)
{
}
JsmData::JsmData(const QByteArray &scriptData, bool demo) :
scriptData(scriptData), _demo(demo)
{
if(this->scriptData.size() % 4 != 0) {
qWarning() << "JsmData::JsmData : Incorrect size" << this->scriptData.size();
this->scriptData.resize(this->scriptData.size() - (this->scriptData.size() % 4));
}
}
int JsmData::nbOpcode() const
{
return scriptData.size()/4;
}
JsmData &JsmData::append(const JsmOpcode &opcode)
{
quint32 op = opcode.opcode();
scriptData.append((char *)&op, 4);
return *this;
}
JsmData &JsmData::append(const JsmData &jsmData)
{
scriptData.append(jsmData.constData());
return *this;
}
JsmOpcode JsmData::opcode(int opcodeID) const
{
const char *constData = scriptData.constData();
quint32 op=0;
memcpy(&op, constData + opcodeID * 4, 4);
JsmOpcode ret(op);
// CANIME and CANIMEKEEP does not exist in early demo version
if(_demo && ret.key() >= JsmOpcode::CANIME) {
ret.setKey(ret.key() + 2);
}
return ret;
}
JsmOpcode *JsmData::opcodep(int opcodeID) const
{
JsmOpcode op = opcode(opcodeID);
switch(op.key()) {
case JsmOpcode::CAL:
return new JsmOpcodeCal(op);
case JsmOpcode::PSHN_L:
case JsmOpcode::PSHI_L:
case JsmOpcode::PSHM_B:
case JsmOpcode::PSHM_W:
case JsmOpcode::PSHM_L:
case JsmOpcode::PSHSM_B:
case JsmOpcode::PSHSM_W:
case JsmOpcode::PSHSM_L:
case JsmOpcode::PSHAC:
return new JsmOpcodePsh(op);
case JsmOpcode::POPI_L:
case JsmOpcode::POPM_B:
case JsmOpcode::POPM_W:
case JsmOpcode::POPM_L:
return new JsmOpcodePop(op);
default:
return new JsmOpcode(op);
}
}
QList<JsmOpcode *> JsmData::opcodesp(int opcodeID, int nbOpcode) const
{
QList<JsmOpcode *> ret;
int count;
if(nbOpcode >= 0) {
count = nbOpcode;
} else {
count = this->nbOpcode() - opcodeID;
}
for(int i = 0 ; i < count ; ++i) {
ret.append(opcodep(opcodeID + i));
}
return ret;
}
JsmData &JsmData::setOpcode(int opcodeID, const JsmOpcode &opcode)
{
quint32 op = opcode.opcode();
scriptData.replace(opcodeID*4, 4, (char *)&op, 4);
return *this;
}
JsmData &JsmData::insertOpcode(int opcodeID, const JsmOpcode &opcode)
{
quint32 op = opcode.opcode();
scriptData.insert(opcodeID*4, (char *)&op, 4);
return *this;
}
JsmData &JsmData::insert(int opcodeID, const JsmData &data)
{
scriptData.insert(opcodeID*4, data.constData());
return *this;
}
JsmData &JsmData::remove(int opcodeID, int nbOpcode)
{
scriptData.remove(opcodeID*4, nbOpcode*4);
return *this;
}
JsmData &JsmData::replace(int opcodeID, int nbOpcode, const JsmData &after)
{
scriptData.replace(opcodeID*4, nbOpcode*4, after.constData());
return *this;
}
JsmData JsmData::mid(int opcodeID, int nbOpcode) const
{
return JsmData(scriptData.mid(opcodeID*4, nbOpcode==-1 ? nbOpcode : nbOpcode*4), _demo);
}
const QByteArray &JsmData::constData() const
{
return scriptData;
}
JsmData &JsmData::operator+=(const JsmOpcode &opcode)
{
return append(opcode);
}
JsmData &JsmData::operator+=(const JsmData &data)
{
return append(data);
}
bool JsmData::operator==(const JsmData &data) const
{
return this->constData() == data.constData();
}
bool JsmData::operator!=(const JsmData &data) const
{
return !(*this == data);
}
JsmOpcode JsmData::operator[](int opcodeID) const
{
return opcode(opcodeID);
}