I was wondering how a Starship or Falcon-9 booster could land on an uneven surface, like that of the Moon or Mars. Is the landing gear similar to the Boeing hydraulic landing gear, which cushions and converts the kinetic energy into heat? Without GPS system, how can it accurately land on a pre-planned site.
There are two possible answers to this, although you probably won't like either of them.
Answer 1: They don't. Falcon 9 only lands on prepared landing sites and Starship doesn't exist yet.
Answer 2: We don't know. Falcon 9 will never land on non-prepared landing sites and Starship iterates so fast that it is impossible to predict what it will look like in 4 years. In every presentation that Elon Musk has done so far, Starship had different landing legs. Every Starship that has flown so far (Starhopper, SN5, and SN6) had different landing legs (and neither of the three had landing legs that matched any of the presentations, although Hopper was at least somewhat close), and Elon Musk has just tweeted last week, that they will be completely changing them again.
Falcon 9 likely could land on a somewhat uneven surface because its leg-base is rather wide and the legs contain one-time-use crush-able aluminum honeycomb impact absorbers. Still, this surface would need to be rather hard and flat to avoid being excavated by the landing engine's exhaust plume and the massive weight of F9 sinking it into the ground too much. Additionally, I'm reasonably sure that the landing sites for F9 have some sort of locator beacon/radar reflector/similar device that helps the F9 zero in on the exact landing spot which would need to be placed (or software adjustments made to F9). I'd say that with prep including software modifications, the F9 could probably land in a salt-flats desert but not on any unprepared Lunar or Martian surfaces.
Starship, on the other hand, is different considering that "Lunar Starship" which is being developed for NASA is specifically capable of landing on unprepared Lunar surfaces. The Lunar Starship variant will be able to land on the Moon and would probably be able to land on Mars too. This is because it presumably has some terrain-adaptive landing legs along with landing jets high on the ship's body to prevent the rocket exhaust from excavating the Lunar surface as it lands.
Here you can see a landed Lunar Starship, notice the engine ports on the sides:
And here you can see a Lunar Starship making a landing and firing the landing engines: