import frida, time, subprocess, sys
sys.path.insert(0,"/root/ants"); import emu
JS=r"""
var loaded=false;
function ins(){var m=Process.findModuleByName("libil2cpp.so");if(!m)return false;var b=m.base;
 var isn=new NativeFunction(Module.findExportByName("libil2cpp.so","il2cpp_string_new"),'pointer',['pointer']);
 var loadScene=new NativeFunction(b.add(0x794653),'void',['pointer','pointer']);
 function H(a,nm){try{Interceptor.attach(b.add(a),{onEnter:function(){send({g:nm});}});}catch(e){}}
 H(0xe47cab,"GC.Awake");H(0xe4bd6a,"SpawnPlayers");
 // when the DoleOutPlayers coroutine has run, force-load an arena scene
 var n=0;
 try{Interceptor.attach(b.add(0xd3df1a),{onLeave:function(r){n++; if(n==8 && !loaded){loaded=true;
   try{var s=isn(Memory.allocUtf8String("ContainerHarbour")); send({g:"forcing LoadScene(ContainerHarbour)"}); loadScene(s,ptr(0)); send({g:"LoadScene returned"});}catch(e){send({g:"loadscene err "+e});}
 }}});}catch(e){}
 send({g:"__ready"});return true;}
if(!ins()){var iv=setInterval(function(){if(ins())clearInterval(iv);},100);}
"""
t=emu.launch_to_menu(); print("menu",int(t) if t else "FAIL",flush=True)
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",{}).get("g",""),flush=True) if isinstance(m.get("payload"),dict) else None)
sc.load(); time.sleep(0.5)
emu.tap(700,730); time.sleep(6)
print("[GO]",flush=True); emu.tap(1355,960); time.sleep(30)
emu.screenshot(); import shutil; shutil.copy("/root/ants/_emu.png","/root/ants/forcestate.png")
print("done",flush=True)
