There's a method, very simple in essence. It's a method of elimination. I know how many heroes there are in total. I know how many computer-controlled opponents are on the map. I subtract twice the second number from the first. Then I start digging up all possible heroes. As soon as their number equals the calculated value, I stop and look at the heroes that haven't been dug up. They are the ones sitting in the taverns of the computer-controlled opponents. The process is quite laborious, but it doesn't involve directly accessing the save file. Although, of course, that would be much easier.
1. The number of heroes in the opponent's taverns doesn't always depend only on the number of computer-controlled opponents.
2. There are also hired heroes. They need to be taken into account.
3. If you dig in the left slot of the tavern, you will never dig up a hero of the same class as the one in the right slot.