2010-02-06 22:35:06 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require "scanf"
|
2010-02-07 00:10:20 +00:00
|
|
|
require "common.rb"
|
2010-02-06 22:35:06 +00:00
|
|
|
|
|
|
|
filename = ARGV[0]
|
|
|
|
|
2010-04-17 22:34:54 +00:00
|
|
|
set_config(ARGV[1])
|
2010-04-17 19:55:15 +00:00
|
|
|
|
2010-02-06 22:35:06 +00:00
|
|
|
def read_int(file)
|
|
|
|
c1 = file.getc
|
|
|
|
c2 = file.getc
|
|
|
|
c3 = file.getc
|
|
|
|
c4 = file.getc
|
|
|
|
|
|
|
|
result = c1 | (c2 << 8) | (c3 << 16) | (c4 << 24)
|
|
|
|
|
|
|
|
if result > (1 << 31)
|
|
|
|
result -= (1 << 32)
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_state(file)
|
|
|
|
result = {}
|
|
|
|
|
|
|
|
result[:spritenum] = read_int(file)
|
|
|
|
result[:frame] = read_int(file)
|
|
|
|
result[:tics] = read_int(file)
|
|
|
|
result[:action] = read_int(file)
|
|
|
|
result[:nextstate] = read_int(file)
|
|
|
|
result[:misc1] = read_int(file)
|
|
|
|
result[:misc2] = read_int(file)
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def action_pointer_to_s(action_ptr)
|
|
|
|
|
|
|
|
# NULL pointer?
|
|
|
|
|
|
|
|
if action_ptr == 0
|
|
|
|
return "NULL"
|
|
|
|
end
|
|
|
|
|
|
|
|
if ACTION_POINTERS[action_ptr] == nil
|
|
|
|
raise "Action pointer #{action_ptr} unknown!"
|
|
|
|
end
|
|
|
|
|
|
|
|
return ACTION_POINTERS[action_ptr]
|
|
|
|
end
|
|
|
|
|
|
|
|
states = []
|
|
|
|
|
|
|
|
File.open(filename) do |file|
|
2010-04-17 22:34:54 +00:00
|
|
|
file.seek(STATE_OFFSET)
|
2010-02-06 22:35:06 +00:00
|
|
|
|
|
|
|
NUM_STATES.times do
|
|
|
|
states.push(read_state(file))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "state_t states[] = {"
|
|
|
|
|
|
|
|
for state_num in 0...NUM_STATES
|
|
|
|
|
|
|
|
state = states[state_num]
|
|
|
|
|
|
|
|
record = sprintf("{%s, %i, %i, %s, %i, %i, %i },",
|
|
|
|
SPRITE_NAMES[state[:spritenum]],
|
|
|
|
state[:frame],
|
|
|
|
state[:tics],
|
|
|
|
action_pointer_to_s(state[:action]),
|
|
|
|
state[:nextstate],
|
|
|
|
state[:misc1],
|
|
|
|
state[:misc2])
|
|
|
|
|
|
|
|
printf " %s", record
|
|
|
|
|
|
|
|
padding = 55 - record.length
|
|
|
|
|
|
|
|
printf " " * padding
|
|
|
|
printf "// state #%i", state_num
|
|
|
|
|
|
|
|
printf "\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "};"
|
|
|
|
|