Last active
February 27, 2023 10:42
-
-
Save ziyuang/21aca9e2788a29719232a0fa2f58d7a2 to your computer and use it in GitHub Desktop.
Send keys to maximize galaxies in Antimatter Dimensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import math | |
import re | |
import time | |
from dataclasses import dataclass | |
from pywinauto.application import Application, WindowSpecification | |
from pywinauto.keyboard import VirtualKeyAction | |
@dataclass | |
class EighthDimensionRequiments: | |
dim_boost: int = -1 | |
galaxy: int = -1 | |
def get_8th_dim_requirements(dlg: WindowSpecification) -> EighthDimensionRequiments: | |
ui_texts = [ | |
child.window_text() for child in dlg.Document.children(control_type="Text") | |
] | |
requirements = EighthDimensionRequiments() | |
for i, text in enumerate(ui_texts): | |
if (m_boost := re.match("Dimension Boost", text)) or re.match( | |
"Antimatter Galaxies", text | |
): | |
m = re.search(r"[\d,]+", ui_texts[i + 1]) | |
assert m is not None, f'Cannot find a number in string "{ui_texts[i + 1]}"' | |
n = int(m.group(0).replace(",", "")) | |
if m_boost: | |
requirements.dim_boost = n | |
else: | |
requirements.galaxy = n | |
return requirements | |
def send_keys(keys: str, pause: float = 0.0): | |
actions = [VirtualKeyAction(ord(k)) for k in keys.upper()] | |
for a in actions: | |
a.run() | |
if pause > 0: | |
time.sleep(pause) | |
def stage_1(start_from: int, pause: float): | |
for i in range(start_from, 8 + 1): | |
send_keys("".join([str(j) for j in range(1, i + 1)]), pause=pause) | |
send_keys(str(i) + "d", pause=pause) | |
def stage_2(dim8_repeats: int, pause: float): | |
send_keys("1234567" + "8t" * dim8_repeats + "gd", pause=pause) | |
def run(stage: int, stage1_dim: int, pause: float): | |
app = Application(backend="uia") | |
title = "Antimatter Dimensions" | |
app.connect(title=title) | |
dlg = app.top_window() | |
dlg.set_focus() | |
dlg.wait("active") | |
default_stage1_dim = 4 | |
round_1 = True | |
while True: | |
dlg.set_focus() | |
if stage <= 1: | |
stage_1( | |
start_from=stage1_dim if round_1 else default_stage1_dim, pause=pause | |
) | |
galaxy_requirement = get_8th_dim_requirements(dlg).galaxy | |
dim8_repeats = int(math.ceil(galaxy_requirement / 10)) | |
stage_2(dim8_repeats=dim8_repeats, pause=pause) | |
stage = 1 | |
round_1 = False | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-s", "--stage", type=int, choices=[1, 2], default=1) | |
parser.add_argument("-d", "--start-dim", type=int, default=4) | |
parser.add_argument("-p", "--pause", type=float, default=0.01) | |
args = parser.parse_args() | |
run( | |
stage=args.stage, | |
stage1_dim=args.start_dim, | |
pause=args.pause, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment