procon_bypass_man 0.1.14 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -0
  3. data/.github/workflows/release.yml +33 -0
  4. data/CHANGELOG.md +15 -0
  5. data/Gemfile +1 -0
  6. data/Gemfile.lock +28 -7
  7. data/README.md +26 -3
  8. data/Steepfile +31 -17
  9. data/docs/setting/left-analogstick-cap.md +60 -0
  10. data/docs/setup_raspi.md +2 -0
  11. data/docs/setup_raspi.mitamae.rb +7 -8
  12. data/docs/setup_raspi_by_mitamae.md +37 -1
  13. data/lib/ext/em_pure_ruby.rb +25 -0
  14. data/lib/procon_bypass_man/background.rb +0 -1
  15. data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +35 -13
  16. data/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +1 -0
  17. data/lib/procon_bypass_man/buttons_setting_configuration/validator.rb +36 -0
  18. data/lib/procon_bypass_man/buttons_setting_configuration.rb +28 -13
  19. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +6 -4
  20. data/lib/procon_bypass_man/bypass.rb +13 -6
  21. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +50 -1
  22. data/lib/procon_bypass_man/commands/print_message_command.rb +8 -0
  23. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +3 -1
  24. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +1 -2
  25. data/lib/procon_bypass_man/commands.rb +1 -0
  26. data/lib/procon_bypass_man/configuration.rb +32 -1
  27. data/lib/procon_bypass_man/domains/binary/base.rb +25 -0
  28. data/lib/procon_bypass_man/domains/binary/has_immutable_binary.rb +5 -0
  29. data/lib/procon_bypass_man/domains/binary/has_mutable_binary.rb +5 -0
  30. data/lib/procon_bypass_man/domains/binary/inbound_procon_binary.rb +9 -0
  31. data/lib/procon_bypass_man/domains/binary/processing_procon_binary.rb +66 -0
  32. data/lib/procon_bypass_man/domains.rb +11 -0
  33. data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
  34. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
  35. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
  36. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
  37. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
  38. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
  39. data/lib/procon_bypass_man/plugins.rb +11 -0
  40. data/lib/procon_bypass_man/processor.rb +4 -5
  41. data/lib/procon_bypass_man/procon/button.rb +11 -0
  42. data/lib/procon_bypass_man/procon/button_collection.rb +9 -11
  43. data/lib/procon_bypass_man/procon/layer_changer.rb +3 -2
  44. data/lib/procon_bypass_man/procon/macro_registry.rb +8 -5
  45. data/lib/procon_bypass_man/procon/mode_registry.rb +4 -4
  46. data/lib/procon_bypass_man/procon/press_button_aware.rb +9 -7
  47. data/lib/procon_bypass_man/procon/user_operation.rb +46 -63
  48. data/lib/procon_bypass_man/procon/{analog_stick.rb → value_objects/analog_stick.rb} +3 -4
  49. data/lib/procon_bypass_man/procon/value_objects/procon_reader.rb +34 -0
  50. data/lib/procon_bypass_man/procon.rb +18 -16
  51. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +4 -0
  52. data/lib/procon_bypass_man/remote_pbm_action/{lib → commands}/update_remote_pbm_action_status_command.rb +0 -0
  53. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +4 -0
  54. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
  55. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +4 -0
  56. data/lib/procon_bypass_man/{value_objects → remote_pbm_action/value_objects}/remote_pbm_action_object.rb +0 -0
  57. data/lib/procon_bypass_man/remote_pbm_action.rb +3 -2
  58. data/lib/procon_bypass_man/runner.rb +4 -4
  59. data/lib/procon_bypass_man/scheduler.rb +0 -7
  60. data/lib/procon_bypass_man/support/compress_array.rb +5 -0
  61. data/lib/procon_bypass_man/support/http_client.rb +4 -0
  62. data/lib/procon_bypass_man/support/on_memory_cache.rb +3 -1
  63. data/lib/procon_bypass_man/support/report_http_client.rb +3 -3
  64. data/lib/procon_bypass_man/support/server_pool.rb +4 -0
  65. data/lib/procon_bypass_man/version.rb +1 -1
  66. data/lib/procon_bypass_man/websocket/pbm_job_client.rb +90 -0
  67. data/lib/procon_bypass_man.rb +50 -33
  68. data/procon_bypass_man.gemspec +2 -0
  69. data/project_template/README.md +10 -5
  70. data/project_template/app.rb +1 -1
  71. data/project_template/setting.yml +8 -8
  72. data/sig/main.rbs +226 -41
  73. data/sig/on_memory_cache.rbs +16 -0
  74. metadata +59 -20
  75. data/lib/procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job.rb +0 -29
  76. data/lib/procon_bypass_man/boot_message.rb +0 -48
  77. data/lib/procon_bypass_man/commands/run_local_shell_command.rb +0 -6
  78. data/lib/procon_bypass_man/procon_reader.rb +0 -31
  79. data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +0 -15
  80. data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +0 -15
  81. data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +0 -15
  82. data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +0 -15
  83. data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +0 -57
  84. data/lib/procon_bypass_man/splatoon2/version.rb +0 -7
  85. data/lib/procon_bypass_man/splatoon2.rb +0 -11
@@ -15,14 +15,21 @@ module ProconBypassMan
15
15
  :neutral_position
16
16
 
17
17
  def self.instance
18
- @@current_context_key ||= :main
19
18
  @@context ||= {}
20
- @@context[@@current_context_key] ||= new
19
+ @@context[current_context_key] ||= new
20
+ end
21
+
22
+ def self.current_context_key
23
+ @@current_context_key ||= :main
24
+ end
25
+
26
+ def self.instance=(val)
27
+ @@context[current_context_key] = val
21
28
  end
22
29
 
23
30
  def self.switch_new_context(key)
24
31
  @@context[key] = new
25
- previous_key = @@current_context_key
32
+ previous_key = current_context_key
26
33
  if block_given?
27
34
  @@current_context_key = key
28
35
  value = yield(@@context[key])
@@ -35,23 +42,31 @@ module ProconBypassMan
35
42
 
36
43
  def initialize
37
44
  reset!
45
+ self.class.instance = self
38
46
  end
39
47
 
40
48
  module ManualMode
41
49
  def self.name
42
- 'manual'
50
+ :manual
43
51
  end
44
52
  end
45
53
  def layer(direction, mode: ManualMode, &block)
46
- mode_name = case mode
47
- when String
48
- mode.to_sym
49
- when Symbol
50
- mode
51
- else
52
- mode.name.to_sym
53
- end
54
- unless ([ManualMode.name.to_sym] + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
54
+ if ProconBypassMan::ButtonsSettingConfiguration::ManualMode == mode
55
+ mode_name = mode.name
56
+ else
57
+ mode_name = case mode
58
+ when ProconBypassMan::ButtonsSettingConfiguration::ManualMode
59
+ mode.name
60
+ when String
61
+ mode.to_sym
62
+ when Symbol
63
+ mode
64
+ else
65
+ mode.to_s.to_sym
66
+ end
67
+ end
68
+
69
+ unless ([ManualMode.name] + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
55
70
  raise("#{mode_name} mode is unknown")
56
71
  end
57
72
 
@@ -28,10 +28,12 @@ class ProconBypassMan::Bypass
28
28
  end
29
29
  end
30
30
 
31
- ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
32
- ProconBypassMan::ReportPressedButtonsJob.perform_async(
33
- ProconBypassMan::ProconReader.new(binary: bypass_value.binary).to_hash
34
- )
31
+ if ProconBypassMan.config.enable_reporting_pressed_buttons
32
+ ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
33
+ ProconBypassMan::ReportPressedButtonsJob.perform_async(
34
+ bypass_value.binary.to_procon_reader.to_hash
35
+ )
36
+ end
35
37
  end
36
38
  end
37
39
  end
@@ -5,7 +5,7 @@ class ProconBypassMan::Bypass
5
5
 
6
6
  class BypassValue < Struct.new(:binary, :sent)
7
7
  def to_text
8
- "#{binary.unpack("H*").first} #{'x' unless sent}"
8
+ "#{binary.unpack.first} #{'x' unless sent}"
9
9
  end
10
10
  end
11
11
 
@@ -21,14 +21,14 @@ class ProconBypassMan::Bypass
21
21
  def send_gadget_to_procon!
22
22
  monitor.record(:start_function)
23
23
  input = nil
24
- self.bypass_value = BypassValue.new(input, sent = false)
24
+ self.bypass_value = BypassValue.new(nil, sent = false)
25
25
 
26
26
  run_callbacks(:send_gadget_to_procon) do
27
27
  begin
28
28
  break if $will_terminate_token
29
29
  # TODO blocking readにしたいが、接続時のフェーズによって長さが違うので厳しい
30
30
  input = self.gadget.read_nonblock(64)
31
- self.bypass_value.binary = input
31
+ self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: input)
32
32
  rescue IO::EAGAINWaitReadable
33
33
  monitor.record(:eagain_wait_readable_on_read)
34
34
  sleep(0.001)
@@ -50,14 +50,14 @@ class ProconBypassMan::Bypass
50
50
  def send_procon_to_gadget!
51
51
  monitor.record(:start_function)
52
52
  output = nil
53
- self.bypass_value = BypassValue.new(output, sent = false)
53
+ self.bypass_value = BypassValue.new(nil, sent = false)
54
54
 
55
55
  run_callbacks(:send_procon_to_gadget) do
56
56
  begin
57
57
  break if $will_terminate_token
58
58
  Timeout.timeout(1) do
59
59
  output = self.procon.read(64)
60
- self.bypass_value.binary = output
60
+ self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: output)
61
61
  end
62
62
  rescue Timeout::Error
63
63
  ProconBypassMan.logger.debug { "read timeout! do sleep. by send_procon_to_gadget!" }
@@ -72,8 +72,15 @@ class ProconBypassMan::Bypass
72
72
  retry
73
73
  end
74
74
 
75
+ # blocking readをしているのでnilが入ることはないが、雑なテストでnilが通るので分岐を入れる。できれば消したい
76
+ break if output.nil?
77
+
75
78
  begin
76
- self.gadget.write_nonblock(ProconBypassMan::Processor.new(output).process)
79
+ self.gadget.write_nonblock(
80
+ ProconBypassMan::Processor.new(
81
+ ProconBypassMan::Domains::InboundProconBinary.new(binary: output)
82
+ ).process
83
+ )
77
84
  self.bypass_value.sent = true
78
85
  rescue IO::EAGAINWaitReadable
79
86
  monitor.record(:eagain_wait_readable_on_write)
@@ -1,7 +1,56 @@
1
1
  class ProconBypassMan::PrintBootMessageCommand
2
+ class BootMessage
3
+ def initialize
4
+ @table = {}
5
+ @table[:ruby_version] = RUBY_VERSION
6
+ @table[:pbm_version] = ProconBypassMan::VERSION
7
+ @table[:pid] = $$
8
+ @table[:root_path] = ProconBypassMan.root
9
+ @table[:pid_path] = ProconBypassMan.pid_path
10
+ @table[:setting_path] = ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path
11
+ @table[:uptime_from_boot] = ProconBypassMan::Uptime.from_boot
12
+ @table[:use_pbmenv] = !(!!`which pbmenv`.empty?)
13
+ @table[:session_id] = ProconBypassMan.session_id
14
+ @table[:device_id] = ProconBypassMan.device_id
15
+
16
+ # 開発中のHEADを取りたかったけど、Gem::Specification経由から取得する必要がありそう
17
+ # build_version = `git rev-parse --short HEAD`.chomp
18
+ # if build_version.empty?
19
+ # @table[:build_version] = 'release version'
20
+ # else
21
+ # @table[:build_version] = build_version
22
+ # end
23
+
24
+ # build version: #{@table[:build_version]}
25
+ end
26
+
27
+ # @return [String]
28
+ def to_s
29
+ booted_message = <<~EOF
30
+ ----
31
+ RUBY_VERSION: #{@table[:ruby_version]}
32
+ ProconBypassMan::VERSION: #{@table[:pbm_version]}
33
+ pid: #{@table[:pid]}
34
+ root: #{@table[:root_path]}
35
+ pid_path: #{@table[:pid_path]}
36
+ setting_path: #{@table[:setting_path]}
37
+ uptime from boot: #{@table[:uptime_from_boot]} sec
38
+ use_pbmenv: #{@table[:use_pbmenv]}
39
+ session_id: #{ProconBypassMan.session_id}
40
+ device_id: #{ProconBypassMan.device_id}
41
+ ----
42
+ EOF
43
+ end
44
+
45
+ # @return [Hash]
46
+ def to_hash
47
+ @table
48
+ end
49
+ end
50
+
2
51
  # @return [void]
3
52
  def self.execute
