import frida, time, subprocess, sys
sys.path.insert(0,"/root/ants"); import emu
JS=r"""
function str(p){try{if(p.isNull())return "null";var n=p.add(8).readS32();if(n<0||n>200)return "len?";return p.add(0xc).readUtf16String(n);}catch(e){return "ERR";}}
function ins(){var m=Process.findModuleByName("libil2cpp.so");if(!m)return false;var b=m.base;
 function T(f){try{f();}catch(e){send({g:"ERR "+e});}}
 T(function(){Interceptor.attach(b.add(0xd916d5),{onLeave:function(r){send({g:"publicID='"+str(r)+"'"});}});});  // PlayerProfile.get_publicID
 T(function(){Interceptor.attach(b.add(0xe5a928),{  // AssemblePlayerList
   onEnter:function(){this.n=(this.n||0);send({g:">> AssemblePlayerList enter"});},
   onLeave:function(r){send({g:"<< AssemblePlayerList ret="+r.toInt32()});}});});
 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)
seen=set()
def onmsg(m,d):
    p=m.get("payload",{})
    if isinstance(p,dict) and "g" in p:
        g=p["g"]
        if g.startswith("<<") or g.startswith("publicID") or "ERR" in g or "ready" in g:
            print(g,flush=True)
sc.on("message",onmsg); sc.load(); time.sleep(1)
print("[GO]",flush=True); emu.tap(1355,970); time.sleep(3); emu.tap(1355,970); time.sleep(18)
print("done",flush=True)
