#!/usr/bin/env python3
import frida, time, subprocess, sys
sys.path.insert(0,"/root/ants"); import emu
JS=r"""
function ins(){var m=Process.findModuleByName("libil2cpp.so");if(!m)return false;var b=m.base;
 function T(f){try{f();}catch(e){send({w:""+e});}}
 [[0xd34fb9,"DecodeResponse"],[0xd3c44a,"OnResponse"],[0xe5a928,"AssemblePlayerList"],[0xd3c903,"NetworkController.Connect"],[0xd6c1e0,"PingRegionsConnectBest"],[0x1009bc0,"ConnectToNameServer"],[0x100ee8a,"OnOperationResponse"]].forEach(function(x){
   T(function(){Interceptor.attach(b.add(x[0]),{onEnter:function(){send({g:"CHAIN "+x[1]});}});});});
 T(function(){Interceptor.attach(b.add(0x1012c1a),{onEnter:function(a){try{send({g:">>> OnStatusChanged "+a[1].toInt32()});}catch(e){}}});});
 send({g:"__ready"});return true;}
if(!ins()){var iv=setInterval(function(){if(ins())clearInterval(iv);},120);}
"""
t=emu.launch_to_menu(); print(f"[menu {t:.0f}s]",flush=True)
emu.tap(700,730); time.sleep(4)
dev=frida.get_usb_device(timeout=10)
pid=int(subprocess.run([emu.ADB,"shell","pidof","se.foglo.svt"],capture_output=True,text=True).stdout.split()[0])
s=dev.attach(pid); sc=s.create_script(JS)
sc.on("message",lambda m,d: print(m.get("payload",m),flush=True)); sc.load(); time.sleep(1)
print("[GO]",flush=True); emu.tap(1355,970); time.sleep(3); emu.tap(1355,970); time.sleep(20)
emu.screenshot("/root/ants/after_go.png"); print("=== shot saved ===",flush=True)
