~ubuntu-branches/debian/jessie/scummvm/jessie

« back to all changes in this revision

Viewing changes to tools/sci/old_objects.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
8
 
 * modify it under the terms of the GNU General Public License
9
 
 * as published by the Free Software Foundation; either version 2
10
 
 * of the License, or (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, write to the Free Software
19
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 
 *
21
 
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/tools/sci/old_objects.cpp $
22
 
 * $Id: old_objects.cpp 38423 2009-02-17 15:59:52Z sev $
23
 
 *
24
 
 */
25
 
 
26
 
#include <sciresource.h>
27
 
#include <console.h>
28
 
#include <script.h>
29
 
#include <vocabulary.h>
30
 
#include <old_objects.h>
31
 
#include <stdio.h>
32
 
#include <stdlib.h>
33
 
#include <util.h>
34
 
#include <vm.h>
35
 
#include <assert.h>
36
 
 
37
 
#ifdef SCI_CONSOLE
38
 
#define printf sciprintf
39
 
/* Yeah, I shouldn't be doing this ;-) [CJR] */
40
 
#endif
41
 
 
42
 
FLEXARRAY_NOEXTRA(object*) fobjects;
43
 
 
44
 
static int knames_count;
45
 
static char** knames;
46
 
static char** snames;
47
 
static opcode* opcodes;
48
 
 
49
 
object **object_map, *object_root;
50
 
int max_object;
51
 
 
52
 
const char* globals[] = {
53
 
        /*00*/
54
 
        "ego",
55
 
        "GAMEID",
56
 
        "roomXX",
57
 
        "speed",
58
 
        /*04*/
59
 
        "quitFlag",
60
 
        "cast",
61
 
        "regions",
62
 
        "timer",
63
 
        /*08*/
64
 
        "sounds",
65
 
        "inv",
66
 
        "eventHandler",
67
 
        "roomNumberExit",
68
 
        /*0C*/
69
 
        "previousRoomNumber",
70
 
        "roomNumber",
71
 
        "enterDebugModeOnRoomExit",
72
 
        "score",
73
 
        /*10*/
74
 
        "maximumScore",
75
 
        "11",
76
 
        "speed",
77
 
        "13",
78
 
        /*14*/
79
 
        "14",
80
 
        "loadCursor",
81
 
        "normalFont",
82
 
        "restoreSaveFont", /*dialogFont*/
83
 
        /*18*/
84
 
        "18",
85
 
        "19",
86
 
        "defaultFont",
87
 
        "1B",
88
 
        /*1C*/
89
 
        "pointerToVersionNumber",
90
 
        "locales",
91
 
        "pointerToSaveGameDirectory",
92
 
        "1F"
93
 
};
94
 
 
95
 
static int add_object(object* obj) {
96
 
        FLEXARRAY_APPEND(object*, fobjects, obj, return 1);
97
 
        return 0;
98
 
}
99
 
 
100
 
static void dump(byte* data, int len) {
101
 
        int i = 0;
102
 
        while (i < len) {
103
 
                printf("%02X ", data[i++]);
104
 
                if (i % 8 == 0) printf("   ");
105
 
                if (i % 16 == 0) printf("\n");
106
 
        }
107
 
        if (i % 16) printf("\n");
108
 
}
109
 
 
110
 
static void printMethod(object* obj, int meth, int indent) {
111
 
        script_method* m = obj->methods[meth];
112
 
        int i, j;
113
 
 
114
 
        for (j = 0; j < indent*2 - 1; j++) printf(" ");
115
 
        printf("Method %s\n", snames[m->number]);
116
 
 
117
 
        for (i = 0; i < m->used; i++) {
118
 
                script_opcode op = m->data[i];
119
 
 
120
 
                for (j = 0; j < indent; j++) printf("  ");
121
 
                printf("%s ", opcodes[op.opcode].name);
122
 
 
123
 
                switch (op.opcode) {
124
 
                case 0x21: { /*callk*/
125
 
                        if (op.arg1 > knames_count) printf("<no such kernel function %02X> ", op.arg1);
126
 
                        else printf("%s ", knames[op.arg1]);
127
 
                        printf("%02X", op.arg2);
128
 
                }
129
 
                break;
130
 
                case 0x28: { /*class*/
131
 
                        if (op.arg1 > max_object) printf("<no such class %02X>", op.arg1);
132
 
                        else {
133
 
                                /* [DJ] op.arg1+1 adjusts for the <root> object */
134
 
                                if (fobjects.data[op.arg1+1] == 0) printf("<null object>");
135
 
                                else printf("%s", fobjects.data[op.arg1+1]->name);
136
 
                        }
137
 
                }
138
 
                break;
139
 
                case 0x44: {
140
 
                        if (op.arg1 > 0x20) printf("<no such global %02X> ", op.arg1);
141
 
                        else printf("%s ", globals[op.arg1]);
142
 
                }
143
 
                break;
144
 
                default: {
145
 
                        int args[3];
146
 
                        args[0] = op.arg1;
147
 
                        args[1] = op.arg2;
148
 
                        args[2] = op.arg3;
149
 
                        for (j = 0; j < 3; j++) {
150
 
                                switch (formats[op.opcode][j]) {
151
 
                                case Script_Invalid: {
152
 
                                        printf("<invalid> ");
153
 
                                }
154
 
                                break;
155
 
                                case Script_None: {
156
 
                                        j = 3;
157
 
                                }
158
 
                                break;
159
 
                                case Script_SByte:
160
 
                                case Script_Byte: {
161
 
                                        printf("%02X ", args[j]);
162
 
                                }
163
 
                                break;
164
 
                                case Script_Word:
165
 
                                case Script_SVariable:
166
 
                                case Script_Variable:
167
 
                                case Script_SRelative:
168
 
                                case Script_Property:
169
 
                                case Script_Global:
170
 
                                case Script_Local:
171
 
                                case Script_Temp:
172
 
                                case Script_Param: {
173
 
                                        printf("%04X ", args[j]);
174
 
                                }
175
 
                                break;
176
 
                                case Script_SWord: {
177
 
                                        if (args[j] < 0) printf("-%04X", -args[j]);
178
 
                                        else printf("%04X", args[j]);
179
 
                                }
180
 
                                break;
181
 
                                case Script_End: {
182
 
                                        printf("\n");
183
 
                                        return;
184
 
                                }
185
 
                                break;
186
 
                                default: {
187
 
                                        printf("<unknown arg type %d> ", formats[op.opcode][j]);
188
 
                                }
189
 
                                }
190
 
                        }
191
 
                }
192
 
                break;
193
 
                }
194
 
                printf("\n");
195
 
        }
196
 
}
197
 
 
198
 
static void printObject_r(object* obj, int flags, int level) {
199
 
        int i;
200
 
        for (i = 0; i < level; i++) printf("  ");
201
 
        if (obj == 0) printf("(null)\n");
202
 
        else {
203
 
                printf("%s\n", obj->name);
204
 
                if (flags&SCRIPT_PRINT_METHODS) {
205
 
                        for (i = 0; i < obj->method_count; i++) {
206
 
                                printMethod(obj, i, level + 1);
207
 
                        }
208
 
                }
209
 
                if (flags&SCRIPT_PRINT_CHILDREN) {
210
 
                        for (i = 0; i < obj->children.used; i++) {
211
 
                                printObject_r(obj->children.data[i], flags, level + 1);
212
 
                        }
213
 
                }
214
 
        }
215
 
}
216
 
 
217
 
void printObject(object* obj, int flags) {
218
 
        printf("pO(%p, %d)\n", obj, flags);
219
 
        printObject_r(obj, flags, 0);
220
 
}
221
 
 
222
 
static object* object_new() {
223
 
        object* obj = (object*)sci_malloc(sizeof(object));
224
 
        if (obj == 0) return 0;
225
 
 
226
 
        obj->parent = 0;
227
 
        FLEXARRAY_INIT(object*, obj->children);
228
 
        obj->name = 0;
229
 
        obj->selector_count = 0;
230
 
        obj->selector_numbers = 0;
231
 
        obj->methods = 0;
232
 
        obj->method_count = 0;
233
 
 
234
 
        return obj;
235
 
}
236
 
 
237
 
static int add_child(object* parent, object* child) {
238
 
        FLEXARRAY_APPEND(object*, parent->children, child, return 1);
239
 
        return 0;
240
 
}
241
 
 
242
 
static object* fake_object(const char* reason) {
243
 
        object* obj = object_new();
244
 
        if (obj == 0) {
245
 
#ifdef SCRIPT_DEBUG
246
 
                printf("object_new failed during fake for %s\n", reason);
247
 
#endif
248
 
                free(obj);
249
 
                return 0;
250
 
        }
251
 
        if (add_child(object_root, obj)) {
252
 
#ifdef SCRIPT_DEBUG
253
 
                printf("add_child failed during fake for %s\n", reason);
254
 
#endif
255
 
                free(obj);
256
 
                return 0;
257
 
        }
258
 
        obj->name = reason;
259
 
        if (add_object(obj)) {
260
 
#ifdef SCRIPT_DEBUG
261
 
                printf("add_object failed during fake for %s\n", reason);
262
 
#endif
263
 
                /*FIXME: clean up parent*/
264
 
                return 0;
265
 
        }
266
 
        return obj;
267
 
}
268
 
 
269
 
static script_method* decode_method(byte* data) {
270
 
        script_method* m;
271
 
        int done = 0;
272
 
        int pos = 0;
273
 
        static int count = 0;
274
 
 
275
 
        count++;
276
 
 
277
 
        if ((m = (script_method*)sci_malloc(sizeof(script_method))) == 0) return 0;
278
 
        FLEXARRAY_INIT(script_opcode, *m);
279
 
 
280
 
        while (!done) {
281
 
                int op = data[pos] >> 1;
282
 
                int size = 2 - (data[pos] & 1);
283
 
                int* args[3];
284
 
                int arg;
285
 
                int old_pos;
286
 
 
287
 
                FLEXARRAY_ADD_SPACE(script_opcode, *m, 1, return 0);
288
 
                old_pos = pos;
289
 
                m->data[m->used-1].pos = pos;
290
 
                m->data[m->used-1].opcode = op;
291
 
 
292
 
                /*Copy the adresses of the args to an array for convenience*/
293
 
                args[0] = &m->data[m->used-1].arg1;
294
 
                args[1] = &m->data[m->used-1].arg2;
295
 
                args[2] = &m->data[m->used-1].arg3;
296
 
 
297
 
                /*Skip past the opcode*/
298
 
                pos++;
299
 
 
300
 
                for (arg = 0; arg < 4; arg++) {
301
 
                        switch (formats[op][arg]) {
302
 
                        case Script_Invalid: { /*Can't happen(tm)*/
303
 
                                int i;
304
 
                                printf("Invalid opcode %02X at %04X in method %d\n", op, pos, count);
305
 
                                for (i = m->used - 9; i < m->used - 1; i++) {
306
 
                                        printf("%s[%02X] ", opcodes[m->data[i].opcode].name, m->data[i].opcode);
307
 
                                        dump(data + m->data[i].pos, m->data[i].size);
308
 
                                }
309
 
                                printf("Dump from %04X-%04X\n", pos - 16, pos + 16);
310
 
                                dump(data + pos - 16, 32);
311
 
                        }
312
 
                        break;
313
 
                        case Script_None: { /*No more args*/
314
 
                                arg = 4;
315
 
                        }
316
 
                        break;
317
 
                        case Script_Byte: /*Just a one byte arg*/
318
 
                        case Script_SByte: {
319
 
                                *args[arg] = data[pos++];
320
 
                        }
321
 
                        break;
322
 
                        case Script_Word: { /*A two byte arg*/
323
 
                                *args[arg] = getInt16(data + pos);
324
 
                                pos += 2;
325
 
                        }
326
 
                        break;
327
 
                        case Script_SWord: { /*A signed two-byte arg*/
328
 
                                int t = getInt16(data + pos);
329
 
                                if (t&0x8000) *args[arg] = -(t & 0x7FFF);
330
 
                                else *args[arg] = t;
331
 
                                pos += 2;
332
 
                        }
333
 
                        break;
334
 
                        case Script_Variable: /*Size of arg depends on LSB in opcode*/
335
 
                        case Script_SVariable:
336
 
                        case Script_SRelative:
337
 
                        case Script_Property:
338
 
                        case Script_Global:
339
 
                        case Script_Local:
340
 
                        case Script_Temp:
341
 
                        case Script_Param: {
342
 
                                if (size == 1) *args[arg] = data[pos++];
343
 
                                else {
344
 
                                        *args[arg] = getInt16(data + pos);
345
 
                                        pos += 2;
346
 
                                }
347
 
                        }
348
 
                        break;
349
 
                        case Script_End: { /*Special tag for ret*/
350
 
                                done = 1;
351
 
                                arg = 4;
352
 
                        }
353
 
                        break;
354
 
                        default: { /*Can't happen(tm)*/
355
 
                                printf("Unknown argument format %d for op %02X\n", formats[op][arg], op);
356
 
                        }
357
 
                        break;
358
 
                        }
359
 
                }
360
 
                fflush(stdout);
361
 
                if (m->used) m->data[m->used-1].size = pos - old_pos;
362
 
        }
363
 
 
364
 
        return m;
365
 
}
366
 
 
367
 
#ifdef SCRIPT_DEBUG
368
 
void list_code_blocks(resource_t* r) {
369
 
        int pos = getInt16(r->data + 2);
370
 
        while (pos < r->size - 2) {
371
 
                int type = getInt16(r->data + pos);
372
 
                int len = getInt16(r->data + pos + 2);
373
 
                if (type == 2) printf("%X-%X\n", pos, pos + len);
374
 
                pos += len;
375
 
        }
376
 
}
377
 
#endif
378
 
 
379
 
 
380
 
/*These expect the frame, the whole frame, and, well, other stuff too,
381
 
 *I guess, as long as it looks like a frame*/
382
 
static int get_type(unsigned char* obj) {
383
 
        return getInt16(obj);
384
 
}
385
 
 
386
 
static int get_length(unsigned char* obj) {
387
 
        return getInt16(obj + 2);
388
 
}
389
 
 
390
 
static int get_selector_count(unsigned char* obj) {
391
 
        return getInt16(obj + 10);
392
 
}
393
 
 
394
 
static int get_selector_value(unsigned char* obj, int sel) {
395
 
        assert(sel < get_selector_count(obj));
396
 
        return getInt16(obj + 12 + sel*2);
397
 
}
398
 
 
399
 
/*Bas things happen if the method offset value is wrong*/
400
 
static unsigned char* get_method_area(unsigned char* obj) {
401
 
        return obj + getInt16(obj + 8) + 10;
402
 
}
403
 
 
404
 
static int get_method_count(unsigned char* obj) {
405
 
        return getInt16(get_method_area(obj));
406
 
}
407
 
 
408
 
static int get_method_number(unsigned char* obj, int i) {
409
 
        assert(i < get_method_count(obj));
410
 
        return getInt16(get_method_area(obj) + 2 + 2*i);
411
 
}
412
 
 
413
 
static int get_method_location(unsigned char* obj, int i) {
414
 
        assert(i < get_method_count(obj));
415
 
        return getInt16(get_method_area(obj) + 4 + 2*get_method_count(obj) + 2*i);
416
 
}
417
 
 
418
 
 
419
 
/*Returns the position of the first frame of type 'type' in resource 'r',
420
 
 *starting from the frame starting at 'start', or -1 on failure.
421
 
 */
422
 
static int find_frame(resource_t* r, int type, unsigned int start) {
423
 
        int t = -1;
424
 
        unsigned int pos = start;
425
 
        unsigned char* frame;
426
 
 
427
 
        assert(start <= r->size - 4);
428
 
 
429
 
#ifdef SCRIPT_DEBUG
430
 
        printf("Searching for frame of type %d in script %03d, starting at %#x\n", type, r->number, start);
431
 
        dump(r->data + start, 32);
432
 
#endif
433
 
 
434
 
        /*Some times there's an extra byte at the beginning. Christoph?*/
435
 
#if 1
436
 
        if (pos == 0 && r->size >= 6 && \
437
 
                !((0 < getInt16(r->data)) && (10 > getInt16(r->data)))) pos = 2;
438
 
#else
439
 
        if (pos == 0)
440
 
                pos = 2;
441
 
#endif
442
 
        frame = r->data + pos;
443
 
        while (1) {
444
 
#ifdef SCRIPT_DEBUG
445
 
                printf("offset = %#x\n", pos);
446
 
                dump(frame, 32);
447
 
#endif
448
 
                t = get_type(frame);
449
 
                if (t == type)
450
 
                        break;
451
 
 
452
 
                if (t == 0)
453
 
                        return -1;
454
 
 
455
 
                pos += get_length(frame);
456
 
                if (pos > (r->size - 2))
457
 
                        return -1;
458
 
                frame += get_length(frame);
459
 
        }
460
 
 
461
 
        return pos;
462
 
}
463
 
 
464
 
 
465
 
 
466
 
/*FIXME: lots of things are identical to read_object and read_class. Some of
467
 
 *these would benefit from being put in separate functions.*/
468
 
 
469
 
static object* read_object(resource_mgr_t *resmgr, int script, int positions[1000]) {
470
 
        resource_t* r = scir_find_resource(resmgr, sci_script, script, 0);
471
 
        unsigned char* raw;
472
 
        int pos;
473
 
        object* obj;
474
 
 
475
 
        printf("Searching for object in script %03d\n", script);
476
 
 
477
 
        if (r == 0) return 0;
478
 
 
479
 
        /*Skip to the next object*/
480
 
#ifdef SCRIPT_DEBUG
481
 
        printf("pre skip: pos=%#x\n", positions[script]);
482
 
#endif
483
 
        pos = find_frame(r, 1, positions[script]);
484
 
#ifdef SCRIPT_DEBUG
485
 
        printf("post skip: pos=%#x\n", pos);
486
 
#endif
487
 
        if (pos == -1) return 0;
488
 
        else positions[script] = pos + get_length(r->data + pos);
489
 
#ifdef SCRIPT_DEBUG
490
 
        printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data + pos));
