Skip to content

Commit

Permalink
Use exposed CTFPlayer::m_bRegenerating netprop
Browse files Browse the repository at this point in the history
Valve made this a networked property with the 2021-12-21 update, so
we don't have to worry about offset breakages any more.

Unless they revert the change in which case aaaaaaa
  • Loading branch information
nosoop committed Dec 22, 2021
1 parent fca45c5 commit 4115de0
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions scripting/cwx.sp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ ConVar mp_stalemate_meleeonly;

int g_attrdef_AllowedInMedievalMode;

any offs_CTFPlayer_m_bRegenerating;

public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
RegPluginLibrary("cwx");

Expand Down Expand Up @@ -114,15 +112,6 @@ public void OnPluginStart() {

mp_stalemate_meleeonly = FindConVar("mp_stalemate_meleeonly");

any offs_CTFPlayer_m_hItem = FindSendPropInfo("CTFPlayer", "m_hItem");
if (!offs_CTFPlayer_m_hItem) {
SetFailState("Failed to resolve member offset CTFPlayer::m_bRegenerating");
}

// m_hItem is dword-aligned, the previous dword contains at least 1 unknown bool value
// this is consistent between Windows / Linux
offs_CTFPlayer_m_bRegenerating = offs_CTFPlayer_m_hItem - 5;

// TODO: I'd like to use a separate, independent database for this
// but leveraging the cookie system is easier for now
char cookieName[64], cookieDesc[128];
Expand Down Expand Up @@ -476,13 +465,9 @@ void OnLoadoutRespawnPreference(QueryCookie cookie, int client, ConVarQueryResul

// mark player as regenerating during respawn -- this prevents stickies from despawning
// this matches the game's internal behavior during GC loadout changes
SetPlayerRegenerationState(client, true);
SetEntProp(client, Prop_Send, "m_bRegenerating", true);
TF2_RespawnPlayer(client);
SetPlayerRegenerationState(client, false);
}

void SetPlayerRegenerationState(int client, bool value) {
SetEntData(client, offs_CTFPlayer_m_bRegenerating, value, .size = 1);
SetEntProp(client, Prop_Send, "m_bRegenerating", false);
}

/**
Expand Down

0 comments on commit 4115de0

Please sign in to comment.