procon_bypass_man 0.1.12 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +33 -0
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +35 -15
  6. data/README.md +19 -8
  7. data/lib/ext/em_pure_ruby.rb +25 -0
  8. data/lib/procon_bypass_man/background/job_runner.rb +6 -5
  9. data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -6
  10. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
  11. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
  12. data/lib/procon_bypass_man/background/{job_runnable.rb → jobs/concerns/job_runnable.rb} +0 -0
  13. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +5 -3
  14. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +6 -5
  15. data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
  16. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +11 -0
  17. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +7 -10
  18. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +5 -4
  19. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
  20. data/lib/procon_bypass_man/background.rb +7 -4
  21. data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +36 -35
  22. data/lib/procon_bypass_man/buttons_setting_configuration.rb +2 -2
  23. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +8 -6
  24. data/lib/procon_bypass_man/bypass.rb +13 -6
  25. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  26. data/lib/procon_bypass_man/commands/connect_device_command.rb +7 -2
  27. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +51 -2
  28. data/lib/procon_bypass_man/commands/print_message_command.rb +8 -0
  29. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +21 -0
  30. data/lib/procon_bypass_man/commands/send_error_command.rb +2 -1
  31. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +2 -2
  32. data/lib/procon_bypass_man/commands/write_device_id_command.rb +1 -0
  33. data/lib/procon_bypass_man/commands/write_session_id_command.rb +1 -7
  34. data/lib/procon_bypass_man/commands.rb +3 -0
  35. data/lib/procon_bypass_man/configuration.rb +51 -5
  36. data/lib/procon_bypass_man/device_connector.rb +32 -24
  37. data/lib/procon_bypass_man/device_status.rb +44 -0
  38. data/lib/procon_bypass_man/domains/binary/base.rb +11 -0
  39. data/lib/procon_bypass_man/domains/binary/has_immutable_binary.rb +5 -0
  40. data/lib/procon_bypass_man/domains/binary/has_mutable_binary.rb +5 -0
  41. data/lib/procon_bypass_man/domains/binary/inbound_procon_binary.rb +23 -0
  42. data/lib/procon_bypass_man/domains/binary/processing_procon_binary.rb +80 -0
  43. data/lib/procon_bypass_man/domains.rb +11 -0
  44. data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
  45. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
  46. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
  47. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
  48. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
  49. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
  50. data/lib/procon_bypass_man/plugins.rb +11 -0
  51. data/lib/procon_bypass_man/processor.rb +4 -5
  52. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +1 -1
  53. data/lib/procon_bypass_man/procon/button.rb +11 -0
  54. data/lib/procon_bypass_man/procon/button_collection.rb +2 -12
  55. data/lib/procon_bypass_man/procon/layer_changer.rb +3 -2
  56. data/lib/procon_bypass_man/procon/press_button_aware.rb +5 -4
  57. data/lib/procon_bypass_man/procon/user_operation.rb +46 -63
  58. data/lib/procon_bypass_man/procon/{analog_stick.rb → value_objects/analog_stick.rb} +3 -4
  59. data/lib/procon_bypass_man/procon/value_objects/procon_reader.rb +34 -0
  60. data/lib/procon_bypass_man/procon.rb +16 -14
  61. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  62. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +25 -0
  63. data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +24 -0
  64. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +21 -0
  65. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
  66. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +21 -0
  67. data/lib/procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object.rb +38 -0
  68. data/lib/procon_bypass_man/remote_pbm_action.rb +32 -0
  69. data/lib/procon_bypass_man/runner.rb +8 -97
  70. data/lib/procon_bypass_man/scheduler.rb +85 -0
  71. data/lib/procon_bypass_man/{callbacks.rb → support/callbacks.rb} +0 -0
  72. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  73. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  74. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  75. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  76. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  77. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  78. data/lib/procon_bypass_man/{background/has_server_pool.rb → support/server_pool.rb} +3 -15
  79. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  80. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  81. data/lib/procon_bypass_man/{uptime.rb → support/uptime.rb} +0 -0
  82. data/lib/procon_bypass_man/version.rb +1 -1
  83. data/lib/procon_bypass_man/websocket/pbm_job_client.rb +79 -0
  84. data/lib/procon_bypass_man.rb +68 -34
  85. data/procon_bypass_man.gemspec +5 -3
  86. data/project_template/README.md +18 -11
  87. data/project_template/app.rb +1 -2
  88. data/project_template/setting.yml +8 -8
  89. data/sig/{README.rb → README.md} +0 -0
  90. data/sig/main.rbs +16 -1
  91. metadata +102 -21
  92. data/lib/procon_bypass_man/background/http_client.rb +0 -70
  93. data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +0 -10
  94. data/lib/procon_bypass_man/boot_message.rb +0 -42
  95. data/lib/procon_bypass_man/procon_reader.rb +0 -31
@@ -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
@@ -60,6 +60,6 @@ class ProconBypassMan::Procon::AnalogStickCap
60
60
  end
61
61
 
62
62
  def hypotenuse
63
- Math.sqrt(relative_x**2 + relative_y**2).floor(6)
63
+ Math.sqrt((relative_x**2) + (relative_y**2)).floor(6)
64
64
  end
65
65
  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)
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
@@ -1,13 +1,14 @@
1
- class ProconBypassMan::PpressButtonAware
1
+ class ProconBypassMan::PressButtonAware
2
2
  def initialize(binary)
3
3
  @binary = binary
4
4
  end
5
5
 
6
- def pressed_button?(button)
6
+ def pressing_button?(button)
7
+ button_obj = ProconBypassMan::Procon::Button.new(button)
7
8
  @binary[
8
- ::ProconBypassMan::Procon::ButtonCollection.load(button).byte_position
9
+ button_obj.byte_position
9
10
  ].unpack("H*").first.to_i(16).to_s(2).reverse[
10
- ::ProconBypassMan::Procon::ButtonCollection.load(button).bit_position
11
+ button_obj.bit_position
11
12
  ] == '1'
12
13
  end
13
14
  end
@@ -1,77 +1,60 @@
1
- class ProconBypassMan::Procon
2
- class UserOperation
3
- attr_reader :binary
1
+ # ボタンを押しているか判断するクラス。バイナリの書き換えはしない
2
+ class ProconBypassMan::Procon::UserOperation
3
+ attr_reader :binary
4
4
 
5
- ::ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.each do |button, _value|
6
- define_method "pressed_#{button}?" do
7
- pressed_button?(button)
8
- end
9
- end
5
+ ASCII_ENCODING = "ASCII-8BIT"
10
6
 
11
- def initialize(binary)
12
- unless binary.encoding.name == ASCII_ENCODING
13
- raise "おかしいです"
14
- end
15
- @binary = binary
7
+ # @param [String] binary
8
+ def initialize(binary)
9
+ unless binary.encoding.name == ASCII_ENCODING
10
+ raise "おかしいです"
16
11
  end
17
12
 
18
- ZERO_BIT = ["0"].pack("H*").freeze
19
- ASCII_ENCODING = "ASCII-8BIT"
20
-
21
- def set_no_action!
22
- binary[3] = ZERO_BIT
23
- binary[4] = ZERO_BIT
24
- binary[5] = ZERO_BIT
25
- end
13
+ @binary = ProconBypassMan::Domains::ProcessingProconBinary.new(binary: binary)
14
+ end
26
15
 
27
- def apply_left_analog_stick_cap(cap: )
28
- binary[6..8] = ProconBypassMan::Procon::AnalogStickCap.new(binary).capped_position(cap_hypotenuse: cap).to_binary
29
- end
16
+ def set_no_action!
17
+ binary.set_no_action!
18
+ end
30
19
 
31
- def unpress_button(button)
32
- return if not pressed_button?(button)
20
+ def apply_left_analog_stick_cap(cap: )
21
+ binary.write_as_apply_left_analog_stick_cap(cap: cap)
22
+ end
33
23
 
34
- byte_position = ButtonCollection.load(button).byte_position
35
- value = binary[byte_position].unpack("H*").first.to_i(16) - (2**ButtonCollection.load(button).bit_position)
36
- binary[byte_position] = ["%02X" % value.to_s].pack("H*")
37
- end
24
+ # @param [Symbol] button
25
+ def unpress_button(button)
26
+ return if not pressing_button?(button)
27
+ binary.write_as_unpress_button(button)
28
+ end
38
29
 
39
- def press_button(button)
40
- return if pressed_button?(button)
30
+ # @param [Symbol] button
31
+ def press_button(button)
32
+ return if pressing_button?(button)
33
+ binary.write_as_press_button(button)
34
+ end
41
35
 
42
- byte_position = ButtonCollection.load(button).byte_position
43
- value = binary[byte_position].unpack("H*").first.to_i(16) + (2**ButtonCollection.load(button).bit_position)
44
- binary[byte_position] = ["%02X" % value.to_s].pack("H*")
45
- end
36
+ # @param [Symbol] button
37
+ def press_button_only(button)
38
+ binary.write_as_press_button_only(button)
39
+ end
46
40
 
