If you need to overnight in Lviv I can recommend the Hotel Cisar (Готель Цісар). I stayed for a night in 2019, admittedly before the major Russian onslaught began.
It's on the tram route 6 from the station, just before the city centre (or a 20-minute walk). The transport system takes cash, but you can (or at least could) buy a day ticket online or buy a "Leocard". There's a cash machine (beware large denomination notes) inside the station, which took my UK bank card.
Together with Lviv Tourist Information Center, we share some tips that will help you to avoid stressful situations and move around Lviv comfortably
lviv.travel
Cisar is Ukrainian for Caesar/Emperor and when I booked I was wondering which Emperor it referred to.
But behind the reception desk was a giant picture of a smiling Emperor Franz Joseph. Lviv/Lemberg was in the Austrian Empire (Galicia) for nearly 150 years until 1919, and there's still strong attachment to the old order.
Austrian Galicia stretched beyond Ternopil, but Khmelnytskyi is about 60km on the "Russian" side of that old border.
Changing trains at Przemysl (where there is break of gauge from standard to broad gauge) is easy, and the town is a very pleasant place, also an old Austrian town, to wander through with some good cafes, or to stay overnight if the connections don't work.
Lviv is only 100km from Przemysl but seems to consume 3 hours to get there (there's also a clock change at the border, UA is 1 hour ahead of PL).
From the European Rail Timetable Ternopil is 140km further and Khmelnytskyi 120km beyond that.
I was able to book Ukrainian trains on the UZ web site in 2019, but don't know if things have changed:
Doubtless security will have been strengthened since my visit.