fix: diagnostics write to mods/AutoMark/diag_log.txt — printf is not a Lua sandbox global (nil call crashed the hook every tick once debug_mode was on) and DMF :info spams notifications; pcall-guarded mod:diag via Mods.lua.io
This commit is contained in:
@@ -245,9 +245,9 @@ local function find_hackable_target_unit_omni()
|
||||
end
|
||||
parts[#parts + 1] = tostring(k) .. "=" .. vs
|
||||
end
|
||||
printf("[MOD][AutoMark][DIAG] %s", "OMNI-HACK-DIAG template: " .. table.concat(parts, " "))
|
||||
mod:diag("OMNI-HACK-DIAG template: " .. table.concat(parts, " "))
|
||||
else
|
||||
printf("[MOD][AutoMark][DIAG] %s", "OMNI-HACK-DIAG template missing: " .. tostring(tpl))
|
||||
mod:diag("OMNI-HACK-DIAG template missing: " .. tostring(tpl))
|
||||
end
|
||||
else
|
||||
local keys = {}
|
||||
@@ -255,7 +255,7 @@ local function find_hackable_target_unit_omni()
|
||||
keys[#keys + 1] = tostring(k)
|
||||
end
|
||||
table.sort(keys)
|
||||
printf("[MOD][AutoMark][DIAG] %s", "OMNI-HACK-DIAG no templates table, system keys: " .. table.concat(keys, ","))
|
||||
mod:diag("OMNI-HACK-DIAG no templates table, system keys: " .. table.concat(keys, ","))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -285,7 +285,7 @@ local function find_hackable_target_unit_omni()
|
||||
if diag_total then
|
||||
mod.omni_hack_diag_counter = (mod.omni_hack_diag_counter or 0) + 1
|
||||
if mod.omni_hack_diag_counter % 10 == 1 then
|
||||
printf("[MOD][AutoMark][DIAG] %s", string.format("OMNI-HACK-DIAG breed_units=%d hackable=%d selected=%s dist=%s", diag_total, diag_hackable, tostring(selected_unit), tostring(selected_distance)))
|
||||
mod:diag(string.format("OMNI-HACK-DIAG breed_units=%d hackable=%d selected=%s dist=%s", diag_total, diag_hackable, tostring(selected_unit), tostring(selected_distance)))
|
||||
end
|
||||
end
|
||||
return selected_unit, selected_distance
|
||||
|
||||
@@ -588,7 +588,7 @@ function mod:find_auto_mark_target_unit(min_range, max_range, tag_name, tag_cont
|
||||
local omni_mark = mod_settings.omni_mark
|
||||
if mod_settings.debug_mode and not mod.omni_diag_settings_logged then
|
||||
mod.omni_diag_settings_logged = true
|
||||
printf("[MOD][AutoMark][DIAG] %s", string.format("OMNI-DIAG settings: omni_mark=%s ignore_los=%s debug=%s", tostring(omni_mark), tostring(mod_settings.omni_mark_ignore_los), tostring(mod_settings.debug_mode)))
|
||||
mod:diag(string.format("OMNI-DIAG settings: omni_mark=%s ignore_los=%s debug=%s", tostring(omni_mark), tostring(mod_settings.omni_mark_ignore_los), tostring(mod_settings.debug_mode)))
|
||||
end
|
||||
local ray_origin, forward, right, up = smart_targeting_extension:_targeting_parameters()
|
||||
local hits, num_hits, hits_are_units
|
||||
@@ -628,7 +628,7 @@ function mod:find_auto_mark_target_unit(min_range, max_range, tag_name, tag_cont
|
||||
for _, n in ipairs(ordered_names) do
|
||||
name_parts[#name_parts + 1] = n .. "x" .. counts[n]
|
||||
end
|
||||
printf("[MOD][AutoMark][DIAG] %s", string.format("OMNI-DIAG candidates=%d breeds=[%s]", num_hits, table.concat(name_parts, ",")))
|
||||
mod:diag(string.format("OMNI-DIAG candidates=%d breeds=[%s]", num_hits, table.concat(name_parts, ",")))
|
||||
end
|
||||
else
|
||||
hits, num_hits = PhysicsWorld_raycast(smart_targeting_extension._physics_world, ray_origin, forward, max_range, "all", "collision_filter", COLLISION_FILTER)
|
||||
@@ -849,7 +849,7 @@ function mod:find_auto_mark_target_unit(min_range, max_range, tag_name, tag_cont
|
||||
parts[#parts + 1] = k .. "=" .. v
|
||||
end
|
||||
table.sort(parts)
|
||||
printf("[MOD][AutoMark][DIAG] %s", string.format("OMNI-DIAG pass[%s] best=%s rejects=[%s]", tostring(tag_name), tostring(best_unit_breed_name), table.concat(parts, ",")))
|
||||
mod:diag(string.format("OMNI-DIAG pass[%s] best=%s rejects=[%s]", tostring(tag_name), tostring(best_unit_breed_name), table.concat(parts, ",")))
|
||||
omni_rejects = nil
|
||||
end
|
||||
|
||||
|
||||
@@ -91,3 +91,23 @@ local ok, err = pcall(mod.dump_breeds, mod)
|
||||
if not ok then
|
||||
mod:print_debug("breed dump error:", tostring(err))
|
||||
end
|
||||
|
||||
-- debug-mode diagnostics: DMF mod:info also pushes on-screen notifications and the
|
||||
-- sandbox has no printf, so append to a plain text file instead (Mods.lua.io again).
|
||||
-- never call unguarded: mod:diag swallows its own failures.
|
||||
function mod:diag(...)
|
||||
local args = { ... }
|
||||
local ok_diag, err_diag = pcall(function()
|
||||
local file = Mods.lua.io.open("./../mods/AutoMark/diag_log.txt", "a")
|
||||
if file then
|
||||
for i = 1, #args do
|
||||
args[i] = tostring(args[i])
|
||||
end
|
||||
file:write(table.concat(args, " ") .. "\n")
|
||||
file:close()
|
||||
end
|
||||
end)
|
||||
if not ok_diag then
|
||||
mod:print_debug("diag error:", tostring(err_diag))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user