-- Pure helpers, deliberately independent of the game or WPF. EspSupport={} local function finite(v)return type(v)=='number'and v==v and math.abs(v)<1e12 end EspSupport.finite=finite EspSupport.maxRangePosition=800 function EspSupport.rangeMetres(position) local step=math.max(0,math.min(EspSupport.maxRangePosition,position)) return math.floor(10^(step/100)+0.5) end function EspSupport.distanceText(a,b) local x,y,z=(a[1]-b[1])/100,(a[2]-b[2])/100,(a[3]-b[3])/100 local metres=math.sqrt(x*x+y*y+z*z) return ('[%dm]'):format(math.floor(metres+0.5)),metres end function EspSupport.absolute(g,x,y) if not g or not finite(x)or not finite(y)then return end local a,b=x*g[8]+y*g[10]+g[12],x*g[9]+y*g[11]+g[13] if finite(a)and finite(b)then return a,b end end function EspSupport.localPoint(g,x,y) if not g then return end local det=g[8]*g[11]-g[9]*g[10] if not finite(det)or math.abs(det)<1e-12 then return end local a,b=x-g[12],y-g[13] local px,py=(a*g[11]-b*g[10])/det,(b*g[8]-a*g[9])/det if finite(px)and finite(py)then return px,py end end function EspSupport.mapPixel(canvas,viewport,clip,u,v,w,h) if not canvas or not viewport or viewport[1]<=0 or viewport[2]<=0 then return end local ax,ay=EspSupport.absolute(canvas,u*canvas[1],v*canvas[2]);if not ax then return end if clip then local x,y=EspSupport.localPoint(clip,ax,ay) if not x or x<0 or y<0 or x>clip[1]or y>clip[2]then return end end local x,y=EspSupport.localPoint(viewport,ax,ay);if not x then return end x,y=x*w/viewport[1],y*h/viewport[2] if x>=0 and x<=w and y>=0 and y<=h then return x,y end end function EspSupport.localize(items,loot) local reverse,ambiguous={},{} local count,total=0,0 for id,english in pairs(items)do total=total+1;local chinese=GetLocalizedItemName(id) if chinese then if reverse[english]and reverse[english]~=chinese then ambiguous[english]=true end reverse[english]=chinese;items[id]=chinese;count=count+1 else items[id]=nil end end local lc,lt=0,0 for id,english in pairs(loot)do lt=lt+1;local chinese=not ambiguous[english]and reverse[english] if not chinese then chinese=GetLocalizedItemName(id:match('([^.]+)$')or id)end loot[id]=chinese;if chinese then lc=lc+1 end end return count,total,lc,lt end function EspSupport.screenFresh(now,thenTime) local age=now-thenTime;return age>=0 and age<350 end function EspSupport.validProjection(x,y,onMap) return finite(x)and finite(y)and(not onMap or x~=0 or y~=0) end function EspSupport.packPoints(points) assert(#points<=300,'ESP批量查询超出300点') local bytes={} for _,p in ipairs(points)do local v=p.position assert(finite(v[1])and finite(v[2])and finite(v[3]),'ESP世界坐标无效') bytes[#bytes+1]=string.pack('