BunnymodXT icon indicating copy to clipboard operation
BunnymodXT copied to clipboard

restructuring: use save data to find offsets for the most of class variables

Open SmileyAG opened this issue 1 year ago • 0 comments

https://github.com/YaLTeR/BunnymodXT/blob/11963346953029d9882e04ad7f86ea0fbf6aea49/HLSDK/engine/eiface.h#L404-L411

  • Find Save or Restore class function (e.g. CBasePlayer::Save)
  • There will definitely be a call(s) to the CSave::WriteFields or CRestore::ReadFields depending on the function you choose:
int CBasePlayer::Save( CSave &save )
{
    if ( !CBaseMonster::Save(save) )
        return 0;

    return save.WriteFields( "PLAYER", this, m_playerSaveData, ARRAYSIZE(m_playerSaveData) );
}
  • You need intercept m_playerSaveData and store total fields number that passed as last argument
  • Now you can iterate through it and get name/offset/size of class variable if it contains in that list

This will also help to remove this ugliest hardcoded offsets for Linux game versions and thereby allow you to play without issues from both versions (Valve added a variable at the end of CBaseMonster for the NPC turn fix, which is also inherited for CBasePlayer):

https://github.com/YaLTeR/BunnymodXT/blob/11963346953029d9882e04ad7f86ea0fbf6aea49/BunnymodXT/modules/ServerDLL.cpp#L991-L1003

SmileyAG avatar Jan 25 '24 14:01 SmileyAG