Raised This Month: $7 Target: $400
 1% 

Problem with hooked fuction


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Misterrr
New Member
Join Date: Jan 2017
Old 06-29-2017 , 08:19   Problem with hooked fuction
Reply With Quote #1

Hello! I'm studying the possibilities of Metamod, and I was wondering if it was possible to intercept the call of the function IBaseFileSystem::Open and call it with another parameter? I was trying to do this:
PHP Code:
SH_DECL_HOOK3(IBaseFileSystemOpenSH_NOATTRIB0FileHandle_t,  const char *, const char *, const char *); 
I announced this
PHP Code:
IBaseFileSystem *basefilesystem NULL;
GET_V_IFACE_CURRENT(GetFileSystemFactorybasefilesystemIBaseFileSystemBASEFILESYSTEM_INTERFACE_VERSION); 
and add hook
PHP Code:
OpenHook SH_ADD_VPHOOK(IBaseFileSystemOpenbasefilesystemSH_MEMBER(this, &SamplePlugin::Hook_Open), false); 
I tried to do so
PHP Code:
FileHandle_t SamplePlugin::Hook_Open(const char *pFileName, const char *pOptions, const char *pathID) {
   if(
strncmp(pFileName"materials/headshot1.vtf"strlen("materials/headshot1.vtf")) == 0) {
         
META_LOG(g_PLAPI"yeaaa opening headshot file \"%s\",pOptions \"%s\",pathID \"%s\"."pFileNamepOptionspathID);
          
RETURN_META_VALUE_NEWPARAMS(MRES_OVERRIDENULL, &IBaseFileSystem::Open, ("materials/headshot2.vtf"pOptionspathID));
   }
RETURN_META_VALUE(MRES_IGNOREDfalse);

but not working((
If you do like this, the server is crashing
PHP Code:
FileHandle_t SamplePlugin::Hook_Open(const char *pFileName, const char *pOptions, const char *pathID) {
   if(
strncmp(pFileName"materials/headshot1.vtf"strlen("materials/headshot1.vtf")) == 0) {
    
META_LOG(g_PLAPI"yeaaa opening headshot file \"%s\",pOptions \"%s\",pathID \"%s\"."pFileNamepOptionspathID);

    
FileHandle_t myhndl basefilesystem->Open(pFileNamepOptionspathID);
RETURN_META_VALUE(MRES_SUPERCEDEmyhndl);
   }

RETURN_META_VALUE(MRES_IGNOREDfalse);


What did I do wrong? I tried using MRES_OVERRIDE, but it did not help...
Misterrr is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-29-2017 , 09:22   Re: Problem with hooked fuction
Reply With Quote #2

You should be using MRES_IGNORED in both cases.

See https://forums.alliedmods.net/showthread.php?t=297857.
__________________
asherkin is offline
Misterrr
New Member
Join Date: Jan 2017
Old 07-03-2017 , 23:50   Re: Problem with hooked fuction
Reply With Quote #3

Quote:
Originally Posted by asherkin View Post
You should be using MRES_IGNORED in both cases.

See https://forums.alliedmods.net/showthread.php?t=297857.
I did as you advised, but the server still crashes, the hook works, but the original function with the new parameter is not called. what should I do? I just need to replace the file name with another file name and call the open function so that it continues working

PHP Code:
FileHandle_t SamplePlugin::Hook_Open(const char *pFileName, const char *pOptions, const char *pathID) {
   if(
strncmp(pFileName"materials/headshot1.vtf"strlen("materials/headshot1.vtf")) == 0) {
         
META_LOG(g_PLAPI"yeaaa opening headshot file \"%s\",pOptions \"%s\",pathID \"%s\"."pFileNamepOptionspathID);
          
RETURN_META_VALUE_NEWPARAMS(MRES_IGNOREDNULL, &IBaseFileSystem::Open, ("materials/headshot2.vtf"pOptionspathID));
   }
RETURN_META_VALUE(MRES_IGNOREDfalse);

Misterrr 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 22:05.


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