Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SmileyAG opened this issue Jan 25, 2024 · 0 comments
Assignees

Comments

@SmileyAG
Copy link
Collaborator

typedef struct
{
FIELDTYPE fieldType;
char *fieldName;
int fieldOffset;
short fieldSize;
short flags;
} TYPEDESCRIPTION;

  • 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):

offm_rgAmmoLast = 0x56C; // 6153: 0x568
offm_iClientFOV = 0x4C4; // 6153: 0x4C0
if (ClientDLL::GetInstance().DoesGameDirContain("czeror")) {
offm_rgAmmoLast = 0x554; // 6153: 0x550
offm_iClientFOV = 0x8B0; // 6153: 0x8AC
offFuncIsPlayer = 0xA8;
offFuncCenter = 0xDC;
offFuncObjectCaps = 0x18;
}
if (ClientDLL::GetInstance().DoesGameDirContain("bshift")) {
offm_rgAmmoLast = 0x568; // 8684: 0x56C
offm_iClientFOV = 0x4C0; // 8684: 0x4C4
}

@SmileyAG SmileyAG self-assigned this Jan 25, 2024
@SmileyAG SmileyAG changed the title Use save data to find offsets for the most of class variables restructuring: use save data to find offsets for the most of class variables Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant