Files
pbz-trainer/runtime/resources/scripts/1337142249.aa
T

483 lines
19 KiB
Plaintext

[ENABLE]
{$lua}
local feature="consumables"
local patterns={DamageAdd="48 89 5C 24 10 F3 0F 11 54 24 18 57 48 83 EC 20 48 8B D9 48 8B FA 48 8B CA",Medicine="48 89 5C 24 18 55 57 41 56 48 81 EC F0 02 00 00 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 E0 02 00 00",InventoryOne="41 8B 80 ?? ?? ?? ?? B9 00 00 00 00 2B C6 48 8B D3 0F 48 C1 48 8D 8F 68 01 00 00 41 89 80 ?? ?? ?? ??",InventoryBatch="8B 81 ?? ?? ?? ?? 44 8B C7 2B C7 48 8B D3 41 0F 48 C4 89 81 ?? ?? ?? ?? 49 8D 8D 68 01 00 00",Modification="48 8B C4 4C 89 40 18 55 53 56 48 8D 68 B1 48 81 EC D0 00 00 00 0F 29 70 B8 49 8B D9 0F 29 78 A8 48 89 78 10 48 8B 3D ?? ?? ?? ?? 4C 89 60 E0 4C 8B E1 4C 89 68 D8 8B CF 4C 89 70 D0",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)]={address=f,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 worldRef=uniqueScan(patterns.world)
local worldSlot=worldRef+7+readInteger(worldRef+3,true)
local namesRef=uniqueScan(patterns.names)+0x1C
state.namePool=namesRef+7+readInteger(namesRef+3,true)
local world=q(worldSlot);assert(ptr(world),'Load a save first')
local giOffset=offset(classOf(world),'OwningGameInstance')
local gi=q(world+giOffset);assert(ptr(gi),'Local game instance unavailable')
local playersOffset=offset(classOf(gi),'LocalPlayers')
local players,num=array(gi+playersOffset,8);assert(players and num>0,'Local player unavailable')
local lp=q(players);assert(ptr(lp),'Local player unavailable')
local controllerOffset=offset(classOf(lp),'PlayerController')
local pc=q(lp+controllerOffset);assert(ptr(pc),'Local controller unavailable')
local pawnOffset=offset(classOf(pc),'Pawn');local pawn=q(pc+pawnOffset)
assert(ptr(pawn),'Local pawn unavailable')
local function baseClass(cl,name)
local seen={}
for i=1,32 do
if not ptr(cl) or seen[cl] then return end;seen[cl]=true
if fname(cl+0x18)==name then return cl end
cl=q(cl+0x40)
end
end
local pawnClass=baseClass(classOf(pawn),'PBZCharacter');assert(pawnClass,'Unsupported local pawn')
local cfg={pid=state.pid,worldSlot=worldSlot,gi=giOffset,players=playersOffset,controller=controllerOffset,
pawn=pawnOffset,asc=offset(classOf(pawn),'AbilitySystemComponent'),pawnClass=pawnClass}
if feature=='consumables' then
cfg.Medicine=uniqueScan(patterns.Medicine);cfg.InventoryOne=uniqueScan(patterns.InventoryOne)
cfg.InventoryBatch=uniqueScan(patterns.InventoryBatch)
local data=q(world+0x9E0);local count=readInteger(world+0x9E8)
assert(ptr(data) and count and count>0 and count<2048,'Unsupported world subsystem map')
local bp
for i=0,count-1 do
local a=q(data+i*24+8)
local cl=ptr(a) and classOf(a)
if ptr(cl) and fname(cl+0x18)=='PBZBackPackSubsystem' and q(a+0x20)==world then bp=a;break end
end
assert(bp,'Local world backpack unavailable');cfg.backpackClass=classOf(bp)
local inventory=field(cfg.backpackClass,'Inventories',true)
local value=q(inventory.address+0x78)
local infoClass=ptr(value) and q(value+0x70)
assert(ptr(infoClass) and fname(infoClass+0x18)=='PBZInventoryInfo','Inventory map ABI changed')
cfg.infoClass=infoClass
local amount=field(infoClass,'CurrentAmount',true)
assert(amount.size==4 and readInteger(cfg.InventoryOne+3)==amount.offset
and readInteger(cfg.InventoryBatch+2)==amount.offset,'Inventory decrement no longer matches reflected amount')
local itemData=field(infoClass,'ItemDataStruct',true)
local itemType=field(itemData.type,'ItemType',true)
local detail=field(itemData.type,'ItemDetailType',true)
local itemGA=field(itemData.type,'ItemGA',true)
local function enumValue(prop,wanted)
local en=q(prop.address+0x78)
assert(ptr(en),'Missing inventory enum')
local names=q(en+0x40);local values=q(en+0x48);local n=readInteger(en+0x50)
assert(ptr(names) and ptr(values) and n and n>0 and n<256,'Unsupported UE5.7 enum storage')
names=names&(~1);values=values&(~1)
for i=0,n-1 do if fname(names+i*8)==wanted then return q(values+i*8) end end
error('Missing enum value '..wanted)
end
cfg.itemValue=enumValue(itemType,'EItemTypes::Item')
cfg.noneValue=enumValue(detail,'EItemDetailType::None');cfg.cookingValue=enumValue(detail,'EItemDetailType::Cooking')
cfg.itemType=itemData.offset+itemType.offset;cfg.detail=itemData.offset+detail.offset
cfg.itemGAPath=itemData.offset+itemGA.offset+8
else
cfg.DamageAdd=uniqueScan(patterns.DamageAdd)
local method=uniqueScan(patterns.Modification)
local ac=q(pawn+offset(classOf(pawn),'Attribute Component'))
local calculator=ptr(ac) and q(ac+offset(classOf(ac),'DefaultDamageCalculator'))
assert(ptr(calculator) and q(q(calculator)+0x2B8)==method,'Unsupported local damage calculator')
local b=readBytes(method,0x1100,true);assert(b and #b==0x1100,'Damage method unreadable')
assert(b[4]==0x4C and b[5]==0x89 and b[6]==0x40 and b[11]==0x48 and b[12]==0x8D and b[13]==0x68,'Damage frame layout changed')
local frame=b[14];if frame>=128 then frame=frame-256 end
cfg.targetASC=b[7]-frame
cfg.targetMap=0x30-frame
local moves={0x0F,0x28,0xD6,0x48,0x8B,0xD0,0x48,0x8B,0xCE}
local getter;local calls={}
for i=1,#b-20 do
if b[i]==0xE8 and b[i+14]==0xE8 then
local match=true;for k=1,9 do if b[i+4+k]~=moves[k] then match=false;break end end
if match then
local a=method+i-1
local target=a+5+readInteger(a+1,true)
local add=a+19+readInteger(a+15,true)
if add==cfg.DamageAdd then
if not getter then getter=target end
if target==getter then calls[#calls+1]=a+19 end
end
end
end
end
assert(getter and #calls>0 and #calls<=32,'Health modification calls unavailable')
local healthName=false
local g=readBytes(getter,0xA0,true)
for i=1,#g-7 do
if g[i]==0x4C and g[i+1]==0x8D and g[i+2]==5 then
local a=getter+i-1;local text=a+7+readInteger(a+3,true)
if exactString(text,6,true)=='Health' then healthName=true;break end
end
end
assert(healthName,'First damage attribute is not verified Health')
cfg.healthCalls=calls
end
cfg.originals={}
local hooks=feature=='consumables' and {{'Medicine',16},{'InventoryOne',14},{'InventoryBatch',14}} or {{'DamageAdd',16}}
for _,h in ipairs(hooks) do
local bytes=readBytes(cfg[h[1]],h[2],true);assert(bytes and #bytes==h[2],'Original instructions unavailable')
local fingerprint=2166136261
for _,b in ipairs(bytes) do fingerprint=((fingerprint~b)*16777619)&0xFFFFFFFF end
cfg[h[1]..'Hash']=fingerprint;cfg.originals[h[1]]=bytes
end
local definitions={}
local function define(k,v) definitions[#definitions+1]=('define(PBZ_IC_%s,%X)'):format(k,v) end
define('PID',cfg.pid)
define('WorldSlot',cfg.worldSlot)
define('MedicineHash',cfg.MedicineHash)
define('InventoryOneHash',cfg.InventoryOneHash)
define('InventoryBatchHash',cfg.InventoryBatchHash)
define('Medicine',cfg.Medicine)
define('InventoryOne',cfg.InventoryOne)
define('InventoryBatch',cfg.InventoryBatch)
define('BackpackClass',cfg.backpackClass)
define('InfoClass',cfg.infoClass)
define('ItemType',cfg.itemType)
define('Detail',cfg.detail)
define('ItemGAPath',cfg.itemGAPath)
define('ItemValue',cfg.itemValue)
define('NoneValue',cfg.noneValue)
define('CookingValue',cfg.cookingValue)
local native=[====[alloc(PBZ_IC_Code,$3000)
label(PBZ_IC_MedicineCode)
label(PBZ_IC_MedicinePass)
label(PBZ_IC_InventoryOneCode)
label(PBZ_IC_InventoryOneUsable)
label(PBZ_IC_InventoryOnePass)
label(PBZ_IC_InventoryBatchCode)
label(PBZ_IC_InventoryBatchUsable)
label(PBZ_IC_InventoryBatchPass)
label(PBZ_IC_Config)
label(PBZ_IC_BackpackClassValue)
label(PBZ_IC_InfoClassValue)
label(PBZ_IC_OriginalMedicine)
label(PBZ_IC_OriginalInventoryOne)
label(PBZ_IC_OriginalInventoryBatch)
registersymbol(PBZ_IC_Code)
registersymbol(PBZ_IC_Config)
registersymbol(PBZ_IC_Medicine)
registersymbol(PBZ_IC_InventoryOne)
registersymbol(PBZ_IC_InventoryBatch)
registersymbol(PBZ_IC_OriginalMedicine)
registersymbol(PBZ_IC_OriginalInventoryOne)
registersymbol(PBZ_IC_OriginalInventoryBatch)
registersymbol(PBZ_IC_MedicineCode)
registersymbol(PBZ_IC_InventoryOneCode)
registersymbol(PBZ_IC_InventoryBatchCode)
PBZ_IC_Code:
PBZ_IC_MedicineCode:
pushfq
push rax
push r10
push r11
test r8d,r8d
jle PBZ_IC_MedicinePass
mov r11,rcx
mov rax,[r11+10]
cmp rax,[PBZ_IC_BackpackClassValue]
jne PBZ_IC_MedicinePass
mov rax,PBZ_IC_WorldSlot
mov rax,[rax]
test rax,rax
je PBZ_IC_MedicinePass
cmp [r11+20],rax
jne PBZ_IC_MedicinePass
xor r8d,r8d
PBZ_IC_MedicinePass:
pop r11
pop r10
pop rax
popfq
readmem(PBZ_IC_Medicine,$10)
db FF 25 00 00 00 00
dq PBZ_IC_Medicine+10
PBZ_IC_InventoryOneCode:
pushfq
push rax
push r10
push r11
test esi,esi
jle PBZ_IC_InventoryOnePass
mov r11,rdi
mov rax,[r11+10]
cmp rax,[PBZ_IC_BackpackClassValue]
jne PBZ_IC_InventoryOnePass
mov rax,PBZ_IC_WorldSlot
mov rax,[rax]
test rax,rax
je PBZ_IC_InventoryOnePass
cmp [r11+20],rax
jne PBZ_IC_InventoryOnePass
mov r10,r8
test r10,r10
je PBZ_IC_InventoryOnePass
mov rax,[r10+10]
cmp rax,[PBZ_IC_InfoClassValue]
jne PBZ_IC_InventoryOnePass
cmp byte ptr [r10+PBZ_IC_ItemType],PBZ_IC_ItemValue
jne PBZ_IC_InventoryOnePass
movzx eax,byte ptr [r10+PBZ_IC_Detail]
cmp eax,PBZ_IC_NoneValue
je PBZ_IC_InventoryOneUsable
cmp eax,PBZ_IC_CookingValue
jne PBZ_IC_InventoryOnePass
PBZ_IC_InventoryOneUsable:
cmp qword ptr [r10+PBZ_IC_ItemGAPath],0
je PBZ_IC_InventoryOnePass
xor esi,esi
PBZ_IC_InventoryOnePass:
pop r11
pop r10
pop rax
popfq
readmem(PBZ_IC_InventoryOne,$0E)
db FF 25 00 00 00 00
dq PBZ_IC_InventoryOne+E
PBZ_IC_InventoryBatchCode:
pushfq
push rax
push r10
push r11
test edi,edi
jle PBZ_IC_InventoryBatchPass
mov r11,r13
mov rax,[r11+10]
cmp rax,[PBZ_IC_BackpackClassValue]
jne PBZ_IC_InventoryBatchPass
mov rax,PBZ_IC_WorldSlot
mov rax,[rax]
test rax,rax
je PBZ_IC_InventoryBatchPass
cmp [r11+20],rax
jne PBZ_IC_InventoryBatchPass
mov r10,rcx
test r10,r10
je PBZ_IC_InventoryBatchPass
mov rax,[r10+10]
cmp rax,[PBZ_IC_InfoClassValue]
jne PBZ_IC_InventoryBatchPass
cmp byte ptr [r10+PBZ_IC_ItemType],PBZ_IC_ItemValue
jne PBZ_IC_InventoryBatchPass
movzx eax,byte ptr [r10+PBZ_IC_Detail]
cmp eax,PBZ_IC_NoneValue
je PBZ_IC_InventoryBatchUsable
cmp eax,PBZ_IC_CookingValue
jne PBZ_IC_InventoryBatchPass
PBZ_IC_InventoryBatchUsable:
cmp qword ptr [r10+PBZ_IC_ItemGAPath],0
je PBZ_IC_InventoryBatchPass
xor edi,edi
PBZ_IC_InventoryBatchPass:
pop r11
pop r10
pop rax
popfq
readmem(PBZ_IC_InventoryBatch,$0E)
db FF 25 00 00 00 00
dq PBZ_IC_InventoryBatch+E
align 10
PBZ_IC_Config:
dq 50425A434F4E3031
dd PBZ_IC_PID
dd 0
dd PBZ_IC_MedicineHash
dd PBZ_IC_InventoryOneHash
dd PBZ_IC_InventoryBatchHash
align 8
PBZ_IC_BackpackClassValue:
dq PBZ_IC_BackpackClass
PBZ_IC_InfoClassValue:
dq PBZ_IC_InfoClass
align 10
PBZ_IC_OriginalMedicine:
readmem(PBZ_IC_Medicine,$10)
align 10
PBZ_IC_OriginalInventoryOne:
readmem(PBZ_IC_InventoryOne,$0E)
align 10
PBZ_IC_OriginalInventoryBatch:
readmem(PBZ_IC_InventoryBatch,$0E)
PBZ_IC_Medicine:
db FF 25 00 00 00 00
dq PBZ_IC_MedicineCode
db 90 90
PBZ_IC_InventoryOne:
db FF 25 00 00 00 00
dq PBZ_IC_InventoryOneCode
PBZ_IC_InventoryBatch:
db FF 25 00 00 00 00
dq PBZ_IC_InventoryBatchCode
]====]
local checks={}
for name,bytes in pairs(cfg.originals) do local text={}
for _,b in ipairs(bytes) do text[#text+1]=('%02X'):format(b) end
checks[#checks+1]=('assert(PBZ_IC_%s,%s)'):format(name,table.concat(text,' ')) end
local assembly=table.concat(definitions,'\n')..'\n'..table.concat(checks,'\n')..'\n'..native
if syntaxcheck then return assembly end
return assembly
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
local prefix="PBZ_IC"
local code=getAddressSafe(prefix..'_Code');local config=getAddressSafe(prefix..'_Config')
if not code or code==0 or not config or config<code or config+32>=code+0x3000 then error('Missing owned restore allocation') end
if readQword(config)~=0x50425a434f4e3031 or readInteger(config+8)~=getOpenedProcessID() then error('Restore process/version mismatch') end
local sections={{name="Medicine",size=16,hashOffset=16,destination="PBZ_IC_MedicineCode",expected={72,137,92,36,24,85,87,65,86,72,129,236,240,2,0,0}},{name="InventoryOne",size=14,hashOffset=20,destination="PBZ_IC_InventoryOneCode",expected={65,139,128,-1,-1,-1,-1,185,0,0,0,0,43,198}},{name="InventoryBatch",size=14,hashOffset=24,destination="PBZ_IC_InventoryBatchCode",expected={139,129,-1,-1,-1,-1,68,139,199,43,199,72,139,211}}}
local restore={}
for _,s in ipairs(sections) do
local hook=getAddressSafe(prefix..'_'..s.name);local original=getAddressSafe(prefix..'_Original'..s.name)
local destination=getAddressSafe(s.destination)
if not hook or not original or original<code or original+s.size>=code+0x3000 or not destination
or destination<code or destination>=code+0x3000 then error('Restore symbols incomplete') end
local b=readBytes(hook,s.size,true)
if not b or #b~=s.size or b[1]~=0xFF or b[2]~=0x25 or b[3]~=0 or b[4]~=0 or b[5]~=0 or b[6]~=0
or readQword(hook+6)~=destination then error('Hook ownership changed; refusing restoration') end
for i=15,s.size do if b[i]~=0x90 then error('Explicit padding changed') end end
b=readBytes(original,s.size,true)
if not b or #b~=s.size then error('Original bytes unreadable') end
for i=1,s.size do if s.expected[i]>=0 and b[i]~=s.expected[i] then error('Saved instructions mismatch') end end
local fingerprint=2166136261
for _,byte in ipairs(b) do fingerprint=((fingerprint~byte)*16777619)&0xFFFFFFFF end
if fingerprint~=readInteger(config+s.hashOffset) then error('Original instruction fingerprint mismatch') end
restore[#restore+1]=('%X:\n readmem(%X,$%X)\n'):format(hook,original,s.size)
end
return table.concat(restore,'\n')..[====[
unregistersymbol(PBZ_IC_Code)
unregistersymbol(PBZ_IC_Config)
unregistersymbol(PBZ_IC_Medicine)
unregistersymbol(PBZ_IC_InventoryOne)
unregistersymbol(PBZ_IC_InventoryBatch)
unregistersymbol(PBZ_IC_OriginalMedicine)
unregistersymbol(PBZ_IC_OriginalInventoryOne)
unregistersymbol(PBZ_IC_OriginalInventoryBatch)
unregistersymbol(PBZ_IC_MedicineCode)
unregistersymbol(PBZ_IC_InventoryOneCode)
unregistersymbol(PBZ_IC_InventoryBatchCode)
dealloc(PBZ_IC_Code)
]====]
{$asm}