[Include] Simple callback printer
#1

There's nothing special with this include, it simply prints out (almost) every callback and its parameter. I created this to be used within debugging only, meaning I'd not suggest you to use this on a public server as the console will be spammed very quickly. The callbacks that are added is:
Quote:
  • OnActorStreamIn
  • OnActorStreamOut
  • OnDialogResponse
  • OnEnterExitModShop
  • OnFilterScriptExit
  • OnFilterScriptInit
  • OnGameModeExit
  • OnGameModeInit
  • OnIncomingConnection
  • OnObjectMoved
  • OnPlayerClickMap
  • OnPlayerClickPlayer
  • OnPlayerClickPlayerTextDraw
  • OnPlayerClickTextDraw
  • OnPlayerCommandText
  • OnPlayerConnect
  • OnPlayerDeath
  • OnPlayerDisconnect
  • OnPlayerEditAttachedObject
  • OnPlayerEditObject
  • OnPlayerEnterCheckpoint
  • OnPlayerEnterRaceCheckpoint
  • OnPlayerEnterVehicle
  • OnPlayerExitVehicle
  • OnPlayerExitedMenu
  • OnPlayerGiveDamage
  • OnPlayerGiveDamageActor
  • OnPlayerInteriorChange
  • OnPlayerKeyStateChange
  • OnPlayerLeaveCheckpoint
  • OnPlayerLeaveRaceCheckpoint
  • OnPlayerObjectMoved
  • OnPlayerPickUpPickup
  • OnPlayerRequestClass
  • OnPlayerRequestSpawn
  • OnPlayerSelectObject
  • OnPlayerSelectedMenuRow
  • OnPlayerSpawn
  • OnPlayerStateChange
  • OnPlayerStreamIn
  • OnPlayerStreamOut
  • OnPlayerTakeDamage
  • OnPlayerText
  • OnPlayerWeaponShot
  • OnRconCommand
  • OnRconLoginAttempt
  • OnVehicleDamageStatusUpdate
  • OnVehicleDeath
  • OnVehicleMod
  • OnVehiclePaintjob
  • OnVehicleRespray
  • OnVehicleSirenStateChange
  • OnVehicleSpawn
  • OnVehicleStreamIn
  • OnVehicleStreamOut
Here's a list of the callbacks that wasn't included and why not:
Quote:
OnTrailerUpdate
Completely unnecessary as it runs every each second depending on the trailer's movement and updates,
would just cause spam to the console.
OnPlayerUpdate
Same as above, would cause enormous spam.
OnUnoccupiedVehicleUpdate
Still same as above.
OnPlayerTeamPrivmsg
Callback was removed in newer versions of SAMP.
OnPlayerPrivmsg
Same as above, removed in newer versions of SAMP.
Some things you might want to keep in mind:
  • OnDialogResponse prints out the whole inputtext, this can be an unprotected password or such.
  • OnRconCommand can send its printf() to the player as a message if it was used by (/rcon)

And last: You must have y_hooks available for this to work, I did code it in ALS at first, but I fucked it up, so I had to change the whole code from ALS hooking to y_hooks.

