shadows: add safemode value & fix -1 force off
Lua: remove some duplicated code