Class: Bayonetta::MOTFile

Inherits:
LibBin::Structure
  • Object
show all
Includes:
MOTDecoder, MOTRemaper
Defined in:
lib/bayonetta/mot.rb

Defined Under Namespace

Classes: Header, Interpolation1, Interpolation4, Interpolation6, Interpolation7, Key4, Key6, Key7, Record

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MOTRemaper

#remap_bones

Methods included from MOTDecoder

#decode, #decode_frame

Class Method Details

.convert(input_name, output_name, input_big = true, output_big = false) ⇒ Object



700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/bayonetta/mot.rb', line 700

def self.convert(input_name, output_name, input_big = true, output_big = false)
  input = File.open(input_name, "rb")
  id = input.read(4).unpack("a4").first
  raise "Invalid file type #{id}!" unless id == "mot\0".b
  output = File.open(output_name, "wb")
  output.write("\x00"*input.size)
  input.seek(0);
  output.seek(0);

  if is_bayo2?(input)
    mot = MOT2File::new
  else
    mot = self::new
  end
  mot.__convert(input, output, input_big, output_big)

  input.close
  output.close
end

.is_bayo2?(f) ⇒ Boolean

Returns:

  • (Boolean)


671
672
673
674
675
676
677
678
679
680
# File 'lib/bayonetta/mot.rb', line 671

def self.is_bayo2?(f)
  f.rewind
  id = f.read(4)
  raise "Invalid id #{id.inspect}!" if id != "mot\0".b
  uint = "L"
  version = f.read(4).unpack(uint).first
  f.rewind
  return true if version == 0x20120405 || version == 0x05041220
  return false
end

.is_big?(f) ⇒ Boolean

Returns:

  • (Boolean)


682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
# File 'lib/bayonetta/mot.rb', line 682

def self.is_big?(f)
  f.rewind
  block = lambda { |int|
    id = f.read(4)
    raise "Invalid id #{id.inspect}!" if id != "mot\0".b
    f.read(4)
    offset_records = f.read(4).unpack(int).first
    num_records = f.read(4).unpack(int).first
    num_records >= 0 && num_records*12 < f.size && offset_records > 0 && offset_records < f.size
  }
  big = block.call("l>")
  f.rewind
  small = block.call("l<")
  f.rewind
  raise "Invalid data!" unless big ^ small
  return big
end

.load(input_name) ⇒ Object



720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
# File 'lib/bayonetta/mot.rb', line 720

def self.load(input_name)
  if input_name.respond_to?(:read) && input_name.respond_to?(:seek)
    input = input_name
  else
    input = File.open(input_name, "rb")
  end

  if is_bayo2?(input)
    input.close unless input_name.respond_to?(:read) && input_name.respond_to?(:seek)
    return MOT2File::load(input_name)
  end

  input_big = is_big?(input)

  mot = self::new
  mot.instance_variable_set(:@__was_big, input_big)
  mot.__load(input, input_big)
  input.close unless input_name.respond_to?(:read) && input_name.respond_to?(:seek)

  mot
end

Instance Method Details

#dump(output_name, output_big = false) ⇒ Object



746
747
748
749
750
751
752
753
754
755
756
757
758
759
# File 'lib/bayonetta/mot.rb', line 746

def dump(output_name, output_big = false)
  if output_name.respond_to?(:write) && output_name.respond_to?(:seek)
    output = output_name
  else
    output = File.open(output_name, "wb")
  end
  output.rewind

  __set_dump_state(output, output_big, nil, nil)
  __dump_fields
  __unset_dump_state
  output.close unless output_name.respond_to?(:write) && output_name.respond_to?(:seek)
  self
end

#interpolation_type_selector(interpolation_type) ⇒ Object



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'lib/bayonetta/mot.rb', line 653

def interpolation_type_selector(interpolation_type)
  interpolation = nil
  case interpolation_type
  when 1
    interpolation = Interpolation1
  when 4
    interpolation = Interpolation4
  when 6
    interpolation = Interpolation6
  when 7
    interpolation = Interpolation7
  when -1, 0
    interpolation = nil
  else
    raise "Unknown interpolation type: #{interpolation_type}, please report!"
  end
end

#was_big?Boolean

Returns:

  • (Boolean)


742
743
744
# File 'lib/bayonetta/mot.rb', line 742

def was_big?
  @__was_big
end