ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.67k stars 622 forks source link

Saving while zoomed in with a weapon and then loading that save game fails to restore field of view #3044

Open SamVanheer opened 3 years ago

SamVanheer commented 3 years ago

When saving the game while zoomed in with a weapon and then loading that saved game, the game fails to restore the field of view resulting in the default field of view being used.

In Opposing Force the behavior is slightly different. The crosshair represents the correct field of view because it is dependent on m_iFOV from CBasePlayer, whereas the actual field of view used to control the zoom level is stored in pev->fov.

pev->fov isn't saved and restored which leads to this discrepancy.

Here's an example: NhyojiE TKuLy08

The first image was taken before loading, the second after loading.

That can be fixed by adding the following lines:

pev->fov = m_iFOV;
m_iClientFOV = -1; // Make sure the client gets the right FOV value.

Here: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L3064-L3066

Both variables are supposed to contain the same value at all times so this shouldn't cause any problems.

To fix the crosshair not restoring correctly these lines here need to be commented out: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/cl_dll/hud.cpp#L630-L632

As noted in the function prediction is supposed to handle fov locally, but it doesn't account for restoring non-default fov values.

Opposing Force doesn't have this problem because it has an extra condition in that if check that causes it to only work if the current game is tfc, which it would only be if you renamed the gearbox directory to tfc before running the game.

SamVanheer commented 3 years ago

Further investigation shows that pev->fov wasn't referenced in game code in the 1.0 SDK. It was added as part of the prediction upgrade, presumably because parts of the code that now reside in game code were initially added in the engine (where CBasePlayer can't be accessed from) before being moved to game code to let it take care of updating that stuff (which allows spectator code to work).

Removing all references to pev->fov and replacing it with m_iFOV where needed doesn't break anything as far as i can tell, but this would have to be verified before making any changes.

SamVanheer commented 2 years ago

Added an additional line of code required so this fix works when cl_lw is set to 0.