491
 
#endif
492
 
 
493
 
        /*Construct the object*/
494
 
        obj = object_new();
495
 
        raw = r->data + pos;
496
 
 
497
 
        /*Fill in the name*/
498
 
        if (get_selector_count(raw) < 4) obj->name = "<anonymous>";
499
 
        else {
500
 
                if (get_selector_value(raw, 3))
501
 
                        obj->name = (char *) r->data + get_selector_value(raw, 3);
502
 
                else obj->name = "<null>";
503
 
        }
504
 
 
505
 
        /*Fill in the class*/
506
 
        if (get_selector_count(raw) == 0) obj->parent = object_root;
507
 
        else {
508
 
                int parent_id = get_selector_value(raw, 1);
509
 
                if (parent_id >= fobjects.used) {
510
 
                        free(obj);
511
 
                        return 0;
512
 
                }
513
 
                if (parent_id < 1) obj->parent = object_root;
514
 
                else obj->parent = fobjects.data[parent_id];
515
 
        }
516
 
 
517
 
        /*Add the object to the class*/
518
 
        if (!obj->parent) {
519
 
                free(obj);
520
 
                return 0;
521
 
        }
522
 
        if (add_child(obj->parent, obj)) {
523
 
                free(obj);
524
 
                return 0;
525
 
        }
