Last active
October 6, 2020 20:56
-
-
Save x4fx77x4f/5aebb572ca4bf1ac3fd7bcad18e4ce09 to your computer and use it in GitHub Desktop.
clientside Lua script to save Wired Digital Screens to PGM/PPM files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local mem = LocalPlayer():GetEyeTrace().Entity | |
if mem then | |
mem = mem.Memory1 | |
end | |
if not mem then | |
print("either there is no entity or the entity has no memory") | |
return | |
end | |
local width = mem[1048573] or 0 | |
local height = mem[1048572] or 0 | |
local mode = mem[1048569] or 0 | |
local filename = "digiscreen.ppm.dat" | |
local i = 1 | |
while file.Exists(filename, "DATA") do | |
i = i+1 | |
filename = "digiscreen_"..i..".ppm.dat" | |
end | |
print(string.format("saving to %q (%d x %d @ mode %d)", filename, width, height, mode)) | |
local handle = file.Open(filename, "wb", "DATA") | |
if mode == 1 then | |
handle:Write("P6 "..width.." "..height.." 255\n") | |
for i=0, width*height*3-1, 3 do | |
handle:WriteByte(math.Clamp(mem[i] or 0, 0, 255)) | |
handle:WriteByte(math.Clamp(mem[i+1] or 0, 0, 255)) | |
handle:WriteByte(math.Clamp(mem[i+2] or 0, 0, 255)) | |
end | |
elseif mode == 2 then | |
handle:Write("P6 "..width.." "..height.." 255\n") | |
for i=0, width*height-1 do | |
local c = mem[i] or 0 | |
handle:WriteByte(math.Clamp(math.floor(c/0x10000) % 0x100, 0, 255)) | |
handle:WriteByte(math.Clamp(math.floor(c/0x100) % 0x100, 0, 255)) | |
handle:WriteByte(math.Clamp(c % 0x100, 0, 255)) | |
end | |
elseif mode == 3 then | |
handle:Write("P6 "..width.." "..height.." 255\n") | |
for i=0, width*height-1 do | |
local c = mem[i] or 0 | |
handle:WriteByte(math.Clamp(math.floor(c/1000000) % 1000, 0, 255)) | |
handle:WriteByte(math.Clamp(math.floor(c/1000) % 1000, 0, 255)) | |
handle:WriteByte(math.Clamp(c % 1000, 0, 255)) | |
end | |
elseif mode == 4 then | |
handle:Write("P5 "..width.." "..height.." 255\n") | |
for i=0, width*height-1 do | |
handle:WriteByte(math.Clamp(mem[i], 0, 255)) | |
end | |
else -- invalid color modes are mode 0 | |
handle:Write("P6 "..width.." "..height.." 10\n") | |
for i=0, width*height-1 do | |
local c = mem[i] or 0 | |
handle:WriteByte(math.Clamp(math.floor((c % 1000000)/100000), 0, 255)) | |
handle:WriteByte(math.Clamp(math.floor((c % 100000)/10000), 0, 255)) | |
handle:WriteByte(math.Clamp((c % 10000)/1000, 0, 255)) | |
end | |
end | |
handle:Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.