halflife
halflife copied to clipboard
[Opposing Force] M249 belt body isn't synced between client and server
In Opposing Force the M249 belt body isn't synchronized between the client and server.
If you pick up an M249, empty it's magazine and then kill yourself, and you then respawn and pick up another M249 the belt will appear empty because the client's M249 still has the belt body from the previous instance set on it.
To fix this the body value has to be synced.
In weapons.h
#include "weaponinfo.h"
//In the CBasePlayerItem class declaration
virtual void GetWeaponData(weapon_data_t& data) {}
virtual void SetWeaponData(const weapon_data_t& data) {}
In the CM249 class declaration:
void GetWeaponData(weapon_data_t& data) override;
void SetWeaponData(const weapon_data_t& data) override;
In the CM249 class definition:
void CM249::GetWeaponData(weapon_data_t& data)
{
data.iuser1 = pev->body;
}
void CM249::SetWeaponData(const weapon_data_t& data)
{
pev->body = data.iuser1;
}
After this line: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/client.cpp#L1635
Add:
gun->GetWeaponData(*item);
After this line: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/cl_dll/hl/hl_weapons.cpp#L797
Add:
pCurrent->SetWeaponData(*pfrom);
After this line: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/cl_dll/hl/hl_weapons.cpp#L977
Add:
pCurrent->GetWeaponData(*pto);
This code will copy the pev->body value into iuser1, which gets sent to the client which then copies it into the client's version of the M249 and then copies the value back out again into the local prediction copy of the weapon data for use in predicting future frames.
Although iuser1 is already used to pass m_chargeReady this variable is only used by the Gauss gun, so it won't affect weapon behavior. (that variable can be moved to the CGauss class and copied using these same functions to simplify the logic a bit)
I don't see Gauss using m_chargeReady. Did you mean satchels?
Also adding virtual functions will probably break server plugins. Still good thing for modders who don't plan to maintain the compatibility.