Class: Bayonetta::EXPFile
- Inherits:
-
LibBin::Structure
- Object
- LibBin::Structure
- Bayonetta::EXPFile
show all
- Defined in:
- lib/bayonetta/exp.rb
Defined Under Namespace
Classes: EXPFileHeader, Entry, Entry1, Entry2, Entry3, Interpolation, Interpolation2, Interpolation4, Interpolation6, Key2, Key4, Key6, Operation, Record
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.convert(input_name, output_name, input_big = true, output_big = false) ⇒ Object
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
|
# File 'lib/bayonetta/exp.rb', line 711
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 == "exp\0".b
output = File.open(output_name, "wb")
output.write("\x00"*input.size)
input.seek(0);
output.seek(0);
if is_bayo2?(input, input_big)
exp = EXPFile2::new
else
exp = self::new
end
exp.__convert(input, output, input_big, output_big)
input.close
output.close
end
|
.is_bayo2?(f, big) ⇒ Boolean
701
702
703
704
705
706
707
708
709
|
# File 'lib/bayonetta/exp.rb', line 701
def self.is_bayo2?(f, big)
f.rewind
id = f.read(4)
uint = "L<"
uint = "L>" if big
version = f.read(4).unpack(uint).first
f.rewind
return version == 0x20110714
end
|
.is_big?(f) ⇒ Boolean
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
# File 'lib/bayonetta/exp.rb', line 682
def self.is_big?(f)
f.rewind
block = lambda { |int|
id = f.read(4)
raise "Invalid id #{id.inspect}!" if id != "exp\0".b
u_a = f.read(4).unpack(int).first
offset_record = f.read(4).unpack(int).first
num_record = f.read(4).unpack(int).first
num_record >= 0 && offset_record > 0 && offset_record < 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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
|
# File 'lib/bayonetta/exp.rb', line 731
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
input_big = is_big?(input)
if is_bayo2?(input, input_big)
exp = EXPFile2::new
else
exp = self::new
end
exp.instance_variable_set(:@__was_big, input_big)
exp.__load(input, input_big)
input.close unless input_name.respond_to?(:read) && input_name.respond_to?(:seek)
exp
end
|
Instance Method Details
#add_entries(hash) ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
|
# File 'lib/bayonetta/exp.rb', line 627
def add_entries(hash)
hash.each { |k, v|
raise "Invalid entry type #{k}!" if k>3 || k<1
v.times {
r = Record::new
r.entry_type = k
r.u_c = -1
@records.insert(-2, r)
case k
when 1
entry = Entry1::new
when 2
entry = Entry2::new
when 3
entry = Entry3::new
end
@entries.insert(-2, entry)
}
}
self
end
|
#apply(tracks, table) ⇒ Object
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
|
# File 'lib/bayonetta/exp.rb', line 600
def apply(tracks, table)
rad_to_deg = 180.0 / Math::PI
deg_to_rad = Math::PI / 180.0
tracks.each { |tr|
tr[3] *= rad_to_deg
tr[4] *= rad_to_deg
tr[5] *= rad_to_deg
}
@records.each_with_index { |r, i|
bone_index = table[r.bone_index]
next unless bone_index
animation_track = r.animation_track
if @entries[i]
value = @entries[i].get_value(tracks, table)
end
if @interpolations[i]
value = @interpolations[i].interpolate(value)
end
tracks[bone_index][animation_track] = value
}
tracks.each { |tr|
tr[3] *= deg_to_rad
tr[4] *= deg_to_rad
tr[5] *= deg_to_rad
}
end
|
#dump(output_name, output_big = false) ⇒ Object
751
752
753
754
755
756
757
758
759
760
761
762
763
764
|
# File 'lib/bayonetta/exp.rb', line 751
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
|
#recompute_layout ⇒ Object
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
|
# File 'lib/bayonetta/exp.rb', line 649
def recompute_layout
@header.num_records = @records.length
last_offset = @header.offset_records
last_offset += @records.collect(&:__size).reduce(:+)
table = @records.zip(@entries).to_h
reverse_table = table.invert
interpolation_table = @records.zip(@interpolations).to_h
reverse_interpolation_table = interpolation_table.invert
@records.sort_by! { |r| [r.bone_index, r.animation_track] }
@entries.sort_by! { |e| e ? [e.bone_index, e.animation_track] : [32767, -1] }
@entries.each { |e|
if e
reverse_table[e].offset = last_offset
last_offset += e.__size
else
reverse_table[e].offset = 0
end
}
@interpolations.each { |i|
if i
reverse_interpolation_table[i].offset_interpolation = last_offset
last_offset += i.size
end
}
@entries = @records.collect { |r| table[r] }
@interpolation = @records.collect { |r| interpolation_table[r] }
self
end
|
#was_big? ⇒ Boolean
596
597
598
|
# File 'lib/bayonetta/exp.rb', line 596
def was_big?
@__was_big
end
|