Files
GaCy-GO/tools/cw_monster_camp_export.lua

44 lines
2.0 KiB
Lua

-- Existing CW handbook monster configurations only, two rows per heartbeat.
-- No battle/level/graph loader, player object, or scene change is invoked.
do
_G.__gacCwCampExport1=_G.__gacCwCampExport1 or {index=0}
local s=_G.__gacCwCampExport1
if s.done then return end
local flags=CS.System.Enum.ToObject(typeof(CS.System.Reflection.BindingFlags),60)
local manager=CS.RPG.Client.GlobalVars.s_GamePhaseManager
local phase=manager and typeof(CS.RPG.Client.GamePhaseManager):GetField('_CurrentPhase',flags):GetValue(manager)
if not phase or typeof(CS.RPG.Client.BattleGamePhase):IsInstanceOfType(phase)then return end
local log=function(v)CS.UnityEngine.Debug.Log('[GAC_CW_MONSTER_CAMP] '..tostring(v))end
local good,err=pcall(function()
if not s.rows then
s.rows=CS.RPG.Client.GlobalVars.s_ModuleManager.GridFightModule:GetAllMonsterCampData()
if s.rows.Count>2048 then error('Monster camp count exceeds capture bound')end
s.expected=s.rows.Count
log('BEGIN count='..s.expected)
if s.expected>0 then
local t=s.rows[0]:GetType()
s.fields=t:GetFields(flags)
log('TYPE '..t.FullName)
for i=0,math.min(s.fields.Length-1,63)do log('FIELD '..tostring(s.fields[i]))end
end
end
for batch=1,2 do
if s.index>=s.expected then s.done=true;s.rows=nil;s.fields=nil;log('END');return end
local object=s.rows[s.index]
local pieces={}
for i=0,math.min(s.fields.Length-1,63)do
local f=s.fields[i]
if not f.IsStatic and (f.FieldType.IsPrimitive or f.FieldType.IsEnum or f.FieldType==typeof(CS.System.String) or f.FieldType.FullName:find('RPG.GameCore.',1,true)==1)then
local value=f:GetValue(object)
pieces[#pieces+1]=CS.Newtonsoft.Json.JsonConvert.SerializeObject(f.Name)..':'..CS.Newtonsoft.Json.JsonConvert.SerializeObject(value)
end
end
local text='{'..table.concat(pieces,',')..'}'
if #text>65536 then error('Monster camp row exceeds capture bound')end
log('ROW '..text)
s.index=s.index+1
end
end)
if not good then s.done=true;s.rows=nil;s.fields=nil;log('ERROR '..tostring(err))end
end