ScummVM API documentation
script.h
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 */
6
7#ifndef LINGODEC_SCRIPT_H
8#define LINGODEC_SCRIPT_H
9
10#include "common/ptr.h"
11#include "common/str.h"
12#include "./enums.h"
13
14namespace Common {
15class ReadStream;
16}
17
18namespace LingoDec {
19
20class CodeWriterVisitor;
21struct Datum;
22struct Handler;
23struct ScriptContext;
24
25/* LiteralStore */
26
28 LiteralType type;
29 uint32 offset;
31
32 void readRecord(Common::SeekableReadStream &stream, int version);
33 void readData(Common::SeekableReadStream &stream, uint32 startOffset);
34};
35
36/* Script */
37
38struct Script {
39 /* 8 */ uint32 totalLength;
40 /* 12 */ uint32 totalLength2;
41 /* 16 */ uint16 headerLength;
42 /* 18 */ uint16 scriptNumber;
43 /* 20 */ int16 unk20;
44 /* 22 */ int16 parentNumber;
45
46 /* 38 */ uint32 scriptFlags;
47 /* 42 */ int16 unk42;
48 /* 44 */ int16 unk43;
49 // This castID is not reliable
50 /* 46 */ int16 castID;
51 /* 48 */ int16 factoryNameID;
52 /* 50 */ uint16 handlerVectorsCount;
53 /* 52 */ uint32 handlerVectorsOffset;
54 /* 56 */ uint32 handlerVectorsSize;
55 /* 60 */ uint16 propertiesCount;
56 /* 62 */ uint32 propertiesOffset;
57 /* 66 */ uint16 globalsCount;
58 /* 68 */ uint32 globalsOffset;
59 /* 72 */ uint16 handlersCount;
60 /* 74 */ uint32 handlersOffset;
61 /* 78 */ uint16 literalsCount;
62 /* 80 */ uint32 literalsOffset;
63 /* 84 */ uint32 literalsDataCount;
64 /* 88 */ uint32 literalsDataOffset;
65
66 Common::Array<int16> propertyNameIDs;
67 Common::Array<int16> globalNameIDs;
68
69 Common::String factoryName;
75
76 unsigned int version;
77 ScriptContext *context;
78
79 Script(unsigned int version_);
80 ~Script();
81 void read(Common::SeekableReadStream &stream);
82 Common::Array<int16> readVarnamesTable(Common::SeekableReadStream &stream, uint16 count, uint32 offset);
83 bool validName(int id) const;
84 Common::String getName(int id) const;
85 void setContext(ScriptContext *ctx);
86 void parse();
87 void writeVarDeclarations(CodeWriterVisitor &code) const;
88 void writeScriptText(CodeWriterVisitor &code) const;
89 Common::String scriptText(const char *lineEnding, bool dotSyntax) const;
90 void writeBytecodeText(CodeWriterVisitor &code) const;
91 Common::String bytecodeText(const char *lineEnding, bool dotSyntax) const;
92
93 bool isFactory() const;
94};
95
96} // namespace LingoDec
97
98#endif // LINGODEC_SCRIPT_H
Definition: stream.h:745
Definition: ptr.h:159
Definition: str.h:59
Definition: codewritervisitor.h:14
Definition: algorithm.h:29
Definition: script.h:27
Definition: context.h:26
Definition: script.h:38