tkkcc / GameBot

1 stars 0 forks source link

design #1

Open tkkcc opened 1 month ago

tkkcc commented 1 month ago

GameBot is designed to work for years without human operations. GameBot should be self upgradable, because mobile games iterating fast. GameBot relies on AccessibilityService and MediaProjection, and use hidden api via HiddenApiRefinePlugin, and gain permission via Shizuku and libsu

plugin / hot update / hot fix / code push / dynamic loading / scripting

  1. plain DexClassLoader/PathClassLoader

    host apk --DexClassLoader/PathClassLoader--> plugin apk/jar/dex

    compile andorid library into dex and load via DexClassLoader, the drawback is all dependencies must be bundled into host apk, library can't add new dependencies, and host apk almost can't use r8. library's resource can't be simply load, but kotlin i18n solutions can be used, like lyricist. fat jar solutions may help, like shadow

    compile andrlid application into apk and load via PathClassLoader, this is what mediabox does. plugin can use new dependencies, but r8 almost unusable.

  2. Shadow / Tinker

    hacky and complicated, may be try BlackShadow

    above two solutions violate google play policy:

    An app distributed via Google Play may not modify, replace, or update itself using any method other than Google Play's update mechanism. Likewise, an app may not download executable code (such as dex, JAR, .so files) from a source other than Google Play. This restriction does not apply to code that runs in a virtual machine or an interpreter where either provides indirect access to Android APIs (such as JavaScript in a webview or browser). Apps or third-party code, like SDKs, with interpreted languages (JavaScript, Python, Lua, etc.) loaded at run time (for example, not packaged with the app) must not allow potential violations of Google Play policies.

  3. flutter

    shorebird

    Also Shorebird does not support changing native code (e.g. Java/Kotlin on Android or Objective-C/Swift on iOS). The tool will warn you during an attempted patch if you have changed native code.

  4. react native

    react-native-code-push

    Any product changes which touch native code (e.g. modifying your AppDelegate.m/MainActivity.java file, adding a new plugin) cannot be distributed via CodePush, and therefore, must be updated via the appropriate store(s).

    above two solutions is complicated as GameBot need deep integration with android system api, so we need to export java/kotlin function into dart and js. we also need to ship their runtime library. can use rich ui component. flutter doesn't support x86. react native does't support 120fps

  5. js embedded

    rhino, used in autojs and it's forks nodejs, used in autojs boa quickjs deno

  6. python embedded

    jython chaquopy rustpython, compilable but runtime exception

  7. lua embedded luajava mlua

  8. wasm embedded wasmtime wasmer

    above solutions are simpler and safer, but we need to export java/kotlin function into vm, if using compose instead of view, we need to implement some kind of serializable data structure. we need to transfer image byte into vm efficiently. first three solutions have zero compile time, but need to struggle with dynamic typing. for wasm, we can use rust, but have to drop support for 32 bit platforms.

    lib size for x86_64:

    jni-rs
    132K
    
    +android_logger
    892K
    
    +mlua(lua51,vendered)
    1.1M
    +mlua(lua54,vendered)
    1.2M
    +mlua(luajit,vendered)
    1.5M
    +mlua(luaujit)
    1.8+1.2M
    +mlua(luau)
    1.5+1.2M
    +wasmer
    4.5M
    +rustpython
    7.3M
    +boa
    4.7M
    +wasmtime
    5.7M
  9. simplar projects

    kotlin/java: FGA, granblue, RobotHelper js: hamibot, autojs6, autox, 自动精灵, EasyClick, 冰狐, aibote, 云控, aiwork lua: 懒人精灵, 节点精灵, 触动精灵, 触摸精灵, 积木编程, 鱼叉助手, 飞天助手, 叉叉助手, autolua python: ascript, aibote, 小派精灵 VBScript/Q: 按键精灵 rpa: 影刀, UiBot, ...

tkkcc commented 4 weeks ago

plugin update from internet

we use git protocol to do this for its atomic and free hosting. jgit is very small, total dex 1M, while git2 need 6.1M * 2 with vendored ssl, and we have to disable ssl check. another lib to try is gitoxide

tkkcc commented 4 weeks ago

rootless support

should stick with shizuku and libsu. These two share common functionality (the shell user permission).

benefits:

  1. single interface for host and plugin development
  2. no need for multiple resolution development

drawbacks:

  1. no one like to install two apps for one task. so some apps embed activation function., like virtual machine apps.
tkkcc commented 4 weeks ago

wasm or lua

should stick with wasm, benefits:

  1. runtime and plugin all in rust
  2. modern language and promising ecosystem
  3. no one do this before

drawbacks:

  1. need compile when developing
  2. runtime and plugin size is bigger
  3. not open source to user, but not easy to hack
tkkcc commented 4 weeks ago

market / billing / online device limitation

  1. should support publish to market and create standalone app ( custom package name and icon )
  2. like neovim, aur, use git repo as plugin distribution. use a index file as the market (simple toml file, pull from our git), each plugin has repo, icon, author, description. plugin developer pull request to add new plugin (but how to update description?), the server needs to get commit messages (with commit time) from repo, total and recent downloads like crates.io. but pull update from multiple git repo can be limited. should ask plugin developers to push package info to our repo, like aur and crates, npm?
  3. monetize is based on cloud support: builtin payment support, billing based on device count and time.

different from ascript: total free if the plugin doesn't use our server. free to make standalone app. 1% billing for using our service.

different from lanren: better local ocr and captcha bypass

  1. make and use plugin in multiple language as we use wasm
  2. provide web debug tool like ascript and lanren, we need to run wasm compiler in browser? or just embed lua. or make native debug tool