526
 
        if (add_object(obj)) {
527
 
                free(obj);
528
 
                return 0;
529
 
        }
530
 
 
531
 
        /*FIXME: decode selectors here*/
532
 
 
533
 
        obj->method_count = get_method_count(raw);
534
 
        obj->methods = (script_method**)sci_malloc(obj->method_count * sizeof(script_method));
535
 
        if (obj->methods == 0) {
536
 
                free(obj);
537
 
                return 0;
538
 
        } else {
539
 
                int i;
540
 
                for (i = 0; i < obj->method_count; i++) {
541
 
                        int number = get_method_number(raw, i);
542
 
                        int position = get_method_location(raw, i);
543
 
 
544
 
                        if ((obj->methods[i] = decode_method(r->data + position)) == 0) {
545
 
                                obj->method_count = i - 1;
546
 
                                break;
547
 
                        }
548
 
                        obj->methods[i]->number = number;
549
 
                }
550
 
        }
551
 
 
552
 
        return obj;
553
 
}
554
 
 
555
 
static object* read_class(resource_mgr_t *resmgr, int script, int positions[1000]) {
556
 
        resource_t* r = scir_find_resource(resmgr, sci_script, script, 0);
557
 
        unsigned char* raw;
558
 
        int pos;
559
 
        object* obj;
560
 
 
561
 
