SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Tools and Files

Reply
 
Thread Tools Display Modes
Old 06/05/2012, 05:58 AM   #1
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 929
Reputation: 158
Default [WIP]SA-MP ALS Hooking Generator 0.3a

SA-MP ALS Hooking Generator 0.3b



About
This is a simple app to generate the code needed to do an ALS hook on any callback.
Dont know what ALS Hooking is? Please check this posts for more info.

http://forum.sa-mp.com/showthread.php?t=85907

Whats this do?
The app will generate code to hook one or more callbacks defining all the ALS code for you
with your set prefix.


supports both pre & post code for OnGameModeInit().
The interface has checkboxs with a list of all callbacks to select to hook.


Is this better/faster than y_hooks?
Quote:
Originally Posted by ****** View Post
For reference, ALS and y_hooks are pretty much equal in run-time speed, but you're right that y_hooks takes longer to compile (though this has been vastly improved) and ALS takes longer to write - so if you have a tool to generate ALS code then that's a win!
Now I found y_hooks to be wonderful, and I use it myself, so it would depend on
where/what you using ALS over y_hooks, Do you want to depend on another lib,
would depend on your code, if your already using YSI then I would use y_hooks.


What language is this written in?
VS c# 2010


Update
After the discussion held here, ****** had some great ideas and some tips that I have implemented.
So credits to ****** for his tips & ideas!

List of changes
0.3b:
  • Fixed a bug in code that was generated for OnGameModeInit()
0.3a:
  • Fixed a bug in code that was generated to check for null strings.
0.3:
  • Added full support for custom functions
  • Added support for storing weather a callback exists or not.

0.2:
  • When no prefix is set, prompt user to enter one.
  • Code now generates support for null strings.
  • Added more to the interface to allow for Custom Callbacks ALS code generation.
    Read below in "Custom Callbacks" to learn how to use it.

Custom Callbacks
Adding a custom callback is easier than ever.
When you launch the ALS generator you'll see a group box
(See ss2.jpg from the attachments)
It takes 3 Parameters:
  • Name //This is the Callback Name ex: OnSomeCallBack
  • Format //This is the format specifier ex: isf
  • Arguments //This is the arguments list ex: playerid,text[],Float:fVal
Add these values and hit the Add Button.
Note that when using a string argument in a custom function
the code to check for null string is also generated for you!.
New in 0.3*
You can now add and remove custom callbacks from a list
before generating the ALS code.

Note
OnGameModeInit() is always generated. If its the only function you want to hook
Just set your prefix and hit generate!.

Future Release
I have planed for a future release that will load all callbacks from a file making it easy
to permanently add your custom callbacks. This will allow me to add the function hooking support
along with release a simple file for updating the app. This will require a rewrite of the hole system
so will not be done right away but over the next few weeks. I have another project to do before this.

Suggestions
Note this is a work in progress but fully functional,
any suggestions will be taken into consideration.


regards,
Attached Images
File Type: jpg ss.jpg (96.0 KB, 555 views)
File Type: jpg ss2.jpg (11.5 KB, 280 views)
Attached Files
File Type: rar SAMP_ALS_HOOKS0.3b.rar (10.0 KB, 367 views)
File Type: rar SAMP_ALS_HOOKS_SRC0.3b.rar (100.0 KB, 103 views)
__________________
If your topic says "REP+", I ignore it.

Last edited by Jonny5; 17/05/2012 at 02:31 AM. Reason: Updates!
Jonny5 is offline   Reply With Quote
Old 06/05/2012, 08:30 AM   #2
Crazymax
Big Clucker
 
Join Date: Apr 2012
Posts: 79
Reputation: 12
Default Re: [WIP]SA-MP ALS Hooking Generator

what does this exactly do... ?
Crazymax is offline   Reply With Quote
Old 06/05/2012, 03:12 PM   #3
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 929
Reputation: 158
Default Re: [WIP]SA-MP ALS Hooking Generator

it will generate code like
pawn Code:
//--------------OnGameModeInit Hook-------------------

public OnGameModeInit()
{
    new ret = 1;
    //your OnGameModeInit pre code here

    if (funcidx("Prefix_OnGameModeInit") != -1)
    {
        ret = CallLocalFunction("Prefix_OnGameModeInit", "");
    }
    //your OnGameModeInit post code here

    return ret;
}
#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#else
    #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit Prefix_OnGameModeInit
forward Prefix_OnGameModeInit();

This allows you to hook any callbacks
check out this post to see more info about ALS Hooking
http://forum.sa-mp.com/showthread.php?t=85907

this app just generates the proper code for you
__________________
If your topic says "REP+", I ignore it.
Jonny5 is offline   Reply With Quote
Old 07/05/2012, 02:57 AM   #4
Crazymax
Big Clucker
 
Join Date: Apr 2012
Posts: 79
Reputation: 12
Default Re: [WIP]SA-MP ALS Hooking Generator

nice... but i read the topic and i dont see why would i need to create different functions if i have all the native ones that i need?
Crazymax is offline   Reply With Quote
Old 07/05/2012, 01:11 PM   #5
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 929
Reputation: 158
Default Re: [WIP]SA-MP ALS Hooking Generator

then this is probably not for you.

The reason is so when you make an include that uses callbacks
you HOOK them and both your functions and the native callbacks get called.
Its mostly for if your making a library of some sort.
If you dont make this kinda stuff this is not for you,
__________________
If your topic says "REP+", I ignore it.
Jonny5 is offline   Reply With Quote
Old 14/05/2012, 08:31 PM   #6
Andrejs
Big Clucker
 
Andrejs's Avatar
 
Join Date: Jul 2010
Location: Estonia
Posts: 64
Reputation: 3
Default Re: [WIP]SA-MP ALS Hooking Generator

Quote:
Originally Posted by Jonny5 View Post
The reason is so when you make an include that uses callbacks
you HOOK them and both your functions and the native callbacks get called.
Its mostly for if your making a library of some sort.
If you dont make this kinda stuff this is not for you,
****** already did y_hook include, and it's much better
Andrejs is offline   Reply With Quote
Old 15/05/2012, 02:01 PM   #7
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 929
Reputation: 158
Default Re: [WIP]SA-MP ALS Hooking Generator

this is not an include, Its a app that will generate code in the ALS_ format,
Which has been around long before y_hooks
and which ****** standardized

I know all about y_hooks, (iv used them in some of my modes)

I dont know if its "better" or just easier.
(I do think he has done something with #emit to make calling the hooks faster than ALS)

This is for if you dont want to use y_hooks in your lib,
y_hooks add a big compile time on, Im guessing from all the marcos text replacements.

this is for people who write ALS code! simple as that, if your not into hooking your own functions
with ALS and writing include's or libraries then you wont need this.

regards,
__________________
If your topic says "REP+", I ignore it.
Jonny5 is offline   Reply With Quote
Old 15/05/2012, 03:04 PM   #8
Niko_boy
High-roller
 
Niko_boy's Avatar
 
Join Date: Aug 2010
Location: Somewhere i belong
Posts: 1,337
Reputation: 138
Default Re: [WIP]SA-MP ALS Hooking Generator

Quote:
Originally Posted by ****** View Post
Nice work! Definitely worth reputation. A few suggestions:
+1
Time Saving
__________________
nope[IMG]http://*******/1r0SOkH_[/IMG]
•••[CLOSED]LCS•Freeroam•DM•Stunts•••AutoArena [0.3z][No SkinShot][sixtytiger.com]Want a decent Attack Defend Gamemode?
N/A176.31.229.148:7830Get This! Attack-Defend(v2.3.1)
Niko_boy is offline   Reply With Quote
Old 15/05/2012, 03:04 PM   #9
Johann95
Big Clucker
 
Join Date: Nov 2010
Location: Austria
Posts: 145
Reputation: 11
Default AW: [WIP]SA-MP ALS Hooking Generator

Not Bad ^^

7/10

Update please Anymore Functions
Johann95 is offline   Reply With Quote
Old 15/05/2012, 09:05 PM   #10
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 929
Reputation: 158
Default Re: [WIP]SA-MP ALS Hooking Generator

Quote:
Originally Posted by ****** View Post
Nice work! Definitely worth reputation. A few thoughts:

1) Add a "custom" option - the patterns are pretty constant, though I'm not sure how parameters would work just yet (but shouldn't be too hard). This way people don't need to rely on waiting for updates when new callbacks are added - either officially or through other libraries.

2) Does this check for "\0" in callbacks with strings? They can be passed empty strings but can't pass them on again.

3) "funcidx" is either used purely in "OnModeInit" or not at all. Wrapping every "CallLocalFunction" in a call to "funcidx" has no gain - the result is normally found in advance and that saved value used. Check the "Optimisations" section of my post you linked to.

4) I'd suggest leaving the "Prefix" box empty by default and prompting for input if it is left blank to aovid everyone just using the defaults blindly (which they will - I did it without even thinking).

I was going to make a note about long callbacks, but I see you've already covered that, so that's even better!



For reference, ALS and y_hooks are pretty much equal in run-time speed, but you're right that y_hooks takes longer to compile (though this has been vastly improved) and ALS takes longer to write - so if you have a tool to generate ALS code then that's a win!
1.) did not even think about this, Great idea and will be added!
Do you think having having it load the custom Callbacks from files would be better?
I could load for each Lib, and have a file for new SAMP callbacks, that could be added to
until I make official update. This way I could write simple list file for each to support YSI, Streamer ect...
I think I may go that route.

2.) this does no checks, it just creates a skeleton ALS function for you,
I assume the scripter will handle any checks, but If its something I can add
I defiantly will. If you can post an example of what you mean that would be great.

3.) I thought doing it this way would return the next callbacks return, I will go back and re-read!
EDIT: I see the only advantage is OnGameModeInit() I will fix this.

4.)Yes you are correct! I will make that change,

Nice ideas!! and thanks for the tips, I will implement them ASAP.


Quote:
Originally Posted by Johann95 View Post
Not Bad ^^

7/10

Update please Anymore Functions
I plan a version for functions to, just need some time to go threw them and
see what ones I want to support, I wont be supporting some functions(db, file, ect..)

If there is any more ideas/features please post them and I will review/add them.

and thanks for the feedback guys!
__________________
If your topic says "REP+", I ignore it.
Jonny5 is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hooking OnPlayerClickPlayerTextDraw SuperViper Scripting Help 1 05/05/2012 07:08 PM
Hooking callbacks in plugins webcode421F Plugin Development 4 18/04/2012 05:15 PM
Hooking, Did i code it right? dowster Scripting Help 2 08/09/2011 04:16 AM
Hooking into callbacks? ScottCFR Help Archive 3 05/08/2011 04:54 AM
S-ALS Hooking Method leong124 Help Archive 4 25/05/2011 04:40 AM


All times are GMT. The time now is 08:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.