Raised This Month: $32 Target: $400
 8% 

[TF2] Friendly Pyro Fire - FlameThrower


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Swixel
Senior Member
Join Date: Jul 2010
Location: Sydney, Australia
Old 11-09-2010 , 05:44   [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #1

This snippet friendly fire on the pyro's flamethrower, if mp_friendlyfire is set to 1. This is because Valve are doing a check further down and line and I'm not going to break half the game to give friendlyfire to one weapon. (Okay, I might, but not now.)

As a disclaimer, I'm putting this here for others who are looking for it. I am working on something with it in it, whether I finish it or get bored by something else shiny, I don't know ...

I didn't even find this request until I'd been hacking away on something totally unrelated (duel related), but I'm set

Game Data ... works as of ... well, now.

PHP Code:
// CTFFlameEntity::OnCollide(CBaseEntity *)
"CTFFlameEntity_OnCollide"
{
    
"library" "server"
    "windows" "\x81\xEC\xA8\x00\x00\x00\x56\x8B\xF1\x8B\x86\xFC\x00\x00\x00\xC1\xE8\x0B\xA8\x01\x57"
    "linux" "@_ZN14CTFFlameEntity9OnCollideEP11CBaseEntity"
}

// CTFFlameEntity::OnCollideWithTeammate(CTFPlayer *)
"CTFFlameEntity_OnCollideWithTeammate"
{
    
"library" "server"
    "windows" "\x56\x8B\x74\x24\x08\x57\x8B\xF9\x6A\x2A\x8B\xCE\x2A\x2A\x2A\x2A\x2A\x84\xC0\x2A\x2A\x2A\x2A\x2A\x2A\x85\xF6\x2A\x2A\x8B\x06\x8B\x50\x08\x8B\xCE\xFF\xD2\x8B\x00\x89\x44\x24\x0C\x2A\x2A"
    "linux" "@_ZN14CTFFlameEntity21OnCollideWithTeammateEP9CTFPlayer"

The detour...

PHP Code:
DETOUR_DECL_MEMBER1(CTFFlameEntity_OnCollideWithTeammateintCBaseEntity*, pPlayer)
{
    
/* Get the original result */
    
int TeamCollision DETOUR_MEMBER_CALL(CTFFlameEntity_OnCollideWithTeammate)(pPlayer);

    
char *addr;
    if(!
g_pGameConf->GetMemSig("CTFFlameEntity_OnCollide", (void **)&addr) || !addr)
    {
        
// If it goes pear-shaped, bail by performing the default function
        
META_CONPRINTF("Could not find signature for 'CTFFlameEntity_OnCollide'.\n");
        return 
TeamCollision;
    }
    
/* predcrab to the rescue -- this calls CTFFlameEntity::OnCollide using |this|, with platform specific code. */
    
union
    
{
        
int (VEmptyClass::*mfpOnCollide)(CBaseEntity *pPlayer);
#ifndef PLATFORM_POSIX
        
void *addr;
    } 
u;
    
u.addr addr;
#else
        
struct  
        
{
            
void *addr;
            
intptr_t adjustor;
        } 
s;
    } 
u;
    
u.s.addr addr;
    
u.s.adjustor 0;
#endif
    
return (reinterpret_cast<VEmptyClass *>(this)->*u.mfpOnCollide)(pPlayer);
    
/* end predcrab to the rescue */

If you want to do what I'm doing in my extension then you need a cvar (enable/disable) or two (enable/disable flamethrower "modes"). You can then check for the cvar values and do whatever you want based on that.

If my extension is disabled it kills all cvars (atm), though I'm thinking of working out a mode of individual functions (based on mode cvars and callbacks).

You can additionally detour OnCollide, if you wish to disable all damage, and just return 0 on both.

While I did find the sigs on my own, there are some people who deserve thanks...
  • predcrab - for providing a large chunk of the code and helping me get the detour working;
  • asherkin - for basically re-teaching me more than I've forgotten about C++, and helping me debug various parts of this, and teaching me to find sigs;
  • psychonic, and Wazz - for explaining things to me and teaching me to find sigs in a sensible way.

Last edited by Swixel; 11-09-2010 at 05:46. Reason: Added some clarity.
Swixel is offline
Thraka
AlliedModders Donor
Join Date: Aug 2005
Old 11-09-2010 , 17:09   Re: [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #2

Cooooool. If someone can turn this into an extension that can be used by other plugins, that would be awesome.
Thraka is offline
Swixel
Senior Member
Join Date: Jul 2010
Location: Sydney, Australia
Old 11-09-2010 , 17:13   Re: [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #3

Quote:
Originally Posted by Thraka View Post
Cooooool. If someone can turn this into an extension that can be used by other plugins, that would be awesome.
It gets a little too difficult to call detours on the fly C++ <-> Pawn... globally you can enable/disable them, you could probably even use a config (with pawn writing to it, C++ reading/updating from it), but it'd get ugly pretty quickly, and I hate file i/o
Swixel is offline
Sir Jake
Senior Member
Join Date: Jan 2009
Old 11-09-2010 , 20:26   Re: [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #4

This would be great with the warmup rounds.
Sir Jake is offline
Swixel
Senior Member
Join Date: Jul 2010
Location: Sydney, Australia
Old 11-09-2010 , 23:51   Re: [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #5

Well Valve checks block it from working outside of friendlyfire *anyway*, so that detour (as is) just enables the flamethrower whenever mp_friendlyfire is on. Otherwise Valve's later check (done by the CTFFlamethrower itself) disables it ...

If you're worried you could always do what I'm doing, and check against an enable cvar (or even check the detour status against mp_friendlyfire):

PHP Code:
// Somewhere up the top, nicely, to declare it
ConVar *cv_FF;

// Within the SDK_OnLoad function
    
cv_FF g_pCVar->FindVar("mp_friendlyfire");

// Within the detour
if(cv_FF->GetBool())
{
/* rest of the detour code */
}
else
{
  return 
TeamCollision;

Or you could just destroy the detour every time cv_FF changes...

PHP Code:
// Declare this somewhere
static void FFCallbackIConVar *var, const char *pOldValuefloat flOldValue )
{
    if(
cv_FF->GetBool())
    {
        
uradetour->EnableDetour();
    }
    else
    {
        
uradetour->DisableDetour();
    }
}

// within OnLoad, after cv_FF is "found"
cv_FF->InstallChangeCallback(FFCallBack); 
* shrugs *

Last edited by Swixel; 11-10-2010 at 04:49. Reason: additionally, asherkin's other point over IRC was very valid
Swixel is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-10-2010 , 03:02   Re: [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #6

Few short notes:
Quote:
Originally Posted by Swixel View Post
PHP Code:
cv_FF g_pCVar->FindVar("mp_friendlyfire"); 
Make sure to check this isn't NULL.
I have had some really nasty crashes forgetting that in the past, even for valve cvars that should be there for sure.

Quote:
Originally Posted by Swixel View Post
PHP Code:
uradetour->Destroy(); 
Probably meant DisableDetour() here, destroy would free the CDetour structure, requiring you to call CreateDetour again
__________________
asherkin is offline
Swixel
Senior Member
Join Date: Jul 2010
Location: Sydney, Australia
Old 11-10-2010 , 03:12   Re: [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #7

Quote:
Originally Posted by asherkin View Post
Few short notes:

Make sure to check this isn't NULL.
I have had some really nasty crashes forgetting that in the past, even for valve cvars that should be there for sure.


Probably meant DisableDetour() here, destroy would free the CDetour structure, requiring you to call CreateDetour again
Both good points ... *edits the above*
Swixel is offline
El Diablo War3Evo
Veteran Member
Join Date: Jun 2013
Old 09-20-2014 , 13:16   Re: [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #8

I know this is an old post, but I am dieing to see this working!

I would love to see this working either as a plugin or a extension.

I did find: https://www.openhub.net/p/wtff .. but i haven't learned c++ good enough to figure out how to compile it and get it going.. plus it is years old and who knows if it is any good still?

Other links:
https://forums.alliedmods.net/showthread.php?t=133740
https://bitbucket.org/aws/wtff/wiki/browse/
__________________

Last edited by El Diablo War3Evo; 09-20-2014 at 13:29.
El Diablo War3Evo is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 09-20-2014 , 23:49   Re: [TF2] Friendly Pyro Fire - FlameThrower
Reply With Quote #9

Did you check to see if it is picked up in ontakedamage_alive ?
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram 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 03:08.


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