176 lines
8.8 KiB
Lua
176 lines
8.8 KiB
Lua
-- One balanced native loose-tag contribution per bound local ability system.
|
|
function CreateHyperArmorLease(binding)
|
|
local s={pending=false,owned=false,active=false,restored=false,started=false}
|
|
local finish,restore
|
|
local function problem(e)s.error=tostring(e or '原生状态请求失败');s.active=false end
|
|
local function send(op,done)
|
|
assert(not s.pending,'霸体请求仍在执行');s.pending=true
|
|
local ok,e=pcall(binding.enqueue,op,function(ok,value)
|
|
s.pending=false
|
|
if not ok then problem(value);if s.stopping and not s.owned then s.restored=true end;return end
|
|
local good,why=pcall(done,value);if not good then problem(why)end
|
|
end)
|
|
if not ok then s.pending=false;problem(e)end
|
|
end
|
|
local function counts(v)
|
|
assert(type(v)=='table'and #v==2,'霸体标签计数不可读')
|
|
for _,n in ipairs(v)do assert(type(n)=='number'and n>=0 and n<=100000 and n%1==0,'霸体标签计数异常')end
|
|
return v
|
|
end
|
|
restore=function()
|
|
if s.pending or s.restored then return end
|
|
if not s.owned or not binding.valid()then s.owned=false;s.active=false;s.restored=true;return end
|
|
send('read',function(value)
|
|
local before=counts(value)
|
|
if not binding.valid()then s.owned=false;s.restored=true;return end
|
|
if before[1]==0 and before[2]==0 then s.owned=false;s.restored=true;return end
|
|
send('remove',function()
|
|
s.owned=false;s.active=false
|
|
send('read',function(after)
|
|
after=counts(after);s.restored=true
|
|
for i=1,2 do assert(after[i]==math.max(0,before[i]-1),'关闭期间标签计数被其他状态改变;本功能已撤销一次')end
|
|
s.error=nil
|
|
end)
|
|
end)
|
|
end)
|
|
end
|
|
s.start=function()
|
|
if s.started or s.stopping then return end;s.started=true
|
|
send('read',function(value)
|
|
s.before=counts(value)
|
|
if s.stopping then restore();return end
|
|
assert(binding.valid(),'角色在开启前已经变化')
|
|
send('add',function()
|
|
s.owned=true
|
|
if s.stopping then restore();return end
|
|
send('read',function(after)
|
|
after=counts(after)
|
|
for i=1,2 do assert(after[i]>=s.before[i]+1,'游戏没有保留霸体状态,请关闭后重试')end
|
|
s.active=true;s.error=nil
|
|
if s.stopping then restore()end
|
|
end)
|
|
end)
|
|
end)
|
|
end
|
|
s.stop=function()s.stopping=true;s.error=nil;restore()end
|
|
return s
|
|
end
|
|
|
|
local armorOwner='hyper_armor'
|
|
local armorTags={'CharacterState.Hitreact.Endure.Stand.Ultimate','CharacterState.Hitreact.Endure.Break.Lv8'}
|
|
local function findArmorName(u,name)
|
|
local blocks=assert(readInteger(u.namePool+8));local cursor=assert(readInteger(u.namePool+12))
|
|
assert(blocks<8192 and cursor<=0x20000,'霸体名称池布局变化')
|
|
local needle=name:lower()
|
|
for block=blocks,0,-1 do
|
|
local data=u.q(u.namePool+0x10+block*8);local bytes=data and H('read',data,block==blocks and cursor or 0x20000)
|
|
if bytes then local text=bytes:lower();local from=1
|
|
while true do local at=text:find(needle,from,true);if not at then break end
|
|
if at>=3 and(at-3)%2==0 then
|
|
local h=string.unpack('<I2',bytes,at-2)
|
|
if h&1==0 and h>>6==#name then return(block<<16)|((at-3)//2)end
|
|
end
|
|
from=at+1
|
|
end
|
|
end
|
|
end
|
|
error('游戏未注册霸体状态:'..name)
|
|
end
|
|
function EnableHyperArmor()
|
|
assert(not PBZ_HyperArmor,'霸体已经开启')
|
|
local u=NativeDamageNumberDependencies();u.prepareObjects()
|
|
local initial=assert(u.context(),'请先载入可操作角色')
|
|
local classes=u.objectInventory({AbilitySystemBlueprintLibrary='Class',PBZHitreactUtils='Class'})
|
|
local function api(cl,name,size,rva,fields)
|
|
local t=u.staticTarget(cl,name,fields);assert(readSmallInteger(t.fn.address+0x106)==size and t.native==getAddress('PBZ.exe')+rva,'霸体原生接口与当前版本不符:'..name);return t
|
|
end
|
|
local add=api(classes.AbilitySystemBlueprintLibrary,'AddLooseGameplayTags',42,0x4CAAFD0,{Actor={0,8},GameplayTags={8,32},bShouldReplicate={40,1},ReturnValue={41,1}})
|
|
local remove=api(classes.AbilitySystemBlueprintLibrary,'RemoveLooseGameplayTags',42,0x4CBD7F0,{Actor={0,8},GameplayTags={8,32},bShouldReplicate={40,1},ReturnValue={41,1}})
|
|
local level=api(classes.PBZHitreactUtils,'GetEndureLevel',12,0x7D6DB00,{AbilitySystem={0,8},ReturnValue={8,4}})
|
|
local brokenLevel=api(classes.PBZHitreactUtils,'GetAbilitySystemBreakEndureLevel',12,0x7D6D6D0,{AbilitySystem={0,8},ReturnValue={8,4}})
|
|
local tags={findArmorName(u,armorTags[1]),findArmorName(u,armorTags[2])}
|
|
local s={pid=getOpenedProcessID(),u=u,tags=tags,add=add,remove=remove,level=level,brokenLevel=brokenLevel}
|
|
local function snapshot(c)
|
|
local pawn=assert(u.identity(c.pawn));local asc=u.q(c.pawn+u.offset(pawn.class,'AbilitySystemComponent'))
|
|
local id=assert(u.identity(asc),'玩家技能系统不可用')
|
|
assert(u.q(asc+0x20)==c.pawn,'技能系统不属于当前角色,拒绝使用未验证的持久状态系统')
|
|
local fn=assert(u.functions(id.class,'GetGameplayTagCount'))
|
|
assert(readSmallInteger(fn+0x106)==12 and u.q(fn+0x128)==getAddress('PBZ.exe')+0x4CB6940,'标签计数接口变化')
|
|
for n,spec in pairs({GameplayTag={0,8},ReturnValue={8,4}})do local f=u.field(fn,n,true);assert(f.offset==spec[1]and f.size==spec[2],'标签计数参数变化')end
|
|
return {pawn=pawn,asc=id,pawnWeak=assert(u.weakReference(pawn)),ascWeak=assert(u.weakReference(id)),countFn=assert(u.identity(fn))}
|
|
end
|
|
local function valid(b)
|
|
return s.pid==getOpenedProcessID()and u.q(b.asc.address+0x20)==b.pawn.address and u.weakReference(b.pawn)==b.pawnWeak and u.weakReference(b.asc)==b.ascWeak
|
|
and u.q(b.pawn.address+u.offset(b.pawn.class,'AbilitySystemComponent'))==b.asc.address
|
|
end
|
|
local first=snapshot(initial)
|
|
local d,assembly=u.acquireDispatch(armorOwner);ProtectDamageNumberDispatcher(d,u.worldSlot);s.dispatcher=d
|
|
local function request(b,target,writes,kind,offset,done,currentPawnOnly)
|
|
local c=u.context()
|
|
if not c or not valid(b)then done(false,'当前角色或技能系统已改变');return end
|
|
local r={owner=armorOwner,world=c.world,pcID=u.identity(c.pc),receiver=target.receiver,fn=target.fn,extra=b.pawn,currentPawnOnly=currentPawnOnly==true,
|
|
resultKind=kind,resultOffset=offset,writes=writes,validate=function()return valid(b)end}
|
|
r.capture=kind=='object'and function(mail)return readInteger(mail+0x80+offset,true)end or nil
|
|
r.callback=function(result)
|
|
if not result.success then done(false,result.error or '游戏拒绝霸体请求')
|
|
elseif kind=='bool'then done(result.result~=0,result.result==0 and '游戏未接受霸体标签命令'or nil)
|
|
else done(true,result.payload)end
|
|
end
|
|
d.enqueue(r)
|
|
end
|
|
local function bind(b)
|
|
s.binding=b
|
|
local lease=CreateHyperArmorLease({valid=function()return valid(b)end,enqueue=function(op,done)
|
|
if op=='read'then
|
|
local result={};local target={receiver=b.asc,fn=b.countFn}
|
|
request(b,target,{{0,tags[1]}},'object',8,function(ok,value)
|
|
if not ok then done(false,value);return end;result[1]=value
|
|
request(b,target,{{0,tags[2]}},'object',8,function(ok,value)
|
|
if not ok then done(false,value);return end;result[2]=value;s.lastCounts={result[1],result[2]};done(true,result)
|
|
end)
|
|
end)
|
|
else
|
|
local mail=assert(getAddressSafe('PBZ_UT_Mailbox'),'霸体调度器尚未安装')
|
|
local writes={{0,b.pawn.address},{8,mail+0x180},{16,2|(2<<32)},{0x100,tags[1]},{0x108,tags[2]}}
|
|
request(b,op=='add'and add or remove,writes,'bool',41,done,op=='add')
|
|
end
|
|
end})
|
|
s.lease=lease;lease.start()
|
|
end
|
|
s.tick=function()
|
|
if s.stopping then return end
|
|
if not getAddressSafe('PBZ_UT_Mailbox')then return end
|
|
local c=u.context()
|
|
if s.lease then
|
|
s.lastError=s.lease.error or d.lastError
|
|
if s.lease.pending then return end
|
|
if s.lease.stopping or not c or not valid(s.binding)or c.pawn~=s.binding.pawn.address then
|
|
s.lease.stop();if s.lease.restored and not s.lease.owned then s.lease=nil;s.binding=nil end
|
|
return
|
|
end
|
|
elseif c then bind(snapshot(c))end
|
|
end
|
|
s.prepareStop=function()
|
|
s.stopping=true
|
|
if s.lease then
|
|
d.drain(armorOwner);s.lease.stop();d.drain(armorOwner)
|
|
assert(s.lease.restored and not s.lease.pending and not s.lease.owned,s.lease.error or '霸体状态尚未撤销,请进入角色场景后重试')
|
|
end
|
|
end
|
|
s.stop=function()
|
|
assert(not s.lease or(s.lease.restored and not s.lease.pending and not s.lease.owned),'请先完成霸体状态恢复')
|
|
local restore=d.release(armorOwner);if s.timer then s.timer.destroy();s.timer=nil end
|
|
if PBZ_HyperArmor==s then PBZ_HyperArmor=nil end;return restore
|
|
end
|
|
s.timer=createTimer(nil,false);s.timer.Interval=100
|
|
s.timer.OnTimer=function()local ok,e=pcall(s.tick);if not ok then s.lastError=tostring(e)end end
|
|
PBZ_HyperArmor=s;s.timer.Enabled=true
|
|
return assembly
|
|
end
|
|
function PrepareHyperArmorDisable()
|
|
local s=PBZ_HyperArmor;if s then s.prepareStop()end
|
|
end
|
|
function DisableHyperArmor()
|
|
local s=PBZ_HyperArmor;return s and s.stop()or ''
|
|
end
|