-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup-lolfixer.tp2
4701 lines (4507 loc) · 221 KB
/
setup-lolfixer.tp2
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
BACKUP ~lolfixer/backup~
AUTHOR ~Lollorian~
VERSION ~10122015~
BEGIN ~Area Stuff - MAJESTIC Area Fixer~
GROUP ~Area Stuff~
ACTION_IF !(FILE_EXISTS ~override/xr2400.are~) THEN BEGIN
COPY_EXISTING ~ar0087.are~ ~override/xr2400.are~
END
ACTION_IF !(FILE_EXISTS ~override/xr2600.are~) THEN BEGIN
COPY_EXISTING ~ar0087.are~ ~override/xr2600.are~
END
ACTION_CLEAR_ARRAY tutu_convert_itm
ACTION_DEFINE_ASSOCIATIVE_ARRAY tutu_convert_itm BEGIN
_AROW01 => AROW01
_AROW02 => AROW02
_AROW07 => AROW07
_AX1H04 => AX1H04
_BOW01 => BOW01
_BOW03 => BOW03
_BOW08 => BOW08
_BLUN02 => BLUN02
_BULL02 => BULL02
_BRAC04 => BRAC04
_CHAN01 => CHAN01
_CHAN04 => CHAN04
_CHAN05 => CHAN05
_CHAN07 => CHAN07
_DAGG01 => DAGG01
_DAGG03 => DAGG03
_DAGG05 => DAGG05
_DART01 => DART01
_DART02 => DART02
_HELM01 => HELM01
_HELM09 => HELM09
_HELM11 => HELM11
_JELLGR1 => JELLGR1
_LEAT01 => LEAT01
_LEAT02 => LEAT02
_LEAT04 => LEAT04
_MAGE01 => MAGE02
_MAGE02 => MAGE02
_MAGE05 => MAGE05
_AGEBRAC => MAGEBRAC
_MISC33 => MISC33
_PLAT01 => PLAT01
_PLAT04 => PLAT04
_POTN08 => POTN08
_POTN20 => POTN20
_POTN21 => POTN21
_POTN36 => POTN36
_POTN37 => POTN37
_POTN45 => POTN45
_RING95 => RING95
_SCRL96 => SCRL96
_SHLD01 => SHLD01
_SHLD08 => SHLD08
_SLNG02 => SLNG02
_SPER01 => SPER01
_SPER02 => SPER02
_STAF01 => STAF01
_STAF02 => STAF02
_STAF07 => STAF07
_SW1H01 => SW1H01
_SW1H04 => SW1H04
_SW1H07 => SW1H07
_SW1H08 => SW1H08
_SW1H24 => SW1H24
_SW2H01 => SW2H01
END
COPY_EXISTING_REGEXP GLOB ~^.+\.are$~ ~override~
PATCH_IF (SOURCE_SIZE > 0x11b) THEN BEGIN
// Script Assigner
READ_ASCII 0x94 "script"
SET "exists" = 0
SET "scexists" = 0
SET "unassigned" = 0
SET "missing" = 0
PATCH_IF FILE_EXISTS_IN_GAME ~%SOURCE_RES%.bcs~ BEGIN
SET "exists" = 1
END
PATCH_IF FILE_EXISTS_IN_GAME ~%script%.bcs~ BEGIN
SET "scexists" = 1
END
PATCH_IF (("%scexists%" = 0) AND ("%exists%" = 0)) BEGIN
SET "missing" = 1
END
PATCH_IF (("%scexists%" = 0) AND ("%exists%" = 1)) BEGIN
SET "unassigned" = 1
END
PATCH_IF ("%unassigned%" = 1) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Area Script (%SOURCE_RES%.bcs) assigned"
WRITE_ASCIIE 0x94 ~%SOURCE_RES%~ #8
END ELSE
PATCH_IF ("%missing%" = 1) BEGIN
PATCH_IF NOT (("%script%" STRING_EQUAL_CASE "NONE") OR ("%script%" STRING_EQUAL_CASE "")) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Missing area Script (%script%.bcs) created"
INNER_ACTION BEGIN
<<<<<<<< %script%.BAF
>>>>>>>>
COMPILE ~%script%.BAF~
END
END ELSE
BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Missing area Script (%SOURCE_RES%.bcs) created and assigned"
INNER_ACTION BEGIN
<<<<<<<< %SOURCE_RES%.BAF
>>>>>>>>
COMPILE ~%SOURCE_RES%.BAF~
END
WRITE_ASCIIE 0x94 ~%SOURCE_RES%~ #8
END
END
// Container Content Validator
READ_LONG 0x70 "cont_off" ELSE 0
READ_SHORT 0x74 "cont_num" ELSE 0
READ_SHORT 0x76 "itm_num" ELSE 0
READ_LONG 0x78 "itm_off" ELSE 0
PATCH_IF (cont_off > 0x11b) THEN BEGIN
FOR (index = 0 ; index < cont_num ; index = index + 1) BEGIN
// Non-empty containers that aren't visible get their items dropped on the ground
READ_SHORT ("%cont_off%" + 0x24 + (0xc0 * "%index%")) "cont_type"
READ_SHORT ("%cont_off%" + 0x38 + (0xc0 * "%index%")) "bound_a"
READ_SHORT ("%cont_off%" + 0x3a + (0xc0 * "%index%")) "bound_b"
READ_SHORT ("%cont_off%" + 0x3c + (0xc0 * "%index%")) "bound_c"
READ_SHORT ("%cont_off%" + 0x3e + (0xc0 * "%index%")) "bound_d"
READ_LONG ("%cont_off%" + 0x44 + (0xc0 * "%index%")) "cont_itm_num"
PATCH_IF ("%bound_a%" = 0) AND ("%bound_b%" = 0) AND ("%bound_c%" = 0) AND ("%bound_d%" = 0) AND ("%cont_type%" != 4) AND ("%cont_itm_num%" > 0) BEGIN
WRITE_SHORT ("%cont_off%" + 0x24 + (0xc0 * "%index%")) 4
PATCH_PRINT "%SOURCE_FILE% issue: Container #%index% has no bounding box but contains items! Dropping all items to ground..."
END
// Invalid container content checker
READ_LONG ("%cont_off%" + 0x40 + (0xc0 * "%index%")) "cont_itm_idx"
READ_LONG ("%cont_off%" + 0x44 + (0xc0 * "%index%")) "cont_itm_num"
FOR (index2 = 0 ; index2 < cont_itm_num ; index2 = index2 + 1) BEGIN
READ_ASCII ("%itm_off%" + (("%index2%" + "%cont_itm_idx%") * 0x14)) "resref"
SET "exists" = 0
PATCH_IF FILE_EXISTS_IN_GAME ~%resref%.itm~ BEGIN
SET "exists" = 1
END
PATCH_IF ("%exists%" = 0) BEGIN
SET "converted" = 0
PHP_EACH tutu_convert_itm AS tutu_itm => bgt_itm BEGIN
PATCH_IF ("%resref%" STRING_EQUAL_CASE "%tutu_itm%") AND (FILE_EXISTS_IN_GAME "%bgt_itm%.itm") BEGIN
WRITE_ASCIIE ("%itm_off%" + (("%index2%" + "%cont_itm_idx%") * 0x14)) "%bgt_itm%" #8
SET "converted" = 1
PATCH_PRINT "%SOURCE_FILE% issue: Container #%index% Item #%index2% had Tutu item! (%resref% -> %bgt_itm%)!"
END
END
PATCH_IF ("%converted%" = 0) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Container #%index% Item #%index2% does not exist (%resref%.itm)! Removing Item #%index2%..."
LAUNCH_PATCH_FUNCTION ~fj_are_structure~
INT_VAR fj_delete_mode = "%index2%" + "%cont_itm_idx%"
STR_VAR fj_structure_type = ~itm~
END
READ_LONG 0x70 "cont_off" ELSE 0
READ_SHORT 0x74 "cont_num" ELSE 0
READ_SHORT 0x76 "itm_num" ELSE 0
READ_LONG 0x78 "itm_off" ELSE 0
READ_LONG ("%cont_off%" + 0x44 + (0xc0 * "%index%")) "cont_itm_num"
SET index = 0 - 1
SET index2 = cont_itm_num
END
END
END
END
END
// Missing Ambient Remover
READ_SHORT 0x82 "amb_num" ELSE 0
READ_LONG 0x84 "amb_off" ELSE 0
PATCH_IF (amb_off > 0x11b) THEN BEGIN
FOR (index = 0 ; index < amb_num ; index = index + 1) BEGIN
FOR (index2 = 0 ; index2 < 10 ; index2 = index2 + 1) BEGIN
READ_ASCII ("%amb_off%" + 0x30 + ("%index2%" * 0x08) + (0xd4 * "%index%")) "resref"
PATCH_IF NOT (("%resref%" STRING_EQUAL_CASE "") OR ("%resref%" STRING_EQUAL_CASE "none")) BEGIN
SET "exists" = 0
PATCH_IF FILE_EXISTS_IN_GAME ~%resref%.wav~ BEGIN
SET "exists" = 1
END
PATCH_IF ("%exists%" = 0) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Ambient #%index% does not exist (%resref%.wav)! Nulling..."
WRITE_ASCII ("%amb_off%" + 0x30 + ("%index2%" * 0x08) + (0xd4 * "%index%")) ~NONE~ #8
END
END
END
END
END
// Missing Actor Remover
READ_LONG 0x54 "actor_off" ELSE 0
READ_SHORT 0x58 "actor_num" ELSE 0
PATCH_IF (actor_off > 0x11b) THEN BEGIN
FOR (index = 0 ; index < actor_num ; index = index + 1) BEGIN
READ_BYTE ("%actor_off%" + 0x28 + (0x110 * "%index%")) "flags" // flags first byte
READ_ASCII ("%actor_off%" + 0x80 + (0x110 * "%index%")) "resref" // cre file
PATCH_IF ("%resref%" STRING_COMPARE_REGEXP "^[Rr][Dd].+$") BEGIN // ignore creatures starting with RD
SET "exists" = 0
PATCH_IF FILE_EXISTS_IN_GAME ~%resref%.cre~ BEGIN
SET "exists" = 1
END
PATCH_IF (("%exists%" = 0) AND (("%flags%" BAND 0b00000001) = 0b00000001)) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Actor #%index% does not exist (%resref%.cre)! Removing actor..."
LPF fj_are_structure
INT_VAR fj_delete_mode = "%index%"
STR_VAR fj_structure_type = actor
END
SET "index" = 0 - 1
READ_SHORT 0x58 "actor_num"
END
END
END
END
// Actor Miscellaneous Patching
READ_LONG 0x54 "actor_off" ELSE 0
READ_SHORT 0x58 "actor_num" ELSE 0
PATCH_IF (actor_off > 0x11b) THEN BEGIN
FOR (index = 0 ; index < actor_num ; index = index + 1) BEGIN
// Invalid Embedded CRE Status Patching
READ_BYTE ("%actor_off%" + 0x28 + (0x110 * "%index%")) "flags" // flags first byte
READ_ASCII ("%actor_off%" + 0x80 + (0x110 * "%index%")) "resref" // cre file
PATCH_IF NOT (("%resref%" STRING_EQUAL_CASE "NONE") OR ("%resref%" STRING_EQUAL_CASE "")) BEGIN
PATCH_IF (("%flags%" BAND 0b00000001) = 0b00000000) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Actor #%index% (%resref%.CRE) exists and should not be attached to the ARE..."
WRITE_BYTE ("%actor_off%" + 0x28 + (0x110 * "%index%")) ("%flags%" BOR 0b00000001)
END
END
// Actor Removal Prevention
READ_LONG ("%actor_off%" + 0x38 + (0x110 * "%index%")) "removal_timer"
PATCH_IF ("%removal_timer%" = 0) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Actor #%index% set to disappear after %removal_timer% seconds! Setting to -1..."
WRITE_LONG ("%actor_off%" + 0x38 + (0x110 * "%index%")) 0xffffffff
END ELSE
PATCH_IF ("%removal_timer%" != 0xffffffff) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Actor #%index% set to disappear after %removal_timer% seconds!"
// WRITE_LONG ("%actor_off%" + 0x38 + (0x110 * "%index%")) 0xffffffff
END
END
END
// Missing Spawn Remover
READ_LONG 0x60 "spawn_off" ELSE 0
READ_LONG 0x64 "spawn_num" ELSE 0
PATCH_IF (spawn_off > 0x11b) THEN BEGIN
FOR (index = 0 ; index < spawn_num ; index = index + 1) BEGIN
FOR (index2 = 0 ; index2 < 10 ; index2 = index2 + 1) BEGIN
READ_ASCII ("%spawn_off%" + 0x24 + ("%index2%" * 0x08) + ("%index%" * 0xc8)) "resref"
PATCH_IF (("%resref%" STRING_COMPARE_CASE "") AND // ignore empty entries
("%resref%" STRING_COMPARE_CASE "none") AND // ignore 'none'
("%resref%" STRING_COMPARE_REGEXP "^[Rr][Dd].+$")) BEGIN // ignore creatures starting with RD
SET "exists" = 0
PATCH_IF FILE_EXISTS_IN_GAME ~%resref%.cre~ BEGIN
SET "exists" = 1
END
PATCH_IF ("%exists%" = 0) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Spawn Point #%index% creature file does not exist (%resref%.cre)! Nulling..."
WRITE_ASCII ("%spawn_off%" + 0x24 + ("%index2%" * 0x08) + ("%index%" * 0xc8)) ~NONE~ #8
END
END
END
SET "none_count" = 0
FOR (index2 = 0 ; index2 < 10 ; index2 = index2 + 1) BEGIN
READ_ASCII ("%spawn_off%" + 0x24 + ("%index2%" * 0x08) + ("%index%" * 0xc8)) "resref"
PATCH_IF (("%resref%" STRING_EQUAL_CASE "") OR ("%resref%" STRING_EQUAL_CASE "none")) BEGIN
SET "none_count" = "none_count" + 1
END
END
PATCH_IF ("%none_count%" = 10) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Spawn Point #%index% has no creatures to spawn! Removing spawn entry..."
LPF fj_are_structure
INT_VAR fj_delete_mode = "%index%"
STR_VAR fj_structure_type = spawn
END
SET "index" = 0 - 1
READ_LONG 0x64 "spawn_num"
END
END
END
// Missing Rest Spawn Remover
READ_LONG 0xc0 "rest_off" ELSE 0
PATCH_IF (rest_off > 0x11b) THEN BEGIN
FOR (index = 0 ; index < 10 ; index = index + 1) BEGIN
READ_ASCII ("%rest_off%" + 0x48 + ("%index%" * 0x08)) "resref"
PATCH_IF (("%resref%" STRING_COMPARE_CASE "") AND // ignore empty entries
("%resref%" STRING_COMPARE_CASE "none") AND // ignore 'none'
("%resref%" STRING_COMPARE_REGEXP "^[Rr][Dd].+$")) BEGIN // ignore creatures starting with RD
SET "exists" = 0
PATCH_IF FILE_EXISTS_IN_GAME ~%resref%.cre~ BEGIN
SET "exists" = 1
END
PATCH_IF ("%exists%" = 0) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Rest Spawn creature file does not exist (%resref%.cre)! Nulling..."
WRITE_ASCII ("%rest_off%" + 0x48 + ("%index%" * 0x08)) "NONE" #8
END
END
END
SET "none_count" = 0
FOR (index = 0 ; index < 10 ; index = index + 1) BEGIN
READ_ASCII ("%rest_off%" + 0x48 + ("%index%" * 0x08)) "resref"
PATCH_IF (("%resref%" STRING_EQUAL_CASE "") OR ("%resref%" STRING_EQUAL_CASE "none")) BEGIN
SET "none_count" = "none_count" + 1
END
END
READ_SHORT ("%rest_off%" + 0x98) "spawncount"
PATCH_IF (("%none_count%" = 10) AND ("%spawncount%" != 0)) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: No creatures in Rest Spawn Entry but area still set to spawn something! Setting number of spawnable creatures to 0..."
WRITE_SHORT ("%rest_off%" + 0x98) 0
END
END
END
BUT_ONLY_IF_IT_CHANGES
BEGIN ~Creature Stuff - Creature Resource Fixer~
GROUP ~Creature Stuff~
OUTER_SET existence_fix = 0
ACTION_IF (FILE_EXISTS "TobEx_ini/TobExCore.ini") AND (FILE_CONTAINS "TobEx_ini/TobExCore.ini" "Existence Sound Fix=1") THEN BEGIN
PRINT "ToBEx Existence Sound Fix is set! Shifting creature EXISTANCE sounds where applicable..."
OUTER_SET existence_fix = 1
COPY_EXISTING ~PDIALOG.2DA~ ~override~
PRETTY_PRINT_2DA
BUT_ONLY_IF_IT_CHANGES
END
COPY_EXISTING_REGEXP GLOB ~^.+\.cre$~ ~override~
LPF FJ_CRE_VALIDITY
INT_VAR do_message = 1
END
PATCH_IF (existence_fix == 1) THEN BEGIN
READ_ASCII 0x280 "DV" (32) NULL
PATCH_IF (NOT FILE_CONTAINS_EVALUATED (~PDIALOG.2DA~ ~^%DV% ~)) BEGIN
READ_LONG 0x1b8 ~soundreplace~
READ_LONG 0x1bc ~soundreplace2~
READ_LONG 0x1c0 ~soundreplace3~
READ_LONG 0x1c4 ~soundreplace4~
READ_LONG 0x1c8 ~soundreplace5~
PATCH_IF ("%soundreplace%" > 0) THEN BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Soundset moved : PICKED_POCKET -> EXISTANCE1"
WRITE_LONG 0x1b8 ~-1~
WRITE_LONG 0x1bc %soundreplace%
END
PATCH_IF ("%soundreplace2%" > 0) THEN BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Soundset moved : EXISTANCE1 -> EXISTANCE2"
WRITE_LONG 0x1bc %soundreplace%
WRITE_LONG 0x1c0 %soundreplace2%
END
PATCH_IF ("%soundreplace3%" > 0) THEN BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Soundset moved : EXISTANCE2 -> EXISTANCE3"
WRITE_LONG 0x1c0 %soundreplace2%
WRITE_LONG 0x1c4 %soundreplace3%
END
PATCH_IF ("%soundreplace4%" > 0) THEN BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Soundset moved : EXISTANCE3 -> EXISTANCE4"
WRITE_LONG 0x1c4 %soundreplace3%
WRITE_LONG 0x1c8 %soundreplace4%
END
PATCH_IF ("%soundreplace5%" > 0) THEN BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Soundset moved : EXISTANCE4 -> EXISTANCE5"
WRITE_LONG 0x1c8 %soundreplace4%
WRITE_LONG 0x1cc %soundreplace5%
END
END
END
PATCH_IF ("%SOURCE_RES%" STRING_EQUAL_CASE "SENDRO03") AND (SOURCE_SIZE > 0x2d3) THEN BEGIN
READ_LONG 0x2a8 "meminfo_off" ELSE 0
READ_LONG 0x2ac "meminfo_num" ELSE 0
READ_LONG 0x2b0 "mem_spl_off" ELSE 0
READ_LONG 0x2b4 "mem_spl_num" ELSE 0
PATCH_IF ("meminfo_off" > 0x2d3) AND ("mem_spl_off" > 0x2d3) THEN BEGIN
READ_SHORT ("%meminfo_off%" + 0x04 + (0x10 * ("%meminfo_num%" - 1))) "spl_mem_num"
READ_SHORT ("%meminfo_off%" + 0x08 + (0x10 * ("%meminfo_num%" - 1))) "spl_tbl_idx"
READ_SHORT ("%meminfo_off%" + 0x0c + (0x10 * ("%meminfo_num%" - 1))) "spl_tbl_cnt"
READ_ASCII ("%mem_spl_off%" + (0x0c * ("%spl_tbl_idx%" + "%spl_tbl_cnt%"))) "resref1" ELSE 0
READ_ASCII ("%mem_spl_off%" + (0x0c * ("%spl_tbl_idx%" + "%spl_tbl_cnt%" + 1))) "resref2" ELSE 0
READ_ASCII ("%mem_spl_off%" + (0x0c * ("%spl_tbl_idx%" + "%spl_tbl_cnt%" + 2))) "resref3" ELSE 0
READ_ASCII ("%mem_spl_off%" + (0x0c * ("%spl_tbl_idx%" + "%spl_tbl_cnt%" + 3))) "resref4" ELSE 0
PATCH_IF ("%resref1%" STRING_EQUAL_CASE "SPCL900") BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Known ERROR in SENDRO03.CRE! (%resref1%, %resref2%, %resref3%, %resref4%) unaccounted for! Fixing..."
WRITE_SHORT ("%meminfo_off%" + 0x04 + (0x10 * ("%meminfo_num%" - 1))) 6
WRITE_SHORT ("%meminfo_off%" + 0x0c + (0x10 * ("%meminfo_num%" - 1))) 6
END
END
END
BUT_ONLY_IF_IT_CHANGES
BEGIN ~Creature Stuff - Inventory Unborker (removes spurious references to the item table)~
GROUP ~Creature Stuff~
COPY_EXISTING_REGEXP GLOB ~^.+\.cre$~ ~override~
PATCH_IF (SOURCE_SIZE > 0x2d3) THEN BEGIN
READ_LONG 0x2b8 "slot_off" ELSE 0
READ_LONG 0x2bc "itm_off" ELSE 0
READ_SHORT 0x2c0 "itm_num" ELSE 0
PATCH_IF ("slot_off" > 0x2d3) THEN BEGIN
FOR (index = 0 ; index < 37 ; index = index + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index%")) "ref" ELSE 0xffff
PATCH_IF ("%ref%" != 0xffff) BEGIN
PATCH_IF ((%ref% + 1) > %itm_num%) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Inventory Item Slot #%index% refers to an item outside the Item Table! Setting to -1..."
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
END
END
END
END
PATCH_IF (("slot_off" > 0x2d3) AND ("itm_off" > 0x2d3)) THEN BEGIN
FOR (index = 0 ; index < itm_num ; index = index + 1) BEGIN
SET "critical" = 0
SET "found" = 0
SET "foundslot" = 0
FOR (index1 = 0 ; index1 < 37 && found = 0 ; index1 = index1 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index1%")) "ref" ELSE 0xffff
PATCH_IF (%index% = %ref%) BEGIN
SET "found" = 1
END
END
PATCH_IF (%found% = 0) BEGIN
READ_ASCII ("%itm_off%" + (0x14 * "%index%")) "item"
PATCH_IF FILE_EXISTS_IN_GAME ~%item%.itm~ BEGIN
INNER_PATCH_FILE ~%item%.itm~ BEGIN
READ_BYTE 0x18 "flags"
READ_SHORT 0x1c "type"
READ_LONG 0x34 "price"
PATCH_IF ("%item%" STRING_COMPARE_REGEXP "^[Rr][Nn][Dd].+$") AND ((("%flags%" BAND 0b00000001) = 0b00000001) OR ((%type% = 0) AND (%price% = 0))) BEGIN
SET "critical" = 1
END
END
END
PATCH_IF %critical% = 1 BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Inventory Item #%index% (%item%.ITM) is not actually in inventory! Potentially quest-breaking item! Removing..."
REMOVE_CRE_ITEM ~%item%~
SET "index" = 0 - 1
READ_LONG 0x2b8 "slot_off" ELSE 0
READ_LONG 0x2bc "itm_off" ELSE 0
READ_SHORT 0x2c0 "itm_num" ELSE 0
END ELSE
BEGIN
FOR (index1 = 21 ; index1 < 37 && foundslot = 0 ; index1 = index1 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index1%")) "ref" ELSE 0xffff
PATCH_IF ("%ref%" = 0xffff) BEGIN
SET "foundslot" = "index1"
END
END
PATCH_IF ("%foundslot%" > 0) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Inventory Item #%index% (%item%.ITM) is not actually in inventory! Adding to Inventory Slot #%foundslot%..."
WRITE_SHORT ("%slot_off%" + (0x02 * "%foundslot%")) "index"
END ELSE
BEGIN
FOR (index1 = 0 ; index1 < 22 && foundslot = 0 ; index1 = index1 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index1%")) "ref" ELSE 0xffff
PATCH_IF ("%ref%" = 0xffff) BEGIN
SET "foundslot" = "index1"
END
END
PATCH_PRINT "%SOURCE_FILE% issue: Inventory Item #%index% (%item%.ITM) is not actually in inventory! No free inventory slot found! Adding to Slot #%foundslot%..."
WRITE_SHORT ("%slot_off%" + (0x02 * "%foundslot%")) "index"
END
END
END
END
END
END
BUT_ONLY_IF_IT_CHANGES
BEGIN ~Creature Stuff - Inventory Cleaner (removes items that don't exist and converts them into already present items where applicable)~
GROUP ~Creature Stuff~
ACTION_CLEAR_ARRAY tutu_convert_itm
ACTION_DEFINE_ASSOCIATIVE_ARRAY tutu_convert_itm BEGIN
_AROW01 => AROW01
_AROW02 => AROW02
_AROW07 => AROW07
_AX1H04 => AX1H04
_BOW01 => BOW01
_BOW03 => BOW03
_BOW08 => BOW08
_BLUN02 => BLUN02
_BULL02 => BULL02
_BRAC04 => BRAC04
_CHAN01 => CHAN01
_CHAN04 => CHAN04
_CHAN05 => CHAN05
_CHAN07 => CHAN07
_DAGG01 => DAGG01
_DAGG03 => DAGG03
_DAGG05 => DAGG05
_DART01 => DART01
_DART02 => DART02
_HELM01 => HELM01
_HELM09 => HELM09
_HELM11 => HELM11
_JELLGR1 => JELLGR1
_LEAT01 => LEAT01
_LEAT02 => LEAT02
_LEAT04 => LEAT04
_MAGE01 => MAGE02
_MAGE02 => MAGE02
_MAGE05 => MAGE05
_AGEBRAC => MAGEBRAC
_MISC33 => MISC33
_PLAT01 => PLAT01
_PLAT04 => PLAT04
_POTN08 => POTN08
_POTN20 => POTN20
_POTN21 => POTN21
_POTN36 => POTN36
_POTN37 => POTN37
_POTN45 => POTN45
_RING95 => RING95
_SCRL96 => SCRL96
_SHLD01 => SHLD01
_SHLD08 => SHLD08
_SLNG02 => SLNG02
_SPER01 => SPER01
_SPER02 => SPER02
_STAF01 => STAF01
_STAF02 => STAF02
_STAF07 => STAF07
_SW1H01 => SW1H01
_SW1H04 => SW1H04
_SW1H07 => SW1H07
_SW1H08 => SW1H08
_SW1H24 => SW1H24
_SW2H01 => SW2H01
// Typoed Items
2HSW02 => SW2H02
ANKSHELL => MISC1A
ARRW01 => AROW01
BLUNT06 => BLUN06
CHAM01 => CHAN01
DWCHA01 => DWCHAN01
GHOST01 => GHOST
HRZRSHED => SD_HRZR
IOUNX6 => IOUNX8
LEATH01 => LEAT01
LEATH04 => LEAT04
MIN1HP => MINHP1
RDNTRE03 => RNDTRE03
RDNTRE04 => RNDTRE04
RNGDEMN => RINGDEMN
SCRL1R => "U!SCRL03" // 'cause WeiDU don't like dem exclamations in filenames
SH1H04 => SW1H04
SLING04 => SLNG04
STAFF01 => STAF01
UMBER1 => UMBER01
VAMP01 => VAMP1
END
COPY_EXISTING_REGEXP GLOB ~^.+\.cre$~ ~override~
PATCH_IF ((SOURCE_SIZE > 0x2d3)) THEN BEGIN
READ_LONG 0x2bc "itm_off" ELSE 0
READ_LONG 0x2c0 "itm_num" ELSE 0
PATCH_IF ("itm_off" > 0x2d3) THEN BEGIN
FOR (index = 0 ; index < itm_num ; index = index + 1) BEGIN
READ_ASCII ("%itm_off%" + (0x14 * "%index%")) "item"
PATCH_IF (NOT (FILE_EXISTS_IN_GAME ~%item%.itm~) AND ("%item%" STRING_COMPARE_REGEXP "^[Rr][Nn][Dd].+$")) BEGIN
SET "converted" = 0
PHP_EACH tutu_convert_itm AS tutu_itm => bgt_itm BEGIN
PATCH_IF ("%item%" STRING_EQUAL_CASE "%tutu_itm%") AND (FILE_EXISTS_IN_GAME "%bgt_itm%.itm") BEGIN
WRITE_ASCIIE ("%itm_off%" + (0x14 * "%index%")) "%bgt_itm%" #8
SET "converted" = 1
PATCH_PRINT "%SOURCE_FILE% issue: Replacing %tutu_itm%.itm with %bgt_itm%.itm..."
END
END
PATCH_IF ("%converted%" = 0) BEGIN
PATCH_PRINT "%SOURCE_FILE% issue: Inventory Item #%index% (%item%.itm) does not exist! Removing item..."
REMOVE_CRE_ITEM ~%item%~
SET "index" = 0 - 1
READ_LONG 0x2c0 "itm_num"
END
END
END
END
END
BUT_ONLY_IF_IT_CHANGES
BEGIN ~Creature Stuff - Inventory Overhauler (moves invalid but equippable items to inventory and equips anything in the inventory to a free slot)~
GROUP ~Creature Stuff~
//G3 Debugging Suite - Equip invalid items
COPY_EXISTING_REGEXP GLOB ~^.+\.cre$~ ~override~
PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
READ_LONG 0x2b8 "slot_off" ELSE 0
READ_LONG 0x2bc "itm_off" ELSE 0
// tracking variables
SET "2hweapon" = 0
SET "offhand" = 0
SET "bow" = 0
SET "arrows" = 0
SET "xbow" = 0
SET "bolts" = 0
SET "sling" = 0
SET "bullets" = 0
SET "helm" = 0
SET "armor" = 0
SET "gloves" = 0
SET "lring" = 0
SET "rring" = 0
SET "boots" = 0
SET "belt" = 0
SET "amulet" = 0
SET "weapon1" = 0
SET "weapon2" = 0
SET "weapon3" = 0
SET "weapon4" = 0
SET "quiver1" = 0
SET "quiver2" = 0
SET "quiver3" = 0
SET "quiver4" = 0
SET "cloak" = 0
SET "2handedequip" = 0
PATCH_IF (("slot_off" > 0x2d3) AND ("itm_off" > 0x2d3)) BEGIN
FOR (index = 0 ; index < 36 ; index = index + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index%")) "ref"
PATCH_IF ("%ref%" != 0xffff) BEGIN
READ_ASCII ("%itm_off%" + (0x14 * "%ref%")) "item"
READ_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) "cre_flags"
PATCH_IF FILE_EXISTS_IN_GAME ~%item%.itm~ THEN BEGIN
INNER_PATCH_FILE ~%item%.itm~ BEGIN
READ_SHORT 0x1c "type"
READ_BYTE 0x18 "flags"
END
PATCH_IF ("%index%" = 0) BEGIN // helm slot
SET "helm" = 1
PATCH_IF (("%type%" != 7) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // helm
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid HELM: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "helm" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid HELM: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 1) BEGIN // armor slot
SET "armor" = 1
PATCH_IF (("%type%" != 2) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // armor
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid ARMOR: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "armor" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid ARMOR: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 2) BEGIN // shield slot
SET "offhand" = 1
PATCH_IF (("%flags%" BAND 0b00010110) = 0b00000110) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // 2h, uncursed and droppable check
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: 2-HANDED OFFHAND: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "offhand" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: 2-HANDED OFFHAND: %item%.itm! Cannot move because Inventory full!~
END
END ELSE
PATCH_IF (("%type%" != 12) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // if not shield, check for valid melee abilities
SET "legit_offhand" = 0
INNER_PATCH_FILE ~%item%.itm~ BEGIN
READ_LONG 0x64 "abil_off"
READ_SHORT 0x68 "abil_num"
FOR (index3 = 0 ; index3 < abil_num ; index3 = index3 + 1) BEGIN
READ_BYTE ("%abil_off%" + (0x38 * "%index3%")) "ability"
PATCH_IF ("%ability%" = 1) AND (%type% > 14) AND (%type% < 31) BEGIN // only melee weapons allowed in offhand
SET "legit_offhand" = 1
END
END
END
PATCH_IF ("%legit_offhand%" = 0) BEGIN
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid OFFHAND: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "offhand" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid OFFHAND: %item%.itm! Cannot move because Inventory full!~
END
END
END ELSE
PATCH_IF ("%type%" = 12) AND (("%flags%" BAND 0b00010100) = 0b00000100) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * 9)) "refa"
READ_SHORT ("%slot_off%" + (0x02 * 10)) "refb"
READ_SHORT ("%slot_off%" + (0x02 * 11)) "refc"
READ_SHORT ("%slot_off%" + (0x02 * 12)) "refd"
PATCH_IF ("%refa%" != 0xffff) BEGIN
READ_ASCII ("%itm_off%" + (0x14 * "%refa%")) "item1"
PATCH_IF FILE_EXISTS_IN_GAME ~%item1%.itm~ THEN BEGIN
INNER_PATCH_FILE ~%item1%.itm~ BEGIN
READ_SHORT 0x1c "type1"
READ_BYTE 0x18 "flags1"
PATCH_IF (("%flags1%" BAND 0b00000010) = 0b00000010) AND ((%type1% > 14) AND (%type1% < 31)) THEN BEGIN
SET "2handedequip" = 1
END
END
END
END
PATCH_IF ("%refb%" != 0xffff) BEGIN
READ_ASCII ("%itm_off%" + (0x14 * "%refb%")) "item2"
PATCH_IF FILE_EXISTS_IN_GAME ~%item2%.itm~ THEN BEGIN
INNER_PATCH_FILE ~%item2%.itm~ BEGIN
READ_SHORT 0x1c "type2"
READ_BYTE 0x18 "flags2"
PATCH_IF (("%flags2%" BAND 0b00000010) = 0b00000010) AND ((%type2% > 14) AND (%type2% < 31)) THEN BEGIN
SET "2handedequip" = 1
END
END
END
END
PATCH_IF ("%refc%" != 0xffff) BEGIN
READ_ASCII ("%itm_off%" + (0x14 * "%refc%")) "item3"
PATCH_IF FILE_EXISTS_IN_GAME ~%item3%.itm~ THEN BEGIN
INNER_PATCH_FILE ~%item3%.itm~ BEGIN
READ_SHORT 0x1c "type3"
READ_BYTE 0x18 "flags3"
PATCH_IF (("%flags3%" BAND 0b00000010) = 0b00000010) AND ((%type3% > 14) AND (%type3% < 31)) THEN BEGIN
SET "2handedequip" = 1
END
END
END
END
PATCH_IF ("%refd%" != 0xffff) BEGIN
READ_ASCII ("%itm_off%" + (0x14 * "%refd%")) "item4"
PATCH_IF FILE_EXISTS_IN_GAME ~%item4%.itm~ THEN BEGIN
INNER_PATCH_FILE ~%item4%.itm~ BEGIN
READ_SHORT 0x1c "type4"
READ_BYTE 0x18 "flags4"
PATCH_IF (("%flags4%" BAND 0b00000010) = 0b00000010) AND ((%type4% > 14) AND (%type4% < 31)) THEN BEGIN
SET "2handedequip" = 1
END
END
END
END
PATCH_IF ("%2handedequip%" = 1) BEGIN
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: OFFHAND with 2-HAND: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "offhand" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: OFFHAND with 2-HAND: %item%.itm! Cannot move because Inventory full!~
END
END
END
END
PATCH_IF ("%index%" = 3) BEGIN // glove slot
SET "gloves" = 1
PATCH_IF (("%type%" != 6) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // gloves
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid GLOVES: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "gloves" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid GLOVES: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 4) BEGIN // left ring slot
SET "lring" = 1
PATCH_IF (("%type%" != 10) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // rings
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid LRING: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "lring" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid LRING: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 5) BEGIN // right ring slot
SET "rring" = 1
PATCH_IF (("%type%" != 10) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // rings
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid RRING: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "rring" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid RRING: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 6) BEGIN // amulet slot
SET "amulet" = 1
PATCH_IF (("%type%" != 1) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // amulet
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid AMULET: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "amulet" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid AMULET: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 7) BEGIN // belt slot
SET "belt" = 1
PATCH_IF (("%type%" != 3) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // belt
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid BELT: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "belt" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid BELT: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 8) BEGIN // boot slot
SET "boots" = 1
PATCH_IF (("%type%" != 4) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN // boot
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid BOOTS: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "boots" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid BOOTS: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 9) BEGIN // first weapon slot
SET "weapon1" = 1
SET "legit_weapon" = 0
INNER_PATCH_FILE ~%item%.itm~ BEGIN
READ_BYTE 0x18 "flags"
READ_LONG 0x64 "abil_off"
READ_SHORT 0x68 "abil_num"
FOR (index3 = 0 ; index3 < abil_num ; index3 = index3 + 1) BEGIN
READ_BYTE ("%abil_off%" + (0x38 * "%index3%")) "ability"
PATCH_IF (("%ability%" = 1) OR ("%ability%" = 2) OR ("%ability%" = 4)) AND ("%type%" > 14) AND ("%type%" < 31) BEGIN // melee, ranged, or launcher
SET "legit_weapon" = 1
END
END
PATCH_IF (("%legit_weapon%" = 1) AND (("%flags%" BAND 0b00000010) = 0b00000010)) BEGIN // 2h check
SET "2handedequip" = 1
END
END
PATCH_IF (("%legit_weapon%" = 0) AND (("%flags%" BAND 0b00010100) = 0b00000100)) AND (("%cre_flags%" BAND 0b00001000) = 0b00000000) BEGIN
SET "ref2" = 1
FOR (index3 = 21 ; ref2 != 0xffff && index3 < 37 ; index3 = index3 + 1) BEGIN
READ_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref2"
END
SET "index3" = "index3" - 1
PATCH_IF ("%ref2%" = 0xffff) BEGIN
SET "slot" = "index3" - 20
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid WEAPON1: %item%.itm! Moving to Inventory Slot #%slot%~
WRITE_SHORT ("%slot_off%" + (0x02 * "%index%")) 0xffff
WRITE_SHORT ("%slot_off%" + (0x02 * "%index3%")) "ref"
WRITE_BYTE ("%itm_off%" + 0x10 + (0x14 * "%ref%")) ("%cre_flags%" BOR 0b00000010)
SET "weapon1" = 0
SET "index" = 0 - 1
END ELSE
BEGIN
PATCH_PRINT ~%SOURCE_FILE% issue: Invalid WEAPON1: %item%.itm! Cannot move because Inventory full!~
END
END
END
PATCH_IF ("%index%" = 10) BEGIN // second weapon slot
SET "weapon2" = 1
SET "legit_weapon" = 0
INNER_PATCH_FILE ~%item%.itm~ BEGIN
READ_BYTE 0x18 "flags"
READ_LONG 0x64 "abil_off"
READ_SHORT 0x68 "abil_num"
FOR (index3 = 0 ; index3 < abil_num ; index3 = index3 + 1) BEGIN
READ_BYTE ("%abil_off%" + (0x38 * "%index3%")) "ability"
PATCH_IF (("%ability%" = 1) OR ("%ability%" = 2) OR ("%ability%" = 4)) AND ("%type%" > 14) AND ("%type%" < 31) BEGIN // melee, ranged, or launcher
SET "legit_weapon" = 1