procon_bypass_man 0.1.13 → 0.1.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +33 -0
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile.lock +26 -6
  5. data/README.md +27 -3
  6. data/docs/setup_raspi.md +2 -0
  7. data/docs/setup_raspi.mitamae.rb +7 -8
  8. data/docs/setup_raspi_by_mitamae.md +37 -1
  9. data/lib/ext/em_pure_ruby.rb +25 -0
  10. data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -6
  11. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
  12. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
  13. data/lib/procon_bypass_man/background/{job_runnable.rb → jobs/concerns/job_runnable.rb} +0 -0
  14. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +5 -3
  15. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +6 -5
  16. data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
  17. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +5 -4
  18. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +7 -10
  19. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +5 -4
  20. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
  21. data/lib/procon_bypass_man/background.rb +5 -4
  22. data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +2 -6
  23. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +6 -8
  24. data/lib/procon_bypass_man/bypass.rb +13 -6
  25. data/lib/procon_bypass_man/commands/connect_device_command.rb +6 -1
  26. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +50 -1
  27. data/lib/procon_bypass_man/commands/print_message_command.rb +8 -0
  28. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +21 -0
  29. data/lib/procon_bypass_man/commands/send_error_command.rb +1 -1
  30. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +1 -2
  31. data/lib/procon_bypass_man/commands/write_session_id_command.rb +1 -7
  32. data/lib/procon_bypass_man/commands.rb +2 -0
  33. data/lib/procon_bypass_man/configuration.rb +49 -2
  34. data/lib/procon_bypass_man/device_connector.rb +2 -1
  35. data/lib/procon_bypass_man/device_status.rb +44 -0
  36. data/lib/procon_bypass_man/domains/binary/base.rb +11 -0
  37. data/lib/procon_bypass_man/domains/binary/has_immutable_binary.rb +5 -0
  38. data/lib/procon_bypass_man/domains/binary/has_mutable_binary.rb +5 -0
  39. data/lib/procon_bypass_man/domains/binary/inbound_procon_binary.rb +23 -0
  40. data/lib/procon_bypass_man/domains/binary/processing_procon_binary.rb +80 -0
  41. data/lib/procon_bypass_man/domains.rb +11 -0
  42. data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
  43. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
  44. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
  45. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
  46. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
  47. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
  48. data/lib/procon_bypass_man/plugins.rb +11 -0
  49. data/lib/procon_bypass_man/processor.rb +4 -5
  50. data/lib/procon_bypass_man/procon/button.rb +11 -0
  51. data/lib/procon_bypass_man/procon/button_collection.rb +2 -12
  52. data/lib/procon_bypass_man/procon/layer_changer.rb +3 -2
  53. data/lib/procon_bypass_man/procon/press_button_aware.rb +5 -4
  54. data/lib/procon_bypass_man/procon/user_operation.rb +46 -63
  55. data/lib/procon_bypass_man/procon/{analog_stick.rb → value_objects/analog_stick.rb} +3 -4
  56. data/lib/procon_bypass_man/procon/value_objects/procon_reader.rb +34 -0
  57. data/lib/procon_bypass_man/procon.rb +16 -14
  58. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  59. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +25 -0
  60. data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +24 -0
  61. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +21 -0
  62. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
  63. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +21 -0
  64. data/lib/procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object.rb +38 -0
  65. data/lib/procon_bypass_man/remote_pbm_action.rb +32 -0
  66. data/lib/procon_bypass_man/runner.rb +4 -4
  67. data/lib/procon_bypass_man/scheduler.rb +85 -0
  68. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  69. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  70. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  71. data/lib/procon_bypass_man/{background/has_server_pool.rb → support/server_pool.rb} +3 -15
  72. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  73. data/lib/procon_bypass_man/version.rb +1 -1
  74. data/lib/procon_bypass_man/websocket/pbm_job_client.rb +79 -0
  75. data/lib/procon_bypass_man.rb +60 -31
  76. data/procon_bypass_man.gemspec +3 -1
  77. data/project_template/README.md +10 -5
  78. data/project_template/app.rb +1 -1
  79. data/project_template/setting.yml +8 -8
  80. data/sig/main.rbs +16 -1
  81. metadata +90 -21
  82. data/lib/procon_bypass_man/background/http_client.rb +0 -67
  83. data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +0 -10
  84. data/lib/procon_bypass_man/boot_message.rb +0 -44
  85. data/lib/procon_bypass_man/procon_reader.rb +0 -31
  86. data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +0 -15
  87. data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +0 -15
  88. data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +0 -15
  89. data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +0 -15
  90. data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +0 -57
  91. data/lib/procon_bypass_man/splatoon2/version.rb +0 -7
  92. data/lib/procon_bypass_man/splatoon2.rb +0 -11
@@ -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
@@ -0,0 +1,21 @@
1
+ class ProconBypassMan::RunRemotePbmActionDispatchCommand
2
+ # @param [String] action
3
+ # @param [String] uuid
4
+ # @return [void]
5
+ def self.execute(action: , uuid: , job_args: )
6
+ case action
7
+ when ProconBypassMan::RemotePbmAction::ACTION_CHANGE_PBM_VERSION
8
+ ProconBypassMan::RemotePbmAction::ChangePbmVersionAction.new(pbm_job_uuid: uuid).run!(job_args: job_args)
9
+ when ProconBypassMan::RemotePbmAction::ACTION_STOP_PBM
10
+ ProconBypassMan::RemotePbmAction::StopPbmAction.new(pbm_job_uuid: uuid).run!(job_args: {})
11
+ when ProconBypassMan::RemotePbmAction::ACTION_REBOOT_OS
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)
15
+ else
16
+ raise "#{action}は対応していないアクションです"
17
+ end
18
+ rescue ProconBypassMan::RemotePbmAction::ActionUnexpectedError => e
19
+ ProconBypassMan::SendErrorCommand.execute(error: e)
20
+ end
21
+ end
@@ -14,6 +14,6 @@ class ProconBypassMan::SendErrorCommand
14
14
  ProconBypassMan.error_logger.error body
15
15
  puts body
16
16
 
17
- ProconBypassMan::ReportErrorJob.perform_async(error)
17
+ ProconBypassMan::ReportErrorJob.perform(error)
18
18
  end
19
19
  end
@@ -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
  )
@@ -2,12 +2,6 @@ class ProconBypassMan::WriteSessionIdCommand
2
2
  # @return [String] session_id ラズパイが起動してからshutdownするまで同じ文字列を返す
3
3
  # 起動すると/tmp がなくなる前提の実装
4
4
  def self.execute
5
- path = "/tmp/pbm_session_id"
6
- if(sid = File.read(path))
7
- return sid
8
- end
9
- rescue Errno::ENOENT
10
- File.write(path, "s_#{SecureRandom.uuid}")
11
- return SecureRandom.uuid
5
+ @@session_id ||= "s_#{SecureRandom.uuid}"
12
6
  end
13
7
  end
@@ -1,7 +1,9 @@
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"
5
6
  require "procon_bypass_man/commands/send_error_command"
6
7
  require "procon_bypass_man/commands/connect_device_command"
7
8
  require "procon_bypass_man/commands/bypass_command"
9
+ require "procon_bypass_man/commands/run_remote_pbm_action_dispatch_command"
@@ -16,6 +16,11 @@ class ProconBypassMan::Configuration
16
16
  @@pid_path ||= File.expand_path("#{root}/pbm_pid", __dir__).freeze
17
17
  end
18
18
 
19
+ # @return [Integer]
20
+ def pid
21
+ File.read(pid_path).to_i
22
+ end
23
+
19
24
  def digest_path
20
25
  config.digest_path
21
26
  end
@@ -31,12 +36,12 @@ class ProconBypassMan::Configuration
31
36
 
32
37
  # @return [String]
33
38
  def device_id
34
- ProconBypassMan::WriteDeviceIdCommand.execute
39
+ ENV["DEBUG_DEVICE_ID"] || ProconBypassMan::WriteDeviceIdCommand.execute
35
40
  end
36
41
  end
37
42
 
38
43
  attr_accessor :enable_critical_error_logging
39
- attr_writer :verbose_bypass_log, :raw_setting
44
+ attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons
40
45
 
41
46
  def root=(path)
42
47
  @root = path
@@ -96,6 +101,44 @@ class ProconBypassMan::Configuration
96
101
  end
97
102
  end
98
103
 
104
+ # @return [Array<ProconBypassMan::ServerPool>]
105
+ def internal_server_pool
106
+ @internal_server_pool ||= ProconBypassMan::ServerPool.new(servers: internal_api_servers)
107
+ end
108
+
109
+ # @return [Array<ProconBypassMan::ServerPool>]
110
+ def server_pool
111
+ @server_pool ||= ProconBypassMan::ServerPool.new(servers: api_servers)
112
+ end
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
+
141
+ # @return [Array<String>]
99
142
  def api_servers
100
143
  if !!ENV["API_SERVER"]
101
144
  [ENV["API_SERVER"]].reject(&:nil?)
@@ -111,4 +154,8 @@ class ProconBypassMan::Configuration
111
154
  def raw_setting
112
155
  @raw_setting ||= {}
113
156
  end
157
+
158
+ def enable_reporting_pressed_buttons
159
+ @enable_reporting_pressed_buttons ||= false
160
+ end
114
161
  end
@@ -1,5 +1,6 @@
1
1
  class ProconBypassMan::DeviceConnector
2
2
  class BytesMismatchError < StandardError; end
3
+ class NotFoundProconError < StandardError; end
3
4
 
4
5
  class Value
5
6
  attr_accessor :read_from, :values
@@ -300,7 +301,7 @@ class ProconBypassMan::DeviceConnector
300
301
  @procon = File.open(PROCON2_PATH, "w+b")
301
302
  @gadget = File.open('/dev/hidg0', "w+b")
302
303
  else
303
- raise "/dev/hidraw0, /dev/hidraw1の両方見つかりませんでした"
304
+ raise NotFoundProconError, "/dev/hidraw0, /dev/hidraw1の両方見つかりませんでした"
304
305
  end
305
306
  system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
306
307
  system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
