-
Notifications
You must be signed in to change notification settings - Fork 1
/
Yoshis-Island-Utilities.lua
4520 lines (3623 loc) · 191 KB
/
Yoshis-Island-Utilities.lua
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
---------------------------------------------------------------------------
-- Super Mario World 2 - Yoshi's Island (U) Utility Script for Snes9x - rr
-- http://tasvideos.org/GameResources/SNES/YoshisIsland.html
--
-- Author: BrunoValads
-- Git repository: https://github.com/brunovalads/yoshis-island-stuff -- TODO
--
-- Based on Amaraticando's Super Mario World script for Snes9x-rr
-- http://github.com/rodamaral/smw-tas/blob/master/Snes9x/smw-snes9x.lua
---------------------------------------------------------------------------
--#############################################################################
-- CONFIG:
local INI_CONFIG_FILENAME = "Yoshi's Island Utilities Config.ini" -- relative to the folder of the script
local DEFAULT_OPTIONS = {
-- Hotkeys
-- make sure that the hotkeys below don't conflict with previous bindings
hotkey_decrease_opacity = "numpad-", -- to decrease the opacity of the text
hotkey_increase_opacity = "numpad+", -- to increase the opacity of the text
-- Display
display_movie_info = true,
display_misc_info = true,
display_player_info = true,
display_player_hitbox = true, -- can be changed by right-clicking on player
display_interaction_points = true, -- can be changed by right-clicking on player
display_throw_info = true,
display_blocked_status = true,
display_sprite_info = true,
display_sprite_hitbox = true, -- you still have to select the sprite with the mouse
display_extended_sprite_info = false,
display_cluster_sprite_info = false,
display_minor_extended_sprite_info = false,
display_bounce_sprite_info = false,
display_level_info = true,
display_yoshi_info = true,
display_counters = true,
display_controller_input = true,
display_static_camera_region = false, -- shows the region in which the camera won't scroll horizontally
draw_tiles_with_click = true,
-- Some extra/debug info
display_debug_info = false, -- shows useful info while investigating the game, but not very useful while TASing
display_debug_player_extra = true,
display_debug_sprite_extra = true,
display_debug_sprite_tweakers = true,
display_debug_extended_sprite = true,
display_debug_cluster_sprite = true,
display_debug_minor_extended_sprite = true,
display_debug_bounce_sprite = true,
display_debug_controller_data = false, -- Snes9x: might cause desyncs
display_miscellaneous_sprite_table = false,
miscellaneous_sprite_table_number = {[1] = true, [2] = true, [3] = true, [4] = true, [5] = true, [6] = true, [7] = true, [8] = true, [9] = true,
[10] = true, [11] = true, [12] = true, [13] = true, [14] = true, [15] = true, [16] = true, [17] = true, [18] = true, [19] = true
},
display_mouse_coordinates = false,
draw_tile_map_grid = false,
draw_tile_map_type = false,
draw_tile_map_gfx_type = false,
draw_tile_map_phy_type = false,
-- Memory edit function
address = 0x7E0000,
size = 1,
value = 0,
edit_method = "Poke",
edit_sprite_table = false,
edit_sprite_table_number = {[1] = false, [2] = false, [3] = false, [4] = false, [5] = false, [6] = false, [7] = false, [8] = false, [9] = false,
[10] = false, [11] = false, [12] = false, [13] = false, [14] = false, [15] = false, [16] = false, [17] = false, [18] = false,
[19] = false, [20] = false, [21] = false, [22] = false, [23] = false, [24] = false},
-- Script settings
max_tiles_drawn = 20, -- the max number of tiles to be drawn/registered by the script
}
-- Colour settings
local DEFAULT_COLOUR = {
-- Text
default_text_opacity = 1.0,
default_bg_opacity = 0.7,
text = "#ffffff", -- white
background = "#000000", -- black
halo = "#000040",
positive = "#00ff00", -- green
warning = "#ff0000", -- red
warning_bg = "#000000ff",
warning2 = "#ff00ff", -- purple
warning_soft = "#ffa500", -- orange
weak = "#00a9a9a9",
weak2 = "#555555", -- gray
very_weak = "#a0ffffff",
memory = "#00ffff", -- cyan
joystick_input = "#ffff00ff",
joystick_input_bg = "#ffffff30",
button_text = "#300030ff",
mainmenu_outline = "#ffffffc0",
mainmenu_bg = "#000000c0",
-- Counters
counter_pipe = "#00ff00ff",
counter_multicoin = "#ffff00ff",
counter_gray_pow = "#a5a5a5ff",
counter_blue_pow = "#4242deff",
counter_dircoin = "#8c5a19ff",
counter_pballoon = "#f8d870ff",
counter_star = "#ffd773ff",
counter_fireflower = "#ff8c00ff",
-- hitbox and related text
mario = "#ff0000ff",
mario_bg = "#00000000",
mario_mounted_bg = "#00000000",
interaction = "#ffffffff",
interaction_bg = "#00000020",
interaction_nohitbox = "#000000a0",
interaction_nohitbox_bg = "#00000070",
sprites = {
"#80ffff", -- cyan
"#a0a0ff", -- blue
"#ff6060", -- red
"#ff80ff", -- magenta
"#ffa100", -- orange
"#ffff80", -- yellow
"#40ff40" -- green
},
sprites_bg = "#00ff00",
sprites_interaction_pts = "#ffffffff",
sprites_clipping_bg = "#000000a0",
extended_sprites = {
"#ff3700", -- orange to red gradient 6
"#ff5b00", -- orange to red gradient 4
"#ff8000", -- orange to red gradient 2
"#ffa500" -- orange to red gradient 0 (orange)
},
extended_sprites_bg = "#00ff0050",
special_extended_sprite_bg = "#00ff0060",
goal_tape_bg = "#ffff0050",
fireball = "#b0d0ffff",
baseball = "#0040a0ff",
cluster_sprites = "#ff80a0ff",
sumo_brother_flame = "#0040a0ff",
minor_extended_sprites = "#ff90b0ff",
awkward_hitbox = "#204060ff",
awkward_hitbox_bg = "#ff800060",
yoshi = "#00ffffff",
yoshi_bg = "#00ffff40",
yoshi_mounted_bg = "#00000000",
tongue_line = "#ffa000ff",
tongue_bg = "#00000060",
cape = "#ffd700ff",
cape_bg = "#ffd70060",
block = "#00008bff",
blank_tile = "#ffffff70",
block_bg = "#22cc88a0",
layer2_line = "#ff2060ff",
layer2_bg = "#ff206040",
static_camera_region = "#40002040",
}
-- Font settings
local SNES9X_FONT_HEIGHT = 8
local SNES9X_FONT_WIDTH = 4
-- GD images dumps (encoded)
local GD_IMAGES_DUMPS = {}
GD_IMAGES_DUMPS.player_blocked_status = {255, 254, 0, 25, 0, 30, 1, 255, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 255, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 66, 33, 0, 255, 148, 0, 0, 255, 148, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 148, 49, 33, 0, 255, 66, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 99, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 99, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 2, 0, 0, 0, 0, 255, 148, 0, 0, 0, 0, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 255, 255, 255, 0, 0, 255, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 255, 0, 0, 0, 99, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 255, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 148, 49, 33, 0, 255, 66, 33, 0, 0, 0, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 255, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 148, 49, 33, 0, 148, 49, 33, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 255, 198, 173, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 198, 173, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 173, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 66, 33, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 255, 198, 173, 0, 255, 198, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 255, 198, 173, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 66, 33, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 255, 198, 173, 0, 255, 198, 173, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 173, 0, 0, 255, 198, 173, 0, 255, 198, 173, 0, 255, 198, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 66, 33, 0, 255, 255, 255, 0, 255, 66, 33, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 173, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 66, 33, 0, 255, 66, 33, 0, 255, 66, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 173, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 231, 214, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 173, 0, 0, 0, 173, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 255, 231, 214, 0, 255, 231, 214, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 231, 214, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 173, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 231, 214, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 198, 173, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 148, 49, 33, 0, 255, 66, 33, 0, 255, 148, 0, 0, 255, 148, 0, 0, 0, 0, 0, 0, 255, 198, 173, 0, 255, 198, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 148, 49, 33, 0, 255, 66, 33, 0, 255, 148, 0, 0, 255, 148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 148, 49, 33, 0, 148, 49, 33, 0, 148, 49, 33, 0, 255, 66, 33, 0, 255, 255, 255, 0, 255, 148, 0, 0, 0, 0, 0, 0, 148, 49, 33, 0, 255, 66, 33, 0, 255, 148, 0, 0, 255, 148, 0, 0, 255, 255, 255, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 148, 49, 33, 0, 148, 49, 33, 0, 255, 66, 33, 0, 255, 148, 0, 0, 255, 148, 0, 0, 255, 148, 0, 0, 0, 0, 0, 0, 148, 49, 33, 0, 148, 49, 33, 0, 255, 66, 33, 0, 255, 66, 33, 0, 255, 148, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255}
GD_IMAGES_DUMPS.goal_tape = {255, 254, 0, 18, 0, 6, 1, 255, 255, 255, 255, 107, 153, 153, 153, 38, 75, 75, 75, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 0, 63, 63, 63, 32, 84, 84, 84, 0, 186, 186, 186, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 62, 62, 62, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 248, 248, 248, 0, 55, 55, 55, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 0, 216, 216, 216, 33, 75, 75, 75, 0, 136, 136, 136, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 0, 176, 176, 176, 106, 160, 160, 160, 40, 60, 60, 60, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40, 0, 40, 40, 40}
-- Symbols
local LEFT_ARROW = "<-"
local RIGHT_ARROW = "->"
-- Others
local Border_right, Border_left, Border_top, Border_bottom = 0, 0, 0, 0
local Buffer_width, Buffer_height, Buffer_middle_x, Buffer_middle_y = 256, 224, 128, 112
local Screen_width, Screen_height, AR_x, AR_y = 256, 224, 1, 1
local Y_CAMERA_OFF = 1 -- small adjustment to display the tiles according to their actual graphics
-- Input key names
local INPUT_KEYNAMES = { -- Snes9x
xmouse=0, ymouse=0, leftclick=false, rightclick=false, middleclick=false,
shift=false, control=false, alt=false, capslock=false, numlock=false, scrolllock=false,
["false"]=false, ["1"]=false, ["2"]=false, ["3"]=false, ["4"]=false, ["5"]=false, ["6"]=false, ["7"]=false, ["8"]=false,["9"]=false,
A=false, B=false, C=false, D=false, E=false, F=false, G=false, H=false, I=false, J=false, K=false, L=false, M=false, N=false,
O=false, P=false, Q=false, R=false, S=false, T=false, U=false, V=false, W=false, X=false, Y=false, Z=false,
F1=false, F2=false, F3=false, F4=false, F5=false, F6=false, F7=false, F8=false, F9=false, F1false=false, F11=false, F12=false,
F13=false, F14=false, F15=false, F16=false, F17=false, F18=false, F19=false, F2false=false, F21=false, F22=false, F23=false, F24=false,
backspace=false, tab=false, enter=false, pause=false, escape=false, space=false,
pageup=false, pagedown=false, ["end"]=false, home=false, insert=false, delete=false,
left=false, up=false, right=false, down=false,
numpadfalse=false, numpad1=false, numpad2=false, numpad3=false, numpad4=false, numpad5=false, numpad6=false, numpad7=false, numpad8=false, numpad9=false,
["numpad*"]=false, ["numpad+"]=false, ["numpad-"]=false, ["numpad."]=false, ["numpad/"]=false,
tilde=false, plus=false, minus=false, leftbracket=false, rightbracket=false,
semicolon=false, quote=false, comma=false, period=false, slash=false, backslash=false
}
-- END OF CONFIG < < < < < < <
--#############################################################################
-- INITIAL STATEMENTS:
print("Starting script")
-- Load environment
local gui, input, joypad, emu, movie, memory = gui, input, joypad, emu, movie, memory
local unpack = unpack or table.unpack
local string, math, table, next, ipairs, pairs, io, os, type = string, math, table, next, ipairs, pairs, io, os, type
local bit = require"bit"
-- Script tries to verify whether the emulator is indeed Snes9x-rr
if snes9x == nil then
error("This script works with Snes9x-rr emulator.")
end
-- TEST: INI library for handling an ini configuration file
function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then io.close(f) return true else return false end
end
function copytable(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[copytable(orig_key)] = copytable(orig_value) -- possible stack overflow
end
setmetatable(copy, copytable(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
function mergetable(source, t2)
for key, value in pairs(t2) do
if type(value) == "table" then
if type(source[key] or false) == "table" then
mergetable(source[key] or {}, t2[key] or {}) -- possible stack overflow
else
source[key] = value
end
else
source[key] = value
end
end
return source
end
-- Creates a set from a list
local function make_set(list)
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end
local INI = {}
function INI.arg_to_string(value)
local str
if type(value) == "string" then
str = "\"" .. value .. "\""
elseif type(value) == "number" or type(value) == "boolean" or value == nil then
str = tostring(value)
elseif type(value) == "table" then
local tmp = {"{"} -- only arrays
for a, b in ipairs(value) do
table.insert(tmp, ("%s%s"):format(INI.arg_to_string(b), a ~= #value and ", " or "")) -- possible stack overflow
end
table.insert(tmp, "}")
str = table.concat(tmp)
else
str = "#BAD_VALUE"
end
return str
end
-- creates the string for ini
function INI.data_to_string(data)
local sections = {}
for section, prop in pairs(data) do
local properties = {}
for key, value in pairs(prop) do
table.insert(properties, ("%s = %s\n"):format(key, INI.arg_to_string(value))) -- properties
end
table.sort(properties)
table.insert(sections, ("[%s]\n"):format(section) .. table.concat(properties) .. "\n")
end
table.sort(sections)
return table.concat(sections)
end
function INI.string_to_data(value)
local data
if tonumber(value) then
data = tonumber(value)
elseif value == "true" then
data = true
elseif value == "false" then
data = false
elseif value == "nil" then
data = nil
else
local quote1, text, quote2 = value:match("(['\"{])(.+)(['\"}])") -- value is surrounded by "", '' or {}?
if quote1 and quote2 and text then
if (quote1 == '"' or quote1 == "'") and quote1 == quote2 then
data = text
elseif quote1 == "{" and quote2 == "}" then
local tmp = {} -- test
for words in text:gmatch("[^,%s]+") do
tmp[#tmp + 1] = INI.string_to_data(words) -- possible stack overflow
end
data = tmp
else
data = value
end
else
data = value
end
end
return data
end
function INI.load(filename)
local file = io.open(filename, "r")
if not file then return false end
local data, section = {}, nil
for line in file:lines() do
local new_section = line:match("^%[([^%[%]]+)%]$")
if new_section then
section = INI.string_to_data(new_section) and INI.string_to_data(new_section) or new_section
if data[section] then print("Duplicated section") end
data[section] = data[section] or {}
else
local prop, value = line:match("^([%w_%-%.]+)%s*=%s*(.+)%s*$") -- prop = value
if prop and value then
value = INI.string_to_data(value)
prop = INI.string_to_data(prop) and INI.string_to_data(prop) or prop
if data[section] == nil then print(prop, value) ; error("Property outside section") end
data[section][prop] = value
else
local ignore = line:match("^;") or line == ""
if not ignore then
print("BAD LINE:", line, prop, value)
end
end
end
end
file:close()
return data
end
function INI.retrieve(filename, data)
if type(data) ~= "table" then error"data must be a table" end
local previous_data
-- Verifies if file already exists
if file_exists(filename) then
ini_data = INI.load(filename)
else return data
end
-- Adds previous values to the new ini
local union_data = mergetable(data, ini_data)
return union_data
end
function INI.overwrite(filename, data)
local file, err = assert(io.open(filename, "w"), "Error loading file :" .. filename)
if not file then print(err) ; return end
file:write(INI.data_to_string(data))
file:close()
end
function INI.save(filename, data)
if type(data) ~= "table" then error"data must be a table" end
local tmp, previous_data
if file_exists(filename) then
previous_data = INI.load(filename)
tmp = mergetable(previous_data, data)
else
tmp = data
end
INI.overwrite(filename, tmp)
end
local OPTIONS = file_exists(INI_CONFIG_FILENAME) and INI.retrieve(INI_CONFIG_FILENAME, {["SNES9X OPTIONS"] = DEFAULT_OPTIONS}).OPTIONS or DEFAULT_OPTIONS
local COLOUR = file_exists(INI_CONFIG_FILENAME) and INI.retrieve(INI_CONFIG_FILENAME, {["SNES9X COLOURS"] = DEFAULT_COLOUR}).COLOURS or DEFAULT_COLOUR
INI.save(INI_CONFIG_FILENAME, {["SNES9X COLOURS"] = COLOUR}) -- Snes9x doesn't need to convert colour string to number
INI.save(INI_CONFIG_FILENAME, {["SNES9X OPTIONS"] = OPTIONS})
function INI.save_options()
INI.save(INI_CONFIG_FILENAME, {["SNES9X OPTIONS"] = OPTIONS})
end
--######################## -- end of test
-- Text/Background_max_opacity is only changed by the player using the hotkeys
-- Text/Bg_opacity must be used locally inside the functions
local Text_max_opacity = COLOUR.default_text_opacity
local Background_max_opacity = COLOUR.default_bg_opacity
local Text_opacity = 1
local Bg_opacity = 1
local fmt = string.format
local floor = math.floor
local sqrt = math.sqrt
local sin = math.sin
local cos = math.cos
local pi = math.pi
-- unsigned to signed (based in <bits> bits)
local function signed(num, bits)
local maxval = 2^(bits - 1)
if num < maxval then return num else return num - 2*maxval end
end
-- Compatibility of the memory read/write functions
local u8 = memory.readbyte
local s8 = memory.readbytesigned
local w8 = memory.writebyte
local u16 = memory.readword
local s16 = memory.readwordsigned
local w16 = memory.writeword
local u24 = function(address, value) return 256*u16(address + 1) + u8(address) end
local s24 = function(address, value) return signed(256*u16(address + 1) + u8(address), 24) end
local w24 = function(address, value) w16(address + 1, floor(value/256)) ; w8(address, value%256) end
-- Images (for gd library)
local IMAGES = {}
IMAGES.player_blocked_status = string.char(unpack(GD_IMAGES_DUMPS.player_blocked_status))
IMAGES.goal_tape = string.char(unpack(GD_IMAGES_DUMPS.goal_tape))
-- Hotkeys availability
if INPUT_KEYNAMES[OPTIONS.hotkey_increase_opacity] == nil then
print(string.format("Hotkey '%s' is not available, to increase opacity.", OPTIONS.hotkey_increase_opacity))
else print(string.format("Hotkey '%s' set to increase opacity.", OPTIONS.hotkey_increase_opacity))
end
if INPUT_KEYNAMES[OPTIONS.hotkey_decrease_opacity] == nil then
print(string.format("Hotkey '%s' is not available, to decrease opacity.", OPTIONS.hotkey_decrease_opacity))
else print(string.format("Hotkey '%s' set to decrease opacity.", OPTIONS.hotkey_decrease_opacity))
end
--#############################################################################
-- GAME AND SNES SPECIFIC MACROS:
local NTSC_FRAMERATE = 60.0
local SMW2 = {
-- Game Modes
game_mode_overworld = 0x0022,
game_mode_level = 0x000F,
-- Sprites
sprite_max = 24,
extended_sprite_max = 16,
cluster_sprite_max = 20,
minor_extended_sprite_max = 12,
bounce_sprite_max = 4,
null_sprite_id = 0xff,
-- Blocks
blank_tile_map16 = 0x25,
}
SFXRAM = { -- 700000~701FFF
-- General
level_timer = 0x701974, -- 2 bytes
screen_number_to_id = 0x700CAA, -- 128 bytes table
RNG = 0x701970, -- 2 bytes
-- Player
x = 0x70008C, -- 2 bytes
y = 0x700090, -- 2 bytes
--previous_x = 0x7000d1,
--previous_y = 0x7000d3,
x_sub = 0x70008A,
y_sub = 0x70008E,
x_speed = 0x7000A9,
x_subspeed = 0x7000A8,
y_speed = 0x7000AB,
y_subspeed = 0x7000AA,
direction = 0x7000C4,
ground_pound_state = 0x7000D4,
ground_pound_timer = 0x7000D6,
egg_target_x = 0x7000E4, -- 2 bytes
egg_target_y = 0x7000E6, -- 2 bytes
egg_target_radial_pos = 0x7000EF,
egg_target_radial_subpos = 0x7000EE,
egg_throw_state = 0x7000DE,
egg_throw_state_timer = 0x7001E2,
player_blocked_status = 0x7000FC,
x_centered = 0x70011C, -- 2 bytes
y_centered = 0x70011E, -- 2 bytes
tongue_x = 0x700152, -- 2 bytes
tongue_y = 0x700154, -- 2 bytes
tongue_state = 0x700150,
ammo_in_mouth = 0x70016A,
is_frozen = 0x7001AE, -- 2 bytes
on_sprite_platform = 0x7001B4,
--is_ducking = 0x700073,
--p_meter = 0x7013e4,
--take_off = 0x70149f,
--powerup = 0x700019,
--diving_status = 0x701409,
--player_animation_trigger = 0x700071,
--climbing_status = 0x700074,
--on_ground = 0x7013ef,
--on_ground_delay = 0x70008d,
--on_air = 0x700072,
--can_jump_from_water = 0x7013fa,
--carrying_item = 0x70148f,
--player_looking_up = 0x7013de,
-- Baby Mario
mario_status = 0x700F00,
-- Timer
invincibility_timer = 0x7001D6,
eat_timer = 0x7001EE,
transform_timer = 0x7001F4,
star_timer = 0x701E04,
-- Sprites
sprite_status = 0x700F00,
sprite_type = 0x701360,
sprite_x = 0x7010E0, -- 2 bytes
sprite_y = 0x701180, -- 2 bytes
sprite_x_sub = 0x7010DF,
sprite_y_sub = 0x70117F,
sprite_x_speed = 0x701221,
sprite_x_subspeed = 0x701220,
sprite_y_speed = 0x701223,
sprite_y_subspeed = 0x701222,
sprite_hitbox_half_width = 0x701B56, -- 2 bytes
sprite_hitbox_half_height = 0x701B58, -- 2 bytes
sprite_x_center = 0x701CD6, -- 2 bytes
sprite_y_center = 0x701CD8 -- 2 bytes
}
--[[
for name, address in pairs(SFXRAM) do
address = address + 0x700000 -- Snes9x
end]]
local SFXRAM = SFXRAM
WRAM = { -- 7E0000~7FFFFF
-- I/O
ctrl_1_1 = 0x0015,
ctrl_1_2 = 0x0017,
firstctrl_1_1 = 0x0016,
firstctrl_1_2 = 0x0018,
-- General
game_mode = 0x0118,
--real_frame = 0x0013,
--effective_frame = 0x0014,
--lag_indicator = 0x01fe,
--timer_frame_counter = 0x0f30,
--RNG = 0x148d,
--current_level = 0x00fe, -- plus 1
--lock_animation_flag = 0x009d, -- Most codes will still run if this is set, but almost nothing will move or animate.
--level_mode_settings = 0x1925,
red_coin_counter = 0x03B4,
star_counter = 0x03B6,
flower_counter = 0x03B8,
coin_counter = 0x037b,
is_paused = 0x0B10,
Map16_data = 0x18000, -- 32768 bytes table, in words
-- Cheats
frozen = 0x13fb,
level_paused = 0x13d4,
level_index = 0x021A, -- 2 bytes
room_index = 0x00ce,
level_flag_table = 0x1ea2,
level_exit_type = 0x0dd5,
midway_point = 0x13ce,
-- Camera
camera_x = 0x0039,
camera_y = 0x003B,
screens_number = 0x005d,
hscreen_number = 0x005e,
vscreen_number = 0x005f,
vertical_scroll_flag_header = 0x1412, -- #$00 = Disable; #$01 = Enable; #$02 = Enable if flying/climbing/etc.
vertical_scroll_enabled = 0x13f1,
camera_scroll_timer = 0x1401,
-- Sprites
sprite_status = 0x14c8,
sprite_number = 0x009e,
sprite_x_high = 0x14e0,
sprite_x_low = 0x00e4,
sprite_y_high = 0x14d4,
sprite_y_low = 0x00d8,
sprite_x_sub = 0x14f8,
sprite_y_sub = 0x14ec,
sprite_x_speed = 0x00b6,
sprite_y_speed = 0x00aa,
sprite_x_offscreen = 0x15a0,
sprite_y_offscreen = 0x186c,
sprite_miscellaneous1 = 0x00c2,
sprite_miscellaneous2 = 0x1504,
sprite_miscellaneous3 = 0x1510,
sprite_miscellaneous4 = 0x151c,
sprite_miscellaneous5 = 0x1528,
sprite_miscellaneous6 = 0x1534,
sprite_miscellaneous7 = 0x1540,
sprite_miscellaneous8 = 0x154c,
sprite_miscellaneous9 = 0x1558,
sprite_miscellaneous10 = 0x1564,
sprite_miscellaneous11 = 0x1570,
sprite_miscellaneous12 = 0x157c,
sprite_miscellaneous13 = 0x1594,
sprite_miscellaneous14 = 0x15ac,
sprite_miscellaneous15 = 0x1602,
sprite_miscellaneous16 = 0x160e,
sprite_miscellaneous17 = 0x1626,
sprite_miscellaneous18 = 0x163e,
sprite_miscellaneous19 = 0x187b,
sprite_underwater = 0x164a,
sprite_disable_cape = 0x1fe2,
sprite_1_tweaker = 0x1656,
sprite_2_tweaker = 0x1662,
sprite_3_tweaker = 0x166e,
sprite_4_tweaker = 0x167a,
sprite_5_tweaker = 0x1686,
sprite_6_tweaker = 0x190f,
sprite_tongue_wait = 0x14a3,
sprite_yoshi_squatting = 0x18af,
sprite_buoyancy = 0x190e,
toadies_relative_x = 0x0E38,
toadies_relative_y = 0x0E4A,
-- Extended sprites
extspr_number = 0x170b,
extspr_x_high = 0x1733,
extspr_x_low = 0x171f,
extspr_y_high = 0x1729,
extspr_y_low = 0x1715,
extspr_x_speed = 0x1747,
extspr_y_speed = 0x173d,
extspr_suby = 0x1751,
extspr_subx = 0x175b,
extspr_table = 0x1765,
extspr_table2 = 0x176f,
-- Cluster sprites
cluspr_flag = 0x18b8,
cluspr_number = 0x1892,
cluspr_x_high = 0x1e3e,
cluspr_x_low = 0x1e16,
cluspr_y_high = 0x1e2a,
cluspr_y_low = 0x1e02,
cluspr_timer = 0x0f9a,
cluspr_table_1 = 0x0f4a,
cluspr_table_2 = 0x0f72,
cluspr_table_3 = 0x0f86,
reappearing_boo_counter = 0x190a,
-- Minor extended sprites
minorspr_number = 0x17f0,
minorspr_x_high = 0x18ea,
minorspr_x_low = 0x1808,
minorspr_y_high = 0x1814,
minorspr_y_low = 0x17fc,
minorspr_xspeed = 0x182c,
minorspr_yspeed = 0x1820,
minorspr_x_sub = 0x1844,
minorspr_y_sub = 0x1838,
minorspr_timer = 0x1850,
-- Bounce sprites
bouncespr_number = 0x1699,
bouncespr_x_high = 0x16ad,
bouncespr_x_low = 0x16a5,
bouncespr_y_high = 0x16a9,
bouncespr_y_low = 0x16a1,
bouncespr_timer = 0x16c5,
bouncespr_last_id = 0x18cd,
turn_block_timer = 0x18ce,
-- Player
x = 0x0094,
y = 0x0096,
previous_x = 0x00d1,
previous_y = 0x00d3,
x_sub = 0x13da,
y_sub = 0x13dc,
x_speed = 0x007b,
x_subspeed = 0x007a,
y_speed = 0x007d,
direction = 0x0076,
is_ducking = 0x0073,
p_meter = 0x13e4,
take_off = 0x149f,
powerup = 0x0019,
cape_spin = 0x14a6,
cape_fall = 0x14a5,
cape_interaction = 0x13e8,
flight_animation = 0x1407,
diving_status = 0x1409,
player_animation_trigger = 0x0071,
climbing_status = 0x0074,
spinjump_flag = 0x140d,
player_blocked_status = 0x0077,
player_item = 0x0dc2, --hex
cape_x = 0x13e9,
cape_y = 0x13eb,
on_ground = 0x13ef,
on_ground_delay = 0x008d,
on_air = 0x0072,
can_jump_from_water = 0x13fa,
carrying_item = 0x148f,
mario_score = 0x0f34,
player_coin = 0x0dbf,
player_looking_up = 0x13de,
-- Yoshi
yoshi_riding_flag = 0x187a, -- #$00 = No, #$01 = Yes, #$02 = Yes, and turning around.
yoshi_tile_pos = 0x0d8c,
-- Timers
--pipe_entrance_timer = 0x0088,
end_level_timer = 0x1493,
--multicoin_block_timer = 0x186b,,
switch_timer = 0x0CEC, -- 2 bytes
-- Layers
layer2_x_nextframe = 0x1466,
layer2_y_nextframe = 0x1468,
}
for name, address in pairs(WRAM) do
address = address + 0x7e0000 -- Snes9x
end
local WRAM = WRAM
local SOLID_BLOCKS = { -- solid and one-way solid blocks, via tests
0x01, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0C, 0x0D, 0x0F,
0x10, 0x15, 0x1A, 0x1B, 0x1C ,
0x29, 0x2C, 0x2F,
0x33, 0x38, 0x39, 0x3E, 0x3F,
0x40, 0x41, 0x44, 0x45, 0x48, 0x49, 0x4B, 0x4C, 0x4E,
0x50, 0x53, 0x55, 0x57, 0x59, 0x5B, 0x5D, 0x5F,
0x66, 0x67, 0x6B, 0x6E,
0x79, 0x7D,
0x90, 0x95, 0x9A, 0x9D, 0x9F,
0xA0, 0xA1, 0xA2
}
local X_INTERACTION_POINTS = {center = 0x8, left_side = 0x2 + 1, left_foot = 0x3, right_side = 0xe - 1, right_foot = 0xd}
local Y_INTERACTION_POINTS = {
{head = 0x10, center = 0x18, shoulder = 0x16, side = 0x1f, foot = 0x20, sprite = 0x15},
{head = 0x08, center = 0x12, shoulder = 0x0f, side = 0x1f, foot = 0x20, sprite = 0x07}, -- this one, for now
{head = 0x13, center = 0x1d, shoulder = 0x19, side = 0x28, foot = 0x30, sprite = 0x19},
{head = 0x10, center = 0x1a, shoulder = 0x16, side = 0x28, foot = 0x30, sprite = 0x11}
}
local HITBOX_SPRITE = { -- sprites' hitbox against player and other sprites
[0x00] = { xoff = 2, yoff = 3, width = 12, height = 10, oscillation = true },
[0x01] = { xoff = 2, yoff = 3, width = 12, height = 21, oscillation = true },
[0x02] = { xoff = 16, yoff = -2, width = 16, height = 18, oscillation = true },
[0x03] = { xoff = 20, yoff = 8, width = 8, height = 8, oscillation = true },
[0x04] = { xoff = 0, yoff = -2, width = 48, height = 14, oscillation = true },
[0x05] = { xoff = 0, yoff = -2, width = 80, height = 14, oscillation = true },
[0x06] = { xoff = 1, yoff = 2, width = 14, height = 24, oscillation = true },
[0x07] = { xoff = 8, yoff = 8, width = 40, height = 48, oscillation = true },
[0x08] = { xoff = -8, yoff = -2, width = 32, height = 16, oscillation = true },
[0x09] = { xoff = -2, yoff = 8, width = 20, height = 30, oscillation = true },
[0x0a] = { xoff = 3, yoff = 7, width = 1, height = 2, oscillation = true },
[0x0b] = { xoff = 6, yoff = 6, width = 3, height = 3, oscillation = true },
[0x0c] = { xoff = 1, yoff = -2, width = 13, height = 22, oscillation = true },
[0x0d] = { xoff = 0, yoff = -4, width = 15, height = 16, oscillation = true },
[0x0e] = { xoff = 6, yoff = 6, width = 20, height = 20, oscillation = true },
[0x0f] = { xoff = 2, yoff = -2, width = 36, height = 18, oscillation = true },
[0x10] = { xoff = 0, yoff = -2, width = 15, height = 32, oscillation = true },
[0x11] = { xoff = -24, yoff = -24, width = 64, height = 64, oscillation = true },
[0x12] = { xoff = -4, yoff = 16, width = 8, height = 52, oscillation = true },
[0x13] = { xoff = -4, yoff = 16, width = 8, height = 116, oscillation = true },
[0x14] = { xoff = 4, yoff = 2, width = 24, height = 12, oscillation = true },
[0x15] = { xoff = 0, yoff = -2, width = 15, height = 14, oscillation = true },
[0x16] = { xoff = -4, yoff = -12, width = 24, height = 24, oscillation = true },
[0x17] = { xoff = 2, yoff = 8, width = 12, height = 69, oscillation = true },
[0x18] = { xoff = 2, yoff = 19, width = 12, height = 58, oscillation = true },
[0x19] = { xoff = 2, yoff = 35, width = 12, height = 42, oscillation = true },
[0x1a] = { xoff = 2, yoff = 51, width = 12, height = 26, oscillation = true },
[0x1b] = { xoff = 2, yoff = 67, width = 12, height = 10, oscillation = true },
[0x1c] = { xoff = 0, yoff = 10, width = 10, height = 48, oscillation = true },
[0x1d] = { xoff = 2, yoff = -3, width = 28, height = 27, oscillation = true },
[0x1e] = { xoff = 6, yoff = -8, width = 3, height = 32, oscillation = true }, -- default: { xoff = -32, yoff = -8, width = 48, height = 32, oscillation = true },
[0x1f] = { xoff = -16, yoff = -4, width = 48, height = 18, oscillation = true },
[0x20] = { xoff = -4, yoff = -24, width = 8, height = 24, oscillation = true },
[0x21] = { xoff = -4, yoff = 16, width = 8, height = 24, oscillation = true },
[0x22] = { xoff = 0, yoff = 0, width = 16, height = 16, oscillation = true },
[0x23] = { xoff = -8, yoff = -24, width = 32, height = 32, oscillation = true },
[0x24] = { xoff = -12, yoff = 32, width = 56, height = 56, oscillation = true },
[0x25] = { xoff = -14, yoff = 4, width = 60, height = 20, oscillation = true },
[0x26] = { xoff = 0, yoff = 88, width = 32, height = 8, oscillation = true },
[0x27] = { xoff = -4, yoff = -4, width = 24, height = 24, oscillation = true },
[0x28] = { xoff = -14, yoff = -24, width = 28, height = 40, oscillation = true },
[0x29] = { xoff = -16, yoff = -4, width = 32, height = 27, oscillation = true },
[0x2a] = { xoff = 2, yoff = -8, width = 12, height = 19, oscillation = true },
[0x2b] = { xoff = 0, yoff = 2, width = 16, height = 76, oscillation = true },
[0x2c] = { xoff = -8, yoff = -8, width = 16, height = 16, oscillation = true },
[0x2d] = { xoff = 4, yoff = 4, width = 8, height = 4, oscillation = true },
[0x2e] = { xoff = 2, yoff = -2, width = 28, height = 34, oscillation = true },
[0x2f] = { xoff = 2, yoff = -2, width = 28, height = 32, oscillation = true },
[0x30] = { xoff = 8, yoff = -14, width = 16, height = 28, oscillation = true },
[0x31] = { xoff = 0, yoff = -2, width = 48, height = 18, oscillation = true },
[0x32] = { xoff = 0, yoff = -2, width = 48, height = 18, oscillation = true },
[0x33] = { xoff = 0, yoff = -2, width = 64, height = 18, oscillation = true },
[0x34] = { xoff = -4, yoff = -4, width = 8, height = 8, oscillation = true },
[0x35] = { xoff = 3, yoff = 0, width = 18, height = 32, oscillation = true },
[0x36] = { xoff = 8, yoff = 8, width = 52, height = 46, oscillation = true },
[0x37] = { xoff = 0, yoff = -8, width = 15, height = 20, oscillation = true },
[0x38] = { xoff = 8, yoff = 16, width = 32, height = 40, oscillation = true },
[0x39] = { xoff = 4, yoff = 3, width = 8, height = 10, oscillation = true },
[0x3a] = { xoff = -8, yoff = 16, width = 32, height = 16, oscillation = true },
[0x3b] = { xoff = 0, yoff = 0, width = 16, height = 13, oscillation = true },
[0x3c] = { xoff = 12, yoff = 10, width = 3, height = 6, oscillation = true },
[0x3d] = { xoff = 12, yoff = 21, width = 3, height = 20, oscillation = true },
[0x3e] = { xoff = 16, yoff = 18, width = 254, height = 16, oscillation = true },
[0x3f] = { xoff = 8, yoff = 8, width = 8, height = 24, oscillation = true }
}
local OBJ_CLIPPING_SPRITE = { -- sprites' interaction points against objects
[0x0] = {xright = 14, xleft = 2, xdown = 8, xup = 8, yright = 8, yleft = 8, ydown = 16, yup = 2},
[0x1] = {xright = 14, xleft = 2, xdown = 7, xup = 7, yright = 18, yleft = 18, ydown = 32, yup = 2},
[0x2] = {xright = 7, xleft = 7, xdown = 7, xup = 7, yright = 7, yleft = 7, ydown = 7, yup = 7},
[0x3] = {xright = 14, xleft = 2, xdown = 8, xup = 8, yright = 16, yleft = 16, ydown = 32, yup = 11},
[0x4] = {xright = 16, xleft = 0, xdown = 8, xup = 8, yright = 18, yleft = 18, ydown = 32, yup = 2},
[0x5] = {xright = 13, xleft = 2, xdown = 8, xup = 8, yright = 24, yleft = 24, ydown = 32, yup = 16},
[0x6] = {xright = 7, xleft = 0, xdown = 4, xup = 4, yright = 4, yleft = 4, ydown = 8, yup = 0},
[0x7] = {xright = 31, xleft = 1, xdown = 16, xup = 16, yright = 16, yleft = 16, ydown = 31, yup = 1},
[0x8] = {xright = 15, xleft = 0, xdown = 8, xup = 8, yright = 8, yleft = 8, ydown = 15, yup = 0},
[0x9] = {xright = 16, xleft = 0, xdown = 8, xup = 8, yright = 8, yleft = 8, ydown = 16, yup = 0},
[0xa] = {xright = 13, xleft = 2, xdown = 8, xup = 8, yright = 72, yleft = 72, ydown = 80, yup = 66},
[0xb] = {xright = 14, xleft = 2, xdown = 8, xup = 8, yright = 4, yleft = 4, ydown = 8, yup = 0},
[0xc] = {xright = 13, xleft = 2, xdown = 8, xup = 8, yright = 0, yleft = 0, ydown = 0, yup = 0},
[0xd] = {xright = 16, xleft = 0, xdown = 8, xup = 8, yright = 8, yleft = 8, ydown = 16, yup = 0},
[0xe] = {xright = 31, xleft = 0, xdown = 16, xup = 16, yright = 8, yleft = 8, ydown = 16, yup = 0},
[0xf] = {xright = 8, xleft = 8, xdown = 8, xup = 16, yright = 4, yleft = 1, ydown = 2, yup = 4}
}
local HITBOX_EXTENDED_SPRITE = { -- extended sprites' hitbox
-- To fill the slots...
--[0] ={ xoff = 3, yoff = 3, width = 64, height = 64}, -- Free slot
[0x01] ={ xoff = 3, yoff = 3, width = 0, height = 0}, -- Puff of smoke with various objects
[0x0e] ={ xoff = 3, yoff = 3, width = 0, height = 0}, -- Wiggler's flower
[0x0f] ={ xoff = 3, yoff = 3, width = 0, height = 0}, -- Trail of smoke
[0x10] ={ xoff = 3, yoff = 3, width = 0, height = 0}, -- Spinjump stars
[0x12] ={ xoff = 3, yoff = 3, width = 0, height = 0}, -- Water bubble
-- extracted from ROM:
[0x02] = { xoff = 3, yoff = 3, width = 1, height = 1, color_line = COLOUR.fireball }, -- Reznor fireball
[0x03] = { xoff = 3, yoff = 3, width = 1, height = 1, color_line = COLOUR.fireball}, -- Flame left by hopping flame
[0x04] = { xoff = 4, yoff = 4, width = 8, height = 8}, -- Hammer
[0x05] = { xoff = 3, yoff = 3, width = 1, height = 1, color_line = COLOUR.fireball }, -- Player fireball
[0x06] = { xoff = 4, yoff = 4, width = 8, height = 8}, -- Bone from Dry Bones
[0x07] = { xoff = 0, yoff = 0, width = 0, height = 0}, -- Lava splash
[0x08] = { xoff = 0, yoff = 0, width = 0, height = 0}, -- Torpedo Ted shooter's arm
[0x09] = { xoff = 0, yoff = 0, width = 15, height = 15}, -- Unknown flickering object
[0x0a] = { xoff = 4, yoff = 2, width = 8, height = 12}, -- Coin from coin cloud game
[0x0b] = { xoff = 3, yoff = 3, width = 1, height = 1, color_line = COLOUR.fireball }, -- Piranha Plant fireball
[0x0c] = { xoff = 3, yoff = 3, width = 1, height = 1, color_line = COLOUR.fireball }, -- Lava Lotus's fiery objects
[0x0d] = { xoff = 3, yoff = 3, width = 1, height = 1, color_line = COLOUR.baseball }, -- Baseball
-- got experimentally:
[0x11] = { xoff = -0x1, yoff = -0x4, width = 11, height = 19}, -- Yoshi fireballs
}
-- Creates a set from a list
local function make_set(list)
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end
-- from sprite number, returns oscillation flag
-- A sprite must be here iff it processes interaction with player every frame AND this bit is not working in the sprite_4_tweaker WRAM(0x167a)
local OSCILLATION_SPRITES = make_set{0x0e, 0x21, 0x29, 0x35, 0x54, 0x74, 0x75, 0x76, 0x77, 0x78, 0x81, 0x83, 0x87}
-- Sprites that have a custom hitbox drawing
local ABNORMAL_HITBOX_SPRITES = make_set{0x62, 0x63, 0x6b, 0x6c}
-- Sprites whose clipping interaction points usually matter
local GOOD_SPRITES_CLIPPING = make_set{
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xf, 0x10, 0x11, 0x13, 0x14, 0x18,
0x1b, 0x1d, 0x1f, 0x20, 0x26, 0x27, 0x29, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
0x32, 0x34, 0x35, 0x3d, 0x3e, 0x3f, 0x40, 0x46, 0x47, 0x48, 0x4d, 0x4e,
0x51, 0x53, 0x6e, 0x6f, 0x70, 0x80, 0x81, 0x86,
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa1, 0xa2, 0xa5, 0xa6, 0xa7, 0xab, 0xb2,
0xb4, 0xbb, 0xbc, 0xbd, 0xbf, 0xc3, 0xda, 0xdb, 0xdc, 0xdd, 0xdf
}
--#############################################################################
-- SCRIPT UTILITIES:
-- Variables used in various functions
local Cheat = {} -- family of cheat functions and variables
local Previous = {}
local User_input = INPUT_KEYNAMES -- Snes9x
local Tiletable = {}
local Joypad = {}
local Layer1_tiles = {}
local Layer2_tiles = {}
local Is_lagged = nil
local Options_menu = {show_menu = false, current_tab = "Show/hide options"}
local Filter_opacity, Filter_color = 0, "#000000ff" -- Snes9x specifc / unlisted color
local Mario_boost_indicator = nil
local Show_player_point_position = false
local Sprites_info = {} -- keeps track of useful sprite info that might be used outside the main sprite function
local Sprite_hitbox = {} -- keeps track of what sprite slots must display the hitbox
local Memory = {} -- family of memory edit functions and variables
-- Initialization of some tables
for i = 0, SMW2.sprite_max -1 do
Sprites_info[i] = {}
end
for key = 0, SMW2.sprite_max - 1 do
Sprite_hitbox[key] = {}
for number = 0, 0xff do
Sprite_hitbox[key][number] = {["sprite"] = true, ["block"] = GOOD_SPRITES_CLIPPING[number]}
end
end
-- Sum of the digits of a integer
local function sum_digits(number)
local sum = 0
while number > 0 do
sum = sum + number%10
number = floor(number*0.1)
end
return sum
end
-- Returns the exact chosen digit of a number from the left to the right, in a given base
-- E.g.: read_digit(654321, 2, 10) -> 5; read_digit(0x4B7A, 3, 16) -> 7
local function read_digit(number, digit, base)
--assert(type(number) == "number" and number >= 0 and number%1 == 0, "Enter an integer number > 0")
--assert(type(digit) == "number" and digit > 0 and digit%1 == 0, "Enter an integer digit > 0")
--assert(type(base) == "number" and base > 1 and base%1 == 0, "Enter an integer base > 1")
local copy = number
local digits_total = 0
while copy >= 1 do
copy = math.floor(copy/base)
digits_total = digits_total + 1