221 lines
12 KiB
Lua
221 lines
12 KiB
Lua
function H(op,...)
|
|
local ok,value=host(op,...)
|
|
if not ok then error(value,2)end
|
|
return value
|
|
end
|
|
syntaxcheck=false
|
|
vtSingle,vtByteArray,soExactValue,rtRounded,fsmNotAligned=4,8,0,0,0
|
|
caNone=0
|
|
process='PBZ.exe'
|
|
function getOpenedProcessID()return H('pid')end
|
|
function getModuleSize()return H('size')end
|
|
function getAddress(x)return resolveAddress(x,false)end
|
|
function getAddressSafe(x)return resolveAddress(x,true)end
|
|
function unregisterSymbol(x)Symbols[x:lower()]=nil end
|
|
unregistersymbol=unregisterSymbol
|
|
function registerSymbol(x,v)Symbols[x:lower()]=v end
|
|
function readBytes(p,n,asTable)
|
|
local bytes=H('read',resolveAddress(p),n or 1);if not bytes then return nil end
|
|
if asTable then return {bytes:byte(1,#bytes)}end
|
|
return bytes:byte(1,#bytes)
|
|
end
|
|
local function read(p,n,kind) local b=H('read',resolveAddress(p),n);if not b then return nil end;return (string.unpack(kind,b))end
|
|
function readQword(p)return read(p,8,'<i8')end
|
|
function readInteger(p,signed)return read(p,4,signed and '<i4' or '<I4')end
|
|
function readSmallInteger(p,signed)return read(p,2,signed and '<i2' or '<I2')end
|
|
function readFloat(p)return read(p,4,'<f')end
|
|
function readDouble(p)return read(p,8,'<d')end
|
|
function writeBytes(p,...)
|
|
local t={...};if type(t[1])=='table'then t=t[1]end
|
|
local b={};for i,v in ipairs(t)do b[i]=string.char(v&255)end
|
|
return H('write',resolveAddress(p),table.concat(b),false)
|
|
end
|
|
local function write(p,kind,v)return H('write',resolveAddress(p),string.pack(kind,v),false)end
|
|
function writeQword(p,v)return write(p,'<i8',v)end
|
|
function writeInteger(p,v)return write(p,'<I4',v&0xFFFFFFFF)end
|
|
function writeSmallInteger(p,v)return write(p,'<I2',v&65535)end
|
|
function writeFloat(p,v)return write(p,'<f',v)end
|
|
function writeDouble(p,v)return write(p,'<d',v)end
|
|
function writeString(p,s,wide)
|
|
if not wide then return H('write',resolveAddress(p),s,false)end
|
|
local chars={};for _,cp in utf8.codes(s)do
|
|
if cp<0x10000 then chars[#chars+1]=string.pack('<I2',cp)else cp=cp-0x10000;chars[#chars+1]=string.pack('<I2I2',0xD800+(cp>>10),0xDC00+(cp&1023))end
|
|
end
|
|
return H('write',resolveAddress(p),table.concat(chars),false)
|
|
end
|
|
function createMemScan()
|
|
local s={hits={}}
|
|
s.firstScan=function(_,_,_,pattern,_,first,last,protection)s.hits=H('scan',pattern,first,last,protection=='+X')end
|
|
s.waitTillDone=function()end;s.destroy=function()end
|
|
return s
|
|
end
|
|
function createFoundList(s)
|
|
local f={Count=0,Address={}}
|
|
f.initialize=function()f.Count=#s.hits;for i,p in ipairs(s.hits)do f.Address[i-1]=('%X'):format(p)end end
|
|
f.destroy=function()end;return f
|
|
end
|
|
function AOBScanModuleUnique(_,pattern,protection)local hits=H('scan',pattern,H('base'),H('base')+H('size')-1,protection=='+X');if #hits==1 then return hits[1]end end
|
|
function getTickCount()return H('ticks')end
|
|
function sleep(n)H('sleep',n)end
|
|
function print(...)local s={};for i,v in ipairs({...})do s[i]=tostring(v)end;H('log',table.concat(s,' '))end
|
|
function showMessage(s)H('message',tostring(s))end
|
|
function writeToClipboard(s)H('clipboard',s)end
|
|
function enumModules()return {{Name='PBZ.exe',PathToFile=H('path'),Address=H('base')}}end
|
|
function getForegroundProcess()return H('foregroundPid')end
|
|
function getForegroundWindow()return H('foregroundWindow')end
|
|
function getWindow(h,c)return H('window',h,c)end
|
|
function getWindowProcessID(h)return H('windowPid',h)end
|
|
function getWindowClassName(h)return H('windowClass',h)end
|
|
function isKeyPressed(k)return H('key',k)end
|
|
function getXBox360ControllerState(i)return H('controller',i or 0)end
|
|
function readIntegerLocal(p,signed)local b=H('localRead',p,4);return(string.unpack(signed and '<i4' or '<I4',b))end
|
|
function writeIntegerLocal(p,v)return H('localWrite',p,string.pack('<I4',v&0xffffffff))end
|
|
function createMemoryStream()
|
|
local s={Memory=H('localAlloc',4096)};s.destroy=function()if s.Memory then H('localFree',s.Memory);s.Memory=nil end end
|
|
return s
|
|
end
|
|
function executeCodeLocalEx(name,...)return H('localCall',name,...)end
|
|
function createHotkey(callback,...)
|
|
local keys={...};if type(keys[1])=='table'then keys=keys[1]end
|
|
local id=H('hotkeyCreate',callback,keys)
|
|
return {destroy=function()H('hotkeyDestroy',id)end}
|
|
end
|
|
function createTimer(owner,enabled)
|
|
if type(owner)=='number'and type(enabled)=='function'then local t=createTimer(nil,false);t.Interval=owner;t.OnTimer=function()t.destroy();enabled()end;t.Enabled=true;return t end
|
|
local id=H('timerCreate');local props={Interval=100,Enabled=enabled~=false}
|
|
local t={destroy=function()H('timerDestroy',id)end}
|
|
return setmetatable(t,{__index=function(_,k)if k=='Enabled'or k=='Interval'then return H('timerGet',id,k)end;return props[k]end,__newindex=function(_,k,v)props[k]=v;H('timerSet',id,k,v)end})
|
|
end
|
|
|
|
Records={};local serial=2000000000
|
|
local function makeRecord(id,description,script)
|
|
local p={ID=id,Description=description,Script=script or '',_active=false,_address='',_parent=nil}
|
|
local methods={}
|
|
methods.destroy=function()for i,r in ipairs(Records)do if r.ID==id then table.remove(Records,i);break end end end
|
|
methods.appendToEntry=function(parent)p._parent=parent end
|
|
local r=setmetatable({}, {__index=function(_,k)
|
|
if k=='Active'then return p._active end
|
|
if k=='Address'then return p._address end
|
|
if k=='Parent'then return p._parent end
|
|
if k=='Value'then local a=resolveAddress(p._address,true);if not a then return nil end;return readFloat(a)end
|
|
return methods[k]or p[k]
|
|
end,__newindex=function(_,k,v)
|
|
if k=='Active'then if v~=p._active then H('toggle',id,v)end
|
|
elseif k=='Address'then p._address=v
|
|
elseif k=='Parent'then p._parent=v
|
|
elseif k=='Value'then assert(writeFloat(p._address,tonumber(v)),'Write failed')
|
|
else p[k]=v end
|
|
end})
|
|
r._props=p;Records[#Records+1]=r;return r
|
|
end
|
|
AddressList={}
|
|
AddressList.getMemoryRecord=function(i)return Records[i+1]end
|
|
AddressList.getMemoryRecordByID=function(id)for _,r in ipairs(Records)do if r.ID==id then return r end end end
|
|
AddressList.getCount=function()return #Records end
|
|
AddressList.createMemoryRecord=function()serial=serial+1;return makeRecord(serial,'','')end
|
|
setmetatable(AddressList,{__index=function(_,k)if k=='Count'then return #Records end end})
|
|
function getAddressList()return AddressList end
|
|
function DefineFeature(id,description,source)makeRecord(id,description,source)end
|
|
|
|
local function section(source,enabled)
|
|
local a,b=source:find('%[ENABLE%]');local c,d=source:find('%[DISABLE%]')
|
|
if not a then error('Feature has no ENABLE section')end
|
|
local prefix=source:sub(1,a-1)
|
|
if enabled then return prefix..source:sub(b+1,c and c-1 or #source)end
|
|
return prefix..(d and source:sub(d+1)or '')
|
|
end
|
|
function GenerateFeature(id,enabled)
|
|
local record=assert(AddressList.getMemoryRecordByID(id),'Unknown feature')
|
|
local input=section(record.Script,enabled);local asm={};local mode='asm';local pending={}
|
|
local function flush()
|
|
local text=table.concat(pending,'\n');pending={}
|
|
if mode=='lua'then
|
|
local previous=memrec;memrec=record
|
|
local fn,why=load(text,'feature-'..id,'t',_G);if not fn then memrec=previous;error(why)end
|
|
local ok,result=pcall(fn);memrec=previous;if not ok then error(result)end
|
|
if type(result)=='string'then asm[#asm+1]=result end
|
|
else asm[#asm+1]=text end
|
|
end
|
|
for line in (input..'\n'):gmatch('(.-)\n')do
|
|
local m=line:match('^%s*{%$([%a]+)}%s*$')
|
|
if m then flush();mode=m:lower();assert(mode=='lua'or mode=='asm','Unknown script mode')
|
|
else pending[#pending+1]=line end
|
|
end
|
|
flush();return table.concat(asm,'\n')
|
|
end
|
|
PendingInitialization={}
|
|
local transactionSnapshots={}
|
|
function FeatureTransactionActive()return next(transactionSnapshots)~=nil end
|
|
function BeginFeatureTransaction(id)
|
|
local globals={Symbols=Symbols,Allocations=Allocations,Records=Records}
|
|
for k,v in pairs(_G)do if type(k)=='string'and k:match('^PBZ[_%u]')then globals[k]=v end end
|
|
local tables={}
|
|
local function visit(t)
|
|
if type(t)~='table'or tables[t]then return end
|
|
local saved={};tables[t]=saved
|
|
for k,v in pairs(t)do saved[k]=v;visit(k);visit(v)end
|
|
end
|
|
for _,v in pairs(globals)do visit(v)end
|
|
for _,r in ipairs(Records)do visit(r._props)end
|
|
transactionSnapshots[id]={globals=globals,tables=tables}
|
|
end
|
|
function CommitFeatureTransaction(id)transactionSnapshots[id]=nil;PendingInitialization[id]=nil end
|
|
function RollbackFeatureTransaction(id)
|
|
local snapshot=assert(transactionSnapshots[id],'Missing feature transaction snapshot')
|
|
for t,saved in pairs(snapshot.tables)do
|
|
for k in pairs(t)do rawset(t,k,nil)end
|
|
for k,v in pairs(saved)do rawset(t,k,v)end
|
|
end
|
|
for k in pairs(_G)do if type(k)=='string'and k:match('^PBZ[_%u]')and snapshot.globals[k]==nil then _G[k]=nil end end
|
|
for k,v in pairs(snapshot.globals)do _G[k]=v end
|
|
transactionSnapshots[id]=nil;PendingInitialization[id]=nil
|
|
end
|
|
function ToggleFeature(id,enabled)
|
|
local r=assert(AddressList.getMemoryRecordByID(id),'Unknown feature')
|
|
if r._props._active==enabled then return true end
|
|
local previous=r._props._active;r._props._active=enabled
|
|
local priorGlobals={};if enabled then
|
|
for k,v in pairs(_G)do if type(k)=='string'and k:match('^PBZ[_%u]')then priorGlobals[k]=v end end
|
|
local symbols,allocations={},{};for k,v in pairs(Symbols)do symbols[k]=v end;for k,v in pairs(Allocations)do allocations[k]=v end
|
|
PendingInitialization[id]={globals=priorGlobals,symbols=symbols,allocations=allocations}
|
|
end
|
|
local ok,why=pcall(function()local asm=GenerateFeature(id,enabled);if asm:match('%S')then AssembleIndependent(asm)end end)
|
|
if not ok then r._props._active=previous;error(why)end
|
|
PendingInitialization[id]=nil
|
|
return true
|
|
end
|
|
function AbortInitialization(id)
|
|
local snapshot=PendingInitialization[id]
|
|
if snapshot then
|
|
for k in pairs(_G)do if type(k)=='string'and k:match('^PBZ[_%u]')and snapshot.globals[k]==nil then _G[k]=nil end end
|
|
for k,v in pairs(snapshot.globals)do _G[k]=v end
|
|
Symbols=snapshot.symbols;Allocations=snapshot.allocations;PendingInitialization[id]=nil
|
|
end
|
|
local r=AddressList.getMemoryRecordByID(id);if r then r._props._active=false end
|
|
end
|
|
function MarkRecovery(id)local r=AddressList.getMemoryRecordByID(id);if r then r._props._active=true end end
|
|
function FeatureProblem(id)
|
|
local managers={
|
|
[1337142248]='PBZ_NoFallDamage',[1337142250]='PBZ_DamageMultiplier',[1337142245]='PBZ_ItemBrowser',
|
|
[1337142246]='PBZ_ESP',[1337142247]='PBZ_DustEditor',[1337142253]='PBZ_NativeTraits',
|
|
[1337142255]='PBZ_NoClipFly',[1337142256]='PBZ_SaveMenuAnywhere',[1337142254]='PBZ_StealthMode',
|
|
[1337142257]='PBZ_PlayerMovementSpeed',[1337142258]='PBZ_PlayerAnimationSpeed',
|
|
[1337142260]='PBZ_PerfectGuardWindow',[1337142261]='PBZ_PerfectDodgeWindow',[1337142262]='PBZ_ExecutionThreshold',[1337142263]='PBZ_DamageNumbers',[1337142264]='PBZ_AccessorySelection',[1337142265]='PBZ_AutoDodge',[1337142267]='PBZ_HyperArmor'
|
|
}
|
|
local key=managers[id];local state=key and rawget(_G,key)
|
|
if state and state.lastError then return tostring(state.lastError)end
|
|
if state and state.paused then return '运行已暂停,请关闭后重新开启并查看日志。'end
|
|
if (id==1337142267 or id==1337142246 or id==1337142256 or id==1337142254 or id==1337142263 or id==1337142264 or id==1337142258)and PBZ_UtilityDispatch and PBZ_UtilityDispatch.lastError then return tostring(PBZ_UtilityDispatch.lastError)end
|
|
return nil
|
|
end
|
|
function ValidateSyntax(id)
|
|
local r=assert(AddressList.getMemoryRecordByID(id));for _,enabled in ipairs({true,false})do
|
|
local input=section(r.Script,enabled);local mode='asm';local pending={}
|
|
local function flush()if mode=='lua'then assert(load(table.concat(pending,'\n'),'syntax-'..id,'t',_G))end;pending={}end
|
|
for line in (input..'\n'):gmatch('(.-)\n')do local m=line:match('^%s*{%$([%a]+)}%s*$');if m then flush();mode=m:lower()else pending[#pending+1]=line end end;flush()
|
|
end;return true
|
|
end
|
|
|
|
-- Scripts are bundled local resources, not an external plugin loader.
|
|
os.execute=nil;io.popen=nil;package.loadlib=nil;dofile=nil;loadfile=nil
|