From afa68adf00405c36000f16f6aece059e7ca74de9 Mon Sep 17 00:00:00 2001 From: LA-DI-DA <11174151+0O0o0oOoO00@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:19:21 +0800 Subject: [PATCH] Add: change ship's attribute --- bin/Lua/ShipFucker.lua | 72 +++++++++++++++++++++++++ config/template.json | 5 ++ module/config/argument/args.json | 14 +++++ module/config/argument/argument.yaml | 6 +++ module/config/argument/task.yaml | 1 + module/config/config_generated.py | 5 ++ module/config/i18n/en-US.json | 18 +++++++ module/config/i18n/ja-JP.json | 18 +++++++ module/config/i18n/zh-CN.json | 18 +++++++ module/config/i18n/zh-TW.json | 18 +++++++ module/gg_handler/change_attribute.py | 77 +++++++++++++++++++++++++++ module/gg_handler/gg_u2.py | 4 ++ 12 files changed, 256 insertions(+) create mode 100644 bin/Lua/ShipFucker.lua create mode 100644 module/gg_handler/change_attribute.py diff --git a/bin/Lua/ShipFucker.lua b/bin/Lua/ShipFucker.lua new file mode 100644 index 000000000..83431c18f --- /dev/null +++ b/bin/Lua/ShipFucker.lua @@ -0,0 +1,72 @@ +function string.split(s, p) + local Result= {} + string.gsub(s, '[^'..p..']+', function(w) table.insert(Result, w) end) + return Result +end +-- 199034;6;3:60>-100;417>-100 +-- {Id};{Star};{Type}:{Attribute}>{Target}[;{Attribute}>{Target}...][|{Id};{Star};{Type}:{Attribute}>{Target}[;{Attribute}>{Target}...]] +function ChangeShipAttribute() + local Result = gg.prompt({"格式:{舰船Id};{舰船星级};{类型Id}:{属性}>{目标值}[;{属性}>{目标值}...],多个之间用'|'连接"} + ,{} + ,{"text"}) + + local TargetList = string.split(tostring(Result[1]), "|") + for i = 1, #TargetList do + local SplitedTarget = string.split(TargetList[i], ":") + local ShipData = SplitedTarget[1] -- {Id};{Star};{Type} + local ShipAttributeList = string.split(SplitedTarget[2], ";") + --[[ + { + {Attribute}>{Target}, + {Attribute}>{Target}, + ... + } + --]] + + gg.searchNumber(ShipData.."::610", gg.TYPE_DOUBLE) + gg.refineNumber(string.split(ShipData, ";")[1], gg.TYPE_AUTO) + + local SearchResult = gg.getResults(1024) + for j = 1, #SearchResult do + local MemoryFrom = SearchResult[j].address - 0x1000 + local MemoryTo = SearchResult[j].address + 0x1000 + for k = 1, #ShipAttributeList do + -- fuck gg + -- fuck lua + -- fuck dynamic type + -- fuck everything + local SplitedAttribute = string.split(tostring(ShipAttributeList[k]), ">") + local AttributeToSearchList = SplitedAttribute[1] + local TargetAttributeList = SplitedAttribute[2] + gg.searchNumber(AttributeToSearchList, gg.TYPE_DOUBLE, false, gg.SIGN_EQUAL, MemoryFrom, MemoryTo) + gg.getResults(1024) + gg.editAll(TargetAttributeList, gg.TYPE_DOUBLE) + gg.clearResults() + end + + end + end + Exit("修改成功!") +end + +function Exit(Message) + gg.alert(Message) + os.exit() +end + +function Main() + Choice = gg.choice({ + "改属性", + "退出", + }, nil, nil) + if Choice == 1 then + ChangeShipAttribute() + end + if Choice == 2 then + Exit("退出成功!") + end + FX=false +end + +gg.clearResults() +Main() \ No newline at end of file diff --git a/config/template.json b/config/template.json index 4114d24fb..5929c6fd0 100644 --- a/config/template.json +++ b/config/template.json @@ -1972,6 +1972,11 @@ "TargetType": "BB", "ShipData": "106021;1;6\n107041;1;6\n206011;1;6\n107011;1;6\n" }, + "ChangeAttribute": { + "Enable": false, + "PushLua": false, + "ShipData": null + }, "Storage": { "Storage": {} } diff --git a/module/config/argument/args.json b/module/config/argument/args.json index 0ada11945..177c299e3 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -9455,6 +9455,20 @@ "value": "106021;1;6\n107041;1;6\n206011;1;6\n107011;1;6\n" } }, + "ChangeAttribute": { + "Enable": { + "type": "checkbox", + "value": false + }, + "PushLua": { + "type": "checkbox", + "value": false + }, + "ShipData": { + "type": "textarea", + "value": "" + } + }, "Storage": { "Storage": { "type": "storage", diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index 8a2688f3d..70882d299 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -743,6 +743,12 @@ ChangeShip: 107041;1;6 206011;1;6 107011;1;6 +ChangeAttribute: + Enable: false + PushLua: false + ShipData: + type: textarea + value: '' InfiniteDelay: Commission: diff --git a/module/config/argument/task.yaml b/module/config/argument/task.yaml index c058bc9cf..8bd30a708 100644 --- a/module/config/argument/task.yaml +++ b/module/config/argument/task.yaml @@ -344,6 +344,7 @@ Tool: - GGHandler - PowerLimit - ChangeShip + - ChangeAttribute SomethingSpecial: - InfiniteDelay - TurnOffForcedOnSettings diff --git a/module/config/config_generated.py b/module/config/config_generated.py index b3f94b6c5..3492fc3cb 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -457,6 +457,11 @@ class GeneratedConfig: ChangeShip_TargetType = 'BB' # CV, BB ChangeShip_ShipData = '106021;1;6\n107041;1;6\n206011;1;6\n107011;1;6\n' + # Group `ChangeAttribute` + ChangeAttribute_Enable = False + ChangeAttribute_PushLua = False + ChangeAttribute_ShipData = None + # Group `InfiniteDelay` InfiniteDelay_Commission = False InfiniteDelay_Research = False diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 24296a1f7..fdc496466 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -2551,6 +2551,24 @@ "help": "ChangeShip.ShipData.help" } }, + "ChangeAttribute": { + "_info": { + "name": "ChangeAttribute._info.name", + "help": "ChangeAttribute._info.help" + }, + "Enable": { + "name": "ChangeAttribute.Enable.name", + "help": "ChangeAttribute.Enable.help" + }, + "PushLua": { + "name": "ChangeAttribute.PushLua.name", + "help": "ChangeAttribute.PushLua.help" + }, + "ShipData": { + "name": "ChangeAttribute.ShipData.name", + "help": "ChangeAttribute.ShipData.help" + } + }, "InfiniteDelay": { "_info": { "name": "InfiniteDelay._info.name", diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index f17bac210..bfecb0387 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -2551,6 +2551,24 @@ "help": "ChangeShip.ShipData.help" } }, + "ChangeAttribute": { + "_info": { + "name": "ChangeAttribute._info.name", + "help": "ChangeAttribute._info.help" + }, + "Enable": { + "name": "ChangeAttribute.Enable.name", + "help": "ChangeAttribute.Enable.help" + }, + "PushLua": { + "name": "ChangeAttribute.PushLua.name", + "help": "ChangeAttribute.PushLua.help" + }, + "ShipData": { + "name": "ChangeAttribute.ShipData.name", + "help": "ChangeAttribute.ShipData.help" + } + }, "InfiniteDelay": { "_info": { "name": "InfiniteDelay._info.name", diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index f2c7830f4..61e985143 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -2551,6 +2551,24 @@ "help": "格式为\"舰船Id;星级;舰种Id\"\n参考https://github.com/0O0o0oOoO00/SmallKai中的数据\n清空会恢复默认" } }, + "ChangeAttribute": { + "_info": { + "name": "改属性", + "help": "需要和倍率一起使用" + }, + "Enable": { + "name": "启用", + "help": "" + }, + "PushLua": { + "name": "始终推送Lua", + "help": "有时推送时会失败,视情况开启或者关闭" + }, + "ShipData": { + "name": "舰船数据", + "help": "格式为\"舰船Id;舰船星级;类型Id:属性>目标值[;属性>目标值...]\"\n参考https://github.com/0O0o0oOoO00/SmallKai中的数据" + } + }, "InfiniteDelay": { "_info": { "name": "无限推迟", diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index c422cddf2..af4b12258 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -2551,6 +2551,24 @@ "help": "ChangeShip.ShipData.help" } }, + "ChangeAttribute": { + "_info": { + "name": "ChangeAttribute._info.name", + "help": "ChangeAttribute._info.help" + }, + "Enable": { + "name": "ChangeAttribute.Enable.name", + "help": "ChangeAttribute.Enable.help" + }, + "PushLua": { + "name": "ChangeAttribute.PushLua.name", + "help": "ChangeAttribute.PushLua.help" + }, + "ShipData": { + "name": "ChangeAttribute.ShipData.name", + "help": "ChangeAttribute.ShipData.help" + } + }, "InfiniteDelay": { "_info": { "name": "InfiniteDelay._info.name", diff --git a/module/gg_handler/change_attribute.py b/module/gg_handler/change_attribute.py new file mode 100644 index 000000000..1af5e17e6 --- /dev/null +++ b/module/gg_handler/change_attribute.py @@ -0,0 +1,77 @@ +from module.logger import logger +from module.config.config import deep_get +from module.base.base import ModuleBase +import uiautomator2 as u2 + +class ChangeAttribute(ModuleBase): + + def __init__(self, config, device): + super().__init__(config, device) + self.d = u2.connect(self.device.serial) + self.gg_package_name = deep_get(self.config.data, keys='GameManager.GGHandler.GGPackageName') + + def GetShipData(self): + DataList: str = deep_get(self.config.data, "GameManager.ChangeAttribute.ShipData").split("\n") + DataString = "|".join(DataList) + return DataString + + def PushLua(self): + IsPush = deep_get(self.config.data, keys='GameManager.ChangeAttribute.PushLua') + if IsPush: + import os + os.popen(f'"toolkit/Lib/site-packages/adbutils/binaries/adb.exe" -s' + f' {self.device.serial} shell mkdir /sdcard/Notes') + self.device.sleep(0.5) + os.popen(f'"toolkit/Lib/site-packages/adbutils/binaries/adb.exe" -s' + f' {self.device.serial} shell rm /sdcard/Notes/ShipFucker.lua') + self.device.sleep(0.5) + os.popen(f'"toolkit/Lib/site-packages/adbutils/binaries/adb.exe" -s' + f' {self.device.serial} push "bin/Lua/ShipFucker.lua" /sdcard/Notes/ShipFucker.lua') + self.device.sleep(0.5) + logger.info('Lua Pushed') + + def ChangeAttribute(self): + _set = False + _confirmed = False + while 1: + if self.d(resourceId=f"{self.gg_package_name}:id/search_toolbar").exists: + self.d.xpath( + f'//*[@resource-id="{self.gg_package_name}' + f':id/search_toolbar"]/android.widget.ImageView[last()]' + ).click() + self.device.sleep(1) + if self.d(resourceId=f"{self.gg_package_name}:id/file").exists: + self.d(resourceId=f"{self.gg_package_name}:id/file").send_keys("/sdcard/Notes/ShipFucker.lua") + logger.info('Lua path set') + if self.d.xpath('//*[@text="执行"]').exists: + self.d.xpath('//*[@text="执行"]').click() + logger.info('Click Run') + self.device.sleep(0.5) + if self.d.xpath('//*[contains(@text,"改属性")]').exists: + self.d.xpath('//*[contains(@text,"改属性")]').click() + logger.info('Click Change Statistic') + self.device.sleep(0.5) + if self.d(resourceId=f"{self.gg_package_name}:id/edit").exists: + ShipDataString = self.GetShipData() + self.d(resourceId=f"{self.gg_package_name}:id/edit")[0].send_keys(ShipDataString) + self.device.sleep(0.5) + _set = True + if _set and self.d.xpath('//*[@text="确定"]').exists: + self.d.xpath('//*[@text="确定"]').click() + logger.info("Click confirm") + self.device.sleep(0.5) + _confirmed = True + self.d.wait_timeout = 90.0 + + if _set and _confirmed: + try: + self.d.xpath('//*[@text="确定"]').click() + self.device.sleep(0.5) + self.d.xpath('//*[@text="确定"]').click() + finally: + pass + self.d.wait_timeout = 3 + if _set and _confirmed: + break + else: + return 0 \ No newline at end of file diff --git a/module/gg_handler/gg_u2.py b/module/gg_handler/gg_u2.py index 9aaf915bf..cb6e5777c 100644 --- a/module/gg_handler/gg_u2.py +++ b/module/gg_handler/gg_u2.py @@ -4,6 +4,7 @@ from module.config.config import deep_get from module.base.base import ModuleBase as Base import uiautomator2 as u2 from module.gg_handler.change_ship import ChangeShip +from module.gg_handler.change_attribute import ChangeAttribute class GGU2(Base): @@ -132,6 +133,8 @@ class GGU2(Base): _repush = deep_get(self.config.data, keys='GameManager.GGHandler.RepushLua') ShipChanger = ChangeShip(self.config, self.device) ShipChanger.PushLua() + AttributeChanger = ChangeAttribute(self.config, self.device) + AttributeChanger.PushLua() if _repush: os.popen(f'"toolkit/Lib/site-packages/adbutils/binaries/adb.exe" -s' f' {self.device.serial} shell mkdir /sdcard/Notes') @@ -144,6 +147,7 @@ class GGU2(Base): self.device.sleep(0.5) logger.info('Lua Pushed') ShipChanger.ChangeShipType() + AttributeChanger.ChangeAttribute() while 1: self.device.sleep(1) if self.d(resourceId=f"{self.gg_package_name}:id/search_toolbar").exists: