Jump to content
Sign in to follow this  
quiznos00

Chip's Challenge Level Splicer

Recommended Posts

CCLP4 voting is soon upon us, and I thought I'd share the script I wrote to assemble the voting packs. It is available on PasteBin.

 

This Python script takes in an text file consisting of one or more lines of the filename of a level set and a level number, separated by a tab. It outputs a new level set consisting of the specified levels. Hopefully someone else will find it useful, and don't hesitate to ask questions about it  :happy:

  • Upvote 4

Share this post


Link to post
Share on other sites

Just had a quick look at the code, the syntax should be

file[tab]number

but the program has several flaws, it doesn't change the level numbers (so the output will not be correct), for the input it doesn't check for empty lines, so it will try to open a file it can't at the end of file if it is, as in most text files, in it's own line, and crash (just insert something like if pair[0]=="": continue in line 15 to avoid it), and it opens all input files multiple times for no apparent reason...
 
This should work properly:

(in Lua)

function levels(s)
  local function g(i) return s:byte(i)+s:byte(i+1)*256 end
  local n, p, t = g(5), 7, {}
  for i=1, n do
    local a = g(p)
    table.insert(t,s:sub(p+4, p+a+1))
    p = p+a+2
  end
  return t
end

if #arg~=2 then
  io.stderr:write("Usage: "..arg[0].." input output")
  os.exit(1)
end

local inp = assert(io.open(arg[1], "r"))
local dat = inp:read("*a")
inp:close()

local a = {}
for line in dat:gmatch("[^\r\n]+") do
  local t = {}
  for w in line:gmatch("%S+") do table.insert(t,w) end
  local inp = assert(io.open(table.remove(t,1), "rb"))
  local ls = levels(inp:read("*a"))
  inp:close()
  for _,x in ipairs(t) do table.insert(a,ls[tonumber(x)]) end
end

function b(n) return string.char(n%256,math.floor(n/256)) end
local out = assert(io.open(arg[2], "wb"))
out:write("\xac\xaa\x02\x00"..b(#a))
for i,x in ipairs(a) do out:write(b(#x+2)..b(i)..x) end
out:close()

and you can specify multiple levels per set per line and use arbitrary white space as separator.

CCLP1.dat 123 2
JoshL5.dat 9
  • Upvote 2

Share this post


Link to post
Share on other sites

Yeah, there is minimal error checking in the code since it was mainly for personal use. And I believe a level editor will fix the problem of the incorrect level number headers (though a set will play fine even when these are incorrect). Maybe I'll release an update to the code :D

 

For Miika, here is an example of a ten-level input file (CCZone doesn't support tabs so just imagine the final space is a tab):

Josh-CCLP4.dat 60
IHNN1-CCLP4 mix.dat 41
Josh-CCLP4.dat 195
C1059-CCLP4.dat 60
IHNN1-CCLP4 mix.dat 17
Josh-CCLP4.dat 180
IHNN1-CCLP4 mix.dat 160
ZK4 submissions.dat 23
The Other 100 Tiles.dat 71
C1059-CCLP4.dat 34
  • Upvote 2

Share this post


Link to post
Share on other sites

but the program has several flaws, it doesn't change the level numbers (so the output will not be correct), for the input it doesn't check for empty lines, so it will try to open a file it can't at the end of file if it is, as in most text files, in it's own line, and crash (just insert something like if pair[0]=="": continue in line 15 to avoid it), and it opens all input files multiple times for no apparent reason...

 

and you can specify multiple levels per set per line and use arbitrary white space as separator.

 

Rewrote my script just for kicks. I polished up stuff, the internal level numbers are now correct, input checks for empty lines, and files are only opened/closed once, though this method isn't necessarily more efficient than opening/closing files on a line-by-line basis, especially if you have lots of unique level sets. Added the multiple levels per line option too.

 

Now that all the CCLP4 packs have been assembled and released, I'd have to say the first script I wrote worked fine  :P I kept the tab separation between the filename and level numbers, because some level sets have spaces in their names, unfortunately.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×