305 lines
17 KiB
Lua
305 lines
17 KiB
Lua
-- Appended in the same private reflection scope as PlayerSpeed.lua.
|
|
local function frameValue(value)
|
|
assert(finite(value)and value%1==0 and value>=1 and value<=120,'窗口帧数必须是 1 到 120 的整数');return value
|
|
end
|
|
local function frameLeaseValid(l)
|
|
if not l or state.pid~=getOpenedProcessID()then return false end
|
|
local id=l.object
|
|
local cl=q(id.address+0x10);local name=q(id.address+0x18);local index=readInteger(id.address+0xC)
|
|
assert(cl~=nil and name~=nil and index~=nil,'战斗参数对象身份不可读,保留恢复信息')
|
|
if cl~=id.class or name~=id.name or index~=id.index then return false end
|
|
local owner=q(id.address+0x20);assert(owner~=nil,'战斗参数归属不可读,保留恢复信息')
|
|
return owner==l.owner
|
|
end
|
|
local function readParameter(l)return (l.kind=='float'and readFloat or readInteger)(l.object.address+l.offset)end
|
|
local function writeParameter(l,v)return (l.kind=='float'and writeFloat or writeInteger)(l.object.address+l.offset,v)end
|
|
local function applyPair(leases,requested,additive)
|
|
local before,values={},{}
|
|
assert(#leases>=1 and #leases<=2,'战斗参数绑定缺失')
|
|
for i,l in ipairs(leases)do
|
|
assert(frameLeaseValid(l),'格挡配置对象身份发生变化')
|
|
local value=assert(readParameter(l),'战斗参数不可读')
|
|
assert(finite(value)and value>=0 and value<=(l.kind=='float'and 3 or 1200),'战斗参数原值异常')
|
|
before[i]={value=value,base=l.base,lastWritten=l.lastWritten}
|
|
local base=l.lastWritten~=nil and value==l.lastWritten and l.base or value
|
|
local target=additive and base+requested[i]/100 or requested[i]
|
|
values[i]=l.kind=='float'and quantize(target)or target
|
|
assert(finite(values[i])and values[i]<=(l.kind=='float'and 3 or 120),'战斗参数目标值异常')
|
|
end
|
|
local ok,e=pcall(function()
|
|
for i,l in ipairs(leases)do
|
|
assert(frameLeaseValid(l),'格挡配置对象身份发生变化')
|
|
local old=before[i]
|
|
if l.lastWritten==nil or old.value~=l.lastWritten then l.base=old.value end
|
|
l.lastWritten=values[i]
|
|
if old.value~=values[i]then assert(writeParameter(l,values[i]),'战斗参数写入失败')end
|
|
end
|
|
end)
|
|
if not ok then
|
|
local errors={}
|
|
for i=#leases,1,-1 do
|
|
local l=leases[i];local old=before[i]
|
|
local restored,why=pcall(function()
|
|
assert(frameLeaseValid(l),'恢复时配置对象身份发生变化')
|
|
local current=readParameter(l)
|
|
if current==values[i]then assert(writeParameter(l,old.value),'成对参数恢复失败')
|
|
else assert(current==old.value,'恢复目标已被游戏更改,已拒绝覆盖')end
|
|
l.base=old.base;l.lastWritten=old.lastWritten
|
|
end)
|
|
if not restored then errors[#errors+1]=tostring(why)end
|
|
end
|
|
error(tostring(e)..(#errors>0 and '; '..table.concat(errors,'; ')or ''))
|
|
end
|
|
end
|
|
function ApplyCombatFramePair(leases,normal,broken)
|
|
assert(#leases==2,'格挡窗口成对绑定缺失')
|
|
return applyPair(leases,{frameValue(normal),frameValue(broken)},false)
|
|
end
|
|
local function bonusValue(v)
|
|
assert(finite(v)and v>=0 and v<=100,'处决阈值加成必须在 0 到 100 个百分点之间');return v
|
|
end
|
|
function ApplyExecutionThresholdPair(leases,normal,broken)
|
|
assert(#leases==2,'处决阈值成对绑定缺失')
|
|
for _,l in ipairs(leases)do assert(l.kind=='float','处决属性绑定类型错误')end
|
|
return applyPair(leases,{bonusValue(normal),bonusValue(broken)},true)
|
|
end
|
|
function RestoreCombatFramePair(leases)
|
|
local errors={}
|
|
for _,l in ipairs(leases or {})do
|
|
local ok,e=pcall(function()
|
|
if frameLeaseValid(l)and l.lastWritten~=nil then
|
|
local current=assert(readParameter(l),'战斗参数不可读,保留恢复信息以便重试')
|
|
if current==l.lastWritten then assert(writeParameter(l,l.base),'战斗参数恢复失败')end
|
|
l.base=nil;l.lastWritten=nil
|
|
end
|
|
end)
|
|
if not ok then errors[#errors+1]=tostring(e)end
|
|
end
|
|
assert(#errors==0,table.concat(errors,'; '))
|
|
end
|
|
local function guardBinding(c)
|
|
local weapons=q(c.pawn+offset(c.id.class,'Character Weapons Component'));local wid=identity(weapons)
|
|
assert(wid and q(weapons+0x20)==c.pawn,'玩家武器组件不可用')
|
|
local combined=q(weapons+offset(wid.class,'GlobalConfig'));local gid=identity(combined)
|
|
assert(gid and fname(gid.class+0x18)=='PDA_GlobalConfig_Combined_C','当前难度配置不可用')
|
|
local combat=q(combined+offset(gid.class,'Combat Config'));local id=identity(combat)
|
|
assert(id and fname(id.class+0x18)=='PDA_GlobalCombatConfig_C','战斗配置不可用')
|
|
local outer=q(combat+0x20);assert(ptr(outer),'战斗配置归属不可用')
|
|
local leases={}
|
|
for _,name in ipairs({'Deflect Perfect Window Frames','Deflect Perfect Window Frames On Break'})do
|
|
local p=field(id.class,name,true);assert(p.size==4,'格挡窗口字段结构发生变化')
|
|
local v=assert(readInteger(combat+p.offset),'格挡窗口不可读');assert(v>=1 and v<=120,'格挡窗口原值超出已验证范围')
|
|
leases[#leases+1]={object=id,owner=outer,offset=p.offset}
|
|
end
|
|
assert(valid(c.id)and valid(wid)and q(weapons+offset(wid.class,'GlobalConfig'))==combined,'玩家难度配置已变化')
|
|
return {object=id,leases=leases,name=fname(combat+0x18)}
|
|
end
|
|
function EnablePerfectGuardWindow()
|
|
assert(not PBZ_PerfectGuardWindow,'完美格挡窗口已经开启')
|
|
local s={pid=state.pid}
|
|
s.refresh=function()
|
|
local c=context()
|
|
if not c then RestoreCombatFramePair(s.binding and s.binding.leases);s.binding=nil;return end
|
|
local nextBinding=guardBinding(c)
|
|
if not s.binding or not valid(s.binding.object)or s.binding.object.address~=nextBinding.object.address then
|
|
RestoreCombatFramePair(s.binding and s.binding.leases);s.binding=nextBinding
|
|
end
|
|
if not s.normal then s.normal=readInteger(s.binding.object.address+s.binding.leases[1].offset);s.broken=readInteger(s.binding.object.address+s.binding.leases[2].offset)end
|
|
ApplyCombatFramePair(s.binding.leases,s.normal,s.broken);s.lastError=nil
|
|
end
|
|
s.stop=function()RestoreCombatFramePair(s.binding and s.binding.leases);if s.timer then s.timer.destroy();s.timer=nil end;PBZ_PerfectGuardWindow=nil end
|
|
s.refresh();s.timer=createTimer(nil,false);s.timer.Interval=250
|
|
s.timer.OnTimer=function()
|
|
local ok,e=pcall(s.refresh)
|
|
if not ok then
|
|
local restored,why=pcall(RestoreCombatFramePair,s.binding and s.binding.leases)
|
|
if restored then s.binding=nil end
|
|
s.lastError=tostring(e)..(restored and ''or '; '..tostring(why))
|
|
end
|
|
end
|
|
PBZ_PerfectGuardWindow=s;s.timer.Enabled=true
|
|
end
|
|
function PerfectGuardFrameValues()
|
|
local s=assert(PBZ_PerfectGuardWindow,'请先开启完美格挡窗口');return ('%d,%d'):format(s.normal,s.broken)
|
|
end
|
|
function SetPerfectGuardFrames(normal,broken)
|
|
normal=frameValue(normal);broken=frameValue(broken)
|
|
local s=assert(PBZ_PerfectGuardWindow,'请先开启完美格挡窗口');assert(s.pid==getOpenedProcessID(),'游戏进程已变化')
|
|
local c=assert(context(),'请先进入可操作的场景');local b=guardBinding(c)
|
|
assert(s.binding and valid(s.binding.object)and s.binding.object.address==b.object.address,'当前难度配置已变化,请稍后再应用')
|
|
local ok,e=pcall(ApplyCombatFramePair,s.binding.leases,normal,broken)
|
|
if not ok then s.lastError=tostring(e);error(e)end
|
|
s.normal=normal;s.broken=broken;s.lastError=nil;return true
|
|
end
|
|
function CombatParametersPreflight()
|
|
local c=assert(context(),'请先进入可操作的场景');local b=guardBinding(c)
|
|
return ('READ_ONLY_OK pid=%d combat=%s normal=%d on_break=%d shared_config=true'):format(state.pid,b.name,readInteger(b.object.address+b.leases[1].offset),readInteger(b.object.address+b.leases[2].offset))
|
|
end
|
|
local function executionBinding(c)
|
|
local attrs=q(c.pawn+offset(c.id.class,'AttributeSetBase'));local id=identity(attrs)
|
|
assert(id and fname(id.class+0x18)=='BasicAttributeSet','玩家处决属性不可用')
|
|
local outer=q(attrs+0x20);assert(ptr(outer),'处决属性归属不可用')
|
|
local leases={}
|
|
for _,name in ipairs({'ExecutionExecutorNormalHealthThreshold','ExecutionExecutorBreakHealthThreshold'})do
|
|
local p=field(id.class,name,true)
|
|
assert(p.size==16 and fname(p.type+0x18)=='GameplayAttributeData','处决阈值属性结构发生变化')
|
|
local base=assert(readFloat(attrs+p.offset+8),'处决属性基值不可读')
|
|
local current=assert(readFloat(attrs+p.offset+12),'处决属性当前值不可读')
|
|
assert(finite(base)and finite(current)and base>=0 and base<=2 and current>=0 and current<=3,'处决属性原值异常')
|
|
leases[#leases+1]={object=id,owner=outer,offset=p.offset+12,kind='float'}
|
|
end
|
|
assert(valid(c.id)and valid(id)and q(c.pawn+offset(c.id.class,'AttributeSetBase'))==attrs,'玩家处决属性已变化')
|
|
return {object=id,leases=leases,pawn=c.pawn}
|
|
end
|
|
function EnableExecutionThreshold()
|
|
assert(not PBZ_ExecutionThreshold,'处决生命阈值已经开启')
|
|
local s={pid=state.pid,normal=0,broken=0}
|
|
local function restore()
|
|
RestoreCombatFramePair(s.binding and s.binding.leases);s.binding=nil
|
|
end
|
|
s.refresh=function()
|
|
local c=context();if not c then restore();return end
|
|
local nextBinding=executionBinding(c)
|
|
if not s.binding or s.binding.pawn~=c.pawn or not valid(s.binding.object)or s.binding.object.address~=nextBinding.object.address then
|
|
restore();s.binding=nextBinding
|
|
end
|
|
ApplyExecutionThresholdPair(s.binding.leases,s.normal,s.broken);s.lastError=nil
|
|
end
|
|
s.stop=function()restore();if s.timer then s.timer.destroy();s.timer=nil end;PBZ_ExecutionThreshold=nil end
|
|
s.refresh();s.timer=createTimer(nil,false);s.timer.Interval=100
|
|
s.timer.OnTimer=function()local ok,e=pcall(s.refresh);if not ok then local restored,why=pcall(restore);s.lastError=tostring(e)..(restored and ''or '; '..tostring(why))end end
|
|
PBZ_ExecutionThreshold=s;s.timer.Enabled=true
|
|
end
|
|
function ExecutionThresholdValues()
|
|
local s=assert(PBZ_ExecutionThreshold,'请先开启处决生命阈值');return ('%.2f,%.2f'):format(s.normal,s.broken)
|
|
end
|
|
function SetExecutionThresholds(normal,broken)
|
|
normal=bonusValue(normal);broken=bonusValue(broken)
|
|
local s=assert(PBZ_ExecutionThreshold,'请先开启处决生命阈值');assert(s.pid==getOpenedProcessID(),'游戏进程已变化')
|
|
local c=assert(context(),'请先进入可操作的场景');local b=executionBinding(c)
|
|
assert(s.binding and s.binding.pawn==c.pawn and valid(s.binding.object)and s.binding.object.address==b.object.address,'玩家属性已变化,请稍后再应用')
|
|
local ok,e=pcall(ApplyExecutionThresholdPair,s.binding.leases,normal,broken)
|
|
if not ok then s.lastError=tostring(e);error(e)end
|
|
s.normal=normal;s.broken=broken;s.lastError=nil;return true
|
|
end
|
|
function ExecutionThresholdPreflight()
|
|
local c=assert(context(),'请先进入可操作的场景');local b=executionBinding(c)
|
|
return ('READ_ONLY_OK pid=%d pawn=%X attributes=%X executor_normal=%.5f executor_break=%.5f'):format(state.pid,c.pawn,b.object.address,readParameter(b.leases[1]),readParameter(b.leases[2]))
|
|
end
|
|
local function millisecondsValue(v)
|
|
assert(finite(v)and v>=50 and v<=1000,'完美闪避窗口必须在 50 到 1000 毫秒之间');return v
|
|
end
|
|
function ApplyPerfectDodgeWindow(lease,milliseconds)
|
|
assert(lease.kind=='float','闪避窗口绑定类型错误')
|
|
return applyPair({lease},{millisecondsValue(milliseconds)/1000},false)
|
|
end
|
|
local function propertyAddress(cl,name)
|
|
local classes={}
|
|
for depth=1,32 do
|
|
if not ptr(cl)or classes[cl]then break end;classes[cl]=true
|
|
local p=q(cl+0x50);local seen={}
|
|
for i=1,1024 do
|
|
if not ptr(p)or seen[p]then break end;seen[p]=true
|
|
if fname(p+0x20)==name then return p end;p=q(p+0x10)
|
|
end
|
|
cl=q(cl+0x40)
|
|
end
|
|
error('找不到属性描述符:'..name)
|
|
end
|
|
local function playerDodgeBase(c)
|
|
local asc=q(c.pawn+offset(c.id.class,'AbilitySystemComponent'));local aid=identity(asc)
|
|
assert(aid and q(asc+0x20)==c.pawn,'玩家能力组件不可用')
|
|
local container=field(aid.class,'ActivatableAbilities',true);local items=field(container.type,'Items',true)
|
|
local inner=q(propertyAddress(container.type,'Items')+0x78);local specType=ptr(inner)and q(inner+0x70)
|
|
local stride=ptr(inner)and readInteger(inner+0x34)
|
|
assert(ptr(specType)and fname(specType+0x18)=='GameplayAbilitySpec'and stride and stride>=64 and stride<=4096,'玩家能力列表结构发生变化')
|
|
local data,n=array(asc+container.offset+items.offset,1024);assert(data and n and n>0,'玩家能力列表不可用')
|
|
local abilityOffset=offset(specType,'Ability')
|
|
for i=0,n-1 do
|
|
local ability=q(data+i*stride+abilityOffset);local cl=ptr(ability)and classOf(ability);local seen={}
|
|
for depth=1,32 do
|
|
if not ptr(cl)or seen[cl]then break end;seen[cl]=true
|
|
if fname(cl+0x18)=='BP_PlayerDodge_Base_C'then
|
|
assert(valid(c.id)and valid(aid)and q(c.pawn+offset(c.id.class,'AbilitySystemComponent'))==asc,'玩家能力组件发生变化')
|
|
return cl
|
|
end
|
|
cl=q(cl+0x40)
|
|
end
|
|
end
|
|
error('当前玩家没有可识别的普通闪避能力')
|
|
end
|
|
local function dodgeEffectClass(base)
|
|
local fn=q(base+0x48);local seen={};local script
|
|
for i=1,1024 do
|
|
if not ptr(fn)or seen[fn]then break end;seen[fn]=true
|
|
if fname(fn+0x18)=='ExecuteUbergraph_BP_PlayerDodge_Base'then
|
|
local data,n=array(fn+0xB0,65536);assert(data and n and n>0,'普通闪避蓝图不可读')
|
|
script=assert(H('read',data,n),'普通闪避蓝图读取失败');break
|
|
end
|
|
fn=q(fn+0x28)
|
|
end
|
|
assert(script,'普通闪避蓝图入口缺失')
|
|
local found
|
|
for i=10,#script-8 do
|
|
if script:byte(i)==0x20 and(script:byte(i-9)==0x68 or script:byte(i-9)==0x1C or script:byte(i-9)==0x46)then
|
|
local cl=string.unpack('<i8',script,i+1);local meta=ptr(cl)and classOf(cl)
|
|
if ptr(meta)and fname(meta+0x18)=='BlueprintGeneratedClass'and fname(cl+0x18)=='GE_PerfectDash_C'then
|
|
local call=string.unpack('<i8',script,i-8)
|
|
assert(ptr(call)and fname(call+0x18)=='BP_ApplyGameplayEffectToOwner','完美闪避效果调用结构发生变化')
|
|
assert(not found or found==cl,'完美闪避效果存在歧义');found=cl
|
|
end
|
|
end
|
|
end
|
|
return assert(found,'找不到普通闪避实际使用的完美判定效果')
|
|
end
|
|
local function dodgeBinding(c)
|
|
local cl=dodgeEffectClass(playerDodgeBase(c))
|
|
-- UClass.ClassDefaultObject +0x160 is verified for the supported executable.
|
|
local object=q(cl+0x160);local id=identity(object)
|
|
assert(id and id.class==cl and fname(object+0x18)=='Default__GE_PerfectDash_C','完美闪避默认效果身份不匹配')
|
|
local owner=q(object+0x20);assert(ptr(owner),'完美闪避效果归属不可用')
|
|
local policy=field(cl,'DurationPolicy',true);assert(policy.size==1 and readBytes(object+policy.offset,1)==2,'完美闪避效果不是有限时长')
|
|
local duration=field(cl,'DurationMagnitude',true);assert(duration.size==480 and ptr(duration.type),'完美闪避时长结构发生变化')
|
|
local calc=field(duration.type,'MagnitudeCalculationType',true)
|
|
assert(calc.size==1 and readBytes(object+duration.offset+calc.offset,1)==0,'完美闪避时长不再是固定数值')
|
|
local scalable=field(duration.type,'ScalableFloatMagnitude',true);assert(scalable.size==40,'闪避时长数值结构发生变化')
|
|
local value=field(scalable.type,'Value',true);assert(value.size==4,'闪避时长精度发生变化')
|
|
local curve=field(scalable.type,'Curve',true);local registry=field(scalable.type,'RegistryType',true)
|
|
local at=object+duration.offset+scalable.offset
|
|
assert(q(at+curve.offset)==0 and q(at+curve.offset+8)==0 and q(at+registry.offset)==0,'闪避时长使用动态曲线,已拒绝覆盖')
|
|
local current=assert(readFloat(at+value.offset),'完美闪避窗口不可读')
|
|
assert(finite(current)and current>=0.01 and current<=2,'完美闪避窗口原值异常')
|
|
assert(valid(c.id)and valid(id)and q(cl+0x160)==object,'闪避效果对象发生变化')
|
|
return {object=id,pawn=c.pawn,leases={{object=id,owner=owner,offset=duration.offset+scalable.offset+value.offset,kind='float'}}}
|
|
end
|
|
function EnablePerfectDodgeWindow()
|
|
assert(not PBZ_PerfectDodgeWindow,'完美闪避窗口已经开启')
|
|
local s={pid=state.pid}
|
|
local function restore()RestoreCombatFramePair(s.binding and s.binding.leases);s.binding=nil end
|
|
s.refresh=function()
|
|
local c=context();if not c then restore();return end
|
|
if not s.binding or s.binding.pawn~=c.pawn or not frameLeaseValid(s.binding.leases[1])then restore();s.binding=dodgeBinding(c)end
|
|
if not s.milliseconds then s.milliseconds=readParameter(s.binding.leases[1])*1000 end
|
|
ApplyPerfectDodgeWindow(s.binding.leases[1],s.milliseconds);s.lastError=nil
|
|
end
|
|
s.stop=function()restore();if s.timer then s.timer.destroy();s.timer=nil end;PBZ_PerfectDodgeWindow=nil end
|
|
s.refresh();s.timer=createTimer(nil,false);s.timer.Interval=250
|
|
s.timer.OnTimer=function()local ok,e=pcall(s.refresh);if not ok then local restored,why=pcall(restore);s.lastError=tostring(e)..(restored and ''or '; '..tostring(why))end end
|
|
PBZ_PerfectDodgeWindow=s;s.timer.Enabled=true
|
|
end
|
|
function PerfectDodgeMilliseconds()
|
|
local s=assert(PBZ_PerfectDodgeWindow,'请先开启完美闪避窗口');return ('%.2f'):format(s.milliseconds)
|
|
end
|
|
function SetPerfectDodgeMilliseconds(value)
|
|
value=millisecondsValue(value);local s=assert(PBZ_PerfectDodgeWindow,'请先开启完美闪避窗口')
|
|
assert(s.pid==getOpenedProcessID(),'游戏进程已变化');local c=assert(context(),'请先进入可操作的场景')
|
|
assert(s.binding and s.binding.pawn==c.pawn and frameLeaseValid(s.binding.leases[1]),'当前角色或效果身份已变化,请稍后再应用')
|
|
local ok,e=pcall(ApplyPerfectDodgeWindow,s.binding.leases[1],value)
|
|
if not ok then s.lastError=tostring(e);error(e)end
|
|
s.milliseconds=value;s.lastError=nil;return true
|
|
end
|
|
function PerfectDodgePreflight()
|
|
local c=assert(context(),'请先进入可操作的场景');local b=dodgeBinding(c)
|
|
return ('READ_ONLY_OK pid=%d pawn=%X effect=%X perfect_dodge_ms=%.3f shared_default=true'):format(state.pid,c.pawn,b.object.address,readParameter(b.leases[1])*1000)
|
|
end
|