The referee does the replacement in the same way every official has ever made a decision before TV replays regardless of the sport. They use their memory and their knowledge and the game-specific techniques they are trained in.
The snooker referee is only required to replace "the ones that matter". Obviously the cue ball counts, and any object balls that were close to its intended path or that have moved into an advantageous position as a result of the foul. A good referee notes in their mind the placement of the cue ball relative to landmarks on the table or in the venue, and where key object balls were placed relatively to the cue ball and similar landmarks.
Having made the replacement, they ask players if the arrangement is correct, and players may indicate (but not move) balls that need further correction. The referee holds the final decision in the case that players disagree with each other or with the referee.
Without a referee, of course, it is upto players to determine together where the balls should be placed, and local rules or specific competitions will have a method of resolving disagreement.