View Single Post
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 02-13-2020 , 17:01   [H3LP] StartObserver with Orpheu
Reply With Quote #1

I want to hook CBasePlayer::ObserverStart with Orpheu, since Okapi is having some issues especially on Linux and with virtual functions mostly, so I don't wanna use it at all anymore, as my server eprforms much betetr since I got rid of it.

Plugin test:

PHP Code:
#include <amxmodx>
#include <orpheu>

new const g_szPluginName[] = "Observer Spectator Test";
new const 
g_szPluginVersion[] = "1.0";
new const 
g_szPluginAuthor[] = "DarthMan";

new 
OrpheuFunctiong_hFuncStartObserver;
new 
OrpheuHookg_hStartObserver;
const 
OrpheuInvalidHook OrpheuHook0;

#define PLUGIN_NAME g_szPluginName
#define PLUGIN_VERSION g_szPluginVersion
#define PLUGIN_AUTHOR g_szPluginAuthor

public plugin_init()
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR);

    
RegisterForward();
}

public 
plugin_precache()
{
    
g_hFuncStartObserver OrpheuGetFunction("StartObserver""CBasePlayer");
}

RegisterForward()
{
    if(
g_hFuncStartObserver != OrpheuInvalidFunction)
    {
        if(
g_hStartObserver == OrpheuInvalidHook)
        {
            
g_hStartObserver OrpheuRegisterHook(g_hFuncStartObserver"OnPlayerSpectate_Post"OrpheuHookPost);
        }
    }
}

UnregisterForward()
{
    if(
g_hStartObserver != OrpheuInvalidHook)
    {
        
OrpheuUnregisterHook(g_hStartObserver);
    }
}

public 
plugin_unpause()
{
    
RegisterForward();
}

public 
plugin_pause()
{
    
UnregisterForward();
}

public 
plugin_end()
{
    
UnregisterForward();
}

public 
OnPlayerSpectate_Post(const iID)
{
    new 
szPlayerName[32];

    
get_user_name(iIDszPlayerNamecharsmax(szPlayerName));

    
server_print("%s joined team 'SPECTATORS'."szPlayerName);

    new 
iPlayers[32], iPlayeriNum;

    
get_players(iPlayersiNum);

    if(
iNum 1)
    {
        for(new 
0iNumi++)
        {
            
iPlayer iPlayers[i];

            if(
iPlayer != iID)
            {
                
client_print(iPlayerprint_chat"* %s joined team 'SPECTATORS'."szPlayerName);
            }
        }
    }

Signature file:

PHP Code:

    
"name" "StartObserver"
    
"class" "CBasePlayer",
    
"library" "mod"
    
"arguments" 
    [ 
        { 
            
"type" "Vector"
        
},
        { 
            
"type" "Vector"
        
}
    ], 
    
"identifiers" :
    [
        {
            
"os" "windows",
            
"mod" "tfc",
            
"value" : [0x53,0x56,0x8B,"*",0x57,0x33,"*",0x8B,"*","*",0x57,0x83,"*","*",0x50,0x6A]
        },
        {
            
"os" "linux",
            
"mod" "tfc",
            
"value" "_ZN11CBasePlayer13StartObserverE6VectorS0_"
        
}
    ]
    

The funcion has Params as Vectos as args as per HLSDK. So, is there a way I can hook it with Orpheu?

Last edited by DarthMan; 02-13-2020 at 17:03.
DarthMan is offline