forked from pixelchai/FireBoyWaterGirlTAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplay.py
99 lines (81 loc) · 2.53 KB
/
replay.py
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
import os
from util import run
import pyperclip as clip
from mod import SwfModder
path_rec = os.path.join("tas", "replay.txt")
path_out = os.path.join("tas", "adventure", "01.txt")
TRIM_END = True
__FORMAT_MAP = ["u", "r", "l"]
def format_frames(frames):
def _format_frame(frame, hold):
out_inputs = []
for i, frame_input in enumerate(frame):
if frame_input:
out_inputs.append(__FORMAT_MAP[i] + " " + str(hold))
if len(out_inputs) > 0:
return ", ".join(out_inputs) + "\n"
else:
return "s " + str(hold) + "\n"
ret = ""
last_frame = frames[0]
hold_count = 0
for frame in frames:
hold_count += 1
if frame != last_frame:
ret += _format_frame(last_frame, hold_count)
last_frame = frame
hold_count = 0
# flush remaining
if not(TRIM_END and all([x is False for x in last_frame])):
ret += _format_frame(last_frame, hold_count)
return ret
def format_raw_replay():
with open(path_rec, "r") as frec:
f_frames = []
w_frames = []
for rec_line in frec:
frame = [(x == "true") for x in rec_line.rstrip().split(",")]
f_frames.append(frame[:3])
w_frames.append(frame[3:])
with open(path_out, "w") as fout:
fout.write("fireboy: \n")
fout.write(format_frames(f_frames))
fout.write("\nwatergirl: \n")
fout.write(format_frames(w_frames))
def record_replay(m, wait=False):
proc = m.launch_async()
if wait:
input("Press enter when done recording...")
print(clip.paste())
proc.kill()
def auto_workflow():
m = SwfModder(os.path.join("swf", "fbwg-replay.swf"), os.path.join("swf", "fbwg-tas.swf"))
while True:
format_raw_replay()
m.disassemble()
m.mod_all()
m.reassemble()
print("Recording")
record_replay(m)
print("Replaying")
m.disassemble()
m.mod_all()
m.reassemble()
proc = m.launch_async()
input("Press enter when done watching...")
proc.kill()
input("Press enter to go again...")
def workflow_record():
m = SwfModder(os.path.join("swf", "fbwg-replay.swf"), os.path.join("swf", "fbwg-tas.swf"))
m.disassemble()
m.mod_all()
m.reassemble()
m.launch()
format_raw_replay()
m.disassemble()
m.mod_all()
m.reassemble()
if __name__ == '__main__':
# auto_workflow()
workflow_record()
# format_raw_replay()