Skip to content

Instantly share code, notes, and snippets.

@edbond
Created January 27, 2009 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edbond/53416 to your computer and use it in GitHub Desktop.
Save edbond/53416 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
$KCODE='u'
require 'jcode'
require 'rubygems'
require 'bindata'
class NDSHeader < BinData::MultiValue
array :header, :type => :uint8, :initial_length => 0x68
uint32le :icon_tiles # 0x68
end
class Banner < BinData::MultiValue
uint16le :version
uint16le :crc
array :reserved, :type => :uint8, :initial_length => 28
array :tile, :type => :uint8, :initial_length => 512
array :palette, :type => :uint8, :initial_length => 32
string :japanese, :read_length => 256
string :english, :read_length => 256
end
saves = Dir.glob('../SAVE/*.*')
Dir.glob('*.nds', File::FNM_CASEFOLD).each do |rom|
file = File.open rom
header = NDSHeader.new
header.read file
#puts format("0x%0x", header.icon_tiles)
file.seek header.icon_tiles, IO::SEEK_SET
banner = Banner.new
banner.read file
file.close
romname = rom.split('.').first
title = banner.english.split(/\0/).join.gsub(/[^0-9A-Za-z]/,'_').squeeze("_ ")
puts "mv '#{rom}' '#{title}.nds'" if title != romname
save = saves.select{|s| File.basename(s).downcase.split('.').first == romname.downcase}.first
if save
puts "mv '#{save}' '../SAVE/#{title}.sav'" if "#{save}" != "../SAVE/#{title}.sav"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment