Scripts/Misc: Fix static analysis issues

Replace CAST_AI() macro with ENSURE_AI() when dynamic_cast is not supposed to return NULL.