AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Problem with hooked fuction (https://forums.alliedmods.net/showthread.php?t=299009)

Misterrr 06-29-2017 08:19

Problem with hooked fuction
 
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...

asherkin 06-29-2017 09:22

Re: Problem with hooked fuction
 
You should be using MRES_IGNORED in both cases.

See https://forums.alliedmods.net/showthread.php?t=297857.

Misterrr 07-03-2017 23:50

Re: Problem with hooked fuction
 
Quote:

Originally Posted by asherkin (Post 2532454)
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);




All times are GMT -4. The time now is 01:22.

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