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
|
#ifndef TIBIA_SCRIPT_HH_
#define TIBIA_SCRIPT_HH_ 1
#include "common.hh"
#include "enums.hh"
#define MAX_IDENT_LENGTH 30
struct TReadScriptFile {
TReadScriptFile(void);
~TReadScriptFile(void);
void open(const char *FileName);
void close(void);
void error(const char *Text);
void nextToken(void);
char *getIdentifier(void);
int getNumber(void);
char *getString(void);
uint8 *getBytesequence(void);
void getCoordinate(int *x, int *y, int *z);
char getSpecial(void);
char *readIdentifier(void){
this->nextToken();
return this->getIdentifier();
}
int readNumber(void){
this->nextToken();
int Sign = 1;
if(this->Token == SPECIAL && this->Special == '-'){
Sign = -1;
this->nextToken();
}
return Sign * this->getNumber();
}
char *readString(void){
this->nextToken();
return this->getString();
}
uint8 *readBytesequence(void){
this->nextToken();
return this->getBytesequence();
}
void readCoordinate(int *x, int *y, int *z){
this->nextToken();
this->getCoordinate(x, y, z);
}
char readSpecial(void){
this->nextToken();
return this->getSpecial();
}
void readSymbol(char Symbol){
if(this->readSpecial() != Symbol){
this->error("symbol mismatch");
}
}
// DATA
// =================
TOKEN Token;
FILE *File[3];
char Filename[3][4096];
int Line[3];
char String[4000];
int RecursionDepth;
uint8 *Bytes;
int Number;
int CoordX;
int CoordY;
int CoordZ;
char Special;
};
struct TWriteScriptFile {
TWriteScriptFile(void);
~TWriteScriptFile(void);
void open(const char *FileName);
void close(void);
void error(const char *Text);
void writeLn(void);
void writeText(const char *Text);
void writeNumber(int Number);
void writeString(const char *Text);
void writeCoordinate(int x ,int y ,int z);
void writeBytesequence(const uint8 *Sequence, int Length);
// DATA
// =================
FILE *File;
char Filename[4096];
int Line;
};
struct TReadBinaryFile: TReadStream {
TReadBinaryFile(void);
void open(const char *FileName);
void close(void);
void error(const char *Text);
int getPosition(void);
int getSize(void);
void seek(int Offset);
// VIRTUAL FUNCTIONS
// =================
uint8 readByte(void) override;
void readBytes(uint8 *Buffer, int Count) override;
bool eof(void) override;
void skip(int Count) override;
// TODO(fusion): Appended virtual functions. These are not in the base class
// VTABLE which can be problematic if we intend to use polymorphism, although
// that doesn't seem to be case.
virtual ~TReadBinaryFile(void); // VTABLE[8]
// Duplicate destructor that also calls operator delete. // VTABLE[9]
// DATA
// =================
FILE *File;
char Filename[4096];
int FileSize;
};
struct TWriteBinaryFile: TWriteStream {
TWriteBinaryFile(void);
void open(const char *FileName);
void close(void);
void error(const char *Text);
// VIRTUAL FUNCTIONS
// =================
void writeByte(uint8 Byte) override;
void writeBytes(const uint8 *Buffer, int Count) override;
// TODO(fusion): Appended virtual functions. These are not in the base class
// VTABLE which can be problematic if we intend to use polymorphism, although
// that doesn't seem to be case.
virtual ~TWriteBinaryFile(void);
// DATA
// =================
FILE *File;
char Filename[4096];
};
#endif //TIBIA_SCRIPT_HH_
|