-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathn_dump_ghost.lua
More file actions
136 lines (119 loc) · 4 KB
/
Copy pathn_dump_ghost.lua
File metadata and controls
136 lines (119 loc) · 4 KB
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
-- Mostly AI-generated
-- Looks for ghost position in memory and dump it to the correct CSV file
dofile("/home/lua/lib/keysyms.lua")
levels = dofile("/home/lua/data/levels.lua")
grounded_levels = dofile("/home/lua/data/grounded_levels.lua")
---- Constants
SAVE_SLOT = 1 -- Save slot number (1–10)
ASSUME_STARTS_PAUSED = false -- Set to false if your game starts unpaused
-- Session state
done = false
triggered = false
need_unpause = false
level = nil
memy=""
memspeed_y=""
shift_pressed = false
original_input_modified = false
dbg = true
ghostFilePath = nil
ghostFile = nil
space_frame = -100
pos_found = false
ramsearch_done = false
pre_reload_skipped = false
function onPaint()
if memy ~= "" then
local y_num = tonumber(memy, 16)
local y = memory.readd(y_num)
local x_num = y_num - 56
local x = memory.readd(x_num)
gui.text(150, 580, string.format("%f ; %f", x, y))
end
end
-- This runs each time the game (process) starts.
function onStartup()
-- Reset session variables (important when restarting the game)
done = false
triggered = false
pos_found = false
-- Request an unpause on first frame if needed
need_unpause = ASSUME_STARTS_PAUSED
memy = ""
memspeed_y = ""
level = movie.getMovieFileName():match("/(%d+-%d+).*%.ltm$")
ghostFilePath = "/home/ghosts/" .. level .. ".csv"
ghostFile = io.open(ghostFilePath, "w")
end
-- Detect Space key press
function onInput()
if not done then
if input.getKey(KEY_SPACE) ~= 0 then
triggered = true
end
end
if not ramsearch_done and grounded_levels[level] and not original_input_modified then
local f = movie.currentFrame()
if f == space_frame then
shift_pressed = input.getKey(KEY_SHIFT)
print(string.format("Shift pressed? %d", shift_pressed))
input.setKey(KEY_SHIFT, 1)
original_input_modified = true
movie.playPause()
end
elseif ramsearch_done and grounded_levels[level] and original_input_modified then
if movie.currentFrame() == space_frame then
-- put original value back
print("Putting back shift value:", shift_pressed)
input.setKey(KEY_SHIFT, shift_pressed)
original_input_modified = false
end
end
end
-- Perform runtime actions (must be done in onFrame)
function onFrame()
local f = movie.currentFrame()
-- Unpause at startup if requested
if need_unpause then
runtime.playPause()
need_unpause = false
end
dofile("/home/lua/lib/n_position_ramsearch.lua")
if ramsearch_done then
if not pre_reload_skipped then
-- since onPaint() is called on the start + 2 frame before
-- the reload, we need to skip this frame to avoid
-- displaying it
pre_reload_skipped = true
else
if memy ~= "" then
local y_num = tonumber(memy, 16)
local y = memory.readd(y_num)
local x_num = y_num - 56
local x = memory.readd(x_num)
-- read keys
local shift = (input.getKey(KEY_SHIFT) ~= 0) and 1 or 0
local left = (input.getKey(KEY_LEFT) ~= 0) and 1 or 0
local right = (input.getKey(KEY_RIGHT) ~= 0) and 1 or 0
-- speed
if memspeed_y ~= "" then
local y_num_speed = tonumber(memspeed_y, 16)
vy = memory.readd(y_num_speed)
local x_num_speed = y_num_speed - 56
vx = memory.readd(x_num_speed)
else
-- give up, we didn't find them
vx = 0.0
vy = 0.0
end
print(string.format("%d,%f,%f,%d,%d,%d,%f,%f", f, x, y, shift, left, right, vx, vy))
ghostFile:write(string.format("%d,%f,%f,%d,%d,%d,%f,%f\n", f - space_frame, x, y, shift, left, right, vx, vy))
end
end
end
-- close ghost file at the end of the movie
if f >= movie.frameCount() then
ghostFile:close()
print("Closed ghost file.")
end
end