4
- message = ProconBypassMan::BootMessage.new
53
+ message = BootMessage.new
5
54
  ProconBypassMan::ReportBootJob.perform_async(message.to_hash)
6
55
  ProconBypassMan::ReportLoadConfigJob.perform_async(ProconBypassMan.config.raw_setting)
7
56
  puts message.to_s
@@ -0,0 +1,8 @@
1
+ class ProconBypassMan::PrintMessageCommand
2
+ # @return [void]
3
+ # @param [String] text
4
+ def self.execute(text: )
5
+ ProconBypassMan.logger.info text
6
+ puts text
7
+ end
8
+ end
@@ -10,8 +10,10 @@ class ProconBypassMan::RunRemotePbmActionDispatchCommand
10
10
  ProconBypassMan::RemotePbmAction::StopPbmAction.new(pbm_job_uuid: uuid).run!(job_args: {})
11
11
  when ProconBypassMan::RemotePbmAction::ACTION_REBOOT_OS
12
12
  ProconBypassMan::RemotePbmAction::RebootOsAction.new(pbm_job_uuid: uuid).run!(job_args: {})
13
+ when ProconBypassMan::RemotePbmAction::ACTION_RESTORE_SETTING
14
+ ProconBypassMan::RemotePbmAction::RestorePbmSettingAction.new(pbm_job_uuid: uuid).run!(job_args: job_args)
13
15
  else
14
- ProconBypassMan::SendErrorCommand.execute(error: "#{action}は対応していないアクションです")
16
+ raise "#{action}は対応していないアクションです"
15
17
  end
16
18
  rescue ProconBypassMan::RemotePbmAction::ActionUnexpectedError => e
17
19
  ProconBypassMan::SendErrorCommand.execute(error: e)
@@ -1,8 +1,7 @@
1
1
  class ProconBypassMan::SendReloadConfigEventCommand
2
2
  # @return [void]
3
3
  def self.execute
4
- puts "設定ファイルの再読み込みができました"
5
- ProconBypassMan.logger.info "設定ファイルの再読み込みができました"
4
+ ProconBypassMan::PrintMessageCommand.execute(text: "設定ファイルの再読み込みができました")
6
5
  ProconBypassMan::ReportReloadConfigJob.perform_async(
7
6
  ProconBypassMan.config.raw_setting
8
7
  )
@@ -1,4 +1,5 @@
1
1
  require "procon_bypass_man/commands/print_boot_message_command"
2
+ require "procon_bypass_man/commands/print_message_command"
2
3
  require "procon_bypass_man/commands/write_session_id_command"
3
4
  require "procon_bypass_man/commands/write_device_id_command"
4
5
  require "procon_bypass_man/commands/send_reload_config_event_command"
@@ -41,7 +41,7 @@ class ProconBypassMan::Configuration
41
41
  end
42
42
 
43
43
  attr_accessor :enable_critical_error_logging
44
- attr_writer :verbose_bypass_log, :raw_setting
44
+ attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons
45
45
 
46
46
  def root=(path)
47
47
  @root = path
@@ -111,6 +111,33 @@ class ProconBypassMan::Configuration
111
111
  @server_pool ||= ProconBypassMan::ServerPool.new(servers: api_servers)
112
112
  end
113
113
 
114
+ # @return [String, NilClass]
115
+ def current_server
116
+ server_pool.server
117
+ end
118
+
119
+ # @return [String, NilClass]
120
+ def current_ws_server
121
+ if (uri = URI.parse(server_pool.server))
122
+ if uri.port == 443
123
+ return "ws://#{uri.host}"
124
+ else
125
+ return "ws://#{uri.host}:#{uri.port}"
126
+ end
127
+ end
128
+ rescue URI::InvalidURIError
129
+ nil
130
+ end
131
+
132
+ # @return [String, NilClass]
133
+ def current_ws_server_url
134
+ return unless current_ws_server
135
+ "#{current_ws_server}/websocket/"
136
+ end
137
+
138
+ # @return [Boolean]
139
+ def enable_ws?; !!current_server; end
140
+
114
141
  # @return [Array<String>]
115
142
  def api_servers
116
143
  if !!ENV["API_SERVER"]
@@ -127,4 +154,8 @@ class ProconBypassMan::Configuration
127
154
  def raw_setting
128
155
  @raw_setting ||= {}
129
156
  end
157
+
158
+ def enable_reporting_pressed_buttons
159
+ @enable_reporting_pressed_buttons ||= false
160
+ end
130
161
  end
@@ -0,0 +1,25 @@
1
+ class ProconBypassMan::Domains::Binary::Base
2
+ # @param [String] binary
3
+ def initialize(binary: )
4
+ @binary = binary
5
+ end
6
+
7
+ # @return [String] バイナリ
8
+ def binary
9
+ raise NotImplementedError
10
+ end
11
+
12
+ # @return [String]
13
+ def raw
14
+ binary
15
+ end
16
+
17
+ def unpack
18
+ binary.unpack("H*")
19
+ end
20
+
21
+ # @return [ProconBypassMan::ProconReader]
22
+ def to_procon_reader
23
+ ProconBypassMan::ProconReader.new(binary: binary)
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module ProconBypassMan::Domains::HasImmutableBinary
2
+ def binary
3
+ @binary.freeze
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module ProconBypassMan::Domains::HasMutableBinary
2
+ def binary
3
+ @binary
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ # proconから取得したばかりのバイナリ
2
+ class ProconBypassMan::Domains::InboundProconBinary < ProconBypassMan::Domains::Binary::Base
3
+ include ProconBypassMan::Domains::HasImmutableBinary
4
+
5
+ # @return [Boolean]
6
+ def user_operation_data?
7
+ binary[0] == "\x30".b
8
+ end
9
+ end
@@ -0,0 +1,66 @@
1
+ # バイナリの書き換えのみをする
2
+ class ProconBypassMan::Domains::ProcessingProconBinary < ProconBypassMan::Domains::Binary::Base
3
+ include ProconBypassMan::Domains::HasMutableBinary
4
+
5
+ ALL_ZERO_BIT = ["0"].pack("H*").freeze
6
+
7
+ def set_no_action!
8
+ binary[3] = ALL_ZERO_BIT
9
+ binary[4] = ALL_ZERO_BIT
10
+ binary[5] = ALL_ZERO_BIT
11
+ end
12
+
13
+ # @param [ProconBypassMan::Domains::ProcessingProconBinary]
14
+ # @return [ProconBypassMan::Domains::ProcessingProconBinary]
15
+ # アナログスティックは上書きし、ボタンだけマージする
16
+ def write_as_merge!(target_binary)
17
+ current_buttons = ProconBypassMan::ProconReader.new(binary: binary).pressing
18
+ target_buttons = ProconBypassMan::ProconReader.new(binary: target_binary.raw).pressing
19
+
20
+ set_no_action!
21
+ (current_buttons + target_buttons).uniq.each do |button|
22
+ write_as_press_button(button)
23
+ end
24
+
25
+ # override analog stick
26
+ tb = [target_binary.raw].pack("H*")
27
+ binary[6] = tb[6]
28
+ binary[7] = tb[7]
29
+ binary[8] = tb[8]
30
+ binary[9] = tb[9]
31
+ binary[10] = tb[10]
32
+ binary[11] = tb[11]
33
+
34
+ self
35
+ end
36
+
37
+ # @param [Symbol] button
38
+ def write_as_press_button(button)
39
+ raise "already pressing button(#{button})" if ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)
40
+
41
+ button_obj = ProconBypassMan::Procon::Button.new(button)
42
+ value = binary[button_obj.byte_position].unpack("C").first + (2**button_obj.bit_position)
43
+ binary[button_obj.byte_position] = ["%02X" % value.to_s].pack("H*")
44
+ end
45
+
46
+ # @param [Symbol] button
47
+ def write_as_unpress_button(button)
48
+ raise "not press button(#{button}) yet" if not ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)
49
+
50
+ button_obj = ProconBypassMan::Procon::Button.new(button)
51
+ value = binary[button_obj.byte_position].unpack("C").first - (2**button_obj.bit_position)
52
+ binary[button_obj.byte_position] = ["%02X" % value.to_s].pack("H*")
53
+ end
54
+
55
+ # @param [Symbol] button
56
+ def write_as_press_button_only(button)
57
+ set_no_action!
58
+ write_as_press_button(button)
59
+ end
60
+
61
+ # @param [Integer] cap
62
+ def write_as_apply_left_analog_stick_cap(cap: )
63
+ analog_stick_cap = ProconBypassMan::Procon::AnalogStickCap.new(binary)
64
+ binary[6..8] = analog_stick_cap.capped_position(cap_hypotenuse: cap).to_binary
65
+ end
66
+ end
@@ -0,0 +1,11 @@
1
+ module ProconBypassMan
2
+ module Domains
3
+ module Binary; end
4
+ end
5
+ end
6
+
7
+ require_relative "domains/binary/base"
8
+ require_relative "domains/binary/has_mutable_binary"
9
+ require_relative "domains/binary/has_immutable_binary"
10
+ require_relative "domains/binary/inbound_procon_binary"
11
+ require_relative "domains/binary/processing_procon_binary"
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module FastReturn
6
+ def self.display_name
7
+ :fast_return
8
+ end
9
+
10
+ def self.steps
11
+ [:x, :down, :a, :a].freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module JumpToLeftKey
6
+ def self.display_name
7
+ :jump_to_left_key
8
+ end
9
+
10
+ def self.steps
11
+ [:x, :left, :a, :a].freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module JumpToRightKey
6
+ def self.display_name
7
+ :jump_to_right_key
8
+ end
9
+
10
+ def self.steps
11
+ [:x, :right, :a, :a].freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module JumpToUpKey
6
+ def self.display_name
7
+ :jump_to_up_key
8
+ end
9
+
10
+ def self.steps
11
+ [:x, :up, :a, :a].freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Mode
5
+ module Guruguru
6
+ def self.binaries
7
+ [ "309481408000362d684658750968f71cfe2c0e51000001480053f71ffedf0d4b000a013d00caf6ecfd4c0d480003011c00000000000000000000000000000000",
8
+ "30978140800037dd6748687509fdf6adfded0d6d0081005d00eef68dfdef0d6d00830059001bf791fd140e720090005400000000000000000000000000000000",
9
+ "309a8140800038cd67495875099af821fe120e40006400880042f8fcfdfd0d470067008900d4f7e0fdf20d4e006a008c00000000000000000000000000000000",
10
+ "309c8140800036ed67466875099bf878fe4a0e35005b004c00c1f875fe400e35005d004c00c4f856fe2d0e390063006c00000000000000000000000000000000",
11
+ "30a081408000371d6847587509b9f71bfee70d22002c002300e3f73afe150e2b003500280014f854fe300e2d0038002900000000000000000000000000000000",
12
+ "30a38140800039fd6743587509def70ffea10d1a0031001f00d1f70ffeb10d19002c002200c5f711feb80d18002c002500000000000000000000000000000000",
13
+ "30a58140800037dd6746687509d8f70bfe980d270035001200ddf70dfe980d240038001900dff70ffe9b0d1f0035001a00000000000000000000000000000000",
14
+ "30a98140800037ed67484875099cf7edfdb00d310020000d009ef7eefda30d310022000c00adf7f2fd980d300028000a00000000000000000000000000000000",
15
+ "30ac8140800036ed67484875099cf709fed40d3a002400160097f7fafdd30d39002200150096f7f0fdc80d380022001400000000000000000000000000000000",
16
+ "30ae8140800038fd674558750987f72efed40d360021001c0089f729fed50d39002400180092f715fed10d390022001800000000000000000000000000000000",
17
+ "30b18140800037dd6747487509b8f705fea90d19001d002000c5f70dfeb00d210019002200bff71efec20d280018002400000000000000000000000000000000",
18
+ "30b48140800038fd684868750980f7e9fdd40d0200080024007df7f1fdba0d060011001e0084f7f8fdaa0d12001a001a00000000000000000000000000000000",
19
+ "30b7814080003fdd694958750918f6a9fd510f0d00d1ff370024f7b0fda90e0100ecff30006cf7d1fd210efffff5ff2c00000000000000000000000000000000",
20
+ "30ba81408080482d744768750963f71ffe190f5e00d9fea100ccf62dfe650f510009ff980015f702fe580f4b002eff8400000000000000000000000000000000",
21
+ "30bd814080802f7d864758750974f70efe4c0f5e00c0fea000d1f726fe1c0f5d00c5fea30028f859fe0e0f5c00cafea800000000000000000000000000000000",
22
+ "30bf8140808057cc984758750961f73afe630f99009dfeae0050f738fe710f7500adfea40050f721fe720f6e00b2fea300000000000000000000000000000000",
23
+ "30c281408080f479bd483875092ef8b6feab0f0a0180feba00f1f798fe900f000181febd00c2f77dfe7c0fdb008efebd00000000000000000000000000000000",
24
+ "30c581408080ad87d846487509e1f80000a6107e0178fea2004ef88dff54106c0185fea70063f826ffe60f520182feae00000000000000000000000000000000",
25
+ "30c8810080800797d84868750995f8e1fe4b0f7a0161fe88000df96dffd00f700149fe990035f9cdff361088016afea000000000000000000000000000000000",
26
+ "30cb810080804586d848487509cef672fe8a0f6d0217ff42002df63cfe280f1d0219ff410059f61cfe070fed01f5fe4a00000000000000000000000000000000",
27
+ "30d08100808002c5d745687509d8f5aaff830f5e03e6fe3e01fbf55bffc30f3f03e4fe100158f600ff3e102903e5fee700000000000000000000000000000000",
28
+ "30d3810080807b94d14838750991f6cd00690f9903f0fff10147f6e200560f7e038fffc60101f6c900560f71033bffa901000000000000000000000000000000",
29
+ "30d681008080b743ca475875095af7f2009c0fca03a400320242f7ca00950fb503820028020af7b000820fa4034e001a02000000000000000000000000000000",
30
+ "30d9810080805be3c047587509e7f77a03c70f0e04bb00410258f79801940f0004b800410251f74401910fd803b3003602000000000000000000000000000000",
31
+ "30dc810080808a02b245587509c0fbd5086a10710475020a03b0fb8d085d106c042102e8027efb660876106a04bc01af02000000000000000000000000000000",
32
+ "30de8100808036d2a14568750970fbbf09ad103704af038003a9fb600989105c0459036103c2fb2a097210690412034603000000000000000000000000000000",
33
+ "30e281008000cbb18d4738750989f8b40b2812380341044c0429f99e0bef11510340043704f2f93c0b7911b0033704f003000000000000000000000000000000",
34
+ "30e581008000c9c18945587509a5f7ca0a2e13e400c6024c0547f7fd0a941264011703270578f74a0b6012e40168030205000000000000000000000000000000",
35
+ "30e781008000c6618948687509acf86909e813d0fe2801a1057cf8cf09ed130fff6301990516f8710aaa13ccff13028205000000000000000000000000000000",
36
+ "30ea81008000c77189475875093af93b0762136efbaeff19060cf90107b113a9fb99ff0906e1f85b07b113bafc9fffcd05000000000000000000000000000000",
37
+ "30ed81008000c791894568750950f9ce047c1432f900026007a5f9a6051f146ef9bb013707bff99206a813fef9ce00c606000000000000000000000000000000",
38
+ "30ef81008000c6d1894558750944f8ad0358143ef81c02f10780f8b403841484f84102d107ccf801049314bcf84202ad07000000000000000000000000000000",
39
+ "30f381008000c761884868750914f72105e4134cf6d001c00743f71a05f11391f6bf01e407a0f7c904fa13faf6b3011008000000000000000000000000000000",
40
+ "30f681008000c7718344587509eaf54a04c812a6f40002500627f66d041313f2f40d02940682f6a60468133ef51a02d806000000000000000000000000000000",
41
+ "30f881008000c4e1814668750b5cf5f803b51125f3b5000d0560f50f04e8118cf33c015d057df525042c1210f4b101cc05000000000000000000000000000000",
42
+ "30fb81008000c5e1814458750b19f65a02a410acf29effb804e2f5db02df10b7f2c0ffbf04a9f55c032011dcf22400d804000000000000000000000000000000",
43
+ "30fe8100800035e2814858750b81f65c00f80f8df231fe940471f6e6001f1088f2a6fe92044ef6b1015a1092f21fffa004000000000000000000000000000000",
44
+ "3001810080004b03814868750b69f6e6fdad0ffef20efdd40479f678feb40fd9f249fdc40484f6f4fec00fb0f29ffdad04000000000000000000000000000000",
45
+ "30048100800079e47d4858750b17f64cfb5f0f46f46afb430529f6c4fb710ff1f3d4fb300538f64bfc830fbbf315fc1d05000000000000000000000000000000",
46
+ "300781008000a7057e4668750bb1f5d3f9fb0e8ef5ccf96405cdf5fcf90c0f44f52dfa6505e1f52dfa210f29f550fa6305000000000000000000000000000000",
47
+ "30098100800041f67d4668750bcdf4b0f9ab0e21f602f955057ef5adf9d00ee1f559f95f05b1f5d3f9fb0e8ef5ccf96405000000000000000000000000000000",
48
+ "300d810080003d877c4838750b84f458f7dd0c89f6d0f8fc0436f4e2f7620d83f614f8430526f4c0f8a00e71f666f85c05000000000000000000000000000000",
49
+ "30108100800058e77a4668750bf7f2c3f57c0c9cf6abfa0a0470f30ef6790c89f65dfa420414f476f67e0c80f6d0f98a04000000000000000000000000000000",
50
+ "30128100800059f77a4658750b7ef249f5580cd9f69bfaa40389f269f56c0cd1f6a9fab503a3f286f5760cacf6c9faeb03000000000000000000000000000000",
51
+ "3016810080005b177b4868750ba9f298f4450b2cf774fa3102b8f2a5f47a0b24f765fa6e02b8f2b8f4b10b1df755faac02000000000000000000000000000000",
52
+ "30198100800057777a4558750b39f258f4480a80f73efaf40016f26af4940a5ef76bfa37014ef275f4d40a46f780fa8401000000000000000000000000000000",
53
+ ].map(&:freeze).freeze
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ProconBypassMan
4
+ module Plugin
5
+ module Splatoon2
6
+ VERSION = "0.1.3"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "plugin/splatoon2/version"
2
+ require_relative "plugin/splatoon2/macro/fast_return"
3
+ require_relative "plugin/splatoon2/macro/jump_to_right_key"
4
+ require_relative "plugin/splatoon2/macro/jump_to_up_key"
5
+ require_relative "plugin/splatoon2/macro/jump_to_left_key"
6
+ require_relative "plugin/splatoon2/mode/guruguru"
7
+
8
+ module ProconBypassMan
9
+ module Plugin
10
+ end
11
+ end
@@ -1,16 +1,15 @@
1
1
  class ProconBypassMan::Processor
2
- # @return [String] binary
2
+
3
+ # @param [ProconBypassMan::Domains::InboundProconBinary] binary
3
4
  def initialize(binary)
4
5
  @binary = binary
5
6
  end
6
7
 
7
8
  # @return [String] 加工後の入力データ
8
9
  def process
9
- unless @binary[0] == "\x30".b
10
- return @binary
11
- end
10
+ return @binary.raw unless @binary.user_operation_data?
12
11
 
13
- procon = ProconBypassMan::Procon.new(@binary)
12
+ procon = ProconBypassMan::Procon.new(@binary.raw)
14
13
  procon.apply!
15
14
  procon.to_binary
16
15
  end
@@ -0,0 +1,11 @@
1
+ class ProconBypassMan::Procon::Button
2
+ class UnknownButtonFoundError < StandardError; end
3
+
4
+ attr_accessor :byte_position, :bit_position
5
+
6
+ def initialize(key)
7
+ b = ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP[key] or raise(UnknownButtonFoundError, '定義にないボタンです')
8
+ self.byte_position = b[:byte_position]
9
+ self.bit_position = b[:bit_position]
10
+ end
11
+ end
@@ -1,13 +1,4 @@
1
1
  class ProconBypassMan::Procon::ButtonCollection
2
- class Button
3
- attr_accessor :byte_position, :bit_position
4
- def initialize(key)
5
- b = BUTTONS_MAP[key] or raise("undefined button")
6
- self.byte_position = b[:byte_position]
7
- self.bit_position = b[:bit_position]
8
- end
9
- end
10
-
11
2
  # https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/ac8093c84194b3232acb675ac1accce9bcb456a3/bluetooth_hid_notes.md
12
3
  #0) Input report ID
13
4
  #1) Timer. Increments very fast. Can be used to estimate excess Bluetooth latency.
@@ -42,9 +33,16 @@ class ProconBypassMan::Procon::ButtonCollection
42
33
  end
43
34
  acc
44
35
  }.freeze
36
+
45
37
  BUTTONS = ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.keys.freeze
46
38
 
47
- def self.load(button_key)
48
- Button.new(button_key)
39
+ LEFT_ANALOG_STICK = { byte_position: 6..8 }
40
+
41
+ # @param [Array<Symbol>] buttons
42
+ # @return [Array<Symbol>]
43
+ def self.normalize(buttons)
44
+ buttons.select { |x|
45
+ !!ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP[x]
46
+ }
49
47
  end
50
48
  end