633 lines
24 KiB
Plaintext
633 lines
24 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",objects="44 8B 49 04 45 85 C9 74 ?? 8B 01 85 C0 78 ?? 3B 05 ?? ?? ?? ?? 7D ?? 8B C8 0F B7 C0 48 C1 E9 10 48 8D 14 40 48 8B 05 ?? ?? ?? ?? 48 8B 0C C8 4C 8D 04 D1"}
|
|
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 identity(a)
|
|
if not ptr(a) then return end
|
|
local cl=q(a+0x10);local n=q(a+0x18);local index=readInteger(a+0xC)
|
|
if not ptr(cl) or not n or not index then return end
|
|
return {address=a,class=cl,name=n,index=index}
|
|
end
|
|
local function valid(id)
|
|
return id and state.pid==getOpenedProcessID() and q(id.address+0x10)==id.class
|
|
and q(id.address+0x18)==id.name and readInteger(id.address+0xC)==id.index
|
|
end
|
|
local function context()
|
|
if state.pid~=getOpenedProcessID() then return 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 list,n=array(gi+offset(classOf(gi),'LocalPlayers'),8);if not list or not n or n<1 then return end
|
|
local lp=q(list);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 dying=field(classOf(pawn),'bActorIsBeingDestroyed')
|
|
if dying and flag(pawn,dying) then return end
|
|
return {world=world,gi=gi,lp=lp,pc=pc,pawn=pawn,pawnID=identity(pawn)}
|
|
end
|
|
local initial=assert(context(),'Load the local player before enabling this entry')
|
|
local function functions(cl,name)
|
|
for d=1,32 do
|
|
if not ptr(cl) then break end
|
|
local fn=q(cl+0x48)
|
|
for i=1,2048 do
|
|
if not ptr(fn) then break end
|
|
if fname(fn+0x18)==name then return fn end
|
|
fn=q(fn+0x28)
|
|
end
|
|
cl=q(cl+0x40)
|
|
end
|
|
end
|
|
local function objectInventory(wanted)
|
|
local ref=uniqueScan(signatures.objects)
|
|
state.objectChunksSlot=ref+0x2B+readInteger(ref+0x27,true)
|
|
state.objectCountSlot=ref+0x15+readInteger(ref+0x11,true)
|
|
local chunks=q(state.objectChunksSlot)
|
|
local count=readInteger(state.objectCountSlot)
|
|
assert(ptr(chunks) and count and count>0 and count<2000000,'Unsupported object array')
|
|
local out={};local last=-1;local chunk
|
|
for i=0,count-1 do
|
|
local ci=i>>16;if ci~=last then chunk=q(chunks+ci*8);last=ci end
|
|
if ptr(chunk) then local slot=chunk+(i&0xFFFF)*24;local flags=readInteger(slot+4)
|
|
if flags and flags&0x10200000==0 then
|
|
local a=q(slot+8)
|
|
if ptr(a) and readInteger(a+0xC)==i then
|
|
local n=fname(a+0x18);local kind=wanted[n]
|
|
if kind and fname(classOf(a)+0x18)==kind then
|
|
assert(not out[n],'Ambiguous loaded object: '..n);out[n]=a
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
for n in pairs(wanted) do assert(out[n],'Required game object is not loaded: '..n) end
|
|
return out
|
|
end
|
|
local function setBit(a,f,value)
|
|
assert(f and f.size==1 and f.byte==0 and f.mask and f.mask>0,'Unsupported boolean property')
|
|
local b=assert(readBytes(a+f.offset,1),'Boolean field unreadable')
|
|
local nextValue=value and (b|f.mask) or (b&(~f.mask&0xFF))
|
|
if nextValue~=b then assert(writeBytes(a+f.offset,nextValue),'Boolean field write failed') end
|
|
end
|
|
local dispatchPatterns={normal="48 8B 0F 4C 8D 44 24 38 48 8B D0 4C 8B 89 60020000 48 8B CF 41 FF D1 48 8B B4 24 E8000000 48 8B AC 24 08010000 48 8B 9C 24 00010000 4C 8B A4 24 E0000000 44 0F28 84 24 A0000000 48 81 C4 F0000000 5F C3",normalOffset=24,paused="48 8B 07 41 0F28 C8 48 8B CF 44 0F28 84 24 A0000000 48 81 C4 F0000000 5F 48 FF A0 18050000"}
|
|
local function findName(name)
|
|
local target=name:lower();local current=readInteger(state.namePool+8);local cursor=readInteger(state.namePool+0xC)
|
|
assert(current and current<8192 and cursor and cursor<=0x20000,'Unsupported FName allocator')
|
|
for block=current,0,-1 do
|
|
local data=q(state.namePool+0x10+block*8);local size=block==current and cursor or 0x20000
|
|
if ptr(data) and size>0 then
|
|
local bytes=readBytes(data,size,true)
|
|
if bytes and #bytes==size then
|
|
local parts={};for lo=1,size,4096 do parts[#parts+1]=string.char(table.unpack(bytes,lo,math.min(lo+4095,size))) end
|
|
local text=table.concat(parts):lower();local from=1
|
|
while true do
|
|
local at=text:find(target,from,true);if not at then break end
|
|
if at>=3 and (at-3)%2==0 then
|
|
local header=bytes[at-2]+bytes[at-1]*256
|
|
if header&1==0 and header>>6==#name then return (block<<16)|((at-3)>>1) end
|
|
end
|
|
from=at+1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
error('Required registered gameplay tag name is unavailable: '..name)
|
|
end
|
|
local function staticTarget(cl,name,expected)
|
|
local fn=assert(functions(cl,name),'Native function unavailable: '..name)
|
|
assert((readInteger(fn+0x100)&0x400)~=0,'Expected native UFunction: '..name)
|
|
for n,spec in pairs(expected) do
|
|
local f=field(fn,n,true);assert(f.offset==spec[1] and f.size==spec[2],'Function parameter layout changed: '..name..'.'..n)
|
|
end
|
|
local cdo=q(cl+0x160);assert(ptr(cdo) and classOf(cdo)==cl,'Class default object unavailable')
|
|
local pe=q(q(cdo)+0x260);local bytes=pe and readBytes(pe,12,true)
|
|
assert(bytes and table.concat(bytes,',')=='64,85,86,87,65,84,65,85,65,86,65,87','UObject.ProcessEvent ABI changed')
|
|
return {receiver=identity(cdo),fn=identity(fn),native=q(fn+0x128),processEvent=pe}
|
|
end
|
|
local function acquireDispatch(key)
|
|
local d=rawget(_G,'PBZ_UtilityDispatch')
|
|
local exports={'Code','NormalEntry','PausedEntry','Mailbox','NormalBackup','PausedBackup'}
|
|
if d and d.pid~=state.pid then
|
|
if d.timer then d.timer.destroy() end
|
|
for _,n in ipairs(exports) do unregisterSymbol('PBZ_UT_'..n) end
|
|
_G.PBZ_UtilityDispatch=nil;d=nil
|
|
end
|
|
if d then
|
|
assert(not d.closing,'Utility dispatcher is finishing cleanup; retry enabling shortly')
|
|
assert(not d.users[key],'This utility is already enabled')
|
|
assert(d.validateHooks,'Unsupported Utility dispatcher version');d.validateHooks()
|
|
d.users[key]=true;return d,''
|
|
end
|
|
assert(not getAddressSafe('PBZ_UT_Code'),'Unowned Utility dispatch symbols; no target bytes changed')
|
|
local normal=uniqueScan(dispatchPatterns.normal)+dispatchPatterns.normalOffset;local paused=uniqueScan(dispatchPatterns.paused)
|
|
local originalNormal=assert(readBytes(normal,16,true));local originalPaused=assert(readBytes(paused,19,true))
|
|
local source=[==[
|
|
alloc(PBZ_UT_Code,$5000)
|
|
label(PBZ_UT_NormalEntry)
|
|
label(PBZ_UT_PausedEntry)
|
|
label(PBZ_UT_Worker)
|
|
label(PBZ_UT_Mailbox)
|
|
label(PBZ_UT_NormalBackup)
|
|
label(PBZ_UT_PausedBackup)
|
|
label(PBZ_UT_ValidateObject)
|
|
label(PBZ_UT_ObjectInvalid)
|
|
label(PBZ_UT_Reject)
|
|
label(PBZ_UT_Return)
|
|
label(PBZ_UT_CheckExtra)
|
|
registersymbol(PBZ_UT_Code)
|
|
registersymbol(PBZ_UT_NormalEntry)
|
|
registersymbol(PBZ_UT_PausedEntry)
|
|
registersymbol(PBZ_UT_Mailbox)
|
|
registersymbol(PBZ_UT_NormalBackup)
|
|
registersymbol(PBZ_UT_PausedBackup)
|
|
PBZ_UT_Code:
|
|
PBZ_UT_NormalEntry:
|
|
call PBZ_UT_Worker
|
|
readmem(PBZ_UT_Normal,$10)
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_UT_Normal+10
|
|
PBZ_UT_PausedEntry:
|
|
call PBZ_UT_Worker
|
|
readmem(PBZ_UT_Paused,$13)
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_UT_Paused+13
|
|
PBZ_UT_Worker:
|
|
pushfq
|
|
push rax
|
|
push rcx
|
|
push rdx
|
|
push r8
|
|
push r9
|
|
push r10
|
|
push r11
|
|
push rbx
|
|
push rsi
|
|
push rdi
|
|
sub rsp,C0
|
|
movdqu [rsp+30],xmm0
|
|
movdqu [rsp+40],xmm1
|
|
movdqu [rsp+50],xmm2
|
|
movdqu [rsp+60],xmm3
|
|
movdqu [rsp+70],xmm4
|
|
movdqu [rsp+80],xmm5
|
|
mov rbx,PBZ_UT_Mailbox
|
|
cmp dword ptr [rbx],1
|
|
jne PBZ_UT_Return
|
|
cmp rdi,[rbx+18]
|
|
jne PBZ_UT_Return
|
|
mov rax,WORLD_SLOT
|
|
mov rax,[rax]
|
|
cmp rax,[rbx+10]
|
|
jne PBZ_UT_Reject
|
|
test rax,rax
|
|
je PBZ_UT_Reject
|
|
mov rax,[rax+GI_OFFSET]
|
|
test rax,rax
|
|
je PBZ_UT_Reject
|
|
cmp dword ptr [rax+PLAYERS_OFFSET+8],1
|
|
jl PBZ_UT_Reject
|
|
mov rax,[rax+PLAYERS_OFFSET]
|
|
test rax,rax
|
|
je PBZ_UT_Reject
|
|
mov rax,[rax]
|
|
test rax,rax
|
|
je PBZ_UT_Reject
|
|
cmp rdi,[rax+CONTROLLER_OFFSET]
|
|
jne PBZ_UT_Reject
|
|
mov rax,[rbx+20]
|
|
mov ecx,[rbx+38]
|
|
call PBZ_UT_ValidateObject
|
|
test al,al
|
|
je PBZ_UT_Reject
|
|
mov rax,[rbx+20]
|
|
mov rcx,[rbx+28]
|
|
cmp [rax+10],rcx
|
|
jne PBZ_UT_Reject
|
|
mov rcx,[rbx+30]
|
|
cmp [rax+18],rcx
|
|
jne PBZ_UT_Reject
|
|
mov ecx,[rbx+38]
|
|
cmp [rax+0C],ecx
|
|
jne PBZ_UT_Reject
|
|
mov rdx,[rbx+40]
|
|
mov rax,rdx
|
|
mov ecx,[rbx+58]
|
|
call PBZ_UT_ValidateObject
|
|
test al,al
|
|
je PBZ_UT_Reject
|
|
mov rdx,[rbx+40]
|
|
mov rcx,[rbx+48]
|
|
cmp [rdx+10],rcx
|
|
jne PBZ_UT_Reject
|
|
mov rcx,[rbx+50]
|
|
cmp [rdx+18],rcx
|
|
jne PBZ_UT_Reject
|
|
mov ecx,[rbx+58]
|
|
cmp [rdx+0C],ecx
|
|
jne PBZ_UT_Reject
|
|
test dword ptr [rdx+100],400
|
|
je PBZ_UT_Reject
|
|
PBZ_UT_CheckExtra:
|
|
mov rax,[rbx+60]
|
|
mov ecx,[rbx+78]
|
|
call PBZ_UT_ValidateObject
|
|
test al,al
|
|
je PBZ_UT_Reject
|
|
mov rax,[rbx+60]
|
|
mov rcx,[rbx+68]
|
|
cmp [rax+10],rcx
|
|
jne PBZ_UT_Reject
|
|
mov rcx,[rbx+70]
|
|
cmp [rax+18],rcx
|
|
jne PBZ_UT_Reject
|
|
mov ecx,[rbx+78]
|
|
cmp [rax+0C],ecx
|
|
jne PBZ_UT_Reject
|
|
cmp dword ptr [rbx+7C],1
|
|
jne @f
|
|
cmp rax,[rdi+PAWN_OFFSET]
|
|
jne PBZ_UT_Reject
|
|
@@:
|
|
mov dword ptr [rbx],2
|
|
mov rcx,[rbx+20]
|
|
mov rdx,[rbx+40]
|
|
lea r8,[rbx+80]
|
|
mov rax,[rcx]
|
|
call qword ptr [rax+260]
|
|
mov dword ptr [rbx],3
|
|
jmp PBZ_UT_Return
|
|
PBZ_UT_Reject:
|
|
mov dword ptr [rbx],4
|
|
PBZ_UT_Return:
|
|
movdqu xmm0,[rsp+30]
|
|
movdqu xmm1,[rsp+40]
|
|
movdqu xmm2,[rsp+50]
|
|
movdqu xmm3,[rsp+60]
|
|
movdqu xmm4,[rsp+70]
|
|
movdqu xmm5,[rsp+80]
|
|
add rsp,C0
|
|
pop rdi
|
|
pop rsi
|
|
pop rbx
|
|
pop r11
|
|
pop r10
|
|
pop r9
|
|
pop r8
|
|
pop rdx
|
|
pop rcx
|
|
pop rax
|
|
popfq
|
|
ret
|
|
PBZ_UT_ValidateObject:
|
|
test rax,rax
|
|
je PBZ_UT_ObjectInvalid
|
|
test ecx,ecx
|
|
js PBZ_UT_ObjectInvalid
|
|
mov r10,OBJECT_COUNT_SLOT
|
|
cmp ecx,[r10]
|
|
jae PBZ_UT_ObjectInvalid
|
|
mov r10,OBJECT_CHUNKS_SLOT
|
|
mov r10,[r10]
|
|
test r10,r10
|
|
je PBZ_UT_ObjectInvalid
|
|
mov r11d,ecx
|
|
shr r11d,10
|
|
mov r10,[r10+r11*8]
|
|
test r10,r10
|
|
je PBZ_UT_ObjectInvalid
|
|
and ecx,FFFF
|
|
imul ecx,ecx,18
|
|
add r10,rcx
|
|
test dword ptr [r10+4],10200000
|
|
jne PBZ_UT_ObjectInvalid
|
|
cmp [r10+8],rax
|
|
jne PBZ_UT_ObjectInvalid
|
|
mov al,1
|
|
ret
|
|
PBZ_UT_ObjectInvalid:
|
|
xor eax,eax
|
|
ret
|
|
PBZ_UT_Code+2000:
|
|
PBZ_UT_NormalBackup:
|
|
readmem(PBZ_UT_Normal,$10)
|
|
PBZ_UT_PausedBackup:
|
|
readmem(PBZ_UT_Paused,$13)
|
|
PBZ_UT_Code+2100:
|
|
PBZ_UT_Mailbox:
|
|
dd 0
|
|
dd 0
|
|
dq PROCESS_ID
|
|
PBZ_UT_Normal:
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_UT_NormalEntry
|
|
db 90 90
|
|
PBZ_UT_Paused:
|
|
db FF 25 00 00 00 00
|
|
dq PBZ_UT_PausedEntry
|
|
db 90 90 90 90 90
|
|
]==]
|
|
local function hex(bytes) local out={};for _,b in ipairs(bytes) do out[#out+1]=('%02X'):format(b) end;return table.concat(out,' ') end
|
|
source='assert(PBZ_UT_Normal,'..hex(originalNormal)..')\nassert(PBZ_UT_Paused,'..hex(originalPaused)..')\n'..source
|
|
local values={PBZ_UT_Normal=normal,PBZ_UT_Paused=paused,WORLD_SLOT=state.worldSlot,
|
|
GI_OFFSET=offset(classOf(initial.world),'OwningGameInstance'),PLAYERS_OFFSET=offset(classOf(initial.gi),'LocalPlayers'),
|
|
CONTROLLER_OFFSET=offset(classOf(initial.lp),'PlayerController'),PAWN_OFFSET=offset(classOf(initial.pc),'Pawn'),
|
|
OBJECT_COUNT_SLOT=state.objectCountSlot,OBJECT_CHUNKS_SLOT=state.objectChunksSlot,PROCESS_ID=state.pid}
|
|
for n,v in pairs(values) do assert(type(v)=='number','Missing dispatch value '..n);source=('define(%s,%X)\n'):format(n,v)..source end
|
|
d={pid=state.pid,users={[key]=true},queue={},normal=normal,paused=paused,normalBytes=originalNormal,pausedBytes=originalPaused}
|
|
d.identity=identity;d.valid=valid
|
|
local function compare(a,b)
|
|
local x=readBytes(a,#b,true);return x and table.concat(x,',')==table.concat(b,',')
|
|
end
|
|
local function mail()
|
|
local p=getAddressSafe('PBZ_UT_Mailbox');if not p then return end
|
|
if readQword(p+8)~=d.pid then error('Utility mailbox PID mismatch') end;return p
|
|
end
|
|
local function writeID(p,id)
|
|
assert(writeQword(p,id.address));assert(writeQword(p+8,id.class));assert(writeQword(p+16,id.name));assert(writeInteger(p+24,id.index))
|
|
end
|
|
d.validateHooks=function()
|
|
assert(mail(),'Utility dispatcher has not finished installing')
|
|
for _,c in ipairs({{d.normal,16,'Normal',d.normalBytes},{d.paused,19,'Paused',d.pausedBytes}}) do
|
|
local entry=assert(getAddressSafe('PBZ_UT_'..c[3]..'Entry'));local backup=assert(getAddressSafe('PBZ_UT_'..c[3]..'Backup'))
|
|
local head=readBytes(c[1],6,true)
|
|
assert(head and table.concat(head,',')=='255,37,0,0,0,0' and q(c[1]+6)==entry,'Utility hook ownership changed')
|
|
assert(compare(backup,c[4]),'Utility backup changed')
|
|
end
|
|
return true
|
|
end
|
|
d.enqueue=function(request)
|
|
assert(not d.closing and d.users[request.owner],'Utility dispatcher is not available to this entry')
|
|
d.queue[#d.queue+1]=request
|
|
end
|
|
d.pending=function(owner)
|
|
if d.current and d.current.owner==owner then return true end
|
|
for _,r in ipairs(d.queue) do if r.owner==owner then return true end end
|
|
return false
|
|
end
|
|
d.pump=function()
|
|
if d.pid~=getOpenedProcessID() then d.timer.Enabled=false;return end
|
|
if d.closing then
|
|
if compare(d.normal,d.normalBytes) and compare(d.paused,d.pausedBytes) then
|
|
d.timer.destroy();d.timer=nil;if rawget(_G,'PBZ_UtilityDispatch')==d then _G.PBZ_UtilityDispatch=nil end
|
|
end
|
|
return
|
|
end
|
|
local m=mail();if not m then return end
|
|
local status=readInteger(m)
|
|
if d.current then
|
|
if status==2 then return end
|
|
if status==1 then
|
|
local r=d.current;local stale=false
|
|
if r.validate and getTickCount()-(r.sentAt or 0)>=250 then local ok,valid=pcall(r.validate);stale=(not ok)or valid==false end
|
|
if not stale then return end
|
|
d.current=nil;assert(writeInteger(m,0));r.done=true;r.success=false;r.error='Request target changed before the game thread ran it'
|
|
if r.callback then r.callback(r) end
|
|
else
|
|
local r=d.current;d.current=nil
|
|
local result
|
|
if status==3 then result=r.resultKind=='bool' and readBytes(m+0x80+r.resultOffset,1) or readQword(m+0x80+r.resultOffset) end
|
|
assert(writeInteger(m,0));r.done=true;r.success=status==3;r.result=result
|
|
if r.callback then r.callback(r) end
|
|
end
|
|
elseif status~=0 then assert(writeInteger(m,0)) end
|
|
if #d.queue==0 then return end
|
|
local r=table.remove(d.queue,1)
|
|
if q(state.worldSlot)~=r.world or not valid(r.pcID) or not valid(r.receiver) or not valid(r.fn) or not valid(r.extra) then
|
|
r.done=true;r.success=false;r.error='World or object identity changed';if r.callback then r.callback(r) end;return
|
|
end
|
|
assert(writeQword(m+0x10,r.world));assert(writeQword(m+0x18,r.pcID.address))
|
|
writeID(m+0x20,r.receiver);writeID(m+0x40,r.fn);writeID(m+0x60,r.extra)
|
|
assert(writeInteger(m+0x7C,r.currentPawnOnly and 1 or 0))
|
|
local zeros={};for i=1,512 do zeros[i]=0 end;assert(writeBytes(m+0x80,table.unpack(zeros)))
|
|
for _,w in ipairs(r.writes) do
|
|
assert(w[1]>=0 and w[1]<0x200,'Parameter write outside mailbox')
|
|
if w[3]=='byte' then assert(writeBytes(m+0x80+w[1],w[2])) else assert(writeQword(m+0x80+w[1],w[2])) end
|
|
end
|
|
d.current=r;r.sentAt=getTickCount();assert(writeInteger(m,1))
|
|
end
|
|
d.drain=function(owner)
|
|
local start=getTickCount();local attempts=0
|
|
while d.pending(owner) and getTickCount()-start<2000 and attempts<200 do
|
|
attempts=attempts+1;d.pump();if d.pending(owner) then sleep(10) end
|
|
end
|
|
if d.pending(owner) then
|
|
local m=mail();local status=m and readInteger(m)or -1
|
|
error(('游戏线程仍有未完成的请求(邮箱状态 %s,已等待 2000 毫秒)。请回到游戏画面、不要停在暂停或加载界面,再重试关闭'):format(tostring(status)),0)
|
|
end
|
|
end
|
|
d.release=function(owner)
|
|
if d.pid~=getOpenedProcessID() then
|
|
if d.timer then d.timer.destroy();d.timer=nil end
|
|
if rawget(_G,'PBZ_UtilityDispatch')~=d then return '' end
|
|
_G.PBZ_UtilityDispatch=nil;local out={};for _,n in ipairs(exports) do out[#out+1]='unregistersymbol(PBZ_UT_'..n..')' end
|
|
return table.concat(out,'\n')
|
|
end
|
|
assert(not d.pending(owner),'Finish utility cleanup before disabling')
|
|
local any=false;for k in pairs(d.users) do if k~=owner then any=true end end
|
|
if any then d.users[owner]=nil;return '' end
|
|
assert(#d.queue==0 and not d.current,'Another utility request is still running')
|
|
local checks={{d.normal,16,'Normal'},{d.paused,19,'Paused'}};local out={}
|
|
for _,c in ipairs(checks) do
|
|
local entry=assert(getAddressSafe('PBZ_UT_'..c[3]..'Entry'));local backup=assert(getAddressSafe('PBZ_UT_'..c[3]..'Backup'))
|
|
local head=readBytes(c[1],6,true)
|
|
assert(head and table.concat(head,',')=='255,37,0,0,0,0' and q(c[1]+6)==entry,'Utility hook ownership changed')
|
|
local saved=c[3]=='Normal' and d.normalBytes or d.pausedBytes
|
|
assert(compare(backup,saved),'Utility original instruction buffer changed')
|
|
if c[2]>14 then local padding=readBytes(c[1]+14,c[2]-14,true);assert(padding and #padding==c[2]-14,'Utility padding unreadable');for _,v in ipairs(padding) do assert(v==0x90,'Utility padding changed') end end
|
|
out[#out+1]=('%X:\n readmem(%X,$%X)'):format(c[1],backup,c[2])
|
|
end
|
|
for _,n in ipairs(exports) do out[#out+1]='unregistersymbol(PBZ_UT_'..n..')' end
|
|
d.users[owner]=nil;d.closing=true
|
|
return table.concat(out,'\n')
|
|
end
|
|
d.timer=createTimer(nil,false);d.timer.Interval=20
|
|
d.timer.OnTimer=function() local ok,e=pcall(d.pump);if not ok then d.lastError=tostring(e) end end
|
|
_G.PBZ_UtilityDispatch=d;d.timer.Enabled=true
|
|
return d,source
|
|
end
|
|
local old=rawget(_G,'PBZ_SaveMenuAnywhere')
|
|
if old and old.pid==state.pid then error('Save Menu Anywhere is already enabled') end
|
|
if old and old.hotkey then old.hotkey.destroy() end
|
|
local objects=objectInventory({CommonUIExtensions='Class',WB_SaveGame_C='WidgetBlueprintGeneratedClass'})
|
|
local target=staticTarget(objects.CommonUIExtensions,'PushContentToLayer_ForPlayer',{
|
|
LocalPlayer={0,8},LayerName={8,8},WidgetClass={0x10,8},ReturnValue={0x18,8}})
|
|
local lpParam=field(target.fn.address,'LocalPlayer',true)
|
|
assert(fname(lpParam.type+0x18)=='LocalPlayer','Expected ULocalPlayer parameter, not a controller pointer')
|
|
local layer=findName('UI.Layer.GameSystem')
|
|
local saveClass=objects.WB_SaveGame_C
|
|
local active=field(saveClass,'bIsActive',true)
|
|
assert(active.size==1 and active.byte==0 and active.mask==1,'Save widget activation field changed')
|
|
local dispatcher,assembly=acquireDispatch('save')
|
|
local s={pid=state.pid,dispatcher=dispatcher,saveClass=saveClass}
|
|
s.open=function()
|
|
if s.stopping or s.pending then return end
|
|
local c=assert(context(),'No active local player')
|
|
if valid(s.widget) and flag(s.widget.address,active) then return end
|
|
local r={owner='save',world=c.world,pcID=identity(c.pc),receiver=target.receiver,fn=target.fn,
|
|
extra=identity(saveClass),currentPawnOnly=false,resultKind='object',resultOffset=0x18,
|
|
writes={{0,c.lp},{8,layer},{0x10,saveClass}}}
|
|
s.pending=r
|
|
r.callback=function(done)
|
|
s.pending=nil
|
|
if done.success and ptr(done.result) and classOf(done.result)==saveClass then s.widget=identity(done.result);s.lastError=nil
|
|
else s.lastError=done.error or 'The game could not push the Save Game widget to its UI layer' end
|
|
end
|
|
dispatcher.enqueue(r)
|
|
end
|
|
s.stop=function()
|
|
s.stopping=true
|
|
if s.pid==getOpenedProcessID() then dispatcher.drain('save') end
|
|
local restore=dispatcher.release('save')
|
|
if s.hotkey then s.hotkey.destroy();s.hotkey=nil end
|
|
if rawget(_G,'PBZ_SaveMenuAnywhere')==s then _G.PBZ_SaveMenuAnywhere=nil end;return restore
|
|
end
|
|
s.hotkey=createHotkey(function()
|
|
if getForegroundProcess()==s.pid then local ok,e=pcall(s.open);if not ok then s.lastError=tostring(e) end end
|
|
end,0x76)
|
|
_G.PBZ_SaveMenuAnywhere=s
|
|
local opened,e=pcall(s.open);if not opened then s.lastError=tostring(e) end
|
|
return assembly
|
|
{$asm}
|
|
[DISABLE]
|
|
{$lua}
|
|
if syntaxcheck then return end
|
|
local s=rawget(_G,'PBZ_SaveMenuAnywhere')
|
|
if s then return s.stop() end
|
|
local d=rawget(_G,'PBZ_UtilityDispatch');if d then return d.release('save') end
|
|
{$asm}
|