-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScene2Lib.cpp
3001 lines (2563 loc) · 89.1 KB
/
Scene2Lib.cpp
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
-------------------------[ LBA Story Coder Source ]--------------------------
Copyright (C) 2004-2005
------------------------------[ SceneLib.cpp ]-------------------------------
Author: Alexandre Fontoura [alexfont]
Begin : Sun Nov 19 2005
Email : alexandrefontoura@oninetspeed.pt
-------------------------------[ GNU License ]-------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------------
*/
#include <vcl.h>
#include <assert.h>
#pragma hdrstop
#include "SceneLib.h"
#include "HQRLib.h"
#include "LBAStoryCoder_main.h"
#include "Commands.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
int conditionMode2;
char indentation2[256];
int lastopcode2;
short int comportementOffsets2[100][50];
short int trackOffsets2[100][256];
bool wrof2=true; // Write Offsets
extern int filesize;
char Track2List[][34] =
{
"END",
"NOP",
"BODY",
"ANIM",
"GOTO_POINT",
"WAIT_ANIM",
"LOOP",
"ANGLE",
"POS_POINT",
"LABEL",
"GOTO",
"STOP",
"GOTO_SYM_POINT",
"WAIT_NB_ANIM",
"SAMPLE",
"GOTO_POINT_3D",
"SPEED",
"BACKGROUND",
"WAIT_NB_SECOND",
"NO_BODY",
"BETA",
"OPEN_LEFT",
"OPEN_RIGHT",
"OPEN_UP",
"OPEN_DOWN",
"CLOSE",
"WAIT_DOOR",
"SAMPLE_RND",
"SAMPLE_ALWAYS",
"SAMPLE_STOP",
"PLAY_FLA",
"REPEAT_SAMPLE",
"SIMPLE_SAMPLE",
"FACE_TWINKEL",
"ANGLE_RND"
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// BINARY SCENES #########
//------------------------
// ----------------
// - LOAD ROUTINES
// -------------------------------------------------------------------------
TScene loadBinaryScene2(char* fileName, int index)
{
unsigned char* scenePtr;
TScene Scene;
// unsigned short int aux = 0;
//int filesize;
if(index != -1)
{
filesize = loadResource(fileName,index,&scenePtr);
if(filesize == -1) // didn't find the file
return Scene;
}
else
{
filesize = ResourceSize(fileName);
FILE* sceneHandle = openResource(fileName);
scenePtr = (unsigned char*)malloc(filesize);
readResource(sceneHandle,(char*)scenePtr,filesize);
closeResource(sceneHandle);
if(filesize == -1) // didn't find the file
return Scene;
}
if(scenePtr)
{
// resolveOffsets2(scenePtr);
Scene.TextBank = *(scenePtr++);
Scene.CubeEntry = *(scenePtr); scenePtr+=6; // recheck
Scene.AlphaLight = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.BetaLight = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb0_1 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb0_2 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb0_3 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb0_4 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb0_5 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb1_1 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb1_2 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb1_3 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb1_4 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb1_5 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb2_1 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb2_2 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb2_3 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb2_4 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb2_5 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb3_1 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb3_2 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb3_3 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb3_4 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Amb3_5 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Second_Min = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Second_Ecart = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.CubeMusic = *(scenePtr++);
Scene.Hero.X = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Hero.Y = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Hero.Z = *((unsigned short *)scenePtr); scenePtr+=2;
//-----------------
int heroTrackBytes = *((unsigned short *)scenePtr); scenePtr+=2;
// unsigned char * heroTrack = scenePtr;
// Scene.Hero.trackScript = decompTrack2Script(scenePtr);
Scene.Hero.trackScript = "END";
scenePtr += heroTrackBytes;
//-----------------
int heroLifeBytes = *((unsigned short *)scenePtr); scenePtr+=2;
// Scene.Hero.lifeScript = decompLife2Script(scenePtr, heroLifeBytes, heroTrack);
Scene.Hero.lifeScript = "END";
scenePtr += heroLifeBytes;
Scene.numActors = *((unsigned short *)scenePtr); scenePtr+=2;
for(int i=1; i < Scene.numActors; i++)
{
TActor Actor;
strcpy(Actor.Name," ");
Actor.staticFlag = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.unknown = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.Entity = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.Body = *((unsigned short *)scenePtr); scenePtr+=2; // <<--- RECHECK
Actor.Animation = *(scenePtr++);
Actor.SpriteEntry = *(scenePtr); scenePtr+=2;
Actor.X = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.Y = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.Z = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.StrengthOfHit = *(scenePtr++);
Actor.BonusParameter = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.Angle = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.SpeedRotation = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.Move = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.cropLeft = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.cropTop = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.cropRight = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.cropBottom = *((unsigned short *)scenePtr); scenePtr+=2;
Actor.BonusAmount = *(scenePtr++);
Actor.TalkColor = *(scenePtr++);
Actor.Armour = *(scenePtr++);
Actor.LifePoints = *(scenePtr++);
int trackBytes = *((unsigned short *)scenePtr); scenePtr+=2;
// unsigned char * actorTrack = scenePtr;
// Actor.trackScript = decompTrack2Script(scenePtr);
Actor.trackScript = "END";
scenePtr += trackBytes;
int lifeBytes = *((unsigned short *)scenePtr); scenePtr+=2;
// Actor.lifeScript = decompLife2Script(scenePtr, lifeBytes, actorTrack);
Actor.lifeScript = "END";
scenePtr += lifeBytes;
Scene.Actors.push_back(Actor);
}
scenePtr+=4;
Scene.numZones = *((unsigned short *)scenePtr); scenePtr+=2;
for(int i=0; i < Scene.numZones; i++)
{
TZone Zone;
Zone.X0 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown1 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Y0 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown2 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Z0 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown3 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.X1 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown4 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Y1 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown5 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Z1 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown6 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Type = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown7 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Info0 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown8 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Info1 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown9 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Info2 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown10 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Info3 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown11 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Info4 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown12 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Info5 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown13 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Info6 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown14 = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.Snap = *((unsigned short *)scenePtr); scenePtr+=2;
Zone.unknown15 = *((unsigned short *)scenePtr); scenePtr+=2;
// CHECK THIS BETTER <------------------------
if(Zone.X1==-32768)
{
Zone.X1 = 32767;
}
if(Zone.X0==-32768)
{
Zone.X0 = 32767;
}
Scene.Zones.push_back(Zone);
}
Scene.numTracks= *((unsigned short *)scenePtr); scenePtr+=2;
for(int i=0; i < Scene.numTracks; i++)
{
TTrack Track;
Track.Num = i;
Track.X = *((unsigned short *)scenePtr); scenePtr+=2;
Track.unknown1 = *((unsigned short *)scenePtr); scenePtr+=2;
Track.Y = *((unsigned short *)scenePtr); scenePtr+=2;
Track.unknown2 = *((unsigned short *)scenePtr); scenePtr+=2;
Track.Z = *((unsigned short *)scenePtr); scenePtr+=2;
Track.unknown3 = *((unsigned short *)scenePtr); scenePtr+=2;
Scene.Tracks.push_back(Track);
}
// Other unknown data
}
return Scene;
}
char * decompTrack2Script(unsigned char *scriptPtr)
{
int finish = 0;
int size = 0;
unsigned char opcode;
char scriptbuff[256];
char scriptbuff2[256];
unsigned char * tempPtr = scriptPtr;
char * ptr = (char *)malloc(1);
*ptr = 0;
do
{
opcode = *(scriptPtr++);
if(wrof2){ // DEBUG
sprintf(scriptbuff2,"%d: ", scriptPtr - tempPtr-1);
size += strlen(scriptbuff2)+2;
ptr = (char *)realloc(ptr,size);
strcat(ptr,scriptbuff2);
}
switch (opcode)
{
case 0: // END
{
sprintf(scriptbuff,"END");
finish = 1;
break;
}
case 1: // NOP
{
sprintf(scriptbuff,"NOP");
break;
}
case 2: // BODY
{
sprintf(scriptbuff,"BODY %d",*(scriptPtr++));
break;
}
case 3: // ANIM
{
sprintf(scriptbuff,"ANIM %d", *(scriptPtr++));
break;
}
case 4: // GOTO_POINT
{
sprintf(scriptbuff,"GOTO_POINT %d",*(scriptPtr++));
break;
}
case 5: // WAIT_ANIM
{
sprintf(scriptbuff,"WAIT_ANIM");
break;
}
case 6: // LOOP
{
sprintf(scriptbuff,"LOOP");
break;
}
case 7: // ANGLE
{
short int temp;
temp = *(short int *) (scriptPtr);
scriptPtr += 2;
sprintf(scriptbuff,"ANGLE %d", temp);
break;
}
case 8: // POS_POINT
{
sprintf(scriptbuff,"POS_POINT %d",*(scriptPtr++));
break;
}
case 9: // LABEL
{
sprintf(scriptbuff,"LABEL %d",*(scriptPtr++));
break;
}
case 10: // GOTO
{
short int temp;
temp = *(short int *) (scriptPtr);
scriptPtr += 2;
temp = *(tempPtr + temp + 1);
sprintf(scriptbuff,"GOTO %d",temp);
break;
}
case 11: // STOP
{
sprintf(scriptbuff,"STOP");
break;
}
case 12: // GOTO_SYM_POINT
{
sprintf(scriptbuff,"GOTO_SYM_POINT %d", *(scriptPtr++));
break;
}
case 13: // WAIT_NB_ANIM
{
sprintf(scriptbuff,"WAIT_NB_ANIM %d %d",*(scriptPtr++), *(scriptPtr++));
break;
}
case 14: // SAMPLE
{
short int temp;
temp = *(short int *) (scriptPtr);
scriptPtr += 2;
sprintf(scriptbuff,"SAMPLE %d", temp);
break;
}
case 15: // GOTO_POINT_3D
{
sprintf(scriptbuff,"GOTO_POINT_3D %d", *(scriptPtr++));
break;
}
case 16: // SPEED
{
short int temp;
temp = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"SPEED %d", temp);
break;
}
case 17: // BACKGROUND
{
sprintf(scriptbuff,"BACKGROUND %d", *(scriptPtr++));
break;
}
case 18: // WAIT_NB_SECOND < - RECHECK #####################
{
/*short int temp1;
short int temp2; */
unsigned char temp3;
temp3 = *(unsigned char *) (scriptPtr++);
/*temp1 = *(int *) (scriptPtr);
scriptPtr += 2;
temp2 = *(int *) (scriptPtr);
scriptPtr += 2; */
scriptPtr += 4;
sprintf(scriptbuff,"WAIT_NB_SECOND %d", temp3);
break;
}
case 19: // NO_BODY
{
sprintf(scriptbuff,"NO_BODY");
break;
}
case 20: // BETA
{
short int temp;
temp = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"BETA %d", temp);
break;
}
case 21: // OPEN_LEFT
{
short int temp;
temp = *(short int *) (scriptPtr);
scriptPtr += 2;
sprintf(scriptbuff,"OPEN_LEFT %d", temp);
break;
}
case 22: // OPEN_RIGHT
{
short int temp;
temp = *(short int *) (scriptPtr);
scriptPtr += 2;
sprintf(scriptbuff,"OPEN_RIGHT %d", temp);
break;
}
case 23: // OPEN_UP
{
short int temp;
temp = *(short int *) (scriptPtr);
scriptPtr += 2;
sprintf(scriptbuff,"OPEN_UP %d", temp);
break;
}
case 24: // OPEN_DOWN
{
short int temp;
temp = *(short int *) (scriptPtr);
scriptPtr += 2;
sprintf(scriptbuff,"OPEN_DOWN %d", temp);
break;
}
case 25: // CLOSE
{
sprintf(scriptbuff,"CLOSE");
break;
}
case 26: // WAIT_DOOR
{
sprintf(scriptbuff,"WAIT_DOOR");
break;
}
case 27: // SAMPLE_RND
{
short int temp;
temp = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"SAMPLE_RND %d", temp);
break;
}
case 28: // SAMPLE_ALWAYS
{
short int temp;
temp = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"SAMPLE_ALWAYS %d", temp);
break;
}
case 29: // SAMPLE_STOP
{
short int temp;
temp = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"SAMPLE_STOP %d", temp);
break;
}
case 30: // PLAY_FLA
{
sprintf(scriptbuff,"PLAY_FLA %s",scriptPtr);
scriptPtr += strlen((char *) scriptPtr) + 1;
break;
}
case 31: // REPEAT_SAMPLE
{
short int temp;
temp = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"REPEAT_SAMPLE %d", temp);
break;
}
case 32: // SIMPLE_SAMPLE
{
short int temp;
temp = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"SIMPLE_SAMPLE %d", temp);
break;
}
case 33: //FACE_TWINKEL
{
short int temp;
temp = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"FACE_TWINKEL %d", temp);
break;
}
case 34: // ANGLE_RND
{
short int temp1;
short int temp2;
temp1 = *(short int *) scriptPtr;
scriptPtr += 2;
temp2 = *(short int *) scriptPtr;
scriptPtr += 2;
sprintf(scriptbuff,"ANGLE_RND %d %d", temp1, temp2);
break;
}
default:
{
sprintf(scriptbuff,"UNK_OPCODE_%d", opcode);
//finish = 1;
break;
}
}
size += strlen(scriptbuff)+2;
ptr = (char *)realloc(ptr,size);
strcat(ptr,scriptbuff);
strcat(ptr,"\n");
}
while (!finish);
return ptr;
}
void decompConditions2(unsigned char **scriptPtr, char *buffer)
{
unsigned char opcode;
char buffer2[256];
opcode = **(scriptPtr);
*(scriptPtr) = (*(scriptPtr)) + 1;
conditionMode2 = 0;
switch (opcode)
{
case 0:
{
strcat(buffer, "COL");
break;
}
case 1:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "COL_OBJ %d", temp);
strcat(buffer, buffer2);
break;
}
case 2:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "DISTANCE %d", temp);
strcat(buffer, buffer2);
conditionMode2 = 1;
break;
}
case 3:
{
strcat(buffer, "ZONE");
break;
}
case 4:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "ZONE_OBJ %d", temp);
strcat(buffer, buffer2);
break;
}
case 5:
{
strcat(buffer, "BODY");
break;
}
case 6:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "BODY_OBJ %d", temp);
strcat(buffer, buffer2);
break;
}
case 7:
{
strcat(buffer, "ANIM");
break;
}
case 8:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "ANIM_OBJ %d", temp);
strcat(buffer, buffer2);
break;
}
case 9:
{
strcat(buffer, "L_TRACK");
break;
}
case 10:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "L_TRACK %d", temp);
strcat(buffer, buffer2);
break;
}
case 11:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "FLAG_CUBE %d", temp);
strcat(buffer, buffer2);
break;
}
case 12:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "CONE_VIEW %d", temp);
strcat(buffer, buffer2);
conditionMode2 = 1;
break;
}
case 13:
{
strcat(buffer, "HIT_BY");
break;
}
case 14:
{
strcat(buffer, "ACTION");
break;
}
case 15:
{
sprintf(buffer2, "FLAG_GAME %d", *((short int *) (*scriptPtr)));
*(scriptPtr) = (*(scriptPtr)) + 2;
strcat(buffer, buffer2);
conditionMode2 = 1;
break;
}
case 16:
{
strcat(buffer, "LIFE_POINT");
break;
}
case 17:
{
char temp;
temp = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "LIFE_POINT_OBJ %d", temp);
strcat(buffer, buffer2);
break;
}
case 18:
{
strcat(buffer, "NB_LITTLE_KEYS");
break;
}
case 19:
{
strcat(buffer, "NB_GOLD_PIECES");
conditionMode2 = 1;
break;
}
case 20:
{
strcat(buffer, "COMPORTEMENT_HERO");
break;
}
case 21:
{
strcat(buffer, "CHAPTER");
break;
}
case 22:
{
char temp;
temp = **(scriptPtr);
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "DISTANCE_3D %d", temp);
strcat(buffer, buffer2);
conditionMode2 = 1;
break;
}
/*
23 .. 24 unused
*/
case 25:
{
char temp;
temp = **(scriptPtr);
*(scriptPtr) = (*(scriptPtr)) + 1;
sprintf(buffer2, "USE_INVENTORY %d", temp);
strcat(buffer, buffer2);
break;
}
case 26:
{
strcat(buffer, "CHOICE");
conditionMode2 = 1;
break;
}
case 27:
{
strcat(buffer, "FUEL");
break;
}
default:
{
printf("Unsupported condition: %d\n", opcode);
exit(1);
}
}
}
void decompOperators2(unsigned char **scriptPtr, char *buffer)
{
unsigned char opcode;
int opcode2;
char buffer2[256];
opcode = **(scriptPtr);
*(scriptPtr) = (*(scriptPtr)) + 1;
switch(conditionMode2)
{
case 0:
{
opcode2 = **scriptPtr;
*(scriptPtr) = (*(scriptPtr)) + 1;
break;
}
case 1:
{
opcode2 = *((short int *) (*scriptPtr));
*(scriptPtr) = (*(scriptPtr)) + 2;
break;
}
default:
{
printf("Operator Error!\n");
exit(1);
break;
}
}
switch (opcode)
{
case 0: // Equal to
{
sprintf(buffer2, " == %d", opcode2);
strcat(buffer, buffer2);
break;
}
case 1: // Greater Than
{
sprintf(buffer2, " > %d", opcode2);
strcat(buffer, buffer2);
break;
}
case 2: // Less Than
{
sprintf(buffer2, " < %d", opcode2);
strcat(buffer, buffer2);
break;
}
case 3: // Greater Than Or Equal To
{
sprintf(buffer2, " >= %d", opcode2);
strcat(buffer, buffer2);
break;
}
case 4: // Less Than Or Equal To
{
sprintf(buffer2, " <= %d", opcode2);
strcat(buffer, buffer2);
break;
}
case 5: // Not equal to
{
sprintf(buffer2, " != %d", opcode2);
strcat(buffer, buffer2);
break;
}
default:
{
printf("doCalc default: %d\n", opcode);
exit(1);
break;
}
}
}
void resolveOffsets2(unsigned char * scenePtr)
{
// short int offset=0;
unsigned char opcode;
unsigned short temp;
scenePtr += 62; // Hero Track Script Offset
temp = *((unsigned short *)scenePtr);
scenePtr+=2;
setTrack2ObjectIndex(0,temp,scenePtr);
scenePtr += temp;
temp = *((unsigned short *)scenePtr); // Hero Life Script Offset
scenePtr+=2;
setComportement2ObjectIndex(0,temp,scenePtr);
scenePtr += temp;
int numActors = *((unsigned short *)scenePtr);
scenePtr += 2;
for(int a=1; a<numActors; a++)
{
scenePtr += 38;
temp = *((unsigned short *)scenePtr);
scenePtr+=2;
setTrack2ObjectIndex(a,temp,scenePtr);
scenePtr += temp;
temp = *((unsigned short *)scenePtr);
scenePtr+=2;
setComportement2ObjectIndex(a,temp,scenePtr);
scenePtr += temp;
}
}
void setComportement2ObjectIndex(int numActor, unsigned short numBytes, unsigned char * ptr)
{
short int offset=0;
unsigned char tempOp;
int numComp=1;
comportementOffsets2[numActor][0] = 0;
for(int a=numBytes; a > 1; a--){
tempOp = *(ptr+offset);
if(tempOp == 35)
{
comportementOffsets2[numActor][numComp] = offset+1;
numComp++;
}
offset++;
}
}
void setTrack2ObjectIndex(int numActor, unsigned short numBytes, unsigned char * ptr)
{
short int offset=0;
unsigned char tempOp;
int numTracks=0;
int temp;
for(int a=numBytes; a > 1; a--){
tempOp = *(ptr+offset);
if(tempOp == 9)
{
temp = *(ptr+offset+1);
trackOffsets2[numActor][temp] = offset;
numTracks++;
}
offset++;
}
}
int getComportement2Index(short int comportement[50], short int offset)
{
for(int a=0; a < 50; a++)
{
if(comportement[a]==offset)
return a;
}
return -1;
}
int getComportement2ObjectIndex(short int offset, int numActor)
{
for(int a=0; a < 50; a++)
{
if(comportementOffsets2[numActor][a]==offset)
return a;
}
return -1;
}
int getTrack2ObjectIndex(short int offset, int numActor)
{
for(int a=0; a < 255; a++)
{
if(trackOffsets2[numActor][a]==offset)
return a;
}
return -1;
}
void indentScript2(unsigned short indent){
if(indent >= 1)
for(int i=0; i < indent; i++){
if(i==0)
sprintf(indentation2, " ");
else
strcat(indentation2, " ");
}
else
sprintf(indentation2, "");
}
char * decompLife2Script(unsigned char *scriptPtr, int lifeBytes, unsigned char *trackPtr)
{
unsigned short indent;
unsigned short indentOffsets[500];