-
Notifications
You must be signed in to change notification settings - Fork 1
/
opcodes.inc
3060 lines (2904 loc) · 109 KB
/
opcodes.inc
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
{%MainUnit yos_script.pas}
type
TOpCodeHandler = procedure(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
{No Operation}
procedure scr_0000_nop(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
asm
nop
end;
end;
{Wait X milliseconds}
procedure scr_0001_wait(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
{Param: 'time'}
thread.waitTime := thread.GetNextParameterInt;
thread.status := tstWaiting;
end;
{Jump to label}
procedure scr_0002_jump(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
{Param: 'label'}
thread.position := thread.script.bytes.ReadQWord - thread.offset;
end;
{Call a subroutine (label)}
procedure scr_0003_gosub(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
{Param: 'label'}
thread.gosubReturn[thread.gosubLevel] := thread.position + 8; {--->>> 8b label id}
inc(thread.gosubLevel);
thread.position := thread.script.bytes.ReadQWord - thread.offset;
end;
{Return from a subroutine}
procedure scr_0004_return(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
{Return from subroutine}
thread.position := thread.gosubReturn[thread.gosubLevel - 1];
dec(thread.gosubLevel);
{If there's an active WB gosub, and we're at the same or 'upper' level as the WB gosub level, disable the WB gosub}
if thread.wbGosubActive and (thread.gosubLevel <= thread.wbGosubLevel) then
thread.wbGosubActive := false;
end;
{Evaluate the conditional result, and jump to label, if the conditional result was false}
procedure scr_0005_jump_if_false(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
result: boolean;
i: integer;
begin
{Evaluate conditional result}
result := false;
if (Length(thread.conditionalValues) > 0) then
case thread.conditionalJumpEvaluationMethod of
cjmpSingle:
result := thread.conditionalValues[0];
cjmpIfAnd:
begin
result := true;
for i := 0 to High(thread.conditionalValues) do
if not thread.conditionalValues[i] then
begin
result := false;
break;
end;
end;
cjmpIfOr:
begin
result := false;
for i := 0 to High(thread.conditionalValues) do
if thread.conditionalValues[i] then
begin
result := true;
break;
end;
end;
end;
{Param: 'label'}
if not result then
thread.position := thread.script.bytes.ReadQWord - thread.offset
else
inc(thread.position, 8); {--->>> 8b label id}
end;
{Start a conditional block}
procedure scr_0006_if(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
{Clear conditional values list}
SetLength(thread.conditionalValues, 0);
{Param: 'method'}
thread.conditionalJumpEvaluationMethod := TConditionalJumpEvaluationMethod(thread.script.bytes.ReadByte);
inc(thread.position, 1); {--->>> 1b evaluation method id}
end;
{End caller thread}
procedure scr_0007_end_thread(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
thread.status := tstFinished;
end;
{End named thread}
procedure scr_0008_end_named_thread(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
{Param: 'name'}
thread.script.KillThreadByName(thread.GetNextParameterString);
end;
{Create thread}
procedure scr_0009_create_thread(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
pos: UINT64;
begin
{Param: 'label'}
pos := thread.script.bytes.ReadQWord;
thread.script.CreateThread(pos);
inc(thread.position, 8); {--->>> 8b label id}
end;
{Set caller thread's name}
procedure scr_000A_set_thread_name(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
begin
{Param: 'name'}
thread.scriptName := thread.GetNextParameterString;
end;
{Reset a variable}
procedure scr_000B_reset_variable(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
end;
{Set var as int}
procedure scr_000C_set_var_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
intValue: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
{Param: 'int_value'}
intValue := thread.GetNextParameterInt;
{Save result}
thread.SetVarInt(vloc, vid, intValue);
end;
{Set var as float}
procedure scr_000D_set_var_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
flt: cfloat;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
{Param: 'float_value'}
flt := thread.GetNextParameterFloat;
{Save Result}
thread.SetVarFloat(vloc, vid, flt);
end;
{Set var as string}
procedure scr_000E_set_var_string(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
stringValue: string;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
{Param: 'string_value'}
stringValue := thread.GetNextParameterString;
{Save result}
thread.AllocateString(vloc, vid, stringValue);
end;
{Set var as Vector3}
procedure scr_000F_set_var_vector3(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
i: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
for i := 0 to High(thread.script.globalVectors) do
if not thread.script.globalVectors[i].Used then
begin
thread.script.globalVectors[i].Used := true;
thread.script.globalVectors[i].Value.x := 0.0;
thread.script.globalVectors[i].Value.y := 0.0;
thread.script.globalVectors[i].Value.z := 0.0;
thread.SetVarData(vloc, svtVector, vid, PUINT32(@i)^);
break;
end;
end;
{Set var as Array (numeric)}
procedure scr_0010_set_var_array(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
i: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
for i := 0 to High(thread.script.globalArrays) do
if not thread.script.globalArrays[i].Used then
begin
thread.script.globalArrays[i].Used := true;
GTA5_SetArrayLength(thread.script.globalArrays[i].Value, 0);
thread.SetVarData(vloc, svtArray, vid, PUINT32(@i)^);
break;
end;
end;
{Set var as Array (string)}
procedure scr_0011_set_var_stringlist(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
i: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
for i := 0 to High(thread.script.globalStringLists) do
if not thread.script.globalStringLists[i].Used then
begin
thread.script.globalStringLists[i].Used := true;
SetLength(thread.script.globalStringLists[i].Value, 0);
thread.SetVarData(vloc, svtStringArray, vid, PUINT32(@i)^);
break;
end;
end;
{Set a Vector3's X}
procedure scr_0012_set_vector3_x(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
f: cfloat;
begin
{Param: 'vector_var'}
thread.GetVarId(vloc, vid);
{Param: 'x'}
f := thread.GetNextParameterFloat;
{Set property}
thread.script.globalVectors[thread.GetVarInt(vloc, vid)].Value.x := f;
end;
{Set a Vector3's Y}
procedure scr_0013_set_vector3_y(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
f: cfloat;
begin
{Param: 'vector_var'}
thread.GetVarId(vloc, vid);
{Param: 'y'}
f := thread.GetNextParameterFloat;
{Set property}
thread.script.globalVectors[thread.GetVarInt(vloc, vid)].Value.y := f;
end;
{Set a Vector3's Z}
procedure scr_0014_set_vector3_z(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
f: cfloat;
begin
{Param: 'vector_var'}
thread.GetVarId(vloc, vid);
{Param: 'z'}
f := thread.GetNextParameterFloat;
{Set property}
thread.script.globalVectors[thread.GetVarInt(vloc, vid)].Value.z := f;
end;
{Get a Vector3's X}
procedure scr_0015_get_vector3_x(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc1, vloc2: TVariableLocation;
vid1, vid2: word;
begin
{Param: 'result'}
thread.GetVarId(vloc1, vid1);
thread.ClearVariable(vloc1, vid1);
{Param: 'vector_var'}
thread.GetVarId(vloc2, vid2);
{Save result}
thread.SetVarFloat(vloc1, vid1, thread.script.globalVectors[thread.GetVarInt(vloc2, vid2)].Value.x);
end;
{Get a Vector3's Y}
procedure scr_0016_get_vector3_y(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc1, vloc2: TVariableLocation;
vid1, vid2: word;
begin
{Param: 'result'}
thread.GetVarId(vloc1, vid1);
thread.ClearVariable(vloc1, vid1);
{Param: 'vector_var'}
thread.GetVarId(vloc2, vid2);
{Save result}
thread.SetVarFloat(vloc1, vid1, thread.script.globalVectors[thread.GetVarInt(vloc2, vid2)].Value.y);
end;
{Get a Vector3's Z}
procedure scr_0017_get_vector3_z(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc1, vloc2: TVariableLocation;
vid1, vid2: word;
begin
{Param: 'result'}
thread.GetVarId(vloc1, vid1);
thread.ClearVariable(vloc1, vid1);
{Param: 'vector_var'}
thread.GetVarId(vloc2, vid2);
{Save result}
thread.SetVarFloat(vloc1, vid1, thread.script.globalVectors[thread.GetVarInt(vloc2, vid2)].Value.z);
end;
{Set an array (numeric) item as int}
procedure scr_0018_set_array_item_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
index, intValue: cint;
begin
{Param: 'array_var'}
thread.GetVarId(vloc, vid);
{Param: 'index'}
index := thread.GetNextParameterInt;
{Param: 'int_value'}
intValue := thread.GetNextParameterInt;
GTA5_SetArrayItem(thread.script.globalArrays[thread.GetVarInt(vloc, vid)].Value, index, PUINT32(@intValue)^);
end;
{Get an array (numeric) item as int}
procedure scr_0019_get_array_item_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc1, vloc2: TVariableLocation;
vid1, vid2: word;
index: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc1, vid1);
thread.ClearVariable(vloc1, vid1);
{Param: 'array_var'}
thread.GetVarId(vloc2, vid2);
{Param: 'index'}
index := thread.GetNextParameterInt;
{Save result}
thread.SetVarData(vloc1, svtInt, vid1, GTA5_GetArrayItem(thread.script.globalArrays[thread.GetVarInt(vloc2, vid2)].Value, index));
end;
{Add a new int item to an array (numeric)}
procedure scr_001A_add_array_item_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
arrayIndex, intValue: cint;
begin
{Param: 'array_var'}
thread.GetVarId(vloc, vid);
{Param: 'int_value'}
intValue := thread.GetNextParameterInt;
{Add item}
arrayIndex := thread.GetVarInt(vloc, vid);
GTA5_SetArrayLength(thread.script.globalArrays[arrayIndex].Value, GTA5_GetArrayLength(thread.script.globalArrays[arrayIndex].Value) + 1);
GTA5_SetArrayItem(thread.script.globalArrays[arrayIndex].Value, GTA5_GetArrayLength(thread.script.globalArrays[arrayIndex].Value) - 1, PUINT32(@intValue)^);
end;
{Set an array (numeric) item as float}
procedure scr_001B_set_array_item_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
index: cint;
floatValue: cfloat;
begin
{Param: 'array_var'}
thread.GetVarId(vloc, vid);
{Param: 'index'}
index := thread.GetNextParameterInt;
{Param: 'float_value'}
floatValue := thread.GetNextParameterFloat;
{Set item}
GTA5_SetArrayItem(thread.script.globalArrays[thread.GetVarInt(vloc, vid)].Value, index, PUINT32(@floatValue)^);
end;
{Get an array (numeric) item as float}
procedure scr_001C_get_array_item_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc1, vloc2: TVariableLocation;
vid1, vid2: word;
index: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc1, vid1);
thread.ClearVariable(vloc1, vid1);
{Param: 'array_var'}
thread.GetVarId(vloc2, vid2);
{Param: 'index'}
index := thread.GetNextParameterInt;
{Save result}
thread.SetVarData(vloc1, svtFloat, vid1, GTA5_GetArrayItem(thread.script.globalArrays[thread.GetVarInt(vloc2, vid2)].Value, index));
end;
{Add a new float item to an array (numeric)}
procedure scr_001D_add_array_item_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
floatValue: cfloat;
arrayIndex: cint;
begin
{Param: 'array_var'}
thread.GetVarId(vloc, vid);
{Param: 'float_value'}
floatValue := thread.GetNextParameterFloat;
{Add item}
arrayIndex := thread.GetVarInt(vloc, vid);
GTA5_SetArrayLength(thread.script.globalArrays[arrayIndex].Value, GTA5_GetArrayLength(thread.script.globalArrays[arrayIndex].Value) + 1);
GTA5_SetArrayItem(thread.script.globalArrays[arrayIndex].Value, GTA5_GetArrayLength(thread.script.globalArrays[arrayIndex].Value) - 1, PUINT32(@floatValue)^);
end;
{Remove an item from an array (numeric)}
procedure scr_001E_remove_array_item(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
index: cint;
arrayIndex, arrayLength, i: cint;
begin
{Param: 'array_var'}
thread.GetVarId(vloc, vid);
{Param: 'index'}
index := thread.GetNextParameterInt;
{Remove item}
arrayIndex := thread.GetVarInt(vloc, vid);
arrayLength := GTA5_GetArrayLength(thread.script.globalArrays[arrayIndex].Value);
if (index >= 0) and (index < arrayLength - 1) then
begin
for i := index to arrayLength - 2 do
GTA5_SetArrayItem(thread.script.globalArrays[arrayIndex].Value, i, GTA5_GetArrayItem(thread.script.globalArrays[arrayIndex].Value, i + 1));
GTA5_SetArrayLength(thread.script.globalArrays[arrayIndex].Value, GTA5_GetArrayLength(thread.script.globalArrays[arrayIndex].Value) - 1);
end;
end;
{Get the length of an array (numeric)}
procedure scr_001F_get_array_length(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc1, vloc2: TVariableLocation;
vid1, vid2: word;
begin
{Param: 'result'}
thread.GetVarId(vloc1, vid1);
thread.ClearVariable(vloc1, vid1);
{Param: 'array_var'}
thread.GetVarId(vloc2, vid2);
{Save the result}
thread.SetVarInt(vloc1, vid1, cint(GTA5_GetArrayLength(thread.script.globalArrays[thread.GetVarInt(vloc2, vid2)].Value)));
end;
{Set array (numeric) length}
procedure scr_0020_set_array_length(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
newLength: cint;
begin
{Param: 'array_var'}
thread.GetVarId(vloc, vid);
{Param: 'new_length'}
newLength := thread.GetNextParameterInt;
{Change length}
GTA5_SetArrayLength(thread.script.globalArrays[thread.GetVarInt(vloc, vid)].Value, integer(newLength));
end;
{Set an array (string) item}
procedure scr_0021_set_stringlist_item(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
index: cint;
begin
{Param: 'stringlist_var'}
thread.GetVarId(vloc, vid);
{Param: 'index'}
index := thread.GetNextParameterInt;
{Param: 'string_value'}
thread.script.globalStringLists[thread.GetVarInt(vloc, vid)].Value[index] := thread.GetNextParameterString;
end;
{Get an array (string) item}
procedure scr_0022_get_stringlist_item(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc1, vloc2: TVariableLocation;
vid1, vid2: word;
index: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc1, vid1);
thread.ClearVariable(vloc1, vid1);
{Param: 'stringlist_var'}
thread.GetVarId(vloc2, vid2);
{Param: 'index'}
index := thread.GetNextParameterInt;
{Save result}
thread.AllocateString(vloc1, vid1, thread.script.globalStringLists[thread.GetVarInt(vloc2, vid2)].Value[index]);
end;
{Add a new item to an array (string)}
procedure scr_0023_add_stringlist_item(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
stringValue: string;
arrayIndex: cint;
begin
{Param: 'stringlist_var'}
thread.GetVarId(vloc, vid);
{Param: 'string_value'}
stringValue := thread.GetNextParameterString;
{Add item}
arrayIndex := thread.GetVarInt(vloc, vid);
SetLength(thread.script.globalStringLists[arrayIndex].Value, Length(thread.script.globalStringLists[arrayIndex].Value) + 1);
thread.script.globalStringLists[arrayIndex].Value[High(thread.script.globalStringLists[arrayIndex].Value)] := stringValue;
end;
{Remove an item from an array (string)}
procedure scr_0024_remove_stringlist_item(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
index, arrayIndex, i: cint;
begin
{Param: 'stringlist_var'}
thread.GetVarId(vloc, vid);
{Param: 'index'}
index := thread.GetNextParameterInt;
{Remove item}
arrayIndex := thread.GetVarInt(vloc, vid);
if (index >= 0) and (index < Length(thread.script.globalStringLists[arrayIndex].Value)) then
begin
for i := index to High(thread.script.globalStringLists[arrayIndex].Value) do
thread.script.globalStringLists[arrayIndex].Value[i] := thread.script.globalStringLists[arrayIndex].Value[i + 1];
SetLength(thread.script.globalStringLists[arrayIndex].Value, Length(thread.script.globalStringLists[arrayIndex].Value) - 1);
end;
end;
{Get the length of an array (string)}
procedure scr_0025_get_stringlist_count(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc1, vloc2: TVariableLocation;
vid1, vid2: word;
begin
{Param: 'result'}
thread.GetVarId(vloc1, vid1);
thread.ClearVariable(vloc1, vid1);
{Param: 'stringlist_var'}
thread.GetVarId(vloc2, vid2);
{Save the result}
thread.SetVarInt(vloc1, vid1, cint(Length(thread.script.globalStringLists[thread.GetVarInt(vloc2, vid2)].Value)));
end;
{Set array (string) length}
procedure scr_0026_set_stringlist_count(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
arrayIndex, newLength: cint;
oldMaxIndex, i: integer;
begin
{Param: 'stringlist_var'}
thread.GetVarId(vloc, vid);
{Param: 'new_length'}
newLength := thread.GetNextParameterInt;
{Change length}
arrayIndex := thread.GetVarInt(vloc, vid);
oldMaxIndex := High(thread.script.globalStringlists[arrayIndex].Value);
SetLength(thread.script.globalStringlists[arrayIndex].Value, newLength);
if (newLength > (oldMaxIndex + 1)) then
for i := oldMaxIndex + 1 to High(thread.script.globalStringlists[arrayIndex].Value) do
thread.script.globalStringlists[arrayIndex].Value[i] := '';
end;
{v -= i}
procedure scr_0027_sub_var_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
intValue: cint;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
if (thread.GetVarType(vloc, vid) = svtFloat) then
thread.SetVarInt(vloc, vid, cint(round(thread.GetVarFloat(vloc, vid))))
else if (thread.GetVarType(vloc, vid) <> svtInt) then
begin
thread.ClearVariable(vloc, vid);
thread.SetVarInt(vloc, vid, 0);
end;
{Param: 'int_value'}
intValue := thread.GetNextParameterInt;
{Subtract}
thread.SetVarInt(vloc, vid, thread.GetVarInt(vloc, vid) - intValue);
end;
{v -= f}
procedure scr_0028_sub_var_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
floatValue: cfloat;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
if (thread.GetVarType(vloc, vid) = svtInt) then
thread.SetVarFloat(vloc, vid, thread.GetVarInt(vloc, vid) * 1.0)
else if (thread.GetVarType(vloc, vid) <> svtFloat) then
begin
thread.ClearVariable(vloc, vid);
thread.SetVarFloat(vloc, vid, 0.0);
end;
{Param: 'float_value'}
floatValue := thread.GetNextParameterFloat;
{Subtract}
thread.SetVarFloat(vloc, vid, thread.GetVarFloat(vloc, vid) - floatValue);
end;
{v += i}
procedure scr_0029_add_var_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
intValue: cint;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
if (thread.GetVarType(vloc, vid) = svtFloat) then
thread.SetVarInt(vloc, vid, cint(round(thread.GetVarFloat(vloc, vid))))
else if (thread.GetVarType(vloc, vid) <> svtInt) then
begin
thread.ClearVariable(vloc, vid);
thread.SetVarInt(vloc, vid, 0);
end;
{Param: 'int_value'}
intValue := thread.GetNextParameterInt;
{Add}
thread.SetVarInt(vloc, vid, thread.GetVarInt(vloc, vid) + intValue);
end;
{v += f}
procedure scr_002A_add_var_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
floatValue: cfloat;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
if (thread.GetVarType(vloc, vid) = svtInt) then
thread.SetVarFloat(vloc, vid, thread.GetVarInt(vloc, vid) * 1.0)
else if (thread.GetVarType(vloc, vid) <> svtFloat) then
begin
thread.ClearVariable(vloc, vid);
thread.SetVarFloat(vloc, vid, 0.0);
end;
{Param: 'float_value'}
floatValue := thread.GetNextParameterFloat;
{Add}
thread.SetVarFloat(vloc, vid, thread.GetVarFloat(vloc, vid) + floatValue);
end;
{v *= i}
procedure scr_002B_mul_var_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
intValue: cint;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
if (thread.GetVarType(vloc, vid) = svtFloat) then
thread.SetVarInt(vloc, vid, cint(round(thread.GetVarFloat(vloc, vid))))
else if (thread.GetVarType(vloc, vid) <> svtInt) then
begin
thread.ClearVariable(vloc, vid);
thread.SetVarInt(vloc, vid, 0);
end;
{Param: 'int_value'}
intValue := thread.GetNextParameterInt;
{Multiply}
thread.SetVarInt(vloc, vid, thread.GetVarInt(vloc, vid) * intValue);
end;
{v *= f}
procedure scr_002C_mul_var_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
floatValue: cfloat;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
if (thread.GetVarType(vloc, vid) = svtInt) then
thread.SetVarFloat(vloc, vid, thread.GetVarInt(vloc, vid) * 1.0)
else if (thread.GetVarType(vloc, vid) <> svtFloat) then
begin
thread.ClearVariable(vloc, vid);
thread.SetVarFloat(vloc, vid, 0.0);
end;
{Param: 'float_value'}
floatValue := thread.GetNextParameterFloat;
{Multiply}
thread.SetVarFloat(vloc, vid, thread.GetVarFloat(vloc, vid) * floatValue);
end;
{v /= i}
procedure scr_002D_div_var_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
intValue: cint;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
if (thread.GetVarType(vloc, vid) = svtFloat) then
thread.SetVarInt(vloc, vid, cint(round(thread.GetVarFloat(vloc, vid))))
else if (thread.GetVarType(vloc, vid) <> svtInt) then
begin
thread.ClearVariable(vloc, vid);
thread.SetVarInt(vloc, vid, 0);
end;
{Param: 'int_value'}
intValue := thread.GetNextParameterInt;
{Divide}
if (intValue = 0) then
thread.SetVarInt(vloc, vid, 0) // Division by zero will result in zero
else
thread.SetVarInt(vloc, vid, thread.GetVarInt(vloc, vid) div intValue);
end;
{v /= f}
procedure scr_002E_div_var_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
floatValue: cfloat;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
if (thread.GetVarType(vloc, vid) = svtInt) then
thread.SetVarFloat(vloc, vid, thread.GetVarInt(vloc, vid) * 1.0)
else if (thread.GetVarType(vloc, vid) <> svtFloat) then
begin
thread.ClearVariable(vloc, vid);
thread.SetVarFloat(vloc, vid, 0.0);
end;
{Param: 'float_value'}
floatValue := thread.GetNextParameterFloat;
{Divide}
if (abs(floatValue) < abs(thread.script.floatEqualThreshold)) then
thread.SetVarFloat(vloc, vid, 0.0) // Division by zero will result in zero
else
thread.SetVarFloat(vloc, vid, thread.GetVarFloat(vloc, vid) / floatValue);
end;
{Convert int to string}
procedure scr_002F_convert_int_to_string(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
intValue: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
{Param: 'int_value'}
intValue := thread.GetNextParameterInt;
{Convert and save result}
thread.AllocateString(vloc, vid, IntToStr(intValue));
end;
{Convert float to string}
procedure scr_0030_convert_float_to_string(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
floatValue: cfloat;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
{Param: 'float_value'}
floatValue := thread.GetNextParameterFloat;
{Convert and save result}
thread.AllocateString(vloc, vid, FloatToStr(floatValue, YosFormatSettings));
end;
{Concat strings}
procedure scr_0031_concat_string(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
stringValue: string;
stringIndex: cint;
begin
{Param: 'var'}
thread.GetVarId(vloc, vid);
{Param: 'string_value'}
stringValue := thread.GetNextParameterString;
{String concat}
if (thread.GetVarType(vloc, vid) <> svtString) then
begin
thread.ClearVariable(vloc, vid);
thread.AllocateString(vloc, vid, '');
end;
if (thread.GetVarType(vloc, vid) = svtString) then // Was the string allocation successful? (if it was already a string, then we're still OK)
begin
stringIndex := thread.GetVarInt(vloc, vid);
thread.script.globalStrings[stringIndex].Value := thread.script.globalStrings[stringIndex].Value + stringValue;
end;
end;
{Get string length}
procedure scr_0032_get_string_length(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
stringValue: string;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
{Param: 'string_value'}
stringValue := thread.GetNextParameterString;
{Save result}
thread.SetVarInt(vloc, vid, cint(Length(stringValue)));
end;
{Get string char code at index}
procedure scr_0033_get_string_char_code_at_index(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
stringValue: string;
index: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
{Param: 'string_value'}
stringValue := thread.GetNextParameterString;
{Param: 'index'}
index := thread.GetNextParameterInt;
{Save result}
if (index <= 0) or (index > Length(stringValue)) then
thread.SetVarInt(vloc, vid, 0) // If out of bounds, return zero
else
thread.SetVarInt(vloc, vid, cint(ord(stringValue[index])));
end;
{Substring}
procedure scr_0034_substring(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
vloc: TVariableLocation;
vid: word;
stringValue, s: string;
startIndex, endIndex: cint;
begin
{Param: 'result'}
thread.GetVarId(vloc, vid);
thread.ClearVariable(vloc, vid);
{Param: 'string_value'}
stringValue := thread.GetNextParameterString;
{Param: 'start_index'}
startIndex := thread.GetNextParameterInt;
{Param: 'start_index'}
endIndex := thread.GetNextParameterInt;
{Get substring and save result}
if (startIndex <= 0) then
startIndex := 1;
if (endIndex > Length(stringValue)) then
endIndex := Length(stringValue);
if (startIndex > endIndex) then
s := ''
else
s := System.Copy(stringValue, startIndex, endIndex - startIndex);
thread.AllocateString(vloc, vid, s);
end;
{i1 > i2}
procedure scr_0035_cmp_gt_int_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
i1, i2: cint;
begin
{Param: 'i1'}
i1 := thread.GetNextParameterInt;
{Param: 'i2'}
i2 := thread.GetNextParameterInt;
{Store conditional result}
thread.AddConditionalResult(i1 > i2, negateresult);
end;
{i > f}
procedure scr_0036_cmp_gt_int_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
i: cint;
f: cfloat;
begin
{Param: 'i'}
i := thread.GetNextParameterInt;
{Param: 'f'}
f := thread.GetNextParameterFloat;
{Store conditional result}
thread.AddConditionalResult(i > f, negateresult);
end;
{f1 > f2}
procedure scr_0037_cmp_gt_float_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
f1, f2: cfloat;
begin
{Param: 'f1'}
f1 := thread.GetNextParameterFloat;
{Param: 'f2'}
f2 := thread.GetNextParameterFloat;
{Store conditional result}
thread.AddConditionalResult(f1 > f2, negateresult);
end;
{i1 >= i2}
procedure scr_0038_cmp_ge_int_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
i1, i2: cint;
begin
{Param: 'i1'}
i1 := thread.GetNextParameterInt;
{Param: 'i2'}
i2 := thread.GetNextParameterInt;
{Store conditional result}
thread.AddConditionalResult(i1 >= i2, negateresult);
end;
{i >= f}
procedure scr_0039_cmp_ge_int_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
i: cint;
f: cfloat;
begin
{Param: 'i'}
i := thread.GetNextParameterInt;
{Param: 'f'}
f := thread.GetNextParameterFloat;
{Store conditional result}
thread.AddConditionalResult(i >= (f + abs(thread.script.floatEqualThreshold)), negateresult);
end;
{f1 >= f2}
procedure scr_003A_cmp_ge_float_float(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
f1, f2: cfloat;
begin
{Param: 'f1'}
f1 := thread.GetNextParameterFloat;
{Param: 'f2'}
f2 := thread.GetNextParameterFloat;
{Store conditional result}
thread.AddConditionalResult(f1 >= (f2 + abs(thread.script.floatEqualThreshold)), negateresult);
end;
{i1 = i2}
procedure scr_003B_cmp_eq_int_int(thread: TMissionThread; negateresult, isPlayerDead, isPlayerBusted: boolean);
var
i1, i2: cint;
begin
{Param: 'i1'}
i1 := thread.GetNextParameterInt;