halflife icon indicating copy to clipboard operation
halflife copied to clipboard

Wrong class specified in CBaseAnimating save data table.

Open malortie opened this issue 3 years ago • 3 comments

The member variables registered in the data table are declared in CBaseAnimating, but the specified field type is CBaseMonster. It should probably be CBaseAnimating.

https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/animating.cpp#L29-L38

malortie avatar Dec 07 '21 23:12 malortie

@malortie Did you have notice any side-effects?

rtxa avatar Dec 08 '21 01:12 rtxa

@rtxa

Here is the macro definition for DEFINE_FIELD :

https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/engine/eiface.h#L401-L402

offsetof is used to calculate the offset of the member variable, relative to the beginning of the object.

In code, all entity classes appear to use single inheritance only. In this case, the base class member variables addresses should be the same as with the derived class. See the following.

I did the following to get the offset of each member variable using CBaseAnimating and CBaseMonster.

int cba_m_flFrameRate = offsetof(CBaseAnimating, m_flFrameRate);
int cba_m_flGroundSpeed = offsetof(CBaseAnimating, m_flGroundSpeed);
int cba_m_flLastEventCheck = offsetof(CBaseAnimating, m_flLastEventCheck);
int cba_m_fSequenceFinished = offsetof(CBaseAnimating, m_fSequenceFinished);
int cba_m_fSequenceLoops = offsetof(CBaseAnimating, m_fSequenceLoops);

int cbm_m_flFrameRate = offsetof(CBaseMonster, m_flFrameRate);
int cbm_m_flGroundSpeed = offsetof(CBaseMonster, m_flGroundSpeed);
int cbm_m_flLastEventCheck = offsetof(CBaseMonster, m_flLastEventCheck);
int cbm_m_fSequenceFinished = offsetof(CBaseMonster, m_fSequenceFinished);
int cbm_m_fSequenceLoops = offsetof(CBaseMonster, m_fSequenceLoops);

In my case, results show that offsets are the same.

cba_m_flFrameRate	92	int
cba_m_flGroundSpeed	96	int
cba_m_flLastEventCheck	100	int
cba_m_fSequenceFinished	104	int
cba_m_fSequenceLoops	105	int

cbm_m_flFrameRate	92	int
cbm_m_flGroundSpeed	96	int
cbm_m_flLastEventCheck	100	int
cbm_m_fSequenceFinished	104	int
cbm_m_fSequenceLoops	105	int

Technically, there should be no breaking changes. Otherwise, this would break saved games but saving again would fix it.

malortie avatar Dec 08 '21 23:12 malortie

@malortie Thanks for taking the time to explain it. Got it!

rtxa avatar Dec 09 '21 13:12 rtxa