@To people who think this is a completely unnecessary include;
It's not, it's really useful if you don't wanna bother going from callback to callback manually, checking if it's run or not etc.
(Yes, I did all of this manually, went through all wiki's etc.)



Pastebin: https://pastebin.com/MeSmDFEk
Reply
#2

That can be a handy for debugging but it's not that hard to do that for specific callbacks until you are lazy. Still good release, keep it up. REP+
Reply
#3

Nice one, useful for debugging prupose, +REP.
Reply
#4

Not bad! I like it.
I prefer this syntax:
PHP Code:
(response == 1)?("true"):("false") -> (response "true" "false"
Reply
#5

This is literally useless. I would rather debug myself only those callbacks which i need to check instead of this cluster. This will spam my log with unnecessary prints.

2-star
Reply
#6

Quote:
Originally Posted by Gammix
View Post
This is literally useless. I would rather debug myself only those callbacks which i need to check instead of this cluster. This will spam my log with unnecessary prints.

2-star
Maybe if it actually did something but all it does is use printf() there is simple then there is useless.
Reply
#7

This would be a perfect use for y_hooks with y_als, which already contains a lot of information about callbacks such as their parameters types and names. Then you could wrap the whole thing up in a nice macro and just have:

PHP Code:
DEBUG_CALLBACK(OnGameModeInit); 
People add that to their script and go!

Since you are already using YSI, you can pull the data from y_als. That used to be a core part of how YSI did things, but a lot has moved on since then and it is mostly legacy now - but still exists because compatability, and sometimes, like now, it has its uses. Unfortunately, that does mean that the API is not very well developed so it can be a little tricky to use. I had to read through the code to figure it out again, and just discovered that I actually wrote tests for it and moved it to the new internal layout... I have no memory of doing this, but it can't have been too long ago so clearly not THAT legacy just yet. And quite nicely, the tests are very similar to what is wanted here, so good!

The only tricky thing here is that we can't use the "hook" macro directly because of the way both it and y_als generate function names - they will interfere. Instead, we can just generate a hook directly (which actually may solve another problem...)

PHP Code:
// Set up the macros to do the right thing for each parameter type.
// These generate the correct string specifiers.
#define DBG_CB_S_more:%0,          "%d, " DBG_CB_S_
#define DBG_CB_S_string:%0[],      "%s, " DBG_CB_S_
#define DBG_CB_S_Float:%0,         "%f, " DBG_CB_S_
#define DBG_CB_S_tag:%3:%0,        "%d, " DBG_CB_S_
#define DBG_CB_S_array:%0[%1],     "{%d, ...}, " DBG_CB_S_
#define DBG_CB_S_end:%0)           "%d"
#define DBG_CB_S_none:%0)
#define DBG_CB_S_end_string:%0[])  "%s"
#define DBG_CB_S_end_Float:%0)     "%f"
#define DBG_CB_S_end_tag:%3:%0)    "%d"
#define DBG_CB_S_end_array:%0[%1]) "{%d, ...}"
// These generate the correct parameters given to the specifiers.
#define DBG_CB_P_more:%0,          ,%0 DBG_CB_P_
#define DBG_CB_P_string:%0[],      ,((%0[0])?(%0):("(null)")) DBG_CB_P_
#define DBG_CB_P_Float:%0,         ,%0 DBG_CB_P_
#define DBG_CB_P_tag:%3:%0,        ,(_:%0) DBG_CB_P_
#define DBG_CB_P_array:%0[%1],     ,_:%0[0] DBG_CB_P_
#define DBG_CB_P_end:%0)           ,%0)
#define DBG_CB_P_none:)            )
#define DBG_CB_P_end_string:%0[])  ,((%0[0])?(%0):("(null)")))
#define DBG_CB_P_end_Float:%0)     ,%0)
#define DBG_CB_P_end_tag:%3:%0)    ,(_:%0))
#define DBG_CB_P_end_array:%0[%1]) ,_:%0[0]) 
Libraries like code-parse should make this much simpler, but y_als has all the data for all the callbacks built-in, others just read code as-is. Now call the macros:

PHP Code:
#include <YSI_Coding\y_hooks>
#include <YSI_Core\y_als>
// The extra ")" is important.
#define DBG_CB_PRINT<%0,%1>(%2) printf("On"#%0" called: ("DBG_CB_S_%2)")"DBG_CB_P_%2)
// Define the parameters.
#define DBG_CB_PARAMS<%0,%1>(%2) @yH_%0@000(ALS_KS_%2)
// Construct the hook manually.
#define DEBUG_CALLBACK(On%0);    \
    
ALS_DO:DBG_CB_PARAMS<%0>;    \
    
ALS_DO:DBG_CB_PARAMS<%0>     \
    {                            \
        
ALS_DO:DBG_CB_PRINT<%0>; \
        return 
ALS_R_%0;         \
    } 
This calls ALS to generate the "forward" from the callback descriptor (note that the "forward" keyword is optional):

PHP Code:
    ALS_DO:DBG_CB_PARAMS<%0>;    \ 
This does the same for the start of the function:

PHP Code:
    ALS_DO:DBG_CB_PARAMS<%0>     \ 
This generates the print statement, again from the same descriptor:

PHP Code:
        ALS_DO:DBG_CB_PRINT<%0>; \ 
This returns the correct default for the current callback (almost always "1"):

PHP Code:
        return ALS_R_%0;         \ 
Examples. This method means that, as others have said, users can just add the following lines to their mode to enable debugging the callbacks they want, instead of all of them:

PHP Code:
DEBUG_CALLBACK(OnGameModeInit);
DEBUG_CALLBACK(OnPlayerConnect);
DEBUG_CALLBACK(OnPlayerGiveDamageActor); 
Unfortunatley we can't detect the END of the callback with y_hooks due to orderings - that would have to be done either in ALS or in y_hooks itself.
Reply
#8

This is useful, do the same with functions
Reply
#9

Quote:
Originally Posted by adri1
View Post
This is useful, do the same with functions
https://github.com/Zeex/samp-plugin-...#configuration

That would be more useful when it comes to debugging functions. You can even use regular expressions to filter out your trace
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)