-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
81 lines (67 loc) · 1.88 KB
/
client.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
local get_player_hp = function()
return bit.clear(mainmemory.read_u8(0x141924), 7)
end
local get_boss_hp = function()
return bit.clear(mainmemory.read_u8(0x13BF2C), 7)
-- slash beast
-- return bit.clear(mainmemory.read_u8(0x13BFC8), 7)
end
local make_msg = function(player_hp, boss_hp)
local msg = ""
msg = msg .. "ph" .. string.format("%02d", player_hp)
msg = msg .. " bh" .. string.format("%02d", boss_hp)
return msg
end
local get_msg = function()
local player_hp = get_player_hp()
local boss_hp = get_boss_hp()
local msg = make_msg(player_hp, boss_hp)
return msg
end
local set_commands = function(commands)
local buttons = {}
buttons["D-Pad Left"] = false
buttons["D-Pad Right"] = false
buttons["X"] = false
buttons["○"] = false
buttons["□"] = false
for i = 1, commands:len() do
local c = commands:sub(i, i)
if c == "l" then
buttons["D-Pad Left"] = true
elseif c == "r" then
buttons["D-Pad Right"] = true
elseif c == "x" then
buttons["X"] = true
elseif c == "o" then
buttons["○"] = true
elseif c == "s" then
buttons["□"] = true
end
end
joypad.set(buttons, 1)
end
local frameadvance = function()
emu.frameadvance()
end
local disable_hud = function()
mainmemory.write_u8(0x1721DF, 0)
end
comm.socketServerSetTimeout(0)
while true do
local msg = get_msg()
comm.socketServerSend(msg)
local response = comm.socketServerScreenShotResponse()
if response:sub(1, 4) == "load" then
savestate.loadslot(tonumber(response:sub(-1)))
-- disable_hud()
frameadvance()
elseif response == "close" then
client.exit()
elseif response ~= "ok" then
for _ = 1, 6 do
set_commands(response)
frameadvance()
end
end
end