Class: ProconBypassMan::Domains::ProcessingProconBinary

Inherits:
Binary::Base
  • Object
show all
Includes:
HasMutableBinary
Defined in:
lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb

Overview

バイナリの書き換えのみをする

Constant Summary collapse

ALL_ZERO_BIT =
["0"].pack("H*").freeze

Instance Method Summary collapse

Methods included from HasMutableBinary

#binary

Methods inherited from Binary::Base

#binary, #initialize, #raw, #to_procon_reader, #unpack

Constructor Details

This class inherits a constructor from ProconBypassMan::Domains::Binary::Base

Instance Method Details

#set_no_action!Object



9
10
11
12
13
# File 'lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb', line 9

def set_no_action!
  binary[3] = ALL_ZERO_BIT
  binary[4] = ALL_ZERO_BIT
  binary[5] = ALL_ZERO_BIT
end

#write_as_apply_left_analog_stick_cap(cap:) ⇒ Object

Parameters:

  • cap (Integer)


69
70
71
72
# File 'lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb', line 69

def write_as_apply_left_analog_stick_cap(cap: )
  analog_stick_cap = ProconBypassMan::Procon::AnalogStickCap.new(binary)
  binary[6..8] = analog_stick_cap.capped_position(cap_hypotenuse: cap).to_binary
end

#write_as_merge!(target_binary) ⇒ ProconBypassMan::Domains::ProcessingProconBinary

アナログスティックは上書きし、ボタンだけマージする



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb', line 18

def write_as_merge!(target_binary)
  current_buttons = ProconBypassMan::ProconReader.new(binary: binary).pressing
  target_buttons = ProconBypassMan::ProconReader.new(binary: target_binary.raw).pressing

  set_no_action!
  (current_buttons + target_buttons).uniq.each do |button|
    write_as_press_button(button)
  end

  # override analog stick
  tb = [target_binary.raw].pack("H*")
  binary[6] = tb[6]
  binary[7] = tb[7]
  binary[8] = tb[8]
  binary[9] = tb[9]
  binary[10] = tb[10]
  binary[11] = tb[11]

  self
end

#write_as_press_button(button) ⇒ Object

Parameters:

  • button (Symbol)


40
41
42
43
44
45
46
# File 'lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb', line 40

def write_as_press_button(button)
  return if ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)

  button_obj = ProconBypassMan::Procon::Button.new(button)
  value = binary[button_obj.byte_position].unpack("C").first + (2**button_obj.bit_position)
  binary[button_obj.byte_position] = ["%02X" % value.to_s].pack("H*")
end

#write_as_press_button_only(button) ⇒ Object

Parameters:

  • button (Symbol)


63
64
65
66
# File 'lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb', line 63

def write_as_press_button_only(button)
  set_no_action!
  write_as_press_button(button)
end

#write_as_tilt_left_stick(step) ⇒ Object

Parameters:

  • stick (Symbol)

    method



49
50
51
# File 'lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb', line 49

def write_as_tilt_left_stick(step)
  binary[6..8] = ProconBypassMan::Procon::AnalogStickManipulator.new(binary, method: step).to_binary
end

#write_as_unpress_button(button) ⇒ Object

Parameters:

  • button (Symbol)


54
55
56
57
58
59
60
# File 'lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb', line 54

def write_as_unpress_button(button)
  raise "do not press button(#{button}) yet" if not ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)

  button_obj = ProconBypassMan::Procon::Button.new(button)
  value = binary[button_obj.byte_position].unpack("C").first - (2**button_obj.bit_position)
  binary[button_obj.byte_position] = ["%02X" % value.to_s].pack("H*")
end