@@ -0,0 +1,44 @@
1
+ class ProconBypassMan::DeviceStatus
2
+ INITIALIZED = :initialized
3
+ RUNNING = :running
4
+ CONNECTED_BUT_SLEEPING = :connected_but_sleeping # コードはつながっているが、switchがsleepしているとき
5
+ PROCON_NOT_FOUND_ERROR = :procon_not_found_error # 繋がっていないとか、デバイスが使えない時
6
+ CONNECTED_BUT_ERROR = :connected_but_error # 実行時エラーあたり
7
+ SETTING_SYNTAX_ERROR_AND_SHUTDOWN = :setting_syntax_error_and_shutdown
8
+
9
+ @@status = nil
10
+
11
+ def self.current
12
+ @@status || INITIALIZED
13
+ end
14
+
15
+ def self.change_to_running!
16
+ @@status = RUNNING
17
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
18
+ end
19
+
20
+ def self.change_to_connected_but_sleeping!
21
+ @@status = CONNECTED_BUT_SLEEPING
22
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
23
+ end
24
+
25
+ def self.change_to_procon_not_found_error!
26
+ @@status = PROCON_NOT_FOUND_ERROR
27
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
28
+ end
29
+
30
+ def self.change_to_device_error!
31
+ @@status = DEVICE_ERROR
32
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
33
+ end
34
+
35
+ def self.change_to_connected_but_error!
36
+ @@status = CONNECTED_BUT_ERROR
37
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
38
+ end
39
+
40
+ def self.change_to_setting_syntax_error_and_shutdown!
41
+ @@status = SETTING_SYNTAX_ERROR_AND_SHUTDOWN
42
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
43
+ end
44
+ end
@@ -0,0 +1,11 @@
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
+ 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,23 @@
1
+ # proconから取得したばかりのバイナリ
2
+ class ProconBypassMan::Domains::InboundProconBinary < ProconBypassMan::Domains::Binary::Base
3
+ include ProconBypassMan::Domains::HasImmutableBinary
4
+
5
+ # @return [String]
6
+ def raw
7
+ binary.dup
8
+ end
9
+
10
+ def unpack
11
+ binary.unpack("H*")
12
+ end
13
+
14
+ # @return [ProconBypassMan::ProconReader]
15
+ def to_procon_reader
16
+ ProconBypassMan::ProconReader.new(binary: binary)
17
+ end
18
+
19
+ # @return [Boolean]
20
+ def user_operation_data?
21
+ binary[0] == "\x30".b
22
+ end
23
+ end
@@ -0,0 +1,80 @@
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
+ # @return [String]
8
+ def raw
9
+ binary
10
+ end
11
+
12
+ def unpack
13
+ binary.unpack("H*")
14
+ end
15
+
16
+ def set_no_action!
17
+ binary[3] = ALL_ZERO_BIT
18
+ binary[4] = ALL_ZERO_BIT
19
+ binary[5] = ALL_ZERO_BIT
20
+ end
21
+
22
+ # @param [ProconBypassMan::Domains::ProcessingProconBinary]
23
+ # @return [ProconBypassMan::Domains::ProcessingProconBinary]
24
+ # アナログスティックは上書きし、ボタンだけマージする
25
+ def write_as_merge!(target_binary)
26
+ current_buttons = ProconBypassMan::ProconReader.new(binary: binary).pressing
27
+ target_buttons = ProconBypassMan::ProconReader.new(binary: target_binary.raw).pressing
28
+
29
+ set_no_action!
30
+ (current_buttons + target_buttons).uniq.each do |button|
31
+ write_as_press_button(button)
32
+ end
33
+
34
+ # override analog stick
35
+ tb = [target_binary.raw].pack("H*")
36
+ binary[6] = tb[6]
37
+ binary[7] = tb[7]
38
+ binary[8] = tb[8]
39
+ binary[9] = tb[9]
40
+ binary[10] = tb[10]
41
+ binary[11] = tb[11]
42
+
43
+ self
44
+ end
45
+
46
+ # @param [Symbol] button
47
+ def write_as_press_button(button)
48
+ raise "already pressing button(#{button})" if ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)
49
+
50
+ button_obj = ProconBypassMan::Procon::Button.new(button)
51
+ value = binary[button_obj.byte_position].unpack("H*").first.to_i(16) + (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_unpress_button(button)
57
+ raise "not press button(#{button}) yet" if not ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)
58
+
59
+ button_obj = ProconBypassMan::Procon::Button.new(button)
60
+ value = binary[button_obj.byte_position].unpack("H*").first.to_i(16) - (2**button_obj.bit_position)
61
+ binary[button_obj.byte_position] = ["%02X" % value.to_s].pack("H*")
62
+ end
63
+
64
+ # @param [Symbol] button
65
+ def write_as_press_button_only(button)
66
+ set_no_action!
67
+ write_as_press_button(button)
68
+ end
69
+
70
+ # @param [Integer] cap
71
+ def write_as_apply_left_analog_stick_cap(cap: )
72
+ analog_stick_cap = ProconBypassMan::Procon::AnalogStickCap.new(binary)
73
+ binary[6..8] = analog_stick_cap.capped_position(cap_hypotenuse: cap).to_binary
74
+ end
75
+
76
+ # @return [ProconBypassMan::ProconReader]
77
+ def to_procon_reader
78
+ ProconBypassMan::ProconReader.new(binary: binary)
79
+ end
80
+ 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.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.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.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.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.2"
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,8 @@ 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)
49
- end
39
+ LEFT_ANALOG_STICK = { byte_position: 6..8 }
50
40
  end
@@ -1,6 +1,7 @@
1
1
  class ProconBypassMan::Procon::LayerChanger
2
+ # @param [ProconBypassMan::Domains::ProcessingProconBinary] binary
2
3
  def initialize(binary: )
3
- @procon_reader = ProconBypassMan::ProconReader.new(binary: binary).freeze
4
+ @procon_reader = binary.to_procon_reader
4
5
  end
5
6
 
6
7
  # @return [Symbol]
@@ -35,6 +36,6 @@ class ProconBypassMan::Procon::LayerChanger
35
36
 
36
37
  # @return [Boolean]
37
38
  def pressed?(button: )
38
- @procon_reader.pressed.include?(button)
39
+ @procon_reader.pressing.include?(button)
39
40
  end
40
41
  end