-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThe-Flintstones-Utils-Snes9x.lua
3444 lines (2810 loc) · 147 KB
/
The-Flintstones-Utils-Snes9x.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
-----------------------------------------------------------------------------------
-- The Flintstones (U) Utility Script for Snes9x-rr
-- http://tasvideos.org/GameResources/SNES/Flintstones.html
--
-- Author: BrunoValads
-- Git repository: https://github.com/brunovalads/the-flintstones-snes
--
-- 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 = "The Flintstones 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,
display_interaction_points = true,
display_club_hitbox = true,
display_sprite_info = true,
display_sprite_hitbox = true,
display_extended_sprite_info = true,
display_extended_sprite_hitbox = true,
display_level_info = true,
display_level_help = true,
display_counters = true,
display_stone_trajectory = true,
display_controller_input = true,
draw_tiles_with_click = true,
-- Some extra/debug info
display_debug_info = true, -- 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_extended_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},
misc_counter,
display_mouse_coordinates = true,
-- Passwords and auto pilot cheats
stage_skip = true,
invincibility = true,
auto_pilot = true,
-- 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, [25] = false, [26] = false, [27] = false,
[28] = false, [29] = false, [30] = false, [31] = false, [32] = false, [33] = false}, -- slots 30~33 are for the reserved sprites
-- 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",
-- Sprites
sprites = {
"#80ffff", -- cyan
"#a0a0ff", -- blue
"#ff6060", -- red
"#ff80ff", -- magenta
"#ffa100", -- orange
"#ffff80", -- yellow
"#40ff40" -- green
},
extsprites = {
"#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)
},
sprites_bg = "#00ff00",
-- Hitbox and related text
Fred = "#ff6600",
Fred_bg = "#ff660055",
interaction = "#ffffffff",
interaction_bg = "#00000020",
interaction_nohitbox = "#000000a0",
interaction_nohitbox_bg = "#00000070",
detection_bg = "#40002030",
-- Tiles
block = "#ffffffff", --"#00008bff",
blank_tile = "#ffffff70",
block_bg = "#22cc88a0"
}
-- Font settings
local SNES9X_FONT_HEIGHT = 8
local SNES9X_FONT_WIDTH = 4
-- GD images dumps (encoded)
local GD_IMAGES_DUMPS = {}
GD_IMAGES_DUMPS.stone_animation = {}
GD_IMAGES_DUMPS.stone_animation[1] = {255, 254, 0, 9, 0, 9, 1, 255, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 148, 57, 24, 0, 82, 24, 0, 0, 148, 57, 24, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 82, 24, 0, 0, 198, 99, 33, 0, 198, 99, 33, 0, 239, 148, 99, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 82, 24, 0, 0, 0, 0, 0, 0, 198, 99, 33, 0, 239, 148, 99, 0, 239, 148, 99, 0, 82, 24, 0, 127, 255, 255, 255, 127, 255, 255, 255, 0, 148, 57, 24, 0, 82, 24, 0, 0, 0, 0, 0, 0, 148, 57, 24, 0, 82, 24, 0, 0, 239, 148, 99, 0, 239, 148, 99, 127, 255, 255, 255, 0, 82, 24, 0, 0, 82, 24, 0, 0, 239, 148, 99, 0, 198, 99, 33, 0, 239, 148, 99, 0, 0, 0, 0, 0, 82, 24, 0, 0, 239, 148, 99, 0, 239, 148, 99, 127, 255, 255, 255, 0, 82, 24, 0, 0, 0, 0, 0, 0, 239, 148, 99, 0, 239, 148, 99, 0, 148, 57, 24, 0, 148, 57, 24, 0, 198, 99, 33, 0, 198, 99, 33, 127, 255, 255, 255, 127, 255, 255, 255, 0, 148, 57, 24, 0, 239, 148, 99, 0, 148, 57, 24, 0, 148, 57, 24, 0, 198, 99, 33, 0, 198, 99, 33, 0, 198, 99, 33, 127, 255, 255, 255, 127, 255, 255, 255, 0, 148, 57, 24, 0, 148, 57, 24, 0, 148, 57, 24, 0, 198, 99, 33, 0, 198, 99, 33, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 82, 24, 0, 0, 198, 99, 33, 0, 198, 99, 33, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255}
GD_IMAGES_DUMPS.stone_animation[2] = {255, 254, 0, 8, 0, 8, 1, 255, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 82, 24, 0, 0, 82, 24, 0, 0, 148, 57, 24, 0, 0, 0, 0, 0, 82, 24, 0, 127, 255, 255, 255, 0, 82, 24, 0, 0, 82, 24, 0, 0, 0, 0, 0, 0, 198, 99, 33, 0, 198, 99, 33, 0, 198, 99, 33, 0, 82, 24, 0, 127, 255, 255, 255, 0, 148, 57, 24, 0, 148, 57, 24, 0, 239, 148, 99, 0, 198, 99, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, 24, 0, 127, 255, 255, 255, 0, 82, 24, 0, 0, 239, 148, 99, 0, 148, 57, 24, 0, 239, 148, 99, 0, 82, 24, 0, 0, 148, 57, 24, 0, 198, 99, 33, 127, 255, 255, 255, 0, 198, 99, 33, 0, 239, 148, 99, 0, 148, 57, 24, 0, 0, 0, 0, 0, 82, 24, 0, 0, 239, 148, 99, 0, 148, 57, 24, 0, 82, 24, 0, 0, 198, 99, 33, 0, 0, 0, 0, 0, 148, 57, 24, 0, 82, 24, 0, 0, 239, 148, 99, 0, 239, 148, 99, 0, 148, 57, 24, 0, 148, 57, 24, 127, 255, 255, 255, 0, 198, 99, 33, 0, 148, 57, 24, 0, 148, 57, 24, 0, 82, 24, 0, 0, 82, 24, 0, 0, 148, 57, 24, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 198, 99, 33, 0, 239, 148, 99, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255}
GD_IMAGES_DUMPS.stone_animation[3] = {255, 254, 0, 9, 0, 9, 1, 255, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 198, 99, 33, 0, 198, 99, 33, 0, 82, 24, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 198, 99, 33, 0, 198, 99, 33, 0, 82, 24, 0, 0, 148, 57, 24, 0, 148, 57, 24, 127, 255, 255, 255, 127, 255, 255, 255, 0, 198, 99, 33, 0, 198, 99, 33, 0, 198, 99, 33, 0, 148, 57, 24, 0, 239, 148, 99, 0, 239, 148, 99, 0, 148, 57, 24, 127, 255, 255, 255, 127, 255, 255, 255, 0, 198, 99, 33, 0, 198, 99, 33, 0, 148, 57, 24, 0, 148, 57, 24, 0, 148, 57, 24, 0, 239, 148, 99, 0, 0, 0, 0, 0, 82, 24, 0, 127, 255, 255, 255, 0, 239, 148, 99, 0, 148, 57, 24, 0, 198, 99, 33, 0, 198, 99, 33, 0, 148, 57, 24, 0, 82, 24, 0, 0, 198, 99, 33, 0, 198, 99, 33, 0, 82, 24, 0, 127, 255, 255, 255, 0, 239, 148, 99, 0, 239, 148, 99, 0, 82, 24, 0, 0, 82, 24, 0, 0, 0, 0, 0, 0, 82, 24, 0, 0, 148, 57, 24, 127, 255, 255, 255, 127, 255, 255, 255, 0, 82, 24, 0, 0, 239, 148, 99, 0, 239, 148, 99, 0, 148, 57, 24, 0, 0, 0, 0, 0, 82, 24, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 239, 148, 99, 0, 198, 99, 33, 0, 148, 57, 24, 0, 82, 24, 0, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 148, 57, 24, 0, 82, 24, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255}
GD_IMAGES_DUMPS.stone_animation[4] = {255, 254, 0, 8, 0, 8, 1, 255, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 239, 148, 99, 0, 239, 148, 99, 0, 198, 99, 33, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 148, 57, 24, 0, 82, 24, 0, 0, 82, 24, 0, 0, 148, 57, 24, 0, 148, 57, 24, 0, 198, 99, 33, 127, 255, 255, 255, 0, 148, 57, 24, 0, 148, 57, 24, 0, 239, 148, 99, 0, 198, 99, 33, 0, 82, 24, 0, 0, 148, 57, 24, 0, 0, 0, 0, 0, 198, 99, 33, 0, 148, 57, 24, 0, 198, 99, 33, 0, 198, 99, 33, 0, 239, 148, 99, 0, 239, 148, 99, 0, 239, 148, 99, 0, 82, 24, 0, 0, 148, 57, 24, 127, 255, 255, 255, 0, 198, 99, 33, 0, 148, 57, 24, 0, 148, 57, 24, 0, 239, 148, 99, 0, 148, 57, 24, 0, 239, 148, 99, 0, 82, 24, 0, 127, 255, 255, 255, 0, 82, 24, 0, 0, 0, 0, 0, 0, 82, 24, 0, 0, 198, 99, 33, 0, 239, 148, 99, 0, 148, 57, 24, 0, 148, 57, 24, 127, 255, 255, 255, 0, 82, 24, 0, 0, 198, 99, 33, 0, 239, 148, 99, 0, 198, 99, 33, 0, 0, 0, 0, 0, 82, 24, 0, 0, 82, 24, 0, 127, 255, 255, 255, 0, 82, 24, 0, 0, 0, 0, 0, 0, 198, 99, 33, 0, 82, 24, 0, 0, 82, 24, 0, 127, 255, 255, 255, 127, 255, 255, 255}
GD_IMAGES_DUMPS.stone_animation[5] = {255, 254, 0, 9, 0, 9, 1, 255, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 82, 24, 0, 0, 148, 57, 24, 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, 148, 57, 24, 0, 148, 57, 24, 0, 148, 57, 24, 0, 239, 148, 99, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 82, 24, 0, 0, 82, 24, 0, 0, 148, 57, 24, 0, 239, 148, 99, 0, 239, 148, 99, 0, 239, 148, 99, 0, 239, 148, 99, 0, 239, 148, 99, 127, 255, 255, 255, 0, 82, 24, 0, 0, 0, 0, 0, 0, 148, 57, 24, 0, 148, 57, 24, 0, 82, 24, 0, 0, 198, 99, 33, 0, 239, 148, 99, 0, 239, 148, 99, 0, 82, 24, 0, 0, 148, 57, 24, 0, 198, 99, 33, 0, 0, 0, 0, 0, 239, 148, 99, 0, 0, 0, 0, 0, 148, 57, 24, 0, 198, 99, 33, 0, 198, 99, 33, 0, 82, 24, 0, 0, 148, 57, 24, 0, 239, 148, 99, 0, 198, 99, 33, 0, 148, 57, 24, 0, 239, 148, 99, 0, 148, 57, 24, 0, 198, 99, 33, 0, 198, 99, 33, 127, 255, 255, 255, 0, 82, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 239, 148, 99, 0, 148, 57, 24, 0, 148, 57, 24, 0, 0, 0, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 82, 24, 0, 0, 148, 57, 24, 0, 148, 57, 24, 0, 82, 24, 0, 0, 82, 24, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 82, 24, 0, 0, 82, 24, 0, 0, 82, 24, 0, 0, 198, 99, 33, 127, 255, 255, 255, 127, 255, 255, 255}
GD_IMAGES_DUMPS.stone_animation[6] = {255, 254, 0, 8, 0, 8, 1, 255, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 148, 57, 24, 0, 148, 57, 24, 0, 82, 24, 0, 0, 82, 24, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 198, 99, 33, 0, 198, 99, 33, 0, 198, 99, 33, 0, 0, 0, 0, 0, 82, 24, 0, 127, 255, 255, 255, 0, 148, 57, 24, 0, 82, 24, 0, 0, 198, 99, 33, 0, 0, 0, 0, 0, 148, 57, 24, 0, 148, 57, 24, 0, 198, 99, 33, 0, 82, 24, 0, 0, 148, 57, 24, 0, 148, 57, 24, 0, 198, 99, 33, 0, 239, 148, 99, 0, 82, 24, 0, 0, 239, 148, 99, 0, 198, 99, 33, 0, 82, 24, 0, 0, 82, 24, 0, 0, 239, 148, 99, 0, 239, 148, 99, 0, 239, 148, 99, 0, 198, 99, 33, 0, 239, 148, 99, 0, 239, 148, 99, 127, 255, 255, 255, 0, 82, 24, 0, 0, 148, 57, 24, 0, 239, 148, 99, 0, 148, 57, 24, 0, 198, 99, 33, 0, 198, 99, 33, 0, 82, 24, 0, 127, 255, 255, 255, 0, 198, 99, 33, 0, 239, 148, 99, 0, 198, 99, 33, 0, 148, 57, 24, 0, 82, 24, 0, 0, 82, 24, 0, 0, 239, 148, 99, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 198, 99, 33, 0, 198, 99, 33, 0, 239, 148, 99, 0, 239, 148, 99, 127, 255, 255, 255, 127, 255, 255, 255}
GD_IMAGES_DUMPS.stone_animation[7] = {255, 254, 0, 8, 0, 8, 1, 255, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 82, 24, 0, 0, 82, 24, 0, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 198, 99, 33, 0, 148, 57, 24, 0, 148, 57, 24, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 148, 57, 24, 0, 239, 148, 99, 0, 239, 148, 99, 0, 0, 0, 0, 0, 239, 148, 99, 0, 239, 148, 99, 0, 82, 24, 0, 127, 255, 255, 255, 0, 239, 148, 99, 0, 148, 57, 24, 0, 148, 57, 24, 0, 0, 0, 0, 0, 198, 99, 33, 0, 82, 24, 0, 0, 0, 0, 0, 0, 198, 99, 33, 0, 239, 148, 99, 0, 0, 0, 0, 0, 198, 99, 33, 0, 148, 57, 24, 0, 82, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 198, 99, 33, 0, 198, 99, 33, 0, 82, 24, 0, 0, 198, 99, 33, 0, 198, 99, 33, 0, 239, 148, 99, 0, 82, 24, 0, 127, 255, 255, 255, 0, 198, 99, 33, 0, 239, 148, 99, 0, 82, 24, 0, 0, 198, 99, 33, 0, 239, 148, 99, 0, 198, 99, 33, 0, 198, 99, 33, 127, 255, 255, 255, 127, 255, 255, 255, 127, 255, 255, 255, 0, 239, 148, 99, 0, 82, 24, 0, 0, 239, 148, 99, 0, 198, 99, 33, 0, 82, 24, 0, 127, 255, 255, 255}
-- 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 for screen coordinates <-> object position conversion
-- 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
}
-- Keyboard/mouse input tables (from gocha's)
local dev_press, dev_down, dev_up, dev_prev = input.get(), {}, {}, {}
local dev_presstime = {
xmouse=0, ymouse=0, leftclick=0, rightclick=0, middleclick=0,
shift=0, control=0, alt=0, capslock=0, numlock=0, scrolllock=0,
["0"]=0, ["1"]=0, ["2"]=0, ["3"]=0, ["4"]=0, ["5"]=0, ["6"]=0, ["7"]=0, ["8"]=0, ["9"]=0,
A=0, B=0, C=0, D=0, E=0, F=0, G=0, H=0, I=0, J=0, K=0, L=0, M=0, N=0, O=0, P=0, Q=0, R=0, S=0, T=0, U=0, V=0, W=0, X=0, Y=0, Z=0,
F1=0, F2=0, F3=0, F4=0, F5=0, F6=0, F7=0, F8=0, F9=0, F10=0, F11=0, F12=0,
F13=0, F14=0, F15=0, F16=0, F17=0, F18=0, F19=0, F20=0, F21=0, F22=0, F23=0, F24=0,
backspace=0, tab=0, enter=0, pause=0, escape=0, space=0,
pageup=0, pagedown=0, ["end"]=0, home=0, insert=0, delete=0,
left=0, up=0, right=0, down=0,
numpad0=0, numpad1=0, numpad2=0, numpad3=0, numpad4=0, numpad5=0, numpad6=0, numpad7=0, numpad8=0, numpad9=0,
["numpad*"]=0, ["numpad+"]=0, ["numpad-"]=0, ["numpad."]=0, ["numpad/"]=0,
tilde=0, plus=0, minus=0, leftbracket=0, rightbracket=0,
semicolon=0, quote=0, comma=0, period=0, slash=0, backslash=0
}
-- 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
-- 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.stone_animation = {}
for k = 1, 7 do
IMAGES.stone_animation[k] = string.char(unpack(GD_IMAGES_DUMPS.stone_animation[k]))
end
-- 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
FLINT = {
game_mode_level = 0xB23B,
sprite_max = 29,
extended_sprite_max = 4
}
WRAM = {
-- General
game_mode = 0x0040, -- 2 bytes
level_index = 0x1D5B,
timer = 0x1D8D, -- 2 bytes
is_paused = 0x0636,
score = 0x1D75, -- 2 bytes
-- Camera
camera_x = 0x001C, -- 2 bytes
camera_y = 0x001E, -- 2 bytes
-- Fred
hitbox_corner1_x = 0x00D7, -- 2 bytes
hitbox_corner1_y = 0x00DB, -- 2 bytes
hitbox_corner2_x = 0x00D9, -- 2 bytes
hitbox_corner2_y = 0x00DD, -- 2 bytes
sprite_platforming_left_x = 0x00DF, -- 2 bytes
sprite_platforming_left_y = 0x00E3, -- 2 bytes
sprite_platforming_right_x = 0x00E1, -- 2 bytes
sprite_platforming_right_y = 0x00E5, -- 2 bytes
club_hitbox_corner1_x = 0x00E7, -- 2 bytes
club_hitbox_corner1_y = 0x00EB, -- 2 bytes
club_hitbox_corner2_x = 0x00E9, -- 2 bytes
club_hitbox_corner2_y = 0x00ED, -- 2 bytes
fred_loaded = 0x0944,
x = 0x0988, -- 2 bytes
y = 0x09CC, -- 2 bytes
x_sub = 0x0A11,
y_sub = 0x0A55,
direction = 0x0CB9,
x_speed = 0x0D85,
x_subspeed = 0x0D84,
y_speed = 0x0DC9,
y_subspeed = 0x0DC8,
on_ground = 0x0E94,
last_valid_x = 0x0FF0, -- 2 bytes
last_valid_y = 0x0FF2, -- 2 bytes
status = 0x0FF6,
is_smashing = 0x1000,
invincibility_timer = 0x1D51,
lives = 0x1D65,
health = 0x1D69,
stones = 0x1D6D,
bowling_balls = 0x1D71,
throw_power = 0x1DD5, -- 2 bytes (but only the first is used)
idle_timer = 0x1DD7, -- 2 bytes
-- Sprites
sprite_type = 0x0946,
sprite_x = 0x098A, -- 2 bytes
sprite_y = 0x09CE, -- 2 bytes
sprite_x_sub = 0x0A13,
sprite_y_sub = 0x0A57,
sprite_x_speed = 0x0D87,
sprite_x_subspeed = 0x0D86,
sprite_y_speed = 0x0DCB,
sprite_y_subspeed = 0x0DCA,
sprite_miscellaneous1 = 0x0ADE, -- 2 bytes
sprite_miscellaneous2 = 0x0B22, -- 2 bytes
sprite_miscellaneous3 = 0x0B66, -- 2 bytes
sprite_miscellaneous4 = 0x0BAA, -- 2 bytes
caveman_boss_animation = 0x0AC4,
caveman_boss_misc_5_high = 0x0BD5,
-- Extended sprites
extsprite_type = 0x0980,
extsprite_x = 0x09C4, -- 2 bytes
extsprite_y = 0x0A08, -- 2 bytes
extsprite_x_sub = 0x0A4D,
extsprite_y_sub = 0x0A91,
extsprite_x_speed = 0x0DC1,
extsprite_x_subspeed = 0x0DC0,
extsprite_y_speed = 0x0E05,
extsprite_y_subspeed = 0x0E04,
extsprite_miscellaneous1 = 0x0B18, -- 2 bytes
extsprite_miscellaneous2 = 0x0B5C, -- 2 bytes
extsprite_miscellaneous3 = 0x0BA0, -- 2 bytes
extsprite_miscellaneous4 = 0x0BE4, -- 2 bytes
-- Passwords
stage_skip = 0x0622,
invincibility = 0x0624,
-- Others
boss_hp = 0x1ED6,
lava_wave_x = 0x1DEB,
lava_wave_y = 0x1DED,
lava_flood_y_static = 0x1E0E,
lava_flood_y_oscillating = 0x1E10
}
for name, address in pairs(WRAM) do
address = address + 0x7e0000 -- Snes9x
end
local WRAM = WRAM
-- 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
--#############################################################################
-- 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 Update_screen = true
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 Show_player_point_position = false
local Sprites_info = {} -- keeps track of useful sprite info that might be used outside the main sprite function
local Memory = {} -- family of memory edit functions and variables
-- Initialization of some tables
for i = 0, 2*FLINT.sprite_max - 1 do
Sprites_info[i] = {}
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
end
if digit > digits_total then return false end
local result = math.floor(number/base^(digits_total - digit))
return result%base
end
-- Transform the binary representation of base into a string
-- For instance, if each bit of a number represents a char of base, then this function verifies what chars are on
local function decode_bits(data, base)
local result = {}
local i = 1
local size = base:len()
for ch in base:gmatch(".") do
if bit.test(data, size-i) then
result[i] = ch
else
result[i] = " "
end
i = i + 1
end
return table.concat(result)
end
function bit.test(value, bitnum) -- Snes9x
return bit.rshift(value, bitnum)%2 == 1
end
local function mouse_onregion(x1, y1, x2, y2)
-- Reads external mouse coordinates
local mouse_x = User_input.xmouse
local mouse_y = User_input.ymouse
-- From top-left to bottom-right
if x2 < x1 then
x1, x2 = x2, x1
end
if y2 < y1 then
y1, y2 = y2, y1
end
if mouse_x >= x1 and mouse_x <= x2 and mouse_y >= y1 and mouse_y <= y2 then
return true
else
return false
end
end
-- Register a function to be executed on key press or release
-- execution happens in the main loop
local Keys = {}
Keys.press = {}
Keys.release = {}
Keys.down, Keys.up, Keys.pressed, Keys.released = {}, {}, {}, {}
function Keys.registerkeypress(key, fn)
Keys.press[key] = fn
end
function Keys.registerkeyrelease(key, fn)
Keys.release[key] = fn
end
-- A cross sign with pos and size
gui.crosshair = gui.crosshair or function(x, y, size, color)
gui.line(x - size, y, x + size, y, color)
gui.line(x, y-size, x, y+size, color)
end
local Movie_active, Readonly, Framecount, Lagcount, Rerecords
local Lastframe_emulated, Starting_subframe_last_frame, Size_last_frame, Final_subframe_last_frame
local Nextframe, Starting_subframe_next_frame, Starting_subframe_next_frame, Final_subframe_next_frame
local function snes9x_status()
Movie_active = movie.active() -- Snes9x
Readonly = movie.playing() -- Snes9x
Framecount = movie.length()
Lagcount = emu.lagcount() -- Snes9x
Rerecords = movie.rerecordcount()
-- Last frame info
Lastframe_emulated = emu.framecount()
-- Next frame info (only relevant in readonly mode)
Nextframe = Lastframe_emulated + 1
end
-- draw a pixel given (x,y) with SNES' pixel sizes
local draw_pixel = gui.pixel
-- draws a line given (x,y) and (x',y') with given scale and SNES' pixel thickness (whose scale is 2) -- EDIT
local function draw_line(x1, y1, x2, y2, scale, color)
-- Draw from top-left to bottom-right
if x2 < x1 then
x1, x2 = x2, x1
end
if y2 < y1 then
y1, y2 = y2, y1
end
x1, y1, x2, y2 = scale*x1, scale*y1, scale*x2, scale*y2
gui.line(x1, y1, x2, y2, color)
end
-- draw an arrow given (x,y) and (x',y')
local function draw_arrow(x1, y1, x2, y2, color, head)
local angle = math.atan((y2-y1)/(x2-x1)) -- in radians
-- Arrow head
local head_size = head or 10
local angle1, angle2 = angle + math.pi/4, angle - math.pi/4 --0.785398163398, angle - 0.785398163398 -- 45° in radians
local delta_x1, delta_y1 = floor(head_size*math.cos(angle1)), floor(head_size*math.sin(angle1))
local delta_x2, delta_y2 = floor(head_size*math.cos(angle2)), floor(head_size*math.sin(angle2))
local head1_x1, head1_y1 = x2, y2
local head1_x2, head1_y2
local head2_x1, head2_y1 = x2, y2
local head2_x2, head2_y2
if x1 < x2 then -- 1st and 4th quadrant
head1_x2, head1_y2 = head1_x1 - delta_x1, head1_y1 - delta_y1
head2_x2, head2_y2 = head2_x1 - delta_x2, head2_y1 - delta_y2
elseif x1 == x2 then -- vertical arrow
head1_x2, head1_y2 = head1_x1 - delta_x1, head1_y1 - delta_y1
head2_x2, head2_y2 = head2_x1 - delta_x2, head2_y1 - delta_y2
else
head1_x2, head1_y2 = head1_x1 + delta_x1, head1_y1 + delta_y1
head2_x2, head2_y2 = head2_x1 + delta_x2, head2_y1 + delta_y2
end
-- Draw
gui.line(x1, y1, x2, y2, color)
gui.line(head1_x1, head1_y1, head1_x2, head1_y2, color)
gui.line(head2_x1, head2_y1, head2_x2, head2_y2, color)
end
-- draws a box given (x,y) and (x',y') with SNES' pixel sizes
local draw_box = function(x1, y1, x2, y2, line, fill)
gui.box(x1, y1, x2, y2, fill, line)
end
-- draws a rectangle given (x,y) and dimensions, with SNES' pixel sizes
local draw_rectangle = function(x, y, w, h, line, fill)
gui.box(x, y, x + w, y + h, fill, line)
end
-- Takes a position and dimensions of a rectangle and returns a new position if this rectangle has points outside the screen
local function put_on_screen(x, y, width, height)
local x_screen, y_screen
width = width or 0
height = height or 0
if x < - Border_left then
x_screen = - Border_left
elseif x > Buffer_width + Border_right - width then
x_screen = Buffer_width + Border_right - width
else
x_screen = x
end
if y < - Border_top then
y_screen = - Border_top
elseif y > Buffer_height + Border_bottom - height then
y_screen = Buffer_height + Border_bottom - height
else
y_screen = y
end
return x_screen, y_screen
end
-- returns the (x, y) position to start the text and its length:
-- number, number, number text_position(x, y, text, font_width, font_height[[[[, always_on_client], always_on_game], ref_x], ref_y])
-- x, y: the coordinates that the refereed point of the text must have
-- text: a string, don't make it bigger than the buffer area width and don't include escape characters
-- font_width, font_height: the sizes of the font
-- always_on_client, always_on_game: boolean
-- ref_x and ref_y: refer to the relative point of the text that must occupy the origin (x,y), from 0% to 100%
-- for instance, if you want to display the middle of the text in (x, y), then use 0.5, 0.5
local function text_position(x, y, text, font_width, font_height, always_on_client, always_on_game, ref_x, ref_y)
-- Reads external variables
local border_left = 0
local border_right = 0
local border_top = 0
local border_bottom = 0
local buffer_width = 256
local buffer_height = 224
-- text processing
local text_length = text and string.len(text)*font_width or font_width -- considering another objects, like bitmaps
-- actual position, relative to game area origin
x = (not ref_x and x) or (ref_x == 0 and x) or x - floor(text_length*ref_x)
y = (not ref_y and y) or (ref_y == 0 and y) or y - floor(font_height*ref_y)
-- adjustment needed if text is supposed to be on screen area
local x_end = x + text_length
local y_end = y + font_height
if always_on_game then
if x < 0 then x = 0 end
if y < 0 then y = 0 end
if x_end > buffer_width then x = buffer_width - text_length end
if y_end > buffer_height then y = buffer_height - font_height end
elseif always_on_client then
if x < -border_left then x = -border_left end
if y < -border_top then y = -border_top end
if x_end > buffer_width + border_right then x = buffer_width + border_right - text_length end
if y_end > buffer_height + border_bottom then y = buffer_height + border_bottom - font_height end
end
return x, y, text_length
end
-- Complex function for drawing, that uses text_position
local function draw_text(x, y, text, ...)
-- Reads external variables
local font_name = Font or false
local font_width = SNES9X_FONT_WIDTH
local font_height = SNES9X_FONT_HEIGHT
local bg_default_color = font_name and COLOUR.outline or COLOUR.background
local text_color, bg_color, always_on_client, always_on_game, ref_x, ref_y
local arg1, arg2, arg3, arg4, arg5, arg6 = ...
if not arg1 or arg1 == true then
text_color = COLOUR.text
bg_color = bg_default_color
always_on_client, always_on_game, ref_x, ref_y = arg1, arg2, arg3, arg4
elseif not arg2 or arg2 == true then
text_color = arg1
bg_color = bg_default_color
always_on_client, always_on_game, ref_x, ref_y = arg2, arg3, arg4, arg5
else
text_color, bg_color = arg1, arg2
always_on_client, always_on_game, ref_x, ref_y = arg3, arg4, arg5, arg6
end
local x_pos, y_pos, length = text_position(x, y, text, font_width, font_height,
always_on_client, always_on_game, ref_x, ref_y)
;
gui.opacity(Text_max_opacity * Text_opacity)
gui.text(x_pos, y_pos, text, text_color, bg_color)
gui.opacity(1.0) -- Snes9x
return x_pos + length, y_pos + font_height, length
end
local function alert_text(x, y, text, text_color, bg_color, always_on_game, ref_x, ref_y)
-- Reads external variables
local font_width = SNES9X_FONT_WIDTH
local font_height = SNES9X_FONT_HEIGHT
local x_pos, y_pos, text_length = text_position(x, y, text, font_width, font_height, false, always_on_game, ref_x, ref_y)
gui.opacity(Background_max_opacity * Bg_opacity)
draw_rectangle(x_pos, y_pos, text_length - 1, font_height - 1, bg_color, bg_color) -- Snes9x
gui.opacity(Text_max_opacity * Text_opacity)
gui.text(x_pos, y_pos, text, text_color, 0)
gui.opacity(1.0)
end
local function draw_over_text(x, y, value, base, color_base, color_value, color_bg, always_on_client, always_on_game, ref_x, ref_y)
value = decode_bits(value, base)
local x_end, y_end, length = draw_text(x, y, base, color_base, color_bg, always_on_client, always_on_game, ref_x, ref_y)
gui.opacity(Text_max_opacity * Text_opacity)
gui.text(x_end - length, y_end - SNES9X_FONT_HEIGHT, value, color_value or COLOUR.text)
gui.opacity(1.0)
return x_end, y_end, length
end
-- Returns frames-time conversion
local function frame_time(frame)
if not NTSC_FRAMERATE then error("NTSC_FRAMERATE undefined."); return end
local total_seconds = frame/NTSC_FRAMERATE
local hours = floor(total_seconds/3600)
local tmp = total_seconds - 3600*hours
local minutes = floor(tmp/60)
tmp = tmp - 60*minutes
local seconds = floor(tmp)
local miliseconds = 1000* (total_seconds%1)
if hours == 0 then hours = "" else hours = string.format("%d:", hours) end
local str = string.format("%s%.2d:%.2d.%03.0f", hours, minutes, seconds, miliseconds)
return str
end
-- Background opacity functions
local function increase_opacity()
if Text_max_opacity <= 0.9 then Text_max_opacity = Text_max_opacity + 0.1
else
if Background_max_opacity <= 0.9 then Background_max_opacity = Background_max_opacity + 0.1 end
end
end
local function decrease_opacity()
if Background_max_opacity >= 0.1 then Background_max_opacity = Background_max_opacity - 0.1
else
if Text_max_opacity >= 0.1 then Text_max_opacity = Text_max_opacity - 0.1 end
end
end
-- displays a button everytime in (x,y)
-- object can be a text or a dbitmap
-- if user clicks onto it, fn is executed once
local Script_buttons = {}
local function create_button(x, y, object, fn, extra_options)
local always_on_client, always_on_game, ref_x, ref_y, button_pressed
if extra_options then
always_on_client, always_on_game, ref_x, ref_y, button_pressed = extra_options.always_on_client, extra_options.always_on_game,
extra_options.ref_x, extra_options.ref_y, extra_options.button_pressed
end
local width, height
local object_type = type(object)
if object_type == "string" then
width, height = SNES9X_FONT_WIDTH, SNES9X_FONT_HEIGHT
x, y, width = text_position(x, y, object, width, height, always_on_client, always_on_game, ref_x, ref_y)
elseif object_type == "boolean" then
width, height = SNES9X_FONT_WIDTH, SNES9X_FONT_HEIGHT
x, y = text_position(x, y, nil, width, height, always_on_client, always_on_game, ref_x, ref_y)
else error"Type of buttton not supported yet"
end
-- draw the button
if button_pressed then
draw_rectangle(x, y, width, height, "white", "#d8d8d8ff") -- unlisted colours
else
draw_rectangle(x, y, width, height, "#606060ff", "#b0b0b0ff")
end
gui.line(x, y, x + width, y, button_pressed and "#606060ff" or "white")
gui.line(x, y, x, y + height, button_pressed and "#606060ff" or "white")
if object_type == "string" then
gui.text(x + 1, y + 1, object, COLOUR.button_text, 0)
elseif object_type == "boolean" then
draw_rectangle(x + 1, y + 1, width - 2, height - 2, "#00ff0080", "#00ff00c0")
end
-- updates the table of buttons
table.insert(Script_buttons, {x = x, y = y, width = width, height = height, object = object, action = fn})
end
function Options_menu.print_help() --TODO
print("\n")
print(" - - - TIPS - - - ")
print("MOUSE:")
print("Use the left click to draw blocks")