Advertisement
gamax92

Mniip's and Gamax92's TPT File Transfer

Sep 18th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. function rbyte(x,y,z)
  2. r=0
  3. if tpt.get_property('type',x,y)==28 then
  4. if z==0 then
  5. r=tpt.get_property('life',x,y)%256
  6. elseif z==1 then
  7. r=math.floor(tpt.get_property('life',x,y)/256)
  8. elseif z==2 then
  9. r=tpt.get_property('vx',x,y)*16+127
  10. elseif z==3 then
  11. r=tpt.get_property('vy',x,y)*16+127
  12. elseif z==4 then
  13. r=tpt.get_property('temp',x,y)
  14. elseif z==5 then
  15. r=tpt.get_property('tmp',x,y)%256
  16. elseif z==6 then
  17. r=math.floor(tpt.get_property('tmp',x,y)/256)
  18. end
  19. end
  20. return r
  21. end
  22.  
  23. function setpx(x,y,n,z)
  24. if z==0 then
  25. tpt.delete(x,y)
  26. tpt.create(x,y,'dmnd')
  27. tpt.set_property('life',n,x,y)
  28. elseif z==1 then
  29. tpt.set_property('life',256*n+tpt.get_property('life',x,y),x,y)
  30. elseif z==2 then
  31. tpt.set_property('vx',n/16-7.9375,x,y)
  32. elseif z==3 then
  33. tpt.set_property('vy',n/16-7.9375,x,y)
  34. elseif z==4 then
  35. tpt.set_property('temp',n,x,y)
  36. elseif z==5 then
  37. tpt.set_property('tmp',n,x,y)
  38. elseif z==6 then
  39. tpt.set_property('tmp',256*n+tpt.get_property('tmp',x,y),x,y)
  40. end
  41. end
  42.  
  43. function upload(name)
  44. local f=io.open(name,'rb')
  45. if f == nil then
  46. tpt.log(name .. " does not exist.")
  47. else
  48. setpx(4,4,165,0)
  49. setpx(5,4,0,0)
  50. setpx(6,4,f:seek('end')%256,0)
  51. setpx(7,4,math.floor(f:seek('end')/256)%256,0)
  52. setpx(8,4,math.floor(f:seek('end')/65536)%256,0)
  53. setpx(9,4,math.floor(f:seek('end')/16777216)%256,0)
  54. for j=1,string.len(name) do
  55. setpx(9+j,4,string.byte(string.sub(name,j,j)),0)
  56. end
  57. f:seek("set",0)
  58. local n=0
  59. local bts=f:read(1)
  60. while not(bts==nil) do
  61. setpx(4+math.floor(n%4200/7),5+math.floor(n/4200),string.byte(bts),n%7)
  62. n=n+1
  63. bts=f:read(1)
  64. end
  65. f:close()
  66. end
  67. end
  68.  
  69. function download()
  70. if rbyte(4,4,0) == 165 then
  71. local params=rbyte(5,4,0)
  72. local name=''
  73. local fsize=rbyte(6,4,0)+rbyte(7,4,0)*256+rbyte(8,4,0)*65536+rbyte(9,4,0)*16777216
  74. i=0
  75. while ((rbyte(10+i,4,0)>31)and(rbyte(10+i,4,0)<128))and(i<73) do
  76. name=name..string.char(rbyte(10+i,4,0))
  77. i=i+1
  78. end
  79. if name=='' then name='untitled.tpt' end
  80. f=io.open(name, 'wb')
  81. i=0
  82. for i=0,fsize-1 do
  83. f:write(string.char(rbyte(4+math.floor((i/7))%600,5+math.floor((i/7/600)),i%7)))
  84. end
  85. f:close()
  86. end
  87. end
  88.  
  89. function filedetect()
  90. if rbyte(4,4,0) == 164 then setpx(4,4,165,0) end
  91. if rbyte(4,4,0) == 165 then
  92. tpt.drawrect(10, 187, 55, 12)
  93. tpt.drawrect(11, 188, 54, 11, 127, 127, 127)
  94. tpt.fillrect(10, 187, 55, 12, 192, 192, 192)
  95. tpt.drawtext(17, 190, "Download")
  96. i=0
  97. name=""
  98. while ((rbyte(10+i,4,0)>31)and(rbyte(10+i,4,0)<128))and(i<73) do
  99. name=name..string.char(rbyte(10+i,4,0))
  100. i=i+1
  101. end
  102. FileLength = rbyte(6,4,0)+rbyte(7,4,0)*256+rbyte(8,4,0)*65536+rbyte(9,4,0)*16777216
  103. FileSize = "B"
  104. if FileLength > 999 then FileLength = math.floor((FileLength / 1024) + 0.5) FileSize = "KB" end
  105. if FileLength > 999 then FileLength = math.floor((FileLength / 1024 * 10) + 0.5)/10 FileSize = "MB" end
  106. tpt.drawtext(67, 190, "-" .. tostring(FileLength) .. FileSize .. "-" .. name, 0, 127, 127, 255)
  107. end
  108. end
  109.  
  110. function downmouse(x, y)
  111. if rbyte(4,4,0) == 165 and x > 9 and x < 56 and y > 187 and y < 200 then
  112. download()
  113. end
  114. end
  115.  
  116. tpt.register_step(filedetect)
  117. tpt.register_mouseclick(downmouse)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement