Files
GaCy-GO/tools/damage_active_stat_field_probe.lua

60 lines
2.8 KiB
Lua

-- At most 16 metadata fields and 32 empty component slots per rendered frame.
-- Scope is the two native level entities in the active battle world.
do
local s=_G.__gacDamageStatField1 or {entity=0,component=0,field=0};_G.__gacDamageStatField1=s
local function log(v)CS.UnityEngine.Debug.Log('[GAC_DAMAGE_STAT_FIELD] '..tostring(v))end
local function step()
if s.done or s.frame==CS.UnityEngine.Time.frameCount then return end
s.frame=CS.UnityEngine.Time.frameCount
local ok,err=pcall(function()
local flags=CS.System.Enum.ToObject(typeof(CS.System.Reflection.BindingFlags),60)
if not s.entities then
local pm=CS.RPG.Client.GlobalVars.s_GamePhaseManager
local phase=typeof(CS.RPG.Client.GamePhaseManager):GetField('_CurrentPhase',flags):GetValue(pm)
if not typeof(CS.RPG.Client.BattleGamePhase):IsInstanceOfType(phase)then return end
local instance=phase.BattleInstanceRef;if not instance then return end
local world=instance:GetType():GetField('_GameWorld',flags):GetValue(instance)
s.entities=world:GetType():GetField('_EntityList',flags):GetValue(world)
end
if not s.components then
for i=s.entity,math.min(s.entity+15,s.entities.Count-1)do
local e=s.entities[i];s.entity=i+1
if e and (e.RuntimeID==CS.RPG.GameCore.GameWorld.CommonLevelEntityRuntimeID or e.RuntimeID==CS.RPG.GameCore.GameWorld.BattleLevelEntityRuntimeID)then
s.components=e:GetType():GetField('_ComponentArray',flags):GetValue(e);s.component=0;log('ENTITY '..e.RuntimeID);return
end
end
if s.entity>=s.entities.Count then s.done=true;log('END_NO_FIELD')end
elseif not s.fields then
for i=s.component,math.min(s.component+31,s.components.Length-1)do
s.component=i+1
local c=s.components[i]
if c then s.owner=c;s.ownerIndex=i;s.fields=c:GetType():GetFields(flags);s.field=0;return end
end
if s.component>=s.components.Length then s.components=nil end
else
for i=s.field,math.min(s.field+15,s.fields.Length-1)do
local f=s.fields[i]
if tostring(f.FieldType.FullName)=='RPG.GameCore.PVEGameStatistics'then
local value=f:GetValue(s.owner)
log('FOUND '..s.ownerIndex..' '..tostring(s.owner:GetType())..' '..f.Name..' '..tostring(value))
s.stats=value;s.done=true;return
end
end
s.field=s.field+16;if s.field>=s.fields.Length then s.fields=nil end
end
end)
if not ok then s.done=true;log('ERROR '..tostring(err))end
end
s.step=step
if not s.registered then
local function tick()if s.step then s.step()end end
local ok=pcall(function()CS.UnityEngine.Camera.onPostRender('+',tick)end)
s.registered=ok
end
if not s.applicationHooked then
local function tick()if s.step then s.step()end end
s.applicationHooked=pcall(function()CS.UnityEngine.Application.onBeforeRender('+',tick)end)
end
step()
end