47
- def press_button_only(button)
48
- [ProconBypassMan::Procon::Consts::NO_ACTION.dup].pack("H*").tap do |no_action_binary|
49
- ButtonCollection.load(button).byte_position
50
- byte_position = ButtonCollection.load(button).byte_position
51
- value = 2**ButtonCollection.load(button).bit_position
52
- no_action_binary[byte_position] = ["%02X" % value.to_s].pack("H*")
53
- binary[3] = no_action_binary[3]
54
- binary[4] = no_action_binary[4]
55
- binary[5] = no_action_binary[5]
56
- end
57
- end
41
+ # @return [void]
42
+ def merge(target_binary)
43
+ binary.write_as_merge!(
44
+ ProconBypassMan::Domains::ProcessingProconBinary.new(binary: target_binary)
45
+ )
46
+ end
58
47
 
59
- def merge(target_binary: )
60
- tb = [target_binary].pack("H*")
61
- binary[3] = tb[3]
62
- binary[4] = tb[4]
63
- binary[5] = tb[5]
64
- binary[6] = tb[6]
65
- binary[7] = tb[7]
66
- binary[8] = tb[8]
67
- binary[9] = tb[9]
68
- binary[10] = tb[10]
69
- binary[11] = tb[11]
70
- self.binary
71
- end
48
+ # @param [Symbol] button
49
+ # @return [Boolean]
50
+ def pressing_button?(button)
51
+ ProconBypassMan::PressButtonAware.new(@binary.raw).pressing_button?(button)
52
+ end
72
53
 
73
- def pressed_button?(button)
74
- ProconBypassMan::PpressButtonAware.new(binary).pressed_button?(button)
75
- end
54
+ # @param [Array<Symbol>] buttons
55
+ # @return [Boolean]
56
+ def pressing_all_buttons?(buttons)
57
+ aware = ProconBypassMan::PressButtonAware.new(@binary.raw)
58
+ buttons.all? { |b| aware.pressing_button?(b) }
76
59
  end
77
60
  end
@@ -4,13 +4,12 @@ class ProconBypassMan::Procon::AnalogStick
4
4
 
5
5
  def initialize(binary: )
6
6
  @neutral_position = ProconBypassMan::ButtonsSettingConfiguration.instance.neutral_position
7
-
8
- byte6 = binary[6].unpack("H*").first.to_i(16).to_s(2).rjust(8, "0")
9
- byte7 = binary[7].unpack("H*").first.to_i(16).to_s(2).rjust(8, "0")
10
- byte8 = binary[8].unpack("H*").first.to_i(16).to_s(2).rjust(8, "0")
7
+ bytes = binary[ProconBypassMan::Procon::ButtonCollection::LEFT_ANALOG_STICK.fetch(:byte_position)]
8
+ byte6, byte7, byte8 = bytes.each_char.map { |x| x.unpack("H*").first.to_i(16).to_s(2).rjust(8, "0") }
11
9
 
12
10
  self.bin_x = "#{byte7[4..7]}#{byte6}"
13
11
  self.bin_y = "#{byte8}#{byte7[0..3]}"
12
+ freeze
14
13
  end
15
14
 
16
15
  def abs_x
@@ -0,0 +1,34 @@
1
+ module ProconBypassMan
2
+ class ProconReader
3
+ def initialize(binary: )
4
+ @binary = binary
5
+ @analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
6
+ freeze
7
+ end
8
+
9
+ # @return [Array<Symbol>]
10
+ def pressing
11
+ aware = ProconBypassMan::PressButtonAware.new(@binary)
12
+ pressed_table = ::ProconBypassMan::Procon::ButtonCollection::BUTTONS.reduce({}) do |acc, button|
13
+ acc[button] = aware.pressing_button?(button)
14
+ acc
15
+ end
16
+ pressed_table.select { |_key, value| value }.keys
17
+ end
18
+
19
+ def left_analog_stick
20
+ { x: @analog_stick.relative_x, y: @analog_stick.relative_y }
21
+ end
22
+
23
+ def left_analog_stick_by_abs
24
+ { x: @analog_stick.abs_x, y: @analog_stick.abs_y }
25
+ end
26
+
27
+ def to_hash
28
+ { left_analog_stick: left_analog_stick,
29
+ left_analog_stick_by_abs: left_analog_stick_by_abs,
30
+ buttons: pressing,
31
+ }
32
+ end
33
+ end
34
+ end