-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy path3rd_training.lua
2911 lines (2559 loc) · 107 KB
/
3rd_training.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
require("src/startup")
print("-----------------------------")
print(" 3rd_training.lua - "..script_version.."")
print(" Training mode for "..game_name.."")
print(" Last tested Fightcade version: "..fc_version.."")
print(" project url: https://github.com/Grouflon/3rd_training_lua")
print("-----------------------------")
print("")
print("Command List:")
print("- Enter training menu by pressing \"Start\" while in game")
print("- Enter/exit recording mode by double tapping \"Coin\"")
print("- In recording mode, press \"Coin\" again to start/stop recording")
print("- In normal mode, press \"Coin\" to start/stop replay")
print("- Lua Hotkey 1 (alt+1) to return to character select screen")
print("")
-- Kudos to indirect contributors:
-- *esn3s* for his work on 3s frame data : http://baston.esn3s.com/
-- *dammit* for his work on 3s hitbox display script : https://dammit.typepad.com/blog/2011/10/improved-3rd-strike-hitboxes.html
-- *furitiem* for his prior work on 3s C# training program : https://www.youtube.com/watch?v=vE27xe0QM64
-- *crytal_cube99* for his prior work on 3s training & trial scripts : https://ameblo.jp/3fv/
-- Thanks to *speedmccool25* for recording all the 4rd strike frame data
-- Thanks to *ProfessorAnon* for the Charge and Hyakuretsu Kyaku special training mode
-- Thanks to *sammygutierrez* for the damage info display
-- FBA-RR Scripting reference:
-- http://tasvideos.org/EmulatorResources/VBA/LuaScriptingFunctions.html
-- https://github.com/TASVideos/mame-rr/wiki/Lua-scripting-functions
-- Resources
-- https://github.com/Jesuszilla/mame-rr-scripts/blob/master/framedata.lua
-- https://imgur.com/gallery/0Tsl7di
-- Stuff
-- As far of selective stages, this one is Elena's Stage, write this: 0x020154F5,0x08
-- It would be also nice to show "alt+1 reset char select" on the top left corner in the character select screen
-- optional speed up
--[[
would it be possible to add a "first, second, third" action when getting hit? So for example i divekick on opponent, first time they throw, second time they standing hk, third time they do another thing.
This isn't really possible with weighting but it can be extremely important for figuring out options after hitting specific choices your opponent makes at awkward timings. So like block 1 = recording 1, block 2 = recording 2, block 3 = recording 3.
it'd need its own menu for setup that would be used just like the "recording" reaction option, but with 1-5 layers. Possibly adding "random recording" as an option for the replay instead of a specific one as well
So like you do your first choice and want opponent to throw, but second time you want them to either throw, or do option 2 or 3 etc etc
And also having throw as an option there as well so you have one less option to record if you don't want a button action
]]--
-- Includes
require("src/tools")
require("src/memory_adresses")
require("src/draw")
require("src/display")
require("src/menu_widgets")
require("src/framedata")
require("src/gamestate")
require("src/input_history")
require("src/attack_data")
require("src/frame_advantage")
require("src/character_select")
recording_slot_count = 8
-- debug options
developer_mode = false -- Unlock frame data recording options. Touch at your own risk since you may use those options to fuck up some already recorded frame data
assert_enabled = developer_mode or assert_enabled
debug_wakeup = false
log_enabled = developer_mode or log_enabled
log_categories_display =
{
input = { history = false, print = false },
projectiles = { history = false, print = false },
fight = { history = false, print = false },
animation = { history = false, print = false },
parry_training_FORWARD = { history = false, print = false },
blocking = { history = false, print = false },
counter_attack = { history = false, print = false },
block_string = { history = false, print = false },
frame_advantage = { history = false, print = false },
} or log_categories_display
saved_recordings_path = "saved/recordings/"
training_settings_file = "training_settings.json"
-- players
function queue_input_sequence(_player_obj, _sequence, _offset)
_offset = _offset or 0
if _sequence == nil or #_sequence == 0 then
return
end
if _player_obj.pending_input_sequence ~= nil then
return
end
local _seq = {}
_seq.sequence = copytable(_sequence)
_seq.current_frame = 1 - _offset
_player_obj.pending_input_sequence = _seq
end
function process_pending_input_sequence(_player_obj, _input)
if _player_obj.pending_input_sequence == nil then
return
end
if is_menu_open then
return
end
if not is_in_match then
return
end
-- Cancel all input
_input[_player_obj.prefix.." Up"] = false
_input[_player_obj.prefix.." Down"] = false
_input[_player_obj.prefix.." Left"] = false
_input[_player_obj.prefix.." Right"] = false
_input[_player_obj.prefix.." Weak Punch"] = false
_input[_player_obj.prefix.." Medium Punch"] = false
_input[_player_obj.prefix.." Strong Punch"] = false
_input[_player_obj.prefix.." Weak Kick"] = false
_input[_player_obj.prefix.." Medium Kick"] = false
_input[_player_obj.prefix.." Strong Kick"] = false
-- Charge moves memory locations
-- P1
-- 0x020259D8 H/Urien V/Oro V/Chun H/Q V/Remy
-- 0x020259F4 (+1C) V/Urien H/Q H/Remy
-- 0x02025A10 (+38) H/Oro H/Remy
-- 0x02025A2C (+54) V/Urien V/Alex
-- 0x02025A48 (+70) H/Alex
-- P2
-- 0x02025FF8
-- 0x02026014
-- 0x02026030
-- 0x0202604C
-- 0x02026068
local _gauges_base = 0
if _player_obj.id == 1 then
_gauges_base = 0x020259D8
elseif _player_obj.id == 2 then
_gauges_base = 0x02025FF8
end
local _gauges_offsets = { 0x0, 0x1C, 0x38, 0x54, 0x70 }
if _player_obj.pending_input_sequence.current_frame >= 1 then
local _s = ""
local _current_frame_input = _player_obj.pending_input_sequence.sequence[_player_obj.pending_input_sequence.current_frame]
for i = 1, #_current_frame_input do
local _input_name = _player_obj.prefix.." "
if _current_frame_input[i] == "forward" then
if _player_obj.flip_input then _input_name = _input_name.."Right" else _input_name = _input_name.."Left" end
elseif _current_frame_input[i] == "back" then
if _player_obj.flip_input then _input_name = _input_name.."Left" else _input_name = _input_name.."Right" end
elseif _current_frame_input[i] == "up" then
_input_name = _input_name.."Up"
elseif _current_frame_input[i] == "down" then
_input_name = _input_name.."Down"
elseif _current_frame_input[i] == "LP" then
_input_name = _input_name.."Weak Punch"
elseif _current_frame_input[i] == "MP" then
_input_name = _input_name.."Medium Punch"
elseif _current_frame_input[i] == "HP" then
_input_name = _input_name.."Strong Punch"
elseif _current_frame_input[i] == "LK" then
_input_name = _input_name.."Weak Kick"
elseif _current_frame_input[i] == "MK" then
_input_name = _input_name.."Medium Kick"
elseif _current_frame_input[i] == "HK" then
_input_name = _input_name.."Strong Kick"
elseif _current_frame_input[i] == "h_charge" then
if _player_obj.char_str == "urien" then
memory.writeword(_gauges_base + _gauges_offsets[1], 0xFFFF)
elseif _player_obj.char_str == "oro" then
memory.writeword(_gauges_base + _gauges_offsets[3], 0xFFFF)
elseif _player_obj.char_str == "chunli" then
elseif _player_obj.char_str == "q" then
memory.writeword(_gauges_base + _gauges_offsets[1], 0xFFFF)
memory.writeword(_gauges_base + _gauges_offsets[2], 0xFFFF)
elseif _player_obj.char_str == "remy" then
memory.writeword(_gauges_base + _gauges_offsets[2], 0xFFFF)
memory.writeword(_gauges_base + _gauges_offsets[3], 0xFFFF)
elseif _player_obj.char_str == "alex" then
memory.writeword(_gauges_base + _gauges_offsets[5], 0xFFFF)
end
elseif _current_frame_input[i] == "v_charge" then
if _player_obj.char_str == "urien" then
memory.writeword(_gauges_base + _gauges_offsets[2], 0xFFFF)
memory.writeword(_gauges_base + _gauges_offsets[4], 0xFFFF)
elseif _player_obj.char_str == "oro" then
memory.writeword(_gauges_base + _gauges_offsets[1], 0xFFFF)
elseif _player_obj.char_str == "chunli" then
memory.writeword(_gauges_base + _gauges_offsets[1], 0xFFFF)
elseif _player_obj.char_str == "q" then
elseif _player_obj.char_str == "remy" then
memory.writeword(_gauges_base + _gauges_offsets[1], 0xFFFF)
elseif _player_obj.char_str == "alex" then
memory.writeword(_gauges_base + _gauges_offsets[4], 0xFFFF)
end
end
_input[_input_name] = true
_s = _s.._input_name
end
end
--print(_s)
_player_obj.pending_input_sequence.current_frame = _player_obj.pending_input_sequence.current_frame + 1
if _player_obj.pending_input_sequence.current_frame > #_player_obj.pending_input_sequence.sequence then
_player_obj.pending_input_sequence = nil
end
end
function clear_input_sequence(_player_obj)
_player_obj.pending_input_sequence = nil
end
function is_playing_input_sequence(_player_obj)
return _player_obj.pending_input_sequence ~= nil and _player_obj.pending_input_sequence.current_frame >= 1
end
function make_input_empty(_input)
if _input == nil then
return
end
_input["P1 Up"] = false
_input["P1 Down"] = false
_input["P1 Left"] = false
_input["P1 Right"] = false
_input["P1 Weak Punch"] = false
_input["P1 Medium Punch"] = false
_input["P1 Strong Punch"] = false
_input["P1 Weak Kick"] = false
_input["P1 Medium Kick"] = false
_input["P1 Strong Kick"] = false
_input["P1 Start"] = false
_input["P1 Coin"] = false
_input["P2 Up"] = false
_input["P2 Down"] = false
_input["P2 Left"] = false
_input["P2 Right"] = false
_input["P2 Weak Punch"] = false
_input["P2 Medium Punch"] = false
_input["P2 Strong Punch"] = false
_input["P2 Weak Kick"] = false
_input["P2 Medium Kick"] = false
_input["P2 Strong Kick"] = false
_input["P2 Start"] = false
_input["P2 Coin"] = false
end
-- training settings
pose = {
"normal",
"crouching",
"jumping",
"highjumping",
}
stick_gesture = {
"none",
"QCF",
"QCB",
"HCF",
"HCB",
"DPF",
"DPB",
"HCharge",
"VCharge",
"360",
"DQCF",
"720",
"forward",
"back",
"down",
"jump",
"super jump",
"forward jump",
"forward super jump",
"back jump",
"back super jump",
"back dash",
"forward dash",
"guard jump (See Readme)",
--"guard back jump",
--"guard forward jump",
"Shun Goku Satsu", -- Gouki hidden SA1
"Kongou Kokuretsu Zan", -- Gouki hidden SA2
}
if is_4rd_strike then
table.insert(stick_gesture, "Demon Armageddon") -- Gouki SA3
end
button_gesture =
{
"none",
"recording",
"LP",
"MP",
"HP",
"EXP",
"LK",
"MK",
"HK",
"EXK",
"LP+LK",
"MP+MK",
"HP+HK",
}
function make_input_sequence(_stick, _button)
if _button == "recording" then
return nil
end
local _sequence = {}
local _offset = 0
if _stick == "none" then _sequence = { { } }
elseif _stick == "forward" then _sequence = { { "forward" } }
elseif _stick == "back" then _sequence = { { "back" } }
elseif _stick == "down" then _sequence = { { "down" } }
elseif _stick == "jump" then _sequence = { { "up" } }
elseif _stick == "super jump" then _sequence = { { "down" }, { "up" } }
elseif _stick == "forward jump" then
_sequence = { { "forward", "up" }, { "forward", "up" }, { "forward", "up" } }
_offset = 2
elseif _stick == "forward super jump" then
_sequence = { { "down" }, { "forward", "up" }, { "forward", "up" } }
_offset = 2
elseif _stick == "back jump" then
_sequence = { { "back", "up" }, { "back", "up" } }
_offset = 2
elseif _stick == "back super jump" then
_sequence = { { "down" }, { "back", "up" }, { "back", "up" } }
_offset = 2
elseif _stick == "guard jump" then
_sequence = {
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "up" }, { "up" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" }
}
_offset = 13
elseif _stick == "guard forward jump" then
_sequence = {
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "forward", "up" },
{ "forward", "up" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" }
}
_offset = 13
elseif _stick == "guard back jump" then
_sequence = {
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "back", "up" },
{ "back", "up" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" },
{ "down", "back" }
}
_offset = 13
elseif _stick == "QCF" then _sequence = { { "down" }, {"down", "forward"}, {"forward"} }
elseif _stick == "QCB" then _sequence = { { "down" }, {"down", "back"}, {"back"} }
elseif _stick == "HCF" then _sequence = { { "back" }, {"down", "back"}, {"down"}, {"down", "forward"}, {"forward"} }
elseif _stick == "HCB" then _sequence = { { "forward" }, {"down", "forward"}, {"down"}, {"down", "back"}, {"back"} }
elseif _stick == "DPF" then _sequence = { { "forward" }, {"down"}, {"down", "forward"} }
elseif _stick == "DPB" then _sequence = { { "back" }, {"down"}, {"down", "back"} }
elseif _stick == "HCharge" then _sequence = { { "back", "h_charge" }, {"forward"} }
elseif _stick == "VCharge" then _sequence = { { "down", "v_charge" }, {"up"} }
elseif _stick == "360" then _sequence = { { "forward" }, { "forward", "down" }, {"down"}, { "back", "down" }, { "back" }, { "up" } }
elseif _stick == "DQCF" then _sequence = { { "down" }, {"down", "forward"}, {"forward"}, { "down" }, {"down", "forward"}, {"forward"} }
elseif _stick == "720" then _sequence = { { "forward" }, { "forward", "down" }, {"down"}, { "back", "down" }, { "back" }, { "up" }, { "forward" }, { "forward", "down" }, {"down"}, { "back", "down" }, { "back" } }
-- full moves special cases
elseif _stick == "back dash" then _sequence = { { "back" }, {}, { "back" } }
return _sequence
elseif _stick == "forward dash" then _sequence = { { "forward" }, {}, { "forward" } }
return _sequence
elseif _stick == "Shun Goku Satsu" then _sequence = { { "LP" }, {}, {}, { "LP" }, { "forward" }, {"LK"}, {}, { "HP" } }
return _sequence
elseif _stick == "Kongou Kokuretsu Zan" then _sequence = { { "down" }, {}, { "down" }, {}, { "down", "LP", "MP", "HP" } }
return _sequence
elseif _stick == "Demon Armageddon" then _sequence = { { "up" }, {}, { "up" }, {}, { "up", "LK", "MK" } }
return _sequence
end
if _button == "none" then
elseif _button == "EXP" then
table.insert(_sequence[#_sequence], "MP")
table.insert(_sequence[#_sequence], "HP")
elseif _button == "EXK" then
table.insert(_sequence[#_sequence], "MK")
table.insert(_sequence[#_sequence], "HK")
elseif _button == "LP+LK" then
table.insert(_sequence[#_sequence], "LP")
table.insert(_sequence[#_sequence], "LK")
elseif _button == "MP+MK" then
table.insert(_sequence[#_sequence], "MP")
table.insert(_sequence[#_sequence], "MK")
elseif _button == "HP+HK" then
table.insert(_sequence[#_sequence], "HP")
table.insert(_sequence[#_sequence], "HK")
else
table.insert(_sequence[#_sequence], _button)
end
return _sequence, _offset
end
fast_wakeup_mode =
{
"never",
"always",
"random",
}
blocking_style =
{
"block",
"parry",
"red parry",
}
blocking_mode =
{
"never",
"always",
"first hit",
"random",
}
tech_throws_mode =
{
"never",
"always",
"random",
}
hit_type =
{
"normal",
"low",
"overhead",
}
life_mode =
{
"no refill",
"refill",
"infinite"
}
meter_mode =
{
"no refill",
"refill",
"infinite"
}
stun_mode =
{
"normal",
"no stun",
"delayed reset"
}
standing_state =
{
"knockeddown",
"standing",
"crouched",
"airborne",
}
players = {
"Player 1",
"Player 2",
}
special_training_mode = {
"none",
"parry",
"charge",
"Hyakuretsu Kyaku (Chun Li)"
}
function make_recording_slot()
return {
inputs = {},
delay = 0,
random_deviation = 0,
weight = 1,
}
end
recording_slots = {}
for _i = 1, recording_slot_count do
table.insert(recording_slots, make_recording_slot())
end
recording_slots_names = {}
for _i = 1, #recording_slots do
table.insert(recording_slots_names, "slot ".._i)
end
slot_replay_mode = {
"normal",
"random",
"ordered",
"repeat",
"repeat random",
"repeat ordered",
}
-- save/load
function save_training_data()
backup_recordings()
if not write_object_to_json_file(training_settings, saved_path..training_settings_file) then
print(string.format("Error: Failed to save training settings to \"%s\"", training_settings_file))
end
end
function load_training_data()
local _training_settings = read_object_from_json_file(saved_path..training_settings_file)
if _training_settings == nil then
_training_settings = {}
end
-- update old versions data
if _training_settings.recordings then
for _key, _value in pairs(_training_settings.recordings) do
for _i, _slot in ipairs(_value) do
if _value[_i].inputs == nil then
_value[_i] = make_recording_slot()
else
_slot.delay = _slot.delay or 0
_slot.random_deviation = _slot.random_deviation or 0
_slot.weight = _slot.weight or 1
end
end
end
end
for _key, _value in pairs(_training_settings) do
training_settings[_key] = _value
end
restore_recordings()
end
function backup_recordings()
-- Init base table
if training_settings.recordings == nil then
training_settings.recordings = {}
end
for _key, _value in ipairs(characters) do
if training_settings.recordings[_value] == nil then
training_settings.recordings[_value] = {}
for _i = 1, #recording_slots do
table.insert(training_settings.recordings[_value], make_recording_slot())
end
end
end
if dummy.char_str ~= "" then
training_settings.recordings[dummy.char_str] = recording_slots
end
end
function restore_recordings()
local _char = player_objects[2].char_str
if _char and _char ~= "" then
local _recording_count = #recording_slots
if training_settings.recordings then
recording_slots = training_settings.recordings[_char] or {}
end
local _missing_slots = _recording_count - #recording_slots
for _i = 1, _missing_slots do
table.insert(recording_slots, make_recording_slot())
end
end
end
-- swap inputs
function swap_inputs(_out_input_table)
function swap(_input)
local carry = _out_input_table["P1 ".._input]
_out_input_table["P1 ".._input] = _out_input_table["P2 ".._input]
_out_input_table["P2 ".._input] = carry
end
swap("Up")
swap("Down")
swap("Left")
swap("Right")
swap("Weak Punch")
swap("Medium Punch")
swap("Strong Punch")
swap("Weak Kick")
swap("Medium Kick")
swap("Strong Kick")
end
-- POSE
function update_pose(_input, _player_obj, _pose)
if current_recording_state == 4 then -- Replaying
return
end
-- pose
if is_in_match and not is_menu_open and not is_playing_input_sequence(_player_obj) then
local _on_ground = is_state_on_ground(_player_obj.standing_state, _player_obj)
local _is_waking_up = _player_obj.is_wakingup and _player_obj.is_past_wakeup_frame
if _pose == 2 and (_on_ground or _is_waking_up) then -- crouch
_input[_player_obj.prefix..' Down'] = true
elseif _pose == 3 and _on_ground then -- jump
_input[_player_obj.prefix..' Up'] = true
elseif _pose == 4 then -- high jump
if _on_ground and not is_playing_input_sequence(_player_obj) then
queue_input_sequence(_player_obj, {{"down"}, {"up"}})
end
end
end
end
-- BLOCKING
function find_move_frame_data(_char_str, _animation_id)
if not frame_data[_char_str] then return nil end
return frame_data[_char_str][_animation_id]
end
function predict_object_position(_object, _frames_prediction, _movement_cycle, _lifetime)
local _result = {
_object.pos_x,
_object.pos_y,
}
if _frames_prediction == 0 then
return _result
end
-- case of supplied movement pattern
_lifetime = _lifetime or 0
if _movement_cycle ~= nil then
local _sign = 1
if _object.flip_x ~= 0 then _sign = -1 end
local _cycle_length = #_movement_cycle
for _i = _lifetime, _lifetime + _frames_prediction - 1 do
local _movement_index = (_i % _cycle_length) + 1
_result[1] = _result[1] + _movement_cycle[_movement_index][1] * _sign
_result[2] = _result[2] + _movement_cycle[_movement_index][2]
end
return _result
end
local _last_velocity_sample = _object.velocity_samples[#_object.velocity_samples]
local _velocity_x = _last_velocity_sample.x + _object.acc.x * _frames_prediction
local _velocity_y = _last_velocity_sample.y + _object.acc.y * _frames_prediction
_result[1] = _result[1] + _velocity_x * _frames_prediction
_result[2] = _result[2] + _velocity_y * _frames_prediction
return _result
end
function predict_frames_before_landing(_player_obj, _max_lookahead_frames)
_max_lookahead_frames = _max_lookahead_frames or 15
if _player_obj.pos_y == 0 then
return 0
end
local _result = -1
for _i = 1, _max_lookahead_frames do
local _pos = predict_object_position(_player_obj, _i)
if _pos[2] <= 3 then
_result = _i
break
end
end
return _result
end
function predict_hitboxes(_player_obj, _frames_prediction)
local _debug = false
local _result = {
frame = 0,
frame_data = nil,
hit_id = 0,
pos_x = 0,
pos_y = 0,
}
local _frame_data = find_move_frame_data(_player_obj.char_str, _player_obj.relevant_animation)
if not _frame_data then return _result end
local _frame_data_meta = frame_data_meta[_player_obj.char_str].moves[_player_obj.relevant_animation]
local _frame = _player_obj.relevant_animation_frame
local _frame_to_check = _frame + _frames_prediction
local _current_animation_pos = {_player_obj.pos_x, _player_obj.pos_y}
local _frame_delta = _frame_to_check - _frame
--print(string.format("update blocking frame %d (freeze: %d)", _frame, _player_obj.current_animation_freeze_frames - 1))
local _next_hit_id = 1
for i = 1, #_frame_data.hit_frames do
if _frame_data.hit_frames[i] ~= nil then
if type(_frame_data.hit_frames[i]) == "number" then
if _frame_to_check >= _frame_data.hit_frames[i] then
_next_hit_id = i
end
else
--print(string.format("%d/%d", _frame_to_check, _frame_data.hit_frames[i].max))
if _frame_to_check > _frame_data.hit_frames[i].max then
_next_hit_id = i + 1
end
end
end
end
if _next_hit_id > #_frame_data.hit_frames then return _result end
if _frame_to_check < #_frame_data.frames then
local _next_frame = _frame_data.frames[_frame_to_check + 1]
local _sign = 1
if _player_obj.flip_x ~= 0 then _sign = -1 end
local _next_attacker_pos = copytable(_current_animation_pos)
local _movement_type = 1
if _frame_data_meta and _frame_data_meta.movement_type then
_movement_type = _frame_data_meta.movement_type
end
if _movement_type == 1 then -- animation base movement
for i = _frame + 1, _frame_to_check do
if i >= 0 then
_next_attacker_pos[1] = _next_attacker_pos[1] + _frame_data.frames[i+1].movement[1] * _sign
_next_attacker_pos[2] = _next_attacker_pos[2] + _frame_data.frames[i+1].movement[2]
end
end
else -- velocity based movement
_next_attacker_pos = predict_object_position(_player_obj, _frame_delta)
end
_result.frame = _frame_to_check
_result.frame_data = _next_frame
_result.hit_id = _next_hit_id
_result.pos_x = _next_attacker_pos[1]
_result.pos_y = _next_attacker_pos[2]
if _debug then
print(string.format(" predicted frame %d: %d hitboxes, hit %d, at %d:%d", _result.frame, #_result.frame_data.boxes, _result.hit_id, _result.pos_x, _result.pos_y))
end
end
return _result
end
function predict_hurtboxes(_player_obj, _frames_prediction)
-- There don't seem to be a need for exact idle animation hurtboxes prediction, so let's return the current hurtboxes for the general case
local _result = _player_obj.boxes
-- If we wake up, we need to foresee the position of the hurtboxes in the frame data so we can block frame 1
if _player_obj.is_wakingup then
local _idle_startup_frame_data = frame_data[_player_obj.char_str].wakeup_to_idle
local _idle_frame_data = frame_data[_player_obj.char_str].idle
if _idle_startup_frame_data ~= nil and _idle_frame_data ~= nil then
local _wakeup_frame = _frames_prediction - _player_obj.remaining_wakeup_time
if _wakeup_frame >= 0 then
if _wakeup_frame <= #_idle_startup_frame_data.frames then
_result = _idle_startup_frame_data.frames[_wakeup_frame + 1].boxes
else
local _frame_index = ((_wakeup_frame - #_idle_startup_frame_data.frames) % #_idle_frame_data.frames) + 1
_result = _idle_frame_data.frames[_frame_index].boxes
end
end
end
end
return _result
end
function update_blocking(_input, _player, _dummy, _mode, _style, _red_parry_hit_count)
local _debug = false
-- ensure variables
_dummy.blocking.blocked_hit_count = _dummy.blocking.blocked_hit_count or 0
_dummy.blocking.expected_attack_animation_hit_frame = _dummy.blocking.expected_attack_animation_hit_frame or 0
_dummy.blocking.expected_attack_hit_id = _dummy.blocking.expected_attack_hit_id or 0
_dummy.blocking.last_attack_hit_id = _dummy.blocking.last_attack_hit_id or 0
_dummy.blocking.is_bypassing_freeze_frames = _dummy.blocking.is_bypassing_freeze_frames or false
_dummy.blocking.bypassed_freeze_frames = _dummy.blocking.bypassed_freeze_frames or 0
function stop_listening_hits(_player_obj)
_dummy.blocking.listening = false
_dummy.blocking.should_block = false
end
function stop_listening_projectiles(_player_obj)
if _dummy.blocking.listening_projectiles then
log(_dummy.prefix, "blocking", "listening proj 0")
end
if _dummy.blocking.should_block_projectile then
log(_dummy.prefix, "blocking", "block proj 0")
end
_dummy.blocking.listening_projectiles = false
_dummy.blocking.should_block_projectile = false
_dummy.blocking.expected_projectile = nil
end
function reset_parry_cooldowns(_player_obj)
memory.writebyte(_player_obj.parry_forward_cooldown_time_addr, 0)
memory.writebyte(_player_obj.parry_down_cooldown_time_addr, 0)
memory.writebyte(_player_obj.parry_air_cooldown_time_addr, 0)
memory.writebyte(_player_obj.parry_antiair_cooldown_time_addr, 0)
end
if not is_in_match then
return
end
-- exit if playing recording
if current_recording_state == 4 then
stop_listening_hits(_dummy)
stop_listening_projectiles(_dummy)
return
end
if _dummy.is_idle then
_dummy.blocking.blocked_hit_count = 0
end
-- blockstring detection
if ((_dummy.blocking.should_block and not _dummy.blocking.randomized_out) or (_dummy.blocking.should_block_projectile and not _dummy.blocking.projectile_randomized_out)) and _dummy.blocking.wait_for_block_string then
_dummy.blocking.block_string = true
_dummy.blocking.wait_for_block_string = false
log(_dummy.prefix, "block_string", string.format("blockstring 1"))
end
if _dummy.blocking.block_string then
if _dummy.has_just_parried or _dummy.has_just_been_hit or (_dummy.remaining_freeze_frames == 0 and _dummy.recovery_time == 0 and _dummy.previous_recovery_time == 1 and not _dummy.blocking.should_block) then
_dummy.blocking.block_string = false
log(_dummy.prefix, "block_string", string.format("blockstring 0 (%d, %d, %d, %d, %d)", to_bit(_dummy.has_just_parried), to_bit(_dummy.has_just_been_hit), _dummy.blocking.last_attack_hit_id, _dummy.blocking.expected_attack_hit_id, _dummy.recovery_time))
end
elseif not _dummy.blocking.wait_for_block_string then
if (
_dummy.has_just_parried or
((_dummy.blocking.expected_attack_hit_id == _dummy.blocking.last_attack_hit_id or not _dummy.blocking.listening) and _dummy.is_idle and _dummy.idle_time > 20)
) then
_dummy.blocking.wait_for_block_string = true
log(_dummy.prefix, "block_string", string.format("wait blockstring (%d, %d, %d)", _dummy.blocking.expected_attack_hit_id, _dummy.blocking.last_attack_hit_id, _dummy.idle_time))
end
end
if _dummy.blocking.is_bypassing_freeze_frames then
_dummy.blocking.bypassed_freeze_frames = _dummy.blocking.bypassed_freeze_frames + 1
end
local _player_relevant_animation_frame = _player.relevant_animation_frame + _dummy.blocking.bypassed_freeze_frames
-- new animation
if _player.has_relevant_animation_just_changed then
if (
frame_data[_player.char_str] and
frame_data[_player.char_str][_player.relevant_animation]
) then
-- known animation, start listening
_dummy.blocking.listening = true
_dummy.blocking.expected_attack_animation_hit_frame = 0
_dummy.blocking.expected_attack_hit_id = 0
_dummy.blocking.last_attack_hit_id = 0
if _dummy.blocking.is_bypassing_freeze_frames then
log(_dummy.prefix, "blocking", string.format("bypassing end&reset"))
end
_dummy.blocking.is_bypassing_freeze_frames = false
_dummy.blocking.bypassed_freeze_frames = 0
_dummy.blocking.should_block = false
reset_parry_cooldowns(_dummy)
log(_dummy.prefix, "blocking", string.format("listening %s", _player.relevant_animation))
if _debug then
print(string.format("%d - %s listening for attack animation \"%s\" (starts at frame %d)", frame_number, _dummy.prefix, _player.relevant_animation, _player.relevant_animation_start_frame))
end
else
-- unknown animation, stop listening
if _dummy.blocking.listening then
log(_dummy.prefix, "blocking", string.format("stopped listening"))
if _debug then
print(string.format("%d - %s stopped listening for attack animation", frame_number, _dummy.prefix))
end
stop_listening_hits(_dummy)
end
end
end
if _mode == 1 or _dummy.throw.listening == true then
stop_listening_hits(_dummy)
stop_listening_projectiles(_dummy)
return
end
function get_meta_hit(_character_str, _move_id, _hit_id)
local _character_meta = frame_data_meta[_character_str]
if _character_meta == nil then return nil end
if _character_meta.moves == nil then return nil end
local _move_meta = _character_meta.moves[_player.relevant_animation]
if _move_meta == nil then return nil end
if _move_meta.hits == nil then return nil end
if _move_meta.hits[_hit_id] == nil then return nil end
return _move_meta.hits[_hit_id]
end
-- update blocked hit count
if _dummy.has_just_blocked or _dummy.has_just_parried then
_dummy.blocking.blocked_hit_count = _dummy.blocking.blocked_hit_count + 1
end
-- check if the hit we are expecting has expired or not
local _hit_expired = false
if _dummy.blocking.expected_attack_hit_id > 0 then
local _frame_data = find_move_frame_data(_player.char_str, _player.relevant_animation)
if _frame_data then
local _hit_frame = _frame_data.hit_frames[_dummy.blocking.expected_attack_hit_id]
local _last_hit_frame = 0
if _hit_frame ~= nil then
if type(_hit_frame) == "number" then
_last_hit_frame = _hit_frame
else
_last_hit_frame = _hit_frame.max
end
else
t_assert(false, string.format("unknown hit id, what is happening ? (anim:%s, hit:%d)", _player.relevant_animation, _dummy.blocking.expected_attack_hit_id))
end
local _frame = frame_number - _player.current_animation_start_frame - _player.current_animation_freeze_frames
_hit_expired = _frame > _last_hit_frame
end
end
if _dummy.blocking.should_block_projectile and _dummy.blocking.projectile_hit_frame < frame_number then
_hit_expired = true
end