ScummVM API documentation
script.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  *
21  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_SCRIPT_H
29 #define GOB_SCRIPT_H
30 
31 #include "common/str.h"
32 #include "common/stack.h"
33 
34 #include "gob/totfile.h"
35 
36 namespace Gob {
37 
38 class GobEngine;
39 class Expression;
40 
41 class Script {
42 public:
43  Script(GobEngine *vm);
44  ~Script();
45 
47  uint32 read(byte *data, int32 size);
49  uint32 peek(byte *data, int32 size, int32 offset = 0) const;
50 
51  // Stream properties
52  int32 pos() const;
53  int32 getSize() const;
54 
55  // Stream seeking
56  bool seek(int32 offset, int whence = SEEK_SET);
57  bool skip(int32 offset);
58  bool skipBlock();
59 
60  // Reading data
61  byte readByte ();
62  char readChar ();
63  uint8 readUint8 ();
64  uint16 readUint16();
65  uint32 readUint32();
66  int8 readInt8 ();
67  int16 readInt16 ();
68  int32 readInt32 ();
69  char *readString(int32 length = -1);
70 
71  // Peeking data
72  byte peekByte (int32 offset = 0);
73  char peekChar (int32 offset = 0);
74  uint8 peekUint8 (int32 offset = 0);
75  uint16 peekUint16(int32 offset = 0);
76  uint32 peekUint32(int32 offset = 0);
77  int8 peekInt8 (int32 offset = 0);
78  int16 peekInt16 (int32 offset = 0);
79  int32 peekInt32 (int32 offset = 0);
80  char *peekString(int32 offset = 0);
81 
82  // Expression parsing functions
83  uint16 readVarIndex(uint16 *size = 0, uint16 *type = 0);
84  int16 readValExpr(byte stopToken = 99);
85  int16 readExpr(byte stopToken, byte *type);
86  void skipExpr(char stopToken);
87 
88  // Higher-level expression parsing functions
89  char evalExpr(int16 *pRes);
90  bool evalBool();
91  int32 evalInt();
92 
93  const char *evalString();
94 
95  // Accessing the result of expressions
96  int32 getResultInt() const;
97  char *getResultStr() const;
98 
100  int32 getOffset(byte *ptr) const;
102  byte *getData(int32 offset) const;
103 
105  byte *getData();
106 
108  bool load(const Common::String &fileName);
110  void unload();
112  bool isLoaded() const;
113 
115  void setFinished(bool finished);
117  bool isFinished() const;
118 
119  // Call stack operations
121  void push();
123  void pop(bool ret = true);
125  void call(uint32 offset);
126 
128  void writeByte(int32 offset, byte v);
129 
130  // Fixed properties
131  uint8 getVersionMajor () const;
132  uint8 getVersionMinor () const;
133  uint32 getVariablesCount () const;
134  uint32 getTextsOffset () const;
135  uint32 getResourcesOffset() const;
136  uint16 getAnimDataSize () const;
137  uint8 getImFileNumber () const;
138  uint8 getExFileNumber () const;
139  uint8 getCommunHandling () const;
140 
141  uint16 getFunctionOffset (uint8 function) const;
142 
143  static uint32 getVariablesCount(const char *fileName, GobEngine *vm);
144 
145 private:
146  struct CallEntry {
147  byte *totPtr;
148  bool finished;
149  };
150 
151  GobEngine *_vm;
152  Expression *_expression;
153 
154  bool _finished;
155 
156  Common::String _totFile;
157  byte *_totData;
158  byte *_totPtr;
159  uint32 _totSize;
160 
162 
163  TOTFile::Properties _totProperties;
164 
165  Common::Stack<CallEntry> _callStack;
166 
168  bool loadTOT(const Common::String &fileName);
170  bool loadLOM(const Common::String &fileName);
171 
173  void unloadTOT();
174 };
175 
176 } // End of namespace Gob
177 
178 #endif // GOB_SCRIPT_H
Definition: gob.h:163
Definition: str.h:59
byte * getData()
bool isLoaded() const
int32 getOffset(byte *ptr) const
uint32 peek(byte *data, int32 size, int32 offset=0) const
Definition: expression.h:114
Definition: script.h:41
Definition: stream.h:745
void unload()
Definition: anifile.h:40
bool load(const Common::String &fileName)
void setFinished(bool finished)
void call(uint32 offset)
void pop(bool ret=true)
Definition: totfile.h:46
void writeByte(int32 offset, byte v)
uint32 read(byte *data, int32 size)
bool isFinished() const