mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:27:33 +08:00
Opt: Merge Emulator.PackageName and Emulator.Server into one dropdown
This commit is contained in:
parent
beabf938fc
commit
618fa52bcb
7
alas.py
7
alas.py
@ -7,7 +7,6 @@ from datetime import datetime
|
||||
import inflection
|
||||
from cached_property import cached_property
|
||||
|
||||
import module.config.server as server
|
||||
from module.config.config import AzurLaneConfig, TaskEnd
|
||||
from module.config.config_updater import ConfigUpdater
|
||||
from module.config.utils import deep_get, deep_set
|
||||
@ -27,8 +26,6 @@ class AzurLaneAutoScript:
|
||||
def config(self):
|
||||
try:
|
||||
config = AzurLaneConfig(config_name=self.config_name)
|
||||
# Set server before loading any buttons.
|
||||
server.server = deep_get(config.data, keys='Alas.Emulator.Server', default='cn')
|
||||
return config
|
||||
except RequestHumanTakeover:
|
||||
logger.critical('Request human takeover')
|
||||
@ -64,7 +61,7 @@ class AzurLaneAutoScript:
|
||||
except (GameStuckError, GameTooManyClickError) as e:
|
||||
logger.warning(e)
|
||||
self.save_error_log()
|
||||
logger.warning(f'Game stuck, {self.config.Emulator_PackageName} will be restarted in 10 seconds')
|
||||
logger.warning(f'Game stuck, {self.device.package} will be restarted in 10 seconds')
|
||||
logger.warning('If you are playing by hand, please stop Alas')
|
||||
self.config.task_call('Restart')
|
||||
self.device.sleep(10)
|
||||
@ -73,7 +70,7 @@ class AzurLaneAutoScript:
|
||||
logger.warning(e)
|
||||
self.save_error_log()
|
||||
logger.warning('An error has occurred in Azur Lane game client, Alas is unable to handle')
|
||||
logger.warning(f'Restarting {self.config.Emulator_PackageName} to fix it')
|
||||
logger.warning(f'Restarting {self.device.package} to fix it')
|
||||
self.config.task_call('Restart')
|
||||
self.device.sleep(10)
|
||||
return False
|
||||
|
@ -129,4 +129,5 @@ Deploy:
|
||||
# --cdn. Use jsdelivr cdn for pywebio static files (css, js).
|
||||
# 'true' for jsdelivr cdn
|
||||
# 'false' for self host cdn (automatically)
|
||||
# 'https://path.to.your/cdn' to use custom cdn
|
||||
CDN: false
|
||||
|
@ -129,4 +129,5 @@ Deploy:
|
||||
# --cdn. Use jsdelivr cdn for pywebio static files (css, js).
|
||||
# 'true' for jsdelivr cdn
|
||||
# 'false' for self host cdn (automatically)
|
||||
# 'https://path.to.your/cdn' to use custom cdn
|
||||
CDN: false
|
||||
|
@ -129,4 +129,5 @@ Deploy:
|
||||
# --cdn. Use jsdelivr cdn for pywebio static files (css, js).
|
||||
# 'true' for jsdelivr cdn
|
||||
# 'false' for self host cdn (automatically)
|
||||
# 'https://path.to.your/cdn' to use custom cdn
|
||||
CDN: false
|
||||
|
@ -129,4 +129,5 @@ Deploy:
|
||||
# --cdn. Use jsdelivr cdn for pywebio static files (css, js).
|
||||
# 'true' for jsdelivr cdn
|
||||
# 'false' for self host cdn (automatically)
|
||||
# 'https://path.to.your/cdn' to use custom cdn
|
||||
CDN: false
|
||||
|
@ -1,9 +1,8 @@
|
||||
{
|
||||
"Alas": {
|
||||
"Emulator": {
|
||||
"Serial": "127.0.0.1:5555",
|
||||
"PackageName": "com.bilibili.azurlane",
|
||||
"Server": "cn",
|
||||
"Serial": "auto",
|
||||
"PackageName": "auto",
|
||||
"ScreenshotMethod": "ADB",
|
||||
"ControlMethod": "minitouch",
|
||||
"ScreenshotDedithering": false
|
||||
|
@ -6,6 +6,7 @@ from tqdm.contrib.concurrent import process_map
|
||||
|
||||
from module.base.utils import get_bbox, get_color, image_size, load_image
|
||||
from module.config.config_manual import ManualConfig as AzurLaneConfig
|
||||
from module.config.server import VALID_SERVER
|
||||
from module.logger import logger
|
||||
|
||||
MODULE_FOLDER = './module'
|
||||
@ -18,7 +19,6 @@ from module.base.template import Template
|
||||
# Don't modify it manually.
|
||||
"""
|
||||
IMPORT_EXP = IMPORT_EXP.strip().split('\n') + ['']
|
||||
VALID_SERVER = ['cn', 'en', 'jp', 'tw']
|
||||
|
||||
|
||||
class ImageExtractor:
|
||||
|
@ -2,6 +2,7 @@ from module.base.button import Button
|
||||
from module.base.timer import Timer
|
||||
from module.base.utils import *
|
||||
from module.config.config import AzurLaneConfig
|
||||
from module.config.server import set_server, to_package
|
||||
from module.device.device import Device
|
||||
from module.logger import logger
|
||||
from module.map_detection.utils import fit_points
|
||||
@ -209,3 +210,14 @@ class ModuleBase:
|
||||
value = load_image(value)
|
||||
|
||||
self.device.image = value
|
||||
|
||||
def set_server(self, server):
|
||||
"""
|
||||
For development.
|
||||
Change server and this will effect globally,
|
||||
including assets and server specific methods.
|
||||
"""
|
||||
package = to_package(server)
|
||||
self.device.package = package
|
||||
set_server(server)
|
||||
logger.attr('Server', self.config.SERVER)
|
||||
|
@ -140,4 +140,4 @@ def release_resources(next_task=''):
|
||||
del_cached_property(ASSETS, attr)
|
||||
|
||||
# Useless in most cases, but just call it
|
||||
gc.collect()
|
||||
# gc.collect()
|
||||
|
@ -3,21 +3,27 @@
|
||||
"Emulator": {
|
||||
"Serial": {
|
||||
"type": "input",
|
||||
"value": "127.0.0.1:5555",
|
||||
"value": "auto",
|
||||
"valuetype": "str"
|
||||
},
|
||||
"PackageName": {
|
||||
"type": "input",
|
||||
"value": "com.bilibili.azurlane"
|
||||
},
|
||||
"Server": {
|
||||
"type": "select",
|
||||
"value": "cn",
|
||||
"value": "auto",
|
||||
"option": [
|
||||
"cn",
|
||||
"en",
|
||||
"jp",
|
||||
"tw"
|
||||
"auto",
|
||||
"com.bilibili.azurlane",
|
||||
"com.YoStarEN.AzurLane",
|
||||
"com.YoStarJP.AzurLane",
|
||||
"com.hkmanjuu.azurlane.gp",
|
||||
"com.bilibili.blhx.huawei",
|
||||
"com.bilibili.blhx.mi",
|
||||
"com.tencent.tmgp.bilibili.blhx",
|
||||
"com.bilibili.blhx.baidu",
|
||||
"com.bilibili.blhx.qihoo",
|
||||
"com.bilibili.blhx.vivo",
|
||||
"com.bilibili.blhx.uc",
|
||||
"com.bilibili.blhx.mzw",
|
||||
"com.yiwu.blhx.yx15"
|
||||
]
|
||||
},
|
||||
"ScreenshotMethod": {
|
||||
|
@ -13,12 +13,11 @@ Scheduler:
|
||||
ServerUpdate: 00:00
|
||||
Emulator:
|
||||
Serial:
|
||||
value: 127.0.0.1:5555
|
||||
value: auto
|
||||
valuetype: str
|
||||
PackageName: com.bilibili.azurlane
|
||||
Server:
|
||||
value: cn
|
||||
option: [cn, en, jp, tw]
|
||||
PackageName:
|
||||
value: auto
|
||||
option: [auto, ]
|
||||
ScreenshotMethod:
|
||||
value: ADB
|
||||
option: [ADB, ADB_nc, uiautomator2, aScreenCap, aScreenCap_nc]
|
||||
|
@ -72,7 +72,7 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig):
|
||||
super().__setattr__(key, value)
|
||||
|
||||
def __init__(self, config_name, task=None):
|
||||
logger.attr('Server', server.server)
|
||||
logger.attr('Server', self.SERVER)
|
||||
# This will read ./config/<config_name>.json
|
||||
self.config_name = config_name
|
||||
# Raw json data in yaml file.
|
||||
@ -471,10 +471,6 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig):
|
||||
|
||||
return config
|
||||
|
||||
@property
|
||||
def SERVER(self):
|
||||
return self.Emulator_Server
|
||||
|
||||
@property
|
||||
def DEVICE_SCREENSHOT_METHOD(self):
|
||||
return self.Emulator_ScreenshotMethod
|
||||
|
@ -18,9 +18,8 @@ class GeneratedConfig:
|
||||
Scheduler_ServerUpdate = '00:00'
|
||||
|
||||
# Group `Emulator`
|
||||
Emulator_Serial = '127.0.0.1:5555'
|
||||
Emulator_PackageName = 'com.bilibili.azurlane'
|
||||
Emulator_Server = 'cn' # cn, en, jp, tw
|
||||
Emulator_Serial = 'auto'
|
||||
Emulator_PackageName = 'auto' # auto, com.bilibili.azurlane, com.YoStarEN.AzurLane, com.YoStarJP.AzurLane, com.hkmanjuu.azurlane.gp, com.bilibili.blhx.huawei, com.bilibili.blhx.mi, com.tencent.tmgp.bilibili.blhx, com.bilibili.blhx.baidu, com.bilibili.blhx.qihoo, com.bilibili.blhx.vivo, com.bilibili.blhx.uc, com.bilibili.blhx.mzw, com.yiwu.blhx.yx15
|
||||
Emulator_ScreenshotMethod = 'ADB' # ADB, ADB_nc, uiautomator2, aScreenCap, aScreenCap_nc
|
||||
Emulator_ControlMethod = 'minitouch' # ADB, uiautomator2, minitouch, Hermit
|
||||
Emulator_ScreenshotDedithering = False
|
||||
|
@ -6,6 +6,7 @@ from cached_property import cached_property
|
||||
from deploy.utils import DEPLOY_TEMPLATE, poor_yaml_read, poor_yaml_write
|
||||
from module.base.timer import timer
|
||||
from module.config.redirect_utils.shop_filter import bp_redirect
|
||||
from module.config.server import to_server, to_package, VALID_PACKAGE, VALID_CN_CHANNEL_PACKAGE
|
||||
from module.config.utils import *
|
||||
from module.logger import logger
|
||||
|
||||
@ -41,12 +42,12 @@ class Event:
|
||||
self.tw = self.tw.replace('、', '')
|
||||
self.is_war_archives = self.directory.startswith('war_archives')
|
||||
self.is_raid = self.directory.startswith('raid_')
|
||||
for server_ in ARCHIVES_PREFIX.keys():
|
||||
if self.__getattribute__(server_) == '-':
|
||||
self.__setattr__(server_, None)
|
||||
for server in ARCHIVES_PREFIX.keys():
|
||||
if self.__getattribute__(server) == '-':
|
||||
self.__setattr__(server, None)
|
||||
else:
|
||||
if self.is_war_archives:
|
||||
self.__setattr__(server_, ARCHIVES_PREFIX[server_] + self.__getattribute__(server_))
|
||||
self.__setattr__(server, ARCHIVES_PREFIX[server] + self.__getattribute__(server))
|
||||
|
||||
def __str__(self):
|
||||
return self.directory
|
||||
@ -235,14 +236,26 @@ class ConfigGenerator:
|
||||
name = event.__getattribute__(LANG_TO_SERVER[lang])
|
||||
if name:
|
||||
deep_default(events, keys=event.directory, value=name)
|
||||
for server_ in ['en', 'cn', 'jp', 'tw']:
|
||||
for server in ['en', 'cn', 'jp', 'tw']:
|
||||
for event in self.event:
|
||||
name = event.__getattribute__(server_)
|
||||
name = event.__getattribute__(server)
|
||||
if name:
|
||||
deep_default(events, keys=event.directory, value=name)
|
||||
for event in self.event:
|
||||
name = events.get(event.directory, event.directory)
|
||||
deep_set(new, keys=f'Campaign.Event.{event.directory}', value=name)
|
||||
# Package names
|
||||
for package, server in VALID_PACKAGE.items():
|
||||
path = ['Emulator', 'PackageName', package]
|
||||
if deep_get(new, keys=path) == package:
|
||||
deep_set(new, keys=path, value=server.upper())
|
||||
cn = deep_get(new, keys=['Emulator', 'PackageName', to_package('cn')])
|
||||
for package, server in VALID_CN_CHANNEL_PACKAGE.items():
|
||||
if lang == SERVER_TO_LANG['cn']:
|
||||
value = f'{server}渠道服 {package}'
|
||||
else:
|
||||
value = f'{cn} {package}'
|
||||
deep_set(new, keys=['Emulator', 'PackageName', package], value=value)
|
||||
# GUI i18n
|
||||
for path, _ in deep_iter(self.gui, depth=2):
|
||||
group, key = path
|
||||
@ -304,15 +317,15 @@ class ConfigGenerator:
|
||||
args.json -----+-----> args.json
|
||||
"""
|
||||
for event in self.event:
|
||||
for server_ in ARCHIVES_PREFIX.keys():
|
||||
name = event.__getattribute__(server_)
|
||||
for server in ARCHIVES_PREFIX.keys():
|
||||
name = event.__getattribute__(server)
|
||||
|
||||
def insert(key):
|
||||
options = deep_get(self.args, keys=f'{key}.Campaign.Event.option')
|
||||
if event not in options:
|
||||
options.append(event)
|
||||
if name:
|
||||
deep_default(self.args, keys=f'{key}.Campaign.Event.{server_}', value=event)
|
||||
deep_default(self.args, keys=f'{key}.Campaign.Event.{server}', value=event)
|
||||
|
||||
if name:
|
||||
if event.is_raid:
|
||||
@ -359,12 +372,20 @@ class ConfigGenerator:
|
||||
update('template-AidLux', aidlux)
|
||||
update('template-AidLux-cn', aidlux, cn)
|
||||
|
||||
def insert_package(self):
|
||||
option = deep_get(self.argument, keys='Emulator.PackageName.option')
|
||||
option += list(VALID_PACKAGE.keys())
|
||||
option += list(VALID_CN_CHANNEL_PACKAGE.keys())
|
||||
deep_set(self.argument, keys='Emulator.PackageName.option', value=option)
|
||||
deep_set(self.args, keys='Alas.Emulator.PackageName.option', value=option)
|
||||
|
||||
@timer
|
||||
def generate(self):
|
||||
_ = self.args
|
||||
_ = self.menu
|
||||
_ = self.event
|
||||
self.insert_event()
|
||||
self.insert_package()
|
||||
write_file(filepath_args(), self.args)
|
||||
write_file(filepath_args('menu'), self.menu)
|
||||
self.generate_code()
|
||||
@ -418,23 +439,23 @@ class ConfigUpdater:
|
||||
else:
|
||||
deep_default(new, 'Alas.DropRecord.AzurStatsID', random_id())
|
||||
# Update to latest event
|
||||
server_ = deep_get(new, 'Alas.Emulator.Server', 'cn')
|
||||
server = to_server(deep_get(new, 'Alas.Emulator.PackageName', 'cn'))
|
||||
if not is_template:
|
||||
for task in ['Event', 'EventAb', 'EventCd', 'EventSp', 'Raid', 'RaidDaily']:
|
||||
deep_set(new,
|
||||
keys=f'{task}.Campaign.Event',
|
||||
value=deep_get(self.args, f'{task}.Campaign.Event.{server_}'))
|
||||
value=deep_get(self.args, f'{task}.Campaign.Event.{server}'))
|
||||
for task in ['GemsFarming']:
|
||||
if deep_get(new, keys=f'{task}.Campaign.Event', default='campaign_main') != 'campaign_main':
|
||||
deep_set(new,
|
||||
keys=f'{task}.Campaign.Event',
|
||||
value=deep_get(self.args, f'{task}.Campaign.Event.{server_}'))
|
||||
value=deep_get(self.args, f'{task}.Campaign.Event.{server}'))
|
||||
# War archive does not allow campaign_main
|
||||
for task in ['WarArchives']:
|
||||
if deep_get(new, keys=f'{task}.Campaign.Event', default='campaign_main') == 'campaign_main':
|
||||
deep_set(new,
|
||||
keys=f'{task}.Campaign.Event',
|
||||
value=deep_get(self.args, f'{task}.Campaign.Event.{server_}'))
|
||||
value=deep_get(self.args, f'{task}.Campaign.Event.{server}'))
|
||||
|
||||
if not is_template:
|
||||
new = self.config_redirect(old, new)
|
||||
|
@ -276,19 +276,25 @@
|
||||
},
|
||||
"Serial": {
|
||||
"name": "Serial",
|
||||
"help": "Default serial for select emulators:\n- BlueStacks 127.0.0.1:5555\n- BlueStacks4 Hyper-V use \"bluestacks4-hyperv\", \"bluestacks4-hyperv-2\" for multi instance, and so on\n- BlueStacks5 Hyper-V use \"bluestacks5-hyperv\", \"bluestacks5-hyperv-1\" for multi instance, and so on\n- NoxPlayer 127.0.0.1:62001\n- NoxPlayer64bit 127.0.0.1:59865\n- MuMuPlayer 127.0.0.1:7555\n- MemuPlayer 127.0.0.1:21503\n- LDPlayer emulator-5554 or 127.0.0.1:5555\n- WSA use \"wsa-0\" to make the game run in the background, which needs to be controlled or closed by third-party software\nIf there are multiple emulator instances running, the default is reserved for one of them and the others will use different serials to avoid conflicts\nOpen console.bat and run `adb devices` to find what they are"
|
||||
"help": "Use \"auto\" to auto-detect emulators, but serial must be filled if multiple emulators are running\nDefault serial for select emulators:\n- BlueStacks 127.0.0.1:5555\n- BlueStacks4 Hyper-V use \"bluestacks4-hyperv\", \"bluestacks4-hyperv-2\" for multi instance, and so on\n- BlueStacks5 Hyper-V use \"bluestacks5-hyperv\", \"bluestacks5-hyperv-1\" for multi instance, and so on\n- NoxPlayer 127.0.0.1:62001\n- NoxPlayer64bit 127.0.0.1:59865\n- MuMuPlayer 127.0.0.1:7555\n- MemuPlayer 127.0.0.1:21503\n- LDPlayer emulator-5554 or 127.0.0.1:5555\n- WSA use \"wsa-0\" to make the game run in the background, which needs to be controlled or closed by third-party software\nIf there are multiple emulator instances running, the default is reserved for one of them and the others will use different serials to avoid conflicts\nOpen console.bat and run `adb devices` to find what they are"
|
||||
},
|
||||
"PackageName": {
|
||||
"name": "Package Name",
|
||||
"help": "com.bilibili.azurlane (CN)\ncom.YoStarEN.AzurLane (EN)\ncom.YoStarJP.AzurLane (JP)\ncom.hkmanjuu.azurlane.gp (TW)\nIf none of these please refer to your AppStore"
|
||||
},
|
||||
"Server": {
|
||||
"name": "Game Server",
|
||||
"help": "Should be aligned with package name e.g. com.YoStarEN.AzurLane > EN",
|
||||
"cn": "CN",
|
||||
"en": "EN",
|
||||
"jp": "JP",
|
||||
"tw": "TW"
|
||||
"help": "Manual select is required if multiple game clients are installed on emulator",
|
||||
"auto": "Auto-detect",
|
||||
"com.bilibili.azurlane": "CN",
|
||||
"com.YoStarEN.AzurLane": "EN",
|
||||
"com.YoStarJP.AzurLane": "JP",
|
||||
"com.hkmanjuu.azurlane.gp": "TW",
|
||||
"com.bilibili.blhx.huawei": "CN com.bilibili.blhx.huawei",
|
||||
"com.bilibili.blhx.mi": "CN com.bilibili.blhx.mi",
|
||||
"com.tencent.tmgp.bilibili.blhx": "CN com.tencent.tmgp.bilibili.blhx",
|
||||
"com.bilibili.blhx.baidu": "CN com.bilibili.blhx.baidu",
|
||||
"com.bilibili.blhx.qihoo": "CN com.bilibili.blhx.qihoo",
|
||||
"com.bilibili.blhx.vivo": "CN com.bilibili.blhx.vivo",
|
||||
"com.bilibili.blhx.uc": "CN com.bilibili.blhx.uc",
|
||||
"com.bilibili.blhx.mzw": "CN com.bilibili.blhx.mzw",
|
||||
"com.yiwu.blhx.yx15": "CN com.yiwu.blhx.yx15"
|
||||
},
|
||||
"ScreenshotMethod": {
|
||||
"name": "Screenshot Method",
|
||||
|
@ -280,15 +280,21 @@
|
||||
},
|
||||
"PackageName": {
|
||||
"name": "Emulator.PackageName.name",
|
||||
"help": "Emulator.PackageName.help"
|
||||
},
|
||||
"Server": {
|
||||
"name": "Emulator.Server.name",
|
||||
"help": "Emulator.Server.help",
|
||||
"cn": "cn",
|
||||
"en": "en",
|
||||
"jp": "jp",
|
||||
"tw": "tw"
|
||||
"help": "Emulator.PackageName.help",
|
||||
"auto": "auto",
|
||||
"com.bilibili.azurlane": "CN",
|
||||
"com.YoStarEN.AzurLane": "EN",
|
||||
"com.YoStarJP.AzurLane": "JP",
|
||||
"com.hkmanjuu.azurlane.gp": "TW",
|
||||
"com.bilibili.blhx.huawei": "CN com.bilibili.blhx.huawei",
|
||||
"com.bilibili.blhx.mi": "CN com.bilibili.blhx.mi",
|
||||
"com.tencent.tmgp.bilibili.blhx": "CN com.tencent.tmgp.bilibili.blhx",
|
||||
"com.bilibili.blhx.baidu": "CN com.bilibili.blhx.baidu",
|
||||
"com.bilibili.blhx.qihoo": "CN com.bilibili.blhx.qihoo",
|
||||
"com.bilibili.blhx.vivo": "CN com.bilibili.blhx.vivo",
|
||||
"com.bilibili.blhx.uc": "CN com.bilibili.blhx.uc",
|
||||
"com.bilibili.blhx.mzw": "CN com.bilibili.blhx.mzw",
|
||||
"com.yiwu.blhx.yx15": "CN com.yiwu.blhx.yx15"
|
||||
},
|
||||
"ScreenshotMethod": {
|
||||
"name": "Emulator.ScreenshotMethod.name",
|
||||
|
@ -276,19 +276,25 @@
|
||||
},
|
||||
"Serial": {
|
||||
"name": "模拟器 Serial",
|
||||
"help": "模拟器默认 Serial:\n- 蓝叠模拟器 127.0.0.1:5555\n- 蓝叠模拟器4 Hyper-v版,填\"bluestacks4-hyperv\"自动连接,多开填\"bluestacks4-hyperv-2\"以此类推\n- 蓝叠模拟器5 Hyper-v版,填\"bluestacks5-hyperv\"自动连接,多开填\"bluestacks5-hyperv-1\"以此类推\n- 夜神模拟器 127.0.0.1:62001\n- 夜神模拟器64位 127.0.0.1:59865\n- MuMu模拟器 127.0.0.1:7555\n- 逍遥模拟器 127.0.0.1:21503\n- 雷电模拟器 emulator-5554 或 127.0.0.1:5555\n- WSA,填\"wsa-0\"使游戏在后台运行,需要使用第三方软件操控或关闭(建议使用scrcpy操控)\n如果你有多个模拟器,它们的 Serial 将不是默认的,可以在 console.bat 中执行 `adb devices` 查询"
|
||||
"help": "填 \"auto\" 自动检测模拟器,有多个模拟器正在运行时必须手动填写 Serial\n模拟器默认 Serial:\n- 蓝叠模拟器 127.0.0.1:5555\n- 蓝叠模拟器4 Hyper-v版,填\"bluestacks4-hyperv\"自动连接,多开填\"bluestacks4-hyperv-2\"以此类推\n- 蓝叠模拟器5 Hyper-v版,填\"bluestacks5-hyperv\"自动连接,多开填\"bluestacks5-hyperv-1\"以此类推\n- 夜神模拟器 127.0.0.1:62001\n- 夜神模拟器64位 127.0.0.1:59865\n- MuMu模拟器 127.0.0.1:7555\n- 逍遥模拟器 127.0.0.1:21503\n- 雷电模拟器 emulator-5554 或 127.0.0.1:5555\n- WSA,填\"wsa-0\"使游戏在后台运行,需要使用第三方软件操控或关闭(建议使用scrcpy操控)\n如果你有多个模拟器,它们的 Serial 将不是默认的,可以在 console.bat 中执行 `adb devices` 查询"
|
||||
},
|
||||
"PackageName": {
|
||||
"name": "游戏包名",
|
||||
"help": "国服 com.bilibili.azurlane\n国际服 com.YoStarEN.AzurLane\n日服 com.YoStarJP.AzurLane\n台服 com.hkmanjuu.azurlane.gp\n国服渠道服需要自行查找"
|
||||
},
|
||||
"Server": {
|
||||
"name": "游戏服务器",
|
||||
"help": "",
|
||||
"cn": "国服",
|
||||
"en": "国际服",
|
||||
"jp": "日服",
|
||||
"tw": "台服"
|
||||
"help": "模拟器上装有多个游戏客户端时,需要手动选择服务器",
|
||||
"auto": "自动检测",
|
||||
"com.bilibili.azurlane": "国服",
|
||||
"com.YoStarEN.AzurLane": "国际服",
|
||||
"com.YoStarJP.AzurLane": "日服",
|
||||
"com.hkmanjuu.azurlane.gp": "台服",
|
||||
"com.bilibili.blhx.huawei": "华为渠道服 com.bilibili.blhx.huawei",
|
||||
"com.bilibili.blhx.mi": "小米渠道服 com.bilibili.blhx.mi",
|
||||
"com.tencent.tmgp.bilibili.blhx": "腾讯应用宝渠道服 com.tencent.tmgp.bilibili.blhx",
|
||||
"com.bilibili.blhx.baidu": "百度渠道服 com.bilibili.blhx.baidu",
|
||||
"com.bilibili.blhx.qihoo": "360渠道服 com.bilibili.blhx.qihoo",
|
||||
"com.bilibili.blhx.vivo": "vivo渠道服 com.bilibili.blhx.vivo",
|
||||
"com.bilibili.blhx.uc": "UC九游渠道服 com.bilibili.blhx.uc",
|
||||
"com.bilibili.blhx.mzw": "拇指玩渠道服 com.bilibili.blhx.mzw",
|
||||
"com.yiwu.blhx.yx15": "一五游戏渠道服 com.yiwu.blhx.yx15"
|
||||
},
|
||||
"ScreenshotMethod": {
|
||||
"name": "模拟器截图方案",
|
||||
|
@ -276,19 +276,25 @@
|
||||
},
|
||||
"Serial": {
|
||||
"name": "模擬器 Serial",
|
||||
"help": "模擬器預設 Serial:\n- 藍疊模擬器 127.0.0.1:5555\n- 藍疊模擬器4 Hyper-v版,填\"bluestacks4-hyperv\"自動連接,多開填\"bluestacks4-hyperv-2\"以此類推\n- 藍疊模擬器5 Hyper-v版,填\"bluestacks5-hyperv\"自動連接,多開填\"bluestacks5-hyperv-1\"以此類推\n- 夜神模擬器 127.0.0.1:62001\n- 夜神模擬器64位元 127.0.0.1:59865\n- MuMu模擬器 127.0.0.1:7555\n- 逍遙模擬器 127.0.0.1:21503\n- 雷電模擬器 emulator-5554 或 127.0.0.1:5555\n- WSA,填\"wsa-0\"使遊戲在後臺運行,需要使用第三方軟件操控或關閉\n如果你有多個模擬器,他們的 Serial 將不是預設的,可以在 console.bat 中執行 `adb devices` 查詢"
|
||||
"help": "填 \"auto\" 自動檢測模擬器,有多個模擬器正在運行時必須手動填寫 Serial\n模擬器預設 Serial:\n- 藍疊模擬器 127.0.0.1:5555\n- 藍疊模擬器4 Hyper-v版,填\"bluestacks4-hyperv\"自動連接,多開填\"bluestacks4-hyperv-2\"以此類推\n- 藍疊模擬器5 Hyper-v版,填\"bluestacks5-hyperv\"自動連接,多開填\"bluestacks5-hyperv-1\"以此類推\n- 夜神模擬器 127.0.0.1:62001\n- 夜神模擬器64位元 127.0.0.1:59865\n- MuMu模擬器 127.0.0.1:7555\n- 逍遙模擬器 127.0.0.1:21503\n- 雷電模擬器 emulator-5554 或 127.0.0.1:5555\n- WSA,填\"wsa-0\"使遊戲在後臺運行,需要使用第三方軟件操控或關閉\n如果你有多個模擬器,他們的 Serial 將不是預設的,可以在 console.bat 中執行 `adb devices` 查詢"
|
||||
},
|
||||
"PackageName": {
|
||||
"name": "遊戲檔名",
|
||||
"help": "國服 com.bilibili.azurlane\n國際服 com.YoStarEN.AzurLane\n日服 com.YoStarJP.AzurLane\n台服 com.hkmanjuu.azurlane.gp\n國服渠道服需要自行查詢"
|
||||
},
|
||||
"Server": {
|
||||
"name": "遊戲伺服器",
|
||||
"help": "",
|
||||
"cn": "國服",
|
||||
"en": "國際服",
|
||||
"jp": "日服",
|
||||
"tw": "台服"
|
||||
"help": "模擬器上裝有多個遊戲客戶端時,需要手動選擇伺服器",
|
||||
"auto": "自動檢測",
|
||||
"com.bilibili.azurlane": "國服",
|
||||
"com.YoStarEN.AzurLane": "國際服",
|
||||
"com.YoStarJP.AzurLane": "日服",
|
||||
"com.hkmanjuu.azurlane.gp": "台服",
|
||||
"com.bilibili.blhx.huawei": "國服 com.bilibili.blhx.huawei",
|
||||
"com.bilibili.blhx.mi": "國服 com.bilibili.blhx.mi",
|
||||
"com.tencent.tmgp.bilibili.blhx": "國服 com.tencent.tmgp.bilibili.blhx",
|
||||
"com.bilibili.blhx.baidu": "國服 com.bilibili.blhx.baidu",
|
||||
"com.bilibili.blhx.qihoo": "國服 com.bilibili.blhx.qihoo",
|
||||
"com.bilibili.blhx.vivo": "國服 com.bilibili.blhx.vivo",
|
||||
"com.bilibili.blhx.uc": "國服 com.bilibili.blhx.uc",
|
||||
"com.bilibili.blhx.mzw": "國服 com.bilibili.blhx.mzw",
|
||||
"com.yiwu.blhx.yx15": "國服 com.yiwu.blhx.yx15"
|
||||
},
|
||||
"ScreenshotMethod": {
|
||||
"name": "模擬器截圖方案",
|
||||
|
@ -4,10 +4,73 @@ Use 'import module.config.server as server' to import, don't use 'from xxx impor
|
||||
"""
|
||||
server = 'cn' # Setting default to cn, will avoid errors when using dev_tools
|
||||
|
||||
VALID_SERVER = ['cn', 'en', 'jp', 'tw']
|
||||
VALID_PACKAGE = {
|
||||
'com.bilibili.azurlane': 'cn',
|
||||
'com.YoStarEN.AzurLane': 'en',
|
||||
'com.YoStarJP.AzurLane': 'jp',
|
||||
'com.hkmanjuu.azurlane.gp': 'tw',
|
||||
}
|
||||
VALID_CN_CHANNEL_PACKAGE = {
|
||||
# App stores
|
||||
'com.bilibili.blhx.huawei': '华为',
|
||||
'com.bilibili.blhx.mi': '小米',
|
||||
'com.tencent.tmgp.bilibili.blhx': '腾讯应用宝',
|
||||
'com.bilibili.blhx.baidu': '百度',
|
||||
'com.bilibili.blhx.qihoo': '360',
|
||||
# 'com.bilibili.blhx.oppo': 'oppo', # Not confirmed
|
||||
'com.bilibili.blhx.vivo': 'vivo',
|
||||
# 'com.bilibili.blhx.letv': '乐视', # Not confirmed
|
||||
# 'com.bilibili.blhx.flyme': '魅族', # Not confirmed
|
||||
# 'com.bilibili.blhx.gionee': '金立', # Not confirmed
|
||||
|
||||
def set_server(target):
|
||||
# 3rd party gaming platforms
|
||||
'com.bilibili.blhx.uc': 'UC九游',
|
||||
'com.bilibili.blhx.mzw': '拇指玩',
|
||||
'com.yiwu.blhx.yx15': '一五游戏',
|
||||
}
|
||||
|
||||
|
||||
def set_server(package_or_server: str):
|
||||
"""
|
||||
Change server and this will effect globally,
|
||||
including assets and server specific methods.
|
||||
|
||||
Args:
|
||||
package_or_server: package name or server.
|
||||
"""
|
||||
global server
|
||||
server = target
|
||||
server = to_server(package_or_server)
|
||||
|
||||
from module.base.resource import release_resources
|
||||
release_resources()
|
||||
|
||||
|
||||
def to_server(package_or_server: str) -> str:
|
||||
"""
|
||||
Convert package/server to server.
|
||||
To unknown packages, consider they are a CN channel servers.
|
||||
"""
|
||||
if package_or_server in VALID_SERVER:
|
||||
return package_or_server
|
||||
elif package_or_server in VALID_PACKAGE:
|
||||
return VALID_PACKAGE[package_or_server]
|
||||
elif package_or_server in VALID_CN_CHANNEL_PACKAGE:
|
||||
return 'cn'
|
||||
else:
|
||||
return 'cn'
|
||||
|
||||
|
||||
def to_package(package_or_server: str) -> str:
|
||||
"""
|
||||
Convert package/server to package.
|
||||
"""
|
||||
package_or_server = package_or_server.lower()
|
||||
if package_or_server in VALID_PACKAGE:
|
||||
return package_or_server
|
||||
|
||||
for key, value in VALID_PACKAGE.items():
|
||||
if value == package_or_server:
|
||||
return key
|
||||
|
||||
raise ValueError(f'Server invalid: {package_or_server}')
|
||||
|
@ -8,7 +8,7 @@ import yaml
|
||||
from atomicwrites import atomic_write
|
||||
from filelock import FileLock
|
||||
|
||||
import module.config.server as server
|
||||
import module.config.server as server_
|
||||
|
||||
LANGUAGES = ['zh-CN', 'en-US', 'ja-JP', 'zh-TW']
|
||||
SERVER_TO_LANG = {
|
||||
@ -112,7 +112,7 @@ def write_file(file, data):
|
||||
with lock:
|
||||
print(f'write: {file}')
|
||||
if ext == '.yaml':
|
||||
with atomic_write(file, overwrite=True, encoding='utf-8') as f:
|
||||
with atomic_write(file, overwrite=True, encoding='utf-8', newline='') as f:
|
||||
if isinstance(data, list):
|
||||
yaml.safe_dump_all(data, f, default_flow_style=False, encoding='utf-8', allow_unicode=True,
|
||||
sort_keys=False)
|
||||
@ -120,7 +120,7 @@ def write_file(file, data):
|
||||
yaml.safe_dump(data, f, default_flow_style=False, encoding='utf-8', allow_unicode=True,
|
||||
sort_keys=False)
|
||||
elif ext == '.json':
|
||||
with atomic_write(file, overwrite=True, encoding='utf-8') as f:
|
||||
with atomic_write(file, overwrite=True, encoding='utf-8', newline='') as f:
|
||||
s = json.dumps(data, indent=2, ensure_ascii=False, sort_keys=False, default=str)
|
||||
f.write(s)
|
||||
else:
|
||||
@ -350,7 +350,7 @@ def dict_to_kv(dictionary, allow_none=True):
|
||||
|
||||
|
||||
def server_timezone():
|
||||
return SERVER_TO_TIMEZONE.get(server.server, 8)
|
||||
return SERVER_TO_TIMEZONE.get(server_.server, 8)
|
||||
|
||||
|
||||
def random_normal_distribution_int(a, b, n=3):
|
||||
|
@ -40,7 +40,7 @@ class AzurLaneUncensored(LoginHandler):
|
||||
|
||||
logger.hr('Push Uncensored Files', level=1)
|
||||
logger.info('This will take a few seconds')
|
||||
command = ['push', 'files', f'/sdcard/Android/data/{self.config.Emulator_PackageName}']
|
||||
command = ['push', 'files', f'/sdcard/Android/data/{self.device.package}']
|
||||
logger.info(f'Command: {command}')
|
||||
self.device.adb_command(command, timeout=30)
|
||||
logger.info('Push success')
|
||||
|
@ -21,13 +21,11 @@ class AppControl(Adb, WSA, Uiautomator2):
|
||||
|
||||
package = package.strip(' \t\r\n')
|
||||
logger.attr('Package_name', package)
|
||||
target = self.config.Emulator_PackageName.strip(' \t\r\n')
|
||||
return package == target
|
||||
return package == self.package
|
||||
|
||||
def app_start(self):
|
||||
package = self.config.Emulator_PackageName
|
||||
method = self.config.Emulator_ControlMethod
|
||||
logger.info(f'App start: {package}')
|
||||
logger.info(f'App start: {self.package}')
|
||||
if self.config.Emulator_Serial == 'wsa-0':
|
||||
self.app_start_wsa(display=0)
|
||||
elif method == 'uiautomator2' or method == 'minitouch':
|
||||
@ -36,9 +34,8 @@ class AppControl(Adb, WSA, Uiautomator2):
|
||||
self.app_start_adb()
|
||||
|
||||
def app_stop(self):
|
||||
package = self.config.Emulator_PackageName
|
||||
method = self.config.Emulator_ControlMethod
|
||||
logger.info(f'App stop: {package}')
|
||||
logger.info(f'App stop: {self.package}')
|
||||
if method == 'uiautomator2' or method == 'minitouch':
|
||||
self.app_stop_uiautomator2()
|
||||
else:
|
||||
|
@ -13,7 +13,7 @@ from deploy.utils import DEPLOY_CONFIG, poor_yaml_read
|
||||
from module.base.decorator import cached_property
|
||||
from module.base.utils import ensure_time
|
||||
from module.config.config import AzurLaneConfig
|
||||
from module.device.game_package import package_to_server
|
||||
from module.config.server import set_server
|
||||
from module.device.method.utils import (del_cached_property, possible_reasons,
|
||||
random_port, recv_all)
|
||||
from module.exception import RequestHumanTakeover
|
||||
@ -42,7 +42,7 @@ class Connection:
|
||||
self.config = config
|
||||
|
||||
# Init adb client
|
||||
logger.attr('Adb_binary', self.adb_binary)
|
||||
logger.attr('AdbBinary', self.adb_binary)
|
||||
# Monkey patch to custom adb
|
||||
adbutils.adb_path = lambda: self.adb_binary
|
||||
# Remove global proxies, or uiautomator2 will go through it
|
||||
@ -72,7 +72,16 @@ class Connection:
|
||||
|
||||
# Connect
|
||||
self.adb_connect(self.serial)
|
||||
logger.attr('Adb_device', self.adb)
|
||||
logger.attr('AdbDevice', self.adb)
|
||||
|
||||
# Package
|
||||
self.package = self.config.Emulator_PackageName
|
||||
if self.package == 'auto':
|
||||
self.detect_package(set_config=False)
|
||||
else:
|
||||
set_server(self.package)
|
||||
logger.attr('PackageName', self.package)
|
||||
logger.attr('Server', self.config.SERVER)
|
||||
|
||||
@staticmethod
|
||||
def find_bluestacks4_hyperv(serial):
|
||||
@ -204,7 +213,7 @@ class Connection:
|
||||
Equivalent to `adb -s <serial> shell <*cmd>`
|
||||
|
||||
Args:
|
||||
cmd (list):
|
||||
cmd (list, str):
|
||||
**kwargs:
|
||||
rstrip (bool): strip the last empty line (Default: True)
|
||||
stream (bool): return stream instead of string output (Default: False)
|
||||
@ -212,7 +221,8 @@ class Connection:
|
||||
Returns:
|
||||
str or socket if stream=True
|
||||
"""
|
||||
cmd = list(map(str, cmd))
|
||||
if not isinstance(cmd, str):
|
||||
cmd = list(map(str, cmd))
|
||||
result = self.adb.shell(cmd, timeout=10, **kwargs)
|
||||
return result
|
||||
|
||||
@ -543,16 +553,30 @@ class Connection:
|
||||
'please copy one of the available devices listed above to Alas.Emulator.Serial')
|
||||
raise RequestHumanTakeover
|
||||
|
||||
def detect_package(self, keywords=('azurlane', 'blhx')):
|
||||
def list_package(self):
|
||||
"""
|
||||
Find all packages on device.
|
||||
Use dumpsys first for faster.
|
||||
"""
|
||||
# 80ms
|
||||
logger.info('Get package list')
|
||||
output = self.adb_shell('dumpsys package | grep "Package \["')
|
||||
packages = re.findall(r'Package \[([^\s]+)\]', output)
|
||||
if len(packages):
|
||||
return packages
|
||||
|
||||
# 200ms
|
||||
logger.info('Get package list')
|
||||
output = self.adb_shell(['pm', 'list', 'packages'])
|
||||
packages = re.findall(r'package:([^\s]+)', output)
|
||||
return packages
|
||||
|
||||
def detect_package(self, keywords=('azurlane', 'blhx'), set_config=True):
|
||||
"""
|
||||
Show all possible packages with the given keyword on this device.
|
||||
"""
|
||||
logger.hr('Detect package')
|
||||
logger.info('Fetching package list')
|
||||
output = self.adb_shell(['pm', 'list', 'packages'])
|
||||
packages = re.findall(r'package:([^\s]+)', output)
|
||||
if not packages:
|
||||
packages = []
|
||||
packages = self.list_package()
|
||||
packages = [p for p in packages if any([k in p for k in keywords])]
|
||||
|
||||
# Show packages
|
||||
@ -571,25 +595,15 @@ class Connection:
|
||||
raise RequestHumanTakeover
|
||||
if len(packages) == 1:
|
||||
logger.info('Auto package detection found only one package, using it')
|
||||
package = packages[0]
|
||||
# Get server
|
||||
server = package_to_server(package)
|
||||
if server is not None:
|
||||
logger.info(f'Package "{package}" is {keywords[0]} {server.upper()}, using it')
|
||||
else:
|
||||
logger.info(f'Package "{package}" might be {keywords[0]} CN channel, using it')
|
||||
server = 'cn'
|
||||
self.package = packages[0]
|
||||
# Set config
|
||||
with self.config.multi_set():
|
||||
self.config.Emulator_PackageName = package
|
||||
self.config.Emulator_Server = server
|
||||
if set_config:
|
||||
self.config.Emulator_PackageName = self.package
|
||||
# Set server
|
||||
logger.info('Server changed, release resources')
|
||||
from module.config.server import set_server
|
||||
set_server(server)
|
||||
set_server(self.package)
|
||||
else:
|
||||
logger.critical(
|
||||
f'Multiple {keywords[0]} packages found, auto package detection cannot decide which to choose, '
|
||||
'please copy one of the available devices listed above to Alas.Emulator.PackageName '
|
||||
'and set Alas.Emulator.Server to the corresponding server')
|
||||
'please copy one of the available devices listed above to Alas.Emulator.PackageName')
|
||||
raise RequestHumanTakeover
|
||||
|
@ -1,10 +0,0 @@
|
||||
GAME_PACKAGE = {
|
||||
'com.bilibili.azurlane': 'cn',
|
||||
'com.YoStarEN.AzurLane': 'en',
|
||||
'com.YoStarJP.AzurLane': 'jp',
|
||||
'com.hkmanjuu.azurlane.gp': 'tw',
|
||||
}
|
||||
|
||||
|
||||
def package_to_server(package: str) -> str:
|
||||
return GAME_PACKAGE.get(package, 'cn')
|
@ -195,7 +195,7 @@ class Adb(Connection):
|
||||
bool: If success to start
|
||||
"""
|
||||
if not package_name:
|
||||
package_name = self.config.Emulator_PackageName
|
||||
package_name = self.package
|
||||
result = self.adb_shell([
|
||||
'monkey', '-p', package_name, '-c',
|
||||
'android.intent.category.LAUNCHER', '1'
|
||||
@ -216,7 +216,7 @@ class Adb(Connection):
|
||||
def app_stop_adb(self, package_name=None):
|
||||
""" Stop one application: am force-stop"""
|
||||
if not package_name:
|
||||
package_name = self.config.Emulator_PackageName
|
||||
package_name = self.package
|
||||
self.adb_shell(['am', 'force-stop', package_name])
|
||||
|
||||
@retry
|
||||
|
@ -202,7 +202,7 @@ class Uiautomator2(Connection):
|
||||
@retry
|
||||
def app_start_uiautomator2(self, package_name=None):
|
||||
if not package_name:
|
||||
package_name = self.config.Emulator_PackageName
|
||||
package_name = self.package
|
||||
try:
|
||||
self.u2.app_start(package_name)
|
||||
except u2.exceptions.BaseError as e:
|
||||
@ -213,7 +213,7 @@ class Uiautomator2(Connection):
|
||||
@retry
|
||||
def app_stop_uiautomator2(self, package_name=None):
|
||||
if not package_name:
|
||||
package_name = self.config.Emulator_PackageName
|
||||
package_name = self.package
|
||||
self.u2.app_stop(package_name)
|
||||
|
||||
@retry
|
||||
|
@ -76,13 +76,12 @@ class WSA(Connection):
|
||||
_activityRE = re.compile(
|
||||
r'ACTIVITY (?P<package>[^\s]+)/(?P<activity>[^/\s]+) \w+ pid=(?P<pid>\d+)'
|
||||
)
|
||||
package = self.config.Emulator_PackageName
|
||||
output = self.adb_shell(['dumpsys', 'activity', 'top'])
|
||||
ms = _activityRE.finditer(output)
|
||||
ret = None
|
||||
for m in ms:
|
||||
ret = m.group('package')
|
||||
if(ret == package):
|
||||
if ret == self.package:
|
||||
return ret
|
||||
if ret: # get last result
|
||||
return ret
|
||||
@ -99,7 +98,7 @@ class WSA(Connection):
|
||||
bool: If success to start
|
||||
"""
|
||||
if not package_name:
|
||||
package_name = self.config.Emulator_PackageName
|
||||
package_name = self.package
|
||||
self.adb_shell(['svc', 'power', 'stayon', 'true'])
|
||||
activity_name = self.get_main_activity_name(package_name=package_name)
|
||||
result = self.adb_shell(['am', 'start', '--display', display, f'{package_name}/{activity_name}'])
|
||||
@ -119,7 +118,7 @@ class WSA(Connection):
|
||||
@retry
|
||||
def get_main_activity_name(self, package_name=None):
|
||||
if not package_name:
|
||||
package_name = self.config.Emulator_PackageName
|
||||
package_name = self.package
|
||||
try:
|
||||
output = self.adb_shell(['dumpsys', 'package', package_name])
|
||||
_activityRE = re.compile(
|
||||
@ -140,7 +139,7 @@ class WSA(Connection):
|
||||
"""
|
||||
try:
|
||||
get_dump_sys_display = str(self.adb_shell(['dumpsys', 'display']))
|
||||
display_id_list = re.findall(r'systemapp:' + self.config.Emulator_PackageName + ':' + '(.+?)', get_dump_sys_display, re.S)
|
||||
display_id_list = re.findall(r'systemapp:' + self.package + ':' + '(.+?)', get_dump_sys_display, re.S)
|
||||
display_id = int(display_id_list[0])
|
||||
return display_id
|
||||
except IndexError:
|
||||
|
@ -217,7 +217,7 @@ class Screenshot(Adb, WSA, Uiautomator2, AScreenCap):
|
||||
return True
|
||||
logger.info(f'Game running on display {display}')
|
||||
logger.warning('Game not running on display 0, will be restarted')
|
||||
self.app_stop_uiautomator2(self.config.Emulator_PackageName)
|
||||
self.app_stop_uiautomator2()
|
||||
return False
|
||||
elif self.config.Emulator_ScreenshotMethod == 'uiautomator2':
|
||||
logger.warning(f'Received pure black screenshots from emulator, color: {color}')
|
||||
|
@ -118,13 +118,8 @@ class ProcessManager:
|
||||
set_file_logger(name=config_name)
|
||||
set_func_logger(func=q.put)
|
||||
|
||||
# Set server before loading any buttons.
|
||||
import module.config.server as server
|
||||
from module.config.config import AzurLaneConfig
|
||||
|
||||
AzurLaneConfig.stop_event = e
|
||||
config = AzurLaneConfig(config_name=config_name)
|
||||
server.server = deep_get(config.data, keys="Alas.Emulator.Server", default="cn")
|
||||
try:
|
||||
# Run alas
|
||||
if func == "Alas":
|
||||
|
Loading…
Reference in New Issue
Block a user