Class: Nitro::Rom

Inherits:
Object
  • Object
show all
Includes:
NitroBind
Defined in:
lib/nitro/nitro.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Rom

Returns a new instance of Rom.



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/nitro/nitro.rb', line 391

def initialize(file_path)
  @ptr = FFI::AutoPointer.new(nitroRom_alloc, method(:nitroRom_release))

  # Check whether file exists here because if C++ throws an exception we get a segfault

  if !File.exist?(file_path)
    puts "Error: #{file_path} does not exist"
    raise "Rom initialization failed"
  end

  nitroRom_load(@ptr, file_path)
  @header = HeaderBin.new(nitroRom_getHeader(@ptr))
  @arm9 = ArmBin.new(ptr: FFI::AutoPointer.new(nitroRom_loadArm9(@ptr), method(:armBin_release)))
  @arm7 = ArmBin.new(ptr: FFI::AutoPointer.new(nitroRom_loadArm7(@ptr), method(:armBin_release)))
  @overlay_count = nitroRom_getOverlayCount(@ptr)
  @overlays = Array.new(@overlay_count)
  @overlay_table = OvtBin.new(ptr: nitroRom_getArm9OvT(@ptr), size: @header.arm9_ovt_size)
  define_ov_accessors
end

Instance Attribute Details

#arm7Object (readonly)

Returns the value of attribute arm7.



385
386
387
# File 'lib/nitro/nitro.rb', line 385

def arm7
  @arm7
end

#arm9Object (readonly)

Returns the value of attribute arm9.



385
386
387
# File 'lib/nitro/nitro.rb', line 385

def arm9
  @arm9
end

#headerObject (readonly)

Returns the value of attribute header.



385
386
387
# File 'lib/nitro/nitro.rb', line 385

def header
  @header
end

#overlay_countObject (readonly) Also known as: ov_count

Returns the value of attribute overlay_count.



385
386
387
# File 'lib/nitro/nitro.rb', line 385

def overlay_count
  @overlay_count
end

#overlay_tableObject (readonly) Also known as: ov_table, ovt

Returns the value of attribute overlay_table.



385
386
387
# File 'lib/nitro/nitro.rb', line 385

def overlay_table
  @overlay_table
end

#overlaysObject (readonly)

Returns the value of attribute overlays.



385
386
387
# File 'lib/nitro/nitro.rb', line 385

def overlays
  @overlays
end

Instance Method Details

#each_overlayObject Also known as: each_ov



441
442
443
444
445
# File 'lib/nitro/nitro.rb', line 441

def each_overlay
  @overlay_count.times do |i|
    yield get_overlay(i), i
  end
end

#get_file(id) ⇒ Object



414
415
416
# File 'lib/nitro/nitro.rb', line 414

def get_file(id)
  nitroRom_getFile(id)
end

#get_file_size(id) ⇒ Object



418
419
420
# File 'lib/nitro/nitro.rb', line 418

def get_file_size(id)
  nitroRom_getFileSize(id)
end

#get_overlay(id) ⇒ Object Also known as: get_ov

Raises:

  • (IndexError)


434
435
436
437
438
# File 'lib/nitro/nitro.rb', line 434

def get_overlay(id)
  raise IndexError if id > @overlay_count-1
  load_overlay(id) if @overlays[id].nil?
  @overlays[id]
end

#load_overlay(id) ⇒ Object Also known as: load_ov

Raises:

  • (IndexError)


426
427
428
429
430
431
# File 'lib/nitro/nitro.rb', line 426

def load_overlay(id)
  raise IndexError if id > @overlay_count-1
  ov_ptr = nitroRom_loadOverlay(@ptr, id)
  raise "Failed to load overlay #{id}." if !ov_ptr
  @overlays[id] = OverlayBin.new(id, ptr: FFI::AutoPointer.new(ov_ptr, method(:overlayBin_release)))
end

#nitro_sdk_versionObject



422
423
424
# File 'lib/nitro/nitro.rb', line 422

def nitro_sdk_version
  @arm9.module_params[:sdk_version_id]
end

#sizeObject



410
411
412
# File 'lib/nitro/nitro.rb', line 410

def size
  nitroRom_getSize(@ptr)
end