Repository navigation
Expand file tree
/
Copy pathQBReader.cpp
More file actions
358 lines (258 loc) · 7.18 KB
/
Copy pathQBReader.cpp
File metadata and controls
358 lines (258 loc) · 7.18 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
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
#include <windows.h>
#include <stdio.h>
// defines
#define GET_ULONG (unsigned long)*(unsigned long*)&
#define GET_USHORT (unsigned short)*(unsigned short*)&
// variables
char g_fileName[MAX_PATH]= "";
unsigned long **g_keyID;
char **g_keyName;
unsigned short g_keyNum = 0;
unsigned char *g_qbData;
unsigned long g_qbSize;
// functions
bool OnLoadFile();
bool OnLoadKeys();
bool OnSaveQB();
int main(int argc, char* argv[])
{
printf(" ___\n");
printf(" __ /\\__\\\n");
printf(" /\\ \\/ / /\n");
printf(" \\ \\/ / / ________\n");
printf(" \\ / / - - -/ \\-\n");
printf(" / / / oshua SOFTWARE\n");
printf(" \\/__/ - - - -\\________/-\n");
printf("\n");
printf("***************************\n");
printf(" THUG2 QB Reader\n");
printf("***************************\n");
printf("Author: yosh64/defeat0r\n");
printf("Website: http://jmn-web.tk\n\n");
printf("<- description\n");
printf("Extract any THUG2 QB Script\n");
printf("file into a readable format.\n\n");
// check runtime parameter count...
if(argc < 2) {
// open file dialog
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFilter = "QB File (*.qb)\0*.qb\0\0";
ofn.lpstrFile = g_fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrInitialDir = NULL;
if(!GetOpenFileName(&ofn)) {
printf("ERROR: No file selected!\n\n");
system("PAUSE");
return 0;
}
}
else {
strcpy(g_fileName, argv[1]);
}
// varify arguments
if(argc > 2) {
printf("+ USAGE: QBReader.exe [input.qb]\n");
return 0;
}
// load qb data
OnLoadFile();
// load key ids
if(!OnLoadKeys()) {
printf("ERROR: Unable to load Key Data!\n\n");
system("PAUSE");
return 0;
}
// tests
printf("<- testing\n");
printf("QB File Size: %i bytes\n", g_qbSize);
printf("Number of Keys: %i \n", (g_keyNum-1));
printf("Key Name [0]: %s \n\n", g_keyName[0]);
// set output filename
short fnLen = strlen(g_fileName);
g_fileName[fnLen-1] = 't';
g_fileName[fnLen-2] = 'x';
g_fileName[fnLen-3] = 't';
g_fileName[fnLen-4] = '.';
// save qb
OnSaveQB();
// free memory
delete[] g_keyID;
delete[] g_keyName;
delete[] g_qbData;
// pause at end
system("PAUSE");
return 0;
}
bool OnLoadFile()
{
FILE *inFile;
inFile = fopen(g_fileName, "rb");
// check if file was opened
if(! inFile) {
printf("ERROR: Unable to open file to load.");
return NULL;
}
// get file size
fseek(inFile, 0, SEEK_END);
g_qbSize = ftell(inFile);
fseek(inFile, 0, SEEK_SET);
// allocate memory
g_qbData = new unsigned char [g_qbSize];
// read data
fread(g_qbData, 1, g_qbSize, inFile);
fclose(inFile);
return true;
}
bool OnLoadKeys()
{
unsigned long keyOffset;
unsigned long lp, lp2, cnt=0;
// Values before declearation...
// 01 04 01 2B
// 01 06 01 2B
// 01 24 01 2B
// 00 06 01 2B
// 21 01 00 2B
// 80 3E 01 2B
// 23 3C 01 2B
// CE 00 00 2B
// 01 2B and 00 2B <- just need these???
// seek to start of key declaration data
for(lp=0;lp<g_qbSize-4;lp++) {
if(GET_USHORT g_qbData[lp] == 0x2B01 || GET_USHORT g_qbData[lp] == 0x2B00) {
keyOffset = lp+1;
break;
}
}
// check if key data offset was found
if(keyOffset == 0) return false;
// find number of keys
for(lp=keyOffset;lp<g_qbSize;lp++) if(g_qbData[lp] == 0x2B) lp+=5, g_keyNum++;
// allocate memory
g_keyID = new unsigned long *[g_keyNum];
g_keyName = new char *[g_keyNum];
lp = keyOffset;
while(lp < g_qbSize) {
if(g_qbData[lp] == 0x2B) { // 0x2B before each key
// set key id
g_keyID[cnt] = (unsigned long*)&g_qbData[lp+1];
// set key name
lp += 5; // goto name
g_keyName[cnt] = (char*)&g_qbData[lp]; // set pointer to string
while(g_qbData[lp] != 0x00) lp++;
lp++, cnt++;
}
else break; // lp++ ???
}
return true;
}
bool OnSaveQB()
{
unsigned long lp, lp2;
short inc = 0;
char strOut[512];
int intOut = 0;
FILE *outFile;
outFile = fopen(g_fileName, "wt");
// check if file was opened
if(!outFile) {
printf("ERROR: Unable to open file to save.");
return false;
}
// output file header
fprintf(outFile, " ___\n __ /\\__\\\n /\\ \\/ / /\n \\ \\/ / /\n \\ / /_ _ _ /¯ ¯ ¯ ¯ \\ _\n / / / oshua SOFTWARE \n \\/ / ¯ ¯ ¯ \\_ _ _ _ / ¯\n ¯¯¯ \n-----------------------------\n+++ THUG2 QB READER\nVersion: 0.5\nWebsite: http://jmn-web.tk\nTHPS Alias: Defeat0r\n\n\n---------- QB START\n\n");
// loop through qb
for(lp=0;lp<g_qbSize;lp++) {
inc = 0;
switch(g_qbData[lp])
{
case 0x03: { // begin section
fprintf(outFile, "%08X:%02X ** BEGIN SECTION ** \n", lp, g_qbData[lp]);
break;
}
case 0x04: { // end section
fprintf(outFile, "%08X:%02X ** END SECTION ** \n", lp, g_qbData[lp]);
break;
}
case 0x05: { // begin array
fprintf(outFile, "%08X:%02X ** BEGIN ARRAY ** \n", lp, g_qbData[lp]);
break;
}
case 0x06: { // end array
fprintf(outFile, "%08X:%02X ** END ARRAY ** \n", lp, g_qbData[lp]);
break;
}
case 0x47: { // ???
fprintf(outFile, "%08X:%02X %02X \n", lp, g_qbData[lp], g_qbData[lp+1]);
inc++;
break;
}
case 0x48: { // ???
fprintf(outFile, "%08X:%02X %02X %02X %02X \n", lp, g_qbData[lp], g_qbData[lp+1], g_qbData[lp+2], g_qbData[lp+3]);
inc += 2;
break;
}
// 0x48
case 0x2B: { // declaration
lp2 = 0;
// loop through string
while(g_qbData[(lp+5)+lp2] != 0x00) {
strOut[lp2] = g_qbData[(lp+5)+lp2];
lp2++;
}
strOut[lp2] = '\0'; // null terminator
fprintf(outFile, "%08X:%02X %02X %02X %02X %02X :: %s \n", lp, g_qbData[lp], g_qbData[lp+1], g_qbData[lp+2], g_qbData[lp+3], g_qbData[lp+4], strOut);
inc += (lp2+5);
break;
}
case 0x16: { // key id
// lookup key id
for(lp2=0;lp2<g_keyNum;lp2++) {
// compare key ids
if(GET_ULONG g_qbData[lp+1] == *g_keyID[lp2]) {
fprintf(outFile, "%08X:%02X %02X %02X %02X %02X -> %s \n", lp, g_qbData[lp], *g_keyID[lp2], g_keyName[lp2]);
}
}
inc += 4;
break;
}
case 0x07: { // set something ???
// output 0x07 line
fprintf(outFile, "%08X:%02X = \n", lp, g_qbData[lp]);
// 0x1B or 0x1C (string)??? 0x17 (int) ???
break;
}
case 0x1B: // string
case 0x1C: {
lp2 = 0;
// loop through string...
while(g_qbData[(lp+5)+lp2] != 0x00) {
strOut[lp2] = g_qbData[(lp+5)+lp2];
lp2++;
}
strOut[lp2] = '\0'; // null terminator
fprintf(outFile, "%08X:%02X %02X %02X %02X %02X :: %s \n", lp, g_qbData[lp], g_qbData[lp+1], g_qbData[lp+2], g_qbData[lp+3], g_qbData[lp+4], strOut);
inc += (lp2+5);
break;
}
case 0x17: { // integer
intOut = GET_ULONG g_qbData[lp+1];
fprintf(outFile, "%08X:%02X %02X %02X %02X %02X :: %i \n", lp, g_qbData[lp], g_qbData[lp+1], g_qbData[lp+2], g_qbData[lp+3], g_qbData[lp+4], intOut);
inc += 4;
break;
}
default: { // nothing??? 0x00, 0x01, 0x0E, 0x23, 0x28, 0x2D, 0x39, 0x42, 0x2C, 0x32
fprintf(outFile, "%08X:%02X \n", lp, g_qbData[lp]);
}
}
lp += inc;
}
// output file footer...
fprintf(outFile, "\n---------- QB END\n\n\n*Thanks Sporadic, your qbConsole was helpful ;)");
fclose(outFile);
return true;
}