-
Notifications
You must be signed in to change notification settings - Fork 0
/
sftm-training_v.0.3.2.lua
4230 lines (4195 loc) · 218 KB
/
sftm-training_v.0.3.2.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
---/Street Fighter: The Movie training lua v.0.3.2 (2022/03/24)/---
---/This works correctly on Fightcade FBNeo v.0.2.97.44 and NOT on mame-rr/---
-- *issue -> things to be solved, *comment -> stuff worth writing but not critical --
---preamble---*important
local gamename = "Street Fighter: The Movie"
local scriptver = "v.0.3.2"
local rb, rbs, rw, rws, rd = memory.readbyte, memory.readbytesigned, memory.readword, memory.readwordsigned, memory.readdword
local wb, wbs, ww, wws, wd = memory.writebyte, memory.writebytesigned, memory.writeword, memory.writewordsigned, memory.writedword
local function readcurrentframe() -- read the current frame
return emu.framecount()
end
local sw,sh = emu.screenwidth(), emu.screenheight() -- read the screen width/height
local function iffileexist(name) --check if the file exists (name: the file name)
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
local function any_true(condition)
for n = 1, #condition do
if condition[n] == true then return true end
end
end
local function lccalc(count, max, add) --calculate loop counter (count: the counter, max: the maximum value, add: the value to add)
if (count+add)%max == 0 then
return max
else
return (count+add)%max
end
end
local function tblconcat(tbl1, tbl2) -- concatenate two tables (the former table: tbl1, the latter table: tbl2)
for i = 1, #tbl2 do
tbl1[#tbl1+1] = tbl2[i]
end
return tbl1
end
local function strsplit(str, sep) -- split a string by a certain patterm (str: string to split, sep: patterm)
if str == nil then
return {}
end
sep = sep or '%s'
local t={}
for _,s in string.gmatch(str, "([^"..sep.."]*)("..sep.."?)") do
table.insert(t, _)
if s == "" then
return t
end
end
end
local function elmdetect(tbl, elm) --detect whether a ceartain element exists in the table (table: tbl, element: elm)
for i,v in pairs(tbl) do
if elm == v then
return i
end
end
return false
end
local function getfilelist(prefix, suffix) --get the list of files in source code's directory (prefix: the phrase at the beginning of file name, suffix: the phrase at the end of file name)
local filelist, filename = {}, ""
local path = debug.getinfo(1).source:sub(2):match("(.*[/\\])")
if prefix == nil then
if suffix == nil then
filename = path.."*"
else
filename = path.."*"..suffix
end
else
if suffix == nil then
filename = path..prefix.."*"
else
filename = path..prefix.."*"..suffix
end
end
for filename in io.popen('dir "'..filename..'" /b'):lines() do
table.insert(filelist, #filelist+1, filename)
end
return filelist
end
local function basenconvert(cnvnum, cnvbase) -- convert positive decimal integer into base-n number (integer: cnvnum, base: cnvbase)
local a, b, c = cnvnum, cnvbase, ""
if type(a) ~= "number" then
print("string is not supported.")
elseif a%1 ~= 0 then
print("float is not supported.")
elseif a < 0 then
print("negative value is not supported.")
elseif a == 0 then
return 0
else
while a > 0 do
c = "".. (a%b)..c
a = math.floor(a/b)
end
return c
end
end
games = {"sftm","sftm110","sftm111","sftmj114"} -- the games this script supports
buttons = {
{"Weak Punch", "LP"},
{"Medium Punch", "MP"},
{"Strong Punch", "HP"},
{"Weak Kick", "LK"},
{"Medium Kick", "MK"},
{"Strong Kick", "HK"}
}
addr = { -- list of addresses
---address P1
P1x = 0x70F0,
P1y = 0x70F2,
P1dir = 0x7133,
P1health = 0x7169,
P1meter = 0x717B,
P1dizzyvalue = 0x7178,
P1dizzy = 0x7187,
P1armor = 0x714B,
P1prjinv = 0x7236,
P1combocounter = 0x73D8,
P1chargever = 0x7246,
P1chargehol = 0x7247,
P1chargeLP = 0x7258,
P1chargeMP = 0x7259,
P1chargeHP = 0x725A,
P1chargeLK = 0x725B,
P1chargeMK = 0x725C,
P1chargeHK = 0x725D,
P1releasebutton = 0x725E,
---address P2 (P1+0x1C2)
P2x = 0x740E,
P2y = 0x7410,
P2dir = 0x72F5,
P2health = 0x732B,
P2meter = 0x733D,
P2dizzyvalue = 0x733A,
P2dizzy = 0x7349,
P2armor = 0x730D,
P2prjinv = 0x73F8,
P2combocounter = 0x7216,
P2chargever = 0x7408,
P2chargehol = 0x7409,
P2chargeLP = 0x741A,
P2chargeMP = 0x741B,
P2chargeHP = 0x741C,
P2chargeLK = 0x741D,
P2chargeMK = 0x741E,
P2chargeHK = 0x741F,
P2releasebutton = 0x7420,
---address misc
timer = 0x715F,
distance = 0x747A
}
P1status = {
x = 0, y = 0, dir = "",
health = 0,
meter = 0,
dizzyvalue = 0,
ifdizzy = {{true, false}, 2},
dizzystate = {{"none", "evil eye", "dizzy", "?"}, 1},
previousdizzy = 0,
combocounter = {0, 0},
combodamage = {0, 0},
healthbeforecomboed = {128, 128},
ifrefillhealth = {{true, false}, 2},
refillcount = 0,
refillcountstartframe = 0,
prjinvstate = {{"none", "reflect", "invul", "?"}, 1},
armorstate = {{"no", "yes", "?"}, 1}
}
P2status = {
x = 0, y = 0, dir = "",
health = 0,
meter = 0,
dizzyvalue = 0,
ifdizzy = {{true, false}, 2},
dizzystate = {{"none", "evil eye", "dizzy", "?"}, 1},
previousdizzy = 0,
combocounter = {0, 0},
combodamage = {0, 0},
healthbeforecomboed = {128, 128},
ifrefillhealth = {{true, false}, 2},
refillcount = 0,
refillcountstartframe = 0,
prjinvstate = {{"none", "reflect", "invul", "?"}, 1},
armorstate = {{"no", "yes", "?"}, 1}
}
local function updatestatus()
sw,sh = emu.screenwidth(), emu.screenheight()
P1status.x, P1status.y = rws(addr.P1x), rws(addr.P1y)
P2status.x, P2status.y = rws(addr.P2x), rws(addr.P2y)
if rbs(addr.P1dir) == 2 then
P1status.dir = "left"
elseif rbs(addr.P1dir) == 0 then
P1status.dir = "right"
end
if rbs(addr.P2dir) == 2 then
P2status.dir = "left"
elseif rbs(addr.P2dir) == 0 then
P2status.dir = "right"
end
end
local luaconfig = {
availablemenu = {{true, false}, 1},
showmenu = {{true, false}, 2},
showhud = {{true, false}, 1},
availablecheat = {{true, false}, 1},
updatefilelist = {{true, false}, 1},
showcautionmessage = {{true, false}, 2}
}
local inputconfig = {
ifswapinput = {{true, false}, 2},
ifdisableinputset = {{true, false}, 2},
disableinputplayer = {{"none", "P1", "P2", "both"}, 1},
ifholdinputset = {{true, false}, 2},
holdinputplayer = {{"none", "P1", "P2", "both"}, 1},
holddirection = {{"down left", "down", "down right", "left", "neutral", "right", "up left", "up", "up right"}, 5}
}
local menuconfig = {
menupage = {},
currentmenuselection = {page = 1, option = 1, subpage = 0, suboption = 1},
menuinput = {P1 = {holdstartframe = 0, currentinput = {}, previousinput = {}}, P2 = {holdstartframe = 0, currentinput = {}, previousinput = {}}},
ifswapped = inputconfig.ifswapinput[1][inputconfig.ifswapinput[2]]
}
local recordconfig = {
ifrecording = {{true, false}, 2},
ifplayback = {{true, false}, 2},
slot = {{}, {} ,{}, {}, {}},
recordslot = 1,
ifslotrecorded = {false, false, false, false, false},
recordstartframe = readcurrentframe(),
framebeforerecording = 40,
timerbeforerecording = 0,
timerafterrecording = 0,
recordinginput = {},
ifrecordend = {{true, false}, 2},
deleteslot = 1,
playbackslot = 1,
playbackstyle = {{"once", "repeat", "sequence", "random"}, 2},
playbacktime = 1,
playbackinput = {},
previousrecordstate = false,
previousplaybackstate = false,
ifshowplayback = {{true, false}, 1},
ifloadstatebefore = {{"yes", "no"}, 1}
}
local macroconfig = {
macrolist = {},
macrolistsorted = {},
playbackslot = 0,
savestatelist = {},
loadstateslot = 0,
game = {
player = 2,
keymap = {
{"U", "P# Up"},
{"D", "P# Down"},
{"L", "P# Left"},
{"R", "P# Right"},
{"F", "P# Forward"},
{"B", "P# Backward"},
{"S", "P# Start"},
{"X", "P# Disable"}
}
},
ifplayback = {{true, false}, 2},
previousplaybackstate = false,
playbackstyle = {{"once", "repeat", "sequence", "random"}, 1},
ifloadedmacro = {{true, false}, 2},
playbackinput = {},
playbacktime = 1,
waitframebefore = 0,
waitframeafter = 0,
waitcountbefore = 1,
waitcountafter = 1,
ifloadstatebefore = {{"yes", "no"}, 1},
ifloadedstate = {{true, false}, 2},
ifshowplayback = {{true, false}, 1},
ifsortmacrofile = {{true, false}, 2}
}
for i = 1, #buttons do
table.insert(macroconfig.game.keymap, #macroconfig.game.keymap+1, {tostring(i), "P# "..buttons[i][1]})
end
local hudconfig = {
hudstyle = {{"detailed", "simple", "debug", "hide"}, 1},
ifshowdarklayer = {{true, false}, 2},
darklayertransparency = 63,
ifshowinput = {{true, false}, 1},
inputstyle = {{"type1", "type2"}, 2},
}
local cheatconfig = {
time = {{"normal", "infinite"}, 2},
P1health = {{"normal", "refill", "infinite", "red"}, 2},
P1meter = {{"normal", "infinite", "empty"}, 1},
P1stun = {{"normal", "never"}, 1},
P2health = {{"normal", "refill", "infinite", "red"}, 2},
P2meter = {{"normal", "infinite", "empty"}, 1},
P2stun = {{"normal", "never"}, 1},
ifdisablemusic = {{"on", "off"}, 1},
selectstage = {{"normal", "Bison's Lair", "Komande Centre", "Tong Warehouse", "Dhalsim's Lab", "Dungeon", "Temple Ruins"}, 1},
selectmusic = {{"normal", "Ryu", "Vega", "Guile", "Sagat", "Ken", "Honda", "Chun Li", "Cammy", "Fei Long", "Balrog", "Blanka", "M. Bison", "Akuma", "Zangief"}, 1},
secretcode = {
ifsecretcode = {{"on", "off"}, 2},
hidemeters = {{"P1", "P2", "both", "off"}, 4},
invisotag = {{"P1", "P2", "both", "off"}, 4},
nothrows = {{"P1", "P2", "both", "off"}, 4},
nospecials = {{"P1", "P2", "both", "off"}, 4},
specialonly = {{"P1", "P2", "both", "off"}, 4},
tagteam = {{"on", "off"}, 2},
doubledamage = {{"P1", "P2", "both", "off"}, 4},
speedselect = {{"normal", "turbo", "slow"}, 1},
noblocking = {{"P1", "P2", "both", "off"}, 4},
combomode = {{"P1", "P2", "both", "off"}, 4},
nokicks = {{"P1", "P2", "both", "off"}, 4},
nopunches = {{"P1", "P2", "both", "off"}, 4},
strobemode = {{"on", "off"}, 2},
invisibility = {{"P1", "P2", "both", "off"}, 4},
classicthrows = {{"P1", "P2", "both", "off"}, 4},
programmerlevel = {{"on", "off"}, 2},
inverted = {{"on", "off"}, 2},
reversecontrols = {{"P1", "P2", "both", "off"}, 4},
swapplayers = {{"on", "off"}, 2},
}
}
local footsiesconfig = {
iffootsies = {{true, false}, 2},
ifshowinfo = {{"yes", "no"}, 1},
distance = {},
movegoaldistance = 150,
allowwalkrangeforward = 30,
allowwalkrangebackward = 30,
allowneutralrangeforward = 0,
allowneutralrangebackward = 20,
reactiondelay = 12,
previousreactiondelay = 12,
ifallowneutral = {{true, false}, 1},
ifallowprewalk = {{true, false}, 1},
movemode = {{"walk", "stand", "crouch"}, 1},
attackmode = {{"normal", "playback"}, 1},
movetype = {{"fwalk", "bwalk", "prewalk", "neutral", "crouch", "attack", "block"}, 1},
premovetype = {{"fwalk", "bwalk", "prewalk", "neutral", "crouch", "attack", "block"}, 1},
attack1stick = {{"db", "d", "df", "b", "n", "f"}, 1},
attack1button = {{}, 1},
attack1distance = 80,
allowattack1range = 40,
attack1holdframe = 2,
attack1blockframe = 30,
attack1probratio = 1,
attack2stick = {{"db", "d", "df", "b", "n", "f"}, 1},
attack2button = {{}, 2},
attack2distance = 170,
allowattack2range = 10,
attack2holdframe = 2,
attack2blockframe = 30,
attack2probratio = 0.5,
attackstick = {},
attackbutton = {},
holdattackframe = 0,
blockframe = 0,
blocktype = {{"stand", "crouch", "jump"}, 2},
baseprobattack = 0.05,
baseprobfwalktogoal = 0.4,
baseprobbwalktogoal = 0.5,
probprewalk = 0.6,
probneutral = 0.02,
probkeepneutral = 0.8,
walklimitfloor = 3,
neutrallimitfloor = 5,
beforeattackframe = 0,
walkcount = 0,
prewalkcount = 0,
neutralcount = 0,
attackcount = 0,
blockcount = 0,
playbackcount = 0,
prewalkdir = 0
}
for i = 1, #buttons do
footsiesconfig.attack1button[1][i] = buttons[i][2]
footsiesconfig.attack2button[1][i] = buttons[i][2]
end
for i = 1, #recordconfig.slot do
table.insert(footsiesconfig.attack1button[1], #footsiesconfig.attack1button[1]+1, "slot"..i)
table.insert(footsiesconfig.attack2button[1], #footsiesconfig.attack2button[1]+1, "slot"..i)
end
for i = 1, footsiesconfig.reactiondelay+1 do
footsiesconfig.distance[i] = math.abs(P1status.x - P2status.x)
end
local replayviewmode = {{true, false}, 2}
if replayviewmode[1][replayviewmode[2]] then
luaconfig.availablemenu[2] = 2
luaconfig.availablecheat[2] = 2
hudconfig.hudstyle[2] = 2
hudconfig.inputstyle[2] = 2
end
local function getfilelist()
if luaconfig.updatefilelist[1][luaconfig.updatefilelist[2]] then
local macrolist, savestatelist = {}, {}
macroconfig.playbackslot, macroconfig.loadstateslot = 0, 0
local path = debug.getinfo(1).source:sub(2):match("(.*[\\])")
if path == nil then
luaconfig.showcautionmessage[2] = 1
else
for filename in io.popen('dir "'..path..emu.romname()..'_macro_*.mis" /b'):lines() do
table.insert(macrolist, #macrolist+1, filename)
end
for filename in io.popen('dir "'..path..emu.romname()..'_macro_*.fs" /b'):lines() do
table.insert(savestatelist, #savestatelist+1, filename)
end
if #macrolist ~= 0 then
macroconfig.playbackslot = 1
end
if #savestatelist ~= 0 then
macroconfig.loadstateslot = 1
end
macroconfig.macrolist = macrolist
macroconfig.savestatelist = savestatelist
if elmdetect(macroconfig.savestatelist, emu.romname().."_macro_default.fs") then
table.remove(macroconfig.savestatelist, elmdetect(macroconfig.savestatelist, emu.romname().."_macro_default.fs"))
table.insert(macroconfig.savestatelist, 1, emu.romname().."_macro_default.fs")
end
if elmdetect(macroconfig.savestatelist, emu.romname().."_macro_default_backup.fs") then
table.remove(macroconfig.savestatelist, elmdetect(macroconfig.savestatelist, emu.romname().."_macro_default_backup.fs"))
table.insert(macroconfig.savestatelist, 2, emu.romname().."_macro_default_backup.fs")
end
luaconfig.updatefilelist[2] = 2
end
end
if macroconfig.ifsortmacrofile[1][macroconfig.ifsortmacrofile[2]] then
local macrolistsorted = {}
if macroconfig.loadstateslot == 0 then
macrolistsorted = macroconfig.macrolist
else
if #macroconfig.macrolist ~= 0 then
for i, v in ipairs(macroconfig.macrolist) do
if v:find(macroconfig.savestatelist[macroconfig.loadstateslot]:sub(1, -4), 1, true) then
table.insert(macrolistsorted, #macrolistsorted+1, v)
end
end
end
if #macrolistsorted == 0 then
macroconfig.playbackslot = 0
end
end
macroconfig.macrolistsorted = macrolistsorted
end
end
---input---*important
local function getinput()
local input = {P1 = {}, P2 = {}}
local player, inp
for i,v in pairs(joypad.get()) do
player, inp = i:sub(1,2), i:sub(4)
if i == "1 Player Start" then
input.P1["Start"] = v
end
if i == "2 Players Start" then
input.P2["Start"] = v
end
if player == "P1" then
input.P1[inp] = v -- get P1's inputs (be sure to check the inside of joypad.get() and correct the name of input(s) such as menuinput.P1[this])
end
if player == "P2" then
input.P2[inp] = v -- get P2's inputs (be sure to check the inside of joypad.get() and correct the name of input(s) such as menuinput.P1[this])
end
end
return input
end
local function setinputs()
local tempinput = joypad.get()
--disable input
function disableinputs(input)
if not inputconfig.ifdisableinputset[1][inputconfig.ifdisableinputset[2]] then
return input
elseif inputconfig.ifdisableinputset[1][inputconfig.ifdisableinputset[2]] then
local player, inp
if inputconfig.disableinputplayer[1][inputconfig.disableinputplayer[2]] == "P1" then
local disableP1input = input
for i,v in pairs(input) do
player, inp = i:sub(1,2), i:sub(4)
if i == "1 Player Start" then
disableP1input["1 Player Start"] = false
elseif player == "P1" then
disableP1input["P1 "..inp] = false
end
end
input = disableP1input
elseif inputconfig.disableinputplayer[1][inputconfig.disableinputplayer[2]] == "P2" then
local disableP2input = input
for i,v in pairs(input) do
player, inp = i:sub(1,2), i:sub(4)
if i == "2 Players Start" then
disableP2input["2 Players Start"] = false
elseif player == "P2" then
disableP2input["P2 "..inp] = false
end
end
input = disableP2input
elseif inputconfig.disableinputplayer[1][inputconfig.disableinputplayer[2]] == "both" then
local disablebothinput = input
for i,v in pairs(input) do
disablebothinput[i] = false
end
input = disablebothinput
end
return input
end
end
function holdinputs(input)
if not inputconfig.ifholdinputset[1][inputconfig.ifholdinputset[2]] or inputconfig.holdinputplayer[1][inputconfig.holdinputplayer[2]] == "none"
or inputconfig.holddirection[1][inputconfig.holddirection[2]] == "neutral" then
return input
elseif inputconfig.ifholdinputset[1][inputconfig.ifholdinputset[2]] then
local holdinput = input
local inp
if inputconfig.holddirection[1][inputconfig.holddirection[2]] == "down left" then
inp = {"Down", "Left"}
elseif inputconfig.holddirection[1][inputconfig.holddirection[2]] == "down" then
inp = {"Down"}
elseif inputconfig.holddirection[1][inputconfig.holddirection[2]] == "down right" then
inp = {"Down", "Right"}
elseif inputconfig.holddirection[1][inputconfig.holddirection[2]] == "left" then
inp = {"Left"}
elseif inputconfig.holddirection[1][inputconfig.holddirection[2]] == "right" then
inp = {"Right"}
elseif inputconfig.holddirection[1][inputconfig.holddirection[2]] == "up left" then
inp = {"Up", "Left"}
elseif inputconfig.holddirection[1][inputconfig.holddirection[2]] == "up" then
inp = {"Up"}
elseif inputconfig.holddirection[1][inputconfig.holddirection[2]] == "up right" then
inp = {"Up", "Right"}
end
if inputconfig.holdinputplayer[1][inputconfig.holdinputplayer[2]] == "P1" then
for i = 1, #inp do
holdinput["P1 "..inp[i]] = true
end
elseif inputconfig.holdinputplayer[1][inputconfig.holdinputplayer[2]] == "P2" then
for i = 1, #inp do
holdinput["P2 "..inp[i]] = true
end
elseif inputconfig.holdinputplayer[1][inputconfig.holdinputplayer[2]] == "both" then
for i = 1, #inp do
holdinput["P1 "..inp[i]] = true
holdinput["P2 "..inp[i]] = true
end
end
input = holdinput
return input
end
end
function swapinputs(input)
local swapinput = {}
if not inputconfig.ifswapinput[1][inputconfig.ifswapinput[2]] then
return input
elseif inputconfig.ifswapinput[1][inputconfig.ifswapinput[2]] then
local player, inp
for i,v in pairs(input) do
player, inp = i:sub(1,2), i:sub(4)
if i == "1 Player Start" then
swapinput["2 Players Start"] = v
elseif i == "2 Players Start" then
swapinput["1 Player Start"] = v
elseif player == "P1" then
swapinput["P2 "..inp] = v
elseif player == "P2" then
swapinput["P1 "..inp] = v
end
end
input = swapinput
return input
end
end
tempinput = disableinputs(tempinput)
tempinput = holdinputs(tempinput)
tempinput = swapinputs(tempinput)
joypad.set(tempinput)
end
local function freezeplayer()
if not luaconfig.showmenu[1][luaconfig.showmenu[2]] then
return input
elseif luaconfig.showmenu[1][luaconfig.showmenu[2]] then
local player, inp
local freezeinput = joypad.get()
for i,v in pairs(freezeinput) do
freezeinput[i] = false
end
joypad.set(freezeinput)
end
end
---record---*important
local function togglerecord()
if not recordconfig.ifrecording[1][recordconfig.ifrecording[2]] then
recordconfig.previousrecordstate = false
elseif recordconfig.ifrecording[1][recordconfig.ifrecording[2]] then
if recordconfig.previousrecordstate == false then
luaconfig.showmenu[2] = 2
end
recordconfig.previousrecordstate = true
if recordconfig.timerbeforerecording < recordconfig.framebeforerecording - 1 then
if recordconfig.timerbeforerecording == 0 then
if recordconfig.ifloadstatebefore[1][recordconfig.ifloadstatebefore[2]] == "yes" then
if iffileexist(emu.romname().."_recording.fs") then
savestate.load(savestate.create(emu.romname().."_recording.fs"))
end
end
end
inputconfig.ifdisableinputset[2] = 1
inputconfig.disableinputplayer[2] = 4
recordconfig.timerbeforerecording = recordconfig.timerbeforerecording + 1
elseif recordconfig.timerbeforerecording == recordconfig.framebeforerecording -1 then
inputconfig.ifdisableinputset[2] = 1
inputconfig.disableinputplayer[2] = 4
inputconfig.ifswapinput[2] = lccalc(inputconfig.ifswapinput[2], #inputconfig.ifswapinput[1], 1)
recordconfig.slot[recordconfig.recordslot] = {}
recordconfig.timerbeforerecording = recordconfig.timerbeforerecording + 1
recordconfig.timerafterrecording = 0
elseif recordconfig.timerbeforerecording == recordconfig.framebeforerecording then
if not recordconfig.ifrecordend[1][recordconfig.ifrecordend[2]] then
inputconfig.ifdisableinputset[2] = 2
inputconfig.disableinputplayer[2] = 1
table.insert(recordconfig.slot[recordconfig.recordslot], #recordconfig.slot[recordconfig.recordslot]+1, swapinputs(joypad.getdown()))
recordconfig.slot[recordconfig.recordslot][#recordconfig.slot[recordconfig.recordslot]]["P1 Coin"] = false
recordconfig.slot[recordconfig.recordslot][#recordconfig.slot[recordconfig.recordslot]]["P2 Coin"] = false
recordconfig.timerafterrecording = recordconfig.timerafterrecording + 1
if recordconfig.timerafterrecording == 600 then
recordconfig.ifrecordend[2] = 1
end
elseif recordconfig.ifrecordend[1][recordconfig.ifrecordend[2]] then
inputconfig.ifswapinput[2] = lccalc(inputconfig.ifswapinput[2], #inputconfig.ifswapinput[1], 1)
luaconfig.showmenu[2] = 1
recordconfig.ifslotrecorded[recordconfig.recordslot] = true
recordconfig.timerbeforerecording = 0
recordconfig.timerafterrecording = 0
recordconfig.ifrecording[2], recordconfig.ifrecordend[2] = 2, 2
end
end
end
end
local function toggleplayback()
if recordconfig.ifrecording[1][recordconfig.ifrecording[2]] then
return
end
if not recordconfig.ifplayback[1][recordconfig.ifplayback[2]] then
recordconfig.previousplaybackstate = false
elseif recordconfig.ifplayback[1][recordconfig.ifplayback[2]] then
if #recordconfig.slot[recordconfig.playbackslot] == 0 then
recordconfig.ifplayback[2] = 2
return
end
if recordconfig.previousplaybackstate == false then
luaconfig.showmenu[2] = 2
end
recordconfig.previousplaybackstate = true
if recordconfig.playbacktime <= #recordconfig.slot[recordconfig.playbackslot] then
if recordconfig.playbacktime == 1 then
if recordconfig.ifloadstatebefore[1][recordconfig.ifloadstatebefore[2]] == "yes" then
if iffileexist(emu.romname().."_recording.fs") then
savestate.load(savestate.create(emu.romname().."_recording.fs"))
end
end
end
recordconfig.playbackinput = joypad.get()
local player, inp
for i,v in pairs(recordconfig.slot[recordconfig.playbackslot][recordconfig.playbacktime]) do
if recordconfig.slot[recordconfig.playbackslot][recordconfig.playbacktime][i] == true then
recordconfig.playbackinput[i] = true
end
end
joypad.set(recordconfig.playbackinput)
recordconfig.playbacktime = recordconfig.playbacktime + 1
elseif recordconfig.playbacktime > #recordconfig.slot[recordconfig.playbackslot] then
recordconfig.playbacktime = 1
if recordconfig.playbackstyle[1][recordconfig.playbackstyle[2]] == "once" then
luaconfig.showmenu[2] = 1
recordconfig.ifplayback[2] = 2
elseif recordconfig.playbackstyle[1][recordconfig.playbackstyle[2]] == "sequence" then
local recordedslotnum, playbackslot = {}, 0
for i = 1, #recordconfig.ifslotrecorded do
if recordconfig.ifslotrecorded[i] then
recordedslotnum[#recordedslotnum+1] = i
end
end
for i = 1, #recordedslotnum do
if recordconfig.playbackslot == recordedslotnum[i] then
playbackslot = i
end
end
recordconfig.playbackslot = recordedslotnum[lccalc(playbackslot, #recordedslotnum, 1)]
elseif recordconfig.playbackstyle[1][recordconfig.playbackstyle[2]] == "random" then
local recordedslotnum = {}
for i = 1, #recordconfig.ifslotrecorded do
if recordconfig.ifslotrecorded[i] then
recordedslotnum[#recordedslotnum+1] = i
end
end
recordconfig.playbackslot = recordedslotnum[math.random(#recordedslotnum)]
end
end
end
end
local function playbackmacro()
if not macroconfig.ifplayback[1][macroconfig.ifplayback[2]] then
macroconfig.previousplaybackstate = false
elseif macroconfig.ifplayback[1][macroconfig.ifplayback[2]] then
if macroconfig.previousplaybackstate == false then
luaconfig.showmenu[2] = 2
macroconfig.playbackinput = {{}}
if macroconfig.playbackslot == 0 then
macroconfig.ifplayback[2] = 2
luaconfig.showmenu[2] = 1
return
else
if not io.open(macroconfig.macrolist[macroconfig.playbackslot], "r") then
print("Error: unable to open '" .. macroconfig.macrolist[macroconfig.playbackslot] .. "'")
macroconfig.ifplayback[2] = 2
luaconfig.showmenu[2] = 1
return
end
end
--macro to input (from macro.lua by Dammit)
local file = io.input(macroconfig.macrolist[macroconfig.playbackslot])
if macroconfig.ifsortmacrofile[1][macroconfig.ifsortmacrofile[2]] then
file = io.input(macroconfig.macrolistsorted[macroconfig.playbackslot])
end
local m = "\n" .. file:read("*a") .. "\n" --Open and read the file.
file:close() --Close the file.
m = m:gsub("([\n\r][^#]-)!.*", "%1") --Remove everything after the first uncommented "!".
m = m:sub(2) --Remove initial linebreak that was inserted
m = m:gsub("#.-[\n\r]", "\n") --Remove lines commented with "#".
m = m:gsub("[wW] ?(%d+)", function(n) return string.rep(".", n) end) --Expand waits into dots.
while m:find("%b() ?%d+") do --Recursively..
m = m:gsub("(%b()) ?(%d+)", function(s, n) --..expand ()n loops..
s = s:sub(2, -2) .. "," --..and remove the parentheses.
return s:rep(n)
end)
end
while m:find("%b()%?%[%d+%-%d+%]") do --Recursively..
m = m:gsub("(%b())%?%[(%d+)%-(%d+)%]", function(s, n1, n2) --..expand ()n loops..
s = s:sub(2, -2) .. "," --..and remove the parentheses.
return s:rep(math.random(math.min(n1, n2), math.max(n1, n2)))
end)
end
m = m:gsub("%|", "}%|{")
while m:find("%b{}%|%b{}") do --Recursively..
m = m:gsub("(%b{})%|(%b{})", function(s1, s2) --..expand ()n loops..
s1 = s1:sub(2, -2).."," --..and remove the parentheses.
s2 = s2:sub(2, -2).."," --..and remove the parentheses.
if math.random(1,2) == 1 then
return s1
else
return s2
end
end)
end
for _,space in pairs({" ",",","\t","\n","\r"}) do --Remove commas, spaces, tabs, and linebreaks.
m = m:gsub(space, "")
end
m = m:sub(m:find("<")+1, m:len())
m = m:sub(1, m:find(">")-1)
m = strsplit(m, "/")
for i = 1, macroconfig.game.player do
if m[i] then
m[i] = strsplit(m[i], ".")
else
m[i] = {}
end
if m[i][#m[i]] == "" then
table.remove(m[i], #m[i])
end
end
local maxframe = 0
for i = 1, macroconfig.game.player do
maxframe = math.max(maxframe, #m[i])
end
if maxframe == 0 then
print("Error: no input is coded in the macro file.")
macroconfig.ifplayback[2] = 2
luaconfig.showmenu[2] = 1
return
else
for i = 1, maxframe do
table.insert(macroconfig.playbackinput, i, {})
end
for p = 1, macroconfig.game.player do
if #m[p] < maxframe then
for i = #m[p]+1, maxframe do
table.insert(m[p], i, "")
end
end
end
end
local holdkey = ""
for p = 1, macroconfig.game.player do
holdkey = ""
for f = 1, #m[p] do
v = "P"..tostring(p).."status"
while string.len(m[p][f]) > 0 do
if string.sub(m[p][f], 1,1) == "_" then
m[p][f] = string.sub(m[p][f], 2)
for _,input in ipairs(macroconfig.game.keymap) do
if string.sub(m[p][f], 1,1) == input[1] then
holdkey = holdkey..string.sub(m[p][f], 1,1)
end
end
elseif string.sub(m[p][f], 1,1) == "^" then
m[p][f] = string.sub(m[p][f], 2)
for _,input in ipairs(macroconfig.game.keymap) do
if string.sub(m[p][f], 1,1) == input[1] then
holdkey = holdkey:gsub(string.sub(m[p][f], 1,1), "")
end
end
else
for _,input in ipairs(macroconfig.game.keymap) do
if string.sub(m[p][f], 1,1) == input[1] then
macroconfig.playbackinput[f]["P"..p.." "..input[2]:sub(4)] = true
end
end
end
m[p][f] = string.sub(m[p][f], 2)
end
if holdkey:len() > 0 then
for i = 1, holdkey:len() do
for _,input in ipairs(macroconfig.game.keymap) do
if holdkey:sub(i,i) == input[1] then
macroconfig.playbackinput[f]["P"..p.." "..input[2]:sub(4)] = true
end
end
end
end
end
end
if macroconfig.playbackinput[#macroconfig.playbackinput][1] == nil then
table.remove(macroconfig.playbackinput)
end
end
macroconfig.previousplaybackstate = true
if macroconfig.ifloadstatebefore[1][macroconfig.ifloadstatebefore[2]] == "yes" then
if not macroconfig.ifloadedstate[1][macroconfig.ifloadedstate[2]] then
if macroconfig.loadstateslot ~= 0 then
if iffileexist(macroconfig.savestatelist[macroconfig.loadstateslot]) then
savestate.load(savestate.create(macroconfig.savestatelist[macroconfig.loadstateslot]))
end
end
end
macroconfig.ifloadedstate[2] = 1
end
if macroconfig.waitcountbefore <= macroconfig.waitframebefore then
macroconfig.waitcountbefore = macroconfig.waitcountbefore + 1
elseif macroconfig.playbacktime <= #macroconfig.playbackinput then
for p = 1,2 do
s = "P"..tostring(p).."status"
for i,v in pairs(macroconfig.playbackinput[macroconfig.playbacktime]) do
if i == "P"..p.." Forward" then
if _G[s].dir == "left" then
macroconfig.playbackinput[macroconfig.playbacktime]["P"..p.." Left"] = true
elseif _G[s].dir == "right" then
macroconfig.playbackinput[macroconfig.playbacktime]["P"..p.." Right"] = true
end
end
if i == "P"..p.." Backward" then
if _G[s].dir == "left" then
macroconfig.playbackinput[macroconfig.playbacktime]["P"..p.." Right"] = true
elseif _G[s].dir == "right" then
macroconfig.playbackinput[macroconfig.playbacktime]["P"..p.." Left"] = true
end
end
if i == "P"..p.." Disable" then
local player, inp
for i,v in pairs(joypad.get()) do
player, inp = i:sub(1,2), i:sub(4)
if player == "P"..p then
if not (macroconfig.playbackinput[macroconfig.playbacktime][i] == true) then
macroconfig.playbackinput[macroconfig.playbacktime][i] = false
end
end
end
end
end
end
joypad.set(macroconfig.playbackinput[macroconfig.playbacktime])
macroconfig.playbacktime = macroconfig.playbacktime + 1
if macroconfig.playbacktime == #macroconfig.playbackinput + 1 then
if (macroconfig.playbackstyle[1][macroconfig.playbackstyle[2]] ~= "once") and (macroconfig.waitframeafter == 0) then
macroconfig.playbacktime = 1
macroconfig.waitcountbefore = 1
macroconfig.ifloadedstate[2] = 2
macroconfig.previousplaybackstate = false
if macroconfig.playbackstyle[1][macroconfig.playbackstyle[2]] == "sequence" then
if macroconfig.ifsortmacrofile[1][macroconfig.ifsortmacrofile[2]] then
macroconfig.playbackslot = lccalc(macroconfig.playbackslot, #macroconfig.macrolistsorted, 1)
else
macroconfig.playbackslot = lccalc(macroconfig.playbackslot, #macroconfig.macrolist, 1)
end
elseif macroconfig.playbackstyle[1][macroconfig.playbackstyle[2]] == "random" then
if macroconfig.ifsortmacrofile[1][macroconfig.ifsortmacrofile[2]] then
macroconfig.playbackslot = math.random(#macroconfig.macrolistsorted)
else
macroconfig.playbackslot = math.random(#macroconfig.macrolist)
end
end
end
end
elseif macroconfig.waitcountafter <= macroconfig.waitframeafter then
macroconfig.waitcountafter = macroconfig.waitcountafter + 1
if macroconfig.waitcountafter == macroconfig.waitframeafter + 1 then
if macroconfig.playbackstyle[1][macroconfig.playbackstyle[2]] ~= "once" then
macroconfig.playbacktime = 1
macroconfig.waitcountbefore = 1
macroconfig.waitcountafter = 1
macroconfig.ifloadedstate[2] = 2
macroconfig.previousplaybackstate = false
if macroconfig.playbackstyle[1][macroconfig.playbackstyle[2]] == "sequence" then
if macroconfig.ifsortmacrofile[1][macroconfig.ifsortmacrofile[2]] then
macroconfig.playbackslot = lccalc(macroconfig.playbackslot, #macroconfig.macrolistsorted, 1)
else
macroconfig.playbackslot = lccalc(macroconfig.playbackslot, #macroconfig.macrolist, 1)
end
elseif macroconfig.playbackstyle[1][macroconfig.playbackstyle[2]] == "random" then
if macroconfig.ifsortmacrofile[1][macroconfig.ifsortmacrofile[2]] then
macroconfig.playbackslot = math.random(#macroconfig.macrolistsorted)
else
macroconfig.playbackslot = math.random(#macroconfig.macrolist)
end
end
end
end
else
macroconfig.playbacktime = 1
macroconfig.waitcountbefore = 1
macroconfig.waitcountafter = 1
macroconfig.ifloadedstate[2] = 2
macroconfig.previousplaybackstate = false
if macroconfig.playbackstyle[1][macroconfig.playbackstyle[2]] == "once" then
macroconfig.ifplayback[2] = 2
luaconfig.showmenu[2] = 1
end
end
end
end
---footsies---*important
local function footsies()
if not footsiesconfig.iffootsies[1][footsiesconfig.iffootsies[2]] then
return
end
luaconfig.showmenu[2] = 2
--get status
if footsiesconfig.previousreactiondelay ~= footsiesconfig.reactiondelay then
for i = 1, footsiesconfig.reactiondelay+1 do
footsiesconfig.distance = {}
footsiesconfig.distance[i] = math.abs(P1status.x - P2status.x)
footsiesconfig.previousreactiondelay = footsiesconfig.reactiondelay
end
end
if footsiesconfig.reactiondelay ~= 0 then
for i = 1, footsiesconfig.reactiondelay do
footsiesconfig.distance[i+1] = footsiesconfig.distance[i]
end
end
footsiesconfig.distance[1] = math.abs(P1status.x - P2status.x)
local distance = footsiesconfig.distance[#footsiesconfig.distance]
--decide opponent's move
if footsiesconfig.movemode[1][footsiesconfig.movemode[2]] == "walk" then
local walklimitnoise = math.random(-1, 6)
if footsiesconfig.walkcount == 0 then
if distance > footsiesconfig.movegoaldistance then
if math.random() > footsiesconfig.baseprobfwalktogoal + (math.abs(distance - footsiesconfig.movegoaldistance)/footsiesconfig.allowwalkrangebackward)^2*(1-footsiesconfig.baseprobfwalktogoal) then
footsiesconfig.movetype[2] = 2
else
footsiesconfig.movetype[2] = 1
end
elseif distance <= footsiesconfig.movegoaldistance then
if math.random() > footsiesconfig.baseprobbwalktogoal + (math.abs(distance - footsiesconfig.movegoaldistance)/footsiesconfig.allowwalkrangeforward)^2*(1-footsiesconfig.baseprobbwalktogoal) then
footsiesconfig.movetype[2] = 1
else
footsiesconfig.movetype[2] = 2
end
end
footsiesconfig.walkcount = 1
elseif footsiesconfig.walkcount < (footsiesconfig.walklimitfloor+walklimitnoise) then
footsiesconfig.walkcount = footsiesconfig.walkcount + 1
elseif footsiesconfig.walkcount >= (footsiesconfig.walklimitfloor+walklimitnoise) then
footsiesconfig.walkcount = 0