rafalh / dashfaction

A community patch for the Red Faction (2001) FPS game
https://www.factionfiles.com/ff.php?action=file&id=6252
Mozilla Public License 2.0
61 stars 11 forks source link

Play Level from Camera doesn't work for levels with space in filename #232

Closed GooberRF closed 6 months ago

GooberRF commented 6 months ago

When launching levels from RED using Play (camera), if the rfl filename has a space, the following error is displayed: image

When launching levels from RED using Play, this issue doesn't occur.

rafalh commented 6 months ago

I debugged it and it's pretty interesting: It is RF bug. When "Play (camera)" is clicked it launches RF with cmd line like:

full_path\\RF.exe -level "level name.rfl" -startpos 0,0.85;0,0.00;0,0.84 -startdir 1,0.84;0,0.00;1,0.53

When "Play" is clicked cmd line is a bit different:

full_path\\RF.exe -level "full_level_path\\level name.rfl"

It seems RF has pretty much broken support for double quotes in code that parses cmd line, but it didn't stop RF devs from using them when launching from editor. When we launch with camera it logs Loading level: "test space.rfl (only the first quote is visible). That's because RF removes level file extension (to avoid having double extension if the name happens to have an extension) and then add .rfl extension. In this case it interprets .rfl" as a file extension (with the ending quote character). As for the starting quote character, it is removed if there is a forward slash before the filename - RF ignores the dir path and uses only the filename part, so the quote is skipped. For some reason when launching without camera it uses full level path, so it has a slash... It does not add quotes when the filename does not contain spaces, so it works in this case for both buttons. The reason for that is that in fact it is DashFaction launcher that is really executed by RED.exe before RF.exe is started and it parses args and removes unnecessary quotes. RF by default puts entire level path into cmd line. It is DF change to put only the filename to avoid buffer overflow but it seems my fix only worked for "Play (camera)". When I corrected it now "Play" does not work as well for levels with spaces So in unmodified game RED launches levels always using quotes (bad) but also have absolute paths which enables a "workaround" for quotes. It works by chance... If ran using rf.exe -level "foo bar" command, it would preserve both quotes and fail.