More generally, any low-difficulty, low-stressful task or source of enjoyment is probably a cure for most homeless people. Especially if you give them a shelter and food and access to shower and safety other stuff you don’t get being homeless.
Homelessness and drug-addiction are a vicious cycle. Imagine yourself, but homeless on the streets, dirty and with a headache. Would you be able to sober up, re-learn software engineering or some other trade on your own, and re-aquire a living space and job? Maybe, but it would be incredibly tough and would take at least a few months. Meanwhile you have to find food, avoid the elements, avoid thieves and police. find spaces to clean, spaces to sleep. And also whatever job you take, you have to compete with people who aren’t homeless and don’t have to do those things. And this is ignoring the temptation and withdrawals from drugs.
But let’s say someone gives you a basic job and basic necessities. Now it’s a lot easier to get back on your feet, because you only have to deal with the drug withdrawals. The work also helps serve as a distraction and alternate source of happiness, which is extremely important.
You gave these people a clear and reasonable way to succeed and enjoy life without drugs, effectively breaking the cycle.