-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathWZScriptEncode.cpp
More file actions
247 lines (204 loc) · 4 KB
/
WZScriptEncode.cpp
File metadata and controls
247 lines (204 loc) · 4 KB
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
// ------------------------------
// Decompiled by Deathway
// Date : 2007-05-09
// ------------------------------
#include "stdafx.h"
#include "WZScriptEncode.h"
// GS-N 0.99.60T // 48c100 Status : Completed 2007-4-30
// GS-N 1.00.18 JPN 0x004A7270 - Completed
unsigned char XorTable[10]={0xA1, 0xB2, 0xAA, 0x12, 0x23, 0xF1, 0xF3, 0xD3, 0x78, 0x02}; // For some reason this is 16
CWZScriptEncode::CWZScriptEncode()
{
this->m_pBuffer=0;
this->m_iBufferSize=0;
this->m_iBufferCount=0;
this->m_hFile=INVALID_HANDLE_VALUE;
}
CWZScriptEncode::~CWZScriptEncode()
{
this->Close();
}
int CWZScriptEncode::Open(char* filename)
{
int filesize;
char* pBuffer;
int iReadFileSize;
if ( this->m_hFile != INVALID_HANDLE_VALUE )
{
CloseHandle( this->m_hFile );
}
this->m_hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0x80 , NULL); // 0x80 == NORMAL
if ( this->m_hFile == INVALID_HANDLE_VALUE )
{
return 0;
}
filesize = GetFileSize(this->m_hFile , NULL);
pBuffer = (char*)malloc(filesize);
ReadFile(this->m_hFile, (void*)pBuffer, filesize, (unsigned long*)&iReadFileSize, 0);
if ( iReadFileSize == 0 )
{
this->Close();
return 0;
}
this->Encode(pBuffer, iReadFileSize);
this->SetScriptParsingBuffer(pBuffer, iReadFileSize);
CloseHandle(this->m_hFile );
return 1;
}
void CWZScriptEncode::Close()
{
if ( this->m_pBuffer != 0)
{
free( this->m_pBuffer );
}
}
void CWZScriptEncode::Encode(char* buffer, int size)
{
int i;
for (i=0;i<size; i++)
{
buffer[i]=buffer[i]^XorTable[i%10];
}
}
int CWZScriptEncode::GetC()
{
if ( this->m_iBufferCount >= this->m_iBufferSize )
{
return -1;
}
else
{
return this->m_pBuffer [ this->m_iBufferCount++ ];
}
}
void CWZScriptEncode::UnGetC(int ch)
{
if ( this->m_iBufferCount <= 0)
{
return;
}
else
{
this->m_iBufferCount--;
this->m_pBuffer [ this->m_iBufferCount ] = ch;
}
}
void CWZScriptEncode::SetScriptParsingBuffer( char* buffer, int size)
{
this->m_pBuffer = buffer;
this->m_iBufferSize = size;
this->m_iBufferCount = 0;
}
int CWZScriptEncode::GetNumber()
{
return this->TokenNumber;
}
char* CWZScriptEncode::GetString()
{
return &this->TokenString[0];
}
enum WZSMDToken CWZScriptEncode::GetToken()
{
char ch;
char* p;
char TempString[100];
this->TokenString[0]=0; // Set String NULL
do
{
if ( (ch=this->GetC ()) == (-1) )
{
return T_END;
}
else
{
if (ch=='/') // this is /
{
if((ch=this->GetC ()) == '/')
{
while ( ((ch=this->GetC()) != ('\n')) ) // End of Line (EOL)
{
continue;
}
}
}
}
}
while (isspace(ch) != 0);
switch(ch)
{
case 0x23: // #
return this->CurrentToken=T_COMMAND;
break;
case 0x3B: // ;
return this->CurrentToken=T_SEMICOLON;
break;
case 0x2C: // ,
return this->CurrentToken=T_COMMA;
break;
case 0x7B: // {
return this->CurrentToken = T_LP;
break;
case 0x7D: // }
return this->CurrentToken = T_RP;
break;
// Nice Index Table :) by Deathway
case 0x2D: //-
case 0x2E: //.
case 0x30: //0
case 0x31: //1
case 0x32: //2
case 0x33: //3
case 0x34: //4
case 0x35: //5
case 0x36: //6
case 0x37: //7
case 0x38: //8
case 0x39: //9
this->UnGetC (ch);
p = TempString;
while (((ch=this->GetC()) != -1) && ((ch == 0x2E) || (isdigit(ch) != 0) || (ch == 0x2D)))
{
*p = ch;
p++;
}
*p = 0;
this->TokenNumber = atof( TempString);
return this->CurrentToken = T_NUMBER ;
break;
case 0x22: // "
p=&this->TokenString[0];
while (((ch=this->GetC() ) != -1 ) && (ch != 0x22)) // nice
{
*p = ch;
p++;
}
if (ch != 0x22 )
{
this->UnGetC(ch);
}
*p = 0;
return this->CurrentToken = T_NAME;
break;
default:
if (isalpha(ch))
{
p=&this->TokenString[0];
*p=ch;
p++;
while ( ((ch=this->GetC() ) != -1) && ( (ch == 0x2E) || (ch == 0x5F) || (isalnum(ch) != 0) ) )
{
*p=ch;
p++;
}
this->UnGetC(ch);
*p=0;
this->CurrentToken=T_NAME;
return T_NAME;
}
else
{
return this->CurrentToken = T_SMD_ERROR;
}
break;
}
}