procon_bypass_man 0.1.9 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +2 -0
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +13 -12
  7. data/README.md +14 -16
  8. data/bin/console +4 -0
  9. data/bin/{report_receive_server.rb → dev_api_server.rb} +8 -1
  10. data/lib/procon_bypass_man/background/has_server_pool.rb +54 -0
  11. data/lib/procon_bypass_man/background/http_client.rb +67 -0
  12. data/lib/procon_bypass_man/background/job_performer.rb +16 -0
  13. data/lib/procon_bypass_man/background/job_runnable.rb +16 -0
  14. data/lib/procon_bypass_man/background/job_runner.rb +45 -0
  15. data/lib/procon_bypass_man/background/jobs/base_job.rb +12 -0
  16. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +10 -0
  17. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +10 -0
  18. data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +10 -0
  19. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +10 -0
  20. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +18 -0
  21. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +10 -0
  22. data/lib/procon_bypass_man/background.rb +12 -0
  23. data/lib/procon_bypass_man/boot_message.rb +13 -9
  24. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/layer.rb +51 -30
  25. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/loader.rb +12 -11
  26. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/validator.rb +1 -1
  27. data/lib/procon_bypass_man/buttons_setting_configuration.rb +101 -0
  28. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +42 -0
  29. data/lib/procon_bypass_man/bypass.rb +57 -38
  30. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  31. data/lib/procon_bypass_man/commands/connect_device_command.rb +11 -0
  32. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +9 -0
  33. data/lib/procon_bypass_man/commands/send_error_command.rb +19 -0
  34. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +11 -0
  35. data/lib/procon_bypass_man/commands/write_device_id_command.rb +12 -0
  36. data/lib/procon_bypass_man/commands/write_session_id_command.rb +13 -0
  37. data/lib/procon_bypass_man/commands.rb +7 -0
  38. data/lib/procon_bypass_man/configuration.rb +92 -78
  39. data/lib/procon_bypass_man/device_connector.rb +31 -25
  40. data/lib/procon_bypass_man/io_monitor.rb +9 -4
  41. data/lib/procon_bypass_man/procon/analog_stick.rb +31 -0
  42. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +9 -32
  43. data/lib/procon_bypass_man/procon/button_collection.rb +1 -0
  44. data/lib/procon_bypass_man/procon/{data.rb → consts.rb} +1 -1
  45. data/lib/procon_bypass_man/procon/layer_changer.rb +40 -0
  46. data/lib/procon_bypass_man/procon/macro_registry.rb +2 -2
  47. data/lib/procon_bypass_man/procon/mode_registry.rb +2 -2
  48. data/lib/procon_bypass_man/procon/user_operation.rb +15 -17
  49. data/lib/procon_bypass_man/procon.rb +15 -15
  50. data/lib/procon_bypass_man/procon_reader.rb +31 -0
  51. data/lib/procon_bypass_man/runner.rb +15 -113
  52. data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +15 -0
  53. data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +15 -0
  54. data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +15 -0
  55. data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +15 -0
  56. data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +57 -0
  57. data/lib/procon_bypass_man/splatoon2/version.rb +7 -0
  58. data/lib/procon_bypass_man/splatoon2.rb +11 -0
  59. data/lib/procon_bypass_man/support/callbacks.rb +70 -0
  60. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  61. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  62. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  63. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  64. data/lib/procon_bypass_man/support/uptime.rb +25 -0
  65. data/lib/procon_bypass_man/version.rb +1 -1
  66. data/lib/procon_bypass_man.rb +41 -82
  67. data/procon_bypass_man.gemspec +2 -2
  68. data/project_template/README.md +19 -12
  69. data/project_template/app.rb +7 -8
  70. data/project_template/systemd_units/pbm_web.service +11 -0
  71. data/project_template/web.rb +16 -0
  72. data/sig/{README.rb → README.md} +0 -0
  73. data/sig/main.rbs +54 -16
  74. metadata +53 -22
  75. data/examples/practical/app.rb +0 -21
  76. data/examples/practical/setting.yml +0 -24
  77. data/lib/procon_bypass_man/analog_stick_position.rb +0 -14
  78. data/lib/procon_bypass_man/error_reporter.rb +0 -44
  79. data/lib/procon_bypass_man/procon/debug_dumper.rb +0 -17
  80. data/lib/procon_bypass_man/procon/layer_changeable.rb +0 -28
  81. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -15
  82. data/lib/procon_bypass_man/reporter.rb +0 -42
  83. data/lib/procon_bypass_man/uptime.rb +0 -13
