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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
#include "ZCutscene.h"
#include <cassert>
#include "Globals.h"
#include "OtherStructs/CutsceneMM_Commands.h"
#include "Utils/BitConverter.h"
#include "Utils/StringHelper.h"
#include "WarningHandler.h"
#include "ZResource.h"
REGISTER_ZFILENODE(Cutscene, ZCutscene);
ZCutscene::ZCutscene(ZFile* nParent) : ZResource(nParent)
{
genOTRDef = true;
}
ZCutscene::~ZCutscene()
{
for (CutsceneCommand* cmd : commands)
delete cmd;
}
std::string ZCutscene::GetBodySourceCode() const
{
std::string output = "";
output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),\n", commands.size(), endFrame);
for (size_t i = 0; i < commands.size(); i++)
{
CutsceneCommand* cmd = commands[i];
output += " " + cmd->GenerateSourceCode();
}
output += StringHelper::Sprintf(" CS_END(),", commands.size(), endFrame);
return output;
}
size_t ZCutscene::GetRawDataSize() const
{
size_t size = 0;
// Beginning
size += 8;
for (size_t i = 0; i < commands.size(); i++)
{
CutsceneCommand* cmd = commands[i];
size += cmd->GetCommandSize();
}
// End
if (Globals::Instance->game == ZGame::MM_RETAIL)
{
size += 4;
}
else
{
size += 8;
}
return size;
}
void ZCutscene::ParseRawData()
{
ZResource::ParseRawData();
const auto& rawData = parent->GetRawData();
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
commands = std::vector<CutsceneCommand*>();
endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
offset_t currentPtr = rawDataIndex + 8;
commands.reserve(numCommands);
for (int32_t i = 0; i < numCommands; i++)
{
uint32_t id = BitConverter::ToUInt32BE(rawData, currentPtr);
if (id == 0xFFFFFFFF)
break;
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
{
printf("Cutscene Command: 0x%X (%i)\n", id, id);
}
currentPtr += 4;
CutsceneCommand* cmd = nullptr;
if (Globals::Instance->game == ZGame::MM_RETAIL)
{
cmd = GetCommandMM(id, currentPtr);
}
else
{
cmd = GetCommandOoT(id, currentPtr);
}
if (cmd == nullptr)
{
HANDLE_WARNING_RESOURCE(
WarningType::NotImplemented, parent, this, rawDataIndex,
StringHelper::Sprintf("Cutscene command not implemented"),
StringHelper::Sprintf("Command ID: 0x%X\nIndex: %d\ncurrentPtr-rawDataIndex: 0x%X",
id, i, currentPtr - rawDataIndex));
cmd = new CutsceneMMCommand_NonImplemented(rawData, currentPtr);
}
assert(cmd != nullptr);
cmd->commandIndex = i;
cmd->SetCommandID(id);
size_t commmandSize = cmd->GetCommandSize();
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
{
printf("\t Command size: 0x%zX (%zu)\n", commmandSize, commmandSize);
}
currentPtr += commmandSize - 4;
commands.push_back(cmd);
}
}
CutsceneCommand* ZCutscene::GetCommandOoT(uint32_t id, offset_t currentPtr) const
{
CutsceneCommands cmdID = static_cast<CutsceneCommands>(id);
const auto& rawData = parent->GetRawData();
switch (id)
{
case 10: // CutsceneCommands::SetPlayerAction
case 15: // CutsceneCommands::SetActorAction1
case 17:
case 18:
case 23:
case 34:
case 39:
case 46:
case 76:
case 85:
case 93:
case 105:
case 107:
case 110:
case 119:
case 123:
case 138:
case 139:
case 144:
case 14: // CutsceneCommands::SetActorAction2
case 16:
case 24:
case 35:
case 40:
case 48:
case 64:
case 68:
case 70:
case 78:
case 80:
case 94:
case 116:
case 118:
case 120:
case 125:
case 131:
case 141:
case 25: // CutsceneCommands::SetActorAction3
case 36:
case 41:
case 50:
case 67:
case 69:
case 72:
case 81:
case 106:
case 117:
case 121:
case 126:
case 132:
case 29: // CutsceneCommands::SetActorAction4
case 37:
case 42:
case 51:
case 53:
case 63:
case 65:
case 66:
case 75:
case 82:
case 108:
case 127:
case 133:
case 30: // CutsceneCommands::SetActorAction5
case 38:
case 43:
case 47:
case 54:
case 79:
case 83:
case 128:
case 135:
case 44: // CutsceneCommands::SetActorAction6
case 55:
case 77:
case 84:
case 90:
case 129:
case 136:
case 31: // CutsceneCommands::SetActorAction7
case 52:
case 57:
case 58:
case 88:
case 115:
case 130:
case 137:
case 49: // CutsceneCommands::SetActorAction8
case 60:
case 89:
case 111:
case 114:
case 134:
case 142:
case 62: // CutsceneCommands::SetActorAction9
case 143: // CutsceneCommands::SetActorAction10
return new CutsceneCommand_ActorAction(rawData, currentPtr);
case 0x0B:
case 0x0D:
case 0x1A:
case 0x1B:
case 0x1C:
case 0x20:
case 0x21:
case 0x3B:
case 0x3D:
case 0x47:
case 0x49:
case 0x6D:
case 0x15:
case 0x16:
case 0x70:
case 0x71:
case 0x4A:
return new CutsceneCommand_GenericCmd(rawData, currentPtr, cmdID);
}
switch (cmdID)
{
case CutsceneCommands::Misc:
case CutsceneCommands::SetLighting:
case CutsceneCommands::PlayBGM:
case CutsceneCommands::StopBGM:
case CutsceneCommands::FadeBGM:
return new CutsceneCommand_GenericCmd(rawData, currentPtr, cmdID);
case CutsceneCommands::SetCameraPos:
case CutsceneCommands::SetCameraFocus:
case CutsceneCommands::SetCameraPosLink:
case CutsceneCommands::SetCameraFocusLink:
return new CutsceneCommandSetCameraPos(rawData, currentPtr);
case CutsceneCommands::Cmd07:
break;
case CutsceneCommands::Cmd08:
break;
case CutsceneCommands::Cmd09:
return new CutsceneCommand_Rumble(rawData, currentPtr);
case CutsceneCommands::Textbox:
return new CutsceneCommand_TextBox(rawData, currentPtr);
case CutsceneCommands::SetPlayerAction:
case CutsceneCommands::SetActorAction1:
case CutsceneCommands::SetActorAction2:
case CutsceneCommands::SetActorAction3:
case CutsceneCommands::SetActorAction4:
case CutsceneCommands::SetActorAction5:
case CutsceneCommands::SetActorAction6:
case CutsceneCommands::SetActorAction7:
case CutsceneCommands::SetActorAction8:
case CutsceneCommands::SetActorAction9:
case CutsceneCommands::SetActorAction10:
break;
case CutsceneCommands::SetSceneTransFX:
return new CutsceneCommandSceneTransFX(rawData, currentPtr);
case CutsceneCommands::SetTime:
return new CutsceneCommand_SetTime(rawData, currentPtr);
case CutsceneCommands::Terminator:
return new CutsceneCommand_Terminator(rawData, currentPtr);
}
return nullptr;
}
CutsceneCommand* ZCutscene::GetCommandMM(uint32_t id, offset_t currentPtr) const
{
CutsceneMMCommands cmdID = static_cast<CutsceneMMCommands>(id);
const auto& rawData = parent->GetRawData();
if (((id >= 100) && (id < 150)) || (id == 201) || ((id >= 450) && (id < 600)))
{
return new CutsceneCommand_ActorAction(rawData, currentPtr);
}
switch (cmdID)
{
case CutsceneMMCommands::CS_CMD_MISC:
case CutsceneMMCommands::CS_CMD_SET_LIGHTING:
case CutsceneMMCommands::CS_CMD_SCENE_TRANS_FX:
case CutsceneMMCommands::CS_CMD_MOTIONBLUR:
case CutsceneMMCommands::CS_CMD_GIVETATL:
case CutsceneMMCommands::CS_CMD_PLAYSEQ:
case CutsceneMMCommands::CS_CMD_130:
case CutsceneMMCommands::CS_CMD_131:
case CutsceneMMCommands::CS_CMD_132:
case CutsceneMMCommands::CS_CMD_STOPSEQ:
case CutsceneMMCommands::CS_CMD_PLAYAMBIENCE:
case CutsceneMMCommands::CS_CMD_FADEAMBIENCE:
case CutsceneMMCommands::CS_CMD_TERMINATOR:
case CutsceneMMCommands::CS_CMD_CHOOSE_CREDITS_SCENES:
case CutsceneMMCommands::CS_CMD_UNK_FA:
case CutsceneMMCommands::CS_CMD_UNK_FE:
case CutsceneMMCommands::CS_CMD_UNK_FF:
case CutsceneMMCommands::CS_CMD_UNK_100:
case CutsceneMMCommands::CS_CMD_UNK_101:
case CutsceneMMCommands::CS_CMD_UNK_102:
case CutsceneMMCommands::CS_CMD_UNK_103:
case CutsceneMMCommands::CS_CMD_UNK_104:
case CutsceneMMCommands::CS_CMD_UNK_105:
case CutsceneMMCommands::CS_CMD_UNK_108:
case CutsceneMMCommands::CS_CMD_UNK_109:
case CutsceneMMCommands::CS_CMD_UNK_12D:
return new CutsceneMMCommand_GenericCmd(rawData, currentPtr, cmdID);
case CutsceneMMCommands::CS_CMD_TEXTBOX:
return new CutsceneCommand_TextBox(rawData, currentPtr);
case CutsceneMMCommands::CS_CMD_CAMERA:
return new CutsceneMMCommand_Camera(rawData, currentPtr);
case CutsceneMMCommands::CS_CMD_FADESCREEN:
return new CutsceneMMCommand_FadeScreen(rawData, currentPtr);
case CutsceneMMCommands::CS_CMD_FADESEQ:
return new CutsceneMMCommand_FadeSeq(rawData, currentPtr);
case CutsceneMMCommands::CS_CMD_SETTIME:
return new CutsceneCommand_SetTime(rawData, currentPtr);
case CutsceneMMCommands::CS_CMD_SET_PLAYER_ACTION:
return new CutsceneCommand_ActorAction(rawData, currentPtr);
case CutsceneMMCommands::CS_CMD_RUMBLE:
return new CutsceneCommand_Rumble(rawData, currentPtr);
}
return nullptr;
}
Declaration* ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
std::string auxName = name;
if (auxName == "")
auxName = GetDefaultName(prefix);
Declaration* decl =
parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
GetSourceTypeName(), auxName, 0, bodyStr);
decl->staticConf = staticConf;
return decl;
}
std::string ZCutscene::GetSourceTypeName() const
{
return "CutsceneData";
}
ZResourceType ZCutscene::GetResourceType() const
{
return ZResourceType::Cutscene;
}
|