• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Very specific problem regarding file functions and y_hooks
#1
So... I don't really know if it is even script related or a bug with samp, y_hooks or sampctl.

TL;DR: hook of CreateMenu doesn't get called when file functions (fwrite, fread etc..) are also hooked

Problem description:

Setup: 2 local Servers, only difference: server 1 uses sampctl, server 2 doesn't

Exact same code:
include file:
Code:
#include <a_samp>
#include <YSI_Coding\y_hooks>

hook function fclose(File:handle)
{
? ?if(handle) return continue(handle);
? ?printf("Invalid handle passed to fclose!");
? ?return ~0;
}

hook function fwrite(File:handle, const string[])
{
? ?if(handle) return continue(handle, string);
? ?printf("Invalid handle passed to fwrite!");
? ?return ~0;
}

hook function fread(File:handle, string[], size = sizeof string, bool:pack = false)
{
? ?if(handle) return continue(handle, string, size, pack);
? ?printf("Invalid handle passed to fread!");
? ?return ~0;
}

hook function fputchar(File: handle, value, bool: utf8 = true)
{
? ?if(handle) return continue(handle, value, utf8);
? ?printf("Invalid handle passed to fputchar!");
? ?return ~0;
}

hook function fgetchar(File: handle, value, bool: utf8 = true)
{
? ?if(handle) return continue(handle, value, utf8);
? ?printf("Invalid handle passed to fgetchar!");
? ?return ~EOF;
}

hook function fblockwrite(File: handle, const buffer[], size = sizeof buffer)
{
? ?if(handle) return continue(handle, buffer, size);
? ?printf("Invalid handle passed to fblockwrite!");
? ?return ~0;
}

hook function fblockread(File: handle, buffer[], size = sizeof buffer)
{
? ?if(handle) return continue(handle, buffer, size);
? ?printf("Invalid handle passed to fblockread!");
? ?return ~0;
}

hook function fseek(File: handle, position = 0, seek_whence:whence = seek_start)
{
? ?if(handle) return continue(handle, position, whence);
? ?printf("Invalid handle passed to fseek!");
? ?return ~0;
}

hook function flength(File: handle)
{
? ?if(handle) return continue(handle);
? ?printf("Invalid handle passed to flength!");
? ?return ~0;
}

hook function CreateMenu(const title[], columns, Float:x, Float:y, Float:col1width, Float:col2width = 0.0)
{
? ?print("hook called");
}
Gamemode:
Code:
#include <a_samp>
#include <test>

main()
{

}

public OnGameModeInit()
{
? ?new Menu:test = CreateMenu("Your Menu", 2, 200.0, 100.0, 150.0, 150.0);
? ?return 1;
}

Result server 1: nothing
Result server 2: hook called

When I delete (or comment out) the file hooks in server 1, it prints, but only then.
It doesn't make any difference in server 2.

So... can someone confirm this issue and/or has any solution or any idea why this happens?
I'm out of ideas.
Can provide more information if needed.

(btw. are code tags broken when using formatting?)

//Update:
It works in server 1 when the CreateMenu hook is placed before the file hooks. Still don't know why this happens...
But didn't test yet, if the file hooks are called when switched place.
Will do more tests, after I finish the include, but seems like this isn't a scripting related problem.
If someone wants to move this thread to the appropriate section, I'd be thankful.
On a side note: if(handle) should be if(handle > 0). It's very unlikely a negative handle is passed by accident, but would still crash.

//Update2:
After adding some more hooks, CreateMenu wasn't called again.
I commented out the hook right after it (in this case DestroyMenu) and it got called again.
Oh, and tested file functions and none of them gets called.
So... I still don't know why, but it seems it has nothing to do with the script or hooks itself.
Also should add that I added a print to the gamemode in the meantime to print menuid and it is printing -2 now, which is very odd.

//Update3:
I give up. I can't find out why this happens.
Creating a third server using sampctl, running code works, still not in server 1 (Again same code).
Also it seems random which hook doesn't get called depending on where it's placed.
Can be more precise, but I don't see the point anymore.
Only assumption I can make is that it doesn't even matter what is hooked.
Solved the return of -2: I returned the menuid of created menu and used "return ~menuid", remove "~" and it returns the correct value.
  Reply


Forum Jump: