Skip to content

Instantly share code, notes, and snippets.

@ishowta
Last active February 26, 2020 23:29
Show Gist options
  • Save ishowta/ccba522e1b10842357e3668a91837be8 to your computer and use it in GitHub Desktop.
Save ishowta/ccba522e1b10842357e3668a91837be8 to your computer and use it in GitHub Desktop.
play media and hide game between Apex matching time
from scapy.all import *
from sys import exit
import sys
from ctypes import *
import win32gui, win32com.client
from enum import Enum
user32 = windll.user32
kernel32 = windll.kernel32
# definition
SPACE = 0x20
VK_MEDIA_PLAY_PAUSE = 0xB3
apexIPList = ["52.40.151.17","35.163.162.180","34.214.254.167","52.10.175.136","54.190.2.47","54.70.26.90","34.213.159.21","54.69.134.200","54.148.221.206","54.70.109.240","54.70.109.240","35.167.66.1","54.201.115.162","34.213.159.21","54.148.221.206","54.201.115.162","35.166.116.205","34.213.159.21","35.166.116.205","52.24.233.184","54.201.115.162","54.70.109.240","54.148.221.206","35.167.66.1","54.148.221.206","35.166.116.205","54.148.221.206","35.167.66.1","52.26.149.214","54.148.221.206","52.24.233.184","54.69.134.200","52.24.233.184","52.24.233.184","54.201.115.162","52.26.149.214","52.26.149.214","52.26.149.214","35.166.116.205","54.70.109.240","54.201.115.162","52.24.233.184","34.213.159.21","52.40.107.0","54.71.134.196"]
class ApexStatus(Enum):
HOME = 1
WAIT = 2
MATCHING = 3
class ApexPlayer():
def __init__(self):
self.status = ApexStatus.HOME
self.spotifyIsPlaying = True
self.currentMatchPlayTime = 0.0
self.apex = user32.FindWindowW(None, "Apex Legends")
if not self.apex:
print("Waiting for Apex to launch…")
while not self.apex:
time.sleep(1)
self.apex = user32.FindWindowW(None, "Apex Legends")
def run(self):
print("Run")
sniff(filter="tcp", prn=self.packet_callback)
def packet_callback(self, packet):
#print(packet.show)
#embed()
if IP in packet and packet[IP].src in apexIPList:
#print("Apex packet length: " + str(len(packet)).ljust(6), end='')
if 1180 <= len(packet) and len(packet) <= 1240:
#print(" Entry?")
# マッチ終了の検知は怪しいのでスルーされた場合もOKにする
if self.status == ApexStatus.HOME or self.status == ApexStatus.MATCHING:
self.waitMatching()
self.status = ApexStatus.WAIT
elif 1290 <= len(packet) and len(packet) <= 1325:
#print(" Begin?")
if self.status == ApexStatus.WAIT:
self.startMatching()
self.currentMatchPlayTime = time.time()
self.status = ApexStatus.MATCHING
elif 1240 <= len(packet) and len(packet) <= 1270: # 1250 1184 1275
#print(" Fin?")
if self.status == ApexStatus.MATCHING and time.time() - self.currentMatchPlayTime > 60:
self.finMatching()
self.status = ApexStatus.HOME
#else:
# print("")
def click(self, keycode):
user32.keybd_event(keycode, 0,0,0)
time.sleep(.05)
user32.keybd_event(keycode, 0,2,0)
def playMedia(self):
if self.spotifyIsPlaying:
return
self.click(VK_MEDIA_PLAY_PAUSE)
self.spotifyIsPlaying = True
def pauseMedia(self):
if not self.spotifyIsPlaying:
return
self.click(VK_MEDIA_PLAY_PAUSE)
self.spotifyIsPlaying = False
def waitMatching(self):
self.playMedia()
win32gui.ShowWindow(self.apex, 6)
def startMatching(self):
time.sleep(10) # マッチングからキャラ選択画面までの時間
self.pauseMedia()
win32gui.SetForegroundWindow(self.apex)
def finMatching(self):
self.playMedia()
apexPlayer = ApexPlayer()
apexPlayer.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment