-
Notifications
You must be signed in to change notification settings - Fork 36
/
fbneo-training-mode.lua
3485 lines (3043 loc) · 122 KB
/
fbneo-training-mode.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
DISABLE_SCROLLING_INPUT = false
-- flip this when the script keeps crashing
-- replace the text after the '=' with:
-- true, do use it
-- false, don't use it
-- memory macros
wb = memory.writebyte
ww = memory.writeword
wdw = memory.writedword
rb = memory.readbyte
rw = memory.readword
rws = memory.readwordsigned
rdw = memory.readdword
if not memory.writeword_audio then -- writeword_audio is defined on fightcade, stub otherwise
memory.writeword_audio = function() end
print "memory.writeword_audio not defined"
end
-- watch replay mode (no health refill, etc..)
if not emu.isreplay then
REPLAY = false
else
REPLAY = emu.isreplay()
end
if REPLAY then
-- we don't want to write memory when watching a replay
wb = function() end
ww = function() end
wdw = function() end
-- this breaks throw hitboxes on some games
-- memory.writebyte = function() end
-- memory.writeword = function() end
-- memory.writedword = function() end
end
require "gd"
FBNEO_TRAINING_MODE_VERSION = "v0.22.10.28"
--- wait 3 frames to allow for emu.screenwidth() and emu.screenheight() to be obtained properly
emu.frameadvance()
emu.frameadvance()
emu.frameadvance()
local fc = emu.framecount()
local games = {
[""] = {}, -- null case
aliencha = {"aliencha", iconfile = "icons-capcom-32.png"},
aof = {"aof", iconfile = "icons-neogeo-32.png"},
aof2 = {"aof2", iconfile = "icons-neogeo-32.png"},
aof3 = {"aof3", iconfile = "icons-neogeo-32.png"},
asurabld = {"asurabld", iconfile = "icons-asurabus-32.png"},
asurabus = {"asurabus", iconfile = "icons-asurabus-32.png"},
avengrgs = {"avengrgs", iconfile = "icons-banpresto-32.png"},
breakrev = {"breakrev", "brkrevext", iconfile = "icons-neogeo-32.png"},
cyberbots = {"cybots", "cybotsam", hitboxes = "cps2-hitboxes", iconfile = "icons-cybots-32.png"},
dankuga = {"dankuga", iconfile= "icons-capcom-32.png"},
daraku = {"daraku", hitboxes = "daraku-hitboxes", iconfile= "icons-psikyo-32.png"},
dinorex = {"dinorex", iconfile = "icons-taito-32.png"},
dbz2 = {"dbz2", iconfile = "icons-banpresto-32.png"},
doubledr = {"doubledr", iconfile = "icons-neogeo-32.png"},
fatfury1 = {"fatfury1", iconfile = "icons-neogeo-32.png"},
fatfury2 = {"fatfury2", iconfile = "icons-neogeo-32.png"},
fatfury3 = {"fatfury3", iconfile = "icons-neogeo-32.png"},
fatfursp = {"fatfursp", iconfile = "icons-neogeo-32.png"},
galaxyfg = {"galaxyfg", iconfile = "icons-neogeo-32.png"},
garou = {"garou", iconfile = "icons-neogeo-32.png"},
gundamex = {"gundamex", iconfile = "icons-banpresto-32.png"},
gowcaizr = {"gowcaizr", iconfile = "icons-neogeo-32.png"},
hsf2 = {"hsf2", hitboxes = "sf2-hitboxes", iconfile = "icons-capcom-32.png"},
jchan2 = {"jchan2", hitboxes = "jchan2-hitboxes", iconfile = "icons-kaneko-32.png"},
jojos = {"jojoba", "jojoban", "jojobanr1", hitboxes = "hftf-hitboxes", iconfile = "icons-jojos-32.png"},
jojov = {"jojo", "jojon", hitboxes = "jojo-hitboxes", iconfile = "icons-jojos-32.png"},
kabukikl = {"kabukikl", iconfile = "icons-neogeo-32.png"},
karnovr = {"karnovr", hitboxes = "karnovr-hitboxes", iconfile = "icons-neogeo-32.png"},
kizuna = {"kizuna", iconfile = "icons-neogeo-32.png"},
kof94 = {"kof94", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof95 = {"kof95", "kof95sp", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof96 = {"kof96", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof97 = {"kof97", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof98 = {"kof98", "kof98cb", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof99 = {"kof99", "kof99ae", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof2000 = {"kof2000", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof2001 = {"kof2001", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof2002 = {"kof2002", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
kof2003 = {"kof2003", hitboxes = "kof2003-hitboxes", iconfile = "icons-neogeo-32.png"},
kf2k5uni = {"kf2k5uni", hitboxes = "kof-hitboxes", iconfile = "icons-neogeo-32.png"},
lastblad = {"lastblad", iconfile = "icons-neogeo-32.png"},
lb2 = {"lastbld2", iconfile = "icons-neogeo-32.png"},
matrim = {"matrim", iconfile = "icons-neogeo-32.png"},
martmast = {"martmast", iconfile = "icons-martmast-32.png"},
msh = {"msh", hitboxes = "marvel-hitboxes", iconfile = "icons-capcom-32.png"},
mshvsf = {"mshvsf", hitboxes = "marvel-hitboxes", iconfile = "icons-capcom-32.png"},
mvc = {"mvc", "mvsc", hitboxes = "marvel-hitboxes", iconfile = "icons-capcom-32.png"},
mwarr = {"mwarr", iconfile = "icons-mwarr-32.png"},
ninjamas = {"ninjamas", iconfile = "icons-neogeo-32.png"},
rabbit = {"rabbit", iconfile = "icons-banpresto-32.png"},
ragnagrd = {"ragnagrd", iconfile = "icons-neogeo-32.png"},
rbff1 = {"rbff1", iconfile = "icons-neogeo-32.png"},
rbff2 = {"rbff2", "rbff2h", iconfile = "icons-neogeo-32.png"},
rbffspec = {"rbffspec", iconfile = "icons-neogeo-32.png"},
redearth = {"redearth", hitboxes = "cps3-hitboxes", iconfile = "icons-capcom-32.png"},
ringdest = {"ringdest", iconfile = "icons-ringdest-32.png"},
rotd = {"rotd", hitboxes = "rotd-hitboxes", iconfile = "icons-neogeo-32.png"},
samsho = {"samsho", iconfile = "icons-neogeo-32.png"},
samsho2 = {"samsho2", iconfile = "icons-neogeo-32.png"},
samsho3 = {"samsho3", iconfile = "icons-neogeo-32.png"},
samsho4 = {"samsho4", iconfile = "icons-neogeo-32.png"},
samsho5 = {"samsho5", iconfile = "icons-neogeo-32.png"},
samsho5sp = {"samsh5sp", iconfile = "icons-neogeo-32.png"},
slammast = {"slammast", iconfile = "icons-slammast-32.png"},
sf = {"sf", iconfile = "icons-capcom-32.png"},
sf2 = {"sf2", hitboxes = "sf2-hitboxes", iconfile = "icons-capcom-32.png"},
sf2ce = {"sf2ce", "sf2hf", "sf2rb", hitboxes = "sf2-hitboxes", iconfile = "icons-capcom-32.png"},
sfa = {"sfa", hitboxes = "cps2-hitboxes", iconfile = "icons-capcom-32.png"},
sfa2 = {"sfa2", "sfa2u", hitboxes = "cps2-hitboxes", iconfile = "icons-capcom-32.png"},
sfa3 = {"sfa3", hitboxes = "cps2-hitboxes", iconfile = "icons-capcom-32.png"},
sfiii = {"sfiii", hitboxes = "cps3-hitboxes", iconfile = "icons-capcom-32.png"},
sfiii2 = {"sfiii2", hitboxes = "cps3-hitboxes", iconfile = "icons-capcom-32.png"},
sfiii3 = {"sfiii3", "sfiii3nr1", hitboxes = "cps3-hitboxes", iconfile = "icons-capcom-32.png"},
sgemf = {"sgemf", hitboxes = "cps2-hitboxes", iconfile = "icons-sgemf-32.png"},
ssf2xjr1 = {"ssf2xjr1", "ssf2tnl", hitboxes = "st-hitboxes", iconfile = "icons-capcom-32letter.png"},
svc = {"svc", "svcsplus", hitboxes = "svc-hitboxes", iconfile = "icons-neogeo-32.png"},
tkdensho = {"tkdensho", iconfile = "icons-banpresto-32.png"},
umk3 = {"umk3", iconfile = "icons-midway-32.png"},
vamp = {"vamp", "vampjr1", hitboxes = "cps2-hitboxes", iconfile = "icons-capcom-32.png"},
vhunt2 = {"vhunt2", hitboxes = "cps2-hitboxes", iconfile = "icons-capcom-32.png"},
vhuntjr2 = {"nwarr", "vhuntjr2", hitboxes = "cps2-hitboxes", iconfile = "icons-capcom-32.png"},
vsav = {"vsav", "vsavj", "vsavae", hitboxes = "cps2-hitboxes", iconfile = "icons-capcom-32.png"},
vsav2 = {"vsav2", hitboxes = "cps2-hitboxes", iconfile = "icons-capcom-32.png"},
wakuwak7 = {"wakuwak7", "wakuwak7bh", iconfile = "icons-neogeo-32.png"},
whp = {"whp", iconfile = "icons-neogeo-32.png"},
xmvsf = {"xmvsf", hitboxes = "marvel-hitboxes", iconfile = "icons-capcom-32.png"},
xmcota = {"xmcota", "xmcotabh", hitboxes = "marvel-hitboxes", iconfile = "icons-capcom-32.png"},
}
local usage = function()
print ("Beta for fbneo-training-script ("..FBNEO_TRAINING_MODE_VERSION..")")
if not REPLAY then
print "Replay with 1 coin press"
print "Record with 2 coin presses"
print "Swap inputs with 3 coin presses"
print "Open the menu with 4 coin presses or hold the button to open it"
print ""
print "Move around the menu with left/right"
print "Select a function with P1 Button 1"
print "Read function info with P1 Button 2"
print "Return to the previous menu with P1 Button 3"
end
end
-- locals
local defaultconfig = {
p1 = {
-- Health
refillhealthspeed = 10,
instantrefillhealth = false,
refillhealthenabled = true,
refillmeterspeed = 10,
instantrefillmeter = false,
refillmeterenabled = true,
},
p2 = {
-- Health
refillhealthspeed = 10,
instantrefillhealth = false,
refillhealthenabled = true,
refillmeterspeed = 10,
instantrefillmeter = false,
refillmeterenabled = true,
},
-- Combo GUI
hud = {
p1healthx = 10,
p1healthy = 10,
p1healthtextcolour = 0xFFFFFFFF,
p1healthenabled = false,
p2healthx = 180,
p2healthy = 10,
p2healthtextcolour = 0xFFFFFFFF,
p2healthenabled = false,
p1meterx = 10,
p1metery = 100,
p1metertextcolour = 0xFFFFFFFF,
p1meterenabled = false,
p2meterx = 180,
p2metery = 100,
p2metertextcolour = 0xFFFFFFFF,
p2meterenabled = false,
combotextx = 180,
combotexty = 42,
combotextcolour = 0xFFFF00FF,
combotextcolour2 = 0x00FF00FF,
damagetextcolour = 0x00FF00FF,
totaltextcolour = 0x00FF00FF,
comboenabled = false,
},
-- Interactive GUI
interactivegui = {
bg = 0xF0F0F0FF,
ol = 0x000000FF,
barcolour = "yellow",
boxxd = 8, -- divisor
boxxm = 7, -- multiplier
boxyd = 10, -- divisor
boxym = 9, -- multiplier
selectioncolour = 0xFF0000FF,
},
-- Input Settings
inputs = {
simplestate = {true,true},
simpleinputxoffset = {},
simpleinputyoffset = {},
kbstate = false,
kbinputxoffset = 0,
kbinputyoffset = 0,
iconsize = 10,
coinleniency = 10,
scrollingstate = {true, true},
framenumbersenabled = false,
scrollinginputxoffset = {},
scrollinginputyoffset = {},
},
recording = {
skiptostart = false,
skiptofinish = false,
},
hitbox = {
enabled = true,
},
}
local config = defaultconfig
local rom = emu.romname()
local interactiveguipages = {}
local configpath = "games/other/"..rom..".lua"
guiinputs = {
P1 = {previousinputs={}, coinframestart = 0, coinpresscount = 0, leftframecount = 0, rightframecount = 0, downframecount = 0, upframecount = 0,},
P2 = {previousinputs={}},
KB = {inputcount={}},
}
do -- file checking logic + global variables/tables
function fexists(s)
local fs = io.open(s,"r")
local res = fs~=nil
if (res) then
fs:close()
end
return res
end
----------------------------------------------
-- ROM NAME
----------------------------------------------
dirname = ""
for i, v in pairs(games) do
for _, k in ipairs(v) do
if (rom == k) then
dirname = i
configpath = "games/"..dirname.."/config.lua"
end
end
end
----------------------------------------------
-- CHECK IF ROM MEMORY FILE EXISTS
----------------------------------------------
nbuttons = 0 -- makes calcs easier to already have this
if fexists("games/"..dirname.."/"..dirname..".lua") then
dofile("games/"..dirname.."/"..dirname..".lua")
local i = 5
while (translationtable[i]:sub(1,6)=="button") do nbuttons = nbuttons+1 i=i+1 end
else
print("Memory addresses not found for "..rom)
end
-- check if the translationtable is valid, failsafe
if translationtable then
local player, input
for i,v in pairs(joypad.get()) do -- check every button
player = i:sub(1,2)
input = i:sub(4)
if player == "P1" then -- assume the same inputs for each player
if not translationtable[input] or not translationtable[translationtable[input]] then -- bad button found
print(input)
print "Translation table malformed"
nbuttons = 0
break
end
end
end
end
if nbuttons == 0 then
print("No buttons found for "..rom)
print "Attempting to make a translationtable from defaults"
-- try to make a translation table
-- modified from dammits input display script
local a = {"Weak Punch", "Medium Punch", "Heavy Punch", "Weak Kick", "Medium Kick", "Heavy Kick",
["Weak Punch"] = 1,
["Medium Punch"] = 2,
["Heavy Punch"] = 3,
["Weak Kick"] = 4,
["Medium Kick"] = 5,
["Heavy Kick"] = 6,
}
local a2 = {"Weak Punch", "Medium Punch", "Strong Punch", "Weak Kick", "Medium Kick", "Strong Kick",
["Weak Punch"] = 1,
["Medium Punch"] = 2,
["Strong Punch"] = 3,
["Weak Kick"] = 4,
["Medium Kick"] = 5,
["Strong Kick"] = 6,
}
local c = joypad.get()
local player, input
nbuttons = nil
for b=6,1,-1 do
for _,v in ipairs({"P1 Button "..b, "P1 Button "..string.char(b+64), "P1 Fire "..b, "P1 "..a[b], "P1 "..a2[b]}) do -- some common buttons
if c[v] ~= nil then
nbuttons = b
break
end
end
if nbuttons then break end
end
-- assume all games have cardinal directions
if nbuttons then
print("Found ".. nbuttons .. " buttons")
local tonum = function(val) -- works for digits and letters in the context of joypad inputs
if (tonumber(val:sub(#val))) then
return tonumber(val:sub(#val))
elseif string.byte(val:sub(#val))-64 <= 6 then -- F (6 buttons)
return string.byte(val:sub(#val))-64
elseif a[val] then
return a[val]
elseif a2[val] then
return a2[val]
else
return nil
end
end
translationtable = {"coin", "start", "select", "up", "down", "left", "right", "button1", "button2", "button3", "button4", "button5", "button6",
Coin = 1,
Start = 2,
Select = 3,
Up = 4,
Down = 5,
Left = 6,
Right = 7,
}
for i,v in pairs(c) do -- check buttons
player = i:sub(1,2)
input = i:sub(4)
if player == "P1" and translationtable[input]==nil then -- change translation table to not work with [1]
translationtable[input] = 7+assert(tonum(input), "Can't make a translation table") -- bind JUST attack buttons
elseif player == "P2" then
else -- stuff like dipswitches
translationtable[i] = 7+nbuttons+1 -- we dont care about any of these but need to make sure they're bound to something
end
end
local d = {nil, nil, "icons-taito-32.png", "icons-neogeo-32.png", nil, "icons-capcom-32.png"} -- iconfiles, 3,4,6 buttons
games[""].iconfile = d[nbuttons]
else
print "Can't make a translationtable"
nbuttons = 0
end
end
----------------------------------------------
-- CHECK IF TABLEIO IS PRESENT AND TRYING TO OPEN CONFIG FILE
----------------------------------------------
-- TRY TO USE CONFIG.LUA, THEN A GAME'S DEFAULT CONFIG, THEN THE GENERAL DEFAULT CONFIG
----------------------------------------------
if fexists("tableio.lua") then
dofile("tableio.lua")
if not gamedefaultconfig then -- comes from game luas
print "Game default config not found."
else
for i, v in pairs(gamedefaultconfig) do
if not config[i] then config[i]={} end
for j, k in pairs(v) do
config[i][j] = k
end
end
end
if fexists(configpath) then
config = table.load(configpath)
if not config then
print("Can't read config file found for "..dirname..", using default config.")
config = defaultconfig
else -- if the file is loaded, make sure the contents are at least superficially correct
local check = true
for i, v in pairs(defaultconfig) do
for j, k in pairs(v) do
if not config[i] or type(k) ~= type(config[i][j]) then
if not config[i] then
config[i] = defaultconfig[i]
else
config[i][j] = defaultconfig[i][j]
end
print("Error reading value "..i.."."..j.." from config file, using default.")
end
end
end
end
end
if dirname ~= nil then
if dirname=="" then assert(table.save(config,configpath)==nil, "Can't save config file")
else assert(table.save(config,configpath)==nil, "Can't save config file") end
end
else
print("Can't read/write")
end
----------------------------------------------
----------------------------------------------
-- VARIABLE TABLES
----------------------------------------------
availablefunctions = {}
checkAvailableFunctions = function() -- SETUP availablefunctions TABLE
-- Training mode functions
if Run then availablefunctions.run = true end
if playerOneInHitstun then availablefunctions.playeroneinhitstun = true end
if playerTwoInHitstun then availablefunctions.playertwoinhitstun = true end
if readPlayerOneHealth then availablefunctions.readplayeronehealth = true end
if writePlayerOneHealth and not REPLAY then availablefunctions.writeplayeronehealth = true end
if readPlayerTwoHealth then availablefunctions.readplayertwohealth = true end
if writePlayerTwoHealth and not REPLAY then availablefunctions.writeplayertwohealth = true end
if readPlayerOneMeter then availablefunctions.readplayeronemeter = true end
if writePlayerOneMeter and not REPLAY then availablefunctions.writeplayeronemeter = true end
if readPlayerTwoMeter then availablefunctions.readplayertwometer = true end
if writePlayerTwoMeter and not REPLAY then availablefunctions.writeplayertwometer = true end
if playerOneFacingLeft then availablefunctions.playeronefacingleft = true end
if playerTwoFacingLeft then availablefunctions.playertwofacingleft = true end
--
-- Hitbox functions
if hitboxesReg then availablefunctions.hitboxesreg = true end
if hitboxesRegAfter then availablefunctions.hitboxesregafter = true end
--
-- Inputs functions try to get these to load a global input table to avoid multiple joypad.get()'s?
if inputDisplayReg then availablefunctions.inputdisplayreg = true end
if scrollingInputReg then availablefunctions.scrollinginputreg = true end
if scrollingInputRegAfter then availablefunctions.scrollinginputregafter = true end
if scrollingInputClear then availablefunctions.scrollinginputclear = true end
if scrollingInputSetInput then availablefunctions.scrollinginputsetinput = true end
if scrollingInputSetSampleInput then availablefunctions.scrollinginputsetsampleinput = true end
--
-- Saving/Loading
if table.save then availablefunctions.tablesave = true end
if table.load then availablefunctions.tableload = true end
--
end
checkAvailableFunctions()
interactivegui = {
enabled = false,
inmenu = false,
page = 1, -- these should be numbers referencing interactiveguipages
selection = 1,
sw = emu.screenwidth(),
sh = emu.screenheight(),
-- CONFIGS
bgcolour = config.interactivegui.bg,
olcolour = config.interactivegui.ol,
barcolour = config.interactivegui.barcolour,
boxx = emu.screenwidth()/config.interactivegui.boxxd, -- proportions of the screen
boxy = emu.screenheight()/config.interactivegui.boxyd-10, -- keep out of range of the tooltips
boxx2 = config.interactivegui.boxxm*(emu.screenwidth()/config.interactivegui.boxxd),
boxy2 = config.interactivegui.boxym*(emu.screenheight()/config.interactivegui.boxyd)-10,
boxxlength = (config.interactivegui.boxxm-1)*(emu.screenwidth()/config.interactivegui.boxxd), -- commonly used calculations
boxylength = (config.interactivegui.boxym-1)*(emu.screenheight()/config.interactivegui.boxyd),
boxxmid = emu.screenwidth()/config.interactivegui.boxxd+(config.interactivegui.boxxm-1)*(emu.screenwidth()/config.interactivegui.boxxd)/2,
boxymid = emu.screenheight()/config.interactivegui.boxyd-10+(config.interactivegui.boxym-1)*(emu.screenheight()/config.interactivegui.boxyd)/2,
selectioncolour = config.interactivegui.selectioncolour,
movehud = {enabled = false, selected = false, selection = 1},
replayeditor = {inputs = {}},
}
modulevars = {
p1 = {
inhitstun = false,
health = 0,
previoushealth = 0,
meter = 0,
constants = {},
maxhealth = config.p1.maxhealth,
maxmeter = config.p1.maxmeter,
},
p2 = {
inhitstun = false,
health = 0,
meter = 0,
previoushealth = 0,
constants = {},
maxhealth = config.p2.maxhealth,
maxmeter = config.p2.maxmeter,
},
constants = {},
}
setAvailableConstants = function() -- SETUP modulevars CONSTANTS TABLES
if p1maxhealth then
modulevars.p1.constants.maxhealth = p1maxhealth
modulevars.p1.maxhealth = modulevars.p1.maxhealth or p1maxhealth
end
if p2maxhealth then
modulevars.p2.constants.maxhealth = p2maxhealth
modulevars.p2.maxhealth = modulevars.p2.maxhealth or p2maxhealth
end
if p1maxmeter then
modulevars.p1.constants.maxmeter = p1maxmeter
modulevars.p1.maxmeter = modulevars.p1.maxmeter or p1maxmeter
end
if p2maxmeter then
modulevars.p2.constants.maxmeter = p2maxmeter
modulevars.p2.maxmeter = modulevars.p2.maxmeter or p2maxmeter
end
if translationtable then modulevars.constants.translationtable = translationtable end
end
setAvailableConstants()
combovars = {
p1 = {
healthdiff = 0,
previousdamage = 0,
combo = 0,
previouscombo = 0,
displaycombo = 0,
comboDamage = 0,
refillhealth = 0,
refillmeter = 0,
-- CONFIGS
refillhealthspeed = config.p1.refillhealthspeed,
instantrefillhealth = config.p1.instantrefillhealth,
refillhealthenabled = config.p1.refillhealthenabled,
refillmeterspeed = config.p1.refillmeterspeed,
instantrefillmeter = config.p1.instantrefillmeter,
refillmeterenabled = config.p1.refillmeterenabled,
},
p2 = {
healthdiff = 0,
previousdamage = 0,
combo = 0,
previouscombo = 0,
displaycombo = 0,
comboDamage = 0,
refillhealth = 0,
refillmeter = 0,
-- CONFIGS
refillhealthspeed = config.p2.refillhealthspeed,
instantrefillhealth = config.p2.instantrefillhealth,
refillhealthenabled = config.p2.refillhealthenabled,
refillmeterspeed = config.p2.refillmeterspeed,
instantrefillmeter = config.p2.instantrefillmeter,
refillmeterenabled = config.p2.refillmeterenabled,
},
}
hud = {
-- CONFIGS
-- p1health
p1healthx = config.hud.p1healthx,
p1healthy = config.hud.p1healthy,
p1healthtextcolour = config.hud.p1healthtextcolour,
p1healthenabled = config.hud.p1healthenabled,
--p1meter
p1meterx = config.hud.p1meterx,
p1metery = config.hud.p1metery,
p1metertextcolour = config.hud.p1metertextcolour,
p1meterenabled = config.hud.p1meterenabled,
--p2health
p2healthx = config.hud.p2healthx,
p2healthy = config.hud.p2healthy,
p2healthtextcolour = config.hud.p2healthtextcolour,
p2healthenabled = config.hud.p2healthenabled,
--p2meter
p2meterx = config.hud.p2meterx,
p2metery = config.hud.p2metery,
p2metertextcolour = config.hud.p2healthtextcolour,
p2meterenabled = config.hud.p2meterenabled,
-- combos
combotextx = config.hud.combotextx,
combotexty = config.hud.combotexty,
combotextcolour = config.hud.combotextcolour,
combotextcolour2 = config.hud.combotextcolour2,
damagetextcolour = config.hud.damagetextcolour,
totaltextcolour = config.hud.totaltextcolour,
comboenabled = config.hud.comboenabled,
}
inputs = {
properties = {
simpleinput = {
simplestate = config.inputs.simplestate,
simpleinputxoffset = config.inputs.simpleinputxoffset,
simpleinputyoffset = config.inputs.simpleinputyoffset,
p1simpleinput = config.inputs.simplestate[1],
p2simpleinput = config.inputs.simplestate[2],
},
scrollinginput = {
iconsize = config.inputs.iconsize,
scrollingstate = config.inputs.scrollingstate,
frames = config.inputs.framenumbersenabled,
scrollinginputxoffset = config.inputs.scrollinginputxoffset,
scrollinginputyoffset = config.inputs.scrollinginputyoffset,
p1scrollinginput = config.inputs.scrollingstate[1],
p2scrollinginput = config.inputs.scrollingstate[2],
},
KB = {
kbstate = config.inputs.kbstate,
kbinputxoffset = config.inputs.kbinputxoffset,
kbinputyoffset = config.inputs.kbinputyoffset,
},
coinleniency = config.inputs.coinleniency,
enableinputswap = false,
enablehold = false,
p1hold = {},
p2hold = {},
},
hotkeys = {
hotkeyin = false,
funcs = {},
},
p1 = {},
p2 = {},
other = {},
setinputs = {},
}
hitboxes = {
enabled = config.hitbox.enabled,
prev = config.hitbox.enabled,
}
recording = {
{},
{},
{},
{},
{},
recordingslot = 1,
hitslot,
savestateslot,
blockslot,
editframe,
skiptostart = config.recording.skiptostart,
skiptofinish = config.recording.skiptofinish,
swapplayers = true,
replayP1 = false,
replayP2 = true,
maxstarttime = 0,
starttime = 0,
startcounter = 0,
}
----------------------------------------------
--
----------------------------------------------
----------------------------------------------
-- TRYING TO OPEN HITBOXES
----------------------------------------------
hitbox = games[dirname].hitboxes
if hitbox then
if fexists("hitboxes/"..hitbox..".lua") then
dofile("hitboxes/"..hitbox..".lua")
else
print("Hitbox file "..games[dirname].hitboxes.."not found for "..rom)
end
else
print("No associated hitbox file for "..rom)
end
----------------------------------------------
-- TRYING TO DISPLAY INPUTS
----------------------------------------------
if fexists("inputs/input-display.lua") then
if fexists("inputs/input-modules.lua") then
dofile("inputs/input-display.lua")
else
print("input-modules.lua not found")
end
else
print("input-display.lua not found")
end
print ""
print "If the script crashes here you may need to edit DISABLE_SCROLLING_INPUT based on your computer. Open the fbneo-training-mode.lua file with a text editor (notepad, notepad++, etc.) and change DISABLE_SCROLLING_INPUT to true or false, whichever it isn't"
if games[dirname].iconfile then
iconfile = games[dirname].iconfile
if fexists("inputs/scrolling-input/"..iconfile) and not DISABLE_SCROLLING_INPUT then
if fexists("inputs/scrolling-input-display.lua") then
if fexists("inputs/scrolling-input/scrolling-input-code.lua") then
dofile("inputs/scrolling-input-display.lua")
else
print("scrolling-input-code.lua not found")
end
else
print("scrolling-input-display.lua not found")
end
else
print("inputs/scrolling-input/"..iconfile.." not found")
end
else
print("No scrolling input image found for "..rom)
end
----------------------------------------------
--
----------------------------------------------
----------------------------------------------
-- CHECK IF GUIPAGES EXISTS AND OPEN
-- DEFINE FUNCTIONS USED BY GUIPAGES
----------------------------------------------
createPopUpMenu = function(BaseMenu, releasefunc, selectfunc, autofunc, Elements, startx, starty, numofelements)
if releasefunc == nil then
releasefunc = function() return function() CIG(interactivegui.previouspage, interactivegui.previousselection) end end
end
menu = {}
for i,v in pairs(BaseMenu) do -- copy over the table and make sure ipairs wont pick up the elements
menu["a"..i] = v
end
local but
if (Elements) then -- fallback to the default, passed elements, if needed
for i, v in ipairs(Elements) do
-- create buttons
but = {}
if (v.releasefunc) then
but.releasefunc = v.releasefunc(i)
else
if (releasefunc) then but.releasefunc = releasefunc(i) end
end
if (v.selectfunc) then
but.selectfunc = v.selectfunc(i)
else
if (selectfunc) then but.selectfunc = selectfunc(i) end
end
if (v.autofunc) then
but.autofunc = v.autofunc(i)
else
if (autofunc) then but.autofunc = autofunc(i) end
end
if (v.text) then
but.text = v.text
else
but.text = tostring(i)
end
if (v.x) then
but.x = v.x
else
but.x = startx
end
if (v.y) then
but.y = v.y
else
but.y = starty+(i-1)*10
end
table.insert(menu, but)
end
else
for i = 1, numofelements do
-- create buttons
but = {}
if (releasefunc) then but.releasefunc = releasefunc(i) end
if (selectfunc) then but.selectfunc = selectfunc(i) end
if (autofunc) then but.autofunc = autofunc(i) end
but.text = tostring(i)
but.x = startx
but.y = starty+(i-1)*10
table.insert(menu, but)
end
end
return menu
end
createScrollingBar = function(BaseMenu, x, y, min, max, updatefunc, length, closingfunc, autofunc, text)
local menu = {}
text = text or ""
local barlen = max - min
length = length or barlen
length = length/4 -- account for text size
for _=1,(length-#text)/4 do
text = " "..text
end
for _=1,(length-(#text/2))/4 do
text = text.." "
end
for i,v in pairs(BaseMenu) do -- copy over the table and make sure ipairs wont pick up the elements
menu["a"..i] = v
end
menu.min = {
x = x-(#tostring(min))*2,
y = y+10,
text = tostring(min)
}
menu.max = {
x = x+(#text)*4-(#tostring(max))*2,
y = y+10,
text = tostring(max)
}
local but = {}
but.x = x
but.y = y
but.text = text
but.olcolour = "black"
but.val = updatefunc()
but.fillpercent = (but.val-min)/barlen
local workingframes = function(n) -- get faster the longer it runs
if (n < 60) then
if n%10==1 then return 1 end -- maybe tie this to coin input leniency?
return 0
elseif (n < 120) then
return 1
elseif (n < 150) then
return 2
elseif (n < 180) then
return 3
elseif (n < 210) then
return 5
elseif (n < 240) then
return 10
elseif (n < 300) then
return 10
end
return 100
end
but.autofunc = function(this)
but.val = updatefunc()
local d = 0
if guiinputs.P1.left then
d = workingframes(guiinputs.P1.leftframecount)
if but.val-d>=min then
updatefunc(-d)
else
updatefunc(max-but.val)
end
elseif guiinputs.P1.right then
d = workingframes(guiinputs.P1.rightframecount)
if but.val+d<=max then
updatefunc(d)
else
updatefunc(min-but.val)
end
end
but.fillpercent = (but.val-min)/barlen
if autofunc then autofunc() end
end
if closingfunc then
but.func = closingfunc
else
but.func = function() CIG(interactivegui.previouspage, interactivegui.previousselection) end
end
menu[1] = but
return menu
end
local hitplayback=gd.createFromPng("resources/replay/hitplayback.png"):gdStr() -- load images
local playback=gd.createFromPng("resources/replay/playback.png"):gdStr()
local savestateslot=gd.createFromPng("resources/replay/savestateslot.png"):gdStr()
drawReplayInfo = function()
for i = 1, 5 do
if (recording[i][1]) then -- something in slot
gui.text(interactivegui.boxx2-41,interactivegui.boxy2-71+10*i, "Slot "..i, "yellow")
else
gui.text(interactivegui.boxx2-41,interactivegui.boxy2-71+10*i, "Slot "..i)
end
if recording.recordingslot == i then
gui.gdoverlay(interactivegui.boxx2-53, interactivegui.boxy2-71+10*i-1, playback)
end
if recording.hitslot == i then
gui.gdoverlay(interactivegui.boxx2-64, interactivegui.boxy2-71+10*i-1, hitplayback)
end
if recording.savestateslot == i then
gui.gdoverlay(interactivegui.boxx2-75, interactivegui.boxy2-71+10*i-1, savestateslot)
end
-- check if anything is recorded in that slot
if (recording[i].p1start~=recording[i].p1finish and recording[i].p1finish and recording[i].p2start~=recording[i].p2finish and recording[i].p2finish) then
gui.text(interactivegui.boxx2-16,interactivegui.boxy2-71+10*i, "P1&2")
elseif (recording[i].p1start~=recording[i].p1finish and recording[i].p1finish) then
gui.text(interactivegui.boxx2-16,interactivegui.boxy2-71+10*i, "P1")
elseif (recording[i].p2start~=recording[i].p2finish and recording[i].p2finish) then
gui.text(interactivegui.boxx2-16,interactivegui.boxy2-71+10*i, "P2")
end
end
end
replaySave = function()
if dirname~="" then assert(table.save(recording[recording.recordingslot],configpath:sub(1,-11).."replay.lua")==nil, "Can't save replay file")
else assert(table.save(recording[recording.recordingslot],configpath:sub(1,-5).."_replay.lua")==nil, "Can't save replay file")
end
end
replayLoad = function()
local path = configpath:sub(1,-5).."_replay.lua"
if dirname~="" then path = configpath:sub(1,-11).."replay.lua" end
if fexists(path) then
recording[recording.recordingslot]=table.load(path)
end
end
function guiTableFormatting(t) -- produces a table of element ids that can be used for up/down/left/right navigation
--[[
takes a table of tables
t = {
{id1, x1, y1},
{id2, x2, y2},
...
}
--]]
local temp = copytable(t)
table.sort(temp, function(a,b) if a.y==b.y then return a.x<b.x end return a.y<b.y end) -- sort both here so the 'A' series lookups can give the exact coords
local tab = {}
local pos = 1
local i=1
local len
while i<=#temp do
if not tab[pos] or temp[i-1].y==temp[i].y then
tab[pos] = tab[pos] or {}
len = #tab[pos]+1
tab[pos][len]=temp[i].id
tab["A"..temp[i].id] = {pos, len}
else
tab[pos].len = #tab[pos]
pos = pos+1
i = i-1
end
i=i+1
end
tab.len = #tab
tab[tab.len].len = #tab[tab.len]
return tab
end
if fexists("guipages.lua") then
dofile("guipages.lua")
interactiveguipages = guipages
else
print("GUI pages not found"..rom)
end