BombBloke

encodeSTA.lua

Jan 21st, 2021
596
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -------------------
  2. -- encodeSTA.lua --
  3. -------------------
  4.  
  5. -- For some game, I don't even know what it is lol.
  6.  
  7. -- Run this within a folder with some TXT files in it.
  8. -- STA file conversions will be created in a "newSTA" subfolder.
  9. -- Pre-existing STA files will be replaced without prompting.
  10.  
  11. require "lfs"
  12. require "bit"
  13.  
  14. lfs.mkdir("newSTA")
  15.  
  16. local header = string.char(0x00, 0x41, 0x54, 0x53, 0x20, 0x12, 0x03, 0x13)
  17.  
  18. local function makeLong(long)
  19.     return string.char(bit.rshift(bit.band(long, 0xFF000000), 24), bit.rshift(bit.band(long, 0xFF0000), 16), bit.rshift(bit.band(long, 0xFF00), 8), bit.band(long, 0xFF))
  20. end
  21.  
  22. for entry in lfs.dir(lfs.currentdir()) do if entry:sub(-4):lower() == ".txt" then
  23.     local lines, curLine = {[0] = {}}, 0
  24.     local input = io.open(entry, "r")
  25.     local output = io.open("newSTA/" .. entry:sub(1, #entry - 3) .. "sta", "wb")
  26.    
  27.     output:write(header)
  28.    
  29.     for line in io.lines(entry) do
  30.         if line:sub(1, 24) == "*Do*Not*Edit*This*Line* " then
  31.             curLine = curLine + 1
  32.             lines[curLine] = {}
  33.         else
  34.             lines[curLine][#lines[curLine] + 1] = line
  35.         end
  36.     end
  37.    
  38.     output:write(makeLong(#lines))
  39.     output:write("\00\00\00\00")
  40.    
  41.     for i = 1, #lines do
  42.         local line = table.concat(lines[i], "\n")
  43.         output:write(makeLong(#line))
  44.         output:write(line)
  45.     end
  46.    
  47.     input:close()
  48.     output:close()
  49. end end
RAW Paste Data