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

Issue with PushFloatByRef


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xerox8521
Senior Member
Join Date: Sep 2011
Old 04-06-2018 , 13:46   Issue with PushFloatByRef
Reply With Quote #1

Hi,

I've setup a SH Hook that should return the weapons range which later in a SM plugin should be changeable using a forward that part works untill i try to push the actual range using PushFloatByRef.
I've looked into other extensions but can't seem to find the issue.
Without the PushFloatByRef the forward is being called.

Even tried swapping around the push order (with all changes done where needed) but no luck.

PHP Code:
float ZPSHooks::OnGetRange()
{
    
CBaseEntity *pWeapon META_IFACEPTR(CBaseEntity);

    
float flOrgRange SH_MCALL(pWeaponWeaponRange)();

    
// If there's an invalid ent or invalid networkable here, we've got issues elsewhere.

    
IServerNetworkable *pNetWeapon = ((IServerUnknown *)pWeapon)->GetNetworkable();
    
ServerClass *pServerClass pNetWeapon->GetServerClass();
    if (!
pServerClass)
    {
        
g_pSM->LogError(myself"Invalid server class on weapon.");
        
RETURN_META_VALUE(MRES_IGNOREDflOrgRange);
    }
    
sm_sendprop_info_t info;
    if (!
gamehelpers->FindSendPropInfo(pServerClass->GetName(), "m_hOwnerEntity", &info))
    {
        
g_pSM->LogError(myself"Could not find m_hOwnerEntity on %s"pServerClass->GetName());
        
RETURN_META_VALUE(MRES_IGNOREDflOrgRange);
    }

    
int ownerIndex = -1;
    
CBaseHandle &hndl = *(CBaseHandle *)((intptr_t)pWeapon info.actual_offset);
    
CBaseEntity *pHandleEntity gamehelpers->ReferenceToEntity(hndl.GetEntryIndex());

    if (
pHandleEntity != nullptr && hndl == reinterpret_cast<IHandleEntity *>(pHandleEntity)->GetRefEHandle())
    {
        
ownerIndex hndl.GetEntryIndex();
    }

    
float flRange flOrgRange;
    
// Printing out the values in console works properly
    
rootconsole->ConsolePrint("[ZPSHOOKS]: Client: %d | Weapon: %d | Classname: %s | Range: %0.2f"ownerIndexgamehelpers->EntityToBCompatRef(pWeapon), gamehelpers->GetEntityClassname(pWeapon), flOrgRange);

    
g_pOnGetRange->PushCell(ownerIndex);
    
g_pOnGetRange->PushCell(gamehelpers->EntityToBCompatRef(pWeapon));
    
g_pOnGetRange->PushFloatByRef(&flRange);
    
g_pOnGetRange->PushString(gamehelpers->GetEntityClassname(pWeapon));
    

    
cell_t result Pl_Continue;

    
g_pOnGetRange->Execute(&result);

    if (
result == Pl_Changed)
    {
        
RETURN_META_VALUE(MRES_SUPERCEDEflRange);
    }
    else
    {
        
        
RETURN_META_VALUE(MRES_IGNOREDflOrgRange);
    }


forward is created this way:

PHP Code:
g_pOnGetRange forwards->CreateForward("OnGetWeaponRange"ET_Event3nullptrParam_CellParam_CellParam_FloatByRefParam_String); 
forward declaration in SP:

PHP Code:
forward Action OnGetWeaponRange(int clientint weaponfloat &flRange, const char[] szClassname); 
Usage in test plugin:

PHP Code:
public Action OnGetWeaponRange(int clientint weaponfloat &flRange, const char[] szClassname)
{
    
PrintToChatAll("Client: %d | Weapon: %d | classname: %s | Range: %0.2f"clientweaponszClassnameflRange);
    return 
Plugin_Continue;

OS: Linux Ubuntu 16.04 (64 Bit)

Code:
sm version
 SourceMod Version Information:
    SourceMod Version: 1.8.0.6041
    SourcePawn Engine: SourcePawn 1.8, jit-x86 (build 1.8.0.6041)
    SourcePawn API: v1 = 4, v2 = 11
    Compiled on: Feb 15 2018 14:39:02
    Built from: https://github.com/alliedmodders/sourcemod/commit/d36b065
    Build ID: 6041:d36b065
    http://www.sourcemod.net/
Code:
meta version
Metamod:Source version 1.10.7-dev
Built from: https://github.com/alliedmodders/metamod-source/commit/f255fa5
Build ID: 961:f255fa5
Loaded As: Valve Server Plugin
Compiled on: Nov  5 2017
Plugin interface version: 15:14
SourceHook version: 5:5
http://www.metamodsource.net/
xerox8521 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 04-06-2018 , 15:53   Re: Issue with PushFloatByRef
Reply With Quote #2

Quote:
Originally Posted by xerox8521 View Post
PHP Code:
g_pOnGetRange forwards->CreateForward("OnGetWeaponRange"ET_Event3nullptrParam_CellParam_CellParam_FloatByRefParam_String); 
You still have 3 for param count.
psychonic is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 04-06-2018 , 17:32   Re: Issue with PushFloatByRef
Reply With Quote #3

Thanks, I somehow oversaw that.
xerox8521 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 15:08.


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