Raised This Month: $51 Target: $400
 12% 

CTFGameStats::ResetPlayerStats crashing server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dietcoke
Junior Member
Join Date: Jan 2021
Old 02-03-2021 , 20:28   CTFGameStats::ResetPlayerStats crashing server
Reply With Quote #1

Does anyone know why this crashes my server when I execute the SDKCall?

Code:
StartPrepSDKCall(SDKCall_Player);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CTFGameStats::ResetPlayerStats");
if ((g_hResetPlayerStats = EndPrepSDKCall()) == null) SetFailState("Failed to create SDKCall for CTFGameStats::ResetPlayerStats signature!");

SDKCall(g_hResetPlayerStats, client);
The symbol I am using is _ZN12CTFGameStats16ResetPlayerStatsEP9CTFPlay er

Last edited by dietcoke; 02-03-2021 at 21:00.
dietcoke is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-03-2021 , 23:18   Re: CTFGameStats::ResetPlayerStats crashing server
Reply With Quote #2

You're calling a non-static function on the CTFGameStats class; you need a CTFGameStats instance in addition to the player parameter.

Code:
StartPrepSDKCall(SDKCall_Raw); // pass the address of a CTFGameStats as 'this'
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CTFGameStats::ResetPlayerStats");
PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer); // this is when you pass the player
g_hResetPlayerStats = EndPrepSDKCall();

// call it -- g_pGameStats is an address of a CTFGameStats instance
SDKCall(g_hResetPlayerStats, g_pGameStats, client);
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
dietcoke
Junior Member
Join Date: Jan 2021
Old 02-04-2021 , 08:47   Re: CTFGameStats::ResetPlayerStats crashing server
Reply With Quote #3

Quote:
Originally Posted by nosoop View Post
You're calling a non-static function on the CTFGameStats class; you need a CTFGameStats instance in addition to the player parameter.

Code:
StartPrepSDKCall(SDKCall_Raw); // pass the address of a CTFGameStats as 'this'
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CTFGameStats::ResetPlayerStats");
PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer); // this is when you pass the player
g_hResetPlayerStats = EndPrepSDKCall();

// call it -- g_pGameStats is an address of a CTFGameStats instance
SDKCall(g_hResetPlayerStats, g_pGameStats, client);
Thanks for the reply. How do I create an instance/get the address of CTFGameStats ?
dietcoke is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-04-2021 , 12:14   Re: CTFGameStats::ResetPlayerStats crashing server
Reply With Quote #4

Quote:
Originally Posted by dietcoke View Post
Thanks for the reply. How do I create an instance/get the address of CTFGameStats ?
It's a global singleton, so the easiest way would be to look at anything that calls a function on CTFGameStats.

On Windows, you can look at the CTFPlayer::RemoveNemesisRelationships() function (which has a unique string) and read the absolute offset from where it gets moved into the ecx register before calling into CTFGameStats::ResetKillHistory().
On Linux / Mac you should be able to use the @CTF_GameStats symbol as the signature (CTF_GameStats is the name of the singleton).

Regardless of platform, you'll need the gameconfig address mechanism with GameConfGetAddress().
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 02-04-2021 at 12:19.
nosoop is offline
dietcoke
Junior Member
Join Date: Jan 2021
Old 02-08-2021 , 07:33   Re: CTFGameStats::ResetPlayerStats crashing server
Reply With Quote #5

Quote:
Originally Posted by nosoop View Post
It's a global singleton, so the easiest way would be to look at anything that calls a function on CTFGameStats.

On Windows, you can look at the CTFPlayer::RemoveNemesisRelationships() function (which has a unique string) and read the absolute offset from where it gets moved into the ecx register before calling into CTFGameStats::ResetKillHistory().
On Linux / Mac you should be able to use the @CTF_GameStats symbol as the signature (CTF_GameStats is the name of the singleton).

Regardless of platform, you'll need the gameconfig address mechanism with GameConfGetAddress().
This is good info, thanks again. Are you familiar with extensions? If so, do you know why when I detour some static, non-member functions the server crashes? Some work just fine, others don't.
And when I try to hook/detour these with dhooks, the server crashes as well.

Last edited by dietcoke; 02-08-2021 at 09:20.
dietcoke is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-08-2021 , 10:41   Re: CTFGameStats::ResetPlayerStats crashing server
Reply With Quote #6

Quote:
Originally Posted by dietcoke View Post
This is good info, thanks again. Are you familiar with extensions? If so, do you know why when I detour some static, non-member functions the server crashes? Some work just fine, others don't.
And when I try to hook/detour these with dhooks, the server crashes as well.
Without seeing which functions you're working with and how you're hooking them, I can't say for sure. Make sure you're using the correct macros (for CDetour) / call conventions (dynhooks) for it.

I use dynhooks plenty and most issues I come across stem from some fault in my own code, and I also use CDetours to some extent and haven't run into problems with the detours themselves (though I think I've only detoured member functions so far).

Getting mixed results is strange, though. They might not be what you think they are.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode