265 lines
10 KiB
Plaintext
265 lines
10 KiB
Plaintext
[ENABLE]
|
|
{$lua}
|
|
if syntaxcheck then return end
|
|
local signatures={world="48 8B 05 ?? ?? ?? ?? 48 85 C0 75 ?? 80 3D ?? ?? ?? ?? 02 72 ?? 48 8D 15 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 33 C0 48 83 C4 20 5B C3",names="89 03 48 8B C3 89 7B 04 48 8B 5C 24 48 48 83 C4 30 5F C3 80 3D ?? ?? ?? ?? 00 74 09 48 8D 05 ?? ?? ?? ?? EB 13 48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? C6 05 ?? ?? ?? ?? 01 0F 28 44 24 20"}
|
|
local state={pid=getOpenedProcessID(),classCache={},nameCache={}}
|
|
local function ptr(p) return type(p)=='number' and p>0x10000 and p<0x7FFFFFFFFFFF end
|
|
local function q(p) return ptr(p) and readQword(p) or nil end
|
|
local function finite(x) return type(x)=='number' and x==x and math.abs(x)<1e12 end
|
|
local function vector(p)
|
|
if not ptr(p) then return end
|
|
local x,y,z=readDouble(p),readDouble(p+8),readDouble(p+16)
|
|
if finite(x) and finite(y) and finite(z) then return {x,y,z} end
|
|
end
|
|
local function array(p,limit)
|
|
local data,num,cap=q(p),readInteger(p+8),readInteger(p+12)
|
|
if not num or not cap or num>limit or cap<num or cap>1000000 then return end
|
|
if num>0 and not ptr(data) then return end
|
|
return data,num
|
|
end
|
|
local function exactString(p,n,wide)
|
|
local bytes=readBytes(p,n*(wide and 2 or 1),true)
|
|
if not bytes or #bytes~=n*(wide and 2 or 1) then return '' end
|
|
if not wide then return string.char(table.unpack(bytes)) end
|
|
local chars={};local i=1
|
|
while i<=#bytes do
|
|
local unit=bytes[i]+bytes[i+1]*256;i=i+2
|
|
if unit>=0xD800 and unit<=0xDBFF and i<#bytes then
|
|
local low=bytes[i]+bytes[i+1]*256
|
|
if low>=0xDC00 and low<=0xDFFF then unit=0x10000+(unit-0xD800)*1024+low-0xDC00;i=i+2
|
|
else unit=0xFFFD end
|
|
elseif unit>=0xD800 and unit<=0xDFFF then unit=0xFFFD end
|
|
if unit==0 then break end
|
|
chars[#chars+1]=utf8.char(unit)
|
|
end
|
|
return table.concat(chars)
|
|
end
|
|
local function fname(p)
|
|
local id=readInteger(p)
|
|
if not id then return '' end
|
|
local text=state.nameCache[id]
|
|
if not text then
|
|
local block=id>>16
|
|
if block>8191 then return '' end
|
|
local b=q(state.namePool+0x10+block*8)
|
|
if not ptr(b) then return '' end
|
|
local entry=b+(id&0xFFFF)*2
|
|
local h=readSmallInteger(entry)
|
|
if not h then return '' end
|
|
local n=h>>6
|
|
if n<1 or n>1023 then return '' end
|
|
text=exactString(entry+2,n,(h&1)~=0)
|
|
if not text then return '' end
|
|
state.nameCache[id]=text
|
|
end
|
|
local number=readInteger(p+4)
|
|
if number and number>0 then text=text..'_'..tostring(number-1) end
|
|
return text
|
|
end
|
|
local function fstring(p)
|
|
local data,n=array(p,1024)
|
|
if not data or n<2 then return '' end
|
|
return exactString(data,n-1,true)
|
|
end
|
|
local function meta(cl)
|
|
if not ptr(cl) then return end
|
|
local nameId=q(cl+0x18)
|
|
local super=q(cl+0x40)
|
|
if not nameId or super==nil then return end
|
|
local old=state.classCache[cl]
|
|
if old and old.nameId==nameId and old.super==super then return old end
|
|
local m={nameId=nameId,super=super,name=fname(cl+0x18)}
|
|
state.classCache[cl]=m
|
|
return m
|
|
end
|
|
local function properties(cl)
|
|
local m=meta(cl);if not m then return {} end
|
|
if m.fields then return m.fields end
|
|
local fields={};local f=q(cl+0x50);local seen={}
|
|
for i=1,512 do
|
|
if not ptr(f) or seen[f] then break end
|
|
seen[f]=true
|
|
local off,size=readInteger(f+0x44),readInteger(f+0x34)
|
|
if off and off<0x100000 and size and size<0x100000 then
|
|
fields[fname(f+0x20)]={offset=off,size=size,type=q(f+0x70),
|
|
byte=readBytes(f+0x71,1),mask=readBytes(f+0x72,1)}
|
|
end
|
|
f=q(f+0x10)
|
|
end
|
|
m.fields=fields;return fields
|
|
end
|
|
local function field(cl,name,required)
|
|
local seen={}
|
|
for i=1,32 do
|
|
if not ptr(cl) or seen[cl] then break end
|
|
seen[cl]=true
|
|
local p=properties(cl)[name];if p then return p end
|
|
local m=meta(cl);cl=m and m.super
|
|
end
|
|
if required then error('Missing reflected field: '..name) end
|
|
end
|
|
local function offset(cl,name) return field(cl,name,true).offset end
|
|
local function classOf(a) return q(a+0x10) end
|
|
local function nativeFunction(cl,name)
|
|
local visited={}
|
|
for i=1,32 do
|
|
if not ptr(cl) or visited[cl] then break end
|
|
visited[cl]=true
|
|
local f=q(cl+0x48);local seen={}
|
|
for j=1,1024 do
|
|
if not ptr(f) or seen[f] then break end
|
|
seen[f]=true
|
|
if fname(f+0x18)==name then return q(f+0x128) end
|
|
f=q(f+0x28)
|
|
end
|
|
local m=meta(cl);cl=m and m.super
|
|
end
|
|
end
|
|
local function flag(a,f)
|
|
if not f or not f.byte or not f.mask then return false end
|
|
local b=readBytes(a+f.offset+f.byte,1)
|
|
return b and (b&f.mask)~=0
|
|
end
|
|
local function uniqueScan(pattern)
|
|
local scan=createMemScan();local found=createFoundList(scan)
|
|
local ok,result=pcall(function()
|
|
local base=getAddress('PBZ.exe')
|
|
scan.firstScan(soExactValue,vtByteArray,rtRounded,pattern,'',base,base+getModuleSize('PBZ.exe')-1,
|
|
'+X',fsmNotAligned,'1',true,false,false,false)
|
|
scan.waitTillDone();found.initialize()
|
|
if found.Count~=1 then error('ESP signature expected 1 match; found '..found.Count) end
|
|
return getAddress(found.Address[0])
|
|
end)
|
|
found.destroy();scan.destroy()
|
|
if not ok then error(result) end
|
|
return result
|
|
end
|
|
local wr=uniqueScan(signatures.world)
|
|
state.worldSlot=wr+7+readInteger(wr+3,true)
|
|
local nr=uniqueScan(signatures.names)+0x1C
|
|
state.namePool=nr+7+readInteger(nr+3,true)
|
|
local function getContext()
|
|
if getOpenedProcessID()~=state.pid then error('No Fall Damage: attached process changed; disable and re-enable') end
|
|
local world=q(state.worldSlot)
|
|
if not ptr(world) then return end
|
|
local gi=q(world+offset(classOf(world),'OwningGameInstance'))
|
|
if not ptr(gi) then return end
|
|
local players,n=array(gi+offset(classOf(gi),'LocalPlayers'),8)
|
|
if not players or not n or n<1 then return end
|
|
local lp=q(players)
|
|
if not ptr(lp) then return end
|
|
local pc=q(lp+offset(classOf(lp),'PlayerController'))
|
|
if not ptr(pc) then return end
|
|
local pawn=q(pc+offset(classOf(pc),'Pawn'))
|
|
if not ptr(pawn) then return end
|
|
local cl=classOf(pawn);local base=cl;local found=false;local seen={}
|
|
for i=1,32 do
|
|
if not ptr(base) or seen[base] then break end;seen[base]=true
|
|
if fname(base+0x18)=='BP_Player_Base_C' then found=true;break end
|
|
base=q(base+0x40)
|
|
end
|
|
if not found then return end
|
|
local damage=field(cl,'DamageDepth',true)
|
|
local dead=field(cl,'DeadDepth',true)
|
|
if damage.size~=8 or dead.size~=8 or damage.offset==dead.offset
|
|
or damage.offset%8~=0 or dead.offset%8~=0 then error('No Fall Damage: unsupported fall threshold layout') end
|
|
local hidden=field(cl,'bActorIsBeingDestroyed',true)
|
|
if flag(pawn,hidden) then return end
|
|
return {world=world,gi=gi,lp=lp,pc=pc,pawn=pawn,class=cl,
|
|
name=q(pawn+0x18),index=readInteger(pawn+0xC),outer=q(pawn+0x20),
|
|
damage=damage.offset,dead=dead.offset,destroyOffset=hidden.offset+hidden.byte,destroyMask=hidden.mask}
|
|
end
|
|
local initial=getContext()
|
|
if not initial then error('Load a save and possess the local player before enabling No Fall Damage') end
|
|
local previous=rawget(_G,'PBZ_NoFallDamage')
|
|
if previous then
|
|
if previous.pid==state.pid then error('Disable the existing No Fall Damage entry first') end
|
|
if previous.timer then previous.timer.Enabled=false;previous.timer.destroy();previous.timer=nil end
|
|
previous.lease=nil
|
|
_G.PBZ_NoFallDamage=nil
|
|
end
|
|
state.damageLimit=1000000000000
|
|
state.deadLimit=2000000000000
|
|
local function numberOK(v) return type(v)=='number' and v==v and math.abs(v)<1e15 end
|
|
local function sameIdentity(c)
|
|
if getOpenedProcessID()~=state.pid or not ptr(c.pawn) then return false end
|
|
local bits=readBytes(c.pawn+c.destroyOffset,1)
|
|
return bits~=nil and (bits&c.destroyMask)==0
|
|
and q(c.pawn+0x10)==c.class
|
|
and q(c.pawn+0x18)==c.name
|
|
and readInteger(c.pawn+0xC)==c.index
|
|
and q(c.pawn+0x20)==c.outer
|
|
end
|
|
local function release()
|
|
local c=state.lease
|
|
if not c then return end
|
|
if sameIdentity(c) then
|
|
for _,f in ipairs({{c.damage,state.damageLimit,'originalDamage'},{c.dead,state.deadLimit,'originalDead'}}) do
|
|
local a=c.pawn+f[1]
|
|
if readDouble(a)==f[2] then
|
|
writeDouble(a,c[f[3]])
|
|
if readDouble(a)~=c[f[3]] then error('No Fall Damage: failed to restore '..f[3]) end
|
|
end
|
|
end
|
|
end
|
|
state.lease=nil
|
|
end
|
|
local function maintain(c)
|
|
if not sameIdentity(c) then error('No Fall Damage: pawn identity changed before writing') end
|
|
local damage,dead=readDouble(c.pawn+c.damage),readDouble(c.pawn+c.dead)
|
|
if not numberOK(damage) or not numberOK(dead) or damage<0 or dead<0 then error('No Fall Damage: invalid fall thresholds') end
|
|
if damage~=state.damageLimit then c.originalDamage=damage end
|
|
if dead~=state.deadLimit then c.originalDead=dead end
|
|
if not numberOK(c.originalDamage) or not numberOK(c.originalDead) then error('No Fall Damage: missing original thresholds') end
|
|
for _,f in ipairs({{c.dead,state.deadLimit},{c.damage,state.damageLimit}}) do
|
|
if not sameIdentity(c) then error('No Fall Damage: pawn changed while updating thresholds') end
|
|
local a=c.pawn+f[1]
|
|
if readDouble(a)~=f[2] then
|
|
writeDouble(a,f[2])
|
|
if readDouble(a)~=f[2] then error('No Fall Damage: threshold write failed') end
|
|
end
|
|
end
|
|
end
|
|
local function tick()
|
|
if getOpenedProcessID()~=state.pid then
|
|
state.lastError='Attached process changed; disable and re-enable No Fall Damage'
|
|
state.timer.Enabled=false;return
|
|
end
|
|
local c=getContext();local old=state.lease
|
|
if old and (not c or c.pawn~=old.pawn or c.world~=old.world or c.class~=old.class
|
|
or c.name~=old.name or c.index~=old.index or c.outer~=old.outer) then release();old=nil end
|
|
if c then
|
|
if not old then state.lease=c;old=c end
|
|
maintain(old)
|
|
end
|
|
state.lastError=nil
|
|
end
|
|
state.stop=function()
|
|
if state.timer then state.timer.Enabled=false end
|
|
release()
|
|
if state.timer then state.timer.destroy();state.timer=nil end
|
|
if rawget(_G,'PBZ_NoFallDamage')==state then _G.PBZ_NoFallDamage=nil end
|
|
end
|
|
local ok,err=pcall(function()
|
|
state.timer=createTimer(nil,false);state.timer.Interval=50
|
|
state.timer.OnTimer=function()
|
|
local good,why=pcall(tick)
|
|
if not good then state.lastError=tostring(why);state.timer.Enabled=false end
|
|
end
|
|
state.lease=initial;maintain(initial)
|
|
_G.PBZ_NoFallDamage=state
|
|
state.timer.Enabled=true
|
|
end)
|
|
if not ok then
|
|
local restored=pcall(state.stop)
|
|
if not restored then _G.PBZ_NoFallDamage=state end
|
|
error(err)
|
|
end
|
|
{$asm}
|
|
[DISABLE]
|
|
{$lua}
|
|
if syntaxcheck then return end
|
|
local s=rawget(_G,'PBZ_NoFallDamage')
|
|
if s then s.stop() end
|
|
{$asm}
|