        printf("Searching for class in script %03d\n", script);
562
 
 
563
 
        if (r == 0) return fake_object("<resource not found>");
564
 
 
565
 
        /*Skip to the next class*/
566
 
#ifdef SCRIPT_DEBUG
567
 
        printf("pre skip: pos=%#x\n", positions[script]);
568
 
#endif
569
 
        pos = find_frame(r, 6, positions[script]);
570
 
#ifdef SCRIPT_DEBUG
571
 
        printf("post skip: pos=%#x\n", pos);
572
 
#endif
573
 
        if (pos == -1) return fake_object("<no more classes in script>");
574
 
        else positions[script] = pos + get_length(r->data + pos);
575
 
#ifdef SCRIPT_DEBUG
576
 
        printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data + pos));
577
 
#endif
578
 
 
579
 
        /*Construct the object*/
580
 
        obj = object_new();
581
 
        raw = r->data + pos;
582
 
 
583
 
        /*Fill in the name*/
584
 
        if (get_selector_count(raw) < 4) obj->name = "<anonymous>";
585
 
        else {
586
 
                if (get_selector_value(raw, 3))
587
 
                        obj->name = (char *) r->data + get_selector_value(raw, 3);
588
 
                else obj->name = "<null>";
589
 
        }
590
 
 
591
 
        /*Fill in the parent*/