@@ -1,12 +1,14 @@
1
1
  class ProconBypassMan::Procon
2
2
  class UserOperation
3
- include LayerChangeable
4
- extend PushedButtonHelper::Dynamic
5
-
6
3
  attr_reader :binary
7
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
10
+
8
11
  def initialize(binary)
9
- self.class.compile_if_not_compile_yet!
10
12
  unless binary.encoding.name == ASCII_ENCODING
11
13
  raise "おかしいです"
12
14
  end
@@ -16,38 +18,34 @@ class ProconBypassMan::Procon
16
18
  ZERO_BIT = ["0"].pack("H*").freeze
17
19
  ASCII_ENCODING = "ASCII-8BIT"
18
20
 
19
- # @depilicate
20
- def binary=(binary)
21
- unless binary.encoding.name == ASCII_ENCODING
22
- raise "おかしいです"
23
- end
24
- @binary = binary
25
- end
26
-
27
21
  def set_no_action!
28
22
  binary[3] = ZERO_BIT
29
23
  binary[4] = ZERO_BIT
30
24
  binary[5] = ZERO_BIT
31
25
  end
32
26
 
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
30
+
33
31
  def unpress_button(button)
32
+ return if not pressed_button?(button)
33
+
34
34
  byte_position = ButtonCollection.load(button).byte_position
35
35
  value = binary[byte_position].unpack("H*").first.to_i(16) - (2**ButtonCollection.load(button).bit_position)
36
36
  binary[byte_position] = ["%02X" % value.to_s].pack("H*")
37
37
  end
38
38
 
39
- def apply_left_analog_stick_cap(cap: )
40
- binary[6..8] = ProconBypassMan::Procon::AnalogStickCap.new(binary).capped_position(cap_hypotenuse: cap).to_binary
41
- end
42
-
43
39
  def press_button(button)
40
+ return if pressed_button?(button)
41
+
44
42
  byte_position = ButtonCollection.load(button).byte_position
45
43
  value = binary[byte_position].unpack("H*").first.to_i(16) + (2**ButtonCollection.load(button).bit_position)
46
44
  binary[byte_position] = ["%02X" % value.to_s].pack("H*")
47
45
  end
48
46
 
49
47
  def press_button_only(button)
50
- [ProconBypassMan::Procon::Data::NO_ACTION.dup].pack("H*").tap do |no_action_binary|
48
+ [ProconBypassMan::Procon::Consts::NO_ACTION.dup].pack("H*").tap do |no_action_binary|
51
49
  ButtonCollection.load(button).byte_position
52
50
  byte_position = ButtonCollection.load(button).byte_position
53
51
  value = 2**ButtonCollection.load(button).bit_position
@@ -1,10 +1,9 @@
1
1
  class ProconBypassMan::Procon
2
- require "procon_bypass_man/procon/data"
2
+ require "procon_bypass_man/procon/consts"
3
3
  require "procon_bypass_man/procon/mode_registry"
4
4
  require "procon_bypass_man/procon/macro_registry"
5
- require "procon_bypass_man/procon/layer_changeable"
5
+ require "procon_bypass_man/procon/layer_changer"
6
6
  require "procon_bypass_man/procon/button_collection"
7
- require "procon_bypass_man/procon/pressed_button_helper"
8
7
  require "procon_bypass_man/procon/user_operation"
9
8
  require "procon_bypass_man/procon/flip_cache"
10
9
  require "procon_bypass_man/procon/press_button_aware"
@@ -31,12 +30,13 @@ class ProconBypassMan::Procon
31
30
  def current_layer_key; @@status[:current_layer_key]; end
32
31
 
33
32
  def current_layer
34
- ProconBypassMan::Configuration.instance.layers[current_layer_key]
33
+ ProconBypassMan::ButtonsSettingConfiguration.instance.layers[current_layer_key]
35
34
  end
36
35
 
37
36
  def apply!
