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 H(a,nm){try{Interceptor.attach(b.add(a),{onEnter:function(){send({g:nm});}});}catch(e){}}
 H(0x1004449,"OnFailedToConnect");H(0x100424c,"OnConnectionFail");H(0x1004646,"OnDisconnected");
 H(0xdc0d62,"SeatingPlan.Initialise");H(0xd3df1a,"DoleCoro");
 H(0xe47cab,"GC.Awake");H(0xe484bd,"GC.Start");H(0xe4bd6a,"SpawnPlayers");
 try{Interceptor.attach(b.add(0xd41677),{onEnter:function(){var sp=this.context.esp;send({g:"set_isSniper("+(sp.add(8).readU32()?1:0)+")"});}});}catch(e){}
 Process.setExceptionHandler(function(d){var a=d.address;var mm=Process.findModuleByAddress(a);var loc=mm?mm.name+"+0x"+a.sub(mm.base).toString(16):""+a;
   var bt="";try{bt=Thread.backtrace(d.context,Backtracer.ACCURATE).slice(0,10).map(function(x){var m2=Process.findModuleByAddress(x);return m2&&m2.name=="libil2cpp.so"?"il+0x"+x.sub(m2.base).toString(16):(m2?m2.name:""+x);}).join(" ");}catch(e){}
   send({g:"*** CRASH "+d.type+" @"+loc+" bt="+bt});return false;});
 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(75)
try: emu.screenshot(); import shutil; shutil.copy("/root/ants/_emu.png","/root/ants/fallstate.png")
except Exception as e: print("shot err",e,flush=True)
print("done",flush=True)