592
 
        if (get_selector_count(raw) == 0) obj->parent = object_root;
593
 
        else {
594
 
                int superclass_id = get_selector_value(raw, 1);
595
 
                printf("superclass==%d\n", superclass_id);
596
 
                if (superclass_id >= fobjects.used) {
597
 
                        free(obj);
598
 
                        return fake_object("<no such superclass>");
599
 
                }
600
 
                if (superclass_id < 1) obj->parent = object_root;
601
 
                else obj->parent = fobjects.data[superclass_id];
602
 
        }
603
 
 
604
 
        /*Add the class to the hierarchy*/
605
 
        if (!obj->parent) {
606
 
                free(obj);
607
 
                return fake_object("<null parent>");
608
 
        }
609
 
        if (add_child(obj->parent, obj)) {
610
 
                free(obj);
611
 
                return fake_object("<add_child failed>");
612
 
        }
613
 
        if (add_object(obj)) {
614
 
                free(obj);
615
 
                return fake_object("<add_object failed>");
616
 
        }
617
 
 
618
 
        /*FIXME: decode selectors and methods here*/
619
 
 
620
 
        return obj;
621
 
}
622
 
 
623
 
void freeObject(object* obj) {
624
 
        int i;
625
 
        for (i = 0; i < obj->children.used; i++) freeObject(obj->children.data[i]);
626
 
        free(obj);
627
 
}
628
 
 
629
 
