Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'win32/api'
- require 'win32con'
- require 'win32con/keymap'
- include Win32CON
- require 'rtesseract'
- SendMessage = Win32::API.new('SendMessage', 'LLLL', 'L', 'user32')
- GetWindowThreadProcessId = Win32::API.new('GetWindowThreadProcessId', 'LL', 'L', 'user32')
- GetAsyncKeyState = Win32::API.new('GetAsyncKeyState', 'L', 'L', 'user32')
- GetCursorPos = Win32::API.new('GetCursorPos', 'P', 'V', 'user32')
- SetCursorPos = Win32::API.new('SetCursorPos', 'LL', 'V', 'user32')
- MouseEvent = Win32::API.new('mouse_event', "LLLLL", 'V', 'user32')
- GetForegroundWindow = Win32::API.new('GetForegroundWindow', 'V', 'L', 'user32')
- KeybdEvent = Win32::API.new('keybd_event', 'LLLP', 'V', 'user32')
- GetSystemMetrics = Win32::API.new('GetSystemMetrics', 'L', 'L', 'user32')
- EnumWindows = Win32::API.new('EnumWindows', 'KL', 'L', 'user32')
- GetWindowText = Win32::API.new('GetWindowText', 'LPI', 'I', 'user32')
- def wait(n); sleep(n); end
- alias :uwait :wait
- module Input
- @keystate = Array.new(0xff){0}
- @mouse_pos = [0,0]
- module_function
- def mouse_pos(real=false)
- if real
- pos = [0, 0].pack("LL"); GetCursorPos.call(pos);
- @mouse_pos = pos.unpack("LL")
- end
- return @mouse_pos
- end
- def update
- 0xff.times do |i|
- @keystate[i] = (GetAsyncKeyState.call(i) & 0x8000) > 0 ? @keystate[i] + 1 : 0
- end
- pos = [0, 0].pack("LL"); GetCursorPos.call(pos);
- @mouse_pos = pos.unpack("LL")
- end
- def trigger?(kcode)
- @keystate[kcode] == 1
- end
- def keystate; @keystate; end
- def mouse_rdown(use_msg, apply_pos)
- if use_msg
- SendMessage.call($APP_Hwnd, WM_RBUTTONDOWN, 0, 0)
- else
- mx = apply_pos ? (@mouse_pos[0] * 0xffff / $PrimaryScreenWidth).to_i : 0
- my = apply_pos ? (@mouse_pos[1] * 0xffff / $PrimaryScreenHeight).to_i : 0
- flag = MOUSEEVENTF_RIGHTDOWN
- flag |= MOUSEEVENTF_ABSOLUTE if apply_pos
- MouseEvent.call(flag, mx, my, 0, 0)
- end
- $flag_pressed = true
- end
- def mouse_rup(use_msg, apply_pos)
- mx = apply_pos ? @mouse_pos[0] : 0
- my = apply_pos ? @mouse_pos[1] : 0
- if use_msg
- SendMessage.call($APP_Hwnd, WM_RBUTTONUP, 0, 0)
- else
- mx = apply_pos ? (@mouse_pos[0] * 0xffff / $PrimaryScreenWidth).to_i : 0
- my = apply_pos ? (@mouse_pos[1] * 0xffff / $PrimaryScreenHeight).to_i : 0
- flag = MOUSEEVENTF_RIGHTUP
- flag |= MOUSEEVENTF_ABSOLUTE if apply_pos
- MouseEvent.call(flag, mx, my, 0, 0)
- end
- $flag_pressed = false
- end
- def mouse_ldown(use_msg,apply_pos)
- if use_msg
- SendMessage.call($APP_Hwnd, WM_LBUTTONDOWN, 0, 0)
- else
- mx = apply_pos ? (@mouse_pos[0] * 0xffff / $PrimaryScreenWidth).to_i : 0
- my = apply_pos ? (@mouse_pos[1] * 0xffff / $PrimaryScreenHeight).to_i : 0
- flag = MOUSEEVENTF_LEFTDOWN
- flag |= MOUSEEVENTF_ABSOLUTE if apply_pos
- MouseEvent.call(flag, mx, my, 0, 0)
- end
- $flag_pressed = true
- end
- def mouse_lup(use_msg,apply_pos)
- if use_msg
- SendMessage.call($APP_Hwnd, WM_LBUTTONUP, 0, 0)
- else
- mx = apply_pos ? (@mouse_pos[0] * 0xffff / $PrimaryScreenWidth).to_i : 0
- my = apply_pos ? (@mouse_pos[1] * 0xffff / $PrimaryScreenHeight).to_i : 0
- flag = MOUSEEVENTF_LEFTUP
- flag |= MOUSEEVENTF_ABSOLUTE if apply_pos
- MouseEvent.call(flag, mx, my, 0, 0)
- end
- $flag_pressed = false
- end
- def click_l(use_msg,apply_pos)
- mouse_ldown(use_msg,apply_pos)
- wait(0.03)
- mouse_lup(use_msg,apply_pos)
- end
- def click_r(use_msg,apply_pos)
- mouse_rdown(use_msg,apply_pos)
- wait(0.03)
- mouse_rup(use_msg,apply_pos)
- end
- def key_down(kid, use_msg=true)
- if use_msg
- SendMessage.call($APP_Hwnd, WM_KEYDOWN, kid, 0)
- else
- KeybdEvent.call(kid, 0, 0, 0)
- end
- $flag_pressed = true
- end
- def key_up(kid, use_msg=true)
- if use_msg
- SendMessage.call($APP_Hwnd, WM_KEYUP, kid, 0)
- else
- KeybdEvent.call(kid, 0, 2, 0)
- end
- $flag_pressed = false
- end
- def trigger_key(kid, use_msg=true)
- key_down(kid, use_msg)
- wait(0.03)
- key_up(kid, use_msg)
- end
- def set_cursor(x,y,use_event=false)
- @mouse_pos = [x,y]
- return SetCursorPos.call(x,y) unless use_event
- x = (x * 0xffff / $PrimaryScreenWidth).to_i
- y = (y * 0xffff / $PrimaryScreenHeight).to_i
- MouseEvent.call(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, 0, 0)
- end
- def moveto(x,y,speed=nil)
- cx,cy = @mouse_pos
- dx = x - cx; dy = y - cy;
- if speed.nil?
- default_speed = 10
- cnt = (Math.hypot(dx,dy) / default_speed).to_i
- if cnt > 42 # prevent it takes too long
- speed = (Math.hypot(dx,dy) / 42).to_i
- cnt = 42
- else
- speed = default_speed
- end
- else
- cnt = (Math.hypot(dx,dy) / speed).to_i
- end
- angle = Math.atan2(dy, dx)
- dx = speed * Math.cos(angle)
- dy = speed * Math.sin(angle)
- cnt.times{ cx += dx; cy += dy; self.set_cursor(cx, cy, false); wait(0.01);}
- self.set_cursor(x, y, false); self.set_cursor(x, y, false);
- end
- end
- class Integer
- def to_tris
- ret = ''
- self.to_s.each_char.reverse_each.each_with_index do |n,i|
- ret += ',' if i > 0 && i%3 == 0
- ret += n
- end
- ret.reverse
- end
- end
- def scroll_down # scroll down to next 3 members
- Input.update
- Input.set_cursor(1194,776)
- Input.mouse_ldown(false,false)
- sleep(0.5)
- Input.moveto(1194,334, 2)
- sleep(0.5)
- Input.mouse_lup(false,false)
- end
- # OCR can't identify names 100% correctly
- $members = ['雪楓Yuki','SuSu','Qazqazqa','chimo','仙人','伏黒ツバキ','レイ','—Yukihana-','亜夜','turtle','yuan-0512','トワイルナスティア','小藍藍藍','柊','ミク','zeta','アメシスト','skifu','M子','BearMochi','なまやん','神無','星露','米豆緑','余','Guozi','J','CM','AscroZ','ming']
- $scores = []
- def do_capture
- system("screenshot-cmd.exe -wt BlueStacks -rc 788 520 1050 890")
- image = RTesseract.new('screenshot.png', lang: 'jpn+chi_tra')
- puts image.to_s
- image.to_s.split(/[\r\n]+/).each do |line|
- next unless line.strip.end_with? '人'
- number = ''
- line = line.split(/(\s|數|数)/).last
- line.each_char{|ch| number += ch if ch.match(/\d/)}
- $scores << number.to_i
- end
- end
- (ARGV[0].to_i / 3).times do
- do_capture
- scroll_down
- end
- dict = Hash[$members.zip $scores]
- sign_delta = "▲"
- puts "馬娘コネ 每周進度報告 (結算時間: #{Time.now.to_s.split('+').first})"
- puts "成員數 #{ARGV[0].to_i}/30"
- puts "總粉絲數 #{$scores.sum.to_tris} 排名 #{ARGV[1]}位 (#{ARGV[2]})"
- puts "======= 成員概況 ======="
- dict.each do |k,v|
- delta = 0
- puts "#{k}: #{v.to_tris} (#{sign_delta} #{delta})"
- end
- puts "======================="
- File.open("data/#{Time.now.to_s.split.first}.dat", 'wb') do |fp|
- Marshal.dump(dict, fp)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement