Publish original trainer v0.1.19.12

This commit is contained in:
111Xinghen-Star111 committed 2026-11-28 15:03:14 +08:00
1 parent 1f6b5cf178
commit f47cd6d1fa
82 files changed
+15911

No files matched your search

+260
View File
@@ -0,0 +1,260 @@
-- Calls the registered native boolean setter on the game thread.
local damageOwner='damage_numbers'
local function booleanValue(value)
assert(value==0 or value==1,'伤害飘字开关必须是 0 或 1');return value
end
function DamageNumberSwitchWrites(object,value)
value=booleanValue(value)
assert(type(object)=='number'and object>=0x10000 and object<0x7FFFFFFFFFFF,'伤害飘字开关地址无效')
return {{0,object},{16,0x30+value}}
end
function CreateDamageNumberSession(binding,send)
local s={phase='idle',pending=false,generation=0}
local function read()
assert(binding.valid(),'伤害飘字原生开关身份已变化')
local value=assert(binding.read(),'伤害飘字状态不可读,保留恢复信息');return booleanValue(value)
end
local function request(value,kind)
assert(not s.pending,'伤害飘字的游戏线程请求仍在执行')
s.generation=s.generation+1;local generation=s.generation
s.pending=true;s.phase=kind=='enable'and 'enabling'or 'restoring';s.lastError=nil
local ok,e=pcall(send,value,function(success,why)
if not s.pending or generation~=s.generation then return end
s.pending=false
if not success then s.phase='error';s.lastError=why or '游戏拒绝了伤害飘字命令';return end
-- A completed engine command may already have changed the value even if the
-- readback fails. Keep ownership information so disabling can retry safely.
s.lastWritten=value
local verified,problem=pcall(function()assert(read()==value,'游戏没有接受伤害飘字开关,请关闭后重试')end)
if not verified then s.phase='error';s.lastError=tostring(problem);return end
s.phase=kind=='enable'and 'active'or 'restored';s.lastError=nil
if kind=='restore'then s.lastWritten=nil end
end)
if not ok then s.pending=false;s.phase='error';s.lastError=tostring(e);error(e)end
end
s.start=function()
assert(s.phase=='idle','伤害飘字会话已经启动');s.original=read()
if s.original==1 then s.phase='active'else request(1,'enable')end
end
s.observe=function()
if s.phase=='active'and not s.pending and read()~=1 then
s.phase='error';s.lastError='伤害飘字开关已被游戏或其他工具更改,请关闭后重试'
end
end
s.restore=function()
assert(not s.pending,'伤害飘字的游戏线程请求仍在执行')
if s.phase=='restored'then return end
if s.phase=='idle'or s.lastWritten==nil or not binding.valid()then s.phase='restored';s.lastError=nil;return end
if read()~=s.lastWritten then s.phase='restored';s.lastError=nil;return end
request(s.original,'restore')
end
return s
end
-- Exact constructor bytes are tied to GameMemory.SupportedHash. RIP decoding
-- handles ASLR; the target name and all live pointer identities are rechecked.
local registration='48 83 EC 38 4C 8D 0D 95 78 56 0B C6 44 24 40 00 4C 8D 44 24 40 C7 44 24 20 00 00 00 00 48 8D 15 54 79 56 0B 48 8D 0D A5 16 ED 0C E8 E0 37 0A 00'
function FindNativeDamageNumberSwitch(util)
local ref=util.uniqueScan(registration)
local name=ref+36+assert(readInteger(ref+32,true),'伤害飘字开关名称不可读')
assert(util.exactString(name,24,true)=='pbz.DamageNumber.Enabled','伤害飘字开关名称不匹配')
local root=ref+43+assert(readInteger(ref+39,true),'伤害飘字注册位置不可读')
local base=getAddress('PBZ.exe');local limit=base+getModuleSize('PBZ.exe')
local function image(p)return util.ptr(p)and p>=base and p<limit end
assert(root>=base and root+24<=limit,'伤害飘字注册位置不在游戏模块内')
local vt=util.q(root);local object=util.q(root+8);local data=util.q(root+16)
assert(image(vt)and util.ptr(object)and util.ptr(data),'伤害飘字原生开关尚未初始化')
local objectVtable=util.q(object)
assert(root==base+0xE0CDEA0 and objectVtable==base+0xA6C61A8 and data==object+0x50 and util.q(objectVtable+0xB0)==base+0x12C0BF0,'伤害飘字原生对象结构发生变化')
local setter=base+0x12C0BF0
assert(H('read',setter,5)==string.char(0xE9,0x5B,0x50,0x6A,0x0E) and
H('read',base+0xF965C50,31)==string.char(0x48,0x89,0x6C,0x24,0x10,0x48,0x89,0x74,0x24,0x18,0x57,0x48,0x83,0xEC,0x20,0x4D,0x8B,0x48,0x04,0x4C,0x89,0xC6,0x45,0x8B,0x00,0x48,0x89,0xD5,0x48,0x89,0xCF),
'伤害飘字原生设置入口已变化')
local b={pid=getOpenedProcessID(),object=object}
b.valid=function()
if b.pid~=getOpenedProcessID()then return false end
local currentVt=util.q(root);local currentObject=util.q(root+8);local currentData=util.q(root+16)
assert(currentVt~=nil and currentObject~=nil and currentData~=nil,'伤害飘字对象不可读,保留恢复信息')
if currentVt~=vt or currentObject~=object or currentData~=data then return false end
local currentObjectVt=util.q(object);assert(currentObjectVt~=nil,'伤害飘字对象身份不可读,保留恢复信息')
return currentObjectVt==objectVtable and util.q(objectVtable+0xB0)==setter
end
b.read=function()return readBytes(data,1)end
booleanValue(b.read());return b
end
function PreflightNativeDamageNumbers(util)
local binding=FindNativeDamageNumberSwitch(util)
return ('READ_ONLY_OK pid=%d native_damage_numbers=%d'):format(binding.pid,booleanValue(binding.read()))
end
function ProtectDamageNumberDispatcher(d,worldSlot)
if d.safeRequests then return end
local originalPump=assert(d.pump,'游戏线程调度器缺少 pump')
local function writeID(at,id)
assert(writeQword(at,id.address));assert(writeQword(at+8,id.class));assert(writeQword(at+16,id.name));assert(writeInteger(at+24,id.index))
end
d.pump=function()
if d.closing or d.pid~=getOpenedProcessID()then return originalPump()end
assert(not FeatureTransactionActive(),'请等待游戏线程请求完成后重试关闭;功能事务不会执行或确认原生命令')
local m=getAddressSafe('PBZ_UT_Mailbox');if not m then return end
assert(readQword(m+8)==d.pid,'Utility mailbox PID mismatch')
local status=assert(readInteger(m),'游戏线程邮箱状态不可读')
if d.current then
if status==1 or status==2 then return end
local r=d.current
if status==3 or status==4 then r.engineStatus=status end
local completedStatus=r.engineStatus or status
local result
if completedStatus==3 then
if r.resultKind=='bool'then result=readBytes(m+0x80+r.resultOffset,1)else result=readQword(m+0x80+r.resultOffset)end
end
if completedStatus==3 and r.capture and not r.captured then r.payload=r.capture(m);r.captured=true end
-- Hold the request until acknowledgement succeeds. If the write committed
-- before throwing, engineStatus preserves the successful native result.
assert(writeInteger(m,0));d.current=nil
r.done=true;r.success=completedStatus==3;r.result=result
if r.callback then r.callback(r)end
elseif status~=0 then error('Utility mailbox has an unowned request')end
if #d.queue==0 then return end
local r=d.queue[1]
assert(not r.nativeEspProjection or d.nativeEspProjectionVersion==1,'ESP原生投影接口未安装');
assert(not r.nativeAccessory or d.nativeAccessoryVersion==1,'饰品原生接口未安装');
assert(not r.nativeDamageSwitch or d.nativeDamageSwitchVersion==1,'原生伤害飘字设置接口尚未安装')
assert(not r.nativeDamageInitialize or d.nativeDamageInitializationVersion==1,'原生伤害数字初始化接口尚未安装');
assert(not r.nativeDamageDemo or d.nativeDamageDemoVersion==1,'原生渲染桥接尚未安装,拒绝作为普通反射命令执行')
if readQword(worldSlot)~=r.world or not d.valid(r.pcID)or not d.valid(r.receiver)or not d.valid(r.fn)or not d.valid(r.extra)or(r.validate and not r.validate())then
table.remove(d.queue,1);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.nativeDamageSwitch and 256 or r.nativeEspProjection and 128 or r.nativeAccessory and 64 or r.nativeDamageInitialize and 32 or r.nativeDamageDemo and 8 or 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
local size=w[3]=='byte'and 1 or 8;assert(w[1]>=0 and w[1]+size<=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
-- Parameters remain queued on failure; publication transfers ownership to
-- current before the game can consume them, including post-write exceptions.
d.current=r;table.remove(d.queue,1);assert(writeInteger(m,1))
end
d.safeRequests=true
end
function StartNativeDamageNumbers(util)
assert(not PBZ_DamageNumbers,'伤害飘字已经开启')
local binding=FindNativeDamageNumberSwitch(util)
local objects=util.objectInventory({KismetSystemLibrary='Class'})
local target=util.staticTarget(objects.KismetSystemLibrary,'ExecuteConsoleCommand',{
WorldContextObject={0,8},Command={8,16},SpecificPlayer={24,8}})
local dispatcher,assembly=util.acquireDispatch(damageOwner)
ProtectDamageNumberDispatcher(dispatcher,util.worldSlot)
local s={pid=getOpenedProcessID(),dispatcher=dispatcher,stopping=false,consoleTarget=target}
local session=CreateDamageNumberSession(binding,function(value,done)
local c=assert(util.context(),'请先进入可操作的游戏场景')
local pcID=assert(util.identity(c.pc),'玩家控制器不可用')
local request={owner=damageOwner,world=c.world,pcID=pcID,receiver=target.receiver,fn=target.fn,
extra=pcID,nativeDamageSwitch=true,currentPawnOnly=false,resultKind='object',resultOffset=0,
validate=binding.valid,writes=DamageNumberSwitchWrites(binding.object,value)}
request.callback=function(result)done(result.success,result.error)end
dispatcher.enqueue(request)
end)
s.session=session
s.tick=function()
if s.stopping then return end
if session.phase=='idle'then
if not getAddressSafe('PBZ_UT_Mailbox')then return end
dispatcher.validateHooks();session.start()
else session.observe()end
s.lastError=session.lastError
end
s.prepareStop=function()
s.stopping=true
if session.phase=='restored'and not session.pending then s.lastError=nil;return end
if s.pid==getOpenedProcessID()then
dispatcher.drain(damageOwner);session.restore();dispatcher.drain(damageOwner)
assert(not session.pending and session.phase=='restored',session.lastError or '伤害飘字原状态尚未恢复,请重试关闭')
end
s.lastError=nil
end
s.stop=function()
assert(s.pid~=getOpenedProcessID()or(not session.pending and session.phase=='restored'),'请先完成伤害飘字的游戏线程恢复')
local restore=dispatcher.release(damageOwner)
if s.timer then s.timer.destroy();s.timer=nil end
if PBZ_DamageNumbers==s then PBZ_DamageNumbers=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_DamageNumbers=s;s.timer.Enabled=true
return assembly
end
function PrepareNativeDamageNumberDisable()
local s=PBZ_DamageNumbers;if not s then return end
local ok,e=pcall(s.prepareStop)
if not ok then s.lastError=tostring(e);error(e)end
end
-- Initialize the native container without emitting a fabricated damage event.
function NativeDamageNumberInitializationEntry()
local native=getAddress('PBZ.exe')+0x7e461c0
local expected={0x40,0x57,0x48,0x83,0xEC,0x20,0x48,0x83,0xB9,0xB0,0,0,0,0,0x48,0x8B,0xF9}
local b=readBytes(native,#expected,true)
assert(b and table.concat(b,',')==table.concat(expected,','),'原生伤害数字初始化入口与支持版本不符')
return native
end
function StartInitializedNativeDamageNumbers(u)
NativeDamageNumberInitializationEntry()
local assembly=StartNativeDamageNumbers(u);local s=assert(PBZ_DamageNumbers)
assert(s.dispatcher.nativeDamageInitializationVersion==1,'共享调度器尚未支持伤害数字初始化')
s.initialization=CreateDamageNumberInitialization(u,s)
local originalTick=s.tick
s.tick=function()
originalTick();if s.stopping or s.session.phase~='active'then return end
s.initialization.tick();if s.initialization.error then s.lastError=s.initialization.error end
end
return assembly
end
function CreateDamageNumberInitialization(u,s)
local t={pending=false,completed=0}
t.tick=function()
if t.pending or t.error then return end
local c=u.context();if not c then t.world=nil;t.subsystem=nil;return end
if t.world==c.world and t.subsystem and u.valid(t.subsystem)and t.container and u.valid(t.container)and u.q(t.subsystem.address+0xB0)==t.container.address then return end
local data=u.q(c.world+0x9E0);local n=readInteger(c.world+0x9E8)
assert(u.ptr(data)and n and n>0 and n<2048,'当前场景伤害子系统映射不可读')
local sys
for i=0,n-1 do
local a=u.q(data+i*24+8);local cl=u.ptr(a)and u.classOf(a)
if u.ptr(cl)and u.fname(cl+0x18)=='PBZDamageNumberSubsystem'and u.q(a+0x20)==c.world then assert(not sys,'当前场景伤害子系统不唯一');sys=u.identity(a)end
end
assert(sys and u.valid(sys),'当前场景伤害子系统不可用')
local world=c.world
local r={nativeDamageInitialize=true,owner='damage_numbers',world=world,pcID=u.identity(c.pc),receiver=sys,fn=s.consoleTarget.fn,extra=u.identity(c.pawn),currentPawnOnly=false,resultKind='object',resultOffset=0,writes={}}
t.pending=true
r.callback=function(result)
t.pending=false
if s.stopping then return end
local now=u.context();if not now or now.world~=world or now.pc~=c.pc or now.pawn~=c.pawn then return end
if not result.success then t.error=result.error or '游戏拒绝初始化伤害数字界面';return end
if not u.valid(sys)or u.q(sys.address+0x20)~=world then return end
local container=u.q(sys.address+0xB0);local id=u.identity(container)
if not id or not u.valid(id)then t.error='游戏未能创建伤害数字界面';return end
t.world=world;t.subsystem=sys;t.container=id;t.completed=t.completed+1
end
s.dispatcher.enqueue(r)
end
return t
end
function PrepareSharedUtilityDisable(id)
local s=id==1337142254 and PBZ_StealthMode or PBZ_SaveMenuAnywhere
if s and s.prepareStop then s.prepareStop()end
end
function PrepareSharedUtilityEnable()
local d=PBZ_UtilityDispatch
if d and d.closing then
assert(not FeatureTransactionActive(),'共享功能收尾应在开启事务前执行')
d.pump()
assert(PBZ_UtilityDispatch~=d,'上一功能尚未恢复完成,请稍后重试')
end
end