static int objects_init(resource_mgr_t *resmgr) {
630
 
        FLEXARRAY_INIT(object*, fobjects);
631
 
        max_object = 0;
632
 
 
633
 
        if ((object_root = object_new()) == 0) return 1;
634
 
        object_root->name = "<root>";
635
 
        add_object(object_root);
636
 
 
637
 
        opcodes = vocabulary_get_opcodes(resmgr);
638
 
        knames = vocabulary_get_knames(resmgr, &knames_count);
639
 
        snames = vocabulary_get_snames(resmgr, NULL, 0);
640
 
 
641
 
        return 0;
642
 
}
643
 
 
644
 
int loadObjects(resource_mgr_t *resmgr) {
645
 
        int i;
646
 
        int *classes, class_count;
647
 
        int positions[1000];
648
 
 
649
 
        if (objects_init(resmgr)) {
650
 
#ifdef SCRIPT_DEBUG
651
 
                perror("objects_init");
652
 
#endif
653
 
                return 1;
654
 
        }
655
 
        classes = vocabulary_get_classes(resmgr, &class_count);
656
 
 
657
 
        for (i = 0; i < 1000; i++) positions[i] = 0;
658
 
        for (i = 0; i < class_count; i++) {
659
 
#ifdef SCRIPT_DEBUG
660
 
                printf("\n\nReading class 0x%02X\n", i);
661
 
#endif
662
 
                if (read_class(resmgr, classes[i], positions) == 0) {
663
 
#ifdef SCRIPT_DEBUG
664
 
                        fprintf(stderr, "Failed to load class %d, which is a parent.\n", i);
665
 
#endif
666
 
                        return 1;
667
 
                }
668
 
        }
669
 
 
670
 
        for (i = 0; i < 1000; i++) positions[i] = 0;
671
 
        for (i = 0; i < 1000; i++) while (read_object(resmgr, i, positions));
672
 
 
673
 
        object_map = fobjects.data;
674
 
        max_object = fobjects.used;
675
 
 
676
 
        return 0;
677
 
}
678
 
 
679