-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwiilog.lua
executable file
·71 lines (69 loc) · 1.89 KB
/
wiilog.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
#!/usr/bin/lua
local socket = require("socket")
local tcp = assert(socket.connect(os.getenv("WIILOAD"):match("tcp:(.*)"), 1337))
function decode_85(data)
local a = { data:byte(1,-1) }
local b = 0
for i = 1,#a do
b = (b * 85) + (a[i]-33)
end
return math.floor(b/65536)%256,math.floor(b/256)%256,b%256
end
local scr_mode = false
local scr_header = false
local scr_start = 0
local w,h = nil,nil
local data = {}
while true do
msg, status = tcp:receive("*l")
if msg ~= nil and scr_mode == false then
if msg:find("-- START SCREENSHOT --",nil,true) then
scr_mode = true
scr_header = false
data = {}
print("Receiving screenshot ...")
else
print(msg)
end
elseif msg ~= nil and scr_mode == true then
if msg:find("-- END SCREENSHOT --",nil,true) then
print("Screenshot received (" .. math.ceil(os.time() - scr_start) .. "s), saving ...")
scr_mode = false
scr_header = false
local file = io.open("rawdata.rgb","wb")
for i = 1,#data do
file:write(string.char(data[i]))
end
file:close()
os.execute("convert -size " .. w .. "x" .. h .. " -depth 8 rawdata.rgb wii_screenshot.png")
print("Screenshot saved.")
elseif msg:find("-- ABORT SCREENSHOT --",nil,true) then
print("Aborting screenshot ...")
scr_mode = false
scr_header = false
elseif scr_header == false then
scr_header = true
w, h = msg:match("W: (%d+), H: (%d+)")
w, h = w + 0, h + 0
scr_start = os.time()
else
local rdata = msg:match(": (.*)"):gsub("(....)~(...)",function(thing,amount)
return string.rep(thing,amount+0)
end)
for pixel in rdata:gmatch("....") do
local a,b,c = decode_85(pixel)
data[#data + 1] = a
data[#data + 1] = b
data[#data + 1] = c
end
local y = tonumber(msg:match("(%d-): ")) + 1
print("Y = " .. y .. " (" .. math.floor(y/h*100) .. "%)")
end
else
if status == "closed" then
break
else
print("NOMSG " .. status)
end
end
end