research/hhe/dump-states

91 lines
1.6 KiB
Text
Raw Normal View History

#!/usr/bin/env ruby
require "scanf"
require "common.rb"
filename = ARGV[0]
set_config(ARGV[1])
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|
file.seek(STATE_OFFSET)
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 "};"