Yes, the Rangers all used the same 3.0l Vulcan engine 1991 to 2008
Only difference was in the upper intakes and oil pans(2wd or 4x4)
2002 and 2005 should be a direct swap if they are both VIN U(gasoline only) or both VIN V(Flex fuel)
And the only difference that matters is the injector size, which needs to match 2005 computer
So easy enough to swap out injectors to match computer
Things you want to change while 3.0l Vulcan is out
Rear main seal
Front timing chain cover gasket and oil pan gasket, BOTH can(will) leak and are a real pain to change in the vehicle
Oil pump is a judgement call, and not an expensive part for what it does
Ford can make changes to connectors and fuel lines from year to year, these are not listed anywhere but in a EVTM or Shop manual from each year
So its always best guess that every engine connection is EXACTLY the same when swapping between years
Ford even makes changes MID-year, so even same year can have a difference
So don't get rid of the original engine until "new" engine is in and running, may need a sensor or connector
And once its in and running, pull off the old sensors and parts to have as spares