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

Solved [TF2] Medigun healing enemy players help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 10-21-2018 , 10:47   [TF2] Medigun healing enemy players help
Reply With Quote #1

Hello everyone,
I'm trying to make mediguns in my server heal enemy players, too. So far i inspected the Source 2007 code and found out that CWeaponMedigun::AllowedToHealTarget and CMedigunFilter::ShouldHitEntity check team numbers. So far i found the CWeaponMedigun::AllowedToHealTarget function in both the Windows and Linux binary and tested with making CWeaponMedigun::AllowedToHealTarget always return true(with debugger), but healing enemies not working. Then I tried to find CMedigunFilter::ShouldHitEntity function, but i can only find the function inside the Linux binary, but not in Windows.

So the questions is: How to find CMedigunFilter::ShouldHitEntity function inside the Windows binary
and how to properly hook it? It's virtual function, but how to find the object(or not possible, since it's object on stack?)?
Also please, explain how you find the function in the Windows binary
Thanks.
__________________
My plugins:
*None for now*


Steam:
naydef

Last edited by Naydef; 10-22-2018 at 14:03.
Naydef is offline
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 10-22-2018 , 14:02   Re: [TF2] Medigun healing enemy players help
Reply With Quote #2

So, after pondering over this issue, i finally found what i did wrong.
I was returning from the CWeaponMedigun::AllowedToHealTarget function using ret, but the function uses the _stdcall calling convention and it accepted one parameter, the problem was that the callee should clear the stack before returning from the function, but in my case ret doesn't clean the stack and who knows how my server didn't manage to crash even with broken stack(magic?). So to fix the issue and make mediguns heal every player, i replaced ret instruction with ret 4, so it will clean the stack before returning and IT WORKED! I can now heal the enemy team, too. Not only this, now i can heal every entity, like sentries. No need to mess with CMedigunFilter::ShouldHitEntity Actually, let me show you what shit happened:

Healing enemy players:


Healin' sentries...:
__________________
My plugins:
*None for now*


Steam:
naydef

Last edited by Naydef; 10-22-2018 at 14:04.
Naydef is offline
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 10-22-2018 , 19:25   Re: [TF2] Medigun healing enemy players help
Reply With Quote #3

That is pretty insane. Care to post the full solution?
Phil25 is offline
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 11-08-2018 , 07:21   Re: [TF2] Medigun healing enemy players help
Reply With Quote #4

Quote:
Originally Posted by Phil25 View Post
That is pretty insane. Care to post the full solution?
I forgot to respond

Gamedata(ghostbuster_defs.txt):
Code:
"Games"
{
	"#default"
	{
		"Signatures"
		{
			"CWeaponMedigun::AllowedToHealTarget" // "weapon_blocks_healing" and 4th function or debug and set breakpoints
			{
				"library"		"server"
				"windows"		"\x55\x8B\xEC\x53\x8B\xD9\x56\x57\x8B\xB3\xE8"
				"linux"			"_ZN14CWeaponMedigun19AllowedToHealTargetEP11CBaseEntity"
			}
		}
	}
}
Some code from my ff2 ghostbuster ability...(Requires DHooks with detours!)
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
#include <dhooks>

#pragma newdecls required

#define PLUGIN_NAME     "Example all-heal plugin"
#define PLUGIN_AUTHOR   "Naydef"
#define PLUGIN_VERSION  "1.0"

public Plugin myinfo =
{
    
name PLUGIN_NAME,
    
author PLUGIN_AUTHOR,
    
version PLUGIN_VERSION,
};

Handle hDetourAllowedToHealTarget;

public 
void OnPluginStart()
{
    
Handle gamedatafile=LoadGameConfigFile("ghostbuster_defs.games");
    if(
gamedatafile==null)
    {
        
SetFailState("Cannot find file ghostbuster_defs.games!");
    }
    
hDetourAllowedToHealTarget=DHookCreateDetour(Address_NullCallConv_THISCALLReturnType_BoolThisPointer_CBaseEntity);
    if(
hDetourAllowedToHealTarget==null)
    {
        
SetFailState("Failed to create CWeaponMedigun::AllowedToHealTarget detour!");
    }
    
// Load the address of the function from PTaH's signature gamedata file.
    
if(!DHookSetFromConf(hDetourAllowedToHealTargetgamedatafileSDKConf_Signature"CWeaponMedigun::AllowedToHealTarget"))
    {
        
SetFailState("Failed to load CWeaponMedigun::AllowedToHealTarget signature from gamedata");
    }
    
// Load the address of the function from PTaH's signature gamedata file.
    
delete gamedatafile;
    
    
//CWeaponMedigun::AllowedToHealTarget
    
DHookAddParam(hDetourAllowedToHealTargetHookParamType_CBaseEntity);
    
    
// Add a post hook on the function.
    
if(!DHookEnableDetour(hDetourAllowedToHealTargetfalseDetour_AllowedToHealTargetPost))
    {
        
SetFailState("Failed to detour CWeaponMedigun::AllowedToHealTarget!");
    }
}

public 
MRESReturn Detour_AllowedToHealTargetPost(int pThisHandle hReturnHandle hParams)
{
    if(
pThis==-|| DHookIsNullParam(hParams1))
    {
        return 
MRES_Ignored;
    }
    
//int targettoheal=DHookGetParam(hParams, 1);
    
DHookSetReturn(hReturntrue); // Just try the medigun in the game :)
    
return MRES_ChangedOverride;

__________________
My plugins:
*None for now*


Steam:
naydef

Last edited by Naydef; 11-08-2018 at 07:21.
Naydef is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-09-2018 , 17:55   Re: [TF2] Medigun healing enemy players help
Reply With Quote #5

Naydef... Thanks for sharing your code!

Question: Code above works to heal enemy players. However, it didn't allow me to heal buildings when running on a Windows dedicated server. Can you add the code that allows for healing buildings?
PC Gamer is offline
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 11-10-2018 , 11:47   Re: [TF2] Medigun healing enemy players help
Reply With Quote #6

Quote:
Originally Posted by PC Gamer View Post
Naydef... Thanks for sharing your code!

Question: Code above works to heal enemy players. However, it didn't allow me to heal buildings when running on a Windows dedicated server. Can you add the code that allows for healing buildings?
You can make something like this:
PHP Code:
public MRESReturn Detour_AllowedToHealTargetPost(int pThisHandle hReturnHandle hParams)
{
    if(
pThis==-|| DHookIsNullParam(hParams1))
    {
        return 
MRES_Ignored;
    }
    
int targettoheal=DHookGetParam(hParams1);
    if(
IsValidEntity(targettoheal) && targettoheal>MaxClients)
    {
        if(
HasEntProp(targettohealProp_Send"m_iHealth"))
        {
            
int health=GetEntProp(targettohealProp_Send"m_iHealth");
            
SetEntProp(targettohealProp_Send"m_iHealth"health+5);
        }
    }
    
DHookSetReturn(hReturntrue); // Just try the medigun in the game :)
    
return MRES_ChangedOverride;

Edit: Many things forgot to make...
__________________
My plugins:
*None for now*


Steam:
naydef

Last edited by Naydef; 11-10-2018 at 13:00. Reason: Many things forgot to make...
Naydef is offline
Reply


Thread Tools
Display Modes

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 06:36.


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