I'm thinking that if you've failed a driveshaft joint then this will cause the engine to race away and its only moving foward by virtue of the 4wd system tying itself in knots
Its very easy to check a joint as if you lift the bonnet and look at the shaft whilst your assistant gently pulls away you should see if both shafts are turning at the same speed
If it was just engine related then it could be an airleak after the airflow meter, any air dragged in here isn't 'seen' by the ECU and so not compensated for and can lean the engine out and can also allow the engine to rev up when not desired causing rough running.
As its a mechanical fault it tends not to turn on the fault light and you can sometime hear a 'hissing' noise with the engine running.
Check the hose clips for tightness and inspect the trunking for any cracks or splits and also all the vacuum system, the small bore pipes and fittings for cracks and missing parts.
The best way to locate a leak is to have the engine running and warm and then spray lighter gas /propane around each joint in turn. If the engine rev's up you've found your leak.
Work your way through each possible joint one at a time and you should find it. I use a slightly flattened piece of brake pipe and some rubber hose from the can of lighter gas to provide a spraying 'wand' and allow a direct blast of gas into each area, especially those difficult to reach with large implements.
Might also be worth checking the wiring and connector to the airflow meter for any signs of corrosion or damage. you can do a quick fault find if you unplug the meter and run the engine without it.
if the engine condition is the same then chances are the meter or the connection to it is faulty
Air leaks are very temperature dependent as gaps can open or close up as things expand with heat, so they can be effected by the weather and engine temperature.
This leads them to be quite intermittent in the case of mild leaks
its also worth cleaning the airflow meter by removing it from the car and spraying the exposed sensor wires inside the tube with a brake or switch cleaner - ensure that the cleaner is one of the old fashioned, non Eco type that does not leave a residue
On no account touch the sensor wires with anything physical as they are extremely fragile
if the garage is only 3km away then I'd suggest having your friend tow it over there rather than try and limp it over there as you may do more damage
So try check joints as I've mentioned 1st and let me know