Search

open.mp forum

RegisterLogin

Discussion

General
Chat
Tech
Life
Art
Programming
open.mp
Development Updates
Questions and Suggestions
SA-MP
General Discussions
Videos and Screenshots
Support
Pawn Scripting
Tutorials
Releases
Plugins
Libraries
Filterscripts
Gamemodes
Maps
Advertisements
Other languages
Spanish/Espa?ol
Programaci?n
Discusi?n GTA SA Multijugador
Mods
Offtopic
Juegos
Portuguese/Portugu?s
Russian/???????
Italian/Italiano
Dutch/Nederlands
German/Deutsch
Romanian/Rom?na
Ex-Yu
Polish/Polski
Og?lne
Serwery
Skryptowanie
Filmiki i zdjecia
Lithuanian/Lietuvi?kas
French/Fran?ais
Hungarian/Magyar
Hindi/Urdu
Turkish
Other
Internal
Team
Hidden
Archived

Library

 Collections Links Members Roles

Very specific problem regarding file functions and y_hooks

So... I don't really know if it is even script related or a bug with samp, y_hooks or sampctl.

ID
d6ouivfilegovhg7bdag
author
plastikmensch's avatar

Plastikmensch

@plastikmensch


View profile
Copy link
  Report member
started
Oct 9, 2019
replies
0
participating
No

scroll to top

powered by storyden

Login
Discussion
Pawn Scripting
Very specific problem regarding file functions and y_hooks
plastikmensch's avatar

Plastikmensch

@plastikmensch


View profile
Copy link
  Report member
• 6y
Pawn Scripting

Very specific problem regarding file functions and y_hooks

pawn

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:

#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:

#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.

0 likes0 replies

    Please sign up or log in to reply