38
- if user_operation.change_layer?
39
- @@status[:current_layer_key] = user_operation.next_layer_key if user_operation.pressed_next_layer?
37
+ layer_changer = ProconBypassMan::Procon::LayerChanger.new(binary: user_operation.binary)
38
+ if layer_changer.change_layer?
39
+ @@status[:current_layer_key] = layer_changer.next_layer_key if layer_changer.pressed_next_layer?
40
40
  user_operation.set_no_action!
41
41
  return
42
42
  end
@@ -95,10 +95,14 @@ class ProconBypassMan::Procon
95
95
  return user_operation.binary
96
96
  end
97
97
 
98
+ current_layer.disables.each do |button|
99
+ user_operation.unpress_button(button)
100
+ end
101
+
98
102
  current_layer.left_analog_stick_caps.each do |button, options|
99
103
  if button.nil? || button.all? { |b| user_operation.pressed_button?(b) }
100
104
  options[:force_neutral]&.each do |force_neutral_button|
101
- user_operation.pressed_button?(force_neutral_button) && user_operation.unpress_button(force_neutral_button)
105
+ user_operation.unpress_button(force_neutral_button)
102
106
  end
103
107
  user_operation.apply_left_analog_stick_cap(cap: options[:cap])
104
108
  end
@@ -107,7 +111,7 @@ class ProconBypassMan::Procon
107
111
  current_layer.flip_buttons.each do |button, options|
108
112
  # 何もしないで常に連打
109
113
  if !options[:if_pressed] && status[button]
110
- user_operation.press_button(button) unless user_operation.pressed_button?(button)
114
+ user_operation.press_button(button)
111
115
  next
112
116
  end
113
117
 
@@ -118,7 +122,7 @@ class ProconBypassMan::Procon
118
122
  end
119
123
 
120
124
  options[:force_neutral]&.each do |force_neutral_button|
121
- user_operation.pressed_button?(force_neutral_button) && user_operation.unpress_button(force_neutral_button)
125
+ user_operation.unpress_button(force_neutral_button)
122
126
  end
123
127
  end
124
128
  end
@@ -128,16 +132,12 @@ class ProconBypassMan::Procon
128
132
  user_operation.unpress_button(from_button)
129
133
  # TODO 2重でpressしないようにしたい
130
134
  to_buttons[:to].each do |to_button|
131
- user_operation.press_button(to_button) unless user_operation.pressed_button?(to_button)
135
+ user_operation.press_button(to_button)
132
136
  end
133
137
  end
134
138
  end
135
139
 
136
- b = user_operation.binary
137
- ProconBypassMan.cache.fetch key: 'user_operation.binary', expires_in: 60 do
138
- ProconBypassMan::Procon::DebugDumper.new(binary: b).dump_analog_sticks
139
- end
140
- b
140
+ user_operation.binary
141
141
  end
142
142
 
143
143
  private
@@ -0,0 +1,31 @@
1
+ class ProconBypassMan::ProconReader
2
+ def initialize(binary: )
3
+ @binary = binary
4
+ @analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
5
+ end
6
+
7
+ # @return [Array<Symbol>]
8
+ def pressed
9
+ aware = ProconBypassMan::PpressButtonAware.new(@binary)
10
+ pressed_table = ::ProconBypassMan::Procon::ButtonCollection::BUTTONS.reduce({}) do |acc, button|
11
+ acc[button] = aware.pressed_button?(button)
12
+ acc
13
+ end
14
+ pressed_table.select { |_key, value| value }.keys
15
+ end
16
+
17
+ def left_analog_stick
18
+ { x: @analog_stick.relative_x, y: @analog_stick.relative_y }
19
+ end
20
+
21
+ def left_analog_stick_by_abs
22
+ { x: @analog_stick.abs_x, y: @analog_stick.abs_y }
23
+ end
24
+
25
+ def to_hash
26
+ { left_analog_stick: left_analog_stick,
27
+ left_analog_stick_by_abs: left_analog_stick_by_abs,
28
+ buttons: pressed,
29
+ }
30
+ end
31
+ end
@@ -1,14 +1,19 @@
1
1
  require_relative "io_monitor"
2
- require_relative "uptime"
3
2
  require_relative "boot_message"
4
3
 
5
4
  class ProconBypassMan::Runner
6
5
  class InterruptForRestart < StandardError; end
7
6
 
8
- def run
9
- first_negotiation
10
- print_booted_message
7
+ include ProconBypassMan::SignalHandler
8
+
9
+ def initialize(gadget: , procon: )
10
+ @gadget = gadget
11
+ @procon = procon
12
+
13
+ ProconBypassMan::PrintBootMessageCommand.execute
14
+ end
11
15
 
16
+ def run
12
17
  self_read, self_write = IO.pipe
13
18
  %w(TERM INT USR1 USR2).each do |sig|
14
19
  begin
@@ -16,13 +21,14 @@ class ProconBypassMan::Runner
16
21
  self_write.puts(sig)
17
22
  end
18
23
  rescue ArgumentError
19
- ProconBypassMan.logger.error("Signal #{sig} not supported")
24
+ ProconBypassMan::SendErrorCommand.execute(error: "Signal #{sig} not supported")
20
25
  end
21
26
  end
22
27
 
23
28
  loop do
24
29
  $will_terminate_token = false
25
- main_loop_pid = fork { main_loop }
30
+ # TODO forkしないでThreadでいいのでは?
31
+ main_loop_pid = Kernel.fork { ProconBypassMan::BypassCommand.new(gadget: @gadget, procon: @procon).execute }
26
32
 
27
33
  begin
28
34
  while(readable_io = IO.select([self_read]))
@@ -35,10 +41,10 @@ class ProconBypassMan::Runner
35
41
  Process.wait
36
42
  ProconBypassMan.logger.info("Reloading config file")
37
43
  begin
38
- ProconBypassMan::Configuration::Loader.reload_setting
39
- puts "設定ファイルの再読み込みができました"
44
+ ProconBypassMan::ButtonsSettingConfiguration::Loader.reload_setting
45
+ ProconBypassMan::SendReloadConfigEventCommand.execute
40
46
  rescue ProconBypassMan::CouldNotLoadConfigError
41
- ProconBypassMan.logger.error "設定ファイルが不正です。再読み込みができませんでした"
47
+ ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。再読み込みができませんでした")
42
48
  end
43
49
  ProconBypassMan.logger.info("バイパス処理を再開します")
44
50
  rescue Interrupt
@@ -53,108 +59,4 @@ class ProconBypassMan::Runner
53
59
  end
54
60
  end
55
61
  end
56
-
57
- private
58
-
59
- def main_loop
60
- ProconBypassMan::IOMonitor.start!
61
- # gadget => procon
62
- # 遅くていい
63
- monitor1 = ProconBypassMan::IOMonitor.new(label: "switch -> procon")
64
- monitor2 = ProconBypassMan::IOMonitor.new(label: "procon -> switch")
65
- ProconBypassMan.logger.info "Thread1を起動します"
66
- t1 = Thread.new do
67
- timer = ProconBypassMan::Timer.new(timeout: Time.now + 10)
68
- bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
69
- loop do
70
- break if $will_terminate_token
71
- timer.throw_if_timeout!
72
- bypass.send_gadget_to_procon!
73
- sleep(0.005)
74
- rescue ProconBypassMan::Timer::Timeout
75
- ProconBypassMan.logger.info "10秒経過したのでThread1を終了します"
76
- puts "10秒経過したのでThread1を終了します"
77
- break
78
- rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
79
- ProconBypassMan.logger.error "Proconが切断されました.終了処理を開始します"
80
- Process.kill "TERM", Process.ppid
81
- rescue Errno::ETIMEDOUT => e
82
- # TODO まれにこれが発生する. 再接続したい
83
- ProconBypassMan::ErrorReporter.report(body: e)
84
- ProconBypassMan.logger.error "Switchとの切断されました.終了処理を開始します"
85
- Process.kill "TERM", Process.ppid
86
- end
87
- ProconBypassMan.logger.info "Thread1を終了します"
88
- end
89
-
90
- # procon => gadget
91
- # シビア
92
- ProconBypassMan.logger.info "Thread2を起動します"
93
- t2 = Thread.new do
94
- bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor2)
95
- loop do
96
- break if $will_terminate_token
97
- bypass.send_procon_to_gadget!
98
- rescue EOFError => e
99
- ProconBypassMan.logger.error "Proconと通信ができませんでした.終了処理を開始します"
100
- Process.kill "TERM", Process.ppid
101
- rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
102
- ProconBypassMan.logger.error "Proconが切断されました。終了処理を開始します"
103
- Process.kill "TERM", Process.ppid
104
- end
105
- ProconBypassMan.logger.info "Thread2を終了します"
106
- end
107
-
108
- self_read, self_write = IO.pipe
109
- %w(TERM INT).each do |sig|
110
- begin
111
- trap sig do
112
- self_write.puts(sig)
113
- end
114
- rescue ArgumentError
115
- puts "プロセスでSignal #{sig} not supported"
116
- end
117
- end
118
-
119
- ProconBypassMan.logger.info "子プロセスでgraceful shutdownの準備ができました"
120
- begin
121
- while(readable_io = IO.select([self_read]))
122
- signal = readable_io.first[0].gets.strip
123
- handle_signal(signal)
124
- end
125
- rescue Interrupt
126
- $will_terminate_token = true
127
- [t1, t2].each(&:join)
128
- @gadget&.close
129
- @procon&.close
130
- exit 1
131
- end
132
- end
133
-
134
- def first_negotiation
135
- @gadget, @procon = ProconBypassMan::DeviceConnector.connect
136
- rescue ProconBypassMan::Timer::Timeout
137
- ::ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
138
- @gadget&.close
139
- @procon&.close
140
- raise ::ProconBypassMan::EternalConnectionError
141
- end
142
-
143
- def handle_signal(sig)
144
- ProconBypassMan.logger.info "#{$$}で#{sig}を受け取りました"
145
- case sig
146
- when 'USR2'
147
- raise InterruptForRestart
148
- when 'INT', 'TERM'
149
- raise Interrupt
150
- end
151
- end
152
-
153
- # @return [void]
154
- def print_booted_message
155
- message = ProconBypassMan::BootMessage.new
156
- ProconBypassMan.logger.info(message.to_s)
157
- Thread.new { ProconBypassMan::Reporter.report(body: message.to_hash) }
158
- puts message.to_s
159
- end
160
62
  end
@@ -0,0 +1,15 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Macro
4
+ module FastReturn
5
+ def self.name
6
+ :fast_return
7
+ end
8
+
9
+ def self.steps
10
+ [:x, :down, :a, :a].freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Macro
4
+ module JumpToLeftKey
5
+ def self.name
6
+ :jump_to_left_key
7
+ end
8
+
9
+ def self.steps
10
+ [:x, :left, :a, :a].freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Macro
4
+ module JumpToRightKey
5
+ def self.name
6
+ :jump_to_right_key
7
+ end
8
+
9
+ def self.steps
10
+ [:x, :right, :a, :a].freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Macro
4
+ module JumpToUpKey
5
+ def self.name
6
+ :jump_to_up_key
7
+ end
8
+
9
+ def self.steps
10
+ [:x, :up, :a, :a].freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Mode
4
+ module Guruguru
5
+ def self.binaries
6
+ [ "309481408000362d684658750968f71cfe2c0e51000001480053f71ffedf0d4b000a013d00caf6ecfd4c0d480003011c00000000000000000000000000000000",
7
+ "30978140800037dd6748687509fdf6adfded0d6d0081005d00eef68dfdef0d6d00830059001bf791fd140e720090005400000000000000000000000000000000",
8
+ "309a8140800038cd67495875099af821fe120e40006400880042f8fcfdfd0d470067008900d4f7e0fdf20d4e006a008c00000000000000000000000000000000",
9
+ "309c8140800036ed67466875099bf878fe4a0e35005b004c00c1f875fe400e35005d004c00c4f856fe2d0e390063006c00000000000000000000000000000000",
10
+ "30a081408000371d6847587509b9f71bfee70d22002c002300e3f73afe150e2b003500280014f854fe300e2d0038002900000000000000000000000000000000",
11
+ "30a38140800039fd6743587509def70ffea10d1a0031001f00d1f70ffeb10d19002c002200c5f711feb80d18002c002500000000000000000000000000000000",
12
+ "30a58140800037dd6746687509d8f70bfe980d270035001200ddf70dfe980d240038001900dff70ffe9b0d1f0035001a00000000000000000000000000000000",
13
+ "30a98140800037ed67484875099cf7edfdb00d310020000d009ef7eefda30d310022000c00adf7f2fd980d300028000a00000000000000000000000000000000",
14
+ "30ac8140800036ed67484875099cf709fed40d3a002400160097f7fafdd30d39002200150096f7f0fdc80d380022001400000000000000000000000000000000",
15
+ "30ae8140800038fd674558750987f72efed40d360021001c0089f729fed50d39002400180092f715fed10d390022001800000000000000000000000000000000",
16
+ "30b18140800037dd6747487509b8f705fea90d19001d002000c5f70dfeb00d210019002200bff71efec20d280018002400000000000000000000000000000000",
17
+ "30b48140800038fd684868750980f7e9fdd40d0200080024007df7f1fdba0d060011001e0084f7f8fdaa0d12001a001a00000000000000000000000000000000",
18
+ "30b7814080003fdd694958750918f6a9fd510f0d00d1ff370024f7b0fda90e0100ecff30006cf7d1fd210efffff5ff2c00000000000000000000000000000000",
19
+ "30ba81408080482d744768750963f71ffe190f5e00d9fea100ccf62dfe650f510009ff980015f702fe580f4b002eff8400000000000000000000000000000000",
20
+ "30bd814080802f7d864758750974f70efe4c0f5e00c0fea000d1f726fe1c0f5d00c5fea30028f859fe0e0f5c00cafea800000000000000000000000000000000",
21
+ "30bf8140808057cc984758750961f73afe630f99009dfeae0050f738fe710f7500adfea40050f721fe720f6e00b2fea300000000000000000000000000000000",
22
+ "30c281408080f479bd483875092ef8b6feab0f0a0180feba00f1f798fe900f000181febd00c2f77dfe7c0fdb008efebd00000000000000000000000000000000",
23
+ "30c581408080ad87d846487509e1f80000a6107e0178fea2004ef88dff54106c0185fea70063f826ffe60f520182feae00000000000000000000000000000000",
24
+ "30c8810080800797d84868750995f8e1fe4b0f7a0161fe88000df96dffd00f700149fe990035f9cdff361088016afea000000000000000000000000000000000",
25
+ "30cb810080804586d848487509cef672fe8a0f6d0217ff42002df63cfe280f1d0219ff410059f61cfe070fed01f5fe4a00000000000000000000000000000000",
26
+ "30d08100808002c5d745687509d8f5aaff830f5e03e6fe3e01fbf55bffc30f3f03e4fe100158f600ff3e102903e5fee700000000000000000000000000000000",
27
+ "30d3810080807b94d14838750991f6cd00690f9903f0fff10147f6e200560f7e038fffc60101f6c900560f71033bffa901000000000000000000000000000000",
28
+ "30d681008080b743ca475875095af7f2009c0fca03a400320242f7ca00950fb503820028020af7b000820fa4034e001a02000000000000000000000000000000",
29
+ "30d9810080805be3c047587509e7f77a03c70f0e04bb00410258f79801940f0004b800410251f74401910fd803b3003602000000000000000000000000000000",
30
+ "30dc810080808a02b245587509c0fbd5086a10710475020a03b0fb8d085d106c042102e8027efb660876106a04bc01af02000000000000000000000000000000",
31
+ "30de8100808036d2a14568750970fbbf09ad103704af038003a9fb600989105c0459036103c2fb2a097210690412034603000000000000000000000000000000",
32
+ "30e281008000cbb18d4738750989f8b40b2812380341044c0429f99e0bef11510340043704f2f93c0b7911b0033704f003000000000000000000000000000000",
33
+ "30e581008000c9c18945587509a5f7ca0a2e13e400c6024c0547f7fd0a941264011703270578f74a0b6012e40168030205000000000000000000000000000000",
34
+ "30e781008000c6618948687509acf86909e813d0fe2801a1057cf8cf09ed130fff6301990516f8710aaa13ccff13028205000000000000000000000000000000",
35
+ "30ea81008000c77189475875093af93b0762136efbaeff19060cf90107b113a9fb99ff0906e1f85b07b113bafc9fffcd05000000000000000000000000000000",
36
+ "30ed81008000c791894568750950f9ce047c1432f900026007a5f9a6051f146ef9bb013707bff99206a813fef9ce00c606000000000000000000000000000000",
37
+ "30ef81008000c6d1894558750944f8ad0358143ef81c02f10780f8b403841484f84102d107ccf801049314bcf84202ad07000000000000000000000000000000",
38
+ "30f381008000c761884868750914f72105e4134cf6d001c00743f71a05f11391f6bf01e407a0f7c904fa13faf6b3011008000000000000000000000000000000",
39
+ "30f681008000c7718344587509eaf54a04c812a6f40002500627f66d041313f2f40d02940682f6a60468133ef51a02d806000000000000000000000000000000",
40
+ "30f881008000c4e1814668750b5cf5f803b51125f3b5000d0560f50f04e8118cf33c015d057df525042c1210f4b101cc05000000000000000000000000000000",
41
+ "30fb81008000c5e1814458750b19f65a02a410acf29effb804e2f5db02df10b7f2c0ffbf04a9f55c032011dcf22400d804000000000000000000000000000000",
42
+ "30fe8100800035e2814858750b81f65c00f80f8df231fe940471f6e6001f1088f2a6fe92044ef6b1015a1092f21fffa004000000000000000000000000000000",
43
+ "3001810080004b03814868750b69f6e6fdad0ffef20efdd40479f678feb40fd9f249fdc40484f6f4fec00fb0f29ffdad04000000000000000000000000000000",
44
+ "30048100800079e47d4858750b17f64cfb5f0f46f46afb430529f6c4fb710ff1f3d4fb300538f64bfc830fbbf315fc1d05000000000000000000000000000000",
45
+ "300781008000a7057e4668750bb1f5d3f9fb0e8ef5ccf96405cdf5fcf90c0f44f52dfa6505e1f52dfa210f29f550fa6305000000000000000000000000000000",
46
+ "30098100800041f67d4668750bcdf4b0f9ab0e21f602f955057ef5adf9d00ee1f559f95f05b1f5d3f9fb0e8ef5ccf96405000000000000000000000000000000",
47
+ "300d810080003d877c4838750b84f458f7dd0c89f6d0f8fc0436f4e2f7620d83f614f8430526f4c0f8a00e71f666f85c05000000000000000000000000000000",
48
+ "30108100800058e77a4668750bf7f2c3f57c0c9cf6abfa0a0470f30ef6790c89f65dfa420414f476f67e0c80f6d0f98a04000000000000000000000000000000",
49
+ "30128100800059f77a4658750b7ef249f5580cd9f69bfaa40389f269f56c0cd1f6a9fab503a3f286f5760cacf6c9faeb03000000000000000000000000000000",
50
+ "3016810080005b177b4868750ba9f298f4450b2cf774fa3102b8f2a5f47a0b24f765fa6e02b8f2b8f4b10b1df755faac02000000000000000000000000000000",
51
+ "30198100800057777a4558750b39f258f4480a80f73efaf40016f26af4940a5ef76bfa37014ef275f4d40a46f780fa8401000000000000000000000000000000",
52
+ ].map(&:freeze).freeze
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ProconBypassMan
4
+ module Splatoon2
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "splatoon2/version"
2
+ require_relative "splatoon2/macro/fast_return"
3
+ require_relative "splatoon2/macro/jump_to_right_key"
4
+ require_relative "splatoon2/macro/jump_to_up_key"
5
+ require_relative "splatoon2/macro/jump_to_left_key"
6
+ require_relative "splatoon2/mode/guruguru"
7
+
8
+ module ProconBypassMan
9
+ module Splatoon2
10
+ end
11
+ end
@@ -0,0 +1,70 @@
1
+ module ProconBypassMan
2
+ module Callbacks
3
+ class CallbacksChain
4
+ attr_accessor :filter, :chain_method
5
+ def initialize(filter: , chain_method: , block: )
6
+ @filter = filter
7
+ @chain_method = chain_method
8
+ @block = block
9
+ end
10
+ end
11
+
12
+ # TODO __callbacksをincludeしたクラス側で保持する. 今はnemespaceがない
13
+ module M
14
+ class << self
15
+ attr_accessor :__callbacks
16
+ end
17
+ end
18
+
19
+ module ClassMethods
20
+ def define_callbacks(name)
21
+ self.singleton_class.attr_accessor "_#{name}_callbacks"
22
+ send "_#{name}_callbacks=", [name] # CallbacksChain
23
+
24
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
25
+ def _run_#{name}_callbacks(&block)
26
+ __run_callbacks__(_#{name}_callbacks, &block)
27
+ end
28
+ RUBY
29
+ end
30
+
31
+ def set_callback(kind, filter, chain_method, &block)
32
+ ProconBypassMan::Callbacks::M.__callbacks ||= {}
33
+ ProconBypassMan::Callbacks::M.__callbacks[kind] = CallbacksChain.new(
34
+ filter: filter,
35
+ chain_method: chain_method,
36
+ block: block,
37
+ )
38
+ end
39
+ end
40
+
41
+ # TODO haltしたらcallbackを止める
42
+ # TODO 複数をチェインできるようにする
43
+ def run_callbacks(kind, &block)
44
+ chain = get_callbacks(kind) or raise("unknown callback")
45
+ case chain.filter
46
+ when :before
47
+ send chain.chain_method
48
+ block.call
49
+ when :after
50
+ block.call
51
+ send chain.chain_method
52
+ else
53
+ raise("unknown filter")
54
+ end
55
+ end
56
+
57
+ # def __run_callbacks__(name, &block)
58
+ # puts "called"
59
+ # end
60
+
61
+ def get_callbacks(kind) # :nodoc:
62
+ ProconBypassMan::Callbacks::M.__callbacks[kind.to_sym]
63
+ end
64
+
65
+ def set_callbacks(name, callbacks) # :nodoc:
66
+ send "_#{name}_callbacks=", callbacks
67
+ ProconBypassMan::Callbacks::M.__callbacks[kind.to_sym] = callbacks
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,56 @@
1
+ module ProconBypassMan
2
+ class CompressArray
3
+ class CompressibleValue
4
+ # @params [String] prev
5
+ # @params [String] current
6
+ def initialize(prev, current)
7
+ @prev = prev
8
+ @current = current
9
+ end
10
+
11
+ # @return [Boolean]
12
+ def compress?
13
+ @prev.include?(@current)
14
+ end
15
+
16
+ # @return [String]
17
+ def to_s_with_mark
18
+ if /^(.+) \* (\d+)/ =~ @prev
19
+ value = $1
20
+ count = $2
21
+ return "#{value} * #{count.to_i + 1}"
22
+ end
23
+ if /^(.+)/ =~ @prev
24
+ value = $1
25
+ return "#{value} * 1"
26
+ end
27
+ end
28
+ end
29
+
30
+ def initialize(array)
31
+ @array = array
32
+ end
33
+
34
+ # @return [Array<String>]
35
+ def compress
36
+ previous_value = nil
37
+ @array.reduce([]) do |acc, item|
38
+ if previous_value.nil?
39
+ acc << item
40
+ previous_value = item
41
+ next acc
42
+ end
43
+
44
+ if CompressibleValue.new(previous_value, item).compress?
45
+ registered_value = acc.pop
46
+ acc << CompressibleValue.new(registered_value, item).to_s_with_mark
47
+ else
48
+ acc << item
49
+ end
50
+
51
+ previous_value = item
52
+ next acc
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  module ProconBypassMan
2
- class Timer
2
+ class SafeTimeout
3
3
  class Timeout < StandardError; end
4
4
 
5
5
  # 5秒後がタイムアウト
@@ -0,0 +1,11 @@
1
+ module ProconBypassMan::SignalHandler
2
+ def handle_signal(sig)
3
+ ProconBypassMan.logger.info "#{$$}で#{sig}を受け取りました"
4
+ case sig
5
+ when 'USR2'
6
+ raise ProconBypassMan::Runner::InterruptForRestart
7
+ when 'INT', 'TERM'
8
+ raise Interrupt
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require "time"
2
+
3
+ module ProconBypassMan
4
+ class Uptime
5
+ # @return [Integer]
6
+ def self.from_boot
7
+ new(uptime_cmd_result: `uptime -s`.chomp).from_boot
8
+ end
9
+
10
+ # @param [String] uptime_cmd_result
11
+ def initialize(uptime_cmd_result: )
12
+ @result = uptime_cmd_result
13
+ end
14
+
15
+ # @return [Integer]
16
+ def from_boot
17
+ return -1 if @result == '' # darwin系だとsオプションが使えない
18
+ boot_time = Time.parse(@result).to_i
19
+ return Time.now.to_i - boot_time.to_i
20
+ rescue => e
21
+ ProconBypassMan.logger.error(e)
22
+ return -1
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProconBypassMan
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.13"
5
5
  end