Class: Bayonetta::MOT2File

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

Defined Under Namespace

Classes: Header, Interpolation1, Interpolation2, Interpolation3, Interpolation4, Interpolation5, Interpolation6, Interpolation7, Interpolation8, Key4, Key5, Key6, Key7, Key8, 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



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/bayonetta/mot.rb', line 419

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);

  unless is_bayo2?(input)
    mot = MOTFile::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)


393
394
395
396
397
398
399
400
401
402
# File 'lib/bayonetta/mot.rb', line 393

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)


404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/bayonetta/mot.rb', line 404

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).unpack(int).first == 0x20120405
  }
  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



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/bayonetta/mot.rb', line 439

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

  unless is_bayo2?(input)
    input.close unless input_name.respond_to?(:read) && input_name.respond_to?(:seek)
    return MOTFile::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



461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/bayonetta/mot.rb', line 461

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
  sz = output.size
  sz = align(sz, 0x4)
  if sz > output.size
    output.seek(sz-1)
    output.write("\x00")
  end

  output.close unless output_name.respond_to?(:write) && output_name.respond_to?(:seek)
  self
end

#interpolation_type_selector(interpolation_type) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/bayonetta/mot.rb', line 366

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

#was_big?Boolean

Returns:

  • (Boolean)


483
484
485
# File 'lib/bayonetta/mot.rb', line 483

def was_big?
  @__was_big
end