Factor out determine_source function.
Make interface to determine_source more general, so that it can be used without an rdata.
Add DialogTracker class.